今天依据最新的需求要对LED灯的提示闪烁频率进行改动,将之前默认的2000ms改为10000ms,可是改动之后没有产生预料中的效果,而是变成了常量,百思不得其解,最后还是read the fucking code,从上层究竟层,一路追下来,终于发现了问题所在,以下直接上MTK的LED driver代码:
#define PMIC_PERIOD_NUM 9
// 100 * period, ex: 0.01 Hz -> 0.01 * 100 = 1
int pmic_period_array[] = {250,500,1000,1250,1666,2000,2500,10000};
//int pmic_freqsel_array[] = {99999, 9999, 4999, 1999, 999, 499, 199, 4, 0};
int pmic_freqsel_array[] = {0, 4, 199, 499, 999, 1999, 1999, 1999};
static int find_time_index_pmic(int time_ms) {
int i;
for(i=0;i<PMIC_PERIOD_NUM;i++) {
if(time_ms<=pmic_period_array[i]) {
return i;
} else {
continue;
}
}
return PMIC_PERIOD_NUM-1;
}
int mt_led_blink_pmic(enum mt65xx_led_pmic pmic_type, struct nled_setting* led) {
int time_index = 0;
int duty = 0;
LEDS_DEBUG("[LED]led_blink_pmic: pmic_type=%d
", pmic_type);
if((pmic_type != MT65XX_LED_PMIC_NLED_ISINK0 && pmic_type!= MT65XX_LED_PMIC_NLED_ISINK1 &&
pmic_type!= MT65XX_LED_PMIC_NLED_ISINK2 && pmic_type!= MT65XX_LED_PMIC_NLED_ISINK3) || led->nled_mode != NLED_BLINK) {
return -1;
}
LEDS_DEBUG("[LED]LED blink on time = %d offtime = %d
",led->blink_on_time,led->blink_off_time);
time_index = find_time_index_pmic(led->blink_on_time + led->blink_off_time);
LEDS_DEBUG("[LED]LED index is %d freqsel=%d
", time_index, pmic_freqsel_array[time_index]);
duty=32*led->blink_on_time/(led->blink_on_time + led->blink_off_time);
从以上代码除了能够看到其本来就不支持1999ms以上的闪烁频率之外,还看到了另外一个问题,就是新手常常发生的数组越界问题,没有採取不论什么的訪问保护。