EFR32 Blue Gecko 1 Software Documentation  efr32bg1-doc-5.1.2
si1133.c
Go to the documentation of this file.
1 /***************************************************************************/
16 #include <stdint.h>
17 #include "i2cspm.h"
18 
19 #include "thunderboard/util.h"
20 #include "thunderboard/board.h"
21 #include "thunderboard/si1133.h"
22 
23 /***************************************************************************/
31 /***************************************************************************/
37 /***************************************************************************/
41 static SI1133_LuxCoeff_TypeDef lk = {
42 
43  { { 0, 209 },
44  { 1665, 93 },
45  { 2064, 65 },
46  { -2671, 234 } },
47  { { 0, 0 },
48  { 1921, 29053 },
49  { -1022, 36363 },
50  { 2320, 20789 },
51  { -367, 57909 },
52  { -1774, 38240 },
53  { -608, 46775 },
54  { -1503, 51831 },
55  { -1886, 58928 } }
57 };
58 
59 /***************************************************************************/
63 static SI1133_Coeff_TypeDef uk[2] = {
64 
65  { 1281, 30902 },
66  { -638, 46301 }
68 };
69 
74 /***************************************************************************/
82 static int32_t SI1133_calcPolyInner ( int32_t input, int8_t fraction, uint16_t mag, int8_t shift );
83 static int32_t SI1133_calcEvalPoly ( int32_t x, int32_t y, uint8_t input_fraction, uint8_t output_fraction, uint8_t num_coeff, SI1133_Coeff_TypeDef *kp );
84 
87 /***************************************************************************/
100 uint32_t SI1133_registerRead( uint8_t reg, uint8_t *data )
101 {
102 
105  uint8_t i2c_write_data[1];
106  uint32_t retval;
107 
108  retval = SI1133_OK;
109 
112  /* Select register to start reading from */
113  i2c_write_data[0] = reg;
114  seq.buf[0].data = i2c_write_data;
115  seq.buf[0].len = 1;
116  /* Select length of data to be read */
117  seq.buf[1].data = data;
118  seq.buf[1].len = 1;
119 
120  ret = I2CSPM_Transfer( SI1133_I2C_DEVICE, &seq );
121  if( ret != i2cTransferDone ) {
122  *data = 0xff;
124  }
125 
126  return retval;
127 
128 }
129 
130 /***************************************************************************/
143 uint32_t SI1133_registerWrite( uint8_t reg, uint8_t data )
144 {
145 
148  uint8_t i2c_write_data[2];
149  uint8_t i2c_read_data[1];
150  uint32_t retval;
151 
152  retval = SI1133_OK;
153 
155  seq.flags = I2C_FLAG_WRITE;
156  /* Select register and data to write */
157  i2c_write_data[0] = reg;
158  i2c_write_data[1] = data;
159  seq.buf[0].data = i2c_write_data;
160  seq.buf[0].len = 2;
161  seq.buf[1].data = i2c_read_data;
162  seq.buf[1].len = 0;
163 
164  ret = I2CSPM_Transfer( SI1133_I2C_DEVICE, &seq );
165  if( ret != i2cTransferDone ) {
167  }
168 
169  return retval;
170 
171 }
172 
173 /***************************************************************************/
189 uint32_t SI1133_registerBlockWrite( uint8_t reg, uint8_t length, uint8_t *data )
190 {
191 
194  uint8_t i2c_write_data[10];
195  uint8_t i2c_read_data[1];
196  uint8_t i;
197  uint32_t retval;
198 
199  retval = SI1133_OK;
200 
202  seq.flags = I2C_FLAG_WRITE;
203  /* Select register to start writing to*/
204  i2c_write_data[0] = reg;
205  for( i = 0; i < length; i++ ) {
206  i2c_write_data[i + 1] = data[i];
207  }
208  seq.buf[0].data = i2c_write_data;
209  seq.buf[0].len = length + 1;
210  seq.buf[1].data = i2c_read_data;
211  seq.buf[1].len = 0;
212 
213  ret = I2CSPM_Transfer( SI1133_I2C_DEVICE, &seq );
214  if( ret != i2cTransferDone ) {
216  }
217 
218  return retval;
219 
220 }
221 
222 /***************************************************************************/
238 uint32_t SI1133_registerBlockRead( uint8_t reg, uint8_t length, uint8_t *data )
239 {
240 
243  uint8_t i2c_write_data[1];
244  uint32_t retval;
245 
246  retval = SI1133_OK;
247 
250  /* Select register to start reading from */
251  i2c_write_data[0] = reg;
252  seq.buf[0].data = i2c_write_data;
253  seq.buf[0].len = 1;
254  /* Select length of data to be read */
255  seq.buf[1].data = data;
256  seq.buf[1].len = length;
257 
258  ret = I2CSPM_Transfer( SI1133_I2C_DEVICE, &seq );
259  if( ret != i2cTransferDone ) {
261  }
262 
263  return retval;
264 
265 }
266 
267 /***************************************************************************/
274 static uint32_t SI1133_waitUntilSleep( void )
275 {
276 
277  uint32_t ret;
278  uint8_t response;
279  uint8_t count = 0;
280  uint32_t retval;
281 
282  retval = SI1133_OK;
283 
284  /* This loops until the Si1133 is known to be in its sleep state */
285  /* or if an i2c error occurs */
286  while( count < 5 )
287  {
288  ret = SI1133_registerRead( SI1133_REG_RESPONSE0, &response );
289  if( ( response & SI1133_RSP0_CHIPSTAT_MASK ) == SI1133_RSP0_SLEEP ) {
290  break;
291  }
292 
293  if( ret != SI1133_OK ) {
294  retval = SI1133_ERROR_SLEEP_FAILED;
295  break;
296  }
297 
298  count++;
299  }
300 
301  return retval;
302 
303 }
304 
305 /***************************************************************************/
312 uint32_t SI1133_reset( void )
313 {
314 
315  uint32_t retval;
316 
317  /* Do not access the Si1133 earlier than 25 ms from power-up */
318  UTIL_delay( 30 );
319 
320  /* Perform the Reset Command */
322 
323  /* Delay for 10 ms. This delay is needed to allow the Si1133 */
324  /* to perform internal reset sequence. */
325  UTIL_delay( 10 );
326 
327  return retval;
328 
329 }
330 
331 /***************************************************************************/
341 static uint32_t SI1133_sendCmd( uint8_t command )
342 {
343 
344  uint8_t response;
345  uint8_t response_stored;
346  uint8_t count = 0;
347  uint32_t ret;
348 
349  /* Get the response register contents */
350  ret = SI1133_registerRead( SI1133_REG_RESPONSE0, &response_stored );
351  if( ret != SI1133_OK ) {
352  return ret;
353  }
354 
355  response_stored = response_stored & SI1133_RSP0_COUNTER_MASK;
356 
357  /* Double-check the response register is consistent */
358  while( count < 5 ) {
359  ret = SI1133_waitUntilSleep();
360  if( ret != SI1133_OK ) {
361  return ret;
362  }
363  /* Skip if the command is RESET COMMAND COUNTER */
364  if( command == SI1133_CMD_RESET_CMD_CTR ) {
365  break;
366  }
367 
368  ret = SI1133_registerRead( SI1133_REG_RESPONSE0, &response );
369 
370  if( ( response & SI1133_RSP0_COUNTER_MASK ) == response_stored ) {
371  break;
372  }
373  else {
374  if( ret != SI1133_OK ) {
375  return ret;
376  }
377  else {
378  response_stored = response & SI1133_RSP0_COUNTER_MASK;
379  }
380  }
381 
382  count++;
383  }
384 
385  /* Send the command */
386  ret = SI1133_registerWrite( SI1133_REG_COMMAND, command );
387  if( ret != SI1133_OK ) {
388  return ret;
389  }
390 
391  count = 0;
392  /* Expect a change in the response register */
393  while( count < 5 )
394  {
395  /* Skip if the command is RESET COMMAND COUNTER */
396  if( command == SI1133_CMD_RESET_CMD_CTR ) {
397  break;
398  }
399 
400  ret = SI1133_registerRead( SI1133_REG_RESPONSE0, &response );
401  if( ( response & SI1133_RSP0_COUNTER_MASK ) != response_stored ) {
402  break;
403  }
404  else {
405  if( ret != SI1133_OK ) {
406  return ret;
407  }
408  }
409 
410  count++;
411  }
412 
413  return SI1133_OK;
414 
415 }
416 
417 /***************************************************************************/
424 uint32_t SI1133_resetCmdCtr( void )
425 {
426 
428 
429 }
430 
431 /***************************************************************************/
438 uint32_t SI1133_measurementForce( void )
439 {
440 
442 
443 }
444 
445 /***************************************************************************/
452 uint32_t SI1133_measurementStart( void )
453 {
454 
456 
457 }
458 
459 /***************************************************************************/
469 uint32_t SI1133_paramRead( uint8_t address )
470 {
471 
472  uint8_t retval;
473  uint8_t cmd;
474 
475  cmd = 0x40 + ( address & 0x3F );
476 
477  retval = SI1133_sendCmd( cmd );
478  if( retval != SI1133_OK ) {
479  return retval;
480  }
481 
483 
484  return retval;
485 
486 }
487 
488 /***************************************************************************/
509 uint32_t SI1133_paramSet( uint8_t address, uint8_t value )
510 {
511 
512  uint32_t retval;
513  uint8_t buffer[2];
514  uint8_t response_stored;
515  uint8_t response;
516  uint8_t count;
517 
518  retval = SI1133_waitUntilSleep();
519  if( retval != SI1133_OK ) {
520  return retval;
521  }
522 
523  SI1133_registerRead( SI1133_REG_RESPONSE0, &response_stored );
524  response_stored &= SI1133_RSP0_COUNTER_MASK;
525 
526  buffer[0] = value;
527  buffer[1] = 0x80 + ( address & 0x3F );
528 
529  retval = SI1133_registerBlockWrite( SI1133_REG_HOSTIN0, 2, (uint8_t*) buffer );
530  if( retval != SI1133_OK ) {
531  return retval;
532  }
533 
534  /* Wait for command to finish */
535  count = 0;
536  /* Expect a change in the response register */
537  while( count < 5 )
538  {
539 
540  retval = SI1133_registerRead( SI1133_REG_RESPONSE0, &response );
541  if( ( response & SI1133_RSP0_COUNTER_MASK ) != response_stored ) {
542  break;
543  }
544  else {
545  if( retval != SI1133_OK ) {
546  return retval;
547  }
548  }
549 
550  count++;
551  }
552 
553  return SI1133_OK;
554 
555 }
556 
557 /***************************************************************************/
564 static uint32_t SI1133_measurementPause( void )
565 {
566 
568 
569 }
570 
571 /**************************************************************************/
578 uint32_t SI1133_init( void )
579 {
580 
581  uint32_t retval;
582 
583  /* Enable power to the sensor */
584  BOARD_envSensEnable( true );
585 
586  /* Allow some time for the part to power up */
587  UTIL_delay( 5 );
588 
589  retval = SI1133_reset();
590 
591  UTIL_delay( 10 );
592 
593  retval += SI1133_paramSet( SI1133_PARAM_CH_LIST, 0x0f );
594  retval += SI1133_paramSet( SI1133_PARAM_ADCCONFIG0, 0x78 );
595  retval += SI1133_paramSet( SI1133_PARAM_ADCSENS0, 0x71 );
596  retval += SI1133_paramSet( SI1133_PARAM_ADCPOST0, 0x40 );
597  retval += SI1133_paramSet( SI1133_PARAM_ADCCONFIG1, 0x4d );
598  retval += SI1133_paramSet( SI1133_PARAM_ADCSENS1, 0xe1 );
599  retval += SI1133_paramSet( SI1133_PARAM_ADCPOST1, 0x40 );
600  retval += SI1133_paramSet( SI1133_PARAM_ADCCONFIG2, 0x41 );
601  retval += SI1133_paramSet( SI1133_PARAM_ADCSENS2, 0xe1 );
602  retval += SI1133_paramSet( SI1133_PARAM_ADCPOST2, 0x50 );
603  retval += SI1133_paramSet( SI1133_PARAM_ADCCONFIG3, 0x4d );
604  retval += SI1133_paramSet( SI1133_PARAM_ADCSENS3, 0x87 );
605  retval += SI1133_paramSet( SI1133_PARAM_ADCPOST3, 0x40 );
606 
607  retval += SI1133_registerWrite( SI1133_REG_IRQ_ENABLE, 0x0f );
608 
609  return retval;
610 
611 }
612 
613 /***************************************************************************/
621 uint32_t SI1133_deInit( void )
622 {
623 
624  uint32_t retval;
625 
626  retval = SI1133_paramSet( SI1133_PARAM_CH_LIST, 0x3f );
627  retval += SI1133_measurementPause();
628  retval += SI1133_waitUntilSleep();
629 
630  return retval;
631 
632 }
633 
634 /***************************************************************************/
646 {
647 
648  uint8_t buffer[13];
649  uint32_t retval;
650 
651  retval = SI1133_registerBlockRead( SI1133_REG_IRQ_STATUS, 13, buffer );
652 
653  samples->irq_status = buffer[0];
654 
655  samples->ch0 = buffer[1] << 16;
656  samples->ch0 |= buffer[2] << 8;
657  samples->ch0 |= buffer[3];
658  if( samples->ch0 & 0x800000 ) {
659  samples->ch0 |= 0xFF000000;
660  }
661 
662  samples->ch1 = buffer[4] << 16;
663  samples->ch1 |= buffer[5] << 8;
664  samples->ch1 |= buffer[6];
665  if( samples->ch1 & 0x800000 ) {
666  samples->ch1 |= 0xFF000000;
667  }
668 
669  samples->ch2 = buffer[7] << 16;
670  samples->ch2 |= buffer[8] << 8;
671  samples->ch2 |= buffer[9];
672  if( samples->ch2 & 0x800000 ) {
673  samples->ch2 |= 0xFF000000;
674  }
675 
676  samples->ch3 = buffer[10] << 16;
677  samples->ch3 |= buffer[11] << 8;
678  samples->ch3 |= buffer[12];
679  if( samples->ch3 & 0x800000 ) {
680  samples->ch3 |= 0xFF000000;
681  }
682 
683  return retval;
684 
685 }
686 
689 /***************************************************************************/
693 int32_t SI1133_calcPolyInner( int32_t input, int8_t fraction, uint16_t mag, int8_t shift )
694 {
695 
696  int32_t value;
697 
698  if( shift < 0 ) {
699  value = ( ( input << fraction ) / mag ) >> -shift;
700  }
701  else {
702  value = ( ( input << fraction ) / mag ) << shift;
703  }
704 
705  return value;
706 
707 }
708 
709 /***************************************************************************/
716 int32_t SI1133_calcEvalPoly( int32_t x, int32_t y, uint8_t input_fraction, uint8_t output_fraction, uint8_t num_coeff, SI1133_Coeff_TypeDef *kp )
717 {
718 
719  uint8_t info, x_order, y_order, counter;
720  int8_t sign, shift;
721  uint16_t mag;
722  int32_t output = 0, x1, x2, y1, y2;
723 
724  for( counter = 0; counter < num_coeff; counter++ ) {
725 
726  info = kp->info;
727  x_order = get_x_order( info );
728  y_order = get_y_order( info );
729 
730  shift = ( (uint16_t) kp->info & 0xff00 ) >> 8;
731  shift ^= 0x00ff;
732  shift += 1;
733  shift = -shift;
734 
735  mag = kp->mag;
736 
737  if( get_sign( info ) ) {
738  sign = -1;
739  }
740  else {
741  sign = 1;
742  }
743 
744  if( ( x_order == 0 ) && ( y_order == 0 ) ) {
745  output += sign * mag << output_fraction;
746  }
747  else {
748  if( x_order > 0 ) {
749  x1 = SI1133_calcPolyInner( x, input_fraction, mag, shift );
750  if( x_order > 1 ) {
751  x2 = SI1133_calcPolyInner( x, input_fraction, mag, shift );
752  }
753  else {
754  x2 = 1;
755  }
756  }
757  else {
758  x1 = 1;
759  x2 = 1;
760  }
761 
762  if( y_order > 0 ) {
763  y1 = SI1133_calcPolyInner( y, input_fraction, mag, shift );
764  if( y_order > 1 ) {
765  y2 = SI1133_calcPolyInner( y, input_fraction, mag, shift );
766  }
767  else {
768  y2 = 1;
769  }
770  }
771  else {
772  y1 = 1;
773  y2 = 1;
774  }
775 
776  output += sign * x1 * x2 * y1 * y2;
777  }
778 
779  kp++;
780  }
781 
782  if( output < 0 ) {
783  output = -output;
784  }
785 
786  return output;
787 
788 }
789 
792 /***************************************************************************/
805 int32_t SI1133_getUv( int32_t uv, SI1133_Coeff_TypeDef *uk )
806 {
807 
808  int32_t uvi;
809 
810  uvi = SI1133_calcEvalPoly( 0, uv, UV_INPUT_FRACTION, UV_OUTPUT_FRACTION, UV_NUMCOEFF, uk );
811 
812  return uvi;
813 
814 }
815 
816 /***************************************************************************/
835 int32_t SI1133_getLux( int32_t vis_high, int32_t vis_low, int32_t ir, SI1133_LuxCoeff_TypeDef *lk )
836 {
837 
838  int32_t lux;
839 
840  if( ( vis_high > ADC_THRESHOLD ) || ( ir > ADC_THRESHOLD ) ) {
841  lux = SI1133_calcEvalPoly( vis_high,
842  ir,
843  INPUT_FRACTION_HIGH,
844  LUX_OUTPUT_FRACTION,
845  NUMCOEFF_HIGH,
846  &( lk->coeff_high[0] ) );
847  }
848  else {
849  lux = SI1133_calcEvalPoly( vis_low,
850  ir,
851  INPUT_FRACTION_LOW,
852  LUX_OUTPUT_FRACTION,
853  NUMCOEFF_LOW,
854  &( lk->coeff_low[0] ) );
855  }
856 
857  return lux;
858 
859 }
860 
861 /***************************************************************************/
874 uint32_t SI1133_measureLuxUvi( float *lux, float *uvi )
875 {
876 
877  SI1133_Samples_TypeDef samples;
878  uint32_t retval;
879  uint8_t response;
880 
881  /* Force measurement */
882  retval = SI1133_measurementForce();
883 
884  /* Go to sleep while the sensor does the conversion */
885  UTIL_delay( 200 );
886 
887  /* Check if the measurement finished, if not then wait */
888  retval += SI1133_registerRead( SI1133_REG_IRQ_STATUS, &response );
889  while( response != 0x0F )
890  {
891  UTIL_delay( 5 );
892  retval += SI1133_registerRead( SI1133_REG_IRQ_STATUS, &response );
893  }
894 
895  /* Get the results */
896  SI1133_measurementGet( &samples );
897 
898  /* Convert the readings to lux */
899  *lux = (float) SI1133_getLux( samples.ch1, samples.ch3, samples.ch2, &lk );
900  *lux = *lux / ( 1 << LUX_OUTPUT_FRACTION );
901 
902  /* Convert the readings to UV index */
903  *uvi = (float) SI1133_getUv( samples.ch0, uk );
904  *uvi = *uvi / ( 1 << UV_OUTPUT_FRACTION );
905 
906  return retval;
907 
908 }
909 
910 /***************************************************************************/
920 uint32_t SI1133_getHardwareID( uint8_t *hardwareID )
921 {
922 
923  uint32_t retval;
924 
925  retval = SI1133_registerRead( SI1133_REG_PART_ID, hardwareID );
926 
927  return retval;
928 
929 }
930 
931 /***************************************************************************/
945 uint32_t SI1133_getMeasurement( float *lux, float *uvi )
946 {
947 
948  SI1133_Samples_TypeDef samples;
949  uint32_t retval;
950 
951  /* Get the results */
952  retval = SI1133_measurementGet( &samples );
953 
954  /* Convert the readings to lux */
955  *lux = (float) SI1133_getLux( samples.ch1, samples.ch3, samples.ch2, &lk );
956  *lux = *lux / ( 1 << LUX_OUTPUT_FRACTION );
957 
958  /* Convert the readings to UV index */
959  *uvi = (float) SI1133_getUv( samples.ch0, uk );
960  *uvi = *uvi / ( 1 << UV_OUTPUT_FRACTION );
961 
962  return retval;
963 
964 }
965 
966 /***************************************************************************/
976 uint32_t SI1133_getIrqStatus( uint8_t *irqStatus )
977 {
978 
979  uint32_t retval;
980 
981  /* Read the IRQ status register */
982  retval = SI1133_registerRead( SI1133_REG_IRQ_STATUS, irqStatus );
983 
984  return retval;
985 
986 }
987 
uint32_t SI1133_getIrqStatus(uint8_t *irqStatus)
Reads the interrupt status register of the device.
Definition: si1133.c:976
#define SI1133_RSP0_COUNTER_MASK
Definition: si1133.h:235
static uint32_t SI1133_waitUntilSleep(void)
Waits until the Si1133 is sleeping before proceeding.
Definition: si1133.c:274
Driver for the Si1133 Ambient Light and UV sensor.
I2C_TransferReturn_TypeDef I2CSPM_Transfer(I2C_TypeDef *i2c, I2C_TransferSeq_TypeDef *seq)
Perform I2C transfer.
Definition: i2cspm.c:124
int32_t SI1133_getLux(int32_t vis_high, int32_t vis_low, int32_t ir, SI1133_LuxCoeff_TypeDef *lk)
Compute lux value.
Definition: si1133.c:835
uint32_t SI1133_registerBlockWrite(uint8_t reg, uint8_t length, uint8_t *data)
Writes a block of data to the Si1133 sensor.
Definition: si1133.c:189
uint32_t SI1133_reset(void)
Resets the Si1133.
Definition: si1133.c:312
#define SI1133_PARAM_CH_LIST
Definition: si1133.h:171
uint32_t SI1133_getHardwareID(uint8_t *hardwareID)
Reads Hardware ID from the SI1133 sensor.
Definition: si1133.c:920
#define SI1133_PARAM_ADCPOST0
Definition: si1133.h:174
#define SI1133_PARAM_ADCSENS2
Definition: si1133.h:181
void UTIL_delay(uint32_t ms)
Delays number of msTick Systicks (1 ms)
Definition: util.c:97
uint32_t SI1133_registerBlockRead(uint8_t reg, uint8_t length, uint8_t *data)
Reads a block of data from the Si1133 sensor.
Definition: si1133.c:238
static uint32_t SI1133_sendCmd(uint8_t command)
Helper function to send a command to the Si1133.
Definition: si1133.c:341
uint32_t SI1133_getMeasurement(float *lux, float *uvi)
Retrieve the sample values from the chip and convert them to lux and UV index values.
Definition: si1133.c:945
#define SI1133_I2C_DEVICE_BUS_ADDRESS
Definition: si1133.h:63
#define SI1133_REG_IRQ_STATUS
Definition: si1133.h:134
#define SI1133_I2C_DEVICE
Definition: si1133.h:62
#define SI1133_RSP0_SLEEP
Definition: si1133.h:236
#define SI1133_REG_HOSTIN0
Definition: si1133.h:129
#define SI1133_RSP0_CHIPSTAT_MASK
Definition: si1133.h:234
uint32_t SI1133_measurementGet(SI1133_Samples_TypeDef *samples)
Read samples from the Si1133 chip.
Definition: si1133.c:645
#define I2C_FLAG_WRITE
Indicate plain write sequence: S+ADDR(W)+DATA0+P.
Definition: em_i2c.h:124
Structure to store the calculation coefficients.
Definition: si1133.h:102
#define SI1133_REG_RESPONSE0
Definition: si1133.h:133
I2C_TransferReturn_TypeDef
Definition: em_i2c.h:179
#define SI1133_REG_COMMAND
Definition: si1133.h:130
uint32_t BOARD_envSensEnable(bool enable)
Enables or disables the environmental sensor group (Pressure, RH/Temp, UV/Ambient light and Hall sens...
Definition: board.c:492
#define SI1133_PARAM_ADCCONFIG3
Definition: si1133.h:184
Structure to store the data measured by the Si1133.
Definition: si1133.h:89
#define SI1133_PARAM_ADCSENS1
Definition: si1133.h:177
#define SI1133_REG_IRQ_ENABLE
Definition: si1133.h:131
#define SI1133_PARAM_ADCSENS3
Definition: si1133.h:185
#define SI1133_PARAM_ADCPOST2
Definition: si1133.h:182
#define SI1133_PARAM_ADCPOST3
Definition: si1133.h:186
I2C simple poll-based master mode driver for the DK/STK.
SI1133_Coeff_TypeDef coeff_low[9]
Definition: si1133.h:115
uint32_t SI1133_paramSet(uint8_t address, uint8_t value)
Writes a byte to an Si1133 Parameter.
Definition: si1133.c:509
uint32_t SI1133_registerRead(uint8_t reg, uint8_t *data)
Reads register from the Si1133 sensor.
Definition: si1133.c:100
Utility Functions for the Thunderboard Sense.
#define SI1133_CMD_RESET_CMD_CTR
Definition: si1133.h:217
struct I2C_TransferSeq_TypeDef::@0 buf[2]
uint32_t SI1133_measureLuxUvi(float *lux, float *uvi)
Measure lux and UV index using the Si1133 sensor.
Definition: si1133.c:874
uint32_t SI1133_resetCmdCtr(void)
Sends a RESET COMMAND COUNTER command to the Si1133.
Definition: si1133.c:424
int32_t SI1133_getUv(int32_t uv, SI1133_Coeff_TypeDef *uk)
Compute UV index.
Definition: si1133.c:805
Structure to store the coefficients used for Lux calculation.
Definition: si1133.h:112
#define SI1133_CMD_RESET
Definition: si1133.h:218
uint32_t SI1133_measurementForce(void)
Sends a FORCE command to the Si1133.
Definition: si1133.c:438
Master mode transfer message structure used to define a complete I2C transfer sequence (from start to...
Definition: em_i2c.h:252
#define SI1133_REG_RESPONSE1
Definition: si1133.h:132
uint32_t SI1133_measurementStart(void)
Sends a START command to the Si1133.
Definition: si1133.c:452
#define SI1133_CMD_START
Definition: si1133.h:222
#define SI1133_ERROR_I2C_TRANSACTION_FAILED
Definition: si1133.h:74
#define SI1133_PARAM_ADCCONFIG1
Definition: si1133.h:176
uint32_t SI1133_paramRead(uint8_t address)
Reads a parameter from the Si1133.
Definition: si1133.c:469
#define SI1133_OK
Definition: si1133.h:73
#define SI1133_CMD_PAUSE_CH
Definition: si1133.h:221
uint8_t irq_status
Definition: si1133.h:91
#define I2C_FLAG_WRITE_READ
Indicate combined write/read sequence: S+ADDR(W)+DATA0+Sr+ADDR(R)+DATA1+P.
Definition: em_i2c.h:148
uint32_t SI1133_init(void)
Initializes the Si1133 chip.
Definition: si1133.c:578
#define SI1133_ERROR_SLEEP_FAILED
Definition: si1133.h:75
#define SI1133_PARAM_ADCCONFIG0
Definition: si1133.h:172
static uint32_t SI1133_measurementPause(void)
Sends a PAUSE command to the Si1133.
Definition: si1133.c:564
#define SI1133_PARAM_ADCPOST1
Definition: si1133.h:178
SI1133_Coeff_TypeDef coeff_high[4]
Definition: si1133.h:114
#define SI1133_PARAM_ADCCONFIG2
Definition: si1133.h:180
#define SI1133_PARAM_ADCSENS0
Definition: si1133.h:173
uint16_t addr
Address to use after (repeated) start.
Definition: em_i2c.h:262
BOARD module header file.
uint32_t SI1133_registerWrite(uint8_t reg, uint8_t data)
Writes register in the Si1133 sensor.
Definition: si1133.c:143
uint32_t SI1133_deInit(void)
Stops the measurements on all channel and waits until the chip goes to sleep state.
Definition: si1133.c:621
#define SI1133_CMD_FORCE_CH
Definition: si1133.h:220
#define SI1133_REG_PART_ID
Definition: si1133.h:126