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  // c6dofimu23_reg
121 
136 #define C6DOFIMU23_FIXED_VALUE 0xAA55
137 
142 #define C6DOFIMU23_DATA_RESOLUTION 32768.0f
143 #define C6DOFIMU23_ACCEL_FS_DEFAULT 16.384f
144 #define C6DOFIMU23_GYRO_FS_DEFAULT 655.36f
145 #define C6DOFIMU23_TEMP_DATA_RESOLUTION 20.0f
146 #define C6DOFIMU23_TEMP_DATA_OFFSET 25.0f
147 
156 #define C6DOFIMU23_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
157 #define C6DOFIMU23_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
158  // c6dofimu23_set
160 
175 #define C6DOFIMU23_MAP_MIKROBUS( cfg, mikrobus ) \
176  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
177  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
178  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
179  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
180  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
181  cfg.odr = MIKROBUS( mikrobus, MIKROBUS_INT )
182  // c6dofimu23_map // c6dofimu23
185 
190 typedef struct
191 {
192  // Output pins
193  digital_out_t rst;
195  // Input pins
196  digital_in_t odr;
198  // Modules
199  spi_master_t spi;
201  pin_name_t chip_select;
203  float acc_fs;
204  float gyro_fs;
206 } c6dofimu23_t;
207 
212 typedef struct
213 {
214  // Communication gpio pins
215  pin_name_t miso;
216  pin_name_t mosi;
217  pin_name_t sck;
218  pin_name_t cs;
220  // Additional gpio pins
221  pin_name_t rst;
222  pin_name_t odr;
225  // static variable
226  uint32_t spi_speed;
227  spi_master_mode_t spi_mode;
228  spi_master_chip_select_polarity_t cs_polarity;
231 
236 typedef struct
237 {
238  float x;
239  float y;
240  float z;
243 
248 typedef enum
249 {
251  C6DOFIMU23_ERROR = -1
252 
254 
271 
286 
300 
313 err_t c6dofimu23_reg_write ( c6dofimu23_t *ctx, uint8_t address, uint16_t data_in );
314 
327 err_t c6dofimu23_reg_read ( c6dofimu23_t *ctx, uint8_t address, uint16_t *data_out );
328 
340 
350 
360 
373 
388 
403 
417 err_t c6dofimu23_get_temperature ( c6dofimu23_t *ctx, float *temperature );
418 
419 #ifdef __cplusplus
420 }
421 #endif
422 #endif // C6DOFIMU23_H
423  // c6dofimu23
425 
426 // ------------------------------------------------------------------------ END
c6dofimu23_return_value_t
c6dofimu23_return_value_t
6DOF IMU 23 Click return value data.
Definition: c6dofimu23.h:249
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:227
spi_specifics.h
This file contains SPI specific macros, functions, etc.
c6dofimu23_axis_t::y
float y
Definition: c6dofimu23.h:239
c6dofimu23_t::spi
spi_master_t spi
Definition: c6dofimu23.h:199
c6dofimu23_cfg_t
6DOF IMU 23 Click configuration object.
Definition: c6dofimu23.h:213
c6dofimu23_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: c6dofimu23.h:228
c6dofimu23_get_temperature
err_t c6dofimu23_get_temperature(c6dofimu23_t *ctx, float *temperature)
6DOF IMU 23 get the internal temperature function.
c6dofimu23_axis_t
6DOF IMU 23 Click axes data structure.
Definition: c6dofimu23.h:237
c6dofimu23_t::chip_select
pin_name_t chip_select
Definition: c6dofimu23.h:201
c6dofimu23_reg_read
err_t c6dofimu23_reg_read(c6dofimu23_t *ctx, uint8_t address, uint16_t *data_out)
6DOF IMU 23 reg read function.
c6dofimu23_cfg_t::miso
pin_name_t miso
Definition: c6dofimu23.h:215
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:217
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 get odr function.
c6dofimu23_axis_t::z
float z
Definition: c6dofimu23.h:240
c6dofimu23_t
6DOF IMU 23 Click context object.
Definition: c6dofimu23.h:191
c6dofimu23_check_communication
err_t c6dofimu23_check_communication(c6dofimu23_t *ctx)
6DOF IMU 23 check communication function.
c6dofimu23_cfg_t::odr
pin_name_t odr
Definition: c6dofimu23.h:222
C6DOFIMU23_OK
@ C6DOFIMU23_OK
Definition: c6dofimu23.h:250
c6dofimu23_cfg_t::rst
pin_name_t rst
Definition: c6dofimu23.h:221
c6dofimu23_cfg_t::mosi
pin_name_t mosi
Definition: c6dofimu23.h:216
C6DOFIMU23_ERROR
@ C6DOFIMU23_ERROR
Definition: c6dofimu23.h:251
c6dofimu23_cfg_t::spi_speed
uint32_t spi_speed
Definition: c6dofimu23.h:226
c6dofimu23_cfg_t::cs
pin_name_t cs
Definition: c6dofimu23.h:218
c6dofimu23_t::acc_fs
float acc_fs
Definition: c6dofimu23.h:203
c6dofimu23_init
err_t c6dofimu23_init(c6dofimu23_t *ctx, c6dofimu23_cfg_t *cfg)
6DOF IMU 23 initialization function.
c6dofimu23_device_disable
void c6dofimu23_device_disable(c6dofimu23_t *ctx)
6DOF IMU 23 device disable function.
c6dofimu23_t::odr
digital_in_t odr
Definition: c6dofimu23.h:196
c6dofimu23_reg_write
err_t c6dofimu23_reg_write(c6dofimu23_t *ctx, uint8_t address, uint16_t data_in)
6DOF IMU 23 reg write function.
c6dofimu23_default_cfg
err_t c6dofimu23_default_cfg(c6dofimu23_t *ctx)
6DOF IMU 23 default configuration function.
c6dofimu23_t::gyro_fs
float gyro_fs
Definition: c6dofimu23.h:204
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:193
c6dofimu23_axis_t::x
float x
Definition: c6dofimu23.h:238