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
44#ifdef PREINIT_SUPPORTED
45#include "preinit.h"
46#endif
47
48#ifdef MikroCCoreVersion
49 #if MikroCCoreVersion >= 1
50 #include "delays.h"
51 #endif
52#endif
53
54#include "drv_digital_out.h"
55#include "drv_digital_in.h"
56#include "drv_i2c_master.h"
57#include "drv_spi_master.h"
58
59// -------------------------------------------------------------- PUBLIC MACROS
70#define C6DOFIMU3_MAP_MIKROBUS( cfg, mikrobus ) \
71 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
72 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
73 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
74 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
75 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
76 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
77 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
78 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
85#define C6DOFIMU3_MASTER_I2C 0
86#define C6DOFIMU3_MASTER_SPI 1
93#define C6DOFIMU3_RETVAL uint8_t
94
95#define C6DOFIMU3_OK 0x00
96#define C6DOFIMU3_INIT_ERROR 0xFF
103#define C6DOFIMU3_REG_I2C_ADDR_0 0x1E
104#define C6DOFIMU3_REG_I2C_ADDR_1 0x1D
105#define C6DOFIMU3_REG_I2C_ADDR_2 0x1C
106#define C6DOFIMU3_REG_I2C_ADDR_3 0x1F
113#define C6DOFIMU3_STATUS 0x00
114#define C6DOFIMU3_DR_STATUS 0x00
115#define C6DOFIMU3_F_STATUS 0x00
116#define C6DOFIMU3_OUT_X_MSB 0x01
117#define C6DOFIMU3_OUT_X_LSB 0x02
118#define C6DOFIMU3_OUT_Y_MSB 0x03
119#define C6DOFIMU3_OUT_Y_LSB 0x04
120#define C6DOFIMU3_OUT_Z_MSB 0x05
121#define C6DOFIMU3_OUT_Z_LSB 0x06
122#define C6DOFIMU3_F_SETUP 0x09
123#define C6DOFIMU3_TRIG_CFG 0x0A
124#define C6DOFIMU3_SYSMOD 0x0B
125#define C6DOFIMU3_INT_SOURCE 0x0C
126#define C6DOFIMU3_WHO_AM_I 0x0D
127#define C6DOFIMU3_XYZ_DATA_CFG 0x0E
128#define C6DOFIMU3_HP_FILTER_CUTOFF 0x0F
129#define C6DOFIMU3_PL_STATUS 0x10
130#define C6DOFIMU3_PL_CFG 0x11
131#define C6DOFIMU3_PL_COUNT 0x12
132#define C6DOFIMU3_PL_BF_ZCOMP 0x13
133#define C6DOFIMU3_P_L_THS_REG 0x14
134#define C6DOFIMU3_A_FFMT_CFG 0x15
135#define C6DOFIMU3_A_FFMT_SRC 0x16
136#define C6DOFIMU3_A_FFMT_THS 0x17
137#define C6DOFIMU3_A_FFMT_COUNT 0x18
138#define C6DOFIMU3_TRANSIENT_CFG 0x1D
139#define C6DOFIMU3_TRANSIENT_SRC 0x1E
140#define C6DOFIMU3_TRANSIENT_THS 0x1F
141#define C6DOFIMU3_TRANSIENT_COUNT 0x20
142#define C6DOFIMU3_PULSE_CFG 0x21
143#define C6DOFIMU3_PULSE_SRC 0x22
144#define C6DOFIMU3_PULSE_THSX 0x23
145#define C6DOFIMU3_PULSE_THSY 0x24
146#define C6DOFIMU3_PULSE_THSZ 0x25
147#define C6DOFIMU3_PULSE_TMLT 0x26
148#define C6DOFIMU3_PULSE_LTCY 0x27
149#define C6DOFIMU3_PULSE_WIND 0x28
150#define C6DOFIMU3_ASLP_COUNT 0x29
151#define C6DOFIMU3_CTRL_REG1 0x2A
152#define C6DOFIMU3_CTRL_REG2 0x2B
153#define C6DOFIMU3_CTRL_REG3 0x2C
154#define C6DOFIMU3_CTRL_REG4 0x2D
155#define C6DOFIMU3_CTRL_REG5 0x2E
156#define C6DOFIMU3_OFF_X 0x2F
157#define C6DOFIMU3_OFF_Y 0x30
158#define C6DOFIMU3_OFF_Z 0x31
159#define C6DOFIMU3_M_DR_STATUS 0x32
160#define C6DOFIMU3_M_OUT_X_MSB 0x33
161#define C6DOFIMU3_M_OUT_X_LSB 0x34
162#define C6DOFIMU3_M_OUT_Y_MSB 0x35
163#define C6DOFIMU3_M_OUT_Y_LSB 0x36
164#define C6DOFIMU3_M_OUT_Z_MSB 0x37
165#define C6DOFIMU3_M_OUT_Z_LSB 0x38
166#define C6DOFIMU3_CMP_OUT_X_MSB 0x39
167#define C6DOFIMU3_CMP_OUT_X_LSB 0x3A
168#define C6DOFIMU3_CMP_OUT_Y_MSB 0x3B
169#define C6DOFIMU3_CMP_OUT_Y_LSB 0x3C
170#define C6DOFIMU3_CMP_OUT_Z_MSB 0x3D
171#define C6DOFIMU3_CMP_OUT_Z_LSB 0x3E
172#define C6DOFIMU3_M_OFF_X_MSB 0x3F
173#define C6DOFIMU3_M_OFF_X_LSB 0x40
174#define C6DOFIMU3_M_OFF_Y_MSB 0x41
175#define C6DOFIMU3_M_OFF_Y_LSB 0x42
176#define C6DOFIMU3_M_OFF_Z_MSB 0x43
177#define C6DOFIMU3_M_OFF_Z_LSB 0x44
178#define C6DOFIMU3_MAX_X_MSB 0x45
179#define C6DOFIMU3_MAX_X_LSB 0x46
180#define C6DOFIMU3_MAX_Y_MSB 0x47
181#define C6DOFIMU3_MAX_Y_LSB 0x48
182#define C6DOFIMU3_MAX_Z_MSB 0x49
183#define C6DOFIMU3_MAX_Z_LSB 0x4A
184#define C6DOFIMU3_MIN_X_MSB 0x4B
185#define C6DOFIMU3_MIN_X_LSB 0x4C
186#define C6DOFIMU3_MIN_Y_MSB 0x4D
187#define C6DOFIMU3_MIN_Y_LSB 0x4E
188#define C6DOFIMU3_MIN_Z_MSB 0x4F
189#define C6DOFIMU3_MIN_Z_LSB 0x50
190#define C6DOFIMU3_TEMP 0x51
191#define C6DOFIMU3_M_THS_CFG 0x52
192#define C6DOFIMU3_M_THS_SRC 0x53
193#define C6DOFIMU3_M_THS_X_MSB 0x54
194#define C6DOFIMU3_M_THS_X_LSB 0x55
195#define C6DOFIMU3_M_THS_Y_MSB 0x56
196#define C6DOFIMU3_M_THS_Y_LSB 0x57
197#define C6DOFIMU3_M_THS_Z_MSB 0x58
198#define C6DOFIMU3_M_THS_Z_LSB 0x59
199#define C6DOFIMU3_M_THS_COUNT 0x5A
200#define C6DOFIMU3_M_CTRL_REG1 0x5B
201#define C6DOFIMU3_M_CTRL_REG2 0x5C
202#define C6DOFIMU3_M_CTRL_REG3 0x5D
203#define C6DOFIMU3_M_INT_SRC 0x5E
204#define C6DOFIMU3_A_VECM_CFG 0x5F
205#define C6DOFIMU3_A_VECM_THS_MSB 0x60
206#define C6DOFIMU3_A_VECM_THS_LSB 0x61
207#define C6DOFIMU3_A_VECM_CNT 0x62
208#define C6DOFIMU3_A_VECM_INITX_MSB 0x63
209#define C6DOFIMU3_A_VECM_INITX_LSB 0x64
210#define C6DOFIMU3_A_VECM_INITY_MSB 0x65
211#define C6DOFIMU3_A_VECM_INITY_LSB 0x66
212#define C6DOFIMU3_A_VECM_INITZ_MSB 0x67
213#define C6DOFIMU3_A_VECM_INITZ_LSB 0x68
214#define C6DOFIMU3_M_VECM_CFG 0x69
215#define C6DOFIMU3_M_VECM_THS_MSB 0x6A
216#define C6DOFIMU3_M_VECM_THS_LSB 0x6B
217#define C6DOFIMU3_M_VECM_CNT 0x6C
218#define C6DOFIMU3_M_VECM_INITX_MSB 0x6D
219#define C6DOFIMU3_M_VECM_INITX_LSB 0x6E
220#define C6DOFIMU3_M_VECM_INITY_MSB 0x6F
221#define C6DOFIMU3_M_VECM_INITY_LSB 0x70
222#define C6DOFIMU3_M_VECM_INITZ_MSB 0x71
223#define C6DOFIMU3_M_VECM_INITZ_LSB 0x72
224#define C6DOFIMU3_A_FFMT_THS_X_MSB 0x73
225#define C6DOFIMU3_A_FFMT_THS_X_LSB 0x74
226#define C6DOFIMU3_A_FFMT_THS_Y_MSB 0x75
227#define C6DOFIMU3_A_FFMT_THS_Y_LSB 0x76
228#define C6DOFIMU3_A_FFMT_THS_Z_MSB 0x77
229#define C6DOFIMU3_A_FFMT_THS_Z_LSB 0x78
236#define C6DOFIMU3_ACCEL_RES_2G 0.244
237#define C6DOFIMU3_ACCEL_RES_4G 0.488
238#define C6DOFIMU3_ACCEL_RES_8G 0.976
245#define C6DOFIMU3_MAGNETOMETER_RES 0.1
252#define C6DOFIMU3_DEVICE_ID_VAL 0xC7
259#define C6DOFIMU3_ERROR 0x00
260#define C6DOFIMU3_SUCCESS 0x01
267#define C6DOFIMU3_BIT_MASK_SPI_CMD_WRITE 0x80
268#define C6DOFIMU3_BIT_MASK_SPI_CMD_READ 0x7F
269#define C6DOFIMU3_BIT_MASK_BIT_7 0x80
276#define C6DOFIMU3_DR_STATUS_XYZ_DATA_ERROR 0x00
283#define C6DOFIMU3_RST_PIN_STATE_LOW 0x00
284#define C6DOFIMU3_RST_PIN_STATE_HIGH 0x01
291#define C6DOFIMU3_SPI_COMMUNICATION_DUMMY 0x00
298#define SPI_COMMUNICATION 1
299#define I2C_COMMUNICATION 2
302 // End group macro
303// --------------------------------------------------------------- PUBLIC TYPES
308typedef struct
309{
310 float x;
311 float y;
312 float z;
313}
315
316typedef struct
317{
318 float x;
319 float y;
320 float z;
321}
323
327typedef uint8_t c6dofimu3_select_t;
328
332typedef void ( *c6dofimu3_master_io_t )( struct c6dofimu3_s*, uint8_t, uint8_t*, uint8_t );
333
337typedef struct c6dofimu3_s
338{
339 // Output pins
340
341 digital_out_t cs;
342 digital_out_t rst;
343
344 // Input pins
345
346 digital_in_t int_pin;
347
348 // Modules
349
350 i2c_master_t i2c;
351 spi_master_t spi;
352
353 // ctx variable
354
356 pin_name_t chip_select;
357
361
363
365
369typedef struct
370{
371 // Communication gpio pins
372
373 pin_name_t scl;
374 pin_name_t sda;
375 pin_name_t miso;
376 pin_name_t mosi;
377 pin_name_t sck;
378 pin_name_t cs;
379
380 // Additional gpio pins
381
382 pin_name_t rst;
383 pin_name_t int_pin;
384
385 // static variable
386
387 uint32_t i2c_speed;
388 uint8_t i2c_address;
389
390 uint32_t spi_speed;
391 spi_master_mode_t spi_mode;
392 spi_master_chip_select_polarity_t cs_polarity;
393
395
397
398 // End types group
399// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
405#ifdef __cplusplus
406extern "C"{
407#endif
408
418
428
437
448void c6dofimu3_generic_write ( c6dofimu3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
449
460void c6dofimu3_generic_read ( c6dofimu3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
461
472void c6dofimu3_set_rst ( c6dofimu3_t *ctx, uint8_t rst_state );
473
487void c6dofimu3_multi_write ( c6dofimu3_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
488
502void c6dofimu3_multi_read ( c6dofimu3_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
503
516
529
540
550
564
578
592
608
609#ifdef __cplusplus
610}
611#endif
612#endif // _C6DOFIMU3_H_
613
614 // End public_function group
616
617// ------------------------------------------------------------------------- END
#define C6DOFIMU3_RETVAL
Definition c6dofimu3.h:93
void c6dofimu3_generic_write(c6dofimu3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
C6DOFIMU3_RETVAL_T c6dofimu3_check_data_ready(c6dofimu3_t *ctx)
Check data ready function.
void c6dofimu3_set_rst(c6dofimu3_t *ctx, uint8_t rst_state)
Set RST pin state function.
C6DOFIMU3_RETVAL_T c6dofimu3_check_id(c6dofimu3_t *ctx)
Check ID function.
void c6dofimu3_get_data(c6dofimu3_t *ctx, c6dofimu3_accel_t *accel_data, c6dofimu3_mag_t *mag_data)
Read Accel and Magnetometer data function.
void c6dofimu3_generic_read(c6dofimu3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
C6DOFIMU3_RETVAL c6dofimu3_init(c6dofimu3_t *ctx, c6dofimu3_cfg_t *cfg)
Initialization function.
void c6dofimu3_read_mag_data(c6dofimu3_t *ctx, c6dofimu3_mag_t *mag_data)
Read Magnetometer data function.
void c6dofimu3_active(c6dofimu3_t *ctx)
Set active mode function.
void c6dofimu3_default_cfg(c6dofimu3_t *ctx)
Click Default Configuration function.
void c6dofimu3_multi_read(c6dofimu3_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
Multi data read function.
void c6dofimu3_multi_write(c6dofimu3_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes)
Multi data write function.
void c6dofimu3_cfg_setup(c6dofimu3_cfg_t *cfg)
Config Object Initialization function.
void c6dofimu3_standby(c6dofimu3_t *ctx)
Set standby mode function.
uint8_t c6dofimu3_check_int1(c6dofimu3_t *ctx)
Get interrupt ststus function.
void c6dofimu3_read_accel_data(c6dofimu3_t *ctx, c6dofimu3_accel_t *accel_data)
Read Accel data function.
uint8_t c6dofimu3_select_t
Communication type.
Definition c6dofimu3.h:327
void(* c6dofimu3_master_io_t)(struct c6dofimu3_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition c6dofimu3.h:332
struct c6dofimu3_s c6dofimu3_t
Click ctx object definition.
#define C6DOFIMU3_RETVAL_T
Definition c6dofimu3.h:38
c6dofimu3_accel_t accel_data
Definition main.c:30
c6dofimu3_mag_t mag_data
Definition main.c:31
Definition c6dofimu3.h:309
float y
Definition c6dofimu3.h:311
float x
Definition c6dofimu3.h:310
float z
Definition c6dofimu3.h:312
Click configuration structure definition.
Definition c6dofimu3.h:370
uint32_t i2c_speed
Definition c6dofimu3.h:387
spi_master_chip_select_polarity_t cs_polarity
Definition c6dofimu3.h:392
pin_name_t sck
Definition c6dofimu3.h:377
spi_master_mode_t spi_mode
Definition c6dofimu3.h:391
pin_name_t mosi
Definition c6dofimu3.h:376
uint32_t spi_speed
Definition c6dofimu3.h:390
pin_name_t scl
Definition c6dofimu3.h:373
pin_name_t int_pin
Definition c6dofimu3.h:383
pin_name_t miso
Definition c6dofimu3.h:375
pin_name_t sda
Definition c6dofimu3.h:374
c6dofimu3_select_t sel
Definition c6dofimu3.h:394
pin_name_t rst
Definition c6dofimu3.h:382
pin_name_t cs
Definition c6dofimu3.h:378
uint8_t i2c_address
Definition c6dofimu3.h:388
Definition c6dofimu3.h:317
float y
Definition c6dofimu3.h:319
float x
Definition c6dofimu3.h:318
float z
Definition c6dofimu3.h:320
Click ctx object definition.
Definition c6dofimu3.h:338
digital_out_t cs
Definition c6dofimu3.h:341
spi_master_t spi
Definition c6dofimu3.h:351
c6dofimu3_master_io_t write_f
Definition c6dofimu3.h:358
uint8_t communication_interface
Definition c6dofimu3.h:362
c6dofimu3_select_t master_sel
Definition c6dofimu3.h:360
digital_in_t int_pin
Definition c6dofimu3.h:346
i2c_master_t i2c
Definition c6dofimu3.h:350
digital_out_t rst
Definition c6dofimu3.h:342
uint8_t slave_address
Definition c6dofimu3.h:355
pin_name_t chip_select
Definition c6dofimu3.h:356
c6dofimu3_master_io_t read_f
Definition c6dofimu3.h:359