no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ad7156.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef __AD7156_H__
34#define __AD7156_H__
35
36#include <stdint.h>
37#include "no_os_i2c.h"
38
40#define AD7156_ADDRESS 0x48
41
43#define AD7156_REG_STATUS 0x00
44#define AD7156_REG_CH1_DATA_H 0x01
45#define AD7156_REG_CH1_DATA_L 0x02
46#define AD7156_REG_CH2_DATA_H 0x03
47#define AD7156_REG_CH2_DATA_L 0x04
48#define AD7156_REG_CH1_AVG_H 0x05
49#define AD7156_REG_CH1_AVG_L 0x06
50#define AD7156_REG_CH2_AVG_H 0x07
51#define AD7156_REG_CH2_AVG_L 0x08
52#define AD7156_REG_CH1_SENS_THRSH_H 0x09
53#define AD7156_REG_CH1_TMO_THRSH_L 0x0A
54#define AD7156_REG_CH1_SETUP 0x0B
55#define AD7156_REG_CH2_SENS_THRSH_H 0x0C
56#define AD7156_REG_CH2_TMO_THRSH_L 0x0D
57#define AD7156_REG_CH2_SETUP 0x0E
58#define AD7156_REG_CONFIG 0x0F
59#define AD7156_REG_PWR_DWN_TMR 0x10
60#define AD7156_REG_CH1_CAPDAC 0x11
61#define AD7156_REG_CH2_CAPDAC 0x12
62#define AD7156_REG_SERIAL_N3 0x13
63#define AD7156_REG_SERIAL_N2 0x14
64#define AD7156_REG_SERIAL_N1 0x15
65#define AD7156_REG_SERIAL_N0 0x16
66#define AD7156_REG_CHIP_ID 0x17
67
69#define AD7156_STATUS_PWR_DWN (1 << 7)
70#define AD7156_STATUS_DAC_STEP2 (1 << 6)
71#define AD7156_STATUS_OUT2 (1 << 5)
72#define AD7156_STATUS_DAC_STEP1 (1 << 4)
73#define AD7156_STATUS_OUT1 (1 << 3)
74#define AD7156_STATUS_C1_C2 (1 << 2)
75#define AD7156_STATUS_RDY2 (1 << 1)
76#define AD7156_STATUS_RDY1 (1 << 0)
77
79#define AD7156_CH1_SETUP_RANGE(x) (((x) & 0x3) << 6)
80#define AD7156_CH1_SETUP_HYST1 (1 << 4)
81#define AD7156_CH1_SETUP_THR1(x) ((x) & 0xF)
82
84#define AD7156_CH2_SETUP_RANGE(x) (((x) & 0x3) << 6)
85#define AD7156_CH2_SETUP_HYST2 (1 << 4)
86#define AD7156_CH2_SETUP_THR2(x) ((x) & 0xF)
89#define AD7156_CDC_RANGE_2_PF 0
90#define AD7156_CDC_RANGE_0_5_PF 1
91#define AD7156_CDC_RANGE_1_PF 2
92#define AD7156_CDC_RANGE_4_PF 3
95#define AD7156_CONFIG_THR_FIXED (1 << 7)
96#define AD7156_CONFIG_THR_MD(x) (((x) & 0x3) << 5)
97#define AD7156_CONFIG_EN_CH1 (1 << 4)
98#define AD7156_CONFIG_EN_CH2 (1 << 3)
99#define AD7156_CONFIG_MD(x) ((x) & 0x7)
102#define AD7156_ADAPTIVE_THRESHOLD 0
103#define AD7156_FIXED_THRESHOLD 1
104
106#define AD7156_THR_MODE_NEGATIVE 0
107#define AD7156_THR_MODE_POSITIVE 1
108#define AD7156_THR_MODE_IN_WINDOW 2
109#define AD7156_THR_MODE_OU_WINDOW 3
110
112#define AD7156_CONV_MODE_IDLE 0
113#define AD7156_CONV_MODE_CONT_CONV 1
114#define AD7156_CONV_MODE_SINGLE_CONV 2
115#define AD7156_CONV_MODE_PWR_DWN 3
116
118#define AD7156_PWR_DWN_TMR_TIMEOUT(x) (((x) & 0x3F) | (1 << 6))
121#define AD7156_CH1_CAPDAC_DAC_EN1 (1 << 7)
122#define AD7156_CH1_CAPDAC_DAC_AUTO1 (1 << 6)
123#define AD7156_CH1_CAPDAC_DAC_VAL1(x) ((x) & 0x3F)
126#define AD7156_CH2_CAPDAC_DAC_EN2 (1 << 7)
127#define AD7156_CH2_CAPDAC_DAC_AUTO2 (1 << 6)
128#define AD7156_CH2_CAPDAC_DAC_VAL2(x) ((x) & 0x3F)
131#define AD7156_DEFAULT_ID 0x88
132
134#define AD7156_RESET_CMD 0xBF
135
137#define AD7156_CHANNEL1 1
138#define AD7156_CHANNEL2 2
139
140struct ad7156_dev {
141 /* I2C */
142 struct no_os_i2c_desc *i2c_desc;
143 /* Device Settings */
147
148struct ad7156_init_param {
149 /* I2C */
151 /* Device Settings */
155
158 uint8_t* p_read_data,
159 uint8_t register_address,
160 uint8_t bytes_number);
161
164 uint16_t register_value,
165 uint8_t register_address,
166 uint8_t bytes_number);
167
169int8_t ad7156_init(struct ad7156_dev **device,
171
173int32_t ad7156_remove(struct ad7156_dev *dev);
174
176void ad7156_reset(struct ad7156_dev *dev);
177
179void ad7156_set_power_mode(struct ad7156_dev *dev,
180 uint8_t pwr_mode);
181
183void ad7156_channel_state(struct ad7156_dev *dev,
184 uint8_t channel,
185 uint8_t enable_conv);
186
188void ad7156_set_range(struct ad7156_dev *dev,
189 uint32_t channel,
190 uint8_t range);
191
193float ad7156_get_range(struct ad7156_dev *dev,
194 uint32_t channel);
195
198 uint8_t thr_mode,
199 uint8_t thr_fixed);
200
202void ad7156_set_threshold(struct ad7156_dev *dev,
203 uint8_t channel,
204 float p_fthr);
205
208void ad7156_set_sensitivity(struct ad7156_dev *dev,
209 uint8_t channel,
210 float p_fsensitivity);
211
213uint16_t ad7156_read_channel_data(struct ad7156_dev *dev,
214 uint8_t channel);
215
218uint16_t ad7156_wait_read_channel_data(struct ad7156_dev *dev,
219 uint8_t channel);
220
224 uint8_t channel);
225
229 uint8_t channel);
230
231#endif /* __AD7156_H__ */
void ad7156_set_power_mode(struct ad7156_dev *dev, uint8_t pwr_mode)
Sets the converter mode of operation.
Definition ad7156.c:159
float ad7156_read_channel_capacitance(struct ad7156_dev *dev, uint8_t channel)
Reads a sample the selected channel and converts the data to picofarads(pF).
Definition ad7156.c:478
void ad7156_set_sensitivity(struct ad7156_dev *dev, uint8_t channel, float p_fsensitivity)
Writes a value(pF) to the sensitivity register. This functions should be used when adaptive threshold...
Definition ad7156.c:377
float ad7156_get_range(struct ad7156_dev *dev, uint32_t channel)
Reads the range bits from the device and returns the range in pF.
Definition ad7156.c:262
uint16_t ad7156_wait_read_channel_data(struct ad7156_dev *dev, uint8_t channel)
Waits for a finished CDC conversion and reads a 12-bit sample from the selected channel.
Definition ad7156.c:437
void ad7156_reset(struct ad7156_dev *dev)
Resets the device.
Definition ad7156.c:141
void ad7156_channel_state(struct ad7156_dev *dev, uint8_t channel, uint8_t enable_conv)
Enables or disables conversion on the selected channel.
Definition ad7156.c:188
void ad7156_set_register_value(struct ad7156_dev *dev, uint16_t register_value, uint8_t register_address, uint8_t bytes_number)
Writes data into one or two registers.
Definition ad7156.c:63
void ad7156_set_threshold(struct ad7156_dev *dev, uint8_t channel, float p_fthr)
Writes to the threshold register when threshold fixed mode is enabled.
Definition ad7156.c:343
float ad7156_wait_read_channel_capacitance(struct ad7156_dev *dev, uint8_t channel)
Waits for a finished CDC conversion the selected channel, reads a sample and converts the data to pic...
Definition ad7156.c:509
int8_t ad7156_init(struct ad7156_dev **device, struct ad7156_init_param init_param)
Initializes the communication peripheral and the initial Values for AD7156 Board.
Definition ad7156.c:90
int32_t ad7156_remove(struct ad7156_dev *dev)
Free the resources allocated by ad7156_init().
Definition ad7156.c:125
void ad7156_get_register_value(struct ad7156_dev *dev, uint8_t *p_read_data, uint8_t register_address, uint8_t bytes_number)
Performs a burst read of a specified number of registers.
Definition ad7156.c:46
uint16_t ad7156_read_channel_data(struct ad7156_dev *dev, uint8_t channel)
Reads a 12-bit sample from the selected channel.
Definition ad7156.c:406
void ad7156_set_threshold_mode(struct ad7156_dev *dev, uint8_t thr_mode, uint8_t thr_fixed)
Selects the threshold mode of operation.
Definition ad7156.c:312
void ad7156_set_range(struct ad7156_dev *dev, uint32_t channel, uint8_t range)
Sets the input range of the specified channel.
Definition ad7156.c:223
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
Header file of I2C Interface.
Definition ad7156.h:152
float ad7156_channel2_range
Definition ad7156.h:157
float ad7156_channel1_range
Definition ad7156.h:156
struct no_os_i2c_desc * i2c_desc
Definition ad7156.h:154
Definition ad7156.h:160
struct no_os_i2c_init_param i2c_init
Definition ad7156.h:162
Definition ad9361_util.h:63
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89
Structure holding the parameters for I2C initialization.
Definition no_os_i2c.h:52