no-OS
ad7091r5.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef SRC_AD7091R5_H_
41 #define SRC_AD7091R5_H_
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 #include <stdbool.h>
47 #include "no_os_i2c.h"
48 #include "no_os_gpio.h"
49 
50 /******************************************************************************/
51 /********************** Macros and Constants Definitions **********************/
52 /******************************************************************************/
53 #define AD7091R5_CHANNEL_NO 4
54 #define AD7091R5_BITS 12
55 #define AD7091R5_CONV_MASK NO_OS_GENMASK(AD7091R5_BITS - 1, 0)
56 
57 /* AD7091r5 registers */
58 #define AD7091R5_REG_RESULT 0
59 #define AD7091R5_REG_CHANNEL 1
60 #define AD7091R5_REG_CONF 2
61 #define AD7091R5_REG_ALERT 3
62 #define AD7091R5_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
63 #define AD7091R5_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
64 #define AD7091R5_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
65 
66 /* AD7091R5_REG_RESULT */
67 #define REG_RESULT_CH_ID(x) (((x) >> 13) & 0x3)
68 #define REG_RESULT_CONV_DATA(x) ((x) & AD7091R5_CONV_MASK)
69 
70 /* AD7091R5_REG_CONF */
71 #define REG_CONF_SLEEP_MODE_MASK NO_OS_BIT(0)
72 #define REG_CONF_SLEEP_MODE(x) ((x & 0x03) << 0)
73 
74 #define REG_CONF_GPO1_MASK NO_OS_BIT(2)
75 #define REG_CONF_GPO1(x) ((x & 0x01) << 2)
76 
77 #define REG_CONF_GPO0_MASK NO_OS_BIT(3)
78 #define REG_CONF_GPO0(x) ((x & 0x01) << 3)
79 
80 #define REG_CONF_GPO0_MODE_MASK (NO_OS_BIT(15) | NO_OS_BIT(5) | NO_OS_BIT(4))
81 #define REG_CONF_GPO0_ALERT(x) ((x & 0x01) << 4)
82 #define REG_CONF_GPO0_BUSY(x) ((x & 0x01) << 5)
83 #define REG_CONF_GPO0_DRIVE_TYPE(x) ((x & 0x01) << 15)
84 
85 #define REG_CONF_CYCLE_TIMER_MASK (NO_OS_BIT(7) | NO_OS_BIT(6))
86 #define REG_CONF_CYCLE_TIMER(x) ((x & 0x03) << 6)
87 
88 #define REG_CONF_GPO2_MASK NO_OS_BIT(14)
89 #define REG_CONF_GPO2(x) ((x & 0x01) << 14)
90 
91 #define REG_CONF_RESET_MASK NO_OS_BIT(9)
92 #define REG_CONF_RESET(x) ((x & 0x01) << 9)
93 
94 #define REG_CONF_MODE_MASK (NO_OS_BIT(10) | NO_OS_BIT(8))
95 #define REG_CONF_AUTO(x) ((x & 0x01) << 8)
96 #define REG_CONF_CMD(x) ((x & 0x01) << 10)
97 
98 /* AD7091R5_REG_ALERT */
99 #define REG_ALERT_MASK(x, ch) (x >> (ch * 2))
100 
101 /******************************************************************************/
102 /*************************** Types Declarations *******************************/
103 /******************************************************************************/
115 };
116 
131 };
132 
144 };
145 
157 };
158 
172 };
173 
185 };
186 
198 };
199 
205  /* I2C */
209 };
210 
215 struct ad7091r5_dev {
216  /* I2C descriptor */
220 };
221 
222 /******************************************************************************/
223 /************************ Functions Declarations ******************************/
224 /******************************************************************************/
225 /* Initialize the device. */
226 int32_t ad7091r5_init(struct ad7091r5_dev **device,
228 
229 /* Remove the device and release resources. */
230 int32_t ad7091r5_remove(struct ad7091r5_dev *dev);
231 
232 /* Set device mode */
233 int32_t ad7091r5_set_mode(struct ad7091r5_dev *dev,
234  enum ad7091r5_mode mode);
235 
236 /* Set device sleep mode */
237 int32_t ad7091r5_sleep_mode(struct ad7091r5_dev *dev,
238  enum ad7091r5_sleep_mode mode);
239 
240 /* Set device set port value */
241 int32_t ad7091r5_set_port(struct ad7091r5_dev *dev,
242  enum ad7091r5_port port, bool value);
243 
244 /* Set device set GPO0 mode */
245 int32_t ad7091r5_set_gpo0_mode(struct ad7091r5_dev *dev,
246  enum ad7091r5_gpo0_mode mode,
247  bool is_cmos);
248 /* Set cycle timer for autocycle mode*/
249 int32_t ad7091r5_set_cycle_timer(struct ad7091r5_dev *dev,
250  enum ad7091r5_cycle_timer timer);
251 
252 /* Set high limit, low limit, hysteresis. */
253 int32_t ad7091r5_set_limit(struct ad7091r5_dev *dev,
254  enum ad7091r5_limit limit,
255  uint8_t channel,
256  uint16_t value);
257 
258 /* Get alert. */
259 int32_t ad7091r5_get_alert(struct ad7091r5_dev *dev,
260  uint8_t channel,
261  enum ad7091r5_alert_type *alert);
262 
263 /* Get high limit, low limit, hysteresis. */
264 int32_t ad7091r5_get_limit(struct ad7091r5_dev *dev,
265  enum ad7091r5_limit limit,
266  uint8_t channel,
267  uint16_t *value);
268 
269 /* Select device channel. */
270 int32_t ad7091r5_set_channel(struct ad7091r5_dev *dev,
271  uint8_t channel);
272 
273 /* Read one sample. */
274 int32_t ad7091r5_read_one(struct ad7091r5_dev *dev,
275  uint8_t channel,
276  uint16_t *read_val);
277 
278 #endif /* SRC_AD7091R5_H_ */
AD7091R5_SLEEP_MODE_2
@ AD7091R5_SLEEP_MODE_2
Definition: ad7091r5.h:128
ad7091r5_sleep_mode
int32_t ad7091r5_sleep_mode(struct ad7091r5_dev *dev, enum ad7091r5_sleep_mode mode)
Definition: ad7091r5.c:169
REG_CONF_GPO0_ALERT
#define REG_CONF_GPO0_ALERT(x)
Definition: ad7091r5.h:81
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:85
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:165
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:58
ad7091r5_read_one
int32_t ad7091r5_read_one(struct ad7091r5_dev *dev, uint8_t channel, uint16_t *read_val)
Definition: ad7091r5.c:499
AD7091R5_HIGH_ALERT
@ AD7091R5_HIGH_ALERT
Definition: ad7091r5.h:182
AD7091R5_SLEEP_MODE_0
@ AD7091R5_SLEEP_MODE_0
Definition: ad7091r5.h:124
ad7091r5_init
int32_t ad7091r5_init(struct ad7091r5_dev **device, struct ad7091r5_init_param *init_param)
Definition: ad7091r5.c:534
ad7091r5_get_alert
int32_t ad7091r5_get_alert(struct ad7091r5_dev *dev, uint8_t channel, enum ad7091r5_alert_type *alert)
Definition: ad7091r5.c:277
ad7091r5_set_limit
int32_t ad7091r5_set_limit(struct ad7091r5_dev *dev, enum ad7091r5_limit limit, uint8_t channel, uint16_t value)
Definition: ad7091r5.c:307
AD7091R5_REG_CH_HYSTERESIS
#define AD7091R5_REG_CH_HYSTERESIS(ch)
Definition: ad7091r5.h:64
REG_CONF_GPO0_MASK
#define REG_CONF_GPO0_MASK
Definition: ad7091r5.h:77
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:119
ad7091r5_init_param::gpio_resetn
struct no_os_gpio_init_param * gpio_resetn
Definition: ad7091r5.h:208
AD7091R5_HIGH_LIMIT
@ AD7091R5_HIGH_LIMIT
Definition: ad7091r5.h:195
ad7091r5_get_limit
int32_t ad7091r5_get_limit(struct ad7091r5_dev *dev, enum ad7091r5_limit limit, uint8_t channel, uint16_t *value)
Definition: ad7091r5.c:342
REG_CONF_RESET_MASK
#define REG_CONF_RESET_MASK
Definition: ad7091r5.h:91
AD7091R5_CYCLE_TIMER_200uS
@ AD7091R5_CYCLE_TIMER_200uS
Definition: ad7091r5.h:167
REG_CONF_GPO0_MODE_MASK
#define REG_CONF_GPO0_MODE_MASK
Definition: ad7091r5.h:80
AD7091R5_SLEEP_MODE_3
@ AD7091R5_SLEEP_MODE_3
Definition: ad7091r5.h:130
no_os_delay.h
Header file of Delay functions.
AD7091R5_REG_RESULT
#define AD7091R5_REG_RESULT
Definition: ad7091r5.h:58
no_os_spi_init_param::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:139
ad7091r5_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: ad7091r5.h:217
AD7091R5_MODE_SAMPLE
@ AD7091R5_MODE_SAMPLE
Definition: ad7091r5.h:110
device
Definition: ad9361_util.h:75
ad7091r5_limit
ad7091r5_limit
Limit type.
Definition: ad7091r5.h:191
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:123
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:53
AD7091R5_REG_CONF
#define AD7091R5_REG_CONF
Definition: ad7091r5.h:60
AD7091R5_GPO0
@ AD7091R5_GPO0
Definition: ad7091r5.h:139
ad7091r5_dev::gpio_resetn
struct no_os_gpio_desc * gpio_resetn
Definition: ad7091r5.h:219
AD7091R5_GPO2
@ AD7091R5_GPO2
Definition: ad7091r5.h:143
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:121
ad7091r5_init_param::i2c_init
struct no_os_i2c_init_param * i2c_init
Definition: ad7091r5.h:206
ad7091r5_i2c_reg_read
int32_t ad7091r5_i2c_reg_read(struct ad7091r5_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition: ad7091r5.c:63
REG_RESULT_CONV_DATA
#define REG_RESULT_CONV_DATA(x)
Definition: ad7091r5.h:68
ad7091r5_port
ad7091r5_port
Converter general purpose outputs.
Definition: ad7091r5.h:137
ad7091r5.h
Header file for ad7091r5 Driver.
REG_CONF_RESET
#define REG_CONF_RESET(x)
Definition: ad7091r5.h:92
ad7091r5_set_port
int32_t ad7091r5_set_port(struct ad7091r5_dev *dev, enum ad7091r5_port port, bool value)
Definition: ad7091r5.c:187
REG_CONF_GPO0
#define REG_CONF_GPO0(x)
Definition: ad7091r5.h:78
ad7091r5_set_mode
int32_t ad7091r5_set_mode(struct ad7091r5_dev *dev, enum ad7091r5_mode mode)
Definition: ad7091r5.c:382
REG_CONF_AUTO
#define REG_CONF_AUTO(x)
Definition: ad7091r5.h:95
REG_CONF_SLEEP_MODE_MASK
#define REG_CONF_SLEEP_MODE_MASK
Definition: ad7091r5.h:71
no_os_error.h
Error codes definition.
AD7091R5_REG_CH_HIGH_LIMIT
#define AD7091R5_REG_CH_HIGH_LIMIT(ch)
Definition: ad7091r5.h:63
ad7091r5_set_port
int32_t ad7091r5_set_port(struct ad7091r5_dev *dev, enum ad7091r5_port port, bool value)
Definition: ad7091r5.c:187
REG_CONF_GPO0_DRIVE_TYPE
#define REG_CONF_GPO0_DRIVE_TYPE(x)
Definition: ad7091r5.h:83
REG_CONF_SLEEP_MODE
#define REG_CONF_SLEEP_MODE(x)
Definition: ad7091r5.h:72
ad7091r5_set_limit
int32_t ad7091r5_set_limit(struct ad7091r5_dev *dev, enum ad7091r5_limit limit, uint8_t channel, uint16_t value)
Definition: ad7091r5.c:307
AD7091R5_NO_ALERT
@ AD7091R5_NO_ALERT
Definition: ad7091r5.h:180
AD7091R5_GPO1
@ AD7091R5_GPO1
Definition: ad7091r5.h:141
ad7091r5_reset
int32_t ad7091r5_reset(struct ad7091r5_dev *dev, bool is_software)
Initialize GPIO driver handlers for the GPIOs in the system. ad7091r5_init() helper function.
Definition: ad7091r5.c:442
AD7091R5_CYCLE_TIMER_400uS
@ AD7091R5_CYCLE_TIMER_400uS
Definition: ad7091r5.h:169
ad7091r5_set_channel
int32_t ad7091r5_set_channel(struct ad7091r5_dev *dev, uint8_t channel)
Definition: ad7091r5.c:412
ad7091r5_set_channel
int32_t ad7091r5_set_channel(struct ad7091r5_dev *dev, uint8_t channel)
Definition: ad7091r5.c:412
AD7091R5_SLEEP_MODE_1
@ AD7091R5_SLEEP_MODE_1
Definition: ad7091r5.h:126
ad7091r5_gpo0_mode
ad7091r5_gpo0_mode
Port 0 configuration.
Definition: ad7091r5.h:150
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:110
no_os_gpio_desc::port
int32_t port
Definition: no_os_gpio.h:104
REG_ALERT_MASK
#define REG_ALERT_MASK(x, ch)
Definition: ad7091r5.h:99
ad7091r5_set_cycle_timer
int32_t ad7091r5_set_cycle_timer(struct ad7091r5_dev *dev, enum ad7091r5_cycle_timer timer)
Definition: ad7091r5.c:259
AD7091R5_CHANNEL_NO
#define AD7091R5_CHANNEL_NO
Definition: ad7091r5.h:53
ad7091r5_cycle_timer
ad7091r5_cycle_timer
Timer used for autocycle mode.
Definition: ad7091r5.h:163
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
ad7091r5_remove
int32_t ad7091r5_remove(struct ad7091r5_dev *dev)
Free the memory allocated by ad7091r5_init().
Definition: ad7091r5.c:580
ad7091r5_dev
Structure representing an ad7091r5 device.
Definition: ad7091r5.h:215
ad7091r5_init
int32_t ad7091r5_init(struct ad7091r5_dev **device, struct ad7091r5_init_param *init_param)
Definition: ad7091r5.c:534
ad7091r5_i2c_write_mask
int32_t ad7091r5_i2c_write_mask(struct ad7091r5_dev *dev, uint8_t reg_addr, uint16_t mask, uint16_t data)
Definition: ad7091r5.c:142
AD7091R5_LOW_LIMIT
@ AD7091R5_LOW_LIMIT
Definition: ad7091r5.h:193
AD7091R5_MODE_COMMAND
@ AD7091R5_MODE_COMMAND
Definition: ad7091r5.h:112
AD7091R5_REG_ALERT
#define AD7091R5_REG_ALERT
Definition: ad7091r5.h:61
ad7091r5_set_cycle_timer
int32_t ad7091r5_set_cycle_timer(struct ad7091r5_dev *dev, enum ad7091r5_cycle_timer timer)
Definition: ad7091r5.c:259
ad7091r5_get_alert
int32_t ad7091r5_get_alert(struct ad7091r5_dev *dev, uint8_t channel, enum ad7091r5_alert_type *alert)
Definition: ad7091r5.c:277
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:107
REG_CONF_GPO2_MASK
#define REG_CONF_GPO2_MASK
Definition: ad7091r5.h:88
AD7091R5_REG_CH_LOW_LIMIT
#define AD7091R5_REG_CH_LOW_LIMIT(ch)
Definition: ad7091r5.h:62
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:196
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:49
no_os_i2c.h
Header file of I2C Interface.
ad7091r5_get_limit
int32_t ad7091r5_get_limit(struct ad7091r5_dev *dev, enum ad7091r5_limit limit, uint8_t channel, uint16_t *value)
Definition: ad7091r5.c:342
ad7091r5_init_param
Structure containing the init parameters needed by the ad7091r5 device.
Definition: ad7091r5.h:204
AD7091R5_REG_CHANNEL
#define AD7091R5_REG_CHANNEL
Definition: ad7091r5.h:59
AD7091R5_MODE_AUTOCYCLE
@ AD7091R5_MODE_AUTOCYCLE
Definition: ad7091r5.h:114
ad7091r5_i2c_read_mask
int32_t ad7091r5_i2c_read_mask(struct ad7091r5_dev *dev, uint8_t reg_addr, uint8_t mask, uint16_t *data)
Definition: ad7091r5.c:117
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:51
REG_CONF_GPO2
#define REG_CONF_GPO2(x)
Definition: ad7091r5.h:89
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:75
ad7091r5_i2c_reg_write
int32_t ad7091r5_i2c_reg_write(struct ad7091r5_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition: ad7091r5.c:93
ad7091r5_remove
int32_t ad7091r5_remove(struct ad7091r5_dev *dev)
Free the memory allocated by ad7091r5_init().
Definition: ad7091r5.c:580
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: aducm3029_delay.c:120
AD7091R5_GPO0_ALERT
@ AD7091R5_GPO0_ALERT
Definition: ad7091r5.h:154
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:70
no_os_gpio_set_value
int32_t no_os_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: no_os_gpio.c:203
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:119
ad7091r5_mode
ad7091r5_mode
Converter supported modes.
Definition: ad7091r5.h:108
REG_CONF_GPO1
#define REG_CONF_GPO1(x)
Definition: ad7091r5.h:75
ad7091r5_set_gpo0_mode
int32_t ad7091r5_set_gpo0_mode(struct ad7091r5_dev *dev, enum ad7091r5_gpo0_mode mode, bool is_cmos)
Definition: ad7091r5.c:225
AD7091R5_CYCLE_TIMER_100uS
@ AD7091R5_CYCLE_TIMER_100uS
Definition: ad7091r5.h:165
REG_RESULT_CH_ID
#define REG_RESULT_CH_ID(x)
Definition: ad7091r5.h:67
REG_CONF_CYCLE_TIMER
#define REG_CONF_CYCLE_TIMER(x)
Definition: ad7091r5.h:86
no_os_gpio.h
Header file of GPIO Interface.
AD7091R5_GPO0_ENABLED
@ AD7091R5_GPO0_ENABLED
Definition: ad7091r5.h:152
REG_CONF_CMD
#define REG_CONF_CMD(x)
Definition: ad7091r5.h:96
ad7091r5_set_mode
int32_t ad7091r5_set_mode(struct ad7091r5_dev *dev, enum ad7091r5_mode mode)
Definition: ad7091r5.c:382
REG_CONF_GPO0_BUSY
#define REG_CONF_GPO0_BUSY(x)
Definition: ad7091r5.h:82
no_os_util.h
Header file of utility functions.
ad7091r5_sleep_mode
ad7091r5_sleep_mode
Converter supported sleep modes.
Definition: ad7091r5.h:121
AD7091R5_GPO0_BUSY
@ AD7091R5_GPO0_BUSY
Definition: ad7091r5.h:156
REG_CONF_GPO1_MASK
#define REG_CONF_GPO1_MASK
Definition: ad7091r5.h:74
no_os_gpio_direction_output
int32_t no_os_gpio_direction_output(struct no_os_gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: no_os_gpio.c:153
ad7091r5_alert_type
ad7091r5_alert_type
Alert status.
Definition: ad7091r5.h:178
ad7091r5_read_one
int32_t ad7091r5_read_one(struct ad7091r5_dev *dev, uint8_t channel, uint16_t *read_val)
Definition: ad7091r5.c:499
AD7091R5_CYCLE_TIMER_800uS
@ AD7091R5_CYCLE_TIMER_800uS
Definition: ad7091r5.h:171
ad7091r5_set_gpo0_mode
int32_t ad7091r5_set_gpo0_mode(struct ad7091r5_dev *dev, enum ad7091r5_gpo0_mode mode, bool is_cmos)
Definition: ad7091r5.c:225
AD7091R5_HYSTERESIS
@ AD7091R5_HYSTERESIS
Definition: ad7091r5.h:197
errno.h
Error macro definition for ARM Compiler.
REG_CONF_MODE_MASK
#define REG_CONF_MODE_MASK
Definition: ad7091r5.h:94
REG_CONF_CYCLE_TIMER_MASK
#define REG_CONF_CYCLE_TIMER_MASK
Definition: ad7091r5.h:85
AD7091R5_LOW_ALERT
@ AD7091R5_LOW_ALERT
Definition: ad7091r5.h:184
no_os_gpio_get_optional
int32_t no_os_gpio_get_optional(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Get the value of an optional GPIO.
Definition: no_os_gpio.c:81