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/jj50 | |
| 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/jj50')
| -rw-r--r-- | keyboards/jj50/i2c.c | 104 | ||||
| -rw-r--r-- | keyboards/jj50/i2c.h | 25 | ||||
| -rw-r--r-- | keyboards/jj50/jj50.c | 67 | ||||
| -rw-r--r-- | keyboards/jj50/rules.mk | 24 |
4 files changed, 11 insertions, 209 deletions
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 |
