no-OS
adxrs290.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef ADXRS290_H_
35 #define ADXRS290_H_
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 
41 #include <stdlib.h>
42 #include <stdbool.h>
43 #include "no_os_gpio.h"
44 #include "no_os_spi.h"
45 #include "no_os_util.h"
46 
47 /******************************************************************************/
48 /********************** Macros and Constants Definitions **********************/
49 /******************************************************************************/
50 
51 /* ADXRS290 ID */
52 #define ADXRS290_ADI_ID 0xAD
53 #define ADXRS290_MEMS_ID 0x1D
54 #define ADXRS290_DEV_ID 0x92
55 
56 /* ADXRS290 Registers */
57 #define ADXRS290_REG_ADI_ID 0x00
58 #define ADXRS290_REG_MEMS_ID 0x01
59 #define ADXRS290_REG_DEV_ID 0x02
60 #define ADXRS290_REG_REV_ID 0x03
61 #define ADXRS290_REG_SN0 0x04
62 #define ADXRS290_REG_SN1 0x05
63 #define ADXRS290_REG_SN2 0x06
64 #define ADXRS290_REG_SN3 0x07
65 #define ADXRS290_REG_DATAX0 0x08
66 #define ADXRS290_REG_DATAX1 0x09
67 #define ADXRS290_REG_DATAY0 0x0A
68 #define ADXRS290_REG_DATAY1 0x0B
69 #define ADXRS290_REG_TEMP0 0x0C
70 #define ADXRS290_REG_TEMP1 0x0D
71 
72 #define ADXRS290_REG_POWER_CTL 0x10
73 #define ADXRS290_REG_FILTER 0x11
74 #define ADXRS290_REG_DATA_READY 0x12
75 
76 #define ADXRS290_READ NO_OS_BIT(7)
77 #define ADXRS290_TSM NO_OS_BIT(0)
78 #define ADXRS290_MEASUREMENT NO_OS_BIT(1)
79 #define ADXRS290_DATA_RDY_OUT NO_OS_BIT(0)
80 #define ADXRS290_SYNC_MASK 0x03
81 #define ADXRS290_SYNC(x) (x) & ADXRS290_SYNC_MASK
82 #define ADXRS290_LPF_MASK 0x07
83 #define ADXRS290_LPF(x) (x) & ADXRS290_LPF_MASK
84 #define ADXRS290_HPF_MASK 0xF0
85 #define ADXRS290_HPF(x) ((x) & ADXRS290_HPF_MASK ) >> 4
86 
87 #define ADXRS290_READ_REG(reg) (ADXRS290_READ | (reg))
88 
89 #define ADXRS290_MAX_TRANSITION_TIME_MS 100
90 #define ADXRS290_CHANNEL_COUNT 3
91 #define ADXRS290_CHANNEL_MASK 0x07
92 /******************************************************************************/
93 /*************************** Types Declarations *******************************/
94 /******************************************************************************/
95 
105 };
106 
118 };
119 
133 };
134 
151 };
152 
168 };
169 
174 struct adxrs290_dev {
180  uint8_t ch_mask;
181 };
182 
183 /******************************************************************************/
184 /************************ Functions Declarations ******************************/
185 /******************************************************************************/
186 
187 /* Read device register. */
188 int32_t adxrs290_reg_read(struct adxrs290_dev *dev, uint8_t address,
189  uint8_t *data);
190 
191 /* Write device register. */
192 int32_t adxrs290_reg_write(struct adxrs290_dev *dev, uint8_t address,
193  uint8_t data);
194 
195 /* Set mode */
196 int32_t adxrs290_set_op_mode(struct adxrs290_dev *dev, enum adxrs290_mode mode);
197 
198 /* Get the low-pass filter pole location. */
199 int32_t adxrs290_get_lpf(struct adxrs290_dev *dev, enum adxrs290_lpf *lpf);
200 
201 /* Set the low-pass filter pole location. */
202 int32_t adxrs290_set_lpf(struct adxrs290_dev *dev, enum adxrs290_lpf lpf);
203 
204 /* Get the high-pass filter pole location. */
205 int32_t adxrs290_get_hpf(struct adxrs290_dev *dev, enum adxrs290_hpf *hpf);
206 
207 /* Set the high-pass filter pole location. */
208 int32_t adxrs290_set_hpf(struct adxrs290_dev *dev, enum adxrs290_hpf hpf);
209 
210 /* Read X or Y angular velocity data */
211 int32_t adxrs290_get_rate_data(struct adxrs290_dev *dev,
212  enum adxrs290_channel ch, int16_t *rate);
213 
214 /* Read Temperature data */
215 int32_t adxrs290_get_temp_data(struct adxrs290_dev *dev, int16_t *temp);
216 
217 /* Get the burst data */
218 int32_t adxrs290_get_burst_data(struct adxrs290_dev *dev, int16_t *burst_data,
219  uint8_t *ch_cnt);
220 
221 /* Set the ADXRS290 active channels */
222 int32_t adxrs290_set_active_channels(struct adxrs290_dev *dev, uint32_t mask);
223 
224 /* Get the data ready state */
225 int32_t adxrs290_get_data_ready(struct adxrs290_dev *dev, bool *rdy);
226 
227 /* Init. the comm. peripheral and checks if the ADXRS290 part is present. */
228 int32_t adxrs290_init(struct adxrs290_dev **device,
229  const struct adxrs290_init_param *init_param);
230 
231 /* Free the resources allocated by adxrs290_init(). */
232 int32_t adxrs290_remove(struct adxrs290_dev *dev);
233 
234 
235 #endif /* ADXRS290_H_ */
adxrs290_get_lpf
int32_t adxrs290_get_lpf(struct adxrs290_dev *dev, enum adxrs290_lpf *lpf)
Get the low-pass filter pole location.
Definition: adxrs290.c:120
adxrs290_init
int32_t adxrs290_init(struct adxrs290_dev **device, const struct adxrs290_init_param *init_param)
Definition: adxrs290.c:333
ADXRS290_REG_FILTER
#define ADXRS290_REG_FILTER
Definition: adxrs290.h:73
ADXRS290_REG_DATAX1
#define ADXRS290_REG_DATAX1
Definition: adxrs290.h:66
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
adxrs290_set_active_channels
int32_t adxrs290_set_active_channels(struct adxrs290_dev *dev, uint32_t mask)
Set the ADXRS290 active channels.
Definition: adxrs290.c:293
ADXRS290_LPF_160HZ
@ ADXRS290_LPF_160HZ
Definition: adxrs290.h:127
ADXRS290_TSM
#define ADXRS290_TSM
Definition: adxrs290.h:77
adxrs290_init_param::mode
enum adxrs290_mode mode
Definition: adxrs290.h:163
adxrs290_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: adxrs290.h:176
adxrs290_get_rate_data
int32_t adxrs290_get_rate_data(struct adxrs290_dev *dev, enum adxrs290_channel ch, int16_t *rate)
Get the Gyro data channels.
Definition: adxrs290.c:203
adxrs290_set_hpf
int32_t adxrs290_set_hpf(struct adxrs290_dev *dev, enum adxrs290_hpf hpf)
Set the low-pass filter pole location.
Definition: adxrs290.c:181
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
ADXRS290_LPF_320HZ
@ ADXRS290_LPF_320HZ
Definition: adxrs290.h:126
no_os_spi.h
Header file of SPI Interface.
ADXRS290_HPF_0HZ087
@ ADXRS290_HPF_0HZ087
Definition: adxrs290.h:144
ADXRS290_HPF_0HZ022
@ ADXRS290_HPF_0HZ022
Definition: adxrs290.h:142
ADXRS290_HPF_0HZ700
@ ADXRS290_HPF_0HZ700
Definition: adxrs290.h:147
ADXRS290_HPF_2HZ800
@ ADXRS290_HPF_2HZ800
Definition: adxrs290.h:149
no_os_gpio_get_value
int32_t no_os_gpio_get_value(struct no_os_gpio_desc *desc, uint8_t *value)
Get the value of the specified GPIO.
Definition: no_os_gpio.c:221
ADXRS290_LPF_40HZ
@ ADXRS290_LPF_40HZ
Definition: adxrs290.h:130
NO_OS_IS_ERR_VALUE
#define NO_OS_IS_ERR_VALUE(x)
Definition: no_os_error.h:50
adxrs290_get_burst_data
int32_t adxrs290_get_burst_data(struct adxrs290_dev *dev, int16_t *burst_data, uint8_t *ch_cnt)
Get the burst data.
Definition: adxrs290.c:253
adxrs290_reg_read
int32_t adxrs290_reg_read(struct adxrs290_dev *dev, uint8_t address, uint8_t *data)
Read device register.
Definition: adxrs290.c:55
ADXRS290_LPF_480HZ
@ ADXRS290_LPF_480HZ
Definition: adxrs290.h:125
device
Definition: ad9361_util.h:69
ADXRS290_MODE_MEASUREMENT
@ ADXRS290_MODE_MEASUREMENT
Definition: adxrs290.h:104
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
adxrs290_dev::gpio_sync
struct no_os_gpio_desc * gpio_sync
Definition: adxrs290.h:178
no_os_gpio_direction_input
int32_t no_os_gpio_direction_input(struct no_os_gpio_desc *desc)
Enable the input direction of the specified GPIO.
Definition: no_os_gpio.c:124
ad7616_init_param::mode
enum ad7616_mode mode
Definition: ad7616.h:226
adxrs290_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: adxrs290.h:159
ADXRS290_HPF_ALL_PASS
@ ADXRS290_HPF_ALL_PASS
Definition: adxrs290.h:140
adxrs290_set_hpf
int32_t adxrs290_set_hpf(struct adxrs290_dev *dev, enum adxrs290_hpf hpf)
Set the low-pass filter pole location.
Definition: adxrs290.c:181
ADXRS290_HPF
#define ADXRS290_HPF(x)
Definition: adxrs290.h:85
ADXRS290_CHANNEL_Y
@ ADXRS290_CHANNEL_Y
Definition: adxrs290.h:115
adxrs290_set_lpf
int32_t adxrs290_set_lpf(struct adxrs290_dev *dev, enum adxrs290_lpf lpf)
Set the low-pass filter pole location.
Definition: adxrs290.c:140
ADXRS290_HPF_1HZ400
@ ADXRS290_HPF_1HZ400
Definition: adxrs290.h:148
adxrs290_get_temp_data
int32_t adxrs290_get_temp_data(struct adxrs290_dev *dev, int16_t *temp)
Get the temperature data.
Definition: adxrs290.c:227
ADXRS290_LPF_80HZ
@ ADXRS290_LPF_80HZ
Definition: adxrs290.h:128
ADXRS290_HPF_0HZ175
@ ADXRS290_HPF_0HZ175
Definition: adxrs290.h:145
ADXRS290_HPF_11HZ30
@ ADXRS290_HPF_11HZ30
Definition: adxrs290.h:150
ADXRS290_CHANNEL_COUNT
#define ADXRS290_CHANNEL_COUNT
Definition: adxrs290.h:90
no_os_error.h
Error codes definition.
ADXRS290_LPF_20HZ
@ ADXRS290_LPF_20HZ
Definition: adxrs290.h:132
ADXRS290_LPF_56HZ6
@ ADXRS290_LPF_56HZ6
Definition: adxrs290.h:129
ADXRS290_CHANNEL_X
@ ADXRS290_CHANNEL_X
Definition: adxrs290.h:113
ADXRS290_HPF_0HZ011
@ ADXRS290_HPF_0HZ011
Definition: adxrs290.h:141
adxrs290_get_burst_data
int32_t adxrs290_get_burst_data(struct adxrs290_dev *dev, int16_t *burst_data, uint8_t *ch_cnt)
Get the burst data.
Definition: adxrs290.c:253
adxrs290_set_active_channels
int32_t adxrs290_set_active_channels(struct adxrs290_dev *dev, uint32_t mask)
Set the ADXRS290 active channels.
Definition: adxrs290.c:293
adxrs290_get_data_ready
int32_t adxrs290_get_data_ready(struct adxrs290_dev *dev, bool *rdy)
Get the state of data ready.
Definition: adxrs290.c:306
adxrs290.h
Implementation of ADXRS290 Driver.
ADXRS290_DEV_ID
#define ADXRS290_DEV_ID
Definition: adxrs290.h:54
adxrs290_remove
int32_t adxrs290_remove(struct adxrs290_dev *dev)
Free memory allocated by adxrs290_setup().
Definition: adxrs290.c:412
adxrs290_get_temp_data
int32_t adxrs290_get_temp_data(struct adxrs290_dev *dev, int16_t *temp)
Get the temperature data.
Definition: adxrs290.c:227
adxrs290_get_rate_data
int32_t adxrs290_get_rate_data(struct adxrs290_dev *dev, enum adxrs290_channel ch, int16_t *rate)
Get the Gyro data channels.
Definition: adxrs290.c:203
ADXRS290_REG_DATA_READY
#define ADXRS290_REG_DATA_READY
Definition: adxrs290.h:74
ADXRS290_REG_POWER_CTL
#define ADXRS290_REG_POWER_CTL
Definition: adxrs290.h:72
adxrs290_init_param
Device driver initialization structure.
Definition: adxrs290.h:157
adxrs290_remove
int32_t adxrs290_remove(struct adxrs290_dev *dev)
Free memory allocated by adxrs290_setup().
Definition: adxrs290.c:412
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
ADXRS290_HPF_0HZ350
@ ADXRS290_HPF_0HZ350
Definition: adxrs290.h:146
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
adxrs290_set_lpf
int32_t adxrs290_set_lpf(struct adxrs290_dev *dev, enum adxrs290_lpf lpf)
Set the low-pass filter pole location.
Definition: adxrs290.c:140
adxrs290_dev
Device driver handler.
Definition: adxrs290.h:174
ADXRS290_LPF
#define ADXRS290_LPF(x)
Definition: adxrs290.h:83
ADXRS290_CHANNEL_TEMP
@ ADXRS290_CHANNEL_TEMP
Definition: adxrs290.h:117
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
ADXRS290_CHANNEL_MASK
#define ADXRS290_CHANNEL_MASK
Definition: adxrs290.h:91
adxrs290_get_data_ready
int32_t adxrs290_get_data_ready(struct adxrs290_dev *dev, bool *rdy)
Get the state of data ready.
Definition: adxrs290.c:306
adxrs290_reg_read
int32_t adxrs290_reg_read(struct adxrs290_dev *dev, uint8_t address, uint8_t *data)
Read device register.
Definition: adxrs290.c:55
adxrs290_init
int32_t adxrs290_init(struct adxrs290_dev **device, const struct adxrs290_init_param *init_param)
Definition: adxrs290.c:333
ADXRS290_LPF_28HZ3
@ ADXRS290_LPF_28HZ3
Definition: adxrs290.h:131
ADXRS290_REG_DEV_ID
#define ADXRS290_REG_DEV_ID
Definition: adxrs290.h:59
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
ADXRS290_MODE_STANDBY
@ ADXRS290_MODE_STANDBY
Definition: adxrs290.h:102
adxrs290_dev::ch_mask
uint8_t ch_mask
Definition: adxrs290.h:180
adxrs290_reg_write
int32_t adxrs290_reg_write(struct adxrs290_dev *dev, uint8_t address, uint8_t data)
Write device register.
Definition: adxrs290.c:77
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
adxrs290_set_op_mode
int32_t adxrs290_set_op_mode(struct adxrs290_dev *dev, enum adxrs290_mode mode)
Set device operation mode.
Definition: adxrs290.c:91
adxrs290_reg_write
int32_t adxrs290_reg_write(struct adxrs290_dev *dev, uint8_t address, uint8_t data)
Write device register.
Definition: adxrs290.c:77
ADXRS290_REG_DATAX0
#define ADXRS290_REG_DATAX0
Definition: adxrs290.h:65
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
adxrs290_set_op_mode
int32_t adxrs290_set_op_mode(struct adxrs290_dev *dev, enum adxrs290_mode mode)
Set device operation mode.
Definition: adxrs290.c:91
adxrs290_get_hpf
int32_t adxrs290_get_hpf(struct adxrs290_dev *dev, enum adxrs290_hpf *hpf)
Get the high-pass filter pole location.
Definition: adxrs290.c:161
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
ADXRS290_DATA_RDY_OUT
#define ADXRS290_DATA_RDY_OUT
Definition: adxrs290.h:79
no_os_gpio.h
Header file of GPIO Interface.
ADXRS290_REG_TEMP1
#define ADXRS290_REG_TEMP1
Definition: adxrs290.h:70
ADXRS290_LPF_MASK
#define ADXRS290_LPF_MASK
Definition: adxrs290.h:82
adxrs290_get_lpf
int32_t adxrs290_get_lpf(struct adxrs290_dev *dev, enum adxrs290_lpf *lpf)
Get the low-pass filter pole location.
Definition: adxrs290.c:120
adxrs290_lpf
adxrs290_lpf
Low-Pass filter pole location.
Definition: adxrs290.h:124
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
adxrs290_hpf
adxrs290_hpf
High-Pass filter pole location.
Definition: adxrs290.h:139
no_os_util.h
Header file of utility functions.
adxrs290_init_param::hpf
enum adxrs290_hpf hpf
Definition: adxrs290.h:167
adxrs290_channel
adxrs290_channel
Channel of teh adxrs290 data rate.
Definition: adxrs290.h:111
adxrs290_get_hpf
int32_t adxrs290_get_hpf(struct adxrs290_dev *dev, enum adxrs290_hpf *hpf)
Get the high-pass filter pole location.
Definition: adxrs290.c:161
ADXRS290_HPF_MASK
#define ADXRS290_HPF_MASK
Definition: adxrs290.h:84
ADXRS290_REG_TEMP0
#define ADXRS290_REG_TEMP0
Definition: adxrs290.h:69
adxrs290_init_param::gpio_sync
struct no_os_gpio_init_param * gpio_sync
Definition: adxrs290.h:161
adxrs290_init_param::lpf
enum adxrs290_lpf lpf
Definition: adxrs290.h:165
ADXRS290_MEASUREMENT
#define ADXRS290_MEASUREMENT
Definition: adxrs290.h:78
adxrs290_mode
adxrs290_mode
Mode of the adxrs290.
Definition: adxrs290.h:100
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
ADXRS290_HPF_0HZ044
@ ADXRS290_HPF_0HZ044
Definition: adxrs290.h:143
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