From 2a7edbce6f74ce396ba85164c3ff148d075df43c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 13 Dec 2016 20:32:54 +0100 Subject: [PATCH 1/2] Light up LEDs on the display when switching layers When switching layers, light up the appropriate LED on the display. For this purpose, start led_display.[ch], which as a start, has a function to set the brightness of a layer led. The function will also turn all other LEDs off, and turn all of them off when on the base layer. Signed-off-by: Gergely Nagy --- right/src/keyboard_layout.c | 3 ++- right/src/led_display.c | 11 +++++++++++ right/src/led_display.h | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 right/src/led_display.c create mode 100644 right/src/led_display.h diff --git a/right/src/keyboard_layout.c b/right/src/keyboard_layout.c index 5a459a9..75bf2d7 100644 --- a/right/src/keyboard_layout.c +++ b/right/src/keyboard_layout.c @@ -1,5 +1,5 @@ #include "keyboard_layout.h" -#include "led_driver.h" +#include "led_display.h" #include "layer.h" static uint8_t keyMasks[SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE]; @@ -82,6 +82,7 @@ bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, co if (key_toggled_off(prevKeyStates, currKeyStates, keyId)) { ActiveLayer = LAYER_ID_BASE; } + LedDisplay_SetLayerLed(ActiveLayer, 0xff); return false; break; default: diff --git a/right/src/led_display.c b/right/src/led_display.c new file mode 100644 index 0000000..bef0e78 --- /dev/null +++ b/right/src/led_display.c @@ -0,0 +1,11 @@ +#include "led_display.h" +#include "layer.h" + +#define LAYER_LED_FIRST FRAME_REGISTER_PWM_FIRST + 13 +#define LAYER_LED_DISTANCE 16 + +void LedDisplay_SetLayerLed(uint8_t layerId, uint8_t brightness) { + for (uint8_t i = 0; i < LAYER_COUNT; i++) { + LedDriver_WriteRegister(I2C_ADDRESS_LED_DRIVER_LEFT, LAYER_LED_FIRST + (i * LAYER_LED_DISTANCE), brightness * (layerId == i + 1)); + } +} diff --git a/right/src/led_display.h b/right/src/led_display.h new file mode 100644 index 0000000..37fb7b7 --- /dev/null +++ b/right/src/led_display.h @@ -0,0 +1,8 @@ +#ifndef __LED_DISPLAY_H__ +#define __LED_DISPLAY_H__ + + #include "led_driver.h" + + void LedDisplay_SetLayerLed(uint8_t layerId, uint8_t brightness); + +#endif From a59dcd1662e699192577165bc1383ecad59de6c0 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 13 Dec 2016 23:23:16 +0100 Subject: [PATCH 2/2] Lift out the LED brightness into a global Instead of passing the same constant to LedDisplay_SetLayerLed() all the time, lift it out into a global. Signed-off-by: Gergely Nagy --- right/src/keyboard_layout.c | 2 +- right/src/led_display.c | 6 ++++-- right/src/led_display.h | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/right/src/keyboard_layout.c b/right/src/keyboard_layout.c index 75bf2d7..4cabe19 100644 --- a/right/src/keyboard_layout.c +++ b/right/src/keyboard_layout.c @@ -82,7 +82,7 @@ bool handleKey(uhk_key_t key, int scancodeIdx, usb_keyboard_report_t *report, co if (key_toggled_off(prevKeyStates, currKeyStates, keyId)) { ActiveLayer = LAYER_ID_BASE; } - LedDisplay_SetLayerLed(ActiveLayer, 0xff); + LedDisplay_SetLayerLed(ActiveLayer); return false; break; default: diff --git a/right/src/led_display.c b/right/src/led_display.c index bef0e78..176b6ca 100644 --- a/right/src/led_display.c +++ b/right/src/led_display.c @@ -4,8 +4,10 @@ #define LAYER_LED_FIRST FRAME_REGISTER_PWM_FIRST + 13 #define LAYER_LED_DISTANCE 16 -void LedDisplay_SetLayerLed(uint8_t layerId, uint8_t brightness) { +uint8_t LedDisplayBrightness = 0xff; + +void LedDisplay_SetLayerLed(uint8_t layerId) { for (uint8_t i = 0; i < LAYER_COUNT; i++) { - LedDriver_WriteRegister(I2C_ADDRESS_LED_DRIVER_LEFT, LAYER_LED_FIRST + (i * LAYER_LED_DISTANCE), brightness * (layerId == i + 1)); + LedDriver_WriteRegister(I2C_ADDRESS_LED_DRIVER_LEFT, LAYER_LED_FIRST + (i * LAYER_LED_DISTANCE), LedDisplayBrightness * (layerId == i + 1)); } } diff --git a/right/src/led_display.h b/right/src/led_display.h index 37fb7b7..c2434bb 100644 --- a/right/src/led_display.h +++ b/right/src/led_display.h @@ -3,6 +3,8 @@ #include "led_driver.h" - void LedDisplay_SetLayerLed(uint8_t layerId, uint8_t brightness); + extern uint8_t LedDisplayBrightness; + + void LedDisplay_SetLayerLed(uint8_t layerId); #endif