//-----------------------------------------------------------------------------
// File: FX2.h
// Contents: EZ-USB FX2/FX2LP/FX1 constants, macros, datatypes, globals, and library
// function prototypes.
//-----------------------------------------------------------------------------
#ifndef FX2_H //Header sentry
#define FX2_H
#ifdef __SDCC
# define code __code
# define data __data
# define xdata __xdata
# define idata __idata
# define pdata __pdata
# define bit __bit
# define interrupt __interrupt
#endif
//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
#define TRUE 1
#define FALSE 0
#define bmBIT7 0x80
/*-----------------------------------------------------------------------------
Macros
-----------------------------------------------------------------------------*/
#define MSB(word) (BYTE)(((WORD)(word) >> 8) & 0xff)
#define LSB(word) (BYTE)((WORD)(word) & 0xff)
#define SWAP_ENDIAN(word) ((BYTE*)&word)[0] ^= ((BYTE*)&word)[1];\
((BYTE*)&word)[1] ^= ((BYTE*)&word)[0];\
((BYTE*)&word)[0] ^= ((BYTE*)&word)[1]
#define EZUSB_IRQ_ENABLE() EUSB = 1
#define EZUSB_IRQ_DISABLE() EUSB = 0
#define EZUSB_IRQ_CLEAR() EXIF &= ~0x10 // IE2_
#define EZUSB_STALL_EP0() EP0CS |= bmEPSTALL
// WRITEDELAY() has been replaced by SYNCDELAY; macro in fx2sdly.h
// ...it is here for backwards compatibility...
// the WRITEDELAY macro compiles to the time equivalent of 3 NOPs.
// It is used in the frameworks to allow for write recovery time
// requirements of certain registers. This is only necessary for
// EZ-USB FX parts. See the EZ-USB FX TRM for
// more information on write recovery time issues.
#define SYNCDELAY {char writedelaydummy = 0;}
// if this firmware will never run on an EZ-USB FX part replace
// with:
// #define WRITEDELAY()
// macro to reset and endpoint data toggle
#define EZUSB_RESET_DATA_TOGGLE(ep) TOGCTL = (((ep & 0x80) >> 3) + (ep & 0x0F));\
TOGCTL |= bmRESETTOGGLE
#define EZUSB_ENABLE_RSMIRQ() (EICON |= 0x20) // Enable Resume Interrupt (EPFI_)
#define EZUSB_DISABLE_RSMIRQ() (EICON &= ~0x20) // Disable Resume Interrupt (EPFI_)
#define EZUSB_CLEAR_RSMIRQ() (EICON &= ~0x10) // Clear Resume Interrupt Flag (PFI_)
#define EZUSB_GETI2CSTATUS() (I2CPckt.status)
#define EZUSB_CLEARI2CSTATUS() if((I2CPckt.status == I2C_BERROR) || (I2CPckt.status == I2C_NACK))\
I2CPckt.status = I2C_IDLE;
#define EZUSB_ENABLEBP() (BREAKPT |= bmBPEN)
#define EZUSB_DISABLEBP() (BREAKPT &= ~bmBPEN)
#define EZUSB_CLEARBP() (BREAKPT |= bmBREAK)
#define EZUSB_BP(addr) BPADDRH = (BYTE)(((WORD)addr >> 8) & 0xff);\
BPADDRL = (BYTE)addr
#define EZUSB_EXTWAKEUP() (((WAKEUPCS & bmWU2) && (WAKEUPCS & bmWU2EN)) ||\
((WAKEUPCS & bmWU) && (WAKEUPCS & bmWUEN)))
#define EZUSB_HIGHSPEED() (USBCS & bmHSM)
//-----------------------------------------------------------------------------
// Datatypes
//-----------------------------------------------------------------------------
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
typedef bit BOOL;
#define INT0_VECT 0
#define TMR0_VECT 1
#define INT1_VECT 2
#define TMR1_VECT 3
#define COM0_VECT 4
#define TMR2_VECT 5
#define WKUP_VECT 6
#define COM1_VECT 7
#define USB_VECT 8
#define I2C_VECT 9
#define INT4_VECT 10
#define INT5_VECT 11
#define INT6_VECT 12
#if 0
typedef struct
{
BYTE length;
BYTE type;
}DSCR;
typedef struct // Device Descriptor
{
BYTE length; // Descriptor length ( = sizeof(DEVICEDSCR) )
BYTE type; // Decriptor type (Device = 1)
BYTE spec_ver_minor; // Specification Version (BCD) minor
BYTE spec_ver_major; // Specification Version (BCD) major
BYTE dev_class; // Device class
BYTE sub_class; // Device sub-class
BYTE protocol; // Device sub-sub-class
BYTE max_packet; // Maximum packet size
BYTE vidL,vidH; // Vendor ID
BYTE pidL,pidH; // Product ID
BYTE verL,verH; // Product version ID
BYTE mfg_str; // Manufacturer string index
BYTE prod_str; // Product string index
BYTE serialnum_str; // Serial number string index
BYTE configs; // Number of configurations
}DEVICEDSCR;
typedef struct // Device Qualifier Descriptor
{
BYTE length; // Descriptor length ( = sizeof(DEVICEQUALDSCR) )
BYTE type; // Decriptor type (Device Qualifier = 6)
BYTE verL; // Specification Version (BCD) minor
BYTE verH; // Specification Version (BCD) major
BYTE dev_class; // Device class
BYTE sub_class; // Device sub-class
BYTE protocol; // Device sub-sub-class
BYTE max_packet; // Maximum packet size
BYTE configs; // Number of configurations
BYTE reserved0;
}DEVICEQUALDSCR;
#endif
typedef struct
{
BYTE length; // Configuration length ( = sizeof(CONFIGDSCR) )
BYTE type; // Descriptor type (Configuration = 2)
BYTE config_lenL; // Configuration + End Points length
BYTE config_lenH;
BYTE interfaces; // Number of interfaces
BYTE index; // Configuration number
BYTE config_str; // Configuration string
BYTE attrib; // Attributes (b7 - buspwr, b6 - selfpwr, b5 - rwu
BYTE power; // Power requirement (div 2 ma)
}CONFIGDSCR;
#if 0
typedef struct
{
BYTE length; // Interface descriptor length ( - sizeof(INTRFCDSCR) )
BYTE type; // Descriptor type (Interface = 4)
BYTE index; // Zero-based index of this interface
BYTE alt_setting; // Alternate setting
BYTE ep_cnt; // Number of end points
BYTE class; // Interface class
BYTE sub_class; // Interface sub class
BYTE protocol; // Interface sub sub class
BYTE interface_str; // Interface descriptor string index
}INTRFCDSCR;
typedef struct
{
BYTE length; // End point descriptor length ( = sizeof(ENDPNTDSCR) )
BYTE type; // Descriptor type (End point = 5)
BYTE addr; // End point address
BYTE ep_type; // End point type
BYTE mp_L; // Maximum packet size
BYTE mp_H;
BYTE interval; // Interrupt polling interval
}ENDPNTDSCR;
typedef struct
{
BYTE length; // String descriptor length
BYTE type; // Descriptor type
}STRINGDSCR;
typedef struct
{
BYTE cntrl; // End point control register
BYTE bytes; // End point buffer byte count
}EPIOC;
#endif
typedef struct
{
BYTE length;
BYTE *dat;
BYTE count;
BYTE status;
}I2CPCKT;
//-----------------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------------
extern code BYTE USB_AutoVector;
//extern WORD pDeviceDscr;
//extern WORD pDeviceQualDscr;
//extern WORD pHighSpeedConfigDscr;
//extern WORD pFullSpeedConfigDscr;
//extern WORD pConfigDscr;
//extern WORD pOtherConfigDscr;
//extern WORD pStringDscr;
//extern code BYTE DeviceQualDscr[];
//extern code CONFIGDSCR HighSpeedConfigDscr;
//extern code BYTE FullSpeedConfigDscr[];
//extern code BYTE StringDscr;
//extern code DSCR UserDscr;
extern I2CPCKT I2CPckt;
//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------
extern void EZUSB_Renum(void);
extern void EZUSB_Discon(BOOL renum);
extern void EZUSB_Susp(void);
extern void EZUSB_Resume(void);
extern void EZUSB_Delay1ms(void);
extern void EZUSB_Delay(WORD ms);
//extern CONFIGDSCR xdata* EZUSB_GetConfigDscr(BYTE ConfigIdx);
//extern INTRFCDSCR xdata* EZUSB_GetIntrfcDscr(BYTE ConfigIdx, BYTE IntrfcIdx, BYTE AltSetting);
//extern STRINGDSCR xdata* EZUSB_GetStringDscr(BYTE StrIdx);
//extern DSCR xdata* EZUSB_GetDscr(BYTE index, DSCR* dscr, BYTE type);
extern void EZUSB_InitI2C(void);
extern BOOL EZUSB_WriteI2C_(BYTE addr, BYTE length, BYTE xdata *dat);
extern BOOL EZUSB_ReadI2C_(BYTE addr, BYTE length, BYTE xdata *dat);
extern BOOL EZUSB_WriteI2C(BYTE addr, BYTE length, BYTE xdata *dat);
extern BOOL EZUSB_ReadI2C(BYTE addr, BYTE length, BYTE xdata *dat);
extern void EZUSB_WaitForEEPROMWrite(BYTE addr);
extern void modify_endpoint_stall(BYTE epid, BYTE stall);
#endif // FX2_H
| Detected encoding: ASCII (7 bit) | 2
|