Fx2lib  0.2
include/setupdat.h
Go to the documentation of this file.
00001 // Copyright (C) 2009 Ubixum, Inc. 
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License, or (at your option) any later version.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00016 
00017 #ifndef SETUPDAT_H
00018 #define SETUPDAT_H
00019 
00020 #include "fx2regs.h"
00021 #include "delay.h"
00100 #define SETUP_VALUE() MAKEWORD(SETUPDAT[3],SETUPDAT[2])
00101 #define SETUP_INDEX() MAKEWORD(SETUPDAT[5],SETUPDAT[4])
00102 #define SETUP_LENGTH() MAKEWORD(SETUPDAT[7],SETUPDAT[6]) 
00103 #define SETUP_TYPE SETUPDAT[0]
00104 
00110 extern volatile BOOL self_powered;
00111 
00117 extern volatile BOOL remote_wakeup_allowed;
00118 
00122 
00123 typedef enum {
00124     GET_STATUS,
00125     CLEAR_FEATURE,
00126     // 0x02 is reserved
00127     SET_FEATURE=0x03,
00128     // 0x04 is reserved
00129     SET_ADDRESS=0x05, // this is handled by EZ-USB core unless RENUM=0
00130     GET_DESCRIPTOR,
00131     SET_DESCRIPTOR,
00132     GET_CONFIGURATION,
00133     SET_CONFIGURATION,
00134     GET_INTERFACE,
00135     SET_INTERFACE,
00136     SYNC_FRAME
00137 } SETUP_DATA;
00138 
00139 
00145 __xdata BYTE* ep_addr(BYTE ep);
00146 
00147 /*
00148  * \brief Handle the "setup data" USB requests.
00149  *
00150  * This function should *not* be called inside an ISR (as it calls
00151  * non-reentrant functions). Instead you should set a flag inside the ISR and
00152  * then call this function ASAP as part of your main loop.
00153  *
00154  * \code
00155  * volatile __bit dosud=FALSE;
00156  * void sudav_isr() __interrupt SUDAV_ISR {
00157  *     CLEAR_SUDAV();
00158  *     if(dosud) {
00159  *         // Indicate error
00160  *     }
00161  *     dosud=TRUE;
00162  * }
00163  *
00164  * void main() {
00165  *     // Other init code
00166  *     ENABLE_SUDAV();
00167  *     EA=1; // Enable interrupts
00168  *
00169  *     while(TRUE) {
00170  *         if(dosud) { // Check flag
00171  *             handle_setupdata();
00172  *             dosud=FALSE;
00173  *         }
00174  *         // Other loop code
00175  *     }
00176  * }
00177  * \endcode
00178  */
00179 void handle_setupdata();
00180 
00181 
00218 void handle_hispeed( BOOL highspeed );
00219 
00220 /* Descriptor header */
00221 typedef struct {
00222     BYTE dsc_len;
00223     BYTE dsc_type;
00224 } HEADER_DSCR;
00225 
00226 /* descriptor types */
00227 #define DSCR_DEVICE_TYPE 1
00228 #define DSCR_CONFIG_TYPE 2
00229 #define DSCR_STRING_TYPE 3
00230 #define DSCR_DEVQUAL_TYPE 6
00231 #define DSCR_OTHERSPD_TYPE 7
00232 #define DSCR_DEBUG_TYPE 10
00233 
00234 /* USB version 2.0 */
00235 #define DSCR_BCD 0x0200
00236 
00237 /* Device descriptor */
00238 typedef struct {
00239     BYTE dsc_len; // descriptor length (18 for this )
00240     BYTE dsc_type; // dscr type
00241     WORD bcd; // bcd
00242     BYTE dev_class; // device class
00243     BYTE dev_subclass; // sub class
00244     BYTE dev_protocol; // sub sub class
00245     BYTE max_pkt; // max packet size
00246     WORD vendor_id;
00247     WORD product_id;
00248     WORD dev_version; // product version id
00249     BYTE idx_manstr; //  manufacturer string index
00250     BYTE idx_devstr; // product string index
00251     BYTE idx_serstr; // serial number index
00252     BYTE num_configs; // number of configurations
00253 } DEVICE_DSCR;
00254 #define DSCR_DEVICE_LEN 18
00255 
00256 /* Config descriptor  */
00257 #define DSCR_CONFIG_LEN 9
00258 #define CONFIG_DSCR DSCR_HEAD
00259 
00260 /* String descriptor */
00261 typedef struct {
00262     BYTE dsc_len;
00263     BYTE dsc_type;
00264     BYTE pstr;
00265 } STRING_DSCR;
00266 
00267 #endif