diff options
| author | MechMerlin <30334081+mechmerlin@users.noreply.github.com> | 2019-04-07 07:34:01 -0700 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-04-07 07:34:01 -0700 |
| commit | a8e3462b4bd5706f17f460e36b88b4063ef148f6 (patch) | |
| tree | 71347d261fd54c053893d7364ed3b2e0b827b050 /keyboards/donutcables | |
| parent | b8f7834051f601d028b8182077322c1b45d7c112 (diff) | |
| download | qmk_firmware-a8e3462b4bd5706f17f460e36b88b4063ef148f6.tar.gz qmk_firmware-a8e3462b4bd5706f17f460e36b88b4063ef148f6.zip | |
[Keyboard] Refactor budget96 to remove custom i2c code in favor of QMK i2c_master (#5571)
* remove custom i2c code in favor of QMK i2c_master
* fix readme
* disable bootmagic as it doesn't work on bmc boards
Diffstat (limited to 'keyboards/donutcables')
| -rw-r--r-- | keyboards/donutcables/budget96/budget96.c | 4 | ||||
| -rw-r--r-- | keyboards/donutcables/budget96/config.h | 6 | ||||
| -rw-r--r-- | keyboards/donutcables/budget96/i2c.c | 106 | ||||
| -rw-r--r-- | keyboards/donutcables/budget96/i2c.h | 24 | ||||
| -rw-r--r-- | keyboards/donutcables/budget96/readme.md | 4 | ||||
| -rw-r--r-- | keyboards/donutcables/budget96/rules.mk | 4 |
6 files changed, 6 insertions, 142 deletions
diff --git a/keyboards/donutcables/budget96/budget96.c b/keyboards/donutcables/budget96/budget96.c index 966dd4c12..7831a91f5 100644 --- a/keyboards/donutcables/budget96/budget96.c +++ b/keyboards/donutcables/budget96/budget96.c | |||
| @@ -25,7 +25,7 @@ | |||
| 25 | #include <avr/pgmspace.h> | 25 | #include <avr/pgmspace.h> |
| 26 | 26 | ||
| 27 | #include "action_layer.h" | 27 | #include "action_layer.h" |
| 28 | #include "i2c.h" | 28 | #include "i2c_master.h" |
| 29 | #include "quantum.h" | 29 | #include "quantum.h" |
| 30 | 30 | ||
| 31 | __attribute__ ((weak)) | 31 | __attribute__ ((weak)) |
| @@ -45,7 +45,7 @@ void rgblight_set(void) { | |||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | i2c_init(); | 47 | i2c_init(); |
| 48 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | 48 | i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100); |
| 49 | } | 49 | } |
| 50 | #endif | 50 | #endif |
| 51 | 51 | ||
diff --git a/keyboards/donutcables/budget96/config.h b/keyboards/donutcables/budget96/config.h index 369cbdd07..74661d828 100644 --- a/keyboards/donutcables/budget96/config.h +++ b/keyboards/donutcables/budget96/config.h | |||
| @@ -39,9 +39,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 39 | #define NO_BACKLIGHT_CLOCK | 39 | #define NO_BACKLIGHT_CLOCK |
| 40 | #define BACKLIGHT_LEVELS 1 | 40 | #define BACKLIGHT_LEVELS 1 |
| 41 | #define RGBLIGHT_ANIMATIONS | 41 | #define RGBLIGHT_ANIMATIONS |
| 42 | |||
| 43 | // Set bootmagic lite key to the key commonly programmed as Esc. | ||
| 44 | #define BOOTMAGIC_LITE_ROW 5 | ||
| 45 | #define BOOTMAGIC_LITE_COLUMN 0 | ||
| 46 | |||
| 47 | /* key combination for command */ | ||
diff --git a/keyboards/donutcables/budget96/i2c.c b/keyboards/donutcables/budget96/i2c.c deleted file mode 100644 index e8c4455ad..000000000 --- a/keyboards/donutcables/budget96/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/donutcables/budget96/i2c.h b/keyboards/donutcables/budget96/i2c.h deleted file mode 100644 index aecc2c05a..000000000 --- a/keyboards/donutcables/budget96/i2c.h +++ /dev/null | |||
| @@ -1,24 +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); | ||
diff --git a/keyboards/donutcables/budget96/readme.md b/keyboards/donutcables/budget96/readme.md index e44b9a3e7..70e4d3afb 100644 --- a/keyboards/donutcables/budget96/readme.md +++ b/keyboards/donutcables/budget96/readme.md | |||
| @@ -12,7 +12,7 @@ Make example for this keyboard (after setting up your build environment): | |||
| 12 | 12 | ||
| 13 | Flashing | 13 | Flashing |
| 14 | 14 | ||
| 15 | **Reset Key:** Hold down the key located at `K00`, commonly programmed as left control while plugging in the keyboard. You may also hold down the key located at `K50`, commonly programmed as the `Esc` key. | 15 | **Reset Key:** Hold down the key located at `K00`, commonly programmed as left control while plugging in the keyboard. |
| 16 | 16 | ||
| 17 | ps2avr(GB) boards use an atmega32a microcontroller and a different bootloader. It is not flashable using the regular QMK methods. | 17 | ps2avr(GB) boards use an atmega32a microcontroller and a different bootloader. It is not flashable using the regular QMK methods. |
| 18 | 18 | ||
| @@ -34,7 +34,7 @@ macOS: | |||
| 34 | ``` | 34 | ``` |
| 35 | 3. Install the following packages: | 35 | 3. Install the following packages: |
| 36 | ``` | 36 | ``` |
| 37 | brew install python | 37 | brew install python3 |
| 38 | pip3 install pyusb | 38 | pip3 install pyusb |
| 39 | brew install --HEAD https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb | 39 | brew install --HEAD https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb |
| 40 | 40 | ||
diff --git a/keyboards/donutcables/budget96/rules.mk b/keyboards/donutcables/budget96/rules.mk index e25b03727..67697ac73 100644 --- a/keyboards/donutcables/budget96/rules.mk +++ b/keyboards/donutcables/budget96/rules.mk | |||
| @@ -31,7 +31,7 @@ F_CPU = 12000000 | |||
| 31 | BOOTLOADER = bootloadHID | 31 | BOOTLOADER = bootloadHID |
| 32 | 32 | ||
| 33 | # build options | 33 | # build options |
| 34 | BOOTMAGIC_ENABLE = lite | 34 | BOOTMAGIC_ENABLE = no |
| 35 | MOUSEKEY_ENABLE = yes | 35 | MOUSEKEY_ENABLE = yes |
| 36 | EXTRAKEY_ENABLE = yes | 36 | EXTRAKEY_ENABLE = yes |
| 37 | CONSOLE_ENABLE = yes | 37 | CONSOLE_ENABLE = yes |
| @@ -43,7 +43,7 @@ RGBLIGHT_CUSTOM_DRIVER = yes | |||
| 43 | OPT_DEFS = -DDEBUG_LEVEL=0 | 43 | OPT_DEFS = -DDEBUG_LEVEL=0 |
| 44 | 44 | ||
| 45 | # custom matrix setup | 45 | # custom matrix setup |
| 46 | SRC = i2c.c | 46 | SRC = i2c_master.c |
| 47 | 47 | ||
| 48 | # programming options | 48 | # programming options |
| 49 | PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex | 49 | PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex |
