00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SUB_H_INCLUDED
00026 #define SUB_H_INCLUDED
00027
00028 #ifdef __cplusplus
00029 extern "C"{
00030 #endif
00031
00032
00033
00034
00035
00036
00037
00038 #if _MSC_VER == 800
00039 typedef long sub_int32_t;
00040 #else
00041 typedef int sub_int32_t;
00042 #endif
00043
00044 typedef void* sub_device;
00045 typedef void* sub_handle;
00046
00047 struct sub_version
00048 {
00049 struct
00050 {
00051 int major;
00052 int minor;
00053 int micro;
00054 int nano;
00055 }dll;
00056
00057 struct
00058 {
00059 int major;
00060 int minor;
00061 int micro;
00062 int nano;
00063 }driver;
00064
00065 struct
00066 {
00067 int micro;
00068 int minor;
00069 int major;
00070 int boot;
00071 }sub_device;
00072 };
00073
00074 struct sub_cfg_vpd
00075 {
00076 int lcd_w;
00077 int lcd_h;
00078 int serial;
00079 int buttons;
00080 int ir_car;
00081 };
00082
00083 union sub_mdio_frame
00084 {
00085 struct
00086 {
00087 int op;
00088 int phyad;
00089 int regad;
00090 int data;
00091 }clause22;
00092 struct
00093 {
00094 int op;
00095 int prtad;
00096 int devad;
00097 int data;
00098 }clause45;
00099 };
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 #define SUB_ERRORS \
00111 DEF_SUB_ERROR( SE_OK, 0, "OK" )\
00112 DEF_SUB_ERROR( SE_NODEV, 1, "SUB Device not found" )\
00113 DEF_SUB_ERROR( SE_OPEN, 2, "Can't open SUB device" )\
00114 DEF_SUB_ERROR( SE_SETCONF, 3, "Can't set configuration" )\
00115 DEF_SUB_ERROR( SE_CLAIM, 4, "Can't claim interface" )\
00116 DEF_SUB_ERROR( SE_SETA, 5, "Failed to setup async transaction" )\
00117 DEF_SUB_ERROR( SE_SUBMIT, 6, "Failed to submit async transaction" )\
00118 DEF_SUB_ERROR( SE_BULKOUT, 7, "Bulk write failed" )\
00119 DEF_SUB_ERROR( SE_BULKIN_RC, 8, "Bulk read failed" )\
00120 DEF_SUB_ERROR( SE_BULKIN_SZ, 9, "Bulk read incomplete" )\
00121 DEF_SUB_ERROR( SE_OUT_OVF, 10, "Out buffer overflow" )\
00122 DEF_SUB_ERROR( SE_I2C, 11, "I2C error" )\
00123 DEF_SUB_ERROR( SE_TAG_CODE, 12, "Wrong tag code in response" )\
00124 DEF_SUB_ERROR( SE_TAG_SIZE, 13, "Wrong tag size in response" )\
00125 DEF_SUB_ERROR( SE_PARAM, 14, "Wrong parameters" )\
00126 DEF_SUB_ERROR( SE_SPI_DIS, 15, "SPI Disabled" )\
00127 DEF_SUB_ERROR( SE_NSUPPORTED, 16, "Feature not supported" )\
00128 DEF_SUB_ERROR( SE_TIMEOUT, 17, "Timeout" )\
00129 DEF_SUB_ERROR( SE_INIT, 18, "Init Failed" )\
00130 DEF_SUB_ERROR( SE_BAD_HNDL, 19, "Bad Handle" )\
00131 DEF_SUB_ERROR( SE_IR, 20, "InfraRed Failure" )
00132
00133 #define DEF_SUB_ERROR(NAME,VAL,DESCR) NAME=VAL,
00134 enum { SUB_ERRORS SUB_LASTERROR };
00135
00136 #ifndef ETIMEDOUT
00137 #define ETIMEDOUT 116
00138 #endif
00139
00140
00141
00142
00143
00144
00145
00146 #ifdef __SUB_STATIC__
00147 #define __SUB_DECL__ extern
00148 #else
00149 #if defined(_MSC_VER) && _MSC_VER > 800
00150 #ifdef __LIBSUB_C__
00151 #define __SUB_DECL__ extern
00152 #else
00153 #define __SUB_DECL__ _declspec( dllimport )
00154 #endif
00155 #elif defined(__CYGWIN__)
00156
00157 #define __SUB_DECL__ __declspec( dllimport )
00158 #else
00159
00160 #define __SUB_DECL__ extern
00161 #endif
00162 #endif
00163
00164 __SUB_DECL__ int sub_errno, sub_i2c_status;
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 #define I2C_GCE 0x01
00176
00177
00178 #define BB_I2C_FAST_P 0x00
00179 #define BB_I2C_FAST 0x01
00180 #define BB_I2C_STD 0x03
00181
00182
00183
00184
00185 #define SPI_ENABLE 0x40
00186
00187
00188 #define SPI_CPOL_RISE 0x00
00189 #define SPI_CPOL_FALL 0x08
00190
00191
00192 #define SPI_SMPL_SETUP 0x00
00193 #define SPI_SETUP_SMPL 0x04
00194
00195
00196 #define SPI_SLAVE 0x10
00197
00198
00199 #define SPI_LSB_FIRST 0x20
00200 #define SPI_MSB_FIRST 0x00
00201
00202
00203 #define SPI_CLK_8MHZ 0x80
00204 #define SPI_CLK_4MHZ 0x00
00205 #define SPI_CLK_2MHZ 0x81
00206 #define SPI_CLK_1MHZ 0x01
00207 #define SPI_CLK_500KHZ 0x82
00208 #define SPI_CLK_250KHZ 0x02
00209 #define SPI_CLK_125KHZ 0x03
00210
00211
00212 #define SS_CONF(SS_N,SS_MODE) ((SS_N)<<4)|((SS_MODE)&0x0F)
00213 #define SS_H 0x0F
00214 #define SS_HL 0x09
00215 #define SS_HHL 0x0A
00216 #define SS_HHHL 0x0B
00217 #define SS_HHHHL 0x0C
00218 #define SS_HI 0x0D
00219 #define SS_L 0x07
00220 #define SS_LH 0x01
00221 #define SS_LLH 0x02
00222 #define SS_LLLH 0x03
00223 #define SS_LLLLH 0x04
00224 #define SS_LO 0x05
00225 #define SS_HiZ 0x08
00226
00227
00228
00229
00230 #define SUB_MDIO22 0x80
00231 #define SUB_MDIO22_READ (0x02|SUB_MDIO22)
00232 #define SUB_MDIO22_WRITE (0x01|SUB_MDIO22)
00233 #define SUB_MDIO45_ADDR 0x00
00234 #define SUB_MDIO45_WRITE 0x01
00235 #define SUB_MDIO45_PRIA 0x02
00236 #define SUB_MDIO45_READ 0x03
00237
00238
00239
00240
00241 #define FPWM_ENABLE 0x0001
00242 #define FPWM_EN0 0x8000
00243 #define FPWM_EN1 0x2000
00244 #define FPWM_EN2 0x0800
00245
00246
00247
00248
00249 #define ADC_ENABLE 0x8000
00250 #define ADC_REF_VCC 0x0040
00251 #define ADC_REF_2_56 0x00C0
00252
00253 enum
00254 {
00255
00256 ADC_S0, ADC_S1, ADC_S2, ADC_S3,
00257 ADC_S4, ADC_S5, ADC_S6, ADC_S7,
00258
00259 ADC_D10_10X = 9,
00260 ADC_D10_200X= 11,
00261 ADC_D32_10X = 13,
00262 ADC_D32_200X= 15,
00263 ADC_D01 = 16,
00264 ADC_D21 = 18,
00265 ADC_D31 = 19,
00266 ADC_D41 = 20,
00267 ADC_D51 = 21,
00268 ADC_D61 = 22,
00269 ADC_D71 = 23,
00270 ADC_D02 = 24,
00271 ADC_D12 = 25,
00272 ADC_D32 = 27,
00273 ADC_D42 = 28,
00274 ADC_D52 = 29,
00275 ADC_1_1V = 30,
00276 ADC_GND = 31,
00277 };
00278
00279
00280
00281
00282
00283 #define RS_RX_ENABLE 0x80
00284 #define RS_TX_ENABLE 0x40
00285
00286
00287 #define RS_CHAR_5 0x00
00288 #define RS_CHAR_6 0x02
00289 #define RS_CHAR_7 0x04
00290 #define RS_CHAR_8 0x06
00291 #define RS_CHAR_9 0x07
00292
00293
00294 #define RS_PARITY_NONE 0x00
00295 #define RS_PARITY_EVEN 0x20
00296 #define RS_PARITY_ODD 0x30
00297
00298
00299 #define RS_STOP_1 0x00
00300 #define RS_STOP_2 0x08
00301
00302
00303 #define RS_RX_BEFORE_TX 0x01
00304 #define RS_RX_AFTER_TX 0x02
00305
00306
00307 #define IR_UART_MODE 0x00
00308 #define IR_ROW_MODE 0x01
00309
00310
00311
00312
00313 #define FIFO_SELECT_SPI 0x01
00314 #define FIFO_SELECT_UART 0x02
00315 #define FIFO_SELECT_I2C 0x10
00316 #define FIFO_CLEAR 0x100
00317 #define FIFO_READ_FULL 0x200
00318
00319
00320
00321
00322
00323
00324
00325 #define SUB_BOOT_MODE 0
00326 int sub_get_mode( sub_handle hndl, int *boot );
00327
00328
00329 int sub_set_debug_level( int level );
00330
00331 sub_device sub_find_devices( sub_device first );
00332 sub_handle sub_open( sub_device dev );
00333 int sub_close( sub_handle hndl );
00334 const struct sub_version* sub_get_version( sub_handle hndl );
00335 const struct sub_cfg_vpd* sub_get_cfg_vpd( sub_handle hndl );
00336
00337
00338 int sub_i2c_freq( sub_handle hndl, sub_int32_t *freq );
00339 int sub_i2c_config( sub_handle hndl, int sa, int flags );
00340 int sub_i2c_start( sub_handle hndl );
00341 int sub_i2c_stop( sub_handle hndl );
00342 int sub_i2c_scan( sub_handle hndl, int* slave_cnt, char* slave_buf );
00343 int sub_i2c_read( sub_handle hndl, int sa, sub_int32_t ma, int ma_sz, char* buf, int sz );
00344 int sub_i2c_write( sub_handle hndl, int sa, sub_int32_t ma, int ma_sz, char* buf, int sz );
00345
00346
00347 int sub_spi_config( sub_handle hndl, int cfg_set, int* cfg_get );
00348 int sub_spi_transfer( sub_handle hndl, char* out_buf, char* in_buf, int sz, int ss_config );
00349 int sub_sdio_transfer( sub_handle hndl, char* out_buf, char* in_buf, int out_sz, int in_sz, int ss_config );
00350
00351
00352 int sub_mdio22( sub_handle hndl, int op, int phyad, int regad, int data, int* content );
00353 int sub_mdio45( sub_handle hndl, int op, int prtad, int devad, int data, int* content );
00354 int sub_mdio_xfer( sub_handle hndl, int count, union sub_mdio_frame* mdios );
00355 int sub_mdio_xfer_ex( sub_handle hndl, int channel, int count, union sub_mdio_frame* mdios );
00356
00357
00358 int sub_gpio_config( sub_handle hndl, sub_int32_t set, sub_int32_t* get, sub_int32_t mask );
00359 int sub_gpio_read( sub_handle hndl, sub_int32_t* get );
00360 int sub_gpio_write( sub_handle hndl, sub_int32_t set, sub_int32_t* get, sub_int32_t mask );
00361
00362 int sub_gpiob_config( sub_handle hndl, sub_int32_t set, sub_int32_t* get, sub_int32_t mask );
00363 int sub_gpiob_read( sub_handle hndl, sub_int32_t* get );
00364 int sub_gpiob_write( sub_handle hndl, sub_int32_t set, sub_int32_t* get, sub_int32_t mask );
00365
00366
00367 int sub_fpwm_config( sub_handle hndl, double freq_hz, int flags );
00368 int sub_fpwm_set( sub_handle hndl, int pwm_n, double duty );
00369
00370
00371 int sub_pwm_config( sub_handle hndl, int res_us, int limit );
00372 int sub_pwm_set( sub_handle hndl, int pwm_n, int duty );
00373
00374
00375
00376 int sub_adc_config( sub_handle hndl, int flags );
00377 int sub_adc_single( sub_handle hndl, int* data, int mux );
00378 int sub_adc_read( sub_handle hndl, int* data, int* mux, int reads );
00379
00380
00381 int sub_lcd_write( sub_handle hndl, char* str );
00382
00383
00384 int sub_rs_set_config( sub_handle hndl, int config, sub_int32_t baud );
00385 int sub_rs_get_config( sub_handle hndl, int* config, sub_int32_t* baud );
00386 int sub_rs_timing( sub_handle hndl,
00387 int flags, int tx_space_us, int rx_msg_us, int rx_byte_us );
00388 int sub_rs_xfer( sub_handle hndl,
00389 char* tx_buf, int tx_sz, char* rx_buf, int rx_sz );
00390
00391
00392 int sub_bb_i2c_config( sub_handle hndl, int mode, int stretch_ms );
00393 int sub_bb_i2c_scan( sub_handle hndl, int channel,
00394 int* slave_cnt, char* slave_buf );
00395 int sub_bb_i2c_read( sub_handle hndl, int channel, int sa,
00396 sub_int32_t ma, int ma_sz, char* buf, int sz );
00397 int sub_bb_i2c_write( sub_handle hndl, int channel, int sa,
00398 sub_int32_t ma, int ma_sz, char* buf, int sz );
00399
00400
00401 int sub_ir_config( sub_handle hndl, int carrier, int duty, int mode, ... );
00402 int sub_ir_tx( sub_handle hndl, int sz, char* buf );
00403
00404
00405 int sub_fifo_write( sub_handle hndl, char* buf, int sz, int to_ms );
00406 int sub_fifo_read( sub_handle hndl, char* buf, int sz, int to_ms );
00407 int sub_fifo_config( sub_handle hndl, int config );
00408
00409
00410 int usb_transaction( sub_handle hndl,
00411 char* out_buf, int out_sz,
00412 char* in_buf, int in_sz,
00413 int timeout );
00414
00415
00416 int sub_control_request( sub_handle hndl,
00417 int type, int request, int value, int index,
00418 char* buf, int sz, int timeout
00419 );
00420 int sub_get_serial_number( sub_handle hndl, char *buf, int sz);
00421 int sub_get_product_id( sub_handle hndl, char *buf, int sz);
00422
00423
00424 char* sub_strerror( int errnum );
00425 int sub_get_errno( void ) ;
00426 int sub_get_i2c_status( void ) ;
00427
00428
00429 #ifdef __cplusplus
00430 }
00431 #endif
00432
00433 #endif
00434