smartdof2 2.1.0.0
smartdof2.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 SMARTDOF2_H
29#define SMARTDOF2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define SMARTDOF2_REG_FUNC_CFG_ACCESS 0x01
76#define SMARTDOF2_REG_PIN_CTRL 0x02
77#define SMARTDOF2_REG_IF_CFG 0x03
78#define SMARTDOF2_REG_S4S_TPH_L 0x04
79#define SMARTDOF2_REG_S4S_TPH_H 0x05
80#define SMARTDOF2_REG_S4S_RR 0x06
81#define SMARTDOF2_REG_FIFO_CTRL1 0x07
82#define SMARTDOF2_REG_FIFO_CTRL2 0x08
83#define SMARTDOF2_REG_FIFO_CTRL3 0x09
84#define SMARTDOF2_REG_FIFO_CTRL4 0x0A
85#define SMARTDOF2_REG_COUNTER_BDR_REG1 0x0B
86#define SMARTDOF2_REG_COUNTER_BDR_REG2 0x0C
87#define SMARTDOF2_REG_INT1_CTRL 0x0D
88#define SMARTDOF2_REG_INT2_CTRL 0x0E
89#define SMARTDOF2_REG_WHO_AM_I 0x0F
90#define SMARTDOF2_REG_CTRL1 0x10
91#define SMARTDOF2_REG_CTRL2 0x11
92#define SMARTDOF2_REG_CTRL3 0x12
93#define SMARTDOF2_REG_CTRL4 0x13
94#define SMARTDOF2_REG_CTRL5 0x14
95#define SMARTDOF2_REG_CTRL6 0x15
96#define SMARTDOF2_REG_CTRL7 0x16
97#define SMARTDOF2_REG_CTRL8 0x17
98#define SMARTDOF2_REG_CTRL9 0x18
99#define SMARTDOF2_REG_CTRL10 0x19
100#define SMARTDOF2_REG_CTRL_STATUS 0x1A
101#define SMARTDOF2_REG_FIFO_STATUS1 0x1B
102#define SMARTDOF2_REG_FIFO_STATUS2 0x1C
103#define SMARTDOF2_REG_ALL_INT_SRC 0x1D
104#define SMARTDOF2_REG_STATUS_REG 0x1E
105#define SMARTDOF2_REG_OUT_TEMP_L 0x20
106#define SMARTDOF2_REG_OUT_TEMP_H 0x21
107#define SMARTDOF2_REG_OUTX_L_G 0x22
108#define SMARTDOF2_REG_OUTX_H_G 0x23
109#define SMARTDOF2_REG_OUTY_L_G 0x24
110#define SMARTDOF2_REG_OUTY_H_G 0x25
111#define SMARTDOF2_REG_OUTZ_L_G 0x26
112#define SMARTDOF2_REG_OUTZ_H_G 0x27
113#define SMARTDOF2_REG_OUTX_L_A 0x28
114#define SMARTDOF2_REG_OUTX_H_A 0x29
115#define SMARTDOF2_REG_OUTY_L_A 0x2A
116#define SMARTDOF2_REG_OUTY_H_A 0x2B
117#define SMARTDOF2_REG_OUTZ_L_A 0x2C
118#define SMARTDOF2_REG_OUTZ_H_A 0x2D
119#define SMARTDOF2_REG_UI_OUTX_L_G_OIS_EIS 0x2E
120#define SMARTDOF2_REG_UI_OUTX_H_G_OIS_EIS 0x2F
121#define SMARTDOF2_REG_UI_OUTY_L_G_OIS_EIS 0x30
122#define SMARTDOF2_REG_UI_OUTY_H_G_OIS_EIS 0x31
123#define SMARTDOF2_REG_UI_OUTZ_L_G_OIS_EIS 0x32
124#define SMARTDOF2_REG_UI_OUTZ_H_G_OIS_EIS 0x33
125#define SMARTDOF2_REG_UI_OUTX_L_A_OIS_DUALC 0x34
126#define SMARTDOF2_REG_UI_OUTX_H_A_OIS_DUALC 0x35
127#define SMARTDOF2_REG_UI_OUTY_L_A_OIS_DUALC 0x36
128#define SMARTDOF2_REG_UI_OUTY_H_A_OIS_DUALC 0x37
129#define SMARTDOF2_REG_UI_OUTZ_L_A_OIS_DUALC 0x38
130#define SMARTDOF2_REG_UI_OUTZ_H_A_OIS_DUALC 0x39
131#define SMARTDOF2_REG_AH_QVAR_OUT_L 0x3A
132#define SMARTDOF2_REG_AH_QVAR_OUT_H 0x3B
133#define SMARTDOF2_REG_TIMESTAMP0 0x40
134#define SMARTDOF2_REG_TIMESTAMP1 0x41
135#define SMARTDOF2_REG_TIMESTAMP2 0x42
136#define SMARTDOF2_REG_TIMESTAMP3 0x43
137#define SMARTDOF2_REG_UI_STATUS_REG_OIS 0x44
138#define SMARTDOF2_REG_WAKE_UP_SRC 0x45
139#define SMARTDOF2_REG_TAP_SRC 0x46
140#define SMARTDOF2_REG_D6D_SRC 0x47
141#define SMARTDOF2_REG_STATUS_MASTER_MAINPAGE 0x48
142#define SMARTDOF2_REG_EMB_FUNC_STATUS_MAINPAGE 0x49
143#define SMARTDOF2_REG_FSM_STATUS_MAINPAGE 0x4A
144#define SMARTDOF2_REG_MLC_STATUS_MAINPAGE 0x4B
145#define SMARTDOF2_REG_INTERNAL_FREQ 0x4F
146#define SMARTDOF2_REG_FUNCTIONS_ENABLE 0x50
147#define SMARTDOF2_REG_DEN 0x51
148#define SMARTDOF2_REG_INACTIVITY_DUR 0x54
149#define SMARTDOF2_REG_INACTIVITY_THS 0x55
150#define SMARTDOF2_REG_TAP_CFG0 0x56
151#define SMARTDOF2_REG_TAP_CFG1 0x57
152#define SMARTDOF2_REG_TAP_CFG2 0x58
153#define SMARTDOF2_REG_TAP_THS_6D 0x59
154#define SMARTDOF2_REG_INT_DUR2 0x5A
155#define SMARTDOF2_REG_WAKE_UP_THS 0x5B
156#define SMARTDOF2_REG_WAKE_UP_DUR 0x5C
157#define SMARTDOF2_REG_FREE_FALL 0x5D
158#define SMARTDOF2_REG_MD1_CFG 0x5E
159#define SMARTDOF2_REG_MD2_CFG 0x5F
160#define SMARTDOF2_REG_S4S_ST_CMD_CODE 0x60
161#define SMARTDOF2_REG_S4S_DT_REG 0x61
162#define SMARTDOF2_REG_EMB_FUNC_CFG 0x63
163#define SMARTDOF2_REG_UI_HANDSHAKE_CTRL 0x64
164#define SMARTDOF2_REG_UI_SPI2_SHARED_0 0x65
165#define SMARTDOF2_REG_UI_SPI2_SHARED_1 0x66
166#define SMARTDOF2_REG_UI_SPI2_SHARED_2 0x67
167#define SMARTDOF2_REG_UI_SPI2_SHARED_3 0x68
168#define SMARTDOF2_REG_UI_SPI2_SHARED_4 0x69
169#define SMARTDOF2_REG_UI_SPI2_SHARED_5 0x6A
170#define SMARTDOF2_REG_CTRL_EIS 0x6B
171#define SMARTDOF2_REG_UI_INT_OIS 0x6F
172#define SMARTDOF2_REG_UI_CTRL1_OIS 0x70
173#define SMARTDOF2_REG_UI_CTRL2_OIS 0x71
174#define SMARTDOF2_REG_UI_CTRL3_OIS 0x72
175#define SMARTDOF2_REG_X_OFS_USR 0x73
176#define SMARTDOF2_REG_Y_OFS_USR 0x74
177#define SMARTDOF2_REG_Z_OFS_USR 0x75
178#define SMARTDOF2_REG_FIFO_DATA_OUT_TAG 0x78
179#define SMARTDOF2_REG_FIFO_DATA_OUT_X_L 0x79
180#define SMARTDOF2_REG_FIFO_DATA_OUT_X_H 0x7A
181#define SMARTDOF2_REG_FIFO_DATA_OUT_Y_L 0x7B
182#define SMARTDOF2_REG_FIFO_DATA_OUT_Y_H 0x7C
183#define SMARTDOF2_REG_FIFO_DATA_OUT_Z_L 0x7D
184#define SMARTDOF2_REG_FIFO_DATA_OUT_Z_H 0x7E
185
186
187 // smartdof2_reg
188
203#define SMARTDOF2_DEVICE_ID 0x70
204
209#define SMARTDOF2_IF_INC_DISABLE 0x00
210#define SMARTDOF2_IF_INC_ENABLE 0x04
211#define SMARTDOF2_IF_INC_BIT_MASK 0xFB
212#define SMARTDOF2_BDU_DISABLE 0x00
213#define SMARTDOF2_BDU_ENABLE 0x40
214#define SMARTDOF2_BDU_BIT_MASK 0xBF
215
220#define SMARTDOF2_FIFO_MODE_BYPASS 0x00
221#define SMARTDOF2_FIFO_MODE_FIFO 0x01
222#define SMARTDOF2_FIFO_MODE_STREAM_WTM_TO_FULL 0x02
223#define SMARTDOF2_FIFO_MODE_STREAM_TO_FIFO 0x03
224#define SMARTDOF2_FIFO_MODE_BYPASS_TO_STREAM 0x04
225#define SMARTDOF2_FIFO_MODE_STREAM 0x06
226#define SMARTDOF2_FIFO_MODE_BYPASS_TO_FIFO 0x07
227#define SMARTDOF2_FIFO_MODE_BIT_MASK 0xF8
228
233#define SMARTDOF2_ODR_OFF 0x00
234#define SMARTDOF2_ODR_AT_1Hz875 0x01
235#define SMARTDOF2_ODR_AT_7Hz5 0x02
236#define SMARTDOF2_ODR_AT_15Hz 0x03
237#define SMARTDOF2_ODR_AT_30Hz 0x04
238#define SMARTDOF2_ODR_AT_60Hz 0x05
239#define SMARTDOF2_ODR_AT_120Hz 0x06
240#define SMARTDOF2_ODR_AT_240Hz 0x07
241#define SMARTDOF2_ODR_AT_480Hz 0x08
242#define SMARTDOF2_ODR_AT_960Hz 0x09
243#define SMARTDOF2_ODR_AT_1920Hz 0x0A
244#define SMARTDOF2_ODR_AT_3840Hz 0x0B
245#define SMARTDOF2_ODR_AT_7680Hz 0x0C
246#define SMARTDOF2_ODR_BIT_MASK 0xF0
247
252#define SMARTDOF2_XL_FULL_SCALE_2g 0x00
253#define SMARTDOF2_XL_FULL_SCALE_4g 0x01
254#define SMARTDOF2_XL_FULL_SCALE_8g 0x02
255#define SMARTDOF2_XL_FULL_SCALE_16g 0x03
256#define SMARTDOF2_XL_FULL_SCALE_BIT_MASK 0xF8
257
262#define SMARTDOF2_GY_FULL_SCALE_125dps 0x00
263#define SMARTDOF2_GY_FULL_SCALE_250dps 0x01
264#define SMARTDOF2_GY_FULL_SCALE_500dps 0x02
265#define SMARTDOF2_GY_FULL_SCALE_1000dps 0x03
266#define SMARTDOF2_GY_FULL_SCALE_2000dps 0x04
267#define SMARTDOF2_GY_FULL_SCALE_4000dps 0x0C
268#define SMARTDOF2_GY_FULL_SCALE_BIT_MASK 0xF0
269
274#define SMARTDOF2_ACC_SENSITIVITY_FS_2g 0.061
275#define SMARTDOF2_ACC_SENSITIVITY_FS_4g 0.122
276#define SMARTDOF2_ACC_SENSITIVITY_FS_8g 0.244
277#define SMARTDOF2_ACC_SENSITIVITY_FS_16g 0.488
278
283#define SMARTDOF2_GYRO_SENSITIVITY_FS_125dps 4.375
284#define SMARTDOF2_GYRO_SENSITIVITY_FS_250dps 8.750
285#define SMARTDOF2_GYRO_SENSITIVITY_FS_500dps 17.500
286#define SMARTDOF2_GYRO_SENSITIVITY_FS_1000dps 35.000
287#define SMARTDOF2_GYRO_SENSITIVITY_FS_2000dps 70.000
288#define SMARTDOF2_GYRO_SENSITIVITY_FS_4000dps 140.000
289
295#define SMARTDOF2_DEVICE_ADDRESS_GND 0x6A
296#define SMARTDOF2_DEVICE_ADDRESS_VCC 0x6B
297
306#define SMARTDOF2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
307#define SMARTDOF2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
308
309 // smartdof2_set
310
325#define SMARTDOF2_MAP_MIKROBUS( cfg, mikrobus ) \
326 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
327 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
328 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
329 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
330 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
331 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
332 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
333
334 // smartdof2_map
335 // smartdof2
336
347
352typedef err_t ( *smartdof2_master_io_t )( struct smartdof2_s*, uint8_t, uint8_t*, uint8_t );
373
378typedef struct
379{
380 pin_name_t scl;
381 pin_name_t sda;
382 pin_name_t miso;
383 pin_name_t mosi;
384 pin_name_t sck;
385 pin_name_t cs;
386 pin_name_t int_pin;
388 uint32_t i2c_speed;
389 uint8_t i2c_address;
391 uint32_t spi_speed;
392 spi_master_mode_t spi_mode;
393 spi_master_chip_select_polarity_t cs_polarity;
398
403typedef struct
404{
405 int16_t x;
406 int16_t y;
407 int16_t z;
408
410
415typedef struct
416{
417 float x;
418 float y;
419 float z;
420
422
433
450
466
481
495
510err_t smartdof2_generic_write ( smartdof2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
511
526err_t smartdof2_generic_read ( smartdof2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
527
541err_t smartdof2_get_device_id ( smartdof2_t *ctx, uint8_t *device_id );
542
557
572
593err_t smartdof2_set_fifo_mode ( smartdof2_t *ctx, uint8_t fifo_mode );
594
621err_t smartdof2_set_acc_data_rate ( smartdof2_t *ctx, uint8_t data_rate );
622
636err_t smartdof2_get_acc_full_scale ( smartdof2_t *ctx, uint8_t *data_scale );
637
655err_t smartdof2_set_acc_full_scale ( smartdof2_t *ctx, uint8_t data_scale );
656
674err_t smartdof2_set_gyro_data_rate ( smartdof2_t *ctx, uint8_t data_rate );
675
689err_t smartdof2_get_gyro_full_scale ( smartdof2_t *ctx, uint8_t *data_scale );
690
708err_t smartdof2_set_gyro_full_scale ( smartdof2_t *ctx, uint8_t data_scale );
709
724
739
753err_t smartdof2_get_acc_sensitivity ( smartdof2_t *ctx, float *sensitivity );
754
768err_t smartdof2_get_gyro_sensitivity ( smartdof2_t *ctx, float *sensitivity );
769
784
799
813err_t smartdof2_get_temperature_raw ( smartdof2_t *ctx, int16_t *temp_raw );
814
829err_t smartdof2_get_temperature ( smartdof2_t *ctx, float *temperature );
830
844
845#ifdef __cplusplus
846}
847#endif
848#endif // SMARTDOF2_H
849
850 // smartdof2
851
852// ------------------------------------------------------------------------ END
err_t smartdof2_init(smartdof2_t *ctx, smartdof2_cfg_t *cfg)
Smart DOF 2 initialization function.
err_t smartdof2_set_gyro_full_scale(smartdof2_t *ctx, uint8_t data_scale)
Smart DOF 2 set full-scale gyro range function.
err_t smartdof2_get_temperature_raw(smartdof2_t *ctx, int16_t *temp_raw)
Smart DOF 2 get temperature data function.
uint8_t smartdof2_get_int_pin(smartdof2_t *ctx)
Smart DOF 2 get interrupt function.
err_t smartdof2_set_fifo_mode(smartdof2_t *ctx, uint8_t fifo_mode)
Smart DOF 2 set FIFO mode function.
err_t smartdof2_generic_write(smartdof2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Smart DOF 2 data writing function.
err_t smartdof2_get_temperature(smartdof2_t *ctx, float *temperature)
Smart DOF 2 get temperature function.
err_t smartdof2_get_acc_full_scale(smartdof2_t *ctx, uint8_t *data_scale)
Smart DOF 2 get full-scale accel range function.
err_t smartdof2_enable_block_data_update(smartdof2_t *ctx)
Smart DOF 2 enable block data update function.
err_t smartdof2_get_gyro_sensitivity(smartdof2_t *ctx, float *sensitivity)
Smart DOF 2 get gyro sensitivity function.
err_t smartdof2_generic_read(smartdof2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Smart DOF 2 data reading function.
err_t smartdof2_get_device_id(smartdof2_t *ctx, uint8_t *device_id)
Smart DOF 2 get device ID function.
err_t smartdof2_set_acc_data_rate(smartdof2_t *ctx, uint8_t data_rate)
Smart DOF 2 set accel data rate function.
err_t smartdof2_set_gyro_data_rate(smartdof2_t *ctx, uint8_t data_rate)
Smart DOF 2 set gyro data rate function.
err_t smartdof2_set_acc_full_scale(smartdof2_t *ctx, uint8_t data_scale)
Smart DOF 2 set full-scale accel range function.
err_t smartdof2_default_cfg(smartdof2_t *ctx)
Smart DOF 2 default configuration function.
void smartdof2_cfg_setup(smartdof2_cfg_t *cfg)
Smart DOF 2 configuration object setup function.
err_t smartdof2_get_gyro_full_scale(smartdof2_t *ctx, uint8_t *data_scale)
Smart DOF 2 get full-scale gyro range function.
err_t smartdof2_get_gyro_axis(smartdof2_t *ctx, smartdof2_axis_t *gyro_axis)
Smart DOF 2 get gyro sensor axes function.
err_t smartdof2_get_acc_sensitivity(smartdof2_t *ctx, float *sensitivity)
Smart DOF 2 get accel sensitivity function.
void smartdof2_drv_interface_selection(smartdof2_cfg_t *cfg, smartdof2_drv_t drv_sel)
Smart DOF 2 driver interface setup function.
err_t smartdof2_get_acc_axis(smartdof2_t *ctx, smartdof2_axis_t *acc_axis)
Smart DOF 2 get accel sensor axes function.
err_t smartdof2_get_gyro_axis_data(smartdof2_t *ctx, smartdof2_axis_data_t *gyro_axis)
Smart DOF 2 get gyro data function.
err_t smartdof2_get_acc_axis_data(smartdof2_t *ctx, smartdof2_axis_data_t *acc_axis)
Smart DOF 2 get accel data function.
err_t smartdof2_enable_auto_increment(smartdof2_t *ctx)
Smart DOF 2 enable auto increment function.
err_t(* smartdof2_master_io_t)(struct smartdof2_s *, uint8_t, uint8_t *, uint8_t)
Smart DOF 2 Click driver interface.
Definition smartdof2.h:352
smartdof2_drv_t
Smart DOF 2 Click driver selector.
Definition smartdof2.h:342
@ SMARTDOF2_DRV_SEL_SPI
Definition smartdof2.h:343
@ SMARTDOF2_DRV_SEL_I2C
Definition smartdof2.h:344
struct smartdof2_s smartdof2_t
Smart DOF 2 Click context object.
smartdof2_return_value_t
Smart DOF 2 Click return value data.
Definition smartdof2.h:428
@ SMARTDOF2_ERROR
Definition smartdof2.h:430
@ SMARTDOF2_OK
Definition smartdof2.h:429
This file contains SPI specific macros, functions, etc.
Smart DOF 2 Click axis raw data structure object.
Definition smartdof2.h:404
int16_t z
Definition smartdof2.h:407
int16_t x
Definition smartdof2.h:405
int16_t y
Definition smartdof2.h:406
Smart DOF 2 Click sensor axes structure object.
Definition smartdof2.h:416
float y
Definition smartdof2.h:418
float x
Definition smartdof2.h:417
float z
Definition smartdof2.h:419
Smart DOF 2 Click configuration object.
Definition smartdof2.h:379
uint32_t i2c_speed
Definition smartdof2.h:388
spi_master_chip_select_polarity_t cs_polarity
Definition smartdof2.h:393
pin_name_t sck
Definition smartdof2.h:384
spi_master_mode_t spi_mode
Definition smartdof2.h:392
pin_name_t mosi
Definition smartdof2.h:383
uint32_t spi_speed
Definition smartdof2.h:391
pin_name_t scl
Definition smartdof2.h:380
pin_name_t int_pin
Definition smartdof2.h:386
pin_name_t miso
Definition smartdof2.h:382
smartdof2_drv_t drv_sel
Definition smartdof2.h:395
pin_name_t sda
Definition smartdof2.h:381
pin_name_t cs
Definition smartdof2.h:385
uint8_t i2c_address
Definition smartdof2.h:389
Smart DOF 2 Click context object.
Definition smartdof2.h:359
spi_master_t spi
Definition smartdof2.h:363
smartdof2_master_io_t write_f
Definition smartdof2.h:369
smartdof2_master_io_t read_f
Definition smartdof2.h:370
digital_in_t int_pin
Definition smartdof2.h:360
i2c_master_t i2c
Definition smartdof2.h:362
uint8_t slave_address
Definition smartdof2.h:365
smartdof2_drv_t drv_sel
Definition smartdof2.h:367
pin_name_t chip_select
Definition smartdof2.h:366