Difference between revisions of "GPIO LEDS"
(→Usage) |
(→Usage: full path is better) |
||
Line 118: | Line 118: | ||
<pre class="apf"> | <pre class="apf"> | ||
− | # echo 17 > gpio | + | # echo 17 > /sys/class/leds/apfdev:green:user/gpio |
</pre> | </pre> | ||
Revision as of 19:30, 8 August 2012
How to use leds-gpio driver to manage states of connected leds of your Armadeus board.
Contents
Introduction
You can manage a led connected to a GPIO pin. The LED management is similar with the standard GPIO sysfs driver, but you have some new features like triggers (e.g. "heartbeat" LED blinks like a heart at the rate oh the CPU load) . Here are the GPIO used for the user LED for each APF board:
- APF9328: PORT A / bit 2
- APF27: GPIO_PORTF | 14
- APF28: PINID_GPMI_RDY1 (Bank 0 - pin 21)
- APF51: GPIO_PORTA | 2
Configuration
First, you need to enable the leds-gpio driver in your kernel and some triggers like the "heartbeat" trigger to make the LED flash like a heartbeat.
Device Drivers ---> --- LED support [*] LED Class Support *** LED drivers *** <*> LED Support for GPIO connected LEDs [*] Platform device bindings for GPIO LEDs *** LED Triggers *** [*] LED Trigger support <*> LED Timer Trigger <*> LED Heartbeat Trigger <*> LED backlight Trigger <*> LED Default ON Trigger
Then, in your apfXX-dev.c, you would need to define your LED before the variable platform_devices[]. This code is already implemented for the APF27, APF28 and APF51 so the source code hereafter (for the APF27) is only present as a reference sample to understand how to activate a GPIO LED driver.
#include <linux/leds.h>
/* GPIO LED */
#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
static struct gpio_led apf27dev_led[] = {
{
.name = "apfdev:green:user",
.default_trigger = "heartbeat",
.gpio = (GPIO_PORTF | 14),
.active_low = 1,
},
};
static struct gpio_led_platform_data apf27dev_led_data = {
.num_leds = ARRAY_SIZE(apf27dev_led),
.leds = apf27dev_led
};
static struct platform_device apf27dev_led_dev = {
.name = "leds-gpio",
.id = -1,
.dev = {
.platform_data = &apf27dev_led_data,
},
};
#endif /* CONFIG_LEDS_GPIO */
Add the LED to get it managed by the kernel.
static struct platform_device *platform_devices[] __initdata = {
#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
&apf27dev_led_dev,
#endif
ALSA_SOUND
};
Then rebuild and update your bard with the new kernel. Upon the next kernel boot you should see the LED flash like a heartbeat (if you have activated the "heartbeat" trigger)
Usage
# ls /sys/class/leds/apfdev\:green\:user/ brightness max_brightness subsystem uevent device power trigger
You can change the trigger behaviors. By default, Heartbeat is selected:
- "heatbeat": led blinks like a heart and blink frequency will change according o the CPU activity.
- "nand-disk": the led will blink each time nand access occur (try with sync command to see it blinking).
# cat /sys/class/leds/apfdev\:green\:user/trigger none nand-disk mmc0 timer [heartbeat] backlight gpio default-on # echo none > /sys/class/leds/apfdev\:green\:user/trigger
Switch on and off the LED
# cat /sys/class/leds/apfdev\:green\:user/max_brightness > /sys/class/leds/apfde v\:green\:user/brightness # echo 0 > /sys/class/leds/apfdev\:green\:user/brightness
It is possible to switch led state using the APF28Dev user button. This button is seen as gpio17 (as seen under APF28Dev datasheet) under Linux, then configure the led trigger as gpio :
# echo "gpio" > /sys/class/leds/apfdev:green:user/trigger
New config files are available :
# ls /sys/class/leds/apfdev:green:user/ brightness gpio power uevent desired_brightness inverted subsystem device max_brightness trigger
Then the trigger gpio can be configured with gpio file :
# echo 17 > /sys/class/leds/apfdev:green:user/gpio
Then pushing the user switch will now commute the LED state.