gyro7  2.0.0.0
gyro7.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 GYRO7_H
29 #define GYRO7_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define GYRO7_REG_DLPF_B1_H_Y_AXIS 0x02
75 #define GYRO7_REG_DLPF_B1_L_Y_AXIS 0x09
76 #define GYRO7_REG_DLPF_B0B2_H_X_AXIS 0x0E
77 #define GYRO7_REG_DLPF_B0B2_L_X_AXIS 0x0F
78 #define GYRO7_REG_DLPF_B1_H_X_AXIS 0x10
79 #define GYRO7_REG_DLPF_B1_L_X_AXIS 0x11
80 #define GYRO7_REG_DLPF_B0B2_H_Y_AXIS 0x12
81 #define GYRO7_REG_XG_OFFS_USRH 0x13
82 #define GYRO7_REG_XG_OFFS_USRL 0x14
83 #define GYRO7_REG_YG_OFFS_USRH 0x15
84 #define GYRO7_REG_YG_OFFS_USRL 0x16
85 #define GYRO7_REG_SMPLRT_DIV 0x19
86 #define GYRO7_REG_CONFIG 0x1A
87 #define GYRO7_REG_GYRO_CONFIG 0x1B
88 #define GYRO7_REG_HPF_DLPF_RST_AZ 0x26
89 #define GYRO7_REG_INT_PIN_CFG 0x37
90 #define GYRO7_REG_INT_ENABLE 0x38
91 #define GYRO7_REG_INT_STATUS 0x3A
92 #define GYRO7_REG_TEMP_OUT_H 0x41
93 #define GYRO7_REG_TEMP_OUT_L 0x42
94 #define GYRO7_REG_GYRO_XOUT_H 0x43
95 #define GYRO7_REG_GYRO_XOUT_L 0x44
96 #define GYRO7_REG_GYRO_YOUT_H 0x45
97 #define GYRO7_REG_GYRO_YOUT_L 0x46
98 #define GYRO7_REG_USER_CTRL 0x6A
99 #define GYRO7_REG_PWR_MGMT_1 0x6B
100 #define GYRO7_REG_DLPF_B0B2_L_Y_AXIS 0x70
101 #define GYRO7_REG_DLPF_A1_H 0x71
102 #define GYRO7_REG_DLPF_A1_L 0x72
103 #define GYRO7_REG_DLPF_A2_H 0x73
104 #define GYRO7_REG_DLPF_A2_L 0x74
105 #define GYRO7_REG_WHO_AM_I 0x75
106 #define GYRO7_REG_SPI_SEL 0x76
107  // gyro7_reg
109 
124 #define GYRO7_DLPF_B0B2_40_160_HZ 0x0004
125 #define GYRO7_DLPF_B0B2_80_320_HZ 0x0011
126 #define GYRO7_DLPF_B0B2_160_640_HZ 0x0040
127 #define GYRO7_DLPF_B0B2_250_HZ 0x0095
128 #define GYRO7_DLPF_B0B2_500_HZ 0x0212
129 #define GYRO7_DLPF_B1_40_160_HZ 0x0008
130 #define GYRO7_DLPF_B1_80_320_HZ 0x001C
131 #define GYRO7_DLPF_B1_160_640_HZ 0x006D
132 #define GYRO7_DLPF_B1_250_HZ 0x0100
133 #define GYRO7_DLPF_B1_500_HZ 0x0387
134 #define GYRO7_DLPF_A1_40_160_HZ 0x82D7
135 #define GYRO7_DLPF_A1_80_320_HZ 0x85AF
136 #define GYRO7_DLPF_A1_160_640_HZ 0x8B59
137 #define GYRO7_DLPF_A1_250_HZ 0x91AE
138 #define GYRO7_DLPF_A1_500_HZ 0xA2EE
139 #define GYRO7_DLPF_A2_40_160_HZ 0x3D38
140 #define GYRO7_DLPF_A2_80_320_HZ 0x3A8F
141 #define GYRO7_DLPF_A2_160_640_HZ 0x3594
142 #define GYRO7_DLPF_A2_250_HZ 0x307C
143 #define GYRO7_DLPF_A2_500_HZ 0x24BD
144 #define GYRO7_DLPF_40_160_HZ 0x00
145 #define GYRO7_DLPF_80_320_HZ 0x01
146 #define GYRO7_DLPF_160_640_HZ 0x02
147 #define GYRO7_DLPF_250_HZ 0x03
148 #define GYRO7_DLPF_500_HZ 0x04
149 
154 #define GYRO7_CONFIG_HPF_ORDER_BYPASS_HPF 0x00
155 #define GYRO7_CONFIG_HPF_ORDER_ONE_HPF 0x40
156 #define GYRO7_CONFIG_HPF_ORDER_TWO_HPF 0x60
157 #define GYRO7_CONFIG_HPF_CFG_M_FACTOR_9 0x00
158 #define GYRO7_CONFIG_HPF_CFG_M_FACTOR_11 0x04
159 #define GYRO7_CONFIG_HPF_CFG_M_FACTOR_12 0x08
160 #define GYRO7_CONFIG_HPF_CFG_M_FACTOR_13 0x0C
161 #define GYRO7_CONFIG_HPF_CFG_M_FACTOR_14 0x10
162 #define GYRO7_CONFIG_HPF_CFG_M_FACTOR_15 0x14
163 #define GYRO7_CONFIG_HPF_CFG_M_FACTOR_16 0x18
164 #define GYRO7_CONFIG_HPF_CFG_M_FACTOR_17 0x1C
165 #define GYRO7_CONFIG_DLPF_CFG_BYPASS_DLPF 0x00
166 #define GYRO7_CONFIG_DLPF_CFG_ENABLE_DLPF 0x02
167 
173 #define GYRO7_SAMPLE_RATE_31p25_HZ 255
174 #define GYRO7_SAMPLE_RATE_40_HZ 199
175 #define GYRO7_SAMPLE_RATE_80_HZ 99
176 #define GYRO7_SAMPLE_RATE_100_HZ 79
177 #define GYRO7_SAMPLE_RATE_200_HZ 39
178 #define GYRO7_SAMPLE_RATE_400_HZ 19
179 #define GYRO7_SAMPLE_RATE_800_HZ 9
180 #define GYRO7_SAMPLE_RATE_1000_HZ 7
181 #define GYRO7_SAMPLE_RATE_2000_HZ 3
182 #define GYRO7_SAMPLE_RATE_4000_HZ 1
183 #define GYRO7_SAMPLE_RATE_8000_HZ 0
184 
189 #define GYRO7_INT_PIN_CFG_INT_LEVEL 0x80
190 #define GYRO7_INT_PIN_CFG_INT_OPEN 0x40
191 #define GYRO7_INT_PIN_CFG_LATCH_INT_EN 0x20
192 #define GYRO7_INT_PIN_CFG_INT_RD_CLEAR 0x10
193 
198 #define GYRO7_INT_ENABLE_DATA_RDY_EN 0x01
199 
204 #define GYRO7_PWR_MGMT_1_DEVICE_RESET 0x80
205 #define GYRO7_PWR_MGMT_1_SLEEP 0x40
206 #define GYRO7_PWR_MGMT_1_INTERNAL_OSC 0x00
207 #define GYRO7_PWR_MGMT_1_PLL_OSC 0x01
208 
213 #define GYRO7_GYRO_CONFIG_XG_ST 0x80
214 #define GYRO7_GYRO_CONFIG_YG_ST 0x40
215 #define GYRO7_GYRO_CONFIG_FS_SEL_46p5_DPS 0x00
216 #define GYRO7_GYRO_CONFIG_FS_SEL_93_DPS 0x08
217 #define GYRO7_GYRO_CONFIG_FS_SEL_187_DPS 0x10
218 #define GYRO7_GYRO_CONFIG_FS_SEL_374_DPS 0x18
219 #define GYRO7_GYRO_CONFIG_FS_SEL_BITS_MASK 0x18
220 #define GYRO7_GYRO_CONFIG_FCHOICE_B 0x01
221 
226 #define GYRO7_GYRO_SENSITIVITY_FS_SEL_0 700.0
227 #define GYRO7_GYRO_SENSITIVITY_FS_SEL_1 350.0
228 #define GYRO7_GYRO_SENSITIVITY_FS_SEL_2 175.0
229 #define GYRO7_GYRO_SENSITIVITY_FS_SEL_3 87.5
230 
235 #define GYRO7_TEMP_SENSITIVITY 123.0
236 
241 #define GYRO7_WHO_AM_I 0x88
242 
247 #define GYRO7_SPI_READ_WRITE_BIT 0x80
248 
257 #define GYRO7_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
258 #define GYRO7_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
259  // gyro7_set
261 
276 #define GYRO7_MAP_MIKROBUS( cfg, mikrobus ) \
277  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
278  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
279  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
280  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
281  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
282  // gyro7_map // gyro7
285 
290 typedef struct
291 {
292  // Input pins
293  digital_in_t int_pin;
295  // Modules
296  spi_master_t spi;
298  pin_name_t chip_select;
300 } gyro7_t;
301 
306 typedef struct
307 {
308  // Communication gpio pins
309  pin_name_t miso;
310  pin_name_t mosi;
311  pin_name_t sck;
312  pin_name_t cs;
314  // Additional gpio pins
315  pin_name_t int_pin;
317  // static variable
318  uint32_t spi_speed;
319  spi_master_mode_t spi_mode;
320  spi_master_chip_select_polarity_t cs_polarity;
322 } gyro7_cfg_t;
323 
328 typedef enum
329 {
330  GYRO7_OK = 0,
331  GYRO7_ERROR = -1
332 
334 
351 
365 err_t gyro7_init ( gyro7_t *ctx, gyro7_cfg_t *cfg );
366 
379 err_t gyro7_default_cfg ( gyro7_t *ctx );
380 
395 err_t gyro7_generic_write ( gyro7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
396 
411 err_t gyro7_generic_read ( gyro7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
412 
425 err_t gyro7_write_register ( gyro7_t *ctx, uint8_t reg, uint8_t data_in );
426 
439 err_t gyro7_read_register ( gyro7_t *ctx, uint8_t reg, uint8_t *data_out );
440 
452 
461 uint8_t gyro7_get_int_pin ( gyro7_t *ctx );
462 
478 err_t gyro7_set_dlpf_config ( gyro7_t *ctx, uint8_t freq );
479 
492 err_t gyro7_read_gyroscope ( gyro7_t *ctx, float *x_axis, float *y_axis );
493 
505 err_t gyro7_read_temperature ( gyro7_t *ctx, float *temperature );
506 
507 #ifdef __cplusplus
508 }
509 #endif
510 #endif // GYRO7_H
511  // gyro7
513 
514 // ------------------------------------------------------------------------ END
gyro7_generic_read
err_t gyro7_generic_read(gyro7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Gyro 7 data reading function.
gyro7_cfg_t::miso
pin_name_t miso
Definition: gyro7.h:309
gyro7_write_register
err_t gyro7_write_register(gyro7_t *ctx, uint8_t reg, uint8_t data_in)
Gyro 7 write register function.
gyro7_read_register
err_t gyro7_read_register(gyro7_t *ctx, uint8_t reg, uint8_t *data_out)
Gyro 7 read register function.
gyro7_generic_write
err_t gyro7_generic_write(gyro7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Gyro 7 data writing function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
gyro7_set_dlpf_config
err_t gyro7_set_dlpf_config(gyro7_t *ctx, uint8_t freq)
Gyro 7 set DLPF config function.
gyro7_t::spi
spi_master_t spi
Definition: gyro7.h:296
gyro7_cfg_t::spi_speed
uint32_t spi_speed
Definition: gyro7.h:318
gyro7_init
err_t gyro7_init(gyro7_t *ctx, gyro7_cfg_t *cfg)
Gyro 7 initialization function.
gyro7_cfg_t::sck
pin_name_t sck
Definition: gyro7.h:311
gyro7_read_temperature
err_t gyro7_read_temperature(gyro7_t *ctx, float *temperature)
Gyro 7 read temperature function.
gyro7_t::chip_select
pin_name_t chip_select
Definition: gyro7.h:298
gyro7_cfg_t::mosi
pin_name_t mosi
Definition: gyro7.h:310
gyro7_t::int_pin
digital_in_t int_pin
Definition: gyro7.h:293
gyro7_read_gyroscope
err_t gyro7_read_gyroscope(gyro7_t *ctx, float *x_axis, float *y_axis)
Gyro 7 read gyroscope function.
gyro7_t
Gyro 7 Click context object.
Definition: gyro7.h:291
gyro7_get_int_pin
uint8_t gyro7_get_int_pin(gyro7_t *ctx)
Gyro 7 get int pin function.
gyro7_cfg_setup
void gyro7_cfg_setup(gyro7_cfg_t *cfg)
Gyro 7 configuration object setup function.
gyro7_cfg_t::cs
pin_name_t cs
Definition: gyro7.h:312
GYRO7_ERROR
@ GYRO7_ERROR
Definition: gyro7.h:331
gyro7_cfg_t::int_pin
pin_name_t int_pin
Definition: gyro7.h:315
gyro7_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gyro7.h:319
gyro7_check_communication
err_t gyro7_check_communication(gyro7_t *ctx)
Gyro 7 check communication function.
GYRO7_OK
@ GYRO7_OK
Definition: gyro7.h:330
gyro7_default_cfg
err_t gyro7_default_cfg(gyro7_t *ctx)
Gyro 7 default configuration function.
gyro7_cfg_t
Gyro 7 Click configuration object.
Definition: gyro7.h:307
gyro7_return_value_t
gyro7_return_value_t
Gyro 7 Click return value data.
Definition: gyro7.h:329
gyro7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gyro7.h:320