gyro9 2.1.0.0
gyro9.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 GYRO9_H
29#define GYRO9_H
30
31#ifdef __cplusplus
32extern "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_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define GYRO9_REG_WHO_AM_I 0x0F
76#define GYRO9_REG_CTRL_REG1 0x20
77#define GYRO9_REG_CTRL_REG2 0x21
78#define GYRO9_REG_CTRL_REG3 0x22
79#define GYRO9_REG_CTRL_REG4 0x23
80#define GYRO9_REG_CTRL_REG5 0x24
81#define GYRO9_REG_REFERENCE 0x25
82#define GYRO9_REG_OUT_TEMP 0x26
83#define GYRO9_REG_STATUS_REG 0x27
84#define GYRO9_REG_OUT_X_L 0x28
85#define GYRO9_REG_OUT_X_H 0x29
86#define GYRO9_REG_OUT_Y_L 0x2A
87#define GYRO9_REG_OUT_Y_H 0x2B
88#define GYRO9_REG_OUT_Z_L 0x2C
89#define GYRO9_REG_OUT_Z_H 0x2D
90#define GYRO9_REG_FIFO_CTRL_REG 0x2E
91#define GYRO9_REG_FIFO_SRC_REG 0x2F
92#define GYRO9_REG_INT1_CFG 0x30
93#define GYRO9_REG_INT1_SRC 0x31
94#define GYRO9_REG_INT1_TSH_XH 0x32
95#define GYRO9_REG_INT1_TSH_XL 0x33
96#define GYRO9_REG_INT1_TSH_YH 0x34
97#define GYRO9_REG_INT1_TSH_YL 0x35
98#define GYRO9_REG_INT1_TSH_ZH 0x36
99#define GYRO9_REG_INT1_TSH_ZL 0x37
100#define GYRO9_REG_INT1_DURATION 0x38
101
102 // gyro9_reg
103
118#define GYRO9_WHO_AM_I 0xD3
119
124#define GYRO9_ODR_100_HZ 0x00
125#define GYRO9_ODR_200_HZ 0x01
126#define GYRO9_ODR_400_HZ 0x02
127#define GYRO9_ODR_800_HZ 0x03
128#define GYRO9_ODR_BIT_MASK 0xC0
129
134#define GYRO9_BW_0 0x00
135#define GYRO9_BW_1 0x01
136#define GYRO9_BW_2 0x02
137#define GYRO9_BW_3 0x03
138#define GYRO9_BW_BIT_MASK 0x30
139
144#define GYRO9_PD_POWER_DOWN 0x00
145#define GYRO9_PD_SLEEP 0x08
146#define GYRO9_PD_NORMAL 0x0F
147#define GYRO9_PD_BIT_MASK 0x08
148
153#define GYRO9_FIFO_CTRL_BYPASS_MODE 0x00
154#define GYRO9_FIFO_CTRL_FIFO_MODE 0x01
155#define GYRO9_FIFO_CTRL_STREAM_MODE 0x02
156#define GYRO9_FIFO_CTRL_BIT_MASK 0xE0
157
162#define GYRO9_CTRL_I1_INT1_EN 0x80
163#define GYRO9_CTRL_I1_INT1_DIS 0x00
164#define GYRO9_CTRL_I1_BOOT_EN 0x40
165#define GYRO9_CTRL_I1_BOOT_DIS 0x00
166#define GYRO9_CTRL_H_LACTIVE_EN 0x20
167#define GYRO9_CTRL_H_LACTIVE_DIS 0x00
168#define GYRO9_CTRL_PP_OD_EN 0x10
169#define GYRO9_CTRL_PP_OD_DIS 0x00
170#define GYRO9_CTRL_I2_DRDY_EN 0x08
171#define GYRO9_CTRL_I2_DRDY_DIS 0x00
172#define GYRO9_CTRL_I2_WTM_EN 0x04
173#define GYRO9_CTRL_I2_WTM_DIS 0x00
174#define GYRO9_CTRL_I2_ORUN_EN 0x02
175#define GYRO9_CTRL_I2_ORUN_DIS 0x00
176#define GYRO9_CTRL_I2_EMPTY_EN 0x01
177#define GYRO9_CTRL_I2_EMPTY_DIS 0x00
178
183#define GYRO9_SENSITIVITY_DPS 0.00875f
184
190#define GYRO9_DEVICE_ADDRESS_GND 0x68
191#define GYRO9_DEVICE_ADDRESS_VCC 0x69
192
201#define GYRO9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
202#define GYRO9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
203
204 // gyro9_set
205
220#define GYRO9_MAP_MIKROBUS( cfg, mikrobus ) \
221 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
222 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
223 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
224 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
225 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
226 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
227 cfg.dr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
228 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
229
230 // gyro9_map
231 // gyro9
232
243
248typedef err_t ( *gyro9_master_io_t )( struct gyro9_s*, uint8_t, uint8_t*, uint8_t );
254typedef struct gyro9_s
255{
256 digital_in_t dr;
257 digital_in_t int_pin;
259 i2c_master_t i2c;
260 spi_master_t spi;
263 pin_name_t chip_select;
270
275typedef struct
276{
277 pin_name_t scl;
278 pin_name_t sda;
279 pin_name_t miso;
280 pin_name_t mosi;
281 pin_name_t sck;
282 pin_name_t cs;
283 pin_name_t dr;
284 pin_name_t int_pin;
286 uint32_t i2c_speed;
287 uint8_t i2c_address;
289 uint32_t spi_speed;
290 spi_master_mode_t spi_mode;
291 spi_master_chip_select_polarity_t cs_polarity;
296
301typedef struct
302{
303 int16_t x;
304 int16_t y;
305 int16_t z;
308
309
314typedef struct
315{
316 float x;
317 float y;
318 float z;
321
326typedef enum
327{
329 GYRO9_ERROR = -1
330
332
349
365
379err_t gyro9_init ( gyro9_t *ctx, gyro9_cfg_t *cfg );
380
394
409err_t gyro9_generic_write ( gyro9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
410
425err_t gyro9_generic_read ( gyro9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
426
440err_t gyro9_get_device_id ( gyro9_t *ctx, uint8_t *who_am_i );
441
455err_t gyro9_set_output_data_rate ( gyro9_t *ctx, uint8_t odr );
456
470err_t gyro9_set_bandwidth_sel ( gyro9_t *ctx, uint8_t bandwidth );
471
485
499
513
527err_t gyro9_set_fifo_mode ( gyro9_t *ctx, uint8_t fifo_mode );
528
542
556err_t gyro9_get_status ( gyro9_t *ctx, uint8_t *status );
557
573
588err_t gyro9_get_gyro_axis ( gyro9_t *ctx, gyro9_axis_t *gyro_axis );
589
603err_t gyro9_get_temperature_raw ( gyro9_t *ctx, int8_t *temp_raw );
604
617
630
631#ifdef __cplusplus
632}
633#endif
634#endif // GYRO9_H
635
636 // gyro9
637
638// ------------------------------------------------------------------------ END
err_t gyro9_get_axis_data(gyro9_t *ctx, gyro9_axis_data_t *gyro_axis)
Gyro 9 get gyro data function.
void gyro9_drv_interface_selection(gyro9_cfg_t *cfg, gyro9_drv_t drv_sel)
Gyro 9 driver interface setup function.
err_t gyro9_get_gyro_axis(gyro9_t *ctx, gyro9_axis_t *gyro_axis)
Gyro 9 get gyro sensor axes function.
err_t gyro9_default_cfg(gyro9_t *ctx)
Gyro 9 default configuration function.
err_t gyro9_generic_write(gyro9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Gyro 9 data writing function.
uint8_t gyro9_get_data_ready(gyro9_t *ctx)
Gyro 9 get data ready function.
err_t gyro9_set_output_data_rate(gyro9_t *ctx, uint8_t odr)
Gyro 9 set output data rate function.
err_t gyro9_get_status(gyro9_t *ctx, uint8_t *status)
Gyro 9 get status function.
err_t gyro9_generic_read(gyro9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Gyro 9 data reading function.
err_t gyro9_get_device_id(gyro9_t *ctx, uint8_t *who_am_i)
Gyro 9 get device ID function.
err_t gyro9_get_temperature_raw(gyro9_t *ctx, int8_t *temp_raw)
Gyro 9 get temperature data function.
err_t gyro9_init(gyro9_t *ctx, gyro9_cfg_t *cfg)
Gyro 9 initialization function.
err_t gyro9_set_fifo_mode(gyro9_t *ctx, uint8_t fifo_mode)
Gyro 9 set FIFO mode function.
err_t gyro9_set_mode_sleep(gyro9_t *ctx)
Gyro 9 set sleep mode function.
err_t gyro9_set_mode_pd(gyro9_t *ctx)
Gyro 9 set power-down mode function.
err_t gyro9_set_bandwidth_sel(gyro9_t *ctx, uint8_t bandwidth)
Gyro 9 set bandwidth function.
void gyro9_cfg_setup(gyro9_cfg_t *cfg)
Gyro 9 configuration object setup function.
err_t gyro9_enable_data_ready(gyro9_t *ctx)
Gyro 9 enable data ready function.
err_t gyro9_set_mode_normal(gyro9_t *ctx)
Gyro 9 set normal mode function.
uint8_t gyro9_get_interrupt(gyro9_t *ctx)
Gyro 9 get interrupt function.
gyro9_return_value_t
Gyro 9 Click return value data.
Definition gyro9.h:327
@ GYRO9_ERROR
Definition gyro9.h:329
@ GYRO9_OK
Definition gyro9.h:328
err_t(* gyro9_master_io_t)(struct gyro9_s *, uint8_t, uint8_t *, uint8_t)
Gyro 9 Click driver interface.
Definition gyro9.h:248
gyro9_drv_t
Gyro 9 Click driver selector.
Definition gyro9.h:238
@ GYRO9_DRV_SEL_I2C
Definition gyro9.h:240
@ GYRO9_DRV_SEL_SPI
Definition gyro9.h:239
struct gyro9_s gyro9_t
Gyro 9 Click context object.
This file contains SPI specific macros, functions, etc.
Gyro 9 Click axis raw data structure object.
Definition gyro9.h:302
int16_t z
Definition gyro9.h:305
int16_t x
Definition gyro9.h:303
int16_t y
Definition gyro9.h:304
Gyro 9 Click sensor axes structure object.
Definition gyro9.h:315
float y
Definition gyro9.h:317
float x
Definition gyro9.h:316
float z
Definition gyro9.h:318
Gyro 9 Click configuration object.
Definition gyro9.h:276
gyro9_drv_t drv_sel
Definition gyro9.h:293
pin_name_t dr
Definition gyro9.h:283
uint32_t i2c_speed
Definition gyro9.h:286
spi_master_chip_select_polarity_t cs_polarity
Definition gyro9.h:291
pin_name_t sck
Definition gyro9.h:281
spi_master_mode_t spi_mode
Definition gyro9.h:290
pin_name_t mosi
Definition gyro9.h:280
uint32_t spi_speed
Definition gyro9.h:289
pin_name_t scl
Definition gyro9.h:277
pin_name_t int_pin
Definition gyro9.h:284
pin_name_t miso
Definition gyro9.h:279
pin_name_t sda
Definition gyro9.h:278
pin_name_t cs
Definition gyro9.h:282
uint8_t i2c_address
Definition gyro9.h:287
Gyro 9 Click context object.
Definition gyro9.h:255
spi_master_t spi
Definition gyro9.h:260
gyro9_master_io_t write_f
Definition gyro9.h:266
gyro9_drv_t drv_sel
Definition gyro9.h:264
gyro9_master_io_t read_f
Definition gyro9.h:267
digital_in_t int_pin
Definition gyro9.h:257
i2c_master_t i2c
Definition gyro9.h:259
uint8_t slave_address
Definition gyro9.h:262
digital_in_t dr
Definition gyro9.h:256
pin_name_t chip_select
Definition gyro9.h:263