diff options
| author | Drashna Jaelre <drashna@live.com> | 2019-11-14 12:00:51 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-14 12:00:51 -0800 |
| commit | 1cf63a193be50b14ecd33ee1c6eb5e470640e084 (patch) | |
| tree | 59b7f70cdd02f8ca767de9400499b9c86686ab91 /keyboards | |
| parent | 8dc9764f31ce3326b2f5fd1a3bea216e86cf4734 (diff) | |
| download | qmk_firmware-1cf63a193be50b14ecd33ee1c6eb5e470640e084.tar.gz qmk_firmware-1cf63a193be50b14ecd33ee1c6eb5e470640e084.zip | |
Move Ergodox EZ RGB Light code to custom driver (#7309)
* Move Ergodox EZ RGB code to custom driver
Also implements full addressing of Ergodox EZ's LED Strip, as written by seebs
Co-authored-by: Seebs <seebs@seebs.net>
* Make Clipping range accessible for custom drivers
* Remove RGBW_BB_TWI from driver and docs
* Revert changes to clipping range support
* Use just rgblight_set instead of full custom driver
* Convert to i2c_master commands
* Rename rgblight driver and clean up includes
Diffstat (limited to 'keyboards')
| -rw-r--r-- | keyboards/ergodox_ez/config.h | 12 | ||||
| -rw-r--r-- | keyboards/ergodox_ez/led_i2c.c | 86 | ||||
| -rw-r--r-- | keyboards/ergodox_ez/post_config.h | 20 | ||||
| -rw-r--r-- | keyboards/ergodox_ez/rules.mk | 5 |
4 files changed, 118 insertions, 5 deletions
diff --git a/keyboards/ergodox_ez/config.h b/keyboards/ergodox_ez/config.h index bb51ec321..e60101e5e 100644 --- a/keyboards/ergodox_ez/config.h +++ b/keyboards/ergodox_ez/config.h | |||
| @@ -75,17 +75,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 75 | /* ws2812 RGB LED */ | 75 | /* ws2812 RGB LED */ |
| 76 | #define RGB_DI_PIN D7 | 76 | #define RGB_DI_PIN D7 |
| 77 | #define RGBLIGHT_ANIMATIONS | 77 | #define RGBLIGHT_ANIMATIONS |
| 78 | #define RGBLED_NUM 15 // Number of LEDs | ||
| 79 | #define RGBLIGHT_HUE_STEP 12 | 78 | #define RGBLIGHT_HUE_STEP 12 |
| 80 | #define RGBLIGHT_SAT_STEP 255 | 79 | #define RGBLIGHT_SAT_STEP 255 |
| 81 | #define RGBLIGHT_VAL_STEP 12 | 80 | #define RGBLIGHT_VAL_STEP 12 |
| 82 | 81 | ||
| 82 | // Pick one of the modes | ||
| 83 | // Defaults to 15 mirror, for legacy behavior | ||
| 84 | |||
| 85 | // #define ERGODOX_LED_15 // Addresses 15 LEDs, but same position on both halves | ||
| 86 | // #define ERGODOX_LED_15_MIRROR // Addresses 15 LEDs, but are mirrored | ||
| 87 | // #define ERGODOX_LED_30 // Addresses all 30 LED individually | ||
| 88 | |||
| 83 | /* fix space cadet rollover issue */ | 89 | /* fix space cadet rollover issue */ |
| 84 | #define DISABLE_SPACE_CADET_ROLLOVER | 90 | #define DISABLE_SPACE_CADET_ROLLOVER |
| 85 | 91 | ||
| 86 | #define RGBW_BB_TWI | 92 | #define RGBW |
| 87 | |||
| 88 | #define RGBW 1 | ||
| 89 | 93 | ||
| 90 | #define RGBLIGHT_SLEEP | 94 | #define RGBLIGHT_SLEEP |
| 91 | 95 | ||
diff --git a/keyboards/ergodox_ez/led_i2c.c b/keyboards/ergodox_ez/led_i2c.c new file mode 100644 index 000000000..3e75a8cd0 --- /dev/null +++ b/keyboards/ergodox_ez/led_i2c.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* | ||
| 2 | * light weight WS2812 lib V2.0b | ||
| 3 | * | ||
| 4 | * Controls WS2811/WS2812/WS2812B RGB-LEDs | ||
| 5 | * Author: Tim (cpldcpu@gmail.com) | ||
| 6 | * | ||
| 7 | * Jan 18th, 2014 v2.0b Initial Version | ||
| 8 | * Nov 29th, 2015 v2.3 Added SK6812RGBW support | ||
| 9 | * | ||
| 10 | * This program is free software: you can redistribute it and/or modify | ||
| 11 | * it under the terms of the GNU General Public License as published by | ||
| 12 | * the Free Software Foundation, either version 2 of the License, or | ||
| 13 | * (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, | ||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | * GNU General Public License for more details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU General Public License | ||
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 22 | */ | ||
| 23 | #ifdef RGBLIGHT_ENABLE | ||
| 24 | |||
| 25 | # include "ws2812.c" | ||
| 26 | # include "ergodox_ez.h" | ||
| 27 | |||
| 28 | extern rgblight_config_t rgblight_config; | ||
| 29 | |||
| 30 | /* | ||
| 31 | * Forward declare internal functions | ||
| 32 | * | ||
| 33 | * The functions take a byte-array and send to the data output as WS2812 bitstream. | ||
| 34 | * The length is the number of bytes to send - three per LED. | ||
| 35 | */ | ||
| 36 | |||
| 37 | void ws2812_sendarray(uint8_t *array, uint16_t length); | ||
| 38 | void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask); | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | void rgblight_set(void) { | ||
| 44 | if (!rgblight_config.enable) { | ||
| 45 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | ||
| 46 | led[i].r = 0; | ||
| 47 | led[i].g = 0; | ||
| 48 | led[i].b = 0; | ||
| 49 | #ifdef RGBW | ||
| 50 | led[i].w = 0; | ||
| 51 | #endif | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | uint8_t led_num = RGBLED_NUM; | ||
| 57 | i2c_init(); | ||
| 58 | i2c_start(0x84, ERGODOX_EZ_I2C_TIMEOUT); | ||
| 59 | int i = 0; | ||
| 60 | # if defined(ERGODOX_LED_30) | ||
| 61 | // prevent right-half code from trying to bitbang all 30 | ||
| 62 | // so with 30 LEDs, we count from 29 to 15 here, and the | ||
| 63 | // other half does 0 to 14. | ||
| 64 | led_num = RGBLED_NUM / 2; | ||
| 65 | for (i = led_num + led_num - 1; i >= led_num; --i) | ||
| 66 | # elif defined(ERGODOX_LED_15_MIRROR) | ||
| 67 | for (i = 0; i < led_num; ++i) | ||
| 68 | # else // ERGDOX_LED_15 non-mirrored | ||
| 69 | for (i = led_num - 1; i >= 0; --i) | ||
| 70 | # endif | ||
| 71 | { | ||
| 72 | uint8_t *data = (uint8_t *)(led + i); | ||
| 73 | i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT); | ||
| 74 | i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT); | ||
| 75 | i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT); | ||
| 76 | #ifdef RGBW | ||
| 77 | i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT); | ||
| 78 | #endif | ||
| 79 | } | ||
| 80 | i2c_stop(); | ||
| 81 | |||
| 82 | ws2812_setleds(led, RGBLED_NUM); | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | #endif // RGBLIGHT_ENABLE | ||
diff --git a/keyboards/ergodox_ez/post_config.h b/keyboards/ergodox_ez/post_config.h new file mode 100644 index 000000000..526cc8c41 --- /dev/null +++ b/keyboards/ergodox_ez/post_config.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #if !defined(ERGODOX_LED_15) && !defined(ERGODOX_LED_30) | ||
| 4 | // if no value is defined, assume previous behavior | ||
| 5 | // # define ERGODOX_LED_15 | ||
| 6 | // # define ERGODOX_LED_30 | ||
| 7 | # define ERGODOX_LED_15_MIRROR | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #if (defined(ERGODOX_LED_30) + defined(ERGODOX_LED_15) + defined(ERGODOX_LED_15_MIRROR)) != 1 | ||
| 11 | # error "You must only define one of the ERGODOX_LED options." | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #ifdef ERGODOX_LED_30 | ||
| 15 | // If using 30 LEDs, then define that many | ||
| 16 | # define RGBLED_NUM 30 // Number of LEDs | ||
| 17 | #else | ||
| 18 | // If not, then only define 15 | ||
| 19 | # define RGBLED_NUM 15 // Number of LEDs | ||
| 20 | #endif | ||
diff --git a/keyboards/ergodox_ez/rules.mk b/keyboards/ergodox_ez/rules.mk index dbc35f683..fd8f5722d 100644 --- a/keyboards/ergodox_ez/rules.mk +++ b/keyboards/ergodox_ez/rules.mk | |||
| @@ -31,11 +31,14 @@ SWAP_HANDS_ENABLE= yes # Allow swapping hands of keyboard | |||
| 31 | SLEEP_LED_ENABLE = no | 31 | SLEEP_LED_ENABLE = no |
| 32 | API_SYSEX_ENABLE = no | 32 | API_SYSEX_ENABLE = no |
| 33 | RGBLIGHT_ENABLE = yes | 33 | RGBLIGHT_ENABLE = yes |
| 34 | RGBLIGHT_CUSTOM_DRIVER = yes | ||
| 35 | |||
| 34 | RGB_MATRIX_ENABLE = no # enable later | 36 | RGB_MATRIX_ENABLE = no # enable later |
| 35 | DEBOUNCE_TYPE = eager_pr | 37 | DEBOUNCE_TYPE = eager_pr |
| 36 | 38 | ||
| 37 | # project specific files | 39 | # project specific files |
| 38 | SRC += matrix.c | 40 | SRC += matrix.c \ |
| 41 | led_i2c.c | ||
| 39 | QUANTUM_LIB_SRC += i2c_master.c | 42 | QUANTUM_LIB_SRC += i2c_master.c |
| 40 | 43 | ||
| 41 | LAYOUTS = ergodox | 44 | LAYOUTS = ergodox |
