usbdrv/usbdrv.h File Reference

#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 Documentation

#define schar   signed char

Definition at line 149 of file usbdrv.h.

Referenced by usbPoll().

#define uchar   unsigned char

Definition at line 146 of file usbdrv.h.

#define USB_BUFSIZE   11

Definition at line 538 of file usbdrv.h.

Referenced by usbPoll().

#define USB_CFG_DESCR_PROPS_HID_REPORT   USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH

Definition at line 414 of file usbdrv.h.

#define USB_CFG_IOPORT   USB_OUTPORT(USB_CFG_IOPORTNAME)

Definition at line 529 of file usbdrv.h.

#define USB_CFG_PULLUP_IOPORT   USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME)

Definition at line 531 of file usbdrv.h.

#define USB_CONCAT ( a,
 )     a ## b

Definition at line 476 of file usbdrv.h.

#define USB_CONCAT_EXPANDED ( a,
 )     USB_CONCAT(a, b)

Definition at line 477 of file usbdrv.h.

#define USB_DDRPORT ( name   )     USB_CONCAT(DDR, name)

Definition at line 481 of file usbdrv.h.

#define USB_INITIAL_DATATOKEN   USBPID_DATA1

Definition at line 608 of file usbdrv.h.

#define USB_INPORT ( name   )     USB_CONCAT(PIN, name)

Definition at line 480 of file usbdrv.h.

#define USB_INTR_CFG   MCUCR

Definition at line 546 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_CFG_CLR   0

Definition at line 553 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_CFG_SET   ((1 << ISC00) | (1 << ISC01))

Definition at line 550 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_ENABLE   GICR

Definition at line 562 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_ENABLE_BIT   INT0

Definition at line 566 of file usbdrv.h.

Referenced by usbInit().

#define USB_INTR_PENDING   GIFR

Definition at line 573 of file usbdrv.h.

#define USB_INTR_PENDING_BIT   INTF0

Definition at line 577 of file usbdrv.h.

#define USB_OUTPORT ( name   )     USB_CONCAT(PORT, name)

Definition at line 479 of file usbdrv.h.

#define USB_PROP_IS_DYNAMIC   (1 << 8)

Definition at line 372 of file usbdrv.h.

#define USB_PROP_IS_RAM   (1 << 9)

Definition at line 376 of file usbdrv.h.

#define USB_PROP_LENGTH ( len   )     ((len) & 0xff)

Definition at line 381 of file usbdrv.h.

#define USB_PULLUP_DDR   USB_DDRPORT(USB_CFG_PULLUP_IOPORTNAME)

Definition at line 521 of file usbdrv.h.

#define USB_PULLUP_OUT   USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME)

Definition at line 518 of file usbdrv.h.

#define USB_SET_DATATOKEN1 ( token   )     usbTxBuf1[0] = token

Definition at line 354 of file usbdrv.h.

#define USB_SET_DATATOKEN3 ( token   )     usbTxBuf3[0] = token

Definition at line 355 of file usbdrv.h.

#define USB_STRING_DESCRIPTOR_HEADER ( stringLength   )     ((2*(stringLength)+2) | (3<<8))

Definition at line 332 of file usbdrv.h.

#define USBATTR_BUSPOWER   0x80

Definition at line 677 of file usbdrv.h.

#define USBATTR_REMOTEWAKE   0x20

Definition at line 679 of file usbdrv.h.

#define USBATTR_SELFPOWER   0x40

Definition at line 678 of file usbdrv.h.

#define usbCrc16 ( data,
len   )     usbCrc16((unsigned)(data), len)

Definition at line 295 of file usbdrv.h.

#define usbCrc16Append ( data,
len   )     usbCrc16Append((unsigned)(data), len)

Definition at line 303 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBDDR   USB_DDRPORT(USB_CFG_IOPORTNAME)

Definition at line 520 of file usbdrv.h.

#define USBDESCR_CONFIG   2

Definition at line 669 of file usbdrv.h.

#define USBDESCR_DEVICE   1

Definition at line 668 of file usbdrv.h.

#define USBDESCR_ENDPOINT   5

Definition at line 672 of file usbdrv.h.

#define USBDESCR_HID   0x21

Definition at line 673 of file usbdrv.h.

#define USBDESCR_HID_PHYS   0x23

Definition at line 675 of file usbdrv.h.

#define USBDESCR_HID_REPORT   0x22

Definition at line 674 of file usbdrv.h.

#define USBDESCR_INTERFACE   4

Definition at line 671 of file usbdrv.h.

#define USBDESCR_STRING   3

Definition at line 670 of file usbdrv.h.

 
#define usbDeviceConnect (  ) 

Value:

Definition at line 274 of file usbdrv.h.

Referenced by main().

 
#define usbDeviceDisconnect (  ) 

Value:

Definition at line 276 of file usbdrv.h.

Referenced by main().

#define USBDRV_VERSION   20080418

Definition at line 125 of file usbdrv.h.

#define usbHidReportDescriptor   usbDescriptorHidReport

Definition at line 226 of file usbdrv.h.

#define USBIDLE   (1<<USB_CFG_DMINUS_BIT)

Definition at line 525 of file usbdrv.h.

#define USBIN   USB_INPORT(USB_CFG_IOPORTNAME)

Definition at line 519 of file usbdrv.h.

 
#define usbInterruptIsReady (  )     (usbTxLen1 & 0x10)

Definition at line 213 of file usbdrv.h.

Referenced by main().

#define USBMASK   ((1<<USB_CFG_DPLUS_BIT) | (1<<USB_CFG_DMINUS_BIT))

Definition at line 526 of file usbdrv.h.

#define USBMINUS   USB_CFG_DMINUS_BIT

Definition at line 523 of file usbdrv.h.

#define USBOUT   USB_OUTPORT(USB_CFG_IOPORTNAME)

Definition at line 517 of file usbdrv.h.

#define USBPID_ACK   0xd2

Definition at line 603 of file usbdrv.h.

#define USBPID_DATA0   0xc3

Definition at line 600 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBPID_DATA1   0x4b

Definition at line 601 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBPID_IN   0x69

Definition at line 599 of file usbdrv.h.

#define USBPID_NAK   0x5a

Definition at line 604 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBPID_OUT   0xe1

Definition at line 598 of file usbdrv.h.

#define USBPID_SETUP   0x2d

Definition at line 597 of file usbdrv.h.

#define USBPID_STALL   0x1e

Definition at line 605 of file usbdrv.h.

Referenced by usbSetInterrupt().

#define USBPLUS   USB_CFG_DPLUS_BIT

Definition at line 524 of file usbdrv.h.

#define USBRQ_CLEAR_FEATURE   1

Definition at line 656 of file usbdrv.h.

#define USBRQ_DIR_DEVICE_TO_HOST   (1<<7)

Definition at line 652 of file usbdrv.h.

#define USBRQ_DIR_HOST_TO_DEVICE   (0<<7)

Definition at line 651 of file usbdrv.h.

#define USBRQ_DIR_MASK   0x80

Definition at line 650 of file usbdrv.h.

#define USBRQ_GET_CONFIGURATION   8

Definition at line 661 of file usbdrv.h.

#define USBRQ_GET_DESCRIPTOR   6

Definition at line 659 of file usbdrv.h.

#define USBRQ_GET_INTERFACE   10

Definition at line 663 of file usbdrv.h.

#define USBRQ_GET_STATUS   0

Definition at line 655 of file usbdrv.h.

#define USBRQ_HID_GET_IDLE   0x02

Definition at line 683 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_HID_GET_PROTOCOL   0x03

Definition at line 684 of file usbdrv.h.

#define USBRQ_HID_GET_REPORT   0x01

Definition at line 682 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_HID_SET_IDLE   0x0a

Definition at line 686 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_HID_SET_PROTOCOL   0x0b

Definition at line 687 of file usbdrv.h.

#define USBRQ_HID_SET_REPORT   0x09

Definition at line 685 of file usbdrv.h.

#define USBRQ_RCPT_DEVICE   0

Definition at line 639 of file usbdrv.h.

#define USBRQ_RCPT_ENDPOINT   2

Definition at line 641 of file usbdrv.h.

#define USBRQ_RCPT_INTERFACE   1

Definition at line 640 of file usbdrv.h.

#define USBRQ_RCPT_MASK   0x1f

Definition at line 638 of file usbdrv.h.

#define USBRQ_SET_ADDRESS   5

Definition at line 658 of file usbdrv.h.

#define USBRQ_SET_CONFIGURATION   9

Definition at line 662 of file usbdrv.h.

#define USBRQ_SET_DESCRIPTOR   7

Definition at line 660 of file usbdrv.h.

#define USBRQ_SET_FEATURE   3

Definition at line 657 of file usbdrv.h.

#define USBRQ_SET_INTERFACE   11

Definition at line 664 of file usbdrv.h.

#define USBRQ_SYNCH_FRAME   12

Definition at line 665 of file usbdrv.h.

#define USBRQ_TYPE_CLASS   (1<<5)

Definition at line 646 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_TYPE_MASK   0x60

Definition at line 644 of file usbdrv.h.

Referenced by usbFunctionSetup().

#define USBRQ_TYPE_STANDARD   (0<<5)

Definition at line 645 of file usbdrv.h.

#define USBRQ_TYPE_VENDOR   (2<<5)

Definition at line 647 of file usbdrv.h.


Typedef Documentation

typedef struct usbRequest usbRequest_t

typedef union usbWord usbWord_t


Function Documentation

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 }


Variable Documentation

Definition at line 32 of file usbdrv.c.

Definition at line 143 of file usbdrv.c.

Definition at line 114 of file usbdrv.c.

Definition at line 75 of file usbdrv.c.

Definition at line 94 of file usbdrv.c.

Definition at line 85 of file usbdrv.c.

uchar* usbMsgPtr

Definition at line 52 of file usbdrv.c.

Referenced by usbFunctionSetup().

uchar usbTxBuf1[USB_BUFSIZE]

Definition at line 44 of file usbdrv.c.

Referenced by usbSetInterrupt().

uchar usbTxBuf3[USB_BUFSIZE]

volatile uchar usbTxLen1

Definition at line 43 of file usbdrv.c.

Referenced by usbSetInterrupt().


Generated on Fri Oct 30 20:43:21 2009 for USB IR HID Device by  doxygen 1.5.8