Today, we need to modify the flashing frequency of the LED light according to the latest requirements, and change the default 10000 ms to ms. However, after the modification, the result is not expected, but is changed to a constant, finally, I read the fucking code from the upper layer to the bottom layer, and finally found the problem. Next I directly wrote the MTK LED driver code:
#define PMIC_PERIOD_NUM 9// 100 * period, ex: 0.01 Hz -> 0.01 * 100 = 1int 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\n", 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\n",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\n", time_index, pmic_freqsel_array[time_index]);duty=32*led->blink_on_time/(led->blink_on_time + led->blink_off_time);
In addition to the above code, we can see that the above Code does not support the flickering frequency over Ms. In addition, we also see another problem, that is, the array out-of-bounds problem that occurs frequently for new users, without any access protection.