Library files for AD7606

Dependents:   EVAL-AD7606

Committer:
mahphalke
Date:
Mon Oct 05 14:14:46 2020 +0530
Revision:
2:77e214c5c02e
AD7606 No-OS driver library- Initial Revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mahphalke 2:77e214c5c02e 1 /***************************************************************************//**
mahphalke 2:77e214c5c02e 2 * @file ad7606.h
mahphalke 2:77e214c5c02e 3 * @brief Header file for the ad7606 Driver.
mahphalke 2:77e214c5c02e 4 * @author Stefan Popa (stefan.popa@analog.com)
mahphalke 2:77e214c5c02e 5 * @author Darius Berghe (darius.berghe@analog.com)
mahphalke 2:77e214c5c02e 6 ********************************************************************************
mahphalke 2:77e214c5c02e 7 * Copyright 2020(c) Analog Devices, Inc.
mahphalke 2:77e214c5c02e 8 *
mahphalke 2:77e214c5c02e 9 * All rights reserved.
mahphalke 2:77e214c5c02e 10 *
mahphalke 2:77e214c5c02e 11 * Redistribution and use in source and binary forms, with or without
mahphalke 2:77e214c5c02e 12 * modification, are permitted provided that the following conditions are met:
mahphalke 2:77e214c5c02e 13 * - Redistributions of source code must retain the above copyright
mahphalke 2:77e214c5c02e 14 * notice, this list of conditions and the following disclaimer.
mahphalke 2:77e214c5c02e 15 * - Redistributions in binary form must reproduce the above copyright
mahphalke 2:77e214c5c02e 16 * notice, this list of conditions and the following disclaimer in
mahphalke 2:77e214c5c02e 17 * the documentation and/or other materials provided with the
mahphalke 2:77e214c5c02e 18 * distribution.
mahphalke 2:77e214c5c02e 19 * - Neither the name of Analog Devices, Inc. nor the names of its
mahphalke 2:77e214c5c02e 20 * contributors may be used to endorse or promote products derived
mahphalke 2:77e214c5c02e 21 * from this software without specific prior written permission.
mahphalke 2:77e214c5c02e 22 * - The use of this software may or may not infringe the patent rights
mahphalke 2:77e214c5c02e 23 * of one or more patent holders. This license does not release you
mahphalke 2:77e214c5c02e 24 * from the requirement that you obtain separate licenses from these
mahphalke 2:77e214c5c02e 25 * patent holders to use this software.
mahphalke 2:77e214c5c02e 26 * - Use of the software either in source or binary form, must be run
mahphalke 2:77e214c5c02e 27 * on or directly connected to an Analog Devices Inc. component.
mahphalke 2:77e214c5c02e 28 *
mahphalke 2:77e214c5c02e 29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
mahphalke 2:77e214c5c02e 30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
mahphalke 2:77e214c5c02e 31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
mahphalke 2:77e214c5c02e 32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
mahphalke 2:77e214c5c02e 33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
mahphalke 2:77e214c5c02e 34 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
mahphalke 2:77e214c5c02e 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mahphalke 2:77e214c5c02e 36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mahphalke 2:77e214c5c02e 37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mahphalke 2:77e214c5c02e 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mahphalke 2:77e214c5c02e 39 *******************************************************************************/
mahphalke 2:77e214c5c02e 40 #ifndef AD7606_H_
mahphalke 2:77e214c5c02e 41 #define AD7606_H_
mahphalke 2:77e214c5c02e 42
mahphalke 2:77e214c5c02e 43 /******************************************************************************/
mahphalke 2:77e214c5c02e 44 /***************************** Include Files **********************************/
mahphalke 2:77e214c5c02e 45 /******************************************************************************/
mahphalke 2:77e214c5c02e 46 #include <stdint.h>
mahphalke 2:77e214c5c02e 47 #include <stdbool.h>
mahphalke 2:77e214c5c02e 48
mahphalke 2:77e214c5c02e 49 #include "platform_drivers.h"
mahphalke 2:77e214c5c02e 50
mahphalke 2:77e214c5c02e 51 /******************************************************************************/
mahphalke 2:77e214c5c02e 52 /********************** Macros and Constants Definitions **********************/
mahphalke 2:77e214c5c02e 53 /******************************************************************************/
mahphalke 2:77e214c5c02e 54 /* Error codes defined in 'errno.h' file but can't find by Mbed online/offline
mahphalke 2:77e214c5c02e 55 * compiler
mahphalke 2:77e214c5c02e 56 * */
mahphalke 2:77e214c5c02e 57 #define ENOTSUP 134
mahphalke 2:77e214c5c02e 58 #define EBADMSG 77 /* Bad message */
mahphalke 2:77e214c5c02e 59 #define ETIME 62 /* Stream ioctl timeout */
mahphalke 2:77e214c5c02e 60 #define ENODEV 19 /* No such device */
mahphalke 2:77e214c5c02e 61
mahphalke 2:77e214c5c02e 62 #define AD7606_REG_STATUS 0x01
mahphalke 2:77e214c5c02e 63 #define AD7606_REG_CONFIG 0x02
mahphalke 2:77e214c5c02e 64 #define AD7606_REG_RANGE_CH_ADDR(ch) (0x03 + ((ch) >> 1))
mahphalke 2:77e214c5c02e 65 #define AD7606_REG_BANDWIDTH 0x07
mahphalke 2:77e214c5c02e 66 #define AD7606_REG_OVERSAMPLING 0x08
mahphalke 2:77e214c5c02e 67 #define AD7606_REG_GAIN_CH(ch) (0x09 + (ch))
mahphalke 2:77e214c5c02e 68 #define AD7606_REG_OFFSET_CH(ch) (0x11 + (ch))
mahphalke 2:77e214c5c02e 69 #define AD7606_REG_PHASE_CH(ch) (0x19 + (ch))
mahphalke 2:77e214c5c02e 70 #define AD7606_REG_DIGITAL_DIAG_ENABLE 0x21
mahphalke 2:77e214c5c02e 71 #define AD7606_REG_DIGITAL_DIAG_ERR 0x22
mahphalke 2:77e214c5c02e 72 #define AD7606_REG_OPEN_DETECT_ENABLE 0x23
mahphalke 2:77e214c5c02e 73 #define AD7606_REG_OPEN_DETECTED 0x24
mahphalke 2:77e214c5c02e 74 #define AD7606_REG_AIN_OV_UV_DIAG_ENABLE 0x25
mahphalke 2:77e214c5c02e 75 #define AD7606_REG_AIN_OV_DIAG_ERROR 0x26
mahphalke 2:77e214c5c02e 76 #define AD7606_REG_AIN_UV_DIAG_ERROR 0x27
mahphalke 2:77e214c5c02e 77 #define AD7606_REG_DIAGNOSTIC_MUX_CH(ch) (0x28 + ((ch) >> 1))
mahphalke 2:77e214c5c02e 78 #define AD7606_REG_OPEN_DETECT_QUEUE 0x2C
mahphalke 2:77e214c5c02e 79 #define AD7606_REG_CLK_FS_COUNTER 0x2D
mahphalke 2:77e214c5c02e 80 #define AD7606_REG_CLK_OS_COUNTER 0x2E
mahphalke 2:77e214c5c02e 81 #define AD7606_REG_ID 0x2F
mahphalke 2:77e214c5c02e 82
mahphalke 2:77e214c5c02e 83 /* AD7606_REG_STATUS */
mahphalke 2:77e214c5c02e 84 #define AD7606_STATUS_CHANNEL_MSK GENMASK(2,0)
mahphalke 2:77e214c5c02e 85 #define AD7606_AIN_UV_ERR_MSK BIT(3)
mahphalke 2:77e214c5c02e 86 #define AD7606_AIN_OV_ERR_MSK BIT(4)
mahphalke 2:77e214c5c02e 87 #define AD7606_OPEN_DETECTED_MSK BIT(5)
mahphalke 2:77e214c5c02e 88 #define AD7606_DIGITAL_ERROR_MSK BIT(6)
mahphalke 2:77e214c5c02e 89 #define AD7606_RESET_DETECT_MSK BIT(7)
mahphalke 2:77e214c5c02e 90
mahphalke 2:77e214c5c02e 91 /* AD7606_REG_CONFIG */
mahphalke 2:77e214c5c02e 92 #define AD7606_CONFIG_OPERATION_MODE_MSK GENMASK(1,0)
mahphalke 2:77e214c5c02e 93 #define AD7606_CONFIG_DOUT_FORMAT_MSK GENMASK(4,3)
mahphalke 2:77e214c5c02e 94 #define AD7606_CONFIG_EXT_OS_CLOCK_MSK BIT(5)
mahphalke 2:77e214c5c02e 95 #define AD7606_CONFIG_STATUS_HEADER_MSK BIT(6)
mahphalke 2:77e214c5c02e 96
mahphalke 2:77e214c5c02e 97 /* AD7606_REG_RANGE_CH_X_Y */
mahphalke 2:77e214c5c02e 98 #define AD7606_RANGE_CH_MSK(ch) (GENMASK(3, 0) << (4 * ((ch) % 2)))
mahphalke 2:77e214c5c02e 99 #define AD7606_RANGE_CH_MODE(ch, mode) \
mahphalke 2:77e214c5c02e 100 ((GENMASK(3, 0) & mode) << (4 * ((ch) % 2)))
mahphalke 2:77e214c5c02e 101
mahphalke 2:77e214c5c02e 102 /* AD7606_REG_OVERSAMPLING */
mahphalke 2:77e214c5c02e 103 #define AD7606_OS_PAD_MSK GENMASK(7,4)
mahphalke 2:77e214c5c02e 104 #define AD7606_OS_RATIO_MSK GENMASK(3,0)
mahphalke 2:77e214c5c02e 105
mahphalke 2:77e214c5c02e 106 /* AD7606_REG_ID */
mahphalke 2:77e214c5c02e 107 #define AD7606_ID_DEVICE_ID_MSK GENMASK(7,4)
mahphalke 2:77e214c5c02e 108 #define AD7606_ID_SILICON_REVISION_MSK GENMASK(3,0)
mahphalke 2:77e214c5c02e 109
mahphalke 2:77e214c5c02e 110 /* AD7606_REG_GAIN_CH */
mahphalke 2:77e214c5c02e 111 #define AD7606_GAIN_MSK GENMASK(5,0)
mahphalke 2:77e214c5c02e 112
mahphalke 2:77e214c5c02e 113 /* AD7606_REG_DIGITAL_DIAG_ENABLE */
mahphalke 2:77e214c5c02e 114 #define AD7606_ROM_CRC_ERR_EN_MSK BIT(0)
mahphalke 2:77e214c5c02e 115 #define AD7606_MM_CRC_ERR_EN_MSK BIT(1)
mahphalke 2:77e214c5c02e 116 #define AD7606_INT_CRC_ERR_EN_MSK BIT(2)
mahphalke 2:77e214c5c02e 117 #define AD7606_SPI_WRITE_ERR_EN_MSK BIT(3)
mahphalke 2:77e214c5c02e 118 #define AD7606_SPI_READ_ERR_EN_MSK BIT(4)
mahphalke 2:77e214c5c02e 119 #define AD7606_BUSY_STUCK_HIGH_ERR_EN_MSK BIT(5)
mahphalke 2:77e214c5c02e 120 #define AD7606_CLK_FS_OS_COUNTER_EN_MSK BIT(6)
mahphalke 2:77e214c5c02e 121 #define AD7606_INTERFACE_CHECK_EN_MSK BIT(7)
mahphalke 2:77e214c5c02e 122
mahphalke 2:77e214c5c02e 123 /* AD7606_REG_DIAGNOSTIC_MUX_CH */
mahphalke 2:77e214c5c02e 124 #define AD7606_DIAGN_MUX_CH_MSK(ch) (GENMASK(2, 0) << (3 * (ch & 0x1)))
mahphalke 2:77e214c5c02e 125
mahphalke 2:77e214c5c02e 126 #define AD7606_RD_FLAG_MSK(x) (BIT(6) | ((x) & 0x3F))
mahphalke 2:77e214c5c02e 127 #define AD7606_WR_FLAG_MSK(x) ((x) & 0x3F)
mahphalke 2:77e214c5c02e 128
mahphalke 2:77e214c5c02e 129 #define AD7606_MAX_CHANNELS 8
mahphalke 2:77e214c5c02e 130
mahphalke 2:77e214c5c02e 131 /**
mahphalke 2:77e214c5c02e 132 * @enum ad7606_device_id
mahphalke 2:77e214c5c02e 133 * @brief Device ID definitions
mahphalke 2:77e214c5c02e 134 */
mahphalke 2:77e214c5c02e 135 enum ad7606_device_id {
mahphalke 2:77e214c5c02e 136 /** 4-Channel DAS with 16-Bit, Bipolar Input, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 137 ID_AD7605_4,
mahphalke 2:77e214c5c02e 138 /** 4-Channel DAS with 16-Bit, Bipolar Input, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 139 ID_AD7606_4,
mahphalke 2:77e214c5c02e 140 /** 6-Channel DAS with 16-Bit, Bipolar Input, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 141 ID_AD7606_6,
mahphalke 2:77e214c5c02e 142 /** 8-Channel DAS with 16-Bit, Bipolar Input, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 143 ID_AD7606_8,
mahphalke 2:77e214c5c02e 144 /** 8-Channel DAS with 16-Bit, 800 kSPS, Bipolar Input, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 145 ID_AD7606B,
mahphalke 2:77e214c5c02e 146 /** 8-Channel DAS with 16-Bit, 1 MSPS, Bipolar Input, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 147 ID_AD7606C_16,
mahphalke 2:77e214c5c02e 148 /** 8-Channel DAS with 18-Bit, 1 MSPS, Bipolar Input, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 149 ID_AD7606C_18,
mahphalke 2:77e214c5c02e 150 /** 8-Channel DAS with 18-Bit, Bipolar, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 151 ID_AD7608,
mahphalke 2:77e214c5c02e 152 /** 8-Channel Differential DAS with 18-Bit, Bipolar, Simultaneous Sampling ADC */
mahphalke 2:77e214c5c02e 153 ID_AD7609,
mahphalke 2:77e214c5c02e 154 };
mahphalke 2:77e214c5c02e 155
mahphalke 2:77e214c5c02e 156 /**
mahphalke 2:77e214c5c02e 157 * @enum ad7606_osr
mahphalke 2:77e214c5c02e 158 * @brief Oversampling ratio
mahphalke 2:77e214c5c02e 159 */
mahphalke 2:77e214c5c02e 160 enum ad7606_osr {
mahphalke 2:77e214c5c02e 161 /** Oversample by 1 */
mahphalke 2:77e214c5c02e 162 AD7606_OSR_1,
mahphalke 2:77e214c5c02e 163 /** Oversample by 2 */
mahphalke 2:77e214c5c02e 164 AD7606_OSR_2,
mahphalke 2:77e214c5c02e 165 /** Oversample by 4 */
mahphalke 2:77e214c5c02e 166 AD7606_OSR_4,
mahphalke 2:77e214c5c02e 167 /** Oversample by 8 */
mahphalke 2:77e214c5c02e 168 AD7606_OSR_8,
mahphalke 2:77e214c5c02e 169 /** Oversample by 16 */
mahphalke 2:77e214c5c02e 170 AD7606_OSR_16,
mahphalke 2:77e214c5c02e 171 /** Oversample by 32 */
mahphalke 2:77e214c5c02e 172 AD7606_OSR_32,
mahphalke 2:77e214c5c02e 173 /** Oversample by 64 */
mahphalke 2:77e214c5c02e 174 AD7606_OSR_64,
mahphalke 2:77e214c5c02e 175 /** Oversample by 128, available for chips that have software mode only */
mahphalke 2:77e214c5c02e 176 AD7606_OSR_128,
mahphalke 2:77e214c5c02e 177 /** Oversample by 256, available for chips that have software mode only */
mahphalke 2:77e214c5c02e 178 AD7606_OSR_256
mahphalke 2:77e214c5c02e 179 };
mahphalke 2:77e214c5c02e 180
mahphalke 2:77e214c5c02e 181 /**
mahphalke 2:77e214c5c02e 182 * @enum ad7606_op_mode
mahphalke 2:77e214c5c02e 183 * @brief Operation mode
mahphalke 2:77e214c5c02e 184 */
mahphalke 2:77e214c5c02e 185 enum ad7606_op_mode {
mahphalke 2:77e214c5c02e 186 /** Normal operation mode */
mahphalke 2:77e214c5c02e 187 AD7606_NORMAL,
mahphalke 2:77e214c5c02e 188 /** Standby mode, all the PGAs, and all the SAR ADCs enter a low power mode */
mahphalke 2:77e214c5c02e 189 AD7606_STANDBY,
mahphalke 2:77e214c5c02e 190 /** Autostandby mode, available only in software mode */
mahphalke 2:77e214c5c02e 191 AD7606_AUTOSTANDBY,
mahphalke 2:77e214c5c02e 192 /** Shutdown mode, all circuitry is powered down */
mahphalke 2:77e214c5c02e 193 AD7606_SHUTDOWN
mahphalke 2:77e214c5c02e 194 };
mahphalke 2:77e214c5c02e 195
mahphalke 2:77e214c5c02e 196 /**
mahphalke 2:77e214c5c02e 197 * @enum ad7606_dout_format
mahphalke 2:77e214c5c02e 198 * @brief Number of DOUT lines
mahphalke 2:77e214c5c02e 199 */
mahphalke 2:77e214c5c02e 200 enum ad7606_dout_format {
mahphalke 2:77e214c5c02e 201 /** DOUT A line is used */
mahphalke 2:77e214c5c02e 202 AD7606_1_DOUT,
mahphalke 2:77e214c5c02e 203 /** DOUT A,B lines are used. */
mahphalke 2:77e214c5c02e 204 AD7606_2_DOUT,
mahphalke 2:77e214c5c02e 205 /** DOUT A,B,C,D lines are used. */
mahphalke 2:77e214c5c02e 206 AD7606_4_DOUT,
mahphalke 2:77e214c5c02e 207 /** DOUT A,B,C,D,E,F,G,H lines are used. */
mahphalke 2:77e214c5c02e 208 AD7606_8_DOUT
mahphalke 2:77e214c5c02e 209 };
mahphalke 2:77e214c5c02e 210
mahphalke 2:77e214c5c02e 211 /**
mahphalke 2:77e214c5c02e 212 * @struct ad7606_config
mahphalke 2:77e214c5c02e 213 * @brief AD7606_REG_CONFIG configuration parameters
mahphalke 2:77e214c5c02e 214 */
mahphalke 2:77e214c5c02e 215 struct ad7606_config {
mahphalke 2:77e214c5c02e 216 /** Operation mode */
mahphalke 2:77e214c5c02e 217 enum ad7606_op_mode op_mode;
mahphalke 2:77e214c5c02e 218 /** Number of DOUT lines */
mahphalke 2:77e214c5c02e 219 enum ad7606_dout_format dout_format;
mahphalke 2:77e214c5c02e 220 /** External oversampling clock switch */
mahphalke 2:77e214c5c02e 221 bool ext_os_clock;
mahphalke 2:77e214c5c02e 222 /** Status header switch */
mahphalke 2:77e214c5c02e 223 bool status_header;
mahphalke 2:77e214c5c02e 224 };
mahphalke 2:77e214c5c02e 225
mahphalke 2:77e214c5c02e 226 /**
mahphalke 2:77e214c5c02e 227 * @struct ad7606_range
mahphalke 2:77e214c5c02e 228 * @brief Operation range as specified in datasheet (in uV)
mahphalke 2:77e214c5c02e 229 */
mahphalke 2:77e214c5c02e 230 struct ad7606_range {
mahphalke 2:77e214c5c02e 231 /** Minimum range value (may be negative) */
mahphalke 2:77e214c5c02e 232 int32_t min;
mahphalke 2:77e214c5c02e 233 /** Maximum range value */
mahphalke 2:77e214c5c02e 234 int32_t max;
mahphalke 2:77e214c5c02e 235 /** Whether the range is differential */
mahphalke 2:77e214c5c02e 236 bool differential;
mahphalke 2:77e214c5c02e 237 };
mahphalke 2:77e214c5c02e 238
mahphalke 2:77e214c5c02e 239 /**
mahphalke 2:77e214c5c02e 240 * @struct ad7606_digital_diag
mahphalke 2:77e214c5c02e 241 * @brief Oversampling settings
mahphalke 2:77e214c5c02e 242 */
mahphalke 2:77e214c5c02e 243 struct ad7606_oversampling {
mahphalke 2:77e214c5c02e 244 /** Oversampling padding */
mahphalke 2:77e214c5c02e 245 uint8_t os_pad:4;
mahphalke 2:77e214c5c02e 246 /** Oversampling ratio */
mahphalke 2:77e214c5c02e 247 enum ad7606_osr os_ratio:4;
mahphalke 2:77e214c5c02e 248 };
mahphalke 2:77e214c5c02e 249
mahphalke 2:77e214c5c02e 250 /**
mahphalke 2:77e214c5c02e 251 * @struct ad7606_digital_diag
mahphalke 2:77e214c5c02e 252 * @brief Digital diagnostics configuration switches
mahphalke 2:77e214c5c02e 253 */
mahphalke 2:77e214c5c02e 254 struct ad7606_digital_diag {
mahphalke 2:77e214c5c02e 255 /** ROM CRC check switch */
mahphalke 2:77e214c5c02e 256 bool rom_crc_err_en: 1;
mahphalke 2:77e214c5c02e 257 /** Mempry map CRC check switch */
mahphalke 2:77e214c5c02e 258 bool mm_crc_err_en: 1;
mahphalke 2:77e214c5c02e 259 /** Conversion and register data CRC check switch */
mahphalke 2:77e214c5c02e 260 bool int_crc_err_en: 1;
mahphalke 2:77e214c5c02e 261 /** SPI write error switch */
mahphalke 2:77e214c5c02e 262 bool spi_write_err_en: 1;
mahphalke 2:77e214c5c02e 263 /** SPI read error switch */
mahphalke 2:77e214c5c02e 264 bool spi_read_err_en: 1;
mahphalke 2:77e214c5c02e 265 /** Busy stuck high for more than 4us error switch */
mahphalke 2:77e214c5c02e 266 bool busy_stuck_high_err_en: 1;
mahphalke 2:77e214c5c02e 267 /** Frame sync and oversampling clock counter switch */
mahphalke 2:77e214c5c02e 268 bool clk_fs_os_counter_en: 1;
mahphalke 2:77e214c5c02e 269 /** Interface check switch */
mahphalke 2:77e214c5c02e 270 bool interface_check_en: 1;
mahphalke 2:77e214c5c02e 271 };
mahphalke 2:77e214c5c02e 272
mahphalke 2:77e214c5c02e 273 /**
mahphalke 2:77e214c5c02e 274 * @struct ad7606_dev
mahphalke 2:77e214c5c02e 275 * @brief Device driver structure
mahphalke 2:77e214c5c02e 276 */
mahphalke 2:77e214c5c02e 277 struct ad7606_dev {
mahphalke 2:77e214c5c02e 278 /** SPI descriptor*/
mahphalke 2:77e214c5c02e 279 spi_desc *spi_desc;
mahphalke 2:77e214c5c02e 280 /** RESET GPIO descriptor */
mahphalke 2:77e214c5c02e 281 struct gpio_desc *gpio_reset;
mahphalke 2:77e214c5c02e 282 /** CONVST GPIO descriptor */
mahphalke 2:77e214c5c02e 283 struct gpio_desc *gpio_convst;
mahphalke 2:77e214c5c02e 284 /** BUSY GPIO descriptor */
mahphalke 2:77e214c5c02e 285 struct gpio_desc *gpio_busy;
mahphalke 2:77e214c5c02e 286 /** STBYn GPIO descriptor */
mahphalke 2:77e214c5c02e 287 struct gpio_desc *gpio_stby_n;
mahphalke 2:77e214c5c02e 288 /** RANGE GPIO descriptor */
mahphalke 2:77e214c5c02e 289 struct gpio_desc *gpio_range;
mahphalke 2:77e214c5c02e 290 /** OS0 GPIO descriptor */
mahphalke 2:77e214c5c02e 291 struct gpio_desc *gpio_os0;
mahphalke 2:77e214c5c02e 292 /** OS1 GPIO descriptor */
mahphalke 2:77e214c5c02e 293 struct gpio_desc *gpio_os1;
mahphalke 2:77e214c5c02e 294 /** OS2 GPIO descriptor */
mahphalke 2:77e214c5c02e 295 struct gpio_desc *gpio_os2;
mahphalke 2:77e214c5c02e 296 /** PARn/SER GPIO descriptor */
mahphalke 2:77e214c5c02e 297 struct gpio_desc *gpio_par_ser;
mahphalke 2:77e214c5c02e 298 /** Device ID */
mahphalke 2:77e214c5c02e 299 enum ad7606_device_id device_id;
mahphalke 2:77e214c5c02e 300 /** Oversampling settings */
mahphalke 2:77e214c5c02e 301 struct ad7606_oversampling oversampling;
mahphalke 2:77e214c5c02e 302 /** Whether the device is running in hardware or software mode */
mahphalke 2:77e214c5c02e 303 bool sw_mode;
mahphalke 2:77e214c5c02e 304 /** Whether the device is running in register or ADC reading mode */
mahphalke 2:77e214c5c02e 305 bool reg_mode;
mahphalke 2:77e214c5c02e 306 /** Number of DOUT lines supported by the device */
mahphalke 2:77e214c5c02e 307 enum ad7606_dout_format max_dout_lines;
mahphalke 2:77e214c5c02e 308 /** Configuration register settings */
mahphalke 2:77e214c5c02e 309 struct ad7606_config config;
mahphalke 2:77e214c5c02e 310 /** Digital diagnostics register settings */
mahphalke 2:77e214c5c02e 311 struct ad7606_digital_diag digital_diag_enable;
mahphalke 2:77e214c5c02e 312 /** Number of input channels of the device */
mahphalke 2:77e214c5c02e 313 uint8_t num_channels;
mahphalke 2:77e214c5c02e 314 /** Channel offset calibration */
mahphalke 2:77e214c5c02e 315 int8_t offset_ch[AD7606_MAX_CHANNELS];
mahphalke 2:77e214c5c02e 316 /** Channel phase calibration */
mahphalke 2:77e214c5c02e 317 uint8_t phase_ch[AD7606_MAX_CHANNELS];
mahphalke 2:77e214c5c02e 318 /** Channel gain calibration */
mahphalke 2:77e214c5c02e 319 uint8_t gain_ch[AD7606_MAX_CHANNELS];
mahphalke 2:77e214c5c02e 320 /** Channel operating range */
mahphalke 2:77e214c5c02e 321 struct ad7606_range range_ch[AD7606_MAX_CHANNELS];
mahphalke 2:77e214c5c02e 322 /** Data buffer (used internally by the SPI communication functions) */
mahphalke 2:77e214c5c02e 323 uint8_t data[28];
mahphalke 2:77e214c5c02e 324 };
mahphalke 2:77e214c5c02e 325
mahphalke 2:77e214c5c02e 326 /**
mahphalke 2:77e214c5c02e 327 * @struct ad7606_dev
mahphalke 2:77e214c5c02e 328 * @brief Device driver initialization parameters
mahphalke 2:77e214c5c02e 329 */
mahphalke 2:77e214c5c02e 330 struct ad7606_init_param {
mahphalke 2:77e214c5c02e 331 /** SPI initialization parameters */
mahphalke 2:77e214c5c02e 332 spi_init_param spi_init;
mahphalke 2:77e214c5c02e 333 /** RESET GPIO initialization parameters */
mahphalke 2:77e214c5c02e 334 struct gpio_init_param *gpio_reset;
mahphalke 2:77e214c5c02e 335 /** CONVST GPIO initialization parameters */
mahphalke 2:77e214c5c02e 336 struct gpio_init_param *gpio_convst;
mahphalke 2:77e214c5c02e 337 /** BUSY GPIO initialization parameters */
mahphalke 2:77e214c5c02e 338 struct gpio_init_param *gpio_busy;
mahphalke 2:77e214c5c02e 339 /** STBYn GPIO initialization parameters */
mahphalke 2:77e214c5c02e 340 struct gpio_init_param *gpio_stby_n;
mahphalke 2:77e214c5c02e 341 /** RANGE GPIO initialization parameters */
mahphalke 2:77e214c5c02e 342 struct gpio_init_param *gpio_range;
mahphalke 2:77e214c5c02e 343 /** OS0 GPIO initialization parameters */
mahphalke 2:77e214c5c02e 344 struct gpio_init_param *gpio_os0;
mahphalke 2:77e214c5c02e 345 /** OS1 GPIO initialization parameters */
mahphalke 2:77e214c5c02e 346 struct gpio_init_param *gpio_os1;
mahphalke 2:77e214c5c02e 347 /** OS2 GPIO initialization parameters */
mahphalke 2:77e214c5c02e 348 struct gpio_init_param *gpio_os2;
mahphalke 2:77e214c5c02e 349 /** PARn/SER GPIO initialization parameters */
mahphalke 2:77e214c5c02e 350 struct gpio_init_param *gpio_par_ser;
mahphalke 2:77e214c5c02e 351 /** Device ID */
mahphalke 2:77e214c5c02e 352 enum ad7606_device_id device_id;
mahphalke 2:77e214c5c02e 353 /** Oversampling settings */
mahphalke 2:77e214c5c02e 354 struct ad7606_oversampling oversampling;
mahphalke 2:77e214c5c02e 355 /** Whether the device is running in hardware or software mode */
mahphalke 2:77e214c5c02e 356 bool sw_mode;
mahphalke 2:77e214c5c02e 357 /** Configuration register settings */
mahphalke 2:77e214c5c02e 358 struct ad7606_config config;
mahphalke 2:77e214c5c02e 359 /** Digital diagnostics register settings */
mahphalke 2:77e214c5c02e 360 struct ad7606_digital_diag digital_diag_enable;
mahphalke 2:77e214c5c02e 361 /** Channel offset calibration */
mahphalke 2:77e214c5c02e 362 int8_t offset_ch[AD7606_MAX_CHANNELS];
mahphalke 2:77e214c5c02e 363 /** Channel phase calibration */
mahphalke 2:77e214c5c02e 364 uint8_t phase_ch[AD7606_MAX_CHANNELS];
mahphalke 2:77e214c5c02e 365 /** Channel gain calibration */
mahphalke 2:77e214c5c02e 366 uint8_t gain_ch[AD7606_MAX_CHANNELS];
mahphalke 2:77e214c5c02e 367 /** Channel operating range */
mahphalke 2:77e214c5c02e 368 struct ad7606_range range_ch[AD7606_MAX_CHANNELS];
mahphalke 2:77e214c5c02e 369 };
mahphalke 2:77e214c5c02e 370
mahphalke 2:77e214c5c02e 371 int32_t ad7606_spi_reg_read(struct ad7606_dev *dev,
mahphalke 2:77e214c5c02e 372 uint8_t reg_addr,
mahphalke 2:77e214c5c02e 373 uint8_t *reg_data);
mahphalke 2:77e214c5c02e 374 int32_t ad7606_spi_reg_write(struct ad7606_dev *dev,
mahphalke 2:77e214c5c02e 375 uint8_t reg_addr,
mahphalke 2:77e214c5c02e 376 uint8_t reg_data);
mahphalke 2:77e214c5c02e 377 int32_t ad7606_spi_write_mask(struct ad7606_dev *dev,
mahphalke 2:77e214c5c02e 378 uint32_t addr,
mahphalke 2:77e214c5c02e 379 uint32_t mask,
mahphalke 2:77e214c5c02e 380 uint32_t val);
mahphalke 2:77e214c5c02e 381 int32_t ad7606_spi_data_read(struct ad7606_dev *dev,
mahphalke 2:77e214c5c02e 382 uint32_t *data);
mahphalke 2:77e214c5c02e 383 int32_t ad7606_read(struct ad7606_dev *dev,
mahphalke 2:77e214c5c02e 384 uint32_t *data);
mahphalke 2:77e214c5c02e 385 int32_t ad7606_convst(struct ad7606_dev *dev);
mahphalke 2:77e214c5c02e 386 int32_t ad7606_reset(struct ad7606_dev *dev);
mahphalke 2:77e214c5c02e 387 int32_t ad7606_set_oversampling(struct ad7606_dev *dev,
mahphalke 2:77e214c5c02e 388 struct ad7606_oversampling oversampling);
mahphalke 2:77e214c5c02e 389 int32_t ad7606_set_ch_range(struct ad7606_dev *dev, uint8_t ch,
mahphalke 2:77e214c5c02e 390 struct ad7606_range range);
mahphalke 2:77e214c5c02e 391 int32_t ad7606_set_ch_offset(struct ad7606_dev *dev, uint8_t ch,
mahphalke 2:77e214c5c02e 392 int8_t offset);
mahphalke 2:77e214c5c02e 393 int32_t ad7606_set_ch_phase(struct ad7606_dev *dev, uint8_t ch,
mahphalke 2:77e214c5c02e 394 uint8_t phase);
mahphalke 2:77e214c5c02e 395 int32_t ad7606_set_ch_gain(struct ad7606_dev *dev, uint8_t ch,
mahphalke 2:77e214c5c02e 396 uint8_t gain);
mahphalke 2:77e214c5c02e 397 int32_t ad7606_set_config(struct ad7606_dev *dev,
mahphalke 2:77e214c5c02e 398 struct ad7606_config config);
mahphalke 2:77e214c5c02e 399 int32_t ad7606_set_digital_diag(struct ad7606_dev *dev,
mahphalke 2:77e214c5c02e 400 struct ad7606_digital_diag diag);
mahphalke 2:77e214c5c02e 401 int32_t ad7606_init(struct ad7606_dev **device,
mahphalke 2:77e214c5c02e 402 struct ad7606_init_param *init_param);
mahphalke 2:77e214c5c02e 403 int32_t ad7606_remove(struct ad7606_dev *dev);
mahphalke 2:77e214c5c02e 404 #endif /* AD7606_H_ */