📄 usbdrv.h
字号:
* transfer's payload data (control-in). It is called in chunks of up to 8 * bytes each. You should copy the data to the location given by 'data' and * return the actual number of bytes copied. If you return less than requested, * the control-in transfer is terminated. If you return 0xff, the driver aborts * the transfer with a STALL token. * In order to get usbFunctionRead() called, define USB_CFG_IMPLEMENT_FN_READ * to 1 in usbconfig.h and return 0xff in usbFunctionSetup().. */#endif /* USB_CFG_IMPLEMENT_FN_READ */#ifdef USB_CFG_PULLUP_IOPORT#define usbDeviceConnect() ((USB_PULLUP_DDR |= (1<<USB_CFG_PULLUP_BIT)), \ (USB_PULLUP_OUT |= (1<<USB_CFG_PULLUP_BIT)))/* This macro (intended to look like a function) connects the device to the * USB bus. It is only available if you have defined the constants * USB_CFG_PULLUP_IOPORT and USB_CFG_PULLUP_BIT in usbconfig.h. */#define usbDeviceDisconnect() (USB_PULLUP_OUT &= ~(1<<USB_CFG_PULLUP_BIT))/* This macro (intended to look like a function) disconnects the device from * the USB bus. It is only available if you have defined the constants * USB_CFG_PULLUP_IOPORT and USB_CFG_PULLUP_BIT in usbconfig.h. */#endif /* USB_CFG_PULLUP_IOPORT */extern unsigned usbCrc16(uchar *data, uchar len);/* 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. */extern unsigned usbCrc16Append(unsigned char *data, unsigned char 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#endif /* __ASSEMBLER__ *//* ------------------------------------------------------------------------- *//* ------------------------- Constant definitions -------------------------- *//* ------------------------------------------------------------------------- */#if USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH && (!defined USB_CFG_VENDOR_ID || !defined USB_CFG_DEVICE_ID)#error "You MUST NOT use obdev's shared VID/PID with HID class devices!"/* The shared VID/PID must be used in conjunction with libusb (see license for * the IDs). This contradicts HID usage (at least on Windows). */#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# define USB_CFG_DEVICE_ID 0xdc, 0x05 /* 1500 in dec, obdev's free PID */#endif#ifndef USB_BUFFER_SECTION# define USB_BUFFER_SECTION ".bss" /* if user has not selected a named section */#endif/* I/O definitions for assembler module */#define USBOUT USB_CFG_IOPORT /* output port for USB bits */#define USB_PULLUP_OUT USB_CFG_PULLUP_IOPORT#ifdef __ASSEMBLER__/* the following two lines must start in column 0 for IAR assembler */USBIN = (USB_CFG_IOPORT - 2) /* input port for USB bits */USBDDR = (USB_CFG_IOPORT - 1) /* data direction for USB bits */#else#define USBIN (*(&USB_CFG_IOPORT - 2)) /* input port for USB bits */#define USBDDR (*(&USB_CFG_IOPORT - 1)) /* data direction for USB bits */#define USB_PULLUP_DDR (*(&USB_CFG_PULLUP_IOPORT - 1))#endif#if USB_CFG_DMINUS_BIT != 0# error "USB_CFG_DMINUS_BIT MUST be 0!"#endif#define USBMINUS 0 /* D- MUST be on bit 0 */#define USBIDLE 0x01 /* value representing J state */#define USBMASK ((1<<USB_CFG_DPLUS_BIT) | 1) /* mask for USB I/O bits */#define USB_BUFSIZE 11 /* PID, 8 bytes data, 2 bytes CRC *//* Try to find registers and bits responsible for ext interrupt 0 */#if defined EICRA# define USB_INTR_CFG EICRA#else# define USB_INTR_CFG MCUCR#endif#define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) /* cfg for rising edge */#define USB_INTR_CFG_CLR 0 /* no bits to clear */#if defined GIMSK# define USB_INTR_ENABLE GIMSK#elif defined EIMSK# define USB_INTR_ENABLE EIMSK#else# define USB_INTR_ENABLE GICR#endif#define USB_INTR_ENABLE_BIT INT0#if defined EIFR# define USB_INTR_PENDING EIFR#else# define USB_INTR_PENDING GIFR#endif#define USB_INTR_PENDING_BIT INTF0/*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 + -