EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-doc-5.1.2

Detailed Description

Data Structures

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

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

Macro Definition Documentation

#define SI1147_ADDR   0xc0

I2C device address for Si1147 on weather station board.

Definition at line 41 of file si114x_algorithm.h.

Enumeration Type Documentation

enum gesture_t

Si114x gestures

Definition at line 67 of file si114x_algorithm.h.

Function Documentation

uint8_t Compress ( uint16_t  input)

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

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

Definition at line 645 of file si114x_functions.c.

void delay_10ms ( void  )

Implements 10ms delay.

Implements 10ms delay.

Definition at line 267 of file si1147_i2c.c.

References RTCDRV_Delay().

Referenced by Si114xReset().

void delay_1ms ( void  )

Implements 1ms delay.

Implements 1ms delay.

Definition at line 279 of file si1147_i2c.c.

References RTCDRV_Delay().

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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[in]lowpowerSet 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 386 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
Returns
Returns 1 on success. Otherwise returns 0.

Definition at line 56 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[out]enableWill be set to 1 if the interrupt output pin is enabled or set to 0 if disabled.
Returns
Returns 0.

Definition at line 111 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[out]uvIndexThe UV index read from the sensor
[out]objectDetectReturns true if an object is detected in front of the sensor, otherwise false.
Returns
Returns 0.

Definition at line 137 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[in]timestampThe timestamp for when the sample interrupt was received.
Returns
Returns the type of gesture detected (as defined by gesture_t).

Definition at line 208 of file si114x_algorithm.c.

References 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[out]dataThe data read from the sensor.
[in]lengthThe number of bytes to write to the sensor.
[in]regThe 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 170 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[out]dataThe data read from the sensor.
[in]regThe 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 42 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[in]enableSet 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 82 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[in]dataThe data to write to the sensor.
[in]lengthThe number of bytes to write to the sensor.
[in]regThe first register to begin writing to.
Returns
Returns zero on success. Otherwise returns error codes based on the I2CDRV.

Definition at line 124 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]i2cThe I2C peripheral to use (not used).
[in]addrThe I2C address of the sensor.
[in]dataThe data to write to the sensor.
[in]regThe register address to write to in the sensor.
Returns
Returns zero on success. Otherwise returns error codes based on the I2CDRV.

Definition at line 82 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_handleThe programmer's toolkit handle
[out]si114x_calPoints 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
0Success
-1Security Check failed
-2i2c communication error
-3Chip does not support factory calibration
-4Null pointers found for si114x_handle or si114x_cal

Definition at line 1330 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_handleThe programmer's toolkit handle
[in]input_ucoefif 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_calPoints to the SI114X_CAL_S structure that holds the calibration values from the Si113x/4x
Return values
0Success
-1The device is neither Si1132, Si1145, Si1146 nor Si1147
<-1Error

Definition at line 1470 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_handleThe programmer's toolkit handle
Return values
0Success
<0Error

Definition at line 220 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_handleThe programmer toolkit handle.
[in]addressThe register address to read from.
[in]lengthThe number of bytes to read.
[in]valuesThe data read from the sensor.
Returns
Returns Error status

Reads block of Si114x registers.

Definition at line 258 of file si1147_i2c.c.

References Si1147_Read_Block_Register().

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_handleThe programmer toolkit handle.
[in]addressThe register address to write to.
[in]lengthThe number of bytes to write.
[in]valuesThe data to write to the sensor.
Returns
Returns Error status

Writes block of Si114x registers.

Definition at line 239 of file si1147_i2c.c.

References Si1147_Write_Block_Register().

Referenced by si114x_set_ucoef(), and Si114xParamSet().

int16_t Si114xNop ( HANDLE  si114x_handle)

Sends a NOP command to the Si113x/4x.

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

Definition at line 190 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_handleThe programmer's toolkit handle
[in]addressThe address of the parameter.
Return values
<0Error
0-255Parameter contents

Definition at line 267 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_handleThe programmer's toolkit handle
[in]addressThe parameter address
[in]valueThe byte value to be written to the Si113x/4x parameter
Return values
0Success
<0Error
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 300 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_handleThe programmer's toolkit handle
Return values
0Success
<0Error

Definition at line 355 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_handleThe programmer's toolkit handle
Return values
0Success
<0Error

Definition at line 250 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_handleThe programmer's toolkit handle
Return values
0Success
<0Error

Definition at line 235 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_handleThe programmer's toolkit handle
Return values
0Success
<0Error

Definition at line 205 of file si114x_functions.c.

int16_t Si114xReadFromRegister ( HANDLE  si114x_handle,
uint8_t  address 
)

Reads from Si114x register.

Parameters
[in]si114x_handleThe programmer toolkit handle.
[in]addressThe register address to read from.
Returns
Returns Value read

Reads from Si114x register.

Definition at line 219 of file si1147_i2c.c.

References Si1147_Read_Register().

Referenced by Si1147_Detect_Device(), Si1147_GetInterruptOutputEnable(), Si1147_MeasureUVAndObjectPresent(), Si1147_NewSample(), si114x_get_calibration(), Si114x_MeasureUVIndex(), si114x_set_ucoef(), 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_handleThe programmer's toolkit handle
Return values
0Success
<0Error

Definition at line 92 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_handleThe programmer toolkit handle.
[in]addressThe register address to write to.
[in]dataThe data to write to the sensor.
Returns
Returns Error status

Writes to Si114x Register.

Definition at line 205 of file si1147_i2c.c.

References Si1147_Write_Register().

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]inputThe 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 557 of file si114x_functions.c.