linux gpio_led framework 用法

1. 先將 menuconfig 裡 LED Trigger support 打開 
Device Drivers  --->  LED Support  --->  LED Trigger support  --->  LED Timer Trigger
                                                                   |->  LED Heartbeat Trigger
                                                                   |->  LED backlight Trigger
                                                                   |->  LED GPIO Trigger
                                                                   |->  LED Default ON Trigger

2. 將 gpio-key 定義好, 並註冊.
struct gpio_led {
const char *name;
const char *default_trigger;
unsigned gpio;
unsigned active_low : 1;
unsigned retain_state_suspended : 1;
unsigned default_state : 2;
/* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
};

struct gpio_led_platform_data {
int num_leds;
struct gpio_led *leds;
int (*gpio_blink_set)(unsigned gpio, int state,
unsigned long *delay_on,
unsigned long *delay_off);
};

#include
#include

static struct gpio_led default_leds[] = {
{
.name = "Heartbeat",
.gpio = CPU_TEST_LED,
.default_trigger = "heartbeat",
.active_low = 1,
},
};

static struct gpio_led_platform_data heartbeat_led_data = {
.num_leds = ARRAY_SIZE(default_leds),
.leds = default_leds,
};

static struct platform_device heartbeat_leds = {
.name = "leds-gpio",
.id = -1,
.dev = {
.platform_data = &heartbeat_led_data,
}
};

platform_device_register(&heartbeat_leds);


3. 編好 kernel 後, 你會看到 /sys/devices/platform/leds-gpio/leds/Heartbeat, 表示你 ...  成功了 ...

4. cat /sys/devices/platform/leds-gpio/leds/Heartbeat/trigger
none nand-disk timer [heartbeat] gpio default-on
表示目前功能是 [heartbeat]

5. 將 trigger 改成 timer, 可以用來 blinking LED ...
echo timer > sys/devices/platform/leds-gpio/leds/Heartbeat/trigger
   cat /sys/devices/platform/leds-gpio/leds/Heartbeat/trigger
none nand-disk [timer] heartbeat gpio default-on

   echo 50 > sys/devices/platform/leds-gpio/leds/Heartbeat/delay_on
   echo 50 > sys/devices/platform/leds-gpio/leds/Heartbeat/delay_off

留言

這個網誌中的熱門文章

NMEA標準格式 -- GPS

網路 Transformer 的用途

cut,sed,awk 字串處理