Vybhav Kadaba
/
EV-PRO-MW1001_Development_code_cleaup
Removed unwanted enums and unused functions
Diff: src/admw_1001.c
- Revision:
- 8:2f2775c34640
- Parent:
- 6:9d393a9677f4
- Child:
- 10:14954555be2a
--- a/src/admw_1001.c Tue Jun 18 09:28:16 2019 +0000 +++ b/src/admw_1001.c Thu Jun 20 18:13:57 2019 +0000 @@ -1,5 +1,5 @@ /* -Copyright 2018 (c) Analog Devices, Inc. +Copyright 2019 (c) Analog Devices, Inc. All rights reserved. @@ -33,46 +33,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/****************************************************************************** -Copyright 2017 (c) Analog Devices, Inc. - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - Neither the name of Analog Devices, Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - The use of this software may or may not infringe the patent rights - of one or more patent holders. This license does not release you - from the requirement that you obtain separate licenses from these - patent holders to use this software. - - Use of the software either in source or binary form, must be run - on or directly connected to an Analog Devices Inc. component. - -THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - *****************************************************************************/ - /*! ****************************************************************************** * @file: - * @brief: ADMW API implementation for ADSNS1000 + * @brief: API implementation for ADMW1001 *----------------------------------------------------------------------------- */ @@ -107,13 +71,13 @@ /* Checks if a value is outside the bounds of the specified register field */ #define CHECK_REG_FIELD_VAL(_field, _val) \ do { \ - uint32_t _mask = BITM_##_field; \ - uint32_t _shift = BITP_##_field; \ + uint32_t _mask = BITM_##_field; \ + uint32_t _shift = BITP_##_field; \ if ((((_val) << _shift) & ~(_mask)) != 0) { \ ADMW_LOG_ERROR("Value 0x%08X invalid for register field %s",\ (uint32_t)(_val), \ STRINGIFY(ADMW_##_field)); \ - return ADMW_INVALID_PARAM; \ + return ADMW_INVALID_PARAM; \ } \ } while(false) @@ -123,26 +87,26 @@ */ #define WRITE_REG(_hdev, _val, _name, _type) \ do { \ - ADMW_RESULT _res; \ + ADMW_RESULT _res; \ _type _regval = _val; \ - _res = admw1001_WriteRegister((_hdev), \ - REG_##_name, \ + _res = admw1001_WriteRegister((_hdev), \ + REG_##_name, \ &_regval, sizeof(_regval)); \ - if (_res != ADMW_SUCCESS) \ + if (_res != ADMW_SUCCESS) \ return _res; \ } while(false) /* Wrapper macro to write a value to a uint32_t register */ -#define WRITE_REG_U32(_hdev, _val, _name) \ +#define WRITE_REG_U32(_hdev, _val, _name) \ WRITE_REG(_hdev, _val, _name, uint32_t) /* Wrapper macro to write a value to a uint16_t register */ -#define WRITE_REG_U16(_hdev, _val, _name) \ +#define WRITE_REG_U16(_hdev, _val, _name) \ WRITE_REG(_hdev, _val, _name, uint16_t) /* Wrapper macro to write a value to a uint8_t register */ -#define WRITE_REG_U8(_hdev, _val, _name) \ +#define WRITE_REG_U8(_hdev, _val, _name) \ WRITE_REG(_hdev, _val, _name, uint8_t) /* Wrapper macro to write a value to a float32_t register */ -#define WRITE_REG_FLOAT(_hdev, _val, _name) \ +#define WRITE_REG_FLOAT(_hdev, _val, _name) \ WRITE_REG(_hdev, _val, _name, float32_t) /* @@ -151,40 +115,40 @@ */ #define READ_REG(_hdev, _val, _name, _type) \ do { \ - ADMW_RESULT _res; \ + ADMW_RESULT _res; \ _type _regval; \ - _res = admw1001_ReadRegister((_hdev), \ - REG_##_name, \ + _res = admw1001_ReadRegister((_hdev), \ + REG_##_name, \ &_regval, sizeof(_regval)); \ - if (_res != ADMW_SUCCESS) \ + if (_res != ADMW_SUCCESS) \ return _res; \ _val = _regval; \ } while(false) /* Wrapper macro to read a value from a uint32_t register */ -#define READ_REG_U32(_hdev, _val, _name) \ +#define READ_REG_U32(_hdev, _val, _name) \ READ_REG(_hdev, _val, _name, uint32_t) /* Wrapper macro to read a value from a uint16_t register */ -#define READ_REG_U16(_hdev, _val, _name) \ +#define READ_REG_U16(_hdev, _val, _name) \ READ_REG(_hdev, _val, _name, uint16_t) /* Wrapper macro to read a value from a uint8_t register */ -#define READ_REG_U8(_hdev, _val, _name) \ +#define READ_REG_U8(_hdev, _val, _name) \ READ_REG(_hdev, _val, _name, uint8_t) /* Wrapper macro to read a value from a float32_t register */ -#define READ_REG_FLOAT(_hdev, _val, _name) \ +#define READ_REG_FLOAT(_hdev, _val, _name) \ READ_REG(_hdev, _val, _name, float32_t) /* * Wrapper macro to write an array of values to a uint8_t register * NOTE - this is intended only for writing to a keyhole data register */ -#define WRITE_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ +#define WRITE_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ do { \ - ADMW_RESULT _res; \ - _res = admw1001_WriteRegister(_hdev, \ - REG_##_name, \ + ADMW_RESULT _res; \ + _res = admw1001_WriteRegister(_hdev, \ + REG_##_name, \ _arr, _len); \ - if (_res != ADMW_SUCCESS) \ + if (_res != ADMW_SUCCESS) \ return _res; \ } while(false) @@ -194,38 +158,39 @@ */ #define READ_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ do { \ - ADMW_RESULT _res; \ - _res = admw1001_ReadRegister((_hdev), \ - REG##_name, \ + ADMW_RESULT _res; \ + _res = admw1001_ReadRegister((_hdev), \ + REG##_name, \ _arr, _len); \ - if (_res != ADMW_SUCCESS) \ + if (_res != ADMW_SUCCESS) \ return _res; \ } while(false) -#define ADMW1001_CHANNEL_IS_ADC(c) \ - ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL) +#define ADMW1001_CHANNEL_IS_ADC(c) \ + ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL) -#define ADMW1001_CHANNEL_IS_ADC_CJC(c) \ - ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) +#define ADMW1001_CHANNEL_IS_ADC_CJC(c) \ + ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_UNIVERSAL) -#define ADMW1001_CHANNEL_IS_ADC_SENSOR(c) \ - ((c) >= ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL && (c) <= ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) +#define ADMW1001_CHANNEL_IS_ADC_SENSOR(c) \ + ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_UNIVERSAL) -#define ADMW1001_CHANNEL_IS_ADC_VOLTAGE(c) \ - ((c) == ADMW1001_CHANNEL_ID_ANALOG_1_DIFFERENTIAL || ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL) +#define ADMW1001_CHANNEL_IS_ADC_VOLTAGE(c) \ + ((c) == ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL || ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL) -#define ADMW1001_CHANNEL_IS_ADC_CURRENT(c) \ - ((c) == ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL || (c) == ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL) +#define ADMW1001_CHANNEL_IS_ADC_CURRENT(c) \ + ((c) == ADMW1001_CH_ID_ANLG_1_UNIVERSAL || (c) == ADMW1001_CH_ID_ANLG_2_UNIVERSAL) -#define ADMW1001_CHANNEL_IS_VIRTUAL(c) \ - ((c) == ADMW1001_CHANNEL_ID_SPI_1 || (c) == ADMW1001_CHANNEL_ID_SPI_2) +#define ADMW1001_CHANNEL_IS_VIRTUAL(c) \ + ((c) == ADMW1001_CH_ID_DIG_SPI_1 || (c) == ADMW1001_CH_ID_DIG_SPI_2) typedef struct { unsigned nDeviceIndex; ADMW_SPI_HANDLE hSpi; ADMW_GPIO_HANDLE hGpio; -} ADMW_DEVICE_CONTEXT; + +} ADMW_DEVICE_CONTEXT; static ADMW_DEVICE_CONTEXT gDeviceCtx[ADMW_PLATFORM_MAX_DEVICES]; @@ -233,7 +198,7 @@ * Open an ADMW device instance. */ ADMW_RESULT admw_Open( - unsigned const nDeviceIndex, + unsigned const nDeviceIndex, ADMW_CONNECTION * const pConnectionInfo, ADMW_DEVICE_HANDLE * const phDevice) { @@ -297,11 +262,20 @@ } } -/* - * Reset the specified ADMW device. +/*! + * @brief Reset the specified ADMW device. + * + * @param[in] hDevice - handle of ADMW device to reset. + * + * @return Status + * - #ADMW_SUCCESS Call completed successfully. + * - #ADMW_FAILURE If reseet faisl + * + * @details Toggle reset pin of the ADMW device low for a + * minimum of 4 usec. + * */ -ADMW_RESULT admw_Reset( - ADMW_DEVICE_HANDLE const hDevice) +ADMW_RESULT admw_Reset(ADMW_DEVICE_HANDLE const hDevice) { ADMW_DEVICE_CONTEXT *pCtx = hDevice; ADMW_RESULT eRet; @@ -320,9 +294,8 @@ return ADMW_SUCCESS; } - /*! - * @brief Get general status of ADISense module. + * @brief Get general status of ADMW module. * * @param[in] * @param[out] pStatus : Pointer to CORE Status struct. @@ -331,7 +304,7 @@ * - #ADMW_SUCCESS Call completed successfully. * - #ADMW_FAILURE If status register read fails. * - * @details Read the general status register for the ADISense + * @details Read the general status register for the ADMW * module. Indicates Error, Alert conditions, data ready * and command running. * @@ -340,10 +313,10 @@ ADMW_DEVICE_HANDLE const hDevice, ADMW_STATUS * const pStatus) { - CORE_Status_t statusReg; + ADMW_CORE_Status_t statusReg; READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); - CORE_Alert_Status_2_t alert2Reg; + ADMW_CORE_Alert_Status_2_t alert2Reg; READ_REG_U16(hDevice, alert2Reg.VALUE16, CORE_ALERT_STATUS_2); memset(pStatus, 0, sizeof(*pStatus)); @@ -358,11 +331,11 @@ { pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ALERT; - CORE_Alert_Code_t alertCodeReg; + ADMW_CORE_Alert_Code_t alertCodeReg; READ_REG_U16(hDevice, alertCodeReg.VALUE16, CORE_ALERT_CODE); pStatus->alertCode = alertCodeReg.Alert_Code; - CORE_Channel_Alert_Status_t channelAlertStatusReg; + ADMW_CORE_Channel_Alert_Status_t channelAlertStatusReg; READ_REG_U16(hDevice, channelAlertStatusReg.VALUE16, CORE_CHANNEL_ALERT_STATUS); @@ -370,11 +343,11 @@ { if (channelAlertStatusReg.VALUE16 & (1 << i)) { - CORE_Alert_Code_Ch_t channelAlertCodeReg; + ADMW_CORE_Alert_Code_Ch_t channelAlertCodeReg; READ_REG_U16(hDevice, channelAlertCodeReg.VALUE16, CORE_ALERT_CODE_CHn(i)); pStatus->channelAlertCodes[i] = channelAlertCodeReg.Alert_Code_Ch; - CORE_Alert_Detail_Ch_t alertDetailReg; + ADMW_CORE_Alert_Detail_Ch_t alertDetailReg; READ_REG_U16(hDevice, alertDetailReg.VALUE16, CORE_ALERT_DETAIL_CHn(i)); @@ -417,11 +390,11 @@ { pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ERROR; - CORE_Error_Code_t errorCodeReg; + ADMW_CORE_Error_Code_t errorCodeReg; READ_REG_U16(hDevice, errorCodeReg.VALUE16, CORE_ERROR_CODE); pStatus->errorCode = errorCodeReg.Error_Code; - CORE_Diagnostics_Status_t diagStatusReg; + ADMW_CORE_Diagnostics_Status_t diagStatusReg; READ_REG_U16(hDevice, diagStatusReg.VALUE16, CORE_DIAGNOSTICS_STATUS); if (diagStatusReg.Diag_Checksum_Error) @@ -434,7 +407,7 @@ if (statusReg.Alert_Active || statusReg.Error) { - CORE_Debug_Code_t debugCodeReg; + ADMW_CORE_Debug_Code_t debugCodeReg; READ_REG_U32(hDevice, debugCodeReg.VALUE32, CORE_DEBUG_CODE); pStatus->debugCode = debugCodeReg.Debug_Code; } @@ -446,7 +419,7 @@ ADMW_DEVICE_HANDLE hDevice, bool *pbCommandRunning) { - CORE_Status_t statusReg; + ADMW_CORE_Status_t statusReg; READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); @@ -461,10 +434,10 @@ static ADMW_RESULT executeCommand( ADMW_DEVICE_HANDLE const hDevice, - CORE_Command_Special_Command const command, + ADMW_CORE_Command_Special_Command const command, bool const bWaitForCompletion) { - CORE_Command_t commandReg; + ADMW_CORE_Command_t commandReg; bool bCommandRunning; ADMW_RESULT eRet; @@ -618,17 +591,6 @@ } /* - * Run digital calibration routines on the device. - * Calibration is executed according to the current applied settings. - * No other command must be running when this is called. - */ -ADMW_RESULT admw_RunDigitalCalibration( - ADMW_DEVICE_HANDLE const hDevice) -{ - return executeCommand(hDevice, CORE_COMMAND_CALIBRATE_DIGITAL, true); -} - -/* * Read a set of data samples from the device. * This may be called at any time. */ @@ -918,110 +880,104 @@ } ADMW_RESULT admw1001_GetDataReadyModeInfo( - ADMW_DEVICE_HANDLE const hDevice, - ADMW_MEASUREMENT_MODE const eMeasurementMode, + ADMW_DEVICE_HANDLE const hDevice, + ADMW_MEASUREMENT_MODE const eMeasurementMode, ADMW1001_OPERATING_MODE * const peOperatingMode, ADMW1001_DATAREADY_MODE * const peDataReadyMode, - uint32_t * const pnSamplesPerDataready, - uint32_t * const pnSamplesPerCycle, - uint8_t * const pnBytesPerSample) + uint32_t * const pnSamplesPerDataready, + uint32_t * const pnSamplesPerCycle, + uint8_t * const pnBytesPerSample) { unsigned nChannelsEnabled = 0; unsigned nSamplesPerCycle = 0; - CORE_Mode_t modeReg; + ADMW_CORE_Mode_t modeReg; READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); if (eMeasurementMode == (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE)) *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; - else if (modeReg.Conversion_Mode == CORE_MODE_MULTICYCLE) - *peOperatingMode = ADMW1001_OPERATING_MODE_MULTICYCLE; else *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; if (eMeasurementMode == ADMW_MEASUREMENT_MODE_OMIT_RAW) { - *pnBytesPerSample = 5; + *pnBytesPerSample = 5; } else { - *pnBytesPerSample = 8; + *pnBytesPerSample = 8; } - for (ADMW1001_CHANNEL_ID chId = ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL; - chId < ADMW1001_MAX_CHANNELS; - chId++) + for (ADMW1001_CH_ID chId = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; + chId < ADMW1001_MAX_CHANNELS; + chId++) { - CORE_Sensor_Details_t sensorDetailsReg; - CORE_Channel_Count_t channelCountReg; - - if (ADMW1001_CHANNEL_IS_VIRTUAL(chId)) - continue; - - READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId)); - READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId)); - - if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) - { - CORE_Sensor_Type_t sensorTypeReg; - unsigned nActualChannels = 1; + ADMW_CORE_Sensor_Details_t sensorDetailsReg; + ADMW_CORE_Channel_Count_t channelCountReg; + + if (ADMW1001_CHANNEL_IS_VIRTUAL(chId)) + continue; + + READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId)); + READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId)); + + if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) + { + ADMW_CORE_Sensor_Type_t sensorTypeReg; + unsigned nActualChannels = 1; + + READ_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(chId)); + + if (chId == ADMW1001_CH_ID_DIG_SPI_0) + { + /* Some sensors automatically generate samples on additional + * "virtual" channels so these channels must be counted as + * active when those sensors are selected and we use the count + * from the corresponding "physical" channel + */ + if ((sensorTypeReg.Sensor_Type >= + CORE_SENSOR_TYPE_SPI_ACCELEROMETER_A) && + (sensorTypeReg.Sensor_Type <= + CORE_SENSOR_TYPE_SPI_ACCELEROMETER_B)) + { + nActualChannels += 2; + } + } - READ_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(chId)); - - if (chId == ADMW1001_CHANNEL_ID_SPI_0) - { - /* Some sensors automatically generate samples on additional "virtual" channels - * so these channels must be counted as active when those sensors are selected - * and we use the count from the corresponding "physical" channel */ - if ((sensorTypeReg.Sensor_Type >= - CORE_SENSOR_TYPE_SPI_ACCELEROMETER_A) && - (sensorTypeReg.Sensor_Type <= - CORE_SENSOR_TYPE_SPI_ACCELEROMETER_B)) - nActualChannels += 2; + nChannelsEnabled += nActualChannels; + + nSamplesPerCycle += nActualChannels * + (channelCountReg.Channel_Count + 1); } - - nChannelsEnabled += nActualChannels; - - nSamplesPerCycle += nActualChannels * - (channelCountReg.Channel_Count + 1); - } } if (nChannelsEnabled == 0) { - *pnSamplesPerDataready = 0; - *pnSamplesPerCycle = 0; - return ADMW_SUCCESS; + *pnSamplesPerDataready = 0; + *pnSamplesPerCycle = 0; + return ADMW_SUCCESS; } *pnSamplesPerCycle = nSamplesPerCycle; - if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CONVERSION) + if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) { - *pnSamplesPerDataready = 1; - } - else if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CYCLE) - { - *pnSamplesPerDataready = nSamplesPerCycle; + *pnSamplesPerDataready = 1; } else { - CORE_Fifo_Num_Cycles_t fifoNumCyclesReg; - READ_REG_U8(hDevice, fifoNumCyclesReg.VALUE8, CORE_FIFO_NUM_CYCLES); - - *pnSamplesPerDataready = - nSamplesPerCycle * fifoNumCyclesReg.Fifo_Num_Cycles; + *pnSamplesPerDataready = nSamplesPerCycle; } - - if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CONVERSION) - *peDataReadyMode = ADMW1001_DATAREADY_PER_CONVERSION; - else if (modeReg.Drdy_Mode == ENUM_CORE_MODE_DRDY_PER_CYCLE) - *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; + + if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) + { + *peDataReadyMode = ADMW1001_DATAREADY_PER_CONVERSION; + } else { - *peDataReadyMode = ADMW1001_DATAREADY_PER_MULTICYCLE_BURST; + *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; } - + return ADMW_SUCCESS; } @@ -1035,8 +991,8 @@ READ_REG_U8(hDevice, productIdLoReg.VALUE8, SPI_PRODUCT_ID_L); READ_REG_U8(hDevice, productIdHiReg.VALUE8, SPI_PRODUCT_ID_H); - *pProductId = (ADMW_PRODUCT_ID)((productIdHiReg.VALUE8 << 8) - | productIdLoReg.VALUE8); + *pProductId = (ADMW_PRODUCT_ID)((productIdHiReg.VALUE8 << 8) | + productIdLoReg.VALUE8); return ADMW_SUCCESS; } @@ -1044,7 +1000,7 @@ ADMW_DEVICE_HANDLE hDevice, ADMW1001_POWER_MODE powerMode) { - CORE_Power_Config_t powerConfigReg; + ADMW_CORE_Power_Config_t powerConfigReg; if (powerMode == ADMW1001_POWER_MODE_HIBERNATION) { @@ -1084,10 +1040,9 @@ static ADMW_RESULT admw_SetMode( ADMW_DEVICE_HANDLE hDevice, ADMW1001_OPERATING_MODE eOperatingMode, - ADMW1001_DATAREADY_MODE eDataReadyMode, - bool bEnableExtFlash) + ADMW1001_DATAREADY_MODE eDataReadyMode) { - CORE_Mode_t modeReg; + ADMW_CORE_Mode_t modeReg; modeReg.VALUE8 = REG_RESET_VAL(CORE_MODE); @@ -1099,10 +1054,6 @@ { modeReg.Conversion_Mode = CORE_MODE_CONTINUOUS; } - else if (eOperatingMode == ADMW1001_OPERATING_MODE_MULTICYCLE) - { - modeReg.Conversion_Mode = CORE_MODE_MULTICYCLE; - } else { ADMW_LOG_ERROR("Invalid operating mode %d specified", @@ -1118,20 +1069,6 @@ { modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CYCLE; } - else if (eDataReadyMode == ADMW1001_DATAREADY_PER_MULTICYCLE_BURST) - { - if (eOperatingMode != ADMW1001_OPERATING_MODE_MULTICYCLE) - { - ADMW_LOG_ERROR( - "Data-ready mode %d cannot be used with operating mode %d", - eDataReadyMode, eOperatingMode); - return ADMW_INVALID_PARAM; - } - else - { - modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_FIFO_FILL; - } - } else { ADMW_LOG_ERROR("Invalid data-ready mode %d specified", eDataReadyMode); @@ -1143,26 +1080,15 @@ return ADMW_SUCCESS; } -ADMW_RESULT admw_SetCycleControl( - ADMW_DEVICE_HANDLE hDevice, - uint32_t nCycleInterval - -#ifdef __V2_3_CFG_FMT__ - , ADMW1001_CYCLE_TYPE eCycleType, - ADMW1001_FILTER_SETTLING eFilterSettling) -#else - ) -#endif +ADMW_RESULT admw_SetCycleControl(ADMW_DEVICE_HANDLE hDevice, + uint32_t nCycleInterval, + bool vBiasEnable) { - CORE_Cycle_Control_t cycleControlReg; + ADMW_CORE_Cycle_Control_t cycleControlReg; cycleControlReg.VALUE16 = REG_RESET_VAL(CORE_CYCLE_CONTROL); - if (nCycleInterval < (1 << 12)) - { - cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_MICROSECONDS; - } - else if (nCycleInterval < (1000 * (1 << 12))) + if (nCycleInterval < (1000 * (1 << 12))) { cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_MILLISECONDS; nCycleInterval /= 1000; @@ -1173,46 +1099,18 @@ nCycleInterval /= 1000000; } + if (vBiasEnable == true) + { + cycleControlReg.Vbias = 1; + } CHECK_REG_FIELD_VAL(CORE_CYCLE_CONTROL_CYCLE_TIME, nCycleInterval); cycleControlReg.Cycle_Time = nCycleInterval; -#ifdef __V2_3_CFG_FMT__ - if (eFilterSettling == ADMW1001_FILTER_SETTLING_ALWAYS) - { - cycleControlReg.Filter_Settling = CORE_CYCLE_CONTROL_FILTER_SETTLING_SETTLED; - } - else if (eFilterSettling == ADMW1001_FILTER_SETTLING_FAST) - { - cycleControlReg.Filter_Settling = CORE_CYCLE_CONTROL_FILTER_SETTLING_FAST; - } - else - { - ADMW_LOG_ERROR("Invalid filter settling option %d specified", eFilterSettling); - return ADMW_INVALID_PARAM; - } -#endif - WRITE_REG_U16(hDevice, cycleControlReg.VALUE16, CORE_CYCLE_CONTROL); return ADMW_SUCCESS; } -static ADMW_RESULT admw_SetMultiCycleConfig( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_MULTICYCLE_CONFIG *pMultiCycleConfig) -{ - CHECK_REG_FIELD_VAL(CORE_FIFO_NUM_CYCLES_FIFO_NUM_CYCLES, - pMultiCycleConfig->cyclesPerBurst); - - WRITE_REG_U8(hDevice, pMultiCycleConfig->cyclesPerBurst, - CORE_FIFO_NUM_CYCLES); - - WRITE_REG_U32(hDevice, pMultiCycleConfig->burstInterval, - CORE_MULTI_CYCLE_REPEAT_INTERVAL); - - return ADMW_SUCCESS; -} - static ADMW_RESULT admw_SetExternalReferenceValues( ADMW_DEVICE_HANDLE hDevice, float32_t externalRef1Value) @@ -1229,39 +1127,28 @@ ADMW_RESULT eRet; eRet = admw_SetMode(hDevice, - pMeasConfig->operatingMode, - pMeasConfig->dataReadyMode, - pMeasConfig->enableExternalFlash); + pMeasConfig->operatingMode, + pMeasConfig->dataReadyMode); if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set operating mode"); return eRet; } - eRet = admw_SetCycleControl(hDevice, - pMeasConfig->cycleInterval); + eRet = admw_SetCycleControl(hDevice, pMeasConfig->cycleInterval, + pMeasConfig->vBiasEnable); if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set cycle control"); return eRet; } - if (pMeasConfig->operatingMode == ADMW1001_OPERATING_MODE_MULTICYCLE) + if(pMeasConfig->externalRef1Value>0) { - eRet = admw_SetMultiCycleConfig(hDevice, - &pMeasConfig->multiCycleConfig); - if (eRet != ADMW_SUCCESS) - { - ADMW_LOG_ERROR("Failed to set multi-cycle configuration"); - return eRet; - } + eRet = admw_SetExternalReferenceValues(hDevice, + pMeasConfig->externalRef1Value); } - if(pMeasConfig->externalRef1Value>0) - eRet = admw_SetExternalReferenceValues(hDevice, - pMeasConfig->externalRef1Value); - else - ; - + if (eRet != ADMW_SUCCESS) { ADMW_LOG_ERROR("Failed to set external reference values"); @@ -1275,7 +1162,7 @@ ADMW_DEVICE_HANDLE hDevice, ADMW1001_DIAGNOSTICS_CONFIG *pDiagnosticsConfig) { - CORE_Diagnostics_Control_t diagnosticsControlReg; + ADMW_CORE_Diagnostics_Control_t diagnosticsControlReg; diagnosticsControlReg.VALUE16 = REG_RESET_VAL(CORE_DIAGNOSTICS_CONTROL); @@ -1316,10 +1203,10 @@ ADMW_RESULT admw1001_SetChannelCount( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, uint32_t nMeasurementsPerCycle) { - CORE_Channel_Count_t channelCountReg; + ADMW_CORE_Channel_Count_t channelCountReg; channelCountReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_COUNTn); @@ -1345,10 +1232,10 @@ ADMW_RESULT admw1001_SetChannelOptions( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_CHANNEL_PRIORITY ePriority) { - CORE_Channel_Options_t channelOptionsReg; + ADMW_CORE_Channel_Options_t channelOptionsReg; channelOptionsReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_OPTIONSn); @@ -1362,10 +1249,10 @@ ADMW_RESULT admw1001_SetChannelSkipCount( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, uint32_t nCycleSkipCount) { - CORE_Channel_Skip_t channelSkipReg; + ADMW_CORE_Channel_Skip_t channelSkipReg; channelSkipReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_SKIPn); @@ -1379,97 +1266,53 @@ } static ADMW_RESULT admw_SetChannelAdcSensorType( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, - ADMW1001_ADC_SENSOR_TYPE sensorType) + ADMW_DEVICE_HANDLE hDevice, + ADMW1001_CH_ID eChannelId, + ADMW1001_ADC_SENSOR_TYPE sensorType) { - CORE_Sensor_Type_t sensorTypeReg; + ADMW_CORE_Sensor_Type_t sensorTypeReg; sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); /* Ensure that the sensor type is valid for this channel */ switch(sensorType) { - case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_3WIRE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_4WIRE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_MICROPHONE_A_DEF_L1: - case ADMW1001_ADC_SENSOR_MICROPHONE_B_DEF_L1: - case ADMW1001_ADC_SENSOR_MICROPHONE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_MICROPHONE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_MICROPHONE_A_ADV_L1: - case ADMW1001_ADC_SENSOR_MICROPHONE_B_ADV_L1: - case ADMW1001_ADC_SENSOR_MICROPHONE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_MICROPHONE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_DEF_L1: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_ADV_L1: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_RTD_2WIRE_4_ADV_L2: - case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA_DEF_L1: - case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA_DEF_L1: - case ADMW1001_ADC_SENSOR_DIODE_2C_1_DEF_L2: - case ADMW1001_ADC_SENSOR_DIODE_3C_1_DEF_L2: - case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA_ADV_L1: - case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA_ADV_L1: - case ADMW1001_ADC_SENSOR_DIODE_2C_1_ADV_L2: - case ADMW1001_ADC_SENSOR_DIODE_3C_1_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMISTOR_1_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_2_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_3_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_4_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMISTOR_1_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_2_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_3_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMISTOR_4_ADV_L2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_1: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_2: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_3: + case ADMW1001_ADC_SENSOR_RTD_3WIRE_4: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_1: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_2: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_3: + case ADMW1001_ADC_SENSOR_RTD_4WIRE_4: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_1: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_2: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_3: + case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE_4: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_1: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_2: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_3: + case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE_4: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_1: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_2: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_3: + case ADMW1001_ADC_SENSOR_RTD_2WIRE_4: + case ADMW1001_ADC_SENSOR_DIODE_2C_TYPEA: + case ADMW1001_ADC_SENSOR_DIODE_3C_TYPEA: + case ADMW1001_ADC_SENSOR_DIODE_2C_1: + case ADMW1001_ADC_SENSOR_DIODE_3C_1: + case ADMW1001_ADC_SENSOR_THERMISTOR_A_10K: + case ADMW1001_ADC_SENSOR_THERMISTOR_B_10K: + case ADMW1001_ADC_SENSOR_THERMISTOR_1: + case ADMW1001_ADC_SENSOR_THERMISTOR_2: + case ADMW1001_ADC_SENSOR_THERMISTOR_3: + case ADMW1001_ADC_SENSOR_THERMISTOR_4: if (! (ADMW1001_CHANNEL_IS_ADC_SENSOR(eChannelId) || ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId))) { @@ -1480,28 +1323,17 @@ } break; case ADMW1001_ADC_SENSOR_VOLTAGE: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A_DEF_L1: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B_DEF_L1: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A_ADV_L1: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B_ADV_L1: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T_DEF_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4_DEF_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T_ADV_L1: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3_ADV_L2: - case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4_ADV_L2: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_A: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_B: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_1: + case ADMW1001_ADC_SENSOR_VOLTAGE_PRESSURE_2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_1: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_2: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_3: + case ADMW1001_ADC_SENSOR_THERMOCOUPLE_4: if (! ADMW1001_CHANNEL_IS_ADC_VOLTAGE(eChannelId)) { ADMW_LOG_ERROR( @@ -1511,12 +1343,9 @@ } break; case ADMW1001_ADC_SENSOR_CURRENT: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A_DEF_L1: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1_DEF_L2: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2_DEF_L2: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A_ADV_L1: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1_ADV_L2: - case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2_ADV_L2: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_A: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_1: + case ADMW1001_ADC_SENSOR_CURRENT_PRESSURE_2: if (! ADMW1001_CHANNEL_IS_ADC_CURRENT(eChannelId)) { ADMW_LOG_ERROR( @@ -1539,8 +1368,8 @@ } static ADMW_RESULT admw_SetChannelAdcSensorDetails( - ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW_DEVICE_HANDLE hDevice, + ADMW1001_CH_ID eChannelId, ADMW1001_CHANNEL_CONFIG *pChannelConfig) /* * TODO - it would be nice if the general- vs. ADC-specific sensor details could be split into separate registers @@ -1552,33 +1381,32 @@ * - PGA_Gain * - Reference_Select * - Reference_Buffer_Disable - * - Vbias */ { ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = &pChannelConfig->adcChannelConfig; - ADMW1001_ADC_REFERENCE_CONFIG *pRefConfig = &pAdcChannelConfig->reference; - CORE_Sensor_Details_t sensorDetailsReg; + ADMW1001_ADC_REFERENCE_TYPE refType = pAdcChannelConfig->reference; + ADMW_CORE_Sensor_Details_t sensorDetailsReg; sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); switch(pChannelConfig->measurementUnit) { - case ADMW1001_MEASUREMENT_UNIT_FAHRENHEIT: - sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGF; - break; - case ADMW1001_MEASUREMENT_UNIT_CELSIUS: - sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGC; - break; - case ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED: - sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; - break; - default: - ADMW_LOG_ERROR("Invalid measurement unit %d specified", - pChannelConfig->measurementUnit); - return ADMW_INVALID_PARAM; + case ADMW1001_MEASUREMENT_UNIT_FAHRENHEIT: + sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGF; + break; + case ADMW1001_MEASUREMENT_UNIT_CELSIUS: + sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGC; + break; + case ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED: + sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; + break; + default: + ADMW_LOG_ERROR("Invalid measurement unit %d specified", + pChannelConfig->measurementUnit); + return ADMW_INVALID_PARAM; } - if (pChannelConfig->compensationChannel == ADMW1001_CHANNEL_ID_NONE) + if (pChannelConfig->compensationChannel == ADMW1001_CH_ID_NONE) { sensorDetailsReg.Compensation_Disable = 1; sensorDetailsReg.Compensation_Channel = 0; @@ -1589,96 +1417,96 @@ sensorDetailsReg.Compensation_Channel = pChannelConfig->compensationChannel; } - switch(pRefConfig->type) + switch(refType) { - case ADMW1001_ADC_REFERENCE_RESISTOR_INTERNAL_1: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_INT; - break; - case ADMW1001_ADC_REFERENCE_VOLTAGE_INTERNAL: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_INT; - break; - case ADMW1001_ADC_REFERENCE_VOLTAGE_AVDD: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_AVDD; - break; - case ADMW1001_ADC_REFERENCE_RESISTOR_EXTERNAL_1: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_REXT1; - break; - case ADMW1001_ADC_REFERENCE_BRIDGE_EXCITATION: - sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_EXC; - break; - default: - ADMW_LOG_ERROR("Invalid ADC reference type %d specified", - pRefConfig->type); - return ADMW_INVALID_PARAM; + case ADMW1001_ADC_REFERENCE_VOLTAGE_INTERNAL: + sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VINT; + break; + case ADMW1001_ADC_REFERENCE_VOLTAGE_EXTERNAL_1: + sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VEXT1; + break; + case ADMW1001_ADC_REFERENCE_VOLTAGE_AVDD: + sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_AVDD; + break; + default: + ADMW_LOG_ERROR("Invalid ADC reference type %d specified", refType); + return ADMW_INVALID_PARAM; } switch(pAdcChannelConfig->gain) { - case ADMW1001_ADC_GAIN_1X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_1; - break; - case ADMW1001_ADC_GAIN_2X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_2; - break; - case ADMW1001_ADC_GAIN_4X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_4; - break; - case ADMW1001_ADC_GAIN_8X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_8; - break; - case ADMW1001_ADC_GAIN_16X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_16; - break; - case ADMW1001_ADC_GAIN_32X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_32; - break; - case ADMW1001_ADC_GAIN_64X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_64; - break; - case ADMW1001_ADC_GAIN_128X: - sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_128; - break; - default: - ADMW_LOG_ERROR("Invalid ADC gain %d specified", - pAdcChannelConfig->gain); - return ADMW_INVALID_PARAM; + case ADMW1001_ADC_GAIN_1X: + sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_1; + break; + case ADMW1001_ADC_GAIN_2X: + sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_2; + break; + case ADMW1001_ADC_GAIN_4X: + sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_4; + break; + case ADMW1001_ADC_GAIN_8X: + sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_8; + break; + case ADMW1001_ADC_GAIN_16X: + sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_16; + break; + case ADMW1001_ADC_GAIN_32X: + sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_32; + break; + case ADMW1001_ADC_GAIN_64X: + sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_64; + break; + case ADMW1001_ADC_GAIN_128X: + sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_128; + break; + default: + ADMW_LOG_ERROR("Invalid ADC gain %d specified", + pAdcChannelConfig->gain); + return ADMW_INVALID_PARAM; } switch(pAdcChannelConfig->rtdCurve) { - case ADMW1001_ADC_RTD_CURVE_EUROPEAN: - sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_EUROPEAN_CURVE; - break; - case ADMW1001_ADC_RTD_CURVE_AMERICAN: - sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_AMERICAN_CURVE; - break; - case ADMW1001_ADC_RTD_CURVE_JAPANESE: - sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_JAPANESE_CURVE; - break; - case ADMW1001_ADC_RTD_CURVE_ITS90: - sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_ITS90_CURVE; - break; - default: - ADMW_LOG_ERROR("Invalid RTD Curve %d specified", - pAdcChannelConfig->rtdCurve); - return ADMW_INVALID_PARAM; + case ADMW1001_ADC_RTD_CURVE_EUROPEAN: + sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_EUROPEAN_CURVE; + break; + case ADMW1001_ADC_RTD_CURVE_AMERICAN: + sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_AMERICAN_CURVE; + break; + case ADMW1001_ADC_RTD_CURVE_JAPANESE: + sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_JAPANESE_CURVE; + break; + case ADMW1001_ADC_RTD_CURVE_ITS90: + sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_ITS90_CURVE; + break; + default: + ADMW_LOG_ERROR("Invalid RTD Curve %d specified", + pAdcChannelConfig->rtdCurve); + return ADMW_INVALID_PARAM; } - if (pAdcChannelConfig->enableVbias) - sensorDetailsReg.Vbias = 1; - else - sensorDetailsReg.Vbias = 0; - if (pChannelConfig->disablePublishing) + { sensorDetailsReg.Do_Not_Publish = 1; + } else + { sensorDetailsReg.Do_Not_Publish = 0; - - if (pChannelConfig->enableUnityLut) - sensorDetailsReg.Unity_LUT_Select = 1; - else - sensorDetailsReg.Unity_LUT_Select = 0; - + } + + switch (pChannelConfig->lutSelect) + { + case ADMW1001_LUT_DEFAULT: + case ADMW1001_LUT_UNITY: + case ADMW1001_LUT_CUSTOM: + sensorDetailsReg.LUT_Select = pChannelConfig->lutSelect; + break; + default: + ADMW_LOG_ERROR("Invalid LUT selection %d specified", + pChannelConfig->lutSelect); + return ADMW_INVALID_PARAM; + } + WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); return ADMW_SUCCESS; @@ -1686,10 +1514,10 @@ static ADMW_RESULT admw_SetChannelAdcFilter( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_ADC_FILTER_CONFIG *pFilterConfig) { - CORE_Measurement_Setup_t MeasSetupReg; + ADMW_CORE_Measurement_Setup_t MeasSetupReg; MeasSetupReg.VALUE32 = REG_RESET_VAL(CORE_MEASUREMENT_SETUPn); if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC4) @@ -1709,10 +1537,8 @@ return ADMW_INVALID_PARAM; } - if(pFilterConfig->filterChop) - MeasSetupReg.Chop_Mode = 1; - else - MeasSetupReg.Chop_Mode = 1; + /* chop mod ecan be 0 (none), 1 (HW, 2 (SW, 3 (HW+SW). */ + MeasSetupReg.Chop_Mode = pFilterConfig->filterChop; if(pFilterConfig->notch1p2) MeasSetupReg.NOTCH_EN_2 = 1; @@ -1740,10 +1566,10 @@ static ADMW_RESULT admw_SetChannelAdcCurrentConfig( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_ADC_EXC_CURRENT_CONFIG *pCurrentConfig) { - CORE_Channel_Excitation_t channelExcitationReg; + ADMW_CORE_Channel_Excitation_t channelExcitationReg; channelExcitationReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_EXCITATIONn); @@ -1806,7 +1632,7 @@ ADMW_RESULT admw_SetAdcChannelConfig( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_CHANNEL_CONFIG *pChannelConfig) { ADMW_RESULT eRet; @@ -1854,14 +1680,14 @@ static ADMW_RESULT admw_SetChannelDigitalSensorDetails( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_CHANNEL_CONFIG *pChannelConfig) { - CORE_Sensor_Details_t sensorDetailsReg; + ADMW_CORE_Sensor_Details_t sensorDetailsReg; sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); - if (pChannelConfig->compensationChannel == ADMW1001_CHANNEL_ID_NONE) + if (pChannelConfig->compensationChannel == ADMW1001_CH_ID_NONE) { sensorDetailsReg.Compensation_Disable = 1; sensorDetailsReg.Compensation_Channel = 0; @@ -1887,13 +1713,6 @@ else sensorDetailsReg.Do_Not_Publish = 0; - if (pChannelConfig->enableUnityLut) - sensorDetailsReg.Unity_LUT_Select = 1; - else - sensorDetailsReg.Unity_LUT_Select = 0; - - sensorDetailsReg.Vbias = 0; - WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); return ADMW_SUCCESS; @@ -1901,11 +1720,11 @@ static ADMW_RESULT admw_SetDigitalSensorCommands( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_DIGITAL_SENSOR_COMMAND *pConfigCommand, ADMW1001_DIGITAL_SENSOR_COMMAND *pDataRequestCommand) { - CORE_Digital_Sensor_Num_Cmds_t numCmdsReg; + ADMW_CORE_Digital_Sensor_Num_Cmds_t numCmdsReg; numCmdsReg.VALUE8 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_NUM_CMDSn); @@ -1922,84 +1741,73 @@ /* * NOTE - the fall-through cases in the switch statement below are - * intentional, so temporarily disable related compiler warnings which may - * be produced here by GCC + * intentional. */ -#ifndef __CC_ARM -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" -#endif - switch (pConfigCommand->commandLength) { - case 7: - WRITE_REG_U8(hDevice, pConfigCommand->command[6], - CORE_DIGITAL_SENSOR_COMMAND7n(eChannelId)); - case 6: - WRITE_REG_U8(hDevice, pConfigCommand->command[5], - CORE_DIGITAL_SENSOR_COMMAND6n(eChannelId)); - case 5: - WRITE_REG_U8(hDevice, pConfigCommand->command[4], - CORE_DIGITAL_SENSOR_COMMAND5n(eChannelId)); - case 4: - WRITE_REG_U8(hDevice, pConfigCommand->command[3], - CORE_DIGITAL_SENSOR_COMMAND4n(eChannelId)); - case 3: - WRITE_REG_U8(hDevice, pConfigCommand->command[2], - CORE_DIGITAL_SENSOR_COMMAND3n(eChannelId)); - case 2: - WRITE_REG_U8(hDevice, pConfigCommand->command[1], - CORE_DIGITAL_SENSOR_COMMAND2n(eChannelId)); - case 1: - WRITE_REG_U8(hDevice, pConfigCommand->command[0], - CORE_DIGITAL_SENSOR_COMMAND1n(eChannelId)); - case 0: - default: - break; + case 7: + WRITE_REG_U8(hDevice, pConfigCommand->command[6], + CORE_DIGITAL_SENSOR_COMMAND7n(eChannelId)); + case 6: + WRITE_REG_U8(hDevice, pConfigCommand->command[5], + CORE_DIGITAL_SENSOR_COMMAND6n(eChannelId)); + case 5: + WRITE_REG_U8(hDevice, pConfigCommand->command[4], + CORE_DIGITAL_SENSOR_COMMAND5n(eChannelId)); + case 4: + WRITE_REG_U8(hDevice, pConfigCommand->command[3], + CORE_DIGITAL_SENSOR_COMMAND4n(eChannelId)); + case 3: + WRITE_REG_U8(hDevice, pConfigCommand->command[2], + CORE_DIGITAL_SENSOR_COMMAND3n(eChannelId)); + case 2: + WRITE_REG_U8(hDevice, pConfigCommand->command[1], + CORE_DIGITAL_SENSOR_COMMAND2n(eChannelId)); + case 1: + WRITE_REG_U8(hDevice, pConfigCommand->command[0], + CORE_DIGITAL_SENSOR_COMMAND1n(eChannelId)); + case 0: + default: + break; }; switch (pDataRequestCommand->commandLength) { - case 7: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[6], - CORE_DIGITAL_SENSOR_READ_CMD7n(eChannelId)); - case 6: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[5], - CORE_DIGITAL_SENSOR_READ_CMD6n(eChannelId)); - case 5: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[4], - CORE_DIGITAL_SENSOR_READ_CMD5n(eChannelId)); - case 4: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[3], - CORE_DIGITAL_SENSOR_READ_CMD4n(eChannelId)); - case 3: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[2], - CORE_DIGITAL_SENSOR_READ_CMD3n(eChannelId)); - case 2: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[1], - CORE_DIGITAL_SENSOR_READ_CMD2n(eChannelId)); - case 1: - WRITE_REG_U8(hDevice, pDataRequestCommand->command[0], - CORE_DIGITAL_SENSOR_READ_CMD1n(eChannelId)); - case 0: - default: - break; + case 7: + WRITE_REG_U8(hDevice, pDataRequestCommand->command[6], + CORE_DIGITAL_SENSOR_READ_CMD7n(eChannelId)); + case 6: + WRITE_REG_U8(hDevice, pDataRequestCommand->command[5], + CORE_DIGITAL_SENSOR_READ_CMD6n(eChannelId)); + case 5: + WRITE_REG_U8(hDevice, pDataRequestCommand->command[4], + CORE_DIGITAL_SENSOR_READ_CMD5n(eChannelId)); + case 4: + WRITE_REG_U8(hDevice, pDataRequestCommand->command[3], + CORE_DIGITAL_SENSOR_READ_CMD4n(eChannelId)); + case 3: + WRITE_REG_U8(hDevice, pDataRequestCommand->command[2], + CORE_DIGITAL_SENSOR_READ_CMD3n(eChannelId)); + case 2: + WRITE_REG_U8(hDevice, pDataRequestCommand->command[1], + CORE_DIGITAL_SENSOR_READ_CMD2n(eChannelId)); + case 1: + WRITE_REG_U8(hDevice, pDataRequestCommand->command[0], + CORE_DIGITAL_SENSOR_READ_CMD1n(eChannelId)); + case 0: + default: + break; }; - /* Re-enable the implicit-fallthrough warning */ -#ifndef __CC_ARM -#pragma GCC diagnostic pop -#endif - return ADMW_SUCCESS; } static ADMW_RESULT admw_SetDigitalSensorFormat( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_DIGITAL_SENSOR_DATA_FORMAT *pDataFormat) { - CORE_Digital_Sensor_Config_t sensorConfigReg; + ADMW_CORE_Digital_Sensor_Config_t sensorConfigReg; sensorConfigReg.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_CONFIGn); @@ -2059,10 +1867,10 @@ static ADMW_RESULT admw_SetDigitalCalibrationParam( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_DIGITAL_CALIBRATION_COMMAND *pCalibrationParam) { - CORE_Calibration_Parameter_t calibrationParamReg; + ADMW_CORE_Calibration_Parameter_t calibrationParamReg; calibrationParamReg.VALUE32 = REG_RESET_VAL(CORE_CALIBRATION_PARAMETERn); @@ -2084,33 +1892,23 @@ static ADMW_RESULT admw_SetChannelI2cSensorType( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_I2C_SENSOR_TYPE sensorType) { - CORE_Sensor_Type_t sensorTypeReg; + ADMW_CORE_Sensor_Type_t sensorTypeReg; sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); /* Ensure that the sensor type is valid for this channel */ switch(sensorType) { - case ADMW1001_I2C_SENSOR_HUMIDITY_A_DEF_L1: - case ADMW1001_I2C_SENSOR_HUMIDITY_B_DEF_L1: - case ADMW1001_I2C_SENSOR_HUMIDITY_A_DEF_L2: - case ADMW1001_I2C_SENSOR_HUMIDITY_B_DEF_L2: - case ADMW1001_I2C_SENSOR_HUMIDITY_A_ADV_L1: - case ADMW1001_I2C_SENSOR_HUMIDITY_B_ADV_L1: - case ADMW1001_I2C_SENSOR_HUMIDITY_A_ADV_L2: - case ADMW1001_I2C_SENSOR_HUMIDITY_B_ADV_L2: - case ADMW1001_I2C_SENSOR_AMBIENTLIGHT_A_DEF_L1: - case ADMW1001_I2C_SENSOR_AMBIENTLIGHT_A_DEF_L2: - case ADMW1001_I2C_SENSOR_AMBIENTLIGHT_A_ADV_L1: - case ADMW1001_I2C_SENSOR_AMBIENTLIGHT_A_ADV_L2: - sensorTypeReg.Sensor_Type = sensorType; - break; - default: - ADMW_LOG_ERROR("Unsupported I2C sensor type %d specified", sensorType); - return ADMW_INVALID_PARAM; + case ADMW1001_I2C_SENSOR_HUMIDITY_A: + case ADMW1001_I2C_SENSOR_HUMIDITY_B: + sensorTypeReg.Sensor_Type = sensorType; + break; + default: + ADMW_LOG_ERROR("Unsupported I2C sensor type %d specified", sensorType); + return ADMW_INVALID_PARAM; } WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); @@ -2120,7 +1918,7 @@ static ADMW_RESULT admw_SetChannelI2cSensorAddress( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, uint32_t deviceAddress) { CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_ADDRESS_DIGITAL_SENSOR_ADDRESS, deviceAddress); @@ -2131,10 +1929,10 @@ static ADMW_RESULT admw_SetDigitalChannelComms( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_DIGITAL_SENSOR_COMMS *pDigitalComms) { - CORE_Digital_Sensor_Comms_t digitalSensorComms; + ADMW_CORE_Digital_Sensor_Comms_t digitalSensorComms; digitalSensorComms.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_COMMSn); @@ -2182,53 +1980,53 @@ switch (pDigitalComms->spiClock) { - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_13MHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_13MHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_8MHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_8MHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_6_5MHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_6_5MHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_4MHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_4MHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3_25MHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_3_25MHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_2MHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_2MHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1_625MHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1_625MHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1MHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1MHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_812KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_812KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_500KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_500KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_406KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_406KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_250KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_250KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_203KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_203KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_125KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_125KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_101KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_101KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_62P5KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_62P5KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_50KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_50KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_31P3KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_31P3KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_25KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_25KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_15P6KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_15P6KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_12KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_12KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_7P8KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_7P8KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_6KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_6KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3P9KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_3P9KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_3KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_3KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1P9KHZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1P9KHZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_1_5KHZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_1_5KHZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_977HZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_977HZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_793HZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_793HZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_488HZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_488HZ; break; - case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_396HZ: - digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_396HZ; + case ADMW1001_DIGITAL_SENSOR_COMMS_SPI_CLOCK_244HZ: + digitalSensorComms.SPI_Clock = CORE_DIGITAL_SENSOR_COMMS_SPI_244HZ; break; default: ADMW_LOG_ERROR("Invalid SPI clock %d specified", @@ -2248,7 +2046,7 @@ ADMW_RESULT admw_SetI2cChannelConfig( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_CHANNEL_CONFIG *pChannelConfig) { ADMW_RESULT eRet; @@ -2324,28 +2122,20 @@ static ADMW_RESULT admw_SetChannelSpiSensorType( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_SPI_SENSOR_TYPE sensorType) { - CORE_Sensor_Type_t sensorTypeReg; + ADMW_CORE_Sensor_Type_t sensorTypeReg; sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); /* Ensure that the sensor type is valid for this channel */ switch(sensorType) { - case ADMW1001_SPI_SENSOR_PRESSURE_A_DEF_L1: - case ADMW1001_SPI_SENSOR_PRESSURE_A_DEF_L2: - case ADMW1001_SPI_SENSOR_PRESSURE_A_ADV_L1: - case ADMW1001_SPI_SENSOR_PRESSURE_A_ADV_L2: - case ADMW1001_SPI_SENSOR_ACCELEROMETER_A_DEF_L1: - case ADMW1001_SPI_SENSOR_ACCELEROMETER_B_DEF_L1: - case ADMW1001_SPI_SENSOR_ACCELEROMETER_A_DEF_L2: - case ADMW1001_SPI_SENSOR_ACCELEROMETER_B_DEF_L2: - case ADMW1001_SPI_SENSOR_ACCELEROMETER_A_ADV_L1: - case ADMW1001_SPI_SENSOR_ACCELEROMETER_B_ADV_L1: - case ADMW1001_SPI_SENSOR_ACCELEROMETER_A_ADV_L2: - case ADMW1001_SPI_SENSOR_ACCELEROMETER_B_ADV_L2: + case ADMW1001_SPI_SENSOR_PRESSURE_A: + case ADMW1001_SPI_SENSOR_ACCELEROMETER_A: + case ADMW1001_SPI_SENSOR_ACCELEROMETER_B: + sensorTypeReg.Sensor_Type = sensorType; break; default: @@ -2360,7 +2150,7 @@ ADMW_RESULT admw_SetSpiChannelConfig( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_CHANNEL_CONFIG *pChannelConfig) { ADMW_RESULT eRet; @@ -2427,7 +2217,7 @@ ADMW_RESULT admw1001_SetChannelThresholdLimits( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, float32_t fHighThresholdLimit, float32_t fLowThresholdLimit) { @@ -2458,7 +2248,7 @@ ADMW_RESULT admw1001_SetOffsetGain( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, float32_t fOffsetAdjustment, float32_t fGainAdjustment) { @@ -2476,7 +2266,7 @@ ADMW_RESULT admw1001_SetSensorParameter( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, float32_t fSensorParam) { if (fSensorParam == 0.0f) @@ -2489,10 +2279,10 @@ ADMW_RESULT admw1001_SetChannelSettlingTime( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, uint32_t nSettlingTime) { - CORE_Settling_Time_t settlingTimeReg; + ADMW_CORE_Settling_Time_t settlingTimeReg; if (nSettlingTime < (1 << 12)) { @@ -2519,7 +2309,7 @@ ADMW_RESULT admw1001_SetChannelConfig( ADMW_DEVICE_HANDLE hDevice, - ADMW1001_CHANNEL_ID eChannelId, + ADMW1001_CH_ID eChannelId, ADMW1001_CHANNEL_CONFIG *pChannelConfig) { ADMW_RESULT eRet; @@ -2559,17 +2349,17 @@ switch (eChannelId) { - case ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL: - case ADMW1001_CHANNEL_ID_ANALOG_2_UNIVERSAL: - case ADMW1001_CHANNEL_ID_ANALOG_1_DIFFERENTIAL: - case ADMW1001_CHANNEL_ID_ANALOG_2_DIFFERENTIAL: + case ADMW1001_CH_ID_ANLG_1_UNIVERSAL: + case ADMW1001_CH_ID_ANLG_2_UNIVERSAL: + case ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL: + case ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL: eRet = admw_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig); break; - case ADMW1001_CHANNEL_ID_I2C_0: - case ADMW1001_CHANNEL_ID_I2C_1: + case ADMW1001_CH_ID_DIG_I2C_0: + case ADMW1001_CH_ID_DIG_I2C_1: eRet = admw_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig); break; - case ADMW1001_CHANNEL_ID_SPI_0: + case ADMW1001_CH_ID_DIG_SPI_0: eRet = admw_SetSpiChannelConfig(hDevice, eChannelId, pChannelConfig); break; default: @@ -2641,7 +2431,8 @@ return ADMW_INVALID_PARAM; } - if(!((pConfig->versionId.major==VERSIONID_MAJOR) && (pConfig->versionId.minor==VERSIONID_MINOR))) + if (!((pConfig->versionId.major==VERSIONID_MAJOR) && + (pConfig->versionId.minor==VERSIONID_MINOR))) { ADMW_LOG_ERROR("Configuration Version ID (0x%X) is not supported", pConfig->versionId); @@ -2659,7 +2450,7 @@ if (pConfig->productId != productId) { ADMW_LOG_ERROR("Configuration Product ID (0x%X) does not match device (0x%0X)", - pConfig->productId, productId); + pConfig->productId, productId); return ADMW_INVALID_PARAM; } @@ -2686,7 +2477,7 @@ return eRet; } - for (ADMW1001_CHANNEL_ID id = ADMW1001_CHANNEL_ID_ANALOG_1_UNIVERSAL; + for (ADMW1001_CH_ID id = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; id < ADMW1001_MAX_CHANNELS; id++) { @@ -2702,13 +2493,12 @@ return ADMW_SUCCESS; } - ADMW_RESULT admw1001_SetLutData( - ADMW_DEVICE_HANDLE const hDevice, + ADMW_DEVICE_HANDLE const hDevice, ADMW1001_LUT * const pLutData) { ADMW1001_LUT_HEADER *pLutHeader = &pLutData->header; - ADMW1001_LUT_TABLE *pLutTable = pLutData->tables; + ADMW1001_LUT_TABLE *pLutTable = pLutData->tables; unsigned actualLength = 0; if (pLutData->header.signature != ADMW_LUT_SIGNATURE)