Android呼吸灯添加
平台:mtk
一.hal层入口
Lights.c (vendor\mediatek\proprietary\hardware\liblights)
char const*const RED_LED_FILE = "/sys/class/leds/red/brightness";
char const*const RED_DELAY_ON_FILE = "/sys/class/leds/red/delay_on";
char const*const RED_DELAY_OFF_FILE = "/sys/class/leds/red/delay_off";
中间层调用open_lights
else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) { //这里有很多种灯的情况,我们就分析提示的
set_light = set_light_notifications;
}
set_light_notifications
handle_speaker_battery_locked(dev);
set_speaker_light_locked(dev, &g_battery); //电池提示
set_speaker_light_locked(dev, &g_notification); //消息提示
blink_red(red, onMS, offMS); //这里有green,red,blue的分支,我们分析red
write_str(RED_TRIGGER_FILE, "timer"); //写入timer
write_int(RED_DELAY_OFF_FILE, offMS); //生成delay_off节点并写入,在电量低的时候
write_int(RED_DELAY_ON_FILE, onMS); //生成delay_on节点并写入,在电量低的时候
二.kernel LEDS架构
1.Cust_leds.c (kernel-3.10\drivers\misc\mediatek\mach\mt6735\ck3_01\leds\mt65xx)
static struct cust_mt65xx_led cust_led_list[MT65XX_LED_TYPE_TOTAL] = {
{"red", MT65XX_LED_MODE_CUST, 1, {0}},
{"green", MT65XX_LED_MODE_CUST, 2, {0}},
}
struct cust_mt65xx_led *get_cust_led_list(void) //获得这个custom
{
return cust_led_list;
}
2.Leds.c (kernel-3.10\drivers\misc\mediatek\leds\mt6735)
struct cust_mt65xx_led * mt_get_cust_led_list(void)
{
return get_cust_led_list();
}
3.Leds_drv.c (kernel-3.10\drivers\misc\mediatek\leds) //mtk里面leds的核心
mt65xx_leds_probe
cust_led_list = mt_get_cust_led_list(); //得到所有的led
g_leds_data[i]->cdev.name = cust_led_list[i].name; //记录名字
g_leds_data[i]->cdev.brightness_set = mt65xx_led_set; //设置相关的操作函数
g_leds_data[i]->cdev.blink_set = mt65xx_blink_set; //设置相关的操作函数
ret = led_classdev_register(&pdev->dev, &g_leds_data[i]->cdev); //注册leds到核心
4.Led-class.c (kernel-3.10\drivers\leds)
led_classdev_register
led_cdev->dev = device_create(leds_class, parent, 0, led_cdev, "%s", led_cdev->name); //在sys/leds/生成相应的节点
list_add_tail(&led_cdev->node, &leds_list); //加入到leds_list
INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed); //初始化
init_timer(&led_cdev->blink_timer);
led_cdev->blink_timer.function = led_timer_function; //timer
led_cdev->blink_timer.data = (unsigned long)led_cdev; //timer
led_trigger_set_default //加入到trigger
led_brightness_store //给上层调节亮度的接口
__led_set_brightness
led_cdev->brightness_set(led_cdev, value); //调用相应的设备的brightness_set,这里是Leds_drv.c中的mt65xx_led_set函数
mt65xx_led_set
mt_mt65xx_led_set(led_cdev, level);
mt_mt65xx_led_set_cust(&led_data->cust, level);
switch (cust->mode) //对不同模式调用不同函数
case MT65XX_LED_MODE_CUST: 这种模式
1 == cust->data //这个私有数据
led_trigger_store //给上层trigger的接口,用于呼吸灯
list_for_each_entry(trig, &trigger_list, next_trig) //遍历trigger_list,找不到相应的
led_trigger_set(led_cdev, trig); //调用这个函数
trig->activate(led_cdev); //这个函数在Ledtrig-timer.c (kernel-3.10\drivers\leds\trigger)中初始化.activate = timer_trig_activate, deactivate = timer_trig_deactivate,
timer_trig_activate
rc = device_create_file(led_cdev->dev, &dev_attr_delay_on); //创建"/sys/class/leds/red/delay_on";节点
rc = device_create_file(led_cdev->dev, &dev_attr_delay_off); //创建"/sys/class/leds/red/delay_off";节点
led_blink_set(led_cdev, &led_cdev->blink_delay_on, &led_cdev->blink_delay_off); //调用相应接口
led_blink_setup(led_cdev, delay_on, delay_off);
led_cdev->blink_set(led_cdev, delay_on, delay_off) //执行这个//调用相应的设备的brightness_set,这里是Leds_drv.c中的mt65xx_blink_set函数
mt_mt65xx_blink_set
else if(led_data->cust.mode == MT65XX_LED_MODE_CUST) //对应的模式
if (1 == led_data->cust.data) //对应的私有变量
led_set_software_blink(led_cdev, *delay_on, *delay_off); //如果前面if (!(led_cdev->flags & LED_BLINK_ONESHOT) && led_cdev->blink_set && !led_cdev->blink_set(led_cdev, delay_on, delay_off))
不成立就调用这个函数
__led_set_brightness(led_cdev, led_cdev->blink_brightness); //设置亮度函数
mod_timer(&led_cdev->blink_timer, jiffies + 1); //重复点亮熄灭
led_delay_off_store
led_blink_set(led_cdev, &led_cdev->blink_delay_on, &state);
led_blink_setup(led_cdev, delay_on, delay_off);
与led_trigger_store的led_blink_setup 一样
led_delay_on_store
与led_delay_off_store差不多
四.呼吸灯驱动
1.在drivers/misc/mediatek/mach/mt6735/CK3_01/core/board.c中的mt_power_off函数中
加上ktd2xx_led_off();
如果不加上会在关机充电的时候拔出充电器,led还是亮着的。