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