Gpio control for keys and lights in the OpenWrt

Source: Internet
Author: User

Based on the Barrierbreaker version, the description is based on the AR9331 AP121 demo veneer

1. Lamp

A. In mach-ap121.c, the definition of the gpio corresponding to the lamp is defined:

#define Ap121_gpio_led_wlan0

#define Ap121_gpio_led_usb1

and defines the GPIO structure object for the lamp:

static struct gpio_led ap121_leds_gpio[] __initdata = {{. Name= "Ap121:green:usb",. Gpio= Ap121_gpio_led_usb,. active_low= 0,},{. Name= "Ap121:green:wlan",. Gpio= Ap121_gpio_led_wlan,. active_low= 0,},

}

In the initialization function: ap121_setup  , using the Span style= "line-height:1.5;" >ath79_register_leds_gpio ( -1, Array_size (Ap121_leds_gpio),   ap121_ Leds_gpio), enabling the registration of LED device. After this function is called, a device of type platform is created, and the leds-gpio driver (LEDS-GPIO.C) implements Bindings. In this way, the control directory for the corresponding LED lights is generated in the /sys/devices/platform/leds-gpio/directory:

Drwxr-xr-x    2 root     root             0 Jan  1  1970  Ap121:green:usbdrwxr-xr-x    2 root     root             0 Jan  1 & Nbsp;1970 ap121:green:wlanb. Enter any of the above directories, such as: Ap121:green:wlan, will have the following files:-rw-r--r--   1 root     Root          4096 Jan 06:19 brightness lrwxrwxrwx    1 root     root             0 Jan 06:04 device. /.. /.. /leds-gpio-r--r--r--   1 root     root          4096 Jan 06:04 max_bright nesslrwxrwxrwx    1 root     root             0 Jan 06:04 Subsystem- >.. /.. /.. /.. /.. /class/leds-rw-r--r--   1 root     root          4096 Jan 06:04 trigger-r w-r--r--   1 root     root         4096 Jan 06:04 uevent

With echo 1 > Brightness, you can control the lights, echo 0 > brightness,

2. Keys

A. In Mach-ap121.c, a gpio and a data structure object are defined for the keystrokes:

#define Ap121_gpio_btn_jumpstart11

#define Ap121_gpio_btn_reset12

And

static struct Gpio_keys_button ap121_gpio_keys[] __initdata = {{. desc= "Jumpstart Button",. type= Ev_key,. Code= Key_wps_button,//defined in GPIO-BUTTON-HOTPLUG.C. Debounce_interval = Ap121_keys_debounce_interval,. Gpio= Ap121_gpio_btn_jumpstart,. active_low= 1,},{. desc= "reset Button",. type= Ev_key,. Code= Key_restart,//defined in GPIO-BUTTON-HOTPLUG.C. Debounce_interval = Ap121_keys_debounce_interval,. Gpio= Ap121_gpio_btn_reset,. active_low= 1,},

}

in the initialization function: Ap121_setup , the use of

Ath79_register_gpio_keys_polled ( -1, Ap121_keys_poll_interval,array_size (Ap121_gpio_keys),Ap121_gpio_keys);

the registration of key device is implemented. After this function is called, the platform type device is created, and the gpio-keys-polled driver (gpio-button-hotplug.c
) implements the binding.

B.

When the key is pressed, the Button_hotplug_event function (GPIO-BUTTON-HOTPLUG.C) is triggered: Call Button_hotplug_create_event to generate Uevent event, call Button_hotplug _fill_even fills the event (in JSON format) and eventually calls Button_hotplug_work to issue uevent broadcast above broadcast, being PROCD in the process of Hotplug_handler (PROCD/PLUG/HOTPLUG.C) Receive and navigate to the corresponding execution function according to the pre-defined JSON content matching criteria in Etc/hotplug.json, as follows:["If",["and",["Has", "button"],["EQ", "SUBSYSTEM", "button"],],["Exec", "/etc/rc.button/%button%"]], and["If",["EQ", "SUBSYSTEM",["NET", "input", "USB", "ieee1394", "Block", "ATM", "Zaptel", "TTY", "button"]],["Exec", "/sbin/hotplug-call", "%subsystem%"]],

Gpio control for keys and lights in the OpenWrt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.