| 1 | /***************************************************************************//** |
| 2 | * @file AD5446.h |
| 3 | * @brief Header file of AD5446 Driver. This driver supporting the following |
| 4 | * devices: AD5553, AD5543, AD5542A, AD5541A, AD5512A, AD5453, |
| 5 | * AD5452, AD5451, AD5450, AD5446, AD5444 |
| 6 | * |
| 7 | * @author Istvan Csomortani ([email protected]) |
| 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 |
| 14 | * modification, |
| 15 | * are permitted provided that the following conditions are met: |
| 16 | * - Redistributions of source code must retain the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer. |
| 18 | * - Redistributions in binary form must reproduce the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer in |
| 20 | * the documentation and/or other materials provided with the |
| 21 | * distribution. |
| 22 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 23 | * contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * - The use of this software may or may not infringe the patent rights |
| 26 | * of one or more patent holders. This license does not release you |
| 27 | * from the requirement that you obtain separate licenses from these |
| 28 | * patent holders to use this software. |
| 29 | * - Use of the software either in source or binary form, must be run |
| 30 | * on or directly connected to an Analog Devices Inc. component. |
| 31 | * |
| 32 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 33 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 34 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 35 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 36 | * INCIDENTAL,SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 37 | * * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 40 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 41 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 42 | * DAMAGE. |
| 43 | * |
| 44 | *******************************************************************************/ |
| 45 | |
| 46 | /******************************************************************************/ |
| 47 | /***************************** Include Files **********************************/ |
| 48 | /******************************************************************************/ |
| 49 | #include "Communication.h" |
| 50 | |
| 51 | /* Supported output types */ |
| 52 | typedef enum |
| 53 | { |
| 54 | unipolar, /* 0 .. Vref */ |
| 55 | unipolar_inv, /* 0 .. -Vref */ |
| 56 | bipolar /* -Vref .. Vref*/ |
| 57 | } vout_type_t; |
| 58 | |
| 59 | /* Supported devices */ |
| 60 | typedef enum { |
| 61 | ID_AD5553, |
| 62 | ID_AD5543, |
| 63 | ID_AD5542A, |
| 64 | ID_AD5541A, |
| 65 | ID_AD5512A, |
| 66 | ID_AD5453, |
| 67 | ID_AD5452, |
| 68 | ID_AD5451, |
| 69 | ID_AD5450, |
| 70 | ID_AD5446, |
| 71 | ID_AD5444, |
| 72 | } AD5446_type_t; |
| 73 | |
| 74 | /* Control Bits */ |
| 75 | #define AD5446_CTRL_LOAD_UPDATE 0x0 |
| 76 | #define AD5446_CTRL_ACTIVE_POSEDGE 0x3 |
| 77 | |
| 78 | /* AD5446 GPIO */ |
| 79 | #define AD5446_LDAC_OUT GPIO1_PIN_OUT |
| 80 | #define AD5446_LDAC_LOW GPIO1_LOW |
| 81 | #define AD5446_LDAC_HIGH GPIO1_HIGH |
| 82 | |
| 83 | #define AD5446_CLR_OUT GPIO0_PIN_OUT |
| 84 | #define AD5446_CLR_LOW GPIO0_LOW |
| 85 | #define AD5446_CLR_HIGH GPIO0_HIGH |
| 86 | |
| 87 | /* SPI slave device ID |
| 88 | * These are board specific defines |
| 89 | * It should be defined in function of the current system configuration and architecture |
| 90 | * */ |
| 91 | #if(defined(AD5446) || defined(AD5444)) |
| 92 | #define AD5446_SLAVE_ID 2 |
| 93 | #else |
| 94 | #define AD5446_SLAVE_ID 1 |
| 95 | #endif |
| 96 | |
| 97 | /******************************************************************************/ |
| 98 | /************************ Functions Declarations ******************************/ |
| 99 | /******************************************************************************/ |
| 100 | /* Initialize SPI and Initial Values for AD5446 Board. */ |
| 101 | char AD5446_Init(AD5446_type_t device); |
| 102 | |
| 103 | /* Write to shift register via SPI. */ |
| 104 | void AD5446_SetRegister(unsigned char command, |
| 105 | unsigned short data); |
| 106 | |
| 107 | /* Sets the output voltage. */ |
| 108 | float AD5446_SetVoltage(float voltage, float vref, vout_type_t vout_type); |