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 
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 SMARTDOF3_REG_FUNC_CFG_ACCESS 0x01
76 #define SMARTDOF3_REG_PIN_CTRL 0x02
77 #define SMARTDOF3_REG_DRDY_PULSED_REG 0x0B
78 #define SMARTDOF3_REG_INT1_CTRL 0x0D
79 #define SMARTDOF3_REG_INT2_CTRL 0x0E
80 #define SMARTDOF3_REG_WHO_AM_I 0x0F
81 #define SMARTDOF3_REG_CTRL1_XL 0x10
82 #define SMARTDOF3_REG_CTRL2_G 0x11
83 #define SMARTDOF3_REG_CTRL3_C 0x12
84 #define SMARTDOF3_REG_CTRL4_C 0x13
85 #define SMARTDOF3_REG_CTRL5_C 0x14
86 #define SMARTDOF3_REG_CTRL6_C 0x15
87 #define SMARTDOF3_REG_CTRL7_G 0x16
88 #define SMARTDOF3_REG_CTRL9_C 0x18
89 #define SMARTDOF3_REG_CTRL10_C 0x19
90 #define SMARTDOF3_REG_ISPU_INT_STATUS0_MP 0x1A
91 #define SMARTDOF3_REG_ISPU_INT_STATUS1_MP 0x1B
92 #define SMARTDOF3_REG_ISPU_INT_STATUS2_MP 0x1C
93 #define SMARTDOF3_REG_ISPU_INT_STATUS3_MP 0x1D
94 #define SMARTDOF3_REG_STATUS 0x1E
95 #define SMARTDOF3_REG_OUT_TEMP_L 0x20
96 #define SMARTDOF3_REG_OUT_TEMP_H 0x21
97 #define SMARTDOF3_REG_OUTX_L_G 0x22
98 #define SMARTDOF3_REG_OUTX_H_G 0x23
99 #define SMARTDOF3_REG_OUTY_L_G 0x24
100 #define SMARTDOF3_REG_OUTY_H_G 0x25
101 #define SMARTDOF3_REG_OUTZ_L_G 0x26
102 #define SMARTDOF3_REG_OUTZ_H_G 0x27
103 #define SMARTDOF3_REG_OUTX_L_A 0x28
104 #define SMARTDOF3_REG_OUTX_H_A 0x29
105 #define SMARTDOF3_REG_OUTY_L_A 0x2A
106 #define SMARTDOF3_REG_OUTY_H_A 0x2B
107 #define SMARTDOF3_REG_OUTZ_L_A 0x2C
108 #define SMARTDOF3_REG_OUTZ_H_A 0x2D
109 #define SMARTDOF3_REG_STATUS_MASTER_MAINPAGE 0x39
110 #define SMARTDOF3_REG_TIMESTAMP0 0x40
111 #define SMARTDOF3_REG_TIMESTAMP1 0x41
112 #define SMARTDOF3_REG_TIMESTAMP2 0x42
113 #define SMARTDOF3_REG_TIMESTAMP3 0x43
114 #define SMARTDOF3_REG_MD1_CFG 0x5E
115 #define SMARTDOF3_REG_MD2_CFG 0x5F
116 #define SMARTDOF3_REG_INTERNAL_FREQ_FINE 0x63
117 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_1_L 0x73
118 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_1_H 0x74
119 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_2_L 0x75
120 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_2_H 0x76
121 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_3_L 0x77
122 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_3_H 0x78
123 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_4_L 0x79
124 #define SMARTDOF3_REG_ISPU_DUMMY_CFG_4_H 0x7A
125  // smartdof3_reg
127 
142 #define SMARTDOF3_DEVICE_ID 0x22
143 
148 #define SMARTDOF3_CTRL3_SOFT_RESET 0x01
149 #define SMARTDOF3_CTRL3_IF_INC_DISABLE 0x00
150 #define SMARTDOF3_CTRL3_IF_INC_ENABLE 0x04
151 #define SMARTDOF3_CTRL3_IF_INC_BIT_MASK 0xFB
152 #define SMARTDOF3_CTRL3_BDU_DISABLE 0x00
153 #define SMARTDOF3_CTRL3_BDU_ENABLE 0x40
154 #define SMARTDOF3_CTRL3_BDU_BIT_MASK 0xBF
155 
160 #define SMARTDOF3_ODR_XL_G_OFF 0x00
161 #define SMARTDOF3_ODR_XL_G_12_5_HZ 0x01
162 #define SMARTDOF3_ODR_XL_G_26_HZ 0x02
163 #define SMARTDOF3_ODR_XL_G_52_HZ 0x03
164 #define SMARTDOF3_ODR_XL_G_104_HZ 0x04
165 #define SMARTDOF3_ODR_XL_G_208_HZ 0x05
166 #define SMARTDOF3_ODR_XL_G_416_HZ 0x06
167 #define SMARTDOF3_ODR_XL_G_833_HZ 0x07
168 #define SMARTDOF3_ODR_XL_G_1667_HZ 0x08
169 #define SMARTDOF3_ODR_XL_G_3333_HZ 0x09
170 #define SMARTDOF3_ODR_XL_G_6667_HZ 0x0A
171 #define SMARTDOF3_ODR_XL_G_BIT_MASK 0x0F
172 
177 #define SMARTDOF3_XL_FULL_SCALE_2G 0x00
178 #define SMARTDOF3_XL_FULL_SCALE_16G 0x01
179 #define SMARTDOF3_XL_FULL_SCALE_4G 0x02
180 #define SMARTDOF3_XL_FULL_SCALE_8G 0x03
181 #define SMARTDOF3_XL_FULL_SCALE_BIT_MASK 0x03
182 
187 #define SMARTDOF3_OP_MODE_PERFORMANCE_LOW 0x00
188 #define SMARTDOF3_OP_MODE_PERFORMANCE_HIGH 0x01
189 
194 #define SMARTDOF3_TIMESTAMP_ENABLE 0x20
195 
200 #define SMARTDOF3_ACC_SENSITIVITY_FS_2G 0.061
201 #define SMARTDOF3_ACC_SENSITIVITY_FS_4G 0.122
202 #define SMARTDOF3_ACC_SENSITIVITY_FS_8G 0.244
203 #define SMARTDOF3_ACC_SENSITIVITY_FS_16G 0.488
204 
209 #define SMARTDOF3_GY_FULL_SCALE_125DPS 0x01
210 #define SMARTDOF3_GY_FULL_SCALE_250DPS 0x00
211 #define SMARTDOF3_GY_FULL_SCALE_500DPS 0x02
212 #define SMARTDOF3_GY_FULL_SCALE_1000DPS 0x04
213 #define SMARTDOF3_GY_FULL_SCALE_2000DPS 0x06
214 #define SMARTDOF3_GY_FULL_SCALE_BIT_MASK 0x07
215 
220 #define SMARTDOF3_GYRO_SENSITIVITY_FS_125DPS 0.004375
221 #define SMARTDOF3_GYRO_SENSITIVITY_FS_250DPS 0.00875
222 #define SMARTDOF3_GYRO_SENSITIVITY_FS_500DPS 0.0175
223 #define SMARTDOF3_GYRO_SENSITIVITY_FS_1000DPS 0.035
224 #define SMARTDOF3_GYRO_SENSITIVITY_FS_2000DPS 0.07
225 
231 #define SMARTDOF3_DEVICE_ADDRESS_GND 0x6A
232 #define SMARTDOF3_DEVICE_ADDRESS_VCC 0x6B
233 
242 #define SMARTDOF3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
243 #define SMARTDOF3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
244  // smartdof3_set
246 
261 #define SMARTDOF3_MAP_MIKROBUS( cfg, mikrobus ) \
262  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
263  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
264  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
265  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
266  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
267  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
268  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
269  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_INT )
270  // smartdof3_map // smartdof3
273 
278 typedef enum
279 {
284 
289 typedef err_t ( *smartdof3_master_io_t )( struct smartdof3_s*, uint8_t, uint8_t*, uint8_t );
295 typedef struct smartdof3_s
296 {
297  digital_in_t it2;
298  digital_in_t it1;
300  i2c_master_t i2c;
301  spi_master_t spi;
303  uint8_t slave_address;
304  pin_name_t chip_select;
311 
316 typedef struct
317 {
318  pin_name_t scl;
319  pin_name_t sda;
320  pin_name_t miso;
321  pin_name_t mosi;
322  pin_name_t sck;
323  pin_name_t cs;
324  pin_name_t it2;
325  pin_name_t it1;
327  uint32_t i2c_speed;
328  uint8_t i2c_address;
330  uint32_t spi_speed;
331  spi_master_mode_t spi_mode;
332  spi_master_chip_select_polarity_t cs_polarity;
337 
342 typedef struct
343 {
344  uint8_t tda;
345  uint8_t gda;
346  uint8_t xlda;
349 
354 typedef struct
355 {
356  int16_t x;
357  int16_t y;
358  int16_t z;
361 
366 typedef struct
367 {
368  float x;
369  float y;
370  float z;
373 
378 typedef enum
379 {
381  SMARTDOF3_ERROR = -1
382 
384 
401 
417 
432 
446 
461 err_t smartdof3_generic_write ( smartdof3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
462 
477 err_t smartdof3_generic_read ( smartdof3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
478 
492 err_t smartdof3_get_device_id ( smartdof3_t *ctx, uint8_t *device_id );
493 
507 
522 
537 
552 err_t smartdof3_set_op_mode ( smartdof3_t *ctx, uint8_t acc_op_mode, uint8_t gyro_op_mode );
553 
578 err_t smartdof3_set_acc_data_rate ( smartdof3_t *ctx, uint8_t data_rate );
579 
597 err_t smartdof3_set_acc_full_scale ( smartdof3_t *ctx, uint8_t data_scale );
598 
612 err_t smartdof3_get_acc_full_scale ( smartdof3_t *ctx, uint8_t *data_scale );
613 
627 err_t smartdof3_get_acc_sensitivity ( smartdof3_t *ctx, float *sensitivity );
628 
653 err_t smartdof3_set_gyro_data_rate ( smartdof3_t *ctx, uint8_t data_rate );
654 
673 err_t smartdof3_set_gyro_full_scale ( smartdof3_t *ctx, uint8_t data_scale );
674 
688 err_t smartdof3_get_gyro_full_scale ( smartdof3_t *ctx, uint8_t *data_scale );
689 
704 
719 err_t smartdof3_get_gyro_sensitivity ( smartdof3_t *ctx, float *sensitivity );
720 
736 
752 
768 
784 
798 
812 err_t smartdof3_get_temperature_raw ( smartdof3_t *ctx, int16_t *temp_raw );
813 
827 err_t smartdof3_get_temperature ( smartdof3_t *ctx, float *temperature );
828 
841 
854 
855 #ifdef __cplusplus
856 }
857 #endif
858 #endif // SMARTDOF3_H
859  // smartdof3
861 
862 // ------------------------------------------------------------------------ END
smartdof3_s::it1
digital_in_t it1
Definition: smartdof3.h:298
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:379
smartdof3_status_t::xlda
uint8_t xlda
Definition: smartdof3.h:346
smartdof3_drv_t
smartdof3_drv_t
Smart DOF 3 Click driver selector.
Definition: smartdof3.h:279
smartdof3_s::read_f
smartdof3_master_io_t read_f
Definition: smartdof3.h:308
smartdof3_axis_data_t::x
int16_t x
Definition: smartdof3.h:356
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:320
smartdof3_axis_t
Smart DOF 3 Click sensor axes structure object.
Definition: smartdof3.h:367
smartdof3_s::drv_sel
smartdof3_drv_t drv_sel
Definition: smartdof3.h:305
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:303
smartdof3_s::i2c
i2c_master_t i2c
Definition: smartdof3.h:300
spi_specifics.h
This file contains SPI specific macros, functions, etc.
smartdof3_s::write_f
smartdof3_master_io_t write_f
Definition: smartdof3.h:307
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:318
smartdof3_s
Smart DOF 3 Click context object.
Definition: smartdof3.h:296
SMARTDOF3_ERROR
@ SMARTDOF3_ERROR
Definition: smartdof3.h:381
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:289
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:357
smartdof3_cfg_t::i2c_address
uint8_t i2c_address
Definition: smartdof3.h:328
smartdof3_cfg_t
Smart DOF 3 Click configuration object.
Definition: smartdof3.h:317
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:280
smartdof3_t
struct smartdof3_s smartdof3_t
Smart DOF 3 Click context object.
smartdof3_en_block_data_upd
err_t smartdof3_en_block_data_upd(smartdof3_t *ctx)
Smart DOF 3 enable block data update function.
smartdof3_status_t::tda
uint8_t tda
Definition: smartdof3.h:344
smartdof3_en_auto_incr
err_t smartdof3_en_auto_incr(smartdof3_t *ctx)
Smart DOF 3 enable auto-increment function.
smartdof3_cfg_t::it1
pin_name_t it1
Definition: smartdof3.h:325
smartdof3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: smartdof3.h:327
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:370
smartdof3_cfg_t::sda
pin_name_t sda
Definition: smartdof3.h:319
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:358
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:368
SMARTDOF3_OK
@ SMARTDOF3_OK
Definition: smartdof3.h:380
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:321
smartdof3_cfg_t::sck
pin_name_t sck
Definition: smartdof3.h:322
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:334
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:281
smartdof3_status_t::gda
uint8_t gda
Definition: smartdof3.h:345
smartdof3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: smartdof3.h:331
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:369
smartdof3_cfg_t::cs
pin_name_t cs
Definition: smartdof3.h:323
smartdof3_status_t
Smart DOF 3 Click sensor status structure object.
Definition: smartdof3.h:343
smartdof3_cfg_t::spi_speed
uint32_t spi_speed
Definition: smartdof3.h:330
smartdof3_s::it2
digital_in_t it2
Definition: smartdof3.h:297
smartdof3_axis_data_t
Smart DOF 3 Click axis raw data structure object.
Definition: smartdof3.h:355
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:304
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:332
smartdof3_s::spi
spi_master_t spi
Definition: smartdof3.h:301
smartdof3_cfg_t::it2
pin_name_t it2
Definition: smartdof3.h:324