Fx2lib  0.2
Data Structures | Defines | Enumerations | Functions | Variables
include/setupdat.h File Reference
#include "fx2regs.h"
#include "delay.h"

Go to the source code of this file.

Data Structures

struct  HEADER_DSCR
struct  DEVICE_DSCR
struct  STRING_DSCR

Defines

#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 SETUP_TYPE   SETUPDAT[0]
#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_DEBUG_TYPE   10
#define DSCR_BCD   0x0200
#define DSCR_DEVICE_LEN   18
#define DSCR_CONFIG_LEN   9
#define CONFIG_DSCR   DSCR_HEAD

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 BYTEep_addr (BYTE ep)
 Get pointer to an endpoint's control/status register.
void handle_setupdata ()
void handle_hispeed (BOOL highspeed)
 Switch the descriptor pointer to right descriptor version.

Variables

volatile BOOL self_powered
volatile BOOL remote_wakeup_allowed

Detailed Description

Utilities for handling setup data and vendor commands.


 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 Documentation

#define CONFIG_DSCR   DSCR_HEAD

Definition at line 258 of file setupdat.h.

#define DSCR_BCD   0x0200

Definition at line 235 of file setupdat.h.

#define DSCR_CONFIG_LEN   9

Definition at line 257 of file setupdat.h.

#define DSCR_CONFIG_TYPE   2

Definition at line 228 of file setupdat.h.

#define DSCR_DEBUG_TYPE   10

Definition at line 232 of file setupdat.h.

#define DSCR_DEVICE_LEN   18

Definition at line 254 of file setupdat.h.

#define DSCR_DEVICE_TYPE   1

Definition at line 227 of file setupdat.h.

#define DSCR_DEVQUAL_TYPE   6

Definition at line 230 of file setupdat.h.

#define DSCR_OTHERSPD_TYPE   7

Definition at line 231 of file setupdat.h.

#define DSCR_STRING_TYPE   3

Definition at line 229 of file setupdat.h.

#define SETUP_INDEX ( )    MAKEWORD(SETUPDAT[5],SETUPDAT[4])

Definition at line 101 of file setupdat.h.

#define SETUP_LENGTH ( )    MAKEWORD(SETUPDAT[7],SETUPDAT[6])

Definition at line 102 of file setupdat.h.

#define SETUP_TYPE   SETUPDAT[0]

Definition at line 103 of file setupdat.h.

#define SETUP_VALUE ( )    MAKEWORD(SETUPDAT[3],SETUPDAT[2])

Definition at line 100 of file setupdat.h.


Enumeration Type Documentation

enum SETUP_DATA

see TRM 2-3 here are the usb setup data commands these are the usb spec pretty much

Enumerator:
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 123 of file setupdat.h.


Function Documentation

__xdata BYTE* ep_addr ( BYTE  ep)

Get pointer to an endpoint's control/status register.

Parameters:
Endpointnumber (lower bits) and direction (bit 7).
void handle_hispeed ( BOOL  highspeed)

Switch the descriptor pointer to right descriptor version.

This function switches the descriptor pointer between the high speed and full speed descriptor versions. To use this function;

  • Your descriptors should have both versions.
  • Enable both USBRESET and HISPEED interrupts.
  • In your ISR for these functions call this method;
  • * highspeed = FALSE for USBRESET
  • * highspeed = TRUE for HISPEED

This function is safe to call both inside an ISR and outside because it disable interrupts while operating (__critical).

See fw::c for full example.

Parameters:
highspeedUse high speed descriptor?
  • TRUE, use high speed descriptor.
  • FALSE, use full speed descriptor.
Examples:
fw.c.
void handle_setupdata ( )
Examples:
fw.c.

Variable Documentation

remote_wakeup_allowed defaults to FALSE but can be set to TRUE with SET_FEATURE from the host. (firmware shouldn't set this.)

Examples:
fw.c.
volatile BOOL self_powered

self_powered is set to FALSE by default. It is used for GET_FEATURE requests. Firmware can set it to TRUE if the device is not powered by the USB bus.