gyro3 2.0.0.0
gyro3.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 GYRO3_H
36#define GYRO3_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 GYRO3_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.di2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
76 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
83#define GYRO3_MASTER_I2C 0
84#define GYRO3_MASTER_SPI 1
91#define GYRO3_RETVAL uint8_t
92
93#define GYRO3_OK 0x00
94#define GYRO3_INIT_ERROR 0xFF
101#define GYRO3_DEVICE_ADDR_SA0 0x68
102#define GYRO3_DEVICE_ADDR_SA1 0x69
109#define GYRO3_MODE_POWER_DOWN 0x00
110#define GYRO3_MODE_SLEEP 0x08
111#define GYRO3_MODE_NORMAL 0x0F
118#define GYRO3_CTRL_REG1 0x20
119#define GYRO3_CTRL_REG2 0x21
120#define GYRO3_CTRL_REG3 0x22
121#define GYRO3_CTRL_REG4 0x23
122#define GYRO3_CTRL_REG5 0x24
129#define GYRO3_ODR_100_CUTOFF_12p5 0x00
130#define GYRO3_ODR_100_CUTOFF_25 0x10
131#define GYRO3_ODR_200_CUTOFF_12p5 0x40
132#define GYRO3_ODR_200_CUTOFF_25 0x50
133#define GYRO3_ODR_200_CUTOFF_50 0x60
134#define GYRO3_ODR_200_CUTOFF_70 0x70
135#define GYRO3_ODR_400_CUTOFF_20 0x80
136#define GYRO3_ODR_400_CUTOFF_25 0x90
137#define GYRO3_ODR_400_CUTOFF_50 0xa0
138#define GYRO3_ODR_400_CUTOFF_110 0xb0
139#define GYRO3_ODR_800_CUTOFF_30 0xc0
140#define GYRO3_ODR_800_CUTOFF_35 0xd0
141#define GYRO3_ODR_800_CUTOFF_50 0xe0
142#define GYRO3_ODR_800_CUTOFF_110 0xf0
149#define GYRO3_FIFO_MODE_BYPASS 0x00
150#define GYRO3_FIFO_EMPTY_INT_ON_INT2 0x01
151#define GYRO3_FIFO_OVERRUN_INT_ON_INT2 0x02
152#define GYRO3_FIFO_WATERMARK_INT_ON_INT2 0x04
153#define GYRO3_FIFO_MODE_FIFO 0x20
154#define GYRO3_FIFO_MODE_STREAM 0x40
155#define GYRO3_FIFO_WTM_STATUS_MASK 0x80
156#define GYRO3_FIFO_OVERRUN_MASK 0x40
157#define GYRO3_FIFO_EMPTY_STATUS 0x20
164#define GYRO3_WHO_AM_I 0x0f
165#define GYRO3_REF_DATACAP 0x25
166#define GYRO3_OUT_TEMP 0x26
167#define GYRO3_STATUS_REG 0x27
168#define GYRO3_OUT_X_L 0x28
169#define GYRO3_OUT_X_H 0x29
170#define GYRO3_OUT_Y_L 0x2a
171#define GYRO3_OUT_Y_H 0x2b
172#define GYRO3_OUT_Z_L 0x2c
173#define GYRO3_OUT_Z_H 0x2d
174#define GYRO3_FIFO_CTRL 0x2e
175#define GYRO3_FIFO_SRC 0x2f
176#define GYRO3_INT1_CFG 0x30
177#define GYRO3_INT1_SRC 0x31
178#define GYRO3_INT1_THS_XH 0x32
179#define GYRO3_INT1_THS_XL 0x33
180#define GYRO3_INT1_THS_YH 0x34
181#define GYRO3_INT1_THS_YL 0x35
182#define GYRO3_INT1_THS_ZH 0x36
183#define GYRO3_INT1_THS_ZL 0x37
184#define GYRO3_INT1_DURATION 0x38
185#define GYRO3_HPF_MODE_NORMAL 0x00
186#define GYRO3_HPF_MODE_REF_SIGNAL 0x10
187#define GYRO3_HPF_MODE_AUTO_RESET_ON_INT 0x30
188#define GYRO3_HPF_CUTOFF_FREQ_8 0x00
189#define GYRO3_HPF_CUTOFF_FREQ_4 0x01
190#define GYRO3_HPF_CUTOFF_FREQ_2 0x02
191#define GYRO3_HPF_CUTOFF_FREQ_1 0x03
192#define GYRO3_HPF_CUTOFF_FREQ_0p5 0x04
193#define GYRO3_HPF_CUTOFF_FREQ_0p2 0x05
194#define GYRO3_HPF_CUTOFF_FREQ_0p1 0x06
195#define GYRO3_HPF_CUTOFF_FREQ_0p05 0x07
196#define GYRO3_HPF_CUTOFF_FREQ_0p02 0x08
197#define GYRO3_HPF_CUTOFF_FREQ_0p01 0x09
198#define GYRO3_INT_ON_INT1 0x80
199#define GYRO3_BOOT_STATUS_ON_INT1 0x40
200#define GYRO3_INT_ACTIVE_CFG_ON_INT1 0x20
201#define GYRO3_PUSH_PULL 0x00
202#define GYRO3_OPEN_DRAIN 0x10
203#define GYRO3_DRDY_ON_INT2 0x08
204#define GYRO3_BIG_ENDIAN 0x40
205#define GYRO3_LITTLE_ENDIAN 0x00
206#define GYRO3_FULL_SCACLE_245 0x00
207#define GYRO3_FULL_SCACLE_500 0x10
208#define GYRO3_FULL_SCACLE_1000 0x20
209#define GYRO3_FULL_SCACLE_2000 0x30
210#define GYRO3_SELF_TEST_NORMAL 0x00
211#define GYRO3_SELF_TEST_0 0x02
212#define GYRO3_SELF_TEST_1 0x06
213#define GYRO3_SPI_MODE_4_WIRE 0x00
214#define GYRO3_SPI_MODE_3_WIRE 0x01
215#define GYRO3_REBOOT_MEMORY 0x80
216#define GYRO3_FIFO_EN 0x40
217#define GYRO3_HPF_EN 0x10
218#define GYRO3_INT_SEL_00 0x00
219#define GYRO3_INT_SEL_01 0x40
220#define GYRO3_INT_SEL_10 0x80
221#define GYRO3_OUT_SEL_00 0x00
222#define GYRO3_OUT_SEL_01 0x01
223#define GYRO3_OUT_SEL_10 0x02
224#define GYRO3_ZYX_OVERRUN_MASK 0x80
225#define GYRO3_Z_MASK 0x40
226#define GYRO3_Y_MASK 0x20
227#define GYRO3_X_MASK 0x10
228#define GYRO3_ZYX_NEW_DATA_MASK 0x08
229#define GYRO3_Z_NEW_DATA_MASK 0x04
230#define GYRO3_Y_NEW_DATA_MASK 0x02
231#define GYRO3_X_NEW_DATA_MASK 0x01
232#define GYRO3_INT1_AND_OR 0x80
233#define GYRO3_INT1_LATCH 0x40
234#define GYRO3_INT1_ON_HIGH_Z 0x20
235#define GYRO3_INT1_ON_LOW_Z 0x10
236#define GYRO3_INT1_ON_HIGH_Y 0x08
237#define GYRO3_INT1_ON_LOW_Y 0x04
238#define GYRO3_INT1_ON_HIGH_X 0x02
239#define GYRO3_INT1_ON_LOW_X 0x01
240#define GYRO3_INT1_INT_ACTIVE_MASK 0x40
241#define GYRO3_INT1_Z_HIGH_INT_MASK 0x20
242#define GYRO3_INT1_Z_LOW_INT_MASK 0x10
243#define GYRO3_INT1_Y_HIGH_INT_MASK 0x08
244#define GYRO3_INT1_Y_LOW_INT_MASK 0x04
245#define GYRO3_INT1_X_HIGH_INT_MASK 0x02
246#define GYRO3_INT1_X_LOW_INT_MASK 0x01
247#define GYRO3_WAIT_ENABLE 0x80
248#define GYRO3_WAIT_DISABLE 0x00
249#define GYRO3_MEAS_RANGE_245 0x01
250#define GYRO3_MEAS_RANGE_500 0x02
251#define GYRO3_MEAS_RANGE_2000 0x03
253 // End group macro
254// --------------------------------------------------------------- PUBLIC TYPES
263typedef uint8_t gyro3_select_t;
264
268typedef void ( *gyro3_master_io_t )( struct gyro3_s*, uint8_t, uint8_t*, uint8_t );
269
273typedef struct gyro3_s
274{
275 // Output pins
276
277 digital_out_t cs;
278
279 // Input pins
280
281 digital_in_t di2;
282 digital_in_t int_pin;
283
284 // Modules
285
286 i2c_master_t i2c;
287 spi_master_t spi;
288
289 // ctx variable
290
292 pin_name_t chip_select;
297
301typedef struct
302{
303 // Communication gpio pins
304
305 pin_name_t scl;
306 pin_name_t sda;
307 pin_name_t miso;
308 pin_name_t mosi;
309 pin_name_t sck;
310 pin_name_t cs;
311
312 // Additional gpio pins
313
314 pin_name_t di2;
315 pin_name_t int_pin;
316
317 // static variable
318
319 uint32_t i2c_speed;
320 uint8_t i2c_address;
321
322 uint32_t spi_speed;
323 spi_master_mode_t spi_mode;
324 spi_master_chip_select_polarity_t cs_polarity;
325
327
329
330 // End types group
331
332// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
338#ifdef __cplusplus
339extern "C"{
340#endif
341
351
361
370
381void gyro3_generic_write ( gyro3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
382
393void gyro3_generic_read ( gyro3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
394
404uint8_t gyro3_int_get ( gyro3_t *ctx );
405
415uint8_t gyro3_di2_get( gyro3_t *ctx );
416
428void gyro3_read ( gyro3_t *ctx, uint8_t register_address, uint8_t * read_buffer, uint8_t n_bytes );
429
439void gyro3_write ( gyro3_t *ctx, uint8_t register_address, uint8_t value );
440
449void gyro3_get_temp ( gyro3_t *ctx, uint8_t *temperature_value );
450
463void gyro3_get_axes ( gyro3_t *ctx, float *x_axis, float *y_axis, float *z_axis, uint8_t measurement_range );
464
473void gyro3_get_status ( gyro3_t *ctx, uint8_t * status_register );
474
484void gyro3_get_fifo_data_level ( gyro3_t *ctx, uint8_t * fifo_data_level );
485
496void gyro3_set_int1_thresholds ( gyro3_t *ctx, int16_t x_threshold, int16_t y_threshold, int16_t z_threshold );
497
509uint8_t gyro3_set_int1_duration ( gyro3_t *ctx, uint8_t wait_enable_bit, uint8_t duration_value );
510
511
512#ifdef __cplusplus
513}
514#endif
515#endif // _GYRO3_H_
516
517 // End public_function group
519
520// ------------------------------------------------------------------------- END
#define GYRO3_RETVAL
Definition gyro3.h:91
void gyro3_write(gyro3_t *ctx, uint8_t register_address, uint8_t value)
Write byte to regiter.
void gyro3_default_cfg(gyro3_t *ctx)
Click Default Configuration function.
void gyro3_read(gyro3_t *ctx, uint8_t register_address, uint8_t *read_buffer, uint8_t n_bytes)
Reading register(s)
uint8_t gyro3_int_get(gyro3_t *ctx)
Get INT pin state.
void gyro3_get_temp(gyro3_t *ctx, uint8_t *temperature_value)
Read value from temperature register.
void gyro3_get_status(gyro3_t *ctx, uint8_t *status_register)
Getting status register content.
uint8_t gyro3_di2_get(gyro3_t *ctx)
Get di2 (AN) pin state.
void gyro3_generic_write(gyro3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void gyro3_get_axes(gyro3_t *ctx, float *x_axis, float *y_axis, float *z_axis, uint8_t measurement_range)
Get XYZ axes dps values.
void gyro3_cfg_setup(gyro3_cfg_t *cfg)
Config Object Initialization function.
GYRO3_RETVAL gyro3_init(gyro3_t *ctx, gyro3_cfg_t *cfg)
Initialization function.
void gyro3_set_int1_thresholds(gyro3_t *ctx, int16_t x_threshold, int16_t y_threshold, int16_t z_threshold)
Setting values for interrupt thresholds.
void gyro3_generic_read(gyro3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t gyro3_set_int1_duration(gyro3_t *ctx, uint8_t wait_enable_bit, uint8_t duration_value)
Setting interrupt duration time on INT1 pin.
void gyro3_get_fifo_data_level(gyro3_t *ctx, uint8_t *fifo_data_level)
Get FIFO data level.
void(* gyro3_master_io_t)(struct gyro3_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition gyro3.h:268
uint8_t gyro3_select_t
Communication type.
Definition gyro3.h:263
struct gyro3_s gyro3_t
Click ctx object definition.
Click configuration structure definition.
Definition gyro3.h:302
pin_name_t di2
Definition gyro3.h:314
uint32_t i2c_speed
Definition gyro3.h:319
gyro3_select_t sel
Definition gyro3.h:326
spi_master_chip_select_polarity_t cs_polarity
Definition gyro3.h:324
pin_name_t sck
Definition gyro3.h:309
spi_master_mode_t spi_mode
Definition gyro3.h:323
pin_name_t mosi
Definition gyro3.h:308
uint32_t spi_speed
Definition gyro3.h:322
pin_name_t scl
Definition gyro3.h:305
pin_name_t int_pin
Definition gyro3.h:315
pin_name_t miso
Definition gyro3.h:307
pin_name_t sda
Definition gyro3.h:306
pin_name_t cs
Definition gyro3.h:310
uint8_t i2c_address
Definition gyro3.h:320
Click ctx object definition.
Definition gyro3.h:274
digital_out_t cs
Definition gyro3.h:277
digital_in_t di2
Definition gyro3.h:281
spi_master_t spi
Definition gyro3.h:287
gyro3_master_io_t write_f
Definition gyro3.h:293
digital_in_t int_pin
Definition gyro3.h:282
i2c_master_t i2c
Definition gyro3.h:286
gyro3_master_io_t read_f
Definition gyro3.h:294
uint8_t slave_address
Definition gyro3.h:291
pin_name_t chip_select
Definition gyro3.h:292
gyro3_select_t master_sel
Definition gyro3.h:295