diff options
52 files changed, 138 insertions, 2539 deletions
diff --git a/keyboards/bfake/bfake.c b/keyboards/bfake/bfake.c index 2160706fe..f7d006576 100644 --- a/keyboards/bfake/bfake.c +++ b/keyboards/bfake/bfake.c | |||
@@ -16,51 +16,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "bfake.h" | 18 | #include "bfake.h" |
19 | #ifdef BACKLIGHT_ENABLE | ||
20 | #include "backlight.h" | ||
21 | #endif | ||
22 | #ifdef RGBLIGHT_ENABLE | ||
23 | #include "rgblight.h" | ||
24 | #endif | ||
25 | |||
26 | #include <avr/pgmspace.h> | ||
27 | |||
28 | #include "action_layer.h" | ||
29 | #include "i2c.h" | ||
30 | #include "quantum.h" | ||
31 | |||
32 | #ifdef RGBLIGHT_ENABLE | ||
33 | extern rgblight_config_t rgblight_config; | ||
34 | |||
35 | void rgblight_set(void) { | ||
36 | if (!rgblight_config.enable) { | ||
37 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | ||
38 | led[i].r = 0; | ||
39 | led[i].g = 0; | ||
40 | led[i].b = 0; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | i2c_init(); | ||
45 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
46 | } | ||
47 | #endif | ||
48 | 19 | ||
49 | __attribute__ ((weak)) | 20 | __attribute__ ((weak)) |
50 | void matrix_scan_user(void) { | 21 | void matrix_scan_user(void) {} |
51 | } | ||
52 | 22 | ||
53 | void backlight_init_ports(void) { | 23 | void backlight_init_ports(void) { |
54 | DDRD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); | 24 | setPinOutput(D0); |
55 | PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); | 25 | setPinOutput(D1); |
26 | setPinOutput(D4); | ||
27 | setPinOutput(D6); | ||
28 | |||
29 | writePinLow(D0); | ||
30 | writePinLow(D1); | ||
31 | writePinLow(D4); | ||
32 | writePinLow(D6); | ||
56 | } | 33 | } |
57 | 34 | ||
58 | void backlight_set(uint8_t level) { | 35 | void backlight_set(uint8_t level) { |
59 | if (level == 0) { | 36 | if (level == 0) { |
60 | // Turn out the lights | 37 | // Turn out the lights |
61 | PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); | 38 | writePinLow(D0); |
39 | writePinLow(D1); | ||
40 | writePinLow(D4); | ||
41 | writePinLow(D6); | ||
62 | } else { | 42 | } else { |
63 | // Turn on the lights | 43 | // Turn on the lights |
64 | PORTD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); | 44 | writePinHigh(D0); |
45 | writePinHigh(D1); | ||
46 | writePinHigh(D4); | ||
47 | writePinHigh(D6); | ||
65 | } | 48 | } |
66 | } | 49 | } |
diff --git a/keyboards/bfake/i2c.c b/keyboards/bfake/i2c.c deleted file mode 100644 index a4f952135..000000000 --- a/keyboards/bfake/i2c.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #include <avr/io.h> | ||
21 | #include <util/twi.h> | ||
22 | |||
23 | #include "i2c.h" | ||
24 | |||
25 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
26 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
27 | if (bitrate_div >= 16) { | ||
28 | bitrate_div = (bitrate_div - 16) / 2; | ||
29 | } | ||
30 | TWBR = bitrate_div; | ||
31 | } | ||
32 | |||
33 | void i2c_init(void) { | ||
34 | // set pull-up resistors on I2C bus pins | ||
35 | PORTC |= 0b11; | ||
36 | |||
37 | i2c_set_bitrate(400); | ||
38 | |||
39 | // enable TWI (two-wire interface) | ||
40 | TWCR |= (1 << TWEN); | ||
41 | |||
42 | // enable TWI interrupt and slave address ACK | ||
43 | TWCR |= (1 << TWIE); | ||
44 | TWCR |= (1 << TWEA); | ||
45 | } | ||
46 | |||
47 | uint8_t i2c_start(uint8_t address) { | ||
48 | // reset TWI control register | ||
49 | TWCR = 0; | ||
50 | |||
51 | // begin transmission and wait for it to end | ||
52 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
53 | while (!(TWCR & (1<<TWINT))); | ||
54 | |||
55 | // check if the start condition was successfully transmitted | ||
56 | if ((TWSR & 0xF8) != TW_START) { | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | // transmit address and wait | ||
61 | TWDR = address; | ||
62 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
63 | while (!(TWCR & (1<<TWINT))); | ||
64 | |||
65 | // check if the device has acknowledged the READ / WRITE mode | ||
66 | uint8_t twst = TW_STATUS & 0xF8; | ||
67 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
68 | return 1; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | void i2c_stop(void) { | ||
75 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
76 | } | ||
77 | |||
78 | uint8_t i2c_write(uint8_t data) { | ||
79 | TWDR = data; | ||
80 | |||
81 | // transmit data and wait | ||
82 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
83 | while (!(TWCR & (1<<TWINT))); | ||
84 | |||
85 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
86 | return 1; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
93 | if (i2c_start(address)) { | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | for (uint16_t i = 0; i < length; i++) { | ||
98 | if (i2c_write(data[i])) { | ||
99 | return 1; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | i2c_stop(); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
diff --git a/keyboards/bfake/i2c.h b/keyboards/bfake/i2c.h deleted file mode 100644 index 93a69c94d..000000000 --- a/keyboards/bfake/i2c.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #ifndef __I2C_H__ | ||
21 | #define __I2C_H__ | ||
22 | |||
23 | void i2c_init(void); | ||
24 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
25 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
26 | |||
27 | #endif | ||
diff --git a/keyboards/bfake/rules.mk b/keyboards/bfake/rules.mk index b5b3b852c..5963c9810 100644 --- a/keyboards/bfake/rules.mk +++ b/keyboards/bfake/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -34,10 +19,10 @@ CONSOLE_ENABLE = yes | |||
34 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
35 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = no |
36 | RGBLIGHT_ENABLE = no | 21 | RGBLIGHT_ENABLE = no |
37 | RGBLIGHT_CUSTOM_DRIVER = yes | 22 | WS2812_DRIVER = i2c |
38 | 23 | ||
39 | OPT_DEFS = -DDEBUG_LEVEL=0 | 24 | OPT_DEFS = -DDEBUG_LEVEL=0 |
40 | 25 | ||
41 | # custom matrix setup | 26 | # custom matrix setup |
42 | CUSTOM_MATRIX = yes | 27 | CUSTOM_MATRIX = yes |
43 | SRC = matrix.c i2c.c | 28 | SRC = matrix.c |
diff --git a/keyboards/jc65/v32a/i2c.c b/keyboards/jc65/v32a/i2c.c deleted file mode 100644 index a4f952135..000000000 --- a/keyboards/jc65/v32a/i2c.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #include <avr/io.h> | ||
21 | #include <util/twi.h> | ||
22 | |||
23 | #include "i2c.h" | ||
24 | |||
25 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
26 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
27 | if (bitrate_div >= 16) { | ||
28 | bitrate_div = (bitrate_div - 16) / 2; | ||
29 | } | ||
30 | TWBR = bitrate_div; | ||
31 | } | ||
32 | |||
33 | void i2c_init(void) { | ||
34 | // set pull-up resistors on I2C bus pins | ||
35 | PORTC |= 0b11; | ||
36 | |||
37 | i2c_set_bitrate(400); | ||
38 | |||
39 | // enable TWI (two-wire interface) | ||
40 | TWCR |= (1 << TWEN); | ||
41 | |||
42 | // enable TWI interrupt and slave address ACK | ||
43 | TWCR |= (1 << TWIE); | ||
44 | TWCR |= (1 << TWEA); | ||
45 | } | ||
46 | |||
47 | uint8_t i2c_start(uint8_t address) { | ||
48 | // reset TWI control register | ||
49 | TWCR = 0; | ||
50 | |||
51 | // begin transmission and wait for it to end | ||
52 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
53 | while (!(TWCR & (1<<TWINT))); | ||
54 | |||
55 | // check if the start condition was successfully transmitted | ||
56 | if ((TWSR & 0xF8) != TW_START) { | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | // transmit address and wait | ||
61 | TWDR = address; | ||
62 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
63 | while (!(TWCR & (1<<TWINT))); | ||
64 | |||
65 | // check if the device has acknowledged the READ / WRITE mode | ||
66 | uint8_t twst = TW_STATUS & 0xF8; | ||
67 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
68 | return 1; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | void i2c_stop(void) { | ||
75 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
76 | } | ||
77 | |||
78 | uint8_t i2c_write(uint8_t data) { | ||
79 | TWDR = data; | ||
80 | |||
81 | // transmit data and wait | ||
82 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
83 | while (!(TWCR & (1<<TWINT))); | ||
84 | |||
85 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
86 | return 1; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
93 | if (i2c_start(address)) { | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | for (uint16_t i = 0; i < length; i++) { | ||
98 | if (i2c_write(data[i])) { | ||
99 | return 1; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | i2c_stop(); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
diff --git a/keyboards/jc65/v32a/i2c.h b/keyboards/jc65/v32a/i2c.h deleted file mode 100644 index 93a69c94d..000000000 --- a/keyboards/jc65/v32a/i2c.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #ifndef __I2C_H__ | ||
21 | #define __I2C_H__ | ||
22 | |||
23 | void i2c_init(void); | ||
24 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
25 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
26 | |||
27 | #endif | ||
diff --git a/keyboards/jc65/v32a/rules.mk b/keyboards/jc65/v32a/rules.mk index ee6efb3fa..18e7f1de9 100644 --- a/keyboards/jc65/v32a/rules.mk +++ b/keyboards/jc65/v32a/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -34,10 +19,10 @@ CONSOLE_ENABLE = yes | |||
34 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
35 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
36 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
37 | RGBLIGHT_CUSTOM_DRIVER = yes | 22 | WS2812_DRIVER = i2c |
38 | 23 | ||
39 | OPT_DEFS = -DDEBUG_LEVEL=0 | 24 | OPT_DEFS = -DDEBUG_LEVEL=0 |
40 | 25 | ||
41 | # custom matrix setup | 26 | # custom matrix setup |
42 | CUSTOM_MATRIX = yes | 27 | CUSTOM_MATRIX = yes |
43 | SRC = matrix.c i2c.c | 28 | SRC = matrix.c |
diff --git a/keyboards/jc65/v32a/v32a.c b/keyboards/jc65/v32a/v32a.c index 8176ade0a..9b1e07274 100644 --- a/keyboards/jc65/v32a/v32a.c +++ b/keyboards/jc65/v32a/v32a.c | |||
@@ -16,56 +16,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "v32a.h" | 18 | #include "v32a.h" |
19 | #ifdef BACKLIGHT_ENABLE | ||
20 | #include "backlight.h" | ||
21 | #endif | ||
22 | #ifdef RGBLIGHT_ENABLE | ||
23 | #include "rgblight.h" | ||
24 | #endif | ||
25 | |||
26 | #include <avr/pgmspace.h> | ||
27 | |||
28 | #include "action_layer.h" | ||
29 | #include "i2c.h" | ||
30 | #include "quantum.h" | ||
31 | |||
32 | #ifdef RGBLIGHT_ENABLE | ||
33 | extern rgblight_config_t rgblight_config; | ||
34 | |||
35 | void rgblight_set(void) { | ||
36 | if (!rgblight_config.enable) { | ||
37 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | ||
38 | led[i].r = 0; | ||
39 | led[i].g = 0; | ||
40 | led[i].b = 0; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | i2c_init(); | ||
45 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
46 | } | ||
47 | #endif | ||
48 | 19 | ||
49 | __attribute__ ((weak)) | 20 | __attribute__ ((weak)) |
50 | void matrix_scan_user(void) { | 21 | void matrix_scan_user(void) {} |
51 | #ifdef RGBLIGHT_ENABLE | ||
52 | rgblight_task(); | ||
53 | #endif | ||
54 | } | ||
55 | 22 | ||
56 | #ifdef BACKLIGHT_ENABLE | 23 | #ifdef BACKLIGHT_ENABLE |
57 | void backlight_init_ports(void) { | 24 | void backlight_init_ports(void) { |
58 | DDRD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); | 25 | setPinOutput(D0); |
59 | PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); | 26 | setPinOutput(D1); |
27 | setPinOutput(D4); | ||
28 | setPinOutput(D6); | ||
29 | |||
30 | writePinLow(D0); | ||
31 | writePinLow(D1); | ||
32 | writePinLow(D4); | ||
33 | writePinLow(D6); | ||
60 | } | 34 | } |
61 | 35 | ||
62 | void backlight_set(uint8_t level) { | 36 | void backlight_set(uint8_t level) { |
63 | if (level == 0) { | 37 | if (level == 0) { |
64 | // Turn out the lights | 38 | // Turn out the lights |
65 | PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); | 39 | writePinLow(D0); |
40 | writePinLow(D1); | ||
41 | writePinLow(D4); | ||
42 | writePinLow(D6); | ||
66 | } else { | 43 | } else { |
67 | // Turn on the lights | 44 | // Turn on the lights |
68 | PORTD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); | 45 | writePinHigh(D0); |
46 | writePinHigh(D1); | ||
47 | writePinHigh(D4); | ||
48 | writePinHigh(D6); | ||
69 | } | 49 | } |
70 | } | 50 | } |
71 | #endif | 51 | #endif |
diff --git a/keyboards/jj50/i2c.c b/keyboards/jj50/i2c.c deleted file mode 100644 index c27f3e3d1..000000000 --- a/keyboards/jj50/i2c.c +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <avr/io.h> | ||
19 | #include <util/twi.h> | ||
20 | |||
21 | #include "i2c.h" | ||
22 | |||
23 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
24 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
25 | if (bitrate_div >= 16) { | ||
26 | bitrate_div = (bitrate_div - 16) / 2; | ||
27 | } | ||
28 | TWBR = bitrate_div; | ||
29 | } | ||
30 | |||
31 | void i2c_init(void) { | ||
32 | // set pull-up resistors on I2C bus pins | ||
33 | PORTC |= 0b11; | ||
34 | |||
35 | i2c_set_bitrate(400); | ||
36 | |||
37 | // enable TWI (two-wire interface) | ||
38 | TWCR |= (1 << TWEN); | ||
39 | |||
40 | // enable TWI interrupt and slave address ACK | ||
41 | TWCR |= (1 << TWIE); | ||
42 | TWCR |= (1 << TWEA); | ||
43 | } | ||
44 | |||
45 | uint8_t i2c_start(uint8_t address) { | ||
46 | // reset TWI control register | ||
47 | TWCR = 0; | ||
48 | |||
49 | // begin transmission and wait for it to end | ||
50 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
51 | while (!(TWCR & (1<<TWINT))); | ||
52 | |||
53 | // check if the start condition was successfully transmitted | ||
54 | if ((TWSR & 0xF8) != TW_START) { | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | // transmit address and wait | ||
59 | TWDR = address; | ||
60 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
61 | while (!(TWCR & (1<<TWINT))); | ||
62 | |||
63 | // check if the device has acknowledged the READ / WRITE mode | ||
64 | uint8_t twst = TW_STATUS & 0xF8; | ||
65 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | void i2c_stop(void) { | ||
73 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
74 | } | ||
75 | |||
76 | uint8_t i2c_write(uint8_t data) { | ||
77 | TWDR = data; | ||
78 | |||
79 | // transmit data and wait | ||
80 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
81 | while (!(TWCR & (1<<TWINT))); | ||
82 | |||
83 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
91 | if (i2c_start(address)) { | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | for (uint16_t i = 0; i < length; i++) { | ||
96 | if (i2c_write(data[i])) { | ||
97 | return 1; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | i2c_stop(); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
diff --git a/keyboards/jj50/i2c.h b/keyboards/jj50/i2c.h deleted file mode 100644 index 27c9d3d05..000000000 --- a/keyboards/jj50/i2c.h +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef __I2C_H__ | ||
19 | #define __I2C_H__ | ||
20 | |||
21 | void i2c_init(void); | ||
22 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
23 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
24 | |||
25 | #endif | ||
diff --git a/keyboards/jj50/jj50.c b/keyboards/jj50/jj50.c index d4a70f68d..7c3cee95d 100644 --- a/keyboards/jj50/jj50.c +++ b/keyboards/jj50/jj50.c | |||
@@ -17,24 +17,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
17 | 17 | ||
18 | #include "jj50.h" | 18 | #include "jj50.h" |
19 | 19 | ||
20 | #include <avr/pgmspace.h> | ||
21 | |||
22 | #include "action_layer.h" | ||
23 | #include "i2c.h" | ||
24 | #include "quantum.h" | ||
25 | |||
26 | #include "backlight.h" | 20 | #include "backlight.h" |
27 | #include "backlight_custom.h" | 21 | #include "backlight_custom.h" |
28 | 22 | ||
29 | // for keyboard subdirectory level init functions | 23 | void matrix_init_kb(void) { matrix_init_user(); } |
30 | // @Override | 24 | |
31 | void matrix_init_kb(void) { | 25 | __attribute__ ((weak)) |
32 | // call user level keymaps, if any | 26 | void matrix_init_user(void) {} |
33 | matrix_init_user(); | 27 | |
34 | } | 28 | void matrix_scan_kb(void) { matrix_scan_user(); } |
29 | |||
30 | __attribute__ ((weak)) | ||
31 | void matrix_scan_user(void) {} | ||
35 | 32 | ||
36 | #ifdef BACKLIGHT_ENABLE | 33 | #ifdef BACKLIGHT_ENABLE |
37 | /// Overrides functions in `quantum.c` | ||
38 | void backlight_init_ports(void) { | 34 | void backlight_init_ports(void) { |
39 | b_led_init_ports(); | 35 | b_led_init_ports(); |
40 | } | 36 | } |
@@ -47,48 +43,3 @@ void backlight_set(uint8_t level) { | |||
47 | b_led_set(level); | 43 | b_led_set(level); |
48 | } | 44 | } |
49 | #endif | 45 | #endif |
50 | |||
51 | #ifdef RGBLIGHT_ENABLE | ||
52 | extern rgblight_config_t rgblight_config; | ||
53 | |||
54 | // custom RGB driver | ||
55 | void rgblight_set(void) { | ||
56 | if (!rgblight_config.enable) { | ||
57 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
58 | led[i].r = 0; | ||
59 | led[i].g = 0; | ||
60 | led[i].b = 0; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | i2c_init(); | ||
65 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
66 | } | ||
67 | |||
68 | bool rgb_init = false; | ||
69 | |||
70 | void matrix_scan_kb(void) { | ||
71 | // if LEDs were previously on before poweroff, turn them back on | ||
72 | if (rgb_init == false && rgblight_config.enable) { | ||
73 | i2c_init(); | ||
74 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
75 | rgb_init = true; | ||
76 | } | ||
77 | |||
78 | rgblight_task(); | ||
79 | #else | ||
80 | void matrix_scan_kb(void) { | ||
81 | #endif | ||
82 | matrix_scan_user(); | ||
83 | /* Nothing else for now. */ | ||
84 | } | ||
85 | |||
86 | __attribute__((weak)) // overridable | ||
87 | void matrix_init_user(void) { | ||
88 | |||
89 | } | ||
90 | |||
91 | __attribute__((weak)) // overridable | ||
92 | void matrix_scan_user(void) { | ||
93 | |||
94 | } | ||
diff --git a/keyboards/jj50/rules.mk b/keyboards/jj50/rules.mk index b23b4becd..40473e6ec 100644 --- a/keyboards/jj50/rules.mk +++ b/keyboards/jj50/rules.mk | |||
@@ -1,19 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
2 | # Modified 2018 Wayne Jones (WarmCatUK) <waynekjones@gmail.com> | ||
3 | |||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License as published by | ||
6 | # the Free Software Foundation, either version 2 of the License, or | ||
7 | # (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | # MCU name | 1 | # MCU name |
18 | MCU = atmega32a | 2 | MCU = atmega32a |
19 | 3 | ||
@@ -35,22 +19,18 @@ CONSOLE_ENABLE = no | |||
35 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
36 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
37 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
38 | RGBLIGHT_CUSTOM_DRIVER = yes | 22 | WS2812_DRIVER = i2c |
39 | NKRO_ENABLE = no | 23 | NKRO_ENABLE = no |
40 | # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 24 | # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
41 | 25 | ||
42 | |||
43 | DISABLE_WS2812 = no | ||
44 | |||
45 | KEY_LOCK_ENABLE = yes | 26 | KEY_LOCK_ENABLE = yes |
46 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 27 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
47 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | 28 | SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend |
48 | 29 | ||
49 | |||
50 | #OPT_DEFS = -DDEBUG_LEVEL=0 | 30 | #OPT_DEFS = -DDEBUG_LEVEL=0 |
51 | 31 | ||
52 | # custom matrix setup | 32 | # custom matrix setup |
53 | CUSTOM_MATRIX = yes | 33 | CUSTOM_MATRIX = yes |
54 | SRC = matrix.c i2c.c backlight.c | 34 | SRC = matrix.c backlight.c |
55 | 35 | ||
56 | LAYOUTS = ortho_5x12 | 36 | LAYOUTS = ortho_5x12 |
diff --git a/keyboards/mechmini/v1/i2c.c b/keyboards/mechmini/v1/i2c.c deleted file mode 100644 index c27f3e3d1..000000000 --- a/keyboards/mechmini/v1/i2c.c +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <avr/io.h> | ||
19 | #include <util/twi.h> | ||
20 | |||
21 | #include "i2c.h" | ||
22 | |||
23 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
24 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
25 | if (bitrate_div >= 16) { | ||
26 | bitrate_div = (bitrate_div - 16) / 2; | ||
27 | } | ||
28 | TWBR = bitrate_div; | ||
29 | } | ||
30 | |||
31 | void i2c_init(void) { | ||
32 | // set pull-up resistors on I2C bus pins | ||
33 | PORTC |= 0b11; | ||
34 | |||
35 | i2c_set_bitrate(400); | ||
36 | |||
37 | // enable TWI (two-wire interface) | ||
38 | TWCR |= (1 << TWEN); | ||
39 | |||
40 | // enable TWI interrupt and slave address ACK | ||
41 | TWCR |= (1 << TWIE); | ||
42 | TWCR |= (1 << TWEA); | ||
43 | } | ||
44 | |||
45 | uint8_t i2c_start(uint8_t address) { | ||
46 | // reset TWI control register | ||
47 | TWCR = 0; | ||
48 | |||
49 | // begin transmission and wait for it to end | ||
50 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
51 | while (!(TWCR & (1<<TWINT))); | ||
52 | |||
53 | // check if the start condition was successfully transmitted | ||
54 | if ((TWSR & 0xF8) != TW_START) { | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | // transmit address and wait | ||
59 | TWDR = address; | ||
60 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
61 | while (!(TWCR & (1<<TWINT))); | ||
62 | |||
63 | // check if the device has acknowledged the READ / WRITE mode | ||
64 | uint8_t twst = TW_STATUS & 0xF8; | ||
65 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | void i2c_stop(void) { | ||
73 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
74 | } | ||
75 | |||
76 | uint8_t i2c_write(uint8_t data) { | ||
77 | TWDR = data; | ||
78 | |||
79 | // transmit data and wait | ||
80 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
81 | while (!(TWCR & (1<<TWINT))); | ||
82 | |||
83 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
91 | if (i2c_start(address)) { | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | for (uint16_t i = 0; i < length; i++) { | ||
96 | if (i2c_write(data[i])) { | ||
97 | return 1; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | i2c_stop(); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
diff --git a/keyboards/mechmini/v1/i2c.h b/keyboards/mechmini/v1/i2c.h deleted file mode 100644 index 194a82cab..000000000 --- a/keyboards/mechmini/v1/i2c.h +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | This program is distributed in the hope that it will be useful, | ||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | GNU General Public License for more details. | ||
11 | You should have received a copy of the GNU General Public License | ||
12 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
13 | */ | ||
14 | |||
15 | #ifndef __I2C_H__ | ||
16 | #define __I2C_H__ | ||
17 | |||
18 | void i2c_init(void); | ||
19 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
20 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
21 | |||
22 | #endif | ||
diff --git a/keyboards/mechmini/v1/rules.mk b/keyboards/mechmini/v1/rules.mk index 3510ca6f3..ee023b43b 100644 --- a/keyboards/mechmini/v1/rules.mk +++ b/keyboards/mechmini/v1/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -34,10 +19,10 @@ CONSOLE_ENABLE = yes | |||
34 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
35 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = no |
36 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
37 | RGBLIGHT_CUSTOM_DRIVER = yes | 22 | WS2812_DRIVER = i2c |
38 | 23 | ||
39 | OPT_DEFS = -DDEBUG_LEVEL=0 | 24 | OPT_DEFS = -DDEBUG_LEVEL=0 |
40 | 25 | ||
41 | # custom matrix setup | 26 | # custom matrix setup |
42 | CUSTOM_MATRIX = yes | 27 | CUSTOM_MATRIX = yes |
43 | SRC = matrix.c i2c.c | 28 | SRC = matrix.c |
diff --git a/keyboards/mechmini/v1/v1.c b/keyboards/mechmini/v1/v1.c index 508d60c78..2c910d965 100644 --- a/keyboards/mechmini/v1/v1.c +++ b/keyboards/mechmini/v1/v1.c | |||
@@ -16,61 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "v1.h" | 18 | #include "v1.h" |
19 | #include <avr/pgmspace.h> | ||
20 | #include "action_layer.h" | ||
21 | #include "i2c.h" | ||
22 | #include "quantum.h" | ||
23 | #include "rgblight.h" | ||
24 | 19 | ||
25 | // for keyboard subdirectory level init functions | 20 | void matrix_init_kb(void) { matrix_init_user(); } |
26 | // @Override | ||
27 | void matrix_init_kb(void) { | ||
28 | // call user level keymaps, if any | ||
29 | matrix_init_user(); | ||
30 | } | ||
31 | 21 | ||
32 | #ifdef RGBLIGHT_ENABLE | 22 | __attribute__ ((weak)) |
33 | extern rgblight_config_t rgblight_config; | 23 | void matrix_init_user(void) {} |
34 | 24 | ||
35 | // custom RGB driver | 25 | void matrix_scan_kb(void) { matrix_scan_user(); } |
36 | void rgblight_set(void) { | ||
37 | if (!rgblight_config.enable) { | ||
38 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
39 | led[i].r = 0; | ||
40 | led[i].g = 0; | ||
41 | led[i].b = 0; | ||
42 | } | ||
43 | } | ||
44 | 26 | ||
45 | i2c_init(); | 27 | __attribute__ ((weak)) |
46 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | 28 | void matrix_scan_user(void) {} |
47 | } | ||
48 | |||
49 | bool rgb_init = false; | ||
50 | |||
51 | void matrix_scan_kb(void) { | ||
52 | // if LEDs were previously on before poweroff, turn them back on | ||
53 | if (rgb_init == false && rgblight_config.enable) { | ||
54 | i2c_init(); | ||
55 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
56 | rgb_init = true; | ||
57 | } | ||
58 | |||
59 | rgblight_task(); | ||
60 | #else | ||
61 | void matrix_scan_kb(void) { | ||
62 | #endif | ||
63 | matrix_scan_user(); | ||
64 | /* Nothing else for now. */ | ||
65 | } | ||
66 | |||
67 | __attribute__((weak)) // overridable | ||
68 | void matrix_init_user(void) { | ||
69 | |||
70 | } | ||
71 | |||
72 | |||
73 | __attribute__((weak)) // overridable | ||
74 | void matrix_scan_user(void) { | ||
75 | |||
76 | } | ||
diff --git a/keyboards/mehkee96/i2c.c b/keyboards/mehkee96/i2c.c deleted file mode 100644 index a4f952135..000000000 --- a/keyboards/mehkee96/i2c.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #include <avr/io.h> | ||
21 | #include <util/twi.h> | ||
22 | |||
23 | #include "i2c.h" | ||
24 | |||
25 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
26 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
27 | if (bitrate_div >= 16) { | ||
28 | bitrate_div = (bitrate_div - 16) / 2; | ||
29 | } | ||
30 | TWBR = bitrate_div; | ||
31 | } | ||
32 | |||
33 | void i2c_init(void) { | ||
34 | // set pull-up resistors on I2C bus pins | ||
35 | PORTC |= 0b11; | ||
36 | |||
37 | i2c_set_bitrate(400); | ||
38 | |||
39 | // enable TWI (two-wire interface) | ||
40 | TWCR |= (1 << TWEN); | ||
41 | |||
42 | // enable TWI interrupt and slave address ACK | ||
43 | TWCR |= (1 << TWIE); | ||
44 | TWCR |= (1 << TWEA); | ||
45 | } | ||
46 | |||
47 | uint8_t i2c_start(uint8_t address) { | ||
48 | // reset TWI control register | ||
49 | TWCR = 0; | ||
50 | |||
51 | // begin transmission and wait for it to end | ||
52 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
53 | while (!(TWCR & (1<<TWINT))); | ||
54 | |||
55 | // check if the start condition was successfully transmitted | ||
56 | if ((TWSR & 0xF8) != TW_START) { | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | // transmit address and wait | ||
61 | TWDR = address; | ||
62 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
63 | while (!(TWCR & (1<<TWINT))); | ||
64 | |||
65 | // check if the device has acknowledged the READ / WRITE mode | ||
66 | uint8_t twst = TW_STATUS & 0xF8; | ||
67 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
68 | return 1; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | void i2c_stop(void) { | ||
75 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
76 | } | ||
77 | |||
78 | uint8_t i2c_write(uint8_t data) { | ||
79 | TWDR = data; | ||
80 | |||
81 | // transmit data and wait | ||
82 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
83 | while (!(TWCR & (1<<TWINT))); | ||
84 | |||
85 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
86 | return 1; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
93 | if (i2c_start(address)) { | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | for (uint16_t i = 0; i < length; i++) { | ||
98 | if (i2c_write(data[i])) { | ||
99 | return 1; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | i2c_stop(); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
diff --git a/keyboards/mehkee96/i2c.h b/keyboards/mehkee96/i2c.h deleted file mode 100644 index 7ce50cdb5..000000000 --- a/keyboards/mehkee96/i2c.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #ifndef __I2C_H__ | ||
21 | #define __I2C_H__ | ||
22 | |||
23 | void i2c_init(void); | ||
24 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
25 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
26 | |||
27 | #endif | ||
diff --git a/keyboards/mehkee96/mehkee96.c b/keyboards/mehkee96/mehkee96.c index 604fad803..46427ec93 100644 --- a/keyboards/mehkee96/mehkee96.c +++ b/keyboards/mehkee96/mehkee96.c | |||
@@ -16,66 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "mehkee96.h" | 18 | #include "mehkee96.h" |
19 | #include "rgblight.h" | ||
20 | 19 | ||
21 | #include <avr/pgmspace.h> | 20 | void matrix_init_kb(void) { matrix_init_user(); } |
22 | 21 | ||
23 | #include "action_layer.h" | 22 | __attribute__ ((weak)) |
24 | #include "i2c.h" | 23 | void matrix_init_user(void) {} |
25 | #include "quantum.h" | ||
26 | 24 | ||
27 | // for keyboard subdirectory level init functions | 25 | void matrix_scan_kb(void) { matrix_scan_user(); } |
28 | // @Override | ||
29 | void matrix_init_kb(void) { | ||
30 | // call user level keymaps, if any | ||
31 | matrix_init_user(); | ||
32 | } | ||
33 | 26 | ||
34 | #ifdef RGBLIGHT_ENABLE | 27 | __attribute__ ((weak)) |
35 | extern rgblight_config_t rgblight_config; | 28 | void matrix_scan_user(void) {} |
36 | |||
37 | // custom RGB driver | ||
38 | void rgblight_set(void) { | ||
39 | if (!rgblight_config.enable) { | ||
40 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
41 | led[i].r = 0; | ||
42 | led[i].g = 0; | ||
43 | led[i].b = 0; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | i2c_init(); | ||
48 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
49 | } | ||
50 | |||
51 | bool rgb_init = false; | ||
52 | |||
53 | void matrix_scan_kb(void) { | ||
54 | // if LEDs were previously on before poweroff, turn them back on | ||
55 | if (rgb_init == false && rgblight_config.enable) { | ||
56 | i2c_init(); | ||
57 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
58 | rgb_init = true; | ||
59 | } | ||
60 | |||
61 | #ifdef RGBLIGHT_ANIMATION | ||
62 | rgblight_task(); | ||
63 | #endif | ||
64 | |||
65 | #else | ||
66 | void matrix_scan_kb(void) { | ||
67 | #endif | ||
68 | matrix_scan_user(); | ||
69 | /* Nothing else for now. */ | ||
70 | } | ||
71 | |||
72 | __attribute__((weak)) // overridable | ||
73 | void matrix_init_user(void) { | ||
74 | |||
75 | } | ||
76 | |||
77 | |||
78 | __attribute__((weak)) // overridable | ||
79 | void matrix_scan_user(void) { | ||
80 | |||
81 | } | ||
diff --git a/keyboards/mehkee96/rules.mk b/keyboards/mehkee96/rules.mk index 244dd2141..1cbd02948 100644 --- a/keyboards/mehkee96/rules.mk +++ b/keyboards/mehkee96/rules.mk | |||
@@ -21,10 +21,10 @@ CONSOLE_ENABLE = yes # Console for debug(+400) | |||
21 | COMMAND_ENABLE = yes # Commands for debug and configuration | 21 | COMMAND_ENABLE = yes # Commands for debug and configuration |
22 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | 22 | BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality |
23 | RGBLIGHT_ENABLE = yes | 23 | RGBLIGHT_ENABLE = yes |
24 | RGBLIGHT_CUSTOM_DRIVER = yes | 24 | WS2812_DRIVER = i2c |
25 | 25 | ||
26 | OPT_DEFS = -DDEBUG_LEVEL=0 | 26 | OPT_DEFS = -DDEBUG_LEVEL=0 |
27 | 27 | ||
28 | # custom matrix setup | 28 | # custom matrix setup |
29 | CUSTOM_MATRIX = yes | 29 | CUSTOM_MATRIX = yes |
30 | SRC = matrix.c i2c.c | 30 | SRC = matrix.c |
diff --git a/keyboards/mt40/i2c.c b/keyboards/mt40/i2c.c deleted file mode 100644 index c27f3e3d1..000000000 --- a/keyboards/mt40/i2c.c +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <avr/io.h> | ||
19 | #include <util/twi.h> | ||
20 | |||
21 | #include "i2c.h" | ||
22 | |||
23 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
24 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
25 | if (bitrate_div >= 16) { | ||
26 | bitrate_div = (bitrate_div - 16) / 2; | ||
27 | } | ||
28 | TWBR = bitrate_div; | ||
29 | } | ||
30 | |||
31 | void i2c_init(void) { | ||
32 | // set pull-up resistors on I2C bus pins | ||
33 | PORTC |= 0b11; | ||
34 | |||
35 | i2c_set_bitrate(400); | ||
36 | |||
37 | // enable TWI (two-wire interface) | ||
38 | TWCR |= (1 << TWEN); | ||
39 | |||
40 | // enable TWI interrupt and slave address ACK | ||
41 | TWCR |= (1 << TWIE); | ||
42 | TWCR |= (1 << TWEA); | ||
43 | } | ||
44 | |||
45 | uint8_t i2c_start(uint8_t address) { | ||
46 | // reset TWI control register | ||
47 | TWCR = 0; | ||
48 | |||
49 | // begin transmission and wait for it to end | ||
50 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
51 | while (!(TWCR & (1<<TWINT))); | ||
52 | |||
53 | // check if the start condition was successfully transmitted | ||
54 | if ((TWSR & 0xF8) != TW_START) { | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | // transmit address and wait | ||
59 | TWDR = address; | ||
60 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
61 | while (!(TWCR & (1<<TWINT))); | ||
62 | |||
63 | // check if the device has acknowledged the READ / WRITE mode | ||
64 | uint8_t twst = TW_STATUS & 0xF8; | ||
65 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | void i2c_stop(void) { | ||
73 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
74 | } | ||
75 | |||
76 | uint8_t i2c_write(uint8_t data) { | ||
77 | TWDR = data; | ||
78 | |||
79 | // transmit data and wait | ||
80 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
81 | while (!(TWCR & (1<<TWINT))); | ||
82 | |||
83 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
91 | if (i2c_start(address)) { | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | for (uint16_t i = 0; i < length; i++) { | ||
96 | if (i2c_write(data[i])) { | ||
97 | return 1; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | i2c_stop(); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
diff --git a/keyboards/mt40/i2c.h b/keyboards/mt40/i2c.h deleted file mode 100644 index 27c9d3d05..000000000 --- a/keyboards/mt40/i2c.h +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef __I2C_H__ | ||
19 | #define __I2C_H__ | ||
20 | |||
21 | void i2c_init(void); | ||
22 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
23 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
24 | |||
25 | #endif | ||
diff --git a/keyboards/mt40/mt40.c b/keyboards/mt40/mt40.c index 555689f87..dd079e7d8 100644 --- a/keyboards/mt40/mt40.c +++ b/keyboards/mt40/mt40.c | |||
@@ -13,32 +13,5 @@ | |||
13 | * You should have received a copy of the GNU General Public License | 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/>. | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ | 15 | */ |
16 | #include "mt40.h" | ||
17 | #include "rgblight.h" | ||
18 | |||
19 | #include <avr/pgmspace.h> | ||
20 | |||
21 | #include "action_layer.h" | ||
22 | #include "i2c.h" | ||
23 | #include "quantum.h" | ||
24 | |||
25 | extern rgblight_config_t rgblight_config; | ||
26 | 16 | ||
27 | void rgblight_set(void) { | 17 | #include "mt40.h" |
28 | if (!rgblight_config.enable) { | ||
29 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | ||
30 | led[i].r = 0; | ||
31 | led[i].g = 0; | ||
32 | led[i].b = 0; | ||
33 | } | ||
34 | } | ||
35 | |||
36 | i2c_init(); | ||
37 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
38 | } | ||
39 | |||
40 | __attribute__ ((weak)) | ||
41 | void matrix_scan_kb(void) { | ||
42 | rgblight_task(); | ||
43 | matrix_init_user(); | ||
44 | } | ||
diff --git a/keyboards/mt40/rules.mk b/keyboards/mt40/rules.mk index 19410bc6e..0cbf90c67 100644 --- a/keyboards/mt40/rules.mk +++ b/keyboards/mt40/rules.mk | |||
@@ -24,14 +24,14 @@ AUDIO_ENABLE ?= no # Audio output on port C6 | |||
24 | UNICODE_ENABLE ?= no # Unicode | 24 | UNICODE_ENABLE ?= no # Unicode |
25 | BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID | 25 | BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID |
26 | RGBLIGHT_ENABLE ?= yes # Enable WS2812 RGB underlight. | 26 | RGBLIGHT_ENABLE ?= yes # Enable WS2812 RGB underlight. |
27 | RGBLIGHT_CUSTOM_DRIVER = yes | 27 | WS2812_DRIVER = i2c |
28 | TAP_DANCE_ENABLE = no | 28 | TAP_DANCE_ENABLE = no |
29 | 29 | ||
30 | OPT_DEFS = -DDEBUG_LEVEL=0 | 30 | OPT_DEFS = -DDEBUG_LEVEL=0 |
31 | 31 | ||
32 | # custom matrix setup | 32 | # custom matrix setup |
33 | CUSTOM_MATRIX = yes | 33 | CUSTOM_MATRIX = yes |
34 | SRC = matrix.c i2c.c | 34 | SRC = matrix.c |
35 | 35 | ||
36 | LAYOUTS = planck_mit | 36 | LAYOUTS = planck_mit |
37 | LAYOUTS_HAS_RGB = no | 37 | LAYOUTS_HAS_RGB = no |
diff --git a/keyboards/percent/canoe/canoe.c b/keyboards/percent/canoe/canoe.c index a7427e152..e59b0dd7b 100644 --- a/keyboards/percent/canoe/canoe.c +++ b/keyboards/percent/canoe/canoe.c | |||
@@ -16,81 +16,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "canoe.h" | 18 | #include "canoe.h" |
19 | #ifdef BACKLIGHT_ENABLE | 19 | |
20 | #include "backlight.h" | 20 | void matrix_init_kb(void) { matrix_init_user(); } |
21 | #endif | 21 | |
22 | #ifdef RGBLIGHT_ENABLE | 22 | __attribute__ ((weak)) |
23 | #include "i2c.h" | 23 | void matrix_init_user(void) {} |
24 | #include "rgblight.h" | 24 | |
25 | #endif | 25 | void matrix_scan_kb(void) { matrix_scan_user(); } |
26 | |||
27 | __attribute__ ((weak)) | ||
28 | void matrix_scan_user(void) {} | ||
26 | 29 | ||
27 | #ifdef BACKLIGHT_ENABLE | 30 | #ifdef BACKLIGHT_ENABLE |
28 | void backlight_set(uint8_t level) { | 31 | void backlight_set(uint8_t level) { |
29 | if (level == 0) { | 32 | if (level == 0) { |
30 | // Turn out the lights | 33 | // Turn out the lights |
31 | PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); | 34 | writePinLow(D0); |
35 | writePinLow(D1); | ||
36 | writePinLow(D4); | ||
37 | writePinLow(D6); | ||
32 | } else { | 38 | } else { |
33 | // Turn on the lights | 39 | // Turn on the lights |
34 | PORTD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); | 40 | writePinHigh(D0); |
41 | writePinHigh(D1); | ||
42 | writePinHigh(D4); | ||
43 | writePinHigh(D6); | ||
35 | } | 44 | } |
36 | } | 45 | } |
37 | 46 | ||
38 | void backlight_init_ports(void) { | 47 | void backlight_init_ports(void) { |
39 | DDRD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); | 48 | setPinOutput(D0); |
40 | PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); | 49 | setPinOutput(D1); |
41 | } | 50 | setPinOutput(D4); |
42 | 51 | setPinOutput(D6); | |
43 | #endif | 52 | |
44 | 53 | writePinLow(D0); | |
45 | // for keyboard subdirectory level init functions | 54 | writePinLow(D1); |
46 | // @Override | 55 | writePinLow(D4); |
47 | void matrix_init_kb(void) { | 56 | writePinLow(D6); |
48 | // call user level keymaps, if any | ||
49 | matrix_init_user(); | ||
50 | } | ||
51 | |||
52 | #ifdef RGBLIGHT_ENABLE | ||
53 | extern rgblight_config_t rgblight_config; | ||
54 | |||
55 | // custom RGB driver | ||
56 | void rgblight_set(void) { | ||
57 | if (!rgblight_config.enable) { | ||
58 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
59 | led[i].r = 0; | ||
60 | led[i].g = 0; | ||
61 | led[i].b = 0; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | i2c_init(); | ||
66 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
67 | } | 57 | } |
68 | |||
69 | bool rgb_init = false; | ||
70 | |||
71 | void matrix_scan_kb(void) { | ||
72 | // if LEDs were previously on before poweroff, turn them back on | ||
73 | if (rgb_init == false && rgblight_config.enable) { | ||
74 | i2c_init(); | ||
75 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
76 | rgb_init = true; | ||
77 | } | ||
78 | |||
79 | rgblight_task(); | ||
80 | #else | ||
81 | void matrix_scan_kb(void) { | ||
82 | #endif | 58 | #endif |
83 | matrix_scan_user(); | ||
84 | /* Nothing else for now. */ | ||
85 | } | ||
86 | |||
87 | __attribute__((weak)) // overridable | ||
88 | void matrix_init_user(void) { | ||
89 | |||
90 | } | ||
91 | |||
92 | |||
93 | __attribute__((weak)) // overridable | ||
94 | void matrix_scan_user(void) { | ||
95 | |||
96 | } | ||
diff --git a/keyboards/percent/canoe/i2c.c b/keyboards/percent/canoe/i2c.c deleted file mode 100644 index a4f952135..000000000 --- a/keyboards/percent/canoe/i2c.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #include <avr/io.h> | ||
21 | #include <util/twi.h> | ||
22 | |||
23 | #include "i2c.h" | ||
24 | |||
25 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
26 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
27 | if (bitrate_div >= 16) { | ||
28 | bitrate_div = (bitrate_div - 16) / 2; | ||
29 | } | ||
30 | TWBR = bitrate_div; | ||
31 | } | ||
32 | |||
33 | void i2c_init(void) { | ||
34 | // set pull-up resistors on I2C bus pins | ||
35 | PORTC |= 0b11; | ||
36 | |||
37 | i2c_set_bitrate(400); | ||
38 | |||
39 | // enable TWI (two-wire interface) | ||
40 | TWCR |= (1 << TWEN); | ||
41 | |||
42 | // enable TWI interrupt and slave address ACK | ||
43 | TWCR |= (1 << TWIE); | ||
44 | TWCR |= (1 << TWEA); | ||
45 | } | ||
46 | |||
47 | uint8_t i2c_start(uint8_t address) { | ||
48 | // reset TWI control register | ||
49 | TWCR = 0; | ||
50 | |||
51 | // begin transmission and wait for it to end | ||
52 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
53 | while (!(TWCR & (1<<TWINT))); | ||
54 | |||
55 | // check if the start condition was successfully transmitted | ||
56 | if ((TWSR & 0xF8) != TW_START) { | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | // transmit address and wait | ||
61 | TWDR = address; | ||
62 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
63 | while (!(TWCR & (1<<TWINT))); | ||
64 | |||
65 | // check if the device has acknowledged the READ / WRITE mode | ||
66 | uint8_t twst = TW_STATUS & 0xF8; | ||
67 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
68 | return 1; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | void i2c_stop(void) { | ||
75 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
76 | } | ||
77 | |||
78 | uint8_t i2c_write(uint8_t data) { | ||
79 | TWDR = data; | ||
80 | |||
81 | // transmit data and wait | ||
82 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
83 | while (!(TWCR & (1<<TWINT))); | ||
84 | |||
85 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
86 | return 1; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
93 | if (i2c_start(address)) { | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | for (uint16_t i = 0; i < length; i++) { | ||
98 | if (i2c_write(data[i])) { | ||
99 | return 1; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | i2c_stop(); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
diff --git a/keyboards/percent/canoe/i2c.h b/keyboards/percent/canoe/i2c.h deleted file mode 100644 index 93a69c94d..000000000 --- a/keyboards/percent/canoe/i2c.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #ifndef __I2C_H__ | ||
21 | #define __I2C_H__ | ||
22 | |||
23 | void i2c_init(void); | ||
24 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
25 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
26 | |||
27 | #endif | ||
diff --git a/keyboards/percent/canoe/rules.mk b/keyboards/percent/canoe/rules.mk index e3269b94d..bb14269a2 100644 --- a/keyboards/percent/canoe/rules.mk +++ b/keyboards/percent/canoe/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -34,12 +19,12 @@ CONSOLE_ENABLE = yes | |||
34 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
35 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = no |
36 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
37 | RGBLIGHT_CUSTOM_DRIVER = yes | 22 | WS2812_DRIVER = i2c |
38 | 23 | ||
39 | OPT_DEFS = -DDEBUG_LEVEL=0 | 24 | OPT_DEFS = -DDEBUG_LEVEL=0 |
40 | 25 | ||
41 | # custom matrix setup | 26 | # custom matrix setup |
42 | CUSTOM_MATRIX = yes | 27 | CUSTOM_MATRIX = yes |
43 | SRC = matrix.c i2c.c | 28 | SRC = matrix.c |
44 | 29 | ||
45 | LAYOUTS = 65_ansi_blocker \ No newline at end of file | 30 | LAYOUTS = 65_ansi_blocker |
diff --git a/keyboards/percent/skog/i2c.c b/keyboards/percent/skog/i2c.c deleted file mode 100644 index a4f952135..000000000 --- a/keyboards/percent/skog/i2c.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #include <avr/io.h> | ||
21 | #include <util/twi.h> | ||
22 | |||
23 | #include "i2c.h" | ||
24 | |||
25 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
26 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
27 | if (bitrate_div >= 16) { | ||
28 | bitrate_div = (bitrate_div - 16) / 2; | ||
29 | } | ||
30 | TWBR = bitrate_div; | ||
31 | } | ||
32 | |||
33 | void i2c_init(void) { | ||
34 | // set pull-up resistors on I2C bus pins | ||
35 | PORTC |= 0b11; | ||
36 | |||
37 | i2c_set_bitrate(400); | ||
38 | |||
39 | // enable TWI (two-wire interface) | ||
40 | TWCR |= (1 << TWEN); | ||
41 | |||
42 | // enable TWI interrupt and slave address ACK | ||
43 | TWCR |= (1 << TWIE); | ||
44 | TWCR |= (1 << TWEA); | ||
45 | } | ||
46 | |||
47 | uint8_t i2c_start(uint8_t address) { | ||
48 | // reset TWI control register | ||
49 | TWCR = 0; | ||
50 | |||
51 | // begin transmission and wait for it to end | ||
52 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
53 | while (!(TWCR & (1<<TWINT))); | ||
54 | |||
55 | // check if the start condition was successfully transmitted | ||
56 | if ((TWSR & 0xF8) != TW_START) { | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | // transmit address and wait | ||
61 | TWDR = address; | ||
62 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
63 | while (!(TWCR & (1<<TWINT))); | ||
64 | |||
65 | // check if the device has acknowledged the READ / WRITE mode | ||
66 | uint8_t twst = TW_STATUS & 0xF8; | ||
67 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
68 | return 1; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | void i2c_stop(void) { | ||
75 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
76 | } | ||
77 | |||
78 | uint8_t i2c_write(uint8_t data) { | ||
79 | TWDR = data; | ||
80 | |||
81 | // transmit data and wait | ||
82 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
83 | while (!(TWCR & (1<<TWINT))); | ||
84 | |||
85 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
86 | return 1; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
93 | if (i2c_start(address)) { | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | for (uint16_t i = 0; i < length; i++) { | ||
98 | if (i2c_write(data[i])) { | ||
99 | return 1; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | i2c_stop(); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
diff --git a/keyboards/percent/skog/i2c.h b/keyboards/percent/skog/i2c.h deleted file mode 100644 index ada8cc7bf..000000000 --- a/keyboards/percent/skog/i2c.h +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | void i2c_init(void); | ||
23 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
24 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
25 | |||
diff --git a/keyboards/percent/skog/rules.mk b/keyboards/percent/skog/rules.mk index b8439906b..2b0c1154d 100644 --- a/keyboards/percent/skog/rules.mk +++ b/keyboards/percent/skog/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2018 Jumail Mundekkat / MxBlue | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -34,9 +19,9 @@ CONSOLE_ENABLE = yes | |||
34 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
35 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
36 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
22 | WS2812_DRIVER = i2c | ||
37 | 23 | ||
38 | BACKLIGHT_CUSTOM_DRIVER = yes | 24 | BACKLIGHT_CUSTOM_DRIVER = yes |
39 | RGBLIGHT_CUSTOM_DRIVER = yes | ||
40 | 25 | ||
41 | OPT_DEFS = -DDEBUG_LEVEL=0 | 26 | OPT_DEFS = -DDEBUG_LEVEL=0 |
42 | 27 | ||
@@ -45,4 +30,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | |||
45 | 30 | ||
46 | # custom matrix setup | 31 | # custom matrix setup |
47 | CUSTOM_MATRIX = yes | 32 | CUSTOM_MATRIX = yes |
48 | SRC = matrix.c i2c.c backlight.c | 33 | SRC = matrix.c backlight.c |
diff --git a/keyboards/percent/skog/skog.c b/keyboards/percent/skog/skog.c index 3d1eb0e1a..8678d483a 100644 --- a/keyboards/percent/skog/skog.c +++ b/keyboards/percent/skog/skog.c | |||
@@ -19,23 +19,18 @@ ps2avrGB support code by Kenneth A. (bminiex/.[ch]) | |||
19 | 19 | ||
20 | #include "skog.h" | 20 | #include "skog.h" |
21 | 21 | ||
22 | #include "rgblight.h" | 22 | #include "backlight.h" |
23 | #include "backlight_custom.h" | ||
23 | 24 | ||
24 | #include <avr/pgmspace.h> | 25 | void matrix_init_kb(void) { matrix_init_user(); } |
25 | 26 | ||
26 | #include "action_layer.h" | 27 | __attribute__ ((weak)) |
27 | #include "i2c.h" | 28 | void matrix_init_user(void) {} |
28 | #include "quantum.h" | ||
29 | 29 | ||
30 | #include "backlight.h" | 30 | void matrix_scan_kb(void) { matrix_scan_user(); } |
31 | #include "backlight_custom.h" | ||
32 | 31 | ||
33 | // for keyboard subdirectory level init functions | 32 | __attribute__ ((weak)) |
34 | // @Override | 33 | void matrix_scan_user(void) {} |
35 | void matrix_init_kb(void) { | ||
36 | // call user level keymaps, if any | ||
37 | matrix_init_user(); | ||
38 | } | ||
39 | 34 | ||
40 | #ifdef BACKLIGHT_ENABLE | 35 | #ifdef BACKLIGHT_ENABLE |
41 | /// Overrides functions in `quantum.c` | 36 | /// Overrides functions in `quantum.c` |
@@ -51,48 +46,3 @@ void backlight_set(uint8_t level) { | |||
51 | b_led_set(level); | 46 | b_led_set(level); |
52 | } | 47 | } |
53 | #endif | 48 | #endif |
54 | |||
55 | #ifdef RGBLIGHT_ENABLE | ||
56 | extern rgblight_config_t rgblight_config; | ||
57 | |||
58 | // custom RGB driver | ||
59 | void rgblight_set(void) { | ||
60 | if (!rgblight_config.enable) { | ||
61 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
62 | led[i].r = 0; | ||
63 | led[i].g = 0; | ||
64 | led[i].b = 0; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | i2c_init(); | ||
69 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
70 | } | ||
71 | |||
72 | bool rgb_init = false; | ||
73 | |||
74 | void matrix_scan_kb(void) { | ||
75 | // if LEDs were previously on before poweroff, turn them back on | ||
76 | if (rgb_init == false && rgblight_config.enable) { | ||
77 | i2c_init(); | ||
78 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
79 | rgb_init = true; | ||
80 | } | ||
81 | |||
82 | rgblight_task(); | ||
83 | #else | ||
84 | void matrix_scan_kb(void) { | ||
85 | #endif | ||
86 | matrix_scan_user(); | ||
87 | /* Nothing else for now. */ | ||
88 | } | ||
89 | |||
90 | __attribute__((weak)) // overridable | ||
91 | void matrix_init_user(void) { | ||
92 | |||
93 | } | ||
94 | |||
95 | __attribute__((weak)) // overridable | ||
96 | void matrix_scan_user(void) { | ||
97 | |||
98 | } | ||
diff --git a/keyboards/winkeyless/bmini/bmini.c b/keyboards/winkeyless/bmini/bmini.c index 35800358c..87a31d052 100644 --- a/keyboards/winkeyless/bmini/bmini.c +++ b/keyboards/winkeyless/bmini/bmini.c | |||
@@ -16,30 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "bmini.h" | 18 | #include "bmini.h" |
19 | #include "rgblight.h" | ||
20 | |||
21 | #include <avr/pgmspace.h> | ||
22 | |||
23 | #include "action_layer.h" | ||
24 | #include "i2c.h" | ||
25 | #include "quantum.h" | ||
26 | |||
27 | extern rgblight_config_t rgblight_config; | ||
28 | |||
29 | void rgblight_set(void) { | ||
30 | if (!rgblight_config.enable) { | ||
31 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | ||
32 | led[i].r = 0; | ||
33 | led[i].g = 0; | ||
34 | led[i].b = 0; | ||
35 | } | ||
36 | } | ||
37 | |||
38 | i2c_init(); | ||
39 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
40 | } | ||
41 | 19 | ||
42 | __attribute__ ((weak)) | 20 | __attribute__ ((weak)) |
43 | void matrix_scan_user(void) { | 21 | void matrix_scan_user(void) {} |
44 | rgblight_task(); | ||
45 | } | ||
diff --git a/keyboards/winkeyless/bmini/i2c.c b/keyboards/winkeyless/bmini/i2c.c deleted file mode 100644 index a4f952135..000000000 --- a/keyboards/winkeyless/bmini/i2c.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #include <avr/io.h> | ||
21 | #include <util/twi.h> | ||
22 | |||
23 | #include "i2c.h" | ||
24 | |||
25 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
26 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
27 | if (bitrate_div >= 16) { | ||
28 | bitrate_div = (bitrate_div - 16) / 2; | ||
29 | } | ||
30 | TWBR = bitrate_div; | ||
31 | } | ||
32 | |||
33 | void i2c_init(void) { | ||
34 | // set pull-up resistors on I2C bus pins | ||
35 | PORTC |= 0b11; | ||
36 | |||
37 | i2c_set_bitrate(400); | ||
38 | |||
39 | // enable TWI (two-wire interface) | ||
40 | TWCR |= (1 << TWEN); | ||
41 | |||
42 | // enable TWI interrupt and slave address ACK | ||
43 | TWCR |= (1 << TWIE); | ||
44 | TWCR |= (1 << TWEA); | ||
45 | } | ||
46 | |||
47 | uint8_t i2c_start(uint8_t address) { | ||
48 | // reset TWI control register | ||
49 | TWCR = 0; | ||
50 | |||
51 | // begin transmission and wait for it to end | ||
52 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
53 | while (!(TWCR & (1<<TWINT))); | ||
54 | |||
55 | // check if the start condition was successfully transmitted | ||
56 | if ((TWSR & 0xF8) != TW_START) { | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | // transmit address and wait | ||
61 | TWDR = address; | ||
62 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
63 | while (!(TWCR & (1<<TWINT))); | ||
64 | |||
65 | // check if the device has acknowledged the READ / WRITE mode | ||
66 | uint8_t twst = TW_STATUS & 0xF8; | ||
67 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
68 | return 1; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | void i2c_stop(void) { | ||
75 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
76 | } | ||
77 | |||
78 | uint8_t i2c_write(uint8_t data) { | ||
79 | TWDR = data; | ||
80 | |||
81 | // transmit data and wait | ||
82 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
83 | while (!(TWCR & (1<<TWINT))); | ||
84 | |||
85 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
86 | return 1; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
93 | if (i2c_start(address)) { | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | for (uint16_t i = 0; i < length; i++) { | ||
98 | if (i2c_write(data[i])) { | ||
99 | return 1; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | i2c_stop(); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
diff --git a/keyboards/winkeyless/bmini/i2c.h b/keyboards/winkeyless/bmini/i2c.h deleted file mode 100644 index 93a69c94d..000000000 --- a/keyboards/winkeyless/bmini/i2c.h +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #ifndef __I2C_H__ | ||
21 | #define __I2C_H__ | ||
22 | |||
23 | void i2c_init(void); | ||
24 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
25 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
26 | |||
27 | #endif | ||
diff --git a/keyboards/winkeyless/bmini/rules.mk b/keyboards/winkeyless/bmini/rules.mk index 8cfc81056..7822bd830 100644 --- a/keyboards/winkeyless/bmini/rules.mk +++ b/keyboards/winkeyless/bmini/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -34,10 +19,10 @@ CONSOLE_ENABLE = yes | |||
34 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
35 | BACKLIGHT_ENABLE = no | 20 | BACKLIGHT_ENABLE = no |
36 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
37 | RGBLIGHT_CUSTOM_DRIVER = yes | 22 | WS2812_DRIVER = i2c |
38 | 23 | ||
39 | OPT_DEFS = -DDEBUG_LEVEL=0 | 24 | OPT_DEFS = -DDEBUG_LEVEL=0 |
40 | 25 | ||
41 | # custom matrix setup | 26 | # custom matrix setup |
42 | CUSTOM_MATRIX = yes | 27 | CUSTOM_MATRIX = yes |
43 | SRC = matrix.c i2c.c | 28 | SRC = matrix.c |
diff --git a/keyboards/winkeyless/bminiex/bminiex.c b/keyboards/winkeyless/bminiex/bminiex.c index d9b05aba5..11315b921 100644 --- a/keyboards/winkeyless/bminiex/bminiex.c +++ b/keyboards/winkeyless/bminiex/bminiex.c | |||
@@ -16,24 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "bminiex.h" | 18 | #include "bminiex.h" |
19 | #include "rgblight.h" | ||
20 | |||
21 | #include <avr/pgmspace.h> | ||
22 | |||
23 | #include "action_layer.h" | ||
24 | #include "i2c.h" | ||
25 | #include "quantum.h" | ||
26 | 19 | ||
27 | #include "backlight.h" | 20 | #include "backlight.h" |
28 | #include "backlight_custom.h" | 21 | #include "backlight_custom.h" |
29 | 22 | ||
30 | // for keyboard subdirectory level init functions | ||
31 | // @Override | ||
32 | void matrix_init_kb(void) { | ||
33 | // call user level keymaps, if any | ||
34 | matrix_init_user(); | ||
35 | } | ||
36 | |||
37 | #ifdef BACKLIGHT_ENABLE | 23 | #ifdef BACKLIGHT_ENABLE |
38 | /// Overrides functions in `quantum.c` | 24 | /// Overrides functions in `quantum.c` |
39 | void backlight_init_ports(void) { | 25 | void backlight_init_ports(void) { |
@@ -48,50 +34,3 @@ void backlight_set(uint8_t level) { | |||
48 | b_led_set(level); | 34 | b_led_set(level); |
49 | } | 35 | } |
50 | #endif | 36 | #endif |
51 | |||
52 | #ifdef RGBLIGHT_ENABLE | ||
53 | extern rgblight_config_t rgblight_config; | ||
54 | |||
55 | // custom RGB driver | ||
56 | void rgblight_set(void) { | ||
57 | if (!rgblight_config.enable) { | ||
58 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
59 | led[i].r = 0; | ||
60 | led[i].g = 0; | ||
61 | led[i].b = 0; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | i2c_init(); | ||
66 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
67 | } | ||
68 | |||
69 | bool rgb_init = false; | ||
70 | |||
71 | void matrix_scan_kb(void) { | ||
72 | // if LEDs were previously on before poweroff, turn them back on | ||
73 | if (rgb_init == false && rgblight_config.enable) { | ||
74 | i2c_init(); | ||
75 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
76 | rgb_init = true; | ||
77 | } | ||
78 | |||
79 | rgblight_task(); | ||
80 | #else | ||
81 | void matrix_scan_kb(void) { | ||
82 | #endif | ||
83 | matrix_scan_user(); | ||
84 | /* Nothing else for now. */ | ||
85 | } | ||
86 | |||
87 | __attribute__((weak)) // overridable | ||
88 | void matrix_init_user(void) { | ||
89 | |||
90 | } | ||
91 | |||
92 | __attribute__((weak)) // overridable | ||
93 | void matrix_scan_user(void) { | ||
94 | |||
95 | } | ||
96 | |||
97 | |||
diff --git a/keyboards/winkeyless/bminiex/i2c.c b/keyboards/winkeyless/bminiex/i2c.c deleted file mode 100644 index a4f952135..000000000 --- a/keyboards/winkeyless/bminiex/i2c.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #include <avr/io.h> | ||
21 | #include <util/twi.h> | ||
22 | |||
23 | #include "i2c.h" | ||
24 | |||
25 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
26 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
27 | if (bitrate_div >= 16) { | ||
28 | bitrate_div = (bitrate_div - 16) / 2; | ||
29 | } | ||
30 | TWBR = bitrate_div; | ||
31 | } | ||
32 | |||
33 | void i2c_init(void) { | ||
34 | // set pull-up resistors on I2C bus pins | ||
35 | PORTC |= 0b11; | ||
36 | |||
37 | i2c_set_bitrate(400); | ||
38 | |||
39 | // enable TWI (two-wire interface) | ||
40 | TWCR |= (1 << TWEN); | ||
41 | |||
42 | // enable TWI interrupt and slave address ACK | ||
43 | TWCR |= (1 << TWIE); | ||
44 | TWCR |= (1 << TWEA); | ||
45 | } | ||
46 | |||
47 | uint8_t i2c_start(uint8_t address) { | ||
48 | // reset TWI control register | ||
49 | TWCR = 0; | ||
50 | |||
51 | // begin transmission and wait for it to end | ||
52 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
53 | while (!(TWCR & (1<<TWINT))); | ||
54 | |||
55 | // check if the start condition was successfully transmitted | ||
56 | if ((TWSR & 0xF8) != TW_START) { | ||
57 | return 1; | ||
58 | } | ||
59 | |||
60 | // transmit address and wait | ||
61 | TWDR = address; | ||
62 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
63 | while (!(TWCR & (1<<TWINT))); | ||
64 | |||
65 | // check if the device has acknowledged the READ / WRITE mode | ||
66 | uint8_t twst = TW_STATUS & 0xF8; | ||
67 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
68 | return 1; | ||
69 | } | ||
70 | |||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | void i2c_stop(void) { | ||
75 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
76 | } | ||
77 | |||
78 | uint8_t i2c_write(uint8_t data) { | ||
79 | TWDR = data; | ||
80 | |||
81 | // transmit data and wait | ||
82 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
83 | while (!(TWCR & (1<<TWINT))); | ||
84 | |||
85 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
86 | return 1; | ||
87 | } | ||
88 | |||
89 | return 0; | ||
90 | } | ||
91 | |||
92 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
93 | if (i2c_start(address)) { | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | for (uint16_t i = 0; i < length; i++) { | ||
98 | if (i2c_write(data[i])) { | ||
99 | return 1; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | i2c_stop(); | ||
104 | |||
105 | return 0; | ||
106 | } | ||
diff --git a/keyboards/winkeyless/bminiex/i2c.h b/keyboards/winkeyless/bminiex/i2c.h deleted file mode 100644 index ada8cc7bf..000000000 --- a/keyboards/winkeyless/bminiex/i2c.h +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | // Please do not modify this file | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | void i2c_init(void); | ||
23 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
24 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
25 | |||
diff --git a/keyboards/winkeyless/bminiex/rules.mk b/keyboards/winkeyless/bminiex/rules.mk index 24e434879..39a77bda1 100644 --- a/keyboards/winkeyless/bminiex/rules.mk +++ b/keyboards/winkeyless/bminiex/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -36,7 +21,7 @@ COMMAND_ENABLE = no | |||
36 | BACKLIGHT_ENABLE = yes | 21 | BACKLIGHT_ENABLE = yes |
37 | BACKLIGHT_CUSTOM_DRIVER = yes | 22 | BACKLIGHT_CUSTOM_DRIVER = yes |
38 | RGBLIGHT_ENABLE = yes | 23 | RGBLIGHT_ENABLE = yes |
39 | RGBLIGHT_CUSTOM_DRIVER = yes | 24 | WS2812_DRIVER = i2c |
40 | TAP_DANCE_ENABLE = no | 25 | TAP_DANCE_ENABLE = no |
41 | 26 | ||
42 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 27 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
@@ -46,4 +31,4 @@ OPT_DEFS = -DDEBUG_LEVEL=0 | |||
46 | 31 | ||
47 | # custom matrix setup | 32 | # custom matrix setup |
48 | CUSTOM_MATRIX = yes | 33 | CUSTOM_MATRIX = yes |
49 | SRC = matrix.c i2c.c backlight.c | 34 | SRC = matrix.c backlight.c |
diff --git a/keyboards/ymd75/i2c.c b/keyboards/ymd75/i2c.c deleted file mode 100644 index c27f3e3d1..000000000 --- a/keyboards/ymd75/i2c.c +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <avr/io.h> | ||
19 | #include <util/twi.h> | ||
20 | |||
21 | #include "i2c.h" | ||
22 | |||
23 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
24 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
25 | if (bitrate_div >= 16) { | ||
26 | bitrate_div = (bitrate_div - 16) / 2; | ||
27 | } | ||
28 | TWBR = bitrate_div; | ||
29 | } | ||
30 | |||
31 | void i2c_init(void) { | ||
32 | // set pull-up resistors on I2C bus pins | ||
33 | PORTC |= 0b11; | ||
34 | |||
35 | i2c_set_bitrate(400); | ||
36 | |||
37 | // enable TWI (two-wire interface) | ||
38 | TWCR |= (1 << TWEN); | ||
39 | |||
40 | // enable TWI interrupt and slave address ACK | ||
41 | TWCR |= (1 << TWIE); | ||
42 | TWCR |= (1 << TWEA); | ||
43 | } | ||
44 | |||
45 | uint8_t i2c_start(uint8_t address) { | ||
46 | // reset TWI control register | ||
47 | TWCR = 0; | ||
48 | |||
49 | // begin transmission and wait for it to end | ||
50 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
51 | while (!(TWCR & (1<<TWINT))); | ||
52 | |||
53 | // check if the start condition was successfully transmitted | ||
54 | if ((TWSR & 0xF8) != TW_START) { | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | // transmit address and wait | ||
59 | TWDR = address; | ||
60 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
61 | while (!(TWCR & (1<<TWINT))); | ||
62 | |||
63 | // check if the device has acknowledged the READ / WRITE mode | ||
64 | uint8_t twst = TW_STATUS & 0xF8; | ||
65 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | void i2c_stop(void) { | ||
73 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
74 | } | ||
75 | |||
76 | uint8_t i2c_write(uint8_t data) { | ||
77 | TWDR = data; | ||
78 | |||
79 | // transmit data and wait | ||
80 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
81 | while (!(TWCR & (1<<TWINT))); | ||
82 | |||
83 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
91 | if (i2c_start(address)) { | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | for (uint16_t i = 0; i < length; i++) { | ||
96 | if (i2c_write(data[i])) { | ||
97 | return 1; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | i2c_stop(); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
diff --git a/keyboards/ymd75/i2c.h b/keyboards/ymd75/i2c.h deleted file mode 100644 index 27c9d3d05..000000000 --- a/keyboards/ymd75/i2c.h +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef __I2C_H__ | ||
19 | #define __I2C_H__ | ||
20 | |||
21 | void i2c_init(void); | ||
22 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
23 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
24 | |||
25 | #endif | ||
diff --git a/keyboards/ymd75/rules.mk b/keyboards/ymd75/rules.mk index 7bee20173..0c1c9110c 100644 --- a/keyboards/ymd75/rules.mk +++ b/keyboards/ymd75/rules.mk | |||
@@ -1,19 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
2 | # Modified 2018 Wayne Jones (WarmCatUK) <waynekjones@gmail.com> | ||
3 | |||
4 | # This program is free software: you can redistribute it and/or modify | ||
5 | # it under the terms of the GNU General Public License as published by | ||
6 | # the Free Software Foundation, either version 2 of the License, or | ||
7 | # (at your option) any later version. | ||
8 | # | ||
9 | # This program is distributed in the hope that it will be useful, | ||
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | # GNU General Public License for more details. | ||
13 | # | ||
14 | # You should have received a copy of the GNU General Public License | ||
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | |||
17 | # MCU name | 1 | # MCU name |
18 | MCU = atmega32a | 2 | MCU = atmega32a |
19 | 3 | ||
@@ -35,7 +19,7 @@ CONSOLE_ENABLE = no | |||
35 | COMMAND_ENABLE = yes | 19 | COMMAND_ENABLE = yes |
36 | BACKLIGHT_ENABLE = yes | 20 | BACKLIGHT_ENABLE = yes |
37 | RGBLIGHT_ENABLE = yes | 21 | RGBLIGHT_ENABLE = yes |
38 | RGBLIGHT_CUSTOM_DRIVER = yes | 22 | WS2812_DRIVER = i2c |
39 | NKRO_ENABLE = no | 23 | NKRO_ENABLE = no |
40 | # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 24 | # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
41 | 25 | ||
@@ -51,4 +35,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend | |||
51 | 35 | ||
52 | # custom matrix setup | 36 | # custom matrix setup |
53 | CUSTOM_MATRIX = yes | 37 | CUSTOM_MATRIX = yes |
54 | SRC = matrix.c i2c.c backlight.c | 38 | SRC = matrix.c backlight.c |
diff --git a/keyboards/ymd75/ymd75.c b/keyboards/ymd75/ymd75.c index 2259dfa5f..74f7c6a49 100644 --- a/keyboards/ymd75/ymd75.c +++ b/keyboards/ymd75/ymd75.c | |||
@@ -16,23 +16,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "ymd75.h" | 18 | #include "ymd75.h" |
19 | //#include "rgblight.h" | ||
20 | |||
21 | #include <avr/pgmspace.h> | ||
22 | |||
23 | #include "action_layer.h" | ||
24 | #include "i2c.h" | ||
25 | #include "quantum.h" | ||
26 | 19 | ||
27 | #include "backlight.h" | 20 | #include "backlight.h" |
28 | #include "backlight_custom.h" | 21 | #include "backlight_custom.h" |
29 | 22 | ||
30 | // for keyboard subdirectory level init functions | 23 | void matrix_init_kb(void) { matrix_init_user(); } |
31 | // @Override | 24 | |
32 | void matrix_init_kb(void) { | 25 | __attribute__ ((weak)) |
33 | // call user level keymaps, if any | 26 | void matrix_init_user(void) {} |
34 | matrix_init_user(); | 27 | |
35 | } | 28 | void matrix_scan_kb(void) { matrix_scan_user(); } |
29 | |||
30 | __attribute__ ((weak)) | ||
31 | void matrix_scan_user(void) {} | ||
36 | 32 | ||
37 | #ifdef BACKLIGHT_ENABLE | 33 | #ifdef BACKLIGHT_ENABLE |
38 | /// Overrides functions in `quantum.c` | 34 | /// Overrides functions in `quantum.c` |
@@ -48,48 +44,3 @@ void backlight_set(uint8_t level) { | |||
48 | b_led_set(level); | 44 | b_led_set(level); |
49 | } | 45 | } |
50 | #endif | 46 | #endif |
51 | |||
52 | #ifdef RGBLIGHT_ENABLE | ||
53 | extern rgblight_config_t rgblight_config; | ||
54 | |||
55 | // custom RGB driver | ||
56 | void rgblight_set(void) { | ||
57 | if (!rgblight_config.enable) { | ||
58 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
59 | led[i].r = 0; | ||
60 | led[i].g = 0; | ||
61 | led[i].b = 0; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | i2c_init(); | ||
66 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
67 | } | ||
68 | |||
69 | bool rgb_init = false; | ||
70 | |||
71 | void matrix_scan_kb(void) { | ||
72 | // if LEDs were previously on before poweroff, turn them back on | ||
73 | if (rgb_init == false && rgblight_config.enable) { | ||
74 | i2c_init(); | ||
75 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
76 | rgb_init = true; | ||
77 | } | ||
78 | |||
79 | rgblight_task(); | ||
80 | #else | ||
81 | void matrix_scan_kb(void) { | ||
82 | #endif | ||
83 | matrix_scan_user(); | ||
84 | /* Nothing else for now. */ | ||
85 | } | ||
86 | |||
87 | __attribute__((weak)) // overridable | ||
88 | void matrix_init_user(void) { | ||
89 | |||
90 | } | ||
91 | |||
92 | __attribute__((weak)) // overridable | ||
93 | void matrix_scan_user(void) { | ||
94 | |||
95 | } | ||
diff --git a/keyboards/ymd96/i2c.c b/keyboards/ymd96/i2c.c deleted file mode 100644 index c27f3e3d1..000000000 --- a/keyboards/ymd96/i2c.c +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <avr/io.h> | ||
19 | #include <util/twi.h> | ||
20 | |||
21 | #include "i2c.h" | ||
22 | |||
23 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
24 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
25 | if (bitrate_div >= 16) { | ||
26 | bitrate_div = (bitrate_div - 16) / 2; | ||
27 | } | ||
28 | TWBR = bitrate_div; | ||
29 | } | ||
30 | |||
31 | void i2c_init(void) { | ||
32 | // set pull-up resistors on I2C bus pins | ||
33 | PORTC |= 0b11; | ||
34 | |||
35 | i2c_set_bitrate(400); | ||
36 | |||
37 | // enable TWI (two-wire interface) | ||
38 | TWCR |= (1 << TWEN); | ||
39 | |||
40 | // enable TWI interrupt and slave address ACK | ||
41 | TWCR |= (1 << TWIE); | ||
42 | TWCR |= (1 << TWEA); | ||
43 | } | ||
44 | |||
45 | uint8_t i2c_start(uint8_t address) { | ||
46 | // reset TWI control register | ||
47 | TWCR = 0; | ||
48 | |||
49 | // begin transmission and wait for it to end | ||
50 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
51 | while (!(TWCR & (1<<TWINT))); | ||
52 | |||
53 | // check if the start condition was successfully transmitted | ||
54 | if ((TWSR & 0xF8) != TW_START) { | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | // transmit address and wait | ||
59 | TWDR = address; | ||
60 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
61 | while (!(TWCR & (1<<TWINT))); | ||
62 | |||
63 | // check if the device has acknowledged the READ / WRITE mode | ||
64 | uint8_t twst = TW_STATUS & 0xF8; | ||
65 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | void i2c_stop(void) { | ||
73 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
74 | } | ||
75 | |||
76 | uint8_t i2c_write(uint8_t data) { | ||
77 | TWDR = data; | ||
78 | |||
79 | // transmit data and wait | ||
80 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
81 | while (!(TWCR & (1<<TWINT))); | ||
82 | |||
83 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
91 | if (i2c_start(address)) { | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | for (uint16_t i = 0; i < length; i++) { | ||
96 | if (i2c_write(data[i])) { | ||
97 | return 1; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | i2c_stop(); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
diff --git a/keyboards/ymd96/i2c.h b/keyboards/ymd96/i2c.h deleted file mode 100644 index 27c9d3d05..000000000 --- a/keyboards/ymd96/i2c.h +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef __I2C_H__ | ||
19 | #define __I2C_H__ | ||
20 | |||
21 | void i2c_init(void); | ||
22 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
23 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
24 | |||
25 | #endif | ||
diff --git a/keyboards/ymd96/rules.mk b/keyboards/ymd96/rules.mk index 96441e1b3..19d9fd81a 100644 --- a/keyboards/ymd96/rules.mk +++ b/keyboards/ymd96/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -37,7 +22,7 @@ BACKLIGHT_ENABLE = yes | |||
37 | BACKLIGHT_CUSTOM_DRIVER = yes | 22 | BACKLIGHT_CUSTOM_DRIVER = yes |
38 | 23 | ||
39 | RGBLIGHT_ENABLE = yes | 24 | RGBLIGHT_ENABLE = yes |
40 | RGBLIGHT_CUSTOM_DRIVER = yes | 25 | WS2812_DRIVER = i2c |
41 | 26 | ||
42 | KEY_LOCK_ENABLE = yes | 27 | KEY_LOCK_ENABLE = yes |
43 | 28 | ||
@@ -48,4 +33,4 @@ OPT_DEFS = -DDEBUG_LEVEL=0 | |||
48 | 33 | ||
49 | # custom matrix setup | 34 | # custom matrix setup |
50 | CUSTOM_MATRIX = yes | 35 | CUSTOM_MATRIX = yes |
51 | SRC = matrix.c i2c.c backlight.c | 36 | SRC = matrix.c backlight.c |
diff --git a/keyboards/ymd96/ymd96.c b/keyboards/ymd96/ymd96.c index b0bf6128f..546a4c6e3 100644 --- a/keyboards/ymd96/ymd96.c +++ b/keyboards/ymd96/ymd96.c | |||
@@ -18,22 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | 18 | ||
19 | #include "ymd96.h" | 19 | #include "ymd96.h" |
20 | 20 | ||
21 | #include <avr/pgmspace.h> | 21 | #include "backlight.h" |
22 | #include "backlight_custom.h" | ||
22 | 23 | ||
23 | #include "action_layer.h" | 24 | void matrix_init_kb(void) { matrix_init_user(); } |
24 | #include "quantum.h" | ||
25 | 25 | ||
26 | #include "i2c.h" | 26 | __attribute__ ((weak)) |
27 | void matrix_init_user(void) {} | ||
27 | 28 | ||
28 | #include "backlight.h" | 29 | void matrix_scan_kb(void) { matrix_scan_user(); } |
29 | #include "backlight_custom.h" | ||
30 | 30 | ||
31 | // for keyboard subdirectory level init functions | 31 | __attribute__ ((weak)) |
32 | // @Override | 32 | void matrix_scan_user(void) {} |
33 | void matrix_init_kb(void) { | ||
34 | // call user level keymaps, if any | ||
35 | matrix_init_user(); | ||
36 | } | ||
37 | 33 | ||
38 | #ifdef BACKLIGHT_ENABLE | 34 | #ifdef BACKLIGHT_ENABLE |
39 | /// Overrides functions in `quantum.c` | 35 | /// Overrides functions in `quantum.c` |
@@ -49,49 +45,3 @@ void backlight_set(uint8_t level) { | |||
49 | b_led_set(level); | 45 | b_led_set(level); |
50 | } | 46 | } |
51 | #endif | 47 | #endif |
52 | |||
53 | #ifdef RGBLIGHT_ENABLE | ||
54 | extern rgblight_config_t rgblight_config; | ||
55 | |||
56 | // custom RGB driver | ||
57 | void rgblight_set(void) { | ||
58 | if (!rgblight_config.enable) { | ||
59 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
60 | led[i].r = 0; | ||
61 | led[i].g = 0; | ||
62 | led[i].b = 0; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | i2c_init(); | ||
67 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
68 | } | ||
69 | |||
70 | bool rgb_init = false; | ||
71 | |||
72 | void matrix_scan_kb(void) { | ||
73 | // if LEDs were previously on before poweroff, turn them back on | ||
74 | if (rgb_init == false && rgblight_config.enable) { | ||
75 | i2c_init(); | ||
76 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
77 | rgb_init = true; | ||
78 | } | ||
79 | |||
80 | rgblight_task(); | ||
81 | #else | ||
82 | void matrix_scan_kb(void) { | ||
83 | #endif | ||
84 | matrix_scan_user(); | ||
85 | /* Nothing else for now. */ | ||
86 | } | ||
87 | |||
88 | __attribute__((weak)) // overridable | ||
89 | void matrix_init_user(void) { | ||
90 | |||
91 | } | ||
92 | |||
93 | |||
94 | __attribute__((weak)) // overridable | ||
95 | void matrix_scan_user(void) { | ||
96 | |||
97 | } | ||
diff --git a/keyboards/ymdk_np21/i2c.c b/keyboards/ymdk_np21/i2c.c deleted file mode 100644 index c27f3e3d1..000000000 --- a/keyboards/ymdk_np21/i2c.c +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #include <avr/io.h> | ||
19 | #include <util/twi.h> | ||
20 | |||
21 | #include "i2c.h" | ||
22 | |||
23 | void i2c_set_bitrate(uint16_t bitrate_khz) { | ||
24 | uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); | ||
25 | if (bitrate_div >= 16) { | ||
26 | bitrate_div = (bitrate_div - 16) / 2; | ||
27 | } | ||
28 | TWBR = bitrate_div; | ||
29 | } | ||
30 | |||
31 | void i2c_init(void) { | ||
32 | // set pull-up resistors on I2C bus pins | ||
33 | PORTC |= 0b11; | ||
34 | |||
35 | i2c_set_bitrate(400); | ||
36 | |||
37 | // enable TWI (two-wire interface) | ||
38 | TWCR |= (1 << TWEN); | ||
39 | |||
40 | // enable TWI interrupt and slave address ACK | ||
41 | TWCR |= (1 << TWIE); | ||
42 | TWCR |= (1 << TWEA); | ||
43 | } | ||
44 | |||
45 | uint8_t i2c_start(uint8_t address) { | ||
46 | // reset TWI control register | ||
47 | TWCR = 0; | ||
48 | |||
49 | // begin transmission and wait for it to end | ||
50 | TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); | ||
51 | while (!(TWCR & (1<<TWINT))); | ||
52 | |||
53 | // check if the start condition was successfully transmitted | ||
54 | if ((TWSR & 0xF8) != TW_START) { | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | // transmit address and wait | ||
59 | TWDR = address; | ||
60 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
61 | while (!(TWCR & (1<<TWINT))); | ||
62 | |||
63 | // check if the device has acknowledged the READ / WRITE mode | ||
64 | uint8_t twst = TW_STATUS & 0xF8; | ||
65 | if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | void i2c_stop(void) { | ||
73 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
74 | } | ||
75 | |||
76 | uint8_t i2c_write(uint8_t data) { | ||
77 | TWDR = data; | ||
78 | |||
79 | // transmit data and wait | ||
80 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
81 | while (!(TWCR & (1<<TWINT))); | ||
82 | |||
83 | if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { | ||
91 | if (i2c_start(address)) { | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | for (uint16_t i = 0; i < length; i++) { | ||
96 | if (i2c_write(data[i])) { | ||
97 | return 1; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | i2c_stop(); | ||
102 | |||
103 | return 0; | ||
104 | } | ||
diff --git a/keyboards/ymdk_np21/i2c.h b/keyboards/ymdk_np21/i2c.h deleted file mode 100644 index 27c9d3d05..000000000 --- a/keyboards/ymdk_np21/i2c.h +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #ifndef __I2C_H__ | ||
19 | #define __I2C_H__ | ||
20 | |||
21 | void i2c_init(void); | ||
22 | void i2c_set_bitrate(uint16_t bitrate_khz); | ||
23 | uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); | ||
24 | |||
25 | #endif | ||
diff --git a/keyboards/ymdk_np21/rules.mk b/keyboards/ymdk_np21/rules.mk index 634b9c69c..2bab3043e 100644 --- a/keyboards/ymdk_np21/rules.mk +++ b/keyboards/ymdk_np21/rules.mk | |||
@@ -1,18 +1,3 @@ | |||
1 | # Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | ||
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 | # MCU name | 1 | # MCU name |
17 | MCU = atmega32a | 2 | MCU = atmega32a |
18 | 3 | ||
@@ -37,8 +22,7 @@ BACKLIGHT_ENABLE = yes | |||
37 | BACKLIGHT_CUSTOM_DRIVER = yes | 22 | BACKLIGHT_CUSTOM_DRIVER = yes |
38 | 23 | ||
39 | RGBLIGHT_ENABLE = yes | 24 | RGBLIGHT_ENABLE = yes |
40 | RGBLIGHT_CUSTOM_DRIVER = yes | 25 | WS2812_DRIVER = i2c |
41 | # DISABLE_WS2812 = no | ||
42 | 26 | ||
43 | KEY_LOCK_ENABLE = yes | 27 | KEY_LOCK_ENABLE = yes |
44 | 28 | ||
@@ -49,4 +33,4 @@ OPT_DEFS = -DDEBUG_LEVEL=0 | |||
49 | 33 | ||
50 | # custom matrix setup | 34 | # custom matrix setup |
51 | CUSTOM_MATRIX = yes | 35 | CUSTOM_MATRIX = yes |
52 | SRC = matrix.c i2c.c backlight.c | 36 | SRC = matrix.c backlight.c |
diff --git a/keyboards/ymdk_np21/ymdk_np21.c b/keyboards/ymdk_np21/ymdk_np21.c index c1b11b404..f2b3d46da 100644 --- a/keyboards/ymdk_np21/ymdk_np21.c +++ b/keyboards/ymdk_np21/ymdk_np21.c | |||
@@ -18,25 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
18 | 18 | ||
19 | #include "ymdk_np21.h" | 19 | #include "ymdk_np21.h" |
20 | 20 | ||
21 | #include <avr/pgmspace.h> | ||
22 | |||
23 | #include "action_layer.h" | ||
24 | #include "quantum.h" | ||
25 | |||
26 | #include "i2c.h" | ||
27 | |||
28 | #include "backlight.h" | 21 | #include "backlight.h" |
29 | #include "backlight_custom.h" | 22 | #include "backlight_custom.h" |
30 | 23 | ||
31 | extern rgblight_config_t rgblight_config; | ||
32 | |||
33 | // for keyboard subdirectory level init functions | ||
34 | // @Override | ||
35 | void matrix_init_kb(void) { | ||
36 | // call user level keymaps, if any | ||
37 | matrix_init_user(); | ||
38 | } | ||
39 | |||
40 | #ifdef BACKLIGHT_ENABLE | 24 | #ifdef BACKLIGHT_ENABLE |
41 | /// Overrides functions in `quantum.c` | 25 | /// Overrides functions in `quantum.c` |
42 | void backlight_init_ports(void) { | 26 | void backlight_init_ports(void) { |
@@ -51,32 +35,3 @@ void backlight_set(uint8_t level) { | |||
51 | b_led_set(level); | 35 | b_led_set(level); |
52 | } | 36 | } |
53 | #endif | 37 | #endif |
54 | |||
55 | // custom RGB driver | ||
56 | void rgblight_set(void) { | ||
57 | if (!rgblight_config.enable) { | ||
58 | for (uint8_t i=0; i<RGBLED_NUM; i++) { | ||
59 | led[i].r = 0; | ||
60 | led[i].g = 0; | ||
61 | led[i].b = 0; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | i2c_init(); | ||
66 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
67 | } | ||
68 | |||
69 | bool rgb_init = false; | ||
70 | void matrix_scan_kb(void) { | ||
71 | // if LEDs were previously on before poweroff, turn them back on | ||
72 | if (rgb_init == false && rgblight_config.enable) { | ||
73 | i2c_init(); | ||
74 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | ||
75 | rgb_init = true; | ||
76 | } | ||
77 | |||
78 | rgblight_task(); | ||
79 | /* Nothing else for now. */ | ||
80 | |||
81 | matrix_scan_user(); | ||
82 | } | ||