diff options
author | fauxpark <fauxpark@gmail.com> | 2019-11-04 09:43:13 +1100 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-11-03 14:43:13 -0800 |
commit | 3a215195ed3a12464df7169e7b68bfe0763e95b1 (patch) | |
tree | 914eb8dadc62958633a862a8f25870b7a98fd4cc /keyboards/mt40 | |
parent | a4d138645fdb5043cd76bc135eea48453cc50dff (diff) | |
download | qmk_firmware-3a215195ed3a12464df7169e7b68bfe0763e95b1.tar.gz qmk_firmware-3a215195ed3a12464df7169e7b68bfe0763e95b1.zip |
Convert remaining PS2AVRGB boards to I2C WS2812 driver (#7245)
* Convert remaining PS2AVRGB boards to I2C WS2812 driver
* Add back functions to make the custom matrices happy
Diffstat (limited to 'keyboards/mt40')
-rw-r--r-- | keyboards/mt40/i2c.c | 104 | ||||
-rw-r--r-- | keyboards/mt40/i2c.h | 25 | ||||
-rw-r--r-- | keyboards/mt40/mt40.c | 29 | ||||
-rw-r--r-- | keyboards/mt40/rules.mk | 4 |
4 files changed, 3 insertions, 159 deletions
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 |