Difference between revisions of "GPIO LEDS"

From ArmadeusWiki
Jump to: navigation, search
(Configuration)
(Introduction)
Line 3: Line 3:
 
==Introduction==
 
==Introduction==
  
You can manage a led connected to a GPIO pin. The managing is similar with the standard GPIO sysfs driver, but you have some new features like triggers (e.g. LED blinks based on disk access) .
+
You can manage a led connected to a GPIO pin. The managing 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) .
  
 
==Configuration==
 
==Configuration==

Revision as of 23:46, 15 May 2012

How to use leds-gpio driver to manage states of connected leds of your Armadeus board.

Introduction

You can manage a led connected to a GPIO pin. The managing 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) .

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 apf27-dev.c, you need to define your LED before the variable platform_devices[].

#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

};
# ls /sys/class/leds/apfdev\:green\:user/
brightness      max_brightness  subsystem       uevent
device          power           trigger