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/mehkee96 | |
| 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/mehkee96')
| -rw-r--r-- | keyboards/mehkee96/i2c.c | 106 | ||||
| -rw-r--r-- | keyboards/mehkee96/i2c.h | 27 | ||||
| -rw-r--r-- | keyboards/mehkee96/mehkee96.c | 65 | ||||
| -rw-r--r-- | keyboards/mehkee96/rules.mk | 4 |
4 files changed, 8 insertions, 194 deletions
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 |
