Vybhav Kadaba
/
EV-PRO-MW1001_Development_code_cleanup2
Code clean up, removed unwanted enums and configurations
src/admw_1001.c@64:e8670e971e22, 2020-04-14 (annotated)
- Committer:
- Vkadaba
- Date:
- Tue Apr 14 07:04:24 2020 +0000
- Revision:
- 64:e8670e971e22
- Parent:
- 63:2655a04c00f5
- Child:
- 65:d91e1d63153d
code clean up - part 2; ADMW_api.h - removed admw_EraseExternalFlash, admw_GetExternalFlashSampleCount, admw_SetExternalFlashIndex, admw_GetExternalFlashData, admw_RunDiagnostics, admw_RunCalibration; admw_RunDigitalCalibration;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ADIJake | 0:85855ecd3257 | 1 | /* |
Vkadaba | 8:2f2775c34640 | 2 | Copyright 2019 (c) Analog Devices, Inc. |
ADIJake | 0:85855ecd3257 | 3 | |
ADIJake | 0:85855ecd3257 | 4 | All rights reserved. |
ADIJake | 0:85855ecd3257 | 5 | |
ADIJake | 0:85855ecd3257 | 6 | Redistribution and use in source and binary forms, with or without |
ADIJake | 0:85855ecd3257 | 7 | modification, are permitted provided that the following conditions are met: |
ADIJake | 0:85855ecd3257 | 8 | - Redistributions of source code must retain the above copyright |
ADIJake | 0:85855ecd3257 | 9 | notice, this list of conditions and the following disclaimer. |
ADIJake | 0:85855ecd3257 | 10 | - Redistributions in binary form must reproduce the above copyright |
ADIJake | 0:85855ecd3257 | 11 | notice, this list of conditions and the following disclaimer in |
ADIJake | 0:85855ecd3257 | 12 | the documentation and/or other materials provided with the |
ADIJake | 0:85855ecd3257 | 13 | distribution. |
ADIJake | 0:85855ecd3257 | 14 | - Neither the name of Analog Devices, Inc. nor the names of its |
ADIJake | 0:85855ecd3257 | 15 | contributors may be used to endorse or promote products derived |
ADIJake | 0:85855ecd3257 | 16 | from this software without specific prior written permission. |
ADIJake | 0:85855ecd3257 | 17 | - The use of this software may or may not infringe the patent rights |
ADIJake | 0:85855ecd3257 | 18 | of one or more patent holders. This license does not release you |
ADIJake | 0:85855ecd3257 | 19 | from the requirement that you obtain separate licenses from these |
ADIJake | 0:85855ecd3257 | 20 | patent holders to use this software. |
ADIJake | 0:85855ecd3257 | 21 | - Use of the software either in source or binary form, must be run |
ADIJake | 0:85855ecd3257 | 22 | on or directly connected to an Analog Devices Inc. component. |
ADIJake | 0:85855ecd3257 | 23 | |
ADIJake | 0:85855ecd3257 | 24 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
ADIJake | 0:85855ecd3257 | 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
ADIJake | 0:85855ecd3257 | 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
ADIJake | 0:85855ecd3257 | 27 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
ADIJake | 0:85855ecd3257 | 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
ADIJake | 0:85855ecd3257 | 29 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
ADIJake | 0:85855ecd3257 | 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ADIJake | 0:85855ecd3257 | 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ADIJake | 0:85855ecd3257 | 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ADIJake | 0:85855ecd3257 | 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ADIJake | 0:85855ecd3257 | 34 | */ |
ADIJake | 0:85855ecd3257 | 35 | |
ADIJake | 0:85855ecd3257 | 36 | /*! |
ADIJake | 0:85855ecd3257 | 37 | ****************************************************************************** |
ADIJake | 0:85855ecd3257 | 38 | * @file: |
Vkadaba | 8:2f2775c34640 | 39 | * @brief: API implementation for ADMW1001 |
ADIJake | 0:85855ecd3257 | 40 | *----------------------------------------------------------------------------- |
ADIJake | 0:85855ecd3257 | 41 | */ |
ADIJake | 0:85855ecd3257 | 42 | |
ADIJake | 0:85855ecd3257 | 43 | #include <float.h> |
ADIJake | 0:85855ecd3257 | 44 | #include <math.h> |
ADIJake | 0:85855ecd3257 | 45 | #include <string.h> |
ADIJake | 0:85855ecd3257 | 46 | |
Vkadaba | 5:0728bde67bdb | 47 | #include "admw_platform.h" |
Vkadaba | 5:0728bde67bdb | 48 | #include "admw_api.h" |
Vkadaba | 5:0728bde67bdb | 49 | #include "admw1001/admw1001_api.h" |
Vkadaba | 5:0728bde67bdb | 50 | |
Vkadaba | 5:0728bde67bdb | 51 | #include "admw1001/ADMW1001_REGISTERS_typedefs.h" |
Vkadaba | 5:0728bde67bdb | 52 | #include "admw1001/ADMW1001_REGISTERS.h" |
Vkadaba | 5:0728bde67bdb | 53 | #include "admw1001/admw1001_lut_data.h" |
Vkadaba | 5:0728bde67bdb | 54 | #include "admw1001/admw1001_host_comms.h" |
Vkadaba | 55:215da406282b | 55 | #include "inc/mbedVersion.h" |
Vkadaba | 13:97cb32670539 | 56 | #define VERSIONID_MAJOR 2 |
Vkadaba | 13:97cb32670539 | 57 | #define VERSIONID_MINOR 0 |
ADIJake | 0:85855ecd3257 | 58 | |
ADIJake | 0:85855ecd3257 | 59 | uint32_t getDataCnt = 0; |
Vkadaba | 32:52445bef314d | 60 | #define ADMW_VERSION_REG_VAL_SIZE 4u |
Vkadaba | 32:52445bef314d | 61 | #define ADMW_FORMATTED_VERSION_SIZE 11u |
ADIJake | 0:85855ecd3257 | 62 | |
Vkadaba | 32:52445bef314d | 63 | #define ADMW_SFL_READ_STATUS_SIZE 42u |
ADIJake | 0:85855ecd3257 | 64 | /* |
ADIJake | 0:85855ecd3257 | 65 | * The following macros are used to encapsulate the register access code |
ADIJake | 0:85855ecd3257 | 66 | * to improve readability in the functions further below in this file |
ADIJake | 0:85855ecd3257 | 67 | */ |
ADIJake | 0:85855ecd3257 | 68 | #define STRINGIFY(name) #name |
ADIJake | 0:85855ecd3257 | 69 | |
ADIJake | 0:85855ecd3257 | 70 | /* Expand the full name of the reset value macro for the specified register */ |
Vkadaba | 5:0728bde67bdb | 71 | #define REG_RESET_VAL(_name) REG_##_name##_RESET |
ADIJake | 0:85855ecd3257 | 72 | |
ADIJake | 0:85855ecd3257 | 73 | /* Checks if a value is outside the bounds of the specified register field */ |
ADIJake | 0:85855ecd3257 | 74 | #define CHECK_REG_FIELD_VAL(_field, _val) \ |
ADIJake | 0:85855ecd3257 | 75 | do { \ |
Vkadaba | 8:2f2775c34640 | 76 | uint32_t _mask = BITM_##_field; \ |
Vkadaba | 8:2f2775c34640 | 77 | uint32_t _shift = BITP_##_field; \ |
ADIJake | 0:85855ecd3257 | 78 | if ((((_val) << _shift) & ~(_mask)) != 0) { \ |
Vkadaba | 6:9d393a9677f4 | 79 | ADMW_LOG_ERROR("Value 0x%08X invalid for register field %s",\ |
ADIJake | 0:85855ecd3257 | 80 | (uint32_t)(_val), \ |
Vkadaba | 6:9d393a9677f4 | 81 | STRINGIFY(ADMW_##_field)); \ |
Vkadaba | 8:2f2775c34640 | 82 | return ADMW_INVALID_PARAM; \ |
ADIJake | 0:85855ecd3257 | 83 | } \ |
ADIJake | 0:85855ecd3257 | 84 | } while(false) |
ADIJake | 0:85855ecd3257 | 85 | |
ADIJake | 0:85855ecd3257 | 86 | /* |
ADIJake | 0:85855ecd3257 | 87 | * Encapsulates the write to a specified register |
ADIJake | 0:85855ecd3257 | 88 | * NOTE - this will cause the calling function to return on error |
ADIJake | 0:85855ecd3257 | 89 | */ |
ADIJake | 0:85855ecd3257 | 90 | #define WRITE_REG(_hdev, _val, _name, _type) \ |
ADIJake | 0:85855ecd3257 | 91 | do { \ |
Vkadaba | 8:2f2775c34640 | 92 | ADMW_RESULT _res; \ |
ADIJake | 0:85855ecd3257 | 93 | _type _regval = _val; \ |
Vkadaba | 8:2f2775c34640 | 94 | _res = admw1001_WriteRegister((_hdev), \ |
Vkadaba | 8:2f2775c34640 | 95 | REG_##_name, \ |
ADIJake | 0:85855ecd3257 | 96 | &_regval, sizeof(_regval)); \ |
Vkadaba | 8:2f2775c34640 | 97 | if (_res != ADMW_SUCCESS) \ |
ADIJake | 0:85855ecd3257 | 98 | return _res; \ |
ADIJake | 0:85855ecd3257 | 99 | } while(false) |
ADIJake | 0:85855ecd3257 | 100 | |
ADIJake | 0:85855ecd3257 | 101 | /* Wrapper macro to write a value to a uint32_t register */ |
Vkadaba | 8:2f2775c34640 | 102 | #define WRITE_REG_U32(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 103 | WRITE_REG(_hdev, _val, _name, uint32_t) |
ADIJake | 0:85855ecd3257 | 104 | /* Wrapper macro to write a value to a uint16_t register */ |
Vkadaba | 8:2f2775c34640 | 105 | #define WRITE_REG_U16(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 106 | WRITE_REG(_hdev, _val, _name, uint16_t) |
ADIJake | 0:85855ecd3257 | 107 | /* Wrapper macro to write a value to a uint8_t register */ |
Vkadaba | 8:2f2775c34640 | 108 | #define WRITE_REG_U8(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 109 | WRITE_REG(_hdev, _val, _name, uint8_t) |
ADIJake | 0:85855ecd3257 | 110 | /* Wrapper macro to write a value to a float32_t register */ |
Vkadaba | 8:2f2775c34640 | 111 | #define WRITE_REG_FLOAT(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 112 | WRITE_REG(_hdev, _val, _name, float32_t) |
ADIJake | 0:85855ecd3257 | 113 | |
ADIJake | 0:85855ecd3257 | 114 | /* |
ADIJake | 0:85855ecd3257 | 115 | * Encapsulates the read from a specified register |
ADIJake | 0:85855ecd3257 | 116 | * NOTE - this will cause the calling function to return on error |
ADIJake | 0:85855ecd3257 | 117 | */ |
ADIJake | 0:85855ecd3257 | 118 | #define READ_REG(_hdev, _val, _name, _type) \ |
ADIJake | 0:85855ecd3257 | 119 | do { \ |
Vkadaba | 8:2f2775c34640 | 120 | ADMW_RESULT _res; \ |
ADIJake | 0:85855ecd3257 | 121 | _type _regval; \ |
Vkadaba | 8:2f2775c34640 | 122 | _res = admw1001_ReadRegister((_hdev), \ |
Vkadaba | 8:2f2775c34640 | 123 | REG_##_name, \ |
ADIJake | 0:85855ecd3257 | 124 | &_regval, sizeof(_regval)); \ |
Vkadaba | 8:2f2775c34640 | 125 | if (_res != ADMW_SUCCESS) \ |
ADIJake | 0:85855ecd3257 | 126 | return _res; \ |
ADIJake | 0:85855ecd3257 | 127 | _val = _regval; \ |
ADIJake | 0:85855ecd3257 | 128 | } while(false) |
ADIJake | 0:85855ecd3257 | 129 | |
ADIJake | 0:85855ecd3257 | 130 | /* Wrapper macro to read a value from a uint32_t register */ |
Vkadaba | 8:2f2775c34640 | 131 | #define READ_REG_U32(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 132 | READ_REG(_hdev, _val, _name, uint32_t) |
ADIJake | 0:85855ecd3257 | 133 | /* Wrapper macro to read a value from a uint16_t register */ |
Vkadaba | 8:2f2775c34640 | 134 | #define READ_REG_U16(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 135 | READ_REG(_hdev, _val, _name, uint16_t) |
ADIJake | 0:85855ecd3257 | 136 | /* Wrapper macro to read a value from a uint8_t register */ |
Vkadaba | 8:2f2775c34640 | 137 | #define READ_REG_U8(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 138 | READ_REG(_hdev, _val, _name, uint8_t) |
ADIJake | 0:85855ecd3257 | 139 | /* Wrapper macro to read a value from a float32_t register */ |
Vkadaba | 8:2f2775c34640 | 140 | #define READ_REG_FLOAT(_hdev, _val, _name) \ |
ADIJake | 0:85855ecd3257 | 141 | READ_REG(_hdev, _val, _name, float32_t) |
ADIJake | 0:85855ecd3257 | 142 | |
ADIJake | 0:85855ecd3257 | 143 | /* |
ADIJake | 0:85855ecd3257 | 144 | * Wrapper macro to write an array of values to a uint8_t register |
ADIJake | 0:85855ecd3257 | 145 | * NOTE - this is intended only for writing to a keyhole data register |
ADIJake | 0:85855ecd3257 | 146 | */ |
Vkadaba | 8:2f2775c34640 | 147 | #define WRITE_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ |
Vkadaba | 6:9d393a9677f4 | 148 | do { \ |
Vkadaba | 8:2f2775c34640 | 149 | ADMW_RESULT _res; \ |
Vkadaba | 8:2f2775c34640 | 150 | _res = admw1001_WriteRegister(_hdev, \ |
Vkadaba | 8:2f2775c34640 | 151 | REG_##_name, \ |
Vkadaba | 6:9d393a9677f4 | 152 | _arr, _len); \ |
Vkadaba | 8:2f2775c34640 | 153 | if (_res != ADMW_SUCCESS) \ |
Vkadaba | 6:9d393a9677f4 | 154 | return _res; \ |
ADIJake | 0:85855ecd3257 | 155 | } while(false) |
ADIJake | 0:85855ecd3257 | 156 | |
ADIJake | 0:85855ecd3257 | 157 | /* |
ADIJake | 0:85855ecd3257 | 158 | * Wrapper macro to read an array of values from a uint8_t register |
ADIJake | 0:85855ecd3257 | 159 | * NOTE - this is intended only for reading from a keyhole data register |
ADIJake | 0:85855ecd3257 | 160 | */ |
Vkadaba | 6:9d393a9677f4 | 161 | #define READ_REG_U8_ARRAY(_hdev, _arr, _len, _name) \ |
Vkadaba | 6:9d393a9677f4 | 162 | do { \ |
Vkadaba | 8:2f2775c34640 | 163 | ADMW_RESULT _res; \ |
Vkadaba | 8:2f2775c34640 | 164 | _res = admw1001_ReadRegister((_hdev), \ |
Vkadaba | 8:2f2775c34640 | 165 | REG##_name, \ |
Vkadaba | 6:9d393a9677f4 | 166 | _arr, _len); \ |
Vkadaba | 8:2f2775c34640 | 167 | if (_res != ADMW_SUCCESS) \ |
Vkadaba | 6:9d393a9677f4 | 168 | return _res; \ |
ADIJake | 0:85855ecd3257 | 169 | } while(false) |
ADIJake | 0:85855ecd3257 | 170 | |
Vkadaba | 8:2f2775c34640 | 171 | #define ADMW1001_CHANNEL_IS_ADC(c) \ |
Vkadaba | 8:2f2775c34640 | 172 | ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL) |
Vkadaba | 6:9d393a9677f4 | 173 | |
Vkadaba | 8:2f2775c34640 | 174 | #define ADMW1001_CHANNEL_IS_ADC_CJC(c) \ |
Vkadaba | 8:2f2775c34640 | 175 | ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 176 | |
Vkadaba | 8:2f2775c34640 | 177 | #define ADMW1001_CHANNEL_IS_ADC_SENSOR(c) \ |
Vkadaba | 8:2f2775c34640 | 178 | ((c) >= ADMW1001_CH_ID_ANLG_1_UNIVERSAL && (c) <= ADMW1001_CH_ID_ANLG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 179 | |
Vkadaba | 8:2f2775c34640 | 180 | #define ADMW1001_CHANNEL_IS_ADC_VOLTAGE(c) \ |
Vkadaba | 8:2f2775c34640 | 181 | ((c) == ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL || ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL) |
Vkadaba | 6:9d393a9677f4 | 182 | |
Vkadaba | 8:2f2775c34640 | 183 | #define ADMW1001_CHANNEL_IS_ADC_CURRENT(c) \ |
Vkadaba | 8:2f2775c34640 | 184 | ((c) == ADMW1001_CH_ID_ANLG_1_UNIVERSAL || (c) == ADMW1001_CH_ID_ANLG_2_UNIVERSAL) |
Vkadaba | 6:9d393a9677f4 | 185 | |
ADIJake | 0:85855ecd3257 | 186 | |
Vkadaba | 32:52445bef314d | 187 | //typedef struct { |
Vkadaba | 32:52445bef314d | 188 | // unsigned nDeviceIndex; |
Vkadaba | 32:52445bef314d | 189 | // ADMW_SPI_HANDLE hSpi; |
Vkadaba | 32:52445bef314d | 190 | // ADMW_GPIO_HANDLE hGpio; |
Vkadaba | 32:52445bef314d | 191 | // |
Vkadaba | 32:52445bef314d | 192 | //} ADMW_DEVICE_CONTEXT; |
Vkadaba | 5:0728bde67bdb | 193 | |
Vkadaba | 5:0728bde67bdb | 194 | static ADMW_DEVICE_CONTEXT gDeviceCtx[ADMW_PLATFORM_MAX_DEVICES]; |
ADIJake | 0:85855ecd3257 | 195 | |
ADIJake | 0:85855ecd3257 | 196 | /* |
Vkadaba | 5:0728bde67bdb | 197 | * Open an ADMW device instance. |
ADIJake | 0:85855ecd3257 | 198 | */ |
Vkadaba | 5:0728bde67bdb | 199 | ADMW_RESULT admw_Open( |
Vkadaba | 8:2f2775c34640 | 200 | unsigned const nDeviceIndex, |
Vkadaba | 5:0728bde67bdb | 201 | ADMW_CONNECTION * const pConnectionInfo, |
Vkadaba | 5:0728bde67bdb | 202 | ADMW_DEVICE_HANDLE * const phDevice) |
ADIJake | 0:85855ecd3257 | 203 | { |
Vkadaba | 5:0728bde67bdb | 204 | ADMW_DEVICE_CONTEXT *pCtx; |
Vkadaba | 5:0728bde67bdb | 205 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 206 | |
Vkadaba | 5:0728bde67bdb | 207 | if (nDeviceIndex >= ADMW_PLATFORM_MAX_DEVICES) |
Vkadaba | 5:0728bde67bdb | 208 | return ADMW_INVALID_DEVICE_NUM; |
ADIJake | 0:85855ecd3257 | 209 | |
ADIJake | 0:85855ecd3257 | 210 | pCtx = &gDeviceCtx[nDeviceIndex]; |
ADIJake | 0:85855ecd3257 | 211 | pCtx->nDeviceIndex = nDeviceIndex; |
ADIJake | 0:85855ecd3257 | 212 | |
Vkadaba | 5:0728bde67bdb | 213 | eRet = admw_LogOpen(&pConnectionInfo->log); |
Vkadaba | 5:0728bde67bdb | 214 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 215 | return eRet; |
ADIJake | 0:85855ecd3257 | 216 | |
Vkadaba | 5:0728bde67bdb | 217 | eRet = admw_GpioOpen(&pConnectionInfo->gpio, &pCtx->hGpio); |
Vkadaba | 5:0728bde67bdb | 218 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 219 | return eRet; |
ADIJake | 0:85855ecd3257 | 220 | |
Vkadaba | 5:0728bde67bdb | 221 | eRet = admw_SpiOpen(&pConnectionInfo->spi, &pCtx->hSpi); |
Vkadaba | 5:0728bde67bdb | 222 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 223 | return eRet; |
ADIJake | 0:85855ecd3257 | 224 | |
ADIJake | 0:85855ecd3257 | 225 | *phDevice = pCtx; |
Vkadaba | 5:0728bde67bdb | 226 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 227 | } |
ADIJake | 0:85855ecd3257 | 228 | |
ADIJake | 0:85855ecd3257 | 229 | /* |
ADIJake | 0:85855ecd3257 | 230 | * Get the current state of the specified GPIO input signal. |
ADIJake | 0:85855ecd3257 | 231 | */ |
Vkadaba | 5:0728bde67bdb | 232 | ADMW_RESULT admw_GetGpioState( |
Vkadaba | 5:0728bde67bdb | 233 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 234 | ADMW_GPIO_PIN const ePinId, |
ADIJake | 0:85855ecd3257 | 235 | bool * const pbAsserted) |
ADIJake | 0:85855ecd3257 | 236 | { |
Vkadaba | 5:0728bde67bdb | 237 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 238 | |
Vkadaba | 5:0728bde67bdb | 239 | return admw_GpioGet(pCtx->hGpio, ePinId, pbAsserted); |
ADIJake | 0:85855ecd3257 | 240 | } |
ADIJake | 0:85855ecd3257 | 241 | |
ADIJake | 0:85855ecd3257 | 242 | /* |
ADIJake | 0:85855ecd3257 | 243 | * Register an application-defined callback function for GPIO interrupts. |
ADIJake | 0:85855ecd3257 | 244 | */ |
Vkadaba | 5:0728bde67bdb | 245 | ADMW_RESULT admw_RegisterGpioCallback( |
Vkadaba | 5:0728bde67bdb | 246 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 247 | ADMW_GPIO_PIN const ePinId, |
Vkadaba | 5:0728bde67bdb | 248 | ADMW_GPIO_CALLBACK const callbackFunction, |
ADIJake | 0:85855ecd3257 | 249 | void * const pCallbackParam) |
ADIJake | 0:85855ecd3257 | 250 | { |
Vkadaba | 5:0728bde67bdb | 251 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
ADIJake | 0:85855ecd3257 | 252 | |
Vkadaba | 23:bb685f35b08b | 253 | if (callbackFunction) { |
Vkadaba | 5:0728bde67bdb | 254 | return admw_GpioIrqEnable(pCtx->hGpio, ePinId, callbackFunction, |
Vkadaba | 23:bb685f35b08b | 255 | pCallbackParam); |
Vkadaba | 23:bb685f35b08b | 256 | } else { |
Vkadaba | 5:0728bde67bdb | 257 | return admw_GpioIrqDisable(pCtx->hGpio, ePinId); |
ADIJake | 0:85855ecd3257 | 258 | } |
ADIJake | 0:85855ecd3257 | 259 | } |
ADIJake | 0:85855ecd3257 | 260 | |
Vkadaba | 8:2f2775c34640 | 261 | /*! |
Vkadaba | 8:2f2775c34640 | 262 | * @brief Reset the specified ADMW device. |
Vkadaba | 8:2f2775c34640 | 263 | * |
Vkadaba | 8:2f2775c34640 | 264 | * @param[in] hDevice - handle of ADMW device to reset. |
Vkadaba | 8:2f2775c34640 | 265 | * |
Vkadaba | 8:2f2775c34640 | 266 | * @return Status |
Vkadaba | 8:2f2775c34640 | 267 | * - #ADMW_SUCCESS Call completed successfully. |
Vkadaba | 8:2f2775c34640 | 268 | * - #ADMW_FAILURE If reseet faisl |
Vkadaba | 8:2f2775c34640 | 269 | * |
Vkadaba | 23:bb685f35b08b | 270 | * @details Toggle reset pin of the ADMW device low for a |
Vkadaba | 8:2f2775c34640 | 271 | * minimum of 4 usec. |
Vkadaba | 8:2f2775c34640 | 272 | * |
ADIJake | 0:85855ecd3257 | 273 | */ |
Vkadaba | 8:2f2775c34640 | 274 | ADMW_RESULT admw_Reset(ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 275 | { |
Vkadaba | 5:0728bde67bdb | 276 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 277 | ADMW_RESULT eRet; |
ADIJake | 0:85855ecd3257 | 278 | |
ADIJake | 0:85855ecd3257 | 279 | /* Pulse the Reset GPIO pin low for a minimum of 4 microseconds */ |
Vkadaba | 5:0728bde67bdb | 280 | eRet = admw_GpioSet(pCtx->hGpio, ADMW_GPIO_PIN_RESET, false); |
Vkadaba | 5:0728bde67bdb | 281 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 282 | return eRet; |
ADIJake | 0:85855ecd3257 | 283 | |
Vkadaba | 5:0728bde67bdb | 284 | admw_TimeDelayUsec(4); |
Vkadaba | 5:0728bde67bdb | 285 | |
Vkadaba | 5:0728bde67bdb | 286 | eRet = admw_GpioSet(pCtx->hGpio, ADMW_GPIO_PIN_RESET, true); |
Vkadaba | 5:0728bde67bdb | 287 | if (eRet != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 288 | return eRet; |
ADIJake | 0:85855ecd3257 | 289 | |
Vkadaba | 5:0728bde67bdb | 290 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 291 | } |
ADIJake | 0:85855ecd3257 | 292 | |
ADIJake | 0:85855ecd3257 | 293 | /*! |
Vkadaba | 8:2f2775c34640 | 294 | * @brief Get general status of ADMW module. |
ADIJake | 0:85855ecd3257 | 295 | * |
ADIJake | 0:85855ecd3257 | 296 | * @param[in] |
ADIJake | 0:85855ecd3257 | 297 | * @param[out] pStatus : Pointer to CORE Status struct. |
ADIJake | 0:85855ecd3257 | 298 | * |
ADIJake | 0:85855ecd3257 | 299 | * @return Status |
Vkadaba | 5:0728bde67bdb | 300 | * - #ADMW_SUCCESS Call completed successfully. |
Vkadaba | 5:0728bde67bdb | 301 | * - #ADMW_FAILURE If status register read fails. |
ADIJake | 0:85855ecd3257 | 302 | * |
Vkadaba | 8:2f2775c34640 | 303 | * @details Read the general status register for the ADMW |
ADIJake | 0:85855ecd3257 | 304 | * module. Indicates Error, Alert conditions, data ready |
ADIJake | 0:85855ecd3257 | 305 | * and command running. |
ADIJake | 0:85855ecd3257 | 306 | * |
ADIJake | 0:85855ecd3257 | 307 | */ |
Vkadaba | 5:0728bde67bdb | 308 | ADMW_RESULT admw_GetStatus( |
Vkadaba | 5:0728bde67bdb | 309 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 310 | ADMW_STATUS * const pStatus) |
ADIJake | 0:85855ecd3257 | 311 | { |
Vkadaba | 8:2f2775c34640 | 312 | ADMW_CORE_Status_t statusReg; |
ADIJake | 0:85855ecd3257 | 313 | READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); |
ADIJake | 0:85855ecd3257 | 314 | |
ADIJake | 0:85855ecd3257 | 315 | memset(pStatus, 0, sizeof(*pStatus)); |
ADIJake | 0:85855ecd3257 | 316 | |
ADIJake | 0:85855ecd3257 | 317 | if (!statusReg.Cmd_Running) /* Active-low, so invert it */ |
Vkadaba | 5:0728bde67bdb | 318 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_BUSY; |
ADIJake | 0:85855ecd3257 | 319 | if (statusReg.Drdy) |
Vkadaba | 5:0728bde67bdb | 320 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_DATAREADY; |
ADIJake | 0:85855ecd3257 | 321 | if (statusReg.FIFO_Error) |
Vkadaba | 5:0728bde67bdb | 322 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_FIFO_ERROR; |
Vkadaba | 23:bb685f35b08b | 323 | if (statusReg.Alert_Active) { |
Vkadaba | 5:0728bde67bdb | 324 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ALERT; |
Vkadaba | 5:0728bde67bdb | 325 | |
Vkadaba | 8:2f2775c34640 | 326 | ADMW_CORE_Channel_Alert_Status_t channelAlertStatusReg; |
ADIJake | 0:85855ecd3257 | 327 | READ_REG_U16(hDevice, channelAlertStatusReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 328 | CORE_CHANNEL_ALERT_STATUS); |
ADIJake | 0:85855ecd3257 | 329 | |
Vkadaba | 23:bb685f35b08b | 330 | for (unsigned i = 0; i < ADMW1001_MAX_CHANNELS; i++) { |
Vkadaba | 23:bb685f35b08b | 331 | if (channelAlertStatusReg.VALUE16 & (1 << i)) { |
Vkadaba | 8:2f2775c34640 | 332 | ADMW_CORE_Alert_Detail_Ch_t alertDetailReg; |
ADIJake | 0:85855ecd3257 | 333 | READ_REG_U16(hDevice, alertDetailReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 334 | CORE_ALERT_DETAIL_CHn(i)); |
ADIJake | 0:85855ecd3257 | 335 | |
Vkadaba | 32:52445bef314d | 336 | if (alertDetailReg.ADC_Near_Overrange) |
Vkadaba | 32:52445bef314d | 337 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_ADC_NEAR_OVERRANGE; |
Vkadaba | 32:52445bef314d | 338 | if (alertDetailReg.Sensor_UnderRange) |
Vkadaba | 32:52445bef314d | 339 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_UNDERRANGE; |
Vkadaba | 32:52445bef314d | 340 | if (alertDetailReg.Sensor_OverRange) |
Vkadaba | 32:52445bef314d | 341 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_OVERRANGE ; |
Vkadaba | 32:52445bef314d | 342 | if (alertDetailReg.CJ_Soft_Fault) |
Vkadaba | 32:52445bef314d | 343 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_CJ_SOFT_FAULT ; |
Vkadaba | 32:52445bef314d | 344 | if (alertDetailReg.CJ_Hard_Fault) |
Vkadaba | 32:52445bef314d | 345 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_CJ_HARD_FAULT; |
Vkadaba | 32:52445bef314d | 346 | if (alertDetailReg.ADC_Input_OverRange) |
Vkadaba | 32:52445bef314d | 347 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_ADC_INPUT_OVERRANGE ; |
Vkadaba | 32:52445bef314d | 348 | if (alertDetailReg.Sensor_HardFault) |
Vkadaba | 32:52445bef314d | 349 | pStatus->channelAlerts[i] |= ADMW_ALERT_DETAIL_CH_SENSOR_HARDFAULT; |
Vkadaba | 32:52445bef314d | 350 | |
ADIJake | 0:85855ecd3257 | 351 | } |
ADIJake | 0:85855ecd3257 | 352 | } |
ADIJake | 0:85855ecd3257 | 353 | |
Vkadaba | 32:52445bef314d | 354 | if (statusReg.Configuration_Error) |
Vkadaba | 5:0728bde67bdb | 355 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_CONFIG_ERROR; |
Vkadaba | 32:52445bef314d | 356 | if (statusReg.LUT_Error) |
Vkadaba | 5:0728bde67bdb | 357 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_LUT_ERROR; |
ADIJake | 0:85855ecd3257 | 358 | } |
ADIJake | 0:85855ecd3257 | 359 | |
Vkadaba | 23:bb685f35b08b | 360 | if (statusReg.Error) { |
Vkadaba | 5:0728bde67bdb | 361 | pStatus->deviceStatus |= ADMW_DEVICE_STATUS_ERROR; |
Vkadaba | 5:0728bde67bdb | 362 | |
Vkadaba | 8:2f2775c34640 | 363 | ADMW_CORE_Error_Code_t errorCodeReg; |
ADIJake | 0:85855ecd3257 | 364 | READ_REG_U16(hDevice, errorCodeReg.VALUE16, CORE_ERROR_CODE); |
ADIJake | 0:85855ecd3257 | 365 | pStatus->errorCode = errorCodeReg.Error_Code; |
ADIJake | 0:85855ecd3257 | 366 | |
ADIJake | 0:85855ecd3257 | 367 | } |
Vkadaba | 5:0728bde67bdb | 368 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 369 | } |
ADIJake | 0:85855ecd3257 | 370 | |
Vkadaba | 5:0728bde67bdb | 371 | ADMW_RESULT admw_GetCommandRunningState( |
Vkadaba | 5:0728bde67bdb | 372 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 373 | bool *pbCommandRunning) |
ADIJake | 0:85855ecd3257 | 374 | { |
Vkadaba | 8:2f2775c34640 | 375 | ADMW_CORE_Status_t statusReg; |
ADIJake | 0:85855ecd3257 | 376 | |
ADIJake | 0:85855ecd3257 | 377 | READ_REG_U8(hDevice, statusReg.VALUE8, CORE_STATUS); |
ADIJake | 0:85855ecd3257 | 378 | |
ADIJake | 0:85855ecd3257 | 379 | /* We should never normally see 0xFF here if the module is operational */ |
ADIJake | 0:85855ecd3257 | 380 | if (statusReg.VALUE8 == 0xFF) |
Vkadaba | 5:0728bde67bdb | 381 | return ADMW_ERR_NOT_INITIALIZED; |
ADIJake | 0:85855ecd3257 | 382 | |
ADIJake | 0:85855ecd3257 | 383 | *pbCommandRunning = !statusReg.Cmd_Running; /* Active-low, so invert it */ |
ADIJake | 0:85855ecd3257 | 384 | |
Vkadaba | 5:0728bde67bdb | 385 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 386 | } |
ADIJake | 0:85855ecd3257 | 387 | |
Vkadaba | 50:d84305e5e1c0 | 388 | ADMW_RESULT admw_deviceInformation(ADMW_DEVICE_HANDLE hDevice) |
Vkadaba | 32:52445bef314d | 389 | { |
Vkadaba | 32:52445bef314d | 390 | uint16_t nAddress = REG_CORE_REVISION; |
Vkadaba | 32:52445bef314d | 391 | char nData[ADMW_VERSION_REG_VAL_SIZE]; //4 Bytes of version register data |
Vkadaba | 32:52445bef314d | 392 | ADMW_RESULT res; |
Vkadaba | 32:52445bef314d | 393 | res=admw1001_ReadRegister(hDevice,nAddress,nData,sizeof(nData)); |
Vkadaba | 32:52445bef314d | 394 | if(res != ADMW_SUCCESS) { |
Vkadaba | 32:52445bef314d | 395 | //if reading version register failed, sending 00.00.0000 as ADMW1001 firmware version |
Vkadaba | 32:52445bef314d | 396 | //strcat(nData, ADMW1001_FIRMWARE_VERSION_DEFAULT); |
Vkadaba | 32:52445bef314d | 397 | ADMW_LOG_INFO("Firmware Version Id is %X.%X",nData[2],nData[0]); |
Vkadaba | 32:52445bef314d | 398 | } else { |
Vkadaba | 32:52445bef314d | 399 | char buffer[ADMW_FORMATTED_VERSION_SIZE]; //00.00.0000 8 digits + 2 Bytes "." + one null character at the end |
Vkadaba | 32:52445bef314d | 400 | strcat(nData, buffer); |
Vkadaba | 42:c9c5a22e539e | 401 | ADMW_LOG_INFO("Firmware Version Id is %X.%X.%X",nData[3],nData[2],nData[0]); |
Vkadaba | 32:52445bef314d | 402 | } |
Vkadaba | 32:52445bef314d | 403 | return ADMW_SUCCESS; |
Vkadaba | 32:52445bef314d | 404 | } |
Vkadaba | 55:215da406282b | 405 | |
Vkadaba | 5:0728bde67bdb | 406 | static ADMW_RESULT executeCommand( |
Vkadaba | 5:0728bde67bdb | 407 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 8:2f2775c34640 | 408 | ADMW_CORE_Command_Special_Command const command, |
ADIJake | 0:85855ecd3257 | 409 | bool const bWaitForCompletion) |
ADIJake | 0:85855ecd3257 | 410 | { |
Vkadaba | 8:2f2775c34640 | 411 | ADMW_CORE_Command_t commandReg; |
ADIJake | 0:85855ecd3257 | 412 | bool bCommandRunning; |
Vkadaba | 5:0728bde67bdb | 413 | ADMW_RESULT eRet; |
ADIJake | 0:85855ecd3257 | 414 | |
ADIJake | 0:85855ecd3257 | 415 | /* |
ADIJake | 0:85855ecd3257 | 416 | * Don't allow another command to be issued if one is already running, but |
Vkadaba | 6:9d393a9677f4 | 417 | * make an exception for ENUM_CORE_COMMAND_NOP which can be used to |
ADIJake | 0:85855ecd3257 | 418 | * request a running command to be stopped (e.g. continuous measurement) |
ADIJake | 0:85855ecd3257 | 419 | */ |
Vkadaba | 23:bb685f35b08b | 420 | if (command != ENUM_CORE_COMMAND_NOP) { |
Vkadaba | 5:0728bde67bdb | 421 | eRet = admw_GetCommandRunningState(hDevice, &bCommandRunning); |
ADIJake | 0:85855ecd3257 | 422 | if (eRet) |
ADIJake | 0:85855ecd3257 | 423 | return eRet; |
ADIJake | 0:85855ecd3257 | 424 | |
ADIJake | 0:85855ecd3257 | 425 | if (bCommandRunning) |
Vkadaba | 5:0728bde67bdb | 426 | return ADMW_IN_USE; |
ADIJake | 0:85855ecd3257 | 427 | } |
ADIJake | 0:85855ecd3257 | 428 | |
ADIJake | 0:85855ecd3257 | 429 | commandReg.Special_Command = command; |
ADIJake | 0:85855ecd3257 | 430 | WRITE_REG_U8(hDevice, commandReg.VALUE8, CORE_COMMAND); |
ADIJake | 0:85855ecd3257 | 431 | |
Vkadaba | 23:bb685f35b08b | 432 | if (bWaitForCompletion) { |
ADIJake | 0:85855ecd3257 | 433 | do { |
Vkadaba | 50:d84305e5e1c0 | 434 | /* Allow a minimum 100usec delay for status update before checking */ |
Vkadaba | 50:d84305e5e1c0 | 435 | admw_TimeDelayUsec(100); |
Vkadaba | 5:0728bde67bdb | 436 | |
Vkadaba | 5:0728bde67bdb | 437 | eRet = admw_GetCommandRunningState(hDevice, &bCommandRunning); |
ADIJake | 0:85855ecd3257 | 438 | if (eRet) |
ADIJake | 0:85855ecd3257 | 439 | return eRet; |
ADIJake | 0:85855ecd3257 | 440 | } while (bCommandRunning); |
ADIJake | 0:85855ecd3257 | 441 | } |
ADIJake | 0:85855ecd3257 | 442 | |
Vkadaba | 5:0728bde67bdb | 443 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 444 | } |
ADIJake | 0:85855ecd3257 | 445 | |
Vkadaba | 5:0728bde67bdb | 446 | ADMW_RESULT admw_ApplyConfigUpdates( |
Vkadaba | 5:0728bde67bdb | 447 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 448 | { |
Vkadaba | 5:0728bde67bdb | 449 | return executeCommand(hDevice, CORE_COMMAND_LATCH_CONFIG, true); |
ADIJake | 0:85855ecd3257 | 450 | } |
ADIJake | 0:85855ecd3257 | 451 | |
ADIJake | 0:85855ecd3257 | 452 | /*! |
ADIJake | 0:85855ecd3257 | 453 | * @brief Start a measurement cycle. |
ADIJake | 0:85855ecd3257 | 454 | * |
ADIJake | 0:85855ecd3257 | 455 | * @param[out] |
ADIJake | 0:85855ecd3257 | 456 | * |
ADIJake | 0:85855ecd3257 | 457 | * @return Status |
Vkadaba | 5:0728bde67bdb | 458 | * - #ADMW_SUCCESS Call completed successfully. |
Vkadaba | 5:0728bde67bdb | 459 | * - #ADMW_FAILURE |
ADIJake | 0:85855ecd3257 | 460 | * |
ADIJake | 0:85855ecd3257 | 461 | * @details Sends the latch config command. Configuration for channels in |
ADIJake | 0:85855ecd3257 | 462 | * conversion cycle should be completed before this function. |
ADIJake | 0:85855ecd3257 | 463 | * Channel enabled bit should be set before this function. |
ADIJake | 0:85855ecd3257 | 464 | * Starts a conversion and configures the format of the sample. |
ADIJake | 0:85855ecd3257 | 465 | * |
ADIJake | 0:85855ecd3257 | 466 | */ |
Vkadaba | 5:0728bde67bdb | 467 | ADMW_RESULT admw_StartMeasurement( |
Vkadaba | 5:0728bde67bdb | 468 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 469 | ADMW_MEASUREMENT_MODE const eMeasurementMode) |
ADIJake | 0:85855ecd3257 | 470 | { |
Vkadaba | 23:bb685f35b08b | 471 | switch (eMeasurementMode) { |
Vkadaba | 23:bb685f35b08b | 472 | case ADMW_MEASUREMENT_MODE_NORMAL: |
Vkadaba | 23:bb685f35b08b | 473 | return executeCommand(hDevice, CORE_COMMAND_CONVERT_WITH_RAW, false); |
Vkadaba | 23:bb685f35b08b | 474 | case ADMW_MEASUREMENT_MODE_OMIT_RAW: |
Vkadaba | 23:bb685f35b08b | 475 | return executeCommand(hDevice, CORE_COMMAND_CONVERT, false); |
Vkadaba | 23:bb685f35b08b | 476 | default: |
Vkadaba | 23:bb685f35b08b | 477 | ADMW_LOG_ERROR("Invalid measurement mode %d specified", |
Vkadaba | 23:bb685f35b08b | 478 | eMeasurementMode); |
Vkadaba | 23:bb685f35b08b | 479 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 480 | } |
ADIJake | 0:85855ecd3257 | 481 | } |
ADIJake | 0:85855ecd3257 | 482 | |
ADIJake | 0:85855ecd3257 | 483 | /* |
ADIJake | 0:85855ecd3257 | 484 | * Store the configuration settings to persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 485 | * The settings can be saved to 4 different flash memory areas (slots). |
ADIJake | 0:85855ecd3257 | 486 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 487 | * Do not power down the device while this command is running. |
ADIJake | 0:85855ecd3257 | 488 | */ |
Vkadaba | 5:0728bde67bdb | 489 | ADMW_RESULT admw_SaveConfig( |
Vkadaba | 5:0728bde67bdb | 490 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 491 | ADMW_USER_CONFIG_SLOT const eSlotId) |
ADIJake | 0:85855ecd3257 | 492 | { |
Vkadaba | 23:bb685f35b08b | 493 | switch (eSlotId) { |
Vkadaba | 5:0728bde67bdb | 494 | case ADMW_FLASH_CONFIG_1: |
Vkadaba | 5:0728bde67bdb | 495 | return executeCommand(hDevice, CORE_COMMAND_SAVE_CONFIG_1, true); |
ADIJake | 0:85855ecd3257 | 496 | default: |
Vkadaba | 5:0728bde67bdb | 497 | ADMW_LOG_ERROR("Invalid user config target slot %d specified", |
Vkadaba | 23:bb685f35b08b | 498 | eSlotId); |
Vkadaba | 5:0728bde67bdb | 499 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 500 | } |
ADIJake | 0:85855ecd3257 | 501 | } |
ADIJake | 0:85855ecd3257 | 502 | |
ADIJake | 0:85855ecd3257 | 503 | /* |
ADIJake | 0:85855ecd3257 | 504 | * Restore the configuration settings from persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 505 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 506 | */ |
Vkadaba | 5:0728bde67bdb | 507 | ADMW_RESULT admw_RestoreConfig( |
Vkadaba | 5:0728bde67bdb | 508 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 509 | ADMW_USER_CONFIG_SLOT const eSlotId) |
ADIJake | 0:85855ecd3257 | 510 | { |
Vkadaba | 23:bb685f35b08b | 511 | switch (eSlotId) { |
Vkadaba | 5:0728bde67bdb | 512 | case ADMW_FLASH_CONFIG_1: |
Vkadaba | 5:0728bde67bdb | 513 | return executeCommand(hDevice, CORE_COMMAND_LOAD_CONFIG_1, true); |
ADIJake | 0:85855ecd3257 | 514 | default: |
Vkadaba | 5:0728bde67bdb | 515 | ADMW_LOG_ERROR("Invalid user config source slot %d specified", |
Vkadaba | 23:bb685f35b08b | 516 | eSlotId); |
Vkadaba | 5:0728bde67bdb | 517 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 518 | } |
ADIJake | 0:85855ecd3257 | 519 | } |
ADIJake | 0:85855ecd3257 | 520 | |
ADIJake | 0:85855ecd3257 | 521 | /* |
ADIJake | 0:85855ecd3257 | 522 | * Store the LUT data to persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 523 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 524 | * Do not power down the device while this command is running. |
ADIJake | 0:85855ecd3257 | 525 | */ |
Vkadaba | 5:0728bde67bdb | 526 | ADMW_RESULT admw_SaveLutData( |
Vkadaba | 5:0728bde67bdb | 527 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 528 | { |
Vkadaba | 5:0728bde67bdb | 529 | return executeCommand(hDevice, CORE_COMMAND_SAVE_LUT, true); |
ADIJake | 0:85855ecd3257 | 530 | } |
ADIJake | 0:85855ecd3257 | 531 | |
ADIJake | 0:85855ecd3257 | 532 | /* |
ADIJake | 0:85855ecd3257 | 533 | * Restore the LUT data from persistent memory on the device. |
ADIJake | 0:85855ecd3257 | 534 | * No other command must be running when this is called. |
ADIJake | 0:85855ecd3257 | 535 | */ |
Vkadaba | 5:0728bde67bdb | 536 | ADMW_RESULT admw_RestoreLutData( |
Vkadaba | 5:0728bde67bdb | 537 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 538 | { |
Vkadaba | 5:0728bde67bdb | 539 | return executeCommand(hDevice, CORE_COMMAND_LOAD_LUT, true); |
ADIJake | 0:85855ecd3257 | 540 | } |
ADIJake | 0:85855ecd3257 | 541 | |
ADIJake | 0:85855ecd3257 | 542 | /* |
ADIJake | 0:85855ecd3257 | 543 | * Stop the measurement cycles on the device. |
ADIJake | 0:85855ecd3257 | 544 | * To be used only if a measurement command is currently running. |
ADIJake | 0:85855ecd3257 | 545 | */ |
Vkadaba | 5:0728bde67bdb | 546 | ADMW_RESULT admw_StopMeasurement( |
Vkadaba | 5:0728bde67bdb | 547 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 548 | { |
Vkadaba | 5:0728bde67bdb | 549 | return executeCommand(hDevice, CORE_COMMAND_NOP, true); |
ADIJake | 0:85855ecd3257 | 550 | } |
ADIJake | 0:85855ecd3257 | 551 | |
ADIJake | 0:85855ecd3257 | 552 | /* |
Vkadaba | 32:52445bef314d | 553 | * |
Vkadaba | 32:52445bef314d | 554 | */ |
Vkadaba | 32:52445bef314d | 555 | ADMW_RESULT admw1001_sendRun( ADMW_DEVICE_HANDLE const hDevice) |
Vkadaba | 32:52445bef314d | 556 | { |
Vkadaba | 32:52445bef314d | 557 | bool bitCommand; |
Vkadaba | 32:52445bef314d | 558 | ADMW_RESULT eRet; |
Vkadaba | 32:52445bef314d | 559 | uint8_t pinreg = 0x1; |
Vkadaba | 32:52445bef314d | 560 | |
Vkadaba | 32:52445bef314d | 561 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 32:52445bef314d | 562 | static uint8_t DataBuffer[SPI_BUFFER_SIZE] = {0}; |
Vkadaba | 32:52445bef314d | 563 | uint16_t nSize; |
Vkadaba | 32:52445bef314d | 564 | |
Vkadaba | 32:52445bef314d | 565 | //Construct Read Status command |
Vkadaba | 32:52445bef314d | 566 | DataBuffer[0] = 0x07; |
Vkadaba | 32:52445bef314d | 567 | DataBuffer[1] = 0x0E; //Packet ID |
Vkadaba | 32:52445bef314d | 568 | |
Vkadaba | 32:52445bef314d | 569 | DataBuffer[2] = 0x00; |
Vkadaba | 32:52445bef314d | 570 | DataBuffer[3] = 0x00; //Data words |
Vkadaba | 32:52445bef314d | 571 | |
Vkadaba | 32:52445bef314d | 572 | DataBuffer[4] = 0x45; |
Vkadaba | 32:52445bef314d | 573 | DataBuffer[5] = 0x00; //Command ID |
Vkadaba | 32:52445bef314d | 574 | |
Vkadaba | 32:52445bef314d | 575 | DataBuffer[6] = 0x00; |
Vkadaba | 32:52445bef314d | 576 | DataBuffer[7] = 0x50; |
Vkadaba | 32:52445bef314d | 577 | DataBuffer[8] = 0x00; |
Vkadaba | 32:52445bef314d | 578 | DataBuffer[9] = 0x00; //Address |
Vkadaba | 32:52445bef314d | 579 | |
Vkadaba | 32:52445bef314d | 580 | DataBuffer[10] = 0x95; |
Vkadaba | 32:52445bef314d | 581 | DataBuffer[11] = 0x00; |
Vkadaba | 32:52445bef314d | 582 | DataBuffer[12] = 0x00; |
Vkadaba | 32:52445bef314d | 583 | DataBuffer[13] = 0x00; //Checksum |
Vkadaba | 32:52445bef314d | 584 | |
Vkadaba | 32:52445bef314d | 585 | nSize = SFL_READ_STATUS_HDR_SIZE; |
Vkadaba | 32:52445bef314d | 586 | |
Vkadaba | 32:52445bef314d | 587 | do { |
Vkadaba | 32:52445bef314d | 588 | // Get the SFL command irq pin to check if SFL is ready to receive commands |
Vkadaba | 32:52445bef314d | 589 | // Status pin is not checked since SFL is just booted, there should not be any issue with SFL |
Vkadaba | 32:52445bef314d | 590 | eRet = admw_GetGpioState( hDevice, ADMW_GPIO_PIN_DATAREADY, &bitCommand ); |
Vkadaba | 32:52445bef314d | 591 | if( eRet != ADMW_SUCCESS) { |
Vkadaba | 32:52445bef314d | 592 | return eRet; |
Vkadaba | 32:52445bef314d | 593 | } |
Vkadaba | 32:52445bef314d | 594 | |
Vkadaba | 32:52445bef314d | 595 | // Command IRQ pin should be low and Status IRQ pin should be high for SFL to be in good state and ready to recieve commands |
Vkadaba | 32:52445bef314d | 596 | // pinreg == '0x00' - Error occured in SFL |
Vkadaba | 32:52445bef314d | 597 | // pinreg == '0x01' - SFL is ready to recieve commands |
Vkadaba | 32:52445bef314d | 598 | // pinreg == '0x02' - Error occured in handling any commands in SFL |
Vkadaba | 32:52445bef314d | 599 | // pinreg == '0x03' - SFL not booted |
Vkadaba | 32:52445bef314d | 600 | |
Vkadaba | 32:52445bef314d | 601 | pinreg = (bitCommand); |
Vkadaba | 32:52445bef314d | 602 | |
Vkadaba | 32:52445bef314d | 603 | } while(pinreg != 0x0u); |
Vkadaba | 32:52445bef314d | 604 | |
Vkadaba | 32:52445bef314d | 605 | eRet = admw_SpiTransfer(pCtx->hSpi, DataBuffer, NULL, |
Vkadaba | 32:52445bef314d | 606 | nSize, false); |
Vkadaba | 32:52445bef314d | 607 | |
Vkadaba | 32:52445bef314d | 608 | return eRet; |
Vkadaba | 32:52445bef314d | 609 | } |
Vkadaba | 32:52445bef314d | 610 | |
Vkadaba | 32:52445bef314d | 611 | /* |
ADIJake | 0:85855ecd3257 | 612 | * Read a set of data samples from the device. |
ADIJake | 0:85855ecd3257 | 613 | * This may be called at any time. |
ADIJake | 0:85855ecd3257 | 614 | */ |
Vkadaba | 32:52445bef314d | 615 | |
Vkadaba | 5:0728bde67bdb | 616 | ADMW_RESULT admw_GetData( |
Vkadaba | 5:0728bde67bdb | 617 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 618 | ADMW_MEASUREMENT_MODE const eMeasurementMode, |
Vkadaba | 5:0728bde67bdb | 619 | ADMW_DATA_SAMPLE * const pSamples, |
ADIJake | 0:85855ecd3257 | 620 | uint8_t const nBytesPerSample, |
ADIJake | 0:85855ecd3257 | 621 | uint32_t const nRequested, |
ADIJake | 0:85855ecd3257 | 622 | uint32_t * const pnReturned) |
ADIJake | 0:85855ecd3257 | 623 | { |
Vkadaba | 5:0728bde67bdb | 624 | ADMW1001_Sensor_Result_t sensorResult; |
Vkadaba | 5:0728bde67bdb | 625 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 626 | uint16_t command = ADMW1001_HOST_COMMS_READ_CMD | |
Vkadaba | 23:bb685f35b08b | 627 | (REG_CORE_DATA_FIFO & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 628 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 629 | command >> 8, |
ADIJake | 0:85855ecd3257 | 630 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 631 | }; |
ADIJake | 0:85855ecd3257 | 632 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 633 | unsigned nValidSamples = 0; |
Vkadaba | 5:0728bde67bdb | 634 | ADMW_RESULT eRet = ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 635 | |
ADIJake | 0:85855ecd3257 | 636 | do { |
Vkadaba | 5:0728bde67bdb | 637 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 638 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 639 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 640 | ADMW_LOG_ERROR("Failed to send read command for FIFO register"); |
ADIJake | 0:85855ecd3257 | 641 | return eRet; |
ADIJake | 0:85855ecd3257 | 642 | } |
Vkadaba | 5:0728bde67bdb | 643 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 644 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 645 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 50:d84305e5e1c0 | 646 | |
Vkadaba | 23:bb685f35b08b | 647 | for (unsigned i = 0; i < nRequested; i++) { |
ADIJake | 0:85855ecd3257 | 648 | bool bHoldCs = true; |
ADIJake | 0:85855ecd3257 | 649 | /* Keep the CS signal asserted for all but the last sample */ |
ADIJake | 0:85855ecd3257 | 650 | if ((i + 1) == nRequested) |
ADIJake | 0:85855ecd3257 | 651 | bHoldCs = false; |
ADIJake | 0:85855ecd3257 | 652 | |
ADIJake | 0:85855ecd3257 | 653 | getDataCnt++; |
ADIJake | 0:85855ecd3257 | 654 | |
Vkadaba | 5:0728bde67bdb | 655 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, &sensorResult, |
Vkadaba | 23:bb685f35b08b | 656 | nBytesPerSample, bHoldCs); |
Vkadaba | 23:bb685f35b08b | 657 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 658 | ADMW_LOG_ERROR("Failed to read data from FIFO register"); |
ADIJake | 0:85855ecd3257 | 659 | return eRet; |
ADIJake | 0:85855ecd3257 | 660 | } |
ADIJake | 0:85855ecd3257 | 661 | |
Vkadaba | 23:bb685f35b08b | 662 | if (! sensorResult.Ch_Valid) { |
ADIJake | 0:85855ecd3257 | 663 | /* |
ADIJake | 0:85855ecd3257 | 664 | * Reading an invalid sample indicates that there are no |
ADIJake | 0:85855ecd3257 | 665 | * more samples available or we've lost sync with the device. |
ADIJake | 0:85855ecd3257 | 666 | * In the latter case, it might be recoverable, but return here |
ADIJake | 0:85855ecd3257 | 667 | * to let the application check the device status and decide itself. |
ADIJake | 0:85855ecd3257 | 668 | */ |
Vkadaba | 5:0728bde67bdb | 669 | eRet = ADMW_INCOMPLETE; |
ADIJake | 0:85855ecd3257 | 670 | break; |
ADIJake | 0:85855ecd3257 | 671 | } |
ADIJake | 0:85855ecd3257 | 672 | |
Vkadaba | 5:0728bde67bdb | 673 | ADMW_DATA_SAMPLE *pSample = &pSamples[nValidSamples]; |
Vkadaba | 5:0728bde67bdb | 674 | |
Vkadaba | 5:0728bde67bdb | 675 | pSample->status = (ADMW_DEVICE_STATUS_FLAGS)0; |
ADIJake | 0:85855ecd3257 | 676 | if (sensorResult.Ch_Error) |
Vkadaba | 5:0728bde67bdb | 677 | pSample->status |= ADMW_DEVICE_STATUS_ERROR; |
ADIJake | 0:85855ecd3257 | 678 | if (sensorResult.Ch_Alert) |
Vkadaba | 5:0728bde67bdb | 679 | pSample->status |= ADMW_DEVICE_STATUS_ALERT; |
ADIJake | 0:85855ecd3257 | 680 | |
ADIJake | 0:85855ecd3257 | 681 | if (sensorResult.Ch_Raw) |
ADIJake | 0:85855ecd3257 | 682 | pSample->rawValue = sensorResult.Raw_Sample; |
ADIJake | 0:85855ecd3257 | 683 | else |
ADIJake | 0:85855ecd3257 | 684 | pSample->rawValue = 0; |
ADIJake | 0:85855ecd3257 | 685 | |
ADIJake | 0:85855ecd3257 | 686 | pSample->channelId = sensorResult.Channel_ID; |
ADIJake | 0:85855ecd3257 | 687 | pSample->processedValue = sensorResult.Sensor_Result; |
ADIJake | 0:85855ecd3257 | 688 | |
ADIJake | 0:85855ecd3257 | 689 | nValidSamples++; |
ADIJake | 0:85855ecd3257 | 690 | |
Vkadaba | 50:d84305e5e1c0 | 691 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
ADIJake | 0:85855ecd3257 | 692 | } |
ADIJake | 0:85855ecd3257 | 693 | *pnReturned = nValidSamples; |
ADIJake | 0:85855ecd3257 | 694 | |
ADIJake | 0:85855ecd3257 | 695 | return eRet; |
ADIJake | 0:85855ecd3257 | 696 | } |
ADIJake | 0:85855ecd3257 | 697 | |
ADIJake | 0:85855ecd3257 | 698 | /* |
Vkadaba | 5:0728bde67bdb | 699 | * Close the given ADMW device. |
ADIJake | 0:85855ecd3257 | 700 | */ |
Vkadaba | 5:0728bde67bdb | 701 | ADMW_RESULT admw_Close( |
Vkadaba | 5:0728bde67bdb | 702 | ADMW_DEVICE_HANDLE const hDevice) |
ADIJake | 0:85855ecd3257 | 703 | { |
Vkadaba | 5:0728bde67bdb | 704 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 705 | |
Vkadaba | 5:0728bde67bdb | 706 | admw_GpioClose(pCtx->hGpio); |
Vkadaba | 5:0728bde67bdb | 707 | admw_SpiClose(pCtx->hSpi); |
Vkadaba | 5:0728bde67bdb | 708 | admw_LogClose(); |
Vkadaba | 5:0728bde67bdb | 709 | |
Vkadaba | 5:0728bde67bdb | 710 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 711 | } |
ADIJake | 0:85855ecd3257 | 712 | |
Vkadaba | 5:0728bde67bdb | 713 | ADMW_RESULT admw1001_WriteRegister( |
Vkadaba | 5:0728bde67bdb | 714 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 715 | uint16_t nAddress, |
ADIJake | 0:85855ecd3257 | 716 | void *pData, |
ADIJake | 0:85855ecd3257 | 717 | unsigned nLength) |
ADIJake | 0:85855ecd3257 | 718 | { |
Vkadaba | 5:0728bde67bdb | 719 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 720 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 721 | uint16_t command = ADMW1001_HOST_COMMS_WRITE_CMD | |
Vkadaba | 23:bb685f35b08b | 722 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 723 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 724 | command >> 8, |
ADIJake | 0:85855ecd3257 | 725 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 726 | }; |
ADIJake | 0:85855ecd3257 | 727 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 728 | |
ADIJake | 0:85855ecd3257 | 729 | do { |
Vkadaba | 5:0728bde67bdb | 730 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 731 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 732 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 733 | ADMW_LOG_ERROR("Failed to send write command for register %u", |
Vkadaba | 23:bb685f35b08b | 734 | nAddress); |
ADIJake | 0:85855ecd3257 | 735 | return eRet; |
ADIJake | 0:85855ecd3257 | 736 | } |
ADIJake | 0:85855ecd3257 | 737 | |
Vkadaba | 5:0728bde67bdb | 738 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 739 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 740 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 5:0728bde67bdb | 741 | |
Vkadaba | 5:0728bde67bdb | 742 | eRet = admw_SpiTransfer(pCtx->hSpi, pData, NULL, nLength, false); |
Vkadaba | 23:bb685f35b08b | 743 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 744 | ADMW_LOG_ERROR("Failed to write data (%dB) to register %u", |
Vkadaba | 23:bb685f35b08b | 745 | nLength, nAddress); |
ADIJake | 0:85855ecd3257 | 746 | return eRet; |
ADIJake | 0:85855ecd3257 | 747 | } |
ADIJake | 0:85855ecd3257 | 748 | |
Vkadaba | 5:0728bde67bdb | 749 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 750 | |
Vkadaba | 5:0728bde67bdb | 751 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 752 | } |
ADIJake | 0:85855ecd3257 | 753 | |
Vkadaba | 64:e8670e971e22 | 754 | ADMW_RESULT admw_GetDeviceReadyState( |
Vkadaba | 64:e8670e971e22 | 755 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 64:e8670e971e22 | 756 | bool * const bReady) |
Vkadaba | 6:9d393a9677f4 | 757 | { |
Vkadaba | 64:e8670e971e22 | 758 | ADMW_SPI_Chip_Type_t chipTypeReg; |
Vkadaba | 6:9d393a9677f4 | 759 | |
Vkadaba | 64:e8670e971e22 | 760 | READ_REG_U8(hDevice, chipTypeReg.VALUE8, SPI_CHIP_TYPE); |
Vkadaba | 64:e8670e971e22 | 761 | /* If we read this register successfully, assume the device is ready */ |
Vkadaba | 64:e8670e971e22 | 762 | *bReady = (chipTypeReg.VALUE8 == REG_SPI_CHIP_TYPE_RESET); |
Vkadaba | 6:9d393a9677f4 | 763 | |
Vkadaba | 6:9d393a9677f4 | 764 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 765 | } |
Vkadaba | 64:e8670e971e22 | 766 | |
Vkadaba | 5:0728bde67bdb | 767 | ADMW_RESULT admw1001_ReadRegister( |
Vkadaba | 5:0728bde67bdb | 768 | ADMW_DEVICE_HANDLE hDevice, |
ADIJake | 0:85855ecd3257 | 769 | uint16_t nAddress, |
ADIJake | 0:85855ecd3257 | 770 | void *pData, |
ADIJake | 0:85855ecd3257 | 771 | unsigned nLength) |
ADIJake | 0:85855ecd3257 | 772 | { |
Vkadaba | 5:0728bde67bdb | 773 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 774 | ADMW_DEVICE_CONTEXT *pCtx = hDevice; |
Vkadaba | 5:0728bde67bdb | 775 | uint16_t command = ADMW1001_HOST_COMMS_READ_CMD | |
Vkadaba | 23:bb685f35b08b | 776 | (nAddress & ADMW1001_HOST_COMMS_ADR_MASK); |
ADIJake | 0:85855ecd3257 | 777 | uint8_t commandData[2] = { |
ADIJake | 0:85855ecd3257 | 778 | command >> 8, |
ADIJake | 0:85855ecd3257 | 779 | command & 0xFF |
ADIJake | 0:85855ecd3257 | 780 | }; |
ADIJake | 0:85855ecd3257 | 781 | uint8_t commandResponse[2]; |
ADIJake | 0:85855ecd3257 | 782 | |
ADIJake | 0:85855ecd3257 | 783 | do { |
Vkadaba | 5:0728bde67bdb | 784 | eRet = admw_SpiTransfer(pCtx->hSpi, commandData, commandResponse, |
Vkadaba | 23:bb685f35b08b | 785 | sizeof(command), false); |
Vkadaba | 23:bb685f35b08b | 786 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 787 | ADMW_LOG_ERROR("Failed to send read command for register %u", |
Vkadaba | 23:bb685f35b08b | 788 | nAddress); |
ADIJake | 0:85855ecd3257 | 789 | return eRet; |
ADIJake | 0:85855ecd3257 | 790 | } |
ADIJake | 0:85855ecd3257 | 791 | |
Vkadaba | 5:0728bde67bdb | 792 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 793 | } while ((commandResponse[0] != ADMW1001_HOST_COMMS_CMD_RESP_0) || |
Vkadaba | 5:0728bde67bdb | 794 | (commandResponse[1] != ADMW1001_HOST_COMMS_CMD_RESP_1)); |
Vkadaba | 5:0728bde67bdb | 795 | |
Vkadaba | 5:0728bde67bdb | 796 | eRet = admw_SpiTransfer(pCtx->hSpi, NULL, pData, nLength, false); |
Vkadaba | 23:bb685f35b08b | 797 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 798 | ADMW_LOG_ERROR("Failed to read data (%uB) from register %u", |
Vkadaba | 23:bb685f35b08b | 799 | nLength, nAddress); |
ADIJake | 0:85855ecd3257 | 800 | return eRet; |
ADIJake | 0:85855ecd3257 | 801 | } |
ADIJake | 0:85855ecd3257 | 802 | |
Vkadaba | 5:0728bde67bdb | 803 | admw_TimeDelayUsec(ADMW1001_HOST_COMMS_XFER_DELAY); |
Vkadaba | 5:0728bde67bdb | 804 | |
Vkadaba | 5:0728bde67bdb | 805 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 806 | } |
ADIJake | 0:85855ecd3257 | 807 | |
Vkadaba | 5:0728bde67bdb | 808 | ADMW_RESULT admw1001_GetDataReadyModeInfo( |
Vkadaba | 8:2f2775c34640 | 809 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 8:2f2775c34640 | 810 | ADMW_MEASUREMENT_MODE const eMeasurementMode, |
Vkadaba | 5:0728bde67bdb | 811 | ADMW1001_OPERATING_MODE * const peOperatingMode, |
Vkadaba | 5:0728bde67bdb | 812 | ADMW1001_DATAREADY_MODE * const peDataReadyMode, |
Vkadaba | 8:2f2775c34640 | 813 | uint32_t * const pnSamplesPerDataready, |
Vkadaba | 8:2f2775c34640 | 814 | uint32_t * const pnSamplesPerCycle, |
Vkadaba | 8:2f2775c34640 | 815 | uint8_t * const pnBytesPerSample) |
ADIJake | 0:85855ecd3257 | 816 | { |
ADIJake | 0:85855ecd3257 | 817 | unsigned nChannelsEnabled = 0; |
ADIJake | 0:85855ecd3257 | 818 | unsigned nSamplesPerCycle = 0; |
ADIJake | 0:85855ecd3257 | 819 | |
Vkadaba | 8:2f2775c34640 | 820 | ADMW_CORE_Mode_t modeReg; |
ADIJake | 0:85855ecd3257 | 821 | READ_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); |
ADIJake | 0:85855ecd3257 | 822 | |
Vkadaba | 57:c6275de14bc5 | 823 | if (modeReg.Conversion_Mode == CORE_MODE_SINGLECYCLE) |
Vkadaba | 50:d84305e5e1c0 | 824 | *peOperatingMode = ADMW1001_OPERATING_MODE_SINGLECYCLE; |
Vkadaba | 50:d84305e5e1c0 | 825 | else |
Vkadaba | 50:d84305e5e1c0 | 826 | *peOperatingMode = ADMW1001_OPERATING_MODE_CONTINUOUS; |
ADIJake | 0:85855ecd3257 | 827 | |
Vkadaba | 23:bb685f35b08b | 828 | if (eMeasurementMode == ADMW_MEASUREMENT_MODE_OMIT_RAW) { |
Vkadaba | 50:d84305e5e1c0 | 829 | *pnBytesPerSample = 8; |
Vkadaba | 23:bb685f35b08b | 830 | } else { |
Vkadaba | 50:d84305e5e1c0 | 831 | *pnBytesPerSample = 12; |
Vkadaba | 6:9d393a9677f4 | 832 | } |
Vkadaba | 23:bb685f35b08b | 833 | |
Vkadaba | 8:2f2775c34640 | 834 | for (ADMW1001_CH_ID chId = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; |
Vkadaba | 23:bb685f35b08b | 835 | chId < ADMW1001_MAX_CHANNELS; |
Vkadaba | 23:bb685f35b08b | 836 | chId++) { |
Vkadaba | 8:2f2775c34640 | 837 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
Vkadaba | 8:2f2775c34640 | 838 | ADMW_CORE_Channel_Count_t channelCountReg; |
Vkadaba | 23:bb685f35b08b | 839 | |
Vkadaba | 23:bb685f35b08b | 840 | |
Vkadaba | 8:2f2775c34640 | 841 | READ_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(chId)); |
Vkadaba | 8:2f2775c34640 | 842 | READ_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(chId)); |
Vkadaba | 23:bb685f35b08b | 843 | |
Vkadaba | 41:df78b7d7b675 | 844 | if (channelCountReg.Channel_Enable && !sensorDetailsReg.Do_Not_Publish) { |
Vkadaba | 8:2f2775c34640 | 845 | unsigned nActualChannels = 1; |
Vkadaba | 63:2655a04c00f5 | 846 | |
Vkadaba | 8:2f2775c34640 | 847 | nChannelsEnabled += nActualChannels; |
Vkadaba | 23:bb685f35b08b | 848 | |
Vkadaba | 8:2f2775c34640 | 849 | nSamplesPerCycle += nActualChannels * |
Vkadaba | 8:2f2775c34640 | 850 | (channelCountReg.Channel_Count + 1); |
ADIJake | 0:85855ecd3257 | 851 | } |
Vkadaba | 6:9d393a9677f4 | 852 | } |
Vkadaba | 23:bb685f35b08b | 853 | |
Vkadaba | 23:bb685f35b08b | 854 | if (nChannelsEnabled == 0) { |
Vkadaba | 8:2f2775c34640 | 855 | *pnSamplesPerDataready = 0; |
Vkadaba | 8:2f2775c34640 | 856 | *pnSamplesPerCycle = 0; |
Vkadaba | 8:2f2775c34640 | 857 | return ADMW_SUCCESS; |
Vkadaba | 6:9d393a9677f4 | 858 | } |
Vkadaba | 23:bb685f35b08b | 859 | |
Vkadaba | 6:9d393a9677f4 | 860 | *pnSamplesPerCycle = nSamplesPerCycle; |
Vkadaba | 23:bb685f35b08b | 861 | |
Vkadaba | 23:bb685f35b08b | 862 | if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) { |
Vkadaba | 8:2f2775c34640 | 863 | *pnSamplesPerDataready = 1; |
Vkadaba | 50:d84305e5e1c0 | 864 | } else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CYCLE) { |
Vkadaba | 50:d84305e5e1c0 | 865 | *pnSamplesPerDataready = nSamplesPerCycle; |
Vkadaba | 50:d84305e5e1c0 | 866 | } else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_FIFO_FILL) { |
Vkadaba | 50:d84305e5e1c0 | 867 | ADMW_CORE_Fifo_Num_Cycles_t fifoNumCyclesReg; |
Vkadaba | 50:d84305e5e1c0 | 868 | |
Vkadaba | 50:d84305e5e1c0 | 869 | READ_REG_U8(hDevice, fifoNumCyclesReg.VALUE8, CORE_FIFO_NUM_CYCLES); |
Vkadaba | 50:d84305e5e1c0 | 870 | |
Vkadaba | 50:d84305e5e1c0 | 871 | *pnSamplesPerDataready = nSamplesPerCycle * fifoNumCyclesReg.Fifo_Num_Cycles; |
Vkadaba | 23:bb685f35b08b | 872 | } else { |
Vkadaba | 50:d84305e5e1c0 | 873 | ADMW_LOG_ERROR("Invalid DRDY mode %d specified", |
Vkadaba | 50:d84305e5e1c0 | 874 | modeReg.Drdy_Mode); |
Vkadaba | 50:d84305e5e1c0 | 875 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 876 | } |
Vkadaba | 23:bb685f35b08b | 877 | |
Vkadaba | 23:bb685f35b08b | 878 | if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CONVERSION) { |
Vkadaba | 8:2f2775c34640 | 879 | *peDataReadyMode = ADMW1001_DATAREADY_PER_CONVERSION; |
Vkadaba | 50:d84305e5e1c0 | 880 | } else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_CYCLE) { |
Vkadaba | 50:d84305e5e1c0 | 881 | *peDataReadyMode = ADMW1001_DATAREADY_PER_CYCLE; |
Vkadaba | 50:d84305e5e1c0 | 882 | } else if (modeReg.Drdy_Mode == CORE_MODE_DRDY_PER_FIFO_FILL) { |
Vkadaba | 50:d84305e5e1c0 | 883 | *peDataReadyMode = ADMW1001_DATAREADY_PER_FIFO_FILL; |
Vkadaba | 23:bb685f35b08b | 884 | } else { |
Vkadaba | 50:d84305e5e1c0 | 885 | ADMW_LOG_ERROR("Invalid DRDY mode %d specified", |
Vkadaba | 50:d84305e5e1c0 | 886 | modeReg.Drdy_Mode); |
Vkadaba | 50:d84305e5e1c0 | 887 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 888 | } |
Vkadaba | 23:bb685f35b08b | 889 | |
Vkadaba | 5:0728bde67bdb | 890 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 891 | } |
ADIJake | 0:85855ecd3257 | 892 | |
Vkadaba | 5:0728bde67bdb | 893 | ADMW_RESULT admw_GetProductID( |
Vkadaba | 5:0728bde67bdb | 894 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 895 | ADMW_PRODUCT_ID *pProductId) |
ADIJake | 0:85855ecd3257 | 896 | { |
Vkadaba | 5:0728bde67bdb | 897 | ADMW_SPI_Product_ID_L_t productIdLoReg; |
Vkadaba | 5:0728bde67bdb | 898 | ADMW_SPI_Product_ID_H_t productIdHiReg; |
ADIJake | 0:85855ecd3257 | 899 | |
ADIJake | 0:85855ecd3257 | 900 | READ_REG_U8(hDevice, productIdLoReg.VALUE8, SPI_PRODUCT_ID_L); |
ADIJake | 0:85855ecd3257 | 901 | READ_REG_U8(hDevice, productIdHiReg.VALUE8, SPI_PRODUCT_ID_H); |
ADIJake | 0:85855ecd3257 | 902 | |
Vkadaba | 23:bb685f35b08b | 903 | *pProductId = (ADMW_PRODUCT_ID)((productIdHiReg.VALUE8 << 8) | |
Vkadaba | 8:2f2775c34640 | 904 | productIdLoReg.VALUE8); |
Vkadaba | 5:0728bde67bdb | 905 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 906 | } |
ADIJake | 0:85855ecd3257 | 907 | |
Vkadaba | 5:0728bde67bdb | 908 | static ADMW_RESULT admw_SetPowerMode( |
Vkadaba | 5:0728bde67bdb | 909 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 910 | ADMW1001_POWER_MODE powerMode) |
ADIJake | 0:85855ecd3257 | 911 | { |
Vkadaba | 50:d84305e5e1c0 | 912 | ADMW_CORE_Power_Config_t powerConfigReg = { 0 }; |
Vkadaba | 5:0728bde67bdb | 913 | |
Vkadaba | 23:bb685f35b08b | 914 | if (powerMode == ADMW1001_POWER_MODE_HIBERNATION) { |
Vkadaba | 6:9d393a9677f4 | 915 | powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_HIBERNATION; |
Vkadaba | 23:bb685f35b08b | 916 | } else if (powerMode == ADMW1001_POWER_MODE_ACTIVE) { |
Vkadaba | 6:9d393a9677f4 | 917 | powerConfigReg.Power_Mode_MCU = CORE_POWER_CONFIG_ACTIVE_MODE; |
Vkadaba | 23:bb685f35b08b | 918 | } else { |
Vkadaba | 5:0728bde67bdb | 919 | ADMW_LOG_ERROR("Invalid power mode %d specified", powerMode); |
Vkadaba | 5:0728bde67bdb | 920 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 921 | } |
ADIJake | 0:85855ecd3257 | 922 | |
ADIJake | 0:85855ecd3257 | 923 | WRITE_REG_U8(hDevice, powerConfigReg.VALUE8, CORE_POWER_CONFIG); |
ADIJake | 0:85855ecd3257 | 924 | |
Vkadaba | 5:0728bde67bdb | 925 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 926 | } |
ADIJake | 0:85855ecd3257 | 927 | |
Vkadaba | 5:0728bde67bdb | 928 | ADMW_RESULT admw1001_SetPowerConfig( |
Vkadaba | 5:0728bde67bdb | 929 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 930 | ADMW1001_POWER_CONFIG *pPowerConfig) |
ADIJake | 0:85855ecd3257 | 931 | { |
Vkadaba | 5:0728bde67bdb | 932 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 933 | |
Vkadaba | 5:0728bde67bdb | 934 | eRet = admw_SetPowerMode(hDevice, pPowerConfig->powerMode); |
Vkadaba | 23:bb685f35b08b | 935 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 936 | ADMW_LOG_ERROR("Failed to set power mode"); |
ADIJake | 0:85855ecd3257 | 937 | return eRet; |
ADIJake | 0:85855ecd3257 | 938 | } |
ADIJake | 0:85855ecd3257 | 939 | |
Vkadaba | 5:0728bde67bdb | 940 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 941 | } |
ADIJake | 0:85855ecd3257 | 942 | |
Vkadaba | 33:df7a00f1b8e1 | 943 | static ADMW_RESULT admw_SetRSenseValue( |
Vkadaba | 33:df7a00f1b8e1 | 944 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 33:df7a00f1b8e1 | 945 | float32_t RSenseValue) |
Vkadaba | 33:df7a00f1b8e1 | 946 | { |
Vkadaba | 41:df78b7d7b675 | 947 | ADMW_CORE_External_Reference_Resistor_t RefResistorConfigReg; |
Vkadaba | 41:df78b7d7b675 | 948 | |
Vkadaba | 41:df78b7d7b675 | 949 | RefResistorConfigReg.Ext_Refin1_Value = RSenseValue; |
Vkadaba | 41:df78b7d7b675 | 950 | |
Vkadaba | 41:df78b7d7b675 | 951 | WRITE_REG_FLOAT(hDevice, RefResistorConfigReg.VALUE32, CORE_EXTERNAL_REFERENCE_RESISTOR); |
Vkadaba | 41:df78b7d7b675 | 952 | |
Vkadaba | 41:df78b7d7b675 | 953 | return ADMW_SUCCESS; |
Vkadaba | 33:df7a00f1b8e1 | 954 | |
Vkadaba | 33:df7a00f1b8e1 | 955 | } |
Vkadaba | 5:0728bde67bdb | 956 | static ADMW_RESULT admw_SetMode( |
Vkadaba | 5:0728bde67bdb | 957 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 958 | ADMW1001_OPERATING_MODE eOperatingMode, |
Vkadaba | 8:2f2775c34640 | 959 | ADMW1001_DATAREADY_MODE eDataReadyMode) |
ADIJake | 0:85855ecd3257 | 960 | { |
Vkadaba | 8:2f2775c34640 | 961 | ADMW_CORE_Mode_t modeReg; |
ADIJake | 0:85855ecd3257 | 962 | |
ADIJake | 0:85855ecd3257 | 963 | modeReg.VALUE8 = REG_RESET_VAL(CORE_MODE); |
ADIJake | 0:85855ecd3257 | 964 | |
Vkadaba | 23:bb685f35b08b | 965 | if (eOperatingMode == ADMW1001_OPERATING_MODE_SINGLECYCLE) { |
Vkadaba | 5:0728bde67bdb | 966 | modeReg.Conversion_Mode = CORE_MODE_SINGLECYCLE; |
Vkadaba | 23:bb685f35b08b | 967 | } else if (eOperatingMode == ADMW1001_OPERATING_MODE_CONTINUOUS) { |
Vkadaba | 5:0728bde67bdb | 968 | modeReg.Conversion_Mode = CORE_MODE_CONTINUOUS; |
Vkadaba | 23:bb685f35b08b | 969 | } else { |
Vkadaba | 5:0728bde67bdb | 970 | ADMW_LOG_ERROR("Invalid operating mode %d specified", |
Vkadaba | 23:bb685f35b08b | 971 | eOperatingMode); |
Vkadaba | 5:0728bde67bdb | 972 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 973 | } |
ADIJake | 0:85855ecd3257 | 974 | |
Vkadaba | 23:bb685f35b08b | 975 | if (eDataReadyMode == ADMW1001_DATAREADY_PER_CONVERSION) { |
Vkadaba | 5:0728bde67bdb | 976 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CONVERSION; |
Vkadaba | 23:bb685f35b08b | 977 | } else if (eDataReadyMode == ADMW1001_DATAREADY_PER_CYCLE) { |
Vkadaba | 5:0728bde67bdb | 978 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_CYCLE; |
Vkadaba | 50:d84305e5e1c0 | 979 | } else if (eDataReadyMode == ADMW1001_DATAREADY_PER_FIFO_FILL) { |
Vkadaba | 50:d84305e5e1c0 | 980 | modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_FIFO_FILL; |
Vkadaba | 23:bb685f35b08b | 981 | } else { |
Vkadaba | 5:0728bde67bdb | 982 | ADMW_LOG_ERROR("Invalid data-ready mode %d specified", eDataReadyMode); |
Vkadaba | 5:0728bde67bdb | 983 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 984 | } |
ADIJake | 0:85855ecd3257 | 985 | |
ADIJake | 0:85855ecd3257 | 986 | WRITE_REG_U8(hDevice, modeReg.VALUE8, CORE_MODE); |
ADIJake | 0:85855ecd3257 | 987 | |
Vkadaba | 5:0728bde67bdb | 988 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 989 | } |
ADIJake | 0:85855ecd3257 | 990 | |
Vkadaba | 8:2f2775c34640 | 991 | ADMW_RESULT admw_SetCycleControl(ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 992 | uint32_t nCycleInterval, |
Vkadaba | 50:d84305e5e1c0 | 993 | bool vBiasEnable, |
Vkadaba | 43:e1789b7214cf | 994 | bool vPostExecCurrentState, |
Vkadaba | 43:e1789b7214cf | 995 | bool vGroundSwitch) |
ADIJake | 0:85855ecd3257 | 996 | { |
Vkadaba | 8:2f2775c34640 | 997 | ADMW_CORE_Cycle_Control_t cycleControlReg; |
ADIJake | 0:85855ecd3257 | 998 | |
ADIJake | 0:85855ecd3257 | 999 | cycleControlReg.VALUE16 = REG_RESET_VAL(CORE_CYCLE_CONTROL); |
ADIJake | 0:85855ecd3257 | 1000 | |
Vkadaba | 43:e1789b7214cf | 1001 | if (nCycleInterval < (1 << 12)) { |
Vkadaba | 43:e1789b7214cf | 1002 | cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_SECONDS; |
Vkadaba | 23:bb685f35b08b | 1003 | } else { |
Vkadaba | 43:e1789b7214cf | 1004 | ADMW_LOG_ERROR("Invalid nCycleInterval %d specified", nCycleInterval); |
Vkadaba | 50:d84305e5e1c0 | 1005 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1006 | } |
ADIJake | 0:85855ecd3257 | 1007 | |
Vkadaba | 23:bb685f35b08b | 1008 | if (vBiasEnable == true) { |
Vkadaba | 8:2f2775c34640 | 1009 | cycleControlReg.Vbias = 1; |
Vkadaba | 8:2f2775c34640 | 1010 | } |
ADIJake | 0:85855ecd3257 | 1011 | CHECK_REG_FIELD_VAL(CORE_CYCLE_CONTROL_CYCLE_TIME, nCycleInterval); |
ADIJake | 0:85855ecd3257 | 1012 | cycleControlReg.Cycle_Time = nCycleInterval; |
Vkadaba | 50:d84305e5e1c0 | 1013 | |
Vkadaba | 50:d84305e5e1c0 | 1014 | switch(vPostExecCurrentState) { |
Vkadaba | 50:d84305e5e1c0 | 1015 | case ADMW1001_ADC_EXC_STATE_CYCLE_POWER: |
Vkadaba | 50:d84305e5e1c0 | 1016 | cycleControlReg.PST_MEAS_EXC_CTRL = CORE_CYCLE_CONTROL_POWERCYCLE; |
Vkadaba | 50:d84305e5e1c0 | 1017 | break; |
Vkadaba | 50:d84305e5e1c0 | 1018 | case ADMW1001_ADC_EXC_STATE_ALWAYS_ON: |
Vkadaba | 50:d84305e5e1c0 | 1019 | cycleControlReg.PST_MEAS_EXC_CTRL = CORE_CYCLE_CONTROL_ALWAYSON; |
Vkadaba | 50:d84305e5e1c0 | 1020 | break; |
Vkadaba | 50:d84305e5e1c0 | 1021 | default: |
Vkadaba | 50:d84305e5e1c0 | 1022 | ADMW_LOG_ERROR("Invalid Post measurement Excitation Current state %d specified", |
Vkadaba | 50:d84305e5e1c0 | 1023 | vPostExecCurrentState); |
Vkadaba | 50:d84305e5e1c0 | 1024 | return ADMW_INVALID_PARAM; |
Vkadaba | 43:e1789b7214cf | 1025 | } |
Vkadaba | 50:d84305e5e1c0 | 1026 | |
Vkadaba | 50:d84305e5e1c0 | 1027 | switch(vGroundSwitch) { |
Vkadaba | 50:d84305e5e1c0 | 1028 | case ADMW1001_ADC_GND_SW_OPEN: |
Vkadaba | 50:d84305e5e1c0 | 1029 | cycleControlReg.GND_SW_CTRL = CORE_CYCLE_CONTROL_OPEN_SW; |
Vkadaba | 50:d84305e5e1c0 | 1030 | break; |
Vkadaba | 50:d84305e5e1c0 | 1031 | case ADMW1001_ADC_GND_SW_CLOSED: |
Vkadaba | 50:d84305e5e1c0 | 1032 | cycleControlReg.GND_SW_CTRL = CORE_CYCLE_CONTROL_CLOSE_SW; |
Vkadaba | 50:d84305e5e1c0 | 1033 | break; |
Vkadaba | 50:d84305e5e1c0 | 1034 | default: |
Vkadaba | 50:d84305e5e1c0 | 1035 | ADMW_LOG_ERROR("Invalid ground switch state %d specified", |
Vkadaba | 50:d84305e5e1c0 | 1036 | vGroundSwitch); |
Vkadaba | 50:d84305e5e1c0 | 1037 | return ADMW_INVALID_PARAM; |
Vkadaba | 43:e1789b7214cf | 1038 | } |
Vkadaba | 50:d84305e5e1c0 | 1039 | |
ADIJake | 0:85855ecd3257 | 1040 | WRITE_REG_U16(hDevice, cycleControlReg.VALUE16, CORE_CYCLE_CONTROL); |
ADIJake | 0:85855ecd3257 | 1041 | |
Vkadaba | 5:0728bde67bdb | 1042 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1043 | } |
Vkadaba | 36:54e2418e7620 | 1044 | static ADMW_RESULT admw_SetExternalReferenceVoltage( |
Vkadaba | 36:54e2418e7620 | 1045 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 36:54e2418e7620 | 1046 | float32_t externalRefVoltage) |
Vkadaba | 36:54e2418e7620 | 1047 | { |
Vkadaba | 36:54e2418e7620 | 1048 | WRITE_REG_FLOAT(hDevice, externalRefVoltage, CORE_EXTERNAL_VOLTAGE_REFERENCE); |
Vkadaba | 36:54e2418e7620 | 1049 | |
Vkadaba | 36:54e2418e7620 | 1050 | return ADMW_SUCCESS; |
Vkadaba | 36:54e2418e7620 | 1051 | } |
Vkadaba | 50:d84305e5e1c0 | 1052 | static ADMW_RESULT admw_SetFifoNumCycles( |
Vkadaba | 50:d84305e5e1c0 | 1053 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 50:d84305e5e1c0 | 1054 | uint8_t fifoNumCycles) |
Vkadaba | 50:d84305e5e1c0 | 1055 | { |
Vkadaba | 50:d84305e5e1c0 | 1056 | WRITE_REG_U8(hDevice, fifoNumCycles, CORE_FIFO_NUM_CYCLES); |
Vkadaba | 50:d84305e5e1c0 | 1057 | |
Vkadaba | 50:d84305e5e1c0 | 1058 | return ADMW_SUCCESS; |
Vkadaba | 50:d84305e5e1c0 | 1059 | } |
ADIJake | 0:85855ecd3257 | 1060 | |
Vkadaba | 5:0728bde67bdb | 1061 | static ADMW_RESULT admw_SetExternalReferenceValues( |
Vkadaba | 5:0728bde67bdb | 1062 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 6:9d393a9677f4 | 1063 | float32_t externalRef1Value) |
ADIJake | 0:85855ecd3257 | 1064 | { |
Vkadaba | 6:9d393a9677f4 | 1065 | WRITE_REG_FLOAT(hDevice, externalRef1Value, CORE_EXTERNAL_REFERENCE_RESISTOR); |
ADIJake | 0:85855ecd3257 | 1066 | |
Vkadaba | 5:0728bde67bdb | 1067 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1068 | } |
Vkadaba | 45:f5f553b8c0d5 | 1069 | static ADMW_RESULT admw_SetAVDDVoltage( |
Vkadaba | 50:d84305e5e1c0 | 1070 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 50:d84305e5e1c0 | 1071 | float32_t AVDDVoltage) |
Vkadaba | 50:d84305e5e1c0 | 1072 | { |
Vkadaba | 45:f5f553b8c0d5 | 1073 | |
Vkadaba | 50:d84305e5e1c0 | 1074 | WRITE_REG_FLOAT(hDevice, AVDDVoltage, CORE_AVDD_VOLTAGE); |
Vkadaba | 45:f5f553b8c0d5 | 1075 | |
Vkadaba | 50:d84305e5e1c0 | 1076 | return ADMW_SUCCESS; |
Vkadaba | 50:d84305e5e1c0 | 1077 | } |
ADIJake | 0:85855ecd3257 | 1078 | |
Vkadaba | 5:0728bde67bdb | 1079 | ADMW_RESULT admw1001_SetMeasurementConfig( |
Vkadaba | 5:0728bde67bdb | 1080 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 1081 | ADMW1001_MEASUREMENT_CONFIG *pMeasConfig) |
ADIJake | 0:85855ecd3257 | 1082 | { |
Vkadaba | 5:0728bde67bdb | 1083 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1084 | |
Vkadaba | 5:0728bde67bdb | 1085 | eRet = admw_SetMode(hDevice, |
Vkadaba | 8:2f2775c34640 | 1086 | pMeasConfig->operatingMode, |
Vkadaba | 8:2f2775c34640 | 1087 | pMeasConfig->dataReadyMode); |
Vkadaba | 23:bb685f35b08b | 1088 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1089 | ADMW_LOG_ERROR("Failed to set operating mode"); |
ADIJake | 0:85855ecd3257 | 1090 | return eRet; |
ADIJake | 0:85855ecd3257 | 1091 | } |
ADIJake | 0:85855ecd3257 | 1092 | |
Vkadaba | 8:2f2775c34640 | 1093 | eRet = admw_SetCycleControl(hDevice, pMeasConfig->cycleInterval, |
Vkadaba | 43:e1789b7214cf | 1094 | pMeasConfig->vBiasEnable, |
Vkadaba | 43:e1789b7214cf | 1095 | pMeasConfig->excitationState, |
Vkadaba | 43:e1789b7214cf | 1096 | pMeasConfig->groundSwitch ); |
Vkadaba | 23:bb685f35b08b | 1097 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1098 | ADMW_LOG_ERROR("Failed to set cycle control"); |
ADIJake | 0:85855ecd3257 | 1099 | return eRet; |
ADIJake | 0:85855ecd3257 | 1100 | } |
ADIJake | 0:85855ecd3257 | 1101 | |
Vkadaba | 50:d84305e5e1c0 | 1102 | if (pMeasConfig->fifoNumCycles > 0) { |
Vkadaba | 50:d84305e5e1c0 | 1103 | eRet = admw_SetFifoNumCycles(hDevice, |
Vkadaba | 50:d84305e5e1c0 | 1104 | pMeasConfig->fifoNumCycles); |
Vkadaba | 50:d84305e5e1c0 | 1105 | } |
Vkadaba | 50:d84305e5e1c0 | 1106 | |
Vkadaba | 50:d84305e5e1c0 | 1107 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 50:d84305e5e1c0 | 1108 | ADMW_LOG_ERROR("Failed to set the FIFO number of cycles."); |
Vkadaba | 50:d84305e5e1c0 | 1109 | return eRet; |
Vkadaba | 50:d84305e5e1c0 | 1110 | } |
Vkadaba | 50:d84305e5e1c0 | 1111 | |
Vkadaba | 43:e1789b7214cf | 1112 | if(pMeasConfig->externalRef1Value > 0) { |
Vkadaba | 8:2f2775c34640 | 1113 | eRet = admw_SetExternalReferenceValues(hDevice, |
Vkadaba | 8:2f2775c34640 | 1114 | pMeasConfig->externalRef1Value); |
ADIJake | 0:85855ecd3257 | 1115 | } |
Vkadaba | 50:d84305e5e1c0 | 1116 | |
Vkadaba | 50:d84305e5e1c0 | 1117 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 50:d84305e5e1c0 | 1118 | ADMW_LOG_ERROR("Failed to set external reference values"); |
Vkadaba | 50:d84305e5e1c0 | 1119 | return eRet; |
Vkadaba | 50:d84305e5e1c0 | 1120 | } |
Vkadaba | 50:d84305e5e1c0 | 1121 | |
Vkadaba | 50:d84305e5e1c0 | 1122 | if((pMeasConfig->AVDDVoltage >= 3.0) && (pMeasConfig->AVDDVoltage <= 3.6)) { |
Vkadaba | 45:f5f553b8c0d5 | 1123 | eRet = admw_SetAVDDVoltage(hDevice, |
Vkadaba | 45:f5f553b8c0d5 | 1124 | pMeasConfig->AVDDVoltage); |
Vkadaba | 45:f5f553b8c0d5 | 1125 | } |
Vkadaba | 50:d84305e5e1c0 | 1126 | |
Vkadaba | 23:bb685f35b08b | 1127 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 50:d84305e5e1c0 | 1128 | ADMW_LOG_ERROR("Failed to set AVDD Voltge"); |
ADIJake | 0:85855ecd3257 | 1129 | return eRet; |
ADIJake | 0:85855ecd3257 | 1130 | } |
ADIJake | 0:85855ecd3257 | 1131 | |
Vkadaba | 33:df7a00f1b8e1 | 1132 | eRet = admw_SetRSenseValue(hDevice, pMeasConfig->RSenseValue); |
Vkadaba | 41:df78b7d7b675 | 1133 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 33:df7a00f1b8e1 | 1134 | ADMW_LOG_ERROR("Failed to set RSenseValue"); |
Vkadaba | 33:df7a00f1b8e1 | 1135 | return eRet; |
Vkadaba | 33:df7a00f1b8e1 | 1136 | } |
Vkadaba | 41:df78b7d7b675 | 1137 | |
Vkadaba | 36:54e2418e7620 | 1138 | eRet = admw_SetExternalReferenceVoltage(hDevice, pMeasConfig->externalRefVoltage); |
Vkadaba | 41:df78b7d7b675 | 1139 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 36:54e2418e7620 | 1140 | ADMW_LOG_ERROR("Failed to set External reference Voltage"); |
Vkadaba | 36:54e2418e7620 | 1141 | return eRet; |
Vkadaba | 41:df78b7d7b675 | 1142 | } |
Vkadaba | 41:df78b7d7b675 | 1143 | |
Vkadaba | 5:0728bde67bdb | 1144 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1145 | } |
Vkadaba | 36:54e2418e7620 | 1146 | ADMW_RESULT admw1001_SetDiagnosticsConfig( |
Vkadaba | 36:54e2418e7620 | 1147 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 36:54e2418e7620 | 1148 | ADMW1001_DIAGNOSTICS_CONFIG *pDiagnosticsConfig) |
Vkadaba | 36:54e2418e7620 | 1149 | { |
Vkadaba | 36:54e2418e7620 | 1150 | ADMW_CORE_Diagnostics_Control_t diagnosticsControlReg; |
ADIJake | 0:85855ecd3257 | 1151 | |
Vkadaba | 36:54e2418e7620 | 1152 | diagnosticsControlReg.VALUE8 = REG_RESET_VAL(CORE_DIAGNOSTICS_CONTROL); |
Vkadaba | 36:54e2418e7620 | 1153 | |
Vkadaba | 36:54e2418e7620 | 1154 | if (pDiagnosticsConfig->disableMeasurementDiag) |
Vkadaba | 36:54e2418e7620 | 1155 | diagnosticsControlReg.Diag_Meas_En = 0; |
Vkadaba | 36:54e2418e7620 | 1156 | else |
Vkadaba | 36:54e2418e7620 | 1157 | diagnosticsControlReg.Diag_Meas_En = 1; |
Vkadaba | 36:54e2418e7620 | 1158 | |
Vkadaba | 55:215da406282b | 1159 | if(pDiagnosticsConfig->osdFrequency <= 0x7F) { |
Vkadaba | 55:215da406282b | 1160 | diagnosticsControlReg.Diag_OSD_Freq = pDiagnosticsConfig->osdFrequency; |
Vkadaba | 55:215da406282b | 1161 | } else { |
Vkadaba | 44:94bdfaefddac | 1162 | ADMW_LOG_ERROR("Invalid open-sensor diagnostic frequency %d specified", |
Vkadaba | 55:215da406282b | 1163 | pDiagnosticsConfig->osdFrequency); |
Vkadaba | 44:94bdfaefddac | 1164 | return ADMW_INVALID_PARAM; |
Vkadaba | 44:94bdfaefddac | 1165 | } |
Vkadaba | 36:54e2418e7620 | 1166 | WRITE_REG_U8(hDevice, diagnosticsControlReg.VALUE8, CORE_DIAGNOSTICS_CONTROL); |
Vkadaba | 36:54e2418e7620 | 1167 | |
Vkadaba | 36:54e2418e7620 | 1168 | return ADMW_SUCCESS; |
Vkadaba | 36:54e2418e7620 | 1169 | } |
ADIJake | 0:85855ecd3257 | 1170 | |
Vkadaba | 5:0728bde67bdb | 1171 | ADMW_RESULT admw1001_SetChannelCount( |
Vkadaba | 5:0728bde67bdb | 1172 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1173 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1174 | uint32_t nMeasurementsPerCycle) |
ADIJake | 0:85855ecd3257 | 1175 | { |
Vkadaba | 8:2f2775c34640 | 1176 | ADMW_CORE_Channel_Count_t channelCountReg; |
ADIJake | 0:85855ecd3257 | 1177 | |
ADIJake | 0:85855ecd3257 | 1178 | channelCountReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_COUNTn); |
ADIJake | 0:85855ecd3257 | 1179 | |
Vkadaba | 23:bb685f35b08b | 1180 | if (nMeasurementsPerCycle > 0) { |
ADIJake | 0:85855ecd3257 | 1181 | nMeasurementsPerCycle -= 1; |
ADIJake | 0:85855ecd3257 | 1182 | |
ADIJake | 0:85855ecd3257 | 1183 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_COUNT_CHANNEL_COUNT, |
ADIJake | 0:85855ecd3257 | 1184 | nMeasurementsPerCycle); |
ADIJake | 0:85855ecd3257 | 1185 | |
ADIJake | 0:85855ecd3257 | 1186 | channelCountReg.Channel_Enable = 1; |
ADIJake | 0:85855ecd3257 | 1187 | channelCountReg.Channel_Count = nMeasurementsPerCycle; |
Vkadaba | 23:bb685f35b08b | 1188 | } else { |
ADIJake | 0:85855ecd3257 | 1189 | channelCountReg.Channel_Enable = 0; |
ADIJake | 0:85855ecd3257 | 1190 | } |
ADIJake | 0:85855ecd3257 | 1191 | |
ADIJake | 0:85855ecd3257 | 1192 | WRITE_REG_U8(hDevice, channelCountReg.VALUE8, CORE_CHANNEL_COUNTn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1193 | |
Vkadaba | 5:0728bde67bdb | 1194 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1195 | } |
ADIJake | 0:85855ecd3257 | 1196 | |
Vkadaba | 5:0728bde67bdb | 1197 | ADMW_RESULT admw1001_SetChannelOptions( |
Vkadaba | 5:0728bde67bdb | 1198 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1199 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 6:9d393a9677f4 | 1200 | ADMW1001_CHANNEL_PRIORITY ePriority) |
ADIJake | 0:85855ecd3257 | 1201 | { |
Vkadaba | 8:2f2775c34640 | 1202 | ADMW_CORE_Channel_Options_t channelOptionsReg; |
ADIJake | 0:85855ecd3257 | 1203 | |
ADIJake | 0:85855ecd3257 | 1204 | channelOptionsReg.VALUE8 = REG_RESET_VAL(CORE_CHANNEL_OPTIONSn); |
ADIJake | 0:85855ecd3257 | 1205 | |
ADIJake | 0:85855ecd3257 | 1206 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_OPTIONS_CHANNEL_PRIORITY, ePriority); |
ADIJake | 0:85855ecd3257 | 1207 | channelOptionsReg.Channel_Priority = ePriority; |
ADIJake | 0:85855ecd3257 | 1208 | |
ADIJake | 0:85855ecd3257 | 1209 | WRITE_REG_U8(hDevice, channelOptionsReg.VALUE8, CORE_CHANNEL_OPTIONSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1210 | |
Vkadaba | 5:0728bde67bdb | 1211 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1212 | } |
ADIJake | 0:85855ecd3257 | 1213 | |
Vkadaba | 5:0728bde67bdb | 1214 | ADMW_RESULT admw1001_SetChannelSkipCount( |
Vkadaba | 5:0728bde67bdb | 1215 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1216 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1217 | uint32_t nCycleSkipCount) |
ADIJake | 0:85855ecd3257 | 1218 | { |
Vkadaba | 8:2f2775c34640 | 1219 | ADMW_CORE_Channel_Skip_t channelSkipReg; |
ADIJake | 0:85855ecd3257 | 1220 | |
ADIJake | 0:85855ecd3257 | 1221 | channelSkipReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_SKIPn); |
ADIJake | 0:85855ecd3257 | 1222 | |
ADIJake | 0:85855ecd3257 | 1223 | CHECK_REG_FIELD_VAL(CORE_CHANNEL_SKIP_CHANNEL_SKIP, nCycleSkipCount); |
ADIJake | 0:85855ecd3257 | 1224 | |
ADIJake | 0:85855ecd3257 | 1225 | channelSkipReg.Channel_Skip = nCycleSkipCount; |
ADIJake | 0:85855ecd3257 | 1226 | |
ADIJake | 0:85855ecd3257 | 1227 | WRITE_REG_U16(hDevice, channelSkipReg.VALUE16, CORE_CHANNEL_SKIPn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1228 | |
Vkadaba | 5:0728bde67bdb | 1229 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1230 | } |
ADIJake | 0:85855ecd3257 | 1231 | |
Vkadaba | 5:0728bde67bdb | 1232 | static ADMW_RESULT admw_SetChannelAdcSensorType( |
Vkadaba | 8:2f2775c34640 | 1233 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1234 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 8:2f2775c34640 | 1235 | ADMW1001_ADC_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1236 | { |
Vkadaba | 8:2f2775c34640 | 1237 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1238 | |
ADIJake | 0:85855ecd3257 | 1239 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1240 | |
ADIJake | 0:85855ecd3257 | 1241 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1242 | switch(sensorType) { |
Vkadaba | 50:d84305e5e1c0 | 1243 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT10: |
Vkadaba | 50:d84305e5e1c0 | 1244 | |
Vkadaba | 50:d84305e5e1c0 | 1245 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT50: |
Vkadaba | 50:d84305e5e1c0 | 1246 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT100: |
Vkadaba | 50:d84305e5e1c0 | 1247 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT200: |
Vkadaba | 50:d84305e5e1c0 | 1248 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT500: |
Vkadaba | 50:d84305e5e1c0 | 1249 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000: |
Vkadaba | 50:d84305e5e1c0 | 1250 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_PT1000_0P00375: |
Vkadaba | 50:d84305e5e1c0 | 1251 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_NI120: |
Vkadaba | 50:d84305e5e1c0 | 1252 | case ADMW1001_ADC_SENSOR_RTD_2WIRE_CUSTOM: |
Vkadaba | 50:d84305e5e1c0 | 1253 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT10: |
Vkadaba | 50:d84305e5e1c0 | 1254 | |
Vkadaba | 50:d84305e5e1c0 | 1255 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT50: |
Vkadaba | 50:d84305e5e1c0 | 1256 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT100: |
Vkadaba | 50:d84305e5e1c0 | 1257 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT200: |
Vkadaba | 50:d84305e5e1c0 | 1258 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT500: |
Vkadaba | 50:d84305e5e1c0 | 1259 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000: |
Vkadaba | 50:d84305e5e1c0 | 1260 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_PT1000_0P00375: |
Vkadaba | 50:d84305e5e1c0 | 1261 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_NI120: |
Vkadaba | 50:d84305e5e1c0 | 1262 | case ADMW1001_ADC_SENSOR_RTD_4WIRE_CUSTOM: |
Vkadaba | 50:d84305e5e1c0 | 1263 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT10: |
Vkadaba | 50:d84305e5e1c0 | 1264 | |
Vkadaba | 50:d84305e5e1c0 | 1265 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT50: |
Vkadaba | 8:2f2775c34640 | 1266 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT100: |
Vkadaba | 50:d84305e5e1c0 | 1267 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT200: |
Vkadaba | 50:d84305e5e1c0 | 1268 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT500: |
Vkadaba | 8:2f2775c34640 | 1269 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000: |
Vkadaba | 50:d84305e5e1c0 | 1270 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_PT1000_0P00375 : |
Vkadaba | 50:d84305e5e1c0 | 1271 | |
Vkadaba | 50:d84305e5e1c0 | 1272 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_NI120: |
Vkadaba | 50:d84305e5e1c0 | 1273 | case ADMW1001_ADC_SENSOR_RTD_3WIRE_CUSTOM: |
Vkadaba | 58:aa9cd5072f66 | 1274 | case ADMW1001_ADC_SENSOR_BRIDGE_4WIRE: |
Vkadaba | 58:aa9cd5072f66 | 1275 | case ADMW1001_ADC_SENSOR_BRIDGE_6WIRE: |
Vkadaba | 50:d84305e5e1c0 | 1276 | case ADMW1001_ADC_SENSOR_DIODE: |
Vkadaba | 50:d84305e5e1c0 | 1277 | case ADMW1001_ADC_SENSOR_THERMISTOR_44004_44033_2P252K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1278 | case ADMW1001_ADC_SENSOR_THERMISTOR_44005_44030_3K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1279 | case ADMW1001_ADC_SENSOR_THERMISTOR_44007_44034_5K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1280 | case ADMW1001_ADC_SENSOR_THERMISTOR_44006_44031_10K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1281 | case ADMW1001_ADC_SENSOR_THERMISTOR_44008_44032_30K_AT_25C: |
Vkadaba | 50:d84305e5e1c0 | 1282 | case ADMW1001_ADC_SENSOR_THERMISTOR_YSI_400: |
Vkadaba | 50:d84305e5e1c0 | 1283 | case ADMW1001_ADC_SENSOR_THERMISTOR_SPECTRUM_1003K_1K: |
Vkadaba | 50:d84305e5e1c0 | 1284 | case ADMW1001_ADC_SENSOR_THERMISTOR_CUSTOM_STEINHART_HART: |
Vkadaba | 50:d84305e5e1c0 | 1285 | case ADMW1001_ADC_SENSOR_THERMISTOR_CUSTOM_TABLE: |
Vkadaba | 36:54e2418e7620 | 1286 | case ADMW1001_ADC_SENSOR_SINGLE_ENDED_ABSOLUTE: |
Vkadaba | 36:54e2418e7620 | 1287 | case ADMW1001_ADC_SENSOR_DIFFERENTIAL_ABSOLUTE: |
Vkadaba | 36:54e2418e7620 | 1288 | case ADMW1001_ADC_SENSOR_SINGLE_ENDED_RATIO: |
Vkadaba | 36:54e2418e7620 | 1289 | case ADMW1001_ADC_SENSOR_DIFFERENTIAL_RATIO: |
Vkadaba | 50:d84305e5e1c0 | 1290 | |
Vkadaba | 50:d84305e5e1c0 | 1291 | if (! (ADMW1001_CHANNEL_IS_ADC_CJC(eChannelId) || |
Vkadaba | 50:d84305e5e1c0 | 1292 | ADMW1001_CHANNEL_IS_ADC(eChannelId) )) { |
Vkadaba | 6:9d393a9677f4 | 1293 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1294 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1295 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1296 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1297 | } |
Vkadaba | 6:9d393a9677f4 | 1298 | break; |
Vkadaba | 8:2f2775c34640 | 1299 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_J: |
Vkadaba | 8:2f2775c34640 | 1300 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_K: |
Vkadaba | 8:2f2775c34640 | 1301 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_T: |
Vkadaba | 50:d84305e5e1c0 | 1302 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_E: |
Vkadaba | 50:d84305e5e1c0 | 1303 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_N: |
Vkadaba | 50:d84305e5e1c0 | 1304 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_R: |
Vkadaba | 50:d84305e5e1c0 | 1305 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_S: |
Vkadaba | 50:d84305e5e1c0 | 1306 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_B: |
Vkadaba | 50:d84305e5e1c0 | 1307 | case ADMW1001_ADC_SENSOR_THERMOCOUPLE_CUSTOM: |
Vkadaba | 23:bb685f35b08b | 1308 | if (! ADMW1001_CHANNEL_IS_ADC_VOLTAGE(eChannelId)) { |
Vkadaba | 6:9d393a9677f4 | 1309 | ADMW_LOG_ERROR( |
Vkadaba | 6:9d393a9677f4 | 1310 | "Invalid ADC sensor type %d specified for channel %d", |
Vkadaba | 6:9d393a9677f4 | 1311 | sensorType, eChannelId); |
Vkadaba | 6:9d393a9677f4 | 1312 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1313 | } |
Vkadaba | 6:9d393a9677f4 | 1314 | break; |
Vkadaba | 6:9d393a9677f4 | 1315 | default: |
Vkadaba | 6:9d393a9677f4 | 1316 | ADMW_LOG_ERROR("Invalid/unsupported ADC sensor type %d specified", |
Vkadaba | 23:bb685f35b08b | 1317 | sensorType); |
Vkadaba | 5:0728bde67bdb | 1318 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1319 | } |
ADIJake | 0:85855ecd3257 | 1320 | |
ADIJake | 0:85855ecd3257 | 1321 | sensorTypeReg.Sensor_Type = sensorType; |
ADIJake | 0:85855ecd3257 | 1322 | |
ADIJake | 0:85855ecd3257 | 1323 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1324 | |
Vkadaba | 5:0728bde67bdb | 1325 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1326 | } |
ADIJake | 0:85855ecd3257 | 1327 | |
Vkadaba | 5:0728bde67bdb | 1328 | static ADMW_RESULT admw_SetChannelAdcSensorDetails( |
Vkadaba | 8:2f2775c34640 | 1329 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1330 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1331 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1332 | /* |
ADIJake | 0:85855ecd3257 | 1333 | * TODO - it would be nice if the general- vs. ADC-specific sensor details could be split into separate registers |
ADIJake | 0:85855ecd3257 | 1334 | * General details: |
ADIJake | 0:85855ecd3257 | 1335 | * - Measurement_Units |
ADIJake | 0:85855ecd3257 | 1336 | * - Compensation_Channel |
ADIJake | 0:85855ecd3257 | 1337 | * - CJC_Publish (if "CJC" was removed from the name) |
ADIJake | 0:85855ecd3257 | 1338 | * ADC-specific details: |
ADIJake | 0:85855ecd3257 | 1339 | * - PGA_Gain |
ADIJake | 0:85855ecd3257 | 1340 | * - Reference_Select |
ADIJake | 0:85855ecd3257 | 1341 | * - Reference_Buffer_Disable |
ADIJake | 0:85855ecd3257 | 1342 | */ |
ADIJake | 0:85855ecd3257 | 1343 | { |
Vkadaba | 5:0728bde67bdb | 1344 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = &pChannelConfig->adcChannelConfig; |
Vkadaba | 8:2f2775c34640 | 1345 | ADMW1001_ADC_REFERENCE_TYPE refType = pAdcChannelConfig->reference; |
Vkadaba | 8:2f2775c34640 | 1346 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
ADIJake | 0:85855ecd3257 | 1347 | |
ADIJake | 0:85855ecd3257 | 1348 | sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); |
ADIJake | 0:85855ecd3257 | 1349 | |
Vkadaba | 23:bb685f35b08b | 1350 | switch(pChannelConfig->measurementUnit) { |
Vkadaba | 8:2f2775c34640 | 1351 | case ADMW1001_MEASUREMENT_UNIT_FAHRENHEIT: |
Vkadaba | 8:2f2775c34640 | 1352 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGF; |
Vkadaba | 8:2f2775c34640 | 1353 | break; |
Vkadaba | 8:2f2775c34640 | 1354 | case ADMW1001_MEASUREMENT_UNIT_CELSIUS: |
Vkadaba | 8:2f2775c34640 | 1355 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_DEGC; |
Vkadaba | 8:2f2775c34640 | 1356 | break; |
Vkadaba | 8:2f2775c34640 | 1357 | case ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED: |
Vkadaba | 8:2f2775c34640 | 1358 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; |
Vkadaba | 8:2f2775c34640 | 1359 | break; |
Vkadaba | 8:2f2775c34640 | 1360 | default: |
Vkadaba | 8:2f2775c34640 | 1361 | ADMW_LOG_ERROR("Invalid measurement unit %d specified", |
Vkadaba | 8:2f2775c34640 | 1362 | pChannelConfig->measurementUnit); |
Vkadaba | 8:2f2775c34640 | 1363 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1364 | } |
ADIJake | 0:85855ecd3257 | 1365 | |
Vkadaba | 23:bb685f35b08b | 1366 | if (pChannelConfig->compensationChannel == ADMW1001_CH_ID_NONE) { |
ADIJake | 0:85855ecd3257 | 1367 | sensorDetailsReg.Compensation_Disable = 1; |
ADIJake | 0:85855ecd3257 | 1368 | sensorDetailsReg.Compensation_Channel = 0; |
Vkadaba | 23:bb685f35b08b | 1369 | } else { |
ADIJake | 0:85855ecd3257 | 1370 | sensorDetailsReg.Compensation_Disable = 0; |
ADIJake | 0:85855ecd3257 | 1371 | sensorDetailsReg.Compensation_Channel = pChannelConfig->compensationChannel; |
ADIJake | 0:85855ecd3257 | 1372 | } |
ADIJake | 0:85855ecd3257 | 1373 | |
Vkadaba | 23:bb685f35b08b | 1374 | switch(refType) { |
Vkadaba | 8:2f2775c34640 | 1375 | case ADMW1001_ADC_REFERENCE_VOLTAGE_INTERNAL: |
Vkadaba | 8:2f2775c34640 | 1376 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VINT; |
Vkadaba | 8:2f2775c34640 | 1377 | break; |
Vkadaba | 8:2f2775c34640 | 1378 | case ADMW1001_ADC_REFERENCE_VOLTAGE_EXTERNAL_1: |
Vkadaba | 8:2f2775c34640 | 1379 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_VEXT1; |
Vkadaba | 8:2f2775c34640 | 1380 | break; |
Vkadaba | 8:2f2775c34640 | 1381 | case ADMW1001_ADC_REFERENCE_VOLTAGE_AVDD: |
Vkadaba | 8:2f2775c34640 | 1382 | sensorDetailsReg.Reference_Select = CORE_SENSOR_DETAILS_REF_AVDD; |
Vkadaba | 8:2f2775c34640 | 1383 | break; |
Vkadaba | 8:2f2775c34640 | 1384 | default: |
Vkadaba | 8:2f2775c34640 | 1385 | ADMW_LOG_ERROR("Invalid ADC reference type %d specified", refType); |
Vkadaba | 8:2f2775c34640 | 1386 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1387 | } |
Vkadaba | 23:bb685f35b08b | 1388 | |
Vkadaba | 23:bb685f35b08b | 1389 | switch(pAdcChannelConfig->gain) { |
Vkadaba | 8:2f2775c34640 | 1390 | case ADMW1001_ADC_GAIN_1X: |
Vkadaba | 8:2f2775c34640 | 1391 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_1; |
Vkadaba | 8:2f2775c34640 | 1392 | break; |
Vkadaba | 8:2f2775c34640 | 1393 | case ADMW1001_ADC_GAIN_2X: |
Vkadaba | 8:2f2775c34640 | 1394 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_2; |
Vkadaba | 8:2f2775c34640 | 1395 | break; |
Vkadaba | 8:2f2775c34640 | 1396 | case ADMW1001_ADC_GAIN_4X: |
Vkadaba | 8:2f2775c34640 | 1397 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_4; |
Vkadaba | 8:2f2775c34640 | 1398 | break; |
Vkadaba | 8:2f2775c34640 | 1399 | case ADMW1001_ADC_GAIN_8X: |
Vkadaba | 8:2f2775c34640 | 1400 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_8; |
Vkadaba | 8:2f2775c34640 | 1401 | break; |
Vkadaba | 8:2f2775c34640 | 1402 | case ADMW1001_ADC_GAIN_16X: |
Vkadaba | 8:2f2775c34640 | 1403 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_16; |
Vkadaba | 8:2f2775c34640 | 1404 | break; |
Vkadaba | 8:2f2775c34640 | 1405 | case ADMW1001_ADC_GAIN_32X: |
Vkadaba | 8:2f2775c34640 | 1406 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_32; |
Vkadaba | 8:2f2775c34640 | 1407 | break; |
Vkadaba | 8:2f2775c34640 | 1408 | case ADMW1001_ADC_GAIN_64X: |
Vkadaba | 8:2f2775c34640 | 1409 | sensorDetailsReg.PGA_Gain = CORE_SENSOR_DETAILS_PGA_GAIN_64; |
Vkadaba | 8:2f2775c34640 | 1410 | break; |
Vkadaba | 8:2f2775c34640 | 1411 | default: |
Vkadaba | 8:2f2775c34640 | 1412 | ADMW_LOG_ERROR("Invalid ADC gain %d specified", |
Vkadaba | 23:bb685f35b08b | 1413 | pAdcChannelConfig->gain); |
Vkadaba | 8:2f2775c34640 | 1414 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1415 | } |
ADIJake | 0:85855ecd3257 | 1416 | |
Vkadaba | 23:bb685f35b08b | 1417 | switch(pAdcChannelConfig->rtdCurve) { |
Vkadaba | 8:2f2775c34640 | 1418 | case ADMW1001_ADC_RTD_CURVE_EUROPEAN: |
Vkadaba | 8:2f2775c34640 | 1419 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_EUROPEAN_CURVE; |
Vkadaba | 8:2f2775c34640 | 1420 | break; |
Vkadaba | 8:2f2775c34640 | 1421 | case ADMW1001_ADC_RTD_CURVE_AMERICAN: |
Vkadaba | 8:2f2775c34640 | 1422 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_AMERICAN_CURVE; |
Vkadaba | 8:2f2775c34640 | 1423 | break; |
Vkadaba | 8:2f2775c34640 | 1424 | case ADMW1001_ADC_RTD_CURVE_JAPANESE: |
Vkadaba | 8:2f2775c34640 | 1425 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_JAPANESE_CURVE; |
Vkadaba | 8:2f2775c34640 | 1426 | break; |
Vkadaba | 8:2f2775c34640 | 1427 | case ADMW1001_ADC_RTD_CURVE_ITS90: |
Vkadaba | 8:2f2775c34640 | 1428 | sensorDetailsReg.RTD_Curve = CORE_SENSOR_DETAILS_ITS90_CURVE; |
Vkadaba | 8:2f2775c34640 | 1429 | break; |
Vkadaba | 8:2f2775c34640 | 1430 | default: |
Vkadaba | 8:2f2775c34640 | 1431 | ADMW_LOG_ERROR("Invalid RTD Curve %d specified", |
Vkadaba | 23:bb685f35b08b | 1432 | pAdcChannelConfig->rtdCurve); |
Vkadaba | 8:2f2775c34640 | 1433 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 1434 | } |
Vkadaba | 6:9d393a9677f4 | 1435 | |
Vkadaba | 23:bb685f35b08b | 1436 | if (pChannelConfig->disablePublishing) { |
ADIJake | 0:85855ecd3257 | 1437 | sensorDetailsReg.Do_Not_Publish = 1; |
Vkadaba | 23:bb685f35b08b | 1438 | } else { |
ADIJake | 0:85855ecd3257 | 1439 | sensorDetailsReg.Do_Not_Publish = 0; |
Vkadaba | 8:2f2775c34640 | 1440 | } |
Vkadaba | 23:bb685f35b08b | 1441 | |
Vkadaba | 23:bb685f35b08b | 1442 | switch (pChannelConfig->lutSelect) { |
Vkadaba | 8:2f2775c34640 | 1443 | case ADMW1001_LUT_DEFAULT: |
Vkadaba | 8:2f2775c34640 | 1444 | case ADMW1001_LUT_CUSTOM: |
Vkadaba | 8:2f2775c34640 | 1445 | sensorDetailsReg.LUT_Select = pChannelConfig->lutSelect; |
Vkadaba | 8:2f2775c34640 | 1446 | break; |
Vkadaba | 8:2f2775c34640 | 1447 | default: |
Vkadaba | 8:2f2775c34640 | 1448 | ADMW_LOG_ERROR("Invalid LUT selection %d specified", |
Vkadaba | 23:bb685f35b08b | 1449 | pChannelConfig->lutSelect); |
Vkadaba | 23:bb685f35b08b | 1450 | return ADMW_INVALID_PARAM; |
Vkadaba | 8:2f2775c34640 | 1451 | } |
Vkadaba | 23:bb685f35b08b | 1452 | |
ADIJake | 0:85855ecd3257 | 1453 | WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1454 | |
Vkadaba | 5:0728bde67bdb | 1455 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1456 | } |
ADIJake | 0:85855ecd3257 | 1457 | |
Vkadaba | 33:df7a00f1b8e1 | 1458 | static ADMW_RESULT admw_SetChannelAdcMeasurementSetup( |
Vkadaba | 5:0728bde67bdb | 1459 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1460 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 33:df7a00f1b8e1 | 1461 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig) |
ADIJake | 0:85855ecd3257 | 1462 | { |
Vkadaba | 8:2f2775c34640 | 1463 | ADMW_CORE_Measurement_Setup_t MeasSetupReg; |
Vkadaba | 33:df7a00f1b8e1 | 1464 | ADMW1001_ADC_FILTER_CONFIG *pFilterConfig = &pAdcChannelConfig->filter; |
Vkadaba | 6:9d393a9677f4 | 1465 | MeasSetupReg.VALUE32 = REG_RESET_VAL(CORE_MEASUREMENT_SETUPn); |
Vkadaba | 33:df7a00f1b8e1 | 1466 | MeasSetupReg.Buffer_Bypass = pAdcChannelConfig->bufferBypass; |
Vkadaba | 41:df78b7d7b675 | 1467 | |
Vkadaba | 23:bb685f35b08b | 1468 | if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC4) { |
Vkadaba | 6:9d393a9677f4 | 1469 | MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC4; |
Vkadaba | 6:9d393a9677f4 | 1470 | MeasSetupReg.ADC_SF = pFilterConfig->sf; |
Vkadaba | 23:bb685f35b08b | 1471 | } else if (pFilterConfig->type == ADMW1001_ADC_FILTER_SINC3) { |
Vkadaba | 6:9d393a9677f4 | 1472 | MeasSetupReg.ADC_Filter_Type = CORE_MEASUREMENT_SETUP_ENABLE_SINC3; |
Vkadaba | 23:bb685f35b08b | 1473 | MeasSetupReg.ADC_SF = pFilterConfig->sf; |
Vkadaba | 23:bb685f35b08b | 1474 | } else { |
Vkadaba | 5:0728bde67bdb | 1475 | ADMW_LOG_ERROR("Invalid ADC filter type %d specified", |
Vkadaba | 23:bb685f35b08b | 1476 | pFilterConfig->type); |
Vkadaba | 5:0728bde67bdb | 1477 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1478 | } |
Vkadaba | 23:bb685f35b08b | 1479 | |
Vkadaba | 8:2f2775c34640 | 1480 | /* chop mod ecan be 0 (none), 1 (HW, 2 (SW, 3 (HW+SW). */ |
Vkadaba | 17:2f0028880874 | 1481 | MeasSetupReg.Chop_Mode = pFilterConfig->chopMode; |
Vkadaba | 23:bb685f35b08b | 1482 | |
Vkadaba | 6:9d393a9677f4 | 1483 | if(pFilterConfig->notch1p2) |
Vkadaba | 6:9d393a9677f4 | 1484 | MeasSetupReg.NOTCH_EN_2 = 1; |
Vkadaba | 6:9d393a9677f4 | 1485 | else |
Vkadaba | 6:9d393a9677f4 | 1486 | MeasSetupReg.NOTCH_EN_2 = 0; |
Vkadaba | 23:bb685f35b08b | 1487 | |
Vkadaba | 6:9d393a9677f4 | 1488 | WRITE_REG_U32(hDevice, MeasSetupReg.VALUE32, CORE_MEASUREMENT_SETUPn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1489 | |
Vkadaba | 5:0728bde67bdb | 1490 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1491 | } |
ADIJake | 0:85855ecd3257 | 1492 | |
Vkadaba | 5:0728bde67bdb | 1493 | static ADMW_RESULT admw_SetChannelAdcCurrentConfig( |
Vkadaba | 5:0728bde67bdb | 1494 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1495 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1496 | ADMW1001_ADC_EXC_CURRENT_CONFIG *pCurrentConfig) |
ADIJake | 0:85855ecd3257 | 1497 | { |
Vkadaba | 8:2f2775c34640 | 1498 | ADMW_CORE_Channel_Excitation_t channelExcitationReg; |
ADIJake | 0:85855ecd3257 | 1499 | |
Vkadaba | 6:9d393a9677f4 | 1500 | channelExcitationReg.VALUE16 = REG_RESET_VAL(CORE_CHANNEL_EXCITATIONn); |
Vkadaba | 6:9d393a9677f4 | 1501 | |
Vkadaba | 18:cbf514cce921 | 1502 | if (pCurrentConfig->outputLevel == ADMW1001_ADC_NO_EXTERNAL_EXC_CURRENT) |
Vkadaba | 18:cbf514cce921 | 1503 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_NONE; |
Vkadaba | 18:cbf514cce921 | 1504 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_EXTERNAL) |
Vkadaba | 6:9d393a9677f4 | 1505 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_EXTERNAL; |
Vkadaba | 18:cbf514cce921 | 1506 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_50uA) |
Vkadaba | 6:9d393a9677f4 | 1507 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_50UA; |
Vkadaba | 6:9d393a9677f4 | 1508 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_100uA) |
Vkadaba | 6:9d393a9677f4 | 1509 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_100UA; |
Vkadaba | 6:9d393a9677f4 | 1510 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_250uA) |
Vkadaba | 6:9d393a9677f4 | 1511 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_250UA; |
Vkadaba | 6:9d393a9677f4 | 1512 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_500uA) |
Vkadaba | 6:9d393a9677f4 | 1513 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_500UA; |
Vkadaba | 6:9d393a9677f4 | 1514 | else if (pCurrentConfig->outputLevel == ADMW1001_ADC_EXC_CURRENT_1000uA) |
Vkadaba | 6:9d393a9677f4 | 1515 | channelExcitationReg.IOUT_Excitation_Current = CORE_CHANNEL_EXCITATION_IEXC_1000UA; |
Vkadaba | 23:bb685f35b08b | 1516 | else { |
Vkadaba | 6:9d393a9677f4 | 1517 | ADMW_LOG_ERROR("Invalid ADC excitation current %d specified", |
Vkadaba | 6:9d393a9677f4 | 1518 | pCurrentConfig->outputLevel); |
Vkadaba | 6:9d393a9677f4 | 1519 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1520 | } |
ADIJake | 0:85855ecd3257 | 1521 | |
Vkadaba | 6:9d393a9677f4 | 1522 | WRITE_REG_U16(hDevice, channelExcitationReg.VALUE16, CORE_CHANNEL_EXCITATIONn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1523 | |
Vkadaba | 5:0728bde67bdb | 1524 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1525 | } |
ADIJake | 0:85855ecd3257 | 1526 | |
Vkadaba | 5:0728bde67bdb | 1527 | ADMW_RESULT admw_SetAdcChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1528 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1529 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1530 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1531 | { |
Vkadaba | 5:0728bde67bdb | 1532 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1533 | ADMW1001_ADC_CHANNEL_CONFIG *pAdcChannelConfig = |
ADIJake | 0:85855ecd3257 | 1534 | &pChannelConfig->adcChannelConfig; |
ADIJake | 0:85855ecd3257 | 1535 | |
Vkadaba | 5:0728bde67bdb | 1536 | eRet = admw_SetChannelAdcSensorType(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1537 | pAdcChannelConfig->sensor); |
Vkadaba | 23:bb685f35b08b | 1538 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1539 | ADMW_LOG_ERROR("Failed to set ADC sensor type for channel %d", |
Vkadaba | 23:bb685f35b08b | 1540 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1541 | return eRet; |
ADIJake | 0:85855ecd3257 | 1542 | } |
ADIJake | 0:85855ecd3257 | 1543 | |
Vkadaba | 5:0728bde67bdb | 1544 | eRet = admw_SetChannelAdcSensorDetails(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1545 | pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1546 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1547 | ADMW_LOG_ERROR("Failed to set ADC sensor details for channel %d", |
Vkadaba | 23:bb685f35b08b | 1548 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1549 | return eRet; |
ADIJake | 0:85855ecd3257 | 1550 | } |
ADIJake | 0:85855ecd3257 | 1551 | |
Vkadaba | 33:df7a00f1b8e1 | 1552 | eRet = admw_SetChannelAdcMeasurementSetup(hDevice, eChannelId, |
Vkadaba | 41:df78b7d7b675 | 1553 | pAdcChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1554 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1555 | ADMW_LOG_ERROR("Failed to set ADC filter for channel %d", |
Vkadaba | 23:bb685f35b08b | 1556 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1557 | return eRet; |
ADIJake | 0:85855ecd3257 | 1558 | } |
ADIJake | 0:85855ecd3257 | 1559 | |
Vkadaba | 5:0728bde67bdb | 1560 | eRet = admw_SetChannelAdcCurrentConfig(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1561 | &pAdcChannelConfig->current); |
Vkadaba | 23:bb685f35b08b | 1562 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1563 | ADMW_LOG_ERROR("Failed to set ADC current for channel %d", |
Vkadaba | 23:bb685f35b08b | 1564 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1565 | return eRet; |
ADIJake | 0:85855ecd3257 | 1566 | } |
ADIJake | 0:85855ecd3257 | 1567 | |
Vkadaba | 5:0728bde67bdb | 1568 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1569 | } |
ADIJake | 0:85855ecd3257 | 1570 | |
Vkadaba | 5:0728bde67bdb | 1571 | static ADMW_RESULT admw_SetChannelDigitalSensorDetails( |
Vkadaba | 5:0728bde67bdb | 1572 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1573 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1574 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1575 | { |
Vkadaba | 8:2f2775c34640 | 1576 | ADMW_CORE_Sensor_Details_t sensorDetailsReg; |
ADIJake | 0:85855ecd3257 | 1577 | |
ADIJake | 0:85855ecd3257 | 1578 | sensorDetailsReg.VALUE32 = REG_RESET_VAL(CORE_SENSOR_DETAILSn); |
ADIJake | 0:85855ecd3257 | 1579 | |
Vkadaba | 23:bb685f35b08b | 1580 | if (pChannelConfig->compensationChannel == ADMW1001_CH_ID_NONE) { |
ADIJake | 0:85855ecd3257 | 1581 | sensorDetailsReg.Compensation_Disable = 1; |
ADIJake | 0:85855ecd3257 | 1582 | sensorDetailsReg.Compensation_Channel = 0; |
Vkadaba | 23:bb685f35b08b | 1583 | } else { |
Vkadaba | 5:0728bde67bdb | 1584 | ADMW_LOG_ERROR("Invalid compensation channel specified for digital sensor"); |
Vkadaba | 5:0728bde67bdb | 1585 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1586 | } |
ADIJake | 0:85855ecd3257 | 1587 | |
Vkadaba | 23:bb685f35b08b | 1588 | if (pChannelConfig->measurementUnit == ADMW1001_MEASUREMENT_UNIT_UNSPECIFIED) { |
Vkadaba | 5:0728bde67bdb | 1589 | sensorDetailsReg.Measurement_Units = CORE_SENSOR_DETAILS_UNITS_UNSPECIFIED; |
Vkadaba | 23:bb685f35b08b | 1590 | } else { |
Vkadaba | 5:0728bde67bdb | 1591 | ADMW_LOG_ERROR("Invalid measurement unit specified for digital channel"); |
Vkadaba | 5:0728bde67bdb | 1592 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1593 | } |
ADIJake | 0:85855ecd3257 | 1594 | |
ADIJake | 0:85855ecd3257 | 1595 | if (pChannelConfig->disablePublishing) |
ADIJake | 0:85855ecd3257 | 1596 | sensorDetailsReg.Do_Not_Publish = 1; |
ADIJake | 0:85855ecd3257 | 1597 | else |
ADIJake | 0:85855ecd3257 | 1598 | sensorDetailsReg.Do_Not_Publish = 0; |
ADIJake | 0:85855ecd3257 | 1599 | |
ADIJake | 0:85855ecd3257 | 1600 | WRITE_REG_U32(hDevice, sensorDetailsReg.VALUE32, CORE_SENSOR_DETAILSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1601 | |
Vkadaba | 5:0728bde67bdb | 1602 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1603 | } |
ADIJake | 0:85855ecd3257 | 1604 | |
Vkadaba | 5:0728bde67bdb | 1605 | static ADMW_RESULT admw_SetDigitalSensorFormat( |
Vkadaba | 5:0728bde67bdb | 1606 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1607 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1608 | ADMW1001_DIGITAL_SENSOR_DATA_FORMAT *pDataFormat) |
ADIJake | 0:85855ecd3257 | 1609 | { |
Vkadaba | 8:2f2775c34640 | 1610 | ADMW_CORE_Digital_Sensor_Config_t sensorConfigReg; |
ADIJake | 0:85855ecd3257 | 1611 | |
ADIJake | 0:85855ecd3257 | 1612 | sensorConfigReg.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_CONFIGn); |
ADIJake | 0:85855ecd3257 | 1613 | |
Vkadaba | 23:bb685f35b08b | 1614 | if (pDataFormat->coding != ADMW1001_DIGITAL_SENSOR_DATA_CODING_NONE) { |
Vkadaba | 23:bb685f35b08b | 1615 | if (pDataFormat->frameLength == 0) { |
Vkadaba | 5:0728bde67bdb | 1616 | ADMW_LOG_ERROR("Invalid frame length specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 1617 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1618 | } |
Vkadaba | 23:bb685f35b08b | 1619 | if (pDataFormat->numDataBits == 0) { |
Vkadaba | 5:0728bde67bdb | 1620 | ADMW_LOG_ERROR("Invalid frame length specified for digital sensor data format"); |
Vkadaba | 5:0728bde67bdb | 1621 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1622 | } |
ADIJake | 0:85855ecd3257 | 1623 | |
ADIJake | 0:85855ecd3257 | 1624 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_READ_BYTES, |
ADIJake | 0:85855ecd3257 | 1625 | pDataFormat->frameLength - 1); |
ADIJake | 0:85855ecd3257 | 1626 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_DATA_BITS, |
ADIJake | 0:85855ecd3257 | 1627 | pDataFormat->numDataBits - 1); |
ADIJake | 0:85855ecd3257 | 1628 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_CONFIG_DIGITAL_SENSOR_BIT_OFFSET, |
ADIJake | 0:85855ecd3257 | 1629 | pDataFormat->bitOffset); |
ADIJake | 0:85855ecd3257 | 1630 | |
ADIJake | 0:85855ecd3257 | 1631 | sensorConfigReg.Digital_Sensor_Read_Bytes = pDataFormat->frameLength - 1; |
ADIJake | 0:85855ecd3257 | 1632 | sensorConfigReg.Digital_Sensor_Data_Bits = pDataFormat->numDataBits - 1; |
ADIJake | 0:85855ecd3257 | 1633 | sensorConfigReg.Digital_Sensor_Bit_Offset = pDataFormat->bitOffset; |
ADIJake | 0:85855ecd3257 | 1634 | sensorConfigReg.Digital_Sensor_Left_Aligned = pDataFormat->leftJustified ? 1 : 0; |
ADIJake | 0:85855ecd3257 | 1635 | sensorConfigReg.Digital_Sensor_Little_Endian = pDataFormat->littleEndian ? 1 : 0; |
ADIJake | 0:85855ecd3257 | 1636 | |
Vkadaba | 23:bb685f35b08b | 1637 | switch (pDataFormat->coding) { |
Vkadaba | 23:bb685f35b08b | 1638 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_UNIPOLAR: |
Vkadaba | 23:bb685f35b08b | 1639 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_UNIPOLAR; |
Vkadaba | 23:bb685f35b08b | 1640 | break; |
Vkadaba | 23:bb685f35b08b | 1641 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_TWOS_COMPLEMENT: |
Vkadaba | 23:bb685f35b08b | 1642 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_TWOS_COMPL; |
Vkadaba | 23:bb685f35b08b | 1643 | break; |
Vkadaba | 23:bb685f35b08b | 1644 | case ADMW1001_DIGITAL_SENSOR_DATA_CODING_OFFSET_BINARY: |
Vkadaba | 23:bb685f35b08b | 1645 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_OFFSET_BINARY; |
Vkadaba | 23:bb685f35b08b | 1646 | break; |
Vkadaba | 23:bb685f35b08b | 1647 | default: |
Vkadaba | 23:bb685f35b08b | 1648 | ADMW_LOG_ERROR("Invalid coding specified for digital sensor data format"); |
Vkadaba | 23:bb685f35b08b | 1649 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1650 | } |
Vkadaba | 23:bb685f35b08b | 1651 | } else { |
Vkadaba | 5:0728bde67bdb | 1652 | sensorConfigReg.Digital_Sensor_Coding = CORE_DIGITAL_SENSOR_CONFIG_CODING_NONE; |
ADIJake | 0:85855ecd3257 | 1653 | } |
ADIJake | 0:85855ecd3257 | 1654 | |
ADIJake | 0:85855ecd3257 | 1655 | WRITE_REG_U16(hDevice, sensorConfigReg.VALUE16, |
ADIJake | 0:85855ecd3257 | 1656 | CORE_DIGITAL_SENSOR_CONFIGn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1657 | |
ADIJake | 0:85855ecd3257 | 1658 | |
Vkadaba | 5:0728bde67bdb | 1659 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1660 | } |
ADIJake | 0:85855ecd3257 | 1661 | |
ADIJake | 0:85855ecd3257 | 1662 | |
Vkadaba | 5:0728bde67bdb | 1663 | static ADMW_RESULT admw_SetChannelI2cSensorType( |
Vkadaba | 5:0728bde67bdb | 1664 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1665 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1666 | ADMW1001_I2C_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1667 | { |
Vkadaba | 8:2f2775c34640 | 1668 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1669 | |
ADIJake | 0:85855ecd3257 | 1670 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1671 | |
ADIJake | 0:85855ecd3257 | 1672 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1673 | switch(sensorType) { |
Vkadaba | 58:aa9cd5072f66 | 1674 | case ADMW1001_I2C_SENSOR_HUMIDITY: |
Vkadaba | 50:d84305e5e1c0 | 1675 | case ADMW1001_I2C_SENSOR_TEMPERATURE_ADT742X: |
Vkadaba | 8:2f2775c34640 | 1676 | sensorTypeReg.Sensor_Type = sensorType; |
Vkadaba | 8:2f2775c34640 | 1677 | break; |
Vkadaba | 8:2f2775c34640 | 1678 | default: |
Vkadaba | 8:2f2775c34640 | 1679 | ADMW_LOG_ERROR("Unsupported I2C sensor type %d specified", sensorType); |
Vkadaba | 8:2f2775c34640 | 1680 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1681 | } |
ADIJake | 0:85855ecd3257 | 1682 | |
ADIJake | 0:85855ecd3257 | 1683 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1684 | |
Vkadaba | 5:0728bde67bdb | 1685 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1686 | } |
ADIJake | 0:85855ecd3257 | 1687 | |
Vkadaba | 5:0728bde67bdb | 1688 | static ADMW_RESULT admw_SetChannelI2cSensorAddress( |
Vkadaba | 5:0728bde67bdb | 1689 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1690 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1691 | uint32_t deviceAddress) |
ADIJake | 0:85855ecd3257 | 1692 | { |
ADIJake | 0:85855ecd3257 | 1693 | CHECK_REG_FIELD_VAL(CORE_DIGITAL_SENSOR_ADDRESS_DIGITAL_SENSOR_ADDRESS, deviceAddress); |
ADIJake | 0:85855ecd3257 | 1694 | WRITE_REG_U8(hDevice, deviceAddress, CORE_DIGITAL_SENSOR_ADDRESSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1695 | |
Vkadaba | 5:0728bde67bdb | 1696 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1697 | } |
ADIJake | 0:85855ecd3257 | 1698 | |
Vkadaba | 5:0728bde67bdb | 1699 | static ADMW_RESULT admw_SetDigitalChannelComms( |
Vkadaba | 5:0728bde67bdb | 1700 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1701 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1702 | ADMW1001_DIGITAL_SENSOR_COMMS *pDigitalComms) |
ADIJake | 0:85855ecd3257 | 1703 | { |
Vkadaba | 8:2f2775c34640 | 1704 | ADMW_CORE_Digital_Sensor_Comms_t digitalSensorComms; |
ADIJake | 0:85855ecd3257 | 1705 | |
ADIJake | 0:85855ecd3257 | 1706 | digitalSensorComms.VALUE16 = REG_RESET_VAL(CORE_DIGITAL_SENSOR_COMMSn); |
ADIJake | 0:85855ecd3257 | 1707 | |
Vkadaba | 23:bb685f35b08b | 1708 | if(pDigitalComms->useCustomCommsConfig) { |
ADIJake | 0:85855ecd3257 | 1709 | |
Vkadaba | 23:bb685f35b08b | 1710 | if(pDigitalComms->i2cClockSpeed == ADMW1001_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_100K) { |
Vkadaba | 5:0728bde67bdb | 1711 | digitalSensorComms.I2C_Clock = CORE_DIGITAL_SENSOR_COMMS_I2C_100K; |
Vkadaba | 23:bb685f35b08b | 1712 | } else if(pDigitalComms->i2cClockSpeed == ADMW1001_DIGITAL_SENSOR_COMMS_I2C_CLOCK_SPEED_400K) { |
Vkadaba | 5:0728bde67bdb | 1713 | digitalSensorComms.I2C_Clock = CORE_DIGITAL_SENSOR_COMMS_I2C_400K; |
Vkadaba | 23:bb685f35b08b | 1714 | } else { |
Vkadaba | 5:0728bde67bdb | 1715 | ADMW_LOG_ERROR("Invalid I2C clock speed %d specified", |
Vkadaba | 23:bb685f35b08b | 1716 | pDigitalComms->i2cClockSpeed); |
Vkadaba | 5:0728bde67bdb | 1717 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1718 | } |
Vkadaba | 63:2655a04c00f5 | 1719 | } |
ADIJake | 0:85855ecd3257 | 1720 | WRITE_REG_U16(hDevice, digitalSensorComms.VALUE16, CORE_DIGITAL_SENSOR_COMMSn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1721 | |
Vkadaba | 5:0728bde67bdb | 1722 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1723 | } |
ADIJake | 0:85855ecd3257 | 1724 | |
Vkadaba | 5:0728bde67bdb | 1725 | ADMW_RESULT admw_SetI2cChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1726 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1727 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1728 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1729 | { |
Vkadaba | 5:0728bde67bdb | 1730 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1731 | ADMW1001_I2C_CHANNEL_CONFIG *pI2cChannelConfig = |
ADIJake | 0:85855ecd3257 | 1732 | &pChannelConfig->i2cChannelConfig; |
ADIJake | 0:85855ecd3257 | 1733 | |
Vkadaba | 5:0728bde67bdb | 1734 | eRet = admw_SetChannelI2cSensorType(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1735 | pI2cChannelConfig->sensor); |
Vkadaba | 23:bb685f35b08b | 1736 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1737 | ADMW_LOG_ERROR("Failed to set I2C sensor type for channel %d", |
Vkadaba | 23:bb685f35b08b | 1738 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1739 | return eRet; |
ADIJake | 0:85855ecd3257 | 1740 | } |
ADIJake | 0:85855ecd3257 | 1741 | |
Vkadaba | 5:0728bde67bdb | 1742 | eRet = admw_SetChannelI2cSensorAddress(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1743 | pI2cChannelConfig->deviceAddress); |
Vkadaba | 23:bb685f35b08b | 1744 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1745 | ADMW_LOG_ERROR("Failed to set I2C sensor address for channel %d", |
Vkadaba | 23:bb685f35b08b | 1746 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1747 | return eRet; |
ADIJake | 0:85855ecd3257 | 1748 | } |
ADIJake | 0:85855ecd3257 | 1749 | |
Vkadaba | 5:0728bde67bdb | 1750 | eRet = admw_SetChannelDigitalSensorDetails(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1751 | pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1752 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1753 | ADMW_LOG_ERROR("Failed to set I2C sensor details for channel %d", |
Vkadaba | 23:bb685f35b08b | 1754 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1755 | return eRet; |
ADIJake | 0:85855ecd3257 | 1756 | } |
ADIJake | 0:85855ecd3257 | 1757 | |
Vkadaba | 5:0728bde67bdb | 1758 | eRet = admw_SetDigitalSensorFormat(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1759 | &pI2cChannelConfig->dataFormat); |
Vkadaba | 23:bb685f35b08b | 1760 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1761 | ADMW_LOG_ERROR("Failed to set I2C sensor data format for channel %d", |
Vkadaba | 23:bb685f35b08b | 1762 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1763 | return eRet; |
ADIJake | 0:85855ecd3257 | 1764 | } |
ADIJake | 0:85855ecd3257 | 1765 | |
ADIJake | 0:85855ecd3257 | 1766 | |
Vkadaba | 5:0728bde67bdb | 1767 | eRet = admw_SetDigitalChannelComms(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1768 | &pI2cChannelConfig->configureComms); |
Vkadaba | 23:bb685f35b08b | 1769 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1770 | ADMW_LOG_ERROR("Failed to set I2C comms for channel %d", |
Vkadaba | 23:bb685f35b08b | 1771 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1772 | return eRet; |
ADIJake | 0:85855ecd3257 | 1773 | } |
ADIJake | 0:85855ecd3257 | 1774 | |
Vkadaba | 5:0728bde67bdb | 1775 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1776 | } |
ADIJake | 0:85855ecd3257 | 1777 | |
Vkadaba | 5:0728bde67bdb | 1778 | static ADMW_RESULT admw_SetChannelSpiSensorType( |
Vkadaba | 5:0728bde67bdb | 1779 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1780 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1781 | ADMW1001_SPI_SENSOR_TYPE sensorType) |
ADIJake | 0:85855ecd3257 | 1782 | { |
Vkadaba | 8:2f2775c34640 | 1783 | ADMW_CORE_Sensor_Type_t sensorTypeReg; |
ADIJake | 0:85855ecd3257 | 1784 | |
ADIJake | 0:85855ecd3257 | 1785 | sensorTypeReg.VALUE16 = REG_RESET_VAL(CORE_SENSOR_TYPEn); |
ADIJake | 0:85855ecd3257 | 1786 | |
ADIJake | 0:85855ecd3257 | 1787 | /* Ensure that the sensor type is valid for this channel */ |
Vkadaba | 23:bb685f35b08b | 1788 | switch(sensorType) { |
Vkadaba | 58:aa9cd5072f66 | 1789 | case ADMW1001_SPI_SENSOR: |
Vkadaba | 23:bb685f35b08b | 1790 | |
Vkadaba | 23:bb685f35b08b | 1791 | sensorTypeReg.Sensor_Type = sensorType; |
Vkadaba | 23:bb685f35b08b | 1792 | break; |
Vkadaba | 23:bb685f35b08b | 1793 | default: |
Vkadaba | 23:bb685f35b08b | 1794 | ADMW_LOG_ERROR("Unsupported SPI sensor type %d specified", sensorType); |
Vkadaba | 23:bb685f35b08b | 1795 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1796 | } |
ADIJake | 0:85855ecd3257 | 1797 | |
ADIJake | 0:85855ecd3257 | 1798 | WRITE_REG_U16(hDevice, sensorTypeReg.VALUE16, CORE_SENSOR_TYPEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1799 | |
Vkadaba | 5:0728bde67bdb | 1800 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1801 | } |
ADIJake | 0:85855ecd3257 | 1802 | |
ADIJake | 0:85855ecd3257 | 1803 | |
Vkadaba | 5:0728bde67bdb | 1804 | ADMW_RESULT admw1001_SetChannelThresholdLimits( |
Vkadaba | 5:0728bde67bdb | 1805 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1806 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1807 | float32_t fHighThresholdLimit, |
ADIJake | 0:85855ecd3257 | 1808 | float32_t fLowThresholdLimit) |
ADIJake | 0:85855ecd3257 | 1809 | { |
ADIJake | 0:85855ecd3257 | 1810 | /* |
ADIJake | 0:85855ecd3257 | 1811 | * If the low/high limits are *both* set to 0 in memory, or NaNs, assume |
ADIJake | 0:85855ecd3257 | 1812 | * that they are unset, or not required, and use infinity defaults instead |
ADIJake | 0:85855ecd3257 | 1813 | */ |
Vkadaba | 23:bb685f35b08b | 1814 | if (fHighThresholdLimit == 0.0f && fLowThresholdLimit == 0.0f) { |
ADIJake | 0:85855ecd3257 | 1815 | fHighThresholdLimit = INFINITY; |
ADIJake | 0:85855ecd3257 | 1816 | fLowThresholdLimit = -INFINITY; |
Vkadaba | 23:bb685f35b08b | 1817 | } else { |
ADIJake | 0:85855ecd3257 | 1818 | if (isnan(fHighThresholdLimit)) |
ADIJake | 0:85855ecd3257 | 1819 | fHighThresholdLimit = INFINITY; |
ADIJake | 0:85855ecd3257 | 1820 | if (isnan(fLowThresholdLimit)) |
ADIJake | 0:85855ecd3257 | 1821 | fLowThresholdLimit = -INFINITY; |
ADIJake | 0:85855ecd3257 | 1822 | } |
ADIJake | 0:85855ecd3257 | 1823 | |
ADIJake | 0:85855ecd3257 | 1824 | WRITE_REG_FLOAT(hDevice, fHighThresholdLimit, |
ADIJake | 0:85855ecd3257 | 1825 | CORE_HIGH_THRESHOLD_LIMITn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1826 | WRITE_REG_FLOAT(hDevice, fLowThresholdLimit, |
ADIJake | 0:85855ecd3257 | 1827 | CORE_LOW_THRESHOLD_LIMITn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1828 | |
Vkadaba | 5:0728bde67bdb | 1829 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1830 | } |
ADIJake | 0:85855ecd3257 | 1831 | |
Vkadaba | 5:0728bde67bdb | 1832 | ADMW_RESULT admw1001_SetOffsetGain( |
Vkadaba | 5:0728bde67bdb | 1833 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1834 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1835 | float32_t fOffsetAdjustment, |
ADIJake | 0:85855ecd3257 | 1836 | float32_t fGainAdjustment) |
ADIJake | 0:85855ecd3257 | 1837 | { |
ADIJake | 0:85855ecd3257 | 1838 | /* Replace with default values if NaNs are specified (or 0.0 for gain) */ |
ADIJake | 0:85855ecd3257 | 1839 | if (isnan(fGainAdjustment) || (fGainAdjustment == 0.0f)) |
ADIJake | 0:85855ecd3257 | 1840 | fGainAdjustment = 1.0f; |
ADIJake | 0:85855ecd3257 | 1841 | if (isnan(fOffsetAdjustment)) |
ADIJake | 0:85855ecd3257 | 1842 | fOffsetAdjustment = 0.0f; |
ADIJake | 0:85855ecd3257 | 1843 | |
ADIJake | 0:85855ecd3257 | 1844 | WRITE_REG_FLOAT(hDevice, fGainAdjustment, CORE_SENSOR_GAINn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1845 | WRITE_REG_FLOAT(hDevice, fOffsetAdjustment, CORE_SENSOR_OFFSETn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1846 | |
Vkadaba | 5:0728bde67bdb | 1847 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1848 | } |
ADIJake | 0:85855ecd3257 | 1849 | |
Vkadaba | 5:0728bde67bdb | 1850 | ADMW_RESULT admw1001_SetSensorParameter( |
Vkadaba | 5:0728bde67bdb | 1851 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1852 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1853 | float32_t fSensorParam) |
ADIJake | 0:85855ecd3257 | 1854 | { |
ADIJake | 0:85855ecd3257 | 1855 | if (fSensorParam == 0.0f) |
ADIJake | 0:85855ecd3257 | 1856 | fSensorParam = NAN; |
ADIJake | 0:85855ecd3257 | 1857 | |
Vkadaba | 32:52445bef314d | 1858 | //WRITE_REG_FLOAT(hDevice, fSensorParam, CORE_SENSOR_PARAMETERn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1859 | |
Vkadaba | 5:0728bde67bdb | 1860 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1861 | } |
ADIJake | 0:85855ecd3257 | 1862 | |
Vkadaba | 5:0728bde67bdb | 1863 | ADMW_RESULT admw1001_SetChannelSettlingTime( |
Vkadaba | 5:0728bde67bdb | 1864 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1865 | ADMW1001_CH_ID eChannelId, |
ADIJake | 0:85855ecd3257 | 1866 | uint32_t nSettlingTime) |
ADIJake | 0:85855ecd3257 | 1867 | { |
Vkadaba | 8:2f2775c34640 | 1868 | ADMW_CORE_Settling_Time_t settlingTimeReg; |
ADIJake | 0:85855ecd3257 | 1869 | |
ADIJake | 0:85855ecd3257 | 1870 | CHECK_REG_FIELD_VAL(CORE_SETTLING_TIME_SETTLING_TIME, nSettlingTime); |
ADIJake | 0:85855ecd3257 | 1871 | settlingTimeReg.Settling_Time = nSettlingTime; |
ADIJake | 0:85855ecd3257 | 1872 | |
ADIJake | 0:85855ecd3257 | 1873 | WRITE_REG_U16(hDevice, settlingTimeReg.VALUE16, CORE_SETTLING_TIMEn(eChannelId)); |
ADIJake | 0:85855ecd3257 | 1874 | |
Vkadaba | 5:0728bde67bdb | 1875 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1876 | } |
ADIJake | 0:85855ecd3257 | 1877 | |
Vkadaba | 5:0728bde67bdb | 1878 | ADMW_RESULT admw1001_SetChannelConfig( |
Vkadaba | 5:0728bde67bdb | 1879 | ADMW_DEVICE_HANDLE hDevice, |
Vkadaba | 8:2f2775c34640 | 1880 | ADMW1001_CH_ID eChannelId, |
Vkadaba | 5:0728bde67bdb | 1881 | ADMW1001_CHANNEL_CONFIG *pChannelConfig) |
ADIJake | 0:85855ecd3257 | 1882 | { |
Vkadaba | 5:0728bde67bdb | 1883 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1884 | |
Vkadaba | 5:0728bde67bdb | 1885 | eRet = admw1001_SetChannelCount(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1886 | pChannelConfig->enableChannel ? |
Vkadaba | 23:bb685f35b08b | 1887 | pChannelConfig->measurementsPerCycle : 0); |
Vkadaba | 23:bb685f35b08b | 1888 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1889 | ADMW_LOG_ERROR("Failed to set measurement count for channel %d", |
Vkadaba | 23:bb685f35b08b | 1890 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1891 | return eRet; |
ADIJake | 0:85855ecd3257 | 1892 | } |
ADIJake | 0:85855ecd3257 | 1893 | |
Vkadaba | 5:0728bde67bdb | 1894 | eRet = admw1001_SetChannelOptions(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1895 | pChannelConfig->priority); |
Vkadaba | 23:bb685f35b08b | 1896 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1897 | ADMW_LOG_ERROR("Failed to set priority for channel %d", |
Vkadaba | 23:bb685f35b08b | 1898 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1899 | return eRet; |
ADIJake | 0:85855ecd3257 | 1900 | } |
ADIJake | 0:85855ecd3257 | 1901 | |
ADIJake | 0:85855ecd3257 | 1902 | /* If the channel is not enabled, we can skip the following steps */ |
Vkadaba | 23:bb685f35b08b | 1903 | if (pChannelConfig->enableChannel) { |
Vkadaba | 5:0728bde67bdb | 1904 | eRet = admw1001_SetChannelSkipCount(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1905 | pChannelConfig->cycleSkipCount); |
Vkadaba | 23:bb685f35b08b | 1906 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1907 | ADMW_LOG_ERROR("Failed to set cycle skip count for channel %d", |
Vkadaba | 23:bb685f35b08b | 1908 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1909 | return eRet; |
ADIJake | 0:85855ecd3257 | 1910 | } |
ADIJake | 0:85855ecd3257 | 1911 | |
Vkadaba | 23:bb685f35b08b | 1912 | switch (eChannelId) { |
Vkadaba | 23:bb685f35b08b | 1913 | case ADMW1001_CH_ID_ANLG_1_UNIVERSAL: |
Vkadaba | 23:bb685f35b08b | 1914 | case ADMW1001_CH_ID_ANLG_2_UNIVERSAL: |
Vkadaba | 23:bb685f35b08b | 1915 | case ADMW1001_CH_ID_ANLG_1_DIFFERENTIAL: |
Vkadaba | 23:bb685f35b08b | 1916 | case ADMW1001_CH_ID_ANLG_2_DIFFERENTIAL: |
Vkadaba | 23:bb685f35b08b | 1917 | eRet = admw_SetAdcChannelConfig(hDevice, eChannelId, pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1918 | break; |
Vkadaba | 23:bb685f35b08b | 1919 | case ADMW1001_CH_ID_DIG_I2C_0: |
Vkadaba | 23:bb685f35b08b | 1920 | case ADMW1001_CH_ID_DIG_I2C_1: |
Vkadaba | 23:bb685f35b08b | 1921 | eRet = admw_SetI2cChannelConfig(hDevice, eChannelId, pChannelConfig); |
Vkadaba | 23:bb685f35b08b | 1922 | break; |
Vkadaba | 23:bb685f35b08b | 1923 | default: |
Vkadaba | 23:bb685f35b08b | 1924 | ADMW_LOG_ERROR("Invalid channel ID %d specified", eChannelId); |
Vkadaba | 32:52445bef314d | 1925 | eRet = ADMW_INVALID_PARAM; |
Vkadaba | 32:52445bef314d | 1926 | #if 0 |
Vkadaba | 32:52445bef314d | 1927 | /* when using i2c sensors there is an error ( dataformat->length=0) |
Vkadaba | 32:52445bef314d | 1928 | the code below catches this error and this causes further problems.*/ |
Vkadaba | 32:52445bef314d | 1929 | break; |
Vkadaba | 32:52445bef314d | 1930 | } |
Vkadaba | 32:52445bef314d | 1931 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 32:52445bef314d | 1932 | ADMW_LOG_ERROR("Failed to set config for channel %d", |
Vkadaba | 32:52445bef314d | 1933 | eChannelId); |
Vkadaba | 32:52445bef314d | 1934 | return eRet; |
Vkadaba | 32:52445bef314d | 1935 | #endif |
ADIJake | 0:85855ecd3257 | 1936 | } |
ADIJake | 0:85855ecd3257 | 1937 | |
Vkadaba | 5:0728bde67bdb | 1938 | eRet = admw1001_SetChannelSettlingTime(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1939 | pChannelConfig->extraSettlingTime); |
Vkadaba | 23:bb685f35b08b | 1940 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1941 | ADMW_LOG_ERROR("Failed to set settling time for channel %d", |
Vkadaba | 23:bb685f35b08b | 1942 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1943 | return eRet; |
ADIJake | 0:85855ecd3257 | 1944 | } |
ADIJake | 0:85855ecd3257 | 1945 | } |
ADIJake | 0:85855ecd3257 | 1946 | |
Vkadaba | 23:bb685f35b08b | 1947 | if (pChannelConfig->enableChannel) { |
ADIJake | 0:85855ecd3257 | 1948 | /* Threshold limits can be configured individually for virtual channels */ |
Vkadaba | 5:0728bde67bdb | 1949 | eRet = admw1001_SetChannelThresholdLimits(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1950 | pChannelConfig->highThreshold, |
Vkadaba | 23:bb685f35b08b | 1951 | pChannelConfig->lowThreshold); |
Vkadaba | 23:bb685f35b08b | 1952 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1953 | ADMW_LOG_ERROR("Failed to set threshold limits for channel %d", |
Vkadaba | 23:bb685f35b08b | 1954 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1955 | return eRet; |
ADIJake | 0:85855ecd3257 | 1956 | } |
ADIJake | 0:85855ecd3257 | 1957 | |
ADIJake | 0:85855ecd3257 | 1958 | /* Offset and gain can be configured individually for virtual channels */ |
Vkadaba | 5:0728bde67bdb | 1959 | eRet = admw1001_SetOffsetGain(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1960 | pChannelConfig->offsetAdjustment, |
Vkadaba | 23:bb685f35b08b | 1961 | pChannelConfig->gainAdjustment); |
Vkadaba | 23:bb685f35b08b | 1962 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1963 | ADMW_LOG_ERROR("Failed to set offset/gain for channel %d", |
Vkadaba | 23:bb685f35b08b | 1964 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1965 | return eRet; |
ADIJake | 0:85855ecd3257 | 1966 | } |
ADIJake | 0:85855ecd3257 | 1967 | |
ADIJake | 0:85855ecd3257 | 1968 | /* Set sensor specific parameter */ |
Vkadaba | 5:0728bde67bdb | 1969 | eRet = admw1001_SetSensorParameter(hDevice, eChannelId, |
Vkadaba | 23:bb685f35b08b | 1970 | pChannelConfig->sensorParameter); |
Vkadaba | 23:bb685f35b08b | 1971 | if (eRet != ADMW_SUCCESS) { |
Vkadaba | 5:0728bde67bdb | 1972 | ADMW_LOG_ERROR("Failed to set sensor parameter for channel %d", |
Vkadaba | 23:bb685f35b08b | 1973 | eChannelId); |
ADIJake | 0:85855ecd3257 | 1974 | return eRet; |
ADIJake | 0:85855ecd3257 | 1975 | } |
ADIJake | 0:85855ecd3257 | 1976 | } |
ADIJake | 0:85855ecd3257 | 1977 | |
Vkadaba | 5:0728bde67bdb | 1978 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 1979 | } |
ADIJake | 0:85855ecd3257 | 1980 | |
Vkadaba | 5:0728bde67bdb | 1981 | ADMW_RESULT admw_SetConfig( |
Vkadaba | 5:0728bde67bdb | 1982 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 1983 | ADMW_CONFIG * const pConfig) |
ADIJake | 0:85855ecd3257 | 1984 | { |
Vkadaba | 5:0728bde67bdb | 1985 | ADMW1001_CONFIG *pDeviceConfig; |
Vkadaba | 5:0728bde67bdb | 1986 | ADMW_PRODUCT_ID productId; |
Vkadaba | 5:0728bde67bdb | 1987 | ADMW_RESULT eRet; |
Vkadaba | 5:0728bde67bdb | 1988 | |
Vkadaba | 23:bb685f35b08b | 1989 | if (pConfig->productId != ADMW_PRODUCT_ID_ADMW1001) { |
Vkadaba | 5:0728bde67bdb | 1990 | ADMW_LOG_ERROR("Configuration Product ID (0x%X) is not supported (0x%0X)", |
Vkadaba | 23:bb685f35b08b | 1991 | pConfig->productId, ADMW_PRODUCT_ID_ADMW1001); |
Vkadaba | 5:0728bde67bdb | 1992 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 1993 | } |
Vkadaba | 23:bb685f35b08b | 1994 | |
Vkadaba | 23:bb685f35b08b | 1995 | if (!((pConfig->versionId.major==VERSIONID_MAJOR) && |
Vkadaba | 23:bb685f35b08b | 1996 | (pConfig->versionId.minor==VERSIONID_MINOR))) { |
Vkadaba | 23:bb685f35b08b | 1997 | ADMW_LOG_ERROR("Configuration Version ID (0x%X) is not supported", |
Vkadaba | 23:bb685f35b08b | 1998 | pConfig->versionId); |
Vkadaba | 6:9d393a9677f4 | 1999 | return ADMW_INVALID_PARAM; |
Vkadaba | 6:9d393a9677f4 | 2000 | } |
Vkadaba | 23:bb685f35b08b | 2001 | |
Vkadaba | 23:bb685f35b08b | 2002 | |
ADIJake | 0:85855ecd3257 | 2003 | /* Check that the actual Product ID is a match? */ |
Vkadaba | 5:0728bde67bdb | 2004 | eRet = admw_GetProductID(hDevice, &productId); |
Vkadaba | 23:bb685f35b08b | 2005 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2006 | ADMW_LOG_ERROR("Failed to read device Product ID register"); |
ADIJake | 0:85855ecd3257 | 2007 | return eRet; |
ADIJake | 0:85855ecd3257 | 2008 | } |
Vkadaba | 23:bb685f35b08b | 2009 | if (pConfig->productId != productId) { |
Vkadaba | 5:0728bde67bdb | 2010 | ADMW_LOG_ERROR("Configuration Product ID (0x%X) does not match device (0x%0X)", |
Vkadaba | 8:2f2775c34640 | 2011 | pConfig->productId, productId); |
Vkadaba | 5:0728bde67bdb | 2012 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2013 | } |
ADIJake | 0:85855ecd3257 | 2014 | |
Vkadaba | 5:0728bde67bdb | 2015 | pDeviceConfig = &pConfig->admw1001; |
Vkadaba | 5:0728bde67bdb | 2016 | |
Vkadaba | 5:0728bde67bdb | 2017 | eRet = admw1001_SetPowerConfig(hDevice, &pDeviceConfig->power); |
Vkadaba | 23:bb685f35b08b | 2018 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2019 | ADMW_LOG_ERROR("Failed to set power configuration"); |
ADIJake | 0:85855ecd3257 | 2020 | return eRet; |
ADIJake | 0:85855ecd3257 | 2021 | } |
ADIJake | 0:85855ecd3257 | 2022 | |
Vkadaba | 5:0728bde67bdb | 2023 | eRet = admw1001_SetMeasurementConfig(hDevice, &pDeviceConfig->measurement); |
Vkadaba | 23:bb685f35b08b | 2024 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2025 | ADMW_LOG_ERROR("Failed to set measurement configuration"); |
ADIJake | 0:85855ecd3257 | 2026 | return eRet; |
ADIJake | 0:85855ecd3257 | 2027 | } |
ADIJake | 0:85855ecd3257 | 2028 | |
Vkadaba | 36:54e2418e7620 | 2029 | eRet = admw1001_SetDiagnosticsConfig(hDevice, &pDeviceConfig->diagnostics); |
Vkadaba | 41:df78b7d7b675 | 2030 | if (eRet) { |
Vkadaba | 36:54e2418e7620 | 2031 | ADMW_LOG_ERROR("Failed to set diagnostics configuration"); |
Vkadaba | 36:54e2418e7620 | 2032 | return eRet; |
Vkadaba | 36:54e2418e7620 | 2033 | } |
ADIJake | 0:85855ecd3257 | 2034 | |
Vkadaba | 8:2f2775c34640 | 2035 | for (ADMW1001_CH_ID id = ADMW1001_CH_ID_ANLG_1_UNIVERSAL; |
Vkadaba | 23:bb685f35b08b | 2036 | id < ADMW1001_MAX_CHANNELS; |
Vkadaba | 23:bb685f35b08b | 2037 | id++) { |
Vkadaba | 5:0728bde67bdb | 2038 | eRet = admw1001_SetChannelConfig(hDevice, id, |
Vkadaba | 23:bb685f35b08b | 2039 | &pDeviceConfig->channels[id]); |
Vkadaba | 23:bb685f35b08b | 2040 | if (eRet) { |
Vkadaba | 5:0728bde67bdb | 2041 | ADMW_LOG_ERROR("Failed to set channel %d configuration", id); |
ADIJake | 0:85855ecd3257 | 2042 | return eRet; |
ADIJake | 0:85855ecd3257 | 2043 | } |
ADIJake | 0:85855ecd3257 | 2044 | } |
ADIJake | 0:85855ecd3257 | 2045 | |
Vkadaba | 5:0728bde67bdb | 2046 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2047 | } |
ADIJake | 0:85855ecd3257 | 2048 | |
Vkadaba | 50:d84305e5e1c0 | 2049 | |
Vkadaba | 5:0728bde67bdb | 2050 | ADMW_RESULT admw1001_SetLutDataRaw( |
Vkadaba | 5:0728bde67bdb | 2051 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 5:0728bde67bdb | 2052 | ADMW1001_LUT_RAW * const pLutData) |
ADIJake | 0:85855ecd3257 | 2053 | { |
Vkadaba | 5:0728bde67bdb | 2054 | return admw1001_SetLutData(hDevice, |
Vkadaba | 23:bb685f35b08b | 2055 | (ADMW1001_LUT *)pLutData); |
ADIJake | 0:85855ecd3257 | 2056 | } |
ADIJake | 0:85855ecd3257 | 2057 | |
Vkadaba | 5:0728bde67bdb | 2058 | static ADMW_RESULT getLutTableSize( |
Vkadaba | 5:0728bde67bdb | 2059 | ADMW1001_LUT_DESCRIPTOR * const pDesc, |
Vkadaba | 5:0728bde67bdb | 2060 | ADMW1001_LUT_TABLE_DATA * const pData, |
ADIJake | 0:85855ecd3257 | 2061 | unsigned *pLength) |
ADIJake | 0:85855ecd3257 | 2062 | { |
Vkadaba | 23:bb685f35b08b | 2063 | switch (pDesc->geometry) { |
Vkadaba | 23:bb685f35b08b | 2064 | case ADMW1001_LUT_GEOMETRY_NES_1D: |
Vkadaba | 23:bb685f35b08b | 2065 | *pLength = ADMW1001_LUT_1D_NES_SIZE(pData->lut1dNes); |
Vkadaba | 23:bb685f35b08b | 2066 | break; |
Vkadaba | 23:bb685f35b08b | 2067 | default: |
Vkadaba | 23:bb685f35b08b | 2068 | ADMW_LOG_ERROR("Invalid LUT table geometry %d specified\r\n", |
Vkadaba | 23:bb685f35b08b | 2069 | pDesc->geometry); |
Vkadaba | 23:bb685f35b08b | 2070 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2071 | } |
ADIJake | 0:85855ecd3257 | 2072 | |
Vkadaba | 5:0728bde67bdb | 2073 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2074 | } |
ADIJake | 0:85855ecd3257 | 2075 | |
Vkadaba | 5:0728bde67bdb | 2076 | ADMW_RESULT admw1001_AssembleLutData( |
Vkadaba | 5:0728bde67bdb | 2077 | ADMW1001_LUT * pLutBuffer, |
ADIJake | 0:85855ecd3257 | 2078 | unsigned nLutBufferSize, |
ADIJake | 0:85855ecd3257 | 2079 | unsigned const nNumTables, |
Vkadaba | 5:0728bde67bdb | 2080 | ADMW1001_LUT_DESCRIPTOR * const ppDesc[], |
Vkadaba | 5:0728bde67bdb | 2081 | ADMW1001_LUT_TABLE_DATA * const ppData[]) |
ADIJake | 0:85855ecd3257 | 2082 | { |
Vkadaba | 5:0728bde67bdb | 2083 | ADMW1001_LUT_HEADER *pHdr = &pLutBuffer->header; |
ADIJake | 0:85855ecd3257 | 2084 | uint8_t *pLutTableData = (uint8_t *)pLutBuffer + sizeof(*pHdr); |
ADIJake | 0:85855ecd3257 | 2085 | |
Vkadaba | 61:0f16a2e3b58b | 2086 | if (sizeof(*pHdr) > nLutBufferSize) |
Vkadaba | 61:0f16a2e3b58b | 2087 | { |
Vkadaba | 5:0728bde67bdb | 2088 | ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); |
Vkadaba | 5:0728bde67bdb | 2089 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2090 | } |
ADIJake | 0:85855ecd3257 | 2091 | |
ADIJake | 0:85855ecd3257 | 2092 | /* First initialise the top-level header */ |
Vkadaba | 5:0728bde67bdb | 2093 | pHdr->signature = ADMW_LUT_SIGNATURE; |
ADIJake | 0:85855ecd3257 | 2094 | pHdr->version.major = 1; |
ADIJake | 0:85855ecd3257 | 2095 | pHdr->version.minor = 0; |
ADIJake | 0:85855ecd3257 | 2096 | pHdr->numTables = 0; |
ADIJake | 0:85855ecd3257 | 2097 | pHdr->totalLength = 0; |
ADIJake | 0:85855ecd3257 | 2098 | |
ADIJake | 0:85855ecd3257 | 2099 | /* |
ADIJake | 0:85855ecd3257 | 2100 | * Walk through the list of table pointers provided, appending the table |
ADIJake | 0:85855ecd3257 | 2101 | * descriptor+data from each one to the provided LUT buffer |
ADIJake | 0:85855ecd3257 | 2102 | */ |
Vkadaba | 61:0f16a2e3b58b | 2103 | for (unsigned i = 0; i < nNumTables; i++) |
Vkadaba | 61:0f16a2e3b58b | 2104 | { |
Vkadaba | 5:0728bde67bdb | 2105 | ADMW1001_LUT_DESCRIPTOR * const pDesc = ppDesc[i]; |
Vkadaba | 5:0728bde67bdb | 2106 | ADMW1001_LUT_TABLE_DATA * const pData = ppData[i]; |
Vkadaba | 5:0728bde67bdb | 2107 | ADMW_RESULT res; |
ADIJake | 0:85855ecd3257 | 2108 | unsigned dataLength = 0; |
ADIJake | 0:85855ecd3257 | 2109 | |
ADIJake | 0:85855ecd3257 | 2110 | /* Calculate the length of the table data */ |
ADIJake | 0:85855ecd3257 | 2111 | res = getLutTableSize(pDesc, pData, &dataLength); |
Vkadaba | 5:0728bde67bdb | 2112 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 2113 | return res; |
ADIJake | 0:85855ecd3257 | 2114 | |
ADIJake | 0:85855ecd3257 | 2115 | /* Fill in the table descriptor length and CRC fields */ |
ADIJake | 0:85855ecd3257 | 2116 | pDesc->length = dataLength; |
ADIJake | 0:85855ecd3257 | 2117 | |
Vkadaba | 61:0f16a2e3b58b | 2118 | if ((sizeof(*pHdr) + pHdr->totalLength + sizeof(*pDesc) + dataLength) > nLutBufferSize) |
Vkadaba | 61:0f16a2e3b58b | 2119 | { |
Vkadaba | 5:0728bde67bdb | 2120 | ADMW_LOG_ERROR("Insufficient LUT buffer size provided"); |
Vkadaba | 5:0728bde67bdb | 2121 | return ADMW_INVALID_PARAM; |
ADIJake | 0:85855ecd3257 | 2122 | } |
ADIJake | 0:85855ecd3257 | 2123 | |
ADIJake | 0:85855ecd3257 | 2124 | /* Append the table to the LUT buffer (desc + data) */ |
ADIJake | 0:85855ecd3257 | 2125 | memcpy(pLutTableData + pHdr->totalLength, pDesc, sizeof(*pDesc)); |
ADIJake | 0:85855ecd3257 | 2126 | pHdr->totalLength += sizeof(*pDesc); |
ADIJake | 0:85855ecd3257 | 2127 | memcpy(pLutTableData + pHdr->totalLength, pData, dataLength); |
ADIJake | 0:85855ecd3257 | 2128 | pHdr->totalLength += dataLength; |
ADIJake | 0:85855ecd3257 | 2129 | |
ADIJake | 0:85855ecd3257 | 2130 | pHdr->numTables++; |
ADIJake | 0:85855ecd3257 | 2131 | } |
ADIJake | 0:85855ecd3257 | 2132 | |
Vkadaba | 5:0728bde67bdb | 2133 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 2134 | } |
Vkadaba | 54:31921ad29828 | 2135 | ADMW_RESULT admw1001_SetLutData( |
Vkadaba | 54:31921ad29828 | 2136 | ADMW_DEVICE_HANDLE const hDevice, |
Vkadaba | 54:31921ad29828 | 2137 | ADMW1001_LUT * const pLutData) |
Vkadaba | 54:31921ad29828 | 2138 | { |
Vkadaba | 61:0f16a2e3b58b | 2139 | #pragma diag_suppress=Pa039 |
Vkadaba | 54:31921ad29828 | 2140 | ADMW1001_LUT_HEADER *pLutHeader = &pLutData->header; |
Vkadaba | 54:31921ad29828 | 2141 | ADMW1001_LUT_TABLE *pLutTable = pLutData->tables; |
Vkadaba | 54:31921ad29828 | 2142 | |
Vkadaba | 54:31921ad29828 | 2143 | unsigned actualLength = 0; |
Vkadaba | 54:31921ad29828 | 2144 | |
Vkadaba | 61:0f16a2e3b58b | 2145 | if (pLutData->header.signature != ADMW_LUT_SIGNATURE) |
Vkadaba | 61:0f16a2e3b58b | 2146 | { |
Vkadaba | 54:31921ad29828 | 2147 | ADMW_LOG_ERROR("LUT signature incorrect (expected 0x%X, actual 0x%X)", |
Vkadaba | 61:0f16a2e3b58b | 2148 | ADMW_LUT_SIGNATURE, pLutHeader->signature); |
Vkadaba | 54:31921ad29828 | 2149 | return ADMW_INVALID_SIGNATURE; |
Vkadaba | 54:31921ad29828 | 2150 | } |
Vkadaba | 54:31921ad29828 | 2151 | if ((pLutData->tables->descriptor.geometry!= ADMW1001_LUT_GEOMETRY_NES_1D) && |
Vkadaba | 61:0f16a2e3b58b | 2152 | (pLutData->tables->data.lut1dNes.nElements > MAX_LUT_NUM_ENTRIES)) |
Vkadaba | 61:0f16a2e3b58b | 2153 | { |
Vkadaba | 54:31921ad29828 | 2154 | return ADMW_INVALID_PARAM; |
Vkadaba | 54:31921ad29828 | 2155 | } |
Vkadaba | 61:0f16a2e3b58b | 2156 | for (unsigned i = 0; i < pLutHeader->numTables; i++) |
Vkadaba | 61:0f16a2e3b58b | 2157 | { |
Vkadaba | 54:31921ad29828 | 2158 | ADMW1001_LUT_DESCRIPTOR *pDesc = &pLutTable->descriptor; |
Vkadaba | 54:31921ad29828 | 2159 | |
Vkadaba | 61:0f16a2e3b58b | 2160 | switch (pDesc->geometry) |
Vkadaba | 61:0f16a2e3b58b | 2161 | { |
Vkadaba | 61:0f16a2e3b58b | 2162 | case ADMW1001_LUT_GEOMETRY_COEFFS: |
Vkadaba | 61:0f16a2e3b58b | 2163 | switch (pDesc->equation) |
Vkadaba | 61:0f16a2e3b58b | 2164 | { |
Vkadaba | 61:0f16a2e3b58b | 2165 | case ADMW1001_LUT_EQUATION_POLYN: |
Vkadaba | 61:0f16a2e3b58b | 2166 | case ADMW1001_LUT_EQUATION_POLYNEXP: |
Vkadaba | 61:0f16a2e3b58b | 2167 | case ADMW1001_LUT_EQUATION_QUADRATIC: |
Vkadaba | 61:0f16a2e3b58b | 2168 | case ADMW1001_LUT_EQUATION_STEINHART: |
Vkadaba | 61:0f16a2e3b58b | 2169 | case ADMW1001_LUT_EQUATION_LOGARITHMIC: |
Vkadaba | 61:0f16a2e3b58b | 2170 | case ADMW1001_LUT_EQUATION_BIVARIATE_POLYN: |
Vkadaba | 61:0f16a2e3b58b | 2171 | break; |
Vkadaba | 61:0f16a2e3b58b | 2172 | default: |
Vkadaba | 61:0f16a2e3b58b | 2173 | ADMW_LOG_ERROR("Invalid equation %u specified for LUT table %u", |
Vkadaba | 61:0f16a2e3b58b | 2174 | pDesc->equation, i); |
Vkadaba | 61:0f16a2e3b58b | 2175 | return ADMW_INVALID_PARAM; |
Vkadaba | 55:215da406282b | 2176 | } |
Vkadaba | 61:0f16a2e3b58b | 2177 | break; |
Vkadaba | 61:0f16a2e3b58b | 2178 | case ADMW1001_LUT_GEOMETRY_NES_1D: |
Vkadaba | 61:0f16a2e3b58b | 2179 | break; |
Vkadaba | 61:0f16a2e3b58b | 2180 | default: |
Vkadaba | 61:0f16a2e3b58b | 2181 | ADMW_LOG_ERROR("Invalid geometry %u specified for LUT table %u", |
Vkadaba | 61:0f16a2e3b58b | 2182 | pDesc->geometry, i); |
Vkadaba | 61:0f16a2e3b58b | 2183 | return ADMW_INVALID_PARAM; |
Vkadaba | 54:31921ad29828 | 2184 | } |
Vkadaba | 54:31921ad29828 | 2185 | |
Vkadaba | 61:0f16a2e3b58b | 2186 | switch (pDesc->dataType) |
Vkadaba | 61:0f16a2e3b58b | 2187 | { |
Vkadaba | 61:0f16a2e3b58b | 2188 | case ADMW1001_LUT_DATA_TYPE_FLOAT32: |
Vkadaba | 61:0f16a2e3b58b | 2189 | case ADMW1001_LUT_DATA_TYPE_FLOAT64: |
Vkadaba | 61:0f16a2e3b58b | 2190 | break; |
Vkadaba | 61:0f16a2e3b58b | 2191 | default: |
Vkadaba | 61:0f16a2e3b58b | 2192 | ADMW_LOG_ERROR("Invalid vector format %u specified for LUT table %u", |
Vkadaba | 61:0f16a2e3b58b | 2193 | pDesc->dataType, i); |
Vkadaba | 61:0f16a2e3b58b | 2194 | return ADMW_INVALID_PARAM; |
Vkadaba | 54:31921ad29828 | 2195 | } |
Vkadaba | 54:31921ad29828 | 2196 | |
Vkadaba | 54:31921ad29828 | 2197 | |
Vkadaba | 54:31921ad29828 | 2198 | actualLength += sizeof(*pDesc) + pDesc->length; |
Vkadaba | 54:31921ad29828 | 2199 | |
Vkadaba | 54:31921ad29828 | 2200 | /* Move to the next look-up table */ |
Vkadaba | 54:31921ad29828 | 2201 | pLutTable = (ADMW1001_LUT_TABLE *)((uint8_t *)pLutTable + sizeof(*pDesc) + pDesc->length); |
Vkadaba | 54:31921ad29828 | 2202 | } |
Vkadaba | 54:31921ad29828 | 2203 | |
Vkadaba | 61:0f16a2e3b58b | 2204 | if (actualLength != pLutHeader->totalLength) |
Vkadaba | 61:0f16a2e3b58b | 2205 | { |
Vkadaba | 54:31921ad29828 | 2206 | ADMW_LOG_ERROR("LUT table length mismatch (expected %u, actual %u)", |
Vkadaba | 61:0f16a2e3b58b | 2207 | pLutHeader->totalLength, actualLength); |
Vkadaba | 54:31921ad29828 | 2208 | return ADMW_WRONG_SIZE; |
Vkadaba | 54:31921ad29828 | 2209 | } |
Vkadaba | 54:31921ad29828 | 2210 | |
Vkadaba | 61:0f16a2e3b58b | 2211 | if (sizeof(*pLutHeader) + pLutHeader->totalLength > ADMW_LUT_MAX_SIZE) |
Vkadaba | 61:0f16a2e3b58b | 2212 | { |
Vkadaba | 54:31921ad29828 | 2213 | ADMW_LOG_ERROR("Maximum LUT table length (%u bytes) exceeded", |
Vkadaba | 61:0f16a2e3b58b | 2214 | ADMW_LUT_MAX_SIZE); |
Vkadaba | 54:31921ad29828 | 2215 | return ADMW_WRONG_SIZE; |
Vkadaba | 54:31921ad29828 | 2216 | } |
Vkadaba | 54:31921ad29828 | 2217 | |
Vkadaba | 54:31921ad29828 | 2218 | /* Write the LUT data to the device */ |
Vkadaba | 54:31921ad29828 | 2219 | unsigned lutSize = sizeof(*pLutHeader) + pLutHeader->totalLength; |
Vkadaba | 54:31921ad29828 | 2220 | WRITE_REG_U16(hDevice, 0, CORE_LUT_OFFSET); |
Vkadaba | 54:31921ad29828 | 2221 | WRITE_REG_U8_ARRAY(hDevice, (uint8_t *)pLutData, lutSize, CORE_LUT_DATA); |
Vkadaba | 54:31921ad29828 | 2222 | |
Vkadaba | 54:31921ad29828 | 2223 | return ADMW_SUCCESS; |
Vkadaba | 54:31921ad29828 | 2224 | } |