驅動代碼
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <mach/gpio.h>
#include <linux/leds.h>
struct gpio_led leds[] = {
{"led0", "heartbeat", GPIOA(18), 0, 0, 0},
};
struct gpio_led_platform_data pdata = {
.num_leds = ARRAY_SIZE(leds),
.leds = leds,
};
struct platform_device mypdev = {
.name = "leds-gpio",
.id = -1,
.dev = {
.platform_data = &pdata,
},
};
module_driver(mypdev, platform_device_register, platform_device_unregister);
MODULE_LICENSE("GPL");
驅動配置在圖形化配置菜單裡選:
Device Driver ---> Led Support
如下圖配置
加載驅動後,led不斷閃爍;
^_^ /# echo 1 > /sys/class/leds/led0/brightness //led亮
^_^ /# echo 0 > /sys/class/leds/led0/brightness //led滅