From 9635039ab8662e47df0c8b0787a092835f9c37ff Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Wed, 9 Apr 2014 16:09:55 +0900 Subject: [PATCH] Add support for ATmega32a --- common/bootloader.h | 3 +++ common/report.h | 1 + common/timer.c | 12 ++++++------ common/timer.h | 18 ++++++++++++++++++ protocol/vusb.mk | 3 ++- protocol/vusb/main.c | 5 +++++ protocol/vusb/usbdrv/usbdrv.c | 17 +++++++++-------- protocol/vusb/usbdrv/usbdrv.h | 16 ++++++++-------- protocol/vusb/vusb.c | 7 ++++--- 9 files changed, 56 insertions(+), 26 deletions(-) diff --git a/common/bootloader.h b/common/bootloader.h index 44775039..32b18477 100644 --- a/common/bootloader.h +++ b/common/bootloader.h @@ -18,6 +18,9 @@ along with this program. If not, see . #ifndef BOOTLOADER_H #define BOOTLOADER_H +#ifndef MCUSR +#define MCUSR MCUCSR +#endif /* give code for your bootloader to come up if needed */ void bootloader_jump(void); diff --git a/common/report.h b/common/report.h index 91982840..1c2d73c3 100644 --- a/common/report.h +++ b/common/report.h @@ -87,6 +87,7 @@ along with this program. If not, see . #else # define REPORT_SIZE 8 # define REPORT_KEYS 6 +# define REPORT_BITS 7 #endif diff --git a/common/timer.c b/common/timer.c index e0dec6ce..cb725ba2 100644 --- a/common/timer.c +++ b/common/timer.c @@ -28,18 +28,18 @@ volatile uint32_t timer_count = 0; void timer_init(void) { // Timer0 CTC mode - TCCR0A = 0x02; + TCCR0A |= (1<. #define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) #define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b) +#ifndef TCCR0A +#define TCCR0A TCCR0 +#endif +#ifndef TCCR0B +#define TCCR0B TCCR0 +#endif +#ifndef TIMSK0 +#define TIMSK0 TIMSK +#endif +#ifndef OCIE0A +#define OCIE0A OCIE0 +#endif +#ifndef OCR0A +#define OCR0A OCR0 +#endif +#ifndef TIMER0_COMPA_vect +#define TIMER0_COMPA_vect TIMER0_COMP_vect +#endif #ifdef __cplusplus extern "C" { diff --git a/protocol/vusb.mk b/protocol/vusb.mk index 3227ca7b..98fbda64 100644 --- a/protocol/vusb.mk +++ b/protocol/vusb.mk @@ -8,9 +8,10 @@ SRC += $(VUSB_DIR)/main.c \ $(VUSB_DIR)/usbdrv/usbdrvasm.S \ $(VUSB_DIR)/usbdrv/oddebug.c - +COMMON_DIR = common ifdef NO_UART SRC += $(COMMON_DIR)/sendchar_null.c +OPT_DEFS += -DNO_UART else SRC += $(COMMON_DIR)/sendchar_uart.c \ $(COMMON_DIR)/uart.c diff --git a/protocol/vusb/main.c b/protocol/vusb/main.c index 8e4a266e..c5817f1a 100644 --- a/protocol/vusb/main.c +++ b/protocol/vusb/main.c @@ -48,9 +48,14 @@ int main(void) uint16_t last_timer = timer_read(); #endif +#ifdef CLKPR CLKPR = 0x80, CLKPR = 0; +#endif + +#ifndef NO_UART #ifndef PS2_USE_USART uart_init(UART_BAUD_RATE); +#endif #endif keyboard_init(); diff --git a/protocol/vusb/usbdrv/usbdrv.c b/protocol/vusb/usbdrv/usbdrv.c index 21ed554f..6c2fe079 100644 --- a/protocol/vusb/usbdrv/usbdrv.c +++ b/protocol/vusb/usbdrv/usbdrv.c @@ -45,7 +45,7 @@ uchar usbCurrentDataToken;/* when we check data toggling to ignore duplica #endif /* USB status registers / not shared with asm code */ -uchar *usbMsgPtr; /* data to transmit next -- ROM or RAM address */ +const uchar *usbMsgPtr; /* data to transmit next -- ROM or RAM address */ static usbMsgLen_t usbMsgLen = USB_NO_MSG; /* remaining number of bytes */ static uchar usbMsgFlags; /* flag values see below */ @@ -67,7 +67,7 @@ optimizing hints: #if USB_CFG_DESCR_PROPS_STRING_0 == 0 #undef USB_CFG_DESCR_PROPS_STRING_0 #define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0) -PROGMEM char usbDescriptorString0[] = { /* language descriptor */ +PROGMEM const char usbDescriptorString0[] = { /* language descriptor */ 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */ 3, /* descriptor type */ 0x09, 0x04, /* language index (0x0409 = US-English) */ @@ -77,7 +77,7 @@ PROGMEM char usbDescriptorString0[] = { /* language descriptor */ #if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN #undef USB_CFG_DESCR_PROPS_STRING_VENDOR #define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor) -PROGMEM int usbDescriptorStringVendor[] = { +PROGMEM const int usbDescriptorStringVendor[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), USB_CFG_VENDOR_NAME }; @@ -86,7 +86,7 @@ PROGMEM int usbDescriptorStringVendor[] = { #if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN #undef USB_CFG_DESCR_PROPS_STRING_PRODUCT #define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice) -PROGMEM int usbDescriptorStringDevice[] = { +PROGMEM const int usbDescriptorStringDevice[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), USB_CFG_DEVICE_NAME }; @@ -95,7 +95,7 @@ PROGMEM int usbDescriptorStringDevice[] = { #if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN #undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER sizeof(usbDescriptorStringSerialNumber) -PROGMEM int usbDescriptorStringSerialNumber[] = { +PROGMEM const int usbDescriptorStringSerialNumber[] = { USB_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN), USB_CFG_SERIAL_NUMBER }; @@ -108,7 +108,7 @@ PROGMEM int usbDescriptorStringSerialNumber[] = { #if USB_CFG_DESCR_PROPS_DEVICE == 0 #undef USB_CFG_DESCR_PROPS_DEVICE #define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice) -PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */ +PROGMEM const char usbDescriptorDevice[] = { /* USB device descriptor */ 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */ USBDESCR_DEVICE, /* descriptor type */ 0x10, 0x01, /* USB version supported */ @@ -139,7 +139,7 @@ PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */ #if USB_CFG_DESCR_PROPS_CONFIGURATION == 0 #undef USB_CFG_DESCR_PROPS_CONFIGURATION #define USB_CFG_DESCR_PROPS_CONFIGURATION sizeof(usbDescriptorConfiguration) -PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ +PROGMEM const char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ USBDESCR_CONFIG, /* descriptor type */ 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + @@ -498,7 +498,8 @@ static uchar usbDeviceRead(uchar *data, uchar len) }else #endif { - uchar i = len, *r = usbMsgPtr; + uchar i = len; + const uchar *r = usbMsgPtr; if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */ do{ uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */ diff --git a/protocol/vusb/usbdrv/usbdrv.h b/protocol/vusb/usbdrv/usbdrv.h index 3a78f307..a4f99c3d 100644 --- a/protocol/vusb/usbdrv/usbdrv.h +++ b/protocol/vusb/usbdrv/usbdrv.h @@ -178,7 +178,7 @@ USB_PUBLIC void usbPoll(void); * Please note that debug outputs through the UART take ~ 0.5ms per byte * at 19200 bps. */ -extern uchar *usbMsgPtr; +extern const uchar *usbMsgPtr; /* This variable may be used to pass transmit data to the driver from the * implementation of usbFunctionWrite(). It is also used internally by the * driver for standard control requests. @@ -452,43 +452,43 @@ extern #if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM) PROGMEM #endif -char usbDescriptorDevice[]; +const char usbDescriptorDevice[]; extern #if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM) PROGMEM #endif -char usbDescriptorConfiguration[]; +const char usbDescriptorConfiguration[]; extern #if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM) PROGMEM #endif -char usbDescriptorHidReport[]; +const char usbDescriptorHidReport[]; extern #if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM) PROGMEM #endif -char usbDescriptorString0[]; +const char usbDescriptorString0[]; extern #if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM) PROGMEM #endif -int usbDescriptorStringVendor[]; +const int usbDescriptorStringVendor[]; extern #if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM) PROGMEM #endif -int usbDescriptorStringDevice[]; +const int usbDescriptorStringDevice[]; extern #if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM) PROGMEM #endif -int usbDescriptorStringSerialNumber[]; +const int usbDescriptorStringSerialNumber[]; #endif /* __ASSEMBLER__ */ diff --git a/protocol/vusb/vusb.c b/protocol/vusb/vusb.c index 328885a9..61dbc357 100644 --- a/protocol/vusb/vusb.c +++ b/protocol/vusb/vusb.c @@ -24,6 +24,7 @@ along with this program. If not, see . #include "debug.h" #include "host_driver.h" #include "vusb.h" +#include "action_util.h" static uint8_t vusb_keyboard_leds = 0; @@ -232,7 +233,7 @@ uchar usbFunctionWrite(uchar *data, uchar len) * * from an example in HID spec appendix */ -PROGMEM uchar keyboard_hid_report[] = { +PROGMEM const uchar keyboard_hid_report[] = { 0x05, 0x01, // Usage Page (Generic Desktop), 0x09, 0x06, // Usage (Keyboard), 0xA1, 0x01, // Collection (Application), @@ -275,7 +276,7 @@ PROGMEM uchar keyboard_hid_report[] = { * http://www.keil.com/forum/15671/ * http://www.microsoft.com/whdc/device/input/wheel.mspx */ -PROGMEM uchar mouse_hid_report[] = { +PROGMEM const uchar mouse_hid_report[] = { /* mouse */ 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x02, // USAGE (Mouse) @@ -358,7 +359,7 @@ PROGMEM uchar mouse_hid_report[] = { * contains: device, interface, HID and endpoint descriptors */ #if USB_CFG_DESCR_PROPS_CONFIGURATION -PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ +PROGMEM const char usbDescriptorConfiguration[] = { /* USB configuration descriptor */ 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ USBDESCR_CONFIG, /* descriptor type */ 9 + (9 + 9 + 7) + (9 + 9 + 7), 0,