Library files for AD5770R

Committer:
mbradley
Date:
Wed Mar 25 16:12:06 2020 +0000
Revision:
1:bcc701b1fd33
Initial Commit for AD5770R No-OS driver.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbradley 1:bcc701b1fd33 1 /***************************************************************************//**
mbradley 1:bcc701b1fd33 2 * @file ad5770r.h
mbradley 1:bcc701b1fd33 3 * @brief Header file for AD5770R Driver.
mbradley 1:bcc701b1fd33 4 * @author Mircea Caprioru (mircea.caprioru@analog.com)
mbradley 1:bcc701b1fd33 5 ********************************************************************************
mbradley 1:bcc701b1fd33 6 * Copyright 2018, 2020(c) Analog Devices, Inc.
mbradley 1:bcc701b1fd33 7 *
mbradley 1:bcc701b1fd33 8 * All rights reserved.
mbradley 1:bcc701b1fd33 9 *
mbradley 1:bcc701b1fd33 10 * Redistribution and use in source and binary forms, with or without
mbradley 1:bcc701b1fd33 11 * modification, are permitted provided that the following conditions are met:
mbradley 1:bcc701b1fd33 12 * - Redistributions of source code must retain the above copyright
mbradley 1:bcc701b1fd33 13 * notice, this list of conditions and the following disclaimer.
mbradley 1:bcc701b1fd33 14 * - Redistributions in binary form must reproduce the above copyright
mbradley 1:bcc701b1fd33 15 * notice, this list of conditions and the following disclaimer in
mbradley 1:bcc701b1fd33 16 * the documentation and/or other materials provided with the
mbradley 1:bcc701b1fd33 17 * distribution.
mbradley 1:bcc701b1fd33 18 * - Neither the name of Analog Devices, Inc. nor the names of its
mbradley 1:bcc701b1fd33 19 * contributors may be used to endorse or promote products derived
mbradley 1:bcc701b1fd33 20 * from this software without specific prior written permission.
mbradley 1:bcc701b1fd33 21 * - The use of this software may or may not infringe the patent rights
mbradley 1:bcc701b1fd33 22 * of one or more patent holders. This license does not release you
mbradley 1:bcc701b1fd33 23 * from the requirement that you obtain separate licenses from these
mbradley 1:bcc701b1fd33 24 * patent holders to use this software.
mbradley 1:bcc701b1fd33 25 * - Use of the software either in source or binary form, must be run
mbradley 1:bcc701b1fd33 26 * on or directly connected to an Analog Devices Inc. component.
mbradley 1:bcc701b1fd33 27 *
mbradley 1:bcc701b1fd33 28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
mbradley 1:bcc701b1fd33 29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
mbradley 1:bcc701b1fd33 30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
mbradley 1:bcc701b1fd33 31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
mbradley 1:bcc701b1fd33 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
mbradley 1:bcc701b1fd33 33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
mbradley 1:bcc701b1fd33 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbradley 1:bcc701b1fd33 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbradley 1:bcc701b1fd33 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbradley 1:bcc701b1fd33 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbradley 1:bcc701b1fd33 38 *******************************************************************************/
mbradley 1:bcc701b1fd33 39
mbradley 1:bcc701b1fd33 40 #ifndef AD5770R_H_
mbradley 1:bcc701b1fd33 41 #define AD5770R_H_
mbradley 1:bcc701b1fd33 42
mbradley 1:bcc701b1fd33 43 /******************************************************************************/
mbradley 1:bcc701b1fd33 44 /***************************** Include Files **********************************/
mbradley 1:bcc701b1fd33 45 /******************************************************************************/
mbradley 1:bcc701b1fd33 46 #include <stdint.h>
mbradley 1:bcc701b1fd33 47 #include "platform_drivers.h"
mbradley 1:bcc701b1fd33 48
mbradley 1:bcc701b1fd33 49 /******************************************************************************/
mbradley 1:bcc701b1fd33 50 /********************** Macros and Constants Definitions **********************/
mbradley 1:bcc701b1fd33 51 /******************************************************************************/
mbradley 1:bcc701b1fd33 52 #ifndef BIT
mbradley 1:bcc701b1fd33 53 #define BIT(x) (1UL << (x))
mbradley 1:bcc701b1fd33 54 #endif
mbradley 1:bcc701b1fd33 55 /*
mbradley 1:bcc701b1fd33 56 * Create a contiguous bitmask starting at bit position @l and ending at
mbradley 1:bcc701b1fd33 57 * position @h.
mbradley 1:bcc701b1fd33 58 */
mbradley 1:bcc701b1fd33 59 #ifdef GENMASK
mbradley 1:bcc701b1fd33 60 #define GENMASK(h, l) \
mbradley 1:bcc701b1fd33 61 (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (31 - (h))))
mbradley 1:bcc701b1fd33 62 #endif
mbradley 1:bcc701b1fd33 63
mbradley 1:bcc701b1fd33 64 /*SPI configuration registers*/
mbradley 1:bcc701b1fd33 65 #define AD5770R_INTERFACE_CONFIG_A 0x00
mbradley 1:bcc701b1fd33 66 #define AD5770R_INTERFACE_CONFIG_B 0x01
mbradley 1:bcc701b1fd33 67 #define AD5770R_CHIP_TYPE 0x03
mbradley 1:bcc701b1fd33 68 #define AD5770R_PRODUCT_ID_L 0x04
mbradley 1:bcc701b1fd33 69 #define AD5770R_PRODUCT_ID_H 0x05
mbradley 1:bcc701b1fd33 70 #define AD5770R_CHIP_GRADE 0x06
mbradley 1:bcc701b1fd33 71 #define AD5770R_SCRATCH_PAD 0x0A
mbradley 1:bcc701b1fd33 72 #define AD5770R_SPI_REVISION 0x0B
mbradley 1:bcc701b1fd33 73 #define AD5770R_VENDOR_L 0x0C
mbradley 1:bcc701b1fd33 74 #define AD5770R_VENDOR_H 0x0D
mbradley 1:bcc701b1fd33 75 #define AD5770R_STREAM_MODE 0x0E
mbradley 1:bcc701b1fd33 76 #define AD5770R_INTERFACE_CONFIG_C 0x10
mbradley 1:bcc701b1fd33 77 #define AD5770R_INTERFACE_STATUS_A 0x11
mbradley 1:bcc701b1fd33 78
mbradley 1:bcc701b1fd33 79 /*AD5770R configuration registers*/
mbradley 1:bcc701b1fd33 80 #define AD5770R_CHANNEL_CONFIG 0x14
mbradley 1:bcc701b1fd33 81 #define AD5770R_OUTPUT_RANGE_CH0 0x15
mbradley 1:bcc701b1fd33 82 #define AD5770R_OUTPUT_RANGE_CH1 0x16
mbradley 1:bcc701b1fd33 83 #define AD5770R_OUTPUT_RANGE_CH2 0x17
mbradley 1:bcc701b1fd33 84 #define AD5770R_OUTPUT_RANGE_CH3 0x18
mbradley 1:bcc701b1fd33 85 #define AD5770R_OUTPUT_RANGE_CH4 0x19
mbradley 1:bcc701b1fd33 86 #define AD5770R_OUTPUT_RANGE_CH5 0x1A
mbradley 1:bcc701b1fd33 87 #define AD5770R_REFERENCE 0x1B
mbradley 1:bcc701b1fd33 88 #define AD5770R_ALARM_CONFIG 0x1C
mbradley 1:bcc701b1fd33 89 #define AD5770R_OUTPUT_FILTER_CH0 0x1D
mbradley 1:bcc701b1fd33 90 #define AD5770R_OUTPUT_FILTER_CH1 0x1E
mbradley 1:bcc701b1fd33 91 #define AD5770R_OUTPUT_FILTER_CH2 0x1F
mbradley 1:bcc701b1fd33 92 #define AD5770R_OUTPUT_FILTER_CH3 0x20
mbradley 1:bcc701b1fd33 93 #define AD5770R_OUTPUT_FILTER_CH4 0x21
mbradley 1:bcc701b1fd33 94 #define AD5770R_OUTPUT_FILTER_CH5 0x22
mbradley 1:bcc701b1fd33 95 #define AD5770R_MONITOR_SETUP 0x23
mbradley 1:bcc701b1fd33 96 #define AD5770R_STATUS 0x24
mbradley 1:bcc701b1fd33 97 #define AD5770R_HW_LDAC 0x25
mbradley 1:bcc701b1fd33 98 #define AD5770R_CH0_DAC_LSB 0x26
mbradley 1:bcc701b1fd33 99 #define AD5770R_CH0_DAC_MSB 0x27
mbradley 1:bcc701b1fd33 100 #define AD5770R_CH1_DAC_LSB 0x28
mbradley 1:bcc701b1fd33 101 #define AD5770R_CH1_DAC_MSB 0x29
mbradley 1:bcc701b1fd33 102 #define AD5770R_CH2_DAC_LSB 0x2A
mbradley 1:bcc701b1fd33 103 #define AD5770R_CH2_DAC_MSB 0x2B
mbradley 1:bcc701b1fd33 104 #define AD5770R_CH3_DAC_LSB 0x2C
mbradley 1:bcc701b1fd33 105 #define AD5770R_CH3_DAC_MSB 0x2D
mbradley 1:bcc701b1fd33 106 #define AD5770R_CH4_DAC_LSB 0x2E
mbradley 1:bcc701b1fd33 107 #define AD5770R_CH4_DAC_MSB 0x2F
mbradley 1:bcc701b1fd33 108 #define AD5770R_CH5_DAC_LSB 0x30
mbradley 1:bcc701b1fd33 109 #define AD5770R_CH5_DAC_MSB 0x31
mbradley 1:bcc701b1fd33 110 #define AD5770R_DAC_PAGE_MASK_LSB 0x32
mbradley 1:bcc701b1fd33 111 #define AD5770R_DAC_PAGE_MASK_MSB 0x33
mbradley 1:bcc701b1fd33 112 #define AD5770R_CH_SELECT 0x34
mbradley 1:bcc701b1fd33 113 #define AD5770R_INPUT_PAGE_MASK_LSB 0x35
mbradley 1:bcc701b1fd33 114 #define AD5770R_INPUT_PAGE_MASK_MSB 0x36
mbradley 1:bcc701b1fd33 115 #define AD5770R_SW_LDAC 0x37
mbradley 1:bcc701b1fd33 116 #define AD5770R_CH0_INPUT_LSB 0x38
mbradley 1:bcc701b1fd33 117 #define AD5770R_CH0_INPUT_MSB 0x39
mbradley 1:bcc701b1fd33 118 #define AD5770R_CH1_INPUT_LSB 0x3A
mbradley 1:bcc701b1fd33 119 #define AD5770R_CH1_INPUT_MSB 0x3B
mbradley 1:bcc701b1fd33 120 #define AD5770R_CH2_INPUT_LSB 0x3C
mbradley 1:bcc701b1fd33 121 #define AD5770R_CH2_INPUT_MSB 0x3D
mbradley 1:bcc701b1fd33 122 #define AD5770R_CH3_INPUT_LSB 0x3E
mbradley 1:bcc701b1fd33 123 #define AD5770R_CH3_INPUT_MSB 0x3F
mbradley 1:bcc701b1fd33 124 #define AD5770R_CH4_INPUT_LSB 0x40
mbradley 1:bcc701b1fd33 125 #define AD5770R_CH4_INPUT_MSB 0x41
mbradley 1:bcc701b1fd33 126 #define AD5770R_CH5_INPUT_LSB 0x42
mbradley 1:bcc701b1fd33 127 #define AD5770R_CH5_INPUT_MSB 0x43
mbradley 1:bcc701b1fd33 128
mbradley 1:bcc701b1fd33 129 /* AD5770R_INTERFACE_CONFIG_A */
mbradley 1:bcc701b1fd33 130 #define AD5770R_INTERFACE_CONFIG_A_SW_RESET_MSK BIT(7) | BIT(0)
mbradley 1:bcc701b1fd33 131 #define AD5770R_INTERFACE_CONFIG_A_SW_RESET(x) (((x) & 0x1) | 0x80)
mbradley 1:bcc701b1fd33 132 #define AD5770R_INTERFACE_CONFIG_A_ADDR_ASCENSION_MSB_MSK BIT(5)
mbradley 1:bcc701b1fd33 133 #define AD5770R_INTERFACE_CONFIG_A_ADDR_ASCENSION_MSB(x) (((x) & 0x1) << 5)
mbradley 1:bcc701b1fd33 134 #define AD5770R_INTERFACE_CONFIG_A_SDO_ACTIVE_MSK BIT(4) | BIT(3)
mbradley 1:bcc701b1fd33 135
mbradley 1:bcc701b1fd33 136 /* AD5770R_INTERFACE_CONFIG_B */
mbradley 1:bcc701b1fd33 137 #define AD5770R_INTERFACE_CONFIG_B_SINGLE_INST_MSK BIT(7)
mbradley 1:bcc701b1fd33 138 #define AD5770R_INTERFACE_CONFIG_B_SINGLE_INST(x) (((x) & 0x1) << 7)
mbradley 1:bcc701b1fd33 139 #define AD5770R_INTERFACE_CONFIG_B_SHORT_INST_MSK BIT(3)
mbradley 1:bcc701b1fd33 140 #define AD5770R_INTERFACE_CONFIG_B_SHORT_INST(x) (((x) & 0x1) << 3)
mbradley 1:bcc701b1fd33 141
mbradley 1:bcc701b1fd33 142 /* AD5770R_INTERFACE_CONFIG_C */
mbradley 1:bcc701b1fd33 143 #define AD5770R_INTERFACE_CONFIG_C_STRUCT_REGISTER_ACCESS_MSK BIT(5)
mbradley 1:bcc701b1fd33 144 #define AD5770R_INTERFACE_CONFIG_C_STRUCT_REGISTER_ACCESS(x) (((x) & 0x1) << 5)
mbradley 1:bcc701b1fd33 145
mbradley 1:bcc701b1fd33 146 /* AD5770R_CHANNEL_CONFIG */
mbradley 1:bcc701b1fd33 147 #define AD5770R_CHANNEL_CONFIG_CH0_SINK_EN_MSK BIT(7)
mbradley 1:bcc701b1fd33 148 #define AD5770R_CHANNEL_CONFIG_CH0_SINK_EN(x) (((x) & 0x1) << 7)
mbradley 1:bcc701b1fd33 149 #define AD5770R_CHANNEL_CONFIG_CH5_SHUTDOWN_B_MSK BIT(5)
mbradley 1:bcc701b1fd33 150 #define AD5770R_CHANNEL_CONFIG_CH5_SHUTDOWN_B(x) (((x) & 0x1) << 5)
mbradley 1:bcc701b1fd33 151 #define AD5770R_CHANNEL_CONFIG_CH4_SHUTDOWN_B_MSK BIT(4)
mbradley 1:bcc701b1fd33 152 #define AD5770R_CHANNEL_CONFIG_CH4_SHUTDOWN_B(x) (((x) & 0x1) << 4)
mbradley 1:bcc701b1fd33 153 #define AD5770R_CHANNEL_CONFIG_CH3_SHUTDOWN_B_MSK BIT(3)
mbradley 1:bcc701b1fd33 154 #define AD5770R_CHANNEL_CONFIG_CH3_SHUTDOWN_B(x) (((x) & 0x1) << 3)
mbradley 1:bcc701b1fd33 155 #define AD5770R_CHANNEL_CONFIG_CH2_SHUTDOWN_B_MSK BIT(2)
mbradley 1:bcc701b1fd33 156 #define AD5770R_CHANNEL_CONFIG_CH2_SHUTDOWN_B(x) (((x) & 0x1) << 2)
mbradley 1:bcc701b1fd33 157 #define AD5770R_CHANNEL_CONFIG_CH1_SHUTDOWN_B_MSK BIT(1)
mbradley 1:bcc701b1fd33 158 #define AD5770R_CHANNEL_CONFIG_CH1_SHUTDOWN_B(x) (((x) & 0x1) << 1)
mbradley 1:bcc701b1fd33 159 #define AD5770R_CHANNEL_CONFIG_CH0_SHUTDOWN_B_MSK BIT(0)
mbradley 1:bcc701b1fd33 160 #define AD5770R_CHANNEL_CONFIG_CH0_SHUTDOWN_B(x) (((x) & 0x1) << 0)
mbradley 1:bcc701b1fd33 161
mbradley 1:bcc701b1fd33 162 /* AD5770R_OUTPUT_RANGE */
mbradley 1:bcc701b1fd33 163 #define AD5770R_OUTPUT_RANGE_OUTPUT_SCALING_MSK GENMASK(7, 2)
mbradley 1:bcc701b1fd33 164 #define AD5770R_OUTPUT_RANGE_OUTPUT_SCALING(x) (((x) & 0x3F) << 2)
mbradley 1:bcc701b1fd33 165 #define AD5770R_OUTPUT_RANGE_MODE_MSK GENMASK(1, 0)
mbradley 1:bcc701b1fd33 166 #define AD5770R_OUTPUT_RANGE_MODE(x) ((x) & 0x03)
mbradley 1:bcc701b1fd33 167
mbradley 1:bcc701b1fd33 168 /* AD5770R_REFERENCE */
mbradley 1:bcc701b1fd33 169 #define AD5770R_REFERENCE_RESISTOR_SEL_MSK BIT(2)
mbradley 1:bcc701b1fd33 170 #define AD5770R_REFERENCE_RESISTOR_SEL(x) (((x) & 0x1) << 2)
mbradley 1:bcc701b1fd33 171 #define AD5770R_REFERENCE_VOLTATE_SEL_MSK GENMASK(1, 0)
mbradley 1:bcc701b1fd33 172 #define AD5770R_REFERENCE_VOLTATE_SEL(x) (((x) & 0x3) << 0)
mbradley 1:bcc701b1fd33 173
mbradley 1:bcc701b1fd33 174 /* AD5770R_ALARM_CONFIG */
mbradley 1:bcc701b1fd33 175 #define AD5770R_ALARM_CONFIG_BACKGROUND_CRC_ALARM_MASK(x) (((x) & 0x1) << 7)
mbradley 1:bcc701b1fd33 176 #define AD5770R_ALARM_CONFIG_IREF_FAULT_ALARM_MASK(x) (((x) & 0x1) << 6)
mbradley 1:bcc701b1fd33 177 #define AD5770R_ALARM_CONFIG_NEGATIVE_CHANNEL0_ALARM_MASK(x) (((x) & 0x1) << 5)
mbradley 1:bcc701b1fd33 178 #define AD5770R_ALARM_CONFIG_OVER_TEMP_ALARM_MASK(x) (((x) & 0x1) << 4)
mbradley 1:bcc701b1fd33 179 #define AD5770R_ALARM_CONFIG_TEMP_WARNING_ALARM_MASK(x) (((x) & 0x1) << 3)
mbradley 1:bcc701b1fd33 180 #define AD5770R_ALARM_CONFIG_BACKGROUND_CRC_EN(x) (((x) & 0x1) << 2)
mbradley 1:bcc701b1fd33 181 #define AD5770R_ALARM_CONFIG_THERMAL_SHUTDOWN_EN(x) (((x) & 0x1) << 1)
mbradley 1:bcc701b1fd33 182 #define AD5770R_ALARM_CONFIG_OPEN_DRAIN_EN(x) (((x) & 0x1) << 0)
mbradley 1:bcc701b1fd33 183
mbradley 1:bcc701b1fd33 184 /* AD5770R_OUTPUT_FILTER_CH */
mbradley 1:bcc701b1fd33 185 #define AD5770R_OUTPUT_FILTER_CH_MSK GENMASK(3, 0)
mbradley 1:bcc701b1fd33 186 #define AD5770R_OUTPUT_FILTER_CH(x) (((x) & 0xF) << 0)
mbradley 1:bcc701b1fd33 187
mbradley 1:bcc701b1fd33 188 /* AD5770R_MONITOR_SETUP */
mbradley 1:bcc701b1fd33 189 #define AD5770R_MONITOR_SETUP_MON_FUNCTION_MSK GENMASK(7, 6)
mbradley 1:bcc701b1fd33 190 #define AD5770R_MONITOR_SETUP_MON_FUNCTION(x) (((x) & 0x3) << 6)
mbradley 1:bcc701b1fd33 191 #define AD5770R_MONITOR_SETUP_MUX_BUFFER_MSK BIT(5)
mbradley 1:bcc701b1fd33 192 #define AD5770R_MONITOR_SETUP_MUX_BUFFER(x) (((x) & 0x1) << 5)
mbradley 1:bcc701b1fd33 193 #define AD5770R_MONITOR_SETUP_IB_EXT_EN_MSK BIT(4)
mbradley 1:bcc701b1fd33 194 #define AD5770R_MONITOR_SETUP_IB_EXT_EN(x) (((x) & 0x1) << 4)
mbradley 1:bcc701b1fd33 195 #define AD5770R_MONITOR_SETUP_MON_CH_MSK GENMASK(3, 0)
mbradley 1:bcc701b1fd33 196 #define AD5770R_MONITOR_SETUP_MON_CH(x) (((x) & 0x7) << 0)
mbradley 1:bcc701b1fd33 197
mbradley 1:bcc701b1fd33 198 /* AD5770R_STATUS */
mbradley 1:bcc701b1fd33 199 #define AD5770R_STATUS_BACKGROUND_CRC_STATUS_MSK BIT(7)
mbradley 1:bcc701b1fd33 200 #define AD5770R_STATUS_IREF_FAULT_MSK BIT(3)
mbradley 1:bcc701b1fd33 201 #define AD5770R_STATUS_NEGATIVE_CHANNEL0_MSK BIT(2)
mbradley 1:bcc701b1fd33 202 #define AD5770R_STATUS_OVER_TEMP_MSK BIT(1)
mbradley 1:bcc701b1fd33 203 #define AD5770R_STATUS_TEMP_WARNING_MSK BIT(0)
mbradley 1:bcc701b1fd33 204
mbradley 1:bcc701b1fd33 205 /* AD5770R_HW_LDAC */
mbradley 1:bcc701b1fd33 206 #define AD5770R_HW_LDAC_MASK_CH(x, channel) (((x) & 0x1) << (channel))
mbradley 1:bcc701b1fd33 207
mbradley 1:bcc701b1fd33 208 /* AD5770R_CH_DAC */
mbradley 1:bcc701b1fd33 209 #define AD5770R_CH_DAC_DATA_LSB(x) (((x) & 0x3F) << 2)
mbradley 1:bcc701b1fd33 210 #define AD5770R_CH_DAC_DATA_MSB(x) (((x) & 0xFF) << 0)
mbradley 1:bcc701b1fd33 211
mbradley 1:bcc701b1fd33 212 /* AD5770R_CH_SELECT */
mbradley 1:bcc701b1fd33 213 #define AD5770R_CH_SELECT_SEL_CH(x, channel) (((x) & 0x1) << (channel))
mbradley 1:bcc701b1fd33 214
mbradley 1:bcc701b1fd33 215 /* AD5770R_CH_INPUT */
mbradley 1:bcc701b1fd33 216 #define AD5770R_CH_DAC_INPUT_DATA_LSB(x) (((x) & 0x3F) << 2)
mbradley 1:bcc701b1fd33 217 #define AD5770R_CH_DAC_INPUT_DATA_MSB(x) (((x) & 0xFF) << 0)
mbradley 1:bcc701b1fd33 218
mbradley 1:bcc701b1fd33 219 /* AD5770R_SW_LDAC */
mbradley 1:bcc701b1fd33 220 #define AD5770R_SW_LDAC_CH(x, channel) (((x) & 0x1) << (channel))
mbradley 1:bcc701b1fd33 221
mbradley 1:bcc701b1fd33 222
mbradley 1:bcc701b1fd33 223 #define AD5770R_REG_READ(x) (((x) & 0x7F) | 0x80)
mbradley 1:bcc701b1fd33 224 #define AD5770R_REG_WRITE(x) ((x) & 0x7F)
mbradley 1:bcc701b1fd33 225
mbradley 1:bcc701b1fd33 226 enum ad5770r_output_filter_resistor {
mbradley 1:bcc701b1fd33 227 AD5770R_OUTPUT_FILTER_RESISTOR_60_OHM = 0x0,
mbradley 1:bcc701b1fd33 228 AD5770R_OUTPUT_FILTER_RESISTOR_5_6_KOHM = 0x5,
mbradley 1:bcc701b1fd33 229 AD5770R_OUTPUT_FILTER_RESISTOR_11_2_KOHM,
mbradley 1:bcc701b1fd33 230 AD5770R_OUTPUT_FILTER_RESISTOR_22_2_KOHM,
mbradley 1:bcc701b1fd33 231 AD5770R_OUTPUT_FILTER_RESISTOR_44_4_KOHM,
mbradley 1:bcc701b1fd33 232 AD5770R_OUTPUT_FILTER_RESISTOR_104_KOHM,
mbradley 1:bcc701b1fd33 233 };
mbradley 1:bcc701b1fd33 234
mbradley 1:bcc701b1fd33 235 enum ad5770r_monitor_function {
mbradley 1:bcc701b1fd33 236 AD5770R_DISABLE = 0,
mbradley 1:bcc701b1fd33 237 AD5770R_VOLTAGE_MONITORING,
mbradley 1:bcc701b1fd33 238 AD5770R_CURRENT_MONITORING,
mbradley 1:bcc701b1fd33 239 AD5770R_TEMPERATURE_MONITORING
mbradley 1:bcc701b1fd33 240 };
mbradley 1:bcc701b1fd33 241
mbradley 1:bcc701b1fd33 242 enum ad5770r_channels {
mbradley 1:bcc701b1fd33 243 AD5770R_CH0 = 0,
mbradley 1:bcc701b1fd33 244 AD5770R_CH1,
mbradley 1:bcc701b1fd33 245 AD5770R_CH2,
mbradley 1:bcc701b1fd33 246 AD5770R_CH3,
mbradley 1:bcc701b1fd33 247 AD5770R_CH4,
mbradley 1:bcc701b1fd33 248 AD5770R_CH5
mbradley 1:bcc701b1fd33 249 };
mbradley 1:bcc701b1fd33 250
mbradley 1:bcc701b1fd33 251 enum ad5770r_reference_voltage {
mbradley 1:bcc701b1fd33 252 AD5770R_EXT_REF_2_5_V = 0,
mbradley 1:bcc701b1fd33 253 AD5770R_INT_REF_1_25_V_OUT_ON,
mbradley 1:bcc701b1fd33 254 AD5770R_EXT_REF_1_25_V,
mbradley 1:bcc701b1fd33 255 AD5770R_INT_REF_1_25_V_OUT_OFF
mbradley 1:bcc701b1fd33 256 };
mbradley 1:bcc701b1fd33 257
mbradley 1:bcc701b1fd33 258 struct ad5770r_monitor_setup {
mbradley 1:bcc701b1fd33 259 enum ad5770r_monitor_function monitor_function;
mbradley 1:bcc701b1fd33 260 bool mux_buffer;
mbradley 1:bcc701b1fd33 261 bool ib_ext_en;
mbradley 1:bcc701b1fd33 262 enum ad5770r_channels monitor_channel;
mbradley 1:bcc701b1fd33 263 };
mbradley 1:bcc701b1fd33 264
mbradley 1:bcc701b1fd33 265 struct ad5770r_dac_page_mask {
mbradley 1:bcc701b1fd33 266 uint16_t dac_data_page_mask;
mbradley 1:bcc701b1fd33 267 uint16_t input_page_mask;
mbradley 1:bcc701b1fd33 268 };
mbradley 1:bcc701b1fd33 269
mbradley 1:bcc701b1fd33 270 struct ad5770r_output_range {
mbradley 1:bcc701b1fd33 271 uint8_t output_scale;
mbradley 1:bcc701b1fd33 272 uint8_t output_range_mode;
mbradley 1:bcc701b1fd33 273 };
mbradley 1:bcc701b1fd33 274
mbradley 1:bcc701b1fd33 275 struct ad5770r_device_spi_settings {
mbradley 1:bcc701b1fd33 276 bool addr_ascension;
mbradley 1:bcc701b1fd33 277 bool single_instruction; // for multibyte read/write
mbradley 1:bcc701b1fd33 278 uint8_t stream_mode_length;
mbradley 1:bcc701b1fd33 279 };
mbradley 1:bcc701b1fd33 280
mbradley 1:bcc701b1fd33 281 struct ad5770r_channel_switches {
mbradley 1:bcc701b1fd33 282 bool en0, en1, en2, en3, en4, en5, sink0;
mbradley 1:bcc701b1fd33 283 };
mbradley 1:bcc701b1fd33 284
mbradley 1:bcc701b1fd33 285 struct ad5770r_alarm_cfg {
mbradley 1:bcc701b1fd33 286 bool open_drain_en;
mbradley 1:bcc701b1fd33 287 bool thermal_shutdown_en;
mbradley 1:bcc701b1fd33 288 bool background_crc_en;
mbradley 1:bcc701b1fd33 289 bool temp_warning_msk;
mbradley 1:bcc701b1fd33 290 bool over_temp_msk;
mbradley 1:bcc701b1fd33 291 bool neg_ch0_msk;
mbradley 1:bcc701b1fd33 292 bool iref_fault_msk;
mbradley 1:bcc701b1fd33 293 bool background_crc_msk;
mbradley 1:bcc701b1fd33 294 };
mbradley 1:bcc701b1fd33 295
mbradley 1:bcc701b1fd33 296 struct ad5770r_dev {
mbradley 1:bcc701b1fd33 297 /* SPI */
mbradley 1:bcc701b1fd33 298 spi_desc *spi_desc;
mbradley 1:bcc701b1fd33 299
mbradley 1:bcc701b1fd33 300 /* Device SPI Settings */
mbradley 1:bcc701b1fd33 301 struct ad5770r_device_spi_settings dev_spi_settings;
mbradley 1:bcc701b1fd33 302 /* Device Settings */
mbradley 1:bcc701b1fd33 303 struct ad5770r_channel_switches channel_config;
mbradley 1:bcc701b1fd33 304 struct ad5770r_output_range output_mode[6];
mbradley 1:bcc701b1fd33 305 bool external_reference;
mbradley 1:bcc701b1fd33 306 enum ad5770r_reference_voltage reference_selector;
mbradley 1:bcc701b1fd33 307 struct ad5770r_alarm_cfg alarm_config;
mbradley 1:bcc701b1fd33 308 enum ad5770r_output_filter_resistor output_filter[6];
mbradley 1:bcc701b1fd33 309 struct ad5770r_monitor_setup mon_setup;
mbradley 1:bcc701b1fd33 310 struct ad5770r_channel_switches mask_hw_ldac;
mbradley 1:bcc701b1fd33 311 uint16_t dac_value[6];
mbradley 1:bcc701b1fd33 312 struct ad5770r_dac_page_mask page_mask;
mbradley 1:bcc701b1fd33 313 struct ad5770r_channel_switches mask_channel_sel;
mbradley 1:bcc701b1fd33 314 struct ad5770r_channel_switches sw_ldac;
mbradley 1:bcc701b1fd33 315 uint16_t input_value[6];
mbradley 1:bcc701b1fd33 316 };
mbradley 1:bcc701b1fd33 317
mbradley 1:bcc701b1fd33 318 struct ad5770r_init_param {
mbradley 1:bcc701b1fd33 319 /* SPI */
mbradley 1:bcc701b1fd33 320 spi_init_param spi_init;
mbradley 1:bcc701b1fd33 321
mbradley 1:bcc701b1fd33 322 /* Device SPI Settings */
mbradley 1:bcc701b1fd33 323 struct ad5770r_device_spi_settings dev_spi_settings;
mbradley 1:bcc701b1fd33 324 /* Device Settings */
mbradley 1:bcc701b1fd33 325 struct ad5770r_channel_switches channel_config;
mbradley 1:bcc701b1fd33 326 struct ad5770r_output_range output_mode[6];
mbradley 1:bcc701b1fd33 327 bool external_reference;
mbradley 1:bcc701b1fd33 328 enum ad5770r_reference_voltage reference_selector;
mbradley 1:bcc701b1fd33 329 struct ad5770r_alarm_cfg alarm_config;
mbradley 1:bcc701b1fd33 330 enum ad5770r_output_filter_resistor output_filter[6];
mbradley 1:bcc701b1fd33 331 struct ad5770r_monitor_setup mon_setup;
mbradley 1:bcc701b1fd33 332 struct ad5770r_channel_switches mask_hw_ldac;
mbradley 1:bcc701b1fd33 333 uint16_t dac_value[6];
mbradley 1:bcc701b1fd33 334 struct ad5770r_dac_page_mask page_mask;
mbradley 1:bcc701b1fd33 335 struct ad5770r_channel_switches mask_channel_sel;
mbradley 1:bcc701b1fd33 336 struct ad5770r_channel_switches sw_ldac;
mbradley 1:bcc701b1fd33 337 uint16_t input_value[6];
mbradley 1:bcc701b1fd33 338 };
mbradley 1:bcc701b1fd33 339
mbradley 1:bcc701b1fd33 340 /******************************************************************************/
mbradley 1:bcc701b1fd33 341 /************************ Functions Declarations ******************************/
mbradley 1:bcc701b1fd33 342 /******************************************************************************/
mbradley 1:bcc701b1fd33 343 int32_t ad5770r_spi_reg_read(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 344 uint8_t reg_addr,
mbradley 1:bcc701b1fd33 345 uint8_t *reg_data);
mbradley 1:bcc701b1fd33 346 int32_t ad5770r_spi_reg_read_multiple(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 347 uint8_t reg_addr,
mbradley 1:bcc701b1fd33 348 uint8_t *reg_data,
mbradley 1:bcc701b1fd33 349 uint16_t count);
mbradley 1:bcc701b1fd33 350 int32_t ad5770r_spi_reg_write(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 351 uint8_t reg_addr,
mbradley 1:bcc701b1fd33 352 uint8_t reg_data);
mbradley 1:bcc701b1fd33 353 int32_t ad5770r_spi_reg_write_multiple(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 354 uint8_t reg_addr,
mbradley 1:bcc701b1fd33 355 uint8_t *reg_data,
mbradley 1:bcc701b1fd33 356 uint16_t count);
mbradley 1:bcc701b1fd33 357 int32_t ad5770r_spi_write_mask(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 358 uint8_t reg_addr,
mbradley 1:bcc701b1fd33 359 uint32_t mask,
mbradley 1:bcc701b1fd33 360 uint8_t data);
mbradley 1:bcc701b1fd33 361 int32_t ad5770r_set_device_spi(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 362 const struct ad5770r_device_spi_settings *spi_settings);
mbradley 1:bcc701b1fd33 363 int32_t ad5770r_channel_config(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 364 const struct ad5770r_channel_switches *channel_config);
mbradley 1:bcc701b1fd33 365 int32_t ad5770r_set_output_mode(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 366 const struct ad5770r_output_range *output_mode,
mbradley 1:bcc701b1fd33 367 enum ad5770r_channels channel);
mbradley 1:bcc701b1fd33 368 int32_t ad5770r_set_reference(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 369 bool external_reference,
mbradley 1:bcc701b1fd33 370 enum ad5770r_reference_voltage reference_selector);
mbradley 1:bcc701b1fd33 371 int32_t ad5770r_set_alarm(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 372 const struct ad5770r_alarm_cfg *const alarm_config);
mbradley 1:bcc701b1fd33 373 int32_t ad5770r_set_output_filter(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 374 enum ad5770r_output_filter_resistor output_filter,
mbradley 1:bcc701b1fd33 375 enum ad5770r_channels channel);
mbradley 1:bcc701b1fd33 376 int32_t ad5770r_set_hw_ldac(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 377 const struct ad5770r_channel_switches *mask_hw_ldac);
mbradley 1:bcc701b1fd33 378 int32_t ad5770r_set_dac_value(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 379 uint16_t dac_value, enum ad5770r_channels channel);
mbradley 1:bcc701b1fd33 380 int32_t ad5770r_set_dac_input(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 381 uint16_t dac_input, enum ad5770r_channels channel);
mbradley 1:bcc701b1fd33 382 int32_t ad5770r_set_page_mask(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 383 const struct ad5770r_dac_page_mask *page_mask);
mbradley 1:bcc701b1fd33 384 int32_t ad5770r_set_mask_channel(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 385 const struct ad5770r_channel_switches *mask_channel_sel);
mbradley 1:bcc701b1fd33 386 int32_t ad5770r_set_sw_ldac(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 387 const struct ad5770r_channel_switches *sw_ldac);
mbradley 1:bcc701b1fd33 388 int32_t ad5770r_get_status(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 389 uint8_t *status);
mbradley 1:bcc701b1fd33 390 int32_t ad5770r_get_interface_status(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 391 uint8_t *status);
mbradley 1:bcc701b1fd33 392 int32_t ad5770r_set_monitor_setup(struct ad5770r_dev *dev,
mbradley 1:bcc701b1fd33 393 const struct ad5770r_monitor_setup *mon_setup);
mbradley 1:bcc701b1fd33 394 int32_t ad5770r_init(struct ad5770r_dev **device,
mbradley 1:bcc701b1fd33 395 const struct ad5770r_init_param *init_param);
mbradley 1:bcc701b1fd33 396 int32_t ad5770r_remove(struct ad5770r_dev *dev);
mbradley 1:bcc701b1fd33 397
mbradley 1:bcc701b1fd33 398 #endif /* AD5770R_H_ */