diff options
Diffstat (limited to 'keyboards/ergodox_ez/led_i2c.c')
| -rw-r--r-- | keyboards/ergodox_ez/led_i2c.c | 86 |
1 files changed, 86 insertions, 0 deletions
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 | ||
