smartdof3  2.1.0.0
smartdof3.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 SMARTDOF3_H
29 #define SMARTDOF3_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 SMARTDOF3_REG_FUNC_CFG_ACCESS 0x01
62 #define SMARTDOF3_REG_PIN_CTRL 0x02
63 #define SMARTDOF3_REG_DRDY_PULSED_REG 0x0B
64 #define SMARTDOF3_REG_INT1_CTRL 0x0D
65 #define SMARTDOF3_REG_INT2_CTRL 0x0E
66 #define SMARTDOF3_REG_WHO_AM_I 0x0F
67 #define SMARTDOF3_REG_CTRL1_XL 0x10
68 #define SMARTDOF3_REG_CTRL2_G 0x11
69 #define SMARTDOF3_REG_CTRL3_C 0x12
70 #define SMARTDOF3_REG_CTRL4_C 0x13
71 #define SMARTDOF3_REG_CTRL5_C 0x14
72 #define SMARTDOF3_REG_CTRL6_C 0x15
73 #define SMARTDOF3_REG_CTRL7_G 0x16
74 #define SMARTDOF3_REG_CTRL9_C 0x18
75 #define SMARTDOF3_REG_CTRL10_C 0x19
76 #define SMARTDOF3_REG_ISPU_INT_STATUS0_MP 0x1A
77 #define SMARTDOF3_REG_ISPU_INT_STATUS1_MP 0x1B
78 #define SMARTDOF3_REG_ISPU_INT_STATUS2_MP 0x1C
79 #define SMARTDOF3_REG_ISPU_INT_STATUS3_MP 0x1D
80 #define SMARTDOF3_REG_STATUS 0x1E
81 #define SMARTDOF3_REG_OUT_TEMP_L 0x20
82 #define SMARTDOF3_REG_OUT_TEMP_H 0x21
83 #define SMARTDOF3_REG_OUTX_L_G 0x22
84 #define SMARTDOF3_REG_OUTX_H_G 0x23
85 #define SMARTDOF3_REG_OUTY_L_G 0x24
86 #define SMARTDOF3_REG_OUTY_H_G 0x25
87 #define SMARTDOF3_REG_OUTZ_L_G 0x26
88 #define SMARTDOF3_REG_OUTZ_H_G 0x27
89 #define SMARTDOF3_REG_OUTX_L_A 0x28
90 #define SMARTDOF3_REG_OUTX_H_A 0x29
91 #define SMARTDOF3_REG_OUTY_L_A 0x2A
92 #define SMARTDOF3_REG_OUTY_H_A 0x2B
93 #define SMARTDOF3_REG_OUTZ_L_A 0x2C
94 #define SMARTDOF3_REG_OUTZ_H_A 0x2D
95 #define SMARTDOF3_REG_STATUS_MASTER_MAINPAGE 0x39
96 #define SMARTDOF3_REG_TIMESTAMP0 0x40
97 #define SMARTDOF3_REG_TIMESTAMP1 0x41
98 #define SMARTDOF3_REG_TIMESTAMP2 0x42
99 #define SMARTDOF3_REG_TIMESTAMP3 0x43
100 #define SMARTDOF3_REG_MD1_CFG 0x5E
101 #define SMARTDOF3_REG_MD2_CFG 0x5F
102 #define SMARTDOF3_REG_INTERNAL_FREQ_FINE 0x63
103 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_1_L 0x73
104 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_1_H 0x74
105 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_2_L 0x75
106 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_2_H 0x76
107 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_3_L 0x77
108 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_3_H 0x78
109 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_4_L 0x79
110 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_4_H 0x7A
111  // smartdof3_reg
113 
128 #define SMARTDOF3_DEVICE_ID 0x22
129 
134 #define SMARTDOF3_SOFT_RESET 0x01
135 #define SMARTDOF3_IF_INC_DISABLE 0x00
136 #define SMARTDOF3_IF_INC_ENABLE 0x04
137 #define SMARTDOF3_IF_INC_BIT_MASK 0xFB
138 #define SMARTDOF3_BDU_DISABLE 0x00
139 #define SMARTDOF3_BDU_ENABLE 0x40
140 #define SMARTDOF3_BDU_BIT_MASK 0xBF
141 
146 #define SMARTDOF3_ODR_XL_G_OFF 0x00
147 #define SMARTDOF3_ODR_XL_G_12_5_HZ 0x01
148 #define SMARTDOF3_ODR_XL_G_26_HZ 0x02
149 #define SMARTDOF3_ODR_XL_G_52_HZ 0x03
150 #define SMARTDOF3_ODR_XL_G_104_HZ 0x04
151 #define SMARTDOF3_ODR_XL_G_208_HZ 0x05
152 #define SMARTDOF3_ODR_XL_G_416_HZ 0x06
153 #define SMARTDOF3_ODR_XL_G_833_HZ 0x07
154 #define SMARTDOF3_ODR_XL_G_1667_HZ 0x08
155 #define SMARTDOF3_ODR_XL_G_3333_HZ 0x09
156 #define SMARTDOF3_ODR_XL_G_6667_HZ 0x0A
157 #define SMARTDOF3_ODR_XL_G_BIT_MASK 0x0F
158 
163 #define SMARTDOF3_XL_FULL_SCALE_2g 0x00
164 #define SMARTDOF3_XL_FULL_SCALE_16g 0x01
165 #define SMARTDOF3_XL_FULL_SCALE_4g 0x02
166 #define SMARTDOF3_XL_FULL_SCALE_8g 0x03
167 #define SMARTDOF3_XL_FULL_SCALE_BIT_MASK 0x03
168 
173 #define SMARTDOF3_OP_MODE_PERFORMANCE_LOW 0x00
174 #define SMARTDOF3_OP_MODE_PERFORMANCE_HIGH 0x01
175 
180 #define SMARTDOF3_TIMESTAMP_ENABLE 0x20
181 
186 #define SMARTDOF3_ACC_SENSITIVITY_FS_2g 0.061
187 #define SMARTDOF3_ACC_SENSITIVITY_FS_4g 0.122
188 #define SMARTDOF3_ACC_SENSITIVITY_FS_8g 0.244
189 #define SMARTDOF3_ACC_SENSITIVITY_FS_16g 0.488
190 
195 #define SMARTDOF3_GY_FULL_SCALE_125dps 0x01
196 #define SMARTDOF3_GY_FULL_SCALE_250dps 0x00
197 #define SMARTDOF3_GY_FULL_SCALE_500dps 0x02
198 #define SMARTDOF3_GY_FULL_SCALE_1000dps 0x04
199 #define SMARTDOF3_GY_FULL_SCALE_2000dps 0x06
200 #define SMARTDOF3_GY_FULL_SCALE_BIT_MASK 0x07
201 
206 #define SMARTDOF3_GYRO_SENSITIVITY_FS_125dps 0.004375
207 #define SMARTDOF3_GYRO_SENSITIVITY_FS_250dps 0.00875
208 #define SMARTDOF3_GYRO_SENSITIVITY_FS_500dps 0.0175
209 #define SMARTDOF3_GYRO_SENSITIVITY_FS_1000dps 0.035
210 #define SMARTDOF3_GYRO_SENSITIVITY_FS_2000dps 0.07
211 
217 #define SMARTDOF3_DEVICE_ADDRESS_GND 0x6A
218 #define SMARTDOF3_DEVICE_ADDRESS_VCC 0x6B
219 
228 #define SMARTDOF3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
229 #define SMARTDOF3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
230  // smartdof3_set
232 
247 #define SMARTDOF3_MAP_MIKROBUS( cfg, mikrobus ) \
248  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
249  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
250  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
251  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
252  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
253  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
254  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
255  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_INT )
256  // smartdof3_map // smartdof3
259 
264 typedef enum
265 {
270 
275 typedef err_t ( *smartdof3_master_io_t )( struct smartdof3_s*, uint8_t, uint8_t*, uint8_t );
281 typedef struct smartdof3_s
282 {
283  digital_in_t it2;
284  digital_in_t it1;
286  i2c_master_t i2c;
287  spi_master_t spi;
289  uint8_t slave_address;
290  pin_name_t chip_select;
297 
302 typedef struct
303 {
304  pin_name_t scl;
305  pin_name_t sda;
306  pin_name_t miso;
307  pin_name_t mosi;
308  pin_name_t sck;
309  pin_name_t cs;
310  pin_name_t it2;
311  pin_name_t it1;
313  uint32_t i2c_speed;
314  uint8_t i2c_address;
316  uint32_t spi_speed;
317  spi_master_mode_t spi_mode;
318  spi_master_chip_select_polarity_t cs_polarity;
323 
328 typedef struct
329 {
330  uint8_t tda;
331  uint8_t gda;
332  uint8_t xlda;
335 
340 typedef struct
341 {
342  int16_t x;
343  int16_t y;
344  int16_t z;
347 
352 typedef struct
353 {
354  float x;
355  float y;
356  float z;
359 
364 typedef enum
365 {
367  SMARTDOF3_ERROR = -1
368 
370 
387 
403 
418 
432 
447 err_t smartdof3_generic_write ( smartdof3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
448 
463 err_t smartdof3_generic_read ( smartdof3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
464 
478 err_t smartdof3_get_device_id ( smartdof3_t *ctx, uint8_t *device_id );
479 
493 
508 
523 
538 err_t smartdof3_set_op_mode ( smartdof3_t *ctx, uint8_t acc_op_mode, uint8_t gyro_op_mode );
539 
564 err_t smartdof3_set_acc_data_rate ( smartdof3_t *ctx, uint8_t data_rate );
565 
583 err_t smartdof3_set_acc_full_scale ( smartdof3_t *ctx, uint8_t data_scale );
584 
598 err_t smartdof3_get_acc_full_scale ( smartdof3_t *ctx, uint8_t *data_scale );
599 
613 err_t smartdof3_get_acc_sensitivity ( smartdof3_t *ctx, float *sensitivity );
614 
639 err_t smartdof3_set_gyro_data_rate ( smartdof3_t *ctx, uint8_t data_rate );
640 
659 err_t smartdof3_set_gyro_full_scale ( smartdof3_t *ctx, uint8_t data_scale );
660 
674 err_t smartdof3_get_gyro_full_scale ( smartdof3_t *ctx, uint8_t *data_scale );
675 
690 
705 err_t smartdof3_get_gyro_sensitivity ( smartdof3_t *ctx, float *sensitivity );
706 
722 
738 
754 
770 
784 
798 err_t smartdof3_get_temperature_raw ( smartdof3_t *ctx, int16_t *temp_raw );
799 
813 err_t smartdof3_get_temperature ( smartdof3_t *ctx, float *temperature );
814 
827 
840 
841 #ifdef __cplusplus
842 }
843 #endif
844 #endif // SMARTDOF3_H
845  // smartdof3
847 
848 // ------------------------------------------------------------------------ END
smartdof3_s::it1
digital_in_t it1
Definition: smartdof3.h:284
smartdof3_default_cfg
err_t smartdof3_default_cfg(smartdof3_t *ctx)
Smart DOF 3 default configuration function.
smartdof3_get_gyro_sensitivity
err_t smartdof3_get_gyro_sensitivity(smartdof3_t *ctx, float *sensitivity)
Smart DOF 3 get the gyro sensitivity function.
smartdof3_return_value_t
smartdof3_return_value_t
Smart DOF 3 Click return value data.
Definition: smartdof3.h:365
smartdof3_status_t::xlda
uint8_t xlda
Definition: smartdof3.h:332
smartdof3_drv_t
smartdof3_drv_t
Smart DOF 3 Click driver selector.
Definition: smartdof3.h:265
smartdof3_s::read_f
smartdof3_master_io_t read_f
Definition: smartdof3.h:294
smartdof3_axis_data_t::x
int16_t x
Definition: smartdof3.h:342
smartdof3_get_gyro_axis_data
err_t smartdof3_get_gyro_axis_data(smartdof3_t *ctx, smartdof3_axis_data_t *gyro_axis)
Smart DOF 3 get the gyro data function.
smartdof3_generic_write
err_t smartdof3_generic_write(smartdof3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Smart DOF 3 data writing function.
smartdof3_cfg_t::miso
pin_name_t miso
Definition: smartdof3.h:306
smartdof3_axis_t
Smart DOF 3 Click sensor axes structure object.
Definition: smartdof3.h:353
smartdof3_s::drv_sel
smartdof3_drv_t drv_sel
Definition: smartdof3.h:291
smartdof3_soft_reset
err_t smartdof3_soft_reset(smartdof3_t *ctx)
Smart DOF 3 software reset function.
smartdof3_drv_interface_selection
void smartdof3_drv_interface_selection(smartdof3_cfg_t *cfg, smartdof3_drv_t drv_sel)
Smart DOF 3 driver interface setup function.
smartdof3_s::slave_address
uint8_t slave_address
Definition: smartdof3.h:289
smartdof3_s::i2c
i2c_master_t i2c
Definition: smartdof3.h:286
spi_specifics.h
This file contains SPI specific macros, functions, etc.
smartdof3_s::write_f
smartdof3_master_io_t write_f
Definition: smartdof3.h:293
smartdof3_enable_auto_increment
err_t smartdof3_enable_auto_increment(smartdof3_t *ctx)
Smart DOF 3 enable auto-increment function.
smartdof3_set_acc_full_scale
err_t smartdof3_set_acc_full_scale(smartdof3_t *ctx, uint8_t data_scale)
Smart DOF 3 sets the accel full-scale range function.
smartdof3_cfg_t::scl
pin_name_t scl
Definition: smartdof3.h:304
smartdof3_s
Smart DOF 3 Click context object.
Definition: smartdof3.h:282
SMARTDOF3_ERROR
@ SMARTDOF3_ERROR
Definition: smartdof3.h:367
smartdof3_get_acc_full_scale
err_t smartdof3_get_acc_full_scale(smartdof3_t *ctx, uint8_t *data_scale)
Smart DOF 3 get the accel full-scale range function.
smartdof3_get_acc_axis_data
err_t smartdof3_get_acc_axis_data(smartdof3_t *ctx, smartdof3_axis_data_t *acc_axis)
Smart DOF 3 get the accel data function.
smartdof3_get_acc_sensitivity
err_t smartdof3_get_acc_sensitivity(smartdof3_t *ctx, float *sensitivity)
Smart DOF 3 get the accel sensitivity function.
smartdof3_master_io_t
err_t(* smartdof3_master_io_t)(struct smartdof3_s *, uint8_t, uint8_t *, uint8_t)
Smart DOF 3 Click driver interface.
Definition: smartdof3.h:275
smartdof3_get_status
err_t smartdof3_get_status(smartdof3_t *ctx, smartdof3_status_t *status)
Smart DOF 3 get the status function.
smartdof3_generic_read
err_t smartdof3_generic_read(smartdof3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Smart DOF 3 data reading function.
smartdof3_set_op_mode
err_t smartdof3_set_op_mode(smartdof3_t *ctx, uint8_t acc_op_mode, uint8_t gyro_op_mode)
Smart DOF 3 sets the operation mode function.
smartdof3_axis_data_t::y
int16_t y
Definition: smartdof3.h:343
smartdof3_cfg_t::i2c_address
uint8_t i2c_address
Definition: smartdof3.h:314
smartdof3_cfg_t
Smart DOF 3 Click configuration object.
Definition: smartdof3.h:303
smartdof3_cfg_setup
void smartdof3_cfg_setup(smartdof3_cfg_t *cfg)
Smart DOF 3 configuration object setup function.
SMARTDOF3_DRV_SEL_SPI
@ SMARTDOF3_DRV_SEL_SPI
Definition: smartdof3.h:266
smartdof3_t
struct smartdof3_s smartdof3_t
Smart DOF 3 Click context object.
smartdof3_status_t::tda
uint8_t tda
Definition: smartdof3.h:330
smartdof3_cfg_t::it1
pin_name_t it1
Definition: smartdof3.h:311
smartdof3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: smartdof3.h:313
smartdof3_enable_temperature
err_t smartdof3_enable_temperature(smartdof3_t *ctx)
Smart DOF 3 enable the temperature function.
smartdof3_axis_t::z
float z
Definition: smartdof3.h:356
smartdof3_cfg_t::sda
pin_name_t sda
Definition: smartdof3.h:305
smartdof3_set_acc_data_rate
err_t smartdof3_set_acc_data_rate(smartdof3_t *ctx, uint8_t data_rate)
Smart DOF 3 sets the accel data rate function.
smartdof3_get_in1_pin
uint8_t smartdof3_get_in1_pin(smartdof3_t *ctx)
Smart DOF 3 get interrupt 1 function.
smartdof3_axis_data_t::z
int16_t z
Definition: smartdof3.h:344
smartdof3_get_gyro_full_scale
err_t smartdof3_get_gyro_full_scale(smartdof3_t *ctx, uint8_t *data_scale)
Smart DOF 3 get the gyro full-scale range function.
smartdof3_set_gyro_data_rate
err_t smartdof3_set_gyro_data_rate(smartdof3_t *ctx, uint8_t data_rate)
Smart DOF 3 sets the gyro data rate function.
smartdof3_axis_t::x
float x
Definition: smartdof3.h:354
SMARTDOF3_OK
@ SMARTDOF3_OK
Definition: smartdof3.h:366
smartdof3_get_device_id
err_t smartdof3_get_device_id(smartdof3_t *ctx, uint8_t *device_id)
Smart DOF 3 get device ID function.
smartdof3_get_in2_pin
uint8_t smartdof3_get_in2_pin(smartdof3_t *ctx)
Smart DOF 3 get interrupt 2 function.
smartdof3_cfg_t::mosi
pin_name_t mosi
Definition: smartdof3.h:307
smartdof3_cfg_t::sck
pin_name_t sck
Definition: smartdof3.h:308
smartdof3_get_temperature
err_t smartdof3_get_temperature(smartdof3_t *ctx, float *temperature)
Smart DOF 3 get the temperature function.
smartdof3_cfg_t::drv_sel
smartdof3_drv_t drv_sel
Definition: smartdof3.h:320
smartdof3_init
err_t smartdof3_init(smartdof3_t *ctx, smartdof3_cfg_t *cfg)
Smart DOF 3 initialization function.
smartdof3_get_gyro_axis
err_t smartdof3_get_gyro_axis(smartdof3_t *ctx, smartdof3_axis_t *gyro_axis)
Smart DOF 3 get the gyro sensor axes function.
SMARTDOF3_DRV_SEL_I2C
@ SMARTDOF3_DRV_SEL_I2C
Definition: smartdof3.h:267
smartdof3_status_t::gda
uint8_t gda
Definition: smartdof3.h:331
smartdof3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: smartdof3.h:317
smartdof3_set_gyro_full_scale
err_t smartdof3_set_gyro_full_scale(smartdof3_t *ctx, uint8_t data_scale)
Smart DOF 3 sets the gyro full-scale range function.
smartdof3_axis_t::y
float y
Definition: smartdof3.h:355
smartdof3_cfg_t::cs
pin_name_t cs
Definition: smartdof3.h:309
smartdof3_status_t
Smart DOF 3 Click sensor status structure object.
Definition: smartdof3.h:329
smartdof3_cfg_t::spi_speed
uint32_t spi_speed
Definition: smartdof3.h:316
smartdof3_s::it2
digital_in_t it2
Definition: smartdof3.h:283
smartdof3_enable_block_data_update
err_t smartdof3_enable_block_data_update(smartdof3_t *ctx)
Smart DOF 3 enable block data update function.
smartdof3_axis_data_t
Smart DOF 3 Click axis raw data structure object.
Definition: smartdof3.h:341
smartdof3_get_temperature_raw
err_t smartdof3_get_temperature_raw(smartdof3_t *ctx, int16_t *temp_raw)
Smart DOF 3 get the temperature data function.
smartdof3_s::chip_select
pin_name_t chip_select
Definition: smartdof3.h:290
smartdof3_get_acc_axis
err_t smartdof3_get_acc_axis(smartdof3_t *ctx, smartdof3_axis_t *acc_axis)
Smart DOF 3 get the accel sensor axes function.
smartdof3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: smartdof3.h:318
smartdof3_s::spi
spi_master_t spi
Definition: smartdof3.h:287
smartdof3_cfg_t::it2
pin_name_t it2
Definition: smartdof3.h:310