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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_spi_master.h"
39 #include "spi_specifics.h"
40 
61 #define GYRO9_REG_WHO_AM_I 0x0F
62 #define GYRO9_REG_CTRL_REG1 0x20
63 #define GYRO9_REG_CTRL_REG2 0x21
64 #define GYRO9_REG_CTRL_REG3 0x22
65 #define GYRO9_REG_CTRL_REG4 0x23
66 #define GYRO9_REG_CTRL_REG5 0x24
67 #define GYRO9_REG_REFERENCE 0x25
68 #define GYRO9_REG_OUT_TEMP 0x26
69 #define GYRO9_REG_STATUS_REG 0x27
70 #define GYRO9_REG_OUT_X_L 0x28
71 #define GYRO9_REG_OUT_X_H 0x29
72 #define GYRO9_REG_OUT_Y_L 0x2A
73 #define GYRO9_REG_OUT_Y_H 0x2B
74 #define GYRO9_REG_OUT_Z_L 0x2C
75 #define GYRO9_REG_OUT_Z_H 0x2D
76 #define GYRO9_REG_FIFO_CTRL_REG 0x2E
77 #define GYRO9_REG_FIFO_SRC_REG 0x2F
78 #define GYRO9_REG_INT1_CFG 0x30
79 #define GYRO9_REG_INT1_SRC 0x31
80 #define GYRO9_REG_INT1_TSH_XH 0x32
81 #define GYRO9_REG_INT1_TSH_XL 0x33
82 #define GYRO9_REG_INT1_TSH_YH 0x34
83 #define GYRO9_REG_INT1_TSH_YL 0x35
84 #define GYRO9_REG_INT1_TSH_ZH 0x36
85 #define GYRO9_REG_INT1_TSH_ZL 0x37
86 #define GYRO9_REG_INT1_DURATION 0x38
87  // gyro9_reg
89 
104 #define GYRO9_WHO_AM_I 0xD3
105 
110 #define GYRO9_ODR_100_HZ 0x00
111 #define GYRO9_ODR_200_HZ 0x01
112 #define GYRO9_ODR_400_HZ 0x02
113 #define GYRO9_ODR_800_HZ 0x03
114 #define GYRO9_ODR_BIT_MASK 0xC0
115 
120 #define GYRO9_BW_0 0x00
121 #define GYRO9_BW_1 0x01
122 #define GYRO9_BW_2 0x02
123 #define GYRO9_BW_3 0x03
124 #define GYRO9_BW_BIT_MASK 0x30
125 
130 #define GYRO9_PD_POWER_DOWN 0x00
131 #define GYRO9_PD_SLEEP 0x08
132 #define GYRO9_PD_NORMAL 0x0F
133 #define GYRO9_PD_BIT_MASK 0x08
134 
139 #define GYRO9_FIFO_CTRL_BYPASS_MODE 0x00
140 #define GYRO9_FIFO_CTRL_FIFO_MODE 0x01
141 #define GYRO9_FIFO_CTRL_STREAM_MODE 0x02
142 #define GYRO9_FIFO_CTRL_BIT_MASK 0xE0
143 
148 #define GYRO9_CTRL_I1_INT1_EN 0x80
149 #define GYRO9_CTRL_I1_INT1_DIS 0x00
150 #define GYRO9_CTRL_I1_BOOT_EN 0x40
151 #define GYRO9_CTRL_I1_BOOT_DIS 0x00
152 #define GYRO9_CTRL_H_LACTIVE_EN 0x20
153 #define GYRO9_CTRL_H_LACTIVE_DIS 0x00
154 #define GYRO9_CTRL_PP_OD_EN 0x10
155 #define GYRO9_CTRL_PP_OD_DIS 0x00
156 #define GYRO9_CTRL_I2_DRDY_EN 0x08
157 #define GYRO9_CTRL_I2_DRDY_DIS 0x00
158 #define GYRO9_CTRL_I2_WTM_EN 0x04
159 #define GYRO9_CTRL_I2_WTM_DIS 0x00
160 #define GYRO9_CTRL_I2_ORUN_EN 0x02
161 #define GYRO9_CTRL_I2_ORUN_DIS 0x00
162 #define GYRO9_CTRL_I2_EMPTY_EN 0x01
163 #define GYRO9_CTRL_I2_EMPTY_DIS 0x00
164 
169 #define GYRO9_SENSITIVITY_DPS 0.00875f
170 
176 #define GYRO9_DEVICE_ADDRESS_GND 0x68
177 #define GYRO9_DEVICE_ADDRESS_VCC 0x69
178 
187 #define GYRO9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
188 #define GYRO9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
189  // gyro9_set
191 
206 #define GYRO9_MAP_MIKROBUS( cfg, mikrobus ) \
207  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
208  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
209  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
210  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
211  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
212  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
213  cfg.dr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
214  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
215  // gyro9_map // gyro9
218 
223 typedef enum
224 {
229 
234 typedef err_t ( *gyro9_master_io_t )( struct gyro9_s*, uint8_t, uint8_t*, uint8_t );
240 typedef struct gyro9_s
241 {
242  digital_in_t dr;
243  digital_in_t int_pin;
245  i2c_master_t i2c;
246  spi_master_t spi;
248  uint8_t slave_address;
249  pin_name_t chip_select;
256 
261 typedef struct
262 {
263  pin_name_t scl;
264  pin_name_t sda;
265  pin_name_t miso;
266  pin_name_t mosi;
267  pin_name_t sck;
268  pin_name_t cs;
269  pin_name_t dr;
270  pin_name_t int_pin;
272  uint32_t i2c_speed;
273  uint8_t i2c_address;
275  uint32_t spi_speed;
276  spi_master_mode_t spi_mode;
277  spi_master_chip_select_polarity_t cs_polarity;
281 } gyro9_cfg_t;
282 
287 typedef struct
288 {
289  int16_t x;
290  int16_t y;
291  int16_t z;
294 
295 
300 typedef struct
301 {
302  float x;
303  float y;
304  float z;
306 } gyro9_axis_t;
307 
312 typedef enum
313 {
314  GYRO9_OK = 0,
315  GYRO9_ERROR = -1
316 
318 
335 
351 
365 err_t gyro9_init ( gyro9_t *ctx, gyro9_cfg_t *cfg );
366 
379 err_t gyro9_default_cfg ( gyro9_t *ctx );
380 
395 err_t gyro9_generic_write ( gyro9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
396 
411 err_t gyro9_generic_read ( gyro9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
412 
426 err_t gyro9_get_device_id ( gyro9_t *ctx, uint8_t *who_am_i );
427 
441 err_t gyro9_set_output_data_rate ( gyro9_t *ctx, uint8_t odr );
442 
456 err_t gyro9_set_bandwidth_sel ( gyro9_t *ctx, uint8_t bandwidth );
457 
470 err_t gyro9_set_mode_pd ( gyro9_t *ctx );
471 
485 
499 
513 err_t gyro9_set_fifo_mode ( gyro9_t *ctx, uint8_t fifo_mode );
514 
528 
542 err_t gyro9_get_status ( gyro9_t *ctx, uint8_t *status );
543 
558 err_t gyro9_get_axis_data ( gyro9_t *ctx, gyro9_axis_data_t *gyro_axis );
559 
574 err_t gyro9_get_gyro_axis ( gyro9_t *ctx, gyro9_axis_t *gyro_axis );
575 
589 err_t gyro9_get_temperature_raw ( gyro9_t *ctx, int8_t *temp_raw );
590 
602 uint8_t gyro9_get_data_ready ( gyro9_t *ctx );
603 
615 uint8_t gyro9_get_interrupt ( gyro9_t *ctx );
616 
617 #ifdef __cplusplus
618 }
619 #endif
620 #endif // GYRO9_H
621  // gyro9
623 
624 // ------------------------------------------------------------------------ END
gyro9_cfg_t::cs
pin_name_t cs
Definition: gyro9.h:268
gyro9_return_value_t
gyro9_return_value_t
Gyro 9 Click return value data.
Definition: gyro9.h:313
gyro9_cfg_setup
void gyro9_cfg_setup(gyro9_cfg_t *cfg)
Gyro 9 configuration object setup function.
gyro9_cfg_t::i2c_address
uint8_t i2c_address
Definition: gyro9.h:273
gyro9_drv_interface_selection
void gyro9_drv_interface_selection(gyro9_cfg_t *cfg, gyro9_drv_t drv_sel)
Gyro 9 driver interface setup function.
gyro9_init
err_t gyro9_init(gyro9_t *ctx, gyro9_cfg_t *cfg)
Gyro 9 initialization function.
gyro9_t
struct gyro9_s gyro9_t
Gyro 9 Click context object.
gyro9_axis_data_t::z
int16_t z
Definition: gyro9.h:291
gyro9_axis_data_t::x
int16_t x
Definition: gyro9.h:289
gyro9_cfg_t::spi_speed
uint32_t spi_speed
Definition: gyro9.h:275
gyro9_drv_t
gyro9_drv_t
Gyro 9 Click driver selector.
Definition: gyro9.h:224
gyro9_get_interrupt
uint8_t gyro9_get_interrupt(gyro9_t *ctx)
Gyro 9 get interrupt function.
gyro9_axis_t::z
float z
Definition: gyro9.h:304
gyro9_set_mode_normal
err_t gyro9_set_mode_normal(gyro9_t *ctx)
Gyro 9 set normal mode function.
gyro9_cfg_t::mosi
pin_name_t mosi
Definition: gyro9.h:266
gyro9_s::chip_select
pin_name_t chip_select
Definition: gyro9.h:249
spi_specifics.h
This file contains SPI specific macros, functions, etc.
gyro9_set_fifo_mode
err_t gyro9_set_fifo_mode(gyro9_t *ctx, uint8_t fifo_mode)
Gyro 9 set FIFO mode function.
gyro9_set_output_data_rate
err_t gyro9_set_output_data_rate(gyro9_t *ctx, uint8_t odr)
Gyro 9 set output data rate function.
gyro9_s::slave_address
uint8_t slave_address
Definition: gyro9.h:248
gyro9_set_mode_sleep
err_t gyro9_set_mode_sleep(gyro9_t *ctx)
Gyro 9 set sleep mode function.
gyro9_cfg_t::drv_sel
gyro9_drv_t drv_sel
Definition: gyro9.h:279
gyro9_get_data_ready
uint8_t gyro9_get_data_ready(gyro9_t *ctx)
Gyro 9 get data ready function.
GYRO9_DRV_SEL_SPI
@ GYRO9_DRV_SEL_SPI
Definition: gyro9.h:225
gyro9_get_status
err_t gyro9_get_status(gyro9_t *ctx, uint8_t *status)
Gyro 9 get status function.
gyro9_default_cfg
err_t gyro9_default_cfg(gyro9_t *ctx)
Gyro 9 default configuration function.
gyro9_s
Gyro 9 Click context object.
Definition: gyro9.h:241
gyro9_axis_t::x
float x
Definition: gyro9.h:302
gyro9_axis_data_t
Gyro 9 Click axis raw data structure object.
Definition: gyro9.h:288
gyro9_get_gyro_axis
err_t gyro9_get_gyro_axis(gyro9_t *ctx, gyro9_axis_t *gyro_axis)
Gyro 9 get gyro sensor axes function.
gyro9_s::write_f
gyro9_master_io_t write_f
Definition: gyro9.h:252
gyro9_axis_data_t::y
int16_t y
Definition: gyro9.h:290
gyro9_s::int_pin
digital_in_t int_pin
Definition: gyro9.h:243
gyro9_s::spi
spi_master_t spi
Definition: gyro9.h:246
gyro9_set_mode_pd
err_t gyro9_set_mode_pd(gyro9_t *ctx)
Gyro 9 set power-down mode function.
gyro9_generic_write
err_t gyro9_generic_write(gyro9_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Gyro 9 data writing function.
GYRO9_DRV_SEL_I2C
@ GYRO9_DRV_SEL_I2C
Definition: gyro9.h:226
gyro9_cfg_t::int_pin
pin_name_t int_pin
Definition: gyro9.h:270
gyro9_cfg_t::dr
pin_name_t dr
Definition: gyro9.h:269
gyro9_s::i2c
i2c_master_t i2c
Definition: gyro9.h:245
gyro9_cfg_t::sda
pin_name_t sda
Definition: gyro9.h:264
gyro9_s::drv_sel
gyro9_drv_t drv_sel
Definition: gyro9.h:250
gyro9_cfg_t::sck
pin_name_t sck
Definition: gyro9.h:267
gyro9_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gyro9.h:277
gyro9_generic_read
err_t gyro9_generic_read(gyro9_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Gyro 9 data reading function.
gyro9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: gyro9.h:272
gyro9_s::dr
digital_in_t dr
Definition: gyro9.h:242
gyro9_enable_data_ready
err_t gyro9_enable_data_ready(gyro9_t *ctx)
Gyro 9 enable data ready function.
gyro9_get_temperature_raw
err_t gyro9_get_temperature_raw(gyro9_t *ctx, int8_t *temp_raw)
Gyro 9 get temperature data function.
gyro9_master_io_t
err_t(* gyro9_master_io_t)(struct gyro9_s *, uint8_t, uint8_t *, uint8_t)
Gyro 9 Click driver interface.
Definition: gyro9.h:234
gyro9_set_bandwidth_sel
err_t gyro9_set_bandwidth_sel(gyro9_t *ctx, uint8_t bandwidth)
Gyro 9 set bandwidth function.
gyro9_cfg_t::scl
pin_name_t scl
Definition: gyro9.h:263
gyro9_axis_t::y
float y
Definition: gyro9.h:303
GYRO9_OK
@ GYRO9_OK
Definition: gyro9.h:314
gyro9_cfg_t::miso
pin_name_t miso
Definition: gyro9.h:265
GYRO9_ERROR
@ GYRO9_ERROR
Definition: gyro9.h:315
gyro9_get_axis_data
err_t gyro9_get_axis_data(gyro9_t *ctx, gyro9_axis_data_t *gyro_axis)
Gyro 9 get gyro data function.
gyro9_axis_t
Gyro 9 Click sensor axes structure object.
Definition: gyro9.h:301
gyro9_get_device_id
err_t gyro9_get_device_id(gyro9_t *ctx, uint8_t *who_am_i)
Gyro 9 get device ID function.
gyro9_s::read_f
gyro9_master_io_t read_f
Definition: gyro9.h:253
gyro9_cfg_t
Gyro 9 Click configuration object.
Definition: gyro9.h:262
gyro9_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gyro9.h:276