summaryrefslogtreecommitdiffstats
path: root/keyboards/ergodox/infinity
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2017-04-01 20:28:27 +0200
committerFred Sundvik <fsundvik@gmail.com>2017-04-09 17:34:59 +0200
commit951b6f33a0dc479d29831aaa5c73fc526faf0471 (patch)
tree048f6e396534f575d049ad0226b89577b7b1688b /keyboards/ergodox/infinity
parentf113f95440f8cd7377930868656caf515dbd609c (diff)
downloadqmk_firmware-951b6f33a0dc479d29831aaa5c73fc526faf0471.tar.gz
qmk_firmware-951b6f33a0dc479d29831aaa5c73fc526faf0471.tar.xz
CIE 1931 for the LCD backlight
Diffstat (limited to 'keyboards/ergodox/infinity')
-rw-r--r--keyboards/ergodox/infinity/infinity.c29
-rw-r--r--keyboards/ergodox/infinity/visualizer.c6
2 files changed, 29 insertions, 6 deletions
diff --git a/keyboards/ergodox/infinity/infinity.c b/keyboards/ergodox/infinity/infinity.c
index 02db67eaf..ecc072abb 100644
--- a/keyboards/ergodox/infinity/infinity.c
+++ b/keyboards/ergodox/infinity/infinity.c
@@ -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))
diff --git a/keyboards/ergodox/infinity/visualizer.c b/keyboards/ergodox/infinity/visualizer.c
index c8fc3d78e..12336fdc5 100644
--- a/keyboards/ergodox/infinity/visualizer.c
+++ b/keyboards/ergodox/infinity/visualizer.c
@@ -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);