Si114xKit Drivers

Detailed Description

Silicon Labs Si114x Ultraviolet (UV) Index, Gesture, Proximity, and Ambient Light Sensor I2C driver.

Data Structures

struct SI114X_CAL_S
SI114X_CAL_S Data Structure.
struct SI114X_IRQ_SAMPLE
Si114x Sample Data Structure.

Macros

#define SI1147_ADDR 0xc0

Enumerations

enum gesture_t {
NONE ,
UP ,
DOWN ,
LEFT ,
RIGHT ,
TAP
}

Functions

uint8_t Compress (uint16_t input)
Converts a 16-bit value to 8-bit value.
void delay_10ms (void)
Implements 10ms delay.
void delay_1ms (void)
Implements 1ms delay.
int Si1147_ConfigureDetection (I2C_TypeDef *i2c, uint8_t addr, int slow)
Initializes and configures the Si1147 sensor.
int Si1147_Detect_Device (I2C_TypeDef *i2c, uint8_t addr)
Detects whether Si1147 is on the i2c bus.
int Si1147_GetInterruptOutputEnable (I2C_TypeDef *i2c, uint8_t addr, int *enable)
Get the enable status of the Si1147 interrupt pin.
int Si1147_MeasureUVAndObjectPresent (I2C_TypeDef *i2c, uint8_t addr, uint16_t *uvIndex, int *objectDetect)
Reads the UV measurement data and checks for object in proximity to the Si1147.
gesture_t Si1147_NewSample (I2C_TypeDef *i2c, uint8_t addr, uint32_t timestamp)
Reads new measurement data and processes a new sample. This function should be called every time an interrupt for a new sample is received.
uint32_t Si1147_Read_Block_Register (I2C_TypeDef *i2c, uint8_t addr, uint8_t reg, uint8_t length, uint8_t *data)
Reads a block of data from the Si1147 sensor.
uint32_t Si1147_Read_Register (I2C_TypeDef *i2c, uint8_t addr, uint8_t reg, uint8_t *data)
Reads register from the Si1147 sensor.
int Si1147_SetInterruptOutputEnable (I2C_TypeDef *i2c, uint8_t addr, int enable)
Enables or disables the Si1147 interrupt pin.
uint32_t Si1147_Write_Block_Register (I2C_TypeDef *i2c, uint8_t addr, uint8_t reg, uint8_t length, uint8_t const *data)
Writes a block of data to the Si1147 sensor.
uint32_t Si1147_Write_Register (I2C_TypeDef *i2c, uint8_t addr, uint8_t reg, uint8_t data)
Writes register in the Si1147 sensor.
int16_t si114x_get_calibration (HANDLE si114x_handle , SI114X_CAL_S *si114x_cal, uint8_t security)
Populates the SI114X_CAL_S structure.
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 Si114xBlockRead (HANDLE si114x_handle , uint8_t address, uint8_t length, uint8_t *values)
Reads block of Si114x registers.
int16_t Si114xBlockWrite (HANDLE si114x_handle , uint8_t address, uint8_t length, uint8_t *values)
Writes block of Si114x registers.
int16_t Si114xNop (HANDLE si114x_handle )
Sends a NOP command to the Si113x/4x.
int16_t Si114xParamRead (HANDLE si114x_handle , uint8_t address)
Reads a Parameter from the Si113x/4x.
int16_t Si114xParamSet (HANDLE si114x_handle , uint8_t address, uint8_t value)
Writes a byte to an Si113x/4x Parameter.
int16_t Si114xPauseAll (HANDLE si114x_handle )
Pauses autonomous measurements.
int16_t Si114xPsAlsAuto (HANDLE si114x_handle )
Sends a PSALSAUTO command to the Si113x/4x.
int16_t Si114xPsAlsForce (HANDLE si114x_handle )
Sends a PSALSFORCE command to the Si113x/4x.
int16_t Si114xPsForce (HANDLE si114x_handle )
Sends a PSFORCE command to the Si113x/4x.
int16_t Si114xReadFromRegister (HANDLE si114x_handle , uint8_t address)
Reads from Si114x register.
int16_t Si114xReset (HANDLE si114x_handle )
Resets the Si113x/4x, clears any interrupts and initializes the HW_KEY register.
int16_t Si114xWriteToRegister (HANDLE si114x_handle , uint8_t address, uint8_t value)
Writes to Si114x Register.
uint16_t Uncompress (uint8_t input)
Converts an 8-bit compressed value to 16-bit.

Macro Definition Documentation

#define SI1147_ADDR   0xc0

I2C device address for Si1147 on weather station board.

Definition at line 55 of file si114x_algorithm.h .

Enumeration Type Documentation

Si114x gestures

Definition at line 80 of file si114x_algorithm.h .

Function Documentation

uint8_t Compress ( uint16_t input )

Converts a 16-bit value to 8-bit value.

Parameters
[in] input The 16-bit input to be compressed
Return values
0-255 The compressed value
<0 Error
Note
The Si1132, Si1145/6/7 does not make use of 8-bit compressed values and does not need this.

Definition at line 662 of file si114x_functions.c .

void delay_10ms ( void )

Implements 10ms delay.

Implements 10ms delay.

Definition at line 275 of file si1147_i2c.c .

References sl_sleeptimer_delay_millisecond() .

Referenced by Si114xReset() .

void delay_1ms ( void )

Implements 1ms delay.

Implements 1ms delay.

Definition at line 287 of file si1147_i2c.c .

References sl_sleeptimer_delay_millisecond() .

Referenced by si114x_get_calibration() , Si114xParamSet() , and Si114xPauseAll() .

int Si1147_ConfigureDetection ( I2C_TypeDef * i2c,
uint8_t addr,
int lowpower
)

Initializes and configures the Si1147 sensor.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[in] lowpower Set to 1 to initialize without autonomous mode (low power) or set to 0 to enable autonomous mode.
Returns
Returns 0 on success.

Definition at line 361 of file si114x_algorithm.c .

References si114x_get_calibration() , si114x_handle , si114x_set_ucoef() , Si114xParamSet() , Si114xPsAlsAuto() , Si114xReset() , Si114xWriteToRegister() , and UV_TASKLIST .

int Si1147_Detect_Device ( I2C_TypeDef * i2c,
uint8_t addr
)

Detects whether Si1147 is on the i2c bus.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
Returns
Returns 1 on success. Otherwise returns 0.

Definition at line 70 of file si114x_algorithm.c .

References si114x_handle , and Si114xReadFromRegister() .

int Si1147_GetInterruptOutputEnable ( I2C_TypeDef * i2c,
uint8_t addr,
int * enable
)

Get the enable status of the Si1147 interrupt pin.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[out] enable Will be set to 1 if the interrupt output pin is enabled or set to 0 if disabled.
Returns
Returns 0.

Definition at line 121 of file si114x_algorithm.c .

References si114x_handle , and Si114xReadFromRegister() .

Referenced by Si1147_MeasureUVAndObjectPresent() .

int Si1147_MeasureUVAndObjectPresent ( I2C_TypeDef * i2c,
uint8_t addr,
uint16_t * uvIndex,
int * objectDetect
)

Reads the UV measurement data and checks for object in proximity to the Si1147.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[out] uvIndex The UV index read from the sensor
[out] objectDetect Returns true if an object is detected in front of the sensor, otherwise false.
Returns
Returns 0.

Definition at line 146 of file si114x_algorithm.c .

References Si1147_GetInterruptOutputEnable() , si114x_handle , Si114xPsAlsForce() , Si114xReadFromRegister() , and Si114xWriteToRegister() .

gesture_t Si1147_NewSample ( I2C_TypeDef * i2c,
uint8_t addr,
uint32_t timestamp
)

Reads new measurement data and processes a new sample. This function should be called every time an interrupt for a new sample is received.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[in] timestamp The timestamp for when the sample interrupt was received.
Returns
Returns the type of gesture detected (as defined by gesture_t).

Definition at line 213 of file si114x_algorithm.c .

References ProcessSi1147Samples() , readPSData() , si114x_handle , Si114xReadFromRegister() , and Si114xWriteToRegister() .

uint32_t Si1147_Read_Block_Register ( I2C_TypeDef * i2c,
uint8_t addr,
uint8_t reg,
uint8_t length,
uint8_t * data
)

Reads a block of data from the Si1147 sensor.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[out] data The data read from the sensor.
[in] length The number of bytes to write to the sensor.
[in] reg The first register to begin reading from.
Returns
Returns number of bytes read on success. Otherwise returns error codes based on the I2CDRV.

Definition at line 179 of file si1147_i2c.c .

References I2C_TransferSeq_TypeDef::addr , I2C_TransferSeq_TypeDef::buf , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE_READ , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .

Referenced by Si114xBlockRead() .

uint32_t Si1147_Read_Register ( I2C_TypeDef * i2c,
uint8_t addr,
uint8_t reg,
uint8_t * data
)

Reads register from the Si1147 sensor.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[out] data The data read from the sensor.
[in] reg The register address to read from in the sensor.
Returns
Returns number of bytes read on success. Otherwise returns error codes based on the I2CDRV.

Definition at line 55 of file si1147_i2c.c .

References I2C_TransferSeq_TypeDef::addr , I2C_TransferSeq_TypeDef::buf , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE_READ , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .

Referenced by Si114xReadFromRegister() .

int Si1147_SetInterruptOutputEnable ( I2C_TypeDef * i2c,
uint8_t addr,
int enable
)

Enables or disables the Si1147 interrupt pin.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[in] enable Set to 1 to enable the interrupt output pin or set to 0 to disable the pin.
Returns
Returns error codes based on the I2CDRV.

Definition at line 95 of file si114x_algorithm.c .

References si114x_handle , and Si114xWriteToRegister() .

uint32_t Si1147_Write_Block_Register ( I2C_TypeDef * i2c,
uint8_t addr,
uint8_t reg,
uint8_t length,
uint8_t const * data
)

Writes a block of data to the Si1147 sensor.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[in] data The data to write to the sensor.
[in] length The number of bytes to write to the sensor.
[in] reg The first register to begin writing to.
Returns
Returns zero on success. Otherwise returns error codes based on the I2CDRV.

Definition at line 135 of file si1147_i2c.c .

References I2C_TransferSeq_TypeDef::addr , I2C_TransferSeq_TypeDef::buf , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .

Referenced by Si114xBlockWrite() .

uint32_t Si1147_Write_Register ( I2C_TypeDef * i2c,
uint8_t addr,
uint8_t reg,
uint8_t data
)

Writes register in the Si1147 sensor.

Parameters
[in] i2c The I2C peripheral to use (not used).
[in] addr The I2C address of the sensor.
[in] data The data to write to the sensor.
[in] reg The register address to write to in the sensor.
Returns
Returns zero on success. Otherwise returns error codes based on the I2CDRV.

Definition at line 94 of file si1147_i2c.c .

References I2C_TransferSeq_TypeDef::addr , I2C_TransferSeq_TypeDef::buf , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_WRITE , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .

Referenced by Si114xWriteToRegister() .

int16_t si114x_get_calibration ( HANDLE si114x_handle,
SI114X_CAL_S * si114x_cal,
uint8_t security
)

Populates the SI114X_CAL_S structure.

Performs some initial checking based on the security level. If the checks fail, the function returns without attempting to fetch calibration values. The reason for the checking is that the Si114x uses the same registers to store calibration values as used for storing proximity and ambient light measurements. Therefore, this function needs to be used only if there is no possibility of an autonomous process possibly overwriting the output registers.

If the checks are successful, then the si114x retrieves the compressed values from the Si114x, then populates the SI114X_CAL_S structure whose pointer is passed to si114x_calibration()

If there are any errors, si114x_cal is populated with default values

Parameters
[in] si114x_handle The programmer's toolkit handle
[out] si114x_cal Points to the SI114X_CAL_S structure that will hold the calibration values from the Si114x. If there are any errors, si114x_cal is populated with default values.
[in] security

0 Minimal checking

1 Checks to make sure that interface registers are zero, otherwise, returns -1 interface registers are zero only when the Si114x has been reset, and no autonomous measurements have started.

Return values
0 Success
-1 Security Check failed
-2 i2c communication error
-3 Chip does not support factory calibration
-4 Null pointers found for si114x_handle or si114x_cal

Definition at line 1368 of file si114x_functions.c .

References SI114X_CAL_S::adcrange_ratio , delay_1ms() , SI114X_CAL_S::irpd_correction , SI114X_CAL_S::irsize_ratio , SI114X_CAL_S::ledi_ratio , Si114xBlockRead() , Si114xNop() , Si114xReadFromRegister() , Si114xWriteToRegister() , cal_ref_t::ucoef , SI114X_CAL_S::ucoef_p , and SI114X_CAL_S::vispd_correction .

Referenced by Si1147_ConfigureDetection() , and Si114x_ConfigureUV() .

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.

Takes in an optional input ucoef pointer, then modifies it based on calibration. If the input ucoef is NULL, default values for clear overlay is assumed and then the si114x_cal is used to adjust it before setting the ucoef. Note that the Si114x ucoef registers are updated by this function; no additional action is required. This routine also performs the necessary querying of the chip identification to make sure that it is a uvindex-capable device.

Parameters
[in] si114x_handle The programmer's toolkit handle
[in] input_ucoef if NULL, a clear overlay is assumed, and datasheet values for ucoef is used. Otherwise, pointer to 4 bytes array representing the reference coefficients is passed.
[in] si114x_cal Points to the SI114X_CAL_S structure that holds the calibration values from the Si113x/4x
Return values
0 Success
-1 The device is neither Si1132, Si1145, Si1146 nor Si1147
<-1 Error

Definition at line 1510 of file si114x_functions.c .

References SI114X_CAL_S::irpd_correction , operand_t::op1 , operand_t::op2 , Si114xBlockWrite() , Si114xReadFromRegister() , SI114X_CAL_S::ucoef_p , and SI114X_CAL_S::vispd_correction .

Referenced by Si1147_ConfigureDetection() , and Si114x_ConfigureUV() .

int16_t Si114xAlsForce ( HANDLE si114x_handle )

Sends an ALSFORCE command to the Si113x/4x.

Parameters
[in] si114x_handle The programmer's toolkit handle
Return values
0 Success
<0 Error

Definition at line 234 of file si114x_functions.c .

int16_t Si114xBlockRead ( HANDLE si114x_handle,
uint8_t address,
uint8_t length,
uint8_t * values
)

Reads block of Si114x registers.

Parameters
[in] si114x_handle The programmer toolkit handle.
[in] address The register address to read from.
[in] length The number of bytes to read.
[in] values The data read from the sensor.
Returns
Returns Error status

Reads block of Si114x registers.

Definition at line 266 of file si1147_i2c.c .

References Si1147_Read_Block_Register() , and Si114x_i2c_smbus_read_i2c_block_data() .

Referenced by si114x_get_calibration() .

int16_t Si114xBlockWrite ( HANDLE si114x_handle,
uint8_t address,
uint8_t length,
uint8_t * values
)

Writes block of Si114x registers.

Parameters
[in] si114x_handle The programmer toolkit handle.
[in] address The register address to write to.
[in] length The number of bytes to write.
[in] values The data to write to the sensor.
Returns
Returns Error status

Writes block of Si114x registers.

Definition at line 247 of file si1147_i2c.c .

References Si1147_Write_Block_Register() , and Si114x_i2c_smbus_write_i2c_block_data() .

Referenced by si114x_set_ucoef() , and Si114xParamSet() .

int16_t Si114xNop ( HANDLE si114x_handle )

Sends a NOP command to the Si113x/4x.

Parameters
[in] si114x_handle The programmer's toolkit handle
Return values
0 Success
<0 Error

Definition at line 204 of file si114x_functions.c .

Referenced by si114x_get_calibration() .

int16_t Si114xParamRead ( HANDLE si114x_handle,
uint8_t address
)

Reads a Parameter from the Si113x/4x.

Parameters
[in] si114x_handle The programmer's toolkit handle
[in] address The address of the parameter.
Return values
<0 Error
0-255 Parameter contents

Definition at line 281 of file si114x_functions.c .

References Si114xReadFromRegister() .

int16_t Si114xParamSet ( HANDLE si114x_handle,
uint8_t address,
uint8_t value
)

Writes a byte to an Si113x/4x Parameter.

Parameters
[in] si114x_handle The programmer's toolkit handle
[in] address The parameter address
[in] value The byte value to be written to the Si113x/4x parameter
Return values
0 Success
<0 Error
Note
This function ensures that the Si113x/4x is idle and ready to receive a command before writing the parameter. Furthermore, command completion is checked. If setting parameter is not done properly, no measurements will occur. This is the most common error. It is highly recommended that host code make use of this function.

Definition at line 316 of file si114x_functions.c .

References delay_1ms() , Si114xBlockWrite() , and Si114xReadFromRegister() .

Referenced by Si1147_ConfigureDetection() , Si114x_ConfigureUV() , and Si114x_EnableVisRange() .

int16_t Si114xPauseAll ( HANDLE si114x_handle )

Pauses autonomous measurements.

Parameters
[in] si114x_handle The programmer's toolkit handle
Return values
0 Success
<0 Error

Definition at line 374 of file si114x_functions.c .

References delay_1ms() , Si114xReadFromRegister() , and Si114xWriteToRegister() .

Referenced by Si114xReset() .

int16_t Si114xPsAlsAuto ( HANDLE si114x_handle )

Sends a PSALSAUTO command to the Si113x/4x.

Parameters
[in] si114x_handle The programmer's toolkit handle
Return values
0 Success
<0 Error

Definition at line 264 of file si114x_functions.c .

Referenced by Si1147_ConfigureDetection() .

int16_t Si114xPsAlsForce ( HANDLE si114x_handle )

Sends a PSALSFORCE command to the Si113x/4x.

Parameters
[in] si114x_handle The programmer's toolkit handle
Return values
0 Success
<0 Error

Definition at line 249 of file si114x_functions.c .

Referenced by Si1147_MeasureUVAndObjectPresent() , and Si114x_MeasureUVIndex() .

int16_t Si114xPsForce ( HANDLE si114x_handle )

Sends a PSFORCE command to the Si113x/4x.

Parameters
[in] si114x_handle The programmer's toolkit handle
Return values
0 Success
<0 Error

Definition at line 219 of file si114x_functions.c .

int16_t Si114xReadFromRegister ( HANDLE si114x_handle,
uint8_t address
)

Reads from Si114x register.

Parameters
[in] si114x_handle The programmer toolkit handle.
[in] address The register address to read from.
Returns
Returns Value read

Reads from Si114x register.

Definition at line 227 of file si1147_i2c.c .

References Si1147_Read_Register() , and Si114x_i2c_smbus_read_byte_data() .

Referenced by readPSData() , Si1147_Detect_Device() , Si1147_GetInterruptOutputEnable() , Si1147_MeasureUVAndObjectPresent() , Si1147_NewSample() , si114x_get_calibration() , Si114x_MeasureUVIndex() , si114x_set_ucoef() , Si114xInit() , Si114xParamRead() , Si114xParamSet() , and Si114xPauseAll() .

int16_t Si114xReset ( HANDLE si114x_handle )

Resets the Si113x/4x, clears any interrupts and initializes the HW_KEY register.

Parameters
[in] si114x_handle The programmer's toolkit handle
Return values
0 Success
<0 Error

Definition at line 95 of file si114x_functions.c .

References delay_10ms() , Si114xPauseAll() , and Si114xWriteToRegister() .

Referenced by Si1147_ConfigureDetection() , and Si114x_ConfigureUV() .

int16_t Si114xWriteToRegister ( HANDLE si114x_handle,
uint8_t address,
uint8_t data
)

Writes to Si114x Register.

Parameters
[in] si114x_handle The programmer toolkit handle.
[in] address The register address to write to.
[in] data The data to write to the sensor.
Returns
Returns Error status

Writes to Si114x Register.

Definition at line 213 of file si1147_i2c.c .

References Si1147_Write_Register() , and Si114x_i2c_smbus_write_byte_data() .

Referenced by Si1147_ConfigureDetection() , Si1147_MeasureUVAndObjectPresent() , Si1147_NewSample() , Si1147_SetInterruptOutputEnable() , Si114x_ConfigureUV() , si114x_get_calibration() , Si114x_MeasureUVIndex() , Si114xPauseAll() , and Si114xReset() .

uint16_t Uncompress ( uint8_t input )

Converts an 8-bit compressed value to 16-bit.

Parameters
[in] input The 8-bit compressed input to be uncompressed
Returns
uncompressed value
Note
The Si1132, Si1145/6/7 does not make use of 8-bit compressed values and does not need this.

Definition at line 571 of file si114x_functions.c .