accel22  2.0.0.0
accel22.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef ACCEL22_H
29 #define ACCEL22_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_spi_master.h"
39 #include "spi_specifics.h"
40 
61 #define ACCEL22_REG_DEVID_AD 0x00
62 #define ACCEL22_REG_DEVID_MST 0x01
63 #define ACCEL22_REG_PART_ID 0x02
64 #define ACCEL22_REG_REV_ID 0x03
65 #define ACCEL22_REG_SERIAL_NUMBER_3 0x04
66 #define ACCEL22_REG_SERIAL_NUMBER_2 0x05
67 #define ACCEL22_REG_SERIAL_NUMBER_1 0x06
68 #define ACCEL22_REG_SERIAL_NUMBER_0 0x07
69 #define ACCEL22_REG_XDATA 0x08
70 #define ACCEL22_REG_YDATA 0x09
71 #define ACCEL22_REG_ZDATA 0x0A
72 #define ACCEL22_REG_STATUS 0x0B
73 #define ACCEL22_REG_FIFO_ENTRIES_L 0x0C
74 #define ACCEL22_REG_FIFO_ENTRIES_H 0x0D
75 #define ACCEL22_REG_XDATA_H 0x0E
76 #define ACCEL22_REG_XDATA_L 0x0F
77 #define ACCEL22_REG_YDATA_H 0x10
78 #define ACCEL22_REG_YDATA_L 0x11
79 #define ACCEL22_REG_ZDATA_H 0x12
80 #define ACCEL22_REG_ZDATA_L 0x13
81 #define ACCEL22_REG_TEMP_H 0x14
82 #define ACCEL22_REG_TEMP_L 0x15
83 #define ACCEL22_REG_EX_ADC_H 0x16
84 #define ACCEL22_REG_EX_ADC_L 0x17
85 #define ACCEL22_REG_I2C_FIFO_DATA 0x18
86 #define ACCEL22_REG_SOFT_RESET 0x19
87 #define ACCEL22_REG_THRESH_ACT_H 0x20
88 #define ACCEL22_REG_THRESH_ACT_L 0x21
89 #define ACCEL22_REG_TIME_ACT 0x22
90 #define ACCEL22_REG_THRESH_INACT_H 0x23
91 #define ACCEL22_REG_THRESH_INACT_L 0x24
92 #define ACCEL22_REG_TIME_INACT_H 0x25
93 #define ACCEL22_REG_TIME_INACT_L 0x26
94 #define ACCEL22_REG_ACT_INACT_CTL 0x27
95 #define ACCEL22_REG_FIFO_CONTROL 0x28
96 #define ACCEL22_REG_FIFO_SAMPLES 0x29
97 #define ACCEL22_REG_INTMAP1_LOWER 0x2A
98 #define ACCEL22_REG_INTMAP2_LOWER 0x2B
99 #define ACCEL22_REG_FILTER_CTL 0x2C
100 #define ACCEL22_REG_POWER_CTL 0x2D
101 #define ACCEL22_REG_SELF_TEST 0x2E
102 #define ACCEL22_REG_TAP_THRESH 0x2F
103 #define ACCEL22_REG_TAP_DUR 0x30
104 #define ACCEL22_REG_TAP_LATENT 0x31
105 #define ACCEL22_REG_TAP_WINDOW 0x32
106 #define ACCEL22_REG_X_OFFSET 0x33
107 #define ACCEL22_REG_Y_OFFSET 0x34
108 #define ACCEL22_REG_Z_OFFSET 0x35
109 #define ACCEL22_REG_X_SENS 0x36
110 #define ACCEL22_REG_Y_SENS 0x37
111 #define ACCEL22_REG_Z_SENS 0x38
112 #define ACCEL22_REG_TIMER_CTL 0x39
113 #define ACCEL22_REG_INTMAP1_UPPER 0x3A
114 #define ACCEL22_REG_INTMAP2_UPPER 0x3B
115 #define ACCEL22_REG_ADC_CTL 0x3C
116 #define ACCEL22_REG_TEMP_CTL 0x3D
117 #define ACCEL22_REG_TEMP_ADC_OVER_THRSH_H 0x3E
118 #define ACCEL22_REG_TEMP_ADC_OVER_THRSH_L 0x3F
119 #define ACCEL22_REG_TEMP_ADC_UNDER_THRSH_H 0x40
120 #define ACCEL22_REG_TEMP_ADC_UNDER_THRSH_L 0x41
121 #define ACCEL22_REG_TEMP_ADC_TIMER 0x42
122 #define ACCEL22_REG_AXIS_MASK 0x43
123 #define ACCEL22_REG_STATUS_COPY 0x44
124 #define ACCEL22_REG_STATUS_2 0x45
125  // accel22_reg
127 
142 #define ACCEL22_INTMAP1_LOWER_INT_LOW 0x80
143 #define ACCEL22_INTMAP1_LOWER_AWAKE 0x40
144 #define ACCEL22_INTMAP1_LOWER_INACT 0x20
145 #define ACCEL22_INTMAP1_LOWER_ACT 0x10
146 #define ACCEL22_INTMAP1_LOWER_FIFO_OR 0x08
147 #define ACCEL22_INTMAP1_LOWER_FIFO_WM 0x04
148 #define ACCEL22_INTMAP1_LOWER_FIFO_RDY 0x02
149 #define ACCEL22_INTMAP1_LOWER_DATA_RDY 0x01
150 
155 #define ACCEL22_POWER_CTL_EXT_CLK 0x40
156 #define ACCEL22_POWER_CTL_NOISE_NORMAL 0x00
157 #define ACCEL22_POWER_CTL_NOISE_LOW 0x10
158 #define ACCEL22_POWER_CTL_NOISE_ULTRALOW 0x20
159 #define ACCEL22_POWER_CTL_NOISE_BIT_MASK 0x30
160 #define ACCEL22_POWER_CTL_WAKEUP 0x08
161 #define ACCEL22_POWER_CTL_AUTOSLEEP 0x04
162 #define ACCEL22_POWER_CTL_STANDBY_MODE 0x00
163 #define ACCEL22_POWER_CTL_MEASUREMENT_MODE 0x02
164 
169 #define ACCEL22_SOFT_RESET 0x52
170 
175 #define ACCEL22_ENABLE_TEMPERATURE 0x01
176 #define ACCEL22_ENABLE_ADC 0x01
177 
182 #define ACCEL22_ACCEL_2G_RES 0.25
183 #define ACCEL22_ACCEL_4G_RES 0.5
184 #define ACCEL22_ACCEL_8G_RES 1.0
185 #define ACCEL22_ROOM_TEMPERATURE 25.0
186 #define ACCEL22_TEMPERATURE_BIAS 165
187 #define ACCEL22_TEMPERATURE_RES 54.0
188 #define ACCEL22_ADC_VREG 1.098
189 #define ACCEL22_ADC_RES 0x3FFF
190 #define ACCEL22_ADC_OFFSET 0x2000
191 
196 #define ACCEL22_ADI_DEVICE_ID 0xAD
197 #define ACCEL22_MEMS_DEVICE_ID 0x1D
198 #define ACCEL22_PART_ID 0xF7
199 
204 #define ACCEL22_SPI_WRITE_REG 0x0A
205 #define ACCEL22_SPI_READ_REG 0x0B
206 #define ACCEL22_SPI_READ_FIFO 0x0D
207 
213 #define ACCEL22_DEVICE_ADDRESS_0 0x1D
214 #define ACCEL22_DEVICE_ADDRESS_1 0x53
215 
224 #define ACCEL22_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
225 #define ACCEL22_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
226  // accel22_set
228 
243 #define ACCEL22_MAP_MIKROBUS( cfg, mikrobus ) \
244  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
245  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
246  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
247  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
248  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
249  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
250  cfg.int2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
251  cfg.int1 = MIKROBUS( mikrobus, MIKROBUS_INT )
252  // accel22_map // accel22
255 
260 typedef enum
261 {
266 
271 typedef err_t ( *accel22_master_io_t )( struct accel22_s*, uint8_t, uint8_t*, uint8_t );
277 typedef struct accel22_s
278 {
279  digital_in_t int2;
280  digital_in_t int1;
282  i2c_master_t i2c;
283  spi_master_t spi;
285  uint8_t slave_address;
286  pin_name_t chip_select;
291  float resolution;
294 
299 typedef struct
300 {
301  pin_name_t scl;
302  pin_name_t sda;
303  pin_name_t miso;
304  pin_name_t mosi;
305  pin_name_t sck;
306  pin_name_t cs;
307  pin_name_t int2;
308  pin_name_t int1;
310  uint32_t i2c_speed;
311  uint8_t i2c_address;
313  uint32_t spi_speed;
314  spi_master_mode_t spi_mode;
315  spi_master_chip_select_polarity_t cs_polarity;
319 } accel22_cfg_t;
320 
325 typedef struct
326 {
327  float x;
328  float y;
329  float z;
332 
337 typedef enum
338 {
339  ACCEL22_2G = 0x00,
340  ACCEL22_4G = 0x01,
341  ACCEL22_8G = 0x02,
343 
345 
350 typedef enum
351 {
358  ACCEL22_ODR_BIT_MASK = 0x07
359 
361 
366 typedef enum
367 {
369  ACCEL22_ERROR = -1
370 
372 
389 
405 
419 err_t accel22_init ( accel22_t *ctx, accel22_cfg_t *cfg );
420 
434 
449 err_t accel22_generic_write ( accel22_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
450 
465 err_t accel22_generic_read ( accel22_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
466 
479 err_t accel22_write_register ( accel22_t *ctx, uint8_t reg, uint8_t data_in );
480 
493 err_t accel22_read_register ( accel22_t *ctx, uint8_t reg, uint8_t *data_out );
494 
506 
516 
526 
542 
556 
569 err_t accel22_get_temperature ( accel22_t *ctx, float *temperature );
570 
583 err_t accel22_get_adc ( accel22_t *ctx, float *v_adc );
584 
596 
608 
609 #ifdef __cplusplus
610 }
611 #endif
612 #endif // ACCEL22_H
613  // accel22
615 
616 // ------------------------------------------------------------------------ END
accel22_cfg_t::int1
pin_name_t int1
Definition: accel22.h:308
accel22_cfg_t::sda
pin_name_t sda
Definition: accel22.h:302
accel22_cfg_t::miso
pin_name_t miso
Definition: accel22.h:303
accel22_set_filter_config
err_t accel22_set_filter_config(accel22_t *ctx, accel22_range_t range, accel22_odr_t odr)
Accel 22 set filter config function.
accel22_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: accel22.h:314
accel22_axes_t::x
float x
Definition: accel22.h:327
accel22_get_adc
err_t accel22_get_adc(accel22_t *ctx, float *v_adc)
Accel 22 get adc function.
accel22_t
struct accel22_s accel22_t
Accel 22 Click context object.
ACCEL22_DRV_SEL_I2C
@ ACCEL22_DRV_SEL_I2C
Definition: accel22.h:263
ACCEL22_12p5HZ
@ ACCEL22_12p5HZ
Definition: accel22.h:352
accel22_read_register
err_t accel22_read_register(accel22_t *ctx, uint8_t reg, uint8_t *data_out)
Accel 22 read register function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
accel22_cfg_t::cs
pin_name_t cs
Definition: accel22.h:306
accel22_return_value_t
accel22_return_value_t
Accel 22 Click return value data.
Definition: accel22.h:367
accel22_s::spi
spi_master_t spi
Definition: accel22.h:283
accel22_cfg_t::mosi
pin_name_t mosi
Definition: accel22.h:304
ACCEL22_RANGE_BIT_MASK
@ ACCEL22_RANGE_BIT_MASK
Definition: accel22.h:342
accel22_cfg_t::spi_speed
uint32_t spi_speed
Definition: accel22.h:313
ACCEL22_200HZ
@ ACCEL22_200HZ
Definition: accel22.h:356
ACCEL22_ERROR
@ ACCEL22_ERROR
Definition: accel22.h:369
ACCEL22_25HZ
@ ACCEL22_25HZ
Definition: accel22.h:353
accel22_range_t
accel22_range_t
Accel 22 Click accel range selection.
Definition: accel22.h:338
accel22_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: accel22.h:315
accel22_drv_interface_selection
void accel22_drv_interface_selection(accel22_cfg_t *cfg, accel22_drv_t drv_sel)
Accel 22 driver interface setup function.
accel22_enable_adc_measurement
err_t accel22_enable_adc_measurement(accel22_t *ctx)
Accel 22 enable ADC measurement function.
accel22_drv_t
accel22_drv_t
Accel 22 Click driver selector.
Definition: accel22.h:261
ACCEL22_50HZ
@ ACCEL22_50HZ
Definition: accel22.h:354
accel22_odr_t
accel22_odr_t
Accel 22 Click output data rate.
Definition: accel22.h:351
accel22_cfg_t::int2
pin_name_t int2
Definition: accel22.h:307
accel22_s::int1
digital_in_t int1
Definition: accel22.h:280
accel22_get_temperature
err_t accel22_get_temperature(accel22_t *ctx, float *temperature)
Accel 22 get temperature function.
accel22_default_cfg
err_t accel22_default_cfg(accel22_t *ctx)
Accel 22 default configuration function.
accel22_cfg_t
Accel 22 Click configuration object.
Definition: accel22.h:300
ACCEL22_400HZ
@ ACCEL22_400HZ
Definition: accel22.h:357
accel22_cfg_t::sck
pin_name_t sck
Definition: accel22.h:305
accel22_get_int2_pin
uint8_t accel22_get_int2_pin(accel22_t *ctx)
Accel 22 get int2 pin function.
accel22_axes_t
Accel 22 Click Axes data structure.
Definition: accel22.h:326
accel22_get_int1_pin
uint8_t accel22_get_int1_pin(accel22_t *ctx)
Accel 22 get int1 pin function.
accel22_check_communication
err_t accel22_check_communication(accel22_t *ctx)
Accel 22 check communication function.
accel22_init
err_t accel22_init(accel22_t *ctx, accel22_cfg_t *cfg)
Accel 22 initialization function.
accel22_axes_t::z
float z
Definition: accel22.h:329
ACCEL22_2G
@ ACCEL22_2G
Definition: accel22.h:339
ACCEL22_ODR_BIT_MASK
@ ACCEL22_ODR_BIT_MASK
Definition: accel22.h:358
accel22_cfg_setup
void accel22_cfg_setup(accel22_cfg_t *cfg)
Accel 22 configuration object setup function.
accel22_s::write_f
accel22_master_io_t write_f
Definition: accel22.h:289
accel22_get_axes
err_t accel22_get_axes(accel22_t *ctx, accel22_axes_t *axes)
Accel 22 get axes function.
ACCEL22_DRV_SEL_SPI
@ ACCEL22_DRV_SEL_SPI
Definition: accel22.h:262
accel22_s::drv_sel
accel22_drv_t drv_sel
Definition: accel22.h:287
ACCEL22_8G
@ ACCEL22_8G
Definition: accel22.h:341
accel22_enable_temperature_measurement
err_t accel22_enable_temperature_measurement(accel22_t *ctx)
Accel 22 enable temperature measurement function.
accel22_s::resolution
float resolution
Definition: accel22.h:291
ACCEL22_4G
@ ACCEL22_4G
Definition: accel22.h:340
accel22_cfg_t::drv_sel
accel22_drv_t drv_sel
Definition: accel22.h:317
accel22_cfg_t::scl
pin_name_t scl
Definition: accel22.h:301
accel22_s::chip_select
pin_name_t chip_select
Definition: accel22.h:286
accel22_s::i2c
i2c_master_t i2c
Definition: accel22.h:282
ACCEL22_100HZ
@ ACCEL22_100HZ
Definition: accel22.h:355
accel22_s::slave_address
uint8_t slave_address
Definition: accel22.h:285
accel22_generic_read
err_t accel22_generic_read(accel22_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Accel 22 data reading function.
accel22_write_register
err_t accel22_write_register(accel22_t *ctx, uint8_t reg, uint8_t data_in)
Accel 22 write register function.
accel22_master_io_t
err_t(* accel22_master_io_t)(struct accel22_s *, uint8_t, uint8_t *, uint8_t)
Accel 22 Click driver interface.
Definition: accel22.h:271
accel22_s::int2
digital_in_t int2
Definition: accel22.h:279
accel22_s
Accel 22 Click context object.
Definition: accel22.h:278
accel22_generic_write
err_t accel22_generic_write(accel22_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Accel 22 data writing function.
accel22_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel22.h:311
accel22_axes_t::y
float y
Definition: accel22.h:328
accel22_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel22.h:310
ACCEL22_OK
@ ACCEL22_OK
Definition: accel22.h:368
accel22_s::read_f
accel22_master_io_t read_f
Definition: accel22.h:290