accel19  2.0.0.0
accel19.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 ACCEL19_H
29 #define ACCEL19_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
49 #include "spi_specifics.h"
50 
71 #define ACCEL19_REG_OUT_T_L 0x0D
72 #define ACCEL19_REG_OUT_T_H 0x0E
73 #define ACCEL19_REG_WHO_AM_I 0x0F
74 #define ACCEL19_REG_CTRL1 0x20
75 #define ACCEL19_REG_CTRL2 0x21
76 #define ACCEL19_REG_CTRL3 0x22
77 #define ACCEL19_REG_CTRL4_INT1_PAD_CTRL 0x23
78 #define ACCEL19_REG_CTRL5_INT2_PAD_CTRL 0x24
79 #define ACCEL19_REG_CTRL6 0x25
80 #define ACCEL19_REG_STATUS 0x27
81 #define ACCEL19_REG_OUT_X_L 0x28
82 #define ACCEL19_REG_OUT_X_H 0x29
83 #define ACCEL19_REG_OUT_Y_L 0x2A
84 #define ACCEL19_REG_OUT_Y_H 0x2B
85 #define ACCEL19_REG_OUT_Z_L 0x2C
86 #define ACCEL19_REG_OUT_Z_H 0x2D
87 #define ACCEL19_REG_FIFO_CTRL 0x2E
88 #define ACCEL19_REG_FIFO_SAMPLES 0x2F
89 #define ACCEL19_REG_TAP_THS_X 0x30
90 #define ACCEL19_REG_TAP_THS_Y 0x31
91 #define ACCEL19_REG_TAP_THS_Z 0x32
92 #define ACCEL19_REG_INT_DUR 0x33
93 #define ACCEL19_REG_WAKE_UP_THS 0x34
94 #define ACCEL19_REG_WAKE_UP_DUR 0x35
95 #define ACCEL19_REG_FREE_FALL 0x36
96 #define ACCEL19_REG_STATUS_DUP 0x37
97 #define ACCEL19_REG_WAKE_UP_SRC 0x38
98 #define ACCEL19_REG_TAP_SRC 0x39
99 #define ACCEL19_REG_SIXD_SRC 0x3A
100 #define ACCEL19_REG_ALL_INT_SRC 0x3B
101 #define ACCEL19_REG_X_OFS_USR 0x3C
102 #define ACCEL19_REG_Y_OFS_USR 0x3D
103 #define ACCEL19_REG_Z_OFS_USR 0x3E
104 #define ACCEL19_REG_CTRL7 0x3F
105  // accel19_reg
107 
122 #define ACCEL19_DEVICE_ID 0x44
123 
128 #define ACCEL19_CTRL1_ODR_BIT_MASK 0xF0
129 #define ACCEL19_CTRL1_ODR_POWER_DOWN 0x00
130 #define ACCEL19_CTRL1_ODR_LP_1_6_Hz 0x10
131 #define ACCEL19_CTRL1_ODR_HP_12_5_Hz 0x10
132 #define ACCEL19_CTRL1_ODR_HP_LP_12_5_Hz 0x20
133 #define ACCEL19_CTRL1_ODR_HP_LP_25_Hz 0x30
134 #define ACCEL19_CTRL1_ODR_HP_LP_50_Hz 0x40
135 #define ACCEL19_CTRL1_ODR_HP_LP_100_Hz 0x50
136 #define ACCEL19_CTRL1_ODR_HP_LP_200_Hz 0x60
137 #define ACCEL19_CTRL1_ODR_LP_200_Hz 0x70
138 #define ACCEL19_CTRL1_ODR_HP_400_Hz 0x70
139 #define ACCEL19_CTRL1_ODR_HP_800_Hz 0x80
140 #define ACCEL19_CTRL1_ODR_HP_1600_Hz 0x90
141 
146 #define ACCEL19_CTRL1_OP_MODE_BIT_MASK 0x0C
147 #define ACCEL19_CTRL1_OP_MODE_LOW_POWER_MODE 0x00
148 #define ACCEL19_CTRL1_OP_MODE_HIGH_POWER_MODE 0x04
149 #define ACCEL19_CTRL1_OP_MODE_SINGLE_DATA_CONV 0x08
150 
155 #define ACCEL19_CTRL1_LP_MODE_BIT_MASK 0x03
156 #define ACCEL19_CTRL1_LP_MODE1_RES_12_bit 0x00
157 #define ACCEL19_CTRL1_LP_MODE2_RES_14_bit 0x01
158 #define ACCEL19_CTRL1_LP_MODE3_RES_14_bit 0x02
159 #define ACCEL19_CTRL1_LP_MODE4_RES_14_bit 0x03
160 
165 #define ACCEL19_CTRL2_SOFT_RESET 0x40
166 
171 #define ACCEL19_INT_DRDY 0x00
172 #define ACCEL19_STATUS_DRDY 0x01
173 
178 #define ACCEL19_CTRL6_BW_FILT_BIT_MASK 0xC0
179 #define ACCEL19_CTRL6_BW_FILT_ODR_2 0x00
180 #define ACCEL19_CTRL6_BW_FILT_ODR_4 0x40
181 #define ACCEL19_CTRL6_BW_FILT_ODR_10 0x80
182 #define ACCEL19_CTRL6_BW_FILT_ODR_20 0xC0
183 
188 #define ACCEL19_CTRL6_FS_BIT_MASK 0x30
189 #define ACCEL19_CTRL6_FS_2g 0x00
190 #define ACCEL19_CTRL6_FS_4g 0x10
191 #define ACCEL19_CTRL6_FS_8g 0x20
192 #define ACCEL19_CTRL6_FS_16g 0x30
193 
199 #define ACCEL19_SET_DEV_ADDR_0 0x18
200 #define ACCEL19_SET_DEV_ADDR_1 0x19
201 
210 #define ACCEL19_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
211 #define ACCEL19_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
212  // accel19_set
214 
229 #define ACCEL19_MAP_MIKROBUS( cfg, mikrobus ) \
230  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
231  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
232  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
233  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
234  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
235  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
236  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
237  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_INT )
238  // accel19_map // accel19
241 
246 typedef enum
247 {
252 
257 typedef err_t ( *accel19_master_io_t )( struct accel19_s*, uint8_t, uint8_t*, uint8_t );
263 typedef struct accel19_s
264 {
265  digital_in_t in2;
266  digital_in_t in1;
268  i2c_master_t i2c;
269  spi_master_t spi;
271  uint8_t slave_address;
272  pin_name_t chip_select;
279 
284 typedef struct
285 {
286  pin_name_t scl;
287  pin_name_t sda;
288  pin_name_t miso;
289  pin_name_t mosi;
290  pin_name_t sck;
291  pin_name_t cs;
293  pin_name_t in2;
294  pin_name_t in1;
296  uint32_t i2c_speed;
297  uint8_t i2c_address;
299  uint32_t spi_speed;
300  spi_master_mode_t spi_mode;
301  spi_master_chip_select_polarity_t cs_polarity;
305 } accel19_cfg_t;
306 
311 typedef struct
312 {
313  int16_t x;
314  int16_t y;
315  int16_t z;
316 
318 
323 typedef enum
324 {
326  ACCEL19_ERROR = -1
327 
329 
346 
362 
377 err_t accel19_init ( accel19_t *ctx, accel19_cfg_t *cfg );
378 
393 
409 err_t accel19_generic_write ( accel19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
410 
426 err_t accel19_generic_read ( accel19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
427 
442 err_t accel19_get_temperature ( accel19_t *ctx, float *temperature );
443 
458 
475 err_t accel19_set_control ( accel19_t *ctx, uint8_t odr, uint8_t op_mode, uint8_t lp_mode );
476 
491 
506 err_t accel19_get_status ( accel19_t *ctx, uint8_t *status );
507 
522 
537 err_t accel19_set_full_scale ( accel19_t *ctx, uint8_t full_scale );
538 
553 err_t accel19_set_bw_filt_odr ( accel19_t *ctx, uint8_t bw_filt_odr );
554 
570 
583 uint8_t accel19_get_int_1 ( accel19_t *ctx );
584 
597 uint8_t accel19_get_int_2 ( accel19_t *ctx );
598 
599 #ifdef __cplusplus
600 }
601 #endif
602 #endif // ACCEL19_H
603  // accel19
605 
606 // ------------------------------------------------------------------------ END
accel19_cfg_t::i2c_address
uint8_t i2c_address
Definition: accel19.h:297
accel19_cfg_t::drv_sel
accel19_drv_t drv_sel
Definition: accel19.h:303
accel19_s::in2
digital_in_t in2
Definition: accel19.h:265
accel19_drv_t
accel19_drv_t
Accel 19 Click driver selector.
Definition: accel19.h:247
accel19_set_full_scale
err_t accel19_set_full_scale(accel19_t *ctx, uint8_t full_scale)
Accel 19 set full scale function.
accel19_set_bw_filt_odr
err_t accel19_set_bw_filt_odr(accel19_t *ctx, uint8_t bw_filt_odr)
Accel 19 set digital filtering cutoff function.
accel19_axis_t
Accel 19 axis data structure.
Definition: accel19.h:312
ACCEL19_DRV_SEL_I2C
@ ACCEL19_DRV_SEL_I2C
Definition: accel19.h:249
spi_specifics.h
This file contains SPI specific macros, functions, etc.
accel19_axis_t::x
int16_t x
Definition: accel19.h:313
accel19_s::spi
spi_master_t spi
Definition: accel19.h:269
ACCEL19_DRV_SEL_SPI
@ ACCEL19_DRV_SEL_SPI
Definition: accel19.h:248
accel19_check_device_id
err_t accel19_check_device_id(accel19_t *ctx)
Accel 19 check device ID function.
accel19_cfg_t::scl
pin_name_t scl
Definition: accel19.h:286
accel19_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: accel19.h:300
accel19_cfg_t::miso
pin_name_t miso
Definition: accel19.h:288
accel19_cfg_t
Accel 19 Click configuration object.
Definition: accel19.h:285
accel19_get_int_2
uint8_t accel19_get_int_2(accel19_t *ctx)
Accel 19 get Interrupt 2 function.
accel19_cfg_t::sck
pin_name_t sck
Definition: accel19.h:290
accel19_return_value_t
accel19_return_value_t
Accel 19 Click return value data.
Definition: accel19.h:324
accel19_default_cfg
err_t accel19_default_cfg(accel19_t *ctx)
Accel 19 default configuration function.
accel19_get_status
err_t accel19_get_status(accel19_t *ctx, uint8_t *status)
Accel 19 get status function.
accel19_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: accel19.h:301
accel19_axis_t::z
int16_t z
Definition: accel19.h:315
accel19_t
struct accel19_s accel19_t
Accel 19 Click context object.
accel19_get_temperature
err_t accel19_get_temperature(accel19_t *ctx, float *temperature)
Accel 19 get temperature function.
accel19_generic_read
err_t accel19_generic_read(accel19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Accel 19 data reading function.
accel19_s::read_f
accel19_master_io_t read_f
Definition: accel19.h:276
accel19_cfg_t::in2
pin_name_t in2
Definition: accel19.h:293
accel19_cfg_t::spi_speed
uint32_t spi_speed
Definition: accel19.h:299
accel19_drv_interface_selection
void accel19_drv_interface_selection(accel19_cfg_t *cfg, accel19_drv_t drv_sel)
Accel 19 driver interface setup function.
ACCEL19_OK
@ ACCEL19_OK
Definition: accel19.h:325
accel19_cfg_t::sda
pin_name_t sda
Definition: accel19.h:287
accel19_data_ready
uint8_t accel19_data_ready(accel19_t *ctx)
Accel 19 data ready function.
accel19_init
err_t accel19_init(accel19_t *ctx, accel19_cfg_t *cfg)
Accel 19 initialization function.
accel19_cfg_setup
void accel19_cfg_setup(accel19_cfg_t *cfg)
Accel 19 configuration object setup function.
accel19_s
Accel 19 Click context object.
Definition: accel19.h:264
accel19_cfg_t::mosi
pin_name_t mosi
Definition: accel19.h:289
accel19_s::write_f
accel19_master_io_t write_f
Definition: accel19.h:275
accel19_cfg_t::in1
pin_name_t in1
Definition: accel19.h:294
accel19_master_io_t
err_t(* accel19_master_io_t)(struct accel19_s *, uint8_t, uint8_t *, uint8_t)
Accel 19 Click driver interface.
Definition: accel19.h:257
accel19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: accel19.h:296
ACCEL19_ERROR
@ ACCEL19_ERROR
Definition: accel19.h:326
accel19_set_control
err_t accel19_set_control(accel19_t *ctx, uint8_t odr, uint8_t op_mode, uint8_t lp_mode)
Accel 19 set control function.
accel19_s::slave_address
uint8_t slave_address
Definition: accel19.h:271
accel19_s::in1
digital_in_t in1
Definition: accel19.h:266
accel19_get_axis_data
err_t accel19_get_axis_data(accel19_t *ctx, accel19_axis_t *axis)
Accel 19 get accelerometer axis function.
accel19_s::drv_sel
accel19_drv_t drv_sel
Definition: accel19.h:273
accel19_get_int_1
uint8_t accel19_get_int_1(accel19_t *ctx)
Accel 19 get Interrupt 1 function.
accel19_axis_t::y
int16_t y
Definition: accel19.h:314
accel19_generic_write
err_t accel19_generic_write(accel19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Accel 19 data writing function.
accel19_soft_reset
err_t accel19_soft_reset(accel19_t *ctx)
Accel 19 soft reset function.
accel19_s::chip_select
pin_name_t chip_select
Definition: accel19.h:272
accel19_s::i2c
i2c_master_t i2c
Definition: accel19.h:268
accel19_cfg_t::cs
pin_name_t cs
Definition: accel19.h:291