EFR32 Blue Gecko 12 Software Documentation  efr32bg12-doc-5.1.2
si114x_functions.h
Go to the documentation of this file.
1 /*************************************************************************/
28 #ifndef SI114X_FUNCTIONS_H
29 #define SI114X_FUNCTIONS_H
30 
31 /***************************************************************************/
36 /***************************************************************************/
41 #include "si114x_types.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /*******************************************************************************
48  ******************************* STRUCTS ***********************************
49  ******************************************************************************/
50 
51 /***************************************************************************/
54 typedef struct
55 {
56  uint32_t vispd_correction;
57  uint32_t irpd_correction;
58  uint32_t adcrange_ratio;
59  uint32_t irsize_ratio;
60  uint32_t ledi_ratio;
61  uint8_t* ucoef_p;
62 } SI114X_CAL_S;
63 
64 /*******************************************************************************
65  *************** Functions Needed by Si114x_functions.c ********************
66  ******************************************************************************/
67 
69  uint8_t address,
70  uint8_t value);
71 int16_t Si114xReadFromRegister(HANDLE si114x_handle, uint8_t address);
72 int16_t Si114xBlockWrite(HANDLE si114x_handle,
73  uint8_t address,
74  uint8_t length,
75  uint8_t* values);
76 int16_t Si114xBlockRead(HANDLE si114x_handle,
77  uint8_t address,
78  uint8_t length,
79  uint8_t* values);
80 void delay_10ms(void);
81 
82 void delay_1ms(void);
83 
84 /*******************************************************************************
85  *************** Functions supplied by Si114x_functions.c ******************
86  ******************************************************************************/
87 
88 int16_t Si114xReset(HANDLE si114x_handle);
89 int16_t Si114xPauseAll(HANDLE si114x_handle);
90 int16_t Si114xNop(HANDLE si114x_handle);
91 int16_t Si114xPsForce(HANDLE si114x_handle);
92 int16_t Si114xAlsForce(HANDLE si114x_handle);
93 int16_t Si114xPsAlsForce(HANDLE si114x_handle);
94 int16_t Si114xPsAlsAuto(HANDLE si114x_handle);
95 int16_t Si114xParamSet(HANDLE si114x_handle, uint8_t address, uint8_t value);
96 int16_t Si114xParamRead(HANDLE si114x_handle, uint8_t address);
97 uint8_t Compress(uint16_t input);
98 uint16_t Uncompress(uint8_t input);
100  SI114X_CAL_S* si114x_cal,
101  uint8_t security);
102 int16_t si114x_set_ucoef(HANDLE si114x_handle,
103  uint8_t* input_ucoef,
104  SI114X_CAL_S* si114x_cal );
105 
106 /*******************************************************************************
107  ************************** Si114x I2C Registers *******************************
108  ******************************************************************************/
110 #define REG_PART_ID 0x00
111 #define REG_REV_ID 0x01
112 #define REG_SEQ_ID 0x02
113 #define REG_INT_CFG 0x03
114 #define REG_IRQ_ENABLE 0x04
115 #define REG_IRQ_MODE1 0x05
116 #define REG_IRQ_MODE2 0x06
117 #define REG_HW_KEY 0x07
118 #define REG_MEAS_RATE 0x08
119 #define REG_ALS_RATE 0x09
120 #define REG_PS_RATE 0x0A
121 #define REG_ALS_LO_TH_LSB 0x0B
122 #define REG_ALS_LO_TH_MSB 0x0C
123 #define REG_ALS_HI_TH_LSB 0x0D
124 #define REG_ALS_HI_TH_MSB 0x0E
125 #define REG_PS_LED21 0x0F
126 #define REG_PS_LED3 0x10
127 #define REG_PS1_TH_LSB 0x11
128 #define REG_PS1_TH_MSB 0x12
129 #define REG_PS2_TH_LSB 0x13
130 #define REG_PS2_TH_MSB 0x14
131 #define REG_PS3_TH_LSB 0x15
132 #define REG_PS3_TH_MSB 0x16
133 #define REG_PARAM_WR 0x17
134 #define REG_COMMAND 0x18
135 #define REG_RESPONSE 0x20
136 #define REG_IRQ_STATUS 0x21
137 #define REG_ALS_VIS_DATA0 0x22
138 #define REG_ALS_VIS_DATA1 0x23
139 #define REG_ALS_IR_DATA0 0x24
140 #define REG_ALS_IR_DATA1 0x25
141 #define REG_PS1_DATA0 0x26
142 #define REG_PS1_DATA1 0x27
143 #define REG_PS2_DATA0 0x28
144 #define REG_PS2_DATA1 0x29
145 #define REG_PS3_DATA0 0x2A
146 #define REG_PS3_DATA1 0x2B
147 #define REG_AUX_DATA0 0x2C
148 #define REG_AUX_DATA1 0x2D
149 #define REG_PARAM_OUT 0x2E
150 #define REG_PARAM_RD 0x2E
151 #define REG_CHIP_STAT 0x30
152 #define REG_UCOEF0 0x13
153 #define REG_UCOEF1 0x14
154 #define REG_UCOEF2 0x15
155 #define REG_UCOEF3 0x16
156 #define REG_MEAS_RATE_LSB 0x08
157 #define REG_MEAS_RATE_MSB 0x09
158 
160 /*******************************************************************************
161  ************************** Si114x I2C Parameter Offsets ***********************
162  ******************************************************************************/
164 #define PARAM_I2C_ADDR 0x00
165 #define PARAM_CH_LIST 0x01
166 #define PARAM_PSLED12_SELECT 0x02
167 #define PARAM_PSLED3_SELECT 0x03
168 #define PARAM_FILTER_EN 0x04
169 #define PARAM_PS_ENCODING 0x05
170 #define PARAM_ALS_ENCODING 0x06
171 #define PARAM_PS1_ADC_MUX 0x07
172 #define PARAM_PS2_ADC_MUX 0x08
173 #define PARAM_PS3_ADC_MUX 0x09
174 #define PARAM_PS_ADC_COUNTER 0x0A
175 #define PARAM_PS_ADC_CLKDIV 0x0B
176 #define PARAM_PS_ADC_GAIN 0x0B
177 #define PARAM_PS_ADC_MISC 0x0C
178 #define PARAM_VIS_ADC_MUX 0x0D
179 #define PARAM_IR_ADC_MUX 0x0E
180 #define PARAM_AUX_ADC_MUX 0x0F
181 #define PARAM_ALSVIS_ADC_COUNTER 0x10
182 #define PARAM_ALSVIS_ADC_CLKDIV 0x11
183 #define PARAM_ALSVIS_ADC_GAIN 0x11
184 #define PARAM_ALSVIS_ADC_MISC 0x12
185 #define PARAM_ALS_HYST 0x16
186 #define PARAM_PS_HYST 0x17
187 #define PARAM_PS_HISTORY 0x18
188 #define PARAM_ALS_HISTORY 0x19
189 #define PARAM_ADC_OFFSET 0x1A
190 #define PARAM_SLEEP_CTRL 0x1B
191 #define PARAM_LED_RECOVERY 0x1C
192 #define PARAM_ALSIR_ADC_COUNTER 0x1D
193 #define PARAM_ALSIR_ADC_CLKDIV 0x1E
194 #define PARAM_ALSIR_ADC_GAIN 0x1E
195 #define PARAM_ALSIR_ADC_MISC 0x1F
196 
198 /*******************************************************************************
199  ******* Si114x Register and Parameter Bit Definitions *********************
200  ******************************************************************************/
202 
203 // REG_IRQ_CFG
204 #define ICG_INTOE 0x01
205 #define ICG_INTMODE 0x02
206 
207 // REG_IRQ_ENABLE
208 // REG_IRQ_STATUS
209 #define IE_NONE 0x00
210 
211 #define IE_ALS_NONE 0x00
212 #define IE_ALS_EVRYSAMPLE 0x01
213 #define IE_ALS_EXIT_WIN 0x01
214 #define IE_ALS_ENTER_WIN 0x02
215 
216 #define IE_PS1_NONE 0x00
217 #define IE_PS1_EVRYSAMPLE 0x04
218 #define IE_PS1_CROSS_TH 0x04
219 #define IE_PS1_EXCEED_TH 0x04
220 #define IE_PS1 0x04
221 
222 #define IE_PS2_NONE 0x00
223 #define IE_PS2_EVRYSAMPLE 0x08
224 #define IE_PS2_CROSS_TH 0x08
225 #define IE_PS2_EXCEEED_TH 0x08
226 #define IE_PS2 0x08
227 
228 #define IE_PS3_NONE 0x00
229 #define IE_PS3_EVRYSAMPLE 0x10
230 #define IE_PS3_CROSS_TH 0x10
231 #define IE_PS3_EXCEED_TH 0x10
232 #define IE_PS3 0x10
233 
234 #define IE_CMD 0x20
235 
236 #define IE_ALL 0x3F
237 
238 // REG_IRQ_MODE1
239 #define IM1_NONE 0x00
240 #define IM1_ALS_NONE 0x00
241 #define IM1_ALS_EVRYSAMPLE 0x00
242 #define IM1_ALS_VIS_EXIT 0x01
243 #define IM1_ALS_VIS_ENTER 0x05
244 #define IM1_ALS_IR_EXIT 0x03
245 #define IM1_ALS_IR_ENTER 0x06
246 
247 #define IM1_PS1_NONE 0x00
248 #define IM1_PS1_EVRYSAMPLE (0x0<<4)
249 #define IM1_PS1_CROSS_TH (0x1<<4)
250 #define IM1_PS1_EXCEED_TH (0x3<<4)
251 
252 #define IM1_PS2_NONE 0x00
253 #define IM1_PS2_EVRYSAMPLE (0x0<<6)
254 #define IM1_PS2_CROSS_TH (0x1<<6)
255 #define IM1_PS2_EXCEED_TH (0x3<<6)
256 
257 
258 // REG_IRQ_MODE1
259 #define IM2_PS3_NONE 0x00
260 #define IM2_PS3_EVRYSAMPLE (0x0)
261 #define IM2_PS3_CROSS_TH (0x1)
262 #define IM2_PS3_EXCEED_TH (0x3)
263 
264 
265 //
266 // REG_PS_LED21 LED2 Current is upper nibble
267 // LED1 Current is lower nibble
268 //
269 // REG_PS_LED3 LED3 Current is lower nibble
270 #define LEDI_000 0x00
271 #define LEDI_006 0x01
272 #define LEDI_011 0x02
273 #define LEDI_022 0x03
274 #define LEDI_045 0x04
275 #define LEDI_067 0x05
276 #define LEDI_090 0x06
277 #define LEDI_112 0x07
278 #define LEDI_135 0x08
279 #define LEDI_157 0x09
280 #define LEDI_180 0x0A
281 #define LEDI_202 0x0B
282 #define LEDI_224 0x0C
283 #define LEDI_269 0x0D
284 #define LEDI_314 0x0E
285 #define LEDI_359 0x0F
286 
287 
288 // PARAM_CH_LIST
289 #define PS1_TASK 0x01
290 #define PS2_TASK 0x02
291 #define PS3_TASK 0x04
292 #define ALS_VIS_TASK 0x10
293 #define ALS_IR_TASK 0x20
294 #define AUX_TASK 0x40
295 
296 //
297 // ADC Counters
298 // PARAM_PS_ADC_COUNTER
299 // PARAM_ALSVIS_ADC_COUNTER
300 // PARAM_ALSIR_ADC_COUNTER
301 //
302 #define RECCNT_001 0x00
303 #define RECCNT_007 0x10
304 #define RECCNT_015 0x20
305 #define RECCNT_031 0x30
306 #define RECCNT_063 0x40
307 #define RECCNT_127 0x50
308 #define RECCNT_255 0x60
309 #define RECCNT_511 0x70
310 
311 //
312 // Proximity LED Selection
313 // PARAM_PSLED12_SELECT PS2 LED Choice is Upper Nibble
314 // PS1 LED Choice is Lower Nibble
315 //
316 // PARAM_PSLED3_SELECT PS3 LED Choice is Lower Nibble
317 //
318 // Each of the three PS measurements can choose whichever
319 // irLED to light up during the measurement, with whichever
320 // combination desired.
321 #define NO_LED 0x00
322 #define LED1_EN 0x01
323 #define LED2_EN 0x02
324 #define LED3_EN 0x04
325 #define SEL_LED1_PS1 (LED1_EN)
326 #define SEL_LED2_PS1 (LED2_EN)
327 #define SEL_LED3_PS1 (LED3_EN)
328 #define SEL_LED1_PS2 (LED1_EN<<4)
329 #define SEL_LED2_PS2 (LED2_EN<<4)
330 #define SEL_LED3_PS2 (LED3_EN<<4)
331 #define SEL_LED1_PS3 (LED1_EN)
332 #define SEL_LED2_PS3 (LED2_EN)
333 #define SEL_LED3_PS3 (LED3_EN)
334 
335 //
336 // PARAM_PS_ENCODING
337 // When these bits are set the corresponding measurement
338 // will report the least significant bits of the
339 // ADC is used instead of the most significant bits
340 #define PS1_LSB 0x10
341 #define PS2_LSB 0x20
342 #define PS3_LSB 0x40
343 #define PS_ENCODING_MASK 0x70
344 
345 //
346 // PARAM_ALS_ENCODING
347 // When these bits are set the corresponding measurement
348 // will report the least significant bits of the
349 // ADC is used instead of the most significant bits
350 #define ALS_VIS_LSB 0x10
351 #define ALS_IR_LSB 0x20
352 #define AUX_LSB 0x40
353 #define ALS_ENCODING_MASK 0xCF
354 
355 //
356 // PARAM_PS_ADC_MISC
357 // PARAM_ALS_VIS_ADC_MISC
358 // PARAM_ALS_IR_ADC_MISC
359 //
360 // PS_MODE_MEAS_MODE and NOT_PS_MEAS_MODE are applicable only
361 // for PARAM_PS_ADC_MISC.
362 //
363 // PS_MEAS_MODE is used to perform normal Proximity measurements.
364 // While in this operatinal mode, it is possible to choose either
365 // the small IR photodiode or big IR photodiode. The big IR
366 // photodiode is the default for normal operation. The small IR
367 // photodiode is typically not used, but it is possible to use it
368 // for proximity measurements.
369 //
370 // NOT_PS_MEAS_MODE can be applied to PARAM_PS_ADC_MISC.
371 //
372 // This allows three PS channels to perform RAW ADC measurements
373 // on any source (no irLED driven). These measurements will have no
374 // reference, and will have an offset of 0x4000 if the most
375 // significant 16 bits of the 17-bit ADC is reported. Otherwise,
376 // if the PARAM_xxx_ENCODING _LSB settings are set, then the
377 // offset will be 0x8000 (due to bit shifting).
378 //
379 // When performing voltage measurements (INT, LED1, LED2, TEMP),
380 // a separate VSS measurement should be subtracted from the reading.
381 //
382 // When performing measurement with visible photodiode, first take
383 // a no-led measurement and subtract away the visible light measurement.
384 //
385 // When performing an optical measurement using either two IR
386 // photodiodes, one should subtract away the no-led measurement from
387 // the IR measurement.
388 //
389 // Note that the subtraction ordering is significant between
390 // taking visible light photodiode vs IR photodiode
391 // measurement. The raw ADC reading of visible light photodiode
392 // decreases with increasing light levels while the raw ADC reading
393 // of IR light photodiode increases with increasing light levels.
394 //
395 // HSIG_EN means 'high signal range enable'. The ADC would
396 // be able to operate with higher light levels, but at the
397 // expense of sensitivity. This setting can be used for
398 // operation under direct sunlight.
399 //
400 // PARAM_PS_ADC_MISC, PARAM_ALSVIS_ADC_MISC and PARAM_ALSIR_ADC_MISC
401 // can use HSIG_EN also.
402 //
403 //
404 #define NOT_PS_MEAS_MODE 0x00
405 #define PS_MEAS_MODE 0x04
406 #define HSIG_EN 0x20
407 #define RANGE_EN 0x20
408 
409 #define ALS_IR_ADC_MISC_MASK 0x20
410 #define ALS_VIS_ADC_MISC_MASK 0x20
411 
412 //
413 // ADC Mux Settings
414 // PARAM_PS1_ADC_MUX See PARAM_PS_ADC_MISC also
415 // PARAM_PS2_ADC_MUX See PARAM_PS_ADC_MISC also
416 // PARAM_PS3_ADC_MUX See PARAM_PS_ADC_MISC also
417 //
418 // PARAM_VIS_ADC_MUX MUX_ALS_VIS or MUX_NONE only
419 // PARAM_IR_ADC_MUX MUX_ALS_IR, MUX_PS_IR or MUX_NONE only
420 // PARAM_AUX_ADC_MUX MUX_VTEMP, MUX_LED1, MUX_LED2, MUX_INT
421 // to use anything other than MUX_VTEMP,
422 // ANA_IN_KEY should be unlocked first.
423 //
424 #define MUX_SMALL_IR 0x00
425 #define MUX_VIS 0x02
426 #define MUX_LARGE_IR 0x03
427 #define MUX_NO_PHOTO_DIODE 0x06
428 #define MUX_VTEMP 0x65
429 #define MUX_INT 0x05
430 #define MUX_LED1 0x15
431 #define MUX_VSS 0x25
432 #define MUX_LED2 0x35
433 #define MUX_VDD 0x75
434 
435 //
436 // ADC Dividers
437 // PARAM_PS_ADC_GAIN
438 // PARAM_ALSVIS_ADC_GAIN
439 // PARAM_ALSIR_ADC_GAIN
440 //
441 #define ADC_NORM 0x00
442 #define ADC_DIV2 0x01
443 #define ADC_DIV4 0x02
444 #define ADC_DIV8 0x03
445 #define ADC_DIV16 0x04
446 #define ADC_DIV32 0x05
447 #define ADC_DIV64 0x06
448 #define ADC_DIV128 0x07
449 #define ADC_DIV256 0x08
450 #define ADC_DIV512 0x09
451 #define ADC_DIV1024 0x0A
452 #define ADC_DIV2048 0x0B
453 
454 // Hardware Key value
455 // REG_HW_KEY
456 #define HW_KEY_VAL0 0x17
457 
458 // Sleep Control
459 // PARAM_SLEEP_CTRL
460 #define SLEEP_DISABLED 0x01
461 
462 // ANA_IN_KEY value
463 #define ANA_KEY_38 0x10
464 #define ANA_KEY_39 0x40
465 #define AMA_KEY_3A 0x62
466 #define ANA_KEY_3B 0x3b
467 
469 #ifdef __cplusplus
470 }
471 #endif
472 
476 #endif // #define SI114X_FUNCTIONS_H
SI114X_CAL_S Data Structure.
void delay_10ms(void)
Implements 10ms delay.
Definition: si1147_i2c.c:267
int16_t Si114xPsForce(HANDLE si114x_handle)
Sends a PSFORCE command to the Si113x/4x.
int16_t Si114xNop(HANDLE si114x_handle)
Sends a NOP command to the Si113x/4x.
uint16_t Uncompress(uint8_t input)
Converts an 8-bit compressed value to 16-bit.
uint32_t vispd_correction
int16_t Si114xParamSet(HANDLE si114x_handle, uint8_t address, uint8_t value)
Writes a byte to an Si113x/4x Parameter.
uint8_t Compress(uint16_t input)
Converts a 16-bit value to 8-bit value.
int16_t Si114xBlockWrite(HANDLE si114x_handle, uint8_t address, uint8_t length, uint8_t *values)
Writes block of Si114x registers.
Definition: si1147_i2c.c:239
uint32_t ledi_ratio
uint32_t irsize_ratio
int16_t Si114xWriteToRegister(HANDLE si114x_handle, uint8_t address, uint8_t value)
Writes to Si114x Register.
Definition: si1147_i2c.c:205
int16_t si114x_set_ucoef(HANDLE si114x_handle, uint8_t *input_ucoef, SI114X_CAL_S *si114x_cal)
Initializes the Si113x/46/47/48 UCOEF Registers.
int16_t Si114xAlsForce(HANDLE si114x_handle)
Sends an ALSFORCE command to the Si113x/4x.
int16_t Si114xParamRead(HANDLE si114x_handle, uint8_t address)
Reads a Parameter from the Si113x/4x.
uint8_t * ucoef_p
void delay_1ms(void)
Implements 1ms delay.
Definition: si1147_i2c.c:279
int16_t Si114xPsAlsForce(HANDLE si114x_handle)
Sends a PSALSFORCE command to the Si113x/4x.
Si114x types.
int16_t Si114xReadFromRegister(HANDLE si114x_handle, uint8_t address)
Reads from Si114x register.
Definition: si1147_i2c.c:219
uint32_t adcrange_ratio
int16_t Si114xBlockRead(HANDLE si114x_handle, uint8_t address, uint8_t length, uint8_t *values)
Reads block of Si114x registers.
Definition: si1147_i2c.c:258
int16_t si114x_get_calibration(HANDLE si114x_handle, SI114X_CAL_S *si114x_cal, uint8_t security)
Populates the SI114X_CAL_S structure.
static void * si114x_handle
Si114x PGM toolkit functions uses a void* to pass hardware parameters through to the lower level i2c ...
int16_t Si114xPsAlsAuto(HANDLE si114x_handle)
Sends a PSALSAUTO command to the Si113x/4x.
int16_t Si114xPauseAll(HANDLE si114x_handle)
Pauses autonomous measurements.
int16_t Si114xReset(HANDLE si114x_handle)
Resets the Si113x/4x, clears any interrupts and initializes the HW_KEY register.
uint32_t irpd_correction