GPIO 接続 LED class device †
GPIO に接続した LED に対して LED class device として扱うための汎用ドライバ drivers/leds/leds-gpio.c があります。gpio_* 関数群でアクセス可能な端子であれば、次のようなデータ構造を記述して struct platform_device を platform_device_register() で platform device として登録するだけで LED class device になります。
具体的な記述の詳細は struct gpio_led または struct gpio_led_platform_data を使っているソースを参照して下さい。
302
303
304
305
306
307
308
309
310
311
312
313
314
| -
|
|
|
|
|
|
|
|
!
| 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;
struct gpio_desc *gpiod;
};
#define LEDS_GPIO_DEFSTATE_OFF 0
#define LEDS_GPIO_DEFSTATE_ON 1
#define LEDS_GPIO_DEFSTATE_KEEP 2
|
316
317
318
319
320
321
322
323
324
325
326
| -
|
|
|
|
|
|
|
|
|
!
| struct gpio_led_platform_data {
int num_leds;
const struct gpio_led *leds;
#define GPIO_LED_NO_BLINK_LOW 0
#define GPIO_LED_NO_BLINK_HIGH 1
#define GPIO_LED_BLINK 2
int (*gpio_blink_set)(struct gpio_desc *desc, int state,
unsigned long *delay_on,
unsigned long *delay_off);
};
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
| struct platform_device {
const char *name;
int id;
bool id_auto;
struct device dev;
u32 num_resources;
struct resource *resource;
const struct platform_device_id *id_entry;
char *driver_override;
struct mfd_cell *mfd_cell;
struct pdev_archdata archdata;
};
|