c6dofimu2  2.0.0.0
c6dofimu2.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 C6DOFIMU2_H
36 #define C6DOFIMU2_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 C6DOFIMU2_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 C6DOFIMU2_MASTER_I2C 0
69 #define C6DOFIMU2_MASTER_SPI 1
70 
76 #define C6DOFIMU2_RETVAL uint8_t
77 
78 #define C6DOFIMU2_OK 0x00
79 #define C6DOFIMU2_INIT_ERROR 0xFF
80 
86 #define C6DOFIMU2_I2C_ADDR 0x68
87 
93 #define C6DOFIMU2_REG_CHIP_ID 0x00
94 #define C6DOFIMU2_REG_ERROR 0x02
95 #define C6DOFIMU2_REG_PMU_STATUS 0x03
96 #define C6DOFIMU2_REG_AUX_DATA 0x04
97 #define C6DOFIMU2_REG_GYRO_DATA 0x0C
98 #define C6DOFIMU2_REG_ACCEL_DATA 0x12
99 #define C6DOFIMU2_REG_STATUS 0x1B
100 #define C6DOFIMU2_REG_INT_STATUS 0x1C
101 #define C6DOFIMU2_REG_FIFO_LENGTH 0x22
102 #define C6DOFIMU2_REG_FIFO_DATA 0x24
103 #define C6DOFIMU2_REG_ACCEL_CONFIG 0x40
104 #define C6DOFIMU2_REG_ACCEL_RANGE 0x41
105 #define C6DOFIMU2_REG_GYRO_CONFIG 0x42
106 #define C6DOFIMU2_REG_GYRO_RANGE 0x43
107 #define C6DOFIMU2_REG_AUX_ODR 0x44
108 #define C6DOFIMU2_REG_FIFO_DOWN 0x45
109 #define C6DOFIMU2_REG_FIFO_CONFIG_0 0x46
110 #define C6DOFIMU2_REG_FIFO_CONFIG_1 0x47
111 #define C6DOFIMU2_REG_AUX_IF_0 0x4B
112 #define C6DOFIMU2_REG_AUX_IF_1 0x4C
113 #define C6DOFIMU2_REG_AUX_IF_2 0x4D
114 #define C6DOFIMU2_REG_AUX_IF_3 0x4E
115 #define C6DOFIMU2_REG_AUX_IF_4 0x4F
116 #define C6DOFIMU2_REG_INT_ENABLE_0 0x50
117 #define C6DOFIMU2_REG_INT_ENABLE_1 0x51
118 #define C6DOFIMU2_REG_INT_ENABLE_2 0x52
119 #define C6DOFIMU2_REG_INT_OUT_CTRL 0x53
120 #define C6DOFIMU2_REG_INT_LATCH 0x54
121 #define C6DOFIMU2_REG_INT_MAP_0 0x55
122 #define C6DOFIMU2_REG_INT_MAP_1 0x56
123 #define C6DOFIMU2_REG_INT_MAP_2 0x57
124 #define C6DOFIMU2_REG_INT_DATA_0 0x58
125 #define C6DOFIMU2_REG_INT_DATA_1 0x59
126 #define C6DOFIMU2_REG_INT_LOWHIGH_0 0x5A
127 #define C6DOFIMU2_REG_INT_LOWHIGH_1 0x5B
128 #define C6DOFIMU2_REG_INT_LOWHIGH_2 0x5C
129 #define C6DOFIMU2_REG_INT_LOWHIGH_3 0x5D
130 #define C6DOFIMU2_REG_INT_LOWHIGH_4 0x5E
131 #define C6DOFIMU2_REG_INT_MOTION_0 0x5F
132 #define C6DOFIMU2_REG_INT_MOTION_1 0x60
133 #define C6DOFIMU2_REG_INT_MOTION_2 0x61
134 #define C6DOFIMU2_REG_INT_MOTION_3 0x62
135 #define C6DOFIMU2_REG_INT_TAP_0 0x63
136 #define C6DOFIMU2_REG_INT_TAP_1 0x64
137 #define C6DOFIMU2_REG_INT_ORIENT_0 0x65
138 #define C6DOFIMU2_REG_INT_ORIENT_1 0x66
139 #define C6DOFIMU2_REG_INT_FLAT_0 0x67
140 #define C6DOFIMU2_REG_INT_FLAT_1 0x68
141 #define C6DOFIMU2_REG_FOC_CONF 0x69
142 #define C6DOFIMU2_REG_CONF 0x6A
143 #define C6DOFIMU2_REG_NV_CONF 0x70
144 
150 #define C6DOFIMU2_CFG_IF_CONF 0x6B
151 #define C6DOFIMU2_CFG_SELF_TEST 0x6D
152 #define C6DOFIMU2_CFG_OFFSET 0x71
153 #define C6DOFIMU2_CFG_OFFSET_CONF 0x77
154 #define C6DOFIMU2_CFG_INT_STEP_CNT_0 0x78
155 #define C6DOFIMU2_CFG_INT_STEP_CONFIG_0 0x7A
156 #define C6DOFIMU2_CFG_INT_STEP_CONFIG_1 0x7B
157 #define C6DOFIMU2_CFG_COMMAND 0x7E
158 #define C6DOFIMU2_CFG_SPI_COMM_TEST 0x7F
159 #define C6DOFIMU2_CFG_INTL_PULLUP_CONF 0x85
160 
166 #define C6DOFIMU2_CMD_ACCEL_NORMAL 0x11
167 #define C6DOFIMU2_CMD_ACCEL_LOW_PWR 0x12
168 #define C6DOFIMU2_CMD_GYRO_NORMAL 0x15
169 #define C6DOFIMU2_CMD_GYRO_FAST 0x7E
170 #define C6DOFIMU2_CMD_SEL_I2C 0x00
171 #define C6DOFIMU2_CMD_SEL_SPI 0x01
172 
179 // GYRO
180 
181 #define C6DOFIMU2_GYRO_X_L 0x0C
182 #define C6DOFIMU2_GYRO_X_H 0x0D
183 #define C6DOFIMU2_GYRO_Y_L 0x0E
184 #define C6DOFIMU2_GYRO_Y_H 0x0F
185 #define C6DOFIMU2_GYRO_Z_L 0x10
186 #define C6DOFIMU2_GYRO_Z_H 0x11
187 
188 // ACCEL
189 
190 #define C6DOFIMU2_ACCEL_X_L 0x12
191 #define C6DOFIMU2_ACCEL_X_H 0x13
192 #define C6DOFIMU2_ACCEL_Y_L 0x14
193 #define C6DOFIMU2_ACCEL_Y_H 0x15
194 #define C6DOFIMU2_ACCEL_Z_L 0x16
195 #define C6DOFIMU2_ACCEL_Z_H 0x17
196  // End group macro
199 
200 // --------------------------------------------------------------- PUBLIC TYPES
209 typedef uint8_t c6dofimu2_select_t;
210 
214 typedef void ( *c6dofimu2_master_io_t )( struct c6dofimu2_s*, uint8_t, uint8_t*, uint8_t );
215 
219 typedef struct c6dofimu2_s
220 {
221  // Output pins
222 
223  digital_out_t cs;
224 
225  // Input pins
226 
227  digital_in_t int_pin;
228 
229  // Modules
230 
231  i2c_master_t i2c;
232  spi_master_t spi;
233 
234  // ctx variable
235 
236  uint8_t slave_address;
237  pin_name_t chip_select;
241 
243 
247 typedef struct
248 {
249  // Communication gpio pins
250 
251  pin_name_t scl;
252  pin_name_t sda;
253  pin_name_t miso;
254  pin_name_t mosi;
255  pin_name_t sck;
256  pin_name_t cs;
257 
258  // Additional gpio pins
259 
260  pin_name_t int_pin;
261 
262  // static variable
263 
264  uint32_t i2c_speed;
265  uint8_t i2c_address;
266  uint32_t spi_speed;
267  spi_master_mode_t spi_mode;
268  spi_master_chip_select_polarity_t cs_polarity;
269 
271 
273  // End types group
275 
284 typedef struct
285 {
286  int16_t accel_x;
287  int16_t accel_y;
288  int16_t accel_z;
289 
291 
295 typedef struct
296 {
297  int16_t gyro_x;
298  int16_t gyro_y;
299  int16_t gyro_z;
300 
302  // Measurement data
304 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
310 #ifdef __cplusplus
311 extern "C"{
312 #endif
313 
323 
333 
354 
365 void c6dofimu2_generic_write ( c6dofimu2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
366 
377 void c6dofimu2_generic_read ( c6dofimu2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
378 
391 int16_t c6dofimu2_get_axis ( c6dofimu2_t *ctx, uint8_t adr_reg_low, uint8_t adr_reg_high );
392 
402 
412 
413 #ifdef __cplusplus
414 }
415 #endif
416 #endif // _C6DOFIMU2_H_
417  // End public_function group
420 
421 // ------------------------------------------------------------------------- END
gyro_data
c6dofimu2_gyro_data_t gyro_data
Definition: main.c:39
c6dofimu2_gyro_data_t
Gyro data object definition.
Definition: c6dofimu2.h:296
c6dofimu2_default_cfg
void c6dofimu2_default_cfg(c6dofimu2_t *ctx, c6dofimu2_cfg_t *cfg)
Click Default Configuration function.
c6dofimu2_init
C6DOFIMU2_RETVAL c6dofimu2_init(c6dofimu2_t *ctx, c6dofimu2_cfg_t *cfg)
Initialization function.
c6dofimu2_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu2.h:265
c6dofimu2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c6dofimu2.h:267
c6dofimu2_gyro_data_t::gyro_y
int16_t gyro_y
Definition: c6dofimu2.h:298
c6dofimu2_s::master_sel
c6dofimu2_select_t master_sel
Definition: c6dofimu2.h:240
accel_data
c6dofimu2_accel_data_t accel_data
Definition: main.c:38
c6dofimu2_cfg_t
Click configuration structure definition.
Definition: c6dofimu2.h:248
c6dofimu2_s
Click ctx object definition.
Definition: c6dofimu2.h:220
c6dofimu2_accel_data_t::accel_x
int16_t accel_x
Definition: c6dofimu2.h:286
c6dofimu2_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu2.h:254
c6dofimu2_t
struct c6dofimu2_s c6dofimu2_t
Click ctx object definition.
c6dofimu2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu2.h:268
c6dofimu2_accel_data_t::accel_z
int16_t accel_z
Definition: c6dofimu2.h:288
c6dofimu2_accel_data_t
Accel data object definition.
Definition: c6dofimu2.h:285
c6dofimu2_cfg_t::scl
pin_name_t scl
Definition: c6dofimu2.h:251
c6dofimu2_cfg_t::sel
c6dofimu2_select_t sel
Definition: c6dofimu2.h:270
c6dofimu2_get_axis
int16_t c6dofimu2_get_axis(c6dofimu2_t *ctx, uint8_t adr_reg_low, uint8_t adr_reg_high)
Low and high register data function.
c6dofimu2_cfg_t::sck
pin_name_t sck
Definition: c6dofimu2.h:255
c6dofimu2_s::int_pin
digital_in_t int_pin
Definition: c6dofimu2.h:227
c6dofimu2_read_gyro
void c6dofimu2_read_gyro(c6dofimu2_t *ctx, c6dofimu2_gyro_data_t *gyro_data)
Read axis function.
c6dofimu2_generic_read
void c6dofimu2_generic_read(c6dofimu2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
c6dofimu2_cfg_t::sda
pin_name_t sda
Definition: c6dofimu2.h:252
C6DOFIMU2_RETVAL
#define C6DOFIMU2_RETVAL
Definition: c6dofimu2.h:76
c6dofimu2_read_accel
void c6dofimu2_read_accel(c6dofimu2_t *ctx, c6dofimu2_accel_data_t *accel_data)
Read axis function.
c6dofimu2_s::spi
spi_master_t spi
Definition: c6dofimu2.h:232
c6dofimu2_accel_data_t::accel_y
int16_t accel_y
Definition: c6dofimu2.h:287
c6dofimu2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu2.h:264
c6dofimu2_s::read_f
c6dofimu2_master_io_t read_f
Definition: c6dofimu2.h:239
c6dofimu2_s::slave_address
uint8_t slave_address
Definition: c6dofimu2.h:236
c6dofimu2_cfg_setup
void c6dofimu2_cfg_setup(c6dofimu2_cfg_t *cfg)
Config Object Initialization function.
c6dofimu2_gyro_data_t::gyro_x
int16_t gyro_x
Definition: c6dofimu2.h:297
c6dofimu2_cfg_t::cs
pin_name_t cs
Definition: c6dofimu2.h:256
c6dofimu2_cfg_t::miso
pin_name_t miso
Definition: c6dofimu2.h:253
c6dofimu2_s::chip_select
pin_name_t chip_select
Definition: c6dofimu2.h:237
c6dofimu2_s::cs
digital_out_t cs
Definition: c6dofimu2.h:223
c6dofimu2_gyro_data_t::gyro_z
int16_t gyro_z
Definition: c6dofimu2.h:299
c6dofimu2_master_io_t
void(* c6dofimu2_master_io_t)(struct c6dofimu2_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: c6dofimu2.h:214
c6dofimu2_s::write_f
c6dofimu2_master_io_t write_f
Definition: c6dofimu2.h:238
c6dofimu2_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu2.h:266
c6dofimu2_generic_write
void c6dofimu2_generic_write(c6dofimu2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
c6dofimu2_cfg_t::int_pin
pin_name_t int_pin
Definition: c6dofimu2.h:260
c6dofimu2_s::i2c
i2c_master_t i2c
Definition: c6dofimu2.h:231
c6dofimu2_select_t
uint8_t c6dofimu2_select_t
Communication type.
Definition: c6dofimu2.h:209