vlx lib
Revision 0:bc9f26b5dadf, committed 2015-02-08
- Comitter:
- vijaynvr
- Date:
- Sun Feb 08 14:26:51 2015 +0000
- Commit message:
- working
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/als_driver.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,482 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/* +''' +Application-level methods used by VL6180X for ALS operations. +''' +*/ + +//# ST libraries +#include "als_driver.h" +#include "debug.h" +#include "platform.h" +#include "utilities.h" + +//----------------------------------------------------------------------------- +// global variable declarations +//----------------------------------------------------------------------------- +static uint16_t _integration_period = DEFAULT_INTEGRATION_PERIOD; +static float_t _lux_resolution = DEFAULT_LUX_RESOLUTION; +static uint32_t _als_scaler = DEFAULT_ALS_SCALER; +static uint32_t _als_real_gain_val = DEFAULT_ALS_GAIN; +//----------------------------------------------------------------------------- +// method definitions +//----------------------------------------------------------------------------- + +sensor_error als_set_dynamic_config(uint8_t device_base_address) +{ +/* + ''' + Device setup for ALS parameters. These settings can be applied at any time. The status of operation bit (bit 0) of the SYSALS_START is not important. + + :rtype: none + ''' +*/ + + LOG_FUNCTION_START((void*)&device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error als_set_systemMode(uint8_t device_base_address, uint8_t mode) +{ + uint8_t startRegVal; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address, (void*)&mode); + switch (mode) + { + case ALS_START_SINGLESHOT: + i2c_write_byte(SYSALS_START, mode, device_base_address); +// i2c_write_byte(SYSALS_START, (uint8_t)ALS_START_SINGLESHOT, I2C_ADDR); + break; + case ALS_START_CONTINUOUS: + // ensure mode bit is set! + startRegVal = i2c_read_byte(SYSALS_START, device_base_address); + startRegVal |= 0x03; + i2c_write_byte(SYSALS_START, startRegVal, device_base_address); + break; + case ALS_STOP: + // ensure mode bit is left unaffected! + startRegVal = i2c_read_byte(SYSALS_START, device_base_address); + startRegVal |= 0x01; + // set the bit, as it is a toggle state, not a 0=Off, 1=ON! + i2c_write_byte(SYSALS_START, startRegVal, device_base_address); + break; + default: + ret = COMMON_INVALID_PARAMS; + } + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t als_get_systemMode(uint8_t device_base_address) +{ + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSALS_START, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint16_t als_get_result(uint8_t device_base_address) +{ + uint16_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_word(RESULT_ALS_VAL, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint16_t als_get_lux(uint8_t device_base_address) +{ + //uint16_t ret=0; + float rawValue = 0.0f; + float integrationTimeRatio = DEFAULT_INTEGRATION_PERIOD/_integration_period; + uint32_t luxValue = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + + rawValue = (float_t)als_get_result(device_base_address); + luxValue = roundFloatToInt(rawValue * integrationTimeRatio * _lux_resolution); + luxValue /= float(_als_scaler * _als_real_gain_val); + + LOG_FUNCTION_END((uint16_t)luxValue); + + return luxValue; +} + +sensor_error als_set_thresholds(uint8_t device_base_address, uint16_t low_threshold, uint16_t high_threshold) +{ + LOG_FUNCTION_START((void*)&device_base_address,(void*)&low_threshold, (void*)&high_threshold); + i2c_write_word(SYSALS_THRESH_LOW, low_threshold, device_base_address); + i2c_write_word(SYSALS_THRESH_HIGH, high_threshold, device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error als_set_high_threshold(uint8_t device_base_address, uint16_t threshold) +{ + LOG_FUNCTION_START((void*)&device_base_address,(void*)&threshold); + i2c_write_word(SYSALS_THRESH_HIGH, threshold, device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint16_t als_get_high_threshold(uint8_t device_base_address) +{ + uint16_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_word(SYSALS_THRESH_HIGH, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error als_set_low_threshold(uint8_t device_base_address, uint16_t threshold) +{ + LOG_FUNCTION_START((void*)&device_base_address,(void*)&threshold); + i2c_write_word(SYSALS_THRESH_LOW, threshold, device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint16_t als_get_low_threshold(uint8_t device_base_address) +{ + LOG_FUNCTION_START((void*)&device_base_address); + uint16_t ret = i2c_read_word(SYSALS_THRESH_LOW, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error als_set_interMeasurement_period(uint8_t device_base_address, uint16_t intermeasurement_period) +{ + LOG_FUNCTION_START((void*)&device_base_address, (void*)&intermeasurement_period); + //clipping: range is 0-2550ms + if (intermeasurement_period >= 255 *10) + intermeasurement_period = 255 *10; + i2c_write_byte(SYSALS_INTERMEASUREMENT_PERIOD, (uint8_t)(intermeasurement_period/10), device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint16_t als_get_interMeasurement_period(uint8_t device_base_address) +{ + uint16_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSALS_INTERMEASUREMENT_PERIOD, device_base_address); + ret *=10; //retun as time in ms + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error als_set_analogue_gain(uint8_t device_base_address, uint8_t light_analogue_gain) +{ + const uint8_t GainDark = 0x40; + uint8_t GainTotal; + + LOG_FUNCTION_START((void*)&device_base_address, (void*)&light_analogue_gain); + if (light_analogue_gain > 7) + { + // ALS_SetAnalogueGainLight: Clipping value to 7 + light_analogue_gain = 7; + } + + GainTotal = GainDark | light_analogue_gain; // add both together + i2c_write_byte(SYSALS_ANALOGUE_GAIN, GainTotal, device_base_address); + + if(light_analogue_gain == 0) + { + _als_real_gain_val = 20.0f; + } + else if(light_analogue_gain == 1) + { + _als_real_gain_val = 10.0f; + } + else if(light_analogue_gain == 2) + { + _als_real_gain_val = 5.0f; + } + else if(light_analogue_gain == 3) + { + _als_real_gain_val = 2.5f; + } + else if(light_analogue_gain == 4) + { + _als_real_gain_val = 1.67f; + } + else if(light_analogue_gain == 5) + { + _als_real_gain_val = 1.25; + } + else if(light_analogue_gain == 6) + { + _als_real_gain_val = 1.0; + } + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint8_t als_get_analogue_gain(uint8_t device_base_address) +{ + int8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSALS_ANALOGUE_GAIN, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error als_set_integration_period(uint8_t device_base_address, uint16_t integration_period) +{ + int myTime; + + LOG_FUNCTION_START((void*)&device_base_address, (void*)&integration_period); + + myTime = integration_period - 1; + + if (myTime < 0) + { + myTime = 0; + } + else if (myTime > 464) + { + // ALS_SetIntegrationPeriod: Clipping value to 465ms + myTime = 464; + } + else if (myTime == 255) + { + myTime++; + // can't write 255 since this causes the device to lock out. + } + + i2c_write_word(SYSALS_INTEGRATION_PERIOD, myTime, device_base_address); + + _integration_period = myTime; + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint16_t als_get_integration_period(uint8_t device_base_address) +{ + LOG_FUNCTION_START((void*)&device_base_address); + uint16_t intTime = i2c_read_word(SYSALS_INTEGRATION_PERIOD, device_base_address); + intTime +=1; + + _integration_period = intTime; + + LOG_FUNCTION_END(intTime); + + return intTime; +} + + +uint8_t als_get_result_status(uint8_t device_base_address) +{ + LOG_FUNCTION_START((void*)&device_base_address); + uint8_t resultStatus = i2c_read_byte(RESULT_ALS_STATUS, device_base_address); + LOG_FUNCTION_END(resultStatus); + + return resultStatus; +} + +bool_t als_get_device_ready(uint8_t device_base_address) +{ + bool_t deviceReady = FALSE; + + LOG_FUNCTION_START((void*)&device_base_address); + if ((i2c_read_byte(RESULT_ALS_STATUS, device_base_address) & ALS_DEVICE_READY) == ALS_DEVICE_READY) + { + deviceReady = TRUE; + } + LOG_FUNCTION_END(deviceReady); + + return deviceReady; +} + +uint8_t als_get_result_error_codes(uint8_t device_base_address) +{ + LOG_FUNCTION_START((void*)&device_base_address); + uint8_t errorCode = (i2c_read_byte(RESULT_ALS_STATUS, device_base_address) & 0xF0) >> 4; + LOG_FUNCTION_END(errorCode); + + return errorCode; +} + + +sensor_error als_set_interleaved_mode(uint8_t device_base_address) +{ + LOG_FUNCTION_START((void*)&device_base_address); + i2c_write_byte(INTERLEAVED_MODE_ENABLE, 1, device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error als_clear_interleaved_mode(uint8_t device_base_address) +{ + LOG_FUNCTION_START((void*)&device_base_address); + i2c_write_byte(INTERLEAVED_MODE_ENABLE, 0, device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint8_t als_get_interleaved_mode(uint8_t device_base_address) +{ + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(INTERLEAVED_MODE_ENABLE, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +/////////////////////// + +sensor_error als_set_system_interrupt_config_gpio(uint8_t device_base_address, uint8_t ALS_GPIO_interrupt_config) +{ + uint8_t cmd, reg; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address, (void*)&ALS_GPIO_interrupt_config); + switch (ALS_GPIO_interrupt_config) + { + case CONFIG_GPIO_INTERRUPT_DISABLED: + case CONFIG_GPIO_INTERRUPT_LEVEL_LOW: + case CONFIG_GPIO_INTERRUPT_LEVEL_HIGH: + case CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW: + case CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY: + cmd = ALS_GPIO_interrupt_config << 3; // shift command upto bits [5:3] + reg = i2c_read_byte(SYSTEM_INTERRUPT_CONFIG_GPIO, device_base_address); + reg &= 0x07; // preserve only the range part of the reg + i2c_write_byte(SYSTEM_INTERRUPT_CONFIG_GPIO, (reg | cmd), device_base_address); + _integration_period = als_get_integration_period(device_base_address); + break; + default : + ret = COMMON_INVALID_PARAMS; + break; + } + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t als_get_system_interrupt_config_gpio(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + //# expose only bits [5:3], then shift down 3 places + ret = ( (i2c_read_byte(SYSTEM_INTERRUPT_CONFIG_GPIO, device_base_address) & 0x38) >> 3 ); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t als_get_result_interrupt_status_gpio(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = ( (i2c_read_byte(RESULT_INTERRUPT_STATUS_GPIO, device_base_address) & 0x38) >> 3 ); + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error als_set_system_interrupt_clear(uint8_t device_base_address) +{ + + LOG_FUNCTION_START((void*)&device_base_address); + i2c_write_byte(SYSTEM_INTERRUPT_CLEAR, INTERRUPT_CLEAR_ALS, device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error als_set_history_buffer_mode_enable(uint8_t device_base_address) +{ + uint8_t mode; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address); + + mode = i2c_read_byte(SYSTEM_HISTORY_CTRL, device_base_address); + mode = mode | 0x03; // set bits 0 and 1 to set to ALS mode and enable + i2c_write_byte(SYSTEM_HISTORY_CTRL, mode, device_base_address); + + LOG_FUNCTION_END(NULL); + + return ret; +} + +sensor_error als_set_scaler(uint8_t device_base_address, uint8_t scaler) +{ + const uint32_t cMask = 0x0f; + + LOG_FUNCTION_START((void*)&device_base_address); + + _als_scaler = (uint32_t)scaler & cMask; + i2c_write_byte(FW_ALS_RESULT_SCALER, (uint8_t)_als_scaler, device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint32_t als_get_scaler(uint8_t device_base_address) +{ + const uint32_t cMask = 0x0f; + + LOG_FUNCTION_START((void*)&device_base_address); + + _als_scaler = (uint32_t)i2c_read_byte(FW_ALS_RESULT_SCALER, device_base_address) & cMask; + + LOG_FUNCTION_END(_als_scaler); + + return _als_scaler; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/als_driver.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,351 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/*! + *\file als_driver.h + *\brief Application-level methods used by VL6180X for ALS operations. + */ + +#ifndef _ALS_DRIVER +#define _ALS_DRIVER + +#include "definitions.h" +#include "common_driver.h" + +//----------------------------------------------------------------------------- +// constant definitions +//---------------------------------------------------------------------------- + +// registers addresses +#define IDENTIFICATION_MODEL_ID 0x00 +#define IDENTIFICATION_FIRMWARE_REVISION_ID 0x0B +#define IDENTIFICATION_MODULE_REV_MAJOR 0x03 +#define IDENTIFICATION_MODULE_REV_MINOR 0x04 + +#define SYSALS_START 0x38 +#define SYSALS_THRESH_HIGH 0x3A +#define SYSALS_THRESH_LOW 0x3C +#define SYSALS_INTERMEASUREMENT_PERIOD 0x3E +#define SYSALS_ANALOGUE_GAIN 0x3F +#define SYSALS_INTEGRATION_PERIOD 0x40 + +#define RESULT_ALS_STATUS 0x4E +#define RESULT_ALS_VAL 0x50 + +#define INTERLEAVED_MODE_ENABLE 0x2A3 + + +// SYSALS_START +#define ALS_START_SINGLESHOT 0x01 // bit 0 set / bit 1 clear +#define ALS_START_CONTINUOUS 0x03 // bit 0 set / bit 1 set +#define ALS_STOP 0x00 // bit 0 set / bit 1 don't care + +// RESULT_ALS_STATUS +#define ALS_DEVICE_READY 0x01 +#define ALS_ERROR_CODE 0xF0 // covers bits [7:4] +#define FW_ALS_RESULT_SCALER 0x120 + + +#define DEFAULT_INTEGRATION_PERIOD 0x64 +#define DEFAULT_LUX_RESOLUTION 0.56f +#define DEFAULT_ALS_SCALER 1 +#define DEFAULT_ALS_GAIN 20 +/** + * @brief This data type defines range measurment data. + */ +typedef struct +{ + float_t lux; + /**< Light measurement (Lux) */ + + uint32_t errorStatus; + /**< Error status of the current measurement. \n + * No Error := 0. \n + * Refer to product sheets for other error codes. */ +}sensor_AlsData; + + +/*! + * + *\brief Device setup for ALS parameters. These settings can be applied at any time. The status of operation bit (bit 0) of the SYSALS_START is not important. + *\param[in] device_base_address + *\retval sensor_error + */ +sensor_error als_set_dynamic_config(uint8_t device_base_address); + +/*! + *\brief Set Mode and Operation commands in the SYSALS_START register. + * + * Possible combinations are : \n + * ALS_START_SINGLESHOT 0x01 (bit 0 set / bit 1 clear) \n + * ALS_START_CONTINUOUS 0x03 (bit 0 set / bit 1 set) \n + * ALS_STOP 0x01 (bit 0 set / bit 1 don't care) \n + *\param[in] device_base_address + *\param[in] mode Mode select/operation command to be written to the SYSALS_START register. + *\retval sensor_error + */ +sensor_error als_set_systemMode(uint8_t device_base_address, uint8_t mode); + +/*! + *\brief Report status of ALS mode-select and Stop/Start. + * + * Returns a reading of the SYSALS_START register. \n + * Possible results are : \n + * ALS_START_SINGLESHOT 0x01 (bit 0 set / bit 1 clear) \n + * ALS_START_CONTINUOUS 0x03 (bit 0 set / bit 1 set) \n + * ALS_STOP 0x01 (bit 0 set / bit 1 don't care) \n + *\param[in] device_base_address + *\retval uint8_t (unsigned, byte-wide integer) + */ +uint8_t als_get_systemMode(uint8_t device_base_address); + +/*! + *\brief Report 16-bit result from last ALS operation. + * + * Accesses the RESULT_ALS_VAL register, to report the latest ALS raw measurement. + *\param[in] device_base_address + *\retval uint16_t (unsigned, word-wide integer) + */ +uint16_t als_get_result(uint8_t device_base_address); + +/*! + *\brief Report 16-bit result from last ALS operation. + * + * Reads the latest ALS measurement and reports to the calling operation in LUX. + *\param[in] device_base_address + *\retval uint16_t (unsigned, word-wide integer) + */ +uint16_t als_get_lux(uint8_t device_base_address); + +/*! + *\brief Set min/max ALS thresholds (units?) in SYSALS_THRESH_LOW & SYSALS_THRESH_HIGH registers. + *\param[in] device_base_address + *\param[in] low_threshold Byte-wide, integer, ALS low threshold to be written to the SYSALS_THRESH_LOW register. + *\param[in] high_threshold Byte-wide, integer, ALS high threshold to be written to the SYSALS_THRESH_HIGH register. + *\retval sensor_error + */ +sensor_error als_set_thresholds(uint8_t device_base_address, uint16_t low_threshold, uint16_t high_threshold); + +/*! + *\brief Set ALS high threshold the SYSALS_THRESH_HIGH register. + *\param[in] device_base_address + *\param[in] threshold Word-wide, integer, ALS high threshold to be written to the SYSALS_THRESH_HIGH register. + *\retval sensor_error + */ +sensor_error als_set_high_threshold(uint8_t device_base_address, uint16_t threshold); + +/*! + *\brief Report ALS high threshold from the SYSALS_THRESH_HIGH register. + *\param[in] device_base_address + *\retval uint16_t (unsigned, word-wide integer) + */ +uint16_t als_get_high_threshold(uint8_t device_base_address); + +/*! + *\brief Set ALS low threshold the SYSALS_THRESH_LOW register. + *\param[in] device_base_address + *\param[in] threshold ALS low threshold to be written to the SYSALS_THRESH_LOW register. + *\retval sensor_error + */ +sensor_error als_set_low_threshold(uint8_t device_base_address, uint16_t threshold); + +/*! + *\brief Report ALS low threshold from the SYSALS_THRESH_LOW register. + *\param[in] device_base_address + *\retval uint16_t (unsigned, word-wide integer) + */ +uint16_t als_get_low_threshold(uint8_t device_base_address); + +/*! + *\brief Set ALS intermeasurement period in the SYSALS_INTERMEASUREMENT_PERIOD register. + * + * Range 10ms-2.55s, 1 code = 10 ms, code 0 = 10ms + *\param[in] device_base_address + *\param[in] intermeasurement_period: Time delay in ms between measurements in continuous-ALS mode. + *\retval sensor_error + */ +sensor_error als_set_interMeasurement_period(uint8_t device_base_address, uint16_t intermeasurement_period); + +/*! + *\brief Report ALS intermeasurement period from the SYSALS_INTERMEASUREMENT_PERIOD register. + * + * Range 0-2.55s, 1 code = 10 ms + *\param[in] device_base_address + *\retval an 16-bit integer as time in ms. + */ +uint16_t als_get_interMeasurement_period(uint8_t device_base_address); + +/*! + *\brief Set dark/light ALS analogue gains in the SYSALS_ANALOGUE_GAIN register. + * + * Light gain will be clipped to a maximum value of 7. \n + * Dark Gain is frozen at 4. \n + * + * [2:0] sysals_analogue_gain_light: ALS analogue gain (light channel) \n + * 0: ALS Gain = 20 \n + * 1: ALS Gain = 10 \n + * 2: ALS Gain = 5.0 \n + * 3: ALS Gain = 2.5 \n + * 4: ALS Gain = 1.67 \n + * 5: ALS Gain = 1.25 \n + * 6: ALS Gain = 1.0 \n + * 7: ALS Gain = 40 (testmode) \n + *\param[in] device_base_address + *\param[in] light_analogue_gain light gain + *\retval sensor_error + */ +sensor_error als_set_analogue_gain(uint8_t device_base_address, uint8_t light_analogue_gain); + +/*! + *\brief Report ALS analogue gain from the SYSALS_ANALOGUE_GAIN register. + *\param[in] device_base_address + *\retval an 8-bit integer. + */ +uint8_t als_get_analogue_gain(uint8_t device_base_address); + +/*! + *\brief Set ALS Integration Period in the SYSALS_INTEGRATION_PERIOD register. + *\param[in] device_base_address + *\param[in] integration_period Integration period for ALS mode, in ms. 1 code = 1ms [codes (0:464) == (1ms:465ms)] + *\retval sensor_error + */ +sensor_error als_set_integration_period(uint8_t device_base_address, uint16_t integration_period); + +/*! + *\brief Report ALS Integration Period from the SYSALS_INTEGRATION_PERIOD register. + *\param[in] device_base_address + *\retval a 16-bit integer. + */ +uint16_t als_get_integration_period(uint8_t device_base_address); + +/*! + *\brief Report ALS Result Status from RESULT_ALS_STATUS register. + *\param[in] device_base_address + *\retval an 8-bit integer. + */ +uint8_t als_get_result_status(uint8_t device_base_address); + +/*! + *\brief Report result_ALS_device_ready status in the ALS_RANGE_STATUS register. + *\param[in] device_base_address + *\retval True if the result_ALS_device_ready bit in the RESULT_ALS_STATUS register is set, otherwise False. + */ +bool_t als_get_device_ready(uint8_t device_base_address); + +/*! + *\brief Report ALS Result Error Codes from RESULT_ALS_STATUS register. + *\param[in] device_base_address + *\retval an 8-bit integer. + */ +uint8_t als_get_result_error_codes(uint8_t device_base_address); + +/*! + *\brief Enable Interleaved Mode. + *\param[in] device_base_address + *\retval sensor_error + */ +sensor_error als_set_interleaved_mode(uint8_t device_base_address); + +/*! + *\brief Disable Interleaved Mode. + *\param[in] device_base_address + *\retval sensor_error + */ +sensor_error als_clear_interleaved_mode(uint8_t device_base_address); + +/*! + *\brief Report Interleaved Mode. + *\param[in] device_base_address + *\retval an 8-bit integer. + */ +uint8_t als_get_interleaved_mode(uint8_t device_base_address); + +/*! + *\brief Set System Interrupt Config GPIO for ALS operations. + + Returns True a valid command was completed successfully, otherwise False.\n + Possible settings are :\n + CONFIG_GPIO_INTERRUPT_DISABLED = 0x00 \n + CONFIG_GPIO_INTERRUPT_LEVEL_LOW = 0x01 \n + CONFIG_GPIO_INTERRUPT_LEVEL_HIGH = 0x02 \n + CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW = 0x03 \n + CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY = 0x04 \n + *\param[in] device_base_address + *\param[in] ALS_GPIO_interrupt_config: + *\retval sensor_error +*/ +sensor_error als_set_system_interrupt_config_gpio(uint8_t device_base_address, uint8_t ALS_GPIO_interrupt_config); + +/*! + *\brief Report System Interrupt Config GPIO ALS. + + Returns the ALS-only portion of the SYSTEM_INTERRUPT_CONFIG_GPIO register.\n + Possible returns are : \n + CONFIG_GPIO_INTERRUPT_DISABLED = 0x00 \n + CONFIG_GPIO_INTERRUPT_LEVEL_LOW = 0x01 \n + CONFIG_GPIO_INTERRUPT_LEVEL_HIGH = 0x02 \n + CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW = 0x03 \n + CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY = 0x04 \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t als_get_system_interrupt_config_gpio(uint8_t device_base_address); + +/*! + *\brief Report GPIO Interrupt Result Status for an ALS operation. + + Returns the ALS-only portion of the RESULT_INTERRUPT_STATUS_GPIO register.\n + Possible returns are : \n + 0: No threshold events reported \n + 1: Level Low threshold event \n + 2: Level High threshold event \n + 3: Out Of Window threshold event \n + 4: New Sample Ready threshold event \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t als_get_result_interrupt_status_gpio(uint8_t device_base_address); + + +/*! + *\brief Clear ALS System Interrupt. + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error als_set_system_interrupt_clear(uint8_t device_base_address); + +/*! + *\brief Set history buffer to ALS mode and enable. + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error als_set_history_buffer_mode_enable(uint8_t device_base_address); + +sensor_error Get_ALS_History_Buffer(uint8_t device_base_address); + +sensor_error als_set_scaler(uint8_t device_base_address, uint8_t scaler); + +uint32_t als_get_scaler(uint8_t device_base_address); + +#endif + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common_driver.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,890 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/* + ''' + Application-level methods used for generic, system or identification operations. + ''' +*/ + +//----------------------------------------------------------------------------- +// module imports +//----------------------------------------------------------------------------- +#include "debug.h" +#include "common_driver.h" +#include "ranging_driver.h" + +//----------------------------------------------------------------------------- +// global variable declarations +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// method definitions +//----------------------------------------------------------------------------- + +sensor_error common_initialise(uint8_t device_base_address) +{ + + LOG_FUNCTION_START((void*)&device_base_address); + + i2c_initialise(device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error common_set_static_config(uint8_t device_base_address) +{ + int8_t reset; + + LOG_FUNCTION_START((void*)&device_base_address); + reset = i2c_read_byte(0x016, device_base_address); + if (reset==1) + { + // check to see has it be Initialised already + //REGISTER_TUNING_SR03_270514_CustomerView.txt + + // Mandatory : private registers + i2c_write_byte(0x0207, 0x01, device_base_address); + i2c_write_byte(0x0208, 0x01, device_base_address); + i2c_write_byte(0x0096, 0x00, device_base_address); + i2c_write_byte(0x0097, 0xfd, device_base_address); + i2c_write_byte(0x00e3, 0x00, device_base_address); + i2c_write_byte(0x00e4, 0x04, device_base_address); + i2c_write_byte(0x00e5, 0x02, device_base_address); + i2c_write_byte(0x00e6, 0x01, device_base_address); + i2c_write_byte(0x00e7, 0x03, device_base_address); + i2c_write_byte(0x00f5, 0x02, device_base_address); + i2c_write_byte(0x00d9, 0x05, device_base_address); + i2c_write_byte(0x00db, 0xce, device_base_address); + i2c_write_byte(0x00dc, 0x03, device_base_address); + i2c_write_byte(0x00dd, 0xf8, device_base_address); + i2c_write_byte(0x009f, 0x00, device_base_address); + i2c_write_byte(0x00a3, 0x3c, device_base_address); + i2c_write_byte(0x00b7, 0x00, device_base_address); + i2c_write_byte(0x00bb, 0x3c, device_base_address); + i2c_write_byte(0x00b2, 0x09, device_base_address); + i2c_write_byte(0x00ca, 0x09, device_base_address); + i2c_write_byte(0x0198, 0x01, device_base_address); + i2c_write_byte(0x01b0, 0x17, device_base_address); + i2c_write_byte(0x01ad, 0x00, device_base_address); + i2c_write_byte(0x00ff, 0x05, device_base_address); + i2c_write_byte(0x0100, 0x05, device_base_address); + i2c_write_byte(0x0199, 0x05, device_base_address); + i2c_write_byte(0x01a6, 0x1b, device_base_address); + i2c_write_byte(0x01ac, 0x3e, device_base_address); + i2c_write_byte(0x01a7, 0x1f, device_base_address); + i2c_write_byte(0x0030, 0x00, device_base_address); + + // Recommended : Public registers - See data sheet for more detail + i2c_write_byte(0x0011, 0x10, device_base_address); // Enables polling for ¡®New Sample ready¡¯ when measurement completes + i2c_write_byte(0x010a, 0x30, device_base_address); // Set the averaging sample period (compromise between lower noise and increased execution time) + i2c_write_byte(0x003f, 0x46, device_base_address); // Sets the light and dark gain (upper nibble). Dark gain should not be changed. + i2c_write_byte(0x0031, 0xFF, device_base_address); // sets the # of range measurements after which auto calibration of system is performed + i2c_write_byte(0x0040, 0x63, device_base_address); // Set ALS integration time to 100ms + i2c_write_byte(0x002e, 0x01, device_base_address); // perform a single temperature calibration of the ranging sensor + + // Optional: Public registers - See data sheet for more detail + i2c_write_byte(0x001b, 0x09, device_base_address); // Set default ranging inter-measurement period to 100ms + i2c_write_byte(0x003e, 0x31, device_base_address); // Set default ALS inter-measurement period to 500ms + i2c_write_byte(0x0014, 0x24, device_base_address); // Configures interrupt on ¡®New sample ready¡¯ + + // extra stuff + i2c_write_byte(0x016, 0x00, device_base_address); // change fresh out of set status to 0 + + } + + // VHV automatically run on parts that are NVM-programmed, ie customer parts! + + range_set_max_convergence_time(device_base_address, 50); // Calculate ece value on initialisation (use max conv) + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error common_get_identification(uint8_t device_base_address) +{ +/* + return_list = [] + + # I2C base address is 8-bit indexing + I2C_base_address = I2C_ReadReg_CCI(I2C_SLAVE_DEVICE_ADDRESS, I2C_ADDR); + I2C_base_address *= 2 # convert from 7-bit to 8-bit address + + # reading from indices 0x00-0x0B + regs = Utilities.device.comms['read'](I2C_base_address, 0x00, 0x0C) + + identification_model_id = regs[0x00] + identification_model_rev_major = regs[0x01] + identification_model_rev_minor = regs[0x02] + identification_module_rev_major = regs[0x03] + identification_module_rev_minor = regs[0x04] + identification_nvm_revision_id = regs[0x05] & 0x0F + identification_mask_revision_id = (regs[0x05] & 0xF0) >> 4 + identification_month = regs[0x06] & 0x0F + identification_year = (regs[0x06] & 0xF0) >> 4 + identification_phase = regs[0x07] & 0x0F + identification_day = (regs[0x07] & 0xF0) >> 4 + identification_time = (regs[0x08] << 8) + regs[0x09] + identification_code = regs[0x0A] + firmware_revision_id = regs[0x0B] + + return_list.append( identification_model_id ) + return_list.append( identification_model_rev_major ) + return_list.append( identification_model_rev_minor ) + return_list.append( identification_module_rev_major ) + return_list.append( identification_module_rev_minor ) + return_list.append( identification_nvm_revision_id ) + return_list.append( identification_mask_revision_id ) + return_list.append( identification_month ) + return_list.append( identification_year ) + return_list.append( identification_phase ) + return_list.append( identification_day ) + return_list.append( identification_time ) + return_list.append( identification_code ) + return_list.append( firmware_revision_id ) + return return_list +*/ + return SENSOR_ERROR_NONE; +} + + +sensor_error common_set_i2c_base_address(uint8_t device_base_address, uint32_t new_i2c_base_address) +{ + //# reduce 8-bit address to a 7-bit address + LOG_FUNCTION_START((void*)&device_base_address,(void*)&new_i2c_base_address); + + i2c_write_byte(I2C_SLAVE_DEVICE_ADDRESS, (new_i2c_base_address >> 1), device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error common_set_i2c_pad_voltage(uint8_t device_base_address, uint8_t pad_voltage) +{ + uint8_t padConfigReg; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&pad_voltage); + + padConfigReg = i2c_read_byte(PAD_I2C_CONFIG, device_base_address); + if (pad_voltage == I2C_1v2_PAD_VOLTAGE) + { + i2c_write_byte(PAD_I2C_CONFIG, (padConfigReg & 0xFE), device_base_address); // clear bit 0 + } + + if (pad_voltage == I2C_2v8_PAD_VOLTAGE) + { + i2c_write_byte(PAD_I2C_CONFIG, (padConfigReg & 0x01), device_base_address); // set bit 0 + } + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint8_t common_get_i2c_pad_voltage(uint8_t device_base_address) +{ + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + + if (!(i2c_read_byte(PAD_I2C_CONFIG, device_base_address) & 0xFE)) // test that bit 0 is clear! + { + ret = I2C_1v2_PAD_VOLTAGE; + } + else if (i2c_read_byte(PAD_I2C_CONFIG, device_base_address) & 0x01) // test that bit 0 is set! + { + ret = I2C_2v8_PAD_VOLTAGE; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_system_mode_gpio0(uint8_t device_base_address, uint8_t mode, uint8_t select, uint8_t polarity) +{ + uint8_t gpioModeReg; + uint8_t gpio_select; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&mode, (void*)&select, (void*)&polarity); + + switch (select) + { + case GPIOx_SELECT_OFF : + case GPIOx_SELECT_MEASURE_READY : + case GPIOx_SELECT_DISABLED : + case GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT : + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address); + gpioModeReg = gpioModeReg & 0x21; // preserve only the mode & polarity bits from the register contents! + gpio_select = select << 1; // move up 1 bit, to make mask for bits 1-4 + + i2c_write_byte(SYSTEM_MODE_GPIO0, + (gpioModeReg | gpio_select), + device_base_address); + break; + default : + ret = COMMON_INVALID_PARAMS; + break; + } + + if ((mode == GPIOx_MODE_SELECT_RANGING) || (mode == GPIOx_MODE_SELECT_ALS)) + { + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address); + i2c_write_byte(SYSTEM_MODE_GPIO0, + (gpioModeReg | mode), + device_base_address); + } + else + { + ret = COMMON_INVALID_PARAMS; + } + + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address); + if (polarity == GPIOx_POLARITY_SELECT_OFF) + { + i2c_write_byte(SYSTEM_MODE_GPIO0, + (gpioModeReg & GPIOx_POLARITY_SELECT_CLEARED), + device_base_address); + } + else if (polarity == GPIOx_POLARITY_SELECT_ON) + { + i2c_write_byte(SYSTEM_MODE_GPIO0, + (gpioModeReg | GPIOx_POLARITY_SELECT), + device_base_address); + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_gpio0_mode(uint8_t device_base_address, uint8_t mode) +{ + uint8_t gpioModeReg; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&mode); + + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address); + if ((mode == GPIOx_MODE_SELECT_RANGING) || (mode == GPIOx_MODE_SELECT_ALS)) + { + i2c_write_byte(SYSTEM_MODE_GPIO0, (gpioModeReg | mode), device_base_address); + } + else + { + ret = COMMON_INVALID_PARAMS; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t common_get_gpio0_mode(uint8_t device_base_address) +{ + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + + if (i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address) & GPIOx_MODE_SELECT) + { + ret = 1; + } + else + { + ret = 0; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_gpio0_select(uint8_t device_base_address, uint8_t select) +{ + uint8_t gpio_select; + uint8_t gpioModeReg; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&select); + + switch (select) + { + case GPIOx_SELECT_OFF: + case GPIOx_SELECT_MEASURE_READY: + case GPIOx_SELECT_THRESHOLD_OUTPUT: + case GPIOx_SELECT_BLANK_IN: + case GPIOx_SELECT_BLANK_OUT: + case GPIOx_SELECT_START_STOP: + case GPIOx_SELECT_DISABLED: + case GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT: + case GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT: + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address); + gpio_select = select << 1; // move up 1 bit, to make mask for bits 1-4 + i2c_write_byte(SYSTEM_MODE_GPIO0, (gpioModeReg | gpio_select), device_base_address); + break; + default : + ret = COMMON_INVALID_PARAMS; + break; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t common_get_gpio0_select(uint8_t device_base_address) +{ + uint8_t gpioModeReg; + uint8_t gpio_select; + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address); + gpio_select = (gpioModeReg & 0x1E) >> 1; // mask only bits 1-4 + switch (gpio_select) + { + case GPIOx_SELECT_OFF: + ret = GPIOx_SELECT_OFF; + break; + case GPIOx_SELECT_MEASURE_READY: + ret = GPIOx_SELECT_MEASURE_READY; + break; + case GPIOx_SELECT_THRESHOLD_OUTPUT: + ret = GPIOx_SELECT_THRESHOLD_OUTPUT; + break; + case GPIOx_SELECT_BLANK_IN: + ret = GPIOx_SELECT_BLANK_IN; + break; + case GPIOx_SELECT_BLANK_OUT: + ret = GPIOx_SELECT_BLANK_OUT; + break; + case GPIOx_SELECT_START_STOP: + ret = GPIOx_SELECT_START_STOP; + break; + case GPIOx_SELECT_DISABLED: + ret = GPIOx_SELECT_DISABLED; + break; + case GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT: + ret = GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT; + break; + case GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT: + ret = GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT; + break; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_gpio0_polarity(uint8_t device_base_address, uint8_t polarity) +{ + uint8_t gpioModeReg; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*) &polarity); + + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address); + if (polarity == GPIOx_POLARITY_SELECT_OFF) + { + i2c_write_byte(SYSTEM_MODE_GPIO0, + (gpioModeReg & GPIOx_POLARITY_SELECT_CLEARED), + device_base_address); + } + else if (polarity == GPIOx_POLARITY_SELECT_ON) + i2c_write_byte(SYSTEM_MODE_GPIO0, (gpioModeReg | GPIOx_POLARITY_SELECT), device_base_address); + else + ret = COMMON_INVALID_PARAMS; + + LOG_FUNCTION_END(ret); + + return ret; +} + +bool_t common_get_gpio0_polarity(uint8_t device_base_address) +{ + bool_t ret=FALSE; + + LOG_FUNCTION_START((void*)&device_base_address); + + if (i2c_read_byte(SYSTEM_MODE_GPIO0, device_base_address) & GPIOx_POLARITY_SELECT) + ret = TRUE; + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_system_mode_gpio1(uint8_t device_base_address, uint8_t mode, uint8_t select, uint8_t polarity) +{ + uint8_t gpioModeReg; + uint8_t gpio_select; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&mode,(void*)&select,(void*)&polarity); + + switch (select) + { + case GPIOx_SELECT_OFF : + case GPIOx_SELECT_MEASURE_READY : + case GPIOx_SELECT_DISABLED : + case GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT : + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address); + gpioModeReg = gpioModeReg & 0x21; // preserve only the mode & polarity bits from the register contents! + gpio_select = select << 1; // move up 1 bit, to make mask for bits 1-4 + i2c_write_byte(SYSTEM_MODE_GPIO1, (gpioModeReg | gpio_select), device_base_address); + break; + default : + ret = COMMON_INVALID_PARAMS; + break; + } + + if ((mode == GPIOx_MODE_SELECT_RANGING) || (mode == GPIOx_MODE_SELECT_ALS)) + { + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address); + i2c_write_byte(SYSTEM_MODE_GPIO1, + (gpioModeReg | mode), + device_base_address); + } + else + { + ret = COMMON_INVALID_PARAMS; + } + + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address); + + if (polarity == GPIOx_POLARITY_SELECT_OFF) + { + i2c_write_byte(SYSTEM_MODE_GPIO1, + (gpioModeReg & GPIOx_POLARITY_SELECT_CLEARED), + device_base_address); + } + + if (polarity == GPIOx_POLARITY_SELECT_ON) + { + i2c_write_byte(SYSTEM_MODE_GPIO1, + (gpioModeReg | GPIOx_POLARITY_SELECT), + device_base_address); + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_gpio1_mode(uint8_t device_base_address, uint8_t mode) +{ + uint8_t gpioModeReg; + sensor_error ret = COMMON_INVALID_PARAMS; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&mode); + + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address); + + if ((mode == GPIOx_MODE_SELECT_RANGING) || (mode == GPIOx_MODE_SELECT_ALS)) + { + i2c_write_byte(SYSTEM_MODE_GPIO1, + (gpioModeReg | mode), + device_base_address); + ret = SENSOR_ERROR_NONE; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t common_get_gpio1_mode(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + + if (i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address) & GPIOx_MODE_SELECT) + { + ret = 1; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_gpio1_select(uint8_t device_base_address, uint8_t select) +{ + uint8_t gpio_select; + uint8_t gpioModeReg; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&select); + + switch (select) + { + case GPIOx_SELECT_OFF: + case GPIOx_SELECT_MEASURE_READY: + case GPIOx_SELECT_THRESHOLD_OUTPUT: + case GPIOx_SELECT_BLANK_IN: + case GPIOx_SELECT_BLANK_OUT: + case GPIOx_SELECT_START_STOP: + case GPIOx_SELECT_DISABLED: + case GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT: + case GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT: + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address); + gpio_select = select << 1; // move up 1 bit, to make mask for bits 1-4 + i2c_write_byte(SYSTEM_MODE_GPIO1, + (gpioModeReg | gpio_select), + device_base_address); + break; + default: + ret = COMMON_INVALID_PARAMS; + break; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t common_get_gpio1_select(uint8_t device_base_address) +{ + uint8_t gpio_select; + uint8_t gpioModeReg; + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address); + + gpio_select = (gpioModeReg & 0x1E) >> 1; // mask only bits 1-4 + + switch (gpio_select) + { + case GPIOx_SELECT_OFF: + ret = GPIOx_SELECT_OFF; + break; + case GPIOx_SELECT_MEASURE_READY: + ret = GPIOx_SELECT_MEASURE_READY; + break; + case GPIOx_SELECT_THRESHOLD_OUTPUT: + ret = GPIOx_SELECT_THRESHOLD_OUTPUT; + break; + case GPIOx_SELECT_BLANK_IN: + ret = GPIOx_SELECT_BLANK_IN; + break; + case GPIOx_SELECT_BLANK_OUT: + ret = GPIOx_SELECT_BLANK_OUT; + break; + case GPIOx_SELECT_START_STOP: + ret = GPIOx_SELECT_START_STOP; + break; + case GPIOx_SELECT_DISABLED: + ret = GPIOx_SELECT_DISABLED; + break; + case GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT: + ret = GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT; + break; + case GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT: + ret = GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT; + break; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_gpio1_polarity(uint8_t device_base_address, uint8_t polarity) +{ + uint8_t gpioModeReg; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&polarity); + + gpioModeReg = i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address); + + if (polarity == GPIOx_POLARITY_SELECT_OFF) + { + i2c_write_byte(SYSTEM_MODE_GPIO1, + (gpioModeReg & GPIOx_POLARITY_SELECT_CLEARED), + device_base_address); + } + else if (polarity == GPIOx_POLARITY_SELECT_ON) + { + i2c_write_byte(SYSTEM_MODE_GPIO1, + (gpioModeReg | GPIOx_POLARITY_SELECT), + device_base_address); + } + else + { + ret = COMMON_INVALID_PARAMS; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +bool_t common_get_gpio1_polarity(uint8_t device_base_address) +{ + bool_t ret= FALSE; + + LOG_FUNCTION_START((void*)&device_base_address); + + if (i2c_read_byte(SYSTEM_MODE_GPIO1, device_base_address) & GPIOx_POLARITY_SELECT) + { + ret = TRUE; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_history_buffer_enable(uint8_t device_base_address, uint8_t history_buffer_enable) +{ + uint8_t mode; + sensor_error ret= COMMON_INVALID_PARAMS; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&history_buffer_enable); + + if ((history_buffer_enable == HISTORY_BUFFER_DISABLE) || + (history_buffer_enable == HISTORY_BUFFER_ENABLE)) + { + mode = i2c_read_byte(SYSTEM_HISTORY_CTRL, device_base_address); + i2c_write_byte(SYSTEM_HISTORY_CTRL, + (mode | history_buffer_enable), + device_base_address); + ret = SENSOR_ERROR_NONE; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +bool_t common_get_history_buffer_enable(uint8_t device_base_address) +{ + bool_t ret = FALSE; + + LOG_FUNCTION_START((void*)&device_base_address); + + if (i2c_read_byte(SYSTEM_HISTORY_CTRL, device_base_address) & HISTORY_BUFFER_ENABLED) + { + ret = TRUE; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_history_buffer_mode(uint8_t device_base_address, uint8_t history_buffer_mode) +{ + uint8_t historyRegVal; + uint8_t mode=0; + sensor_error ret= SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&history_buffer_mode); + + historyRegVal = i2c_read_byte(SYSTEM_HISTORY_CTRL, device_base_address); + + if (history_buffer_mode & HISTORY_BUFFER_ALS_MODE) + { + mode = historyRegVal | 0x02; // set bit 1 to enable ALS mode + } + else if (history_buffer_mode & HISTORY_BUFFER_RANGING_MODE) + { + mode = historyRegVal & 0xFD; // clear bit 1 + } + else + { + ret = COMMON_INVALID_PARAMS; + } + i2c_write_byte(SYSTEM_HISTORY_CTRL, mode, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t common_get_history_buffer_mode(uint8_t device_base_address) +{ + int32_t ret = HISTORY_BUFFER_RANGING_MODE; + + LOG_FUNCTION_START((void*)&device_base_address); + + if (i2c_read_byte(SYSTEM_HISTORY_CTRL, device_base_address) & HISTORY_BUFFER_MODE) + { + ret = HISTORY_BUFFER_ALS_MODE; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_history_buffer_clear(uint8_t device_base_address) +{ + uint8_t mode; + + LOG_FUNCTION_START((void*)&device_base_address); + + mode = i2c_read_byte(SYSTEM_HISTORY_CTRL, device_base_address); + mode = mode | 0x04; // set bit 2 to 1 to clear history buffer + i2c_write_byte(SYSTEM_HISTORY_CTRL, mode, device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +bool_t common_get_history_buffer_clear(uint8_t device_base_address) +{ + bool_t ret = FALSE; + + LOG_FUNCTION_START((void*)&device_base_address); + if (i2c_read_byte(SYSTEM_HISTORY_CTRL, device_base_address) & HISTORY_BUFFER_CLEARED) + { + ret= TRUE; + } + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_system_interrupt_clear_error(uint8_t device_base_address) +{ + + LOG_FUNCTION_START((void*)&device_base_address); + + i2c_write_byte(SYSTEM_INTERRUPT_CLEAR, INTERRUPT_CLEAR_ERROR, device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint8_t common_get_error_result_interrupt_status_gpio(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + + ret = ( (i2c_read_byte(RESULT_INTERRUPT_STATUS_GPIO, device_base_address) & 0xC0) >> 6 ); + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_clear_system_fresh_out_of_reset(uint8_t device_base_address) +{ + + LOG_FUNCTION_START((void*)&device_base_address); + + i2c_write_byte(SYSTEM_FRESH_OUT_OF_RESET, 0x00, device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +bool_t common_get_system_fresh_out_of_reset(uint8_t device_base_address) +{ + uint8_t cFreshOutOfReset = 0x01; + bool_t ret= FALSE; + + LOG_FUNCTION_START((void*)&device_base_address); + + if (i2c_read_byte(SYSTEM_FRESH_OUT_OF_RESET, device_base_address) & cFreshOutOfReset) + { + ret = TRUE; + } + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_system_group_parameter_hold(uint8_t device_base_address) +{ + + LOG_FUNCTION_START((void*)&device_base_address); + + i2c_write_byte(SYSTEM_GROUPED_PARAMETER_HOLD, 0x01, device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error common_clear_system_group_parameter_hold(uint8_t device_base_address) +{ + + LOG_FUNCTION_START((void*)&device_base_address); + + i2c_write_byte(SYSTEM_GROUPED_PARAMETER_HOLD, 0x00, device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint8_t common_get_system_fatal_error_code(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + + ret = i2c_read_byte(SYSTEM_FATAL_ERROR_CODE, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t common_get_system_fatal_error_status(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + + ret = i2c_read_byte(SYSTEM_FATAL_ERROR_STATUS, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +// ?? +uint8_t common_get_system_health_check(uint8_t device_base_address) +{ +// return threshold + return 1; // temp only, will stub is here! +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common_driver.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,576 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/*! + *\file common_driver.h + *\brief Application-level methods used for generic, system or identification operations. + */ + +#ifndef _RANGE_DRIVER +#define _RANGE_DRIVER + +#include "definitions.h" +#include "platform.h" +//----------------------------------------------------------------------------- +// module imports +//----------------------------------------------------------------------------- + +// "circle_types.h" included for following definition : +//#ifndef __cplusplus +//typedef enum {FALSE = 0, TRUE = !FALSE} bool; +//#endif + + +//----------------------------------------------------------------------------- +// constant definitions +//----------------------------------------------------------------------------- + +// API Version Strings +#define API_MAJOR_VERSION 01 +#define API_MINOR_VERSION 00 +#define API_BUILD_NUMBER 00 +#define API_CODE_REVISION 1590 + +// register addresses +#define SYSTEM_MODE_GPIO0 0x10 +#define SYSTEM_MODE_GPIO1 0x11 +#define SYSTEM_HISTORY_CTRL 0x12 +#define SYSTEM_INTERRUPT_CONFIG_GPIO 0x14 +#define SYSTEM_INTERRUPT_CLEAR 0x15 +#define SYSTEM_FRESH_OUT_OF_RESET 0x16 +#define SYSTEM_GROUPED_PARAMETER_HOLD 0x17 + +#define RESULT_INTERRUPT_STATUS_GPIO 0x4F + +#define PAD_I2C_CONFIG 0x13D + +#define I2C_SLAVE_DEVICE_ADDRESS 0x212 + +#define SYSTEM_FATAL_ERROR_CODE 0x290 +#define SYSTEM_FATAL_ERROR_STATUS 0x291 + + + +// PAD_I2C_CONFIG +#define I2C_1v2_PAD_VOLTAGE 0x01 +#define I2C_2v8_PAD_VOLTAGE 0x02 + +// SYSTEM_INTERRUPT_CONFIG_GPIO +#define CONFIG_GPIO_INTERRUPT_DISABLED 0x00 +#define CONFIG_GPIO_INTERRUPT_LEVEL_LOW 0x01 +#define CONFIG_GPIO_INTERRUPT_LEVEL_HIGH 0x02 +#define CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW 0x03 +#define CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY 0x04 + +// SYSTEM_MODE_GPIOx +#define GPIOx_MODE_SELECT_RANGING 0x00 +#define GPIOx_MODE_SELECT_ALS 0x01 + +#define GPIOx_POLARITY_SELECT_OFF 0x00 +#define GPIOx_POLARITY_SELECT_ON 0x01 +#define GPIOx_POLARITY_SELECT_CLEARED 0xDF + +#define GPIOx_MODE_SELECT 0x01 +#define GPIOx_POLARITY_SELECT 0x20 + +#define GPIOx_SELECT_OFF 0x00 +#define GPIOx_SELECT_MEASURE_READY 0x01 +#define GPIOx_SELECT_THRESHOLD_OUTPUT 0x02 +#define GPIOx_SELECT_BLANK_IN 0x03 +#define GPIOx_SELECT_BLANK_OUT 0x04 +#define GPIOx_SELECT_START_STOP 0x05 +#define GPIOx_SELECT_DISABLED 0x06 +#define GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT 0x07 +#define GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT 0x08 + +// SYSTEM_HISTORY_CTRL +#define HISTORY_BUFFER_ENABLE 0x01 +#define HISTORY_BUFFER_DISABLE 0x00 + +#define HISTORY_BUFFER_ENABLED 0x01 +#define HISTORY_BUFFER_MODE 0x02 +#define HISTORY_BUFFER_CLEARED 0x04 + +#define HISTORY_BUFFER_RANGING_MODE 0x00 +#define HISTORY_BUFFER_ALS_MODE 0x01 + +// SYSTEM_INTERRUPT_CLEAR +#define INTERRUPT_CLEAR_RANGING 0x01 +#define INTERRUPT_CLEAR_ALS 0x02 +#define INTERRUPT_CLEAR_ERROR 0x04 + +// RESULT_INTERRUPT_STATUS_GPIO +#define RES_INT_STAT_GPIO_NO_ERROR 0x00 +#define RES_INT_STAT_GPIO_LOW_LEVEL_THRESHOLD 0x01 +#define RES_INT_STAT_GPIO_HIGH_LEVEL_THRESHOLD 0x02 +#define RES_INT_STAT_GPIO_OUT_OF_WINDOW 0x03 +#define RES_INT_STAT_GPIO_NEW_SAMPLE_READY 0x04 + + +//----------------------------------------------------------------------------- +// global variable declarations +//----------------------------------------------------------------------------- + +//----------------------------------------------------------------------------- +// method definitions +//----------------------------------------------------------------------------- + +/*! + * + */ +sensor_error common_initialise(uint8_t device_base_address); + +/*! + *\brief Device setup for Ranging and ALS operations.\n + * + * To apply these settings the operation bits (bit 0) in the SYSRANGE_START SYSALS_START Registers must be cleared. \n + * + *\param[in] device_base_address + *\retval sensor_error + */ +sensor_error common_set_static_config(uint8_t device_base_address); + +/*! + *\brief Report device Identification Info. + * + * Return the contents of the Identification block registers, in the following order : \n + * + * IDENTIFICATION_MODEL_ID \n + * IDENTIFICATION_MODEL_REV_MAJOR \n + * IDENTIFICATION_MODEL_REV_MINOR \n + * IDENTIFICATION_MODULE_REV_MAJOR \n + * IDENTIFICATION_MODULE_REV_MINOR \n + * IDENTIFICATION_NVM_REVISION_ID \n + * IDENTIFICATION_MASK_REVISION_ID \n + * IDENTIFICATION_month \n + * IDENTIFICATION_year \n + * IDENTIFICATION_phase \n + * IDENTIFICATION_day \n + * IDENTIFICATION_time \n + * IDENTIFICATION_code \n + * IDENTIFICATION_FIRMWARE_REVISION_ID\n + *\param[in] device_base_address + *\retval List + */ +sensor_error common_get_identification(uint8_t device_base_address); + +/*! + *\brief Set Device I2C Base Address. + * + * Uses I2C_Slave_Device_address register at 0x0212. Can be over-written by a value read from NVM. \n + * Defaults to 0x52 (8-bit address)/0x29 (7-bit). Register reports a 7-bit value. \n + *\param[in] device_base_address + *\param[in] i2c_base_address 8-bit I2C Slave device base address. + *\retval sensor_error + */ +sensor_error common_set_i2c_base_address(uint8_t device_base_address, uint32_t i2c_base_address); + +/*! + *\brief Set I2C Pad Voltage. + * + * I2C Pad External Bus Supply voltage (applies to both pads). Can be overridden by a value read from in NVM. \n + * + * Possible values are : \n + * I2C_1v8_PAD_VOLTAGE = 0x01 \n + * I2C_2v8_PAD_VOLTAGE = 0x02 \n + *\param[in] device_base_address + *\param[in] pad_voltage I2C Pad External Bus Supply voltage. + *\retval sensor_error + */ +sensor_error common_set_i2c_pad_voltage(uint8_t device_base_address, uint8_t pad_voltage); + +/*! + *\brief Report I2C Pad Voltage. + * + * I2C Pad External Bus Supply voltage. + * Possible values are : \n + * I2C_1v8_PAD_VOLTAGE = 0x01 \n + * I2C_2v8_PAD_VOLTAGE = 0x02 \n + *\param[in] device_base_address + *\retval Integer + */ +uint8_t common_get_i2c_pad_voltage(uint8_t device_base_address); + +/*! + *\brief Set GPIO0 Mode. + * + * Possible values for mode are : \n + * GPIOx_MODE_SELECT_RANGING = 0x00 \n + * GPIOx_MODE_SELECT_ALS = 0x01 \n + * + * Possible settings for select are : \n + * GPIOx_SELECT_OFF = 0x00 \n + * GPIOx_SELECT_MEASURE_READY = 0x01 \n + * GPIOx_SELECT_DISABLED = 0x06 \n + * GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT = 0x08 \n + * + * Possible settings for polarity are : \n + * GPIOx_POLARITY_SELECT_OFF = 0x00 \n + * GPIOx_POLARITY_SELECT_ON = 0x01 \n + *\param[in] device_base_address + *\param[in] mode Operating mode to be selected. + *\param[in] select + *\param[in] polarity + *\retval sensor_error + */ +sensor_error common_set_system_mode_gpio0(uint8_t device_base_address, uint8_t mode, uint8_t select, uint8_t polarity); + +/*! + *\brief Set GPIO0 Mode. + * + * Possible values for mode are : \n + * GPIOx_MODE_SELECT_RANGING = 0x00 \n + * GPIOx_MODE_SELECT_ALS = 0x01 \n + *\param[in] device_base_address + *\param[in] mode: Operating mode to be selected. + *\retval sensor_error + */ +sensor_error common_set_gpio0_mode(uint8_t device_base_address, uint8_t mode); + +/*! + *\brief Report GPIO0 Mode. + + Possible results are : \n + GPIOx_MODE_SELECT_RANGING = 0x00 \n + GPIOx_MODE_SELECT_ALS = 0x01 \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t common_get_gpio0_mode(uint8_t device_base_address); + +/*! + *\brief Set GPIO0 function configuration. + + Possible settings are : \n + GPIOx_SELECT_OFF = 0x00 \n + GPIOx_SELECT_MEASURE_READY = 0x01 \n + GPIOx_SELECT_THRESHOLD_OUTPUT = 0x02 \n + GPIOx_SELECT_BLANK_IN = 0x03 \n + GPIOx_SELECT_BLANK_OUT = 0x04 \n + GPIOx_SELECT_START_STOP = 0x05 \n + GPIOx_SELECT_DISABLED = 0x06 \n + GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT = 0x07 \n + GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT = 0x08 \n + *\param[in] device_base_address + *\param[in] select: + *\retval sensor_error +*/ +sensor_error common_set_gpio0_select(uint8_t device_base_address, uint8_t select); + +/*! + *\brief Report GPIO0 functional configuration. + + Possible results are : \n + GPIOx_SELECT_OFF = 0x00 \n + GPIOx_SELECT_MEASURE_READY = 0x01 \n + GPIOx_SELECT_THRESHOLD_OUTPUT = 0x02 \n + GPIOx_SELECT_BLANK_IN = 0x03 \n + GPIOx_SELECT_BLANK_OUT = 0x04 \n + GPIOx_SELECT_START_STOP = 0x05 \n + GPIOx_SELECT_DISABLED = 0x06 \n + GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT = 0x07 \n + GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT = 0x08 \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t common_get_gpio0_select(uint8_t device_base_address); + +/*! + *\brief Set GPIO0 Polarity. + + Possible settings are : \n + GPIOx_POLARITY_SELECT_OFF = 0x00 \n + GPIOx_POLARITY_SELECT_ON = 0x01 \n + *\param[in] device_base_address + *\param[in] polarity: + *\retval sensor_error +*/ +sensor_error common_set_gpio0_polarity(uint8_t device_base_address, uint8_t polarity); + +/*! + *\brief Report GPIO0 Polarity. + * + * Report the status of the GPIO_0 Polarity select bit in SYSTEM_MODE_GPIO0 register. \n + *\param[in] device_base_address + *\retval Boolean +*/ +bool_t common_get_gpio0_polarity(uint8_t device_base_address); + +/*! + *\brief Set GPIO1 Mode. + + Possible values for mode are : \n + GPIOx_MODE_SELECT_RANGING = 0x00 \n + GPIOx_MODE_SELECT_ALS = 0x01 \n + + Possible settings for select are : \n + GPIOx_SELECT_OFF = 0x00 \n + GPIOx_SELECT_MEASURE_READY = 0x01 \n + GPIOx_SELECT_DISABLED = 0x06 \n + GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT = 0x08 \n + + Possible settings for polarity are : \n + GPIOx_POLARITY_SELECT_OFF = 0x00 \n + GPIOx_POLARITY_SELECT_ON = 0x01 \n + *\param[in] device_base_address + *\param[in] mode: Operating mode to be selected. + *\param[in] select: + *\param[in] polarity: + *\retval sensor_error +*/ +sensor_error common_set_system_mode_gpio1(uint8_t device_base_address, uint8_t mode, uint8_t select, uint8_t polarity); + +/*! + *\brief Set GPIO1 Mode. + + Possible mode settings are : \n + GPIOx_MODE_SELECT_RANGING = 0x00 \n + GPIOx_MODE_SELECT_ALS = 0x01 \n + *\param[in] device_base_address + *\param[in] mode: + *\retval sensor_error +*/ +sensor_error common_set_gpio1_mode(uint8_t device_base_address, uint8_t mode); + +/*! + *\brief Report GPIO1 Mode. + + Possible results are : \n + GPIOx_MODE_SELECT_RANGING = 0x00 \n + GPIOx_MODE_SELECT_ALS = 0x01 \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t common_get_gpio1_mode(uint8_t device_base_address); + +/*! + *\brief Set GPIO1 functional configuration. + + Possible settings are : \n + GPIOx_SELECT_OFF = 0x00 \n + GPIOx_SELECT_MEASURE_READY = 0x01 \n + GPIOx_SELECT_THRESHOLD_OUTPUT = 0x02 \n + GPIOx_SELECT_BLANK_IN = 0x03 \n + GPIOx_SELECT_BLANK_OUT = 0x04 \n + GPIOx_SELECT_START_STOP = 0x05 \n + GPIOx_SELECT_DISABLED = 0x06 \n + GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT = 0x07 \n + GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT = 0x08 \n + *\param[in] device_base_address + *\param[in] select: + *\retval sensor_error +*/ +sensor_error common_set_gpio1_select(uint8_t device_base_address, uint8_t select); + +/*! + *\brief Report GPIO1 functional configuration. + + Possible results are : \n + GPIOx_SELECT_OFF = 0x00 \n + GPIOx_SELECT_MEASURE_READY = 0x01 \n + GPIOx_SELECT_THRESHOLD_OUTPUT = 0x02 \n + GPIOx_SELECT_BLANK_IN = 0x03 \n + GPIOx_SELECT_BLANK_OUT = 0x04 \n + GPIOx_SELECT_START_STOP = 0x05 \n + GPIOx_SELECT_DISABLED = 0x06 \n + GPIOx_SELECT_COMBINED_THRESHOLD_OUTPUT = 0x07 \n + GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT = 0x08 \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t common_get_gpio1_select(uint8_t device_base_address); + +/*! + *\brief Set GPIO1 Polarity. + + GPIOx_POLARITY_SELECT_OFF = 0x00 \n + GPIOx_POLARITY_SELECT_ON = 0x01 \n + *\param[in] device_base_address + *\param[in] polarity: + *\retval sensor_error +*/ +sensor_error common_set_gpio1_polarity(uint8_t device_base_address, uint8_t polarity); + +/*! + *\brief Report GPIO1 Polarity. + + Report the status of the GPIO_0 Polarity select bit in SYSTEM_MODE_GPIO0 register. + *\param[in] device_base_address + *\retval Boolean +*/ +bool_t common_get_gpio1_polarity(uint8_t device_base_address); + +/*! + *\brief Set History Buffer Enable. + + Possible settings are : \n + HISTORY_BUFFER_ENABLE = 0x01 \n + HISTORY_BUFFER_DISABLE = 0x00 \n + *\param[in] device_base_address + *\param[in] history_buffer_enable: + *\retval sensor_error +*/ +sensor_error common_set_history_buffer_enable(uint8_t device_base_address, uint8_t history_buffer_enable); + +/*! + *\brief Report History Buffer Enable status. + + Returns True if the command completes successfully, otherwise False.\n + *\param[in] device_base_address + *\retval Boolean +*/ +bool_t common_get_history_buffer_enable(uint8_t device_base_address); + +/*! + *\brief Set History Buffer Mode. + + Possible modes are : \n + HISTORY_BUFFER_RANGING_MODE = 0x00 \n + HISTORY_BUFFER_ALS_MODE = 0x01 \n + *\param[in] device_base_address + *\param[in] history_buffer_mode: + *\retval sensor_error +*/ +sensor_error common_set_history_buffer_mode(uint8_t device_base_address, uint8_t history_buffer_mode); + +/*! + *\brief Report History Buffer Mode. + + Returns the contents of the SYSTEM_HISTORY_CTRL register. \n + Possible values are : \n + HISTORY_BUFFER_RANGING_MODE = 0x00 \n + HISTORY_BUFFER_ALS_MODE = 0x01 \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t common_get_history_buffer_mode(uint8_t device_base_address); + +/*! + *\brief Clear history buffer (mode not cleared) + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error common_set_history_buffer_clear(uint8_t device_base_address); + +/*! + *\brief Report History Buffer Clear status. + * + * Returns True if the SYSTEM_HISTORY_CTRL register is cleared, otherwise False. \n + *\param[in] device_base_address + *\retval Boolean +*/ +bool_t common_get_history_buffer_clear(uint8_t device_base_address); + +/*! + *\brief Clear 'Error' System Interrupt. + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error common_set_system_interrupt_clear_error(uint8_t device_base_address); + +/*! + *\brief Report GPIO Interrupt Error Result Status. + + Returns the Error flag portion of the RESULT_INTERRUPT_STATUS_GPIO register. \n + Possible returns are : \n + 0: No error reported \n + 1: Laser Safety Error \n + 2: PLL error (either PLL1 or PLL2) \n + 3: Measurement error \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t common_get_error_result_interrupt_status_gpio(uint8_t device_base_address); + +/*! + *\brief Clear System Fresh Out Of Reset flag. + * + * The fresh out of reset bit defaults to 1 at boot-up. The user can set this to 0 after initial boot and then use this flag to check for reset conditions. + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error common_clear_system_fresh_out_of_reset(uint8_t device_base_address); + +/*! + *\brief Report System Fresh Out Of Reset status. + * + * Returns True if the SYSTEM_FRESH_OUT_OF_RESET register status is set, otherwise False. \n + *\param[in] device_base_address + *\retval Boolean +*/ +bool_t common_get_system_fresh_out_of_reset(uint8_t device_base_address); + +/*! + *\brief Set System Group Parameter Hold flag. + + The grouped_parameter_hold flag is set to indicate that device data is being updated. \n + 0: Data is stable - user is safe to copy. \n + 1: Data being updated - user not safe to copy. \n + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error common_set_system_group_parameter_hold(uint8_t device_base_address); + +/*! + *\brief Clear System Group Parameter Hold flag. + + The grouped_parameter_hold flag is set to indicate that device data is being updated. \n + 0: Data is stable - user is safe to copy. \n + 1: Data being updated - user not safe to copy. \n + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error common_clear_system_group_parameter_hold(uint8_t device_base_address); + +/*! + *\brief Report System Fatal Error Code flag status. + * + * Returns the contents of the SYSTEM_FATAL_ERROR_CODE register, which is written to when a fatal error occurs. + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t common_get_system_fatal_error_code(uint8_t device_base_address); + +/*! + *\brief Report System Fatal Error Status. + + Returns the contents of the SYSTEM_FATAL_ERROR_STATUS register, which is written to when a fatal error occurs.\n + + Read Only HW status bit, set high when a 1 is written into FATAL_ERROR_CODE. \n + Checked by FW on bootup to ascertain device status. Can only be rest by a main Go2 reset. \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t common_get_system_fatal_error_status(uint8_t device_base_address); + +/*! + *\brief Report System Health. + * + * A combination of fresh_from_reset, fatal_error and laser safety checks + *\param[in] device_base_address + *\retval Integer. A combined system health flag. +*/ +uint8_t common_get_system_health_check(uint8_t device_base_address); + +#endif + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debug.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,1240 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +//! \defgroup Debugging_Functions +#ifndef __KERNEL__ +#include <string.h> +#else +#include <linux/kernel.h> +#include <linux/string.h> +#endif +#include "debug.h" +#include "definitions.h" +#include "als_driver.h" +#include "ranging_driver.h" +#include "i2c_log.h" + +// Defines for internal use + +#define DEBUG_NONE 0 +#define DEBUG_BYTE 1 +#define DEBUG_BOOL 1 +#define DEBUG_UINT8 1 +#define DEBUG_INT8 1 +#define DEBUG_UINT16 2 +#define DEBUG_INT16 2 +#define DEBUG_UINT32 3 +#define DEBUG_UINT64 4 +#define DEBUG_FLOAT 5 +#define DEBUG_DOUBLE 6 +#define DEBUG_STRUCT 9 + + + +#ifdef DEBUG_ENABLE + +#define DUMP_PARAM_STRUCT(ParamName, Param, ParamType) dumpParameter(#ParamName, sizeof(ParamType), (uint8_t *)Param, DEBUG_STRUCT, #ParamType) +#define DUMP_PARAM(ParamName, Param, ParamType) dumpParameter(#ParamName, 1, (uint8_t *)Param, ParamType, NULL) +#define DUMP_PARAM_PTR(ParamName, Param, ParamSize, ParamType) dumpParameter(#ParamName, ParamSize, (uint8_t *)Param, ParamType, NULL) +#define DUMP_STRUCTPARAM(StructType, StructName, ParamName, ParamType) dumpParameter(#ParamName, 1, (uint8_t *)&(((StructType*)StructName)->ParamName), ParamType, NULL); +#define DUMP_STRUCTPARAM_PTR(StructType, StructName, ParamName, ParamSize, ParamType) dumpParameter(#ParamName, ParamSize, (uint8_t *)(((StructType*)StructName)->ParamName), ParamType, NULL); +#define DUMP_STRUCTPARAM_ARRAY(StructType, StructName, ParamName, ParamSize, ParamType) dumpParameter(#ParamName, ParamSize, (uint8_t *)(&(((StructType*)StructName)->ParamName[0])), ParamType, NULL); +#define DUMP_STRUCTPARAM_STRUCT(StructType, StructName, ParamName, ParamType) dumpParameter(#ParamName, sizeof(ParamType), (uint8_t *)&(((StructType*)StructName)->ParamName), DEBUG_STRUCT, #ParamType); + +#define DEBUG_TEST_STR_EQUALITY(Str1, Str2, UINT8_VAR) core_strCmpr(Str1, Str2, &UINT8_VAR);if(UINT8_VAR) + + + +/* private functions for debugging */ +sensor_error dumpParameters(const char* pFunctionName, void **pFuncArguments); +sensor_error dumpParameter(const char* pParamName, const uint32_t ParamLength, const uint8_t *pParamValues, const uint8_t ParamType, const char* pStructName); +sensor_error isApiCoreFunction(const char* pFunctionName, bool_t* isCoreFunc); +sensor_error core_strCmpr(const char* Str1, const char* Str2, bool_t *pEqual); +sensor_error logFunction(bool_t* pLogFunction, const char* pFunctionName, const bool_t IsCoreFunction, const bool_t FunctionStart); +sensor_error logFunctionParameters(bool_t* pLogFunctionParams, const char* pFunctionName, const bool_t IsCoreFunction, const bool_t FunctionStart); + +/* Global variables used only by debug system */ +#define LINE_SIZE 1024 +char DebugBuffer[LINE_SIZE]; +char * pDebugBuffer=0; +char * pOffLineBuffer=0; +uint32_t OffLineLogSize=0,CurLogSize=0; +bool_t DebugStarted=FALSE; + +char DebugLogLevel = (char)NORMAL_LOG_LEVEL; +char DebugMode = (char)DEBUG_ONLINE; +char DebugCurrentFunctionLevel = 0; + + +/**************************************************************/ +/* Debugging Functions */ +/**************************************************************/ +sensor_error loggingOpen() +{ + /* Debug String Line buffer */ + pDebugBuffer = &DebugBuffer[0]; + CurLogSize = 0; + DebugCurrentFunctionLevel = 0; + + + return SENSOR_ERROR_NONE; +} + +sensor_error loggingClose() +{ + sensor_error Status = SENSOR_ERROR_NONE; + if(DebugStarted){ + Status = loggingStop(); + } + if(Status == SENSOR_ERROR_NONE){ + pDebugBuffer=0; + } + + return Status; +} + +sensor_error loggingSetMode (char mode) +{ + if (mode != DEBUG_ONLINE && mode != DEBUG_OFFLINE) + return SENSOR_ERROR; + DebugMode = mode; + + return SENSOR_ERROR_NONE; +} + +sensor_error loggingSetBuffer (char *pBuf, uint32_t size) +{ + sensor_error Status = SENSOR_ERROR_NONE; + if (pBuf == 0 || size ==0) + return SENSOR_ERROR; + pOffLineBuffer = pBuf; + OffLineLogSize = size; + CurLogSize = 0; + + return Status; +} + +sensor_error loggingStart(uint8_t DebugLevel) +{ + sensor_error Status = SENSOR_ERROR_NONE; + uint32_t CurrentTime = 0; + + if(DebugMode==DEBUG_OFFLINE && pOffLineBuffer==0) { + /* Offline mode but Log buffer not assigned yet, return error */ + debug1_print("loggingStart Error, OFFLINE mode, no Offline buffer provided yet!!!\n"); + return SENSOR_ERROR; + } + CurLogSize = 0; + CurrentTime = timer_get_clock_time_msecs(); + + if(pDebugBuffer==0) { + /* Log buffer not assigned yet, create it first */ + Status = loggingOpen(); + } + + DebugLogLevel = DebugLevel; + DebugStarted=TRUE; + + //if(Status == SENSOR_ERROR_NONE){ + // Status = GetTimeStamp(&CurrentTime); + //} + if(Status == SENSOR_ERROR_NONE){ + DEBUG_WRITE_IN_LOG("<LoggingSession TimeStamp(ms)=\"%.8d\">\n", CurrentTime); + DEBUG_WRITE_IN_LOG(" <DebugStart TimeStamp(ms)=\"%.8d\"/>\n", CurrentTime); + } + if (DebugLogLevel == I2C_LOG_LEVEL) + i2c_log_start(); + else + i2c_log_end(); + + DebugCurrentFunctionLevel = 0; + + return SENSOR_ERROR_NONE; +} + +sensor_error loggingStop() +{ + sensor_error Status = SENSOR_ERROR_NONE; + uint32_t CurrentTime = 0; + + CurrentTime = timer_get_clock_time_msecs(); + if(Status == SENSOR_ERROR_NONE){ + DEBUG_WRITE_IN_LOG(" <DebugStop TimeStamp(ms)=\"%.8d\"/>\n", CurrentTime); + DEBUG_WRITE_IN_LOG("</LoggingSession>\n"); + } + + DebugStarted=FALSE; + + + return SENSOR_ERROR_NONE; +} + +sensor_error logDebugMessageStart(const char* pFunctionName) +{ + sensor_error Status = SENSOR_ERROR_NONE; + uint32_t CurrentTime = 0; + + CurrentTime = timer_get_clock_time_msecs(); + if(Status==SENSOR_ERROR_NONE){ + DEBUG_WRITE_IN_LOG("<Log_message TimeStamp(ms)=\"%.8d\" API_Function_Name=\"%s\">\n",CurrentTime, pFunctionName); + } + + return Status; +} + +sensor_error logDebugMessageEnd() +{ + sensor_error Status = SENSOR_ERROR_NONE; + + DEBUG_WRITE_IN_LOG("</Log_message>\n"); + + return Status; +} + +sensor_error logErrorMessageStart(const char* pFunctionName) +{ + sensor_error Status = SENSOR_ERROR_NONE; + uint32_t CurrentTime = 0; + + CurrentTime = timer_get_clock_time_msecs(); + if(Status==SENSOR_ERROR_NONE){ + DEBUG_WRITE_IN_LOG("<ERROR_MESSAGE TimeStamp(ms)=\"%.8d\" API_Function_Name=\"%s\">\n",CurrentTime, pFunctionName); + + } + + return Status; +} + +sensor_error logErrorMessageEnd() +{ + sensor_error Status = SENSOR_ERROR_NONE; + + DEBUG_WRITE_IN_LOG("</ERROR_MESSAGE>\n"); + + + return Status; +} + + +sensor_error loggingFunctionStart(const char* pFunctionName, void **pFuncArguments) +{ + sensor_error Status = SENSOR_ERROR_NONE; + uint32_t CurrentTime = 0; + bool_t isCoreFunc = FALSE; + bool_t logFunc; + bool_t logFuncParams; + + if(DebugStarted){ + CurrentTime = timer_get_clock_time_msecs(); + if(Status==SENSOR_ERROR_NONE){ + /* Check if we are starting to log an API function */ + logFunction(&logFunc, pFunctionName, isCoreFunc, TRUE); + logFunctionParameters(&logFuncParams, pFunctionName, isCoreFunc, TRUE); + if(logFunc) + { + DEBUG_WRITE_IN_LOG("<API_Function>\n"); + DEBUG_WRITE_IN_LOG(" <Exec_Start TimeStamp(ms)=\"%.8d\">\n", CurrentTime); + DEBUG_WRITE_IN_LOG(" <API_Function_Name>%s</API_Function_Name>\n", pFunctionName); + + if(logFuncParams) + { + DEBUG_WRITE_IN_LOG(" <API_Input_Arguments>\n"); + dumpParameters(pFunctionName, pFuncArguments); + DEBUG_WRITE_IN_LOG(" </API_Input_Arguments>\n"); + } + + DEBUG_WRITE_IN_LOG(" </Exec_Start>\n"); + } + + } + } + return Status; +} + + +sensor_error loggingFunctionEnd(const char* pFunctionName, sensor_error ReturnedValue, void **pFuncArguments) +{ + sensor_error Status = SENSOR_ERROR_NONE; + uint32_t CurrentTime=0; + bool_t isCoreFunc=FALSE; + bool_t logFunc; + bool_t logFuncParams=FALSE; + + if(DebugStarted){ + CurrentTime = timer_get_clock_time_msecs(); + + if(Status==SENSOR_ERROR_NONE){ + + logFunction(&logFunc, pFunctionName, isCoreFunc, FALSE); + logFunctionParameters(&logFuncParams, pFunctionName, isCoreFunc, FALSE); + + if(logFunc) + { + DEBUG_WRITE_IN_LOG(" <Exec_End TimeStamp(ms)=\"%.8d\"/>\n", CurrentTime); + DEBUG_WRITE_IN_LOG(" <API_Function_Name>%s</API_Function_Name>\n", pFunctionName); + + if(logFuncParams) + { + DEBUG_WRITE_IN_LOG(" <API_Output_Arguments>\n"); + dumpParameters(pFunctionName, pFuncArguments); + DEBUG_WRITE_IN_LOG(" </API_Output_Arguments>\n"); + } + + DEBUG_WRITE_IN_LOG(" <Returned_Value>0x%x</Returned_Value>\n", ReturnedValue); + } + if(logFunc) + { + DEBUG_WRITE_IN_LOG("</API_Function>\n"); + } + } + } + return Status; +} + +sensor_error loggingOutput(char* pBuffer) +{ + //check the mode + if (DebugMode == DEBUG_ONLINE) + { + debug1_print(pBuffer); + } + else + { + if (CurLogSize + strlen(pBuffer) < OffLineLogSize) + { + sprintf(pOffLineBuffer+CurLogSize,pBuffer); + CurLogSize += strlen(pBuffer); + } + } + + return SENSOR_ERROR_NONE; +} + +sensor_error loggingOfflineOutput(void) +{ + if (DebugMode == DEBUG_OFFLINE) + { + uint32_t i=0,size=0; + while (i <CurLogSize) + { + if ((CurLogSize-i) > LINE_SIZE) + size = LINE_SIZE; + else + size = (CurLogSize-i); + strncpy(pDebugBuffer,(pOffLineBuffer+i), size); + debug1_print(pDebugBuffer); + i+=size; + } + + } + return SENSOR_ERROR_NONE; +} + +sensor_error core_strCmpr(const char* Str1, const char* Str2, bool_t *pEqual) +{ + sensor_error Status = SENSOR_ERROR_NONE; + uint16_t Str1Length = 0; + uint16_t Str2Length = 0; + uint16_t Index; + + *pEqual=FALSE; + Index=0; + while(((uint8_t)(*(Str1+Index)))!=0) + { + Index=Index+1; + } + Str1Length=Index; + + Index=0; + while(((uint8_t)(*(Str2+Index)))!=0) + { + Index=Index+1; + } + Str2Length=Index; + + if(Str1Length != Str2Length){ + *pEqual=FALSE; + return Status; + } + + for(Index=0;Index<Str1Length;Index++){ + if(((uint8_t)(*(Str1+Index)))!=((uint8_t)(*(Str2+Index)))){ + *pEqual=FALSE; + return Status; + } + } + + *pEqual=TRUE; + return Status; +} + + +sensor_error isApiCoreFunction(const char* pFunctionName, bool_t* isCoreFunc) +{ + sensor_error Status = SENSOR_ERROR_NONE; + + char corefunctionRoot[]="core"; + char functionRoot[13]; + uint8_t i; + + for(i=0; ((i<12)&&(pFunctionName[i]!=0)); i=i+1) + { + functionRoot[i]=pFunctionName[i]; + } + functionRoot[i]=0; + + /* Test Equality */ + Status = core_strCmpr(functionRoot, corefunctionRoot, isCoreFunc); + + return Status; +} + + +sensor_error logFunction(bool_t* pLogFunction, const char* pFunctionName, const bool_t IsCoreFunction, const bool_t FunctionStart) +{ + sensor_error Status = SENSOR_ERROR_NONE; + const uint8_t NbOfFunctions=36; + //#heavy load APIs only output for verbos mode + char *functions[36] = { //has to match NbOfFunctions. + "getApiVersionNumber", + "getRangeMeasurement", + "getAlsMeasurement", + "readRegister", + "range_set_systemMode", + "range_get_result", + "range_get_result_status", + "range_get_device_ready", + "range_get_result_error_codes", + "range_get_max_convergence_time", + "range_set_system_interrupt_clear", + "range_get_result_interrupt_status_gpio", + "als_get_lux", + "als_get_result", + "als_set_system_interrupt_config_gpio", + "als_set_system_interrupt_clear", + "als_get_result_interrupt_status_gpio", + "common_set_gpio0_mode", + "common_get_gpio0_mode", + "common_set_gpio0_select", + "common_get_gpio0_select", + "common_set_gpio0_polarity", + "common_get_gpio0_polarity", + "common_set_gpio1_mode", + "common_set_gpio1_select", + "common_get_gpio1_select", + "common_set_gpio1_polarity", + "common_get_gpio1_polarity", + "common_get_history_buffer_clear", + "common_set_system_interrupt_config_gpio_ranging", + "common_set_system_interrupt_clear_ranging", + "common_set_system_interrupt_clear_error", + "common_get_range_result_interrupt_status_gpio", + "common_get_error_result_interrupt_status_gpio", + "er_get_result", + "er_set_scaler" + }; + uint8_t i=0; + bool_t StrEquality; + /* Depending on Log level, we will log only: + * API UI calls in MINIMUM_LOG_LEVEL + * API UI and core calls in NORMAL_LOG_LEVEL and VERBOSE_LOG_LEVEL */ + if (DebugLogLevel==I2C_LOG_LEVEL) + { + *pLogFunction=FALSE; + return Status; + } + if (DebugLogLevel==VERBOSE_LOG_LEVEL) + { + *pLogFunction=TRUE; + return Status; + } + for(i=0;i<NbOfFunctions;i++) + { + core_strCmpr(pFunctionName, functions[i], &StrEquality); + if(StrEquality==TRUE) + { + *pLogFunction=FALSE; + break; + } + } + + return Status; +} + +sensor_error logFunctionParameters(bool_t* pLogFunctionParams, const char* pFunctionName, const bool_t IsCoreFunction, const bool_t FunctionStart) +{ + sensor_error Status = SENSOR_ERROR_NONE; + + //#heavy load APIs only output for verbos mode + char *functions[1] = { + "to_define_later" + }; + uint8_t NbOfFunctions=0; + uint8_t i; + bool_t DoLog; + bool_t StrEquality; + + + /* Depending on Log level, we will log only: + * API UI calls parameters in ILP0013_MINIMUM_LOG_LEVEL and ILP0013_NORMAL_LOG_LEVEL + * API UI and core parameters in ILP0013_VERBOSE_LOG_LEVEL */ + switch(DebugLogLevel) + { + case MINIMUM_LOG_LEVEL: + if(IsCoreFunction) + *pLogFunctionParams=FALSE; + else + { + if(FunctionStart) + DoLog = TRUE; + else + DoLog = FALSE; + for(i=0;i<NbOfFunctions;i++) + { + core_strCmpr(pFunctionName, functions[i], &StrEquality); + if(StrEquality==TRUE) + { + DoLog = (bool_t)!DoLog; + break; + } + } + + *pLogFunctionParams=DoLog; + } + break; + case NORMAL_LOG_LEVEL: + if(IsCoreFunction) + *pLogFunctionParams=FALSE; + else + *pLogFunctionParams=TRUE; + break; + case VERBOSE_LOG_LEVEL: + *pLogFunctionParams=TRUE; + break; + case I2C_LOG_LEVEL: + *pLogFunctionParams=FALSE; + break; + default: + *pLogFunctionParams=TRUE; + break; + } + + return Status; +} + +sensor_error dumpParameters(const char* pFunctionName, void **pFuncArguments) +{ + sensor_error Status = SENSOR_ERROR_NONE; + bool_t FuncStrEqual; + + /* API FUNCTIONS */ + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_history_buffer_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_snr_thresh", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(snrThresh, *(pFuncArguments+1), DEBUG_FLOAT); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_system_fresh_out_of_reset", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_lower_limit", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_i2c_pad_voltage", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_gpio1_polarity", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(polarity, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "er_get_scaler", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_system_interrupt_config_gpio", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_vhv_repeat_rate", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(VHV_repeat_rate, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "decodeFrom4_4_Format", FuncStrEqual){ + DUMP_PARAM(value, *(pFuncArguments+0), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_scaler", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_crosstalk_compensation_rate", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(crosstalk_compensation_rate, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_interMeasurement_period", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(intermeasurement_period, *(pFuncArguments+1), DEBUG_UINT16); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_interMeasurement_period", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(intermeasurement_period, *(pFuncArguments+1), DEBUG_UINT16); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_system_interrupt_config_gpio", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(Ranging_GPIO_interrupt_config, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_ece_factor", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(ECE_Factor_M, *(pFuncArguments+1), DEBUG_UINT32); + DUMP_PARAM(ECE_Factor_D, *(pFuncArguments+2), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_gpio0_polarity", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_gpio1_select", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "get_als_measurement", FuncStrEqual){ + DUMP_PARAM(id, *(pFuncArguments+0), DEBUG_UINT32); + DUMP_PARAM_STRUCT(pAlsData, *(pFuncArguments+1), sensor_AlsData); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_system_interrupt_config_gpio", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(ALS_GPIO_interrupt_config, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "Range_Set_Thresholds", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(low_threshold, *(pFuncArguments+1), DEBUG_UINT32); + DUMP_PARAM(high_threshold, *(pFuncArguments+2), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "initialise", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_interMeasurement_period", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "get_range_measurement", FuncStrEqual){ + DUMP_PARAM(id, *(pFuncArguments+0), DEBUG_UINT32); + DUMP_PARAM_STRUCT(pRangeData, *(pFuncArguments+1), sensor_RangeData); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_early_convergence_estimate_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "er_get_lower_limit", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_history_buffer_mode_enable", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "encodeTo9_7_Format", FuncStrEqual){ + DUMP_PARAM(value, *(pFuncArguments+0), DEBUG_FLOAT); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_early_convergence_estimate_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_systemMode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "decodeFrom9_7_Format", FuncStrEqual){ + DUMP_PARAM(value, *(pFuncArguments+0), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_ignore_valid_height", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(ignore_valid_height, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_system_interrupt_clear", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_vhv_recalibrate", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_device_ready", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_initialise", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_low_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "er_set_part2Part_range_offset", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(part_to_part_range_offset, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_system_interrupt_config_gpio", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_i2c_base_address", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(i2c_base_address, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "roundFloatToInt", FuncStrEqual){ + DUMP_PARAM(floatVal, *(pFuncArguments+0), DEBUG_FLOAT); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_high_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "er_set_static_config", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "unPackBytes", FuncStrEqual){ + DUMP_PARAM(data, *(pFuncArguments+0), DEBUG_UINT32); + DUMP_PARAM_PTR(byteArray, *(pFuncArguments+1), 1, DEBUG_UINT8); + DUMP_PARAM(size, *(pFuncArguments+2), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_history_buffer_enable", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_max_convergence_time", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "er_range_get_part2Part_range_offset", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_dynamic_config", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_system_interrupt_clear", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_result_status", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_result", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_range_check_enables", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_integration_period", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(integration_period, *(pFuncArguments+1), DEBUG_UINT16); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_result", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_clear_interleaved_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_device_ready", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_interMeasurement_period", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_gpio0_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_system_health_check", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_result_interrupt_status_gpio", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_history_buffer_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(history_buffer_mode, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_ece_factor", FuncStrEqual){ + DUMP_PARAM_PTR(pece_factor_m, *(pFuncArguments+0), 1, DEBUG_UINT32); + DUMP_PARAM_PTR(pece_factor_d, *(pFuncArguments+1), 1, DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_analogue_gain", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(light_analogue_gain, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_gpio1_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_system_group_parameter_hold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_signal_rate", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "er_get_result", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_clear_system_fresh_out_of_reset", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "Get_Range_History_Buffer", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_max_convergence_time", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(max_convergence_time, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_scaler", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(scaler, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_static_config", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_vhv_repeat_rate", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_crosstalk_compensation_rate", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "get_version", FuncStrEqual){ + DUMP_PARAM(id, *(pFuncArguments+0), DEBUG_UINT32); + DUMP_PARAM_PTR(pVersionStr, *(pFuncArguments+1), 1, DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_snr_thresh", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_system_fatal_error_code", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_systemMode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_high_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_gpio1_select", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(select, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_thresholds", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(low_threshold, *(pFuncArguments+1), DEBUG_UINT16); + DUMP_PARAM(high_threshold, *(pFuncArguments+2), DEBUG_UINT16); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "i2c_initialise", FuncStrEqual){ + DUMP_PARAM(addr, *(pFuncArguments+0), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_low_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_gpio1_polarity", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_upper_limit", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_history_buffer_mode_enable", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_crosstalk_compensation_range", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_high_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(threshold, *(pFuncArguments+1), DEBUG_UINT16); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_crosstalk_valid_height", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_history_buffer_clear", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_full_result", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_interleaved_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "Get_ALS_History_Buffer", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_analogue_gain", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_clear_system_group_parameter_hold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "start_extended_ranging", FuncStrEqual){ + DUMP_PARAM(id, *(pFuncArguments+0), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "er_set_scaler", FuncStrEqual){ + DUMP_PARAM(scaler, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(device_base_address, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_system_fatal_error_status", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_result_interrupt_status_gpio", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_range_check_enables", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(range_check_enables, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "encodeTo4_4_Format", FuncStrEqual){ + DUMP_PARAM(value, *(pFuncArguments+0), DEBUG_FLOAT); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_i2c_pad_voltage", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(pad_voltage, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_gpio0_polarity", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(polarity, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_gpio0_select", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "packBytes", FuncStrEqual){ + DUMP_PARAM_PTR(byteArray, *(pFuncArguments+0), 1, DEBUG_UINT8); + DUMP_PARAM(size, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_integration_period", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_vernier_ave_total_time", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_result_status", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_gpio0_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(mode, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_system_interrupt_clear_error", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "start_als", FuncStrEqual){ + DUMP_PARAM(id, *(pFuncArguments+0), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_systemMode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(mode, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_range_ignore_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_error_result_interrupt_status_gpio", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_lux", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_systemMode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(mode, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_low_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(threshold, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_gpio0_select", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(select, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_history_buffer_enable", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(history_buffer_enable, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_get_result_error_codes", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_crosstalk_valid_height", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(crosstalk_valid_height, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_system_mode_gpio0", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(mode, *(pFuncArguments+1), DEBUG_UINT8); + DUMP_PARAM(select, *(pFuncArguments+2), DEBUG_UINT8); + DUMP_PARAM(polarity, *(pFuncArguments+3), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_system_mode_gpio1", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(mode, *(pFuncArguments+1), DEBUG_UINT8); + DUMP_PARAM(select, *(pFuncArguments+2), DEBUG_UINT8); + DUMP_PARAM(polarity, *(pFuncArguments+3), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_dynamic_config", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "i2c_read_uint32", FuncStrEqual){ + DUMP_PARAM(reg, *(pFuncArguments+0), DEBUG_UINT32); + DUMP_PARAM(baseAddr, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_low_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(threshold, *(pFuncArguments+1), DEBUG_UINT16); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "i2c_write", FuncStrEqual){ + DUMP_PARAM(reg, *(pFuncArguments+0), DEBUG_UINT32); + DUMP_PARAM_PTR(data, *(pFuncArguments+1), 1, DEBUG_UINT8); + DUMP_PARAM(size, *(pFuncArguments+2), DEBUG_UINT32); + DUMP_PARAM(baseAddr, *(pFuncArguments+3), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "als_set_interleaved_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_converg_ctrl_rtn_thresh_fine", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_emitter_block_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(emitter_block_threshold, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_vhv_recalibrate", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(VHV_Recalibrate, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_crosstalk_compensation_range", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(crosstalk_compensation_range, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "get_vendor", FuncStrEqual){ + DUMP_PARAM_PTR(pVendorStr, *(pFuncArguments+0), 1, DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_result_error_codes", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_history_buffer_clear", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_ignore_valid_height", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_range_ignore_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(range_ignore_threshold, *(pFuncArguments+1), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_get_emitter_block_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_set_gpio1_mode", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(mode, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "common_get_identification", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "range_set_high_threshold", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + DUMP_PARAM(threshold, *(pFuncArguments+1), DEBUG_UINT8); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "start_ranging", FuncStrEqual){ + DUMP_PARAM(id, *(pFuncArguments+0), DEBUG_UINT32); + } + + DEBUG_TEST_STR_EQUALITY(pFunctionName, "er_get_upper_limit", FuncStrEqual){ + DUMP_PARAM(device_base_address, *(pFuncArguments+0), DEBUG_UINT8); + } + + /* API CORE FUNCTIONS */ + /* END API FUNCTIONS */ + return Status; +} + +sensor_error dumpParameter(const char* pParamName, const uint32_t ParamLength, const uint8_t *pParamValues, const uint8_t ParamType, const char* pStructName) +{ + sensor_error Status = SENSOR_ERROR_NONE; + uint32_t I; + //bool_t ParamStrEqual; + + DEBUG_WRITE_IN_LOG(" <%s>",pParamName); + + if(ParamType==DEBUG_STRUCT){ + /* DUMP STRUCTURES */ + /* END DUMP STRUCTURES */ + /* END DUMP STRUCTURES */ + } else { + for(I=0; I<ParamLength; I++){ + switch(ParamType) + { + case DEBUG_NONE: + /* SHOULD NEVER ENTER HERE */ + break; + case DEBUG_BYTE: + DEBUG_WRITE_IN_LOG("0x%02x",(uint8_t)*(pParamValues+I)); + break; + case DEBUG_UINT16: + DEBUG_WRITE_IN_LOG("0x%04x",*(uint16_t*)(pParamValues+(I*2))); + break; + case DEBUG_UINT32: + DEBUG_WRITE_IN_LOG("0x%08x",*(uint32_t*)(pParamValues+(I*4))); + break; + case DEBUG_UINT64: + DEBUG_WRITE_IN_LOG("0x%016x",*(uint32_t*)(pParamValues+(I*8))); + break; + case DEBUG_FLOAT: + DEBUG_WRITE_IN_LOG("0x%08x",*(uint32_t*)(pParamValues+(I*4))); + break; + case DEBUG_DOUBLE: + DEBUG_WRITE_IN_LOG("0x%08x",*(uint32_t*)(pParamValues+(I*8))); + break; + default: + break; + } + /* + if(I<(ParamLength-1)) + DEBUG_WRITE_IN_LOG(", "); + */ + } + + } + + DEBUG_WRITE_IN_LOG("</%s>\n",pParamName); + + return Status; +} + +#endif +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debug.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,254 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/*! + *\file debug.h + *\brief All debug related features to be used with the High Level API are defined here. + */ + +#ifndef SENSOR_DEBUG +#define SENSOR_DEBUG +#ifndef __KERNEL__ +#include <stdio.h> +#include "host_serial.h" +#endif +#include "definitions.h" +//Debug Enable Switch +#define DEBUG_ENABLE 1 /*!< Set to 1 to enable Function Logging feature */ +#define I2CLOG_ENABLE 0 /*!< Set to 1 to enable I2C Logging feature */ + +/* Error code definition */ +#define SENSOR_ERROR_NONE 0 /*!< No error, Function executed successfully */ +#define SENSOR_ERROR 1 /*!< Generic error code */ + +#define COMMON_ERROR_BASE 0x0100 /*!< Base number for all errors common to all function */ +#define COMMON_INVALID_PARAMS COMMON_ERROR_BASE +0x001 /*!< Provided Invalid params */ +#define COMMON_INVALID_OUTPUT COMMON_ERROR_BASE +0x002 /*!< Provided Invalid output */ +#define SYSTEM_ERROR_BASE 0x0200 /*!< Base number for all errors related to system function */ + +#define RANGE_ERROR_BASE 0x0300 /*!< Base number for all errors related to ranging function */ + +#define ALS_ERROR_BASE 0x0400 /*!< Base number for all errors related to als function */ + +#define DEBUG_SESSION_NOT_OPENE 2 +#define DEBUG_ONLINE 0x10 /*!< Run time debugging. output via usb-serial port */ +#define DEBUG_OFFLINE 0x20 /*!< Offline debugging. Store debug log in memory space */ + +/* Debugging api definition */ +#define MINIMUM_LOG_LEVEL 0 +#define NORMAL_LOG_LEVEL 1 +#define VERBOSE_LOG_LEVEL 2 +#define I2C_LOG_LEVEL 3 + + +#ifdef DEBUG_ENABLE + +extern char* pDebugBuffer; +extern uint32_t DebugLogSize; +extern bool_t DebugStarted; + +/* Defines for external use */ +#define SPRINTF(buf,fmt,args...) sprintf((char *)buf,fmt,##args) + +#define LOG_FUNCTION_START(...) void* _pLogAllARgs_[]={ __VA_ARGS__ }; loggingFunctionStart(__func__, _pLogAllARgs_); +#define LOG_FUNCTION_END(returned) loggingFunctionEnd(__func__, returned, _pLogAllARgs_) + + +#define DEBUG_WRITE_IN_LOG(...) SPRINTF(pDebugBuffer,##__VA_ARGS__); loggingOutput(pDebugBuffer); +#define INTERNAL_DEBUG_LOG(...) if(DebugStarted){logDebugMessageStart(__func__);DEBUG_WRITE_IN_LOG(__VA_ARGS__);logDebugMessageEnd();} +#define INTERNAL_ERROR_LOG(...) logErrorMessageStart(__func__);DEBUG_WRITE_IN_LOG(__VA_ARGS__);logErrorMessageEnd(); + +#define DEBUG_LOG(...) INTERNAL_DEBUG_LOG(__VA_ARGS__);CUSTOMER_DEBUG_LOG(__VA_ARGS__) +#define SENSOR_ERROR_LOG(...) INTERNAL_ERROR_LOG(__VA_ARGS__);CUSTOMER_ERROR_LOG(__VA_ARGS__) + +/* Help compiling in C++ */ +#ifdef __cplusplus +extern "C"{ +#endif /*__cplusplus*/ + + +/*! + * \fn sensor_error loggingOpen() + * \brief Initialize debug sequence + * + * This function should be called at the beginning of the debugging session. It initializes everything that is necessary. + * This function allocates a big size buffer in order to store all logged data. + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingOpen(); + +/*! + * \fn sensor_error loggingClose() + * \brief Initialize debug sequence + * + * This function shall be called once logging functionalities are no more required. + * This function will free the memory allocated during the call to logingOpen function + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingClose(); + +/*! + * \fn sensor_error loggingSetMode() + * \brief Set up debug mode + * + * This function shall be called before start logging functions. + * This function will set the debug logging mode as realtime output or offline mode. + * \param[in] mode + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingSetMode(char mode); + +/*! + * \fn sensor_error loggingSetBuffer() + * \brief Set up offline debug buffer + * + * This function shall be called to set up offline debug buffer. + * This function will use the buffer created from user application to store the logging data. + * \param[in] pBuf pointer of user buffer + * \param[in] size size of user buffer + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingSetBuffer(char *pBuf, uint32_t size); + +/*! + * \fn sensor_error loggingStart(uint8_t DebugLevel) + * \brief Start logging all activities + * + * All device activity will be logged once this function is called. + * This function shall be called after loggingOpen(). + * \param[in] DebugLevel + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingStart(uint8_t DebugLevel); + +/*! + * \fn sensor_error loggingStop() + * \brief Stop logging all activities + * + * All device activity will stop to be logged once this function is called. + * This function shall be called after loggingStart(). + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingStop(); + +/*! + * \fn sensor_error logDebugMessageStart(const char* pFunctionName) + * \brief Write start section to log debug message + * \param[in] pFunctionName + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error logDebugMessageStart(const char* pFunctionName); + +/*! + * \fn sensor_error logDebugMessageEnd() + * \brief Write end section to log debug message + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error logDebugMessageEnd(); + +/*! + * \fn sensor_error logErrorMessageStart(const char* pFunctionName) + * \brief Write start section to log error message + * \param[in] pFunctionName + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error logErrorMessageStart(const char* pFunctionName); + +/*! + * \fn sensor_error logErrorMessageEnd() + * \brief Write end section to log error message + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error logErrorMessageEnd(); + +/*! + * \fn sensor_error loggingFunctionStart(const char* FunctionName, void **pFuncArguments) + * \brief log start of an API function + * \param[in] FunctionName + * \param[in] pFuncArguments + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingFunctionStart(const char* pFunctionName, void **pFuncArguments); + +/*! + * \fn sensor_error loggingFunctionEnd(const char* pFunctionName, sensor_error ReturnedValue, void **pFuncArguments) + * \brief log end of an API function + * \param[in] pFunctionName + * \param[in] ReturnedValue + * \param[in] pFuncArguments + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingFunctionEnd(const char* pFunctionName, sensor_error ReturnedValue, void **pFuncArguments); + +/*! + * \fn sensor_error loggingOutput(char* pBuffer) + * \brief Write messge bugger to actual output + * \param[in] pBuffer + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingOutput(char* pBuffer); + +/*! + * \fn sensor_error loggingOfflineOutput() + * \brief Write messge bugger from offline buffer to actual output + * \retval SENSOR_ERROR_NONE : Success + * \retval "Other Error Code" : Failure + */ +sensor_error loggingOfflineOutput(); + +/* help compiling in C++ */ +#ifdef __cplusplus +} +#endif /*__cplusplus*/ + + +#else + +#define SENSOR_ERROR_LOG(...) ; +#define DEBUG_LOG(...) ; +#define LOG_FUNCTION_START(...) ; +#define LOG_FUNCTION_END(...) ; +#define loggingOpen() SENSOR_ERROR_NONE +#define loggingClose() SENSOR_ERROR_NONE +#define loggingStart(...) SENSOR_ERROR_NONE +#define loggingStop() SENSOR_ERROR_NONE +#define loggingGetSize(...) SENSOR_ERROR_NONE +#define loggingReadBack(...) SENSOR_ERROR_NONE +#define loggingOutput(...) SENSOR_ERROR_NONE +#endif + +#endif /* DEBUG */ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/definitions.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,39 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/** + * @file definitions.h + * + * @brief All type definitions for the High Level API are defined here . + * + */ + +#ifndef _DEFINITIONS +#define _DEFINITIONS + +#include "platform.h" + +typedef uint16_t sensor_error; + +#endif + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/i2c_log.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,148 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + + +#include "platform.h" +#include "utilities.h" +#ifndef __KERNEL__ +#include <stdio.h> +#else +#include <linux/kernel.h> +#include <linux/string.h> +#endif +static bool_t _i2c_log_started = FALSE; + +void i2c_log_start(void) +{ + _i2c_log_started= TRUE; +} + +void i2c_log_end(void) +{ + _i2c_log_started= FALSE; +} + +void i2c_log_outputReadByteMsg(uint8_t value, uint32_t regOffset) +{ + const int32_t cMaxStrSize = 255; + char str[cMaxStrSize]; + if (_i2c_log_started) + { + sprintf(str, "Read reg : 0x%04X, Val : 0x%02X\n", regOffset, (uint32_t)value); + + debug2_print(str); + } +} + +void i2c_log_outputReadWordMsg(uint16_t value, uint32_t regOffset) +{ + const int32_t cMaxStrSize = 255; + char str[cMaxStrSize]; + if (_i2c_log_started) + { + sprintf(str, "Read reg : 0x%04X, Val : 0x%04X\n", regOffset, (uint32_t)value); + + debug2_print(str); + } +} + +void i2c_log_outputReadIntMsg(uint32_t value, uint32_t regOffset) +{ + const int32_t cMaxStrSize = 255; + char str[cMaxStrSize]; + + if (_i2c_log_started) + { + sprintf(str, "Read reg : 0x%04X, Val : 0x%08X\n", regOffset, (uint32_t)value); + + debug2_print(str); + } +} + +void i2c_log_outputReadMsg(uint8_t *data, uint32_t regOffset, int32_t size) +{ + const int32_t cMaxStrSize = 255; + char str[cMaxStrSize]; + char dataStr[cMaxStrSize]; + + if (_i2c_log_started) + { + array2HexCString(data, dataStr, size); + + sprintf(str, "Read reg : 0x%04X, Val : %s\n", regOffset, dataStr); + + debug2_print(str); + } +} + +void i2c_log_outputWriteByteMsg(uint8_t data, uint32_t regOffset) +{ + const int32_t cMaxStrSize = 255; + char str[cMaxStrSize]; + if (_i2c_log_started) + { + sprintf(str, "Write reg : 0x%04X, Val : 0x%02X\n", regOffset, (uint32_t)data); + + debug2_print(str); + } +} + +void i2c_log_outputWriteWordMsg(uint16_t data, uint32_t regOffset) +{ + const int32_t cMaxStrSize = 255; + char str[cMaxStrSize]; + if (_i2c_log_started) + { + + sprintf(str, "Write reg : 0x%04X, Val : 0x%04X\n", regOffset, (uint32_t)data); + + debug2_print(str); + } +} + +void i2c_log_outputWriteIntMsg(uint32_t data, uint32_t regOffset) +{ + const int32_t cMaxStrSize = 255; + char str[cMaxStrSize]; + if (_i2c_log_started) + { + sprintf(str, "Write reg : 0x%04X, Val : 0x%08X\n", regOffset, data); + + debug2_print(str); + } +} + +void i2c_log_outputWriteMsg(uint8_t *data, uint32_t regOffset, int32_t size) +{ + const int32_t cMaxStrSize = 255; + char str[cMaxStrSize]; + char dataStr[cMaxStrSize]; + if (_i2c_log_started) + { + array2HexCString(data, dataStr, size); + + sprintf(str, "Write reg : 0x%04X, Val : %s\n", regOffset, dataStr); + + debug2_print(str); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/i2c_log.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,122 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/*! + *\file i2c_log.h + *\brief I2C logging functionality. + */ + +#include "platform.h" + +/*! + * \brief Function to Start logging all I2C activities + * + * All I2C access activity will be logged once this function is called. + * This function shall be called when debug level is set to I2C_LOG_LEVEL. + * \retval none + */ +void i2c_log_start(); + +/*! + * \brief Function to Stop logging all I2C activities + * + * All I2C access activity will stop to be logged once this function is called. + * This function shall be called when debug level is set to I2C_LOG_LEVEL. + * \retval none + */ +void i2c_log_end(); + +/*! + *\brief Function to output an I2C read transaction for a single byte to log file. + * + *\param[in] value data value read. + *\param[in] regOffset I2C register identifier. + *\retval none + */ +void i2c_log_outputReadByteMsg(uint8_t value, uint32_t regOffset); + +/*! + *\brief Function to output an I2C read transaction for a single word to log file. + * + *\param[in] value data value read. + *\param[in] regOffset I2C register identifier. + *\retval none + */ +void i2c_log_outputReadWordMsg(uint16_t value, uint32_t regOffset); + +/*! + *\brief Function to output an I2C read transaction for a single int to log file. + * + *\param[in] value data value read. + *\param[in] regOffset I2C register identifier. + *\retval none + */ +void i2c_log_outputReadIntMsg(uint32_t value, uint32_t regOffset); + +/*! + *\brief Function to output an I2C read transaction for an array of bytes to log file. + * + *\param[in] data data values read. + *\param[in] regOffset I2C register identifier. + *\param[in] size size of the data buffer. + *\retval none + */ +void i2c_log_outputReadMsg(uint8_t *data, uint32_t regOffset, int32_t size); + +/*! + *\brief Function to output an I2C write transaction for a single byte to log file. + * + *\param[in] data data value written. + *\param[in] regOffset I2C register identifier. + *\retval none + */ +void i2c_log_outputWriteByteMsg(uint8_t data, uint32_t regOffset); + +/*! + *\brief Function to output an I2C write transaction for a single byte to log file. + * + *\param[in] data data value written. + *\param[in] regOffset I2C register identifier. + *\retval none + */ +void i2c_log_outputWriteWordMsg(uint16_t data, uint32_t regOffset); + +/*! + *\brief Function to output an I2C write transaction for a single byte to log file. + * + *\param[in] data data value written. + *\param[in] regOffset I2C register identifier. + *\retval none + */ +void i2c_log_outputWriteintMsg(uint32_t data, uint32_t regOffset); + +/*! + *\brief Function to output an I2C write transaction for an array of bytes to log file. + * + *\param[in] value data values written. + *\param[in] regOffset I2C register identifier. + *\param[in] size size of the data buffer. + *\retval none + */ +void i2c_log_outputWriteMsg(uint8_t *value, uint32_t regOffset, int32_t size); + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/platform.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,144 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +#include "definitions.h" +#include "platform.h" +#include "debug.h" +#include "i2c_log.h" +#ifndef __KERNEL__ +#include "i2c_stm32_mbed.h" +#include "timer_stm32_mbed.h" +#else +#include <linux/i2c.h> +#define I2C_M_WR 0x00 +#endif +static char time_str[255]; + +void debug1_print(char* pBuffer) +{ + //output to UART + serial_printf(pBuffer); +} + +void debug2_print(char* pBuffer) +{ + //output to UART + serial_printf(pBuffer); +} + +void i2c_initialise(uint32_t addr) +{ + stm32_i2c_initialise(addr); +} + +void i2c_close() +{ + stm32_i2c_close(); +} + +void i2c_write_byte(uint32_t reg, uint8_t data, uint8_t baseAddr) +{ + stm32_i2c_write_byte(reg, data, baseAddr); + i2c_log_outputWriteByteMsg(data, reg); +} + + +void i2c_write_word(uint32_t reg, uint16_t data, uint8_t baseAddr) +{ + stm32_i2c_write_word(reg, data, baseAddr); + i2c_log_outputWriteWordMsg(data, reg); +} + +void i2c_write(uint32_t reg, uint8_t *data, int32_t size, uint8_t baseAddr) +{ + stm32_i2c_write(reg, data, size, baseAddr); + i2c_log_outputWriteMsg(data, reg, size); +} + +uint8_t i2c_read_byte(uint32_t reg, uint8_t baseAddr) +{ + uint8_t data = stm32_i2c_read_byte(reg, baseAddr); + i2c_log_outputReadByteMsg(data, reg); + return data; +} + +uint16_t i2c_read_word(uint32_t reg, uint8_t baseAddr) +{ + uint16_t data = stm32_i2c_read_word(reg, baseAddr); + i2c_log_outputReadWordMsg(data, reg); + return data; +} + +uint32_t i2c_read_uint32(uint32_t reg, uint8_t baseAddr) +{ + uint32_t data = stm32_i2c_read_int(reg, baseAddr); + i2c_log_outputReadIntMsg(data, reg); + return data; +} + +void i2c_read(uint32_t reg, uint8_t *dataOut, int32_t size, uint8_t baseAddr) +{ + stm32_i2c_read(reg, dataOut, size, baseAddr); + i2c_log_outputReadMsg(dataOut, reg, size); +} + +void timer_start() +{ + stm32_timer_start(); +} + +double_t timer_elapsedTime() +{ + return stm32_timer_elapsed_time(); +} + +void timer_stop() +{ + stm32_timer_stop(); +} + +void timer_wait_ms(int32_t ms) +{ + stm32_timer_wait_ms((int)ms); +} + +void timer_wait_us(int32_t us) +{ + stm32_timer_wait_us((int)us); +} + +uint32_t timer_get_clock_time_usecs() +{ + return stm32_timer_get_clock_time_usecs(); +} + +uint32_t timer_get_clock_time_msecs() +{ + return stm32_timer_get_clock_time_msecs(); +} + +char* timer_get_clock_timestamp() +{ + stm32_timer_get_clock_timestamp(time_str); + return time_str; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/platform.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,210 @@ +/******************************************************************************* +################################################################################ +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/** + * @file platform.h + * + * @brief All platform specific declarations to be used by the High Level API are defined here. + * The developer is responsible for providing the implementation of the prototypes declared. + * + */ + +#ifndef _PLATFORM +#define _PLATFORM +#ifndef __KERNEL__ +#include <stdbool.h> +#include <stdint.h> +#endif +/** @brief Typedef defining .\n + * The developer should modify this to suit the platform being deployed. + */ +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +/** @brief Typedef defining 8 bit unsigned char type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef unsigned char bool_t; + +#ifndef _STDINT_H + +/** @brief Typedef defining 64 bit unsigned long type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef unsigned long long uint64_t; + +/** @brief Typedef defining 64 bit long type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef long long long64_t; + +/** @brief Typedef defining 32 bit unsigned int type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef unsigned int uint32_t; + +/** @brief Typedef defining 32 bit int type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef int int32_t; + +/** @brief Typedef defining 16 bit unsigned short type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef unsigned short uint16_t; + +/** @brief Typedef defining 16 bit short type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef short int16_t; + +/** @brief Typedef defining 8 bit unsigned char type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef unsigned char uint8_t; + +/** @brief Typedef defining 8 bit char type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef signed char int8_t; + +#endif //_STDINT_H + +/** @brief Typedef defining 64 bit double type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef double double_t; + +/** @brief Typedef defining 32 bit float type.\n + * The developer should modify this to suit the platform being deployed. + */ +typedef float float_t; + +#ifndef NULL +#define NULL 0 +#endif + +/** + * @brief Method to print a given string to the program output. + */ +void debug1_print(char *pBuffer); + +/** + * @brief Method to print a given string to the program output. + */ +void debug2_print(char *pBuffer); + +/** + * Method to initialise a given I2C device for a given I2C + * address. + */ +void i2c_initialise(uint32_t addr); + +/** + * Method to close device if opened. + */ +void i2c_close(); + +/** + * Method to write a single byte to a given I2C reg index. + * Throws WriteFail upon failure. + */ +void i2c_write_byte(uint32_t reg, uint8_t data, uint8_t baseAddr); + +/** + * Method to write a single word to a given I2C reg index. + * Throws WriteFail upon failure. + */ +void i2c_write_word(uint32_t reg, uint16_t data, uint8_t baseAddr); + +/** + * Method to write an array of bytes to a given I2C reg index. + * Throws WriteFail upon failure. + */ +void i2c_write(uint32_t reg, uint8_t *data, int32_t size, uint8_t baseAddr); + +/** + * Method to read a single byte from a given I2C reg index. + * Throws ReadFail upon error. + */ +uint8_t i2c_read_byte(uint32_t reg, uint8_t baseAddr); + +/** + * Method to read a two byte word from a given I2C reg index. + * Throws ReadFail upon error. + */ +uint16_t i2c_read_word(uint32_t reg, uint8_t baseAddr); + +/** + * Method to read an int32 from a given I2C reg index. + * Throws ReadFail upon error. + */ +uint32_t i2c_read_uint32(uint32_t reg, uint8_t baseAddr); + +/** + * Method to read multiple bytes from a given I2C reg index. + * Throws ReadFail upon error. + */ +void i2c_read(uint32_t reg, uint8_t* data, int32_t size, uint8_t baseAddr); + +/** + * Method to start the timer. + */ +void timer_start(); + +/** + * Method reporting the number of seconds elapsed since the timer was started. + */ +double_t timer_elapsedTime(); + +/** + * Method to stop the timer. + */ +void timer_stop(); + +/** + * Method to wait a given number of ms. + */ +void timer_wait_ms(int32_t ms); + +/** + * Method to wait a given number of us + */ +void timer_wait_us(int32_t us); + +/** + * Method to report the current clock time in us. + */ +uint32_t timer_get_clock_time_usecs(); + +/** + * Method to report the current clock time in ms. + */ +uint32_t timer_get_clock_time_msecs(); + +#endif /* _PLATFORM */ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/range_upscaling_driver.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,275 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/* +''' +Application-level functions used for configuration and operation during extended +ranging. +''' +*/ + +//----------------------------------------------------------------------------- +// module imports +//----------------------------------------------------------------------------- + +// ST libraries + +#include "range_upscaling_driver.h" + +#include "common_driver.h" +#include "ranging_driver.h" +#include "debug.h" +#include "platform.h" + + +//----------------------------------------------------------------------------- +// constant definitions +//----------------------------------------------------------------------------- +#define IDENTIFICATION_MODEL_ID 0x00 +#define IDENTIFICATION_MODULE_REV_MAJOR 0x03 +#define IDENTIFICATION_MODULE_REV_MINOR 0x04 + +#define RESULT_RANGE_VAL 0x62 + +#define RANGE_SCALER 0x96 + +//----------------------------------------------------------------------------- +// global variable declarations +//----------------------------------------------------------------------------- +static ExtRangeScaler _rangeScaler = Scale2X; + +//----------------------------------------------------------------------------- +// method definitions +//----------------------------------------------------------------------------- + +static void er_set_register_tuning(uint8_t device_base_address); + + +static void er_set_register_tuning(uint8_t device_base_address) +{ + // apply REGISTER_TUNING_ER02_100614_CustomerView.tx + + // Mandatory : private registers + i2c_write_byte(0x0207, 0x01, device_base_address); + i2c_write_byte(0x0208, 0x01, device_base_address); + i2c_write_byte(0x0096, 0x00, device_base_address); + i2c_write_byte(0x0097, 0x54, device_base_address); + i2c_write_byte(0x00e3, 0x00, device_base_address); + i2c_write_byte(0x00e4, 0x04, device_base_address); + i2c_write_byte(0x00e5, 0x02, device_base_address); + i2c_write_byte(0x00e6, 0x01, device_base_address); + i2c_write_byte(0x00e7, 0x03, device_base_address); + i2c_write_byte(0x00f5, 0x02, device_base_address); + i2c_write_byte(0x00d9, 0x05, device_base_address); + i2c_write_byte(0x00db, 0xce, device_base_address); + i2c_write_byte(0x00dc, 0x03, device_base_address); + i2c_write_byte(0x00dd, 0xf8, device_base_address); + i2c_write_byte(0x009f, 0x00, device_base_address); + i2c_write_byte(0x00a3, 0x28, device_base_address); + i2c_write_byte(0x00b7, 0x00, device_base_address); + i2c_write_byte(0x00bb, 0x28, device_base_address); + i2c_write_byte(0x00b2, 0x09, device_base_address); + i2c_write_byte(0x00ca, 0x09, device_base_address); + i2c_write_byte(0x0198, 0x01, device_base_address); + i2c_write_byte(0x01b0, 0x17, device_base_address); + i2c_write_byte(0x01ad, 0x00, device_base_address); + i2c_write_byte(0x00ff, 0x05, device_base_address); + i2c_write_byte(0x0100, 0x05, device_base_address); + i2c_write_byte(0x0199, 0x05, device_base_address); + i2c_write_byte(0x01a6, 0x1b, device_base_address); + i2c_write_byte(0x01ac, 0x3e, device_base_address); + i2c_write_byte(0x01a7, 0x1f, device_base_address); + i2c_write_byte(0x0030, 0x00, device_base_address); + + // Recommended : Public registers - See data sheet for more detail + i2c_write_byte(0x0011, 0x10, device_base_address); // Enables polling for �New Sample ready� when measurement completes + i2c_write_byte(0x010a, 0x30, device_base_address); // Set the averaging sample period (compromise between lower noise and increased execution time) + i2c_write_byte(0x003f, 0x46, device_base_address); // Sets the light and dark gain (upper nibble). Dark gain should not be changed. + i2c_write_byte(0x0031, 0xFF, device_base_address); // sets the # of range measurements after which auto calibration of system is performed + i2c_write_byte(0x0040, 0x63, device_base_address); // Set ALS integration time to 100ms + i2c_write_byte(0x002e, 0x01, device_base_address); // perform a single temperature calibration of the ranging sensor + i2c_write_byte(0x002c, 0xff, device_base_address); // set SNR limit to 0.06 + + // Optional: Public registers - See data sheet for more detail + i2c_write_byte(0x001b, 0x09, device_base_address); // Set default ranging inter-measurement period to 100ms + i2c_write_byte(0x003e, 0x31, device_base_address); // Set default ALS inter-measurement period to 500ms + i2c_write_byte(0x0014, 0x24, device_base_address); // Configures interrupt on �New sample ready� +} + +sensor_error er_set_static_config(uint8_t device_base_address) +{ + unsigned char module_id, rev_maj, rev_min; + bool_t module; + int32_t programmedOffset; + + LOG_FUNCTION_START((void*)&device_base_address); + + module_id = i2c_read_byte(IDENTIFICATION_MODEL_ID, device_base_address); + // for use with NVM-programmed parts + rev_maj = i2c_read_byte(IDENTIFICATION_MODULE_REV_MAJOR, device_base_address); + rev_min = i2c_read_byte(IDENTIFICATION_MODULE_REV_MINOR, device_base_address); + + module = FALSE; + if ((module_id == 0xb4) && (rev_maj == 0x01) && (rev_min == 0x02)) + module = TRUE; + + if (module) + er_set_register_tuning(device_base_address); + + // VHV automatically run on parts that are NVM-programmed, ie customer parts! + + if (common_get_system_fresh_out_of_reset(device_base_address)) + { + // must write the scaler at least once to the device to ensure the scaler is in a known state. + er_set_scaler(_rangeScaler, device_base_address); + + // for upscaled ranging, recalibrate the part-2-part offset + programmedOffset = er_range_get_part2Part_range_offset(device_base_address); + er_set_part2Part_range_offset(device_base_address, (uint8_t)(programmedOffset/_rangeScaler)); + + // *** only if using glass **** + // xtalk_height = ranging.Range_Get_Crosstalk_Valid_Height(device) + // ranging.Range_Set_Crosstalk_Valid_Height(device, int(xtalk_height/_rangeScaler)) + + common_clear_system_fresh_out_of_reset(device_base_address); + } + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error er_set_part2Part_range_offset(uint8_t device_base_address, uint8_t part_to_part_range_offset) +{ + LOG_FUNCTION_START((void*)&device_base_address,(void*)&part_to_part_range_offset); + + i2c_write_byte(SYSRANGE_PART_TO_PART_RANGE_OFFSET, part_to_part_range_offset, device_base_address); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint8_t er_range_get_part2Part_range_offset(uint8_t device_base_address) +{ + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSRANGE_PART_TO_PART_RANGE_OFFSET, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint32_t er_get_result(uint8_t device_base_address) +{ + uint32_t range = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + + range = (uint32_t)(i2c_read_byte(RESULT_RANGE_VAL, device_base_address) * _rangeScaler); + + LOG_FUNCTION_END(range); + + return range; +} + + +sensor_error er_set_scaler(uint8_t scaler, uint8_t device_base_address) +{ + //const uint16_t cMask = 0x01ff; + const uint16_t cScalerVal1X = 253; + const uint16_t cScalerVal2X = 127; + const uint16_t cScalerVal3X = 84; + uint32_t ret=0; + uint16_t scalerVal = cScalerVal2X; + + LOG_FUNCTION_START((void*)&device_base_address); + + if(scaler == Scale1X) + { + _rangeScaler = Scale1X; + scalerVal = cScalerVal1X; + } + else if(scaler == Scale2X) + { + _rangeScaler = Scale2X; + scalerVal = cScalerVal2X; + } + else + { + _rangeScaler = Scale3X; + scalerVal = cScalerVal3X; + } + + i2c_write_word(RANGE_SCALER, scalerVal, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t er_get_scaler(uint8_t device_base_address) +{ + uint8_t ret = _rangeScaler; + + //LOG_FUNCTION_START((void*)&device_base_address); + + //LOG_FUNCTION_END(ret); + + return ret; +} + +uint32_t er_get_upper_limit(uint8_t device_base_address) +{ + const uint32_t cScalerMax1X = 255; + const uint32_t cScalerMax2X = 510; + const uint32_t cScalerMax3X = 765; + uint32_t upperLim = cScalerMax1X; + + LOG_FUNCTION_START((void*)&device_base_address); + + if(_rangeScaler == Scale2X) + { + upperLim = cScalerMax2X; + } + else if(_rangeScaler == Scale3X) + { + upperLim = cScalerMax3X; + } + + LOG_FUNCTION_END(upperLim); + + return upperLim; +} + + +uint32_t er_get_lower_limit(uint8_t device_base_address) +{ + uint32_t lowerLimit = 0; + LOG_FUNCTION_START((void*)&device_base_address); + + LOG_FUNCTION_END(lowerLimit); + + return lowerLimit; +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/range_upscaling_driver.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,121 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/*! + *\file range_upscaling_driver.h + *\brief Application-level functions used for configuration and operation during upscaled ranging. + */ + + +#ifndef EXT_RANGING_DRIVER +#define EXT_RANGING_DRIVER + +//----------------------------------------------------------------------------- +// module imports +//----------------------------------------------------------------------------- + +// ST libraries +#include "definitions.h" + +//----------------------------------------------------------------------------- +// type definitions +//----------------------------------------------------------------------------- +typedef enum { Scale1X = 1, Scale2X = 2, Scale3X = 3 } ExtRangeScaler; + +//----------------------------------------------------------------------------- +// method definitions +//----------------------------------------------------------------------------- + +/*! + *\brief Device setup for Upscaled Ranging operations. + * + * Device setup for extended-range operations. To apply these settings the operation bit (bit 0) in the SYSRANGE__START & SYSALS__START Registers must be cleared. + *\param[in] device_base_address + *\retval sensor_error + */ +sensor_error er_set_static_config(uint8_t device_base_address); + +/*! + *\brief Set the Part-to-Part Range Offset + * + * Set part-to-part range offset in the sysrange_part_to_part_range_offset register. + * + *\param[in] device_base_address + *\param[in] part_to_part_range_offset + *\retval sensor_error + */ +sensor_error er_set_part2Part_range_offset(uint8_t device_base_address, uint8_t part_to_part_range_offset); + +/*! + *\brief Report the part-to-part range offset. + * + * Report the part-to-part range offset from sysrange_part_to_part_range_offset register. + * + *\param[in] device_base_address + *\retval Byte-wide, integer + */ +uint8_t er_range_get_part2Part_range_offset(uint8_t device_base_address); + +/*! + *\brief Report result from last completed upscaled ranging operation. + *\param[in] device_base_address + *\retval 32-bit integer + */ +uint32_t er_get_result(uint8_t device_base_address); + +/*! + *\brief Set the extended range scaling to either 2X or 3X scaling. An increased scaler + *\ will result in a greater measurement distance but more coarse resolution. + *\param[in] scaler + *\param[in] device_base_address + *\retval sensor_error + */ +sensor_error er_set_scaler(uint8_t scaler, uint8_t device_base_address); + +/*! + *\brief Reports the current scaler setting. + *\param[in] device_base_address + *\retval Byte-wide, integer + */ +uint8_t er_get_scaler(uint8_t device_base_address); + + +/** + * @brief Function to return the Maximum range reported by the + * sensor. + *\param[in] device_base_address + *\retval 32-bit integer + */ +uint32_t er_get_upper_limit(uint8_t device_base_address); + +/** + * @brief Function to return the Minimum range reported by the + * sensor. + *\param[in] device_base_address + *\retval 32-bit integer + */ +uint32_t er_get_lower_limit(uint8_t device_base_address); + +#endif + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ranging_driver.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,686 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +// Ranging_Driver.c + +/* +''' +Application-level functions used for configuration and operation during ranging. +''' +*/ + + +// ST libraries +#include "ranging_driver.h" +#include "utilities.h" +#include "platform.h" +#include "debug.h" +//----------------------------ECE_FACTOR------------------------------------------------- +// global variable declarations +//----------------------------------------------------------------------------- +//double_t ece_factor = ECE_FACTOR; // user set ECE margin (< 1.00 for maximum detection, > 1.00 for minimizing red glow) +uint32_t ece_factor_m = ECE_FACTOR_M; +uint32_t ece_factor_d = ECE_FACTOR_D; + +//----------------------------------------------------------------------------- +// function definitions +//----------------------------------------------------------------------------- + +sensor_error range_set_dynamic_config(uint8_t device_base_address) +{ + + LOG_FUNCTION_START((void*)&device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error range_set_systemMode(uint8_t device_base_address, int32_t mode) +{ + uint8_t startRegVal; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&mode); + switch (mode) + { + case RANGE_START_SINGLESHOT: + i2c_write_byte(SYSRANGE_START, mode, device_base_address); + break; + case RANGE_START_CONTINUOUS: + // ensure mode bit is set! + startRegVal = i2c_read_byte(SYSRANGE_START, device_base_address); + startRegVal |= 0x03; + i2c_write_byte(SYSRANGE_START, startRegVal, device_base_address); + break; + case RANGE_STOP: + // ensure mode bit is left unaffected! + startRegVal = i2c_read_byte(SYSRANGE_START, device_base_address); + startRegVal |= 0x01; + // set the bit, as it is a toggle state, not a 0=Off, 1=ON! + i2c_write_byte(SYSRANGE_START, startRegVal, device_base_address); + break; + default: + ret = COMMON_INVALID_PARAMS; + } + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_systemMode(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSRANGE_START, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_result(uint8_t device_base_address) +{ + return i2c_read_byte(RESULT_RANGE_VAL, device_base_address); +} + +uint32_t range_get_signal_rate(uint8_t device_base_address) +{ + uint32_t rawVal = (uint32_t)i2c_read_word(RESULT_RANGE_SIGNAL_RATE, device_base_address); + + return rawVal; +} + +sensor_error range_get_full_result(uint8_t device_base_address) +{ +/* + return_list = [] + +# I2C base address is 8-bit indexing + I2C_base_address = Utilities.device['reg_bank_go2']['I2C_SLAVE_DEVICE_ADDRESS'].read() + I2C_base_address *= 2 # convert from 7-bit to 8-bit address + +# make the indexing easy, read from index 0x60, but we only want data from 0x62! +# reading from indices 0x60-0x84 +# common.Set_System_Group_Parameter_Hold() + regs = Utilities.device.comms['read'](I2C_base_address, 0x60, 0x25) + conv_threshold = Utilities.device['reg_bank_go2']['USER_CONV_CTRL_RETURN_THRESHOLD_FINE'].read() * 256 +# common.Clear_System_Group_Parameter_Hold() + + result_range_val = regs[2] # address 0x62 + result_range_stray = regs[3] + result_range_raw = regs[4] +# no results at 0x65 + result_range_return_rate = (regs[6] << 8) + regs[7] + result_range_reference_rate = (regs[8] << 8) + regs[9] +# indices 0x6A, 0x6B empty + result_range_Return_VCSEL_count = (regs[0x0C] << 24) + (regs[0x0D] << 16) + (regs[0x0E] << 8) + regs[0x0F] + result_range_Reference_VCSEL_count = (regs[0x10] << 24) + (regs[0x11] << 16) + (regs[0x12] << 8) + regs[0x13] + result_range_Return_AMB_count = (regs[0x14] << 24) + (regs[0x15] << 16) + (regs[0x16] << 8) + regs[0x17] + result_range_Reference_AMB_count = (regs[0x18] << 24) + (regs[0x19] << 16) + (regs[0x1A] << 8) + regs[0x1B] + result_range_Return_Conv_time = (regs[0x1C] << 24) + (regs[0x1D] << 16) + (regs[0x1E] << 8) + regs[0x1F] + result_range_Reference_Conv_time = (regs[0x20] << 24) + (regs[0x21] << 16) + (regs[0x22] << 8) + regs[0x23] + + return_list.append( result_range_val ) + return_list.append( result_range_stray ) + return_list.append( result_range_raw ) + return_list.append( result_range_return_rate ) + return_list.append( result_range_reference_rate ) + return_list.append( result_range_Return_VCSEL_count ) + return_list.append( result_range_Reference_VCSEL_count ) + return_list.append( result_range_Return_AMB_count ) + return_list.append( result_range_Reference_AMB_count ) + return_list.append( result_range_Return_Conv_time ) + return_list.append( result_range_Reference_Conv_time ) + return_list.append( conv_threshold ) + return return_list + +*/ + return SENSOR_ERROR_NONE; + +} + +sensor_error range_set_high_threshold(uint8_t device_base_address, uint8_t threshold) +{ + //threshold type is uint8_t. no need to check parameter since from 0-255 + LOG_FUNCTION_START((void*)&device_base_address,(void*)&threshold); + i2c_write_byte(SYSRANGE_THRESH_HIGH, threshold, device_base_address); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +uint8_t range_get_high_threshold(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSRANGE_THRESH_HIGH, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error range_set_low_threshold(uint8_t device_base_address, uint8_t threshold) +{ + sensor_error ret = SENSOR_ERROR_NONE; + //threshold type is uint8_t. no need to check parameter since from 0-255 + LOG_FUNCTION_START((void*)&device_base_address,(void*)&threshold); + i2c_write_byte(SYSRANGE_THRESH_LOW, threshold, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_low_threshold(uint8_t device_base_address) +{ + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSRANGE_THRESH_LOW, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error range_set_interMeasurement_period(uint8_t device_base_address, uint16_t intermeasurement_period) +{ + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&intermeasurement_period); + if (intermeasurement_period > 255*10) + { + // Clipping value to max of 2.55s + intermeasurement_period = 255*10; + } + i2c_write_byte(SYSRANGE_INTERMEASUREMENT_PERIOD, (uint8_t)(intermeasurement_period/10), device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint16_t range_get_interMeasurement_period(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSRANGE_INTERMEASUREMENT_PERIOD, device_base_address); + ret *=10; //return in ms + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error range_set_max_convergence_time(uint8_t device_base_address, int32_t max_convergence_time) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address,(void*)&max_convergence_time); + i2c_write_byte(SYSRANGE_MAX_CONVERGENCE_TIME, max_convergence_time, device_base_address); + range_set_early_convergence_estimate_threshold(device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_max_convergence_time(uint8_t device_base_address) +{ + return i2c_read_byte(SYSRANGE_MAX_CONVERGENCE_TIME, device_base_address); +} + +sensor_error range_set_crosstalk_compensation_rate(uint8_t device_base_address, int32_t crosstalk_compensation_rate) +{ + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&crosstalk_compensation_rate); + i2c_write_word(SYSRANGE_CROSSTALK_COMPENSATION_RATE, crosstalk_compensation_rate, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +int32_t range_get_crosstalk_compensation_rate(uint8_t device_base_address) +{ + uint32_t ret=0; + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_word(SYSRANGE_CROSSTALK_COMPENSATION_RATE, device_base_address); + LOG_FUNCTION_END(NULL); + + return ret; +} + +sensor_error range_set_crosstalk_compensation_range(uint8_t device_base_address, int32_t crosstalk_compensation_range) +{ + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&crosstalk_compensation_range); + i2c_write_byte(SYSRANGE_CROSSTALK_COMPENSATION_RANGE, crosstalk_compensation_range, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_crosstalk_compensation_range(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSRANGE_CROSSTALK_COMPENSATION_RANGE, device_base_address); + LOG_FUNCTION_END(NULL); + + return ret; +} + +sensor_error range_set_crosstalk_valid_height(uint8_t device_base_address, int32_t crosstalk_valid_height) +{ + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&crosstalk_valid_height); + i2c_write_byte(SYSRANGE_CROSSTALK_VALID_HEIGHT, crosstalk_valid_height, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_crosstalk_valid_height(uint8_t device_base_address) +{ + uint8_t ret; + LOG_FUNCTION_START((void*)&device_base_address); + ret = i2c_read_byte(SYSRANGE_CROSSTALK_VALID_HEIGHT, device_base_address); + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error range_set_early_convergence_estimate_threshold(uint8_t device_base_address) +{ + sensor_error ret = SENSOR_ERROR_NONE; + + uint32_t cMicroSecPerMilliSec = 1000; + uint32_t cEceSampleTime_us = 500; + uint32_t maxConv_ms = (uint32_t)range_get_max_convergence_time(device_base_address); + uint32_t convergTime_us = maxConv_ms * cMicroSecPerMilliSec - range_get_vernier_ave_total_time(device_base_address); + uint32_t fineThresh = range_get_converg_ctrl_rtn_thresh_fine(device_base_address); + uint32_t eceThresh = ece_factor_m * cEceSampleTime_us * fineThresh/(convergTime_us * ece_factor_d); + LOG_FUNCTION_START((void*)&device_base_address,); + + i2c_write_word(SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, (uint16_t)eceThresh, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_early_convergence_estimate_threshold(uint8_t device_base_address) +{ + uint8_t ret; + + LOG_FUNCTION_START((void*)&device_base_address); + + ret = i2c_read_word(SYSRANGE_EARLY_CONVERGENCE_ESTIMATE, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint32_t range_get_vernier_ave_total_time(uint8_t device_base_address) +{ + uint32_t cFwOverhead_us = 24; + uint32_t cVernVcpSetupTime_us = 70; + uint32_t cPLL2_StartupDelay_us = 200; + uint8_t cVernMeasMask = 0x07; + uint32_t vernSamples; + uint32_t vernSamplePeriod; + uint32_t singleVernTime_us; + uint32_t totalVernAveTime_us; + + LOG_FUNCTION_START((void*)&device_base_address); + + // Calculate Vernier average time + vernSamples = (uint32_t)(i2c_read_byte(VERNIER_MEASUREMENTS, device_base_address) & cVernMeasMask); + vernSamplePeriod = (uint32_t)i2c_read_byte(VERNIER_RIPPLE_AVE_SAMPLE_PERIOD, device_base_address); + singleVernTime_us = cFwOverhead_us + cVernVcpSetupTime_us + (vernSamplePeriod * 10); + totalVernAveTime_us = (vernSamples + 1) * singleVernTime_us + cPLL2_StartupDelay_us; + + LOG_FUNCTION_END(totalVernAveTime_us); + + return totalVernAveTime_us; +} + +uint32_t range_get_converg_ctrl_rtn_thresh_fine(uint8_t device_base_address) +{ + //uint32_t cBitMask = 0x00FFFFFFF; + uint32_t cFineThreshLsb = 256; + uint32_t rawValue; + uint32_t realValue; + + LOG_FUNCTION_START((void*)&device_base_address); + + rawValue = i2c_read_uint32(USER_CONV_CTRL_RETURN_THRESHOLD_FINE, device_base_address); + realValue = rawValue * cFineThreshLsb; + + LOG_FUNCTION_END(realValue); + + return realValue; +} + +sensor_error range_set_ignore_valid_height(uint8_t device_base_address, int32_t ignore_valid_height) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address, (void*)&ignore_valid_height); + + i2c_write_byte(SYSRANGE_RANGE_IGNORE_VALID_HEIGHT, ignore_valid_height, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_ignore_valid_height(uint8_t device_base_address) +{ + uint8_t ret; + LOG_FUNCTION_START((void*)&device_base_address); + + ret = i2c_read_byte(SYSRANGE_RANGE_IGNORE_VALID_HEIGHT, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error range_set_range_ignore_threshold(uint8_t device_base_address, uint32_t range_ignore_threshold) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address, (void*)&range_ignore_threshold); + i2c_write_word(SYSRANGE_RANGE_IGNORE_THRESHOLD, + (uint16_t)range_ignore_threshold, + device_base_address); + + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint32_t range_get_range_ignore_threshold(uint8_t device_base_address) +{ + uint16_t ignoreThreshRegVal = i2c_read_word(SYSRANGE_RANGE_IGNORE_THRESHOLD, device_base_address); + return ignoreThreshRegVal; +} + +sensor_error range_set_emitter_block_threshold(uint8_t device_base_address, int32_t emitter_block_threshold) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address, (void*)&emitter_block_threshold); + i2c_write_word(SYSRANGE_EMITTER_BLOCK_THRESHOLD, emitter_block_threshold, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_emitter_block_threshold(uint8_t device_base_address) +{ + return i2c_read_word(SYSRANGE_EMITTER_BLOCK_THRESHOLD, device_base_address); +} +#ifndef __KERNEL__ +sensor_error range_set_snr_thresh(uint8_t device_base_address, float_t snrThresh) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address, (void*)&snrThresh); + + const float cRegFractionLsb = 0.0625f; + const float cRegWholeLsb = 1.0f; + const float cReciprocalMax = 16.0f - cRegFractionLsb; + const float cSnrMin = 1.0f/cReciprocalMax; + + uint8_t snrThresRegVal; + + // Taking the reciprocal into account the allowable SNR range is 0.0625...16.0. + if(snrThresh < cSnrMin) + { + snrThresh = cSnrMin; + } + + float snrthreshMult = 1.0f/snrThresh; + snrThresRegVal = (uint8_t)encodeTo4_4_Format(snrthreshMult); + i2c_write_byte(SYSRANGE_MAX_AMBIENT_LEVEL_MULT, (uint8_t)snrThresRegVal, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + + +float range_get_snr_thresh(uint8_t device_base_address) +{ + LOG_FUNCTION_START((void*)&device_base_address); + + uint8_t snrthreshMult = i2c_read_byte(SYSRANGE_MAX_AMBIENT_LEVEL_MULT, device_base_address); + float snrThresh = 1.0f/decodeFrom4_4_Format((uint32_t)snrthreshMult); + + LOG_FUNCTION_END(snrThresh); + + return snrThresh; +} +#endif +sensor_error range_set_range_check_enables(uint8_t device_base_address, int32_t range_check_enables) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address, (void*)&range_check_enables); + + i2c_write_byte(SYSRANGE_RANGE_CHECK_ENABLES, range_check_enables, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_range_check_enables(uint8_t device_base_address) +{ + return i2c_read_byte(SYSRANGE_RANGE_CHECK_ENABLES, device_base_address); +} + +sensor_error range_set_vhv_recalibrate(uint8_t device_base_address, int32_t VHV_Recalibrate) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address, (void*)&VHV_Recalibrate); + + i2c_write_byte(SYSRANGE_VHV_RECALIBRATE, VHV_Recalibrate, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_vhv_recalibrate(uint8_t device_base_address) +{ + return i2c_read_byte(SYSRANGE_VHV_RECALIBRATE, device_base_address); +} + +sensor_error range_set_vhv_repeat_rate(uint8_t device_base_address, int32_t VHV_repeat_rate) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address, (void*)&VHV_repeat_rate); + + i2c_write_byte(SYSRANGE_VHV_REPEAT_RATE, VHV_repeat_rate, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_vhv_repeat_rate(uint8_t device_base_address) +{ + return i2c_read_byte(SYSRANGE_VHV_REPEAT_RATE, device_base_address); +} + +int32_t range_get_result_status(uint8_t device_base_address) +{ + return i2c_read_byte(RESULT_RANGE_STATUS, device_base_address); +} + +bool_t range_get_device_ready(uint8_t device_base_address) +{ + if (i2c_read_byte(RESULT_RANGE_STATUS, device_base_address) & RANGE_DEVICE_READY) + { + return TRUE; + } + return FALSE; +} + +uint8_t range_get_result_error_codes(uint8_t device_base_address) +{ + return (i2c_read_byte(RESULT_RANGE_STATUS, device_base_address) & RANGE_ERROR_CODE) >> 4; +} + +sensor_error range_set_ece_factor(uint8_t device_base_address, uint32_t ECE_Factor_M, uint32_t ECE_Factor_D) +{ + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&ECE_Factor_M, (void*)&ECE_Factor_D); + + ece_factor_m = ECE_Factor_M; + ece_factor_d = ECE_Factor_D; + range_set_early_convergence_estimate_threshold(device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error range_get_ece_factor(uint32_t *pece_factor_m, uint32_t *pece_factor_d) +{ + *pece_factor_m = ece_factor_m; + *pece_factor_d = ece_factor_d; + + return SENSOR_ERROR_NONE; +} + +sensor_error range_set_system_interrupt_config_gpio(uint8_t device_base_address, uint8_t Ranging_GPIO_interrupt_config) +{ + uint8_t reg; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address,(void*)&Ranging_GPIO_interrupt_config); + switch (Ranging_GPIO_interrupt_config) + { + case CONFIG_GPIO_INTERRUPT_DISABLED: + case CONFIG_GPIO_INTERRUPT_LEVEL_LOW: + case CONFIG_GPIO_INTERRUPT_LEVEL_HIGH: + case CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW: + case CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY: + reg = i2c_read_byte(SYSTEM_INTERRUPT_CONFIG_GPIO, device_base_address); + reg &= 0x38; // preserve only the ALS part of reg + i2c_write_byte(SYSTEM_INTERRUPT_CONFIG_GPIO, + (reg | Ranging_GPIO_interrupt_config), + device_base_address); + break; + default : + ret = COMMON_INVALID_PARAMS; + break; + } + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_system_interrupt_config_gpio(uint8_t device_base_address) +{ + uint8_t ret=0; + + LOG_FUNCTION_START((void*)&device_base_address); + // expose only bits [2:0] + + ret = (i2c_read_byte(SYSTEM_INTERRUPT_CONFIG_GPIO, device_base_address) & 0x07); + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error range_set_system_interrupt_clear(uint8_t device_base_address) +{ + sensor_error ret = SENSOR_ERROR_NONE; + LOG_FUNCTION_START((void*)&device_base_address); + + i2c_write_byte(SYSTEM_INTERRUPT_CLEAR, INTERRUPT_CLEAR_RANGING, device_base_address); + + LOG_FUNCTION_END(ret); + + return ret; +} + +uint8_t range_get_result_interrupt_status_gpio(uint8_t device_base_address) +{ + uint8_t ret = 0; + + LOG_FUNCTION_START((void*)&device_base_address); + + ret = (i2c_read_byte(RESULT_INTERRUPT_STATUS_GPIO, device_base_address) & 0x07); + + LOG_FUNCTION_END(ret); + + return ret; +} + +sensor_error common_set_history_buffer_range_mode_enable(uint8_t device_base_address) +{ + uint8_t mode; + sensor_error ret = SENSOR_ERROR_NONE; + + LOG_FUNCTION_START((void*)&device_base_address); + + mode = i2c_read_byte(SYSTEM_HISTORY_CTRL, device_base_address); + mode = mode & 0xFD; // clear bit 1 to set to range mode + mode = mode | 0x01; // set bit 0 to enable history buffer + i2c_write_byte(SYSTEM_HISTORY_CTRL, mode, device_base_address); + + LOG_FUNCTION_END(NULL); + + return ret; +} + + +uint32_t range_get_upper_limit(uint8_t device_base_address) +{ + const uint32_t cScalerMax1X = 255; + uint32_t upperLim = cScalerMax1X; + + LOG_FUNCTION_START((void*)&device_base_address); + + LOG_FUNCTION_END(upperLim); + + return upperLim; +} + + +uint32_t range_get_lower_limit(uint8_t device_base_address) +{ + uint32_t lowerLimit = 0; + LOG_FUNCTION_START((void*)&device_base_address); + + LOG_FUNCTION_END(lowerLimit); + + return lowerLimit; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ranging_driver.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,629 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/*! + *\file ranging_driver.h + *\brief Application-level functions used for configuration and operation during ranging. + */ + +#ifndef RANGING_DRIVER +#define RANGING_DRIVER + +#include "common_driver.h" + +//----------------------------------------------------------------------------- +// constant definitions +//----------------------------------------------------------------------------- + +#define ECE_FACTOR (85/100) //0.85 +#define ECE_FACTOR_M 85 //ECE factor Molecular +#define ECE_FACTOR_D 100 //ECE factor Denominator + +// register addresses +#define SYSRANGE_START 0x18 +#define SYSRANGE_THRESH_HIGH 0x19 +#define SYSRANGE_THRESH_LOW 0x1A +#define SYSRANGE_INTERMEASUREMENT_PERIOD 0x1B +#define SYSRANGE_MAX_CONVERGENCE_TIME 0x1C +#define SYSRANGE_CROSSTALK_COMPENSATION_RATE 0x1E +#define SYSRANGE_CROSSTALK_COMPENSATION_RANGE 0x20 +#define SYSRANGE_CROSSTALK_VALID_HEIGHT 0x21 +#define SYSRANGE_EARLY_CONVERGENCE_ESTIMATE 0x22 +#define SYSRANGE_PART_TO_PART_RANGE_OFFSET 0x24 +#define SYSRANGE_RANGE_IGNORE_VALID_HEIGHT 0x25 +#define SYSRANGE_RANGE_IGNORE_THRESHOLD 0x26 +#define SYSRANGE_EMITTER_BLOCK_THRESHOLD 0x28 +#define SYSRANGE_MAX_AMBIENT_LEVEL_THRESH 0x2A +#define SYSRANGE_MAX_AMBIENT_LEVEL_MULT 0x2C +#define SYSRANGE_RANGE_CHECK_ENABLES 0x2D +#define SYSRANGE_VHV_RECALIBRATE 0x2E +#define SYSRANGE_VHV_REPEAT_RATE 0x31 + +#define RESULT_RANGE_STATUS 0x4D +#define RESULT_RANGE_VAL 0x62 +#define RESULT_RANGE_SIGNAL_RATE 0x66 + +// SYSRANGE_START +#define RANGE_START_SINGLESHOT 0x01 // bit 0 set / bit 1 clear +#define RANGE_START_CONTINUOUS 0x03 // bit 0 set / bit 1 set +#define RANGE_CONTINUOUS_MODE 0x02 // bit 0 clear / bit 1 set +#define RANGE_STOP 0x00 // bit 0 set / bit 1 don't care + +// RESULT_RANGE_STATUS bit masks +#define RANGE_DEVICE_READY 0x01 +#define RANGE_ERROR_CODE 0xF0 // covers bits [7:4] + +// SYSRANGE_RANGE_CHECK_ENABLES bit masks +#define RANGE_EARLY_CONVERGENCE_ENABLE 0x01 +#define RANGE_EARLY_CONVERGENCE_DISABLE 0xFE +#define RANGE_RANGE_IGNORE_ENABLE 0x02 +#define RANGE_RANGE_IGNORE_DISABLE 0xFD +#define RANGE_MAX_AMBIENT_ENABLE 0x04 +#define RANGE_MAX_AMBIENT_DISABLE 0xFB +#define RANGE_EMITTER_BLOCK_ENABLE 0x08 +#define RANGE_EMITTER_BLOCK_DISABLE 0xF7 +#define RANGE_SIGNAL_TO_NOISE_ENABLE 0x10 +#define RANGE_SIGNAL_TO_NOISE_DISABLE 0xEF + +#define USER_CONV_CTRL_RETURN_THRESHOLD_FINE 0xB8 + +#define VERNIER_MEASUREMENTS 0x0109 +#define VERNIER_RIPPLE_AVE_SAMPLE_PERIOD 0x010A + + +/** + * @brief This data type defines range measurement data. + */ +typedef struct +{ + int32_t range_mm; + /**< range distance measurement (mm). */ + + float_t signalRate_mcps; + /**< signal rate (MCPS), which is effectively a measure of target reflectance.*/ + + uint32_t errorStatus; + /**< Error status of the current measurement. \n + * No Error := 0. \n + * Refer to product sheets for other error codes. */ +}sensor_RangeData; + + +/*! + *\brief Device setup, for Ranging operations, with parameters that require the system mode to be STARTed before being applied. + *\param[in] device_base_address + *\retval sensor_error + */ +sensor_error range_set_dynamic_config(uint8_t device_base_address); + +/*! + *\brief Set Mode and Operation commands in the sysrange_start register. + * + * Possible combinations are : \n + * + * RANGE_START_SINGLESHOT 0x01 # bit 0 set / bit 1 clear \n + * RANGE_START_CONTINUOUS 0x03 # bit 0 set / bit 1 set \n + * RANGE_STOP 0x01 # bit 0 set / bit 1 don't care \n + * + *\param[in] device_base_address + *\param[in] mode Mode select/operation command to be written to the SYSRANGE_START register. + * + *\retval Boolean. Return True if a valid command is applied, otherwise False. + */ +sensor_error range_set_systemMode(uint8_t device_base_address, int32_t mode); + +/*! + *\brief Report status of Range mode-select and Stop/Start. + * + * Range_Start_Singleshot \n + * Range_Start_Continuous \n + * Range_Stop \n + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_START register. + */ +uint8_t range_get_systemMode(uint8_t device_base_address); + +/*! + *\brief Report basic result from last ranging operation. + * + * Accessing Result_Range_Val register \n + * + *\param[in] device_base_address + *\retval 8-bit Integer. Returns the result of the last successfully completed ranging operation, by reading the RESULT_RANGE_VAL register. + */ +uint8_t range_get_result(uint8_t device_base_address); + +/*! + *\brief Report signal rate from last ranging operation. + * Reads the RESULT_RANGE_SIGNAL_RATE register. + *\param[in] device_base_address + *\retval a uint32_t in 9.7 format. + */ +uint32_t range_get_signal_rate(uint8_t device_base_address); + +/*! + *\brief Report all results from last ranging operation. + * + * Report all results data associated with a ranging operation. \n\n + * + * Result_range_val \n + * Result_range_stray \n + * Result_range_raw \n + * Result_range_return_rate \n + * Result_range_reference_rate \n + * Result_range_Return_VCSEL_count \n + * Result_range_Reference_VCSEL_count \n + * Result_range_Return_AMB_count \n + * Result_range_Reference_AMB_count \n + * Result_range_Return_Conv_time \n + * Result_range_Reference_Conv_time \n + * + *\param[in] device_base_address + * + *\retval List. Returns a list of all the results data, from the last successfully completed ranging operation. + */ +sensor_error range_get_full_result(uint8_t device_base_address); + +/*! + *\brief Set min/max range thresholds (1 to 254mm) in SYSRANGE_THRESH_LOW & SYSRANGE_THRESH_HIGH registers. + * + *\param[in] device_base_address + *\param[in] low_threshold Ranging low threshold to be written to the SYSRANGE_THRESH_LOW register (default = 0mm.) + *\param[in] high_threshold Ranging high threshold to be written to the SYSRANGE_THRESH_HIGH register (default = 255mm.) + *\retval sensor_error + */ +sensor_error Range_Set_Thresholds(uint8_t device_base_address, int32_t low_threshold, int32_t high_threshold); + +/*! + *\brief Set ranging high threshold in the SYSRANGE_THRESH_HIGH register. + * + * Range : 0-255 mm \n + * + *\param[in] device_base_address + *\param[in] threshold Ranging high threshold to be written to the SYSRANGE_THRESH_HIGH register(0-255mm). + *\retval sensor_error + */ +sensor_error range_set_high_threshold(uint8_t device_base_address, uint8_t threshold); + +/*! + *\brief Report ranging high threshold from the SYSRANGE_THRESH_HIGH register. + * + * Range : 0-255 mm \n + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_THRESH_HIGH register. + */ +uint8_t range_get_high_threshold(uint8_t device_base_address); + +/*! + *\brief Set ranging low threshold in the SYSRANGE_THRESH_LOW register. + * + * Range : 0-255 mm \n + * + *\param[in] device_base_address + *\param[in] threshold Ranging low threshold to be written to the SYSRANGE_THRESH_LOW register. + *\retval sensor_error + */ +sensor_error range_set_low_threshold(uint8_t device_base_address, uint8_t threshold); + +/*! + *\brief Report ranging low threshold from the SYSRANGE_THRESH_LOW register. + * + * Range : 0-255 mm \n + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_THRESH_LOW register. + */ +uint8_t range_get_low_threshold(uint8_t device_base_address); + +/*! + *\brief Set ranging intermeasurement period in the SYSRANGE_INTERMEASUREMENT_PERIOD register. + * + * Time delay between measurements in continuous ranging mode. Range 10ms - 2.55secs (1 code = 10ms. Code 0 = 10ms.).\n + * Min (default) value stored in NVM. + * + *\param[in] device_base_address + *\param[in] intermeasurement_period Time delay in ms between measurements in continuous-ranging mode. <0-2550ms> + *\retval sensor_error + */ +sensor_error range_set_interMeasurement_period(uint8_t device_base_address, uint16_t intermeasurement_period); + +/*! + *\brief Report ranging intermeasurement period from the SYSRANGE_INTERMEASUREMENT_PERIOD register. + * + * Range 10ms-2.55s, 1 code = 10 ms, code 0 = 10ms. \n + * + *\param[in] device_base_address + *\retval Integer. Returns the range inter measurement period in ms. + */ +uint16_t range_get_interMeasurement_period(uint8_t device_base_address); + +/*! + *\brief Set ranging maximum convergence time in the SYSRANGE_MAX_CONVERGENCE_TIME register. + * + * Maximum time to run measurements in ranging modes. \n + * + * Range 0-50ms, 1 code = 1 ms \n + * + *\param[in] device_base_address + *\param[in] max_convergence_time Maximum time to run measurements in ranging modes (max = 50ms). + *\retval sensor_error + */ +sensor_error range_set_max_convergence_time(uint8_t device_base_address, int32_t max_convergence_time); + +/*! + *\brief Report ranging maximum convergence time from the SYSRANGE_MAX_CONVERGENCE_TIME register. + * + * Range 0-50ms, 1 code = 1 ms \n + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_MAX_CONVERGENCE_TIME register. + */ + +uint8_t range_get_max_convergence_time(uint8_t device_base_address); + +/*! + *\brief Set ranging crosstalk compensation rate in the SYSRANGE_CROSSTALK_COMPENSATION_RATE register. + * + * User-controlled crosstalk compensation rate, in MHz. \n + * + *\param[in] device_base_address + *\param[in] crosstalk_compensation_rate User-controlled crosstalk compensation rate, in ranging modes. + *\retval sensor_error + */ +sensor_error range_set_crosstalk_compensation_rate(uint8_t device_base_address, int32_t crosstalk_compensation_rate); + +/*! + *\brief Report ranging crosstalk compensation rate (MHz) from the SYSRANGE_CROSSTALK_COMPENSATION_RATE register. + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_CROSSTALK_COMPENSATION_RATE register. + */ +int32_t range_get_crosstalk_compensation_rate(uint8_t device_base_address); + +/*! + *\brief Set ranging crosstalk compensation range in the SYSRANGE_CROSSTALK_COMPENSATION_RANGE register. + * + * User-controlled crosstalk compensation range, in mm. \n + * + *\param[in] device_base_address + *\param[in] crosstalk_compensation_range User-controlled crosstalk compensation range, in ranging modes. + *\retval sensor_error + */ +sensor_error range_set_crosstalk_compensation_range(uint8_t device_base_address, int32_t crosstalk_compensation_range); + +/*! + *\brief Report ranging crosstalk compensation range (mm) from the SYSRANGE_CROSSTALK_COMPENSATION_RANGE register. + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_CROSSTALK_COMPENSATION_RANGE register. + */ +uint8_t range_get_crosstalk_compensation_range(uint8_t device_base_address); + +/*! + *\brief Set ranging crosstalk valid height in the SYSRANGE_CROSSTALK_VALID_HEIGHT register. + * + * Minimum range at which to apply crosstalk compensation, in mm. \n + *\param[in] device_base_address + *\param[in] crosstalk_valid_height Minimum range at which to apply crosstalk compensation, in ranging modes. + *\retval sensor_error + */ +sensor_error range_set_crosstalk_valid_height(uint8_t device_base_address, int32_t crosstalk_valid_height); + +/*! + *\brief Report ranging crosstalk valid height from the SYSRANGE_CROSSTALK_VALID_HEIGHT register. + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_CROSSTALK_VALID_HEIGHT register. + */ +uint8_t range_get_crosstalk_valid_height(uint8_t device_base_address); + +/*! + *\brief Set ranging ECE (early convergence estimate) Threshold in the SYSRANGE_EARLY_CONVERGENCE_ESTIMATE' register. + * + * User-set limit below which a ranging operation is aborted. \n + * An estimate of convergence time is performed 1ms into a ranging operation. If the return rate is below this user-set limit, the ranging operation is aborted to save power. \n + * + *\param[in] device_base_address + *\retval sensor_error + */ +sensor_error range_set_early_convergence_estimate_threshold(uint8_t device_base_address); + +/*! + *\brief Report ranging early convergence estimate from the SYSRANGE_EARLY_CONVERGENCE_ESTIMATE register. + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_EARLY_CONVERGENCE_ESTIMATE register. + */ +uint8_t range_get_early_convergence_estimate_threshold(uint8_t device_base_address); + +uint32_t range_get_vernier_ave_total_time(uint8_t device_base_address); + +/*! + *\brief read convergence count threshold from USER_CONV_CTRL_RETURN_THRESHOLD_FINE register. + * + *\param[in] device_base_address + *\retval Integer. Returns the formated reading of the USER_CONV_CTRL_RETURN_THRESHOLD_FINE register. + */ +uint32_t range_get_converg_ctrl_rtn_thresh_fine(uint8_t device_base_address); + +/*! + *\brief Set Ranging Ignore Valid Height threshold in the SYSRANGE_RANGE_IGNORE_VALID_HEIGHT register. + * + * Default : 256 \n + * + *\param[in] device_base_address + *\param[in] ignore_valid_height User-set limit + *\retval sensor_error + */ +sensor_error range_set_ignore_valid_height(uint8_t device_base_address, int32_t ignore_valid_height); + +/*! + *\brief Report ranging ignore valid height threshold from the SYSRANGE_RANGE_IGNORE_VALID_HEIGHT register. + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_RANGE_IGNORE_VALID_HEIGHT register. + */ +uint8_t range_get_ignore_valid_height(uint8_t device_base_address); + +/*! + *\brief Set Range Ignore Threshold in the SYSRANGE_RANGE_IGNORE_THRESHOLD register. + * + * Minimum acceptable count rate of VCSEL counts on the return array. \n + * + * Default : 2. \n + * + *\param[in] device_base_address + *\param[in] range_ignore_threshold Minimum acceptable count rate of VCSEL counts on the return array. in Mcps 9.7 format. + *\retval sensor_error + */ +sensor_error range_set_range_ignore_threshold(uint8_t device_base_address, uint32_t range_ignore_threshold); + +/*! + *\brief Report Range Ignore Threshold from the SYSRANGE_RANGE_IGNORE_THRESHOLD register. in Mcps 9.7 format. + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_RANGE_IGNORE_THRESHOLD register. + */ +uint32_t range_get_range_ignore_threshold(uint8_t device_base_address); + +/*! + *\brief Set Emitter Block Threshold in the SYSRANGE_EMITTER_BLOCK_THRESHOLD register. + * + * Maximum Reference Array VCSEL returns allowed before reporting that the emitter is blocked. \n + * MHz, 9.7 format \n + * + *\param[in] device_base_address + *\param[in] emitter_block_threshold Minimum acceptable count rate of VCSEL counts on the return array. + *\retval sensor_error + */ +sensor_error range_set_emitter_block_threshold(uint8_t device_base_address, int32_t emitter_block_threshold); + +/*! + *\brief Report Emitter Block Threshold from the SYSRANGE_EMITTER_BLOCK_THRESHOLD register. + * + * MHz, 9.7 format \n + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_EMITTER_BLOCK_THRESHOLD register. + */ +uint8_t range_get_emitter_block_threshold(uint8_t device_base_address); + +/** + * @brief Function to set the SNR threshold. + * + *\param[in] device_base_address + *\param[in] snrThresh + *\retval sensor_error + */ +sensor_error range_set_snr_thresh(uint8_t device_base_address, float_t snrThresh); + +/** + * @brief Function to get the SNR threshold. + * + *\param[in] device_base_address + *\retval Float. Returns the SNR threshold. + */ +float_t range_get_snr_thresh(uint8_t device_base_address); + + +/*! + *\brief Set Range Check Enables in the SYSRANGE_RANGE_CHECK_ENABLES register. + * + *\param[in] device_base_address + *\param[in] range_check_enables + *\retval sensor_error + */ +sensor_error range_set_range_check_enables(uint8_t device_base_address, int32_t range_check_enables); + +/*! + *\brief Report Range Check Enables from the SYSRANGE_RANGE_CHECK_ENABLES register. + * + *\param[in] device_base_address + *\retval Integer. Returns the contents of the SYSRANGE_RANGE_CHECK_ENABLES register. + */ +uint8_t range_get_range_check_enables(uint8_t device_base_address); + +/*! + *\brief Set Range Check Enables in the SYSRANGE_VHV_RECALIBRATE register. + * + *\param[in] device_base_address + *\param[in] VHV_Recalibrate + *\retval sensor_error + */ +sensor_error range_set_vhv_recalibrate(uint8_t device_base_address, int32_t VHV_Recalibrate); + +/*! + *\brief Report Range Check Enables from the SYSRANGE_VHV_RECALIBRATE register. + * + *\param[in] device_base_address + *\retval Integer. + */ +uint8_t range_get_vhv_recalibrate(uint8_t device_base_address); + +/*! + *\brief Set VHV Repeat Rate. + * + * Repeat rate of autoVHV task \n + * measurements, 0 = off, 255 = after every 255 measurements \n + * + *\param[in] device_base_address + *\param[in] VHV_repeat_rate Repeat rate of autoVHV task + *\retval sensor_error + */ +sensor_error range_set_vhv_repeat_rate(uint8_t device_base_address, int32_t VHV_repeat_rate); + +/*! + *\brief Report VHV Repeat Rate. + * + *\param[in] device_base_address + *\retval Integer. Repeat rate of autoVHV task, in measurements. 0 = off, 255 = after every 255 measurements. + */ +uint8_t range_get_vhv_repeat_rate(uint8_t device_base_address); + +/*! + *\brief Report contents of the RESULT_RANGE_STATUS register. + * + *\param[in] device_base_address + *\retval Integer + */ +int32_t range_get_result_status(uint8_t device_base_address); + +/*! + *\brief Report result_range_device_ready status in the RESULT_RANGE_STATUS register. + * + *\param[in] device_base_address + *\retval Boolean. Return True if the result_range_device_ready bit in the RESULT_RANGE_STATUS register is set, otherwise False. + */ +bool_t range_get_device_ready(uint8_t device_base_address); + +/*! + *\brief Report result_range_error_codes status. + * + *\param[in] device_base_address + *\retval Integer. Return True if the result_range_error_codes bit in the RESULT_RANGE_STATUS register is set, otherwise False. + */ +uint8_t range_get_result_error_codes(uint8_t device_base_address); + +/*! + *\brief Set the ECE Factor Molecular and Demoninator. + * + * (< 1.00 for maximum detection, > 1.00 for minimizing red glow) + * + *\param[in] device_base_address + *\param[in] ECE_Factor_M + *\param[in] ECE_Factor_D + *\retval sensor_error + */ +sensor_error range_set_ece_factor(uint8_t device_base_address, uint32_t ECE_Factor_M, uint32_t ECE_Factor_D); + +/*! + *\brief Store the ECE Margin Molecular and Demoninator to provided variables. + * + * (< 1.00 for maximum detection, > 1.00 for minimizing red glow) + * + *\param[in] pece_factor_m pointer to ECE_Factor_M variable + *\param[in] pece_factor_d pointer to ECE_Factor_D variable + *\retval sensor_error. + */ +sensor_error range_get_ece_factor(uint32_t *pece_factor_m, uint32_t *pece_factor_d); + + +/*! + *\brief Set System Interrupt Config GPIO for Ranging operations. + + Returns True if a command is successfully applied to the SYSTEM_INTERRUPT_CONFIG_GPIO register, otherwise False. \n + Possible settings are : \n + CONFIG_GPIO_INTERRUPT_DISABLED = 0x00 \n + CONFIG_GPIO_INTERRUPT_LEVEL_LOW = 0x01 \n + CONFIG_GPIO_INTERRUPT_LEVEL_HIGH = 0x02 \n + CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW = 0x03 \n + CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY = 0x04 \n + *\param[in] device_base_address + *\param[in] Ranging_GPIO_interrupt_config + *\retval sensor_error +*/ +sensor_error range_set_system_interrupt_config_gpio(uint8_t device_base_address, uint8_t Ranging_GPIO_interrupt_config); + +/*! + *\brief Report System Interrupt Config GPIO Ranging. + + Returns the ranging-only portion of the SYSTEM_INTERRUPT_CONFIG_GPIO register. \n + Possible returns are : \n + CONFIG_GPIO_INTERRUPT_DISABLED = 0x00 \n + CONFIG_GPIO_INTERRUPT_LEVEL_LOW = 0x01 \n + CONFIG_GPIO_INTERRUPT_LEVEL_HIGH = 0x02 \n + CONFIG_GPIO_INTERRUPT_OUT_OF_WINDOW = 0x03 \n + CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY = 0x04 \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t range_get_system_interrupt_config_gpio(uint8_t device_base_address); + +/*! + *\brief Clear Ranging System Interrupt. + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error range_set_system_interrupt_clear(uint8_t device_base_address); + + +sensor_error Get_Range_History_Buffer(uint8_t device_base_address); + +/*! + *\brief Report GPIO Interrupt Result Status for a Ranging operation. + + Returns the Ranging-only portion of the RESULT_INTERRUPT_STATUS_GPIO register. \n + Possible returns are : \n + 0: No threshold events reported \n + 1: Level Low threshold event \n + 2: Level High threshold event \n + 3: Out Of Window threshold event \n + 4: New Sample Ready threshold event \n + *\param[in] device_base_address + *\retval Integer +*/ +uint8_t range_get_result_interrupt_status_gpio(uint8_t device_base_address); + +/*! + *\brief Set history buffer to range mode and enable. + *\param[in] device_base_address + *\retval sensor_error +*/ +sensor_error range_set_history_buffer_mode_enable(uint8_t device_base_address); + + +/** + * @brief Function to return the Maximum range reported by the + * sensor. + */ +uint32_t range_get_upper_limit(uint8_t device_base_address); + +/** + * @brief Function to return the Minimum range reported by the + * sensor. + */ +uint32_t range_get_lower_limit(uint8_t device_base_address); + +#endif + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utilities.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,143 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/** + * @file utilities.cpp + * + * Copyright (C) 2014 ST MicroElectronics + * + * Utilities module definition. + * + */ + +#include "utilities.h" +#include "platform.h" +#ifndef __KERNEL__ +#include <cstring> +#include <cstdlib> +#include <stdio.h> +#else +#include <linux/kernel.h> +#include <linux/string.h> +#endif +#ifndef __KERNEL__ +int32_t roundFloatToInt(float_t floatVal) +{ + floatVal += 0.5f; + return (int32_t)floatVal; +} +#endif +int32_t unPackBytes(int32_t data, uint8_t *byteArray, int32_t size) +{ + const int32_t cByteBitShift = 8; + const int32_t cByteMask = 0xFF; + int32_t bitShift = cByteBitShift * (size - 1); + int32_t byteIndex = 0; + + for (byteIndex = 0; byteIndex < size; byteIndex++) + { + int32_t mask = cByteMask << bitShift; + int32_t value = (data & mask) >> bitShift; + bitShift -= cByteBitShift; + byteArray[byteIndex] = (uint8_t)(value); + } + return 0; +} + +uint32_t packBytes(uint8_t *byteArray, uint32_t size) +{ + const int cBitsPerByte = 8; + uint32_t cBytesPerInt = 4; + uint32_t data = 0; + unsigned int index = 0; + + if(size > cBytesPerInt) + { + size = cBytesPerInt; + } + + for(index = 0; index < size; index++) + { + if(index > 0) + { + data <<= cBitsPerByte; + } + data += byteArray[index]; + } + return data; +} + +int32_t array2HexCString(uint8_t *byteArray, char *str, uint32_t count) +{ + uint32_t i; + + sprintf(str, "0x"); + +// int32_t length = count; +// for(int32_t i = 0; i < count; i++) + for(i = 0; i < count; i++) + { + str += 2; + sprintf(str, "%02X", (uint32_t)byteArray[i]); + } + return 0; +} + +#ifndef __KERNEL__ +uint32_t encodeTo9_7_Format(float_t value) +{ + const float_t cShiftFactor = 128.0f; + const uint32_t cMax = 65535; + uint32_t encodedVal = (uint32_t)roundFloatToInt(value * cShiftFactor); + if (encodedVal > cMax) + { + encodedVal = cMax; + } + return encodedVal; +} + +float_t decodeFrom9_7_Format(uint32_t value) +{ + const float_t cShiftFactor = 128.0f; + return (float_t)value / cShiftFactor; +} + + +uint32_t encodeTo4_4_Format(float_t value) +{ + const float_t cShiftFactor = 16.0f; + const uint32_t cMax = 255; + uint32_t encodedVal = (uint32_t)roundFloatToInt(value * cShiftFactor); + if (encodedVal > cMax) + { + encodedVal = cMax; + } + return encodedVal; +} + +float_t decodeFrom4_4_Format(uint32_t value) +{ + const float_t cShiftFactor = 16.0f; + return (float_t)value / cShiftFactor; +} +#endif +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utilities.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,89 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/*! + *\file utilities.h + *\brief Utilities module to contain common and useful routines. + */ + +#ifndef _UTILITIES +#define _UTILITIES + +#include "platform.h" +#include "definitions.h" + +/** + * @brief This function converts a given array of bytes to a string in hex + * format. To be used when it is desired to display loose bytes as + * a short, int, long long etc. + * + * If a valid length parameter is supplied only this number of bytes + * will be converted. A count of 0 will be ignored. + */ +int32_t array2HexCString(uint8_t *byteArray, char *str, uint32_t count); + +/** + * @brief This function unpacks an integer to a given array of bytes. + */ +int32_t unPackBytes(int32_t data, uint8_t *byteArray, int32_t size); + +/** + * @brief This function packs an attay of bytes to a given integer. + */ +uint32_t packBytes(uint8_t *byteArray, uint32_t size); + +/** + * @brief This function round a float value to an integer value. + */ +int32_t roundFloatToInt(float_t floatVal); + +/** + * @brief Method to encode a float to 9:7 format and return as an + * unsigned int. This is performed by shifting the float 7 + * bits to the left and then converting to unsigned int. + */ +uint32_t encodeTo9_7_Format(float_t value); + +/** + * @brief Method to decode a 9:7 formatted data word into a + * float. The data word is shifted 7 bits to the right and + * converted to float. + */ +float_t decodeFrom9_7_Format(uint32_t value); + +/** + * @brief Method to encode a float to 4:4 format and return as an + * unsigned int. This is performed by shifting the float 4 + * bits to the left and then converting to unsigned int. + */ +uint32_t encodeTo4_4_Format(float_t value); + +/** + * @brief Method to decode a 4:4 formatted data word into a + * float. The data word is shifted 4 bits to the right and + * converted to float. + */ +float_t decodeFrom4_4_Format(uint32_t value); + +#endif + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vl6180x_high_level_api.cpp Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,208 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + + +/** + * @file high_level_api.cpp + * + * Copyright (C) 2014 ST MicroElectronics + * + * @brief High level interface definition for device, providing methods for basic + * ranging. + * + */ + +#include "vl6180x_high_level_api.h" +#include "definitions.h" +#include "common_driver.h" +#include "ranging_driver.h" +#include "als_driver.h" +#include "range_upscaling_driver.h" +#include "debug.h" +#include "utilities.h" + +static uint8_t _device_i2c_addr = 0; + +sensor_error get_vendor(uint8_t *pVendorStr) +{ + LOG_FUNCTION_START((void*)pVendorStr); + + LOG_FUNCTION_END(NULL); + return SENSOR_ERROR_NONE; +} + +sensor_error get_version(int32_t id, uint8_t *pVersionStr) +{ + LOG_FUNCTION_START((void*)&id,(void*)pVersionStr); + + LOG_FUNCTION_END(NULL); + return SENSOR_ERROR_NONE; +} + +uint32_t get_max_range() +{ + uint32_t maxRange = 0; + + maxRange = range_get_upper_limit(_device_i2c_addr); + + return maxRange; +} + +uint32_t get_min_range() +{ + return range_get_lower_limit(_device_i2c_addr);; +} + +sensor_error initialise(uint8_t device_base_address) +{ + + LOG_FUNCTION_START((void*)&device_base_address); + + _device_i2c_addr = device_base_address; + common_initialise(_device_i2c_addr); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error start_ranging(int32_t id) +{ + LOG_FUNCTION_START((void*)&id); + + // load settings + common_set_static_config(_device_i2c_addr); + + // ranging setup + range_set_low_threshold(_device_i2c_addr, 10); // threshold defaults are 0mm and 255mm + range_set_high_threshold(_device_i2c_addr, 200);//200mm + range_set_max_convergence_time(_device_i2c_addr, 50); // set max convergence time to 50ms; + + //set ranging in InterruptMode + common_set_gpio1_polarity(_device_i2c_addr, GPIOx_POLARITY_SELECT_OFF); + common_set_gpio1_select(_device_i2c_addr, GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT); + common_set_gpio1_mode(_device_i2c_addr, GPIOx_MODE_SELECT_RANGING); + range_set_system_interrupt_config_gpio(_device_i2c_addr, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + + //range_set_systemMode(_device_i2c_addr, RANGE_START_SINGLESHOT); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error start_extended_ranging(int32_t id) +{ + LOG_FUNCTION_START((void*)&id); + // load settings onto + er_set_static_config(_device_i2c_addr); + + // ranging setup + // range_set_low_threshold(_device_i2c_addr, 10); // threshold defaults are 0mm and 255mm + // range_set_high_threshold(_device_i2c_addr, 200);//200mm + range_set_max_convergence_time(_device_i2c_addr, 63); // set max convergence time to 50ms; + range_set_crosstalk_compensation_rate(_device_i2c_addr, 0); + + //set ranging in InterruptMode + common_set_gpio1_polarity(_device_i2c_addr, GPIOx_POLARITY_SELECT_OFF); + common_set_gpio1_select(_device_i2c_addr, GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT); + common_set_gpio1_mode(_device_i2c_addr, GPIOx_MODE_SELECT_RANGING); + range_set_system_interrupt_config_gpio(_device_i2c_addr, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error get_range_measurement(int32_t id, sensor_RangeData *pRangeData) +{ + const int cErrorDataShift = 4; + + LOG_FUNCTION_START((void*)&id,(void*)pRangeData); + // start single range measurement + range_set_systemMode(_device_i2c_addr, RANGE_START_SINGLESHOT); + + // poll the till new sample ready + while (range_get_result_interrupt_status_gpio(_device_i2c_addr) != RES_INT_STAT_GPIO_NEW_SAMPLE_READY) + { + timer_wait_us(100); + } + + pRangeData->range_mm = range_get_result(_device_i2c_addr); + pRangeData->signalRate_mcps = decodeFrom9_7_Format(range_get_signal_rate(_device_i2c_addr)); + pRangeData->errorStatus = (range_get_result_status(_device_i2c_addr)) >> cErrorDataShift; + + // clear the interrupt on + range_set_system_interrupt_clear(_device_i2c_addr); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error start_als(int32_t id) +{ + LOG_FUNCTION_START((void*)&id); + common_set_static_config(_device_i2c_addr); + + als_set_integration_period(_device_i2c_addr, 100); //100ms + als_set_interMeasurement_period(_device_i2c_addr, 200); //200ms + als_set_analogue_gain(_device_i2c_addr, 0); + + als_set_low_threshold(_device_i2c_addr, 0); + als_set_high_threshold(_device_i2c_addr, 0x0FFFF); + + common_set_gpio1_polarity(_device_i2c_addr, GPIOx_POLARITY_SELECT_OFF); + common_set_gpio1_select(_device_i2c_addr, GPIOx_SELECT_GPIO_INTERRUPT_OUTPUT); + common_set_gpio1_mode(_device_i2c_addr, GPIOx_MODE_SELECT_ALS); + als_set_system_interrupt_config_gpio(_device_i2c_addr, CONFIG_GPIO_INTERRUPT_NEW_SAMPLE_READY); + +// als_set_systemMode(_device_i2c_addr, ALS_START_SINGLESHOT); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error get_als_measurement(int32_t id, sensor_AlsData *pAlsData) +{ + const int cErrorDataShift = 4; + + LOG_FUNCTION_START((void*)&id,(void*)pAlsData); + als_set_systemMode(_device_i2c_addr, ALS_START_SINGLESHOT); + + while (als_get_result_interrupt_status_gpio(_device_i2c_addr) != RES_INT_STAT_GPIO_NEW_SAMPLE_READY) + { + timer_wait_us(100); + } + pAlsData->lux = als_get_lux(_device_i2c_addr); + pAlsData->errorStatus = (als_get_result_status(_device_i2c_addr)) >> cErrorDataShift; + + als_set_system_interrupt_clear(_device_i2c_addr); + LOG_FUNCTION_END(NULL); + + return SENSOR_ERROR_NONE; +} + +sensor_error get_minimum_delay() +{ + + return SENSOR_ERROR_NONE; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vl6180x_high_level_api.h Sun Feb 08 14:26:51 2015 +0000 @@ -0,0 +1,125 @@ +/******************************************************************************* +################################################################################ +# (C) STMicroelectronics 2014 +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License version 2 and only version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +#------------------------------------------------------------------------------ +# Imaging Division +################################################################################ +********************************************************************************/ + +/** + * @file vl6180x_high_level_api.h + * + * @brief High level interface for the device, providing methods for basic + * ranging and ambient light sensor measurement. + * + */ + +#ifndef VL6180X_HL_API +#define VL6180X_HL_API + +#include "definitions.h" +#include "als_driver.h" +#include "ranging_driver.h" + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/** + * @brief Function to report the Vendor ID as a string. + */ +sensor_error get_vendor(uint8_t *pVendorStr); + +/** + * @brief Function to report the Device Version as a string. + * id : device identifier. 0, if only one device. \n + * Returns -1 to report error. + */ +sensor_error get_version(int32_t id, uint8_t *pVersionStr); + + +/** + * @brief Function to return the Maximum range reported by the + * sensor. + */ +uint32_t get_max_range(); + +/** + * @brief Function to return the Minimum range reported by the + * sensor. + */ +uint32_t get_min_range(); + +/** + * @brief Function to perform device initialisation. \n + * Returns -1 to report error. + */ +sensor_error initialise(uint8_t device_base_address); + +/** + * @brief Function to configure the device for single shot + * ranging. \n + * Returns -1 to report error. + */ +sensor_error start_ranging(int32_t id); + +/** + * @brief Function to configure the device for single shot + * extended ranging. \n + * Returns -1 to report error. + */ +sensor_error start_extended_ranging(int32_t id); + +/** + * @brief Function to perform a single shot range measurement + * and reports the results to the given argument. \n + * Pre-Requisite : Requires startRanging() to be called + * beforehand. \n + * Returns -1 to report error. + */ +sensor_error get_range_measurement(int32_t id, sensor_RangeData *pRangeData); + +/** + * @brief Function to configure the device for single shot + * ALS measurements. \n + * Returns -1 to report error. + */ +sensor_error start_als(int32_t id); + +/** + * @brief Function to perform a single shot ALS measurement + * and reports the results to the given argument. \n + * Pre-Requisite : Requires startAls() to be called beforehand. \n + * Returns -1 to report error. + */ +sensor_error get_als_measurement(int32_t id, sensor_AlsData *pAlsData); + +/** + * @brief TBC + */ +sensor_error get_minimum_delay(); + +#ifdef __cplusplus +} +#endif + +#endif /* VL6180X_HL_API */ + +