no-OS
adxl362.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef __ADXL362_H__
35 #define __ADXL362_H__
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 #include <stdint.h>
41 #include "no_os_spi.h"
42 
43 /******************************************************************************/
44 /********************************* ADXL362 ************************************/
45 /******************************************************************************/
46 
47 /* ADXL362 communication commands */
48 #define ADXL362_WRITE_REG 0x0A
49 #define ADXL362_READ_REG 0x0B
50 #define ADXL362_WRITE_FIFO 0x0D
51 
52 /* Registers */
53 #define ADXL362_REG_DEVID_AD 0x00
54 #define ADXL362_REG_DEVID_MST 0x01
55 #define ADXL362_REG_PARTID 0x02
56 #define ADXL362_REG_REVID 0x03
57 #define ADXL362_REG_XDATA 0x08
58 #define ADXL362_REG_YDATA 0x09
59 #define ADXL362_REG_ZDATA 0x0A
60 #define ADXL362_REG_STATUS 0x0B
61 #define ADXL362_REG_FIFO_L 0x0C
62 #define ADXL362_REG_FIFO_H 0x0D
63 #define ADXL362_REG_XDATA_L 0x0E
64 #define ADXL362_REG_XDATA_H 0x0F
65 #define ADXL362_REG_YDATA_L 0x10
66 #define ADXL362_REG_YDATA_H 0x11
67 #define ADXL362_REG_ZDATA_L 0x12
68 #define ADXL362_REG_ZDATA_H 0x13
69 #define ADXL362_REG_TEMP_L 0x14
70 #define ADXL362_REG_TEMP_H 0x15
71 #define ADXL362_REG_SOFT_RESET 0x1F
72 #define ADXL362_REG_THRESH_ACT_L 0x20
73 #define ADXL362_REG_THRESH_ACT_H 0x21
74 #define ADXL362_REG_TIME_ACT 0x22
75 #define ADXL362_REG_THRESH_INACT_L 0x23
76 #define ADXL362_REG_THRESH_INACT_H 0x24
77 #define ADXL362_REG_TIME_INACT_L 0x25
78 #define ADXL362_REG_TIME_INACT_H 0x26
79 #define ADXL362_REG_ACT_INACT_CTL 0x27
80 #define ADXL362_REG_FIFO_CTL 0x28
81 #define ADXL362_REG_FIFO_SAMPLES 0x29
82 #define ADXL362_REG_INTMAP1 0x2A
83 #define ADXL362_REG_INTMAP2 0x2B
84 #define ADXL362_REG_FILTER_CTL 0x2C
85 #define ADXL362_REG_POWER_CTL 0x2D
86 #define ADXL362_REG_SELF_TEST 0x2E
87 
88 /* ADXL362_REG_STATUS definitions */
89 #define ADXL362_STATUS_ERR_USER_REGS (1 << 7)
90 #define ADXL362_STATUS_AWAKE (1 << 6)
91 #define ADXL362_STATUS_INACT (1 << 5)
92 #define ADXL362_STATUS_ACT (1 << 4)
93 #define ADXL362_STATUS_FIFO_OVERRUN (1 << 3)
94 #define ADXL362_STATUS_FIFO_WATERMARK (1 << 2)
95 #define ADXL362_STATUS_FIFO_RDY (1 << 1)
96 #define ADXL362_STATUS_DATA_RDY (1 << 0)
97 
98 /* ADXL362_REG_ACT_INACT_CTL definitions */
99 #define ADXL362_ACT_INACT_CTL_LINKLOOP(x) (((x) & 0x3) << 4)
100 #define ADXL362_ACT_INACT_CTL_INACT_REF (1 << 3)
101 #define ADXL362_ACT_INACT_CTL_INACT_EN (1 << 2)
102 #define ADXL362_ACT_INACT_CTL_ACT_REF (1 << 1)
103 #define ADXL362_ACT_INACT_CTL_ACT_EN (1 << 0)
104 
105 /* ADXL362_ACT_INACT_CTL_LINKLOOP(x) options */
106 #define ADXL362_MODE_DEFAULT 0
107 #define ADXL362_MODE_LINK 1
108 #define ADXL362_MODE_LOOP 3
109 
110 /* ADXL362_REG_FIFO_CTL */
111 #define ADXL362_FIFO_CTL_AH (1 << 3)
112 #define ADXL362_FIFO_CTL_FIFO_TEMP (1 << 2)
113 #define ADXL362_FIFO_CTL_FIFO_MODE(x) (((x) & 0x3) << 0)
114 
115 /* ADXL362_FIFO_CTL_FIFO_MODE(x) options */
116 #define ADXL362_FIFO_DISABLE 0
117 #define ADXL362_FIFO_OLDEST_SAVED 1
118 #define ADXL362_FIFO_STREAM 2
119 #define ADXL362_FIFO_TRIGGERED 3
120 
121 /* ADXL362_REG_INTMAP1 */
122 #define ADXL362_INTMAP1_INT_LOW (1 << 7)
123 #define ADXL362_INTMAP1_AWAKE (1 << 6)
124 #define ADXL362_INTMAP1_INACT (1 << 5)
125 #define ADXL362_INTMAP1_ACT (1 << 4)
126 #define ADXL362_INTMAP1_FIFO_OVERRUN (1 << 3)
127 #define ADXL362_INTMAP1_FIFO_WATERMARK (1 << 2)
128 #define ADXL362_INTMAP1_FIFO_READY (1 << 1)
129 #define ADXL362_INTMAP1_DATA_READY (1 << 0)
130 
131 /* ADXL362_REG_INTMAP2 definitions */
132 #define ADXL362_INTMAP2_INT_LOW (1 << 7)
133 #define ADXL362_INTMAP2_AWAKE (1 << 6)
134 #define ADXL362_INTMAP2_INACT (1 << 5)
135 #define ADXL362_INTMAP2_ACT (1 << 4)
136 #define ADXL362_INTMAP2_FIFO_OVERRUN (1 << 3)
137 #define ADXL362_INTMAP2_FIFO_WATERMARK (1 << 2)
138 #define ADXL362_INTMAP2_FIFO_READY (1 << 1)
139 #define ADXL362_INTMAP2_DATA_READY (1 << 0)
140 
141 /* ADXL362_REG_FILTER_CTL definitions */
142 #define ADXL362_FILTER_CTL_RANGE(x) (((x) & 0x3) << 6)
143 #define ADXL362_FILTER_CTL_RES (1 << 5)
144 #define ADXL362_FILTER_CTL_HALF_BW (1 << 4)
145 #define ADXL362_FILTER_CTL_EXT_SAMPLE (1 << 3)
146 #define ADXL362_FILTER_CTL_ODR(x) (((x) & 0x7) << 0)
147 
148 /* ADXL362_FILTER_CTL_RANGE(x) options */
149 #define ADXL362_RANGE_2G 0 /* +/-2 g */
150 #define ADXL362_RANGE_4G 1 /* +/-4 g */
151 #define ADXL362_RANGE_8G 2 /* +/-8 g */
152 
153 /* ADXL362_FILTER_CTL_ODR(x) options */
154 #define ADXL362_ODR_12_5_HZ 0 /* 12.5 Hz */
155 #define ADXL362_ODR_25_HZ 1 /* 25 Hz */
156 #define ADXL362_ODR_50_HZ 2 /* 50 Hz */
157 #define ADXL362_ODR_100_HZ 3 /* 100 Hz */
158 #define ADXL362_ODR_200_HZ 4 /* 200 Hz */
159 #define ADXL362_ODR_400_HZ 5 /* 400 Hz */
160 
161 /* ADXL362_REG_POWER_CTL definitions */
162 #define ADXL362_POWER_CTL_RES (1 << 7)
163 #define ADXL362_POWER_CTL_EXT_CLK (1 << 6)
164 #define ADXL362_POWER_CTL_LOW_NOISE(x) (((x) & 0x3) << 4)
165 #define ADXL362_POWER_CTL_WAKEUP (1 << 3)
166 #define ADXL362_POWER_CTL_AUTOSLEEP (1 << 2)
167 #define ADXL362_POWER_CTL_MEASURE(x) (((x) & 0x3) << 0)
168 
169 /* ADXL362_POWER_CTL_LOW_NOISE(x) options */
170 #define ADXL362_NOISE_MODE_NORMAL 0
171 #define ADXL362_NOISE_MODE_LOW 1
172 #define ADXL362_NOISE_MODE_ULTRALOW 2
173 
174 /* ADXL362_POWER_CTL_MEASURE(x) options */
175 #define ADXL362_MEASURE_STANDBY 0
176 #define ADXL362_MEASURE_ON 2
177 
178 /* ADXL362_REG_SELF_TEST */
179 #define ADXL362_SELF_TEST_ST (1 << 0)
180 
181 /* ADXL362 device information */
182 #define ADXL362_DEVICE_AD 0xAD
183 #define ADXL362_DEVICE_MST 0x1D
184 #define ADXL362_PART_ID 0xF2
185 
186 /* ADXL362 Reset settings */
187 #define ADXL362_RESET_KEY 0x52
188 
189 /******************************************************************************/
190 /*************************** Types Declarations *******************************/
191 /******************************************************************************/
192 
197 struct adxl362_dev {
201  uint8_t selected_range;
202 };
203 
211 };
212 
213 /******************************************************************************/
214 /************************ Functions Declarations ******************************/
215 /******************************************************************************/
216 
218 int32_t adxl362_init(struct adxl362_dev **device,
220 
222 int32_t adxl362_remove(struct adxl362_dev *dev);
223 
225 void adxl362_set_register_value(struct adxl362_dev *dev,
226  uint16_t register_value,
227  uint8_t register_address,
228  uint8_t bytes_number);
229 
231 void adxl362_get_register_value(struct adxl362_dev *dev,
232  uint8_t *read_data,
233  uint8_t register_address,
234  uint8_t bytes_number);
235 
237 void adxl362_get_fifo_value(struct adxl362_dev *dev,
238  uint8_t *buffer,
239  uint16_t bytes_number);
240 
242 void adxl362_software_reset(struct adxl362_dev *dev);
243 
245 void adxl362_set_power_mode(struct adxl362_dev *dev,
246  uint8_t pwr_mode);
247 
249 void adxl362_set_range(struct adxl362_dev *dev,
250  uint8_t g_range);
251 
253 void adxl362_set_output_rate(struct adxl362_dev *dev,
254  uint8_t out_rate);
255 
257 void adxl362_get_xyz(struct adxl362_dev *dev,
258  int16_t *x,
259  int16_t *y,
260  int16_t *z);
261 
263 void adxl362_get_g_xyz(struct adxl362_dev *dev,
264  float* x,
265  float* y,
266  float* z);
267 
269 float adxl362_read_temperature(struct adxl362_dev *dev);
270 
272 void adxl362_fifo_setup(struct adxl362_dev *dev,
273  uint8_t mode,
274  uint16_t water_mark_lvl,
275  uint8_t en_temp_read);
276 
279  uint8_t ref_or_abs,
280  uint16_t threshold,
281  uint8_t time);
282 
285  uint8_t ref_or_abs,
286  uint16_t threshold,
287  uint16_t time);
288 
289 #endif /* __ADXL362_H__ */
no_os_alloc.h
adxl362_software_reset
void adxl362_software_reset(struct adxl362_dev *dev)
Resets the device via SPI communication bus.
Definition: adxl362.c:189
iio_trigger.h
Header file for iio_trigger.
ADXL362_REG_TEMP_L
#define ADXL362_REG_TEMP_L
Definition: adxl362.h:69
ADXL362_REG_THRESH_ACT_L
#define ADXL362_REG_THRESH_ACT_L
Definition: adxl362.h:72
adxl362_fifo_setup
void adxl362_fifo_setup(struct adxl362_dev *dev, uint8_t mode, uint16_t water_mark_lvl, uint8_t en_temp_read)
Configures the FIFO feature.
Definition: adxl362.c:383
adxl362_setup_activity_detection
void adxl362_setup_activity_detection(struct adxl362_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint8_t time)
Configures activity detection.
Definition: adxl362.c:418
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
ADXL362_POWER_CTL_MEASURE
#define ADXL362_POWER_CTL_MEASURE(x)
Definition: adxl362.h:167
adxl362_dev
ADXL362 Device structure.
Definition: adxl362.h:197
adxl362_read_temperature
float adxl362_read_temperature(struct adxl362_dev *dev)
Reads the temperature of the device.
Definition: adxl362.c:350
no_os_spi.h
Header file of SPI Interface.
ADXL362_MEASURE_ON
#define ADXL362_MEASURE_ON
Definition: adxl362.h:176
ADXL362_REG_THRESH_INACT_L
#define ADXL362_REG_THRESH_INACT_L
Definition: adxl362.h:75
adxl355_iio_trig_desc
struct iio_trigger adxl355_iio_trig_desc
Definition: iio_adxl355_trig.c:44
iio_trig_disable
int iio_trig_disable(void *trig)
Disable system interrupt which is linked to the given trigger.
Definition: iio_trigger.c:127
ADXL362_WRITE_FIFO
#define ADXL362_WRITE_FIFO
Definition: adxl362.h:50
no_os_spi_init_param::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:148
ADXL362_ACT_INACT_CTL_INACT_EN
#define ADXL362_ACT_INACT_CTL_INACT_EN
Definition: adxl362.h:101
device
Definition: ad9361_util.h:69
adxl362_set_output_rate
void adxl362_set_output_rate(struct adxl362_dev *dev, uint8_t out_rate)
Selects the Output Data Rate of the device.
Definition: adxl362.c:270
adxl362_set_register_value
void adxl362_set_register_value(struct adxl362_dev *dev, uint16_t register_value, uint8_t register_address, uint8_t bytes_number)
Writes data into a register.
Definition: adxl362.c:109
adxl362_get_xyz
void adxl362_get_xyz(struct adxl362_dev *dev, int16_t *x, int16_t *y, int16_t *z)
Reads the 3-axis raw data from the accelerometer.
Definition: adxl362.c:298
adxl362_get_xyz
void adxl362_get_xyz(struct adxl362_dev *dev, int16_t *x, int16_t *y, int16_t *z)
Reads the 3-axis raw data from the accelerometer.
Definition: adxl362.c:298
ADXL362_RESET_KEY
#define ADXL362_RESET_KEY
Definition: adxl362.h:187
ADXL362_FIFO_CTL_FIFO_TEMP
#define ADXL362_FIFO_CTL_FIFO_TEMP
Definition: adxl362.h:112
adxl362_get_g_xyz
void adxl362_get_g_xyz(struct adxl362_dev *dev, float *x, float *y, float *z)
Reads the 3-axis raw data from the accelerometer and converts it to g.
Definition: adxl362.c:324
ADXL362_PART_ID
#define ADXL362_PART_ID
Definition: adxl362.h:184
iio.h
Header file of iio.
ADXL362_FILTER_CTL_RANGE
#define ADXL362_FILTER_CTL_RANGE(x)
Definition: adxl362.h:142
ADXL362_REG_POWER_CTL
#define ADXL362_REG_POWER_CTL
Definition: adxl362.h:85
adxl362_get_fifo_value
void adxl362_get_fifo_value(struct adxl362_dev *dev, uint8_t *buffer, uint16_t bytes_number)
Reads multiple bytes from the device's FIFO buffer.
Definition: adxl362.c:164
adxl362_read_temperature
float adxl362_read_temperature(struct adxl362_dev *dev)
Reads the temperature of the device.
Definition: adxl362.c:350
iio_trig_enable
int iio_trig_enable(void *trig)
Enable system interrupt which is linked to the given trigger.
Definition: iio_trigger.c:110
ADXL362_REG_FIFO_CTL
#define ADXL362_REG_FIFO_CTL
Definition: adxl362.h:80
adxl362_init_param
Structure holding the parameters for ADXL362 device initialization.
Definition: adxl362.h:208
ADXL362_ACT_INACT_CTL_ACT_EN
#define ADXL362_ACT_INACT_CTL_ACT_EN
Definition: adxl362.h:103
ADXL362_REG_SOFT_RESET
#define ADXL362_REG_SOFT_RESET
Definition: adxl362.h:71
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
adxl362_get_register_value
void adxl362_get_register_value(struct adxl362_dev *dev, uint8_t *read_data, uint8_t register_address, uint8_t bytes_number)
Performs a burst read of a specified number of registers.
Definition: adxl362.c:135
ADXL362_REG_ACT_INACT_CTL
#define ADXL362_REG_ACT_INACT_CTL
Definition: adxl362.h:79
adxl362_set_register_value
void adxl362_set_register_value(struct adxl362_dev *dev, uint16_t register_value, uint8_t register_address, uint8_t bytes_number)
Writes data into a register.
Definition: adxl362.c:109
adxl362_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: adxl362.h:210
adxl362_get_register_value
void adxl362_get_register_value(struct adxl362_dev *dev, uint8_t *read_data, uint8_t register_address, uint8_t bytes_number)
Performs a burst read of a specified number of registers.
Definition: adxl362.c:135
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
adxl362_init
int32_t adxl362_init(struct adxl362_dev **device, struct adxl362_init_param init_param)
Initializes communication with the device and checks if the part is present by reading the device id.
Definition: adxl362.c:56
adxl362_dev::selected_range
uint8_t selected_range
Definition: adxl362.h:201
adxl362_get_g_xyz
void adxl362_get_g_xyz(struct adxl362_dev *dev, float *x, float *y, float *z)
Reads the 3-axis raw data from the accelerometer and converts it to g.
Definition: adxl362.c:324
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
ADXL362_REG_PARTID
#define ADXL362_REG_PARTID
Definition: adxl362.h:55
ADXL362_FIFO_CTL_FIFO_MODE
#define ADXL362_FIFO_CTL_FIFO_MODE(x)
Definition: adxl362.h:113
adxl362_fifo_setup
void adxl362_fifo_setup(struct adxl362_dev *dev, uint8_t mode, uint16_t water_mark_lvl, uint8_t en_temp_read)
Configures the FIFO feature.
Definition: adxl362.c:383
iio_trigger
Definition: iio_types.h:231
adxl362_get_fifo_value
void adxl362_get_fifo_value(struct adxl362_dev *dev, uint8_t *buffer, uint16_t bytes_number)
Reads multiple bytes from the device's FIFO buffer.
Definition: adxl362.c:164
adxl362_setup_inactivity_detection
void adxl362_setup_inactivity_detection(struct adxl362_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint16_t time)
Configures inactivity detection.
Definition: adxl362.c:465
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
adxl362_setup_activity_detection
void adxl362_setup_activity_detection(struct adxl362_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint8_t time)
Configures activity detection.
Definition: adxl362.c:418
adxl362_set_range
void adxl362_set_range(struct adxl362_dev *dev, uint8_t g_range)
Selects the measurement range.
Definition: adxl362.c:237
adxl362_set_output_rate
void adxl362_set_output_rate(struct adxl362_dev *dev, uint8_t out_rate)
Selects the Output Data Rate of the device.
Definition: adxl362.c:270
ADXL362_REG_TIME_INACT_L
#define ADXL362_REG_TIME_INACT_L
Definition: adxl362.h:77
adxl362_init
int32_t adxl362_init(struct adxl362_dev **device, struct adxl362_init_param init_param)
Initializes communication with the device and checks if the part is present by reading the device id.
Definition: adxl362.c:56
adxl362_set_power_mode
void adxl362_set_power_mode(struct adxl362_dev *dev, uint8_t pwr_mode)
Places the device into standby/measure mode.
Definition: adxl362.c:207
ADXL362_WRITE_REG
#define ADXL362_WRITE_REG
Definition: adxl362.h:48
adxl362_remove
int32_t adxl362_remove(struct adxl362_dev *dev)
Free the resources allocated by adxl362_init().
Definition: adxl362.c:88
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
adxl362.h
Header file of ADXL362 Driver.
adxl362_set_power_mode
void adxl362_set_power_mode(struct adxl362_dev *dev, uint8_t pwr_mode)
Places the device into standby/measure mode.
Definition: adxl362.c:207
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
ADXL362_REG_FIFO_SAMPLES
#define ADXL362_REG_FIFO_SAMPLES
Definition: adxl362.h:81
iio_trigger::is_synchronous
bool is_synchronous
Definition: iio_types.h:234
ADXL362_REG_FILTER_CTL
#define ADXL362_REG_FILTER_CTL
Definition: adxl362.h:84
adxl362_setup_inactivity_detection
void adxl362_setup_inactivity_detection(struct adxl362_dev *dev, uint8_t ref_or_abs, uint16_t threshold, uint16_t time)
Configures inactivity detection.
Definition: adxl362.c:465
ADXL362_ACT_INACT_CTL_ACT_REF
#define ADXL362_ACT_INACT_CTL_ACT_REF
Definition: adxl362.h:102
adxl362_set_range
void adxl362_set_range(struct adxl362_dev *dev, uint8_t g_range)
Selects the measurement range.
Definition: adxl362.c:237
adxl362_software_reset
void adxl362_software_reset(struct adxl362_dev *dev)
Resets the device via SPI communication bus.
Definition: adxl362.c:189
ADXL362_FILTER_CTL_ODR
#define ADXL362_FILTER_CTL_ODR(x)
Definition: adxl362.h:146
ADXL362_READ_REG
#define ADXL362_READ_REG
Definition: adxl362.h:49
adxl362_remove
int32_t adxl362_remove(struct adxl362_dev *dev)
Free the resources allocated by adxl362_init().
Definition: adxl362.c:88
ADXL362_REG_TIME_ACT
#define ADXL362_REG_TIME_ACT
Definition: adxl362.h:74
ADXL362_ACT_INACT_CTL_INACT_REF
#define ADXL362_ACT_INACT_CTL_INACT_REF
Definition: adxl362.h:100
adxl362_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: adxl362.h:199
ADXL362_REG_XDATA_L
#define ADXL362_REG_XDATA_L
Definition: adxl362.h:63
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140