no-OS
ad7091r8.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef __AD7091R8_H__
35 #define __AD7091R8_H__
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 #include <stdbool.h>
41 
42 #include "no_os_spi.h"
43 #include "no_os_gpio.h"
44 
45 /******************************************************************************/
46 /********************** Macros and Constants Definitions **********************/
47 /******************************************************************************/
48 #define AD7091R_NUM_CHANNELS(id) (1 << ((id) + 1))
49 #define AD7091R8_BITS 12
50 
51 #define AD7091R8_CONV_MASK NO_OS_GENMASK(AD7091R8_BITS - 1, 0)
52 
53 /* AD7091r8 registers */
54 #define AD7091R8_REG_RESULT 0x00
55 #define AD7091R8_REG_CHANNEL 0x01
56 #define AD7091R8_REG_CONF 0x02
57 #define AD7091R8_REG_ALERT 0x03
58 #define AD7091R8_REG_CH_LOW_LIMIT(ch) ((ch) * 3 + 4)
59 #define AD7091R8_REG_CH_HIGH_LIMIT(ch) ((ch) * 3 + 5)
60 #define AD7091R8_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6)
61 
62 /* AD7091R8_REG_RESULT */
63 #define AD7091R8_REG_RESULT_DATA_MASK NO_OS_GENMASK(11, 0)
64 #define AD7091R8_REG_RESULT_ALT_MASK NO_OS_BIT(12)
65 #define AD7091R8_REG_RESULT_CH_ID_MASK NO_OS_GENMASK(15, 13)
66 
67 /* AD7091R8_REG_CONF */
68 #define REG_CONF_SLEEP_MODE_MASK NO_OS_GENMASK(1, 0)
69 #define REG_CONF_GPO1_MASK NO_OS_BIT(2)
70 #define REG_CONF_GPO0_MASK NO_OS_BIT(3)
71 #define REG_CONF_GPO0_MODE_MASK NO_OS_GENMASK(6, 4)
72 #define REG_CONF_ALERT_STICKY_MASK NO_OS_BIT(7)
73 #define REG_CONF_RESET_MASK NO_OS_BIT(9)
74 
75 /* AD7091R8_REG_ALERT */
76 #define REG_ALERT_MASK(x, ch) (x >> (ch * 2))
77 
78 /* AD7091R8 read/write protocol masks */
79 #define AD7091R8_REG_DATA_MSK NO_OS_GENMASK(9, 0)
80 #define AD7091R8_RD_WR_FLAG_MSK NO_OS_BIT(10)
81 #define AD7091R8_REG_ADDR_MSK NO_OS_GENMASK(15, 11)
82 
83 /*****************************************************************************/
84 /*************************** Types Declarations *******************************/
85 /******************************************************************************/
90 };
91 
92 static char * const ad7091r8_names[] = {
93  [AD7091R2] = "ad7091r-2",
94  [AD7091R4] = "ad7091r-4",
95  [AD7091R8] = "ad7091r-8",
96 };
97 
112 };
113 
123 };
124 
136 };
137 
149 };
150 
162 };
163 
164 struct ad7091r8_dev {
166  //spi_desc *spi_desc;
168  /* Reference voltage */
169  int vref_mv;
170  /* CONVST GPIO handler */
176  /* AD7091R specific device identifier */
178  /* AD7091R device sleep mode */
180 };
181 
183  /* SPI initialization parameters */
185  /* External Voltage Reference */
186  int vref_mv;
187  /* CONVST GPIO initialization parameters */
189  /* Reset GPIO initialization parameters */
191  /* Alert GPIO initialization parameters */
193  /* AD7091R specific device identifier */
195  /* AD7091R device sleep mode */
197 };
198 
199 /******************************************************************************/
200 /************************ Functions Declarations ******************************/
201 /******************************************************************************/
202 /* Initialize the device. */
203 int ad7091r8_init(struct ad7091r8_dev **device,
205 
206 /* Remove the device and release resources. */
207 int ad7091r8_remove(struct ad7091r8_dev *dev);
208 
209 /* Set device sleep mode */
210 int ad7091r8_set_sleep_mode(struct ad7091r8_dev *dev,
211  enum ad7091r8_sleep_mode mode);
212 
213 /* Set device set port value */
214 int ad7091r8_set_port(struct ad7091r8_dev *dev,
215  enum ad7091r8_port port,
216  bool value);
217 
218 /* Set device set GPO0 mode */
219 int ad7091r8_set_gpo0_mode(struct ad7091r8_dev *dev,
220  enum ad7091r8_gpo0_mode mode,
221  bool is_cmos);
222 
223 /* Set high limit, low limit, hysteresis. */
224 int ad7091r8_set_limit(struct ad7091r8_dev *dev,
225  enum ad7091r8_limit limit,
226  uint8_t channel,
227  uint16_t value);
228 
229 /* Get alert. */
230 int ad7091r8_get_alert(struct ad7091r8_dev *dev,
231  uint8_t channel,
232  enum ad7091r8_alert_type *alert);
233 
234 /* Get high limit, low limit, hysteresis. */
235 int ad7091r8_get_limit(struct ad7091r8_dev *dev,
236  enum ad7091r8_limit limit,
237  uint8_t channel,
238  uint16_t *value);
239 
240 /* Select device channel. */
241 int ad7091r8_set_channel(struct ad7091r8_dev *dev,
242  uint8_t channel);
243 
244 /* Read one sample. */
245 int ad7091r8_read_one(struct ad7091r8_dev *dev,
246  uint8_t chan,
247  uint16_t *read_val);
248 
249 /* Read next channel set in the channel sequencer. */
250 int ad7091r8_sequenced_read(struct ad7091r8_dev *dev,
251  uint16_t *read_val);
252 
253 /* Read device register. */
254 int ad7091r8_spi_reg_read(struct ad7091r8_dev *dev,
255  uint8_t reg_addr,
256  uint16_t *reg_data);
257 
258 /* Write to device register. */
259 int ad7091r8_spi_reg_write(struct ad7091r8_dev *dev,
260  uint8_t reg_addr,
261  uint16_t reg_data);
262 
263 /* SPI write to device using a mask. */
264 int ad7091r8_spi_write_mask(struct ad7091r8_dev* dev,
265  uint8_t reg_addr,
266  uint16_t mask,
267  uint16_t data);
268 
269 int ad7091r8_pulse_convst(struct ad7091r8_dev *dev);
270 
271 #endif // __AD7091R8_H__
ad7091r8_dev::gpio_reset
struct no_os_gpio_desc * gpio_reset
Definition: ad7091r8.h:173
ad7091r8_init_param::sleep_mode
enum ad7091r8_sleep_mode sleep_mode
Definition: ad7091r8.h:196
AD7091R8_HIGH_LIMIT
@ AD7091R8_HIGH_LIMIT
Definition: ad7091r8.h:146
ad7091r8_set_channel
int ad7091r8_set_channel(struct ad7091r8_dev *dev, uint8_t channel)
Definition: ad7091r8.c:484
no_os_put_unaligned_be16
void no_os_put_unaligned_be16(uint16_t val, uint8_t *buf)
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
AD7091R8_GPO0_BUSY
@ AD7091R8_GPO0_BUSY
Definition: ad7091r8.h:135
ad7091r8_remove
int ad7091r8_remove(struct ad7091r8_dev *dev)
Free the resources allocated by ad7091r8_init().
Definition: ad7091r8.c:458
ad7091r8_get_alert
int ad7091r8_get_alert(struct ad7091r8_dev *dev, uint8_t channel, enum ad7091r8_alert_type *alert)
Definition: ad7091r8.c:284
AD7091R8_REG_DATA_MSK
#define AD7091R8_REG_DATA_MSK
Definition: ad7091r8.h:79
ad7091r8_pulse_convst
int ad7091r8_pulse_convst(struct ad7091r8_dev *dev)
Definition: ad7091r8.c:48
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:159
AD7091R8_GPO1
@ AD7091R8_GPO1
Definition: ad7091r8.h:122
no_os_spi.h
Header file of SPI Interface.
REG_CONF_GPO0_MASK
#define REG_CONF_GPO0_MASK
Definition: ad7091r5.h:71
REG_CONF_RESET_MASK
#define REG_CONF_RESET_MASK
Definition: ad7091r5.h:85
REG_CONF_GPO0_MODE_MASK
#define REG_CONF_GPO0_MODE_MASK
Definition: ad7091r5.h:74
AD7091R8_LOW_ALERT
@ AD7091R8_LOW_ALERT
Definition: ad7091r8.h:161
no_os_delay.h
Header file of Delay functions.
ad7091r8_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad7091r8.h:167
no_os_gpio_init_param::port
int32_t port
Definition: no_os_gpio.h:81
ad7091r8_spi_reg_write
int ad7091r8_spi_reg_write(struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition: ad7091r8.c:69
device
Definition: ad9361_util.h:69
ad7091r8_device_id
ad7091r8_device_id
Definition: ad7091r8.h:86
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
AD7091R8_REG_CH_HYSTERESIS
#define AD7091R8_REG_CH_HYSTERESIS(ch)
Definition: ad7091r8.h:60
AD7091R8_REG_RESULT
#define AD7091R8_REG_RESULT
Definition: ad7091r8.h:54
no_os_calloc
void * no_os_calloc(size_t nitems, size_t size)
Allocate memory and return a pointer to it, set memory to 0.
Definition: chibios_alloc.c:54
ad7091r8.h
Implementation of AD7091R-8 driver header file.
AD7091R8_REG_CHANNEL
#define AD7091R8_REG_CHANNEL
Definition: ad7091r8.h:55
AD7091R8_REG_ALERT
#define AD7091R8_REG_ALERT
Definition: ad7091r8.h:57
AD7091R8_HIGH_ALERT
@ AD7091R8_HIGH_ALERT
Definition: ad7091r8.h:159
ad7091r8_init_param::gpio_alert
struct no_os_gpio_init_param * gpio_alert
Definition: ad7091r8.h:192
ad7091r8_init_param
Definition: ad7091r8.h:182
ad7091r8_dev::gpio_alert
struct no_os_gpio_desc * gpio_alert
Definition: ad7091r8.h:175
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:115
ad7091r8_dev
Definition: ad7091r8.h:164
ad7091r8_dev::device_id
enum ad7091r8_device_id device_id
Definition: ad7091r8.h:177
no_os_field_prep
uint32_t no_os_field_prep(uint32_t mask, uint32_t val)
ad7091r8_get_limit
int ad7091r8_get_limit(struct ad7091r8_dev *dev, enum ad7091r8_limit limit, uint8_t channel, uint16_t *value)
Definition: ad7091r8.c:315
ad7091r8_remove
int ad7091r8_remove(struct ad7091r8_dev *dev)
Free the resources allocated by ad7091r8_init().
Definition: ad7091r8.c:458
REG_CONF_SLEEP_MODE_MASK
#define REG_CONF_SLEEP_MODE_MASK
Definition: ad7091r5.h:65
no_os_error.h
Error codes definition.
ad7091r8_limit
ad7091r8_limit
Limit type.
Definition: ad7091r8.h:142
ad7091r8_sleep_mode
ad7091r8_sleep_mode
Converter supported sleep modes.
Definition: ad7091r8.h:102
ad7091r8_get_limit
int ad7091r8_get_limit(struct ad7091r8_dev *dev, enum ad7091r8_limit limit, uint8_t channel, uint16_t *value)
Definition: ad7091r8.c:315
ad7091r8_dev::gpio_convst
struct no_os_gpio_desc * gpio_convst
Definition: ad7091r8.h:171
ad7091r8_spi_write_mask
int ad7091r8_spi_write_mask(struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t mask, uint16_t data)
Definition: ad7091r8.c:148
AD7091R8_GPO0
@ AD7091R8_GPO0
Definition: ad7091r8.h:120
AD7091R8_RD_WR_FLAG_MSK
#define AD7091R8_RD_WR_FLAG_MSK
Definition: ad7091r8.h:80
AD7091R8_SLEEP_MODE_1
@ AD7091R8_SLEEP_MODE_1
Definition: ad7091r8.h:107
ad7091r8_set_port
int ad7091r8_set_port(struct ad7091r8_dev *dev, enum ad7091r8_port port, bool value)
Definition: ad7091r8.c:199
AD7091R_NUM_CHANNELS
#define AD7091R_NUM_CHANNELS(id)
Definition: ad7091r8.h:48
ad7091r8_init_param::device_id
enum ad7091r8_device_id device_id
Definition: ad7091r8.h:194
ad7091r8_set_sleep_mode
int ad7091r8_set_sleep_mode(struct ad7091r8_dev *dev, enum ad7091r8_sleep_mode mode)
Set device sleep mode.
Definition: ad7091r8.c:174
ad7091r8_init_param::gpio_convst
struct no_os_gpio_init_param * gpio_convst
Definition: ad7091r8.h:188
AD7091R8_SLEEP_MODE_3
@ AD7091R8_SLEEP_MODE_3
Definition: ad7091r8.h:111
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
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
ad7091r8_set_sleep_mode
int ad7091r8_set_sleep_mode(struct ad7091r8_dev *dev, enum ad7091r8_sleep_mode mode)
Set device sleep mode.
Definition: ad7091r8.c:174
REG_ALERT_MASK
#define REG_ALERT_MASK(x, ch)
Definition: ad7091r5.h:93
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
AD7091R8_CONV_MASK
#define AD7091R8_CONV_MASK
Definition: ad7091r8.h:51
AD7091R4
@ AD7091R4
Definition: ad7091r8.h:88
ad7091r8_sequenced_read
int ad7091r8_sequenced_read(struct ad7091r8_dev *dev, uint16_t *read_val)
Definition: ad7091r8.c:533
ad7091r8_set_limit
int ad7091r8_set_limit(struct ad7091r8_dev *dev, enum ad7091r8_limit limit, uint8_t channel, uint16_t value)
Definition: ad7091r8.c:252
ad7091r8_set_port
int ad7091r8_set_port(struct ad7091r8_dev *dev, enum ad7091r8_port port, bool value)
Definition: ad7091r8.c:199
no_os_gpio_get
int32_t no_os_gpio_get(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: no_os_gpio.c:49
AD7091R2
@ AD7091R2
Definition: ad7091r8.h:87
AD7091R8_GPO0_ALERT
@ AD7091R8_GPO0_ALERT
Definition: ad7091r8.h:133
ad7091r8_sequenced_read
int ad7091r8_sequenced_read(struct ad7091r8_dev *dev, uint16_t *read_val)
Definition: ad7091r8.c:533
no_os_field_get
uint32_t no_os_field_get(uint32_t mask, uint32_t word)
ad7091r8_dev::sleep_mode
enum ad7091r8_sleep_mode sleep_mode
Definition: ad7091r8.h:179
ad7091r8_set_limit
int ad7091r8_set_limit(struct ad7091r8_dev *dev, enum ad7091r8_limit limit, uint8_t channel, uint16_t value)
Definition: ad7091r8.c:252
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:45
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
AD7091R8
@ AD7091R8
Definition: ad7091r8.h:89
AD7091R8_REG_CONF
#define AD7091R8_REG_CONF
Definition: ad7091r8.h:56
ad7091r8_reset
int ad7091r8_reset(struct ad7091r8_dev *dev, bool is_software)
Initiate a software reset or hardware reset through the RESET pin.
Definition: ad7091r8.c:346
ad7091r8_spi_reg_write
int ad7091r8_spi_reg_write(struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition: ad7091r8.c:69
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: aducm3029_delay.c:114
ad7091r8_init_param::spi_init
struct no_os_spi_init_param * spi_init
Definition: ad7091r8.h:184
ad7091r8_get_alert
int ad7091r8_get_alert(struct ad7091r8_dev *dev, uint8_t channel, enum ad7091r8_alert_type *alert)
Definition: ad7091r8.c:284
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
AD7091R8_SLEEP_MODE_2
@ AD7091R8_SLEEP_MODE_2
Definition: ad7091r8.h:109
ad7091r8_init
int ad7091r8_init(struct ad7091r8_dev **device, struct ad7091r8_init_param *init_param)
Definition: ad7091r8.c:380
AD7091R8_REG_CH_HIGH_LIMIT
#define AD7091R8_REG_CH_HIGH_LIMIT(ch)
Definition: ad7091r8.h:59
AD7091R8_REG_ADDR_MSK
#define AD7091R8_REG_ADDR_MSK
Definition: ad7091r8.h:81
AD7091R8_HYSTERESIS
@ AD7091R8_HYSTERESIS
Definition: ad7091r8.h:148
ad7091r8_set_gpo0_mode
int ad7091r8_set_gpo0_mode(struct ad7091r8_dev *dev, enum ad7091r8_gpo0_mode mode, bool is_cmos)
Definition: ad7091r8.c:229
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:116
ad7091r8_alert_type
ad7091r8_alert_type
Alert status.
Definition: ad7091r8.h:155
no_os_gpio.h
Header file of GPIO Interface.
AD7091R8_SLEEP_MODE_0
@ AD7091R8_SLEEP_MODE_0
Definition: ad7091r8.h:105
ad7091r8_init_param::gpio_reset
struct no_os_gpio_init_param * gpio_reset
Definition: ad7091r8.h:190
AD7091R8_GPO0_ENABLED
@ AD7091R8_GPO0_ENABLED
Definition: ad7091r8.h:131
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:52
AD7091R8_LOW_LIMIT
@ AD7091R8_LOW_LIMIT
Definition: ad7091r8.h:144
no_os_get_unaligned_be16
uint16_t no_os_get_unaligned_be16(uint8_t *buf)
ad7091r8_read_one
int ad7091r8_read_one(struct ad7091r8_dev *dev, uint8_t chan, uint16_t *read_val)
Definition: ad7091r8.c:509
ad7091r8_set_channel
int ad7091r8_set_channel(struct ad7091r8_dev *dev, uint8_t channel)
Definition: ad7091r8.c:484
no_os_util.h
Header file of utility functions.
ad7091r8_spi_reg_read
int ad7091r8_spi_reg_read(struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition: ad7091r8.c:97
ad7091r8_init
int ad7091r8_init(struct ad7091r8_dev **device, struct ad7091r8_init_param *init_param)
Definition: ad7091r8.c:380
ad7091r8_gpo0_mode
ad7091r8_gpo0_mode
Port 0 configuration.
Definition: ad7091r8.h:129
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
ad7091r8_pulse_convst
int ad7091r8_pulse_convst(struct ad7091r8_dev *dev)
Definition: ad7091r8.c:48
ad7091r8_spi_reg_read
int ad7091r8_spi_reg_read(struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition: ad7091r8.c:97
ad7091r8_spi_write_mask
int ad7091r8_spi_write_mask(struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t mask, uint16_t data)
Definition: ad7091r8.c:148
ad7091r8_init_param::vref_mv
int vref_mv
Definition: ad7091r8.h:186
AD7091R8_NO_ALERT
@ AD7091R8_NO_ALERT
Definition: ad7091r8.h:157
ad7091r8_set_gpo0_mode
int ad7091r8_set_gpo0_mode(struct ad7091r8_dev *dev, enum ad7091r8_gpo0_mode mode, bool is_cmos)
Definition: ad7091r8.c:229
ad7091r8_port
ad7091r8_port
Converter general purpose outputs.
Definition: ad7091r8.h:118
ad7091r8_dev::vref_mv
int vref_mv
Definition: ad7091r8.h:169
ad7091r8_read_one
int ad7091r8_read_one(struct ad7091r8_dev *dev, uint8_t channel, uint16_t *read_val)
Definition: ad7091r8.c:509
errno.h
Error macro definition for ARM Compiler.
AD7091R8_REG_CH_LOW_LIMIT
#define AD7091R8_REG_CH_LOW_LIMIT(ch)
Definition: ad7091r8.h:58
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
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