📄 usbdrv.h
字号:
/* This function calculates the binary complement of the data CRC used in * USB data packets. The value is used to build raw transmit packets. * You may want to use this function for data checksums or to verify received * data. We enforce 16 bit calling conventions for compatibility with IAR's * tiny memory model. */extern unsigned usbCrc16Append(unsigned data, uchar len);#define usbCrc16Append(data, len) usbCrc16Append((unsigned)(data), len)/* This function is equivalent to usbCrc16() above, except that it appends * the 2 bytes CRC (lowbyte first) in the 'data' buffer after reading 'len' * bytes. */extern uchar usbConfiguration;/* This value contains the current configuration set by the host. The driver * allows setting and querying of this variable with the USB SET_CONFIGURATION * and GET_CONFIGURATION requests, but does not use it otherwise. * You may want to reflect the "configured" status with a LED on the device or * switch on high power parts of the circuit only if the device is configured. */#define USB_STRING_DESCRIPTOR_HEADER(stringLength) ((2*(stringLength)+2) | (3<<8))/* This macro builds a descriptor header for a string descriptor given the * string's length. See usbdrv.c for an example how to use it. */#if USB_CFG_SERIAL_NUMBER_LENGTHextern PROGMEM int usbCfgSerialNumberStringDescriptor[];/* This array of unicode characters (prefixed by a string descriptor header as * explained above) represents the serial number of the device. */#endif /* USB_CFG_SERIAL_NUMBER_LENGTH */#if USB_CFG_HAVE_FLOWCONTROLextern volatile schar usbRxLen;#define usbDisableAllRequests() usbRxLen = -1/* Must be called from usbFunctionWrite(). This macro disables all data input * from the USB interface. Requests from the host are answered with a NAK * while they are disabled. */#define usbEnableAllRequests() usbRxLen = 0/* May only be called if requests are disabled. This macro enables input from * the USB interface after it has been disabled with usbDisableAllRequests(). */#define usbAllRequestsAreDisabled() (usbRxLen < 0)/* Use this macro to find out whether requests are disabled. It may be needed * to ensure that usbEnableAllRequests() is never called when requests are * enabled. */#endif#if USB_CFG_EXTERNAL_CONFIG_DESCRIPTOR_LENGHextern PROGMEM char usbDescrConfig[];#endif#endif /* __ASSEMBLER__ *//* ------------------------------------------------------------------------- *//* ------------------------ General Purpose Macros ------------------------- *//* ------------------------------------------------------------------------- */#define OD_CONCAT(a, b) a ## b#define OD_CONCAT_EXPANDED(a, b) OD_CONCAT(a, b)#define USB_OUTPORT(name) OD_CONCAT(PORT, name)#define USB_INPORT(name) OD_CONCAT(PIN, name)#define USB_DDRPORT(name) OD_CONCAT(DDR, name)/* The double-define trick above lets us concatenate strings which are * defined by macros. *//* ------------------------------------------------------------------------- *//* ------------------------- Constant definitions -------------------------- *//* ------------------------------------------------------------------------- */#if !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"#warning "Using default values depending on device class."#endif/* make sure we have a VID and PID defined, byte order is lowbyte, highbyte */#ifndef USB_CFG_VENDOR_ID# define USB_CFG_VENDOR_ID 0xc0, 0x16 /* 5824 in dec, stands for VOTI */#endif#ifndef USB_CFG_DEVICE_ID# if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH# define USB_CFG_DEVICE_ID 0xdf, 0x05 /* 1503 in dec, shared PID for HIDs */# elif USB_CFG_INTERFACE_CLASS == 2# define USB_CFG_DEVICE_ID 0xe1, 0x05 /* 1505 in dec, shared PID for CDC Modems */# else# define USB_CFG_DEVICE_ID 0xdc, 0x05 /* 1500 in dec, obdev's free PID */# endif#endif#ifndef USB_BUFFER_SECTION# define USB_BUFFER_SECTION ".bss" /* if user has not selected a named section */#endif/* Derive Output, Input and DataDirection ports from port names */#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 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 *//* defines for backward compatibility with older driver versions: */#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#define USB_BUFSIZE 11 /* PID, 8 bytes data, 2 bytes CRC *//* ----- Try to find registers and bits responsible for ext interrupt 0 ----- */#ifndef USB_INTR_CFG /* allow user to override our default */# if defined EICRA# define USB_INTR_CFG EICRA# else# define USB_INTR_CFG MCUCR# endif#endif#ifndef USB_INTR_CFG_SET /* allow user to override our default */# define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */#endif#ifndef USB_INTR_CFG_CLR /* allow user to override our default */# define USB_INTR_CFG_CLR 0 /* no bits to clear */#endif#ifndef USB_INTR_ENABLE /* allow user to override our default */# 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 /* allow user to override our default */# define USB_INTR_ENABLE_BIT INT0#endif#ifndef USB_INTR_PENDING /* allow user to override our default */# if defined EIFR# define USB_INTR_PENDING EIFR# else# define USB_INTR_PENDING GIFR# endif#endif#ifndef USB_INTR_PENDING_BIT /* allow user to override our default */# define USB_INTR_PENDING_BIT INTF0#endif/*The defines above don't work for the following chipsat90c8534: no ISC0?, no PORTB, can't find a data sheetat86rf401: no PORTB, no MCUCR etc, low clock rateatmega103: no ISC0? (maybe omission in header, can't find data sheet)atmega603: not defined in avr-libcat43usb320, at43usb355, at76c711: have USB anywayat94k: is different...at90s1200, attiny11, attiny12, attiny15, attiny28: these have no RAM*//* ------------------------------------------------------------------------- *//* ----------------- USB Specification Constants and Types ----------------- *//* ------------------------------------------------------------------------- *//* USB Token values */#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 __ASSEMBLER__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;/* This structure matches the 8 byte setup request */#endif/* bmRequestType field in USB setup: * d t t r r r r r, where * d ..... direction: 0=host->device, 1=device->host * t ..... type: 0=standard, 1=class, 2=vendor, 3=reserved * r ..... recipient: 0=device, 1=interface, 2=endpoint, 3=other *//* USB setup recipient values */#define USBRQ_RCPT_MASK 0x1f#define USBRQ_RCPT_DEVICE 0#define USBRQ_RCPT_INTERFACE 1#define USBRQ_RCPT_ENDPOINT 2/* USB request type values */#define USBRQ_TYPE_MASK 0x60#define USBRQ_TYPE_STANDARD (0<<5)#define USBRQ_TYPE_CLASS (1<<5)#define USBRQ_TYPE_VENDOR (2<<5)/* USB direction values: */#define USBRQ_DIR_MASK 0x80#define USBRQ_DIR_HOST_TO_DEVICE (0<<7)#define USBRQ_DIR_DEVICE_TO_HOST (1<<7)/* USB Standard Requests */#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/* USB descriptor constants */#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/* USB HID Requests */#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 /* __usbdrv_h_included__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -