Difference between revisions of "GPIO LEDS"

From ArmadeusWiki
Jump to: navigation, search
(Introduction)
(Configuration)
Line 7: Line 7:
 
==Configuration==
 
==Configuration==
  
First, you need to enable the leds-gpio driver in your kernel.
+
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.
  
 
<pre class="config">
 
<pre class="config">
Line 13: Line 13:
 
     --- LED support
 
     --- LED support
 
         [*] LED Class Support
 
         [*] LED Class Support
 +
              *** LED drivers ***
 
         <*> LED Support for GPIO connected LEDs
 
         <*> LED Support for GPIO connected LEDs
 
               [*] Platform device bindings for GPIO 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
 
</pre>
 
</pre>
  
Line 20: Line 27:
  
 
<source lang="c">
 
<source lang="c">
 +
 +
#include <linux/leds.h>
 +
 
/* GPIO LED */
 
/* GPIO LED */
#if 1
+
#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
+
static struct gpio_led apf27dev_led[] = {
/* PORTF_14 used as leds-gpio (GPIO used as LED) */
+
static struct gpio_led apf27_gpio_leds[] = {
+
 
{
 
{
.name = "portf14",
+
.name = "apfdev:green:user",
.default_trigger = "none",
+
.default_trigger = "heartbeat",
 
.gpio = (GPIO_PORTF | 14),
 
.gpio = (GPIO_PORTF | 14),
//.active_low = 1,
+
.active_low = 1,
//.retain_state_suspended = 1,
+
//.default_state = LEDS_GPIO_DEFSTATE_ON,
+
 
},
 
},
 
};
 
};
  
static struct gpio_led_platform_data apf27_gpio_leds_platform_data = {
+
static struct gpio_led_platform_data apf27dev_led_data = {
.leds = apf27_gpio_leds,
+
.num_leds = ARRAY_SIZE(apf27dev_led),
.num_leds = ARRAY_SIZE(apf27_gpio_leds),
+
.leds = apf27dev_led
 
};
 
};
  
static struct platform_device apf27_gpio_leds_device = {
+
static struct platform_device apf27dev_led_dev = {
.name = "leds-gpio",
+
.name = "leds-gpio",
.id = 0,
+
.id = -1,
.dev = {
+
.dev = {
.platform_data = &apf27_gpio_leds_platform_data,
+
.platform_data = &apf27dev_led_data,
 
},
 
},
 
};
 
};
# define LEDS_GPIO &apf27_gpio_leds_device,
+
#endif /* CONFIG_LEDS_GPIO */
#else
+
# define LEDS_GPIO
+
#endif
+
 
</source>
 
</source>
  
Add the button to get it recognized by the card.
+
Add the LED to get it managed by the kernel.
  
 
<source lang="c">
 
<source lang="c">
 
static struct platform_device *platform_devices[] __initdata = {
 
static struct platform_device *platform_devices[] __initdata = {
 +
#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
 +
&apf27dev_led_dev,
 +
#endif
 
ALSA_SOUND
 
ALSA_SOUND
LEDS_GPIO
+
 
 
};
 
};
 
</source>
 
</source>
  
 
<pre class="apf">
 
<pre class="apf">
# ls /sys/class/leds/portf14/
+
# ls /sys/class/leds/apfdev\:green\:user/
 
brightness      max_brightness  subsystem      uevent
 
brightness      max_brightness  subsystem      uevent
 
device          power          trigger
 
device          power          trigger
 
</pre>
 
</pre>

Revision as of 00:44, 16 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. LED blinks based on disk access) .

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