Some PPC controls do not use linear counting, but use cyclic counting, that is, the adjusted value of the next moment is related to the adjusted value of the previous time. Take aw9956 as an example: it is a pulse-controlled LCD backlight driver chip with a total brightness of 16 levels, with a rising edge count.
As shown above, Ton is the level from the LCD backlight from the shutdown to the Enable level, followed by a regular equi-long pulse, and finally tshdn is the shutdown LCD backlight. The brightness count is allocated as follows:
Example of Pulse Count:
(1) linear counting: Although aw9656 is a loop counting chip, it can also work in linear counting mode, but this mode is not in standard working mode, there will be a typical screen flash. You only need to reset it after each preset shutdown. The instance code is as follows:
int Brightness_SetGpio(int gpio_num,int level){ int i; int min_level = 30; //the min value for UI brightness setup int max_level = 255; //the max value for UI brightness setup int min_bri = 1; //the min value for adjust the brightness int max_bri = 16; //the max value for adjust the brightness kal_uint8 count=0, to_count=0; static int s_bBacklightOn = 1; mt_set_gpio_mode(gpio_num, GPIO_MODE_GPIO); mt_set_gpio_dir(gpio_num, GPIO_DIR_OUT); if (level) { if (level < min_level) { to_count = max_bri; } else if (level > 255) { to_count = min_bri; } else { to_count = max_bri-((level-min_level)*(max_bri-min_bri)/(max_level-min_level)); LEDS_DEBUG("[LED] infact count=%d\n", to_count); } mt_set_gpio_out(gpio_num, GPIO_OUT_ZERO); mdelay(5); //turn off EN PIN mt_set_gpio_out(gpio_num, GPIO_OUT_ONE); udelay(20); //resetting EN PIN to_count--; //to_count not include the first EN pluse for (i=1; i<to_count; i++) { mt_set_gpio_out(gpio_num, GPIO_OUT_ZERO); udelay(2); mt_set_gpio_out(gpio_num, GPIO_OUT_ONE); udelay(2); } } else { mt_set_gpio_out(gpio_num, GPIO_OUT_ZERO); mdelay(5); } return 0;}
(2) accumulate the count (there is a probability of an error)
volatile kal_uint8 g_ledCurrPulseCount = 1;
static int brightness_set_gpio(int gpio_num, enum led_brightness level){int i;int min_level = 30;//the min value for UI brightness setupint max_level = 255;//the max value for UI brightness setupint min_bri = 1;//the min value for adjust the brightnessint max_bri = 16;//the max value for adjust the brightnesskal_uint8 count=0, to_count=0;static int s_bBacklightOn = 1; mt_set_gpio_mode(gpio_num, GPIO_MODE_GPIO);mt_set_gpio_dir(gpio_num, GPIO_DIR_OUT);if (level) {if (level < min_level) {to_count = max_bri;}else if (level > 255) {to_count = min_bri;}else {to_count = max_bri-((level-min_level)*(max_bri-min_bri)/(max_level-min_level));LEDS_DEBUG("[LED] infact count=%d\n", to_count);}if (s_bBacklightOn) {if (g_ledCurrPulseCount > to_count) { //change brightercount = to_count+16-g_ledCurrPulseCount;}else if (g_ledCurrPulseCount < to_count){//change darkercount = to_count-g_ledCurrPulseCount;}else {goto end;}}else {count = to_count;}//count = 16-3*(count-g_ledCurrPulseCount);LEDS_DEBUG("[LED] need more count=%d\n", count);if (s_bBacklightOn) {Eint_Mask();for (i=0; i<count; i++) {mt_set_gpio_out(gpio_num, GPIO_OUT_ZERO);udelay(2);mt_set_gpio_out(gpio_num, GPIO_OUT_ONE);udelay(2); }Eint_Unmask();}else {//first pulse must set high more than 20 usmt_set_gpio_out(gpio_num, GPIO_OUT_ONE);udelay(30);Eint_Mask();for (i=1; i<count; i++) {mt_set_gpio_out(gpio_num, GPIO_OUT_ZERO);udelay(2);mt_set_gpio_out(gpio_num, GPIO_OUT_ONE);udelay(2); }Eint_Unmask();}g_ledCurrPulseCount = to_count;LEDS_DEBUG("[LED]GPIO111#%d:%d:curr count=%d, more count=%d, s_bBacklightOn=%d\n", gpio_num, level, g_ledCurrPulseCount, count, s_bBacklightOn);mdelay(3);s_bBacklightOn = 1;}else {mt_set_gpio_out(gpio_num, GPIO_OUT_ZERO);s_bBacklightOn = 0;mdelay(3);}end:LEDS_DEBUG("[LED]GPIO222#%d:%d:curr count=%d, to count=%d, s_bBacklightOn=%d\n", gpio_num, level, g_ledCurrPulseCount, count, s_bBacklightOn);return 0;}