Si114x reusable functions. More...
#include "si114x_functions.h"
Go to the source code of this file.
Data Structures | |
struct | cal_ref_t |
Structure Definition for calref array. More... | |
struct | operand_t |
The fx20_divide and fx20_multiply uses this structure to pass values into it. More... | |
Defines | |
#define | INCLUDE_SI114X_CALIBRATIONCODE 1 |
INCLUDE_SI114X_CALIBRATIONCODE should be assigned to 1 for the Si1132, Si1145, Si1146 and Si1147. | |
#define | INCLUDE_SI114X_COMPRESS_CODE 1 |
INCLUDE_SI114X_COMPRESS_CODE should be assigned to 1 for the Si1141, Si1142, Si1143. | |
#define | LOOP_TIMEOUT_MS 200 |
#define | FORCE_ROUND_16 1 |
This compile switch used only to experiment with various rounding precisions. | |
Functions | |
static int16_t | _waitUntilSleep (HANDLE si114x_handle) |
Waits until the Si113x/4x is sleeping before proceeding. | |
int16_t | Si114xReset (HANDLE si114x_handle) |
Resets the Si113x/4x, clears any interrupts and initializes the HW_KEY register. | |
static int16_t | _sendCmd (HANDLE si114x_handle, uint8_t command) |
Helper function to send a command to the Si113x/4x. | |
int16_t | Si114xNop (HANDLE si114x_handle) |
Sends a NOP command to the Si113x/4x. | |
int16_t | Si114xPsForce (HANDLE si114x_handle) |
Sends a PSFORCE command to the Si113x/4x. | |
int16_t | Si114xAlsForce (HANDLE si114x_handle) |
Sends an ALSFORCE command to the Si113x/4x. | |
int16_t | Si114xPsAlsForce (HANDLE si114x_handle) |
Sends a PSALSFORCE command to the Si113x/4x. | |
int16_t | Si114xPsAlsAuto (HANDLE si114x_handle) |
Sends a PSALSAUTO 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. | |
static int16_t | _PsAlsPause (HANDLE si114x_handle) |
Pause measurement helper function. | |
int16_t | Si114xPauseAll (HANDLE si114x_handle) |
Pauses autonomous measurements. | |
uint16_t | Uncompress (uint8_t input) |
Converts an 8-bit compressed value to 16-bit. | |
uint8_t | Compress (uint16_t input) |
Converts a 16-bit value to 8-bit value. | |
static uint32_t | decode (uint32_t input) |
Converts the 12-bit factory test value from the Si114x and returns the fixed-point representation of this 12-bit factory test value. | |
static uint32_t | collect (uint8_t *buffer, uint8_t msb_addr, uint8_t lsb_addr, uint8_t alignment) |
The buffer[] is assumed to point to a byte array that containst the factory calibration values after writing 0x12 to the command register This function takes the 12 bytes from the Si114x, then converts it to a fixed point representation, with the help of the decode() function. | |
static void | shift_left (uint32_t *value_p, int8_t shift) |
This performs a shift_left function. | |
static int8_t | align (uint32_t *value_p, int8_t direction) |
Aligns the value pointed by value_p to either the LEFT or RIGHT the number of shifted bits is returned. | |
static void | fx20_round (uint32_t *value_p) |
The fx20_round was designed to perform rounding to however many significant digits. | |
static uint32_t | fx20_divide (struct operand_t *operand_p) |
Returns a fixed-point (20-bit fraction) after dividing op1/op2. | |
static uint32_t | fx20_multiply (struct operand_t *operand_p) |
Returns a fixed-point (20-bit fraction) after multiplying op1*op2. | |
static int16_t | find_cal_index (uint8_t *buffer) |
Due to small differences in factory test setup, the reference calibration values may have slight variation. | |
static uint32_t | vispd_correction (uint8_t *buffer) |
Returns the calibration ratio to be applied to VIS measurements. | |
static uint32_t | irpd_correction (uint8_t *buffer) |
Returns the calibration ratio to be applied to IR measurements. | |
static uint32_t | adcrange_ratio (uint8_t *buffer) |
Returns the ratio to correlate between x_RANGE=0 and x_RANGE=1 It is typically 14.5, but may have some slight component-to-component differences. | |
static uint32_t | irsize_ratio (uint8_t *buffer) |
Returns the ratio to correlate between measurements made from large PD to measurements made from small PD. | |
static uint32_t | ledi_ratio (uint8_t *buffer) |
Returns the ratio to adjust for differences in IRLED drive strength. | |
static int16_t | si114x_get_cal_index (HANDLE si114x_handle, uint8_t *buffer) |
This is a helper function called from si114x_get_calibration() Writes 0x11 to the Command Register, then populates buffer[12] and buffer[13] with the factory calibration index. | |
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. | |
Variables | |
struct cal_ref_t | calref [2] |
Factory Calibration Reference Values. |
Si114x reusable functions.
(C) Copyright 2014 Silicon Labs, http://www.silabs.com
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgement in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.
Definition in file si114x_functions.c.
#define FORCE_ROUND_16 1 |
This compile switch used only to experiment with various rounding precisions.
The flexibility has a small performance price.
Definition at line 934 of file si114x_functions.c.
#define INCLUDE_SI114X_CALIBRATIONCODE 1 |
INCLUDE_SI114X_CALIBRATIONCODE should be assigned to 1 for the Si1132, Si1145, Si1146 and Si1147.
For the Si1141, Si1142 and Si1143, assign it to 0 to save code space.
Definition at line 41 of file si114x_functions.c.
#define INCLUDE_SI114X_COMPRESS_CODE 1 |
INCLUDE_SI114X_COMPRESS_CODE should be assigned to 1 for the Si1141, Si1142, Si1143.
This switch should be assigned to 0 only if it is certain that the code is not used elsewhere.
Definition at line 54 of file si114x_functions.c.
static int16_t _PsAlsPause | ( | HANDLE | si114x_handle | ) | [static] |
Pause measurement helper function.
Definition at line 334 of file si114x_functions.c.
References _sendCmd().
Referenced by Si114xPauseAll().
static int16_t _sendCmd | ( | HANDLE | si114x_handle, | |
uint8_t | command | |||
) | [static] |
Helper function to send a command to the Si113x/4x.
Definition at line 134 of file si114x_functions.c.
References _waitUntilSleep(), delay_1ms(), Si114xReadFromRegister(), and Si114xWriteToRegister().
Referenced by _PsAlsPause(), Si114xAlsForce(), Si114xNop(), Si114xParamRead(), Si114xPsAlsAuto(), Si114xPsAlsForce(), and Si114xPsForce().
static int16_t _waitUntilSleep | ( | HANDLE | si114x_handle | ) | [static] |
Waits until the Si113x/4x is sleeping before proceeding.
Definition at line 62 of file si114x_functions.c.
References delay_1ms(), and Si114xReadFromRegister().
Referenced by _sendCmd(), si114x_get_cal_index(), si114x_get_calibration(), and Si114xParamSet().
static uint32_t adcrange_ratio | ( | uint8_t * | buffer | ) | [static] |
Returns the ratio to correlate between x_RANGE=0 and x_RANGE=1 It is typically 14.5, but may have some slight component-to-component differences.
Definition at line 1146 of file si114x_functions.c.
References fx20_divide(), operand_t::op1, and operand_t::op2.
Referenced by si114x_get_calibration().
static int8_t align | ( | uint32_t * | value_p, | |
int8_t | direction | |||
) | [static] |
Aligns the value pointed by value_p to either the LEFT or RIGHT the number of shifted bits is returned.
The value in value_p is overwritten.
Definition at line 891 of file si114x_functions.c.
References shift_left().
Referenced by fx20_divide(), fx20_multiply(), and fx20_round().
static uint32_t collect | ( | uint8_t * | buffer, | |
uint8_t | msb_addr, | |||
uint8_t | lsb_addr, | |||
uint8_t | alignment | |||
) | [static] |
The buffer[] is assumed to point to a byte array that containst the factory calibration values after writing 0x12 to the command register This function takes the 12 bytes from the Si114x, then converts it to a fixed point representation, with the help of the decode() function.
Definition at line 841 of file si114x_functions.c.
References decode().
static uint32_t decode | ( | uint32_t | input | ) | [static] |
Converts the 12-bit factory test value from the Si114x and returns the fixed-point representation of this 12-bit factory test value.
Definition at line 816 of file si114x_functions.c.
Referenced by collect().
static int16_t find_cal_index | ( | uint8_t * | buffer | ) | [static] |
Due to small differences in factory test setup, the reference calibration values may have slight variation.
This function retrieves the calibration index stored in the Si114x so that it is possible to know which calibration reference values to use.
Definition at line 1062 of file si114x_functions.c.
Referenced by irpd_correction(), ledi_ratio(), si114x_get_calibration(), and vispd_correction().
static uint32_t fx20_divide | ( | struct operand_t * | operand_p | ) | [static] |
Returns a fixed-point (20-bit fraction) after dividing op1/op2.
Definition at line 999 of file si114x_functions.c.
References align(), fx20_round(), operand_t::op1, operand_t::op2, and shift_left().
Referenced by adcrange_ratio(), irpd_correction(), irsize_ratio(), ledi_ratio(), and vispd_correction().
static uint32_t fx20_multiply | ( | struct operand_t * | operand_p | ) | [static] |
Returns a fixed-point (20-bit fraction) after multiplying op1*op2.
Definition at line 1030 of file si114x_functions.c.
References align(), fx20_round(), operand_t::op1, operand_t::op2, and shift_left().
Referenced by si114x_set_ucoef().
static void fx20_round | ( | uint32_t * | value_p | ) | [static] |
The fx20_round was designed to perform rounding to however many significant digits.
However, for the factory calibration code, rounding to 16 always is sufficient. So, the FORCE_ROUND_16 define is provided just in case it would be necessary to dynamically choose how many bits to round to. Rounds the uint32_t value pointed by ptr, by the number of bits specified by round.
Definition at line 947 of file si114x_functions.c.
References align(), and shift_left().
Referenced by fx20_divide(), and fx20_multiply().
static uint32_t irpd_correction | ( | uint8_t * | buffer | ) | [static] |
Returns the calibration ratio to be applied to IR measurements.
Definition at line 1122 of file si114x_functions.c.
References find_cal_index(), fx20_divide(), operand_t::op1, operand_t::op2, and cal_ref_t::sirpd_adclo_irled.
Referenced by si114x_get_calibration().
static uint32_t irsize_ratio | ( | uint8_t * | buffer | ) | [static] |
Returns the ratio to correlate between measurements made from large PD to measurements made from small PD.
Definition at line 1164 of file si114x_functions.c.
References fx20_divide(), operand_t::op1, and operand_t::op2.
Referenced by si114x_get_calibration().
static uint32_t ledi_ratio | ( | uint8_t * | buffer | ) | [static] |
Returns the ratio to adjust for differences in IRLED drive strength.
Note that this does not help with LED irradiance variation.
Definition at line 1183 of file si114x_functions.c.
References find_cal_index(), fx20_divide(), cal_ref_t::ledi_65ma, operand_t::op1, and operand_t::op2.
Referenced by si114x_get_calibration().
static void shift_left | ( | uint32_t * | value_p, | |
int8_t | shift | |||
) | [static] |
This performs a shift_left function.
For convenience, a negative shift value will shift the value right. Value pointed will be overwritten.
Definition at line 873 of file si114x_functions.c.
Referenced by align(), fx20_divide(), fx20_multiply(), and fx20_round().
static int16_t si114x_get_cal_index | ( | HANDLE | si114x_handle, | |
uint8_t * | buffer | |||
) | [static] |
This is a helper function called from si114x_get_calibration() Writes 0x11 to the Command Register, then populates buffer[12] and buffer[13] with the factory calibration index.
Definition at line 1210 of file si114x_functions.c.
References _waitUntilSleep(), delay_1ms(), Si114xBlockRead(), Si114xNop(), Si114xReadFromRegister(), and Si114xWriteToRegister().
Referenced by si114x_get_calibration().
static uint32_t vispd_correction | ( | uint8_t * | buffer | ) | [static] |
Returns the calibration ratio to be applied to VIS measurements.
Definition at line 1100 of file si114x_functions.c.
References find_cal_index(), fx20_divide(), operand_t::op1, operand_t::op2, and cal_ref_t::vispd_adclo_whled.
Referenced by si114x_get_calibration().
{ { FLT_TO_FX20( 4.021290), FLT_TO_FX20(57.528500), FLT_TO_FX20( 2.690010), FLT_TO_FX20( 0.042903), FLT_TO_FX20( 0.633435), FLT_TO_FX20(23.902900), FLT_TO_FX20(56.889300), {0x7B, 0x6B, 0x01, 0x00} }, { FLT_TO_FX20( 2.325484), FLT_TO_FX20(33.541500), FLT_TO_FX20( 1.693750), FLT_TO_FX20( 0.026775), FLT_TO_FX20( 0.398443), FLT_TO_FX20(12.190900), FLT_TO_FX20(56.558200), {0xdb, 0x8f, 0x01, 0x00} } }
Factory Calibration Reference Values.
Definition at line 787 of file si114x_functions.c.