]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/model01/leds.c
Keyboard: add Keyboardio Model 01 (#3900)
[qmk_firmware.git] / keyboards / model01 / leds.c
1 /* Copyright 2018 James Laird-Wah
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16 #include <quantum.h>
17 #include <i2c_master.h>
18 #include <led_tables.h>
19 #include "model01.h"
20
21 #define I2C_TIMEOUT     1000
22
23 #define LINCOR(i) pgm_read_byte(&CIE1931_CURVE[i])
24
25 int set_all_leds_to_raw(uint8_t r, uint8_t g, uint8_t b) {
26   uint8_t buf[] = {
27     TWI_CMD_LED_SET_ALL_TO,
28     b, g, r
29   };
30   int ret = 0;
31   ret |= i2c_transmit(I2C_ADDR(LEFT), buf, sizeof(buf), I2C_TIMEOUT);
32   ret |= i2c_transmit(I2C_ADDR(RIGHT), buf, sizeof(buf), I2C_TIMEOUT);
33   _delay_us(10);
34   return ret;
35 }
36
37 int set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
38   return set_all_leds_to_raw(LINCOR(r), LINCOR(g), LINCOR(b));
39 }
40
41 int set_led_to_raw(uint8_t led, uint8_t r, uint8_t g, uint8_t b) {
42   uint8_t buf[] = {
43     TWI_CMD_LED_SET_ONE_TO,
44     led & 0x1f,
45     b, g, r
46   };
47   int hand = (led >= 32) ? RIGHT : LEFT;
48   int ret = i2c_transmit(I2C_ADDR(hand), buf, sizeof(buf), I2C_TIMEOUT);
49   _delay_us(10);
50   return ret;
51 }
52
53 int set_led_to(uint8_t led, uint8_t r, uint8_t g, uint8_t b) {
54   return set_led_to_raw(led, LINCOR(r), LINCOR(g), LINCOR(b));
55 }
56
57 /* vim: set ts=2 sw=2 et: */