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