CIE 1931 for the LCD backlight
This commit is contained in:
parent
f113f95440
commit
951b6f33a0
2 changed files with 29 additions and 6 deletions
|
@ -70,10 +70,33 @@ void lcd_backlight_hal_init(void) {
|
|||
RGB_PORT->PCR[BLUE_PIN] = RGB_MODE;
|
||||
}
|
||||
|
||||
static uint16_t cie_lightness(uint16_t v) {
|
||||
// The CIE 1931 formula for lightness
|
||||
// Y = luminance (output) 0-1
|
||||
// L = lightness input 0 - 100
|
||||
|
||||
// Y = (L* / 902.3) if L* <= 8
|
||||
// Y = ((L* + 16) / 116)^3 if L* > 8
|
||||
|
||||
float l = 100.0f * (v / 65535.0f);
|
||||
float y = 0.0f;
|
||||
if (l <= 8.0f) {
|
||||
y = l / 902.3;
|
||||
}
|
||||
else {
|
||||
y = ((l + 16.0f) / 116.0f);
|
||||
y = y * y * y;
|
||||
if (y > 1.0f) {
|
||||
y = 1.0f;
|
||||
}
|
||||
}
|
||||
return y * 65535.0f;
|
||||
}
|
||||
|
||||
void lcd_backlight_hal_color(uint16_t r, uint16_t g, uint16_t b) {
|
||||
CHANNEL_RED.CnV = r;
|
||||
CHANNEL_GREEN.CnV = g;
|
||||
CHANNEL_BLUE.CnV = b;
|
||||
CHANNEL_RED.CnV = cie_lightness(r);
|
||||
CHANNEL_GREEN.CnV = cie_lightness(g);
|
||||
CHANNEL_BLUE.CnV = cie_lightness(b);
|
||||
}
|
||||
|
||||
__attribute__ ((weak))
|
||||
|
|
|
@ -70,8 +70,8 @@ static const uint8_t image_data_lcd_logo[512] = {
|
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0x80);
|
||||
static const uint32_t initial_color = LCD_COLOR(0, 0, 0xFF);
|
||||
static const uint32_t logo_background_color = LCD_COLOR(0x00, 0x00, 0xFF);
|
||||
static const uint32_t initial_color = LCD_COLOR(0, 0, 0);
|
||||
|
||||
bool display_logo(keyframe_animation_t* animation, visualizer_state_t* state) {
|
||||
(void)state;
|
||||
|
@ -155,7 +155,7 @@ static keyframe_animation_t resume_animation = {
|
|||
void initialize_user_visualizer(visualizer_state_t* state) {
|
||||
// The brightness will be dynamically adjustable in the future
|
||||
// But for now, change it here.
|
||||
lcd_backlight_brightness(0x50);
|
||||
lcd_backlight_brightness(130);
|
||||
state->current_lcd_color = initial_color;
|
||||
state->target_lcd_color = logo_background_color;
|
||||
start_keyframe_animation(&startup_animation);
|
||||
|
|
Loading…
Reference in a new issue