Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/device_drivers/AD5791/AD5791.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file AD5791.h
3 * @brief Header file of AD5791 Driver.
4 * @author DNechita ([email protected])
5 ********************************************************************************
6 * Copyright 2013(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 *******************************************************************************/
40 #ifndef __AD5791_H__
41 #define __AD5791_H__
42
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 #include "Communication.h" // Communication definitions
47
48 /******************************************************************************/
49 /******************* Macros and Constants Definitions *************************/
50 /******************************************************************************/
51 /* Supported devices */
52 typedef enum {
53 ID_AD5760,
54 ID_AD5780,
55 ID_AD5781,
56 ID_AD5790,
57 ID_AD5791,
58 } AD5791_type;
59
60 /******************************************************************************/
61 /*********************************** GPIO *************************************/
62 /******************************************************************************/
63 #define AD5791_RESET_OUT GPIO2_PIN_OUT
64 #define AD5791_RESET_LOW GPIO2_LOW
65 #define AD5791_RESET_HIGH GPIO2_HIGH
66
67 #define AD5791_CLR_OUT GPIO3_PIN_OUT
68 #define AD5791_CLR_LOW GPIO3_LOW
69 #define AD5791_CLR_HIGH GPIO3_HIGH
70
71 #define AD5791_LDAC_OUT GPIO4_PIN_OUT
72 #define AD5791_LDAC_LOW GPIO4_LOW
73 #define AD5791_LDAC_HIGH GPIO4_HIGH
74
75 /******************************************************************************/
76 /********************************** AD5791 ************************************/
77 /******************************************************************************/
78
79 /* SPI slave device ID */
80 #define AD5791_SLAVE_ID 1
81
82 /* Maximum resolution */
83 #define MAX_RESOLUTION 20
84
85 /* Register Map */
86 #define AD5791_NOP 0 // No operation (NOP).
87 #define AD5791_REG_DAC 1 // DAC register.
88 #define AD5791_REG_CTRL 2 // Control register.
89 #define AD5791_REG_CLR_CODE 3 // Clearcode register.
90 #define AD5791_CMD_WR_SOFT_CTRL 4 // Software control register(Write only).
91
92 /* Input Shift Register bit definition. */
93 #define AD5791_READ (1ul << 23)
94 #define AD5791_WRITE (0ul << 23)
95 #define AD5791_ADDR_REG(x) (((unsigned long)(x) & 0x7) << 20)
96
97 /* Control Register bit Definition */
98 #define AD5791_CTRL_LINCOMP(x) (((x) & 0xF) << 6) // Linearity error compensation.
99 #define AD5791_CTRL_SDODIS (1 << 5) // SDO pin enable/disable control.
100 #define AD5791_CTRL_BIN2SC (1 << 4) // DAC register coding selection.
101 #define AD5791_CTRL_DACTRI (1 << 3) // DAC tristate control.
102 #define AD5791_CTRL_OPGND (1 << 2) // Output ground clamp control.
103 #define AD5791_CTRL_RBUF (1 << 1) // Output amplifier configuration control.
104
105 /* Software Control Register bit definition */
106 #define AD5791_SOFT_CTRL_RESET (1 << 2) // RESET function.
107 #define AD5791_SOFT_CTRL_CLR (1 << 1) // CLR function.
108 #define AD5791_SOFT_CTRL_LDAC (1 << 0) // LDAC function.
109
110 /* DAC OUTPUT STATES */
111 #define AD5791_OUT_NORMAL 0x0
112 #define AD5791_OUT_CLAMPED_6K 0x1
113 #define AD5791_OUT_TRISTATE 0x2
114
115 /******************************************************************************/
116 /************************ Functions Declarations ******************************/
117 /******************************************************************************/
118
119 /*! Initializes the communication with the device. */
120 long AD5791_Init(AD5791_type device);
121
122 /*! Writes data into a register. */
123 long AD5791_SetRegisterValue(unsigned char registerAddress,
124 unsigned long registerValue);
125
126 /*! Reads the value of a register. */
127 long AD5791_GetRegisterValue(unsigned char registerAddress);
128
129 /*! Sets the DAC output in one of the three states. */
130 long AD5791_DacOuputState(unsigned char state);
131
132 /*! Writes to the DAC register. */
133 long AD5791_SetDacValue(unsigned long value);
134
135 /*! Asserts RESET, CLR or LDAC in a software manner. */
136 long AD5791_SoftInstruction(unsigned char instructionBit);
137
138 /*! Configures the output amplifier, DAC coding, SDO state and the linearity
139 error compensation. */
140 long AD5791_Setup(unsigned long setupWord);
141
142 #endif /* __AD5791_H__ */