From f7462aaa613a08ba4b86dbb912ce26722cfccaff Mon Sep 17 00:00:00 2001 From: Luiz Ribeiro Date: Sat, 21 Jan 2017 12:30:06 -0500 Subject: Got ps2avrGB to work with the V-USB protocol --- tmk_core/common.mk | 8 ++++++++ tmk_core/common/avr/bootloader.c | 10 ++++++++++ tmk_core/common/avr/suspend.c | 2 ++ tmk_core/common/avr/timer.c | 33 ++++++++++++++++++++++++--------- tmk_core/common/command.c | 2 ++ tmk_core/protocol/vusb.mk | 7 ++++--- tmk_core/protocol/vusb/main.c | 6 +++++- tmk_core/protocol/vusb/vusb.c | 22 ++++++++++++++++++---- 8 files changed, 73 insertions(+), 17 deletions(-) (limited to 'tmk_core') 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) TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN endif +ifeq ($(strip $(NO_UART)), yes) + TMK_COMMON_DEFS += -DNO_UART +endif + +ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes) + TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN +endif + ifeq ($(strip $(BACKLIGHT_ENABLE)), yes) TMK_COMMON_SRC += $(COMMON_DIR)/backlight.c 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 @@ #include #include #include +#include #include #include #include @@ -89,6 +90,10 @@ void bootloader_jump(void) { _delay_ms(5); #endif + #ifdef EEPROM_BOOTLOADER_START + eeprom_write_byte((uint8_t *)EEPROM_BOOTLOADER_START, 0x00); + #endif + // watchdog reset reset_key = BOOTLOADER_RESET_KEY; wdt_enable(WDTO_250MS); @@ -114,6 +119,11 @@ void bootloader_jump(void) { #endif } +#ifdef __AVR_ATmega32A__ +// MCUSR is actually called MCUCSR in ATmega32A +#define MCUSR MCUCSR +#endif + /* this runs before main() */ void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); 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; static void power_down(uint8_t wdto) { +#ifndef __AVR_ATmega32A__ #ifdef PROTOCOL_LUFA if (USB_DeviceState == DEVICE_STATE_Configured) return; #endif @@ -99,6 +100,7 @@ static void power_down(uint8_t wdto) // Disable watchdog after sleep wdt_disable(); +#endif } #endif 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; void timer_init(void) { - // Timer0 CTC mode - TCCR0A = 0x02; - #if TIMER_PRESCALER == 1 - TCCR0B = 0x01; + uint8_t prescaler = 0x01; #elif TIMER_PRESCALER == 8 - TCCR0B = 0x02; + uint8_t prescaler = 0x02; #elif TIMER_PRESCALER == 64 - TCCR0B = 0x03; + uint8_t prescaler = 0x03; #elif TIMER_PRESCALER == 256 - TCCR0B = 0x04; + uint8_t prescaler = 0x04; #elif TIMER_PRESCALER == 1024 - TCCR0B = 0x05; + uint8_t prescaler = 0x05; #else # error "Timer prescaler value is NOT vaild." #endif +#ifndef __AVR_ATmega32A__ + // Timer0 CTC mode + TCCR0A = 0x02; + + TCCR0B = prescaler; + OCR0A = TIMER_RAW_TOP; TIMSK0 = (1<. */ +#include +#include #include #include "usbdrv.h" #include "usbconfig.h" @@ -24,6 +26,7 @@ along with this program. If not, see . #include "debug.h" #include "host_driver.h" #include "vusb.h" +#include "bootloader.h" static uint8_t vusb_keyboard_leds = 0; @@ -163,6 +166,7 @@ static struct { uint16_t len; enum { NONE, + BOOTLOADER, SET_LED } kind; } last_req; @@ -193,6 +197,11 @@ usbRequest_t *rq = (void *)data; debug("SET_LED: "); last_req.kind = SET_LED; last_req.len = rq->wLength.word; +#ifdef BOOTLOADER_SIZE + } else if(rq->wValue.word == 0x0301) { + last_req.kind = BOOTLOADER; + last_req.len = rq->wLength.word; +#endif } return USB_NO_MSG; // to get data in usbFunctionWrite } else { @@ -220,6 +229,11 @@ uchar usbFunctionWrite(uchar *data, uchar len) last_req.len = 0; return 1; break; + case BOOTLOADER: + usbDeviceDisconnect(); + bootloader_jump(); + return 1; + break; case NONE: default: return -1; @@ -266,7 +280,7 @@ const PROGMEM uchar keyboard_hid_report[] = { 0x95, 0x06, // Report Count (6), 0x75, 0x08, // Report Size (8), 0x15, 0x00, // Logical Minimum (0), - 0x25, 0xFF, 0x00 // Logical Maximum(255), + 0x25, 0xFF, 0x00, // Logical Maximum(255), 0x05, 0x07, // Usage Page (Key Codes), 0x19, 0x00, // Usage Minimum (0), 0x29, 0xFF, // Usage Maximum (255), @@ -336,7 +350,7 @@ const PROGMEM uchar mouse_hid_report[] = { 0xa1, 0x01, // COLLECTION (Application) 0x85, REPORT_ID_SYSTEM, // REPORT_ID (2) 0x15, 0x01, // LOGICAL_MINIMUM (0x1) - 0x25, 0xb7, 0x00 // LOGICAL_MAXIMUM (0xb7) + 0x25, 0xb7, 0x00, // LOGICAL_MAXIMUM (0xb7) 0x19, 0x01, // USAGE_MINIMUM (0x1) 0x29, 0xb7, // USAGE_MAXIMUM (0xb7) 0x75, 0x10, // REPORT_SIZE (16) @@ -481,11 +495,11 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) /* interface index */ switch (rq->wIndex.word) { case 0: - usbMsgPtr = keyboard_hid_report; + usbMsgPtr = (unsigned char *)keyboard_hid_report; len = sizeof(keyboard_hid_report); break; case 1: - usbMsgPtr = mouse_hid_report; + usbMsgPtr = (unsigned char *)mouse_hid_report; len = sizeof(mouse_hid_report); break; } -- cgit v1.2.3