- 在config裡勾選
CONFIG_NEW_LEDS=y CONFIG_LEDS_CLASS=y CONFIG_LEDS_GPIO=y CONFIG_LEDS_TRIGGERS=y CONFIG_LEDS_TRIGGER_TIMER=y
- 在board-*.c 裡面建立platform_device
static struct gpio_led gpio_leds[] = { { .name = "WHITE_LED",//should change to your own .gpio = _GPIO_1, //should change to your own .active_low = 1, .default_trigger = "timer", }, }; static struct gpio_led_platform_data gpio_led_info = { .leds = gpio_leds, .num_leds = ARRAY_SIZE(gpio_leds), }; static struct platform_device leds_gpio = { .name = "leds-gpio", .id = -1, .dev = { .platform_data = &gpio_led_info, }, }; //記得要在類似init加入--> platform_device_register(&leds_gpio);
- 實做platform_driver
基本上依我的板子為例,platform_driver的實做已經在driver/leds/leds-gpio.c裡面做好了 不需要更改
- 修改LED HAL
以我的版為例,修改的是libleds.c 在 static int open_lights(const struct hw_module_t *module, char const *name, struct hw_device_t **device) 裡面新增了 }else if(0 == strcmp(LIGHT_ID_BATTERY, name)){ set_light = set_light_battery; } 然後因為我的led是gpio led, 只支援on/off ,沒有brightness level, Android定義了不同的level會有不同的顏色或閃爍 因此我的實做為 static int set_light_battery(struct light_device_t *dev, struct light_state_t const *state) { int err = 0; int flashmode=state->flashMode; pthread_mutex_lock(&g_lock); //set flash if(flashmode==1){ err = write_str("/sys/class/leds/PMU_LED/trigger","timer"); err = write_int("/sys/class/leds/PMU_LED/delay_on",250); err = write_int("/sys/class/leds/PMU_LED/delay_off",150); }else if(state->color ==0xffffff00||state->color ==0xffff0000||state->color ==-256){ err = write_str("/sys/class/leds/PMU_LED/trigger","none"); err = write_int("/sys/class/leds/PMU_LED/brightness",0); }else if(state->color ==0xff00ff00||state->color ==0x0){ err = write_str("/sys/class/leds/PMU_LED/trigger","none"); err = write_int("/sys/class/leds/PMU_LED/brightness",255); } pthread_mutex_unlock(&g_lock); return err; }
2012年3月23日 星期五
Android LED Implementation
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言