ad7746.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 #include "periph/i2c.h"
51 #include "periph/gpio.h"
52 
56 #define AD7746_ZERO_SCALE_CODE (0x800000LL)
57 
61 #define AD7746_INTERNAL_VREF (1170)
62 
66 #define AD7746_DAC_MAX (0x7F)
67 
71 enum {
74 };
75 
79 enum {
80  AD7746_OK = 0,
81  AD7746_NOI2C = -1,
82  AD7746_NODEV = -2,
83  AD7746_NODATA = -3
84 };
85 
89 typedef enum {
93  AD7746_VT_SR_082 = 3
95 
99 typedef enum {
104  AD7746_VT_MD_VIN = 3
106 
110 typedef enum {
114 
118 typedef enum {
126  AD7746_CAP_SR_091 = 7
128 
132 typedef enum {
133  AD7746_EXC_A = 0x06,
134  AD7746_EXC_B = 0x09,
135  AD7746_EXC_AB = 0x0A
137 
141 typedef struct ad7746_params {
143  uint8_t addr;
144  uint8_t dac_a_cap;
145  uint8_t dac_b_cap;
152 
156 typedef struct ad7746 {
159 
170 int ad7746_init(ad7746_t *dev, const ad7746_params_t *params);
171 
188 int ad7746_read_capacitance_1(ad7746_t *dev, int *value);
189 
206 int ad7746_read_capacitance_2(ad7746_t *dev, int *value);
207 
225 int ad7746_read_voltage_in(ad7746_t *dev, int *value);
226 
243 int ad7746_read_voltage_vdd(ad7746_t *dev, int *value);
244 
261 int ad7746_read_temperature_int(ad7746_t *dev, int *value);
262 
279 int ad7746_read_temperature_ext(ad7746_t *dev, int *value);
280 
293 
306 
317 
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 
Low-level GPIO peripheral driver interface definitions.
int ad7746_set_cap_ch_input(const ad7746_t *dev, ad7746_cap_input_t input)
Sets the current input for the capacitive measurement.If not configured manually, the driver sets the...
struct ad7746 ad7746_t
AD7746 device descriptor.
ad7746_exc_config_t
Excitation signal output configuration.
Definition: ad7746.h:132
int ad7746_set_vt_ch_mode(ad7746_t *dev, ad7746_vt_mode_t mode)
Sets the mode for the voltage / temperature channel and updates the descriptor with the new configura...
ad7746_cap_input_t
Capacitance channel input.
Definition: ad7746.h:110
int ad7746_read_capacitance_2(ad7746_t *dev, int *value)
Reads the capacitance from the input 2 (CIN2).
int ad7746_init(ad7746_t *dev, const ad7746_params_t *params)
Initializes an AD7746 device.
ad7746_vt_mode_t
Voltage / Temperature channel modes.
Definition: ad7746.h:99
int ad7746_read_voltage_in(ad7746_t *dev, int *value)
Reads the voltage from the external voltage input (VIN).
int ad7746_set_vt_sr(const ad7746_t *dev, ad7746_vt_sample_rate_t sr)
Sets the sample rate for the voltage / temperature channel.
int ad7746_read_capacitance_1(ad7746_t *dev, int *value)
Reads the capacitance from the input 1 (CIN1).
int ad7746_read_temperature_ext(ad7746_t *dev, int *value)
Reads the temperature from the external sensor (see datasheet).
struct ad7746_params ad7746_params_t
AD7746 params.
ad7746_vt_sample_rate_t
Voltage / Temperature channel sample rates.
Definition: ad7746.h:89
int ad7746_read_voltage_vdd(ad7746_t *dev, int *value)
Reads the voltage from the VDD pin.
int ad7746_set_cap_sr(const ad7746_t *dev, ad7746_cap_sample_rate_t sr)
Sets the sample rate for the capacitance channel.
ad7746_cap_sample_rate_t
Capacitive channel sample rate.
Definition: ad7746.h:118
int ad7746_read_temperature_int(ad7746_t *dev, int *value)
Reads the temperature from the internal sensor.
@ AD7746_READ_VT_CH
read voltage / temperature channel
Definition: ad7746.h:73
@ AD7746_READ_CAP_CH
read capacitive channel
Definition: ad7746.h:72
@ AD7746_EXC_B
enable only exc B output
Definition: ad7746.h:134
@ AD7746_EXC_AB
enable exc A and B outputs
Definition: ad7746.h:135
@ AD7746_EXC_A
enable only exc A output
Definition: ad7746.h:133
@ AD7746_CAP_IN_1
CIN1 input.
Definition: ad7746.h:111
@ AD7746_CAP_IN_2
CIN2 input.
Definition: ad7746.h:112
@ AD7746_VT_MD_TEMP
internal temperature sensor
Definition: ad7746.h:101
@ AD7746_VT_MD_DIS
channel disabled
Definition: ad7746.h:100
@ AD7746_VT_MD_VDD
Vdd voltage monitor.
Definition: ad7746.h:103
@ AD7746_VT_MD_ETEMP
external temperature sensor (see datasheet)
Definition: ad7746.h:102
@ AD7746_VT_MD_VIN
external voltage input (Vin)
Definition: ad7746.h:104
@ AD7746_VT_SR_082
8.2 Hz
Definition: ad7746.h:93
@ AD7746_VT_SR_312
31.2 Hz
Definition: ad7746.h:91
@ AD7746_VT_SR_498
49.8 Hz
Definition: ad7746.h:90
@ AD7746_VT_SR_161
16.1 Hz
Definition: ad7746.h:92
@ AD7746_CAP_SR_109
10.9 Hz
Definition: ad7746.h:125
@ AD7746_CAP_SR_130
13.0 Hz
Definition: ad7746.h:124
@ AD7746_CAP_SR_263
26.3 Hz
Definition: ad7746.h:122
@ AD7746_CAP_SR_500
50.0 Hz
Definition: ad7746.h:121
@ AD7746_CAP_SR_161
16.1 Hz
Definition: ad7746.h:123
@ AD7746_CAP_SR_091
9.1 Hz
Definition: ad7746.h:126
@ AD7746_CAP_SR_909
90.9 Hz
Definition: ad7746.h:119
@ AD7746_CAP_SR_838
83.8 Hz
Definition: ad7746.h:120
@ AD7746_NOI2C
I2C communication failed.
Definition: ad7746.h:81
@ AD7746_OK
everything was fine
Definition: ad7746.h:80
@ AD7746_NODEV
no AD7746 device found on the bus
Definition: ad7746.h:82
@ AD7746_NODATA
no data available
Definition: ad7746.h:83
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:144
Low-level I2C peripheral driver interface definition.
AD7746 params.
Definition: ad7746.h:141
uint8_t addr
i2c address
Definition: ad7746.h:143
i2c_t i2c
i2c device
Definition: ad7746.h:142
ad7746_exc_config_t exc_config
excitation signal config
Definition: ad7746.h:146
ad7746_vt_mode_t vt_mode
mode of the voltage/temp ch
Definition: ad7746.h:149
ad7746_cap_sample_rate_t cap_sample_rate
capacitance sample rate
Definition: ad7746.h:147
uint8_t dac_b_cap
DAC B capacitance.
Definition: ad7746.h:145
ad7746_cap_input_t cap_input
selected capacitance input
Definition: ad7746.h:150
uint8_t dac_a_cap
DAC A capacitance.
Definition: ad7746.h:144
ad7746_vt_sample_rate_t vt_sample_rate
voltage/temp sample rate
Definition: ad7746.h:148
AD7746 device descriptor.
Definition: ad7746.h:156
ad7746_params_t params
device driver configuration
Definition: ad7746.h:157