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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_spi_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define C6DOFIMU_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
56  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
57  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
58  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
59  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
60  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
61  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
62 
68 #define C6DOFIMU_MASTER_I2C 0
69 #define C6DOFIMU_MASTER_SPI 1
70 
76 #define C6DOFIMU_RETVAL uint8_t
77 
78 #define C6DOFIMU_OK 0x00
79 #define C6DOFIMU_INIT_ERROR 0xFF
80 
86 #define C6DOFIMU_SLAVE_ADDRESS 0x6B;
87 
93 #define C6DOFIMU_FUNC_CFG_ACCESS 0x01
94 
95 #define C6DOFIMU_FIFO_CTRL1 0x06
96 #define C6DOFIMU_FIFO_CTRL2 0x07
97 #define C6DOFIMU_FIFO_CTRL3 0x08
98 #define C6DOFIMU_FIFO_CTRL4 0x09
99 #define C6DOFIMU_FIFO_CTRL5 0x0A
100 
101 #define C6DOFIMU_ORIENT_CFG_G 0x0B
102 
103 #define C6DOFIMU_INT1_CTRL 0x0D
104 #define C6DOFIMU_INT2_CTRL 0x0E
105 
106 #define C6DOFIMU_CTRL1_XL 0x10
107 #define C6DOFIMU_CTRL2_G 0x11
108 #define C6DOFIMU_CTRL3_C 0x12
109 #define C6DOFIMU_CTRL4_C 0x13
110 #define C6DOFIMU_CTRL5_C 0x14
111 #define C6DOFIMU_CTRL6_C 0x15
112 #define C6DOFIMU_CTRL7_G 0x16
113 #define C6DOFIMU_CTRL8_XL 0x17
114 #define C6DOFIMU_CTRL9_XL 0x18
115 #define C6DOFIMU_CTRL10_C 0x19
116 
122 #define C6DOFIMU_OUT_TEMP_L 0x20
123 #define C6DOFIMU_OUT_TEMP_H 0x21
124 
125 #define C6DOFIMU_OUTX_L_G 0x22
126 #define C6DOFIMU_OUTX_H_G 0x23
127 #define C6DOFIMU_OUTY_L_G 0x24
128 #define C6DOFIMU_OUTY_H_G 0x25
129 #define C6DOFIMU_OUTZ_L_G 0x26
130 #define C6DOFIMU_OUTZ_H_G 0x27
131 
132 #define C6DOFIMU_OUTX_L_XL 0x28
133 #define C6DOFIMU_OUTX_H_XL 0x29
134 #define C6DOFIMU_OUTY_L_XL 0x2A
135 #define C6DOFIMU_OUTY_H_XL 0x2B
136 #define C6DOFIMU_OUTZ_L_XL 0x2C
137 #define C6DOFIMU_OUTZ_H_XL 0x2D
138 
139 #define C6DOFIMU_FIFO_DATA_OUT_L 0x3E
140 #define C6DOFIMU_FIFO_DATA_OUT_H 0x3F
141 
142 #define C6DOFIMU_TIMESTAMP0_REG 0x40
143 #define C6DOFIMU_TIMESTAMP1_REG 0x41
144 #define C6DOFIMU_TIMESTAMP2_REG 0x42
145 
146 #define C6DOFIMU_STEP_COUNTER_L 0x4B
147 #define C6DOFIMU_STEP_COUNTER_H 0x4C
148 
154 #define C6DOFIMU_STATUS_REG 0x1E
155 
156 #define C6DOFIMU_FIFO_STATUS1 0x3A
157 #define C6DOFIMU_FIFO_STATUS2 0x3B
158 #define C6DOFIMU_FIFO_STATUS3 0x3C
159 #define C6DOFIMU_FIFO_STATUS4 0x3D
160 
161 #define C6DOFIMU_TIMESTAMP_L 0x49
162 #define C6DOFIMU_TIMESTAMP_H 0x4A
163 
164 #define C6DOFIMU_WHO_AM_I 0x0F
165 
171 #define C6DOFIMU_WAKE_UP_SRC 0x1B
172 #define C6DOFIMU_TAP_SRC 0x1C
173 #define C6DOFIMU_D6D_SRC 0x1D
174 
175 #define C6DOFIMU_FUN_SRC 0x53
176 
177 #define C6DOFIMU_TAP_CFG 0x58
178 #define C6DOFIMU_TAP_THS_6D 0x59
179 #define C6DOFIMU_INT_DUR2 0x5A
180 #define C6DOFIMU_WAKE_UP_THS 0x5B
181 #define C6DOFIMU_WAKE_UP_DUR 0x5C
182 #define C6DOFIMU_FREE_FALL 0x5D
183 #define C6DOFIMU_MD1_CFG 0x5E
184 #define C6DOFIMU_MD2_CFG 0x5F
185 
191 #define C6DOFIMU_CFG_BIT_0 0x01
192 #define C6DOFIMU_CFG_BIT_1 0x02
193 #define C6DOFIMU_CFG_BIT_2 0x04
194 #define C6DOFIMU_CFG_BIT_3 0x08
195 #define C6DOFIMU_CFG_BIT_4 0x10
196 #define C6DOFIMU_CFG_BIT_5 0x20
197 #define C6DOFIMU_CFG_BIT_6 0x40
198 #define C6DOFIMU_CFG_BIT_7 0x80
199 
205 #define C6DOFIMU_ACCEL_READ_MODE 0x00
206 #define C6DOFIMU_GYRO_READ_MODE 0x01
207  // End group macro
210 // --------------------------------------------------------------- PUBLIC TYPES
219 typedef uint8_t c6dofimu_select_t;
220 
224 typedef void ( *c6dofimu_master_io_t )( struct c6dofimu_s*, uint8_t, uint8_t*, uint8_t );
225 
229 typedef struct
230 {
231  int16_t x;
232  int16_t y;
233  int16_t z;
234 
236 
240 typedef struct c6dofimu_s
241 {
242 
243  digital_out_t cs;
244 
245  // Input pins
246 
247  digital_in_t int_pin;
248 
249  // Modules
250 
251  i2c_master_t i2c;
252  spi_master_t spi;
253 
254  // ctx variable
255 
256  uint8_t slave_address;
257  pin_name_t chip_select;
261 
264 
266 
270 typedef struct
271 {
272  // Communication gpio pins
273 
274  pin_name_t scl;
275  pin_name_t sda;
276  pin_name_t miso;
277  pin_name_t mosi;
278  pin_name_t sck;
279  pin_name_t cs;
280 
281  // Additional gpio pins
282 
283  pin_name_t int_pin;
284 
285  // static variable
286 
287  uint32_t i2c_speed;
288  uint8_t i2c_address;
289  uint32_t spi_speed;
290  spi_master_mode_t spi_mode;
291  spi_master_chip_select_polarity_t cs_polarity;
292 
294 
296  // End types group
298 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
304 #ifdef __cplusplus
305 extern "C"{
306 #endif
307 
317 
326 
335 
346 void c6dofimu_generic_write ( c6dofimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
347 
358 void c6dofimu_generic_read ( c6dofimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
359 
369 void c6dofimu_read_axis_data ( c6dofimu_t *ctx, uint8_t read_mode );
370 
379 
388 
389 #ifdef __cplusplus
390 }
391 #endif
392 #endif // _C6DOFIMU_H_
393  // End public_function group
396 
397 // ------------------------------------------------------------------------- END
c6dofimu_cfg_t::sel
c6dofimu_select_t sel
Definition: c6dofimu.h:293
c6dofimu_default_cfg
void c6dofimu_default_cfg(c6dofimu_t *ctx)
Click Default Configuration function.
c6dofimu_generic_read
void c6dofimu_generic_read(c6dofimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
c6dofimu_axis_t
Gyro/Accel Axis structure.
Definition: c6dofimu.h:230
c6dofimu_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c6dofimu.h:290
c6dofimu_digital_read_int
uint8_t c6dofimu_digital_read_int(c6dofimu_t *ctx)
Digital read interrupt function.
C6DOFIMU_RETVAL
#define C6DOFIMU_RETVAL
Definition: c6dofimu.h:76
c6dofimu_s::write_f
c6dofimu_master_io_t write_f
Definition: c6dofimu.h:258
c6dofimu_select_t
uint8_t c6dofimu_select_t
Communication type.
Definition: c6dofimu.h:219
c6dofimu_s::spi
spi_master_t spi
Definition: c6dofimu.h:252
c6dofimu_axis_t::z
int16_t z
Definition: c6dofimu.h:233
c6dofimu_read_temperature
float c6dofimu_read_temperature(c6dofimu_t *ctx)
Read temperature data function.
c6dofimu_generic_write
void c6dofimu_generic_write(c6dofimu_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c6dofimu_axis_t::x
int16_t x
Definition: c6dofimu.h:231
c6dofimu_cfg_t::sck
pin_name_t sck
Definition: c6dofimu.h:278
c6dofimu_s::accel_axis
c6dofimu_axis_t accel_axis
Definition: c6dofimu.h:262
c6dofimu_cfg_t::miso
pin_name_t miso
Definition: c6dofimu.h:276
c6dofimu_s
Click ctx object definition.
Definition: c6dofimu.h:241
c6dofimu_s::int_pin
digital_in_t int_pin
Definition: c6dofimu.h:247
c6dofimu_cfg_t
Click configuration structure definition.
Definition: c6dofimu.h:271
c6dofimu_s::i2c
i2c_master_t i2c
Definition: c6dofimu.h:251
c6dofimu_cfg_t::scl
pin_name_t scl
Definition: c6dofimu.h:274
c6dofimu_cfg_setup
void c6dofimu_cfg_setup(c6dofimu_cfg_t *cfg)
Config Object Initialization function.
c6dofimu_s::cs
digital_out_t cs
Definition: c6dofimu.h:243
c6dofimu_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu.h:291
c6dofimu_s::slave_address
uint8_t slave_address
Definition: c6dofimu.h:256
c6dofimu_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu.h:277
c6dofimu_s::read_f
c6dofimu_master_io_t read_f
Definition: c6dofimu.h:259
c6dofimu_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu.h:287
c6dofimu_init
C6DOFIMU_RETVAL c6dofimu_init(c6dofimu_t *ctx, c6dofimu_cfg_t *cfg)
Initialization function.
c6dofimu_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu.h:289
c6dofimu_t
struct c6dofimu_s c6dofimu_t
Click ctx object definition.
c6dofimu_cfg_t::cs
pin_name_t cs
Definition: c6dofimu.h:279
c6dofimu_master_io_t
void(* c6dofimu_master_io_t)(struct c6dofimu_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: c6dofimu.h:224
c6dofimu_read_axis_data
void c6dofimu_read_axis_data(c6dofimu_t *ctx, uint8_t read_mode)
Read axis data function.
c6dofimu_cfg_t::sda
pin_name_t sda
Definition: c6dofimu.h:275
c6dofimu_s::gyro_axis
c6dofimu_axis_t gyro_axis
Definition: c6dofimu.h:263
c6dofimu_s::chip_select
pin_name_t chip_select
Definition: c6dofimu.h:257
c6dofimu_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu.h:288
c6dofimu_axis_t::y
int16_t y
Definition: c6dofimu.h:232
c6dofimu_s::master_sel
c6dofimu_select_t master_sel
Definition: c6dofimu.h:260
c6dofimu_cfg_t::int_pin
pin_name_t int_pin
Definition: c6dofimu.h:283