| 1 | /***************************************************************************//** |
| 2 | * @file AD5686.h |
| 3 | * @brief Header file of AD5686 Driver. This driver supporting the following |
| 4 | * devices: AD5684R, AD5685R, AD5686R, AD5694R, AD5695R, AD5696R, |
| 5 | * |
| 6 | * @author Istvan Csomortani ([email protected]) |
| 7 | ******************************************************************************** |
| 8 | * Copyright 2013(c) Analog Devices, Inc. |
| 9 | * |
| 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, |
| 14 | * are permitted provided that the following conditions are met: |
| 15 | * - Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer. |
| 17 | * - Redistributions in binary form must reproduce the above copyright |
| 18 | * notice, this list of conditions and the following disclaimer in |
| 19 | * the documentation and/or other materials provided with the |
| 20 | * distribution. |
| 21 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 22 | * contributors may be used to endorse or promote products derived |
| 23 | * from this software without specific prior written permission. |
| 24 | * - The use of this software may or may not infringe the patent rights |
| 25 | * of one or more patent holders. This license does not release you |
| 26 | * from the requirement that you obtain separate licenses from these |
| 27 | * patent holders to use this software. |
| 28 | * - Use of the software either in source or binary form, must be run |
| 29 | * on or directly connected to an Analog Devices Inc. component. |
| 30 | * |
| 31 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 32 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 33 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 34 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 35 | * INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 36 | * * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 39 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 40 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 41 | * DAMAGE. |
| 42 | * |
| 43 | *******************************************************************************/ |
| 44 | |
| 45 | /******************************************************************************/ |
| 46 | /***************************** Include Files **********************************/ |
| 47 | /******************************************************************************/ |
| 48 | #include "Communication.h" |
| 49 | |
| 50 | /* Supported devices */ |
| 51 | typedef enum { |
| 52 | ID_AD5684R, |
| 53 | ID_AD5685R, |
| 54 | ID_AD5686R, |
| 55 | ID_AD5694R, |
| 56 | ID_AD5695R, |
| 57 | ID_AD5696R, |
| 58 | } AD5686_type_t; |
| 59 | |
| 60 | /* Control Bits */ |
| 61 | #define AD5686_CTRL_NOP 0 |
| 62 | #define AD5686_CTRL_WRITE 1 |
| 63 | #define AD5686_CTRL_UPDATE 2 |
| 64 | #define AD5686_CTRL_WRITEUPDATE 3 |
| 65 | #define AD5686_CTRL_PWR 4 |
| 66 | #define AD5686_CTRL_LDAC_MASK 5 |
| 67 | #define AD5686_CTRL_SWRESET 6 |
| 68 | #define AD5686_CTRL_IREF_REG 7 |
| 69 | #define AD5686_CTRL_DCEN 8 |
| 70 | #define AD5686_CTRL_RB_REG 9 |
| 71 | |
| 72 | /* AD5686 channels */ |
| 73 | #define AD5686_CH_A 1 |
| 74 | #define AD5686_CH_B 2 |
| 75 | #define AD5686_CH_C 4 |
| 76 | #define AD5686_CH_D 8 |
| 77 | #define AD5686_CH_ALL 0xF |
| 78 | |
| 79 | /* Power-down operation modes masks */ |
| 80 | #define AD5686_PWRM_NORMAL 0 |
| 81 | #define AD5686_PWRM_1K 1 |
| 82 | #define AD5686_PWRM_100K 2 |
| 83 | #define AD5686_PWRM_THREESTATE 3 |
| 84 | |
| 85 | #define AD5686_PWRM_MASK 3 |
| 86 | |
| 87 | /* Power-down operation modes offset for each channel */ |
| 88 | #define AD5686_PWRM_CHA_OFFSET 0 |
| 89 | #define AD5686_PWRM_CHB_OFFSET 2 |
| 90 | #define AD5686_PWRM_CHC_OFFSET 4 |
| 91 | #define AD5686_PWRM_CHD_OFFSET 6 |
| 92 | |
| 93 | /* AD5449 GPIO */ |
| 94 | #define AD5686_LDAC_OUT GPIO0_PIN_OUT |
| 95 | #define AD5686_LDAC_LOW GPIO0_LOW |
| 96 | #define AD5686_LDAC_HIGH GPIO0_HIGH |
| 97 | #define AD5686_RESET_OUT GPIO1_PIN_OUT |
| 98 | #define AD5686_RESET_LOW GPIO1_LOW |
| 99 | #define AD5686_RESET_HIGH GPIO1_HIGH |
| 100 | |
| 101 | /* Enable/disable defines */ |
| 102 | #define AD5686_INTREF_EN 1 |
| 103 | #define AD5686_INTREF_DIS 0 |
| 104 | #define AD5686_DC_EN 1 |
| 105 | #define AD5686_DC_DIS 0 |
| 106 | #define AD5686_RB_EN 1 |
| 107 | #define AD5686_RB_DIS 0 |
| 108 | |
| 109 | /* Define I2C hardwired address */ |
| 110 | #define AD5686_I2C_ADDR 0x0E |
| 111 | |
| 112 | /* SPI slave device ID */ |
| 113 | #define AD5686_SLAVE_ID 1 |
| 114 | |
| 115 | /******************************************************************************/ |
| 116 | /************************ Functions Declarations ******************************/ |
| 117 | /******************************************************************************/ |
| 118 | /* Initialize SPI and Initial Values for AD5449 Board. */ |
| 119 | char AD5686_Init(AD5686_type_t device); |
| 120 | /* Write to input register */ |
| 121 | unsigned short AD5686_SetShiftReg(unsigned char command, |
| 122 | unsigned char address, |
| 123 | unsigned short data); |
| 124 | |
| 125 | /* Write to Input Register n (dependent on LDAC) */ |
| 126 | void AD5686_WriteRegister(unsigned char address, |
| 127 | unsigned short data); |
| 128 | |
| 129 | /* Update DAC Register n with contents of Input Register n */ |
| 130 | void AD5686_UpdateRegister(unsigned char address); |
| 131 | |
| 132 | /* Write to and update DAC channel n */ |
| 133 | void AD5686_WriteUpdateRegister(unsigned char address, |
| 134 | unsigned short data); |
| 135 | |
| 136 | /* Read back Input Register n */ |
| 137 | unsigned short AD5686_ReadBackRegister(unsigned char address); |
| 138 | |
| 139 | /* Power down / power up DAC */ |
| 140 | void AD5686_PowerMode(unsigned char address, |
| 141 | unsigned char mode); |
| 142 | |
| 143 | /* Set up LDAC mask register */ |
| 144 | void AD5686_LdacMask(unsigned char ldacMask); |
| 145 | |
| 146 | /* Software reset (power-on reset) */ |
| 147 | void AD5686_SoftwareReset(); |
| 148 | |
| 149 | /* Write to Internal reference setup register */ |
| 150 | void AD5686_InternalReference(unsigned char value); |
| 151 | |
| 152 | /* Set up DCEN register (daisy-chain enable) */ |
| 153 | void AD5686_DaisyChainEn(unsigned char value); |
| 154 | |
| 155 | /* Set up readback register (readback enable) */ |
| 156 | void AD5686_ReadBackEn(unsigned char value); |