#ifndef BOOTLOADER_H | #ifndef BOOTLOADER_H | ||||
#define BOOTLOADER_H | #define BOOTLOADER_H | ||||
#ifndef MCUSR | |||||
#define MCUSR MCUCSR | |||||
#endif | |||||
/* give code for your bootloader to come up if needed */ | /* give code for your bootloader to come up if needed */ | ||||
void bootloader_jump(void); | void bootloader_jump(void); |
#else | #else | ||||
# define REPORT_SIZE 8 | # define REPORT_SIZE 8 | ||||
# define REPORT_KEYS 6 | # define REPORT_KEYS 6 | ||||
# define REPORT_BITS 7 | |||||
#endif | #endif | ||||
void timer_init(void) | void timer_init(void) | ||||
{ | { | ||||
// Timer0 CTC mode | // Timer0 CTC mode | ||||
TCCR0A = 0x02; | |||||
TCCR0A |= (1<<WGM01 | 0<<WGM00); | |||||
#if TIMER_PRESCALER == 1 | #if TIMER_PRESCALER == 1 | ||||
TCCR0B = 0x01; | |||||
TCCR0B |= (0<<CS02 | 0<<CS01 | 1<<CS00); | |||||
#elif TIMER_PRESCALER == 8 | #elif TIMER_PRESCALER == 8 | ||||
TCCR0B = 0x02; | |||||
TCCR0B |= (0<<CS02 | 1<<CS01 | 0<<CS00); | |||||
#elif TIMER_PRESCALER == 64 | #elif TIMER_PRESCALER == 64 | ||||
TCCR0B = 0x03; | |||||
TCCR0B |= (0<<CS02 | 1<<CS01 | 1<<CS00); | |||||
#elif TIMER_PRESCALER == 256 | #elif TIMER_PRESCALER == 256 | ||||
TCCR0B = 0x04; | |||||
TCCR0B |= (1<<CS02 | 0<<CS01 | 0<<CS00); | |||||
#elif TIMER_PRESCALER == 1024 | #elif TIMER_PRESCALER == 1024 | ||||
TCCR0B = 0x05; | |||||
TCCR0B |= (1<<CS02 | 0<<CS01 | 1<<CS00); | |||||
#else | #else | ||||
# error "Timer prescaler value is NOT vaild." | # error "Timer prescaler value is NOT vaild." | ||||
#endif | #endif |
#define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) | #define TIMER_DIFF_32(a, b) TIMER_DIFF(a, b, UINT32_MAX) | ||||
#define TIMER_DIFF_RAW(a, b) TIMER_DIFF_8(a, b) | #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 | #ifdef __cplusplus | ||||
extern "C" { | extern "C" { |
$(VUSB_DIR)/usbdrv/usbdrvasm.S \ | $(VUSB_DIR)/usbdrv/usbdrvasm.S \ | ||||
$(VUSB_DIR)/usbdrv/oddebug.c | $(VUSB_DIR)/usbdrv/oddebug.c | ||||
COMMON_DIR = common | |||||
ifdef NO_UART | ifdef NO_UART | ||||
SRC += $(COMMON_DIR)/sendchar_null.c | SRC += $(COMMON_DIR)/sendchar_null.c | ||||
OPT_DEFS += -DNO_UART | |||||
else | else | ||||
SRC += $(COMMON_DIR)/sendchar_uart.c \ | SRC += $(COMMON_DIR)/sendchar_uart.c \ | ||||
$(COMMON_DIR)/uart.c | $(COMMON_DIR)/uart.c |
uint16_t last_timer = timer_read(); | uint16_t last_timer = timer_read(); | ||||
#endif | #endif | ||||
#ifdef CLKPR | |||||
CLKPR = 0x80, CLKPR = 0; | CLKPR = 0x80, CLKPR = 0; | ||||
#endif | |||||
#ifndef NO_UART | |||||
#ifndef PS2_USE_USART | #ifndef PS2_USE_USART | ||||
uart_init(UART_BAUD_RATE); | uart_init(UART_BAUD_RATE); | ||||
#endif | |||||
#endif | #endif | ||||
keyboard_init(); | keyboard_init(); |
#endif | #endif | ||||
/* USB status registers / not shared with asm code */ | /* 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 usbMsgLen_t usbMsgLen = USB_NO_MSG; /* remaining number of bytes */ | ||||
static uchar usbMsgFlags; /* flag values see below */ | static uchar usbMsgFlags; /* flag values see below */ | ||||
#if USB_CFG_DESCR_PROPS_STRING_0 == 0 | #if USB_CFG_DESCR_PROPS_STRING_0 == 0 | ||||
#undef USB_CFG_DESCR_PROPS_STRING_0 | #undef USB_CFG_DESCR_PROPS_STRING_0 | ||||
#define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0) | #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 */ | 4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */ | ||||
3, /* descriptor type */ | 3, /* descriptor type */ | ||||
0x09, 0x04, /* language index (0x0409 = US-English) */ | 0x09, 0x04, /* language index (0x0409 = US-English) */ | ||||
#if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN | #if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN | ||||
#undef USB_CFG_DESCR_PROPS_STRING_VENDOR | #undef USB_CFG_DESCR_PROPS_STRING_VENDOR | ||||
#define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor) | #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_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN), | ||||
USB_CFG_VENDOR_NAME | USB_CFG_VENDOR_NAME | ||||
}; | }; | ||||
#if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN | #if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN | ||||
#undef USB_CFG_DESCR_PROPS_STRING_PRODUCT | #undef USB_CFG_DESCR_PROPS_STRING_PRODUCT | ||||
#define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice) | #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_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN), | ||||
USB_CFG_DEVICE_NAME | USB_CFG_DEVICE_NAME | ||||
}; | }; | ||||
#if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN | #if USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER == 0 && USB_CFG_SERIAL_NUMBER_LEN | ||||
#undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER | #undef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER | ||||
#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER sizeof(usbDescriptorStringSerialNumber) | #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_STRING_DESCRIPTOR_HEADER(USB_CFG_SERIAL_NUMBER_LEN), | ||||
USB_CFG_SERIAL_NUMBER | USB_CFG_SERIAL_NUMBER | ||||
}; | }; | ||||
#if USB_CFG_DESCR_PROPS_DEVICE == 0 | #if USB_CFG_DESCR_PROPS_DEVICE == 0 | ||||
#undef USB_CFG_DESCR_PROPS_DEVICE | #undef USB_CFG_DESCR_PROPS_DEVICE | ||||
#define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice) | #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 */ | 18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */ | ||||
USBDESCR_DEVICE, /* descriptor type */ | USBDESCR_DEVICE, /* descriptor type */ | ||||
0x10, 0x01, /* USB version supported */ | 0x10, 0x01, /* USB version supported */ | ||||
#if USB_CFG_DESCR_PROPS_CONFIGURATION == 0 | #if USB_CFG_DESCR_PROPS_CONFIGURATION == 0 | ||||
#undef USB_CFG_DESCR_PROPS_CONFIGURATION | #undef USB_CFG_DESCR_PROPS_CONFIGURATION | ||||
#define USB_CFG_DESCR_PROPS_CONFIGURATION sizeof(usbDescriptorConfiguration) | #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 */ | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ | ||||
USBDESCR_CONFIG, /* descriptor type */ | USBDESCR_CONFIG, /* descriptor type */ | ||||
18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + | 18 + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT + 7 * USB_CFG_HAVE_INTRIN_ENDPOINT3 + | ||||
}else | }else | ||||
#endif | #endif | ||||
{ | { | ||||
uchar i = len, *r = usbMsgPtr; | |||||
uchar i = len; | |||||
const uchar *r = usbMsgPtr; | |||||
if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */ | if(usbMsgFlags & USB_FLG_MSGPTR_IS_ROM){ /* ROM data */ | ||||
do{ | do{ | ||||
uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */ | uchar c = USB_READ_FLASH(r); /* assign to char size variable to enforce byte ops */ |
* Please note that debug outputs through the UART take ~ 0.5ms per byte | * Please note that debug outputs through the UART take ~ 0.5ms per byte | ||||
* at 19200 bps. | * at 19200 bps. | ||||
*/ | */ | ||||
extern uchar *usbMsgPtr; | |||||
extern const uchar *usbMsgPtr; | |||||
/* This variable may be used to pass transmit data to the driver from the | /* This variable may be used to pass transmit data to the driver from the | ||||
* implementation of usbFunctionWrite(). It is also used internally by the | * implementation of usbFunctionWrite(). It is also used internally by the | ||||
* driver for standard control requests. | * driver for standard control requests. | ||||
#if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM) | #if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM) | ||||
PROGMEM | PROGMEM | ||||
#endif | #endif | ||||
char usbDescriptorDevice[]; | |||||
const char usbDescriptorDevice[]; | |||||
extern | extern | ||||
#if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM) | #if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM) | ||||
PROGMEM | PROGMEM | ||||
#endif | #endif | ||||
char usbDescriptorConfiguration[]; | |||||
const char usbDescriptorConfiguration[]; | |||||
extern | extern | ||||
#if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM) | #if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM) | ||||
PROGMEM | PROGMEM | ||||
#endif | #endif | ||||
char usbDescriptorHidReport[]; | |||||
const char usbDescriptorHidReport[]; | |||||
extern | extern | ||||
#if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM) | #if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM) | ||||
PROGMEM | PROGMEM | ||||
#endif | #endif | ||||
char usbDescriptorString0[]; | |||||
const char usbDescriptorString0[]; | |||||
extern | extern | ||||
#if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM) | #if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM) | ||||
PROGMEM | PROGMEM | ||||
#endif | #endif | ||||
int usbDescriptorStringVendor[]; | |||||
const int usbDescriptorStringVendor[]; | |||||
extern | extern | ||||
#if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM) | #if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM) | ||||
PROGMEM | PROGMEM | ||||
#endif | #endif | ||||
int usbDescriptorStringDevice[]; | |||||
const int usbDescriptorStringDevice[]; | |||||
extern | extern | ||||
#if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM) | #if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM) | ||||
PROGMEM | PROGMEM | ||||
#endif | #endif | ||||
int usbDescriptorStringSerialNumber[]; | |||||
const int usbDescriptorStringSerialNumber[]; | |||||
#endif /* __ASSEMBLER__ */ | #endif /* __ASSEMBLER__ */ | ||||
#include "debug.h" | #include "debug.h" | ||||
#include "host_driver.h" | #include "host_driver.h" | ||||
#include "vusb.h" | #include "vusb.h" | ||||
#include "action_util.h" | |||||
static uint8_t vusb_keyboard_leds = 0; | static uint8_t vusb_keyboard_leds = 0; | ||||
* | * | ||||
* from an example in HID spec appendix | * from an example in HID spec appendix | ||||
*/ | */ | ||||
PROGMEM uchar keyboard_hid_report[] = { | |||||
PROGMEM const uchar keyboard_hid_report[] = { | |||||
0x05, 0x01, // Usage Page (Generic Desktop), | 0x05, 0x01, // Usage Page (Generic Desktop), | ||||
0x09, 0x06, // Usage (Keyboard), | 0x09, 0x06, // Usage (Keyboard), | ||||
0xA1, 0x01, // Collection (Application), | 0xA1, 0x01, // Collection (Application), | ||||
* http://www.keil.com/forum/15671/ | * http://www.keil.com/forum/15671/ | ||||
* http://www.microsoft.com/whdc/device/input/wheel.mspx | * http://www.microsoft.com/whdc/device/input/wheel.mspx | ||||
*/ | */ | ||||
PROGMEM uchar mouse_hid_report[] = { | |||||
PROGMEM const uchar mouse_hid_report[] = { | |||||
/* mouse */ | /* mouse */ | ||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop) | 0x05, 0x01, // USAGE_PAGE (Generic Desktop) | ||||
0x09, 0x02, // USAGE (Mouse) | 0x09, 0x02, // USAGE (Mouse) | ||||
* contains: device, interface, HID and endpoint descriptors | * contains: device, interface, HID and endpoint descriptors | ||||
*/ | */ | ||||
#if USB_CFG_DESCR_PROPS_CONFIGURATION | #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 */ | 9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */ | ||||
USBDESCR_CONFIG, /* descriptor type */ | USBDESCR_CONFIG, /* descriptor type */ | ||||
9 + (9 + 9 + 7) + (9 + 9 + 7), 0, | 9 + (9 + 9 + 7) + (9 + 9 + 7), 0, |