如何注册一个GPIO为Led、Button

From WRTnode Wiki Site
Jump to: navigation, search
This page is a translated version of the page How to register a GPIO as Led or Button and the translation is 100% complete.

Other languages:
English 100% • ‎中文(中国大陆)‎ 100%

"make menuconfig"命令进入配置界面,选择Led、Button驱动
Led 驱动:

LED modules    --->   <*> kmod-leds-gpio 
                      <*> kmod-ledtrig-usbdev

Button 驱动:

Other modules  --->   <*> kmod-gpio-button-hotplug.

打开并修改WRTNODE.dts
添加 Led:

   gpio-leds {
       compatible = "gpio-leds";
       indicator {
           label = "wrtnode:blue:indicator";
           gpios = <&gpio1 14 1>;
       };
   }; 

compatible要与Led的驱动leds-gpio.c里compatible对应。label是设备的名字,在文件系统/sys/class/leds/目录下设备名对应
gpios = <&gpio1 14 1>,这是指定对应的gpio引脚(GPIO#40)

Usergpio1.png

Addled1.png

添加Button:

   gpio-keys-polled {
       compatible = "gpio-keys-polled";
       #address-cells = <1>;
       #size-cells = <0>;
       poll-interval = <20>;
       reset {
           label = "reset";
           gpios = <&gpio0 1 1>;
           linux,code = <0x198>;
         };
   };