Go to the documentation of this file.
35 #include "mikrosdk_version.h"
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
71 #define SMARTDOF2_REG_FUNC_CFG_ACCESS 0x01
72 #define SMARTDOF2_REG_PIN_CTRL 0x02
73 #define SMARTDOF2_REG_IF_CFG 0x03
74 #define SMARTDOF2_REG_S4S_TPH_L 0x04
75 #define SMARTDOF2_REG_S4S_TPH_H 0x05
76 #define SMARTDOF2_REG_S4S_RR 0x06
77 #define SMARTDOF2_REG_FIFO_CTRL1 0x07
78 #define SMARTDOF2_REG_FIFO_CTRL2 0x08
79 #define SMARTDOF2_REG_FIFO_CTRL3 0x09
80 #define SMARTDOF2_REG_FIFO_CTRL4 0x0A
81 #define SMARTDOF2_REG_COUNTER_BDR_REG1 0x0B
82 #define SMARTDOF2_REG_COUNTER_BDR_REG2 0x0C
83 #define SMARTDOF2_REG_INT1_CTRL 0x0D
84 #define SMARTDOF2_REG_INT2_CTRL 0x0E
85 #define SMARTDOF2_REG_WHO_AM_I 0x0F
86 #define SMARTDOF2_REG_CTRL1 0x10
87 #define SMARTDOF2_REG_CTRL2 0x11
88 #define SMARTDOF2_REG_CTRL3 0x12
89 #define SMARTDOF2_REG_CTRL4 0x13
90 #define SMARTDOF2_REG_CTRL5 0x14
91 #define SMARTDOF2_REG_CTRL6 0x15
92 #define SMARTDOF2_REG_CTRL7 0x16
93 #define SMARTDOF2_REG_CTRL8 0x17
94 #define SMARTDOF2_REG_CTRL9 0x18
95 #define SMARTDOF2_REG_CTRL10 0x19
96 #define SMARTDOF2_REG_CTRL_STATUS 0x1A
97 #define SMARTDOF2_REG_FIFO_STATUS1 0x1B
98 #define SMARTDOF2_REG_FIFO_STATUS2 0x1C
99 #define SMARTDOF2_REG_ALL_INT_SRC 0x1D
100 #define SMARTDOF2_REG_STATUS_REG 0x1E
101 #define SMARTDOF2_REG_OUT_TEMP_L 0x20
102 #define SMARTDOF2_REG_OUT_TEMP_H 0x21
103 #define SMARTDOF2_REG_OUTX_L_G 0x22
104 #define SMARTDOF2_REG_OUTX_H_G 0x23
105 #define SMARTDOF2_REG_OUTY_L_G 0x24
106 #define SMARTDOF2_REG_OUTY_H_G 0x25
107 #define SMARTDOF2_REG_OUTZ_L_G 0x26
108 #define SMARTDOF2_REG_OUTZ_H_G 0x27
109 #define SMARTDOF2_REG_OUTX_L_A 0x28
110 #define SMARTDOF2_REG_OUTX_H_A 0x29
111 #define SMARTDOF2_REG_OUTY_L_A 0x2A
112 #define SMARTDOF2_REG_OUTY_H_A 0x2B
113 #define SMARTDOF2_REG_OUTZ_L_A 0x2C
114 #define SMARTDOF2_REG_OUTZ_H_A 0x2D
115 #define SMARTDOF2_REG_UI_OUTX_L_G_OIS_EIS 0x2E
116 #define SMARTDOF2_REG_UI_OUTX_H_G_OIS_EIS 0x2F
117 #define SMARTDOF2_REG_UI_OUTY_L_G_OIS_EIS 0x30
118 #define SMARTDOF2_REG_UI_OUTY_H_G_OIS_EIS 0x31
119 #define SMARTDOF2_REG_UI_OUTZ_L_G_OIS_EIS 0x32
120 #define SMARTDOF2_REG_UI_OUTZ_H_G_OIS_EIS 0x33
121 #define SMARTDOF2_REG_UI_OUTX_L_A_OIS_DUALC 0x34
122 #define SMARTDOF2_REG_UI_OUTX_H_A_OIS_DUALC 0x35
123 #define SMARTDOF2_REG_UI_OUTY_L_A_OIS_DUALC 0x36
124 #define SMARTDOF2_REG_UI_OUTY_H_A_OIS_DUALC 0x37
125 #define SMARTDOF2_REG_UI_OUTZ_L_A_OIS_DUALC 0x38
126 #define SMARTDOF2_REG_UI_OUTZ_H_A_OIS_DUALC 0x39
127 #define SMARTDOF2_REG_AH_QVAR_OUT_L 0x3A
128 #define SMARTDOF2_REG_AH_QVAR_OUT_H 0x3B
129 #define SMARTDOF2_REG_TIMESTAMP0 0x40
130 #define SMARTDOF2_REG_TIMESTAMP1 0x41
131 #define SMARTDOF2_REG_TIMESTAMP2 0x42
132 #define SMARTDOF2_REG_TIMESTAMP3 0x43
133 #define SMARTDOF2_REG_UI_STATUS_REG_OIS 0x44
134 #define SMARTDOF2_REG_WAKE_UP_SRC 0x45
135 #define SMARTDOF2_REG_TAP_SRC 0x46
136 #define SMARTDOF2_REG_D6D_SRC 0x47
137 #define SMARTDOF2_REG_STATUS_MASTER_MAINPAGE 0x48
138 #define SMARTDOF2_REG_EMB_FUNC_STATUS_MAINPAGE 0x49
139 #define SMARTDOF2_REG_FSM_STATUS_MAINPAGE 0x4A
140 #define SMARTDOF2_REG_MLC_STATUS_MAINPAGE 0x4B
141 #define SMARTDOF2_REG_INTERNAL_FREQ 0x4F
142 #define SMARTDOF2_REG_FUNCTIONS_ENABLE 0x50
143 #define SMARTDOF2_REG_DEN 0x51
144 #define SMARTDOF2_REG_INACTIVITY_DUR 0x54
145 #define SMARTDOF2_REG_INACTIVITY_THS 0x55
146 #define SMARTDOF2_REG_TAP_CFG0 0x56
147 #define SMARTDOF2_REG_TAP_CFG1 0x57
148 #define SMARTDOF2_REG_TAP_CFG2 0x58
149 #define SMARTDOF2_REG_TAP_THS_6D 0x59
150 #define SMARTDOF2_REG_INT_DUR2 0x5A
151 #define SMARTDOF2_REG_WAKE_UP_THS 0x5B
152 #define SMARTDOF2_REG_WAKE_UP_DUR 0x5C
153 #define SMARTDOF2_REG_FREE_FALL 0x5D
154 #define SMARTDOF2_REG_MD1_CFG 0x5E
155 #define SMARTDOF2_REG_MD2_CFG 0x5F
156 #define SMARTDOF2_REG_S4S_ST_CMD_CODE 0x60
157 #define SMARTDOF2_REG_S4S_DT_REG 0x61
158 #define SMARTDOF2_REG_EMB_FUNC_CFG 0x63
159 #define SMARTDOF2_REG_UI_HANDSHAKE_CTRL 0x64
160 #define SMARTDOF2_REG_UI_SPI2_SHARED_0 0x65
161 #define SMARTDOF2_REG_UI_SPI2_SHARED_1 0x66
162 #define SMARTDOF2_REG_UI_SPI2_SHARED_2 0x67
163 #define SMARTDOF2_REG_UI_SPI2_SHARED_3 0x68
164 #define SMARTDOF2_REG_UI_SPI2_SHARED_4 0x69
165 #define SMARTDOF2_REG_UI_SPI2_SHARED_5 0x6A
166 #define SMARTDOF2_REG_CTRL_EIS 0x6B
167 #define SMARTDOF2_REG_UI_INT_OIS 0x6F
168 #define SMARTDOF2_REG_UI_CTRL1_OIS 0x70
169 #define SMARTDOF2_REG_UI_CTRL2_OIS 0x71
170 #define SMARTDOF2_REG_UI_CTRL3_OIS 0x72
171 #define SMARTDOF2_REG_X_OFS_USR 0x73
172 #define SMARTDOF2_REG_Y_OFS_USR 0x74
173 #define SMARTDOF2_REG_Z_OFS_USR 0x75
174 #define SMARTDOF2_REG_FIFO_DATA_OUT_TAG 0x78
175 #define SMARTDOF2_REG_FIFO_DATA_OUT_X_L 0x79
176 #define SMARTDOF2_REG_FIFO_DATA_OUT_X_H 0x7A
177 #define SMARTDOF2_REG_FIFO_DATA_OUT_Y_L 0x7B
178 #define SMARTDOF2_REG_FIFO_DATA_OUT_Y_H 0x7C
179 #define SMARTDOF2_REG_FIFO_DATA_OUT_Z_L 0x7D
180 #define SMARTDOF2_REG_FIFO_DATA_OUT_Z_H 0x7E
199 #define SMARTDOF2_DEVICE_ID 0x70
205 #define SMARTDOF2_IF_INC_DISABLE 0x00
206 #define SMARTDOF2_IF_INC_ENABLE 0x04
207 #define SMARTDOF2_IF_INC_BIT_MASK 0xFB
208 #define SMARTDOF2_BDU_DISABLE 0x00
209 #define SMARTDOF2_BDU_ENABLE 0x40
210 #define SMARTDOF2_BDU_BIT_MASK 0xBF
216 #define SMARTDOF2_FIFO_MODE_BYPASS 0x00
217 #define SMARTDOF2_FIFO_MODE_FIFO 0x01
218 #define SMARTDOF2_FIFO_MODE_STREAM_WTM_TO_FULL 0x02
219 #define SMARTDOF2_FIFO_MODE_STREAM_TO_FIFO 0x03
220 #define SMARTDOF2_FIFO_MODE_BYPASS_TO_STREAM 0x04
221 #define SMARTDOF2_FIFO_MODE_STREAM 0x06
222 #define SMARTDOF2_FIFO_MODE_BYPASS_TO_FIFO 0x07
223 #define SMARTDOF2_FIFO_MODE_BIT_MASK 0xF8
229 #define SMARTDOF2_ODR_OFF 0x00
230 #define SMARTDOF2_ODR_AT_1Hz875 0x01
231 #define SMARTDOF2_ODR_AT_7Hz5 0x02
232 #define SMARTDOF2_ODR_AT_15Hz 0x03
233 #define SMARTDOF2_ODR_AT_30Hz 0x04
234 #define SMARTDOF2_ODR_AT_60Hz 0x05
235 #define SMARTDOF2_ODR_AT_120Hz 0x06
236 #define SMARTDOF2_ODR_AT_240Hz 0x07
237 #define SMARTDOF2_ODR_AT_480Hz 0x08
238 #define SMARTDOF2_ODR_AT_960Hz 0x09
239 #define SMARTDOF2_ODR_AT_1920Hz 0x0A
240 #define SMARTDOF2_ODR_AT_3840Hz 0x0B
241 #define SMARTDOF2_ODR_AT_7680Hz 0x0C
242 #define SMARTDOF2_ODR_BIT_MASK 0xF0
248 #define SMARTDOF2_XL_FULL_SCALE_2g 0x00
249 #define SMARTDOF2_XL_FULL_SCALE_4g 0x01
250 #define SMARTDOF2_XL_FULL_SCALE_8g 0x02
251 #define SMARTDOF2_XL_FULL_SCALE_16g 0x03
252 #define SMARTDOF2_XL_FULL_SCALE_BIT_MASK 0xF8
258 #define SMARTDOF2_GY_FULL_SCALE_125dps 0x00
259 #define SMARTDOF2_GY_FULL_SCALE_250dps 0x01
260 #define SMARTDOF2_GY_FULL_SCALE_500dps 0x02
261 #define SMARTDOF2_GY_FULL_SCALE_1000dps 0x03
262 #define SMARTDOF2_GY_FULL_SCALE_2000dps 0x04
263 #define SMARTDOF2_GY_FULL_SCALE_4000dps 0x0C
264 #define SMARTDOF2_GY_FULL_SCALE_BIT_MASK 0xF0
270 #define SMARTDOF2_ACC_SENSITIVITY_FS_2g 0.061
271 #define SMARTDOF2_ACC_SENSITIVITY_FS_4g 0.122
272 #define SMARTDOF2_ACC_SENSITIVITY_FS_8g 0.244
273 #define SMARTDOF2_ACC_SENSITIVITY_FS_16g 0.488
279 #define SMARTDOF2_GYRO_SENSITIVITY_FS_125dps 4.375
280 #define SMARTDOF2_GYRO_SENSITIVITY_FS_250dps 8.750
281 #define SMARTDOF2_GYRO_SENSITIVITY_FS_500dps 17.500
282 #define SMARTDOF2_GYRO_SENSITIVITY_FS_1000dps 35.000
283 #define SMARTDOF2_GYRO_SENSITIVITY_FS_2000dps 70.000
284 #define SMARTDOF2_GYRO_SENSITIVITY_FS_4000dps 140.000
291 #define SMARTDOF2_DEVICE_ADDRESS_GND 0x6A
292 #define SMARTDOF2_DEVICE_ADDRESS_VCC 0x6B
302 #define SMARTDOF2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
303 #define SMARTDOF2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
321 #define SMARTDOF2_MAP_MIKROBUS( cfg, mikrobus ) \
322 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
323 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
324 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
325 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
326 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
327 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
328 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
844 #endif // SMARTDOF2_H
err_t smartdof2_default_cfg(smartdof2_t *ctx)
Smart DOF 2 default configuration function.
err_t smartdof2_get_acc_axis_data(smartdof2_t *ctx, smartdof2_axis_data_t *acc_axis)
Smart DOF 2 get accel data function.
float x
Definition: smartdof2.h:413
pin_name_t miso
Definition: smartdof2.h:378
uint8_t slave_address
Definition: smartdof2.h:361
int16_t y
Definition: smartdof2.h:402
uint8_t i2c_address
Definition: smartdof2.h:385
err_t smartdof2_enable_block_data_update(smartdof2_t *ctx)
Smart DOF 2 enable block data update function.
uint8_t smartdof2_get_int_pin(smartdof2_t *ctx)
Smart DOF 2 get interrupt function.
digital_in_t int_pin
Definition: smartdof2.h:356
Smart DOF 2 Click axis raw data structure object.
Definition: smartdof2.h:400
@ SMARTDOF2_DRV_SEL_SPI
Definition: smartdof2.h:339
This file contains SPI specific macros, functions, etc.
spi_master_mode_t spi_mode
Definition: smartdof2.h:388
i2c_master_t i2c
Definition: smartdof2.h:358
void smartdof2_cfg_setup(smartdof2_cfg_t *cfg)
Smart DOF 2 configuration object setup 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_axis(smartdof2_t *ctx, smartdof2_axis_t *acc_axis)
Smart DOF 2 get accel sensor axes function.
err_t smartdof2_get_temperature_raw(smartdof2_t *ctx, int16_t *temp_raw)
Smart DOF 2 get temperature data function.
@ SMARTDOF2_DRV_SEL_I2C
Definition: smartdof2.h:340
float y
Definition: smartdof2.h:414
smartdof2_drv_t
Smart DOF 2 Click driver selector.
Definition: smartdof2.h:338
pin_name_t sck
Definition: smartdof2.h:380
Smart DOF 2 Click configuration object.
Definition: smartdof2.h:375
err_t smartdof2_init(smartdof2_t *ctx, smartdof2_cfg_t *cfg)
Smart DOF 2 initialization function.
err_t smartdof2_get_gyro_full_scale(smartdof2_t *ctx, uint8_t *data_scale)
Smart DOF 2 get full-scale gyro range 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_generic_write(smartdof2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Smart DOF 2 data writing function.
smartdof2_master_io_t write_f
Definition: smartdof2.h:365
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_enable_auto_increment(smartdof2_t *ctx)
Smart DOF 2 enable auto increment function.
int16_t x
Definition: smartdof2.h:401
smartdof2_drv_t drv_sel
Definition: smartdof2.h:391
err_t smartdof2_get_acc_sensitivity(smartdof2_t *ctx, float *sensitivity)
Smart DOF 2 get accel sensitivity function.
pin_name_t sda
Definition: smartdof2.h:377
err_t smartdof2_get_temperature(smartdof2_t *ctx, float *temperature)
Smart DOF 2 get temperature function.
spi_master_chip_select_polarity_t cs_polarity
Definition: smartdof2.h:389
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_master_io_t)(struct smartdof2_s *, uint8_t, uint8_t *, uint8_t)
Smart DOF 2 Click driver interface.
Definition: smartdof2.h:348
Smart DOF 2 Click context object.
Definition: smartdof2.h:355
@ SMARTDOF2_OK
Definition: smartdof2.h:425
@ SMARTDOF2_ERROR
Definition: smartdof2.h:426
struct smartdof2_s smartdof2_t
Smart DOF 2 Click context object.
err_t smartdof2_set_gyro_data_rate(smartdof2_t *ctx, uint8_t data_rate)
Smart DOF 2 set gyro data rate function.
Smart DOF 2 Click sensor axes structure object.
Definition: smartdof2.h:412
err_t smartdof2_get_device_id(smartdof2_t *ctx, uint8_t *device_id)
Smart DOF 2 get device ID 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_set_acc_full_scale(smartdof2_t *ctx, uint8_t data_scale)
Smart DOF 2 set full-scale accel range function.
pin_name_t int_pin
Definition: smartdof2.h:382
smartdof2_master_io_t read_f
Definition: smartdof2.h:366
pin_name_t mosi
Definition: smartdof2.h:379
err_t smartdof2_set_fifo_mode(smartdof2_t *ctx, uint8_t fifo_mode)
Smart DOF 2 set FIFO mode 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_gyro_sensitivity(smartdof2_t *ctx, float *sensitivity)
Smart DOF 2 get gyro sensitivity function.
uint32_t i2c_speed
Definition: smartdof2.h:384
smartdof2_return_value_t
Smart DOF 2 Click return value data.
Definition: smartdof2.h:424
int16_t z
Definition: smartdof2.h:403
pin_name_t cs
Definition: smartdof2.h:381
pin_name_t scl
Definition: smartdof2.h:376
uint32_t spi_speed
Definition: smartdof2.h:387
spi_master_t spi
Definition: smartdof2.h:359
pin_name_t chip_select
Definition: smartdof2.h:362
float z
Definition: smartdof2.h:415
err_t smartdof2_set_acc_data_rate(smartdof2_t *ctx, uint8_t data_rate)
Smart DOF 2 set accel data rate function.
smartdof2_drv_t drv_sel
Definition: smartdof2.h:363