c6dofimu3  2.0.0.0
c6dofimu3.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef C6DOFIMU3_H
36 #define C6DOFIMU3_H
37 #define c6dofimu3_obj_t const uint8_t*
38 #define C6DOFIMU3_RETVAL_T uint8_t
39 
40 #include "mikrosdk_version.h"
41 
42 #ifdef __GNUC__
43 #if mikroSDK_GET_VERSION < 20800ul
44 #include "rcu_delays.h"
45 #else
46 #include "delays.h"
47 #endif
48 #endif
49 
50 #include "drv_digital_out.h"
51 #include "drv_digital_in.h"
52 #include "drv_i2c_master.h"
53 #include "drv_spi_master.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
66 #define C6DOFIMU3_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
75 
81 #define C6DOFIMU3_MASTER_I2C 0
82 #define C6DOFIMU3_MASTER_SPI 1
83 
89 #define C6DOFIMU3_RETVAL uint8_t
90 
91 #define C6DOFIMU3_OK 0x00
92 #define C6DOFIMU3_INIT_ERROR 0xFF
93 
99 #define C6DOFIMU3_REG_I2C_ADDR_0 0x1E
100 #define C6DOFIMU3_REG_I2C_ADDR_1 0x1D
101 #define C6DOFIMU3_REG_I2C_ADDR_2 0x1C
102 #define C6DOFIMU3_REG_I2C_ADDR_3 0x1F
103 
109 #define C6DOFIMU3_STATUS 0x00
110 #define C6DOFIMU3_DR_STATUS 0x00
111 #define C6DOFIMU3_F_STATUS 0x00
112 #define C6DOFIMU3_OUT_X_MSB 0x01
113 #define C6DOFIMU3_OUT_X_LSB 0x02
114 #define C6DOFIMU3_OUT_Y_MSB 0x03
115 #define C6DOFIMU3_OUT_Y_LSB 0x04
116 #define C6DOFIMU3_OUT_Z_MSB 0x05
117 #define C6DOFIMU3_OUT_Z_LSB 0x06
118 #define C6DOFIMU3_F_SETUP 0x09
119 #define C6DOFIMU3_TRIG_CFG 0x0A
120 #define C6DOFIMU3_SYSMOD 0x0B
121 #define C6DOFIMU3_INT_SOURCE 0x0C
122 #define C6DOFIMU3_WHO_AM_I 0x0D
123 #define C6DOFIMU3_XYZ_DATA_CFG 0x0E
124 #define C6DOFIMU3_HP_FILTER_CUTOFF 0x0F
125 #define C6DOFIMU3_PL_STATUS 0x10
126 #define C6DOFIMU3_PL_CFG 0x11
127 #define C6DOFIMU3_PL_COUNT 0x12
128 #define C6DOFIMU3_PL_BF_ZCOMP 0x13
129 #define C6DOFIMU3_P_L_THS_REG 0x14
130 #define C6DOFIMU3_A_FFMT_CFG 0x15
131 #define C6DOFIMU3_A_FFMT_SRC 0x16
132 #define C6DOFIMU3_A_FFMT_THS 0x17
133 #define C6DOFIMU3_A_FFMT_COUNT 0x18
134 #define C6DOFIMU3_TRANSIENT_CFG 0x1D
135 #define C6DOFIMU3_TRANSIENT_SRC 0x1E
136 #define C6DOFIMU3_TRANSIENT_THS 0x1F
137 #define C6DOFIMU3_TRANSIENT_COUNT 0x20
138 #define C6DOFIMU3_PULSE_CFG 0x21
139 #define C6DOFIMU3_PULSE_SRC 0x22
140 #define C6DOFIMU3_PULSE_THSX 0x23
141 #define C6DOFIMU3_PULSE_THSY 0x24
142 #define C6DOFIMU3_PULSE_THSZ 0x25
143 #define C6DOFIMU3_PULSE_TMLT 0x26
144 #define C6DOFIMU3_PULSE_LTCY 0x27
145 #define C6DOFIMU3_PULSE_WIND 0x28
146 #define C6DOFIMU3_ASLP_COUNT 0x29
147 #define C6DOFIMU3_CTRL_REG1 0x2A
148 #define C6DOFIMU3_CTRL_REG2 0x2B
149 #define C6DOFIMU3_CTRL_REG3 0x2C
150 #define C6DOFIMU3_CTRL_REG4 0x2D
151 #define C6DOFIMU3_CTRL_REG5 0x2E
152 #define C6DOFIMU3_OFF_X 0x2F
153 #define C6DOFIMU3_OFF_Y 0x30
154 #define C6DOFIMU3_OFF_Z 0x31
155 #define C6DOFIMU3_M_DR_STATUS 0x32
156 #define C6DOFIMU3_M_OUT_X_MSB 0x33
157 #define C6DOFIMU3_M_OUT_X_LSB 0x34
158 #define C6DOFIMU3_M_OUT_Y_MSB 0x35
159 #define C6DOFIMU3_M_OUT_Y_LSB 0x36
160 #define C6DOFIMU3_M_OUT_Z_MSB 0x37
161 #define C6DOFIMU3_M_OUT_Z_LSB 0x38
162 #define C6DOFIMU3_CMP_OUT_X_MSB 0x39
163 #define C6DOFIMU3_CMP_OUT_X_LSB 0x3A
164 #define C6DOFIMU3_CMP_OUT_Y_MSB 0x3B
165 #define C6DOFIMU3_CMP_OUT_Y_LSB 0x3C
166 #define C6DOFIMU3_CMP_OUT_Z_MSB 0x3D
167 #define C6DOFIMU3_CMP_OUT_Z_LSB 0x3E
168 #define C6DOFIMU3_M_OFF_X_MSB 0x3F
169 #define C6DOFIMU3_M_OFF_X_LSB 0x40
170 #define C6DOFIMU3_M_OFF_Y_MSB 0x41
171 #define C6DOFIMU3_M_OFF_Y_LSB 0x42
172 #define C6DOFIMU3_M_OFF_Z_MSB 0x43
173 #define C6DOFIMU3_M_OFF_Z_LSB 0x44
174 #define C6DOFIMU3_MAX_X_MSB 0x45
175 #define C6DOFIMU3_MAX_X_LSB 0x46
176 #define C6DOFIMU3_MAX_Y_MSB 0x47
177 #define C6DOFIMU3_MAX_Y_LSB 0x48
178 #define C6DOFIMU3_MAX_Z_MSB 0x49
179 #define C6DOFIMU3_MAX_Z_LSB 0x4A
180 #define C6DOFIMU3_MIN_X_MSB 0x4B
181 #define C6DOFIMU3_MIN_X_LSB 0x4C
182 #define C6DOFIMU3_MIN_Y_MSB 0x4D
183 #define C6DOFIMU3_MIN_Y_LSB 0x4E
184 #define C6DOFIMU3_MIN_Z_MSB 0x4F
185 #define C6DOFIMU3_MIN_Z_LSB 0x50
186 #define C6DOFIMU3_TEMP 0x51
187 #define C6DOFIMU3_M_THS_CFG 0x52
188 #define C6DOFIMU3_M_THS_SRC 0x53
189 #define C6DOFIMU3_M_THS_X_MSB 0x54
190 #define C6DOFIMU3_M_THS_X_LSB 0x55
191 #define C6DOFIMU3_M_THS_Y_MSB 0x56
192 #define C6DOFIMU3_M_THS_Y_LSB 0x57
193 #define C6DOFIMU3_M_THS_Z_MSB 0x58
194 #define C6DOFIMU3_M_THS_Z_LSB 0x59
195 #define C6DOFIMU3_M_THS_COUNT 0x5A
196 #define C6DOFIMU3_M_CTRL_REG1 0x5B
197 #define C6DOFIMU3_M_CTRL_REG2 0x5C
198 #define C6DOFIMU3_M_CTRL_REG3 0x5D
199 #define C6DOFIMU3_M_INT_SRC 0x5E
200 #define C6DOFIMU3_A_VECM_CFG 0x5F
201 #define C6DOFIMU3_A_VECM_THS_MSB 0x60
202 #define C6DOFIMU3_A_VECM_THS_LSB 0x61
203 #define C6DOFIMU3_A_VECM_CNT 0x62
204 #define C6DOFIMU3_A_VECM_INITX_MSB 0x63
205 #define C6DOFIMU3_A_VECM_INITX_LSB 0x64
206 #define C6DOFIMU3_A_VECM_INITY_MSB 0x65
207 #define C6DOFIMU3_A_VECM_INITY_LSB 0x66
208 #define C6DOFIMU3_A_VECM_INITZ_MSB 0x67
209 #define C6DOFIMU3_A_VECM_INITZ_LSB 0x68
210 #define C6DOFIMU3_M_VECM_CFG 0x69
211 #define C6DOFIMU3_M_VECM_THS_MSB 0x6A
212 #define C6DOFIMU3_M_VECM_THS_LSB 0x6B
213 #define C6DOFIMU3_M_VECM_CNT 0x6C
214 #define C6DOFIMU3_M_VECM_INITX_MSB 0x6D
215 #define C6DOFIMU3_M_VECM_INITX_LSB 0x6E
216 #define C6DOFIMU3_M_VECM_INITY_MSB 0x6F
217 #define C6DOFIMU3_M_VECM_INITY_LSB 0x70
218 #define C6DOFIMU3_M_VECM_INITZ_MSB 0x71
219 #define C6DOFIMU3_M_VECM_INITZ_LSB 0x72
220 #define C6DOFIMU3_A_FFMT_THS_X_MSB 0x73
221 #define C6DOFIMU3_A_FFMT_THS_X_LSB 0x74
222 #define C6DOFIMU3_A_FFMT_THS_Y_MSB 0x75
223 #define C6DOFIMU3_A_FFMT_THS_Y_LSB 0x76
224 #define C6DOFIMU3_A_FFMT_THS_Z_MSB 0x77
225 #define C6DOFIMU3_A_FFMT_THS_Z_LSB 0x78
226 
232 #define C6DOFIMU3_ACCEL_RES_2G 0.244
233 #define C6DOFIMU3_ACCEL_RES_4G 0.488
234 #define C6DOFIMU3_ACCEL_RES_8G 0.976
235 
241 #define C6DOFIMU3_MAGNETOMETER_RES 0.1
242 
248 #define C6DOFIMU3_DEVICE_ID_VAL 0xC7
249 
255 #define C6DOFIMU3_ERROR 0x00
256 #define C6DOFIMU3_SUCCESS 0x01
257 
263 #define C6DOFIMU3_BIT_MASK_SPI_CMD_WRITE 0x80
264 #define C6DOFIMU3_BIT_MASK_SPI_CMD_READ 0x7F
265 #define C6DOFIMU3_BIT_MASK_BIT_7 0x80
266 
272 #define C6DOFIMU3_DR_STATUS_XYZ_DATA_ERROR 0x00
273 
279 #define C6DOFIMU3_RST_PIN_STATE_LOW 0x00
280 #define C6DOFIMU3_RST_PIN_STATE_HIGH 0x01
281 
287 #define C6DOFIMU3_SPI_COMMUNICATION_DUMMY 0x00
288 
294 #define SPI_COMMUNICATION 1
295 #define I2C_COMMUNICATION 2
296  // End group macro
299 // --------------------------------------------------------------- PUBLIC TYPES
304 typedef struct
305 {
306  float x;
307  float y;
308  float z;
309 }
311 
312 typedef struct
313 {
314  float x;
315  float y;
316  float z;
317 }
319 
323 typedef uint8_t c6dofimu3_select_t;
324 
328 typedef void ( *c6dofimu3_master_io_t )( struct c6dofimu3_s*, uint8_t, uint8_t*, uint8_t );
329 
333 typedef struct c6dofimu3_s
334 {
335  // Output pins
336 
337  digital_out_t cs;
338  digital_out_t rst;
339 
340  // Input pins
341 
342  digital_in_t int_pin;
343 
344  // Modules
345 
346  i2c_master_t i2c;
347  spi_master_t spi;
348 
349  // ctx variable
350 
351  uint8_t slave_address;
352  pin_name_t chip_select;
353 
357 
359 
361 
365 typedef struct
366 {
367  // Communication gpio pins
368 
369  pin_name_t scl;
370  pin_name_t sda;
371  pin_name_t miso;
372  pin_name_t mosi;
373  pin_name_t sck;
374  pin_name_t cs;
375 
376  // Additional gpio pins
377 
378  pin_name_t rst;
379  pin_name_t int_pin;
380 
381  // static variable
382 
383  uint32_t i2c_speed;
384  uint8_t i2c_address;
385 
386  uint32_t spi_speed;
387  spi_master_mode_t spi_mode;
388  spi_master_chip_select_polarity_t cs_polarity;
389 
391 
393  // End types group
395 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
401 #ifdef __cplusplus
402 extern "C"{
403 #endif
404 
414 
424 
433 
444 void c6dofimu3_generic_write ( c6dofimu3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
445 
456 void c6dofimu3_generic_read ( c6dofimu3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
457 
468 void c6dofimu3_set_rst ( c6dofimu3_t *ctx, uint8_t rst_state );
469 
483 void c6dofimu3_multi_write ( c6dofimu3_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
484 
498 void c6dofimu3_multi_read ( c6dofimu3_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
499 
512 
525 
536 
546 
560 
574 
588 
604 
605 #ifdef __cplusplus
606 }
607 #endif
608 #endif // _C6DOFIMU3_H_
609  // End public_function group
612 
613 // ------------------------------------------------------------------------- END
c6dofimu3_t
struct c6dofimu3_s c6dofimu3_t
Click ctx object definition.
c6dofimu3_select_t
uint8_t c6dofimu3_select_t
Communication type.
Definition: c6dofimu3.h:323
c6dofimu3_cfg_t::scl
pin_name_t scl
Definition: c6dofimu3.h:369
mag_data
c6dofimu3_mag_t mag_data
Definition: main.c:31
c6dofimu3_master_io_t
void(* c6dofimu3_master_io_t)(struct c6dofimu3_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: c6dofimu3.h:328
c6dofimu3_cfg_t::sck
pin_name_t sck
Definition: c6dofimu3.h:373
c6dofimu3_s::communication_interface
uint8_t communication_interface
Definition: c6dofimu3.h:358
c6dofimu3_s
Click ctx object definition.
Definition: c6dofimu3.h:334
c6dofimu3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c6dofimu3.h:387
c6dofimu3_s::write_f
c6dofimu3_master_io_t write_f
Definition: c6dofimu3.h:354
c6dofimu3_generic_write
void c6dofimu3_generic_write(c6dofimu3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c6dofimu3_cfg_setup
void c6dofimu3_cfg_setup(c6dofimu3_cfg_t *cfg)
Config Object Initialization function.
c6dofimu3_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu3.h:384
c6dofimu3_read_accel_data
void c6dofimu3_read_accel_data(c6dofimu3_t *ctx, c6dofimu3_accel_t *accel_data)
Read Accel data function.
c6dofimu3_accel_t
Definition: c6dofimu3.h:305
c6dofimu3_active
void c6dofimu3_active(c6dofimu3_t *ctx)
Set active mode function.
c6dofimu3_mag_t::x
float x
Definition: c6dofimu3.h:314
c6dofimu3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu3.h:383
c6dofimu3_accel_t::x
float x
Definition: c6dofimu3.h:306
c6dofimu3_s::spi
spi_master_t spi
Definition: c6dofimu3.h:347
c6dofimu3_s::chip_select
pin_name_t chip_select
Definition: c6dofimu3.h:352
c6dofimu3_s::read_f
c6dofimu3_master_io_t read_f
Definition: c6dofimu3.h:355
c6dofimu3_cfg_t
Click configuration structure definition.
Definition: c6dofimu3.h:366
c6dofimu3_s::i2c
i2c_master_t i2c
Definition: c6dofimu3.h:346
c6dofimu3_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu3.h:386
c6dofimu3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu3.h:388
c6dofimu3_cfg_t::int_pin
pin_name_t int_pin
Definition: c6dofimu3.h:379
c6dofimu3_accel_t::z
float z
Definition: c6dofimu3.h:308
c6dofimu3_mag_t::z
float z
Definition: c6dofimu3.h:316
c6dofimu3_standby
void c6dofimu3_standby(c6dofimu3_t *ctx)
Set standby mode function.
c6dofimu3_mag_t
Definition: c6dofimu3.h:313
c6dofimu3_cfg_t::rst
pin_name_t rst
Definition: c6dofimu3.h:378
c6dofimu3_check_int1
uint8_t c6dofimu3_check_int1(c6dofimu3_t *ctx)
Get interrupt ststus function.
c6dofimu3_read_mag_data
void c6dofimu3_read_mag_data(c6dofimu3_t *ctx, c6dofimu3_mag_t *mag_data)
Read Magnetometer data function.
c6dofimu3_cfg_t::sda
pin_name_t sda
Definition: c6dofimu3.h:370
c6dofimu3_multi_write
void c6dofimu3_multi_write(c6dofimu3_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes)
Multi data write function.
c6dofimu3_s::slave_address
uint8_t slave_address
Definition: c6dofimu3.h:351
c6dofimu3_cfg_t::sel
c6dofimu3_select_t sel
Definition: c6dofimu3.h:390
c6dofimu3_check_id
C6DOFIMU3_RETVAL_T c6dofimu3_check_id(c6dofimu3_t *ctx)
Check ID function.
c6dofimu3_s::cs
digital_out_t cs
Definition: c6dofimu3.h:337
c6dofimu3_multi_read
void c6dofimu3_multi_read(c6dofimu3_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
Multi data read function.
c6dofimu3_s::master_sel
c6dofimu3_select_t master_sel
Definition: c6dofimu3.h:356
c6dofimu3_generic_read
void c6dofimu3_generic_read(c6dofimu3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
c6dofimu3_default_cfg
void c6dofimu3_default_cfg(c6dofimu3_t *ctx)
Click Default Configuration function.
C6DOFIMU3_RETVAL
#define C6DOFIMU3_RETVAL
Definition: c6dofimu3.h:89
c6dofimu3_cfg_t::cs
pin_name_t cs
Definition: c6dofimu3.h:374
c6dofimu3_s::int_pin
digital_in_t int_pin
Definition: c6dofimu3.h:342
c6dofimu3_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu3.h:372
accel_data
c6dofimu3_accel_t accel_data
Definition: main.c:30
c6dofimu3_set_rst
void c6dofimu3_set_rst(c6dofimu3_t *ctx, uint8_t rst_state)
Set RST pin state function.
c6dofimu3_init
C6DOFIMU3_RETVAL c6dofimu3_init(c6dofimu3_t *ctx, c6dofimu3_cfg_t *cfg)
Initialization function.
c6dofimu3_cfg_t::miso
pin_name_t miso
Definition: c6dofimu3.h:371
c6dofimu3_check_data_ready
C6DOFIMU3_RETVAL_T c6dofimu3_check_data_ready(c6dofimu3_t *ctx)
Check data ready function.
c6dofimu3_get_data
void c6dofimu3_get_data(c6dofimu3_t *ctx, c6dofimu3_accel_t *accel_data, c6dofimu3_mag_t *mag_data)
Read Accel and Magnetometer data function.
c6dofimu3_mag_t::y
float y
Definition: c6dofimu3.h:315
C6DOFIMU3_RETVAL_T
#define C6DOFIMU3_RETVAL_T
Definition: c6dofimu3.h:38
c6dofimu3_accel_t::y
float y
Definition: c6dofimu3.h:307
c6dofimu3_s::rst
digital_out_t rst
Definition: c6dofimu3.h:338