no-OS
ad7091r5.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef SRC_AD7091R5_H_
35 #define SRC_AD7091R5_H_
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 #include <stdbool.h>
41 #include "no_os_i2c.h"
42 #include "no_os_gpio.h"
43 
44 /******************************************************************************/
45 /********************** Macros and Constants Definitions **********************/
46 /******************************************************************************/
47 #define AD7091R5_CHANNEL_NO 4
48 #define AD7091R5_BITS 12
49 #define AD7091R5_CONV_MASK NO_OS_GENMASK(AD7091R5_BITS - 1, 0)
50 
51 /* AD7091r5 registers */
52 #define AD7091R5_REG_RESULT 0
53 #define AD7091R5_REG_CHANNEL 1
54 #define AD7091R5_REG_CONF 2
55 #define AD7091R5_REG_ALERT 3
56 #define AD7091R5_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
57 #define AD7091R5_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
58 #define AD7091R5_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
59 
60 /* AD7091R5_REG_RESULT */
61 #define REG_RESULT_CH_ID(x) (((x) >> 13) & 0x3)
62 #define REG_RESULT_CONV_DATA(x) ((x) & AD7091R5_CONV_MASK)
63 
64 /* AD7091R5_REG_CONF */
65 #define REG_CONF_SLEEP_MODE_MASK NO_OS_BIT(0)
66 #define REG_CONF_SLEEP_MODE(x) ((x & 0x03) << 0)
67 
68 #define REG_CONF_GPO1_MASK NO_OS_BIT(2)
69 #define REG_CONF_GPO1(x) ((x & 0x01) << 2)
70 
71 #define REG_CONF_GPO0_MASK NO_OS_BIT(3)
72 #define REG_CONF_GPO0(x) ((x & 0x01) << 3)
73 
74 #define REG_CONF_GPO0_MODE_MASK (NO_OS_BIT(15) | NO_OS_BIT(5) | NO_OS_BIT(4))
75 #define REG_CONF_GPO0_ALERT(x) ((x & 0x01) << 4)
76 #define REG_CONF_GPO0_BUSY(x) ((x & 0x01) << 5)
77 #define REG_CONF_GPO0_DRIVE_TYPE(x) ((x & 0x01) << 15)
78 
79 #define REG_CONF_CYCLE_TIMER_MASK (NO_OS_BIT(7) | NO_OS_BIT(6))
80 #define REG_CONF_CYCLE_TIMER(x) ((x & 0x03) << 6)
81 
82 #define REG_CONF_GPO2_MASK NO_OS_BIT(14)
83 #define REG_CONF_GPO2(x) ((x & 0x01) << 14)
84 
85 #define REG_CONF_RESET_MASK NO_OS_BIT(9)
86 #define REG_CONF_RESET(x) ((x & 0x01) << 9)
87 
88 #define REG_CONF_MODE_MASK (NO_OS_BIT(10) | NO_OS_BIT(8))
89 #define REG_CONF_AUTO(x) ((x & 0x01) << 8)
90 #define REG_CONF_CMD(x) ((x & 0x01) << 10)
91 
92 /* AD7091R5_REG_ALERT */
93 #define REG_ALERT_MASK(x, ch) (x >> (ch * 2))
94 
95 /******************************************************************************/
96 /*************************** Types Declarations *******************************/
97 /******************************************************************************/
109 };
110 
125 };
126 
138 };
139 
151 };
152 
166 };
167 
179 };
180 
192 };
193 
199  /* I2C */
203 };
204 
209 struct ad7091r5_dev {
210  /* I2C descriptor */
214 };
215 
216 /******************************************************************************/
217 /************************ Functions Declarations ******************************/
218 /******************************************************************************/
219 /* Initialize the device. */
220 int32_t ad7091r5_init(struct ad7091r5_dev **device,
222 
223 /* Remove the device and release resources. */
224 int32_t ad7091r5_remove(struct ad7091r5_dev *dev);
225 
226 /* Set device mode */
227 int32_t ad7091r5_set_mode(struct ad7091r5_dev *dev,
228  enum ad7091r5_mode mode);
229 
230 /* Set device sleep mode */
231 int32_t ad7091r5_sleep_mode(struct ad7091r5_dev *dev,
232  enum ad7091r5_sleep_mode mode);
233 
234 /* Set device set port value */
235 int32_t ad7091r5_set_port(struct ad7091r5_dev *dev,
236  enum ad7091r5_port port, bool value);
237 
238 /* Set device set GPO0 mode */
239 int32_t ad7091r5_set_gpo0_mode(struct ad7091r5_dev *dev,
240  enum ad7091r5_gpo0_mode mode,
241  bool is_cmos);
242 /* Set cycle timer for autocycle mode*/
243 int32_t ad7091r5_set_cycle_timer(struct ad7091r5_dev *dev,
244  enum ad7091r5_cycle_timer timer);
245 
246 /* Set high limit, low limit, hysteresis. */
247 int32_t ad7091r5_set_limit(struct ad7091r5_dev *dev,
248  enum ad7091r5_limit limit,
249  uint8_t channel,
250  uint16_t value);
251 
252 /* Get alert. */
253 int32_t ad7091r5_get_alert(struct ad7091r5_dev *dev,
254  uint8_t channel,
255  enum ad7091r5_alert_type *alert);
256 
257 /* Get high limit, low limit, hysteresis. */
258 int32_t ad7091r5_get_limit(struct ad7091r5_dev *dev,
259  enum ad7091r5_limit limit,
260  uint8_t channel,
261  uint16_t *value);
262 
263 /* Select device channel. */
264 int32_t ad7091r5_set_channel(struct ad7091r5_dev *dev,
265  uint8_t channel);
266 
267 /* Read one sample. */
268 int32_t ad7091r5_read_one(struct ad7091r5_dev *dev,
269  uint8_t channel,
270  uint16_t *read_val);
271 
272 #endif /* SRC_AD7091R5_H_ */
AD7091R5_SLEEP_MODE_2
@ AD7091R5_SLEEP_MODE_2
Definition: ad7091r5.h:122
ad7091r5_sleep_mode
int32_t ad7091r5_sleep_mode(struct ad7091r5_dev *dev, enum ad7091r5_sleep_mode mode)
Definition: ad7091r5.c:163
REG_CONF_GPO0_ALERT
#define REG_CONF_GPO0_ALERT(x)
Definition: ad7091r5.h:75
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
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:159
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:52
ad7091r5_read_one
int32_t ad7091r5_read_one(struct ad7091r5_dev *dev, uint8_t channel, uint16_t *read_val)
Definition: ad7091r5.c:493
AD7091R5_HIGH_ALERT
@ AD7091R5_HIGH_ALERT
Definition: ad7091r5.h:176
AD7091R5_SLEEP_MODE_0
@ AD7091R5_SLEEP_MODE_0
Definition: ad7091r5.h:118
ad7091r5_init
int32_t ad7091r5_init(struct ad7091r5_dev **device, struct ad7091r5_init_param *init_param)
Definition: ad7091r5.c:528
ad7091r5_get_alert
int32_t ad7091r5_get_alert(struct ad7091r5_dev *dev, uint8_t channel, enum ad7091r5_alert_type *alert)
Definition: ad7091r5.c:271
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:301
AD7091R5_REG_CH_HYSTERESIS
#define AD7091R5_REG_CH_HYSTERESIS(ch)
Definition: ad7091r5.h:58
REG_CONF_GPO0_MASK
#define REG_CONF_GPO0_MASK
Definition: ad7091r5.h:71
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:113
ad7091r5_init_param::gpio_resetn
struct no_os_gpio_init_param * gpio_resetn
Definition: ad7091r5.h:202
AD7091R5_HIGH_LIMIT
@ AD7091R5_HIGH_LIMIT
Definition: ad7091r5.h:189
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:336
REG_CONF_RESET_MASK
#define REG_CONF_RESET_MASK
Definition: ad7091r5.h:85
AD7091R5_CYCLE_TIMER_200uS
@ AD7091R5_CYCLE_TIMER_200uS
Definition: ad7091r5.h:161
REG_CONF_GPO0_MODE_MASK
#define REG_CONF_GPO0_MODE_MASK
Definition: ad7091r5.h:74
AD7091R5_SLEEP_MODE_3
@ AD7091R5_SLEEP_MODE_3
Definition: ad7091r5.h:124
no_os_delay.h
Header file of Delay functions.
AD7091R5_REG_RESULT
#define AD7091R5_REG_RESULT
Definition: ad7091r5.h:52
no_os_spi_init_param::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:148
ad7091r5_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: ad7091r5.h:211
AD7091R5_MODE_SAMPLE
@ AD7091R5_MODE_SAMPLE
Definition: ad7091r5.h:104
device
Definition: ad9361_util.h:69
ad7091r5_limit
ad7091r5_limit
Limit type.
Definition: ad7091r5.h:185
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:49
AD7091R5_REG_CONF
#define AD7091R5_REG_CONF
Definition: ad7091r5.h:54
AD7091R5_GPO0
@ AD7091R5_GPO0
Definition: ad7091r5.h:133
ad7091r5_dev::gpio_resetn
struct no_os_gpio_desc * gpio_resetn
Definition: ad7091r5.h:213
AD7091R5_GPO2
@ AD7091R5_GPO2
Definition: ad7091r5.h:137
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:115
ad7091r5_init_param::i2c_init
struct no_os_i2c_init_param * i2c_init
Definition: ad7091r5.h:200
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:57
REG_RESULT_CONV_DATA
#define REG_RESULT_CONV_DATA(x)
Definition: ad7091r5.h:62
ad7091r5_port
ad7091r5_port
Converter general purpose outputs.
Definition: ad7091r5.h:131
ad7091r5.h
Header file for ad7091r5 Driver.
REG_CONF_RESET
#define REG_CONF_RESET(x)
Definition: ad7091r5.h:86
ad7091r5_set_port
int32_t ad7091r5_set_port(struct ad7091r5_dev *dev, enum ad7091r5_port port, bool value)
Definition: ad7091r5.c:181
REG_CONF_GPO0
#define REG_CONF_GPO0(x)
Definition: ad7091r5.h:72
ad7091r5_set_mode
int32_t ad7091r5_set_mode(struct ad7091r5_dev *dev, enum ad7091r5_mode mode)
Definition: ad7091r5.c:376
REG_CONF_AUTO
#define REG_CONF_AUTO(x)
Definition: ad7091r5.h:89
REG_CONF_SLEEP_MODE_MASK
#define REG_CONF_SLEEP_MODE_MASK
Definition: ad7091r5.h:65
no_os_error.h
Error codes definition.
AD7091R5_REG_CH_HIGH_LIMIT
#define AD7091R5_REG_CH_HIGH_LIMIT(ch)
Definition: ad7091r5.h:57
ad7091r5_set_port
int32_t ad7091r5_set_port(struct ad7091r5_dev *dev, enum ad7091r5_port port, bool value)
Definition: ad7091r5.c:181
REG_CONF_GPO0_DRIVE_TYPE
#define REG_CONF_GPO0_DRIVE_TYPE(x)
Definition: ad7091r5.h:77
REG_CONF_SLEEP_MODE
#define REG_CONF_SLEEP_MODE(x)
Definition: ad7091r5.h:66
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:301
AD7091R5_NO_ALERT
@ AD7091R5_NO_ALERT
Definition: ad7091r5.h:174
AD7091R5_GPO1
@ AD7091R5_GPO1
Definition: ad7091r5.h:135
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:436
AD7091R5_CYCLE_TIMER_400uS
@ AD7091R5_CYCLE_TIMER_400uS
Definition: ad7091r5.h:163
ad7091r5_set_channel
int32_t ad7091r5_set_channel(struct ad7091r5_dev *dev, uint8_t channel)
Definition: ad7091r5.c:406
ad7091r5_set_channel
int32_t ad7091r5_set_channel(struct ad7091r5_dev *dev, uint8_t channel)
Definition: ad7091r5.c:406
AD7091R5_SLEEP_MODE_1
@ AD7091R5_SLEEP_MODE_1
Definition: ad7091r5.h:120
ad7091r5_gpo0_mode
ad7091r5_gpo0_mode
Port 0 configuration.
Definition: ad7091r5.h:144
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:104
no_os_gpio_desc::port
int32_t port
Definition: no_os_gpio.h:98
REG_ALERT_MASK
#define REG_ALERT_MASK(x, ch)
Definition: ad7091r5.h:93
ad7091r5_set_cycle_timer
int32_t ad7091r5_set_cycle_timer(struct ad7091r5_dev *dev, enum ad7091r5_cycle_timer timer)
Definition: ad7091r5.c:253
AD7091R5_CHANNEL_NO
#define AD7091R5_CHANNEL_NO
Definition: ad7091r5.h:47
ad7091r5_cycle_timer
ad7091r5_cycle_timer
Timer used for autocycle mode.
Definition: ad7091r5.h:157
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
ad7091r5_remove
int32_t ad7091r5_remove(struct ad7091r5_dev *dev)
Free the memory allocated by ad7091r5_init().
Definition: ad7091r5.c:574
ad7091r5_dev
Structure representing an ad7091r5 device.
Definition: ad7091r5.h:209
ad7091r5_init
int32_t ad7091r5_init(struct ad7091r5_dev **device, struct ad7091r5_init_param *init_param)
Definition: ad7091r5.c:528
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:136
AD7091R5_LOW_LIMIT
@ AD7091R5_LOW_LIMIT
Definition: ad7091r5.h:187
AD7091R5_MODE_COMMAND
@ AD7091R5_MODE_COMMAND
Definition: ad7091r5.h:106
AD7091R5_REG_ALERT
#define AD7091R5_REG_ALERT
Definition: ad7091r5.h:55
ad7091r5_set_cycle_timer
int32_t ad7091r5_set_cycle_timer(struct ad7091r5_dev *dev, enum ad7091r5_cycle_timer timer)
Definition: ad7091r5.c:253
ad7091r5_get_alert
int32_t ad7091r5_get_alert(struct ad7091r5_dev *dev, uint8_t channel, enum ad7091r5_alert_type *alert)
Definition: ad7091r5.c:271
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:101
REG_CONF_GPO2_MASK
#define REG_CONF_GPO2_MASK
Definition: ad7091r5.h:82
AD7091R5_REG_CH_LOW_LIMIT
#define AD7091R5_REG_CH_LOW_LIMIT(ch)
Definition: ad7091r5.h:56
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:190
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
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:336
ad7091r5_init_param
Structure containing the init parameters needed by the ad7091r5 device.
Definition: ad7091r5.h:198
AD7091R5_REG_CHANNEL
#define AD7091R5_REG_CHANNEL
Definition: ad7091r5.h:53
AD7091R5_MODE_AUTOCYCLE
@ AD7091R5_MODE_AUTOCYCLE
Definition: ad7091r5.h:108
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:111
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:45
REG_CONF_GPO2
#define REG_CONF_GPO2(x)
Definition: ad7091r5.h:83
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:69
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:87
ad7091r5_remove
int32_t ad7091r5_remove(struct ad7091r5_dev *dev)
Free the memory allocated by ad7091r5_init().
Definition: ad7091r5.c:574
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: aducm3029_delay.c:114
AD7091R5_GPO0_ALERT
@ AD7091R5_GPO0_ALERT
Definition: ad7091r5.h:148
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
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:197
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
ad7091r5_mode
ad7091r5_mode
Converter supported modes.
Definition: ad7091r5.h:102
REG_CONF_GPO1
#define REG_CONF_GPO1(x)
Definition: ad7091r5.h:69
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:219
AD7091R5_CYCLE_TIMER_100uS
@ AD7091R5_CYCLE_TIMER_100uS
Definition: ad7091r5.h:159
REG_RESULT_CH_ID
#define REG_RESULT_CH_ID(x)
Definition: ad7091r5.h:61
REG_CONF_CYCLE_TIMER
#define REG_CONF_CYCLE_TIMER(x)
Definition: ad7091r5.h:80
no_os_gpio.h
Header file of GPIO Interface.
AD7091R5_GPO0_ENABLED
@ AD7091R5_GPO0_ENABLED
Definition: ad7091r5.h:146
REG_CONF_CMD
#define REG_CONF_CMD(x)
Definition: ad7091r5.h:90
ad7091r5_set_mode
int32_t ad7091r5_set_mode(struct ad7091r5_dev *dev, enum ad7091r5_mode mode)
Definition: ad7091r5.c:376
REG_CONF_GPO0_BUSY
#define REG_CONF_GPO0_BUSY(x)
Definition: ad7091r5.h:76
no_os_util.h
Header file of utility functions.
ad7091r5_sleep_mode
ad7091r5_sleep_mode
Converter supported sleep modes.
Definition: ad7091r5.h:115
AD7091R5_GPO0_BUSY
@ AD7091R5_GPO0_BUSY
Definition: ad7091r5.h:150
REG_CONF_GPO1_MASK
#define REG_CONF_GPO1_MASK
Definition: ad7091r5.h:68
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:147
ad7091r5_alert_type
ad7091r5_alert_type
Alert status.
Definition: ad7091r5.h:172
ad7091r5_read_one
int32_t ad7091r5_read_one(struct ad7091r5_dev *dev, uint8_t channel, uint16_t *read_val)
Definition: ad7091r5.c:493
AD7091R5_CYCLE_TIMER_800uS
@ AD7091R5_CYCLE_TIMER_800uS
Definition: ad7091r5.h:165
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:219
AD7091R5_HYSTERESIS
@ AD7091R5_HYSTERESIS
Definition: ad7091r5.h:191
errno.h
Error macro definition for ARM Compiler.
REG_CONF_MODE_MASK
#define REG_CONF_MODE_MASK
Definition: ad7091r5.h:88
REG_CONF_CYCLE_TIMER_MASK
#define REG_CONF_CYCLE_TIMER_MASK
Definition: ad7091r5.h:79
AD7091R5_LOW_ALERT
@ AD7091R5_LOW_ALERT
Definition: ad7091r5.h:178
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:75