diff options
-rw-r--r-- | keyboards/winkeyless/bface/README.md | 4 | ||||
-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/bface.h | 11 | ||||
-rw-r--r-- | keyboards/winkeyless/bface/config.h | 9 | ||||
-rw-r--r-- | keyboards/winkeyless/bface/i2c.c | 104 | ||||
-rw-r--r-- | keyboards/winkeyless/bface/i2c.h | 25 | ||||
-rw-r--r-- | keyboards/winkeyless/bface/matrix.c | 113 | ||||
-rw-r--r-- | keyboards/winkeyless/bface/rules.mk | 5 | ||||
-rw-r--r-- | keyboards/winkeyless/bface/usbconfig.h | 5 |
11 files changed, 84 insertions, 415 deletions
diff --git a/keyboards/winkeyless/bface/README.md b/keyboards/winkeyless/bface/README.md index f1789b04c..da0eb8088 100644 --- a/keyboards/winkeyless/bface/README.md +++ b/keyboards/winkeyless/bface/README.md | |||
@@ -14,6 +14,8 @@ Flashing | |||
14 | 14 | ||
15 | ps2avr(GB) boards use an atmega32a microcontroller and a different bootloader. It is not flashable using the regular QMK methods. | 15 | ps2avr(GB) boards use an atmega32a microcontroller and a different bootloader. It is not flashable using the regular QMK methods. |
16 | 16 | ||
17 | **Reset Key:** Hold down the key located at K00, commonly programmed as left control while plugging in the keyboard. | ||
18 | |||
17 | Windows: | 19 | Windows: |
18 | 1. Download [HIDBootFlash](http://vusb.wikidot.com/project:hidbootflash). | 20 | 1. Download [HIDBootFlash](http://vusb.wikidot.com/project:hidbootflash). |
19 | 2. Place your keyboard into reset. | 21 | 2. Place your keyboard into reset. |
@@ -33,7 +35,7 @@ macOS: | |||
33 | 3. Install the following packages: | 35 | 3. Install the following packages: |
34 | ``` | 36 | ``` |
35 | brew install python | 37 | brew install python |
36 | brew install pyusb | 38 | pip3 install pyusb |
37 | 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 |
38 | ``` | 40 | ``` |
39 | 41 | ||
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/bface.h b/keyboards/winkeyless/bface/bface.h index 62d62f695..f7a3b9521 100644 --- a/keyboards/winkeyless/bface/bface.h +++ b/keyboards/winkeyless/bface/bface.h | |||
@@ -16,8 +16,7 @@ You should have received a copy of the GNU General Public License | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #ifndef KEYMAP_COMMON_H | 19 | #pragma once |
20 | #define KEYMAP_COMMON_H | ||
21 | 20 | ||
22 | #include "quantum_keycodes.h" | 21 | #include "quantum_keycodes.h" |
23 | #include "keycode.h" | 22 | #include "keycode.h" |
@@ -27,8 +26,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
27 | K04, K14, K24, K34, K44, K54, K16, KB6, KB7, K17, KA4, KB4, KC4, KE4, \ | 26 | K04, K14, K24, K34, K44, K54, K16, KB6, KB7, K17, KA4, KB4, KC4, KE4, \ |
28 | K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC3, KD3, \ | 27 | K03, K13, K23, K33, K43, K53, K26, KC6, KC7, K27, KA3, KB3, KC3, KD3, \ |
29 | K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KB2, KD2, \ | 28 | K02, K12, K22, K32, K42, K52, K36, KD6, KD7, K37, KA2, KB2, KD2, \ |
30 | K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KB1, \ | 29 | K01, K11, K21, K31, K41, K51, K46, KE6, KE7, K47, KA1, KB1, \ |
31 | K00, K10, K20, K56, K57, KA0, KB0, KC0 \ | 30 | K00, K10, K20, K56, K57, KA0, KB0, KC0 \ |
32 | ){ \ | 31 | ){ \ |
33 | { K00, K10, K20, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KA0, KB0, KC0, KC_NO, KC_NO }, \ | 32 | { K00, K10, K20, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KA0, KB0, KC0, KC_NO, KC_NO }, \ |
34 | { K01, K11, K21, K31, K41, K51, KC_NO, KC_NO, KC_NO, KC_NO, KA1, KB1, KC_NO, KC_NO, KC_NO }, \ | 33 | { K01, K11, K21, K31, K41, K51, KC_NO, KC_NO, KC_NO, KC_NO, KA1, KB1, KC_NO, KC_NO, KC_NO }, \ |
@@ -37,8 +36,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
37 | { K04, K14, K24, K34, K44, K54, KC_NO, KC_NO, KC_NO, KC_NO, KA4, KB4, KC4, KC_NO, KE4 }, \ | 36 | { K04, K14, K24, K34, K44, K54, KC_NO, KC_NO, KC_NO, KC_NO, KA4, KB4, KC4, KC_NO, KE4 }, \ |
38 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ | 37 | { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \ |
39 | { KC_NO, K16, K26, K36, K46, K56, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KB6, KC6, KD6, KE6 }, \ | 38 | { KC_NO, K16, K26, K36, K46, K56, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KB6, KC6, KD6, KE6 }, \ |
40 | { KC_NO, K17, K27, K37, K47, K57, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KB7, KC7, KD7, KE7 } \ | 39 | { KC_NO, K17, K27, K37, K47, K57, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KB7, KC7, KD7, KE7 } \ |
41 | } | 40 | } |
42 | 41 | ||
43 | |||
44 | #endif | ||
diff --git a/keyboards/winkeyless/bface/config.h b/keyboards/winkeyless/bface/config.h index 11ac373c0..7a1fe3335 100644 --- a/keyboards/winkeyless/bface/config.h +++ b/keyboards/winkeyless/bface/config.h | |||
@@ -16,8 +16,7 @@ You should have received a copy of the GNU General Public License | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #ifndef CONFIG_H | 19 | #pragma once |
20 | #define CONFIG_H | ||
21 | 20 | ||
22 | #define VENDOR_ID 0x20A0 | 21 | #define VENDOR_ID 0x20A0 |
23 | #define PRODUCT_ID 0x422D | 22 | #define PRODUCT_ID 0x422D |
@@ -30,6 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
30 | #define MATRIX_ROWS 8 | 29 | #define MATRIX_ROWS 8 |
31 | #define MATRIX_COLS 15 | 30 | #define MATRIX_COLS 15 |
32 | 31 | ||
32 | // 0 1 2 3 4 5 6 7 8 9 A B C D E | ||
33 | #define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, B5, B6, B7 } | ||
34 | #define MATRIX_COL_PINS { A0, A1, A2, A3, A4, A5, A6, A7, C7, C6, C5, C4, C3, C2, D7} | ||
35 | #define UNUSED_PINS | ||
36 | |||
33 | #define RGBLED_NUM 16 | 37 | #define RGBLED_NUM 16 |
34 | #define RGBLIGHT_ANIMATIONS | 38 | #define RGBLIGHT_ANIMATIONS |
35 | 39 | ||
@@ -43,4 +47,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
43 | #define BACKLIGHT_PORT_NUM (1 << 4) | 47 | #define BACKLIGHT_PORT_NUM (1 << 4) |
44 | #endif | 48 | #endif |
45 | 49 | ||
46 | #endif | ||
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/matrix.c b/keyboards/winkeyless/bface/matrix.c deleted file mode 100644 index b3761a63c..000000000 --- a/keyboards/winkeyless/bface/matrix.c +++ /dev/null | |||
@@ -1,113 +0,0 @@ | |||
1 | /* | ||
2 | Copyright 2017 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/delay.h> | ||
20 | |||
21 | #include "matrix.h" | ||
22 | |||
23 | #ifndef DEBOUNCE | ||
24 | # define DEBOUNCE 5 | ||
25 | #endif | ||
26 | |||
27 | static uint8_t debouncing = DEBOUNCE; | ||
28 | |||
29 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
30 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
31 | |||
32 | void matrix_init(void) { | ||
33 | // all outputs for rows high | ||
34 | DDRB = 0xFF; | ||
35 | PORTB = 0xFF; | ||
36 | // all inputs for columns | ||
37 | DDRA = 0x00; | ||
38 | DDRC &= ~(0x111111<<2); | ||
39 | DDRD &= ~(1<<PIND7); | ||
40 | // all columns are pulled-up | ||
41 | PORTA = 0xFF; | ||
42 | PORTC |= (0b111111<<2); | ||
43 | PORTD |= (1<<PIND7); | ||
44 | |||
45 | // initialize matrix state: all keys off | ||
46 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
47 | matrix[row] = 0x00; | ||
48 | matrix_debouncing[row] = 0x00; | ||
49 | } | ||
50 | |||
51 | // activate backlight | ||
52 | //PORTD |= (1 << 4); | ||
53 | //_SFR_IO8(0x09) |= (1 << 4); //_BV(0x94 & 0xF); | ||
54 | // | ||
55 | // this is the code that *should* be executed in quantum.c | ||
56 | _SFR_IO8(0x12) |= _BV(0x4); | ||
57 | } | ||
58 | |||
59 | void matrix_set_row_status(uint8_t row) { | ||
60 | DDRB = (1 << row); | ||
61 | PORTB = ~(1 << row); | ||
62 | } | ||
63 | |||
64 | uint8_t bit_reverse(uint8_t x) { | ||
65 | x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); | ||
66 | x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); | ||
67 | x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); | ||
68 | return x; | ||
69 | } | ||
70 | |||
71 | uint8_t matrix_scan(void) { | ||
72 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
73 | matrix_set_row_status(row); | ||
74 | _delay_us(5); | ||
75 | |||
76 | matrix_row_t cols = ( | ||
77 | // cols 0..7, PORTA 0 -> 7 | ||
78 | (~PINA) & 0xFF | ||
79 | ) | ( | ||
80 | // cols 8..13, PORTC 7 -> 0 | ||
81 | bit_reverse((~PINC) & 0xFF) << 8 | ||
82 | ) | ( | ||
83 | // col 14, PORTD 7 | ||
84 | ((~PIND) & (1 << PIND7)) << 7 | ||
85 | ); | ||
86 | |||
87 | if (matrix_debouncing[row] != cols) { | ||
88 | matrix_debouncing[row] = cols; | ||
89 | debouncing = DEBOUNCE; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | if (debouncing) { | ||
94 | if (--debouncing) { | ||
95 | _delay_ms(1); | ||
96 | } else { | ||
97 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
98 | matrix[i] = matrix_debouncing[i]; | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | |||
103 | matrix_scan_user(); | ||
104 | |||
105 | return 1; | ||
106 | } | ||
107 | |||
108 | inline matrix_row_t matrix_get_row(uint8_t row) { | ||
109 | return matrix[row]; | ||
110 | } | ||
111 | |||
112 | void matrix_print(void) { | ||
113 | } | ||
diff --git a/keyboards/winkeyless/bface/rules.mk b/keyboards/winkeyless/bface/rules.mk index 369ccf2ed..b6d172f26 100644 --- a/keyboards/winkeyless/bface/rules.mk +++ b/keyboards/winkeyless/bface/rules.mk | |||
@@ -25,7 +25,7 @@ NO_SUSPEND_POWER_DOWN = yes | |||
25 | F_CPU = 12000000 | 25 | F_CPU = 12000000 |
26 | 26 | ||
27 | # build options | 27 | # build options |
28 | BOOTMAGIC_ENABLE = yes | 28 | BOOTMAGIC_ENABLE = no |
29 | MOUSEKEY_ENABLE = yes | 29 | MOUSEKEY_ENABLE = yes |
30 | EXTRAKEY_ENABLE = yes | 30 | EXTRAKEY_ENABLE = yes |
31 | CONSOLE_ENABLE = no | 31 | CONSOLE_ENABLE = no |
@@ -40,8 +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 | CUSTOM_MATRIX = yes | 43 | SRC = i2c_master.c |
44 | SRC = matrix.c i2c.c backlight_ps2avrGB.c | ||
45 | 44 | ||
46 | # programming options | 45 | # programming options |
47 | PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex | 46 | PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex |
diff --git a/keyboards/winkeyless/bface/usbconfig.h b/keyboards/winkeyless/bface/usbconfig.h index f87922615..192d80d91 100644 --- a/keyboards/winkeyless/bface/usbconfig.h +++ b/keyboards/winkeyless/bface/usbconfig.h | |||
@@ -8,8 +8,7 @@ | |||
8 | * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ | 8 | * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ |
9 | */ | 9 | */ |
10 | 10 | ||
11 | #ifndef __usbconfig_h_included__ | 11 | #pragma once |
12 | #define __usbconfig_h_included__ | ||
13 | 12 | ||
14 | #include "config.h" | 13 | #include "config.h" |
15 | 14 | ||
@@ -392,5 +391,3 @@ section at the end of this file). | |||
392 | /* #define USB_INTR_PENDING EIFR */ | 391 | /* #define USB_INTR_PENDING EIFR */ |
393 | #define USB_INTR_PENDING_BIT INTF1 | 392 | #define USB_INTR_PENDING_BIT INTF1 |
394 | #define USB_INTR_VECTOR INT1_vect | 393 | #define USB_INTR_VECTOR INT1_vect |
395 | |||
396 | #endif /* __usbconfig_h_included__ */ | ||