c6dofimu12  2.0.0.0
c6dofimu12.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 C6DOFIMU12_H
36 #define C6DOFIMU12_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 C6DOFIMU12_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.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
62  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
63 
69 #define C6DOFIMU12_MASTER_I2C 0
70 #define C6DOFIMU12_MASTER_SPI 1
71 
77 #define C6DOFIMU12_RETVAL uint8_t
78 
79 #define C6DOFIMU12_OK 0x00
80 #define C6DOFIMU12_INIT_ERROR 0xFF
81 
87 #define C6DOFIMU12_REG_I2C_ADDR_GND 0x68
88 #define C6DOFIMU12_REG_I2C_ADDR_VCC 0x69
89 
96 #define C6DOFIMU12_REG_CHIP_ID_ADDR 0x00
97 #define C6DOFIMU12_REG_ERROR 0x02
98 #define C6DOFIMU12_REG_STATUS_ADDR 0x03
99 #define C6DOFIMU12_REG_AUX_X_LSB_ADDR 0x04
100 #define C6DOFIMU12_REG_ACC_X_LSB_ADDR 0x0C
101 #define C6DOFIMU12_REG_GYR_X_LSB_ADDR 0x12
102 #define C6DOFIMU12_REG_EVENT_ADDR 0x1B
103 #define C6DOFIMU12_REG_INT_STATUS_0_ADDR 0x1C
104 #define C6DOFIMU12_REG_INT_STATUS_1_ADDR 0x1D
105 #define C6DOFIMU12_REG_SC_OUT_0_ADDR 0x1E
106 #define C6DOFIMU12_REG_SYNC_COMMAND_ADDR 0x1E
107 #define C6DOFIMU12_REG_GYR_CAS_GPIO0_ADDR 0x1E
108 #define C6DOFIMU12_REG_INTERNAL_STATUS_ADDR 0x21
109 #define C6DOFIMU12_REG_FIFO_LENGTH_0_ADDR 0X24
110 #define C6DOFIMU12_REG_FIFO_DATA_ADDR 0X26
111 #define C6DOFIMU12_REG_FEAT_PAGE_ADDR 0x2F
112 #define C6DOFIMU12_REG_FEATURES_REG_ADDR 0x30
113 #define C6DOFIMU12_REG_ACC_CONF_ADDR 0x40
114 #define C6DOFIMU12_REG_GYR_CONF_ADDR 0x42
115 #define C6DOFIMU12_REG_AUX_CONF_ADDR 0x44
116 #define C6DOFIMU12_REG_FIFO_DOWNS_ADDR 0X45
117 #define C6DOFIMU12_REG_FIFO_WTM_0_ADDR 0X46
118 #define C6DOFIMU12_REG_FIFO_WTM_1_ADDR 0X47
119 #define C6DOFIMU12_REG_FIFO_CONFIG_0_ADDR 0X48
120 #define C6DOFIMU12_REG_FIFO_CONFIG_1_ADDR 0X49
121 #define C6DOFIMU12_REG_AUX_DEV_ID_ADDR 0x4B
122 #define C6DOFIMU12_REG_AUX_IF_CONF_ADDR 0x4C
123 #define C6DOFIMU12_REG_AUX_RD_ADDR 0x4D
124 #define C6DOFIMU12_REG_AUX_WR_ADDR 0x4E
125 #define C6DOFIMU12_REG_AUX_WR_DATA_ADDR 0x4F
126 #define C6DOFIMU12_REG_INT1_IO_CTRL_ADDR 0x53
127 #define C6DOFIMU12_REG_INT2_IO_CTRL_ADDR 0x54
128 #define C6DOFIMU12_REG_INT1_MAP_FEAT_ADDR 0x56
129 #define C6DOFIMU12_REG_INT2_MAP_FEAT_ADDR 0x57
130 #define C6DOFIMU12_REG_INT_MAP_DATA_ADDR 0x58
131 #define C6DOFIMU12_REG_INIT_CTRL_ADDR 0x59
132 #define C6DOFIMU12_REG_INIT_ADDR_0 0x5B
133 #define C6DOFIMU12_REG_INIT_ADDR_1 0x5C
134 #define C6DOFIMU12_REG_INIT_DATA_ADDR 0x5E
135 #define C6DOFIMU12_REG_GYR_CRT_CONF_ADDR 0X69
136 #define C6DOFIMU12_REG_NVM_CONF_ADDR 0x6A
137 #define C6DOFIMU12_REG_IF_CONF_ADDR 0X6B
138 #define C6DOFIMU12_REG_ACC_SELF_TEST_ADDR 0X6D
139 #define C6DOFIMU12_REG_GYR_SELF_TEST_AXES_ADDR 0x6E
140 #define C6DOFIMU12_REG_SELF_TEST_MEMS_ADDR 0X6F
141 #define C6DOFIMU12_REG_NV_CONF_ADDR 0x70
142 #define C6DOFIMU12_REG_ACC_OFF_COMP_0_ADDR 0X71
143 #define C6DOFIMU12_REG_GYR_OFF_COMP_3_ADDR 0X74
144 #define C6DOFIMU12_REG_GYR_OFF_COMP_6_ADDR 0X77
145 #define C6DOFIMU12_REG_GYR_USR_GAIN_0_ADDR 0X78
146 #define C6DOFIMU12_REG_PWR_CONF_ADDR 0x7C
147 #define C6DOFIMU12_REG_PWR_CTRL_ADDR 0x7D
148 #define C6DOFIMU12_REG_CMD_REG_ADDR 0x7E
149 
155 #define C6DOFIMU12_DEVICE_ID_VAL 0x24
156 
162 #define C6DOFIMU12_AUX_EN_MASK 0x01
163 #define C6DOFIMU12_GYR_EN_MASK 0x02
164 #define C6DOFIMU12_ACC_EN_MASK 0x04
165 #define C6DOFIMU12_TEMP_EN_MASK 0x08
166 
172 #define C6DOFIMU12_ACC_PWR_OPTIMIZED 0x00
173 #define C6DOFIMU12_ACC_OSR2_PWR_PERFORMANCE 0x80
174 
180 #define C6DOFIMU12_ACC_OSR4_AVG1 0x00
181 #define C6DOFIMU12_ACC_OSR2_AVG2 0x10
182 #define C6DOFIMU12_ACC_NORMAL_AVG4 0x20
183 #define C6DOFIMU12_ACC_CIC_AVG8 0x30
184 #define C6DOFIMU12_ACC_RES_AVG16 0x40
185 #define C6DOFIMU12_ACC_RES_AVG32 0x50
186 #define C6DOFIMU12_ACC_RES_AVG64 0x60
187 #define C6DOFIMU12_ACC_RES_AVG128 0x70
188 
194 #define C6DOFIMU12_ACC_ODR_0_78HZ 0x01
195 #define C6DOFIMU12_ACC_ODR_1_56HZ 0x02
196 #define C6DOFIMU12_ACC_ODR_3_12HZ 0x03
197 #define C6DOFIMU12_ACC_ODR_6_25HZ 0x04
198 #define C6DOFIMU12_ACC_ODR_12_5HZ 0x05
199 #define C6DOFIMU12_ACC_ODR_25HZ 0x06
200 #define C6DOFIMU12_ACC_ODR_50HZ 0x07
201 #define C6DOFIMU12_ACC_ODR_100HZ 0x08
202 #define C6DOFIMU12_ACC_ODR_200HZ 0x09
203 #define C6DOFIMU12_ACC_ODR_400HZ 0x0A
204 #define C6DOFIMU12_ACC_ODR_800HZ 0x0B
205 #define C6DOFIMU12_ACC_ODR_1600HZ 0x0C
206 
212 #define C6DOFIMU12_ACC_RANGE_2G 0x00
213 #define C6DOFIMU12_ACC_RANGE_4G 0x01
214 #define C6DOFIMU12_ACC_RANGE_8G 0x02
215 #define C6DOFIMU12_ACC_RANGE_16G 0x03
216 
222 #define C6DOFIMU12_ACC_RANGE_MASK 0x03
223 #define C6DOFIMU12_ACC_ODR_MASK 0x0F
224 #define C6DOFIMU12_ACC_BW_PARAM_MASK 0x70
225 #define C6DOFIMU12_ACC_FILTER_PERF_MODE_MASK 0x80
226 
231 #define C6DOFIMU12_ACC_BW_PARAM_POS 0x04
232 #define C6DOFIMU12_ACC_FILTER_PERF_MODE_POS 0x07
233 
238 #define C6DOFIMU12_ACC_SELF_TEST_RANGE 16
239 
244 #define C6DOFIMU12_ST_ACC_X_SIG_MIN_DIFF 1800
245 #define C6DOFIMU12_ST_ACC_X_SIG_MAX_DIFF 10200
246 #define C6DOFIMU12_ST_ACC_Y_SIG_MIN_DIFF -10200
247 #define C6DOFIMU12_ST_ACC_Y_SIG_MAX_DIFF -1800
248 #define C6DOFIMU12_ST_ACC_Z_SIG_MIN_DIFF 800
249 #define C6DOFIMU12_ST_ACC_Z_SIG_MAX_DIFF 10200
250 
255 #define C6DOFIMU12_ACC_SELF_TEST_EN_MASK 0x01
256 #define C6DOFIMU12_ACC_SELF_TEST_SIGN_MASK 0x04
257 #define C6DOFIMU12_ACC_SELF_TEST_AMP_MASK 0x08
258 
263 #define C6DOFIMU12_ACC_SELF_TEST_SIGN_POS 0x02
264 #define C6DOFIMU12_ACC_SELF_TEST_AMP_POS 0x03
265 
267 // MASK definition for gyro self test status
268 #define C6DOFIMU12_GYR_ST_AXES_DONE_MASK 0X01
269 #define C6DOFIMU12_GYR_AXIS_X_OK_MASK 0x02
270 #define C6DOFIMU12_GYR_AXIS_Y_OK_MASK 0x04
271 #define C6DOFIMU12_GYR_AXIS_Z_OK_MASK 0x08
272 
273 // Bit position for gyro self test status
274 #define C6DOFIMU12_GYR_AXIS_X_OK_POS 0x01
275 #define C6DOFIMU12_GYR_AXIS_Y_OK_POS 0x02
276 #define C6DOFIMU12_GYR_AXIS_Z_OK_POS 0x03
277 
278 // Gyroscope filter performance mode
279 #define C6DOFIMU12_GYR_PWR_OPTIMIZED 0x00
280 #define C6DOFIMU12_GYR_PWR_PERFORMANCE 0x80
281 
282 // Gyroscope noise performance
283 #define C6DOFIMU12_GYR_NOISE_OPTIMIZED 0x00
284 #define C6DOFIMU12_GYR_NOISE_PERFORMANCE 0x40
285 
286 // Gyroscope parameters
287 #define C6DOFIMU12_GYR_OSR4_MODE 0x00
288 #define C6DOFIMU12_GYR_OSR2_MODE 0x10
289 #define C6DOFIMU12_GYR_NORMAL_MODE 0x20
290 #define C6DOFIMU12_GYR_CIC_MODE 0x30
291 
292 // Gyroscope Output Data Rate
293 #define C6DOFIMU12_GYR_ODR_25HZ 0x06
294 #define C6DOFIMU12_GYR_ODR_50HZ 0x07
295 #define C6DOFIMU12_GYR_ODR_100HZ 0x08
296 #define C6DOFIMU12_GYR_ODR_200HZ 0x09
297 #define C6DOFIMU12_GYR_ODR_400HZ 0x0A
298 #define C6DOFIMU12_GYR_ODR_800HZ 0x0B
299 #define C6DOFIMU12_GYR_ODR_1600HZ 0x0C
300 #define C6DOFIMU12_GYR_ODR_3200HZ 0x0D
301 
302 // Gyroscope OIS Range
303 #define C6DOFIMU12_GYR_OIS_250 0x00
304 #define C6DOFIMU12_GYR_OIS_2000 0x01
305 
306 // Gyroscope Angular Rate Measurement Range
307 #define C6DOFIMU12_GYR_RANGE_2000 0x00
308 #define C6DOFIMU12_GYR_RANGE_1000 0x01
309 #define C6DOFIMU12_GYR_RANGE_500 0x02
310 #define C6DOFIMU12_GYR_RANGE_250 0x03
311 #define C6DOFIMU12_GYR_RANGE_125 0x04
312 
313 // Mask definitions for gyroscope configuration register
314 #define C6DOFIMU12_GYR_RANGE_MASK 0x07
315 #define C6DOFIMU12_GYR_OIS_RANGE_MASK 0x08
316 #define C6DOFIMU12_GYR_ODR_MASK 0x0F
317 #define C6DOFIMU12_GYR_BW_PARAM_MASK 0x30
318 #define C6DOFIMU12_GYR_NOISE_PERF_MODE_MASK 0x40
319 #define C6DOFIMU12_GYR_FILTER_PERF_MODE_MASK 0x80
320 
321 // Bit position definitions for gyroscope configuration register
322 #define C6DOFIMU12_GYR_OIS_RANGE_POS 0x03
323 #define C6DOFIMU12_GYR_BW_PARAM_POS 0x04
324 #define C6DOFIMU12_GYR_NOISE_PERF_MODE_POS 0x06
325 #define C6DOFIMU12_GYR_FILTER_PERF_MODE_POS 0x07
326 
327 // Auxiliary Output Data Rate
328 #define C6DOFIMU12_AUX_ODR_RESERVED 0x00
329 #define C6DOFIMU12_AUX_ODR_0_78HZ 0x01
330 #define C6DOFIMU12_AUX_ODR_1_56HZ 0x02
331 #define C6DOFIMU12_AUX_ODR_3_12HZ 0x03
332 #define C6DOFIMU12_AUX_ODR_6_25HZ 0x04
333 #define C6DOFIMU12_AUX_ODR_12_5HZ 0x05
334 #define C6DOFIMU12_AUX_ODR_25HZ 0x06
335 #define C6DOFIMU12_AUX_ODR_50HZ 0x07
336 #define C6DOFIMU12_AUX_ODR_100HZ 0x08
337 #define C6DOFIMU12_AUX_ODR_200HZ 0x09
338 #define C6DOFIMU12_AUX_ODR_400HZ 0x0A
339 #define C6DOFIMU12_AUX_ODR_800HZ 0x0B
340 
341 // Power mode configuration register
342 #define C6DOFIMU12_PWR_CONF_ADV_PWR_SAVE_DISABLED 0x00
343 #define C6DOFIMU12_PWR_CONF_ADV_PWR_SAVE_ENABLED 0x01
344 #define C6DOFIMU12_FIFO_READ_DISABLED 0x00
345 #define C6DOFIMU12_FIFO_READ_ENABLED 0x02
346 #define C6DOFIMU12_FAST_PWR_UP_DISABLED 0x00
347 #define C6DOFIMU12_FAST_PWR_UP_ENABLED 0x04
348 
349 // Start initialization register
350 #define C6DOFIMU12_CMD_INITIALIZATION_START 0x00
351 #define C6DOFIMU12_CMD_INITIALIZATION_STOP 0x01
352 
353 // Macro to define burst read lengths for both manual and auto modes
354 #define C6DOFIMU12_AUX_READ_LEN_0 0x00
355 #define C6DOFIMU12_AUX_READ_LEN_1 0x01
356 #define C6DOFIMU12_AUX_READ_LEN_2 0x02
357 #define C6DOFIMU12_AUX_READ_LEN_3 0x03
358 
359 // Mask definitions for auxiliary interface configuration register
360 #define C6DOFIMU12_AUX_SET_I2C_ADDR_MASK 0xFE
361 #define C6DOFIMU12_AUX_MAN_MODE_EN_MASK 0x80
362 #define C6DOFIMU12_AUX_FCU_WR_EN_MASK 0x40
363 #define C6DOFIMU12_AUX_MAN_READ_BURST_MASK 0x0C
364 #define C6DOFIMU12_AUX_READ_BURST_MASK 0x03
365 #define C6DOFIMU12_AUX_ODR_EN_MASK 0x0F
366 #define C6DOFIMU12_AUX_OFFSET_READ_OUT_MASK 0xF0
367 
368 // Bit positions for auxiliary interface configuration register
369 #define C6DOFIMU12_AUX_SET_I2C_ADDR_POS 0x01
370 #define C6DOFIMU12_AUX_MAN_MODE_EN_POS 0x07
371 #define C6DOFIMU12_AUX_FCU_WR_EN_POS 0x06
372 #define C6DOFIMU12_AUX_MAN_READ_BURST_POS 0x02
373 #define C6DOFIMU12_AUX_OFFSET_READ_OUT_POS 0x04
374 
375 // FIFO Definitions
376 #define C6DOFIMU12_FIFO_VIRT_FRM_MODE 0x03
377 
378 // FIFO Header Mask definitions
379 #define C6DOFIMU12_FIFO_HEADER_ACC_FRM 0x84
380 #define C6DOFIMU12_FIFO_HEADER_AUX_FRM 0x90
381 #define C6DOFIMU12_FIFO_HEADER_GYR_FRM 0x88
382 #define C6DOFIMU12_FIFO_HEADER_GYR_ACC_FRM 0x8C
383 #define C6DOFIMU12_FIFO_HEADER_AUX_ACC_FRM 0x94
384 #define C6DOFIMU12_FIFO_HEADER_AUX_GYR_FRM 0x98
385 #define C6DOFIMU12_FIFO_HEADER_ALL_FRM 0x9C
386 #define C6DOFIMU12_FIFO_HEADER_SENS_TIME_FRM 0x44
387 #define C6DOFIMU12_FIFO_HEADER_SKIP_FRM 0x40
388 #define C6DOFIMU12_FIFO_HEADER_INPUT_CFG_FRM 0x48
389 #define C6DOFIMU12_FIFO_HEAD_OVER_READ_MSB 0x80
390 #define C6DOFIMU12_FIFO_VIRT_ACT_RECOG_FRM 0xC8
391 
392 // Sensor selection for header-less frames
393 #define C6DOFIMU12_FIFO_HEAD_LESS_ACC_FRM 0x40
394 #define C6DOFIMU12_FIFO_HEAD_LESS_AUX_FRM 0x20
395 #define C6DOFIMU12_FIFO_HEAD_LESS_GYR_FRM 0x80
396 #define C6DOFIMU12_FIFO_HEAD_LESS_GYR_AUX_FRM 0xA0
397 #define C6DOFIMU12_FIFO_HEAD_LESS_GYR_ACC_FRM 0xC0
398 #define C6DOFIMU12_FIFO_HEAD_LESS_AUX_ACC_FRM 0x60
399 #define C6DOFIMU12_FIFO_HEAD_LESS_ALL_FRM 0xE0
400 
401 // Mask definitions for FIFO frame content configuration
402 #define C6DOFIMU12_FIFO_STOP_ON_FULL 0x0001
403 #define C6DOFIMU12_FIFO_TIME_EN 0x0002
404 #define C6DOFIMU12_FIFO_TAG_INT1 0x0300
405 #define C6DOFIMU12_FIFO_TAG_INT2 0x0C00
406 #define C6DOFIMU12_FIFO_HEADER_EN 0x1000
407 #define C6DOFIMU12_FIFO_AUX_EN 0x2000
408 #define C6DOFIMU12_FIFO_ACC_EN 0x4000
409 #define C6DOFIMU12_FIFO_GYR_EN 0x8000
410 #define C6DOFIMU12_FIFO_ALL_EN 0xE000
411 
412 // FIFO sensor data lengths
413 #define C6DOFIMU12_FIFO_ACC_LENGTH 6
414 #define C6DOFIMU12_FIFO_GYR_LENGTH 6
415 #define C6DOFIMU12_FIFO_AUX_LENGTH 8
416 #define C6DOFIMU12_FIFO_ACC_AUX_LENGTH 14
417 #define C6DOFIMU12_FIFO_GYR_AUX_LENGTH 14
418 #define C6DOFIMU12_FIFO_ACC_GYR_LENGTH 12
419 #define C6DOFIMU12_FIFO_ALL_LENGTH 20
420 #define C6DOFIMU12_SENSOR_TIME_LENGTH 3
421 #define C6DOFIMU12_FIFO_CONFIG_LENGTH 2
422 #define C6DOFIMU12_FIFO_WM_LENGTH 2
423 #define C6DOFIMU12_MAX_VALUE_FIFO_FILTER 1
424 #define C6DOFIMU12_FIFO_DATA_LENGTH 2
425 #define C6DOFIMU12_FIFO_LENGTH_MSB_BYTE 1
426 #define C6DOFIMU12_FIFO_INPUT_CFG_LENGTH 4
427 #define C6DOFIMU12_FIFO_SKIP_FRM_LENGTH 1
428 
429 // FIFO sensor virtual data lengths: sensor data plus sensor time
430 #define C6DOFIMU12_FIFO_VIRT_ACC_LENGTH 9
431 #define C6DOFIMU12_FIFO_VIRT_GYR_LENGTH 9
432 #define C6DOFIMU12_FIFO_VIRT_AUX_LENGTH 11
433 #define C6DOFIMU12_FIFO_VIRT_ACC_AUX_LENGTH 17
434 #define C6DOFIMU12_FIFO_VIRT_GYR_AUX_LENGTH 17
435 #define C6DOFIMU12_FIFO_VIRT_ACC_GYR_LENGTH 15
436 #define C6DOFIMU12_FIFO_VIRT_ALL_LENGTH 23
437 
438 // FIFO sensor virtual data lengths: activity recognition
439 #define C6DOFIMU12_FIFO_VIRT_ACT_DATA_LENGTH 6
440 #define C6DOFIMU12_FIFO_VIRT_ACT_TIME_LENGTH 4
441 #define C6DOFIMU12_FIFO_VIRT_ACT_TYPE_LENGTH 1
442 #define C6DOFIMU12_FIFO_VIRT_ACT_STAT_LENGTH 1
443 
444 // FIFO data filter modes
445 #define C6DOFIMU12_FIFO_UNFILTERED_DATA 0
446 #define C6DOFIMU12_FIFO_FILTERED_DATA 1
447 
448 // FIFO frame masks
449 #define C6DOFIMU12_FIFO_LSB_CONFIG_CHECK 0x00
450 #define C6DOFIMU12_FIFO_MSB_CONFIG_CHECK 0x80
451 #define C6DOFIMU12_FIFO_TAG_INTR_MASK 0xFF
452 
453 // Mask definitions of FIFO configuration registers
454 #define C6DOFIMU12_FIFO_CONFIG_0_MASK 0x0003
455 #define C6DOFIMU12_FIFO_CONFIG_1_MASK 0xFF00
456 
457 // FIFO self wake-up mask definition
458 #define C6DOFIMU12_FIFO_SELF_WAKE_UP_MASK 0x02
459 
460 // FIFO down sampling mask definition
461 #define C6DOFIMU12_ACC_FIFO_DOWNS_MASK 0x70
462 #define C6DOFIMU12_GYR_FIFO_DOWNS_MASK 0x07
463 
464 // FIFO down sampling bit positions
465 #define C6DOFIMU12_ACC_FIFO_DOWNS_POS 0x04
466 
467 // FIFO filter mask definition
468 #define C6DOFIMU12_ACC_FIFO_FILT_DATA_MASK 0x80
469 #define C6DOFIMU12_GYR_FIFO_FILT_DATA_MASK 0x08
470 
471 // FIFO filter bit positions
472 #define C6DOFIMU12_ACC_FIFO_FILT_DATA_POS 0x07
473 #define C6DOFIMU12_GYR_FIFO_FILT_DATA_POS 0x03
474 
475 // FIFO byte counter mask definition
476 #define C6DOFIMU12_FIFO_BYTE_COUNTER_MSB_MASK 0x3F
477 
478 // FIFO self wake-up bit positions
479 #define C6DOFIMU12_FIFO_SELF_WAKE_UP_POS 0x02
480 
481 // Mask Definitions for Virtual FIFO frames
482 #define C6DOFIMU12_FIFO_VIRT_FRM_MODE_MASK 0xC0
483 #define C6DOFIMU12_FIFO_VIRT_PAYLOAD_MASK 0x3C
484 
485 // Bit Positions for Virtual FIFO frames
486 #define C6DOFIMU12_FIFO_VIRT_FRM_MODE_POS 0x06
487 #define C6DOFIMU12_FIFO_VIRT_PAYLOAD_POS 0x02
488 
489 // Interrupt Definitions
490 #define C6DOFIMU12_INT_NON_LATCH 0
491 
492 // Permanently latched
493 #define C6DOFIMU12_INT_LATCH 1
494 
495 // Interrupt Pin Behavior
496 #define C6DOFIMU12_INT_PUSH_PULL 0
497 #define C6DOFIMU12_INT_OPEN_DRAIN 1
498 
499 // Interrupt Pin Level
500 #define C6DOFIMU12_INT_ACTIVE_LOW 0
501 #define C6DOFIMU12_INT_ACTIVE_HIGH 1
502 
503 // Interrupt Output Enable
504 #define C6DOFIMU12_INT_OUTPUT_DISABLE 0
505 #define C6DOFIMU12_INT_OUTPUT_ENABLE 1
506 
507 // Interrupt Input Enable
508 #define C6DOFIMU12_INT_INPUT_DISABLE 0
509 #define C6DOFIMU12_INT_INPUT_ENABLE 1
510 
511 // Mask definitions for interrupt pin configuration
512 #define C6DOFIMU12_INT_LATCH_MASK 0x01
513 #define C6DOFIMU12_INT_LEVEL_MASK 0x02
514 #define C6DOFIMU12_INT_OPEN_DRAIN_MASK 0x04
515 #define C6DOFIMU12_INT_OUTPUT_EN_MASK 0x08
516 #define C6DOFIMU12_INT_INPUT_EN_MASK 0x10
517 
518 // Bit position definitions for interrupt pin configuration
519 #define C6DOFIMU12_INT_LEVEL_POS 0x01
520 #define C6DOFIMU12_INT_OPEN_DRAIN_POS 0x02
521 #define C6DOFIMU12_INT_OUTPUT_EN_POS 0x03
522 #define C6DOFIMU12_INT_INPUT_EN_POS 0x04
523 
524 // Mask definitions for data interrupt mapping
525 #define C6DOFIMU12_FFULL_INT 0x01
526 #define C6DOFIMU12_FWM_INT 0x02
527 #define C6DOFIMU12_DRDY_INT 0x04
528 #define C6DOFIMU12_ERR_INT 0x08
529 
530 // Mask definitions for data interrupt status bits
531 #define C6DOFIMU12_FFULL_INT_STATUS_MASK 0x0100
532 #define C6DOFIMU12_FWM_INT_STATUS_MASK 0x0200
533 #define C6DOFIMU12_ERR_INT_STATUS_MASK 0x0400
534 #define C6DOFIMU12_AUX_DRDY_INT_MASK 0x2000
535 #define C6DOFIMU12_GYR_DRDY_INT_MASK 0x4000
536 #define C6DOFIMU12_ACC_DRDY_INT_MASK 0x8000
537 
538 // Maximum number of interrupt pins
539 #define C6DOFIMU12_INT_PIN_MAX_NUM 2
540 
541 // Macro for mapping feature interrupts
542 #define C6DOFIMU12_FEAT_BIT_DISABLE 0
543 #define C6DOFIMU12_FEAT_BIT0 1
544 #define C6DOFIMU12_FEAT_BIT1 2
545 #define C6DOFIMU12_FEAT_BIT2 3
546 #define C6DOFIMU12_FEAT_BIT3 4
547 #define C6DOFIMU12_FEAT_BIT4 5
548 #define C6DOFIMU12_FEAT_BIT5 6
549 #define C6DOFIMU12_FEAT_BIT6 7
550 #define C6DOFIMU12_FEAT_BIT7 8
551 #define C6DOFIMU12_FEAT_BIT_MAX 9
552 
553 // OIS Interface configuration register
554 #define C6DOFIMU12_OIS_IF_EN_MASK 0x10
555 #define C6DOFIMU12_AUX_IF_EN_MASK 0x20
556 
557 // Bit positions for OIS interface enable
558 #define C6DOFIMU12_OIS_IF_EN_POS 0x04
559 #define C6DOFIMU12_AUX_IF_EN_POS 0x05
560 
561 // Macros for the user-defined values of axes and their polarities
562 #define C6DOFIMU12_X 0x01
563 #define C6DOFIMU12_NEG_X 0x09
564 #define C6DOFIMU12_Y 0x02
565 #define C6DOFIMU12_NEG_Y 0x0A
566 #define C6DOFIMU12_Z 0x04
567 #define C6DOFIMU12_NEG_Z 0x0C
568 #define C6DOFIMU12_AXIS_MASK 0x07
569 #define C6DOFIMU12_AXIS_SIGN 0x08
570 
571 // Mask definitions of gyroscope offset compensation registers
572 #define C6DOFIMU12_GYR_GAIN_EN_MASK 0x80
573 #define C6DOFIMU12_GYR_OFF_COMP_EN_MASK 0x40
574 
575 // Bit positions of gyroscope offset compensation registers
576 #define C6DOFIMU12_GYR_OFF_COMP_EN_POS 0x06
577 
578 // Mask definitions of gyroscope user-gain registers
579 #define C6DOFIMU12_GYR_USR_GAIN_X_MASK 0x7F
580 #define C6DOFIMU12_GYR_USR_GAIN_Y_MASK 0x7F
581 #define C6DOFIMU12_GYR_USR_GAIN_Z_MASK 0x7F
582 
583 // Bit positions of gyroscope offset compensation registers
584 #define C6DOFIMU12_GYR_GAIN_EN_POS 0x07
585 
586 // Macro Definitions for internal status
587 #define C6DOFIMU12_NOT_INIT 0x00
588 #define C6DOFIMU12_INIT_OK 0x01
589 #define C6DOFIMU12_INIT_ERR 0x02
590 #define C6DOFIMU12_DRV_ERR 0x03
591 #define C6DOFIMU12_SNS_STOP 0x04
592 #define C6DOFIMU12_NVM_ERROR 0x05
593 #define C6DOFIMU12_START_UP_ERROR 0x06
594 #define C6DOFIMU12_COMPAT_ERROR 0x07
595 #define C6DOFIMU12_VFM_SKIPPED 0x10
596 #define C6DOFIMU12_AXES_MAP_ERROR 0x20
597 #define C6DOFIMU12_ODR_50_HZ_ERROR 0x40
598 #define C6DOFIMU12_ODR_HIGH_ERROR 0x80
599 
600 // Error status form gyro gain update status
601 #define C6DOFIMU12_G_TRIGGER_NO_ERROR 0x00
602 #define C6DOFIMU12_G_TRIGGER_PRECON_ERROR 0x01
603 #define C6DOFIMU12_G_TRIGGER_DL_ERROR 0x02
604 #define C6DOFIMU12_G_TRIGGER_ABORT_ERROR 0x03
605 
606 // Variant specific features selection
607 #define C6DOFIMU12_CRT_RTOSK_ENABLE 0x01
608 #define C6DOFIMU12_GYRO_CROSS_SENS_ENABLE 0x02
609 #define C6DOFIMU12_GYRO_USER_GAIN_ENABLE 0x08
610 #define C6DOFIMU12_NO_FEATURE_ENABLE 0x00
611 #define C6DOFIMU12_CRT_IN_FIFO_NOT_REQ 0x10
612 #define C6DOFIMU12_MINIMAL_VARIANT 0x20
613 
614 // Check error
615 #define C6DOFIMU12_ERROR 0x00
616 #define C6DOFIMU12_SUCCESS 0x01
617 
621 #define C6DOFIMU12_SPI_CMD_WRITE 0x00
622 #define C6DOFIMU12_SPI_CMD_READ 0x80
623 #define C6DOFIMU12_SPI_COMMUNICATION_DUMMY 0x00
624  // End group macro
627 // --------------------------------------------------------------- PUBLIC TYPES
636 typedef uint8_t c6dofimu12_select_t;
637 
641 typedef void ( *c6dofimu12_master_io_t )( struct c6dofimu12_s*, uint8_t, uint8_t*, uint16_t );
642 
646 typedef struct c6dofimu12_s
647 {
648  // Input pins
649 
650  digital_out_t cs;
651  digital_in_t pwm;
652  digital_in_t int_pin;
653 
654  // Modules
655 
656  i2c_master_t i2c;
657  spi_master_t spi;
658 
659  // ctx variable
660 
661  uint8_t slave_address;
662  pin_name_t chip_select;
667 
668 typedef struct c6dofimu12_accel_t
669 {
670  int16_t x;
671  int16_t y;
672  int16_t z;
674 
675 typedef struct c6dofimu12_gyro_t
676 {
677  int16_t x;
678  int16_t y;
679  int16_t z;
681 
685 typedef struct
686 {
687  // Communication gpio pins
688 
689  pin_name_t scl;
690  pin_name_t sda;
691  pin_name_t miso;
692  pin_name_t mosi;
693  pin_name_t sck;
694  pin_name_t cs;
695 
696  // Additional gpio pins
697 
698  pin_name_t pwm;
699  pin_name_t int_pin;
700 
701  // static variable
702 
703  uint32_t i2c_speed;
704  uint8_t i2c_address;
705 
706  uint32_t spi_speed;
707  spi_master_mode_t spi_mode;
708  spi_master_chip_select_polarity_t cs_polarity;
709 
711 
713  // End types group
715 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
721 #ifdef __cplusplus
722 extern "C"{
723 #endif
724 
734 
744 
753 
764 void c6dofimu12_generic_write ( c6dofimu12_t *ctx, uint8_t reg, uint8_t *data_buf, uint16_t len );
765 
776 void c6dofimu12_generic_read ( c6dofimu12_t *ctx, uint8_t reg, uint8_t *data_buf, uint16_t len );
777 
792 
807 
823 
824 
836 
837 
849 
850 
851 #ifdef __cplusplus
852 }
853 #endif
854 #endif // _C6DOFIMU12_H_
855  // End public_function group
858 
859 // ------------------------------------------------------------------------- END
c6dofimu12_s::cs
digital_out_t cs
Definition: c6dofimu12.h:650
c6dofimu12_s::spi
spi_master_t spi
Definition: c6dofimu12.h:657
c6dofimu12_cfg_t::int_pin
pin_name_t int_pin
Definition: c6dofimu12.h:699
c6dofimu12_gyro_t::z
int16_t z
Definition: c6dofimu12.h:679
c6dofimu12_s::master_sel
c6dofimu12_select_t master_sel
Definition: c6dofimu12.h:665
c6dofimu12_check_int1
C6DOFIMU12_RETVAL c6dofimu12_check_int1(c6dofimu12_t *ctx)
Get interrupt 1 status function.
c6dofimu12_gyro_t::x
int16_t x
Definition: c6dofimu12.h:677
c6dofimu12_t
struct c6dofimu12_s c6dofimu12_t
Click ctx object definition.
c6dofimu12_init
C6DOFIMU12_RETVAL c6dofimu12_init(c6dofimu12_t *ctx, c6dofimu12_cfg_t *cfg)
Initialization function.
c6dofimu12_select_t
uint8_t c6dofimu12_select_t
Communication type.
Definition: c6dofimu12.h:636
c6dofimu12_cfg_t::cs
pin_name_t cs
Definition: c6dofimu12.h:694
c6dofimu12_accel_t
struct c6dofimu12_accel_t c6dofimu12_accel_t
c6dofimu12_cfg_t
Click configuration structure definition.
Definition: c6dofimu12.h:686
c6dofimu12_s::pwm
digital_in_t pwm
Definition: c6dofimu12.h:651
c6dofimu12_cfg_t::sda
pin_name_t sda
Definition: c6dofimu12.h:690
c6dofimu12_get_data
void c6dofimu12_get_data(c6dofimu12_t *ctx, c6dofimu12_accel_t *accel_data, c6dofimu12_gyro_t *gyro_data)
Read Accel and Gyro data function.
c6dofimu12_check_int2
C6DOFIMU12_RETVAL c6dofimu12_check_int2(c6dofimu12_t *ctx)
Get interrupt 2 status function.
c6dofimu12_s::slave_address
uint8_t slave_address
Definition: c6dofimu12.h:661
c6dofimu12_s::write_f
c6dofimu12_master_io_t write_f
Definition: c6dofimu12.h:663
c6dofimu12_generic_read
void c6dofimu12_generic_read(c6dofimu12_t *ctx, uint8_t reg, uint8_t *data_buf, uint16_t len)
Generic read function.
C6DOFIMU12_RETVAL
#define C6DOFIMU12_RETVAL
Definition: c6dofimu12.h:77
c6dofimu12_cfg_t::i2c_address
uint8_t i2c_address
Definition: c6dofimu12.h:704
c6dofimu12_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu12.h:706
c6dofimu12_accel_t::z
int16_t z
Definition: c6dofimu12.h:672
c6dofimu12_accel_t::y
int16_t y
Definition: c6dofimu12.h:671
c6dofimu12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c6dofimu12.h:703
c6dofimu12_check_id
C6DOFIMU12_RETVAL c6dofimu12_check_id(c6dofimu12_t *ctx)
Check ID function.
c6dofimu12_s::chip_select
pin_name_t chip_select
Definition: c6dofimu12.h:662
c6dofimu12_check_init_status
C6DOFIMU12_RETVAL c6dofimu12_check_init_status(c6dofimu12_t *ctx)
Check ID function.
c6dofimu12_cfg_setup
void c6dofimu12_cfg_setup(c6dofimu12_cfg_t *cfg)
Config Object Initialization function.
c6dofimu12_cfg_t::miso
pin_name_t miso
Definition: c6dofimu12.h:691
c6dofimu12_gyro_t
struct c6dofimu12_gyro_t c6dofimu12_gyro_t
c6dofimu12_cfg_t::scl
pin_name_t scl
Definition: c6dofimu12.h:689
c6dofimu12_accel_t
Definition: c6dofimu12.h:669
c6dofimu12_cfg_t::sck
pin_name_t sck
Definition: c6dofimu12.h:693
c6dofimu12_generic_write
void c6dofimu12_generic_write(c6dofimu12_t *ctx, uint8_t reg, uint8_t *data_buf, uint16_t len)
Generic write function.
c6dofimu12_gyro_t::y
int16_t y
Definition: c6dofimu12.h:678
c6dofimu12_s::i2c
i2c_master_t i2c
Definition: c6dofimu12.h:656
c6dofimu12_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu12.h:708
c6dofimu12_master_io_t
void(* c6dofimu12_master_io_t)(struct c6dofimu12_s *, uint8_t, uint8_t *, uint16_t)
Master Input/Output type.
Definition: c6dofimu12.h:641
c6dofimu12_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c6dofimu12.h:707
c6dofimu12_s::read_f
c6dofimu12_master_io_t read_f
Definition: c6dofimu12.h:664
c6dofimu12_s
Click ctx object definition.
Definition: c6dofimu12.h:647
c6dofimu12_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu12.h:692
c6dofimu12_cfg_t::sel
c6dofimu12_select_t sel
Definition: c6dofimu12.h:710
c6dofimu12_default_cfg
void c6dofimu12_default_cfg(c6dofimu12_t *ctx)
Click Default Configuration function.
c6dofimu12_s::int_pin
digital_in_t int_pin
Definition: c6dofimu12.h:652
c6dofimu12_cfg_t::pwm
pin_name_t pwm
Definition: c6dofimu12.h:698
c6dofimu12_gyro_t
Definition: c6dofimu12.h:676
c6dofimu12_accel_t::x
int16_t x
Definition: c6dofimu12.h:670