gyro 2.0.0.0
gyro.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 GYRO_H
36#define GYRO_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
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define GYRO_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define GYRO_RETVAL uint8_t
79
80#define GYRO_OK 0x00
81#define GYRO_INIT_ERROR 0xFF
88#define GYRO_L3GD20_I2C_ADDRESS 0x6B
89#define GYRO_L3GD20_REGISTER_WHO_AM_I 0x0F
90#define GYRO_L3GD20_REGISTER_CTRL_REG1 0x20
91#define GYRO_L3GD20_REGISTER_CTRL_REG2 0x21
92#define GYRO_L3GD20_REGISTER_CTRL_REG3 0x22
93#define GYRO_L3GD20_REGISTER_CTRL_REG4 0x23
94#define GYRO_L3GD20_REGISTER_CTRL_REG5 0x24
95#define GYRO_L3GD20_REGISTER_REFERENCE 0x25
96#define GYRO_L3GD20_REGISTER_OUT_TEMP 0x26
97#define GYRO_L3GD20_REGISTER_STATUS_REG 0x27
98#define GYRO_L3GD20_REGISTER_OUT_X_L 0x28
99#define GYRO_L3GD20_REGISTER_OUT_X_H 0x29
100#define GYRO_L3GD20_REGISTER_OUT_Y_L 0x2A
101#define GYRO_L3GD20_REGISTER_OUT_Y_H 0x2B
102#define GYRO_L3GD20_REGISTER_OUT_Z_L 0x2C
103#define GYRO_L3GD20_REGISTER_OUT_Z_H 0x2D
104#define GYRO_L3GD20_REGISTER_FIFO_CTRL_REG 0x2E
105#define GYRO_L3GD20_REGISTER_FIFO_SRC_REG 0x2F
112#define GYRO_L3GD20_REGISTER_INT1_CFG 0x30
113#define GYRO_L3GD20_REGISTER_INT1_SRC 0x31
114#define GYRO_L3GD20_REGISTER_TSH_XH 0x32
115#define GYRO_L3GD20_REGISTER_TSH_XL 0x33
116#define GYRO_L3GD20_REGISTER_TSH_YH 0x34
117#define GYRO_L3GD20_REGISTER_TSH_YL 0x35
118#define GYRO_L3GD20_REGISTER_TSH_ZH 0x36
119#define GYRO_L3GD20_REGISTER_TSH_ZL 0x37
120#define GYRO_L3GD20_REGISTER_INT1_DURATION 0x38
127#define GYRO_L3GD20_REG1_NORMAL_MODE 0x0F
128#define GYRO_L3GD20_REG4_250DPS 0x00
129#define GYRO_L3GD20_REG5_FIFO_ENABLE_INT1 0x50
130#define GYRO_L3GD20_FIFO_CTRL_REG_CONFIG 0x40
133 // End group macro
134// --------------------------------------------------------------- PUBLIC TYPES
143typedef struct
144{
145 // Output pins
146
147 digital_out_t rst;
148
149 // Input pins
150
151 digital_in_t int_pin;
152
153 // Modules
154
155 i2c_master_t i2c;
156
157 // ctx variable
158
160
161} gyro_t;
162
166typedef struct
167{
168 // Communication gpio pins
169
170 pin_name_t scl;
171 pin_name_t sda;
172
173 // Additional gpio pins
174
175 pin_name_t rst;
176 pin_name_t int_pin;
177
178 // static variable
179
180 uint32_t i2c_speed;
181 uint8_t i2c_address;
182
183} gyro_cfg_t;
184
185 // End types group
186
187// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
188
194#ifdef __cplusplus
195extern "C"{
196#endif
197
207
216
225
238void gyro_write_data ( gyro_t *ctx, uint8_t address, uint8_t write_command );
239
251uint8_t gyro_read_data ( gyro_t *ctx, uint8_t address );
252
265int16_t gyro_get_axis ( gyro_t *ctx, uint8_t adr_reg_low );
266
279void gyro_read_gyro ( gyro_t *ctx, int16_t *gyro_x, int16_t *gyro_y, int16_t *gyro_z );
280
281
282#ifdef __cplusplus
283}
284#endif
285#endif // GYRO_H
286
287 // End public_function group
289
290// ------------------------------------------------------------------------ END
#define GYRO_RETVAL
Definition gyro.h:78
int16_t gyro_get_axis(gyro_t *ctx, uint8_t adr_reg_low)
Function get low and high register data.
uint8_t gyro_read_data(gyro_t *ctx, uint8_t address)
Generic read data function.
void gyro_cfg_setup(gyro_cfg_t *cfg)
Config Object Initialization function.
GYRO_RETVAL gyro_init(gyro_t *ctx, gyro_cfg_t *cfg)
Initialization function.
void gyro_write_data(gyro_t *ctx, uint8_t address, uint8_t write_command)
Generic write data function.
void gyro_read_gyro(gyro_t *ctx, int16_t *gyro_x, int16_t *gyro_y, int16_t *gyro_z)
Function read axis.
void gyro_default_cfg(gyro_t *ctx)
Click Default Configuration function.
Click configuration structure definition.
Definition gyro.h:167
uint32_t i2c_speed
Definition gyro.h:180
pin_name_t scl
Definition gyro.h:170
pin_name_t int_pin
Definition gyro.h:176
pin_name_t sda
Definition gyro.h:171
pin_name_t rst
Definition gyro.h:175
uint8_t i2c_address
Definition gyro.h:181
Click ctx object definition.
Definition gyro.h:144
digital_in_t int_pin
Definition gyro.h:151
i2c_master_t i2c
Definition gyro.h:155
digital_out_t rst
Definition gyro.h:147
uint8_t slave_address
Definition gyro.h:159