Skip to content

Commit

Permalink
Fix Ergodox Indicator LEDs (#402)
Browse files Browse the repository at this point in the history
* Revert "fix: shine led indicator brightness"

This reverts commit 0b6f7f9.

* Cleanup leds

* Confirm working on AVR and ARM
  • Loading branch information
drashna authored Nov 26, 2024
1 parent 0b6f7f9 commit 4ae6ea9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 64 deletions.
31 changes: 19 additions & 12 deletions keyboards/zsa/ergodox_ez/ergodox_ez.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "ergodox_ez.h"
#include "bootmagic.h"
#include "gpio.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);
gpio_set_pin_output(ERGODOX_LED_1_PIN);
gpio_set_pin_output(ERGODOX_LED_2_PIN);
gpio_set_pin_output(ERGODOX_LED_3_PIN);
}

void keyboard_post_init_kb(void) {
keyboard_post_init_sub();
#ifdef ERGODOX_LED_SHUTOFF_PIN
setPinOutput(ERGODOX_LED_SHUTOFF_PIN);
gpio_set_pin_output(ERGODOX_LED_SHUTOFF_PIN);
#endif

keyboard_config.raw = eeconfig_read_kb();
Expand All @@ -49,25 +50,28 @@ void keyboard_post_init_kb(void) {

void ergodox_board_led_on(void) {
#ifdef ERGODOX_LED_SHUTOFF_PIN
writePinHigh(ERGODOX_LED_SHUTOFF_PIN);
gpio_write_pin_high(ERGODOX_LED_SHUTOFF_PIN);
#endif
}

__attribute__((weak)) void ergodox_right_led_1_on(void) {
writePinHigh(ERGODOX_LED_1_PIN);
gpio_set_pin_output(ERGODOX_LED_1_PIN);
gpio_write_pin_high(ERGODOX_LED_1_PIN);
}

__attribute__((weak)) void ergodox_right_led_2_on(void) {
writePinHigh(ERGODOX_LED_2_PIN);
gpio_set_pin_output(ERGODOX_LED_2_PIN);
gpio_write_pin_high(ERGODOX_LED_2_PIN);
}

__attribute__((weak)) void ergodox_right_led_3_on(void) {
writePinHigh(ERGODOX_LED_3_PIN);
gpio_set_pin_output(ERGODOX_LED_3_PIN);
gpio_write_pin_high(ERGODOX_LED_3_PIN);
}

void ergodox_board_led_off(void) {
#ifdef ERGODOX_LED_SHUTOFF_PIN
writePinLow(ERGODOX_LED_SHUTOFF_PIN);
gpio_write_pin_low(ERGODOX_LED_SHUTOFF_PIN);
#else
ergodox_right_led_1_off();
ergodox_right_led_2_off();
Expand All @@ -76,15 +80,18 @@ void ergodox_board_led_off(void) {
}

__attribute__((weak)) void ergodox_right_led_1_off(void) {
setPinInput(ERGODOX_LED_1_PIN);
gpio_set_pin_input(ERGODOX_LED_1_PIN);
gpio_write_pin_low(ERGODOX_LED_1_PIN);
}

__attribute__((weak)) void ergodox_right_led_2_off(void) {
setPinInput(ERGODOX_LED_2_PIN);
gpio_set_pin_input(ERGODOX_LED_2_PIN);
gpio_write_pin_low(ERGODOX_LED_2_PIN);
}

__attribute__((weak)) void ergodox_right_led_3_off(void) {
setPinInput(ERGODOX_LED_3_PIN);
gpio_set_pin_input(ERGODOX_LED_3_PIN);
gpio_write_pin_low(ERGODOX_LED_3_PIN);
}

void ergodox_right_led_on(uint8_t led) {
Expand Down
4 changes: 2 additions & 2 deletions keyboards/zsa/ergodox_ez/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
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),
LT(SYMB,KC_GRV), KC_QUOT, LALT(KC_LSFT), KC_LEFT, KC_RGHT, KC_UP, KC_DOWN, KC_LBRC, LED_LEVEL, 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
Expand Down Expand Up @@ -72,7 +72,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
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,
EE_CLR, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_DOT, KC_0, KC_TRNS, 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
Expand Down
72 changes: 22 additions & 50 deletions keyboards/zsa/ergodox_ez/m32u4/m32u4.c
Original file line number Diff line number Diff line change
@@ -1,83 +1,55 @@
// Copyright 2023 Christopher Courtney, aka Drashna Jael're (@drashna) <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later

#include <stdint.h>
#include "ergodox_ez.h"

static uint8_t ergodox_right_led_1_duty;
static uint8_t ergodox_right_led_2_duty;
static uint8_t ergodox_right_led_3_duty;

void ergodox_right_led_1_set(uint8_t n) {
ergodox_right_led_1_duty = n;
if (ergodox_right_led_1_duty == 0) {
ergodox_right_led_1_off();
} else {
ergodox_right_led_1_on();
}
OCR1A = n;
}

void ergodox_right_led_1_on(void) {
OCR1A = ergodox_right_led_1_duty;
void ergodox_right_led_2_set(uint8_t n) {
OCR1B = n;
}

void ergodox_right_led_1_off(void) {
OCR1A = 0;
void ergodox_right_led_3_set(uint8_t n) {
OCR1C = n;
}

void ergodox_right_led_2_set(uint8_t n) {
ergodox_right_led_2_duty = n;
if (ergodox_right_led_2_duty == 0) {
ergodox_right_led_2_off();
} else {
ergodox_right_led_2_on();
}
__attribute__((weak)) void ergodox_right_led_1_on(void) {
gpio_write_pin_high(ERGODOX_LED_1_PIN);
}

void ergodox_right_led_2_on(void) {
OCR1B = ergodox_right_led_2_duty;
__attribute__((weak)) void ergodox_right_led_2_on(void) {
gpio_write_pin_high(ERGODOX_LED_2_PIN);
}

void ergodox_right_led_2_off(void) {
OCR1B = 0;
__attribute__((weak)) void ergodox_right_led_3_on(void) {
gpio_write_pin_high(ERGODOX_LED_3_PIN);
}

void ergodox_right_led_3_set(uint8_t n) {
ergodox_right_led_3_duty = n;
if (ergodox_right_led_3_duty == 0) {
ergodox_right_led_3_off();
} else {
ergodox_right_led_3_on();
}
__attribute__((weak)) void ergodox_right_led_1_off(void) {
gpio_write_pin_low(ERGODOX_LED_1_PIN);
}

void ergodox_right_led_3_off(void) {
OCR1C = 0;
__attribute__((weak)) void ergodox_right_led_2_off(void) {
gpio_write_pin_low(ERGODOX_LED_2_PIN);
}

void ergodox_right_led_3_on(void) {
OCR1C = ergodox_right_led_3_duty;
__attribute__((weak)) void ergodox_right_led_3_off(void) {
gpio_write_pin_low(ERGODOX_LED_3_PIN);
}


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);
gpio_set_pin_input(B4);

// unused pins - C7, D4, D5, E6
// set as input with internal pull-up enabled
setPinInputHigh(C7);
setPinInputHigh(D4);
setPinInputHigh(D5);
setPinInputHigh(E6);

setPinOutput(ERGODOX_LED_1_PIN);
setPinOutput(ERGODOX_LED_2_PIN);
setPinOutput(ERGODOX_LED_3_PIN);
gpio_set_pin_input_high(C7);
gpio_set_pin_input_high(D4);
gpio_set_pin_input_high(D5);
gpio_set_pin_input_high(E6);
}

#ifdef RGB_MATRIX_ENABLE
Expand Down

0 comments on commit 4ae6ea9

Please sign in to comment.