diff options
author | Drashna Jael're <drashna@live.com> | 2019-08-04 09:33:44 -0700 |
---|---|---|
committer | Florian Didron <fdidron@users.noreply.github.com> | 2019-08-05 09:36:54 +0900 |
commit | 927969d6cb09daa969faebec69998186b883c140 (patch) | |
tree | 0b2cf2ea85bbc4ae7a3e9b1ebc107f5b9ca63614 /keyboards/ergodox_ez | |
parent | d2100ba45d0c0bf5258dcab2f503aa350f423120 (diff) |
Enable LED Light level control for Ergodox EZ
Diffstat (limited to 'keyboards/ergodox_ez')
-rw-r--r-- | keyboards/ergodox_ez/ergodox_ez.c | 29 | ||||
-rw-r--r-- | keyboards/ergodox_ez/ergodox_ez.h | 14 |
2 files changed, 43 insertions, 0 deletions
diff --git a/keyboards/ergodox_ez/ergodox_ez.c b/keyboards/ergodox_ez/ergodox_ez.c index 951278517a..12b3419ecf 100644 --- a/keyboards/ergodox_ez/ergodox_ez.c +++ b/keyboards/ergodox_ez/ergodox_ez.c @@ -22,6 +22,7 @@ extern inline void ergodox_right_led_set(uint8_t led, uint8_t n); extern inline void ergodox_led_all_set(uint8_t n); +keyboard_config_t keyboard_config; bool i2c_initialized = 0; i2c_status_t mcp23018_status = 0x20; @@ -43,6 +44,9 @@ void matrix_init_kb(void) { PORTD |= (1<<5 | 1<<4); PORTE |= (1<<6); + keyboard_config.raw = eeconfig_read_kb(); + ergodox_led_all_set((uint8_t)keyboard_config.led_level * 255 / 4 ); + ergodox_blink_all_leds(); matrix_init_user(); @@ -316,3 +320,28 @@ led_config_t g_led_config = { { } }; #endif + + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { + case LED_LEVEL: + if (record->event.pressed) { + keyboard_config.led_level++; + if (keyboard_config.led_level > 4) { + keyboard_config.led_level = 0; + } + ergodox_led_all_set((uint8_t)keyboard_config.led_level * 255 / 4 ); + eeconfig_update_kb(keyboard_config.raw); + layer_state_set_kb(layer_state); + } + break; + } + return process_record_user(keycode, record); +} + +void eeconfig_init_kb(void) { // EEPROM is getting reset! + keyboard_config.raw = 0; + keyboard_config.led_level = 4; + eeconfig_update_kb(keyboard_config.raw); + eeconfig_init_user(); +} diff --git a/keyboards/ergodox_ez/ergodox_ez.h b/keyboards/ergodox_ez/ergodox_ez.h index 383702b957..38377fdf87 100644 --- a/keyboards/ergodox_ez/ergodox_ez.h +++ b/keyboards/ergodox_ez/ergodox_ez.h @@ -107,6 +107,20 @@ inline void ergodox_led_all_set(uint8_t n) ergodox_right_led_3_set(n); } +enum ergodox_ez_keycodes { + LED_LEVEL = SAFE_RANGE, + EZ_SAFE_RANGE, +}; + +typedef union { + uint32_t raw; + struct { + uint8_t led_level :3; + }; +} keyboard_config_t; + +extern keyboard_config_t keyboard_config; + /* * LEFT HAND: LINES 115-122 * RIGHT HAND: LINES 124-131 |