GPIO 接続 LED class device

GPIO に接続した LED に対して LED class device として扱うための汎用ドライバ drivers/leds/leds-gpio.c があります。gpio_* 関数群でアクセス可能な端子であれば、次のようなデータ構造を記述して struct platform_deviceplatform_device_register() で platform device として登録するだけで LED class device になります。

  • struct gpio_led を静的に配列状に配置し、そのメンバ name(名前), gpio(GPIO ピン番号), active_low(Low Level で点灯ならば 1) を記述します。
  • struct gpio_led_platform_data を静的に配置し上記で配置した配列を格納します。1 要素の配列でも良い
  • struct platform_device を静的に配置し、dev.platform_data に上記の struct gpio_led_platform_data を指すポインタを格納して、name(platform device の class 名) = "leds-gpio", id = -1 とします。

具体的な記述の詳細は struct gpio_led または struct gpio_led_platform_data を使っているソースを参照して下さい。

fileOpenGrok(linux-4.1.27/include/linux/leds.h:302)
Expand allFold all
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;
        /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
        struct gpio_desc *gpiod;
};
#define LEDS_GPIO_DEFSTATE_OFF          0
#define LEDS_GPIO_DEFSTATE_ON           1
#define LEDS_GPIO_DEFSTATE_KEEP         2
fileOpenGrok(linux-4.1.27/include/linux/leds.h:316)
Expand allFold all
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       /* No blink GPIO state low */
#define GPIO_LED_NO_BLINK_HIGH  1       /* No blink GPIO state high */
#define GPIO_LED_BLINK          2       /* Please, blink */
        int             (*gpio_blink_set)(struct gpio_desc *desc, int state,
                                        unsigned long *delay_on,
                                        unsigned long *delay_off);
};
fileOpenGrok(linux-4.1.27/include/linux/platform_device.h:22)
Expand allFold all
 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; /* Driver name to force a match */
 
        /* MFD cell pointer */
        struct mfd_cell *mfd_cell;
 
        /* arch specific additions */
        struct pdev_archdata    archdata;
};

ノート

今後、具体的なサンプルを用意するかな。


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2017-06-28 (水) 01:13:22 (2497d)