c6dofimu 2.0.0.0
c6dofimu.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 C6DOFIMU_H
36#define C6DOFIMU_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define C6DOFIMU_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
75 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define C6DOFIMU_MASTER_I2C 0
83#define C6DOFIMU_MASTER_SPI 1
90#define C6DOFIMU_RETVAL uint8_t
91
92#define C6DOFIMU_OK 0x00
93#define C6DOFIMU_INIT_ERROR 0xFF
100#define C6DOFIMU_SLAVE_ADDRESS 0x6B;
107#define C6DOFIMU_FUNC_CFG_ACCESS 0x01
108
109#define C6DOFIMU_FIFO_CTRL1 0x06
110#define C6DOFIMU_FIFO_CTRL2 0x07
111#define C6DOFIMU_FIFO_CTRL3 0x08
112#define C6DOFIMU_FIFO_CTRL4 0x09
113#define C6DOFIMU_FIFO_CTRL5 0x0A
114
115#define C6DOFIMU_ORIENT_CFG_G 0x0B
116
117#define C6DOFIMU_INT1_CTRL 0x0D
118#define C6DOFIMU_INT2_CTRL 0x0E
119
120#define C6DOFIMU_CTRL1_XL 0x10
121#define C6DOFIMU_CTRL2_G 0x11
122#define C6DOFIMU_CTRL3_C 0x12
123#define C6DOFIMU_CTRL4_C 0x13
124#define C6DOFIMU_CTRL5_C 0x14
125#define C6DOFIMU_CTRL6_C 0x15
126#define C6DOFIMU_CTRL7_G 0x16
127#define C6DOFIMU_CTRL8_XL 0x17
128#define C6DOFIMU_CTRL9_XL 0x18
129#define C6DOFIMU_CTRL10_C 0x19
136#define C6DOFIMU_OUT_TEMP_L 0x20
137#define C6DOFIMU_OUT_TEMP_H 0x21
138
139#define C6DOFIMU_OUTX_L_G 0x22
140#define C6DOFIMU_OUTX_H_G 0x23
141#define C6DOFIMU_OUTY_L_G 0x24
142#define C6DOFIMU_OUTY_H_G 0x25
143#define C6DOFIMU_OUTZ_L_G 0x26
144#define C6DOFIMU_OUTZ_H_G 0x27
145
146#define C6DOFIMU_OUTX_L_XL 0x28
147#define C6DOFIMU_OUTX_H_XL 0x29
148#define C6DOFIMU_OUTY_L_XL 0x2A
149#define C6DOFIMU_OUTY_H_XL 0x2B
150#define C6DOFIMU_OUTZ_L_XL 0x2C
151#define C6DOFIMU_OUTZ_H_XL 0x2D
152
153#define C6DOFIMU_FIFO_DATA_OUT_L 0x3E
154#define C6DOFIMU_FIFO_DATA_OUT_H 0x3F
155
156#define C6DOFIMU_TIMESTAMP0_REG 0x40
157#define C6DOFIMU_TIMESTAMP1_REG 0x41
158#define C6DOFIMU_TIMESTAMP2_REG 0x42
159
160#define C6DOFIMU_STEP_COUNTER_L 0x4B
161#define C6DOFIMU_STEP_COUNTER_H 0x4C
168#define C6DOFIMU_STATUS_REG 0x1E
169
170#define C6DOFIMU_FIFO_STATUS1 0x3A
171#define C6DOFIMU_FIFO_STATUS2 0x3B
172#define C6DOFIMU_FIFO_STATUS3 0x3C
173#define C6DOFIMU_FIFO_STATUS4 0x3D
174
175#define C6DOFIMU_TIMESTAMP_L 0x49
176#define C6DOFIMU_TIMESTAMP_H 0x4A
177
178#define C6DOFIMU_WHO_AM_I 0x0F
185#define C6DOFIMU_WAKE_UP_SRC 0x1B
186#define C6DOFIMU_TAP_SRC 0x1C
187#define C6DOFIMU_D6D_SRC 0x1D
188
189#define C6DOFIMU_FUN_SRC 0x53
190
191#define C6DOFIMU_TAP_CFG 0x58
192#define C6DOFIMU_TAP_THS_6D 0x59
193#define C6DOFIMU_INT_DUR2 0x5A
194#define C6DOFIMU_WAKE_UP_THS 0x5B
195#define C6DOFIMU_WAKE_UP_DUR 0x5C
196#define C6DOFIMU_FREE_FALL 0x5D
197#define C6DOFIMU_MD1_CFG 0x5E
198#define C6DOFIMU_MD2_CFG 0x5F
205#define C6DOFIMU_CFG_BIT_0 0x01
206#define C6DOFIMU_CFG_BIT_1 0x02
207#define C6DOFIMU_CFG_BIT_2 0x04
208#define C6DOFIMU_CFG_BIT_3 0x08
209#define C6DOFIMU_CFG_BIT_4 0x10
210#define C6DOFIMU_CFG_BIT_5 0x20
211#define C6DOFIMU_CFG_BIT_6 0x40
212#define C6DOFIMU_CFG_BIT_7 0x80
219#define C6DOFIMU_ACCEL_READ_MODE 0x00
220#define C6DOFIMU_GYRO_READ_MODE 0x01
223 // End group macro
224// --------------------------------------------------------------- PUBLIC TYPES
233typedef uint8_t c6dofimu_select_t;
234
238typedef void ( *c6dofimu_master_io_t )( struct c6dofimu_s*, uint8_t, uint8_t*, uint8_t );
239
243typedef struct
244{
245 int16_t x;
246 int16_t y;
247 int16_t z;
248
250
254typedef struct c6dofimu_s
255{
256
257 digital_out_t cs;
258
259 // Input pins
260
261 digital_in_t int_pin;
262
263 // Modules
264
265 i2c_master_t i2c;
266 spi_master_t spi;
267
268 // ctx variable
269
271 pin_name_t chip_select;
275
278
280
284typedef struct
285{
286 // Communication gpio pins
287
288 pin_name_t scl;
289 pin_name_t sda;
290 pin_name_t miso;
291 pin_name_t mosi;
292 pin_name_t sck;
293 pin_name_t cs;
294
295 // Additional gpio pins
296
297 pin_name_t int_pin;
298
299 // static variable
300
301 uint32_t i2c_speed;
302 uint8_t i2c_address;
303 uint32_t spi_speed;
304 spi_master_mode_t spi_mode;
305 spi_master_chip_select_polarity_t cs_polarity;
306
308
310
311 // End types group
312// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
318#ifdef __cplusplus
319extern "C"{
320#endif
321
331
340
349
360void c6dofimu_generic_write ( c6dofimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
361
372void c6dofimu_generic_read ( c6dofimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
373
383void c6dofimu_read_axis_data ( c6dofimu_t *ctx, uint8_t read_mode );
384
393
402
403#ifdef __cplusplus
404}
405#endif
406#endif // _C6DOFIMU_H_
407
408 // End public_function group
410
411// ------------------------------------------------------------------------- END
#define C6DOFIMU_RETVAL
Definition c6dofimu.h:90
C6DOFIMU_RETVAL c6dofimu_init(c6dofimu_t *ctx, c6dofimu_cfg_t *cfg)
Initialization function.
void c6dofimu_default_cfg(c6dofimu_t *ctx)
Click Default Configuration function.
void c6dofimu_generic_read(c6dofimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void c6dofimu_cfg_setup(c6dofimu_cfg_t *cfg)
Config Object Initialization function.
void c6dofimu_generic_write(c6dofimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t c6dofimu_digital_read_int(c6dofimu_t *ctx)
Digital read interrupt function.
void c6dofimu_read_axis_data(c6dofimu_t *ctx, uint8_t read_mode)
Read axis data function.
float c6dofimu_read_temperature(c6dofimu_t *ctx)
Read temperature data function.
uint8_t c6dofimu_select_t
Communication type.
Definition c6dofimu.h:233
void(* c6dofimu_master_io_t)(struct c6dofimu_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition c6dofimu.h:238
struct c6dofimu_s c6dofimu_t
Click ctx object definition.
Gyro/Accel Axis structure.
Definition c6dofimu.h:244
int16_t z
Definition c6dofimu.h:247
int16_t x
Definition c6dofimu.h:245
int16_t y
Definition c6dofimu.h:246
Click configuration structure definition.
Definition c6dofimu.h:285
c6dofimu_select_t sel
Definition c6dofimu.h:307
uint32_t i2c_speed
Definition c6dofimu.h:301
spi_master_chip_select_polarity_t cs_polarity
Definition c6dofimu.h:305
pin_name_t sck
Definition c6dofimu.h:292
spi_master_mode_t spi_mode
Definition c6dofimu.h:304
pin_name_t mosi
Definition c6dofimu.h:291
uint32_t spi_speed
Definition c6dofimu.h:303
pin_name_t scl
Definition c6dofimu.h:288
pin_name_t int_pin
Definition c6dofimu.h:297
pin_name_t miso
Definition c6dofimu.h:290
pin_name_t sda
Definition c6dofimu.h:289
pin_name_t cs
Definition c6dofimu.h:293
uint8_t i2c_address
Definition c6dofimu.h:302
Click ctx object definition.
Definition c6dofimu.h:255
digital_out_t cs
Definition c6dofimu.h:257
spi_master_t spi
Definition c6dofimu.h:266
c6dofimu_master_io_t write_f
Definition c6dofimu.h:272
c6dofimu_master_io_t read_f
Definition c6dofimu.h:273
c6dofimu_select_t master_sel
Definition c6dofimu.h:274
digital_in_t int_pin
Definition c6dofimu.h:261
i2c_master_t i2c
Definition c6dofimu.h:265
c6dofimu_axis_t accel_axis
Definition c6dofimu.h:276
uint8_t slave_address
Definition c6dofimu.h:270
pin_name_t chip_select
Definition c6dofimu.h:271
c6dofimu_axis_t gyro_axis
Definition c6dofimu.h:277