| 1 | /**************************************************************************//** |
| 2 | * @file ad525x.h |
| 3 | * @brief Header file of AD525X Driver for Microblaze processor. This driver |
| 4 | * supporting the following devices : AD5232, AD5235, AD5252, AD5251, |
| 5 | * AD5254, AD5253, ADN2850 |
| 6 | * @author Istvan Csomortani ([email protected]) |
| 7 | * |
| 8 | ******************************************************************************* |
| 9 | * Copyright 2013(c) Analog Devices, Inc. |
| 10 | * |
| 11 | * All rights reserved. |
| 12 | * |
| 13 | * Redistribution and use in source and binary forms, with or without 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 IMPLIED |
| 32 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY |
| 33 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 34 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 36 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 37 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 38 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 40 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 41 | * |
| 42 | ******************************************************************************/ |
| 43 | #ifndef __AD525X_H__ |
| 44 | #define __AD525X_H__ |
| 45 | |
| 46 | #include "Communication.h" |
| 47 | |
| 48 | /* Custom boolean type */ |
| 49 | typedef enum _Bool_t |
| 50 | { |
| 51 | false, |
| 52 | true |
| 53 | } Bool_t; |
| 54 | |
| 55 | /* Communication types */ |
| 56 | typedef enum _CommType_t |
| 57 | { |
| 58 | SPI, |
| 59 | I2C |
| 60 | } CommType_t; |
| 61 | |
| 62 | /* Supported devices */ |
| 63 | typedef enum _AD525X_type_t |
| 64 | { |
| 65 | ID_AD5232, |
| 66 | ID_AD5235, |
| 67 | ID_ADN2850, |
| 68 | ID_AD5252, |
| 69 | ID_AD5251, |
| 70 | ID_AD5254, |
| 71 | ID_AD5253, |
| 72 | } AD525X_type_t; |
| 73 | |
| 74 | /*****************************************************************************/ |
| 75 | /* Device specific MACROs */ |
| 76 | /*****************************************************************************/ |
| 77 | /* GPIOs */ |
| 78 | #define AD525X_RESET_OUT GPIO1_PIN_OUT |
| 79 | #define AD525X_RESET_LOW GPIO1_LOW |
| 80 | #define AD525X_RESET_HIGH GPIO1_HIGH |
| 81 | #define AD525X_SHUTDOWN_OUT GPIO3_PIN_OUT |
| 82 | #define AD525X_SHUTDOWN_LOW GPIO3_LOW |
| 83 | #define AD525X_SHUTDOWN_HIGH GPIO3_HIGH |
| 84 | #define AD525X_READY_IN GPIO0_PIN_IN |
| 85 | #define AD525X_READY_LOW GPIO0_LOW |
| 86 | #define AD525X_READY_HIGH GPIO0_HIGH |
| 87 | #define AD525X_WP_BF_OUT GPIO2_PIN_OUT |
| 88 | #define AD525X_WP_BF_LOW GPIO2_LOW |
| 89 | #define AD525X_WP_BF_HIGH GPIO2_HIGH |
| 90 | |
| 91 | /* Data word masks */ |
| 92 | #define AD525X_MEM_ADDR_MASK 0xF |
| 93 | #define AD525X_RDAC_ADDR_MASK_1BIT 0x1 |
| 94 | #define AD525X_RDAC_ADDR_MASK_3BIT 0x7 |
| 95 | #define AD525X_DATA8_MASK 0xFF |
| 96 | #define AD525X_DATA10_MASK 0x3FF |
| 97 | |
| 98 | /*********************** Command definitions *********************************/ |
| 99 | #define AD525X_CMD_NOP 0x0 |
| 100 | #define AD525X_CMD_MEM2RDAC 0x1 |
| 101 | #define AD525X_CMD_RDAC2MEM 0x2 |
| 102 | #define AD525X_CMD_DECRDAC_6DB 0x3 |
| 103 | #define AD525X_CMD_DECALLRDAC_6DB 0x4 |
| 104 | #define AD525X_CMD_DECRDAC_ONE 0x5 |
| 105 | #define AD525X_CMD_DECALLRDAC_ONE 0x6 |
| 106 | #define AD525X_CMD_RESET 0x7 |
| 107 | #define AD525X_CMD_INCRDAC_6DB 0x8 |
| 108 | #define AD525X_CMD_INCALLRDAC_6DB 0x9 |
| 109 | #define AD525X_CMD_INCRDAC_ONE 0xA |
| 110 | #define AD525X_CMD_INCALLRDAC_ONE 0xB |
| 111 | /*****************************************************************************/ |
| 112 | |
| 113 | /**************************** SPI specific macros ****************************/ |
| 114 | #define AD525X_CMD_SPI_OFFSET 0x4 |
| 115 | #define AD525X_CMD_MASK 0xF |
| 116 | /* SPI Read/Write commands */ |
| 117 | #define AD525X_CMD_SPI_SREG2MEM 0x3 |
| 118 | #define AD525X_CMD_SPI_MEM2SREG 0x9 // Result in the next frame |
| 119 | #define AD525X_CMD_SPI_RDAC2SREG 0xA // Result in the next frame |
| 120 | #define AD525X_CMD_SPI_SREG2RDAC 0xB |
| 121 | |
| 122 | /*************************** I2C specific macros *****************************/ |
| 123 | /* I2C device address */ |
| 124 | #define AD525X_I2C_HARD_ADDR 0x2C |
| 125 | /* Package pin-programmable address bits */ |
| 126 | #define AD525X_I2C_PIN_ADDR_MASK 0x03 |
| 127 | /* Mask for I2C Control Bits */ |
| 128 | #define AD525X_I2C_CNTR_MASK 0xBF |
| 129 | /* Access Types */ |
| 130 | #define AD525X_I2C_CMD_OR_REG 0x80 |
| 131 | #define AD525X_I2C_EE_OR_RDAC 0x20 |
| 132 | /* Address mask for EEMEM addresses, one bit wider than at devices with SPI */ |
| 133 | #define AD525X_I2C_MEM_ADDR_MASK 0x1F |
| 134 | /* The offset of the Command in the I2C word */ |
| 135 | #define AD525X_CMD_I2C_OFFSET 0x3 |
| 136 | |
| 137 | /*************************** Reading tolerance addresses *********************/ |
| 138 | /* Note: The valid tolerance addresses varies on different devices. Check the data sheet for further information */ |
| 139 | #define AD525x_RDAC_TOLERANCE 0x0F |
| 140 | #define AD525X_RDAC0_SIGN_TOL 0x18 |
| 141 | #define AD525X_RDAC0_DECIMAL_TOL 0x19 |
| 142 | #define AD525X_RDAC1_SIGN_TOL 0x1A |
| 143 | #define AD525X_RDAC1_DECIMAL_TOL 0x1B |
| 144 | #define AD525X_RDAC2_SIGN_TOL 0x1C |
| 145 | #define AD525X_RDAC2_DECIMAL_TOL 0x1D |
| 146 | #define AD525X_RDAC3_SIGN_TOL 0x1E |
| 147 | #define AD525X_RDAC4_DECIMAL_TOL 0x1F |
| 148 | |
| 149 | /* The default slave ID for SPI interface */ |
| 150 | #define AD525X_SLAVE_ID 1 |
| 151 | |
| 152 | /*****************************************************************************/ |
| 153 | /* Functions Prototypes */ |
| 154 | /*****************************************************************************/ |
| 155 | /* Initialize the communication with the device */ |
| 156 | char AD525X_Init(AD525X_type_t device); |
| 157 | |
| 158 | /* Read data from the EEMEM */ |
| 159 | unsigned short AD525X_ReadMem(unsigned char slaveId, |
| 160 | unsigned char address); |
| 161 | |
| 162 | /* Write data to EEMEM */ |
| 163 | void AD525X_WriteMem(unsigned char slaveId, |
| 164 | unsigned char address, |
| 165 | unsigned short data); |
| 166 | |
| 167 | /* Read the value of the RDAC register */ |
| 168 | unsigned short AD525X_ReadRdac(unsigned char slaveId, |
| 169 | unsigned char address); |
| 170 | |
| 171 | /* Write the value of the RDAC register */ |
| 172 | void AD525X_WriteRdac(unsigned char slaveId, |
| 173 | unsigned char address, |
| 174 | unsigned short data); |
| 175 | |
| 176 | /* Write quick commands to the device */ |
| 177 | void AD525X_WriteCommand(unsigned char slaveId, |
| 178 | unsigned char command, |
| 179 | unsigned char address); |
| 180 | |
| 181 | #endif // __AD525X_H__ |