]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/exclusive/e6v2/bmc/bmc.c
[Keyboard] revert back to the old custom i2c code for bmc (#5501)
[qmk_firmware.git] / keyboards / exclusive / e6v2 / bmc / bmc.c
1 /* Copyright 2019 MechMerlin
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 "bmc.h"
17 #include "rgblight.h"
18 #include "i2c.h"
19
20 void matrix_init_kb(void) {
21         // put your keyboard start-up code here
22         // runs once when the firmware starts up
23
24         matrix_init_user();
25 }
26
27 void matrix_scan_kb(void) {
28         // put your looping keyboard code here
29         // runs every cycle (a lot)
30
31         matrix_scan_user();
32 }
33
34 bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
35         // put your per-action keyboard code here
36         // runs for every action, just before processing by the firmware
37
38         return process_record_user(keycode, record);
39 }
40
41 void led_set_kb(uint8_t usb_led) {
42         // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
43
44         led_set_user(usb_led);
45 }
46
47 #ifdef RGBLIGHT_ENABLE
48 extern rgblight_config_t rgblight_config;
49
50 void rgblight_set(void) {
51     if (!rgblight_config.enable) {
52         for (uint8_t i = 0; i < RGBLED_NUM; i++) {
53             led[i].r = 0;
54             led[i].g = 0;
55             led[i].b = 0;
56         }
57     }
58
59     i2c_init();
60     i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
61 }
62 #endif
63
64 __attribute__ ((weak))
65 void matrix_scan_user(void) {
66 }
67
68 void backlight_init_ports(void) {
69     // initialize pins D0, D1, D4 and D6 as output
70     setPinOutput(D0);
71     setPinOutput(D1);
72     setPinOutput(D4);
73     setPinOutput(D6);
74
75     // turn RGB LEDs on
76     writePinHigh(D0);
77     writePinHigh(D1);
78     writePinHigh(D4);
79     writePinHigh(D6);
80 }
81
82 void backlight_set(uint8_t level) {
83         if (level == 0) {
84         // turn RGB LEDs off
85         writePinLow(D0);
86         writePinLow(D1);
87         writePinLow(D4);
88         writePinLow(D6);
89         } else {
90         // turn RGB LEDs on
91         writePinHigh(D0);
92         writePinHigh(D1);
93         writePinHigh(D4);
94         writePinHigh(D6);
95         }
96 }