#include "fx2regs.h"
#include "delay.h"
Go to the source code of this file.
Data Structures | |
struct | DEVICE_DSCR |
struct | CONFIG_DSCR |
struct | STRING_DSCR |
Defines | |
#define | STALLEP0() EP0CS |= bmEPSTALL |
#define | RESETTOGGLE(ep) TOGCTL = (ep&0x0F) + ((ep&0x80)>>3); TOGCTL |= bmRESETTOGGLE |
#define | RENUMERATE() USBCS|=bmDISCON|bmRENUM;delay(1500);USBCS &= ~bmDISCON |
#define | SETUP_VALUE() MAKEWORD(SETUPDAT[3],SETUPDAT[2]) |
#define | SETUP_INDEX() MAKEWORD(SETUPDAT[5],SETUPDAT[4]) |
#define | SETUP_LENGTH() MAKEWORD(SETUPDAT[7],SETUPDAT[6]) |
#define | DSCR_DEVICE_TYPE 1 |
#define | DSCR_CONFIG_TYPE 2 |
#define | DSCR_STRING_TYPE 3 |
#define | DSCR_DEVQUAL_TYPE 6 |
#define | DSCR_OTHERSPD_TYPE 7 |
#define | DSCR_BCD 2 |
#define | DSCR_DEVICE_LEN 18 |
#define | DSCR_CONFIG_LEN 9 |
Enumerations | |
enum | SETUP_DATA { GET_STATUS, CLEAR_FEATURE, SET_FEATURE = 0x03, SET_ADDRESS = 0x05, GET_DESCRIPTOR, SET_DESCRIPTOR, GET_CONFIGURATION, SET_CONFIGURATION, GET_INTERFACE, SET_INTERFACE, SYNC_FRAME } |
Functions | |
xdata BYTE * | ep_addr (BYTE ep) |
void | handle_setupdata () |
void | handle_hispeed () |
This module needs initialized with a device descriptor. NOTE that your descriptors need to be located in code memory to use the SUDPTRH:L to auto transfer the data and vendor commands handler. You have to provide callbacks. DEVICE DESCRIPTORS // copy the dscr_asm file from the lib dir to your // own project directory, change it how // you want, and link it against your project VENDOR COMMANDS 0xA0 is handled by ez-usb firmware. (Upload/Download ram) 0xA1-0xAF is reserved for other ez-usb functions so don't use that Any other value (Above 0x0C anyway) can be used for device specific commands. If you include this file, you need to define a function for vendor commands even if you don't want to implement any vendor commands. The function should return TRUE if you handled the command and FALSE if you didn't. The handle_setup function calls EP0CS |= bmHSNAK; before returning so there is no reason to set that bit in your vendor command handler. (You do need to Set EP0 data and byte counts appropriately though.) // return TRUE if you handle the command // you can directly get SETUPDAT[0-7] for the data sent with the command BOOL handle_vendorcommand(BYTE cmd) { return FALSE; } // a note on vencor commands // this from the usb spec for requesttype D7 Data Phase Transfer Direction 0 = Host to Device 1 = Device to Host D6..5 Type 0 = Standard 1 = Class 2 = Vendor 3 = Reserved D4..0 Recipient 0 = Device 1 = Interface 2 = Endpoint 3 = Other 4..31 = Reserved // if you want libusb to send data back to the host via ep0, you need to make // sure the requesttype had 1 in bit 7. This is for libusb on linux anyway. // set *alt_ifc to the current alt interface for ifc BOOL handle_get_interface(BYTE ifc, BYTE* alt_ifc) { *ifc=0;*alt_ifc=0;} // return TRUE if you set the interface requested // NOTE this function should reconfigure and reset the endpoints // according to the interface descriptors you provided. BOOL handle_set_interface(BYTE ifc,BYTE alt_ifc) { return TRUE; } // handle getting and setting the configuration // 0 is the default. If you support more than one config // keep track of the config number and return the correct number // config numbers are set int the dscr file. BYTE handle_get_configuration() { return 1; } // return TRUE if you handle this request // NOTE changing config requires the device to reset all the endpoints BOOL handle_set_configuration(BYTE cfg) { return FALSE; } // ep num (byte 7 is dir 1=IN,0=OUT) // client needs to reset the endpoint to default state void handle_reset_ep(BYTE ep) { }
Definition in file setupdat.h.
#define DSCR_BCD 2 |
Definition at line 166 of file setupdat.h.
#define DSCR_CONFIG_LEN 9 |
Definition at line 192 of file setupdat.h.
#define DSCR_CONFIG_TYPE 2 |
Definition at line 160 of file setupdat.h.
#define DSCR_DEVICE_LEN 18 |
Definition at line 170 of file setupdat.h.
#define DSCR_DEVICE_TYPE 1 |
Definition at line 159 of file setupdat.h.
#define DSCR_DEVQUAL_TYPE 6 |
Definition at line 162 of file setupdat.h.
#define DSCR_OTHERSPD_TYPE 7 |
Definition at line 163 of file setupdat.h.
#define DSCR_STRING_TYPE 3 |
Definition at line 161 of file setupdat.h.
Definition at line 104 of file setupdat.h.
#define RESETTOGGLE | ( | ep | ) | TOGCTL = (ep&0x0F) + ((ep&0x80)>>3); TOGCTL |= bmRESETTOGGLE |
Definition at line 103 of file setupdat.h.
Definition at line 107 of file setupdat.h.
Definition at line 108 of file setupdat.h.
Definition at line 106 of file setupdat.h.
#define STALLEP0 | ( | ) | EP0CS |= bmEPSTALL |
Definition at line 101 of file setupdat.h.
enum SETUP_DATA |
see TRM 2-3 here are the usb setup data commands these are the usb spec pretty much
GET_STATUS | |
CLEAR_FEATURE | |
SET_FEATURE | |
SET_ADDRESS | |
GET_DESCRIPTOR | |
SET_DESCRIPTOR | |
GET_CONFIGURATION | |
SET_CONFIGURATION | |
GET_INTERFACE | |
SET_INTERFACE | |
SYNC_FRAME |
Definition at line 115 of file setupdat.h.
returns the control/status register for an end point (bit 7=1 for IN, 0 for out
void handle_hispeed | ( | ) |
For devices to properly handle usb hispeed (This is if your descriptor has high speed and full speed versions and it should since the fx2lp is a high speed capable device ) enable both USBRESET and HISPEED interrupts and call this function to switch the descriptors
void handle_setupdata | ( | ) |