]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
CIE 1931 for the LCD backlight
authorFred Sundvik <fsundvik@gmail.com>
Sat, 1 Apr 2017 18:28:27 +0000 (21:28 +0300)
committerFred Sundvik <fsundvik@gmail.com>
Sun, 9 Apr 2017 15:34:59 +0000 (18:34 +0300)
keyboards/ergodox/infinity/infinity.c
keyboards/ergodox/infinity/visualizer.c

index 02db67eaf263c8dfe4eb00a95a86d791de1c1da8..ecc072abbe5177a0bebec887a31e0b950a297ecc 100644 (file)
@@ -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))
index c8fc3d78efbc790b749b2805defab7fd09e9d275..12336fdc57a853f1c80c60779fa41a2bcc6fd734 100644 (file)
@@ -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);