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