diff --git a/keyboards/zsa/ergodox_ez/config.h b/keyboards/zsa/ergodox_ez/config.h new file mode 100644 index 000000000000..b8f20e74a007 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/config.h @@ -0,0 +1,186 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +/* key matrix size */ +#define MATRIX_ROWS_PER_SIDE (MATRIX_ROWS / 2) + +#define ROWS_EXPANDED \ + { true, true, true, true, true, true, true, false, false, false, false, false, false, false } +#define DIODE_DIRECTION COL2ROW +#define EXPANDER_COL_REGISTER MCP23018_GPIOB +#define EXPANDER_ROW_REGISTER MCP23018_GPIOA +#define MATRIX_EXPANDER_COL_PINS \ + { 5, 4, 3, 2, 1, 0 } +#define MATRIX_EXPANDER_ROW_PINS \ + { 0, 1, 2, 3, 4, 5, 6 } + +#define MOUSEKEY_INTERVAL 20 +#define MOUSEKEY_DELAY 0 +#define MOUSEKEY_TIME_TO_MAX 60 +#define MOUSEKEY_MAX_SPEED 7 +#define MOUSEKEY_WHEEL_DELAY 400 +#define MOUSEKEY_WHEEL_INTERVAL MOUSEKEY_INTERVAL +#define MOUSEKEY_WHEEL_MAX_SPEED MOUSEKEY_MAX_SPEED +#define MOUSEKEY_WHEEL_TIME_TO_MAX MOUSEKEY_TIME_TO_MAX + +#define TAPPING_TOGGLE 1 + +#define BOOTMAGIC_LITE_ROW_RIGHT 13 +#define BOOTMAGIC_LITE_COLUMN_RIGHT 0 + +/* key combination for command */ +#define IS_COMMAND() (get_mods() == (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL)) || get_mods() == (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT))) + +#ifndef LED_BRIGHTNESS_LO +# define LED_BRIGHTNESS_LO 15 +#endif +#ifndef LED_BRIGHTNESS_HI +# define LED_BRIGHTNESS_HI 255 +#endif +#define LED_BRIGHTNESS_DEFAULT (LED_BRIGHTNESS_HI) + +// Pick one of the modes +// Defaults to 15 mirror, for legacy behavior + +// #define ERGODOX_LED_15 // Addresses 15 LEDs, but same position on both halves +// #define ERGODOX_LED_15_MIRROR // Addresses 15 LEDs, but are mirrored +// #define ERGODOX_LED_30 // Addresses all 30 LED individually + +/* fix space cadet rollover issue */ +#define DISABLE_SPACE_CADET_ROLLOVER + +/* + * The debounce filtering reports a key/switch change directly, + * without any extra delay. After that the debounce logic will filter + * all further changes, until the key/switch reports the same state for + * the given count of scans. + * So a perfect switch will get a short debounce period and + * a bad key will get a much longer debounce period. + * The result is an adaptive debouncing period for each switch. + * + * If you don't define it here, the matrix code will default to + * 5, which is now closer to 10ms, but still plenty according to + * manufacturer specs. + */ + +// RGB backlight +#define DRIVER_ADDR_1 0b1110100 +#define DRIVER_ADDR_2 0b1110111 +#define DRIVER_COUNT 2 +#define DRIVER_1_LED_TOTAL 24 +#define DRIVER_2_LED_TOTAL 24 +#define RGB_MATRIX_LED_COUNT (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) + +#define RGB_MATRIX_LED_PROCESS_LIMIT 5 +#define RGB_MATRIX_LED_FLUSH_LIMIT 26 + +#define RGB_DISABLE_WHEN_USB_SUSPENDED +// RGB Matrix Animation modes. Explicitly enabled +// For full list of effects, see: +// https://docs.qmk.fm/#/feature_rgb_matrix?id=rgb-matrix-effects +#define ENABLE_RGB_MATRIX_ALPHAS_MODS +#define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN +#define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT +#define ENABLE_RGB_MATRIX_BREATHING +#define ENABLE_RGB_MATRIX_BAND_SAT +#define ENABLE_RGB_MATRIX_BAND_VAL +#define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +#define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +#define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT +#define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL +#define ENABLE_RGB_MATRIX_CYCLE_ALL +#define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +#define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN +#define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +#define ENABLE_RGB_MATRIX_CYCLE_OUT_IN +#define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +#define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL +#define ENABLE_RGB_MATRIX_CYCLE_SPIRAL +#define ENABLE_RGB_MATRIX_DUAL_BEACON +#define ENABLE_RGB_MATRIX_RAINBOW_BEACON +#define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS +#define ENABLE_RGB_MATRIX_RAINDROPS +#define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS +#define ENABLE_RGB_MATRIX_HUE_BREATHING +#define ENABLE_RGB_MATRIX_HUE_PENDULUM +#define ENABLE_RGB_MATRIX_HUE_WAVE +#define ENABLE_RGB_MATRIX_PIXEL_RAIN +#define ENABLE_RGB_MATRIX_PIXEL_FLOW +#define ENABLE_RGB_MATRIX_PIXEL_FRACTAL +// enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined +#define ENABLE_RGB_MATRIX_TYPING_HEATMAP +#define ENABLE_RGB_MATRIX_DIGITAL_RAIN +// enabled only of RGB_MATRIX_KEYPRESSES or RGB_MATRIX_KEYRELEASES is defined +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS +#define ENABLE_RGB_MATRIX_SPLASH +#define ENABLE_RGB_MATRIX_MULTISPLASH +#define ENABLE_RGB_MATRIX_SOLID_SPLASH +#define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH + +#define TAPPING_TOGGLE 1 + +// Enable rgb light animations for the shine +#define RGBLIGHT_EFFECT_ALTERNATING +#define RGBLIGHT_EFFECT_BREATHING +#define RGBLIGHT_EFFECT_CHRISTMAS +#define RGBLIGHT_EFFECT_KNIGHT +#define RGBLIGHT_EFFECT_RAINBOW_MOOD +#define RGBLIGHT_EFFECT_RAINBOW_SWIRL +#define RGBLIGHT_EFFECT_RGB_TEST +#define RGBLIGHT_EFFECT_SNAKE +#define RGBLIGHT_EFFECT_STATIC_GRADIENT +#define RGBLIGHT_EFFECT_TWINKLE + +#define RGBLIGHT_DEFAULT_MODE RGBLIGHT_MODE_RAINBOW_SWIRL +// #define RGBLIGHT_COLOR_LAYER_0 0x00, 0x00, 0xFF +/* #define RGBLIGHT_COLOR_LAYER_1 0x00, 0x00, 0xFF */ +/* #define RGBLIGHT_COLOR_LAYER_2 0xFF, 0x00, 0x00 */ +/* #define RGBLIGHT_COLOR_LAYER_3 0x00, 0xFF, 0x00 */ +/* #define RGBLIGHT_COLOR_LAYER_4 0xFF, 0xFF, 0x00 */ +/* #define RGBLIGHT_COLOR_LAYER_5 0x00, 0xFF, 0xFF */ +/* #define RGBLIGHT_COLOR_LAYER_6 0xFF, 0x00, 0xFF */ +/* #define RGBLIGHT_COLOR_LAYER_7 0xFF, 0xFF, 0xFF */ + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +// #define NO_DEBUG + +/* disable print */ +// #define NO_PRINT + +/* disable action features */ +// #define NO_ACTION_LAYER +// #define NO_ACTION_TAPPING +// #define NO_ACTION_ONESHOT + +// #define DEBUG_MATRIX_SCAN_RATE diff --git a/keyboards/zsa/ergodox_ez/ergodox_ez.c b/keyboards/zsa/ergodox_ez/ergodox_ez.c new file mode 100644 index 000000000000..665dd297fd7b --- /dev/null +++ b/keyboards/zsa/ergodox_ez/ergodox_ez.c @@ -0,0 +1,369 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "ergodox_ez.h" +#include "bootmagic.h" + +keyboard_config_t keyboard_config; + +__attribute__((weak)) void keyboard_post_init_sub(void) { + setPinOutput(ERGODOX_LED_1_PIN); + setPinOutput(ERGODOX_LED_2_PIN); + setPinOutput(ERGODOX_LED_3_PIN); +} + +void keyboard_post_init_kb(void) { + keyboard_post_init_sub(); +#ifdef ERGODOX_LED_SHUTOFF_PIN + setPinOutput(ERGODOX_LED_SHUTOFF_PIN); +#endif + + keyboard_config.raw = eeconfig_read_kb(); + ergodox_led_all_set((uint8_t)keyboard_config.led_level * 255 / 4); + ergodox_blink_all_leds(); + + keyboard_post_init_user(); +} + +void ergodox_board_led_on(void) { +#ifdef ERGODOX_LED_SHUTOFF_PIN + writePinHigh(ERGODOX_LED_SHUTOFF_PIN); +#endif +} + +__attribute__((weak)) void ergodox_right_led_1_on(void) { + writePinHigh(ERGODOX_LED_1_PIN); +} + +__attribute__((weak)) void ergodox_right_led_2_on(void) { + writePinHigh(ERGODOX_LED_2_PIN); +} + +__attribute__((weak)) void ergodox_right_led_3_on(void) { + writePinHigh(ERGODOX_LED_3_PIN); +} + +void ergodox_board_led_off(void) { +#ifdef ERGODOX_LED_SHUTOFF_PIN + writePinLow(ERGODOX_LED_SHUTOFF_PIN); +#else + ergodox_right_led_1_off(); + ergodox_right_led_2_off(); + ergodox_right_led_3_off(); +#endif +} + +__attribute__((weak)) void ergodox_right_led_1_off(void) { + setPinInput(ERGODOX_LED_1_PIN); +} + +__attribute__((weak)) void ergodox_right_led_2_off(void) { + setPinInput(ERGODOX_LED_2_PIN); +} + +__attribute__((weak)) void ergodox_right_led_3_off(void) { + setPinInput(ERGODOX_LED_3_PIN); +} + +void ergodox_right_led_on(uint8_t led) { + if (led == 1) { + ergodox_right_led_1_on(); + } else if (led == 2) { + ergodox_right_led_2_on(); + } else if (led == 3) { + ergodox_right_led_3_on(); + } +} + +void ergodox_right_led_off(uint8_t led) { + if (led == 1) { + ergodox_right_led_1_off(); + } else if (led == 2) { + ergodox_right_led_2_off(); + } else if (led == 3) { + ergodox_right_led_3_off(); + } +} + +void ergodox_right_led_set(uint8_t led, uint8_t n) { + if (led == 1) { + ergodox_right_led_1_set(n); + } else if (led == 2) { + ergodox_right_led_2_set(n); + } else if (led == 3) { + ergodox_right_led_3_set(n); + } +} + +void ergodox_led_all_on(void) { + ergodox_board_led_on(); + ergodox_right_led_1_on(); + ergodox_right_led_2_on(); + ergodox_right_led_3_on(); +} + +void ergodox_led_all_off(void) { + ergodox_board_led_off(); + ergodox_right_led_1_off(); + ergodox_right_led_2_off(); + ergodox_right_led_3_off(); +} + +void ergodox_led_all_set(uint8_t n) { + ergodox_right_led_1_set(n); + ergodox_right_led_2_set(n); + ergodox_right_led_3_set(n); +} + +void ergodox_blink_all_leds(void) { + ergodox_led_all_off(); + ergodox_led_all_set(LED_BRIGHTNESS_DEFAULT); + ergodox_right_led_1_on(); + wait_ms(50); + ergodox_right_led_2_on(); + wait_ms(50); + ergodox_right_led_3_on(); + wait_ms(50); + + ergodox_right_led_1_off(); + wait_ms(50); + ergodox_right_led_2_off(); + wait_ms(50); + ergodox_right_led_3_off(); + + // ergodox_led_all_on(); + //_delay_ms(333); + ergodox_led_all_set((uint8_t)keyboard_config.led_level * 255 / 4); + + ergodox_led_all_off(); +} + +#ifdef SWAP_HANDS_ENABLE +__attribute__((weak)) +// swap-hands action needs a matrix to define the swap +const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = { + /* Left hand, matrix positions */ + {{0, 13}, {1, 13}, {2, 13}, {3, 13}, {4, 13}, {5, 13}}, + {{0, 12}, {1, 12}, {2, 12}, {3, 12}, {4, 12}, {5, 12}}, + {{0, 11}, {1, 11}, {2, 11}, {3, 11}, {4, 11}, {5, 11}}, + {{0, 10}, {1, 10}, {2, 10}, {3, 10}, {4, 10}, {5, 10}}, + {{0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 9}, {5, 9}}, + {{0, 8}, {1, 8}, {2, 8}, {3, 8}, {4, 8}, {5, 8}}, + {{0, 7}, {1, 7}, {2, 7}, {3, 7}, {4, 7}, {5, 7}}, + /* Right hand, matrix positions */ + {{0, 6}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6}}, + {{0, 5}, {1, 5}, {2, 5}, {3, 5}, {4, 5}, {5, 5}}, + {{0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4}}, + {{0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3}}, + {{0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2}}, + {{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}}, + {{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}}, +}; +#endif + +#ifdef RGB_MATRIX_ENABLE +// clang-format off +__attribute__((weak)) const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = { +/* driver + * | R location + * | | G location + * | | | B location + * | | | | */ + {0, C2_3, C1_3, C3_3}, // LED1 on right + {0, C2_4, C1_4, C3_4}, // LED2 + {0, C2_5, C1_5, C3_5}, // LED3 + {0, C2_6, C1_6, C3_6}, // LED4 + {0, C2_7, C1_7, C3_7}, // LED5 + {0, C2_8, C1_8, C3_8}, // LED6 + {0, C8_1, C7_1, C9_1}, // LED7 + {0, C8_2, C7_2, C9_2}, // LED8 + {0, C8_3, C7_3, C9_3}, // LED9 + {0, C8_4, C7_4, C9_4}, // LED10 + {0, C8_5, C7_5, C9_5}, // LED11 + {0, C8_6, C7_6, C9_6}, // LED12 + {0, C2_11, C1_11, C3_11}, // LED13 + {0, C2_12, C1_12, C3_12}, // LED14 + {0, C2_13, C1_13, C3_13}, // LED15 + {0, C2_14, C1_14, C3_14}, // LED16 + {0, C2_15, C1_15, C3_15}, // LED17 + {0, C2_16, C1_16, C3_16}, // LED18 + + {0, C8_9, C7_9, C9_9}, // LED19 + {0, C8_10, C7_10, C9_10}, // LED20 + {0, C8_11, C7_11, C9_11}, // LED21 + {0, C8_12, C7_12, C9_12}, // LED22 + {0, C8_13, C7_13, C9_13}, // LED23 + {0, C8_14, C7_14, C9_14}, // LED24 + + {1, C3_1, C2_1, C4_1}, // LED1 on left + {1, C6_1, C5_1, C7_1}, // LED2 + {1, C4_2, C3_2, C5_2}, // LED3 + {1, C7_2, C6_2, C8_2}, // LED4 + {1, C2_3, C1_3, C3_3}, // LED5 + {1, C5_3, C4_3, C6_3}, // LED6 + {1, C8_3, C7_3, C9_3}, // LED7 + {1, C2_4, C1_4, C3_4}, // LED8 + {1, C6_4, C5_4, C7_4}, // LED9 + {1, C2_5, C1_5, C3_5}, // LED10 + {1, C7_5, C6_5, C8_5}, // LED11 + {1, C2_6, C1_6, C3_6}, // LED12 + {1, C5_6, C4_6, C6_6}, // LED13 + {1, C8_6, C7_6, C9_6}, // LED14 + {1, C2_7, C1_7, C3_7}, // LED15 + {1, C5_7, C4_7, C6_7}, // LED16 + {1, C2_8, C1_8, C3_8}, // LED17 + {1, C5_8, C4_8, C6_8}, // LED18 + + {1, C3_9, C2_9, C4_9}, // LED19 + {1, C6_9, C5_9, C7_9}, // LED20 + {1, C4_10, C3_10, C5_10}, // LED21 + {1, C7_10, C6_10, C8_10}, // LED22 + {1, C2_11, C1_11, C3_11}, // LED23 + {1, C5_11, C4_11, C6_11} // LED24 +}; +// clang-format on + +#endif + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { +#ifdef ORYX_CONFIGURATOR + 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); + rgb_matrix_set_color_all(0, 0, 0); + } break; + default: { + rgb_matrix_set_flags(LED_FLAG_ALL); + } break; + } + } + return false; +# endif +#endif + } + 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(); +} + +#ifdef DYNAMIC_MACRO_ENABLE +static bool is_dynamic_recording = false; +static uint16_t dynamic_loop_timer; + +void dynamic_macro_record_start_user(int8_t direction) { + is_dynamic_recording = true; + dynamic_loop_timer = timer_read(); + ergodox_right_led_1_on(); +} + +void dynamic_macro_record_end_user(int8_t direction) { + is_dynamic_recording = false; + layer_state_set_user(layer_state); +} +#endif + +void housekeeping_task_kb(void) { +#ifdef DYNAMIC_MACRO_ENABLE + if (is_dynamic_recording) { + ergodox_right_led_1_off(); + // if (timer_elapsed(dynamic_loop_timer) > 5) + { + static uint8_t counter; + counter++; + if (counter > 100) ergodox_right_led_1_on(); + dynamic_loop_timer = timer_read(); + } + } +#endif + +#ifdef CAPS_LOCK_STATUS + led_t led_state = host_keyboard_led_state(); + if (led_state.caps_lock) { + ergodox_right_led_3_on(); + } else { + uint8_t layer = get_highest_layer(layer_state); + if (layer != 3) { + ergodox_right_led_3_off(); + } + } +#endif +} + +#ifdef BOOTMAGIC_LITE +__attribute__((weak)) void bootmagic_lite(void) { + // We need multiple scans because debouncing can't be turned off. + matrix_scan(); +# if defined(DEBOUNCE) && DEBOUNCE > 0 + wait_ms(DEBOUNCE * 2); +# else + wait_ms(30); +# endif + matrix_scan(); + + // If the configured key (commonly Esc) is held down on power up, + // reset the EEPROM valid state and jump to bootloader. + // This isn't very generalized, but we need something that doesn't + // rely on user's keymaps in firmware or EEPROM. + uint8_t row_left = BOOTMAGIC_LITE_ROW; + uint8_t col_left = BOOTMAGIC_LITE_COLUMN; + +# if defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT) + uint8_t row_right = BOOTMAGIC_LITE_ROW_RIGHT; + uint8_t col_right = BOOTMAGIC_LITE_COLUMN_RIGHT; +# endif + + if (matrix_get_row(row_left) & (1 << col_left) || matrix_get_row(row_right) & (1 << col_right)) { + void bootmagic_lite_reset_eeprom(void); + bootmagic_lite_reset_eeprom(); + + // Jump to bootloader. + reset_keyboard(); + } +} +#endif + +void rgb_matrix_update_pwm_buffers(void); diff --git a/keyboards/zsa/ergodox_ez/ergodox_ez.h b/keyboards/zsa/ergodox_ez/ergodox_ez.h new file mode 100644 index 000000000000..cb6d0466c6c9 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/ergodox_ez.h @@ -0,0 +1,85 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#include "quantum.h" +#include +#include +#include "i2c_master.h" + +extern i2c_status_t mcp23018_status; + +#ifndef ERGODOX_EZ_I2C_TIMEOUT +# define ERGODOX_EZ_I2C_TIMEOUT 80 +#endif +#ifndef MCP23018_EXPANDER_I2C_ADDR +# define MCP23018_EXPANDER_I2C_ADDR (0x20 << 1) +#endif + +uint8_t init_mcp23018(void); +void ergodox_blink_all_leds(void); +bool is_transport_connected(void); + +void ergodox_board_led_on(void); +void ergodox_right_led_1_on(void); +void ergodox_right_led_2_on(void); +void ergodox_right_led_3_on(void); +void ergodox_right_led_on(uint8_t led); +void ergodox_board_led_off(void); +void ergodox_right_led_1_off(void); +void ergodox_right_led_2_off(void); +void ergodox_right_led_3_off(void); +void ergodox_right_led_off(uint8_t led); +void ergodox_led_all_on(void); +void ergodox_led_all_off(void); +void ergodox_right_led_1_set(uint8_t n); +void ergodox_right_led_2_set(uint8_t n); +void ergodox_right_led_3_set(uint8_t n); +void ergodox_right_led_set(uint8_t led, uint8_t n); +void ergodox_led_all_set(uint8_t n); + +#ifndef LED_BRIGHTNESS_LO +# define LED_BRIGHTNESS_LO 15 +#endif +#ifndef LED_BRIGHTNESS_HI +# define LED_BRIGHTNESS_HI 255 +#endif + +enum ergodox_ez_keycodes { + LED_LEVEL = QK_KB, + TOGGLE_LAYER_COLOR, + EZ_SAFE_RANGE +}; + +typedef union { + uint32_t raw; + struct { + uint8_t led_level : 3; + bool disable_layer_led : 1; + bool placeholder : 1; + }; +} keyboard_config_t; + +extern keyboard_config_t keyboard_config; + +#define STATUS_LED_1(status) (bool)status ? ergodox_right_led_1_on() : ergodox_right_led_1_off() +#define STATUS_LED_2(status) (bool)status ? ergodox_right_led_2_on() : ergodox_right_led_2_off() +#define STATUS_LED_3(status) (bool)status ? ergodox_right_led_3_on() : ergodox_right_led_3_off() diff --git a/keyboards/zsa/ergodox_ez/gd32/base/info.json b/keyboards/zsa/ergodox_ez/gd32/base/info.json new file mode 100644 index 000000000000..2af5c29a8fca --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/base/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ", + "usb": { + "pid": "0x2031" + } +} diff --git a/keyboards/zsa/ergodox_ez/gd32/base/rules.mk b/keyboards/zsa/ergodox_ez/gd32/base/rules.mk new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/keyboards/zsa/ergodox_ez/gd32/chconf.h b/keyboards/zsa/ergodox_ez/gd32/chconf.h new file mode 100644 index 000000000000..5abb62208631 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/chconf.h @@ -0,0 +1,14 @@ +#pragma once + +#define CH_CFG_ST_RESOLUTION 16 + +#define CH_CFG_ST_FREQUENCY 2000 + +#define CH_CFG_INTERVALS_SIZE 32 + +#define CH_CFG_TIME_TYPES_SIZE 32 + +#define CH_CFG_USE_CONDVARS_TIMEOUT FALSE + +#include_next + diff --git a/keyboards/zsa/ergodox_ez/gd32/config.h b/keyboards/zsa/ergodox_ez/gd32/config.h new file mode 100644 index 000000000000..bb12265e9db7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/config.h @@ -0,0 +1,30 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#define MATRIX_ONBOARD_ROW_PINS \ + { 0, 0, 0, 0, 0, 0, 0, A7, A6, A5, A4, A3, A2, A1 } +#define MATRIX_ONBOARD_COL_PINS \ + { B15, B14, B13, B12, B11, B10 } + +#define ERGODOX_LED_1_PIN B5 +#define ERGODOX_LED_2_PIN B4 +#define ERGODOX_LED_3_PIN B3 diff --git a/keyboards/zsa/ergodox_ez/gd32/gd32.c b/keyboards/zsa/ergodox_ez/gd32/gd32.c new file mode 100644 index 000000000000..76d4966816ff --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/gd32.c @@ -0,0 +1,217 @@ +// Copyright 2023 Christopher Courtney, aka Drashna Jael're (@drashna) +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "ergodox_ez.h" +#include +#include + +#if HAL_USE_PWM == TRUE +static uint16_t cie_lightness(uint16_t v) { + if (v <= 5243) // if below 8% of max + return v / 9; // same as dividing by 900% + else { + uint32_t y = (((uint32_t)v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare + // to get a useful result with integer division, we shift left in the expression above + // and revert what we've done again after squaring. + y = y * y * y >> 8; + if (y > 0xFFFFUL) // prevent overflow + return 0xFFFFU; + else + return (uint16_t)y; + } +} + +// clang-format off +static PWMConfig pwmCFG = { + .frequency = 0xFFFF, + .period = 256, + .callback = NULL, + .channels = { +#ifdef REMAPPED_LEDS + { .mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB4 + { .mode = PWM_OUTPUT_DISABLED, .callback = NULL}, + { .mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB0 + { .mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL} // PB1 +#else + { .mode = PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB3 + { .mode = PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB4 + { .mode = PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB5 + { .mode = PWM_OUTPUT_DISABLED, .callback = NULL} +#endif + }, + .cr2 = 0, + .dier = TIM_DIER_UDE +}; +// clang-format on + +static uint32_t ergodox_right_led_1_duty; +static uint32_t ergodox_right_led_2_duty; +static uint32_t ergodox_right_led_3_duty; +#endif + +void ergodox_right_led_1_on(void) { +#if HAL_USE_PWM == TRUE +# ifdef REMAPPED_LEDS + pwmEnableChannel(&PWMD3, 2, PWM_FRACTION_TO_WIDTH(&PWMD3, 0xFFFF, ergodox_right_led_1_duty)); +# else + pwmEnableChannel(&PWMD8, 2, PWM_FRACTION_TO_WIDTH(&PWMD8, 0xFFFF, ergodox_right_led_1_duty)); +# endif +#else + writePinHigh(ERGODOX_LED_1_PIN); +#endif +} + +void ergodox_right_led_1_off(void) { +#if HAL_USE_PWM == TRUE +# ifdef REMAPPED_LEDS + pwmDisableChannel(&PWMD3, 2); +# else + pwmDisableChannel(&PWMD8, 2); +# endif +#else + writePinLow(ERGODOX_LED_1_PIN); +#endif +} + +void ergodox_right_led_1_set(uint8_t level) { +#if HAL_USE_PWM == TRUE + ergodox_right_led_1_duty = (uint32_t)(cie_lightness(0xFFFF * (uint32_t)level / 255)); +#endif + if (level == 0) { + ergodox_right_led_1_off(); + } else { + ergodox_right_led_1_on(); + } +} + +void ergodox_right_led_2_on(void) { +#if HAL_USE_PWM == TRUE +# ifdef REMAPPED_LEDS + pwmEnableChannel(&PWMD3, 3, PWM_FRACTION_TO_WIDTH(&PWMD3, 0xFFFF, ergodox_right_led_2_duty)); +# else + pwmEnableChannel(&PWMD8, 1, PWM_FRACTION_TO_WIDTH(&PWMD8, 0xFFFF, ergodox_right_led_2_duty)); +# endif +#else + writePinHigh(ERGODOX_LED_2_PIN); +#endif +} + +void ergodox_right_led_2_off(void) { +#if HAL_USE_PWM == TRUE +# ifdef REMAPPED_LEDS + pwmDisableChannel(&PWMD3, 3); +# else + pwmDisableChannel(&PWMD8, 1); +# endif +#else + writePinLow(ERGODOX_LED_2_PIN); +#endif +} + +void ergodox_right_led_2_set(uint8_t level) { +#if HAL_USE_PWM == TRUE + ergodox_right_led_2_duty = (uint32_t)(cie_lightness(0xFFFF * (uint32_t)level / 255)); +#endif + if (level == 0) { + ergodox_right_led_2_off(); + } else { + ergodox_right_led_2_on(); + } +} + +void ergodox_right_led_3_on(void) { +#if HAL_USE_PWM == TRUE +# ifdef REMAPPED_LEDS + pwmEnableChannel(&PWMD3, 0, PWM_FRACTION_TO_WIDTH(&PWMD3, 0xFFFF, ergodox_right_led_3_duty)); +# else + pwmEnableChannel(&PWMD8, 1, PWM_FRACTION_TO_WIDTH(&PWMD8, 0xFFFF, ergodox_right_led_3_duty)); +# endif +#else + writePinHigh(ERGODOX_LED_3_PIN); +#endif +} +void ergodox_right_led_3_off(void) { +#if HAL_USE_PWM == TRUE +# ifdef REMAPPED_LEDS + pwmDisableChannel(&PWMD3, 0); +# else + pwmDisableChannel(&PWMD8, 1); +# endif +#else + writePinLow(ERGODOX_LED_3_PIN); +#endif +} + +void ergodox_right_led_3_set(uint8_t level) { +#if HAL_USE_PWM == TRUE + ergodox_right_led_3_duty = (uint32_t)(cie_lightness(0xFFFF * (uint32_t)level / 255)); +#endif + if (level == 0) { + ergodox_right_led_3_off(); + } else { + ergodox_right_led_3_on(); + } +} + +void keyboard_post_init_sub(void) { +#if HAL_USE_PWM == TRUE +# ifdef REMAPPED_LEDS + pwmStart(&PWMD3, &pwmCFG); + palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); + palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATE(2) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); + palSetPadMode(GPIOB, 4, PAL_MODE_ALTERNATE(2) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); +# else + pwmStart(&PWMD8, &pwmCFG); + palSetPadMode(GPIOB, 5, PAL_MODE_ALTERNATE(3) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); + palSetPadMode(GPIOB, 4, PAL_MODE_ALTERNATE(4) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); + palSetPadMode(GPIOB, 3, PAL_MODE_ALTERNATE(4) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); +# endif +#endif + ergodox_right_led_1_set((uint8_t)keyboard_config.led_level * 255 / 4); + ergodox_right_led_2_set((uint8_t)keyboard_config.led_level * 255 / 4); + ergodox_right_led_3_set((uint8_t)keyboard_config.led_level * 255 / 4); + + ergodox_right_led_1_off(); + ergodox_right_led_2_off(); + ergodox_right_led_3_off(); +} + +void board_init(void) { +#if HAL_USE_PWM == TRUE +# ifdef REMAPPED_LEDS + AFIO->MAPR |= AFIO_MAPR_TIM3_REMAP_PARTIALREMAP; +# else + AFIO->MAPR |= AFIO_MAPR_TIM3_REMAP_PARTIALREMAP; +# endif +#endif +} + +#define APP_ADDRESS 0x08002000 + +__attribute__((weak)) void bootloader_jump(void) { + // The ignition bootloader is checking for a high signal on A8 for 100ms when powering on the board. + // Setting both A8 and A9 high will charge the capacitor quickly. + // Setting A9 low before reset will cause the capacitor to discharge + // thus making the bootloder unlikely to trigger twice between power cycles. + setPinOutputPushPull(A9); + setPinOutputPushPull(A8); + writePinHigh(A9); + writePinHigh(A8); + wait_ms(500); + writePinLow(A9); + + NVIC_SystemReset(); +} + +__attribute__((weak)) void mcu_reset(void) { + // When resetting the MCU, we want to jump to the application. + SCB->AIRCR = APP_ADDRESS & 0xFFFF; + + // Set the stack pointer to the applications stack pointer + __asm__ volatile("msr msp, %0" ::"g"(*(volatile uint32_t *)APP_ADDRESS)); + + // Jump to the application + (*(void (**)())(APP_ADDRESS + 4))(); + while (1) + ; +} diff --git a/keyboards/zsa/ergodox_ez/gd32/glow/glow.h b/keyboards/zsa/ergodox_ez/gd32/glow/glow.h new file mode 100644 index 000000000000..da7a6073efcc --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/glow/glow.h @@ -0,0 +1,23 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#include "ergodox_ez.h" diff --git a/keyboards/zsa/ergodox_ez/gd32/glow/info.json b/keyboards/zsa/ergodox_ez/gd32/glow/info.json new file mode 100644 index 000000000000..5ae73959764f --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/glow/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ Glow", + "usb": { + "pid": "0x2010" + } +} diff --git a/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/glow/keymap.c b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/glow/keymap.c new file mode 100644 index 000000000000..526c364029f7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/glow/keymap.c @@ -0,0 +1 @@ +// Placeholder. See ../default/keymap.c for details diff --git a/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/glow/rules.mk b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/glow/rules.mk new file mode 100644 index 000000000000..894a6a5e1339 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/glow/rules.mk @@ -0,0 +1,6 @@ +RGBLIGHT_ENABLE = no +RGB_MATRIX_ENABLE = IS31FL3731 # enable later + +SRC += keymaps/default/keymap.c + +LTO_ENABLE = yes diff --git a/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/config.h b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/config.h new file mode 100644 index 000000000000..6e86f8d9d048 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/config.h @@ -0,0 +1,12 @@ +#pragma once + +#define RGB_MATRIX_KEYPRESSES +#define RGB_MATRIX_FRAMEBUFFER_EFFECTS + +#define DISABLE_RGB_MATRIX_DIGITAL_RAIN +#define DISABLE_RGB_MATRIX_ALPHAS_MODS +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#define DISABLE_RGB_MATRIX_SPLASH +#define DISABLE_RGB_MATRIX_SOLID_SPLASH diff --git a/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/keymap.c b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/keymap.c new file mode 100644 index 000000000000..526c364029f7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/keymap.c @@ -0,0 +1 @@ +// Placeholder. See ../default/keymap.c for details diff --git a/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/rules.mk b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/rules.mk new file mode 100644 index 000000000000..21a5fb45ce84 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/glow/keymaps/reactive/rules.mk @@ -0,0 +1,7 @@ +RGBLIGHT_ENABLE = no +RGB_MATRIX_ENABLE = IS31FL3731 # enable later + +SRC += keymaps/default/keymap.c + +LTO_ENABLE = yes +COMMAND_ENABLE = no diff --git a/keyboards/zsa/ergodox_ez/gd32/glow/rules.mk b/keyboards/zsa/ergodox_ez/gd32/glow/rules.mk new file mode 100644 index 000000000000..aad92997d0fa --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/glow/rules.mk @@ -0,0 +1 @@ +RGB_MATRIX_ENABLE = yes diff --git a/keyboards/zsa/ergodox_ez/gd32/halconf.h b/keyboards/zsa/ergodox_ez/gd32/halconf.h new file mode 100644 index 000000000000..1b8733be60f2 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/halconf.h @@ -0,0 +1,21 @@ +/* Copyright 2021 QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#define HAL_USE_I2C TRUE +// #define HAL_USE_PWM TRUE + +#include_next diff --git a/keyboards/zsa/ergodox_ez/gd32/info.json b/keyboards/zsa/ergodox_ez/gd32/info.json new file mode 100644 index 000000000000..13e045f4b260 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/info.json @@ -0,0 +1,10 @@ +{ + "bootloader": "custom", + "usb": { + "pid": "0x1999" + }, + "processor": "GD32F303", + "ws2812": { + "pin": "D7" + } +} diff --git a/keyboards/zsa/ergodox_ez/gd32/mcuconf.h b/keyboards/zsa/ergodox_ez/gd32/mcuconf.h new file mode 100644 index 000000000000..5ea6c85cdf32 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/mcuconf.h @@ -0,0 +1,28 @@ +/* Copyright 2021 QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include_next + +#undef STM32_PWM_USE_TIM2 +#define STM32_PWM_USE_TIM2 TRUE + +#undef STM32_PWM_USE_TIM3 +#define STM32_PWM_USE_TIM3 TRUE + +#undef STM32_ST_USE_TIMER +#define STM32_ST_USE_TIMER 4 diff --git a/keyboards/zsa/ergodox_ez/gd32/rules.mk b/keyboards/zsa/ergodox_ez/gd32/rules.mk new file mode 100644 index 000000000000..a608b829422c --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/rules.mk @@ -0,0 +1,6 @@ +MCU_LDSCRIPT = ergodox_ez +PROGRAM_CMD = $(call EXEC_DFU) +DFU_ARGS = -d 3297:2001 -a 0 -s 0x08002000:leave +DFU_SUFFIX_ARGS = -v 3297 -p 2001 + +DEFAULT_FOLDER = zsa/ergodox_ez/gd32/base diff --git a/keyboards/zsa/ergodox_ez/gd32/shine/info.json b/keyboards/zsa/ergodox_ez/gd32/shine/info.json new file mode 100644 index 000000000000..b0f28cf1e1d9 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/shine/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ Shine", + "usb": { + "pid": "0x2021" + } +} diff --git a/keyboards/zsa/ergodox_ez/gd32/shine/rules.mk b/keyboards/zsa/ergodox_ez/gd32/shine/rules.mk new file mode 100644 index 000000000000..1e3cebb14515 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/shine/rules.mk @@ -0,0 +1 @@ +RGBLIGHT_ENABLE = yes diff --git a/keyboards/zsa/ergodox_ez/gd32/shine/shine.h b/keyboards/zsa/ergodox_ez/gd32/shine/shine.h new file mode 100644 index 000000000000..da7a6073efcc --- /dev/null +++ b/keyboards/zsa/ergodox_ez/gd32/shine/shine.h @@ -0,0 +1,23 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#include "ergodox_ez.h" diff --git a/keyboards/zsa/ergodox_ez/info.json b/keyboards/zsa/ergodox_ez/info.json new file mode 100644 index 000000000000..55c5460eb374 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/info.json @@ -0,0 +1,245 @@ +{ + "manufacturer": "ZSA Technology Labs", + "keyboard_name": "Ergodox EZ", + "maintainer": "Drashna Jaelre", + "features": { + "bootmagic": true, + "command": false, + "console": false, + "extrakey": true, + "mousekey": true, + "nkro": true + }, + "matrix_size": { + "cols": 6, + "rows": 14 + }, + "url": "", + "usb": { + "device_version": "1.0.0", + "vid": "0x3297" + }, + "debounce": 20, + "rgb_matrix": { + "driver": "is31fl3731", + "layout": [ + {"matrix": [8, 0], "x": 137, "y": 0, "flags": 4}, + {"matrix": [9, 0], "x": 154, "y": 0, "flags": 4}, + {"matrix": [10, 0], "x": 172, "y": 0, "flags": 4}, + {"matrix": [11, 0], "x": 189, "y": 0, "flags": 4}, + {"matrix": [12, 0], "x": 206, "y": 0, "flags": 4}, + {"matrix": [8, 1], "x": 137, "y": 12, "flags": 4}, + {"matrix": [9, 1], "x": 154, "y": 12, "flags": 4}, + {"matrix": [10, 1], "x": 172, "y": 12, "flags": 4}, + {"matrix": [11, 1], "x": 189, "y": 12, "flags": 4}, + {"matrix": [12, 1], "x": 206, "y": 12, "flags": 4}, + {"matrix": [8, 2], "x": 137, "y": 25, "flags": 4}, + {"matrix": [9, 2], "x": 154, "y": 25, "flags": 4}, + {"matrix": [10, 2], "x": 172, "y": 25, "flags": 4}, + {"matrix": [11, 2], "x": 189, "y": 25, "flags": 4}, + {"matrix": [12, 2], "x": 206, "y": 25, "flags": 4}, + {"matrix": [8, 3], "x": 137, "y": 38, "flags": 4}, + {"matrix": [9, 3], "x": 154, "y": 38, "flags": 4}, + {"matrix": [10, 3], "x": 172, "y": 38, "flags": 4}, + {"matrix": [11, 3], "x": 189, "y": 38, "flags": 4}, + {"matrix": [12, 3], "x": 206, "y": 38, "flags": 4}, + {"matrix": [9, 4], "x": 154, "y": 51, "flags": 1}, + {"matrix": [10, 4], "x": 172, "y": 51, "flags": 1}, + {"matrix": [11, 4], "x": 189, "y": 51, "flags": 1}, + {"matrix": [12, 4], "x": 206, "y": 51, "flags": 1}, + {"matrix": [5, 0], "x": 86, "y": 0, "flags": 4}, + {"matrix": [4, 0], "x": 68, "y": 0, "flags": 4}, + {"matrix": [3, 0], "x": 51, "y": 0, "flags": 4}, + {"matrix": [2, 0], "x": 34, "y": 0, "flags": 4}, + {"matrix": [1, 0], "x": 17, "y": 0, "flags": 4}, + {"matrix": [5, 1], "x": 86, "y": 12, "flags": 4}, + {"matrix": [4, 1], "x": 68, "y": 12, "flags": 4}, + {"matrix": [3, 1], "x": 51, "y": 12, "flags": 4}, + {"matrix": [2, 1], "x": 34, "y": 12, "flags": 4}, + {"matrix": [1, 1], "x": 17, "y": 12, "flags": 4}, + {"matrix": [5, 2], "x": 86, "y": 25, "flags": 4}, + {"matrix": [4, 2], "x": 68, "y": 25, "flags": 4}, + {"matrix": [3, 2], "x": 51, "y": 25, "flags": 4}, + {"matrix": [2, 2], "x": 34, "y": 25, "flags": 4}, + {"matrix": [1, 2], "x": 17, "y": 25, "flags": 4}, + {"matrix": [5, 3], "x": 86, "y": 38, "flags": 4}, + {"matrix": [4, 3], "x": 68, "y": 38, "flags": 4}, + {"matrix": [3, 3], "x": 51, "y": 38, "flags": 4}, + {"matrix": [2, 3], "x": 34, "y": 38, "flags": 4}, + {"matrix": [1, 3], "x": 17, "y": 38, "flags": 4}, + {"matrix": [4, 4], "x": 68, "y": 51, "flags": 1}, + {"matrix": [3, 4], "x": 51, "y": 51, "flags": 1}, + {"matrix": [2, 4], "x": 34, "y": 51, "flags": 1}, + {"matrix": [1, 4], "x": 17, "y": 51, "flags": 1} + ] + }, + "rgblight": { + "brightness_steps": 12, + "hue_steps": 12, + "rgbw": true, + "saturation_steps": 255, + "sleep": true + }, + "layouts": { + "LAYOUT_ergodox": { + "layout": [ + { "label": "k00", "matrix": [0, 0], "w": 1.5, "x": 0, "y": 0.375 }, + { "label": "k01", "matrix": [1, 0], "w": 1, "x": 1.5, "y": 0.375 }, + { "label": "k02", "matrix": [2, 0], "w": 1, "x": 2.5, "y": 0.125 }, + { "label": "k03", "matrix": [3, 0], "w": 1, "x": 3.5, "y": 0 }, + { "label": "k04", "matrix": [4, 0], "w": 1, "x": 4.5, "y": 0.125 }, + { "label": "k05", "matrix": [5, 0], "w": 1, "x": 5.5, "y": 0.25 }, + { "label": "k06", "matrix": [6, 0], "w": 1, "x": 6.5, "y": 0.25 }, + { "label": "k10", "matrix": [0, 1], "w": 1.5, "x": 0, "y": 1.375 }, + { "label": "k11", "matrix": [1, 1], "w": 1, "x": 1.5, "y": 1.375 }, + { "label": "k12", "matrix": [2, 1], "w": 1, "x": 2.5, "y": 1.125 }, + { "label": "k13", "matrix": [3, 1], "w": 1, "x": 3.5, "y": 1 }, + { "label": "k14", "matrix": [4, 1], "w": 1, "x": 4.5, "y": 1.125 }, + { "label": "k15", "matrix": [5, 1], "w": 1, "x": 5.5, "y": 1.25 }, + { "h": 1.5, "label": "k16", "matrix": [6, 1], "w": 1, "x": 6.5, "y": 1.25 }, + { "label": "k20", "matrix": [0, 2], "w": 1.5, "x": 0, "y": 2.375 }, + { "label": "k21", "matrix": [1, 2], "w": 1, "x": 1.5, "y": 2.375 }, + { "label": "k22", "matrix": [2, 2], "w": 1, "x": 2.5, "y": 2.125 }, + { "label": "k23", "matrix": [3, 2], "w": 1, "x": 3.5, "y": 2 }, + { "label": "k24", "matrix": [4, 2], "w": 1, "x": 4.5, "y": 2.125 }, + { "label": "k25", "matrix": [5, 2], "w": 1, "x": 5.5, "y": 2.25 }, + { "label": "k30", "matrix": [0, 3], "w": 1.5, "x": 0, "y": 3.375 }, + { "label": "k31", "matrix": [1, 3], "w": 1, "x": 1.5, "y": 3.375 }, + { "label": "k32", "matrix": [2, 3], "w": 1, "x": 2.5, "y": 3.125 }, + { "label": "k33", "matrix": [3, 3], "w": 1, "x": 3.5, "y": 3 }, + { "label": "k34", "matrix": [4, 3], "w": 1, "x": 4.5, "y": 3.125 }, + { "label": "k35", "matrix": [5, 3], "w": 1, "x": 5.5, "y": 3.25 }, + { "h": 1.5, "label": "k36", "matrix": [6, 3], "w": 1, "x": 6.5, "y": 2.75 }, + { "label": "k40", "matrix": [0, 4], "w": 1, "x": 0.5, "y": 4.375 }, + { "label": "k41", "matrix": [1, 4], "w": 1, "x": 1.5, "y": 4.375 }, + { "label": "k42", "matrix": [2, 4], "w": 1, "x": 2.5, "y": 4.125 }, + { "label": "k43", "matrix": [3, 4], "w": 1, "x": 3.5, "y": 4 }, + { "label": "k44", "matrix": [4, 4], "w": 1, "x": 4.5, "y": 4.125 }, + { "label": "k55", "matrix": [5, 5], "w": 1, "x": 6, "y": 5 }, + { "label": "k56", "matrix": [6, 5], "w": 1, "x": 7, "y": 5 }, + { "label": "k54", "matrix": [4, 5], "w": 1, "x": 7, "y": 6 }, + { "h": 2, "label": "k53", "matrix": [3, 5], "w": 1, "x": 5, "y": 6 }, + { "h": 2, "label": "k52", "matrix": [2, 5], "w": 1, "x": 6, "y": 6 }, + { "label": "k51", "matrix": [1, 5], "w": 1, "x": 7, "y": 7 }, + { "label": "k07", "matrix": [7, 0], "w": 1, "x": 9.5, "y": 0.25 }, + { "label": "k08", "matrix": [8, 0], "w": 1, "x": 10.5, "y": 0.25 }, + { "label": "k09", "matrix": [9, 0], "w": 1, "x": 11.5, "y": 0.125 }, + { "label": "k0A", "matrix": [10, 0], "w": 1, "x": 12.5, "y": 0 }, + { "label": "k0B", "matrix": [11, 0], "w": 1, "x": 13.5, "y": 0.125 }, + { "label": "k0C", "matrix": [12, 0], "w": 1, "x": 14.5, "y": 0.375 }, + { "label": "k0D", "matrix": [13, 0], "w": 1.5, "x": 15.5, "y": 0.375 }, + { "h": 1.5, "label": "k17", "matrix": [7, 1], "w": 1, "x": 9.5, "y": 1.25 }, + { "label": "k18", "matrix": [8, 1], "w": 1, "x": 10.5, "y": 1.25 }, + { "label": "k19", "matrix": [9, 1], "w": 1, "x": 11.5, "y": 1.125 }, + { "label": "k1A", "matrix": [10, 1], "w": 1, "x": 12.5, "y": 1 }, + { "label": "k1B", "matrix": [11, 1], "w": 1, "x": 13.5, "y": 1.125 }, + { "label": "k1C", "matrix": [12, 1], "w": 1, "x": 14.5, "y": 1.375 }, + { "label": "k1D", "matrix": [13, 1], "w": 1.5, "x": 15.5, "y": 1.375 }, + { "label": "k28", "matrix": [8, 2], "w": 1, "x": 10.5, "y": 2.25 }, + { "label": "k29", "matrix": [9, 2], "w": 1, "x": 11.5, "y": 2.125 }, + { "label": "k2A", "matrix": [10, 2], "w": 1, "x": 12.5, "y": 2 }, + { "label": "k2B", "matrix": [11, 2], "w": 1, "x": 13.5, "y": 2.125 }, + { "label": "k2C", "matrix": [12, 2], "w": 1, "x": 14.5, "y": 2.375 }, + { "label": "k2D", "matrix": [13, 2], "w": 1.5, "x": 15.5, "y": 2.375 }, + { "h": 1.5, "label": "k37", "matrix": [7, 3], "w": 1, "x": 9.5, "y": 2.75 }, + { "label": "k38", "matrix": [8, 3], "w": 1, "x": 10.5, "y": 3.25 }, + { "label": "k39", "matrix": [9, 3], "w": 1, "x": 11.5, "y": 3.125 }, + { "label": "k3A", "matrix": [10, 3], "w": 1, "x": 12.5, "y": 3 }, + { "label": "k3B", "matrix": [11, 3], "w": 1, "x": 13.5, "y": 3.125 }, + { "label": "k3C", "matrix": [12, 3], "w": 1, "x": 14.5, "y": 3.375 }, + { "label": "k3D", "matrix": [13, 3], "w": 1.5, "x": 15.5, "y": 3.375 }, + { "label": "k49", "matrix": [9, 4], "w": 1, "x": 11.5, "y": 4.125 }, + { "label": "k4A", "matrix": [10, 4], "w": 1, "x": 12.5, "y": 4 }, + { "label": "k4B", "matrix": [11, 4], "w": 1, "x": 13.5, "y": 4.125 }, + { "label": "k4C", "matrix": [12, 4], "w": 1, "x": 14.5, "y": 4.375 }, + { "label": "k4D", "matrix": [13, 4], "w": 1, "x": 15.5, "y": 4.375 }, + { "label": "k57", "matrix": [7, 5], "w": 1, "x": 9, "y": 5 }, + { "label": "k58", "matrix": [8, 5], "w": 1, "x": 10, "y": 5 }, + { "label": "k59", "matrix": [9, 5], "w": 1, "x": 9, "y": 6 }, + { "label": "k5C", "matrix": [12, 5], "w": 1, "x": 9, "y": 7 }, + { "h": 2, "label": "k5B", "matrix": [11, 5], "w": 1, "x": 10, "y": 6 }, + { "h": 2, "label": "k5A", "matrix": [10, 5], "w": 1, "x": 11, "y": 6 } + ] + }, + "LAYOUT_ergodox_pretty": { + "layout": [ + { "label": "L00", "matrix": [0, 0], "w": 1.5, "x": 0, "y": 0.375 }, + { "label": "L01", "matrix": [1, 0], "w": 1, "x": 1.5, "y": 0.375 }, + { "label": "L02", "matrix": [2, 0], "w": 1, "x": 2.5, "y": 0.125 }, + { "label": "L03", "matrix": [3, 0], "w": 1, "x": 3.5, "y": 0 }, + { "label": "L04", "matrix": [4, 0], "w": 1, "x": 4.5, "y": 0.125 }, + { "label": "L05", "matrix": [5, 0], "w": 1, "x": 5.5, "y": 0.25 }, + { "label": "L06", "matrix": [6, 0], "w": 1, "x": 6.5, "y": 0.25 }, + { "label": "R00", "matrix": [7, 0], "w": 1, "x": 9.5, "y": 0.25 }, + { "label": "R01", "matrix": [8, 0], "w": 1, "x": 10.5, "y": 0.25 }, + { "label": "R02", "matrix": [9, 0], "w": 1, "x": 11.5, "y": 0.125 }, + { "label": "R03", "matrix": [10, 0], "w": 1, "x": 12.5, "y": 0 }, + { "label": "R04", "matrix": [11, 0], "w": 1, "x": 13.5, "y": 0.125 }, + { "label": "R05", "matrix": [12, 0], "w": 1, "x": 14.5, "y": 0.375 }, + { "label": "R06", "matrix": [13, 0], "w": 1.5, "x": 15.5, "y": 0.375 }, + { "label": "L10", "matrix": [0, 1], "w": 1.5, "x": 0, "y": 1.375 }, + { "label": "L11", "matrix": [1, 1], "w": 1, "x": 1.5, "y": 1.375 }, + { "label": "L12", "matrix": [2, 1], "w": 1, "x": 2.5, "y": 1.125 }, + { "label": "L13", "matrix": [3, 1], "w": 1, "x": 3.5, "y": 1 }, + { "label": "L14", "matrix": [4, 1], "w": 1, "x": 4.5, "y": 1.125 }, + { "label": "L15", "matrix": [5, 1], "w": 1, "x": 5.5, "y": 1.25 }, + { "h": 1.5, "label": "L16", "matrix": [6, 1], "w": 1, "x": 6.5, "y": 1.25 }, + { "h": 1.5, "label": "R10", "matrix": [7, 1], "w": 1, "x": 9.5, "y": 1.25 }, + { "label": "R11", "matrix": [8, 1], "w": 1, "x": 10.5, "y": 1.25 }, + { "label": "R12", "matrix": [9, 1], "w": 1, "x": 11.5, "y": 1.125 }, + { "label": "R13", "matrix": [10, 1], "w": 1, "x": 12.5, "y": 1 }, + { "label": "R14", "matrix": [11, 1], "w": 1, "x": 13.5, "y": 1.125 }, + { "label": "R15", "matrix": [12, 1], "w": 1, "x": 14.5, "y": 1.375 }, + { "label": "R16", "matrix": [13, 1], "w": 1.5, "x": 15.5, "y": 1.375 }, + { "label": "L20", "matrix": [0, 2], "w": 1.5, "x": 0, "y": 2.375 }, + { "label": "L21", "matrix": [1, 2], "w": 1, "x": 1.5, "y": 2.375 }, + { "label": "L22", "matrix": [2, 2], "w": 1, "x": 2.5, "y": 2.125 }, + { "label": "L23", "matrix": [3, 2], "w": 1, "x": 3.5, "y": 2 }, + { "label": "L24", "matrix": [4, 2], "w": 1, "x": 4.5, "y": 2.125 }, + { "label": "L25", "matrix": [5, 2], "w": 1, "x": 5.5, "y": 2.25 }, + { "label": "R21", "matrix": [8, 2], "w": 1, "x": 10.5, "y": 2.25 }, + { "label": "R22", "matrix": [9, 2], "w": 1, "x": 11.5, "y": 2.125 }, + { "label": "R23", "matrix": [10, 2], "w": 1, "x": 12.5, "y": 2 }, + { "label": "R24", "matrix": [11, 2], "w": 1, "x": 13.5, "y": 2.125 }, + { "label": "R25", "matrix": [12, 2], "w": 1, "x": 14.5, "y": 2.375 }, + { "label": "R26", "matrix": [13, 2], "w": 1.5, "x": 15.5, "y": 2.375 }, + { "label": "L30", "matrix": [0, 3], "w": 1.5, "x": 0, "y": 3.375 }, + { "label": "L31", "matrix": [1, 3], "w": 1, "x": 1.5, "y": 3.375 }, + { "label": "L32", "matrix": [2, 3], "w": 1, "x": 2.5, "y": 3.125 }, + { "label": "L33", "matrix": [3, 3], "w": 1, "x": 3.5, "y": 3 }, + { "label": "L34", "matrix": [4, 3], "w": 1, "x": 4.5, "y": 3.125 }, + { "label": "L35", "matrix": [5, 3], "w": 1, "x": 5.5, "y": 3.25 }, + { "h": 1.5, "label": "L36", "matrix": [6, 3], "w": 1, "x": 6.5, "y": 2.75 }, + { "h": 1.5, "label": "R30", "matrix": [7, 3], "w": 1, "x": 9.5, "y": 2.75 }, + { "label": "R31", "matrix": [8, 3], "w": 1, "x": 10.5, "y": 3.25 }, + { "label": "R32", "matrix": [9, 3], "w": 1, "x": 11.5, "y": 3.125 }, + { "label": "R33", "matrix": [10, 3], "w": 1, "x": 12.5, "y": 3 }, + { "label": "R34", "matrix": [11, 3], "w": 1, "x": 13.5, "y": 3.125 }, + { "label": "R35", "matrix": [12, 3], "w": 1, "x": 14.5, "y": 3.375 }, + { "label": "R36", "matrix": [13, 3], "w": 1.5, "x": 15.5, "y": 3.375 }, + { "label": "L40", "matrix": [0, 4], "w": 1, "x": 0.5, "y": 4.375 }, + { "label": "L41", "matrix": [1, 4], "w": 1, "x": 1.5, "y": 4.375 }, + { "label": "L42", "matrix": [2, 4], "w": 1, "x": 2.5, "y": 4.125 }, + { "label": "L43", "matrix": [3, 4], "w": 1, "x": 3.5, "y": 4 }, + { "label": "L44", "matrix": [4, 4], "w": 1, "x": 4.5, "y": 4.125 }, + { "label": "R42", "matrix": [9, 4], "w": 1, "x": 11.5, "y": 4.125 }, + { "label": "R43", "matrix": [10, 4], "w": 1, "x": 12.5, "y": 4 }, + { "label": "R44", "matrix": [11, 4], "w": 1, "x": 13.5, "y": 4.125 }, + { "label": "R45", "matrix": [12, 4], "w": 1, "x": 14.5, "y": 4.375 }, + { "label": "R46", "matrix": [13, 4], "w": 1, "x": 15.5, "y": 4.375 }, + { "label": "L55", "matrix": [5, 5], "w": 1, "x": 6, "y": 5 }, + { "label": "L56", "matrix": [6, 5], "w": 1, "x": 7, "y": 5 }, + { "label": "R50", "matrix": [7, 5], "w": 1, "x": 9, "y": 5 }, + { "label": "R51", "matrix": [8, 5], "w": 1, "x": 10, "y": 5 }, + { "label": "L54", "matrix": [4, 5], "w": 1, "x": 7, "y": 6 }, + { "label": "R52", "matrix": [9, 5], "w": 1, "x": 9, "y": 6 }, + { "h": 2, "label": "L53", "matrix": [3, 5], "w": 1, "x": 5, "y": 6 }, + { "h": 2, "label": "L52", "matrix": [2, 5], "w": 1, "x": 6, "y": 6 }, + { "label": "L51", "matrix": [1, 5], "w": 1, "x": 7, "y": 7 }, + { "label": "R55", "matrix": [12, 5], "w": 1, "x": 9, "y": 7 }, + { "h": 2, "label": "R54", "matrix": [11, 5], "w": 1, "x": 10, "y": 6 }, + { "h": 2, "label": "R53", "matrix": [10, 5], "w": 1, "x": 11, "y": 6 } + ] + } + } +} diff --git a/keyboards/zsa/ergodox_ez/keymaps/default/keymap.c b/keyboards/zsa/ergodox_ez/keymaps/default/keymap.c new file mode 100644 index 000000000000..0a40cc91fddc --- /dev/null +++ b/keyboards/zsa/ergodox_ez/keymaps/default/keymap.c @@ -0,0 +1,169 @@ +#include QMK_KEYBOARD_H +#include "version.h" + +enum layers { + BASE, // default layer + SYMB, // symbols + MDIA, // media keys +}; + +enum custom_keycodes { + VRSN = QK_USER, +}; + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { +/* Keymap 0: Basic layer + * + * ,--------------------------------------------------. ,--------------------------------------------------. + * | = | 1 | 2 | 3 | 4 | 5 | LEFT | | RIGHT| 6 | 7 | 8 | 9 | 0 | - | + * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------| + * | Del | Q | W | E | R | T | L1 | | L1 | Y | U | I | O | P | \ | + * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------| + * | BkSp | A | S | D | F | G |------| |------| H | J | K | L |; / L2|' / Cmd | + * |--------+------+------+------+------+------| Hyper| | Meh |------+------+------+------+------+--------| + * | LShift |Z/Ctrl| X | C | V | B | | | | N | M | , | . |//Ctrl| RShift | + * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------' + * |Grv/L1| '" |AltShf| Left | Right| | Up | Down | [ | ] | ~L1 | + * `----------------------------------' `----------------------------------' + * ,-------------. ,-------------. + * | App | LGui | | Alt |Ctrl/Esc| + * ,------|------|------| |------+--------+------. + * | | | Home | | PgUp | | | + * | Space|Backsp|------| |------| Tab |Enter | + * | |ace | End | | PgDn | | | + * `--------------------' `----------------------' + */ +[BASE] = LAYOUT_ergodox_pretty( + // left hand + KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, KC_RGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, + KC_DEL, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(SYMB), TG(SYMB), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS, + KC_BSPC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(MDIA, KC_SCLN), GUI_T(KC_QUOT), + KC_LSFT, CTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, ALL_T(KC_NO), MEH_T(KC_NO), KC_N, KC_M, KC_COMM, KC_DOT, CTL_T(KC_SLSH), KC_RSFT, + LT(SYMB,KC_GRV), KC_QUOT, LALT(KC_LSFT), KC_LEFT, KC_RGHT, KC_UP, KC_DOWN, KC_LBRC, KC_RBRC, TT(SYMB), + ALT_T(KC_APP), KC_LGUI, KC_LALT, CTL_T(KC_ESC), + KC_HOME, KC_PGUP, + KC_SPC, KC_BSPC, KC_END, KC_PGDN, KC_TAB, KC_ENT +), +/* Keymap 1: Symbol Layer + * + * ,---------------------------------------------------. ,--------------------------------------------------. + * |Version | F1 | F2 | F3 | F4 | F5 | | | | F6 | F7 | F8 | F9 | F10 | F11 | + * |---------+------+------+------+------+------+------| |------+------+------+------+------+------+--------| + * | | ! | @ | { | } | | | | | | Up | 7 | 8 | 9 | * | F12 | + * |---------+------+------+------+------+------| | | |------+------+------+------+------+--------| + * | | # | $ | ( | ) | ` |------| |------| Down | 4 | 5 | 6 | + | | + * |---------+------+------+------+------+------| | | |------+------+------+------+------+--------| + * | | % | ^ | [ | ] | ~ | | | | & | 1 | 2 | 3 | \ | | + * `---------+------+------+------+------+-------------' `-------------+------+------+------+------+--------' + * | EPRM | | | | | | | . | 0 | = | | + * `-----------------------------------' `----------------------------------' + * ,-------------. ,-------------. + * |Animat| | |Toggle|Solid | + * ,------|------|------| |------+------+------. + * |Bright|Bright| | | |Hue- |Hue+ | + * |ness- |ness+ |------| |------| | | + * | | | | | | | | + * `--------------------' `--------------------' + */ +[SYMB] = LAYOUT_ergodox_pretty( + // left hand + VRSN, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRNS, KC_TRNS, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, + KC_TRNS, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRNS, KC_TRNS, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12, + KC_TRNS, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRV, KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRNS, + QK_BOOT, KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD, KC_TRNS, KC_TRNS, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLS, KC_TRNS, + EE_CLR, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_DOT, KC_0, KC_EQL, KC_TRNS, + RGB_MOD, KC_TRNS, RGB_TOG, RGB_M_P, + KC_TRNS, KC_TRNS, + RGB_VAD, RGB_VAI, KC_TRNS, KC_TRNS, RGB_HUD, RGB_HUI +), +/* Keymap 2: Media and mouse keys + * + * ,--------------------------------------------------. ,--------------------------------------------------. + * | | | | | | | | | | | | | | | | + * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------| + * | | | | MsUp | | | | | | | | | | | | + * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------| + * | | |MsLeft|MsDown|MsRght| |------| |------| | | | | | Play | + * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------| + * | | | | | | | | | | | | Prev | Next | | | + * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------' + * | | | | Lclk | Rclk | |VolUp |VolDn | Mute | | | + * `----------------------------------' `----------------------------------' + * ,-------------. ,-------------. + * | | | | | | + * ,------|------|------| |------+------+------. + * | | | | | | |Brwser| + * | | |------| |------| |Back | + * | | | | | | | | + * `--------------------' `--------------------' + */ +[MDIA] = LAYOUT_ergodox_pretty( + // left hand + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_MS_U, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_R, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_BTN2, KC_VOLU, KC_VOLD, KC_MUTE, KC_TRNS, KC_TRNS, + + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_WBAK +), +}; +// clang-format on + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + switch (keycode) { + case VRSN: + SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION); + return false; + } + } + return true; +} + +// Runs whenever there is a layer state change. +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(); + ergodox_right_led_3_off(); + + uint8_t layer = get_highest_layer(state); + switch (layer) { + case 0: + break; + case 1: + ergodox_right_led_1_on(); + break; + case 2: + ergodox_right_led_2_on(); + break; + case 3: + ergodox_right_led_3_on(); + break; + case 4: + ergodox_right_led_1_on(); + ergodox_right_led_2_on(); + break; + case 5: + ergodox_right_led_1_on(); + ergodox_right_led_3_on(); + break; + case 6: + ergodox_right_led_2_on(); + ergodox_right_led_3_on(); + break; + case 7: + ergodox_right_led_1_on(); + ergodox_right_led_2_on(); + ergodox_right_led_3_on(); + break; + default: + break; + } + + return state; +}; diff --git a/keyboards/zsa/ergodox_ez/keymaps/oryx/config.h b/keyboards/zsa/ergodox_ez/keymaps/oryx/config.h new file mode 100644 index 000000000000..1c7897be6c5c --- /dev/null +++ b/keyboards/zsa/ergodox_ez/keymaps/oryx/config.h @@ -0,0 +1,6 @@ +#pragma once + +#define LAYER_STATE_8BIT +#define FIRMWARE_VERSION u8"default/latest" +#define RAW_USAGE_PAGE 0xFF60 +#define RAW_USAGE_ID 0x61 diff --git a/keyboards/zsa/ergodox_ez/keymaps/oryx/keymap.c b/keyboards/zsa/ergodox_ez/keymaps/oryx/keymap.c new file mode 100644 index 000000000000..e7318adfc37c --- /dev/null +++ b/keyboards/zsa/ergodox_ez/keymaps/oryx/keymap.c @@ -0,0 +1,149 @@ +#include QMK_KEYBOARD_H +#include "version.h" +#include "keymap_german.h" +#include "keymap_nordic.h" +#include "keymap_french.h" +#include "keymap_spanish.h" +#include "keymap_hungarian.h" +#include "keymap_swedish.h" +#include "keymap_brazilian_abnt2.h" +#include "keymap_canadian_multilingual.h" +#include "keymap_swiss_de.h" +#include "keymap_japanese.h" + +#define KC_MAC_UNDO LGUI(KC_Z) +#define KC_MAC_CUT LGUI(KC_X) +#define KC_MAC_COPY LGUI(KC_C) +#define KC_MAC_PASTE LGUI(KC_V) +#define KC_PC_UNDO LCTL(KC_Z) +#define KC_PC_CUT LCTL(KC_X) +#define KC_PC_COPY LCTL(KC_C) +#define KC_PC_PASTE LCTL(KC_V) +#define ES_LESS_MAC KC_GRAVE +#define ES_GRTR_MAC LSFT(KC_GRAVE) +#define ES_BSLS_MAC ALGR(KC_6) + +enum custom_keycodes { + RGB_SLD = EZ_SAFE_RANGE, + HSV_172_255_255, + HSV_86_255_128, + HSV_27_255_255, +}; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [0] = LAYOUT_ergodox_pretty( + WEBUSB_PAIR, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT, KC_RIGHT, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINUS, + KC_DELETE, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(1), TG(1), KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLASH, + KC_BSPACE, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(2,KC_SCOLON),LGUI_T(KC_QUOTE), + KC_LSHIFT, LCTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_HYPR, KC_MEH, KC_N, KC_M, KC_COMMA, KC_DOT, RCTL_T(KC_SLASH),KC_RSHIFT, + LT(1,KC_GRAVE), KC_QUOTE, LALT(KC_LSHIFT),KC_LEFT, KC_RIGHT, KC_UP, KC_DOWN, KC_LBRACKET, KC_RBRACKET, MO(1), + LALT_T(KC_APPLICATION),KC_LGUI, KC_LALT, LCTL_T(KC_ESCAPE), + KC_HOME, KC_PGUP, + KC_SPACE, KC_BSPACE, KC_END, KC_PGDOWN, KC_TAB, KC_ENTER + ), + [1] = LAYOUT_ergodox_pretty( + KC_ESCAPE, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRANSPARENT, KC_TRANSPARENT, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, + KC_TRANSPARENT, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, KC_TRANSPARENT, KC_TRANSPARENT, KC_UP, KC_7, KC_8, KC_9, KC_ASTR, KC_F12, + KC_TRANSPARENT, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRAVE, KC_DOWN, KC_4, KC_5, KC_6, KC_PLUS, KC_TRANSPARENT, + KC_TRANSPARENT, KC_PERC, KC_CIRC, KC_LBRACKET, KC_RBRACKET, KC_TILD, KC_TRANSPARENT, KC_TRANSPARENT, KC_AMPR, KC_1, KC_2, KC_3, KC_BSLASH, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_DOT, KC_0, KC_EQUAL, KC_TRANSPARENT, + RGB_MOD, HSV_172_255_255,RGB_TOG, RGB_SLD, + HSV_86_255_128, KC_TRANSPARENT, + RGB_VAD, RGB_VAI, HSV_27_255_255, KC_TRANSPARENT, RGB_HUD, RGB_HUI + ), + [2] = LAYOUT_ergodox_pretty( + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_UP, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MEDIA_PLAY_PAUSE, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MEDIA_PREV_TRACK,KC_MEDIA_NEXT_TRACK,KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_MS_BTN1, KC_MS_BTN2, KC_AUDIO_VOL_UP,KC_AUDIO_VOL_DOWN,KC_AUDIO_MUTE, KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, + KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_TRANSPARENT, KC_WWW_BACK + ), +}; + + +bool suspended = false; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + switch (keycode) { +#ifdef RGBLIGHT_ENABLE + case RGB_SLD: + if (record->event.pressed) { + rgblight_mode(1); + } + return false; + case HSV_172_255_255: + if (record->event.pressed) { + #ifdef RGBLIGHT_ENABLE + rgblight_enable(); + rgblight_mode(1); + rgblight_sethsv(172,255,255); + #endif + } + return false; + case HSV_86_255_128: + if (record->event.pressed) { + #ifdef RGBLIGHT_ENABLE + rgblight_enable(); + rgblight_mode(1); + rgblight_sethsv(86,255,128); + #endif + } + return false; + case HSV_27_255_255: + if (record->event.pressed) { + #ifdef RGBLIGHT_ENABLE + rgblight_enable(); + rgblight_mode(1); + rgblight_sethsv(27,255,255); + #endif + } + return false; +#endif + } + return true; +} + +layer_state_t layer_state_set_user(layer_state_t state) { + + uint8_t layer = biton32(state); + + ergodox_board_led_off(); + ergodox_right_led_1_off(); + ergodox_right_led_2_off(); + ergodox_right_led_3_off(); + switch (layer) { + case 1: + ergodox_right_led_1_on(); + break; + case 2: + ergodox_right_led_2_on(); + break; + case 3: + ergodox_right_led_3_on(); + break; + case 4: + ergodox_right_led_1_on(); + ergodox_right_led_2_on(); + break; + case 5: + ergodox_right_led_1_on(); + ergodox_right_led_3_on(); + break; + case 6: + ergodox_right_led_2_on(); + ergodox_right_led_3_on(); + break; + case 7: + ergodox_right_led_1_on(); + ergodox_right_led_2_on(); + ergodox_right_led_3_on(); + break; + default: + break; + } + return state; + +}; diff --git a/keyboards/zsa/ergodox_ez/keymaps/oryx/rules.mk b/keyboards/zsa/ergodox_ez/keymaps/oryx/rules.mk new file mode 100644 index 000000000000..2f68136efc32 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/keymaps/oryx/rules.mk @@ -0,0 +1 @@ +ORYX_ENABLE = yes diff --git a/keyboards/zsa/ergodox_ez/ld/ergodox_ez.ld b/keyboards/zsa/ergodox_ez/ld/ergodox_ez.ld new file mode 100644 index 000000000000..86fd487a8cfa --- /dev/null +++ b/keyboards/zsa/ergodox_ez/ld/ergodox_ez.ld @@ -0,0 +1,85 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +/* + * STM32F303xC memory setup. + */ +MEMORY +{ + flash0 (rx) : org = 0x08002000, len = 128k - 0x2000 + flash1 (rx) : org = 0x00000000, len = 0 + flash2 (rx) : org = 0x00000000, len = 0 + flash3 (rx) : org = 0x00000000, len = 0 + flash4 (rx) : org = 0x00000000, len = 0 + flash5 (rx) : org = 0x00000000, len = 0 + flash6 (rx) : org = 0x00000000, len = 0 + flash7 (rx) : org = 0x00000000, len = 0 + ram0 (wx) : org = 0x20000000, len = 32k + ram1 (wx) : org = 0x00000000, len = 0 + ram2 (wx) : org = 0x00000000, len = 0 + ram3 (wx) : org = 0x00000000, len = 0 + ram4 (wx) : org = 0x10000000, len = 8k + ram5 (wx) : org = 0x00000000, len = 0 + ram6 (wx) : org = 0x00000000, len = 0 + ram7 (wx) : org = 0x00000000, len = 0 +} + +/* For each data/text section two region are defined, a virtual region + and a load region (_LMA suffix).*/ + +/* Flash region to be used for exception vectors.*/ +REGION_ALIAS("VECTORS_FLASH", flash0); +REGION_ALIAS("VECTORS_FLASH_LMA", flash0); + +/* Flash region to be used for constructors and destructors.*/ +REGION_ALIAS("XTORS_FLASH", flash0); +REGION_ALIAS("XTORS_FLASH_LMA", flash0); + +/* Flash region to be used for code text.*/ +REGION_ALIAS("TEXT_FLASH", flash0); +REGION_ALIAS("TEXT_FLASH_LMA", flash0); + +/* Flash region to be used for read only data.*/ +REGION_ALIAS("RODATA_FLASH", flash0); +REGION_ALIAS("RODATA_FLASH_LMA", flash0); + +/* Flash region to be used for various.*/ +REGION_ALIAS("VARIOUS_FLASH", flash0); +REGION_ALIAS("VARIOUS_FLASH_LMA", flash0); + +/* Flash region to be used for RAM(n) initialization data.*/ +REGION_ALIAS("RAM_INIT_FLASH_LMA", flash0); + +/* RAM region to be used for Main stack. This stack accommodates the processing + of all exceptions and interrupts.*/ +REGION_ALIAS("MAIN_STACK_RAM", ram0); + +/* RAM region to be used for the process stack. This is the stack used by + the main() function.*/ +REGION_ALIAS("PROCESS_STACK_RAM", ram0); + +/* RAM region to be used for data segment.*/ +REGION_ALIAS("DATA_RAM", ram0); +REGION_ALIAS("DATA_RAM_LMA", flash0); + +/* RAM region to be used for BSS segment.*/ +REGION_ALIAS("BSS_RAM", ram0); + +/* RAM region to be used for the default heap.*/ +REGION_ALIAS("HEAP_RAM", ram0); + +/* Generic rules inclusion.*/ +INCLUDE rules.ld diff --git a/keyboards/zsa/ergodox_ez/led_i2c.c b/keyboards/zsa/ergodox_ez/led_i2c.c new file mode 100644 index 000000000000..d246acfdde43 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/led_i2c.c @@ -0,0 +1,65 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifdef RGBLIGHT_ENABLE + +# include "ergodox_ez.h" + +void rgblight_call_driver(LED_TYPE *led, uint8_t led_num) { + uint16_t length = 0; + uint8_t i = 0; + uint8_t j = 0; +# ifdef RGBW + const uint8_t bytes_per_led = 4; +# else + const uint8_t bytes_per_led = 3; +# endif +# if defined(ERGODOX_LED_30) + // prevent right-half code from trying to bitbang all 30 + // so with 30 LEDs, we count from 29 to 15 here, and the + // other half does 0 to 14. + uint8_t half_led_num = RGBLED_NUM / 2; + length = half_led_num * bytes_per_led; + uint8_t data[length]; + for (i = half_led_num + half_led_num - 1; i >= half_led_num; --i) +# elif defined(ERGODOX_LED_15_MIRROR) + length = led_num * bytes_per_led; + uint8_t data[length]; + for (i = 0; i < led_num; ++i) +# else // ERGDOX_LED_15 non-mirrored + length = led_num * bytes_per_led; + uint8_t data[length]; + for (i = led_num - 1; i >= 0; --i) +# endif + { + uint8_t *data_byte = (uint8_t *)(led + i); + data[j++] = data_byte[0]; + data[j++] = data_byte[1]; + data[j++] = data_byte[2]; +# ifdef RGBW + data[j++] = data_byte[3]; +# endif + } + i2c_transmit(0x84, data, sizeof(data), ERGODOX_EZ_I2C_TIMEOUT); + + ws2812_setleds(led, led_num); +} + +#endif // RGBLIGHT_ENABLE diff --git a/keyboards/zsa/ergodox_ez/m32u4/base/info.json b/keyboards/zsa/ergodox_ez/m32u4/base/info.json new file mode 100644 index 000000000000..be1433ccbafd --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/base/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ", + "usb": { + "pid": "0x4974" + } +} diff --git a/keyboards/zsa/ergodox_ez/m32u4/base/rules.mk b/keyboards/zsa/ergodox_ez/m32u4/base/rules.mk new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/keyboards/zsa/ergodox_ez/m32u4/config.h b/keyboards/zsa/ergodox_ez/m32u4/config.h new file mode 100644 index 000000000000..7bdc54b92173 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/config.h @@ -0,0 +1,30 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#define MATRIX_ONBOARD_ROW_PINS { 0, 0, 0, 0, 0, 0, 0, B0, B1, B2, B3, D2, D3, C6 } +#define MATRIX_ONBOARD_COL_PINS { F0, F1, F4, F5, F6, F7 } + +#define ERGODOX_LED_1_PIN B5 +#define ERGODOX_LED_2_PIN B6 +#define ERGODOX_LED_3_PIN B7 + +#define ERGODOX_LED_SHUTOFF_PIN D6 diff --git a/keyboards/zsa/ergodox_ez/m32u4/glow/glow.h b/keyboards/zsa/ergodox_ez/m32u4/glow/glow.h new file mode 100644 index 000000000000..da7a6073efcc --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/glow/glow.h @@ -0,0 +1,23 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#include "ergodox_ez.h" diff --git a/keyboards/zsa/ergodox_ez/m32u4/glow/info.json b/keyboards/zsa/ergodox_ez/m32u4/glow/info.json new file mode 100644 index 000000000000..dcbb1999ca90 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/glow/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ Glow", + "usb": { + "pid": "0x4976" + } +} diff --git a/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/glow/keymap.c b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/glow/keymap.c new file mode 100644 index 000000000000..526c364029f7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/glow/keymap.c @@ -0,0 +1 @@ +// Placeholder. See ../default/keymap.c for details diff --git a/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/glow/rules.mk b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/glow/rules.mk new file mode 100644 index 000000000000..894a6a5e1339 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/glow/rules.mk @@ -0,0 +1,6 @@ +RGBLIGHT_ENABLE = no +RGB_MATRIX_ENABLE = IS31FL3731 # enable later + +SRC += keymaps/default/keymap.c + +LTO_ENABLE = yes diff --git a/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/config.h b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/config.h new file mode 100644 index 000000000000..6e86f8d9d048 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/config.h @@ -0,0 +1,12 @@ +#pragma once + +#define RGB_MATRIX_KEYPRESSES +#define RGB_MATRIX_FRAMEBUFFER_EFFECTS + +#define DISABLE_RGB_MATRIX_DIGITAL_RAIN +#define DISABLE_RGB_MATRIX_ALPHAS_MODS +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#define DISABLE_RGB_MATRIX_SPLASH +#define DISABLE_RGB_MATRIX_SOLID_SPLASH diff --git a/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/keymap.c b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/keymap.c new file mode 100644 index 000000000000..526c364029f7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/keymap.c @@ -0,0 +1 @@ +// Placeholder. See ../default/keymap.c for details diff --git a/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/rules.mk b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/rules.mk new file mode 100644 index 000000000000..21a5fb45ce84 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/glow/keymaps/reactive/rules.mk @@ -0,0 +1,7 @@ +RGBLIGHT_ENABLE = no +RGB_MATRIX_ENABLE = IS31FL3731 # enable later + +SRC += keymaps/default/keymap.c + +LTO_ENABLE = yes +COMMAND_ENABLE = no diff --git a/keyboards/zsa/ergodox_ez/m32u4/glow/rules.mk b/keyboards/zsa/ergodox_ez/m32u4/glow/rules.mk new file mode 100644 index 000000000000..aad92997d0fa --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/glow/rules.mk @@ -0,0 +1 @@ +RGB_MATRIX_ENABLE = yes diff --git a/keyboards/zsa/ergodox_ez/m32u4/info.json b/keyboards/zsa/ergodox_ez/m32u4/info.json new file mode 100644 index 000000000000..29282162536a --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/info.json @@ -0,0 +1,7 @@ +{ + "bootloader": "halfkay", + "processor": "atmega32u4", + "ws2812": { + "pin": "D7" + } +} diff --git a/keyboards/zsa/ergodox_ez/m32u4/m32u4.c b/keyboards/zsa/ergodox_ez/m32u4/m32u4.c new file mode 100644 index 000000000000..e899b5c332cf --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/m32u4.c @@ -0,0 +1,96 @@ +// Copyright 2023 Christopher Courtney, aka Drashna Jael're (@drashna) +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "ergodox_ez.h" + +void ergodox_right_led_1_set(uint8_t n) { + OCR1A = n; +} +void ergodox_right_led_2_set(uint8_t n) { + OCR1B = n; +} +void ergodox_right_led_3_set(uint8_t n) { + OCR1C = n; +} + +void keyboard_post_init_sub(void) { + // keyboard LEDs (see "PWM on ports OC1(A|B|C)" in "teensy-2-0.md") + TCCR1A = 0b10101001; // set and configure fast PWM + TCCR1B = 0b00001001; // set and configure fast PWM + + // (tied to Vcc for hardware convenience) + setPinInput(B4); + + // unused pins - C7, D4, D5, D7, E6 + // set as input with internal pull-up enabled + setPinInputHigh(C7); + setPinInputHigh(D4); + setPinInputHigh(D5); + setPinInputHigh(D7); + setPinInputHigh(E6); + + setPinOutput(ERGODOX_LED_1_PIN); + setPinOutput(ERGODOX_LED_2_PIN); + setPinOutput(ERGODOX_LED_3_PIN); +} + +#ifdef RGB_MATRIX_ENABLE +const is31_led PROGMEM g_is31_leds[RGB_MATRIX_LED_COUNT] = { +/* driver + * | R location + * | | G location + * | | | B location + * | | | | */ + {0, C3_1, C2_1, C4_1}, // LED1 on right + {0, C6_1, C5_1, C7_1}, // LED2 + {0, C4_2, C3_2, C5_2}, // LED3 + {0, C7_2, C6_2, C8_2}, // LED4 + {0, C2_3, C1_3, C3_3}, // LED5 + {0, C5_3, C4_3, C6_3}, // LED6 + {0, C8_3, C7_3, C9_3}, // LED7 + {0, C2_4, C1_4, C3_4}, // LED8 + {0, C6_4, C5_4, C7_4}, // LED9 + {0, C2_5, C1_5, C3_5}, // LED10 + {0, C7_5, C6_5, C8_5}, // LED11 + {0, C2_6, C1_6, C3_6}, // LED12 + {0, C5_6, C4_6, C6_6}, // LED13 + {0, C8_6, C7_6, C9_6}, // LED14 + {0, C2_7, C1_7, C3_7}, // LED15 + {0, C5_7, C4_7, C6_7}, // LED16 + {0, C2_8, C1_8, C3_8}, // LED17 + {0, C5_8, C4_8, C6_8}, // LED18 + + {0, C3_9, C2_9, C4_9}, // LED19 + {0, C6_9, C5_9, C7_9}, // LED20 + {0, C4_10, C3_10, C5_10}, // LED21 + {0, C7_10, C6_10, C8_10}, // LED22 + {0, C2_11, C1_11, C3_11}, // LED23 + {0, C5_11, C4_11, C6_11}, // LED24 + + {1, C3_1, C2_1, C4_1}, // LED1 on left + {1, C6_1, C5_1, C7_1}, // LED2 + {1, C4_2, C3_2, C5_2}, // LED3 + {1, C7_2, C6_2, C8_2}, // LED4 + {1, C2_3, C1_3, C3_3}, // LED5 + {1, C5_3, C4_3, C6_3}, // LED6 + {1, C8_3, C7_3, C9_3}, // LED7 + {1, C2_4, C1_4, C3_4}, // LED8 + {1, C6_4, C5_4, C7_4}, // LED9 + {1, C2_5, C1_5, C3_5}, // LED10 + {1, C7_5, C6_5, C8_5}, // LED11 + {1, C2_6, C1_6, C3_6}, // LED12 + {1, C5_6, C4_6, C6_6}, // LED13 + {1, C8_6, C7_6, C9_6}, // LED14 + {1, C2_7, C1_7, C3_7}, // LED15 + {1, C5_7, C4_7, C6_7}, // LED16 + {1, C2_8, C1_8, C3_8}, // LED17 + {1, C5_8, C4_8, C6_8}, // LED18 + + {1, C3_9, C2_9, C4_9}, // LED19 + {1, C6_9, C5_9, C7_9}, // LED20 + {1, C4_10, C3_10, C5_10}, // LED21 + {1, C7_10, C6_10, C8_10}, // LED22 + {1, C2_11, C1_11, C3_11}, // LED23 + {1, C5_11, C4_11, C6_11} // LED24 +}; +#endif diff --git a/keyboards/zsa/ergodox_ez/m32u4/rules.mk b/keyboards/zsa/ergodox_ez/m32u4/rules.mk new file mode 100644 index 000000000000..1df1d144615d --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/rules.mk @@ -0,0 +1 @@ +DEFAULT_FOLDER = zsa/ergodox_ez/m32u4/base diff --git a/keyboards/zsa/ergodox_ez/m32u4/shine/info.json b/keyboards/zsa/ergodox_ez/m32u4/shine/info.json new file mode 100644 index 000000000000..11c3a8b209b7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/shine/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ Shine", + "usb": { + "pid": "0x4975" + } +} diff --git a/keyboards/zsa/ergodox_ez/m32u4/shine/rules.mk b/keyboards/zsa/ergodox_ez/m32u4/shine/rules.mk new file mode 100644 index 000000000000..1e3cebb14515 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/shine/rules.mk @@ -0,0 +1 @@ +RGBLIGHT_ENABLE = yes diff --git a/keyboards/zsa/ergodox_ez/m32u4/shine/shine.h b/keyboards/zsa/ergodox_ez/m32u4/shine/shine.h new file mode 100644 index 000000000000..da7a6073efcc --- /dev/null +++ b/keyboards/zsa/ergodox_ez/m32u4/shine/shine.h @@ -0,0 +1,23 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#include "ergodox_ez.h" diff --git a/keyboards/zsa/ergodox_ez/matrix.c b/keyboards/zsa/ergodox_ez/matrix.c new file mode 100644 index 000000000000..5d19f08ea5fa --- /dev/null +++ b/keyboards/zsa/ergodox_ez/matrix.c @@ -0,0 +1,261 @@ +/* + +Note for ErgoDox EZ customizers: Here be dragons! +This is not a file you want to be messing with. +All of the interesting stuff for you is under keymaps/ :) +Love, Erez + +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + + +/* + * scan matrix + */ +#include "ergodox_ez.h" +#include "wait.h" +#include "action_layer.h" +#include "print.h" +#include "debug.h" +#include "i2c_master.h" +#include "gpio.h" +#include "atomic_util.h" + +/* + * This constant define not debouncing time in msecs, assuming eager_pr. + * + * On Ergodox matrix scan rate is relatively low, because of slow I2C. + * Now it's only 317 scans/second, or about 3.15 msec/scan. + * According to Cherry specs, debouncing time is 5 msec. + * + * However, some switches seem to have higher debouncing requirements, or + * something else might be wrong. (Also, the scan speed has improved since + * that comment was written.) + */ + +/* matrix state(1:on, 0:off) */ +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +static const pin_t onboard_row_pins[MATRIX_ROWS] = MATRIX_ONBOARD_ROW_PINS; +static const pin_t onboard_col_pins[MATRIX_COLS] = MATRIX_ONBOARD_COL_PINS; +static const bool row_expanded[MATRIX_ROWS] = ROWS_EXPANDED; + +static void init_cols(void); +static matrix_row_t read_cols(uint8_t row); +static void unselect_rows(void); +static void select_row(uint8_t row); +static void unselect_row(uint8_t row); + +static uint8_t mcp23018_reset_loop; +i2c_status_t mcp23018_status = 0x20; +static bool i2c_initialized = false; + +#ifdef RGBLIGHT_ENABLE +extern bool i2c_rgblight; +#endif + +#define MCP23018_IODIRA 0x00 // i/o direction register +#define MCP23018_IODIRB 0x01 +#define MCP23018_GPPUA 0x0C // GPIO pull-up resistor register +#define MCP23018_GPPUB 0x0D +#define MCP23018_GPIOA 0x12 // general purpose i/o port register (write modifies OLAT) +#define MCP23018_GPIOB 0x13 +#define MCP23018_OLATA 0x14 // output latch register +#define MCP23018_OLATB 0x15 + + +uint8_t init_mcp23018(void) { + mcp23018_status = 0x20; + + if (!i2c_initialized) { + i2c_init(); // on pins D(1,0) + i2c_initialized = true; + wait_ms(1000); + } + + // set pin direction + // - unused : input : 1 + // - input : input : 1 + // - driving : output : 0 + uint8_t buf[] = {0b00000000, 0b00111111}; + mcp23018_status = i2c_writeReg(MCP23018_EXPANDER_I2C_ADDR, MCP23018_IODIRA, buf, sizeof(buf), ERGODOX_EZ_I2C_TIMEOUT); + + if (!mcp23018_status) { + // set pull-up + // - unused : on : 1 + // - input : on : 1 + // - driving : off : 0 + mcp23018_status = i2c_writeReg(MCP23018_EXPANDER_I2C_ADDR, MCP23018_GPPUA, buf, sizeof(buf), ERGODOX_EZ_I2C_TIMEOUT); + } + + return mcp23018_status; +} + +void matrix_init_custom(void) { + // initialize row and col + + mcp23018_status = init_mcp23018(); + + unselect_rows(); + init_cols(); +} + +// Reads and stores a row, returning +// whether a change occurred. +static inline bool store_raw_matrix_row(uint8_t index) { + matrix_row_t temp = 0x3F & read_cols(index); + if (raw_matrix[index] != temp) { + raw_matrix[index] = temp; + return true; + } + return false; +} + +bool matrix_scan_custom(matrix_row_t current_matrix[]) { + if (mcp23018_status) { // if there was an error + if (++mcp23018_reset_loop == 0) { + print("trying to reset mcp23018\n"); + mcp23018_status = init_mcp23018(); + if (mcp23018_status) { + print("left side not responding\n"); + } else { + print("left side attached\n"); + wait_ms(200); + mcu_reset(); + } + } + } + + bool changed = false; + for (uint8_t i = 0; i < MATRIX_ROWS_PER_SIDE; i++) { + // select rows from left and right hands + uint8_t left_index = i; + uint8_t right_index = i + MATRIX_ROWS_PER_SIDE; + select_row(left_index); + select_row(right_index); + + changed |= store_raw_matrix_row(left_index); + changed |= store_raw_matrix_row(right_index); + + unselect_rows(); + } + + return changed; +} + +static void init_cols(void) { + // init on mcp23018 + // not needed, already done as part of init_mcp23018() + + for (uint8_t x = 0; x < MATRIX_COLS; x++) { + ATOMIC_BLOCK_FORCEON { + setPinInputHigh(onboard_col_pins[x]); + } + } +} + +static matrix_row_t read_cols(uint8_t row) { + if (row < MATRIX_ROWS_PER_SIDE) { + if (mcp23018_status) { // if there was an error + return 0; + } else { + uint8_t data = 0; + // reading GPIOB (column port) since in mcp23018's sequential mode + // it is addressed directly after writing to GPIOA in select_row() + mcp23018_status = i2c_readReg(MCP23018_EXPANDER_I2C_ADDR, EXPANDER_COL_REGISTER, &data, 1, ERGODOX_EZ_I2C_TIMEOUT); + return ~data; + } + } else { + select_row(row); + matrix_row_t current_row_value = 0; + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + // Select the col pin to read (active low) + uint8_t pin_state = readPin(onboard_col_pins[col_index]); + + // Populate the matrix row with the state of the col pin + current_row_value |= pin_state ? 0 : ((matrix_row_t)1 << col_index); + } + unselect_row(row); + return current_row_value; + } +} + +/* Row pin configuration + * + * Teensy + * row: 7 8 9 10 11 12 13 + * pin: B0 B1 B2 B3 D2 D3 C6 + * + * MCP23018 + * row: 0 1 2 3 4 5 6 + * pin: A0 A1 A2 A3 A4 A5 A6 + */ +static void unselect_rows(void) { + // no need to unselect on mcp23018, because the select step sets all + // the other row bits high, and it's not changing to a different + // direction + + for (uint8_t row_index = MATRIX_ROWS_PER_SIDE; row_index < MATRIX_ROWS; row_index++) { + if (!row_expanded[row_index]) { + unselect_row(row_index); + } + } +} + +static void unselect_row(uint8_t row) { + if (!row_expanded[row]) { + ATOMIC_BLOCK_FORCEON { + setPinInputHigh(onboard_row_pins[row]); + } + } +} + +static void select_row(uint8_t row) { + if (row < 7) { + // select on mcp23018 + if (!mcp23018_status) { + // set active row low : 0 + // set other rows hi-Z : 1 + uint8_t data; + data = 0xFF & ~(1 << row); + mcp23018_status = i2c_writeReg(MCP23018_EXPANDER_I2C_ADDR, EXPANDER_ROW_REGISTER, &data, 1, ERGODOX_EZ_I2C_TIMEOUT); + } + } else { + // select on teensy + // Output low(DDR:1, PORT:0) to select + if (!row_expanded[row]) { + ATOMIC_BLOCK_FORCEON { + setPinOutput(onboard_row_pins[row]); + writePinLow(onboard_row_pins[row]); + } + } + } +} + +// DO NOT REMOVE +// Needed for proper wake/sleep +void matrix_power_up(void) { + matrix_init_custom(); + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + } + +} diff --git a/keyboards/zsa/ergodox_ez/mcuconf.h b/keyboards/zsa/ergodox_ez/mcuconf.h new file mode 100644 index 000000000000..f75edce3e9b7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/mcuconf.h @@ -0,0 +1,23 @@ +/* Copyright 2021 QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include_next + +// for i2c expander, and ISSI +#undef STM32_I2C_USE_I2C1 +#define STM32_I2C_USE_I2C1 TRUE diff --git a/keyboards/zsa/ergodox_ez/post_config.h b/keyboards/zsa/ergodox_ez/post_config.h new file mode 100644 index 000000000000..5fc0d83440dd --- /dev/null +++ b/keyboards/zsa/ergodox_ez/post_config.h @@ -0,0 +1,44 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#if !defined(ERGODOX_LED_15) && !defined(ERGODOX_LED_30) +// if no value is defined, assume previous behavior +// # define ERGODOX_LED_15 +// # define ERGODOX_LED_30 +# define ERGODOX_LED_15_MIRROR +#endif + +#if (defined(ERGODOX_LED_30) + defined(ERGODOX_LED_15) + defined(ERGODOX_LED_15_MIRROR)) != 1 +# error "You must only define one of the ERGODOX_LED options." +#endif + +#ifdef ERGODOX_LED_30 +// If using 30 LEDs, then define that many +# define RGBLED_NUM 30 // Number of LEDs +#else +// If not, then only define 15 +# define RGBLED_NUM 15 // Number of LEDs +#endif + +#ifndef ISSI_TIMEOUT +# define ISSI_TIMEOUT 3 +#endif diff --git a/keyboards/zsa/ergodox_ez/readme.md b/keyboards/zsa/ergodox_ez/readme.md new file mode 100644 index 000000000000..acdfd8c1c49a --- /dev/null +++ b/keyboards/zsa/ergodox_ez/readme.md @@ -0,0 +1,27 @@ +# zsa/ergodox_ + +![zsa/ergodox_](imgur.com image replace me!) + +*A short description of the keyboard/project* + +* Keyboard Maintainer: [Drashna Jael're](https://github.com/Drashna Jael're) +* Hardware Supported: *The PCBs, controllers supported* +* Hardware Availability: *Links to where you can find this hardware* + +Make example for this keyboard (after setting up your build environment): + + make zsa/ergodox_:default + +Flashing example for this keyboard: + + make zsa/ergodox_:default:flash + +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). + +## Bootloader + +Enter the bootloader in 3 ways: + +* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard +* **Physical reset button**: Briefly press the button on the back of the PCB - some may have pads you must short instead +* **Keycode in layout**: Press the key mapped to `QK_BOOT` if it is available diff --git a/keyboards/zsa/ergodox_ez/rgb_matrix_kb.inc b/keyboards/zsa/ergodox_ez/rgb_matrix_kb.inc new file mode 100644 index 000000000000..8dbd24e90ffd --- /dev/null +++ b/keyboards/zsa/ergodox_ez/rgb_matrix_kb.inc @@ -0,0 +1,26 @@ +#ifdef RGB_MATRIX_ENABLE +RGB_MATRIX_EFFECT(oryx_webhid_effect) +# ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +RGB webhid_leds[RGB_MATRIX_LED_COUNT]; + +static bool oryx_webhid_effect_run(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + uint8_t val = rgb_matrix_get_val() * 100 / 175; + if(val == 0) { + rgb_matrix_set_color_all(0, 0, 0); + } + else { + for (uint8_t i = led_min; i < led_max; ++i) { + rgb_matrix_set_color(i, webhid_leds[i].r * val / 100, webhid_leds[i].g * val / 100, webhid_leds[i].b * val / 100); + } + } + return rgb_matrix_check_finished_leds(led_max); +} + +static bool oryx_webhid_effect(effect_params_t* params) { + return oryx_webhid_effect_run(params); +} + +# endif +#endif diff --git a/keyboards/zsa/ergodox_ez/rules.mk b/keyboards/zsa/ergodox_ez/rules.mk new file mode 100644 index 000000000000..19088af9a318 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/rules.mk @@ -0,0 +1,12 @@ + +CUSTOM_MATRIX = lite + +#project specific files +SRC += matrix.c \ + led_i2c.c + +QUANTUM_LIB_SRC += i2c_master.c + +MOUSE_SHARED_EP = no + +DEFAULT_FOLDER = zsa/ergodox_ez/m32u4/base diff --git a/keyboards/zsa/ergodox_ez/stm32/base/info.json b/keyboards/zsa/ergodox_ez/stm32/base/info.json new file mode 100644 index 000000000000..1e4b1ac9cd85 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/base/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ", + "usb": { + "pid": "0x2030" + } +} diff --git a/keyboards/zsa/ergodox_ez/stm32/base/rules.mk b/keyboards/zsa/ergodox_ez/stm32/base/rules.mk new file mode 100644 index 000000000000..8ce4c0654328 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/base/rules.mk @@ -0,0 +1,2 @@ +DFU_SUFFIX_ARGS = -v 3297 -p 2002 +DFU_ARGS = -d 3297:2002 -a 0 -s 0x08002000:leave diff --git a/keyboards/zsa/ergodox_ez/stm32/config.h b/keyboards/zsa/ergodox_ez/stm32/config.h new file mode 100644 index 000000000000..34185a7e69e2 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/config.h @@ -0,0 +1,42 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#define MATRIX_ONBOARD_ROW_PINS \ + { 0, 0, 0, 0, 0, 0, 0, A7, A6, A5, A4, A3, A2, A1 } +#define MATRIX_ONBOARD_COL_PINS \ + { B15, B14, B13, B12, B11, B10 } + +#ifdef REMAPPED_LEDS +# define ERGODOX_LED_1_PIN B0 +# define ERGODOX_LED_2_PIN B1 +# define ERGODOX_LED_3_PIN B4 +#else +# define ERGODOX_LED_1_PIN B5 +# define ERGODOX_LED_2_PIN B4 +# define ERGODOX_LED_3_PIN B3 + +# define WS2812_PWM_DRIVER PWMD16 +# define WS2812_PWM_CHANNEL 1 +# define WS2812_PWM_PAL_MODE 1 +# define WS2812_DMA_STREAM STM32_DMA1_STREAM3 +# define WS2812_DMA_CHANNEL 3 +#endif diff --git a/keyboards/zsa/ergodox_ez/stm32/glow/glow.h b/keyboards/zsa/ergodox_ez/stm32/glow/glow.h new file mode 100644 index 000000000000..da7a6073efcc --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/glow/glow.h @@ -0,0 +1,23 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#include "ergodox_ez.h" diff --git a/keyboards/zsa/ergodox_ez/stm32/glow/info.json b/keyboards/zsa/ergodox_ez/stm32/glow/info.json new file mode 100644 index 000000000000..5ae73959764f --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/glow/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ Glow", + "usb": { + "pid": "0x2010" + } +} diff --git a/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/glow/keymap.c b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/glow/keymap.c new file mode 100644 index 000000000000..526c364029f7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/glow/keymap.c @@ -0,0 +1 @@ +// Placeholder. See ../default/keymap.c for details diff --git a/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/glow/rules.mk b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/glow/rules.mk new file mode 100644 index 000000000000..894a6a5e1339 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/glow/rules.mk @@ -0,0 +1,6 @@ +RGBLIGHT_ENABLE = no +RGB_MATRIX_ENABLE = IS31FL3731 # enable later + +SRC += keymaps/default/keymap.c + +LTO_ENABLE = yes diff --git a/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/config.h b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/config.h new file mode 100644 index 000000000000..6e86f8d9d048 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/config.h @@ -0,0 +1,12 @@ +#pragma once + +#define RGB_MATRIX_KEYPRESSES +#define RGB_MATRIX_FRAMEBUFFER_EFFECTS + +#define DISABLE_RGB_MATRIX_DIGITAL_RAIN +#define DISABLE_RGB_MATRIX_ALPHAS_MODS +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#define DISABLE_RGB_MATRIX_SPLASH +#define DISABLE_RGB_MATRIX_SOLID_SPLASH diff --git a/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/keymap.c b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/keymap.c new file mode 100644 index 000000000000..526c364029f7 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/keymap.c @@ -0,0 +1 @@ +// Placeholder. See ../default/keymap.c for details diff --git a/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/rules.mk b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/rules.mk new file mode 100644 index 000000000000..21a5fb45ce84 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/glow/keymaps/reactive/rules.mk @@ -0,0 +1,7 @@ +RGBLIGHT_ENABLE = no +RGB_MATRIX_ENABLE = IS31FL3731 # enable later + +SRC += keymaps/default/keymap.c + +LTO_ENABLE = yes +COMMAND_ENABLE = no diff --git a/keyboards/zsa/ergodox_ez/stm32/glow/rules.mk b/keyboards/zsa/ergodox_ez/stm32/glow/rules.mk new file mode 100644 index 000000000000..e4038c797a94 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/glow/rules.mk @@ -0,0 +1,3 @@ +RGB_MATRIX_ENABLE = yes +DFU_SUFFIX_ARGS = -v 3297 -p 2000 +DFU_ARGS = -d 3297:2000 -a 0 -s 0x08002000:leave diff --git a/keyboards/zsa/ergodox_ez/stm32/halconf.h b/keyboards/zsa/ergodox_ez/stm32/halconf.h new file mode 100644 index 000000000000..a1ccc060eb51 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/halconf.h @@ -0,0 +1,21 @@ +/* Copyright 2021 QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#define HAL_USE_I2C TRUE +#define HAL_USE_PWM TRUE + +#include_next diff --git a/keyboards/zsa/ergodox_ez/stm32/info.json b/keyboards/zsa/ergodox_ez/stm32/info.json new file mode 100644 index 000000000000..651ce01e1002 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/info.json @@ -0,0 +1,8 @@ +{ + "bootloader": "custom", + "processor": "STM32F303", + "ws2812": { + "pin": "B8", + "driver": "pwm" + } +} diff --git a/keyboards/zsa/ergodox_ez/stm32/mcuconf.h b/keyboards/zsa/ergodox_ez/stm32/mcuconf.h new file mode 100644 index 000000000000..296029dc9b20 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/mcuconf.h @@ -0,0 +1,31 @@ +/* Copyright 2021 QMK + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include_next + +#ifdef REMAPPED_LEDS +# undef STM32_PWM_USE_TIM3 +# define STM32_PWM_USE_TIM3 TRUE +#else +# undef STM32_PWM_USE_TIM8 +# define STM32_PWM_USE_TIM8 TRUE +# undef STM32_PWM_USE_TIM16 +# define STM32_PWM_USE_TIM16 TRUE +# undef STM32_PWM_USE_ADVANCED +# define STM32_PWM_USE_ADVANCED TRUE +#endif diff --git a/keyboards/zsa/ergodox_ez/stm32/post_rules.mk b/keyboards/zsa/ergodox_ez/stm32/post_rules.mk new file mode 100644 index 000000000000..23a2fd735a5f --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/post_rules.mk @@ -0,0 +1,9 @@ +ifeq ($(strip $(BOOTLOADER)), custom) + MCU_LDSCRIPT = ergodox_ez + PROGRAM_CMD = $(call EXEC_DFU) +else + # boards ship with ignition but for drashna's sanity during testing, we'll + # make sure that we can use stm32-dfu as well + DFU_SUFFIX_ARGS = -v 0483 -p df11 + DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000:leave +endif diff --git a/keyboards/zsa/ergodox_ez/stm32/rules.mk b/keyboards/zsa/ergodox_ez/stm32/rules.mk new file mode 100644 index 000000000000..fb7f8a18cfc5 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/rules.mk @@ -0,0 +1 @@ +DEFAULT_FOLDER = zsa/ergodox_ez/stm32/base diff --git a/keyboards/zsa/ergodox_ez/stm32/shine/info.json b/keyboards/zsa/ergodox_ez/stm32/shine/info.json new file mode 100644 index 000000000000..8a265511dccf --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/shine/info.json @@ -0,0 +1,6 @@ +{ + "keyboard_name": "ErgoDox EZ Shine", + "usb": { + "pid": "0x2020" + } +} diff --git a/keyboards/zsa/ergodox_ez/stm32/shine/rules.mk b/keyboards/zsa/ergodox_ez/stm32/shine/rules.mk new file mode 100644 index 000000000000..fd829f5b3e61 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/shine/rules.mk @@ -0,0 +1,3 @@ +RGBLIGHT_ENABLE = yes +DFU_SUFFIX_ARGS = -v 3297 -p 2001 +DFU_ARGS = -d 3297:2001 -a 0 -s 0x08002000:leave diff --git a/keyboards/zsa/ergodox_ez/stm32/shine/shine.h b/keyboards/zsa/ergodox_ez/stm32/shine/shine.h new file mode 100644 index 000000000000..da7a6073efcc --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/shine/shine.h @@ -0,0 +1,23 @@ +/* +Copyright 2012 Jun Wako +Copyright 2013 Oleg Kostyuk +Copyright 2015 ZSA Technology Labs Inc (@zsa) +Copyright 2020 Christopher Courtney (@drashna) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#pragma once + +#include "ergodox_ez.h" diff --git a/keyboards/zsa/ergodox_ez/stm32/stm32.c b/keyboards/zsa/ergodox_ez/stm32/stm32.c new file mode 100644 index 000000000000..02cf882324d0 --- /dev/null +++ b/keyboards/zsa/ergodox_ez/stm32/stm32.c @@ -0,0 +1,177 @@ +// Copyright 2023 Christopher Courtney, aka Drashna Jael're (@drashna) +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "ergodox_ez.h" +#include +#include + +static uint16_t cie_lightness(uint16_t v) { + if (v <= 5243) // if below 8% of max + return v / 9; // same as dividing by 900% + else { + uint32_t y = (((uint32_t)v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare + // to get a useful result with integer division, we shift left in the expression above + // and revert what we've done again after squaring. + y = y * y * y >> 8; + if (y > 0xFFFFUL) // prevent overflow + return 0xFFFFU; + else + return (uint16_t)y; + } +} + +// clang-format off +static PWMConfig pwmCFG = { + .frequency = 0xFFFF, + .period = 256, + .callback = NULL, + .channels = { +#ifdef REMAPPED_LEDS + { .mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB4 + { .mode = PWM_OUTPUT_DISABLED, .callback = NULL}, + { .mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB0 + { .mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL} // PB1 +#else + { .mode = PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB3 + { .mode = PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB4 + { .mode = PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // PB5 + { .mode = PWM_OUTPUT_DISABLED, .callback = NULL} +#endif + }, + .cr2 = 0, + .dier = TIM_DIER_UDE +}; +// clang-format on + + +static uint32_t ergodox_right_led_1_duty; +static uint32_t ergodox_right_led_2_duty; +static uint32_t ergodox_right_led_3_duty; + +void ergodox_right_led_1_on(void) { +#ifdef REMAPPED_LEDS + pwmEnableChannel(&PWMD3, 2, PWM_FRACTION_TO_WIDTH(&PWMD3, 0xFFFF, ergodox_right_led_1_duty)); +#else + pwmEnableChannel(&PWMD8, 2, PWM_FRACTION_TO_WIDTH(&PWMD8, 0xFFFF, ergodox_right_led_1_duty)); +#endif +} + +void ergodox_right_led_1_off(void) { +#ifdef REMAPPED_LEDS + pwmDisableChannel(&PWMD3, 2); +#else + pwmDisableChannel(&PWMD8, 2); +#endif +} + +void ergodox_right_led_1_set(uint8_t level) { + ergodox_right_led_1_duty = (uint32_t)(cie_lightness(0xFFFF * (uint32_t)level / 255)); + if (level == 0) { + ergodox_right_led_1_off(); + } else { + ergodox_right_led_1_on(); + } +} + +void ergodox_right_led_2_on(void) { +#ifdef REMAPPED_LEDS + pwmEnableChannel(&PWMD3, 3, PWM_FRACTION_TO_WIDTH(&PWMD3, 0xFFFF, ergodox_right_led_2_duty)); +#else + pwmEnableChannel(&PWMD8, 1, PWM_FRACTION_TO_WIDTH(&PWMD8, 0xFFFF, ergodox_right_led_2_duty)); +#endif +} + +void ergodox_right_led_2_off(void) { +#ifdef REMAPPED_LEDS + pwmDisableChannel(&PWMD3, 3); +#else + pwmDisableChannel(&PWMD8, 1); +#endif +} + +void ergodox_right_led_2_set(uint8_t level) { + ergodox_right_led_2_duty = (uint32_t)(cie_lightness(0xFFFF * (uint32_t)level / 255)); + if (level == 0) { + ergodox_right_led_2_off(); + } else { + ergodox_right_led_2_on(); + } +} + +void ergodox_right_led_3_on(void) { +#ifdef REMAPPED_LEDS + pwmEnableChannel(&PWMD3, 0, PWM_FRACTION_TO_WIDTH(&PWMD3, 0xFFFF, ergodox_right_led_3_duty)); +#else + pwmEnableChannel(&PWMD8, 0, PWM_FRACTION_TO_WIDTH(&PWMD8, 0xFFFF, ergodox_right_led_3_duty)); +#endif +} +void ergodox_right_led_3_off(void) { +#ifdef REMAPPED_LEDS + pwmDisableChannel(&PWMD3, 0); +#else + pwmDisableChannel(&PWMD8, 0); +#endif +} + +void ergodox_right_led_3_set(uint8_t level) { + ergodox_right_led_3_duty = (uint32_t)(cie_lightness(0xFFFF * (uint32_t)level / 255)); + if (level == 0) { + ergodox_right_led_3_off(); + } else { + ergodox_right_led_3_on(); + } +} + +void keyboard_post_init_sub(void) { +#ifdef REMAPPED_LEDS + pwmStart(&PWMD3, &pwmCFG); + palSetPadMode(GPIOB, 0, PAL_MODE_ALTERNATE(2) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); + palSetPadMode(GPIOB, 1, PAL_MODE_ALTERNATE(2) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); + palSetPadMode(GPIOB, 4, PAL_MODE_ALTERNATE(2) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); +#else + pwmStart(&PWMD8, &pwmCFG); + palSetPadMode(GPIOB, 5, PAL_MODE_ALTERNATE(3) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); + palSetPadMode(GPIOB, 4, PAL_MODE_ALTERNATE(4) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); + palSetPadMode(GPIOB, 3, PAL_MODE_ALTERNATE(4) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST | PAL_PUPDR_FLOATING); +#endif + + + ergodox_right_led_1_set((uint8_t)keyboard_config.led_level * 255 / 4); + ergodox_right_led_2_set((uint8_t)keyboard_config.led_level * 255 / 4); + ergodox_right_led_3_set((uint8_t)keyboard_config.led_level * 255 / 4); + + ergodox_right_led_1_off(); + ergodox_right_led_2_off(); + ergodox_right_led_3_off(); +} + +#ifdef BOOTLOADER_CUSTOM +#define APP_ADDRESS 0x08002000 +__attribute__((weak)) void bootloader_jump(void) { + // The ignition bootloader is checking for a high signal on A8 for 100ms when powering on the board. + // Setting both A8 and A9 high will charge the capacitor quickly. + // Setting A9 low before reset will cause the capacitor to discharge + // thus making the bootloder unlikely to trigger twice between power cycles. + setPinOutputPushPull(A9); + setPinOutputPushPull(A8); + writePinHigh(A9); + writePinHigh(A8); + wait_ms(500); + writePinLow(A9); + + NVIC_SystemReset(); +} + +__attribute__((weak)) void mcu_reset(void) { + // When resetting the MCU, we want to jump to the application. + SCB->AIRCR = APP_ADDRESS & 0xFFFF; + + // Set the stack pointer to the applications stack pointer + __asm__ volatile("msr msp, %0" ::"g"(*(volatile uint32_t *)APP_ADDRESS)); + + // Jump to the application + (*(void (**)())(APP_ADDRESS + 4))(); + while (1) + ; +} +#endif