#include "usbconfig.h"
#include "iarcompat.h"
Go to the source code of this file.
Data Structures | |
union | usbWord |
struct | usbRequest |
Defines | |
#define | USBDRV_VERSION 20080418 |
#define | uchar unsigned char |
#define | schar signed char |
#define | usbInterruptIsReady() (usbTxLen1 & 0x10) |
#define | usbHidReportDescriptor usbDescriptorHidReport |
#define | usbDeviceConnect() |
#define | usbDeviceDisconnect() |
#define | usbCrc16(data, len) usbCrc16((unsigned)(data), len) |
#define | usbCrc16Append(data, len) usbCrc16Append((unsigned)(data), len) |
#define | USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8)) |
#define | USB_SET_DATATOKEN1(token) usbTxBuf1[0] = token |
#define | USB_SET_DATATOKEN3(token) usbTxBuf3[0] = token |
#define | USB_PROP_IS_DYNAMIC (1 << 8) |
#define | USB_PROP_IS_RAM (1 << 9) |
#define | USB_PROP_LENGTH(len) ((len) & 0xff) |
#define | USB_CFG_DESCR_PROPS_HID_REPORT USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH |
#define | USB_CONCAT(a, b) a ## b |
#define | USB_CONCAT_EXPANDED(a, b) USB_CONCAT(a, b) |
#define | USB_OUTPORT(name) USB_CONCAT(PORT, name) |
#define | USB_INPORT(name) USB_CONCAT(PIN, name) |
#define | USB_DDRPORT(name) USB_CONCAT(DDR, name) |
#define | USBOUT USB_OUTPORT(USB_CFG_IOPORTNAME) |
#define | USB_PULLUP_OUT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME) |
#define | USBIN USB_INPORT(USB_CFG_IOPORTNAME) |
#define | USBDDR USB_DDRPORT(USB_CFG_IOPORTNAME) |
#define | USB_PULLUP_DDR USB_DDRPORT(USB_CFG_PULLUP_IOPORTNAME) |
#define | USBMINUS USB_CFG_DMINUS_BIT |
#define | USBPLUS USB_CFG_DPLUS_BIT |
#define | USBIDLE (1<<USB_CFG_DMINUS_BIT) |
#define | USBMASK ((1<<USB_CFG_DPLUS_BIT) | (1<<USB_CFG_DMINUS_BIT)) |
#define | USB_CFG_IOPORT USB_OUTPORT(USB_CFG_IOPORTNAME) |
#define | USB_CFG_PULLUP_IOPORT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME) |
#define | USB_BUFSIZE 11 |
#define | USB_INTR_CFG MCUCR |
#define | USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) |
#define | USB_INTR_CFG_CLR 0 |
#define | USB_INTR_ENABLE GICR |
#define | USB_INTR_ENABLE_BIT INT0 |
#define | USB_INTR_PENDING GIFR |
#define | USB_INTR_PENDING_BIT INTF0 |
#define | USBPID_SETUP 0x2d |
#define | USBPID_OUT 0xe1 |
#define | USBPID_IN 0x69 |
#define | USBPID_DATA0 0xc3 |
#define | USBPID_DATA1 0x4b |
#define | USBPID_ACK 0xd2 |
#define | USBPID_NAK 0x5a |
#define | USBPID_STALL 0x1e |
#define | USB_INITIAL_DATATOKEN USBPID_DATA1 |
#define | USBRQ_RCPT_MASK 0x1f |
#define | USBRQ_RCPT_DEVICE 0 |
#define | USBRQ_RCPT_INTERFACE 1 |
#define | USBRQ_RCPT_ENDPOINT 2 |
#define | USBRQ_TYPE_MASK 0x60 |
#define | USBRQ_TYPE_STANDARD (0<<5) |
#define | USBRQ_TYPE_CLASS (1<<5) |
#define | USBRQ_TYPE_VENDOR (2<<5) |
#define | USBRQ_DIR_MASK 0x80 |
#define | USBRQ_DIR_HOST_TO_DEVICE (0<<7) |
#define | USBRQ_DIR_DEVICE_TO_HOST (1<<7) |
#define | USBRQ_GET_STATUS 0 |
#define | USBRQ_CLEAR_FEATURE 1 |
#define | USBRQ_SET_FEATURE 3 |
#define | USBRQ_SET_ADDRESS 5 |
#define | USBRQ_GET_DESCRIPTOR 6 |
#define | USBRQ_SET_DESCRIPTOR 7 |
#define | USBRQ_GET_CONFIGURATION 8 |
#define | USBRQ_SET_CONFIGURATION 9 |
#define | USBRQ_GET_INTERFACE 10 |
#define | USBRQ_SET_INTERFACE 11 |
#define | USBRQ_SYNCH_FRAME 12 |
#define | USBDESCR_DEVICE 1 |
#define | USBDESCR_CONFIG 2 |
#define | USBDESCR_STRING 3 |
#define | USBDESCR_INTERFACE 4 |
#define | USBDESCR_ENDPOINT 5 |
#define | USBDESCR_HID 0x21 |
#define | USBDESCR_HID_REPORT 0x22 |
#define | USBDESCR_HID_PHYS 0x23 |
#define | USBATTR_BUSPOWER 0x80 |
#define | USBATTR_SELFPOWER 0x40 |
#define | USBATTR_REMOTEWAKE 0x20 |
#define | USBRQ_HID_GET_REPORT 0x01 |
#define | USBRQ_HID_GET_IDLE 0x02 |
#define | USBRQ_HID_GET_PROTOCOL 0x03 |
#define | USBRQ_HID_SET_REPORT 0x09 |
#define | USBRQ_HID_SET_IDLE 0x0a |
#define | USBRQ_HID_SET_PROTOCOL 0x0b |
Typedefs | |
typedef union usbWord | usbWord_t |
typedef struct usbRequest | usbRequest_t |
Functions | |
USB_PUBLIC void | usbInit (void) |
USB_PUBLIC void | usbPoll (void) |
USB_PUBLIC uchar | usbFunctionSetup (uchar data[8]) |
USB_PUBLIC uchar | usbFunctionDescriptor (struct usbRequest *rq) |
USB_PUBLIC void | usbSetInterrupt (uchar *data, uchar len) |
unsigned | usbCrc16 (unsigned data, uchar len) |
unsigned | usbCrc16Append (unsigned data, uchar len) |
Variables | |
uchar * | usbMsgPtr |
volatile uchar | usbTxLen1 |
uchar | usbConfiguration |
PROGMEM char | usbDescriptorDevice [] |
PROGMEM char | usbDescriptorConfiguration [] |
PROGMEM char | usbDescriptorHidReport [] |
PROGMEM char | usbDescriptorString0 [] |
PROGMEM int | usbDescriptorStringVendor [] |
PROGMEM int | usbDescriptorStringDevice [] |
PROGMEM int | usbDescriptorStringSerialNumber [] |
uchar | usbTxBuf1 [USB_BUFSIZE] |
uchar | usbTxBuf3 [USB_BUFSIZE] |
#define USB_CFG_DESCR_PROPS_HID_REPORT USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH |
#define USB_CFG_PULLUP_IOPORT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME) |
#define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) |
#define USB_PULLUP_DDR USB_DDRPORT(USB_CFG_PULLUP_IOPORTNAME) |
#define USB_PULLUP_OUT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME) |
#define USB_STRING_DESCRIPTOR_HEADER | ( | stringLength | ) | ((2*(stringLength)+2) | (3<<8)) |
#define usbCrc16 | ( | data, | |||
len | ) | usbCrc16((unsigned)(data), len) |
#define usbCrc16Append | ( | data, | |||
len | ) | usbCrc16Append((unsigned)(data), len) |
#define usbDeviceConnect | ( | ) |
Value:
((USB_PULLUP_DDR |= (1<<USB_CFG_PULLUP_BIT)), \ (USB_PULLUP_OUT |= (1<<USB_CFG_PULLUP_BIT)))
Definition at line 274 of file usbdrv.h.
Referenced by main().
#define usbDeviceDisconnect | ( | ) |
Value:
((USB_PULLUP_DDR &= ~(1<<USB_CFG_PULLUP_BIT)), \ (USB_PULLUP_OUT &= ~(1<<USB_CFG_PULLUP_BIT)))
Definition at line 276 of file usbdrv.h.
Referenced by main().
#define usbHidReportDescriptor usbDescriptorHidReport |
#define usbInterruptIsReady | ( | ) | (usbTxLen1 & 0x10) |
#define USBMASK ((1<<USB_CFG_DPLUS_BIT) | (1<<USB_CFG_DMINUS_BIT)) |
#define USBPID_DATA0 0xc3 |
#define USBPID_DATA1 0x4b |
#define USBPID_NAK 0x5a |
#define USBPID_STALL 0x1e |
#define USBRQ_HID_GET_IDLE 0x02 |
#define USBRQ_HID_GET_REPORT 0x01 |
#define USBRQ_HID_SET_IDLE 0x0a |
#define USBRQ_TYPE_CLASS (1<<5) |
#define USBRQ_TYPE_MASK 0x60 |
typedef struct usbRequest usbRequest_t |
unsigned usbCrc16 | ( | unsigned | data, | |
uchar | len | |||
) |
unsigned usbCrc16Append | ( | unsigned | data, | |
uchar | len | |||
) |
USB_PUBLIC uchar usbFunctionDescriptor | ( | struct usbRequest * | rq | ) |
USB_PUBLIC uchar usbFunctionSetup | ( | uchar | data[8] | ) |
Definition at line 453 of file main.c.
00454 { 00455 usbRequest_t* rq = (void *)data; 00456 usbMsgPtr = reportBuffer; 00457 if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) 00458 { 00459 /* class request type */ 00460 if(rq->bRequest == USBRQ_HID_GET_REPORT) 00461 { 00462 /* wValue: ReportType (highbyte), ReportID (lowbyte) */ 00463 /* we only have one report type, so don't look at wValue */ 00464 buildReport(rq->wValue.bytes[0],ir_key_pressed,vtLastKey); 00465 return sizeof(reportBuffer); 00466 } 00467 else if(rq->bRequest == USBRQ_HID_GET_IDLE) 00468 { 00469 usbMsgPtr = &idleRate; 00470 return 1; 00471 } 00472 else if(rq->bRequest == USBRQ_HID_SET_IDLE) 00473 { 00474 idleRate = rq->wValue.bytes[1]; 00475 } 00476 } 00477 else 00478 { 00479 /* no vendor specific requests implemented */ 00480 } 00481 return 0; 00482 }
USB_PUBLIC void usbInit | ( | void | ) |
Definition at line 566 of file usbdrv.c.
Referenced by main().
00567 { 00568 #if USB_INTR_CFG_SET != 0 00569 USB_INTR_CFG |= USB_INTR_CFG_SET; 00570 #endif 00571 #if USB_INTR_CFG_CLR != 0 00572 USB_INTR_CFG &= ~(USB_INTR_CFG_CLR); 00573 #endif 00574 USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT); 00575 usbResetDataToggling(); 00576 }
USB_PUBLIC void usbPoll | ( | void | ) |
Definition at line 526 of file usbdrv.c.
Referenced by main().
00527 { 00528 schar len; 00529 uchar i; 00530 00531 if((len = usbRxLen) > 0){ 00532 /* We could check CRC16 here -- but ACK has already been sent anyway. If you 00533 * need data integrity checks with this driver, check the CRC in your app 00534 * code and report errors back to the host. Since the ACK was already sent, 00535 * retries must be handled on application level. 00536 * unsigned crc = usbCrc16(buffer + 1, usbRxLen - 3); 00537 */ 00538 usbProcessRx(usbRxBuf + USB_BUFSIZE + 1 - usbInputBufOffset, len - 3); 00539 #if USB_CFG_HAVE_FLOWCONTROL 00540 if(usbRxLen > 0) /* only mark as available if not inactivated */ 00541 usbRxLen = 0; 00542 #else 00543 usbRxLen = 0; /* mark rx buffer as available */ 00544 #endif 00545 } 00546 if(usbTxLen & 0x10){ /* transmit system idle */ 00547 if(usbMsgLen != 0xff){ /* transmit data pending? */ 00548 usbBuildTxBlock(); 00549 } 00550 } 00551 for(i = 10; i > 0; i--){ 00552 if(isNotSE0()) 00553 break; 00554 } 00555 if(i == 0){ /* RESET condition, called multiple times during reset */ 00556 usbNewDeviceAddr = 0; 00557 usbDeviceAddr = 0; 00558 usbResetStall(); 00559 DBG1(0xff, 0, 0); 00560 } 00561 usbHandleResetHook(i); 00562 }
USB_PUBLIC void usbSetInterrupt | ( | uchar * | data, | |
uchar | len | |||
) |
Definition at line 229 of file usbdrv.c.
Referenced by main().
00230 { 00231 uchar *p, i; 00232 00233 #if USB_CFG_IMPLEMENT_HALT 00234 if(usbTxLen1 == USBPID_STALL) 00235 return; 00236 #endif 00237 #if 0 /* No runtime checks! Caller is responsible for valid data! */ 00238 if(len > 8) /* interrupt transfers are limited to 8 bytes */ 00239 len = 8; 00240 #endif 00241 if(usbTxLen1 & 0x10){ /* packet buffer was empty */ 00242 usbTxBuf1[0] ^= USBPID_DATA0 ^ USBPID_DATA1; /* toggle token */ 00243 }else{ 00244 usbTxLen1 = USBPID_NAK; /* avoid sending outdated (overwritten) interrupt data */ 00245 } 00246 p = usbTxBuf1 + 1; 00247 for(i=len;i--;) 00248 *p++ = *data++; 00249 usbCrc16Append(&usbTxBuf1[1], len); 00250 usbTxLen1 = len + 4; /* len must be given including sync byte */ 00251 DBG2(0x21, usbTxBuf1, len + 3); 00252 }
uchar usbConfiguration |
PROGMEM char usbDescriptorDevice[] |
PROGMEM char usbDescriptorHidReport[] |
PROGMEM char usbDescriptorString0[] |
uchar* usbMsgPtr |
uchar usbTxBuf1[USB_BUFSIZE] |
uchar usbTxBuf3[USB_BUFSIZE] |
volatile uchar usbTxLen1 |