si114x_functions.h

Go to the documentation of this file.
00001 /*************************************************************************/
00028 #ifndef SI114X_FUNCTIONS_H
00029 #define SI114X_FUNCTIONS_H
00030 
00031 /***************************************************************************/
00036 /***************************************************************************/
00041 #include "si114x_types.h"
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 /*******************************************************************************
00048  *******************************   STRUCTS   ***********************************
00049  ******************************************************************************/
00050 
00051 /***************************************************************************/
00054 typedef struct 
00055 {
00056     uint32_t    vispd_correction;  
00057     uint32_t    irpd_correction;   
00058     uint32_t    adcrange_ratio;    
00059     uint32_t    irsize_ratio;      
00060     uint32_t    ledi_ratio;        
00061     uint8_t*    ucoef_p;           
00062 } SI114X_CAL_S;
00063 
00064 /*******************************************************************************
00065  ***************   Functions Needed by Si114x_functions.c   ********************
00066  ******************************************************************************/
00067 
00068 int16_t Si114xWriteToRegister(HANDLE si114x_handle, 
00069                               uint8_t address, 
00070                               uint8_t value);
00071 int16_t Si114xReadFromRegister(HANDLE si114x_handle, uint8_t address);
00072 int16_t Si114xBlockWrite(HANDLE si114x_handle, 
00073                          uint8_t  address, 
00074                          uint8_t  length, 
00075                          uint8_t* values);
00076 int16_t Si114xBlockRead(HANDLE si114x_handle, 
00077                         uint8_t  address, 
00078                         uint8_t  length, 
00079                         uint8_t* values);
00080 void delay_10ms(void);
00081 
00082 void delay_1ms(void);
00083 
00084 /*******************************************************************************
00085  ***************   Functions supplied by Si114x_functions.c   ******************
00086  ******************************************************************************/
00087 
00088 int16_t  Si114xReset(HANDLE si114x_handle);
00089 int16_t  Si114xPauseAll(HANDLE si114x_handle);
00090 int16_t  Si114xNop(HANDLE si114x_handle);
00091 int16_t  Si114xPsForce(HANDLE si114x_handle);
00092 int16_t  Si114xAlsForce(HANDLE si114x_handle);
00093 int16_t  Si114xPsAlsForce(HANDLE si114x_handle);
00094 int16_t  Si114xPsAlsAuto(HANDLE si114x_handle);
00095 int16_t  Si114xParamSet(HANDLE si114x_handle, uint8_t address, uint8_t value);
00096 int16_t  Si114xParamRead(HANDLE si114x_handle, uint8_t address);
00097 uint8_t  Compress(uint16_t input);
00098 uint16_t Uncompress(uint8_t input);
00099 int16_t  si114x_get_calibration(HANDLE si114x_handle,
00100                                 SI114X_CAL_S* si114x_cal,
00101                                 uint8_t security);
00102 int16_t si114x_set_ucoef(HANDLE si114x_handle,
00103                          uint8_t* input_ucoef,
00104                          SI114X_CAL_S* si114x_cal );
00105 
00106 /*******************************************************************************
00107  ************************** Si114x I2C Registers *******************************
00108  ******************************************************************************/
00110 #define REG_PART_ID               0x00
00111 #define REG_REV_ID                0x01
00112 #define REG_SEQ_ID                0x02
00113 #define REG_INT_CFG               0x03
00114 #define REG_IRQ_ENABLE            0x04
00115 #define REG_IRQ_MODE1             0x05
00116 #define REG_IRQ_MODE2             0x06
00117 #define REG_HW_KEY                0x07
00118 #define REG_MEAS_RATE             0x08
00119 #define REG_ALS_RATE              0x09
00120 #define REG_PS_RATE               0x0A
00121 #define REG_ALS_LO_TH_LSB         0x0B
00122 #define REG_ALS_LO_TH_MSB         0x0C
00123 #define REG_ALS_HI_TH_LSB         0x0D
00124 #define REG_ALS_HI_TH_MSB         0x0E
00125 #define REG_PS_LED21              0x0F
00126 #define REG_PS_LED3               0x10
00127 #define REG_PS1_TH_LSB            0x11
00128 #define REG_PS1_TH_MSB            0x12
00129 #define REG_PS2_TH_LSB            0x13
00130 #define REG_PS2_TH_MSB            0x14
00131 #define REG_PS3_TH_LSB            0x15
00132 #define REG_PS3_TH_MSB            0x16
00133 #define REG_PARAM_WR              0x17
00134 #define REG_COMMAND               0x18
00135 #define REG_RESPONSE              0x20
00136 #define REG_IRQ_STATUS            0x21
00137 #define REG_ALS_VIS_DATA0         0x22
00138 #define REG_ALS_VIS_DATA1         0x23
00139 #define REG_ALS_IR_DATA0          0x24
00140 #define REG_ALS_IR_DATA1          0x25
00141 #define REG_PS1_DATA0             0x26
00142 #define REG_PS1_DATA1             0x27
00143 #define REG_PS2_DATA0             0x28
00144 #define REG_PS2_DATA1             0x29
00145 #define REG_PS3_DATA0             0x2A
00146 #define REG_PS3_DATA1             0x2B
00147 #define REG_AUX_DATA0             0x2C
00148 #define REG_AUX_DATA1             0x2D
00149 #define REG_PARAM_OUT             0x2E
00150 #define REG_PARAM_RD              0x2E
00151 #define REG_CHIP_STAT             0x30
00152 #define REG_UCOEF0                0x13  
00153 #define REG_UCOEF1                0x14
00154 #define REG_UCOEF2                0x15  
00155 #define REG_UCOEF3                0x16  
00156 #define REG_MEAS_RATE_LSB         0x08
00157 #define REG_MEAS_RATE_MSB         0x09
00158 
00159 
00160 /*******************************************************************************
00161  ************************** Si114x I2C Parameter Offsets ***********************
00162  ******************************************************************************/
00164 #define PARAM_I2C_ADDR            0x00
00165 #define PARAM_CH_LIST             0x01
00166 #define PARAM_PSLED12_SELECT      0x02
00167 #define PARAM_PSLED3_SELECT       0x03
00168 #define PARAM_FILTER_EN           0x04
00169 #define PARAM_PS_ENCODING         0x05
00170 #define PARAM_ALS_ENCODING        0x06
00171 #define PARAM_PS1_ADC_MUX         0x07
00172 #define PARAM_PS2_ADC_MUX         0x08
00173 #define PARAM_PS3_ADC_MUX         0x09
00174 #define PARAM_PS_ADC_COUNTER      0x0A
00175 #define PARAM_PS_ADC_CLKDIV       0x0B
00176 #define PARAM_PS_ADC_GAIN         0x0B
00177 #define PARAM_PS_ADC_MISC         0x0C
00178 #define PARAM_VIS_ADC_MUX         0x0D
00179 #define PARAM_IR_ADC_MUX          0x0E
00180 #define PARAM_AUX_ADC_MUX         0x0F
00181 #define PARAM_ALSVIS_ADC_COUNTER  0x10
00182 #define PARAM_ALSVIS_ADC_CLKDIV   0x11
00183 #define PARAM_ALSVIS_ADC_GAIN     0x11
00184 #define PARAM_ALSVIS_ADC_MISC     0x12
00185 #define PARAM_ALS_HYST            0x16
00186 #define PARAM_PS_HYST             0x17
00187 #define PARAM_PS_HISTORY          0x18
00188 #define PARAM_ALS_HISTORY         0x19
00189 #define PARAM_ADC_OFFSET          0x1A
00190 #define PARAM_SLEEP_CTRL          0x1B
00191 #define PARAM_LED_RECOVERY        0x1C
00192 #define PARAM_ALSIR_ADC_COUNTER   0x1D
00193 #define PARAM_ALSIR_ADC_CLKDIV    0x1E
00194 #define PARAM_ALSIR_ADC_GAIN      0x1E
00195 #define PARAM_ALSIR_ADC_MISC      0x1F
00196 
00197 
00198 /*******************************************************************************
00199  *******    Si114x Register and Parameter Bit Definitions  *********************
00200  ******************************************************************************/
00202 
00203 // REG_IRQ_CFG 
00204 #define  ICG_INTOE                0x01
00205 #define  ICG_INTMODE              0x02
00206 
00207 // REG_IRQ_ENABLE
00208 // REG_IRQ_STATUS
00209 #define IE_NONE                   0x00
00210 
00211 #define IE_ALS_NONE               0x00
00212 #define IE_ALS_EVRYSAMPLE         0x01
00213 #define IE_ALS_EXIT_WIN           0x01
00214 #define IE_ALS_ENTER_WIN          0x02
00215 
00216 #define IE_PS1_NONE               0x00
00217 #define IE_PS1_EVRYSAMPLE         0x04
00218 #define IE_PS1_CROSS_TH           0x04
00219 #define IE_PS1_EXCEED_TH          0x04
00220 #define IE_PS1                    0x04
00221 
00222 #define IE_PS2_NONE               0x00
00223 #define IE_PS2_EVRYSAMPLE         0x08
00224 #define IE_PS2_CROSS_TH           0x08
00225 #define IE_PS2_EXCEEED_TH         0x08
00226 #define IE_PS2                    0x08
00227 
00228 #define IE_PS3_NONE               0x00
00229 #define IE_PS3_EVRYSAMPLE         0x10
00230 #define IE_PS3_CROSS_TH           0x10
00231 #define IE_PS3_EXCEED_TH          0x10
00232 #define IE_PS3                    0x10
00233 
00234 #define IE_CMD                    0x20
00235 
00236 #define IE_ALL                    0x3F
00237 
00238 // REG_IRQ_MODE1
00239 #define IM1_NONE                  0x00
00240 #define IM1_ALS_NONE              0x00
00241 #define IM1_ALS_EVRYSAMPLE        0x00
00242 #define IM1_ALS_VIS_EXIT          0x01
00243 #define IM1_ALS_VIS_ENTER         0x05
00244 #define IM1_ALS_IR_EXIT           0x03
00245 #define IM1_ALS_IR_ENTER          0x06
00246 
00247 #define IM1_PS1_NONE              0x00
00248 #define IM1_PS1_EVRYSAMPLE        (0x0<<4)
00249 #define IM1_PS1_CROSS_TH          (0x1<<4)
00250 #define IM1_PS1_EXCEED_TH         (0x3<<4)
00251 
00252 #define IM1_PS2_NONE              0x00
00253 #define IM1_PS2_EVRYSAMPLE        (0x0<<6)
00254 #define IM1_PS2_CROSS_TH          (0x1<<6)
00255 #define IM1_PS2_EXCEED_TH         (0x3<<6)
00256 
00257 
00258 // REG_IRQ_MODE1
00259 #define IM2_PS3_NONE              0x00
00260 #define IM2_PS3_EVRYSAMPLE        (0x0)
00261 #define IM2_PS3_CROSS_TH          (0x1)
00262 #define IM2_PS3_EXCEED_TH         (0x3)
00263 
00264 
00265 //
00266 // REG_PS_LED21   LED2 Current is upper nibble
00267 //                LED1 Current is lower nibble 
00268 //
00269 // REG_PS_LED3    LED3 Current is lower nibble
00270 #define LEDI_000                  0x00
00271 #define LEDI_006                  0x01
00272 #define LEDI_011                  0x02
00273 #define LEDI_022                  0x03
00274 #define LEDI_045                  0x04
00275 #define LEDI_067                  0x05
00276 #define LEDI_090                  0x06
00277 #define LEDI_112                  0x07
00278 #define LEDI_135                  0x08
00279 #define LEDI_157                  0x09
00280 #define LEDI_180                  0x0A
00281 #define LEDI_202                  0x0B
00282 #define LEDI_224                  0x0C
00283 #define LEDI_269                  0x0D
00284 #define LEDI_314                  0x0E
00285 #define LEDI_359                  0x0F
00286 
00287 
00288 // PARAM_CH_LIST
00289 #define PS1_TASK                  0x01
00290 #define PS2_TASK                  0x02
00291 #define PS3_TASK                  0x04
00292 #define ALS_VIS_TASK              0x10
00293 #define ALS_IR_TASK               0x20
00294 #define AUX_TASK                  0x40
00295 
00296 //
00297 // ADC Counters
00298 // PARAM_PS_ADC_COUNTER      
00299 // PARAM_ALSVIS_ADC_COUNTER  
00300 // PARAM_ALSIR_ADC_COUNTER  
00301 //
00302 #define RECCNT_001                0x00
00303 #define RECCNT_007                0x10
00304 #define RECCNT_015                0x20
00305 #define RECCNT_031                0x30
00306 #define RECCNT_063                0x40
00307 #define RECCNT_127                0x50
00308 #define RECCNT_255                0x60
00309 #define RECCNT_511                0x70
00310 
00311 //
00312 // Proximity LED Selection
00313 // PARAM_PSLED12_SELECT  PS2 LED Choice is Upper Nibble
00314 //                       PS1 LED Choice is Lower Nibble 
00315 //
00316 // PARAM_PSLED3_SELECT   PS3 LED Choice is Lower Nibble
00317 //
00318 // Each of the three PS measurements can choose whichever
00319 // irLED to light up during the measurement, with whichever
00320 // combination desired.
00321 #define NO_LED                    0x00
00322 #define LED1_EN                   0x01
00323 #define LED2_EN                   0x02
00324 #define LED3_EN                   0x04
00325 #define SEL_LED1_PS1              (LED1_EN)
00326 #define SEL_LED2_PS1              (LED2_EN)
00327 #define SEL_LED3_PS1              (LED3_EN)
00328 #define SEL_LED1_PS2              (LED1_EN<<4)
00329 #define SEL_LED2_PS2              (LED2_EN<<4)
00330 #define SEL_LED3_PS2              (LED3_EN<<4)
00331 #define SEL_LED1_PS3              (LED1_EN)
00332 #define SEL_LED2_PS3              (LED2_EN)
00333 #define SEL_LED3_PS3              (LED3_EN)
00334 
00335 //
00336 // PARAM_PS_ENCODING  
00337 // When these bits are set the corresponding measurement 
00338 // will report the least significant bits of the
00339 // ADC is used instead of the most significant bits
00340 #define PS1_LSB                   0x10
00341 #define PS2_LSB                   0x20
00342 #define PS3_LSB                   0x40
00343 #define PS_ENCODING_MASK          0x70
00344 
00345 //
00346 // PARAM_ALS_ENCODING 
00347 // When these bits are set the corresponding measurement 
00348 // will report the least significant bits of the
00349 // ADC is used instead of the most significant bits
00350 #define ALS_VIS_LSB               0x10
00351 #define ALS_IR_LSB                0x20
00352 #define AUX_LSB                   0x40
00353 #define ALS_ENCODING_MASK         0xCF
00354 
00355 //
00356 // PARAM_PS_ADC_MISC         
00357 // PARAM_ALS_VIS_ADC_MISC         
00358 // PARAM_ALS_IR_ADC_MISC         
00359 //
00360 // PS_MODE_MEAS_MODE and NOT_PS_MEAS_MODE are applicable only
00361 // for PARAM_PS_ADC_MISC.
00362 //
00363 //    PS_MEAS_MODE is used to perform normal Proximity measurements. 
00364 //    While in this operatinal mode, it is possible to choose either
00365 //    the small IR photodiode or big IR photodiode. The big IR
00366 //    photodiode is the default for normal operation. The small IR
00367 //    photodiode is typically not used, but it is possible to use it
00368 //    for proximity measurements.
00369 //
00370 //    NOT_PS_MEAS_MODE can be applied to PARAM_PS_ADC_MISC.
00371 //
00372 //    This allows three PS channels to perform RAW ADC measurements 
00373 //    on any source (no irLED driven). These measurements will have no
00374 //    reference, and will have an offset of 0x4000 if the most 
00375 //    significant 16 bits of the 17-bit ADC is reported. Otherwise, 
00376 //    if the PARAM_xxx_ENCODING _LSB settings are set, then the 
00377 //    offset will be 0x8000 (due to bit shifting). 
00378 //
00379 //    When performing voltage measurements (INT, LED1, LED2, TEMP), 
00380 //    a separate VSS measurement should be subtracted from the reading.
00381 //
00382 //    When performing measurement with visible photodiode, first take
00383 //    a no-led measurement and subtract away the visible light measurement.
00384 //
00385 //    When performing an optical measurement using either two IR 
00386 //    photodiodes, one should subtract away the no-led measurement from 
00387 //    the IR measurement.
00388 //
00389 //    Note that the subtraction ordering is significant between
00390 //    taking visible light photodiode vs IR photodiode
00391 //    measurement. The raw ADC reading of visible light photodiode
00392 //    decreases with increasing light levels while the raw ADC reading 
00393 //    of IR light photodiode increases with increasing light levels.
00394 //
00395 // HSIG_EN means 'high signal range enable'. The ADC would
00396 // be able to operate with higher light levels, but at the
00397 // expense of sensitivity. This setting can be used for 
00398 // operation under direct sunlight.
00399 //
00400 // PARAM_PS_ADC_MISC, PARAM_ALSVIS_ADC_MISC and PARAM_ALSIR_ADC_MISC    
00401 // can use HSIG_EN also.
00402 // 
00403 //
00404 #define NOT_PS_MEAS_MODE          0x00 
00405 #define PS_MEAS_MODE              0x04
00406 #define HSIG_EN                   0x20
00407 #define RANGE_EN                  0x20
00408 
00409 #define ALS_IR_ADC_MISC_MASK      0x20
00410 #define ALS_VIS_ADC_MISC_MASK     0x20
00411 
00412 //
00413 // ADC Mux Settings
00414 // PARAM_PS1_ADC_MUX    See PARAM_PS_ADC_MISC also 
00415 // PARAM_PS2_ADC_MUX    See PARAM_PS_ADC_MISC also
00416 // PARAM_PS3_ADC_MUX    See PARAM_PS_ADC_MISC also
00417 //
00418 // PARAM_VIS_ADC_MUX    MUX_ALS_VIS or MUX_NONE only
00419 // PARAM_IR_ADC_MUX     MUX_ALS_IR, MUX_PS_IR or MUX_NONE only
00420 // PARAM_AUX_ADC_MUX    MUX_VTEMP, MUX_LED1, MUX_LED2, MUX_INT
00421 //                      to use anything other than MUX_VTEMP, 
00422 //                      ANA_IN_KEY should be unlocked first.
00423 //
00424 #define MUX_SMALL_IR              0x00
00425 #define MUX_VIS                   0x02
00426 #define MUX_LARGE_IR              0x03
00427 #define MUX_NO_PHOTO_DIODE        0x06
00428 #define MUX_VTEMP                 0x65
00429 #define MUX_INT                   0x05
00430 #define MUX_LED1                  0x15
00431 #define MUX_VSS                   0x25
00432 #define MUX_LED2                  0x35
00433 #define MUX_VDD                   0x75
00434 
00435 //
00436 // ADC Dividers
00437 // PARAM_PS_ADC_GAIN       
00438 // PARAM_ALSVIS_ADC_GAIN  
00439 // PARAM_ALSIR_ADC_GAIN 
00440 //
00441 #define ADC_NORM                  0x00
00442 #define ADC_DIV2                  0x01
00443 #define ADC_DIV4                  0x02
00444 #define ADC_DIV8                  0x03
00445 #define ADC_DIV16                 0x04
00446 #define ADC_DIV32                 0x05
00447 #define ADC_DIV64                 0x06
00448 #define ADC_DIV128                0x07
00449 #define ADC_DIV256                0x08
00450 #define ADC_DIV512                0x09
00451 #define ADC_DIV1024               0x0A
00452 #define ADC_DIV2048               0x0B
00453 
00454 // Hardware Key value
00455 // REG_HW_KEY
00456 #define HW_KEY_VAL0               0x17
00457 
00458 // Sleep Control
00459 // PARAM_SLEEP_CTRL 
00460 #define SLEEP_DISABLED            0x01
00461 
00462 // ANA_IN_KEY value
00463 #define ANA_KEY_38                0x10
00464 #define ANA_KEY_39                0x40
00465 #define AMA_KEY_3A                0x62
00466 #define ANA_KEY_3B                0x3b
00467 
00468 
00469 #ifdef __cplusplus
00470 }
00471 #endif
00472 
00476 #endif // #define SI114X_FUNCTIONS_H