sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Classes | Macros | Typedefs | Functions | Variables
usbdrv.h File Reference
#include "usbconfig.h"
#include "usbportability.h"

Go to the source code of this file.

Classes

struct  usbTxStatus
 
union  usbWord
 
struct  usbRequest
 

Macros

#define USBDRV_VERSION   20121206
 
#define USB_PUBLIC
 
#define uchar   unsigned char
 
#define schar   signed char
 
#define usbMsgLen_t   uchar
 
#define USB_NO_MSG   ((usbMsgLen_t)-1) /* constant meaning "no message" */
 
#define usbMsgPtr_t   uchar *
 
#define usbDeviceConnect()   (USBDDR &= ~(1<<USBMINUS))
 
#define usbDeviceDisconnect()   (USBDDR |= (1<<USBMINUS))
 
#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   (1u << 14)
 
#define USB_PROP_IS_RAM   (1u << 15)
 
#define USB_PROP_LENGTH(len)   ((len) & 0x3fff)
 
#define USB_CFG_DESCR_PROPS_DEVICE   0
 
#define USB_CFG_DESCR_PROPS_CONFIGURATION   0
 
#define USB_CFG_DESCR_PROPS_STRINGS   0
 
#define USB_CFG_DESCR_PROPS_STRING_0   0
 
#define USB_CFG_DESCR_PROPS_STRING_VENDOR   0
 
#define USB_CFG_DESCR_PROPS_STRING_PRODUCT   0
 
#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER   0
 
#define USB_CFG_DESCR_PROPS_HID   0
 
#define USB_CFG_DESCR_PROPS_HID_REPORT   0
 
#define USB_CFG_DESCR_PROPS_UNKNOWN   0
 
#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 USB_CFG_VENDOR_ID   0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */
 
#define USB_CFG_DEVICE_ID   0xdc, 0x05 /* = 0x5dc = 1500, obdev's free PID */
 
#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) /* value representing J state */
 
#define USBMASK   ((1<<USB_CFG_DPLUS_BIT) | (1<<USB_CFG_DMINUS_BIT)) /* mask for USB I/O bits */
 
#define USB_CFG_IOPORT   USB_OUTPORT(USB_CFG_IOPORTNAME)
 
#define USB_CFG_EP3_NUMBER   3
 
#define USB_CFG_HAVE_INTRIN_ENDPOINT3   0
 
#define USB_BUFSIZE   11 /* PID, 8 bytes data, 2 bytes CRC */
 
#define USB_INTR_CFG   MCUCR
 
#define USB_INTR_CFG_SET   ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */
 
#define USB_INTR_CFG_CLR   0 /* no bits to clear */
 
#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 usbTxLen1   usbTxStatus1.len
 
#define usbTxBuf1   usbTxStatus1.buffer
 
#define usbTxLen3   usbTxStatus3.len
 
#define usbTxBuf3   usbTxStatus3.buffer
 
#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   0
 
#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 struct usbTxStatus usbTxStatus_t
 
typedef union usbWord usbWord_t
 
typedef struct usbRequest usbRequest_t
 

Functions

USB_PUBLIC void usbInit (void)
 
USB_PUBLIC void usbPoll (void)
 
USB_PUBLIC usbMsgLen_t usbFunctionSetup (uchar data[8])
 
USB_PUBLIC usbMsgLen_t usbFunctionDescriptor (struct usbRequest *rq)
 
unsigned usbCrc16 (unsigned data, uchar len)
 
unsigned usbCrc16Append (unsigned data, uchar len)
 

Variables

usbMsgPtr_t usbMsgPtr
 
uchar usbRxToken
 
uchar usbConfiguration
 
PROGMEM const char usbDescriptorDevice []
 
PROGMEM const char usbDescriptorConfiguration []
 
PROGMEM const char usbDescriptorHidReport []
 
PROGMEM const char usbDescriptorString0 []
 
PROGMEM const int usbDescriptorStringVendor []
 
PROGMEM const int usbDescriptorStringDevice []
 
PROGMEM const int usbDescriptorStringSerialNumber []
 
usbTxStatus_t usbTxStatus1
 
usbTxStatus_t usbTxStatus3
 

Macro Definition Documentation

#define schar   signed char
#define uchar   unsigned char
#define USB_BUFSIZE   11 /* PID, 8 bytes data, 2 bytes CRC */
#define USB_CFG_DESCR_PROPS_CONFIGURATION   0
#define USB_CFG_DESCR_PROPS_DEVICE   0
#define USB_CFG_DESCR_PROPS_HID   0
#define USB_CFG_DESCR_PROPS_HID_REPORT   0
#define USB_CFG_DESCR_PROPS_STRING_0   0
#define USB_CFG_DESCR_PROPS_STRING_PRODUCT   0
#define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER   0
#define USB_CFG_DESCR_PROPS_STRING_VENDOR   0
#define USB_CFG_DESCR_PROPS_STRINGS   0
#define USB_CFG_DESCR_PROPS_UNKNOWN   0
#define USB_CFG_DEVICE_ID   0xdc, 0x05 /* = 0x5dc = 1500, obdev's free PID */
#define USB_CFG_EP3_NUMBER   3
#define USB_CFG_HAVE_INTRIN_ENDPOINT3   0
#define USB_CFG_IOPORT   USB_OUTPORT(USB_CFG_IOPORTNAME)
#define USB_CFG_VENDOR_ID   0xc0, 0x16 /* = 0x16c0 = 5824 = voti.nl */
#define USB_CONCAT (   a,
  b 
)    a ## b
#define USB_CONCAT_EXPANDED (   a,
  b 
)    USB_CONCAT(a, b)
#define USB_DDRPORT (   name)    USB_CONCAT(DDR, name)
#define USB_INITIAL_DATATOKEN   USBPID_DATA1
#define USB_INPORT (   name)    USB_CONCAT(PIN, name)
#define USB_INTR_CFG   MCUCR
#define USB_INTR_CFG_CLR   0 /* no bits to clear */
#define USB_INTR_CFG_SET   ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */
#define USB_INTR_ENABLE   GICR
#define USB_INTR_ENABLE_BIT   INT0
#define USB_INTR_PENDING   GIFR
#define USB_INTR_PENDING_BIT   INTF0
#define USB_NO_MSG   ((usbMsgLen_t)-1) /* constant meaning "no message" */
#define USB_OUTPORT (   name)    USB_CONCAT(PORT, name)
#define USB_PROP_IS_DYNAMIC   (1u << 14)
#define USB_PROP_IS_RAM   (1u << 15)
#define USB_PROP_LENGTH (   len)    ((len) & 0x3fff)
#define USB_PUBLIC
#define USB_PULLUP_DDR   USB_DDRPORT(USB_CFG_PULLUP_IOPORTNAME)
#define USB_PULLUP_OUT   USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME)
#define USB_SET_DATATOKEN1 (   token)    usbTxBuf1[0] = token
#define USB_SET_DATATOKEN3 (   token)    usbTxBuf3[0] = token
#define USB_STRING_DESCRIPTOR_HEADER (   stringLength)    ((2*(stringLength)+2) | (3<<8))
#define USBATTR_BUSPOWER   0
#define USBATTR_REMOTEWAKE   0x20
#define USBATTR_SELFPOWER   0x40
#define usbCrc16 (   data,
  len 
)    usbCrc16((unsigned)(data), len)
#define usbCrc16Append (   data,
  len 
)    usbCrc16Append((unsigned)(data), len)
#define USBDDR   USB_DDRPORT(USB_CFG_IOPORTNAME)
#define USBDESCR_CONFIG   2
#define USBDESCR_DEVICE   1
#define USBDESCR_ENDPOINT   5
#define USBDESCR_HID   0x21
#define USBDESCR_HID_PHYS   0x23
#define USBDESCR_HID_REPORT   0x22
#define USBDESCR_INTERFACE   4
#define USBDESCR_STRING   3
#define usbDeviceConnect ( )    (USBDDR &= ~(1<<USBMINUS))
#define usbDeviceDisconnect ( )    (USBDDR |= (1<<USBMINUS))
#define USBDRV_VERSION   20121206
#define USBIDLE   (1<<USB_CFG_DMINUS_BIT) /* value representing J state */
#define USBIN   USB_INPORT(USB_CFG_IOPORTNAME)
#define USBMASK   ((1<<USB_CFG_DPLUS_BIT) | (1<<USB_CFG_DMINUS_BIT)) /* mask for USB I/O bits */
#define USBMINUS   USB_CFG_DMINUS_BIT
#define usbMsgLen_t   uchar
#define usbMsgPtr_t   uchar *
#define USBOUT   USB_OUTPORT(USB_CFG_IOPORTNAME)
#define USBPID_ACK   0xd2
#define USBPID_DATA0   0xc3
#define USBPID_DATA1   0x4b
#define USBPID_IN   0x69
#define USBPID_NAK   0x5a
#define USBPID_OUT   0xe1
#define USBPID_SETUP   0x2d
#define USBPID_STALL   0x1e
#define USBPLUS   USB_CFG_DPLUS_BIT
#define USBRQ_CLEAR_FEATURE   1
#define USBRQ_DIR_DEVICE_TO_HOST   (1<<7)
#define USBRQ_DIR_HOST_TO_DEVICE   (0<<7)
#define USBRQ_DIR_MASK   0x80
#define USBRQ_GET_CONFIGURATION   8
#define USBRQ_GET_DESCRIPTOR   6
#define USBRQ_GET_INTERFACE   10
#define USBRQ_GET_STATUS   0
#define USBRQ_HID_GET_IDLE   0x02
#define USBRQ_HID_GET_PROTOCOL   0x03
#define USBRQ_HID_GET_REPORT   0x01
#define USBRQ_HID_SET_IDLE   0x0a
#define USBRQ_HID_SET_PROTOCOL   0x0b
#define USBRQ_HID_SET_REPORT   0x09
#define USBRQ_RCPT_DEVICE   0
#define USBRQ_RCPT_ENDPOINT   2
#define USBRQ_RCPT_INTERFACE   1
#define USBRQ_RCPT_MASK   0x1f
#define USBRQ_SET_ADDRESS   5
#define USBRQ_SET_CONFIGURATION   9
#define USBRQ_SET_DESCRIPTOR   7
#define USBRQ_SET_FEATURE   3
#define USBRQ_SET_INTERFACE   11
#define USBRQ_SYNCH_FRAME   12
#define USBRQ_TYPE_CLASS   (1<<5)
#define USBRQ_TYPE_MASK   0x60
#define USBRQ_TYPE_STANDARD   (0<<5)
#define USBRQ_TYPE_VENDOR   (2<<5)
#define usbTxBuf1   usbTxStatus1.buffer
#define usbTxBuf3   usbTxStatus3.buffer
#define usbTxLen1   usbTxStatus1.len
#define usbTxLen3   usbTxStatus3.len

Typedef Documentation

typedef struct usbRequest usbRequest_t
typedef struct usbTxStatus usbTxStatus_t
typedef union usbWord usbWord_t

Function Documentation

unsigned usbCrc16 ( unsigned  data,
uchar  len 
)
unsigned usbCrc16Append ( unsigned  data,
uchar  len 
)
USB_PUBLIC usbMsgLen_t usbFunctionDescriptor ( struct usbRequest rq)
USB_PUBLIC usbMsgLen_t usbFunctionSetup ( uchar  data[8])
USB_PUBLIC void usbInit ( void  )
USB_PUBLIC void usbPoll ( void  )

Variable Documentation

uchar usbConfiguration
PROGMEM const char usbDescriptorConfiguration[]
PROGMEM const char usbDescriptorDevice[]
PROGMEM const char usbDescriptorHidReport[]
PROGMEM const char usbDescriptorString0[]
PROGMEM const int usbDescriptorStringDevice[]
PROGMEM const int usbDescriptorStringSerialNumber[]
PROGMEM const int usbDescriptorStringVendor[]
usbMsgPtr_t usbMsgPtr
uchar usbRxToken
usbTxStatus_t usbTxStatus1
usbTxStatus_t usbTxStatus3