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