| 1 | /**************************************************************************//** |
| 2 | * @file AD5421.h |
| 3 | * @brief Header file of AD5421 Driver for Microblaze processor. |
| 4 | * @author Lucian Sin ([email protected]) |
| 5 | * |
| 6 | ******************************************************************************* |
| 7 | * Copyright 2013(c) Analog Devices, Inc. |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, |
| 13 | * are permitted provided that the following conditions are met: |
| 14 | * - Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * - Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in |
| 18 | * the documentation and/or other materials provided with the |
| 19 | * distribution. |
| 20 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 21 | * contributors may be used to endorse or promote products derived |
| 22 | * from this software without specific prior written permission. |
| 23 | * - The use of this software may or may not infringe the patent rights |
| 24 | * of one or more patent holders. This license does not release you |
| 25 | * from the requirement that you obtain separate licenses from these |
| 26 | * patent holders to use this software. |
| 27 | * - Use of the software either in source or binary form, must be run |
| 28 | * on or directly connected to an Analog Devices Inc. component. |
| 29 | * |
| 30 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 31 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 32 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 33 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 34 | * INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 35 | * * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS |
| 36 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 37 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 38 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 39 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 40 | * DAMAGE. |
| 41 | * |
| 42 | ******************************************************************************/ |
| 43 | #ifndef _AD5421_H_ |
| 44 | #define _AD5421_H_ |
| 45 | |
| 46 | /*****************************************************************************/ |
| 47 | /******************** Macros and Constants Definitions ***********************/ |
| 48 | /*****************************************************************************/ |
| 49 | /* COMMAND Bytes */ |
| 50 | #define AD5421_CMDWRDAC 1 |
| 51 | #define AD5421_CMDWRCTRL 2 |
| 52 | #define AD5421_CMDWROFFSET 3 |
| 53 | #define AD5421_CMDWRGAIN 4 |
| 54 | #define AD5421_CMDRST 7 |
| 55 | #define AD5421_CMDMEASVTEMP 8 |
| 56 | #define AD5421_CMDRDDAC 129 |
| 57 | #define AD5421_CMDRDCTRL 130 |
| 58 | #define AD5421_CMDRDOFFSET 131 |
| 59 | #define AD5421_CMDRDGAIN 132 |
| 60 | #define AD5421_CMDRDFAULT 133 |
| 61 | |
| 62 | /* AD5421 COMMAND mask */ |
| 63 | #define AD5421_CMD(x) ((x & 0xFF) << 16) |
| 64 | |
| 65 | /* AD5421 GPIO */ |
| 66 | #define AD5421_LDAC_OUT GPIO0_PIN_OUT |
| 67 | #define AD5421_LDAC_LOW GPIO0_LOW |
| 68 | #define AD5421_LDAC_HIGH GPIO0_HIGH |
| 69 | #define AD5421_FAULT_IN GPIO1_PIN_IN |
| 70 | |
| 71 | /* CONTROL register bits */ |
| 72 | #define CTRL_SPI_WATCHDOG (1 << 12) |
| 73 | #define CTRL_AUTO_FAULT_RDBK (1 << 11) |
| 74 | #define CTRL_SEL_ADC_INPUT (1 << 8) |
| 75 | #define CTRL_ONCHIP_ADC (1 << 7) |
| 76 | |
| 77 | /* SPI Configuration */ |
| 78 | #define AD5421_SLAVE_ID 1 |
| 79 | |
| 80 | /*****************************************************************************/ |
| 81 | /************************* Functions Declarations ****************************/ |
| 82 | /*****************************************************************************/ |
| 83 | /* Initialize the communication with the device. */ |
| 84 | int AD5421_Init(void); |
| 85 | /* Initialize the communication with the device. */ |
| 86 | int AD5421_UpdateParameters(void); |
| 87 | /* Set the value of DAC register. */ |
| 88 | void AD5421_SetDac(int dacValue); |
| 89 | /* Set the value of OFFSET register. */ |
| 90 | void AD5421_SetOffset(int offsetValue); |
| 91 | /* Set the value of GAIN register. */ |
| 92 | void AD5421_SetGain(int gainValue); |
| 93 | /* Read the DAC register. */ |
| 94 | int AD5421_GetDac(void); |
| 95 | /* Read OFFSET register. */ |
| 96 | int AD5421_GetOffset(void); |
| 97 | /* Read GAIN register. */ |
| 98 | int AD5421_GetGain(void); |
| 99 | /* Read FAULT register. */ |
| 100 | int AD5421_GetFault(void); |
| 101 | /* Read the temperature from Fault register. */ |
| 102 | int AD5421_GetTemp(void); |
| 103 | /* Read VLoop-COM from Fault register. */ |
| 104 | float AD5421_GetVloop(void); |
| 105 | /* Send command via SPI. */ |
| 106 | int AD5421_Set(int *iValue); |
| 107 | /* Receive value via SPI. */ |
| 108 | int AD5421_Get(void); |
| 109 | /* Resets the AD5421 device. */ |
| 110 | void AD5421_Reset(void); |
| 111 | |
| 112 | #endif /* _AD5421_H_ */ |