| 1 | /**************************************************************************//** |
| 2 | * @file AD7156.h |
| 3 | * @brief AD7156 Driver Header file. |
| 4 | * @author ATofan ([email protected]) |
| 5 | * |
| 6 | ******************************************************************************* |
| 7 | * Copyright 2011(c) Analog Devices, Inc. |
| 8 | * |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without modification, |
| 12 | * are permitted provided that the following conditions are met: |
| 13 | * - Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer. |
| 15 | * - Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in |
| 17 | * the documentation and/or other materials provided with the |
| 18 | * distribution. |
| 19 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 20 | * contributors may be used to endorse or promote products derived |
| 21 | * from this software without specific prior written permission. |
| 22 | * - The use of this software may or may not infringe the patent rights |
| 23 | * of one or more patent holders. This license does not release you |
| 24 | * from the requirement that you obtain separate licenses from these |
| 25 | * patent holders to use this software. |
| 26 | * - Use of the software either in source or binary form, must be run |
| 27 | * on or directly connected to an Analog Devices Inc. component. |
| 28 | * |
| 29 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED |
| 30 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY |
| 31 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 32 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 34 | * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 35 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 36 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 38 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 39 | * |
| 40 | ******************************************************************************* |
| 41 | * SVN Revision: $WCREV$ |
| 42 | ******************************************************************************/ |
| 43 | |
| 44 | #ifndef AD7156_H_ |
| 45 | #define AD7156_H_ |
| 46 | |
| 47 | #include "xparameters.h" |
| 48 | |
| 49 | #define I2C_BASEADDR XPAR_AXI_IIC_1_BASEADDR |
| 50 | #define AD7156_I2C_ADDR 0x48 |
| 51 | /******************************************************************************/ |
| 52 | /* ADXL345 */ |
| 53 | /******************************************************************************/ |
| 54 | // AD7156 Registers |
| 55 | #define AD7156_STATUS 0x00 |
| 56 | #define AD7156_CH1_DATA_HIGH 0x01 |
| 57 | #define AD7156_CH1_DATA_LOW 0x02 |
| 58 | #define AD7156_CH2_DATA_HIGH 0x03 |
| 59 | #define AD7156_CH2_DATA_LOW 0x04 |
| 60 | #define AD7156_CH1_AVERAGE_HIGH 0x05 |
| 61 | #define AD7156_CH1_AVERAGE_LOW 0x06 |
| 62 | #define AD7156_CH2_AVERAGE_HIGH 0x07 |
| 63 | #define AD7156_CH2_AVERAGE_LOW 0x08 |
| 64 | #define AD7156_CH1_THRESH_HIGH 0x09 |
| 65 | #define AD7156_CH1_THRESH_LOW 0x0A |
| 66 | #define AD7156_CH1_SETUP 0x0B |
| 67 | #define AD7156_CH2_THRESH_HIGH 0x0C |
| 68 | #define AD7156_CH2_THRESH_LOW 0x0D |
| 69 | #define AD7156_CH2_SETUP 0x0E |
| 70 | #define AD7156_CONFIGURATION 0x0F |
| 71 | #define AD7156_POWER_DOWN_TIMER 0x10 |
| 72 | #define AD7156_CH1_CAPDAC 0x11 |
| 73 | #define AD7156_CH2_CAPDAC 0x12 |
| 74 | #define AD7156_SERIAL_NR_3 0x13 |
| 75 | #define AD7156_SERIAL_NR_2 0x14 |
| 76 | #define AD7156_SERIAL_NR_1 0x15 |
| 77 | #define AD7156_SERIAL_NR_0 0x16 |
| 78 | #define AD7156_CHIP_ID 0x17 |
| 79 | |
| 80 | // Register specific bits |
| 81 | // Status Register 0x00 |
| 82 | #define AD7156_PwrDown 7 |
| 83 | #define AD7156_DacStep2 6 |
| 84 | #define AD7156_OUT2 5 |
| 85 | #define AD7156_DacStep1 4 |
| 86 | #define AD7156_OUT1 3 |
| 87 | #define AD7156_C1_C2 2 |
| 88 | #define AD7156_nRDY2 1 |
| 89 | #define AD7156_nRDY1 0 |
| 90 | // Channel 1 Data High 0x01 |
| 91 | // Channel 1 Data Low 0x02 |
| 92 | // Channel 2 Data High 0x03 |
| 93 | // Channel 2 Data Low 0x04 |
| 94 | // Channel 1 Average High 0x05 |
| 95 | // Channel 1 Average Low 0x06 |
| 96 | // Channel 2 Average High 0x07 |
| 97 | // Channel 2 Average Low 0x08 |
| 98 | // Channel 1 Threshold High 0x09 |
| 99 | // Channel 1 Threshold Low 0x0A |
| 100 | // Channel 1 Threshold High 0x0C |
| 101 | // Channel 1 Threshold Low 0x0D |
| 102 | // Channel 1 Setup 0x0B |
| 103 | // Channel 2 Setup 0x0E |
| 104 | #define AD7156_RngH 7 |
| 105 | #define AD7156_RngL 6 |
| 106 | #define AD7156_nHyst 4 |
| 107 | #define AD7156_ThrSettling 0 |
| 108 | // Configuration Register 0x0F |
| 109 | #define AD7156_ThrFixed 7 |
| 110 | #define AD7156_ThrMD1 6 |
| 111 | #define AD7156_ThrMD0 5 |
| 112 | #define AD7156_EnCh1 4 |
| 113 | #define AD7156_EnCh2 3 |
| 114 | #define AD7156_MD2 2 |
| 115 | #define AD7156_MD1 1 |
| 116 | #define AD7156_MD0 0 |
| 117 | // Power Down Timer Register 0x10 |
| 118 | #define AD7156_PowerDownValue 0 |
| 119 | // Channel 1 CAPDAC Register 0x11 |
| 120 | // Channel 2 CAPDAC Register 0x12 |
| 121 | #define AD7156_DacEn 7 |
| 122 | #define AD7156_DacAuto 6 |
| 123 | #define AD7156_DacValue 0 |
| 124 | |
| 125 | /******************************************************************************/ |
| 126 | /* Function Prototypes */ |
| 127 | /******************************************************************************/ |
| 128 | void AD7156_DisplayMainMenu(void); |
| 129 | void AD7156_DisplayMenu(void); |
| 130 | int AD7156_ReadReg(int reg); |
| 131 | int AD7156_BurstReadReg(int reg, char size); |
| 132 | void AD7156_WriteReg(int reg, unsigned char txData); |
| 133 | void AD7156_BurstWriteReg(int reg, char size, int txData); |
| 134 | void AD7156_DisplayCurrentSettings(void); |
| 135 | void AD7156_Init(void); |
| 136 | void AD7156_ChangeRange(char range, char chan); |
| 137 | void AD7156_SetRange(void); |
| 138 | void AD7156_PrintCap(char channel); |
| 139 | void AD7156_PrintAverageCap(char channel); |
| 140 | void AD7156_Print(char channel); |
| 141 | void AD7156_PrintAverage(char channel); |
| 142 | void AD7156_SelChannels(void); |
| 143 | void AD7156_SelThreshold(void); |
| 144 | void AD7156_SetThreshold(void); |
| 145 | void ADITimerIntrFunction(void); |
| 146 | void ADIExtIntrFunction(void); |
| 147 | void DemoProgram(void); |
| 148 | |
| 149 | #endif /* AD7156_H_ */ |