U2C-11 USB-I2C/SPI/GPIO Interface Adapter

 
Main Page   Modules   Compound List   File List   Compound Members   File Members  

i2cbridge.h

Go to the documentation of this file.
00001 // Copyright (C)2004 Dimax ( http://www.xdimax.com )
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU General Public License for more details.
00011 
00012 #ifndef I2C_BRIDGE_H_10DF0DED_E85F_4f14_88D9_610BEA2211F7
00013 
00014 #define I2C_BRIDGE_H_10DF0DED_E85F_4f14_88D9_610BEA2211F7
00015 
00016 #ifdef __linux__
00017 /*
00018 * Compatibility stuff
00019 */
00020 #include <sys/types.h>
00021 typedef int         BOOL;        
00022 #define TRUE 1
00023 #define FALSE 0
00024 typedef u_int8_t    BYTE;
00025 typedef u_int8_t    UCHAR;
00026 typedef u_int16_t   WORD; 
00027 typedef u_int32_t   DWORD; 
00028 typedef u_int32_t   ULONG; 
00029 typedef void*       HANDLE;
00030 #define _stdcall        /* nothing */
00031 #define INVALID_HANDLE_VALUE ((HANDLE)(-1))
00032 #endif
00033 
00034 #pragma pack(push, 1)
00035 
00036 typedef enum
00037 {
00038         U2C_SUCCESS,                              
00039         U2C_BAD_PARAMETER,                      
00040         U2C_HARDWARE_NOT_FOUND,                 
00041         U2C_SLAVE_DEVICE_NOT_FOUND,             
00042         U2C_TRANSACTION_FAILED,                 
00043         U2C_SLAVE_OPENNING_FOR_WRITE_FAILED,    
00044         U2C_SLAVE_OPENNING_FOR_READ_FAILED,     
00045         U2C_SENDING_MEMORY_ADDRESS_FAILED,      
00046         U2C_SENDING_DATA_FAILED,                
00047         U2C_NOT_IMPLEMENTED,                    
00048         U2C_NO_ACK,                             
00049         U2C_DEVICE_BUSY,                        
00050         U2C_MEMORY_ERROR,                       
00051         U2C_UNKNOWN_ERROR,                      
00052 } U2C_RESULT;
00053 
00054 
00060 typedef struct _U2C_TRANSACTION
00061 {
00062         BYTE nSlaveDeviceAddress;   
00063         BYTE nMemoryAddressLength;  
00064         DWORD nMemoryAddress;       
00065         WORD nBufferLength;         
00066         BYTE Buffer[256];           
00067 } U2C_TRANSACTION, *PU2C_TRANSACTION;
00068  
00072 typedef struct _U2C_TRANSACTION_PACK
00073 {
00074     BOOL rw;                    
00075     U2C_TRANSACTION tr;         
00076     int rc;                      
00077 } U2C_TRANSACTION_PACK, *PU2C_TRANSACTION_PACK;
00078 
00079 // I2C bus frequency values:
00080 #define U2C_I2C_FREQ_FAST   0
00081 #define U2C_I2C_FREQ_STD    1
00082 #define U2C_I2C_FREQ_83KHZ  2
00083 #define U2C_I2C_FREQ_71KHZ  3
00084 #define U2C_I2C_FREQ_62KHZ  4
00085 #define U2C_I2C_FREQ_50KHZ  6
00086 #define U2C_I2C_FREQ_25KHZ  16
00087 #define U2C_I2C_FREQ_10KHZ  46
00088 #define U2C_I2C_FREQ_5KHZ   96
00089 #define U2C_I2C_FREQ_2KHZ   242
00090 
00091 
00092 // SPI bus frequency values:
00093 #define U2C_SPI_FREQ_200KHZ  0
00094 #define U2C_SPI_FREQ_100KHZ  1
00095 #define U2C_SPI_FREQ_83KHZ  2
00096 #define U2C_SPI_FREQ_71KHZ  3
00097 #define U2C_SPI_FREQ_62KHZ  4
00098 #define U2C_SPI_FREQ_50KHZ  6
00099 #define U2C_SPI_FREQ_25KHZ  16
00100 #define U2C_SPI_FREQ_10KHZ  46
00101 #define U2C_SPI_FREQ_5KHZ   96
00102 #define U2C_SPI_FREQ_2KHZ   242
00103 
00104 
00105 
00106 typedef struct _U2C_SLAVE_ADDR_LIST
00107 {
00108         BYTE nDeviceNumber;
00109         BYTE List[256];
00110 } U2C_SLAVE_ADDR_LIST, *PU2C_SLAVE_ADDR_LIST;
00111 
00112 typedef struct _U2C_VERSION_INFO
00113 {
00114         WORD MajorVersion;
00115         WORD MinorVersion;
00116 } U2C_VERSION_INFO, *PU2C_VERSION_INFO;
00117 
00118 typedef enum 
00119 {
00120         LS_RELEASED,
00121         LS_DROPPED_BY_I2C_BRIDGE,
00122         LS_DROPPED_BY_SLAVE,
00123         LS_RAISED_BY_I2C_BRIDGE,
00124 } U2C_LINE_STATE;
00125 
00126 
00127 #pragma pack(pop)
00128 // I2CBridge Board Initialization Routines
00129 BYTE _stdcall U2C_GetDeviceCount();
00130 U2C_RESULT _stdcall U2C_GetSerialNum(HANDLE hDevice, long* pSerialNum); 
00131 U2C_RESULT _stdcall U2C_IsHandleValid(HANDLE hDevice); 
00132 HANDLE _stdcall U2C_OpenDevice(BYTE nDevice);
00133 HANDLE _stdcall U2C_OpenDeviceBySerialNum(long nSerialNum); 
00134 U2C_RESULT _stdcall U2C_CloseDevice(HANDLE hDevice);
00135 U2C_RESULT _stdcall U2C_GetFirmwareVersion(HANDLE hDevice, PU2C_VERSION_INFO pVersion);
00136 U2C_RESULT _stdcall U2C_GetDriverVersion(HANDLE hDevice, PU2C_VERSION_INFO pVersion);
00137 U2C_VERSION_INFO _stdcall U2C_GetDllVersion(); 
00138 
00139 // I2C high level and configuration routines
00140 U2C_RESULT _stdcall U2C_SetI2cFreq(HANDLE hDevice, BYTE Frequency);
00141 U2C_RESULT _stdcall U2C_GetI2cFreq(HANDLE hDevice, BYTE *pFrequency);
00142 U2C_RESULT _stdcall U2C_Read(HANDLE hDevice, PU2C_TRANSACTION pTransaction);
00143 U2C_RESULT _stdcall U2C_Write(HANDLE hDevice, PU2C_TRANSACTION pTransaction);
00144 U2C_RESULT _stdcall U2C_RW_Pack(HANDLE hDevice, PU2C_TRANSACTION_PACK pTransaction, int count);
00145 U2C_RESULT _stdcall U2C_ScanDevices(HANDLE hDevice, PU2C_SLAVE_ADDR_LIST pList);
00146 
00147 // I2C low level routines
00148 U2C_RESULT _stdcall U2C_Start(HANDLE hDevice);
00149 U2C_RESULT _stdcall U2C_RepeatedStart(HANDLE hDevice);
00150 U2C_RESULT _stdcall U2C_Stop(HANDLE hDevice);
00151 U2C_RESULT _stdcall U2C_PutByte(HANDLE hDevice, BYTE Data);
00152 U2C_RESULT _stdcall U2C_GetByte(HANDLE hDevice, BYTE *pData);
00153 U2C_RESULT _stdcall U2C_PutByteWithAck(HANDLE hDevice, BYTE Data);
00154 U2C_RESULT _stdcall U2C_GetByteWithAck(HANDLE hDevice, BYTE *pData, BOOL bAck);
00155 U2C_RESULT _stdcall U2C_PutAck(HANDLE hDevice, BOOL bAck);
00156 U2C_RESULT _stdcall U2C_GetAck(HANDLE hDevice);
00157 
00158 // I2c wire level routines
00159 U2C_RESULT _stdcall U2C_ReadScl(HANDLE hDevice, U2C_LINE_STATE *pState);
00160 U2C_RESULT _stdcall U2C_ReadSda(HANDLE hDevice, U2C_LINE_STATE *pState);
00161 U2C_RESULT _stdcall U2C_ReleaseScl(HANDLE hDevice);
00162 U2C_RESULT _stdcall U2C_ReleaseSda(HANDLE hDevice);
00163 U2C_RESULT _stdcall U2C_DropScl(HANDLE hDevice);
00164 U2C_RESULT _stdcall U2C_DropSda(HANDLE hDevice);
00165 
00166 // GPIO routines
00167 U2C_RESULT _stdcall U2C_SetIoDirection(HANDLE hDevice, ULONG Value, ULONG Mask);
00168 U2C_RESULT _stdcall U2C_GetIoDirection(HANDLE hDevice, ULONG *pValue);
00169 U2C_RESULT _stdcall U2C_IoWrite(HANDLE hDevice, ULONG Value, ULONG Mask);
00170 U2C_RESULT _stdcall U2C_IoRead(HANDLE hDevice, ULONG *pValue);
00171 U2C_RESULT _stdcall U2C_SetSingleIoDirection(HANDLE hDevice, ULONG IoNumber, BOOL bOutput);
00172 U2C_RESULT _stdcall U2C_GetSingleIoDirection(HANDLE hDevice, ULONG IoNumber, BOOL *pbOutput);
00173 U2C_RESULT _stdcall U2C_SingleIoWrite(HANDLE hDevice, ULONG IoNumber, BOOL Value);
00174 U2C_RESULT _stdcall U2C_SingleIoRead(HANDLE hDevice, ULONG IoNumber, BOOL *pValue);
00175 
00176 // SPI configuration routines
00177 U2C_RESULT _stdcall U2C_SpiSetConfig(HANDLE hDevice, BYTE CPOL, BYTE CPHA);
00178 U2C_RESULT _stdcall U2C_SpiGetConfig(HANDLE hDevice, BYTE *pCPOL, BYTE *pCPHA);
00179 U2C_RESULT _stdcall U2C_SpiSetFreq(HANDLE hDevice, BYTE Frequency);
00180 U2C_RESULT _stdcall U2C_SpiGetFreq(HANDLE hDevice, BYTE *pFrequency);
00181 U2C_RESULT _stdcall U2C_SpiReadWrite(HANDLE hDevice, BYTE *pOutBuffer, BYTE *pInBuffer, WORD Length);
00182 U2C_RESULT _stdcall U2C_SpiWrite(HANDLE hDevice, BYTE *pOutBuffer, WORD Length);
00183 U2C_RESULT _stdcall U2C_SpiRead(HANDLE hDevice, BYTE *pInBuffer, WORD Length);
00184 
00185 #endif //I2C_BRIDGE_H_10DF0DED_E85F_4f14_88D9_610BEA2211F7
Copyright DiMAX 2002-2004