Skip to content

Commit

Permalink
[Keyboard] Updates to ZSA boards (qmk#6513)
Browse files Browse the repository at this point in the history
* Update Layer functions to use layer_state_t in ZSA Boards

* Update Music Mask for ZSA boards

Fixes an issue with the board getting stuck on Adjust layer when activating music mode

* Add Support for SMART LED Toggle to Planck EZ

* Add support for SMART LED toggle in Ergodox EZ

* Ifdef swiss cheeze for Oryx Configurator

* Documentation and updates

* Add Oryx Keymap

* Add option to configure the layers for the Layer Indicator

* Update keymap with better examples

* Make sure eeprom is initialized before reading from it

* Force flush of LED matrix when suspending board

This fixes an issue where the LEDs don't fully clear sometimes when the host system goes to sleep

* Enable RGB Sleeping by default

* Add clarification about planck ez led layer config
  • Loading branch information
drashna committed Aug 22, 2019
1 parent 1c5b0cb commit 94efa18
Show file tree
Hide file tree
Showing 12 changed files with 629 additions and 11 deletions.
4 changes: 4 additions & 0 deletions keyboards/ergodox_ez/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#define RGBW 1

#define RGBLIGHT_SLEEP

/*
* The debounce filtering reports a key/switch change directly,
* without any extra delay. After that the debounce logic will filter
Expand Down Expand Up @@ -112,6 +114,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define RGB_MATRIX_LED_PROCESS_LIMIT 5
#define RGB_MATRIX_LED_FLUSH_LIMIT 26

#define RGB_DISABLE_WHEN_USB_SUSPENDED true

// #define RGBLIGHT_COLOR_LAYER_0 0x00, 0x00, 0xFF
/* #define RGBLIGHT_COLOR_LAYER_1 0x00, 0x00, 0xFF */
/* #define RGBLIGHT_COLOR_LAYER_2 0xFF, 0x00, 0x00 */
Expand Down
74 changes: 74 additions & 0 deletions keyboards/ergodox_ez/ergodox_ez.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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 +45,16 @@ 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 );
#ifdef RGB_MATRIX_ENABLE
if (keyboard_config.rgb_matrix_enable) {
rgb_matrix_set_flags(LED_FLAG_ALL);
} else {
rgb_matrix_set_flags(LED_FLAG_NONE);
}
#endif

ergodox_blink_all_leds();

matrix_init_user();
Expand Down Expand Up @@ -305,6 +317,7 @@ led_config_t g_led_config = { {
} };

void suspend_power_down_kb(void) {
rgb_matrix_set_color_all(0, 0, 0);
rgb_matrix_set_suspend_state(true);
suspend_power_down_user();
}
Expand All @@ -314,4 +327,65 @@ void suspend_power_down_kb(void) {
suspend_wakeup_init_user();
}

#ifdef ORYX_CONFIGURATOR
void keyboard_post_init_kb(void) {
rgb_matrix_enable_noeeprom();
keyboard_post_init_user();
}
#endif
#endif

#ifdef ORYX_CONFIGURATOR
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;
#ifdef RGB_MATRIX_ENABLE
case TOGGLE_LAYER_COLOR:
if (record->event.pressed) {
keyboard_config.disable_layer_led ^= 1;
if (keyboard_config.disable_layer_led)
rgb_matrix_set_color_all(0, 0, 0);
eeconfig_update_kb(keyboard_config.raw);
}
break;
case RGB_TOG:
if (record->event.pressed) {
switch (rgb_matrix_get_flags()) {
case LED_FLAG_ALL: {
rgb_matrix_set_flags(LED_FLAG_NONE);
keyboard_config.rgb_matrix_enable = false;
rgb_matrix_set_color_all(0, 0, 0);
}
break;
default: {
rgb_matrix_set_flags(LED_FLAG_ALL);
keyboard_config.rgb_matrix_enable = true;
}
break;
}
eeconfig_update_kb(keyboard_config.raw);
}
return false;
#endif
}
return process_record_user(keycode, record);
}
#endif

void eeconfig_init_kb(void) { // EEPROM is getting reset!
keyboard_config.raw = 0;
keyboard_config.led_level = 4;
keyboard_config.rgb_matrix_enable = true;
eeconfig_update_kb(keyboard_config.raw);
eeconfig_init_user();
}
19 changes: 19 additions & 0 deletions keyboards/ergodox_ez/ergodox_ez.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,25 @@ inline void ergodox_led_all_set(uint8_t n)
ergodox_right_led_3_set(n);
}

#ifdef ORYX_CONFIGURATOR
enum ergodox_ez_keycodes {
LED_LEVEL = SAFE_RANGE,
TOGGLE_LAYER_COLOR,
EZ_SAFE_RANGE,
};
#endif

typedef union {
uint32_t raw;
struct {
uint8_t led_level :3;
bool disable_layer_led :1;
bool rgb_matrix_enable :1;
};
} keyboard_config_t;

extern keyboard_config_t keyboard_config;

/*
* LEFT HAND: LINES 115-122
* RIGHT HAND: LINES 124-131
Expand Down
6 changes: 5 additions & 1 deletion keyboards/ergodox_ez/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#define MDIA 2 // media keys

enum custom_keycodes {
#ifdef ORYX_CONFIGURATOR
EPRM = EZ_SAFE_RANGE,
#else
EPRM = SAFE_RANGE,
#endif
VRSN,
RGB_SLD
};
Expand Down Expand Up @@ -164,7 +168,7 @@ void matrix_init_user(void) {
};

// Runs whenever there is a layer state change.
uint32_t layer_state_set_user(uint32_t state) {
layer_state_t layer_state_set_user(layer_state_t state) {
ergodox_board_led_off();
ergodox_right_led_1_off();
ergodox_right_led_2_off();
Expand Down
1 change: 1 addition & 0 deletions keyboards/planck/ez/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@

#define RGB_MATRIX_KEYPRESSES
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
#define RGB_DISABLE_WHEN_USB_SUSPENDED true

#define RGB_MATRIX_LED_PROCESS_LIMIT 5
#define RGB_MATRIX_LED_FLUSH_LIMIT 26
Expand Down
94 changes: 86 additions & 8 deletions keyboards/planck/ez/ez.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "ez.h"
#include "ch.h"
#include "hal.h"
keyboard_config_t keyboard_config;

keyboard_config_t keyboard_config;

#ifdef RGB_MATRIX_ENABLE
const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
Expand Down Expand Up @@ -106,6 +106,7 @@ led_config_t g_led_config = { {
} };

void suspend_power_down_kb(void) {
rgb_matrix_set_color_all(0, 0, 0);
rgb_matrix_set_suspend_state(true);
suspend_power_down_user();
}
Expand Down Expand Up @@ -207,33 +208,65 @@ void led_initialize_hardware(void) {
}

void keyboard_pre_init_kb(void) {
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
// read kb settings from eeprom
keyboard_config.raw = eeconfig_read_kb();

// initialize settings for front LEDs
#if defined(RGB_MATRIX_ENABLE) && defined(ORYX_CONFIGURATOR)
if (keyboard_config.rgb_matrix_enable) {
rgb_matrix_set_flags(LED_FLAG_ALL);
} else {
rgb_matrix_set_flags(LED_FLAG_NONE);
}
#endif
led_initialize_hardware();
keyboard_pre_init_user();
}

#if defined(RGB_MATRIX_ENABLE) && defined(ORYX_CONFIGURATOR)
void keyboard_post_init_kb(void) {
rgb_matrix_enable_noeeprom();
keyboard_post_init_user();
}
#endif

void eeconfig_init_kb(void) { // EEPROM is getting reset!
keyboard_config.raw = 0;
keyboard_config.rgb_matrix_enable = true;
keyboard_config.led_level = 4;
eeconfig_update_kb(keyboard_config.raw);
eeconfig_init_user();
}


#ifdef ORYX_CONFIGURATOR

#ifndef PLANCK_EZ_USER_LEDS

#ifndef PLANCK_EZ_LED_LOWER
# define PLANCK_EZ_LED_LOWER 3
#endif
#ifndef PLANCK_EZ_LED_RAISE
# define PLANCK_EZ_LED_RAISE 4
#endif
#ifndef PLANCK_EZ_LED_ADJUST
# define PLANCK_EZ_LED_ADJUST 6
#endif

layer_state_t layer_state_set_kb(layer_state_t state) {
planck_ez_left_led_off();
planck_ez_right_led_off();
state = layer_state_set_user(state);
uint8_t layer = biton32(state);
switch (layer) {
case 3:
case PLANCK_EZ_LED_LOWER:
planck_ez_left_led_on();
break;
case 4:
case PLANCK_EZ_LED_RAISE:
planck_ez_right_led_on();
break;
case 6:
case PLANCK_EZ_LED_ADJUST:
planck_ez_right_led_on();
planck_ez_left_led_on();
break;
Expand All @@ -242,7 +275,7 @@ layer_state_t layer_state_set_kb(layer_state_t state) {
}
return state;
}

#endif

bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
Expand All @@ -258,6 +291,51 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
layer_state_set_kb(layer_state);
}
break;
#ifdef RGB_MATRIX_ENABLE
case TOGGLE_LAYER_COLOR:
if (record->event.pressed) {
keyboard_config.disable_layer_led ^= 1;
if (keyboard_config.disable_layer_led)
rgb_matrix_set_color_all(0, 0, 0);
eeconfig_update_kb(keyboard_config.raw);
}
break;
case RGB_TOG:
if (record->event.pressed) {
switch (rgb_matrix_get_flags()) {
case LED_FLAG_ALL: {
rgb_matrix_set_flags(LED_FLAG_NONE);
keyboard_config.rgb_matrix_enable = false;
rgb_matrix_set_color_all(0, 0, 0);
}
break;
default: {
rgb_matrix_set_flags(LED_FLAG_ALL);
keyboard_config.rgb_matrix_enable = true;
}
break;
}
eeconfig_update_kb(keyboard_config.raw);
}
return false;
#endif
}
return true;
return process_record_user(keycode, record);
}
#endif

#ifdef AUDIO_ENABLE
bool music_mask_kb(uint16_t keycode) {
switch (keycode) {
case QK_LAYER_TAP ... QK_ONE_SHOT_LAYER_MAX:
case QK_LAYER_TAP_TOGGLE ... QK_LAYER_MOD_MAX:
case QK_MOD_TAP ... QK_MOD_TAP_MAX:
case AU_ON ... MUV_DE:
case RESET:
case EEP_RST:
return false;
default:
return music_mask_user(keycode);
}
}
#endif
5 changes: 4 additions & 1 deletion keyboards/planck/ez/ez.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ void planck_ez_left_led_level(uint8_t level);

enum planck_ez_keycodes {
LED_LEVEL = SAFE_RANGE,
TOGGLE_LAYER_COLOR,
EZ_SAFE_RANGE,
};

typedef union {
uint32_t raw;
struct {
uint8_t led_level :3;
uint8_t led_level :3;
bool disable_layer_led :1;
bool rgb_matrix_enable :1;
};
} keyboard_config_t;

Expand Down
41 changes: 41 additions & 0 deletions keyboards/planck/ez/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,44 @@ Make example for this keyboard (after setting up your build environment):
make planck/ez:default

See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).

## Planck EZ Configuration (from Oryx)

### Indicator LEDs

The two front "teeth" LED indicators are PWM controlled. If you have `ORYX_CONFIGURATOR` defined in your keymap's `config.h`, you can use the `LED_LEVEL` to cycle through preset vales (0, 25%, 50%, 75%, 100%), and will be saved to EEPROM (persistent storage)

Alternatively, you can set the brightness by calling the following functions:

```c
void planck_ez_right_led_level(uint8_t level);
void planck_ez_left_led_level(uint8_t level);
```
These settings are not persistent, so you'd need to reset it every time the board starts.
These are on a 0-255 scale
#### Layer indication
By default, the indicator lights are used for layer indication, expecting the specific layers used in the default keymap. However, this may not work for you. And if that is the case, you can add `#define PLANCK_EZ_USER_LEDS` to your `config.h` file.
This will remove the default behavior for changing the LEDs based on layer, and allow you to control them manually.
Alternatively, you can use the following defines in your keymap's `config.h` to control which layers are used, as long as you have `ORYX_CONFIGURATOR` defined in your keymap's `config.h` file, as well.
```c
#define PLANCK_EZ_LED_LOWER 3
#define PLANCK_EZ_LED_RAISE 4
#define PLANCK_EZ_LED_ADJUST 6
```

This will allow you to change the layers that are used, without having to add anything code to your `keymap.c`

### RGB Matrix Features

If you're using the Smart LED (layer indication) feature from the Oryx Configurator, you want to make sure that you enable these options by adding `#define ORYX_CONFIGURATOR` to your keymap's `config.h`.

This changes the `RGB_TOG` keycode so that it will toggle the lights on and off, in a way that will allow the Smart LEDs to continue to work, even with the rest of the LEDs turned off.

Additionally, a new keycode has been added to toggle the Smart LEDs. Use `TOGGLE_LAYER_COLOR`, if you aren't already.
2 changes: 1 addition & 1 deletion keyboards/planck/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
#endif

uint32_t layer_state_set_user(uint32_t state) {
layer_state_t layer_state_set_user(layer_state_t state) {
return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
}

Expand Down
Loading

0 comments on commit 94efa18

Please sign in to comment.