diff options
| -rw-r--r-- | keyboards/winkeyless/bface/backlight_ps2avrGB.c | 94 | ||||
| -rw-r--r-- | keyboards/winkeyless/bface/backlight_ps2avrGB.h | 35 | ||||
| -rw-r--r-- | keyboards/winkeyless/bface/bface.c | 94 | ||||
| -rw-r--r-- | keyboards/winkeyless/bface/i2c.c | 104 | ||||
| -rw-r--r-- | keyboards/winkeyless/bface/i2c.h | 25 | ||||
| -rw-r--r-- | keyboards/winkeyless/bface/rules.mk | 2 |
6 files changed, 69 insertions, 285 deletions
diff --git a/keyboards/winkeyless/bface/backlight_ps2avrGB.c b/keyboards/winkeyless/bface/backlight_ps2avrGB.c deleted file mode 100644 index c0f642840..000000000 --- a/keyboards/winkeyless/bface/backlight_ps2avrGB.c +++ /dev/null | |||
| @@ -1,94 +0,0 @@ | |||
| 1 | /* Copyright 2017 Sebastian Kaim | ||
| 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 | |||
| 17 | #ifdef BACKLIGHT_ENABLE | ||
| 18 | |||
| 19 | #include "backlight_ps2avrGB.h" | ||
| 20 | #define sbi(reg,bit) reg |= (_BV(bit)) | ||
| 21 | #define cbi(reg,bit) reg &= (~_BV(bit)) | ||
| 22 | #define PWM10 WGM10 | ||
| 23 | #define PWM11 WGM11 | ||
| 24 | #define COM1x1 COM1B1 | ||
| 25 | #define OCR1x OCR1B | ||
| 26 | |||
| 27 | void backlight_init_ports(void) | ||
| 28 | { | ||
| 29 | #if BACKLIGHT_ON_STATE == 0 | ||
| 30 | backlight_off(); | ||
| 31 | #else | ||
| 32 | backlight_on(); | ||
| 33 | #endif | ||
| 34 | |||
| 35 | // setup pwm | ||
| 36 | // this bitmagic is sourced from the original firmware | ||
| 37 | /*TCCR1B = ((TCCR1B & ~0x07) | 0x03); | ||
| 38 | TCNT1H = 0; | ||
| 39 | TCNT1L = 0; | ||
| 40 | sbi(TIMSK, TOIE1); | ||
| 41 | OCR1BH = 0; | ||
| 42 | OCR1BL = 0; | ||
| 43 | cbi(TCCR1A,PWM11); | ||
| 44 | sbi(TCCR1A,PWM10); | ||
| 45 | sbi(TCCR1A,COM1B1); | ||
| 46 | cbi(TCCR1A,COM1B0);*/ | ||
| 47 | ICR1 = 0xFFFF; | ||
| 48 | |||
| 49 | TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010; | ||
| 50 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 51 | |||
| 52 | backlight_init(); | ||
| 53 | } | ||
| 54 | |||
| 55 | void backlight_set(uint8_t level) | ||
| 56 | { | ||
| 57 | if( level == 0 ) { | ||
| 58 | backlight_off(); | ||
| 59 | } | ||
| 60 | else { | ||
| 61 | backlight_on(); | ||
| 62 | /*uint8_t pwm = get_pwm_for_brightness(level); | ||
| 63 | set_backlight_pwm(pwm); | ||
| 64 | TCCR1A |= _BV(COM1x1); | ||
| 65 | OCR1x = (level >= 2) ? 0xFFFF : 0x00FF;*/ | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | #define PWM_MAX 0xFF | ||
| 70 | uint8_t get_pwm_for_brightness(uint8_t level) | ||
| 71 | { | ||
| 72 | // we need to cast up here to allow multiplication with 0xFF. We could also use floats, but this is probably a lot faster. | ||
| 73 | uint16_t brightness = (uint16_t)level * (uint16_t)PWM_MAX / (uint16_t)BACKLIGHT_LEVELS; | ||
| 74 | return (uint8_t)brightness; | ||
| 75 | } | ||
| 76 | |||
| 77 | void backlight_on(void) | ||
| 78 | { | ||
| 79 | //_SFR_IO8(0x12) |= _BV(0x4); | ||
| 80 | LED_PIN |= BACKLIGHT_PORT_NUM; | ||
| 81 | } | ||
| 82 | |||
| 83 | void backlight_off(void) | ||
| 84 | { | ||
| 85 | //_SFR_IO8(0x12) &= ~_BV(0x4); | ||
| 86 | LED_PIN &= ~BACKLIGHT_PORT_NUM; | ||
| 87 | } | ||
| 88 | |||
| 89 | void set_backlight_pwm(uint8_t level) { | ||
| 90 | // this does not work (yet) | ||
| 91 | //OCR1B = level; | ||
| 92 | } | ||
| 93 | |||
| 94 | #endif // BACKLIGHT_ENABLE | ||
diff --git a/keyboards/winkeyless/bface/backlight_ps2avrGB.h b/keyboards/winkeyless/bface/backlight_ps2avrGB.h deleted file mode 100644 index d5ca90399..000000000 --- a/keyboards/winkeyless/bface/backlight_ps2avrGB.h +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | /* Copyright 2017 Sebastian Kaim | ||
| 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 | |||
| 17 | |||
| 18 | #if defined(__AVR__) | ||
| 19 | #include <avr/pgmspace.h> | ||
| 20 | #include <avr/io.h> | ||
| 21 | #include <avr/interrupt.h> | ||
| 22 | #endif | ||
| 23 | #include <stddef.h> | ||
| 24 | #include <stdlib.h> | ||
| 25 | #include "backlight.h" | ||
| 26 | |||
| 27 | #ifndef PS2AVRGB_BACKLIGHT_H | ||
| 28 | #define PS2AVRGB_BACKLIGHT_H | ||
| 29 | |||
| 30 | uint8_t get_pwm_for_brightness(uint8_t level); | ||
| 31 | void set_backlight_pwm(uint8_t level); | ||
| 32 | void backlight_on(void); | ||
| 33 | void backlight_off(void); | ||
| 34 | |||
| 35 | #endif | ||
diff --git a/keyboards/winkeyless/bface/bface.c b/keyboards/winkeyless/bface/bface.c index 8422a4a40..1c83be4b8 100644 --- a/keyboards/winkeyless/bface/bface.c +++ b/keyboards/winkeyless/bface/bface.c | |||
| @@ -1,30 +1,23 @@ | |||
| 1 | /* | 1 | /* Copyright 2019 MechMerlin |
| 2 | Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> | 2 | * |
| 3 | Copyright 2018 Sebastian Kaim <sebb@sebb767.de> | 3 | * This program is free software: you can redistribute it and/or modify |
| 4 | 4 | * it under the terms of the GNU General Public License as published by | |
| 5 | This program is free software: you can redistribute it and/or modify | 5 | * the Free Software Foundation, either version 2 of the License, or |
| 6 | it under the terms of the GNU General Public License as published by | 6 | * (at your option) any later version. |
| 7 | the Free Software Foundation, either version 2 of the License, or | 7 | * |
| 8 | (at your option) any later version. | 8 | * This program is distributed in the hope that it will be useful, |
| 9 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 | This program is distributed in the hope that it will be useful, | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * GNU General Public License for more details. |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * |
| 13 | GNU General Public License for more details. | 13 | * You should have received a copy of the GNU General Public License |
| 14 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 15 | You should have received a copy of the GNU General Public License | 15 | */ |
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "bface.h" | ||
| 20 | #include "rgblight.h" | 16 | #include "rgblight.h" |
| 21 | 17 | #include "i2c_master.h" | |
| 22 | #include <avr/pgmspace.h> | ||
| 23 | |||
| 24 | #include "action_layer.h" | ||
| 25 | #include "i2c.h" | ||
| 26 | #include "quantum.h" | 18 | #include "quantum.h" |
| 27 | 19 | ||
| 20 | #ifdef RGBLIGHT_ENABLE | ||
| 28 | extern rgblight_config_t rgblight_config; | 21 | extern rgblight_config_t rgblight_config; |
| 29 | 22 | ||
| 30 | void rgblight_set(void) { | 23 | void rgblight_set(void) { |
| @@ -37,10 +30,59 @@ void rgblight_set(void) { | |||
| 37 | } | 30 | } |
| 38 | 31 | ||
| 39 | i2c_init(); | 32 | i2c_init(); |
| 40 | i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); | 33 | i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100); |
| 34 | } | ||
| 35 | #endif | ||
| 36 | |||
| 37 | void matrix_init_kb(void) { | ||
| 38 | #ifdef RGBLIGHT_ENABLE | ||
| 39 | if (rgblight_config.enable) { | ||
| 40 | i2c_init(); | ||
| 41 | i2c_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100); | ||
| 42 | } | ||
| 43 | #endif | ||
| 44 | // call user level keymaps, if any | ||
| 45 | matrix_init_user(); | ||
| 46 | } | ||
| 47 | |||
| 48 | void matrix_scan_kb(void) { | ||
| 49 | #ifdef RGBLIGHT_ENABLE | ||
| 50 | rgblight_task(); | ||
| 51 | #endif | ||
| 52 | matrix_scan_user(); | ||
| 53 | /* Nothing else for now. */ | ||
| 41 | } | 54 | } |
| 42 | 55 | ||
| 43 | __attribute__ ((weak)) | 56 | __attribute__ ((weak)) |
| 44 | void matrix_scan_user(void) { | 57 | void matrix_scan_user(void) { |
| 45 | rgblight_task(); | 58 | } |
| 59 | |||
| 60 | void backlight_init_ports(void) { | ||
| 61 | // initialize pins D0, D1, D4 and D6 as output | ||
| 62 | setPinOutput(D0); | ||
| 63 | setPinOutput(D1); | ||
| 64 | setPinOutput(D4); | ||
| 65 | setPinOutput(D6); | ||
| 66 | |||
| 67 | // turn backlight LEDs on | ||
| 68 | writePinHigh(D0); | ||
| 69 | writePinHigh(D1); | ||
| 70 | writePinHigh(D4); | ||
| 71 | writePinHigh(D6); | ||
| 72 | } | ||
| 73 | |||
| 74 | void backlight_set(uint8_t level) { | ||
| 75 | if (level == 0) { | ||
| 76 | // turn backlight LEDs off | ||
| 77 | writePinLow(D0); | ||
| 78 | writePinLow(D1); | ||
| 79 | writePinLow(D4); | ||
| 80 | writePinLow(D6); | ||
| 81 | } else { | ||
| 82 | // turn backlight LEDs on | ||
| 83 | writePinHigh(D0); | ||
| 84 | writePinHigh(D1); | ||
| 85 | writePinHigh(D4); | ||
| 86 | writePinHigh(D6); | ||
| 87 | } | ||
| 46 | } | 88 | } |
diff --git a/keyboards/winkeyless/bface/i2c.c b/keyboards/winkeyless/bface/i2c.c deleted file mode 100644 index c27f3e3d1..000000000 --- a/keyboards/winkeyless/bface/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/winkeyless/bface/i2c.h b/keyboards/winkeyless/bface/i2c.h deleted file mode 100644 index 27c9d3d05..000000000 --- a/keyboards/winkeyless/bface/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/winkeyless/bface/rules.mk b/keyboards/winkeyless/bface/rules.mk index 49b012e52..b6d172f26 100644 --- a/keyboards/winkeyless/bface/rules.mk +++ b/keyboards/winkeyless/bface/rules.mk | |||
| @@ -40,7 +40,7 @@ OPT_DEFS = -DDEBUG_LEVEL=0 | |||
| 40 | OPT_DEFS += -DBOOTLOADER_SIZE=2048 | 40 | OPT_DEFS += -DBOOTLOADER_SIZE=2048 |
| 41 | 41 | ||
| 42 | # custom matrix setup | 42 | # custom matrix setup |
| 43 | SRC = i2c.c backlight_ps2avrGB.c | 43 | SRC = i2c_master.c |
| 44 | 44 | ||
| 45 | # programming options | 45 | # programming options |
| 46 | PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex | 46 | PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex |
