00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __HTSPB_H__
00012 #define __HTSPB_H__
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #pragma systemFile
00041
00042 #ifndef __COMMON_H__
00043 #include "common.h"
00044 #endif
00045
00046 #define HTSPB_I2C_ADDR 0x10
00047 #define HTSPB_OFFSET 0x42
00048 #define HTSPB_A0_U 0x00
00049 #define HTSPB_A0_L 0x01
00050 #define HTSPB_DIGIN 0x0A
00051 #define HTSPB_DIGOUT 0x0B
00052 #define HTSPB_DIGCTRL 0x0C
00053 #define HTSPB_STROBE 0x0E
00054 #define HTSPB_LED 0x0F
00055 #define HTSPB_O0MODE 0x10
00056 #define HTSPB_O0FREQ 0x11
00057 #define HTSPB_O0VOLT 0x13
00058 #define HTSPB_O1MODE 0x15
00059 #define HTSPB_O1FREQ 0x16
00060 #define HTSPB_O1VOLT 0x18
00061
00062 #define HTSPB_DACO0 0x10
00063 #define HTSPB_DACO1 0x15
00064
00065
00066
00067 #define DAC_MODE_DCOUT 0
00068 #define DAC_MODE_SINEWAVE 1
00069 #define DAC_MODE_SQUAREWAVE 2
00070 #define DAC_MODE_SAWPOSWAVE 3
00071 #define DAC_MODE_SAWNEGWAVE 4
00072 #define DAC_MODE_TRIANGLEWAVE 5
00073 #define DAC_MODE_PWMVOLTAGE 6
00074
00075
00076
00077 tByteArray HTSPB_I2CRequest;
00078 tByteArray HTSPB_I2CReply;
00079
00080 ubyte HTSPBreadIO(tSensors link, ubyte mask);
00081 bool HTSPBwriteIO(tSensors link, ubyte mask);
00082 bool HTSPBsetupIO(tSensors link, ubyte mask);
00083 int HTSPBreadADC(tSensors link, byte channel, byte width);
00084 bool HTSPBreadAllADC(tSensors link, int &adch0, int &adch1, int &adch2, int &adch3, int &adch4, byte width);
00085 bool HTSPBsetSamplingTime(tSensors link, byte interval);
00086
00087
00088
00089
00090
00091
00092
00093 ubyte HTSPBreadIO(tSensors link, ubyte mask) {
00094 memset(HTSPB_I2CRequest, 0, sizeof(tByteArray));
00095
00096 HTSPB_I2CRequest[0] = 2;
00097 HTSPB_I2CRequest[1] = HTSPB_I2C_ADDR;
00098 HTSPB_I2CRequest[2] = HTSPB_OFFSET + HTSPB_DIGIN;
00099
00100 if (!writeI2C(link, HTSPB_I2CRequest, HTSPB_I2CReply, 1))
00101 return 0;
00102
00103 return HTSPB_I2CReply[0] & mask;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113 bool HTSPBwriteIO(tSensors link, ubyte mask) {
00114 memset(HTSPB_I2CRequest, 0, sizeof(tByteArray));
00115
00116 HTSPB_I2CRequest[0] = 3;
00117 HTSPB_I2CRequest[1] = HTSPB_I2C_ADDR;
00118 HTSPB_I2CRequest[2] = HTSPB_OFFSET + HTSPB_DIGOUT;
00119 HTSPB_I2CRequest[3] = mask;
00120
00121
00122 return writeI2C(link, HTSPB_I2CRequest);
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 bool HTSPBsetupIO(tSensors link, ubyte mask) {
00133 memset(HTSPB_I2CRequest, 0, sizeof(tByteArray));
00134
00135 HTSPB_I2CRequest[0] = 3;
00136 HTSPB_I2CRequest[1] = HTSPB_I2C_ADDR;
00137 HTSPB_I2CRequest[2] = HTSPB_OFFSET + HTSPB_DIGCTRL;
00138 HTSPB_I2CRequest[3] = mask;
00139
00140 return writeI2C(link, HTSPB_I2CRequest);
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 int HTSPBreadADC(tSensors link, byte channel, byte width) {
00152 memset(HTSPB_I2CRequest, 0, sizeof(tByteArray));
00153
00154 int _adcVal = 0;
00155 HTSPB_I2CRequest[0] = 2;
00156 HTSPB_I2CRequest[1] = HTSPB_I2C_ADDR;
00157 HTSPB_I2CRequest[2] = HTSPB_OFFSET + HTSPB_A0_U + (channel * 2);
00158
00159 if (!writeI2C(link, HTSPB_I2CRequest, HTSPB_I2CReply, 2))
00160 return -1;
00161
00162
00163
00164
00165
00166
00167 if (width == 8)
00168 _adcVal = HTSPB_I2CReply[0];
00169 else
00170 _adcVal = (HTSPB_I2CReply[0] * 4) + HTSPB_I2CReply[1];
00171
00172 return _adcVal;
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 bool HTSPBreadAllADC(tSensors link, int &adch0, int &adch1, int &adch2, int &adch3, byte width) {
00188 memset(HTSPB_I2CRequest, 0, sizeof(tByteArray));
00189
00190 HTSPB_I2CRequest[0] = 2;
00191 HTSPB_I2CRequest[1] = HTSPB_I2C_ADDR;
00192 HTSPB_I2CRequest[2] = HTSPB_OFFSET + HTSPB_A0_U;
00193
00194 if (!writeI2C(link, HTSPB_I2CRequest, HTSPB_I2CReply, 10))
00195 return false;
00196
00197
00198
00199
00200
00201
00202 if (width == 8) {
00203 adch0 = (int)HTSPB_I2CReply[0];
00204 adch1 = (int)HTSPB_I2CReply[2];
00205 adch2 = (int)HTSPB_I2CReply[4];
00206 adch3 = (int)HTSPB_I2CReply[6];
00207 } else {
00208 adch0 = ((int)HTSPB_I2CReply[0] << 2) + (int)HTSPB_I2CReply[1];
00209 adch1 = ((int)HTSPB_I2CReply[2] << 2) + (int)HTSPB_I2CReply[3];
00210 adch2 = ((int)HTSPB_I2CReply[4] << 2) + (int)HTSPB_I2CReply[5];
00211 adch3 = ((int)HTSPB_I2CReply[6] << 2) + (int)HTSPB_I2CReply[7];
00212 }
00213 return true;
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 bool HTSPBwriteAnalog(tSensors link, byte dac, byte mode, int freq, int volt) {
00228 memset(HTSPB_I2CRequest, 0, sizeof(tByteArray));
00229
00230 HTSPB_I2CRequest[0] = 7;
00231 HTSPB_I2CRequest[1] = HTSPB_I2C_ADDR;
00232 HTSPB_I2CRequest[2] = HTSPB_OFFSET + dac;
00233 HTSPB_I2CRequest[3] = mode;
00234 HTSPB_I2CRequest[4] = freq/256;
00235 HTSPB_I2CRequest[5] = freq&255;
00236 HTSPB_I2CRequest[6] = volt/4;
00237 HTSPB_I2CRequest[7] = volt&3;
00238
00239 return writeI2C(link, HTSPB_I2CRequest);
00240 }
00241
00242
00243
00244 #endif // __HTSPB_H__
00245
00246
00247
00248
00249
00250