Skip to content

Commit

Permalink
Enable LED Light level control for Ergodox EZ
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna authored and fdidron committed Aug 5, 2019
1 parent d2100ba commit 927969d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
29 changes: 29 additions & 0 deletions keyboards/ergodox_ez/ergodox_ez.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
14 changes: 14 additions & 0 deletions keyboards/ergodox_ez/ergodox_ez.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 927969d

Please sign in to comment.