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