c6dofimu23  2.1.0.0
c6dofimu23.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef C6DOFIMU23_H
29 #define C6DOFIMU23_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define C6DOFIMU23_OFFSET_X_DATA 0x00
71 #define C6DOFIMU23_OFFSET_Y_DATA 0x01
72 #define C6DOFIMU23_OFFSET_Z_DATA 0x02
73 #define C6DOFIMU23_OFFSET_TEMPERATURE_1 0x03
74 #define C6DOFIMU23_OFFSET_ACCEL_X_DATA 0x04
75 #define C6DOFIMU23_OFFSET_ACCEL_Y_DATA 0x05
76 #define C6DOFIMU23_OFFSET_ACCEL_Z_DATA 0x06
77 #define C6DOFIMU23_OFFSET_TEMPERATURE_2 0x07
78 #define C6DOFIMU23_OFFSET_LR_ACCEL_X_DATA 0x08
79 #define C6DOFIMU23_OFFSET_LR_ACCEL_Y_DATA 0x09
80 #define C6DOFIMU23_OFFSET_LR_ACCEL_Z_DATA 0x0A
81 #define C6DOFIMU23_OFFSET_FIXED_VALUE 0x0B
82 #define C6DOFIMU23_OFFSET_FILTER_SETTINGS_YZ 0x0C
83 #define C6DOFIMU23_OFFSET_FILTER_SETTINGS_X 0x0E
84 #define C6DOFIMU23_OFFSET_TEMPERATURE_DIF 0x0F
85 #define C6DOFIMU23_OFFSET_DC_TRIGGER 0x16
86 #define C6DOFIMU23_OFFSET_TEST 0x17
87 #define C6DOFIMU23_OFFSET_RESET 0x18
88 #define C6DOFIMU23_OFFSET_MODE 0x19
89 #define C6DOFIMU23_OFFSET_ID 0x1B
90 #define C6DOFIMU23_OFFSET_HW_REV 0x1C
91 #define C6DOFIMU23_OFFSET_ID_CODE_3 0x1D
92 #define C6DOFIMU23_OFFSET_ID_CODE_4 0x1E
93 #define C6DOFIMU23_OFFSET_BANK_SELECTION 0x1F
94 
99 #define C6DOFIMU23_OFFSET_SELF_TEST_ACCEL 0x11
100 #define C6DOFIMU23_OFFSET_SELF_TEST_GYRO 0x12
101 #define C6DOFIMU23_OFFSET_WHO_AM_I 0x0E
102 
107 #define C6DOFIMU23_OFFSET_ODR_CFG_1 0x11
108 #define C6DOFIMU23_OFFSET_ODR_CFG_2 0x13
109 #define C6DOFIMU23_OFFSET_ODR_CFG_3 0x14
110 #define C6DOFIMU23_OFFSET_ODR_CFG_4 0x14
111 #define C6DOFIMU23_OFFSET_ODR_CFG_5 0x15
112 #define C6DOFIMU23_OFFSET_ODR_CFG_6 0x16
113 
118 #define C6DOFIMU23_OFFSET_SENSITIVITY_CFG 0x14
119 
124 #define C6DOFIMU23_CMD_SET_BANK_0 0xFC000064ul
125 #define C6DOFIMU23_CMD_ACCEL_DC_TRIGGER_POS 0xD8000834ul
126 #define C6DOFIMU23_CMD_ACCEL_DC_TRIGGER_NEG 0xD800102Cul
127 #define C6DOFIMU23_CMD_GYRO_DC_TRIGGER_POS 0xD80080BCul
128 #define C6DOFIMU23_CMD_GYRO_DC_TRIGGER_NEG 0xD8010021ul
129 #define C6DOFIMU23_CMD_DC_TRIGGER_RST 0xD800003Cul
130 #define C6DOFIMU23_CMD_ACCEL_X_DATA 0x10000045ul
131 #define C6DOFIMU23_CMD_ACCEL_Y_DATA 0x14000068ul
132 #define C6DOFIMU23_CMD_ACCEL_Z_DATA 0x1800001Ful
133 #define C6DOFIMU23_CMD_GYRO_X_DATA 0x000000F1ul
134 #define C6DOFIMU23_CMD_GYRO_Y_DATA 0x040000DCul
135 #define C6DOFIMU23_CMD_GYRO_Z_DATA 0x080000ABul
136 #define C6DOFIMU23_CMD_DUMMY 0x5C0000D8ul
137  // c6dofimu23_reg
139 
154 #define C6DOFIMU23_DATA_RESOLUTION 32768.0f
155 #define C6DOFIMU23_ACCEL_FS_DEFAULT 16.384f
156 #define C6DOFIMU23_GYRO_FS_DEFAULT 655.36f
157 
166 #define C6DOFIMU23_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
167 #define C6DOFIMU23_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
168  // c6dofimu23_set
170 
185 #define C6DOFIMU23_MAP_MIKROBUS( cfg, mikrobus ) \
186  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
187  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
188  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
189  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
190  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
191  cfg.odr = MIKROBUS( mikrobus, MIKROBUS_INT )
192  // c6dofimu23_map // c6dofimu23
195 
200 typedef struct
201 {
202  // Output pins
203  digital_out_t rst;
205  // Input pins
206  digital_in_t odr;
208  // Modules
209  spi_master_t spi;
211  pin_name_t chip_select;
213  float acc_fs;
214  float gyro_fs;
216 } c6dofimu23_t;
217 
222 typedef struct
223 {
224  // Communication gpio pins
225  pin_name_t miso;
226  pin_name_t mosi;
227  pin_name_t sck;
228  pin_name_t cs;
230  // Additional gpio pins
231  pin_name_t rst;
232  pin_name_t odr;
235  // static variable
236  uint32_t spi_speed;
237  spi_master_mode_t spi_mode;
238  spi_master_chip_select_polarity_t cs_polarity;
241 
246 typedef struct
247 {
248  float x;
249  float y;
250  float z;
253 
258 typedef enum
259 {
261  C6DOFIMU23_ERROR = -1
262 
264 
281 
296 
306 
319 
334 err_t c6dofimu23_generic_write ( c6dofimu23_t *ctx, uint8_t offset, uint8_t *data_in, uint8_t len );
335 
350 err_t c6dofimu23_generic_read ( c6dofimu23_t *ctx, uint8_t offset, uint8_t *data_out, uint8_t len );
351 
365 err_t c6dofimu23_write_prtcl ( c6dofimu23_t *ctx, uint8_t *data_in );
366 
381 err_t c6dofimu23_read_prtcl ( c6dofimu23_t *ctx, uint8_t *data_in, uint16_t *data_out );
382 
396 err_t c6dofimu23_cmd_write ( c6dofimu23_t *ctx, uint32_t cmd );
397 
412 err_t c6dofimu23_cmd_read ( c6dofimu23_t *ctx, uint32_t cmd, uint16_t *data_out );
413 
428 
443 
444 #ifdef __cplusplus
445 }
446 #endif
447 #endif // C6DOFIMU23_H
448  // c6dofimu23
450 
451 // ------------------------------------------------------------------------ END
c6dofimu23_return_value_t
c6dofimu23_return_value_t
6DOF IMU 23 Click return value data.
Definition: c6dofimu23.h:259
c6dofimu23_device_enable
void c6dofimu23_device_enable(c6dofimu23_t *ctx)
6DOF IMU 23 device enable function.
c6dofimu23_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: c6dofimu23.h:237
c6dofimu23_generic_read
err_t c6dofimu23_generic_read(c6dofimu23_t *ctx, uint8_t offset, uint8_t *data_out, uint8_t len)
6DOF IMU 23 data reading function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
c6dofimu23_axis_t::y
float y
Definition: c6dofimu23.h:249
c6dofimu23_t::spi
spi_master_t spi
Definition: c6dofimu23.h:209
c6dofimu23_cfg_t
6DOF IMU 23 Click configuration object.
Definition: c6dofimu23.h:223
c6dofimu23_generic_write
err_t c6dofimu23_generic_write(c6dofimu23_t *ctx, uint8_t offset, uint8_t *data_in, uint8_t len)
6DOF IMU 23 data writing function.
c6dofimu23_cmd_write
err_t c6dofimu23_cmd_write(c6dofimu23_t *ctx, uint32_t cmd)
6DOF IMU 23 command writing function.
c6dofimu23_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu23.h:238
c6dofimu23_axis_t
6DOF IMU 23 Click axes data structure.
Definition: c6dofimu23.h:247
c6dofimu23_t::chip_select
pin_name_t chip_select
Definition: c6dofimu23.h:211
c6dofimu23_cfg_t::miso
pin_name_t miso
Definition: c6dofimu23.h:225
c6dofimu23_cfg_setup
void c6dofimu23_cfg_setup(c6dofimu23_cfg_t *cfg)
6DOF IMU 23 configuration object setup function.
c6dofimu23_cfg_t::sck
pin_name_t sck
Definition: c6dofimu23.h:227
c6dofimu23_get_accel_data
err_t c6dofimu23_get_accel_data(c6dofimu23_t *ctx, c6dofimu23_axis_t *acc_axis)
6DOF IMU 23 get the accel sensor axes function.
c6dofimu23_get_odr
uint8_t c6dofimu23_get_odr(c6dofimu23_t *ctx)
6DOF IMU 23 device enable function.
c6dofimu23_axis_t::z
float z
Definition: c6dofimu23.h:250
c6dofimu23_t
6DOF IMU 23 Click context object.
Definition: c6dofimu23.h:201
c6dofimu23_write_prtcl
err_t c6dofimu23_write_prtcl(c6dofimu23_t *ctx, uint8_t *data_in)
6DOF IMU 23 data writing protocol function.
c6dofimu23_cfg_t::odr
pin_name_t odr
Definition: c6dofimu23.h:232
C6DOFIMU23_OK
@ C6DOFIMU23_OK
Definition: c6dofimu23.h:260
c6dofimu23_cfg_t::rst
pin_name_t rst
Definition: c6dofimu23.h:231
c6dofimu23_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu23.h:226
C6DOFIMU23_ERROR
@ C6DOFIMU23_ERROR
Definition: c6dofimu23.h:261
c6dofimu23_read_prtcl
err_t c6dofimu23_read_prtcl(c6dofimu23_t *ctx, uint8_t *data_in, uint16_t *data_out)
6DOF IMU 23 data reading protocol function.
c6dofimu23_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu23.h:236
c6dofimu23_cfg_t::cs
pin_name_t cs
Definition: c6dofimu23.h:228
c6dofimu23_t::acc_fs
float acc_fs
Definition: c6dofimu23.h:213
c6dofimu23_init
err_t c6dofimu23_init(c6dofimu23_t *ctx, c6dofimu23_cfg_t *cfg)
6DOF IMU 23 initialization function.
c6dofimu23_t::odr
digital_in_t odr
Definition: c6dofimu23.h:206
c6dofimu23_t::gyro_fs
float gyro_fs
Definition: c6dofimu23.h:214
c6dofimu23_get_gyro_data
err_t c6dofimu23_get_gyro_data(c6dofimu23_t *ctx, c6dofimu23_axis_t *gyro_axis)
6DOF IMU 23 get the gyro sensor axes function.
c6dofimu23_t::rst
digital_out_t rst
Definition: c6dofimu23.h:203
c6dofimu23_cmd_read
err_t c6dofimu23_cmd_read(c6dofimu23_t *ctx, uint32_t cmd, uint16_t *data_out)
6DOF IMU 23 command reading function.
c6dofimu23_axis_t::x
float x
Definition: c6dofimu23.h:248