123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735 |
- #ifndef __usbdrv_h_included__
- #define __usbdrv_h_included__
- #include "usbconfig.h"
- #include "usbportability.h"
- #define USBDRV_VERSION 20100715
- #ifndef USB_PUBLIC
- #define USB_PUBLIC
- #endif
- #ifndef __ASSEMBLER__
- #ifndef uchar
- #define uchar unsigned char
- #endif
- #ifndef schar
- #define schar signed char
- #endif
- #if USB_CFG_LONG_TRANSFERS
- # define usbMsgLen_t unsigned
- #else
- # define usbMsgLen_t uchar
- #endif
- #define USB_NO_MSG ((usbMsgLen_t)-1)
- struct usbRequest;
- USB_PUBLIC void usbInit(void);
- USB_PUBLIC void usbPoll(void);
- extern uchar *usbMsgPtr;
- USB_PUBLIC usbMsgLen_t usbFunctionSetup(uchar data[8]);
- USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq);
- #if USB_CFG_HAVE_INTRIN_ENDPOINT
- USB_PUBLIC void usbSetInterrupt(uchar *data, uchar len);
- #define usbInterruptIsReady() (usbTxLen1 & 0x10)
- #if USB_CFG_HAVE_INTRIN_ENDPOINT3
- USB_PUBLIC void usbSetInterrupt3(uchar *data, uchar len);
- #define usbInterruptIsReady3() (usbTxLen3 & 0x10)
- #endif
- #endif
- #if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH
- #define usbHidReportDescriptor usbDescriptorHidReport
- #endif
- #if USB_CFG_IMPLEMENT_FN_WRITE
- USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len);
- #endif
- #if USB_CFG_IMPLEMENT_FN_READ
- USB_PUBLIC uchar usbFunctionRead(uchar *data, uchar len);
- #endif
- extern uchar usbRxToken;
- #if USB_CFG_IMPLEMENT_FN_WRITEOUT
- USB_PUBLIC void usbFunctionWriteOut(uchar *data, uchar len);
- #endif
- #ifdef USB_CFG_PULLUP_IOPORTNAME
- #define usbDeviceConnect() ((USB_PULLUP_DDR |= (1<<USB_CFG_PULLUP_BIT)), \
- (USB_PULLUP_OUT |= (1<<USB_CFG_PULLUP_BIT)))
- #define usbDeviceDisconnect() ((USB_PULLUP_DDR &= ~(1<<USB_CFG_PULLUP_BIT)), \
- (USB_PULLUP_OUT &= ~(1<<USB_CFG_PULLUP_BIT)))
- #else
- #define usbDeviceConnect() (USBDDR &= ~(1<<USBMINUS))
- #define usbDeviceDisconnect() (USBDDR |= (1<<USBMINUS))
- #endif
- extern unsigned usbCrc16(unsigned data, uchar len);
- #define usbCrc16(data, len) usbCrc16((unsigned)(data), len)
- extern unsigned usbCrc16Append(unsigned data, uchar len);
- #define usbCrc16Append(data, len) usbCrc16Append((unsigned)(data), len)
- #if USB_CFG_HAVE_MEASURE_FRAME_LENGTH
- extern unsigned usbMeasureFrameLength(void);
- #endif
- extern uchar usbConfiguration;
- #if USB_COUNT_SOF
- extern volatile uchar usbSofCount;
- #endif
- #if USB_CFG_CHECK_DATA_TOGGLING
- extern uchar usbCurrentDataToken;
- #endif
- #define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8))
- #if USB_CFG_HAVE_FLOWCONTROL
- extern volatile schar usbRxLen;
- #define usbDisableAllRequests() usbRxLen = -1
- #define usbEnableAllRequests() usbRxLen = 0
- #define usbAllRequestsAreDisabled() (usbRxLen < 0)
- #endif
- #define USB_SET_DATATOKEN1(token) usbTxBuf1[0] = token
- #define USB_SET_DATATOKEN3(token) usbTxBuf3[0] = token
- #endif
- #define USB_PROP_IS_DYNAMIC (1 << 14)
- #define USB_PROP_IS_RAM (1 << 15)
- #define USB_PROP_LENGTH(len) ((len) & 0x3fff)
- #ifndef USB_CFG_DESCR_PROPS_DEVICE
- #define USB_CFG_DESCR_PROPS_DEVICE 0
- #endif
- #ifndef USB_CFG_DESCR_PROPS_CONFIGURATION
- #define USB_CFG_DESCR_PROPS_CONFIGURATION 0
- #endif
- #ifndef USB_CFG_DESCR_PROPS_STRINGS
- #define USB_CFG_DESCR_PROPS_STRINGS 0
- #endif
- #ifndef USB_CFG_DESCR_PROPS_STRING_0
- #define USB_CFG_DESCR_PROPS_STRING_0 0
- #endif
- #ifndef USB_CFG_DESCR_PROPS_STRING_VENDOR
- #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0
- #endif
- #ifndef USB_CFG_DESCR_PROPS_STRING_PRODUCT
- #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0
- #endif
- #ifndef USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER
- #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0
- #endif
- #ifndef USB_CFG_DESCR_PROPS_HID
- #define USB_CFG_DESCR_PROPS_HID 0
- #endif
- #if !(USB_CFG_DESCR_PROPS_HID_REPORT)
- # undef USB_CFG_DESCR_PROPS_HID_REPORT
- # if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH
- # define USB_CFG_DESCR_PROPS_HID_REPORT USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH
- # else
- # define USB_CFG_DESCR_PROPS_HID_REPORT 0
- # endif
- #endif
- #ifndef USB_CFG_DESCR_PROPS_UNKNOWN
- #define USB_CFG_DESCR_PROPS_UNKNOWN 0
- #endif
- #ifndef __ASSEMBLER__
- extern
- #if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM)
- PROGMEM
- #endif
- const char usbDescriptorDevice[];
- extern
- #if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM)
- PROGMEM
- #endif
- const char usbDescriptorConfiguration[];
- extern
- #if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM)
- PROGMEM
- #endif
- const char usbDescriptorHidReport[];
- extern
- #if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM)
- PROGMEM
- #endif
- const char usbDescriptorString0[];
- extern
- #if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM)
- PROGMEM
- #endif
- const int usbDescriptorStringVendor[];
- extern
- #if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM)
- PROGMEM
- #endif
- const int usbDescriptorStringDevice[];
- extern
- #if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM)
- PROGMEM
- #endif
- const int usbDescriptorStringSerialNumber[];
- #endif
- #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)
- #if !defined __ASSEMBLER__ && (!defined USB_CFG_VENDOR_ID || !defined USB_CFG_DEVICE_ID)
- #warning "You should define USB_CFG_VENDOR_ID and USB_CFG_DEVICE_ID in usbconfig.h"
- #endif
- #ifndef USB_CFG_VENDOR_ID
- # define USB_CFG_VENDOR_ID 0xc0, 0x16
- #endif
- #ifndef USB_CFG_DEVICE_ID
- # if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH
- # define USB_CFG_DEVICE_ID 0xdf, 0x05
- # elif USB_CFG_INTERFACE_CLASS == 2
- # define USB_CFG_DEVICE_ID 0xe1, 0x05
- # else
- # define USB_CFG_DEVICE_ID 0xdc, 0x05
- # endif
- #endif
- #ifndef USB_CFG_IOPORTNAME
- #error "You must define USB_CFG_IOPORTNAME in usbconfig.h, see usbconfig-prototype.h"
- #endif
- #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)
- #ifdef USB_CFG_PULLUP_IOPORTNAME
- #define USB_CFG_PULLUP_IOPORT USB_OUTPORT(USB_CFG_PULLUP_IOPORTNAME)
- #endif
- #ifndef USB_CFG_EP3_NUMBER
- #define USB_CFG_EP3_NUMBER 3
- #endif
- #ifndef USB_CFG_HAVE_INTRIN_ENDPOINT3
- #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0
- #endif
- #define USB_BUFSIZE 11
- #ifndef USB_INTR_CFG
- # if defined EICRA
- # define USB_INTR_CFG EICRA
- # else
- # define USB_INTR_CFG MCUCR
- # endif
- #endif
- #ifndef USB_INTR_CFG_SET
- # if defined(USB_COUNT_SOF) || defined(USB_SOF_HOOK)
- # define USB_INTR_CFG_SET (1 << ISC01)
-
- # else
- # define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01))
- # endif
- #endif
- #ifndef USB_INTR_CFG_CLR
- # define USB_INTR_CFG_CLR 0
- #endif
- #ifndef USB_INTR_ENABLE
- # if defined GIMSK
- # define USB_INTR_ENABLE GIMSK
- # elif defined EIMSK
- # define USB_INTR_ENABLE EIMSK
- # else
- # define USB_INTR_ENABLE GICR
- # endif
- #endif
- #ifndef USB_INTR_ENABLE_BIT
- # define USB_INTR_ENABLE_BIT INT0
- #endif
- #ifndef USB_INTR_PENDING
- # if defined EIFR
- # define USB_INTR_PENDING EIFR
- # else
- # define USB_INTR_PENDING GIFR
- # endif
- #endif
- #ifndef USB_INTR_PENDING_BIT
- # define USB_INTR_PENDING_BIT INTF0
- #endif
- #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
- #ifndef USB_INITIAL_DATATOKEN
- #define USB_INITIAL_DATATOKEN USBPID_DATA1
- #endif
- #ifndef __ASSEMBLER__
- typedef struct usbTxStatus{
- volatile uchar len;
- uchar buffer[USB_BUFSIZE];
- }usbTxStatus_t;
- extern usbTxStatus_t usbTxStatus1, usbTxStatus3;
- #define usbTxLen1 usbTxStatus1.len
- #define usbTxBuf1 usbTxStatus1.buffer
- #define usbTxLen3 usbTxStatus3.len
- #define usbTxBuf3 usbTxStatus3.buffer
- typedef union usbWord{
- unsigned word;
- uchar bytes[2];
- }usbWord_t;
- typedef struct usbRequest{
- uchar bmRequestType;
- uchar bRequest;
- usbWord_t wValue;
- usbWord_t wIndex;
- usbWord_t wLength;
- }usbRequest_t;
- #endif
- #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_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
- #endif
|