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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define GYRO5_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
75 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define GYRO5_MASTER_I2C 0
83#define GYRO5_MASTER_SPI 1
84#define GYRO5_COM_I2C 0x01
85#define GYRO5_COM_SPI 0x02
92#define GYRO5_RETVAL uint8_t
93
94#define GYRO5_OK 0x00
95#define GYRO5_INIT_ERROR 0xFF
102#define GYRO5_I2C_DEV_ADR_GND 0x68
103#define GYRO5_I2C_DEV_ADR_VCC 0x69
110#define GYRO5_SLEEP_DISABLE 0x00
111#define GYRO5_SLEEP_ENABLE 0x01
118#define GYRO5_INT_DATA_RDY 0x00
119#define GYRO5_INT_FSYNC 0x01
120#define GYRO5_INT_FIFO_OVF 0x02
127#define GYRO5_REG_XG_OFFS_TC_H 0x04
128#define GYRO5_REG_XG_OFFS_TC_L 0x05
129#define GYRO5_REG_YG_OFFS_TC_H 0x07
130#define GYRO5_REG_YG_OFFS_TC_L 0x08
131#define GYRO5_REG_ZG_OFFS_TC_H 0x0A
132#define GYRO5_REG_ZG_OFFS_TC_L 0x0B
133#define GYRO5_REG_XG_OFFS_USRH 0x13
134#define GYRO5_REG_XG_OFFS_USRL 0x14
135#define GYRO5_REG_YG_OFFS_USRH 0x15
136#define GYRO5_REG_YG_OFFS_USRL 0x16
137#define GYRO5_REG_ZG_OFFS_USRH 0x17
138#define GYRO5_REG_G_OFFS_USRL 0x18
139#define GYRO5_REG_SMPLRT_DIV 0x19
140#define GYRO5_REG_CONFIG 0x1A
141#define GYRO5_REG_GYRO_CONFIG 0x1B
142#define GYRO5_REG_FIFO_EN 0x23
143#define GYRO5_REG_INT_PIN_CFG 0x37
144#define GYRO5_REG_INT_ENABLE 0x38
145#define GYRO5_REG_INT_STATUS 0x3A
146#define GYRO5_REG_TEMP_OUT_H 0x41
147#define GYRO5_REG_TEMP_OUT_L 0x42
148#define GYRO5_REG_GYRO_XOUT_H 0x43
149#define GYRO5_REG_GYRO_XOUT_L 0x44
150#define GYRO5_REG_GYRO_YOUT_H 0x45
151#define GYRO5_REG_GYRO_YOUT_L 0x46
152#define GYRO5_REG_GYRO_ZOUT_H 0x47
153#define GYRO5_REG_GYRO_ZOUT_L 0x48
154#define GYRO5_REG_USER_CTRL 0x6A
155#define GYRO5_REG_PWR_MGMT_1 0x6B
156#define GYRO5_REG_PWR_MGMT_2 0x6C
157#define GYRO5_REG_FIFO_COUNTH 0x72
158#define GYRO5_REG_FIFO_COUNTL 0x73
159#define GYRO5_REG_FIFO_R_W 0x74
160#define GYRO5_REG_WHO_AM_I 0x75
167#define GYRO5_CFG_PWR_MGMT_1_DEV_RST 0x80
168#define GYRO5_CFG_PWR_MGMT_1_SLEEP 0x40
169#define GYRO5_CFG_PWR_MGMT_1_TEMP_DIS 0x10
170#define GYRO5_CFG_PWR_MGMT_1_CLKSEL_EXT_OSC 0x06
171#define GYRO5_CFG_PWR_MGMT_1_CLKSEL_PLL 0x01
172#define GYRO5_CFG_PWR_MGMT_1_CLKSEL_INT_OSC 0x00
179#define GYRO5_CFG_PWR_MGMT_2_STBY_XG 0x04
180#define GYRO5_CFG_PWR_MGMT_2_STBY_YG 0x02
181#define GYRO5_CFG_PWR_MGMT_2_STBY_ZG 0x01
182#define GYRO5_CFG_PWR_MGMT_2_DIS_ALL 0x00
189#define GYRO5_CFG_USER_CTRL_FIFO_EN 0x40
190#define GYRO5_CFG_USER_CTRL_I2C_IF_DIS 0x10
191#define GYRO5_CFG_USER_CTRL_FIFO_RESET 0x08
192#define GYRO5_CFG_USER_CTRL_SIG_COND_RST 0x01
199#define GYRO5_CFG_SMPLRT_DIV_DEF 0x00
206#define GYRO5_CFG_CONFIG_EXT_SYNC_SET_GYRO_ZOUT_L 0x20
207#define GYRO5_CFG_CONFIG_EXT_SYNC_SET_GYRO_YOUT_L 0x18
208#define GYRO5_CFG_CONFIG_EXT_SYNC_SET_GYRO_XOUT_L 0x10
209#define GYRO5_CFG_CONFIG_EXT_SYNC_SET_TEMP_OUT_L 0x08
210#define GYRO5_CFG_CONFIG_EXT_SYNC_SET_IN_DIS 0x00
211#define GYRO5_CFG_CONFIG_DEF 0x00
218#define GYRO5_CFG_GYRO_CONFIG_FS_SEL_4000 0x18
219#define GYRO5_CFG_GYRO_CONFIG_FS_SEL_2000 0x10
220#define GYRO5_CFG_GYRO_CONFIG_FS_SEL_1000 0x08
221#define GYRO5_CFG_GYRO_CONFIG_FS_SEL_500 0x00
228#define GYRO5_CFG_FIFO_EN_TEMP 0x80
229#define GYRO5_CFG_FIFO_EN_GYRO_X 0x40
230#define GYRO5_CFG_FIFO_EN_GYRO_Y 0x20
231#define GYRO5_CFG_FIFO_EN_GYRO_Z 0x10
232#define GYRO5_CFG_FIFO_EN_DIS_ALL 0x00
239#define GYRO5_CFG_INT_PIN_CFG_INT_LEVEL 0x80
240#define GYRO5_CFG_INT_PIN_CFG_INT_OPEN 0x40
241#define GYRO5_CFG_INT_PIN_CFG_LATCH_INT_EN 0x20
242#define GYRO5_CFG_INT_PIN_CFG_INT_RD_CLEAR 0x10
243#define GYRO5_CFG_INT_PIN_CFG_FSYNC_INT_LEVEL 0x08
244#define GYRO5_CFG_INT_PIN_CFG_FSYNC_INT_MODE_EN 0x04
245#define GYRO5_CFG_INT_PIN_CFG_DIS_ALL 0x00
252#define GYRO5_CFG_INT_ENABLE_FIFO_OFLOW_EN 0x10
253#define GYRO5_CFG_INT_ENABLE_FSYNC_INT_EN 0x08
254#define GYRO5_CFG_INT_ENABLE_DATA_RDY_EN 0x01
261#define GYRO5_STATUS_INT_FIFO_OFLOW 0x10
262#define GYRO5_STATUS_INT_FSYNC 0x08
263#define GYRO5_STATUS_INT_DATA_RDY 0x01
264#define GYRO5_STATUS_INT_NOT_DATA_RDY 0x00
271#define GYRO5_STATUS_INT_TYPES_SEL_FIFO_OFLOW 0x02
272#define GYRO5_STATUS_INT_TYPES_INT_FSYNC 0x01
273#define GYRO5_STATUS_INT_TYPES_INT_DATA_RDY 0x00
280#define GYRO5_SLEEP_STATUS_EN 0x01
281#define GYRO5_SLEEP_STATUS_DIS 0x00
284 // End group macro
285// --------------------------------------------------------------- PUBLIC TYPES
294typedef uint8_t gyro5_select_t;
295
299typedef void ( *gyro5_master_io_t )( struct gyro5_s*, uint8_t, uint8_t*, uint8_t );
300
304typedef struct gyro5_s
305{
306 // Output pins
307
308 digital_out_t cs;
309
310 // Input pins
311
312 digital_in_t int_pin;
313
314 // Modules
315
316 i2c_master_t i2c;
317 spi_master_t spi;
318
319 // ctx variable
320
322 pin_name_t chip_select;
326
328
332typedef struct
333{
334 // Communication gpio pins
335
336 pin_name_t scl;
337 pin_name_t sda;
338 pin_name_t miso;
339 pin_name_t mosi;
340 pin_name_t sck;
341 pin_name_t cs;
342
343 pin_name_t int_pin;
344
345 // static variable
346
347 uint32_t i2c_speed;
348 uint8_t i2c_address;
349
350 uint32_t spi_speed;
351 spi_master_mode_t spi_mode;
352 spi_master_chip_select_polarity_t cs_polarity;
353
355
357
358 // End types group
359
360// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
366#ifdef __cplusplus
367extern "C"{
368#endif
369
379
389
398
409void gyro5_generic_write ( gyro5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
410
421void gyro5_generic_read ( gyro5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
422
434uint8_t gyro5_get_int ( gyro5_t *ctx );
435
448uint8_t gyro5_int_status ( gyro5_t *ctx, uint8_t int_type );
449
459void gyro5_get_temperature ( gyro5_t *ctx, float *temperature );
460
472void gyro5_get_axes ( gyro5_t *ctx, float *x_axis, float *y_axis, float *z_axis );
473
484void gyro5_sleep ( gyro5_t *ctx, uint8_t en_sleep );
485
486#ifdef __cplusplus
487}
488#endif
489#endif // _GYRO5_H_
490
491 // End public_function group
493
494// ------------------------------------------------------------------------- END
#define GYRO5_RETVAL
Definition gyro5.h:92
GYRO5_RETVAL gyro5_init(gyro5_t *ctx, gyro5_cfg_t *cfg)
Initialization function.
void gyro5_generic_write(gyro5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void gyro5_get_temperature(gyro5_t *ctx, float *temperature)
Getting temperature value.
void gyro5_sleep(gyro5_t *ctx, uint8_t en_sleep)
Set sleep mode.
uint8_t gyro5_get_int(gyro5_t *ctx)
Getting INT pin state.
uint8_t gyro5_int_status(gyro5_t *ctx, uint8_t int_type)
Getting interrupt status.
void gyro5_default_cfg(gyro5_t *ctx)
Click Default Configuration function.
void gyro5_generic_read(gyro5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void gyro5_cfg_setup(gyro5_cfg_t *cfg)
Config Object Initialization function.
void gyro5_get_axes(gyro5_t *ctx, float *x_axis, float *y_axis, float *z_axis)
Getting gyroscope axes values.
struct gyro5_s gyro5_t
Click ctx object definition.
uint8_t gyro5_select_t
Communication type.
Definition gyro5.h:294
void(* gyro5_master_io_t)(struct gyro5_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition gyro5.h:299
Click configuration structure definition.
Definition gyro5.h:333
gyro5_select_t sel
Definition gyro5.h:354
uint32_t i2c_speed
Definition gyro5.h:347
spi_master_chip_select_polarity_t cs_polarity
Definition gyro5.h:352
pin_name_t sck
Definition gyro5.h:340
spi_master_mode_t spi_mode
Definition gyro5.h:351
pin_name_t mosi
Definition gyro5.h:339
uint32_t spi_speed
Definition gyro5.h:350
pin_name_t scl
Definition gyro5.h:336
pin_name_t int_pin
Definition gyro5.h:343
pin_name_t miso
Definition gyro5.h:338
pin_name_t sda
Definition gyro5.h:337
pin_name_t cs
Definition gyro5.h:341
uint8_t i2c_address
Definition gyro5.h:348
Click ctx object definition.
Definition gyro5.h:305
digital_out_t cs
Definition gyro5.h:308
spi_master_t spi
Definition gyro5.h:317
gyro5_select_t master_sel
Definition gyro5.h:325
gyro5_master_io_t write_f
Definition gyro5.h:323
digital_in_t int_pin
Definition gyro5.h:312
i2c_master_t i2c
Definition gyro5.h:316
uint8_t slave_address
Definition gyro5.h:321
gyro5_master_io_t read_f
Definition gyro5.h:324
pin_name_t chip_select
Definition gyro5.h:322