Problems found in mtk led driver by an LED flash Problem

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.