diff options
author | Luiz Ribeiro <luizribeiro@gmail.com> | 2017-01-21 12:30:06 -0500 |
---|---|---|
committer | Luiz Ribeiro <luizribeiro@gmail.com> | 2017-01-21 12:55:19 -0500 |
commit | f7462aaa613a08ba4b86dbb912ce26722cfccaff (patch) | |
tree | cd7bd4b109fdb9d6f5253885138e1b34ee277e12 /tmk_core | |
parent | 10ff9623214ee62935a17b3f68d5180756b7a27b (diff) | |
download | qmk_firmware-f7462aaa613a08ba4b86dbb912ce26722cfccaff.tar.gz qmk_firmware-f7462aaa613a08ba4b86dbb912ce26722cfccaff.zip |
Got ps2avrGB to work with the V-USB protocol
Diffstat (limited to 'tmk_core')
-rw-r--r-- | tmk_core/common.mk | 8 | ||||
-rw-r--r-- | tmk_core/common/avr/bootloader.c | 10 | ||||
-rw-r--r-- | tmk_core/common/avr/suspend.c | 2 | ||||
-rw-r--r-- | tmk_core/common/avr/timer.c | 33 | ||||
-rw-r--r-- | tmk_core/common/command.c | 2 | ||||
-rw-r--r-- | tmk_core/protocol/vusb.mk | 7 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/main.c | 6 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 22 |
8 files changed, 73 insertions, 17 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 3c1373c08..a86dccc61 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk | |||
@@ -80,6 +80,14 @@ ifeq ($(strip $(SLEEP_LED_ENABLE)), yes) | |||
80 | TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN | 80 | TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN |
81 | endif | 81 | endif |
82 | 82 | ||
83 | ifeq ($(strip $(NO_UART)), yes) | ||
84 | TMK_COMMON_DEFS += -DNO_UART | ||
85 | endif | ||
86 | |||
87 | ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes) | ||
88 | TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN | ||
89 | endif | ||
90 | |||
83 | ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) | 91 | ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) |
84 | TMK_COMMON_SRC += $(COMMON_DIR)/backlight.c | 92 | TMK_COMMON_SRC += $(COMMON_DIR)/backlight.c |
85 | TMK_COMMON_DEFS += -DBACKLIGHT_ENABLE | 93 | TMK_COMMON_DEFS += -DBACKLIGHT_ENABLE |
diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c index ad547b985..98a24d178 100644 --- a/tmk_core/common/avr/bootloader.c +++ b/tmk_core/common/avr/bootloader.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <stdint.h> | 1 | #include <stdint.h> |
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <avr/io.h> | 3 | #include <avr/io.h> |
4 | #include <avr/eeprom.h> | ||
4 | #include <avr/interrupt.h> | 5 | #include <avr/interrupt.h> |
5 | #include <avr/wdt.h> | 6 | #include <avr/wdt.h> |
6 | #include <util/delay.h> | 7 | #include <util/delay.h> |
@@ -89,6 +90,10 @@ void bootloader_jump(void) { | |||
89 | _delay_ms(5); | 90 | _delay_ms(5); |
90 | #endif | 91 | #endif |
91 | 92 | ||
93 | #ifdef EEPROM_BOOTLOADER_START | ||
94 | eeprom_write_byte((uint8_t *)EEPROM_BOOTLOADER_START, 0x00); | ||
95 | #endif | ||
96 | |||
92 | // watchdog reset | 97 | // watchdog reset |
93 | reset_key = BOOTLOADER_RESET_KEY; | 98 | reset_key = BOOTLOADER_RESET_KEY; |
94 | wdt_enable(WDTO_250MS); | 99 | wdt_enable(WDTO_250MS); |
@@ -114,6 +119,11 @@ void bootloader_jump(void) { | |||
114 | #endif | 119 | #endif |
115 | } | 120 | } |
116 | 121 | ||
122 | #ifdef __AVR_ATmega32A__ | ||
123 | // MCUSR is actually called MCUCSR in ATmega32A | ||
124 | #define MCUSR MCUCSR | ||
125 | #endif | ||
126 | |||
117 | /* this runs before main() */ | 127 | /* this runs before main() */ |
118 | void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); | 128 | void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); |
119 | void bootloader_jump_after_watchdog_reset(void) | 129 | void bootloader_jump_after_watchdog_reset(void) |
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 0c81e8361..0e97892d9 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c | |||
@@ -65,6 +65,7 @@ static uint8_t wdt_timeout = 0; | |||
65 | 65 | ||
66 | static void power_down(uint8_t wdto) | 66 | static void power_down(uint8_t wdto) |
67 | { | 67 | { |
68 | #ifndef __AVR_ATmega32A__ | ||
68 | #ifdef PROTOCOL_LUFA | 69 | #ifdef PROTOCOL_LUFA |
69 | if (USB_DeviceState == DEVICE_STATE_Configured) return; | 70 | if (USB_DeviceState == DEVICE_STATE_Configured) return; |
70 | #endif | 71 | #endif |
@@ -99,6 +100,7 @@ static void power_down(uint8_t wdto) | |||
99 | 100 | ||
100 | // Disable watchdog after sleep | 101 | // Disable watchdog after sleep |
101 | wdt_disable(); | 102 | wdt_disable(); |
103 | #endif | ||
102 | } | 104 | } |
103 | #endif | 105 | #endif |
104 | 106 | ||
diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c index 84af44488..369015200 100644 --- a/tmk_core/common/avr/timer.c +++ b/tmk_core/common/avr/timer.c | |||
@@ -29,25 +29,35 @@ volatile uint32_t timer_count; | |||
29 | 29 | ||
30 | void timer_init(void) | 30 | void timer_init(void) |
31 | { | 31 | { |
32 | // Timer0 CTC mode | ||
33 | TCCR0A = 0x02; | ||
34 | |||
35 | #if TIMER_PRESCALER == 1 | 32 | #if TIMER_PRESCALER == 1 |
36 | TCCR0B = 0x01; | 33 | uint8_t prescaler = 0x01; |
37 | #elif TIMER_PRESCALER == 8 | 34 | #elif TIMER_PRESCALER == 8 |
38 | TCCR0B = 0x02; | 35 | uint8_t prescaler = 0x02; |
39 | #elif TIMER_PRESCALER == 64 | 36 | #elif TIMER_PRESCALER == 64 |
40 | TCCR0B = 0x03; | 37 | uint8_t prescaler = 0x03; |
41 | #elif TIMER_PRESCALER == 256 | 38 | #elif TIMER_PRESCALER == 256 |
42 | TCCR0B = 0x04; | 39 | uint8_t prescaler = 0x04; |
43 | #elif TIMER_PRESCALER == 1024 | 40 | #elif TIMER_PRESCALER == 1024 |
44 | TCCR0B = 0x05; | 41 | uint8_t prescaler = 0x05; |
45 | #else | 42 | #else |
46 | # error "Timer prescaler value is NOT vaild." | 43 | # error "Timer prescaler value is NOT vaild." |
47 | #endif | 44 | #endif |
48 | 45 | ||
46 | #ifndef __AVR_ATmega32A__ | ||
47 | // Timer0 CTC mode | ||
48 | TCCR0A = 0x02; | ||
49 | |||
50 | TCCR0B = prescaler; | ||
51 | |||
49 | OCR0A = TIMER_RAW_TOP; | 52 | OCR0A = TIMER_RAW_TOP; |
50 | TIMSK0 = (1<<OCIE0A); | 53 | TIMSK0 = (1<<OCIE0A); |
54 | #else | ||
55 | // Timer0 CTC mode | ||
56 | TCCR0 = (1 << WGM01) | prescaler; | ||
57 | |||
58 | OCR0 = TIMER_RAW_TOP; | ||
59 | TIMSK = (1 << OCIE0); | ||
60 | #endif | ||
51 | } | 61 | } |
52 | 62 | ||
53 | inline | 63 | inline |
@@ -107,7 +117,12 @@ uint32_t timer_elapsed32(uint32_t last) | |||
107 | } | 117 | } |
108 | 118 | ||
109 | // excecuted once per 1ms.(excess for just timer count?) | 119 | // excecuted once per 1ms.(excess for just timer count?) |
110 | ISR(TIMER0_COMPA_vect) | 120 | #ifndef __AVR_ATmega32A__ |
121 | #define TIMER_INTERRUPT_VECTOR TIMER0_COMPA_vect | ||
122 | #else | ||
123 | #define TIMER_INTERRUPT_VECTOR TIMER0_COMP_vect | ||
124 | #endif | ||
125 | ISR(TIMER_INTERRUPT_VECTOR, ISR_NOBLOCK) | ||
111 | { | 126 | { |
112 | timer_count++; | 127 | timer_count++; |
113 | } | 128 | } |
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index 5f29bc0b4..beba768ec 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c | |||
@@ -235,8 +235,10 @@ static void print_status(void) | |||
235 | print("\n\t- Status -\n"); | 235 | print("\n\t- Status -\n"); |
236 | 236 | ||
237 | print_val_hex8(host_keyboard_leds()); | 237 | print_val_hex8(host_keyboard_leds()); |
238 | #ifndef PROTOCOL_VUSB | ||
238 | print_val_hex8(keyboard_protocol); | 239 | print_val_hex8(keyboard_protocol); |
239 | print_val_hex8(keyboard_idle); | 240 | print_val_hex8(keyboard_idle); |
241 | #endif | ||
240 | #ifdef NKRO_ENABLE | 242 | #ifdef NKRO_ENABLE |
241 | print_val_hex8(keymap_config.nkro); | 243 | print_val_hex8(keymap_config.nkro); |
242 | #endif | 244 | #endif |
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk index 3cba3f71a..4d90510af 100644 --- a/tmk_core/protocol/vusb.mk +++ b/tmk_core/protocol/vusb.mk | |||
@@ -2,7 +2,7 @@ VUSB_DIR = protocol/vusb | |||
2 | 2 | ||
3 | OPT_DEFS += -DPROTOCOL_VUSB | 3 | OPT_DEFS += -DPROTOCOL_VUSB |
4 | 4 | ||
5 | SRC += $(VUSB_DIR)/main.c \ | 5 | SRC += $(VUSB_DIR)/main.c \ |
6 | $(VUSB_DIR)/vusb.c \ | 6 | $(VUSB_DIR)/vusb.c \ |
7 | $(VUSB_DIR)/usbdrv/usbdrv.c \ | 7 | $(VUSB_DIR)/usbdrv/usbdrv.c \ |
8 | $(VUSB_DIR)/usbdrv/usbdrvasm.S \ | 8 | $(VUSB_DIR)/usbdrv/usbdrvasm.S \ |
@@ -16,6 +16,7 @@ SRC += $(COMMON_DIR)/sendchar_uart.c \ | |||
16 | $(COMMON_DIR)/uart.c | 16 | $(COMMON_DIR)/uart.c |
17 | endif | 17 | endif |
18 | 18 | ||
19 | |||
20 | # Search Path | 19 | # Search Path |
21 | VPATH += $(TMK_DIR)/protocol/vusb:$(TMK_DIR)/protocol/vusb/usbdrv | 20 | #VPATH += $(TMK_PATH)/$(VUSB_DIR) |
21 | VPATH += $(TMK_PATH)/$(VUSB_DIR) | ||
22 | VPATH += $(TMK_PATH)/$(VUSB_DIR)/usbdrv | ||
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index 8e4a266e9..f6a0c7e9a 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c | |||
@@ -48,8 +48,12 @@ int main(void) | |||
48 | uint16_t last_timer = timer_read(); | 48 | uint16_t last_timer = timer_read(); |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | #ifdef CLKPR | ||
52 | // avoid unintentional changes of clock frequency in devices that have a | ||
53 | // clock prescaler | ||
51 | CLKPR = 0x80, CLKPR = 0; | 54 | CLKPR = 0x80, CLKPR = 0; |
52 | #ifndef PS2_USE_USART | 55 | #endif |
56 | #ifndef NO_UART | ||
53 | uart_init(UART_BAUD_RATE); | 57 | uart_init(UART_BAUD_RATE); |
54 | #endif | 58 | #endif |
55 | 59 | ||
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index eaa1c512d..a8c13b928 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c | |||
@@ -15,6 +15,8 @@ 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/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <avr/eeprom.h> | ||
19 | #include <avr/wdt.h> | ||
18 | #include <stdint.h> | 20 | #include <stdint.h> |
19 | #include "usbdrv.h" | 21 | #include "usbdrv.h" |
20 | #include "usbconfig.h" | 22 | #include "usbconfig.h" |
@@ -24,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
24 | #include "debug.h" | 26 | #include "debug.h" |
25 | #include "host_driver.h" | 27 | #include "host_driver.h" |
26 | #include "vusb.h" | 28 | #include "vusb.h" |
29 | #include "bootloader.h" | ||
27 | 30 | ||
28 | 31 | ||
29 | static uint8_t vusb_keyboard_leds = 0; | 32 | static uint8_t vusb_keyboard_leds = 0; |
@@ -163,6 +166,7 @@ static struct { | |||
163 | uint16_t len; | 166 | uint16_t len; |
164 | enum { | 167 | enum { |
165 | NONE, | 168 | NONE, |
169 | BOOTLOADER, | ||
166 | SET_LED | 170 | SET_LED |
167 | } kind; | 171 | } kind; |
168 | } last_req; | 172 | } last_req; |
@@ -193,6 +197,11 @@ usbRequest_t *rq = (void *)data; | |||
193 | debug("SET_LED: "); | 197 | debug("SET_LED: "); |
194 | last_req.kind = SET_LED; | 198 | last_req.kind = SET_LED; |
195 | last_req.len = rq->wLength.word; | 199 | last_req.len = rq->wLength.word; |
200 | #ifdef BOOTLOADER_SIZE | ||
201 | } else if(rq->wValue.word == 0x0301) { | ||
202 | last_req.kind = BOOTLOADER; | ||
203 | last_req.len = rq->wLength.word; | ||
204 | #endif | ||
196 | } | 205 | } |
197 | return USB_NO_MSG; // to get data in usbFunctionWrite | 206 | return USB_NO_MSG; // to get data in usbFunctionWrite |
198 | } else { | 207 | } else { |
@@ -220,6 +229,11 @@ uchar usbFunctionWrite(uchar *data, uchar len) | |||
220 | last_req.len = 0; | 229 | last_req.len = 0; |
221 | return 1; | 230 | return 1; |
222 | break; | 231 | break; |
232 | case BOOTLOADER: | ||
233 | usbDeviceDisconnect(); | ||
234 | bootloader_jump(); | ||
235 | return 1; | ||
236 | break; | ||
223 | case NONE: | 237 | case NONE: |
224 | default: | 238 | default: |
225 | return -1; | 239 | return -1; |
@@ -266,7 +280,7 @@ const PROGMEM uchar keyboard_hid_report[] = { | |||
266 | 0x95, 0x06, // Report Count (6), | 280 | 0x95, 0x06, // Report Count (6), |
267 | 0x75, 0x08, // Report Size (8), | 281 | 0x75, 0x08, // Report Size (8), |
268 | 0x15, 0x00, // Logical Minimum (0), | 282 | 0x15, 0x00, // Logical Minimum (0), |
269 | 0x25, 0xFF, 0x00 // Logical Maximum(255), | 283 | 0x25, 0xFF, 0x00, // Logical Maximum(255), |
270 | 0x05, 0x07, // Usage Page (Key Codes), | 284 | 0x05, 0x07, // Usage Page (Key Codes), |
271 | 0x19, 0x00, // Usage Minimum (0), | 285 | 0x19, 0x00, // Usage Minimum (0), |
272 | 0x29, 0xFF, // Usage Maximum (255), | 286 | 0x29, 0xFF, // Usage Maximum (255), |
@@ -336,7 +350,7 @@ const PROGMEM uchar mouse_hid_report[] = { | |||
336 | 0xa1, 0x01, // COLLECTION (Application) | 350 | 0xa1, 0x01, // COLLECTION (Application) |
337 | 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2) | 351 | 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2) |
338 | 0x15, 0x01, // LOGICAL_MINIMUM (0x1) | 352 | 0x15, 0x01, // LOGICAL_MINIMUM (0x1) |
339 | 0x25, 0xb7, 0x00 // LOGICAL_MAXIMUM (0xb7) | 353 | 0x25, 0xb7, 0x00, // LOGICAL_MAXIMUM (0xb7) |
340 | 0x19, 0x01, // USAGE_MINIMUM (0x1) | 354 | 0x19, 0x01, // USAGE_MINIMUM (0x1) |
341 | 0x29, 0xb7, // USAGE_MAXIMUM (0xb7) | 355 | 0x29, 0xb7, // USAGE_MAXIMUM (0xb7) |
342 | 0x75, 0x10, // REPORT_SIZE (16) | 356 | 0x75, 0x10, // REPORT_SIZE (16) |
@@ -481,11 +495,11 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) | |||
481 | /* interface index */ | 495 | /* interface index */ |
482 | switch (rq->wIndex.word) { | 496 | switch (rq->wIndex.word) { |
483 | case 0: | 497 | case 0: |
484 | usbMsgPtr = keyboard_hid_report; | 498 | usbMsgPtr = (unsigned char *)keyboard_hid_report; |
485 | len = sizeof(keyboard_hid_report); | 499 | len = sizeof(keyboard_hid_report); |
486 | break; | 500 | break; |
487 | case 1: | 501 | case 1: |
488 | usbMsgPtr = mouse_hid_report; | 502 | usbMsgPtr = (unsigned char *)mouse_hid_report; |
489 | len = sizeof(mouse_hid_report); | 503 | len = sizeof(mouse_hid_report); |
490 | break; | 504 | break; |
491 | } | 505 | } |