Board : Nanopi M4
流程
1)寫設備樹
驅動的compatible 與設備樹的compatible對應,再用GPIO API(devm_get_gpiod_from_child)擷取設備樹pin
2)驅動是現成的pio_keys_polled.c gpiod_get_value
編譯kernel後燒錄
3)user space用api做read(fd, &ev, sizeof(struct input_event)
設備樹
gpio-keys {
compatible = "gpio-keys-polled";
poll-interval = <100>; //轮训间隔设置100ms
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&key_0 &key_1 &key_2 &key_3>;
user_k1 {
label = "User Push Button K1";
linux,code = <KEY_RED>;
gpios = <&gpio4 RK_PC0 GPIO_ACTIVE_HIGH>; //PC0 = K1 red