| #include "led.h" |
| #include "i2c_led_driver.h" |
| |
| #define LED_NUM 1 |
| #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| |
| LED leds_lp5018[LED_NUM] = { |
| { |
| false, |
| 1, |
| 0x29, |
| LED_DRIVER_TYPE_LP5018, |
| } |
| }; |
| |
| LED leds_aw210xx[LED_NUM] = { |
| { |
| false, |
| 1, |
| 0x21, |
| LED_DRIVER_TYPE_AW210XX, |
| } |
| }; |
| |
| static int leds_inited = 0; |
| |
| static void init_leds(int led_driver_type) { |
| int ret = -1; |
| |
| if (0 == leds_inited) { |
| if (led_driver_type == LED_DRIVER_TYPE_LP5018) { |
| ret = i2c_led_init(leds_lp5018, LED_NUM); |
| } else if (led_driver_type == LED_DRIVER_TYPE_AW210XX) { |
| ret = i2c_led_init(leds_aw210xx, LED_NUM); |
| } |
| |
| if (ret == 0) { |
| leds_inited = 1; |
| } |
| } |
| |
| return; |
| } |
| |
| extern int lgpl_printf(const char *format, ...); |
| |
| #ifdef LOAD_LED_CAL_DATA |
| /* frame table is 8 (brightness) + 8 * 3 (b/r/g) */ |
| /* i2c 0/1/2/3 maps to LED 3/2/1/0 */ |
| #define LUT_SET_COLOR(frame, index, c_index) do { \ |
| lgpl_printf("LUT table LED %d\n", index); \ |
| frame[index] = lut.led[index].color[c_index].brightness; \ |
| frame[8 + 3 * (3 - index) ] = lut.led[index].color[c_index].b; \ |
| frame[8 + 3 * (3 - index) + 1] = lut.led[index].color[c_index].r; \ |
| frame[8 + 3 * (3 - index) + 2] = lut.led[index].color[c_index].g; \ |
| } while(0) |
| #endif |
| |
| void detect_led_driver(int *led_driver_type) { |
| if (i2c_led_detect_driver(leds_lp5018, LED_NUM, led_driver_type) == 0) { |
| lgpl_printf("Detected LP5018 LED Driver\n"); |
| } else if (i2c_led_detect_driver(leds_aw210xx, LED_NUM, led_driver_type) == 0) { |
| lgpl_printf("Detected AW21018 LED Driver\n"); |
| } else { |
| lgpl_printf("Failed to detect LED Driver\n"); |
| *led_driver_type = LED_DRIVER_TYPE_UNKNOWN; |
| } |
| } |
| |
| void cold_boot_show_led_init_boot(int led_driver_type) { |
| init_leds(led_driver_type); |
| if (!leds_inited) |
| return; |
| |
| unsigned char led_frame_29[32] = { |
| 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 0x00, 0x00, 0x00, 0x9A, 0x9A, 0x9A, |
| 0x9A, 0x9A, 0x9A, 0x00, 0x00, 0x00, |
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| }; |
| |
| #ifdef LOAD_LED_CAL_DATA |
| if (lut.validated) { |
| LUT_SET_COLOR(led_frame_29, 1, LED_COLOR_INDEX_WHITE); |
| LUT_SET_COLOR(led_frame_29, 2, LED_COLOR_INDEX_WHITE); |
| } |
| #endif |
| |
| i2c_led_show_frame(0, led_frame_29, ARRAY_SIZE(led_frame_29)); |
| } |
| |
| void cold_boot_show_led_done_boot() { |
| // See go/vento-schematics for led channel mapping |
| unsigned char led_frame_29[32] = { |
| 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, |
| 0x9A, 0x9A, 0x9A, 0x9A, 0x9A, 0x9A, |
| 0x9A, 0x9A, 0x9A, 0x9A, 0x9A, 0x9A, |
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| }; |
| |
| if (!leds_inited) |
| return; |
| |
| #ifdef LOAD_LED_CAL_DATA |
| if (lut.validated) { |
| LUT_SET_COLOR(led_frame_29, 0, LED_COLOR_INDEX_WHITE); |
| LUT_SET_COLOR(led_frame_29, 1, LED_COLOR_INDEX_WHITE); |
| LUT_SET_COLOR(led_frame_29, 2, LED_COLOR_INDEX_WHITE); |
| LUT_SET_COLOR(led_frame_29, 3, LED_COLOR_INDEX_WHITE); |
| } |
| #endif |
| |
| i2c_led_show_frame(0, led_frame_29, ARRAY_SIZE(led_frame_29)); |
| } |
| |