gyro5  2.0.0.0
gyro5.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 GYRO5_H
36 #define GYRO5_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 GYRO5_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.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define GYRO5_MASTER_I2C 0
79 #define GYRO5_MASTER_SPI 1
80 #define GYRO5_COM_I2C 0x01
81 #define GYRO5_COM_SPI 0x02
82 
88 #define GYRO5_RETVAL uint8_t
89 
90 #define GYRO5_OK 0x00
91 #define GYRO5_INIT_ERROR 0xFF
92 
98 #define GYRO5_I2C_DEV_ADR_GND 0x68
99 #define GYRO5_I2C_DEV_ADR_VCC 0x69
100 
106 #define GYRO5_SLEEP_DISABLE 0x00
107 #define GYRO5_SLEEP_ENABLE 0x01
108 
114 #define GYRO5_INT_DATA_RDY 0x00
115 #define GYRO5_INT_FSYNC 0x01
116 #define GYRO5_INT_FIFO_OVF 0x02
117 
123 #define GYRO5_REG_XG_OFFS_TC_H 0x04
124 #define GYRO5_REG_XG_OFFS_TC_L 0x05
125 #define GYRO5_REG_YG_OFFS_TC_H 0x07
126 #define GYRO5_REG_YG_OFFS_TC_L 0x08
127 #define GYRO5_REG_ZG_OFFS_TC_H 0x0A
128 #define GYRO5_REG_ZG_OFFS_TC_L 0x0B
129 #define GYRO5_REG_XG_OFFS_USRH 0x13
130 #define GYRO5_REG_XG_OFFS_USRL 0x14
131 #define GYRO5_REG_YG_OFFS_USRH 0x15
132 #define GYRO5_REG_YG_OFFS_USRL 0x16
133 #define GYRO5_REG_ZG_OFFS_USRH 0x17
134 #define GYRO5_REG_G_OFFS_USRL 0x18
135 #define GYRO5_REG_SMPLRT_DIV 0x19
136 #define GYRO5_REG_CONFIG 0x1A
137 #define GYRO5_REG_GYRO_CONFIG 0x1B
138 #define GYRO5_REG_FIFO_EN 0x23
139 #define GYRO5_REG_INT_PIN_CFG 0x37
140 #define GYRO5_REG_INT_ENABLE 0x38
141 #define GYRO5_REG_INT_STATUS 0x3A
142 #define GYRO5_REG_TEMP_OUT_H 0x41
143 #define GYRO5_REG_TEMP_OUT_L 0x42
144 #define GYRO5_REG_GYRO_XOUT_H 0x43
145 #define GYRO5_REG_GYRO_XOUT_L 0x44
146 #define GYRO5_REG_GYRO_YOUT_H 0x45
147 #define GYRO5_REG_GYRO_YOUT_L 0x46
148 #define GYRO5_REG_GYRO_ZOUT_H 0x47
149 #define GYRO5_REG_GYRO_ZOUT_L 0x48
150 #define GYRO5_REG_USER_CTRL 0x6A
151 #define GYRO5_REG_PWR_MGMT_1 0x6B
152 #define GYRO5_REG_PWR_MGMT_2 0x6C
153 #define GYRO5_REG_FIFO_COUNTH 0x72
154 #define GYRO5_REG_FIFO_COUNTL 0x73
155 #define GYRO5_REG_FIFO_R_W 0x74
156 #define GYRO5_REG_WHO_AM_I 0x75
157 
163 #define GYRO5_CFG_PWR_MGMT_1_DEV_RST 0x80
164 #define GYRO5_CFG_PWR_MGMT_1_SLEEP 0x40
165 #define GYRO5_CFG_PWR_MGMT_1_TEMP_DIS 0x10
166 #define GYRO5_CFG_PWR_MGMT_1_CLKSEL_EXT_OSC 0x06
167 #define GYRO5_CFG_PWR_MGMT_1_CLKSEL_PLL 0x01
168 #define GYRO5_CFG_PWR_MGMT_1_CLKSEL_INT_OSC 0x00
169 
175 #define GYRO5_CFG_PWR_MGMT_2_STBY_XG 0x04
176 #define GYRO5_CFG_PWR_MGMT_2_STBY_YG 0x02
177 #define GYRO5_CFG_PWR_MGMT_2_STBY_ZG 0x01
178 #define GYRO5_CFG_PWR_MGMT_2_DIS_ALL 0x00
179 
185 #define GYRO5_CFG_USER_CTRL_FIFO_EN 0x40
186 #define GYRO5_CFG_USER_CTRL_I2C_IF_DIS 0x10
187 #define GYRO5_CFG_USER_CTRL_FIFO_RESET 0x08
188 #define GYRO5_CFG_USER_CTRL_SIG_COND_RST 0x01
189 
195 #define GYRO5_CFG_SMPLRT_DIV_DEF 0x00
196 
202 #define GYRO5_CFG_CONFIG_EXT_SYNC_SET_GYRO_ZOUT_L 0x20
203 #define GYRO5_CFG_CONFIG_EXT_SYNC_SET_GYRO_YOUT_L 0x18
204 #define GYRO5_CFG_CONFIG_EXT_SYNC_SET_GYRO_XOUT_L 0x10
205 #define GYRO5_CFG_CONFIG_EXT_SYNC_SET_TEMP_OUT_L 0x08
206 #define GYRO5_CFG_CONFIG_EXT_SYNC_SET_IN_DIS 0x00
207 #define GYRO5_CFG_CONFIG_DEF 0x00
208 
214 #define GYRO5_CFG_GYRO_CONFIG_FS_SEL_4000 0x18
215 #define GYRO5_CFG_GYRO_CONFIG_FS_SEL_2000 0x10
216 #define GYRO5_CFG_GYRO_CONFIG_FS_SEL_1000 0x08
217 #define GYRO5_CFG_GYRO_CONFIG_FS_SEL_500 0x00
218 
224 #define GYRO5_CFG_FIFO_EN_TEMP 0x80
225 #define GYRO5_CFG_FIFO_EN_GYRO_X 0x40
226 #define GYRO5_CFG_FIFO_EN_GYRO_Y 0x20
227 #define GYRO5_CFG_FIFO_EN_GYRO_Z 0x10
228 #define GYRO5_CFG_FIFO_EN_DIS_ALL 0x00
229 
235 #define GYRO5_CFG_INT_PIN_CFG_INT_LEVEL 0x80
236 #define GYRO5_CFG_INT_PIN_CFG_INT_OPEN 0x40
237 #define GYRO5_CFG_INT_PIN_CFG_LATCH_INT_EN 0x20
238 #define GYRO5_CFG_INT_PIN_CFG_INT_RD_CLEAR 0x10
239 #define GYRO5_CFG_INT_PIN_CFG_FSYNC_INT_LEVEL 0x08
240 #define GYRO5_CFG_INT_PIN_CFG_FSYNC_INT_MODE_EN 0x04
241 #define GYRO5_CFG_INT_PIN_CFG_DIS_ALL 0x00
242 
248 #define GYRO5_CFG_INT_ENABLE_FIFO_OFLOW_EN 0x10
249 #define GYRO5_CFG_INT_ENABLE_FSYNC_INT_EN 0x08
250 #define GYRO5_CFG_INT_ENABLE_DATA_RDY_EN 0x01
251 
257 #define GYRO5_STATUS_INT_FIFO_OFLOW 0x10
258 #define GYRO5_STATUS_INT_FSYNC 0x08
259 #define GYRO5_STATUS_INT_DATA_RDY 0x01
260 #define GYRO5_STATUS_INT_NOT_DATA_RDY 0x00
261 
267 #define GYRO5_STATUS_INT_TYPES_SEL_FIFO_OFLOW 0x02
268 #define GYRO5_STATUS_INT_TYPES_INT_FSYNC 0x01
269 #define GYRO5_STATUS_INT_TYPES_INT_DATA_RDY 0x00
270 
276 #define GYRO5_SLEEP_STATUS_EN 0x01
277 #define GYRO5_SLEEP_STATUS_DIS 0x00
278  // End group macro
281 // --------------------------------------------------------------- PUBLIC TYPES
290 typedef uint8_t gyro5_select_t;
291 
295 typedef void ( *gyro5_master_io_t )( struct gyro5_s*, uint8_t, uint8_t*, uint8_t );
296 
300 typedef struct gyro5_s
301 {
302  // Output pins
303 
304  digital_out_t cs;
305 
306  // Input pins
307 
308  digital_in_t int_pin;
309 
310  // Modules
311 
312  i2c_master_t i2c;
313  spi_master_t spi;
314 
315  // ctx variable
316 
317  uint8_t slave_address;
318  pin_name_t chip_select;
322 
324 
328 typedef struct
329 {
330  // Communication gpio pins
331 
332  pin_name_t scl;
333  pin_name_t sda;
334  pin_name_t miso;
335  pin_name_t mosi;
336  pin_name_t sck;
337  pin_name_t cs;
338 
339  pin_name_t int_pin;
340 
341  // static variable
342 
343  uint32_t i2c_speed;
344  uint8_t i2c_address;
345 
346  uint32_t spi_speed;
347  spi_master_mode_t spi_mode;
348  spi_master_chip_select_polarity_t cs_polarity;
349 
351 
352 } gyro5_cfg_t;
353  // End types group
355 
356 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
362 #ifdef __cplusplus
363 extern "C"{
364 #endif
365 
375 
385 
394 
405 void gyro5_generic_write ( gyro5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
406 
417 void gyro5_generic_read ( gyro5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
418 
430 uint8_t gyro5_get_int ( gyro5_t *ctx );
431 
444 uint8_t gyro5_int_status ( gyro5_t *ctx, uint8_t int_type );
445 
455 void gyro5_get_temperature ( gyro5_t *ctx, float *temperature );
456 
468 void gyro5_get_axes ( gyro5_t *ctx, float *x_axis, float *y_axis, float *z_axis );
469 
480 void gyro5_sleep ( gyro5_t *ctx, uint8_t en_sleep );
481 
482 #ifdef __cplusplus
483 }
484 #endif
485 #endif // _GYRO5_H_
486  // End public_function group
489 
490 // ------------------------------------------------------------------------- END
gyro5_t
struct gyro5_s gyro5_t
Click ctx object definition.
gyro5_cfg_t::mosi
pin_name_t mosi
Definition: gyro5.h:335
gyro5_cfg_t::miso
pin_name_t miso
Definition: gyro5.h:334
gyro5_s::slave_address
uint8_t slave_address
Definition: gyro5.h:317
gyro5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gyro5.h:347
gyro5_generic_write
void gyro5_generic_write(gyro5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
GYRO5_RETVAL
#define GYRO5_RETVAL
Definition: gyro5.h:88
gyro5_get_int
uint8_t gyro5_get_int(gyro5_t *ctx)
Getting INT pin state.
gyro5_s::spi
spi_master_t spi
Definition: gyro5.h:313
gyro5_default_cfg
void gyro5_default_cfg(gyro5_t *ctx)
Click Default Configuration function.
gyro5_get_temperature
void gyro5_get_temperature(gyro5_t *ctx, float *temperature)
Getting temperature value.
gyro5_int_status
uint8_t gyro5_int_status(gyro5_t *ctx, uint8_t int_type)
Getting interrupt status.
gyro5_s::chip_select
pin_name_t chip_select
Definition: gyro5.h:318
gyro5_master_io_t
void(* gyro5_master_io_t)(struct gyro5_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: gyro5.h:295
gyro5_s
Click ctx object definition.
Definition: gyro5.h:301
gyro5_cfg_t::sda
pin_name_t sda
Definition: gyro5.h:333
gyro5_cfg_t::sck
pin_name_t sck
Definition: gyro5.h:336
gyro5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gyro5.h:348
gyro5_cfg_setup
void gyro5_cfg_setup(gyro5_cfg_t *cfg)
Config Object Initialization function.
gyro5_s::write_f
gyro5_master_io_t write_f
Definition: gyro5.h:319
gyro5_get_axes
void gyro5_get_axes(gyro5_t *ctx, float *x_axis, float *y_axis, float *z_axis)
Getting gyroscope axes values.
gyro5_s::master_sel
gyro5_select_t master_sel
Definition: gyro5.h:321
gyro5_generic_read
void gyro5_generic_read(gyro5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
gyro5_s::read_f
gyro5_master_io_t read_f
Definition: gyro5.h:320
gyro5_s::int_pin
digital_in_t int_pin
Definition: gyro5.h:308
gyro5_cfg_t::scl
pin_name_t scl
Definition: gyro5.h:332
gyro5_select_t
uint8_t gyro5_select_t
Communication type.
Definition: gyro5.h:290
gyro5_sleep
void gyro5_sleep(gyro5_t *ctx, uint8_t en_sleep)
Set sleep mode.
gyro5_init
GYRO5_RETVAL gyro5_init(gyro5_t *ctx, gyro5_cfg_t *cfg)
Initialization function.
gyro5_cfg_t::int_pin
pin_name_t int_pin
Definition: gyro5.h:339
gyro5_s::cs
digital_out_t cs
Definition: gyro5.h:304
gyro5_s::i2c
i2c_master_t i2c
Definition: gyro5.h:312
gyro5_cfg_t::cs
pin_name_t cs
Definition: gyro5.h:337
gyro5_cfg_t::i2c_address
uint8_t i2c_address
Definition: gyro5.h:344
gyro5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: gyro5.h:343
gyro5_cfg_t::sel
gyro5_select_t sel
Definition: gyro5.h:350
gyro5_cfg_t::spi_speed
uint32_t spi_speed
Definition: gyro5.h:346
gyro5_cfg_t
Click configuration structure definition.
Definition: gyro5.h:329