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 );
105 uint8_t i2c_write_data[1];
113 i2c_write_data[0] = reg;
114 seq.
buf[0].
data = i2c_write_data;
148 uint8_t i2c_write_data[2];
149 uint8_t i2c_read_data[1];
157 i2c_write_data[0] = reg;
158 i2c_write_data[1] = data;
159 seq.
buf[0].
data = i2c_write_data;
161 seq.
buf[1].
data = i2c_read_data;
194 uint8_t i2c_write_data[10];
195 uint8_t i2c_read_data[1];
204 i2c_write_data[0] = reg;
205 for( i = 0; i < length; i++ ) {
206 i2c_write_data[i + 1] = data[i];
208 seq.
buf[0].
data = i2c_write_data;
209 seq.
buf[0].
len = length + 1;
210 seq.
buf[1].
data = i2c_read_data;
243 uint8_t i2c_write_data[1];
251 i2c_write_data[0] = reg;
252 seq.
buf[0].
data = i2c_write_data;
345 uint8_t response_stored;
370 if( ( response & SI1133_RSP0_COUNTER_MASK ) == response_stored ) {
401 if( ( response & SI1133_RSP0_COUNTER_MASK ) != response_stored ) {
475 cmd = 0x40 + ( address & 0x3F );
514 uint8_t response_stored;
527 buffer[1] = 0x80 + ( address & 0x3F );
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;
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;
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;
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;
693 int32_t SI1133_calcPolyInner( int32_t input, int8_t fraction, uint16_t mag, int8_t shift )
699 value = ( ( input << fraction ) / mag ) >> -shift;
702 value = ( ( input << fraction ) / mag ) << shift;
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 )
719 uint8_t info, x_order, y_order, counter;
722 int32_t output = 0, x1, x2, y1, y2;
724 for( counter = 0; counter < num_coeff; counter++ ) {
727 x_order = get_x_order( info );
728 y_order = get_y_order( info );
730 shift = ( (uint16_t) kp->
info & 0xff00 ) >> 8;
737 if( get_sign( info ) ) {
744 if( ( x_order == 0 ) && ( y_order == 0 ) ) {
745 output += sign * mag << output_fraction;
749 x1 = SI1133_calcPolyInner( x, input_fraction, mag, shift );
751 x2 = SI1133_calcPolyInner( x, input_fraction, mag, shift );
763 y1 = SI1133_calcPolyInner( y, input_fraction, mag, shift );
765 y2 = SI1133_calcPolyInner( y, input_fraction, mag, shift );
776 output += sign * x1 * x2 * y1 * y2;
810 uvi = SI1133_calcEvalPoly( 0, uv, UV_INPUT_FRACTION, UV_OUTPUT_FRACTION, UV_NUMCOEFF, uk );
840 if( ( vis_high > ADC_THRESHOLD ) || ( ir > ADC_THRESHOLD ) ) {
841 lux = SI1133_calcEvalPoly( vis_high,
849 lux = SI1133_calcEvalPoly( vis_low,
889 while( response != 0x0F )
900 *lux = *lux / ( 1 << LUX_OUTPUT_FRACTION );
904 *uvi = *uvi / ( 1 << UV_OUTPUT_FRACTION );
956 *lux = *lux / ( 1 << LUX_OUTPUT_FRACTION );
960 *uvi = *uvi / ( 1 << UV_OUTPUT_FRACTION );
uint32_t SI1133_getIrqStatus(uint8_t *irqStatus)
Reads the interrupt status register of the device.
#define SI1133_RSP0_COUNTER_MASK
static uint32_t SI1133_waitUntilSleep(void)
Waits until the Si1133 is sleeping before proceeding.
Driver for the Si1133 Ambient Light and UV sensor.
I2C_TransferReturn_TypeDef I2CSPM_Transfer(I2C_TypeDef *i2c, I2C_TransferSeq_TypeDef *seq)
Perform I2C transfer.
int32_t SI1133_getLux(int32_t vis_high, int32_t vis_low, int32_t ir, SI1133_LuxCoeff_TypeDef *lk)
Compute lux value.
uint32_t SI1133_registerBlockWrite(uint8_t reg, uint8_t length, uint8_t *data)
Writes a block of data to the Si1133 sensor.
uint32_t SI1133_reset(void)
Resets the Si1133.
#define SI1133_PARAM_CH_LIST
uint32_t SI1133_getHardwareID(uint8_t *hardwareID)
Reads Hardware ID from the SI1133 sensor.
#define SI1133_PARAM_ADCPOST0
#define SI1133_PARAM_ADCSENS2
void UTIL_delay(uint32_t ms)
Delays number of msTick Systicks (1 ms)
uint32_t SI1133_registerBlockRead(uint8_t reg, uint8_t length, uint8_t *data)
Reads a block of data from the Si1133 sensor.
static uint32_t SI1133_sendCmd(uint8_t command)
Helper function to send a command to the Si1133.
uint32_t SI1133_getMeasurement(float *lux, float *uvi)
Retrieve the sample values from the chip and convert them to lux and UV index values.
#define SI1133_I2C_DEVICE_BUS_ADDRESS
#define SI1133_REG_IRQ_STATUS
#define SI1133_I2C_DEVICE
#define SI1133_RSP0_SLEEP
#define SI1133_REG_HOSTIN0
#define SI1133_RSP0_CHIPSTAT_MASK
uint32_t SI1133_measurementGet(SI1133_Samples_TypeDef *samples)
Read samples from the Si1133 chip.
#define I2C_FLAG_WRITE
Indicate plain write sequence: S+ADDR(W)+DATA0+P.
Structure to store the calculation coefficients.
#define SI1133_REG_RESPONSE0
I2C_TransferReturn_TypeDef
#define SI1133_REG_COMMAND
uint32_t BOARD_envSensEnable(bool enable)
Enables or disables the environmental sensor group (Pressure, RH/Temp, UV/Ambient light and Hall sens...
#define SI1133_PARAM_ADCCONFIG3
Structure to store the data measured by the Si1133.
#define SI1133_PARAM_ADCSENS1
#define SI1133_REG_IRQ_ENABLE
#define SI1133_PARAM_ADCSENS3
#define SI1133_PARAM_ADCPOST2
#define SI1133_PARAM_ADCPOST3
I2C simple poll-based master mode driver for the DK/STK.
SI1133_Coeff_TypeDef coeff_low[9]
uint32_t SI1133_paramSet(uint8_t address, uint8_t value)
Writes a byte to an Si1133 Parameter.
uint32_t SI1133_registerRead(uint8_t reg, uint8_t *data)
Reads register from the Si1133 sensor.
Utility Functions for the Thunderboard Sense.
#define SI1133_CMD_RESET_CMD_CTR
struct I2C_TransferSeq_TypeDef::@0 buf[2]
uint32_t SI1133_measureLuxUvi(float *lux, float *uvi)
Measure lux and UV index using the Si1133 sensor.
uint32_t SI1133_resetCmdCtr(void)
Sends a RESET COMMAND COUNTER command to the Si1133.
int32_t SI1133_getUv(int32_t uv, SI1133_Coeff_TypeDef *uk)
Compute UV index.
Structure to store the coefficients used for Lux calculation.
uint32_t SI1133_measurementForce(void)
Sends a FORCE command to the Si1133.
Master mode transfer message structure used to define a complete I2C transfer sequence (from start to...
#define SI1133_REG_RESPONSE1
uint32_t SI1133_measurementStart(void)
Sends a START command to the Si1133.
#define SI1133_ERROR_I2C_TRANSACTION_FAILED
#define SI1133_PARAM_ADCCONFIG1
uint32_t SI1133_paramRead(uint8_t address)
Reads a parameter from the Si1133.
#define SI1133_CMD_PAUSE_CH
#define I2C_FLAG_WRITE_READ
Indicate combined write/read sequence: S+ADDR(W)+DATA0+Sr+ADDR(R)+DATA1+P.
uint32_t SI1133_init(void)
Initializes the Si1133 chip.
#define SI1133_ERROR_SLEEP_FAILED
#define SI1133_PARAM_ADCCONFIG0
static uint32_t SI1133_measurementPause(void)
Sends a PAUSE command to the Si1133.
#define SI1133_PARAM_ADCPOST1
SI1133_Coeff_TypeDef coeff_high[4]
#define SI1133_PARAM_ADCCONFIG2
#define SI1133_PARAM_ADCSENS0
uint16_t addr
Address to use after (repeated) start.
BOARD module header file.
uint32_t SI1133_registerWrite(uint8_t reg, uint8_t data)
Writes register in the Si1133 sensor.
uint32_t SI1133_deInit(void)
Stops the measurements on all channel and waits until the chip goes to sleep state.
#define SI1133_CMD_FORCE_CH
#define SI1133_REG_PART_ID