gyro6  2.0.0.0
gyro6.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 GYRO6_H
29 #define GYRO6_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 GYRO6_REG_SELF_TEST_X_GYRO 0x00
62 #define GYRO6_REG_SELF_TEST_Y_GYRO 0x01
63 #define GYRO6_REG_SELF_TEST_Z_GYRO 0x02
64 #define GYRO6_REG_XG_OFFS_USRH 0x13
65 #define GYRO6_REG_XG_OFFS_USRL 0x14
66 #define GYRO6_REG_YG_OFFS_USRH 0x15
67 #define GYRO6_REG_YG_OFFS_USRL 0x16
68 #define GYRO6_REG_ZG_OFFS_USRH 0x17
69 #define GYRO6_REG_ZG_OFFS_USRL 0x18
70 #define GYRO6_REG_SMPLRT_DIV 0x19
71 #define GYRO6_REG_CONFIG 0x1A
72 #define GYRO6_REG_GYRO_CONFIG 0x1B
73 #define GYRO6_REG_LP_MODE_CFG 0x1E
74 #define GYRO6_REG_FIFO_EN 0x23
75 #define GYRO6_REG_FSYNC_INT 0x36
76 #define GYRO6_REG_INT_PIN_CFG 0x37
77 #define GYRO6_REG_INT_ENABLE 0x38
78 #define GYRO6_REG_INT_STATUS 0x3A
79 #define GYRO6_REG_TEMP_OUT_H 0x41
80 #define GYRO6_REG_TEMP_OUT_L 0x42
81 #define GYRO6_REG_GYRO_XOUT_H 0x43
82 #define GYRO6_REG_GYRO_XOUT_L 0x44
83 #define GYRO6_REG_GYRO_YOUT_H 0x45
84 #define GYRO6_REG_GYRO_YOUT_L 0x46
85 #define GYRO6_REG_GYRO_ZOUT_H 0x47
86 #define GYRO6_REG_GYRO_ZOUT_L 0x48
87 #define GYRO6_REG_SIGNAL_PATH_RESET 0x68
88 #define GYRO6_REG_USER_CTRL 0x6A
89 #define GYRO6_REG_PWR_MGMT_1 0x6B
90 #define GYRO6_REG_PWR_MGMT_2 0x6C
91 #define GYRO6_REG_FIFO_COUNTH 0x72
92 #define GYRO6_REG_FIFO_COUNTL 0x73
93 #define GYRO6_REG_FIFO_R_W 0x74
94 #define GYRO6_REG_WHO_AM_I 0x75
95  // gyro6_reg
97 
112 #define GYRO6_CONFIG_FIFO_MODE 0x40
113 #define GYRO6_CONFIG_EXT_SYNC_DIS 0x00
114 #define GYRO6_CONFIG_EXT_SYNC_TEMP_OUT_L 0x08
115 #define GYRO6_CONFIG_EXT_SYNC_GYRO_XOUT_L 0x10
116 #define GYRO6_CONFIG_EXT_SYNC_GYRO_YOUT_L 0x18
117 #define GYRO6_CONFIG_EXT_SYNC_GYRO_ZOUT_L 0x20
118 #define GYRO6_CONFIG_FIFO_MODE 0x40
119 #define GYRO6_CONFIG_DLPF_CFG_0 0x00
120 #define GYRO6_CONFIG_DLPF_CFG_1 0x01
121 #define GYRO6_CONFIG_DLPF_CFG_2 0x02
122 #define GYRO6_CONFIG_DLPF_CFG_3 0x03
123 #define GYRO6_CONFIG_DLPF_CFG_4 0x04
124 #define GYRO6_CONFIG_DLPF_CFG_5 0x05
125 #define GYRO6_CONFIG_DLPF_CFG_6 0x06
126 #define GYRO6_CONFIG_DLPF_CFG_7 0x07
127 
132 #define GYRO6_GYRO_CONFIG_XG_ST 0x80
133 #define GYRO6_GYRO_CONFIG_YG_ST 0x40
134 #define GYRO6_GYRO_CONFIG_ZG_ST 0x20
135 #define GYRO6_GYRO_CONFIG_FS_SEL_250DPS 0x00
136 #define GYRO6_GYRO_CONFIG_FS_SEL_500DPS 0x08
137 #define GYRO6_GYRO_CONFIG_FS_SEL_1000DPS 0x10
138 #define GYRO6_GYRO_CONFIG_FS_SEL_2000DPS 0x18
139 #define GYRO6_GYRO_CONFIG_FS_SEL_BITS_MASK 0x18
140 #define GYRO6_GYRO_CONFIG_FCHOICE_B_0 0x00
141 #define GYRO6_GYRO_CONFIG_FCHOICE_B_1 0x01
142 #define GYRO6_GYRO_CONFIG_FCHOICE_B_2 0x02
143 #define GYRO6_GYRO_CONFIG_FCHOICE_B_3 0x03
144 
150 #define GYRO6_SAMPLE_RATE_3p9HZ 255
151 #define GYRO6_SAMPLE_RATE_10HZ 99
152 #define GYRO6_SAMPLE_RATE_15p4HZ 64
153 #define GYRO6_SAMPLE_RATE_30p3HZ 32
154 #define GYRO6_SAMPLE_RATE_50HZ 19
155 #define GYRO6_SAMPLE_RATE_100HZ 9
156 #define GYRO6_SAMPLE_RATE_125HZ 7
157 #define GYRO6_SAMPLE_RATE_200HZ 4
158 #define GYRO6_SAMPLE_RATE_250HZ 3
159 #define GYRO6_SAMPLE_RATE_333p3HZ 2
160 #define GYRO6_SAMPLE_RATE_500HZ 1
161 #define GYRO6_SAMPLE_RATE_1000HZ 0
162 
167 #define GYRO6_LP_MODE_CFG_GYRO_CYCLE 0x80
168 #define GYRO6_LP_MODE_CFG_G_AVGCFG_1X 0x00
169 #define GYRO6_LP_MODE_CFG_G_AVGCFG_2X 0x10
170 #define GYRO6_LP_MODE_CFG_G_AVGCFG_4X 0x20
171 #define GYRO6_LP_MODE_CFG_G_AVGCFG_8X 0x30
172 #define GYRO6_LP_MODE_CFG_G_AVGCFG_16X 0x40
173 #define GYRO6_LP_MODE_CFG_G_AVGCFG_32X 0x50
174 #define GYRO6_LP_MODE_CFG_G_AVGCFG_64X 0x60
175 #define GYRO6_LP_MODE_CFG_G_AVGCFG_128X 0x70
176 
181 #define GYRO6_FIFO_EN_TEMP_FIFO_EN 0x80
182 #define GYRO6_FIFO_EN_XG_FIFO_EN 0x40
183 #define GYRO6_FIFO_EN_YG_FIFO_EN 0x20
184 #define GYRO6_FIFO_EN_ZG_FIFO_EN 0x10
185 
190 #define GYRO6_FSYNC_INT 0x80
191 
196 #define GYRO6_INT_PIN_CFG_INT_LEVEL 0x80
197 #define GYRO6_INT_PIN_CFG_INT_OPEN 0x40
198 #define GYRO6_INT_PIN_CFG_LATCH_INT_EN 0x20
199 #define GYRO6_INT_PIN_CFG_INT_RD_CLEAR 0x10
200 #define GYRO6_INT_PIN_CFG_FSYNC_INT_LEVEL 0x08
201 #define GYRO6_INT_PIN_CFG_FSYNC_INT_MODE_EN 0x04
202 
207 #define GYRO6_INT_ENABLE_FIFO_OFLOW_INT_EN 0x10
208 #define GYRO6_INT_ENABLE_GDRIVE_INT_EN 0x04
209 #define GYRO6_INT_ENABLE_DATA_RDY_INT_EN 0x01
210 
215 #define GYRO6_INT_STATUS_FIFO_OFLOW_INT 0x10
216 #define GYRO6_INT_STATUS_GDRIVE_INT 0x04
217 #define GYRO6_INT_STATUS_DATA_RDY_INT 0x01
218 
223 #define GYRO6_ROOM_TEMP_OFFSET 0
224 #define GYRO6_TEMP_SENSITIVITY 326.8
225 #define GYRO6_TEMP_NOMINAL 25.0
226 
231 #define GYRO6_GYRO_SENSITIVITY_FS_SEL_0 131.0
232 #define GYRO6_GYRO_SENSITIVITY_FS_SEL_1 65.5
233 #define GYRO6_GYRO_SENSITIVITY_FS_SEL_2 32.8
234 #define GYRO6_GYRO_SENSITIVITY_FS_SEL_3 16.4
235 
240 #define GYRO6_SIGNAL_PATH_RESET_TEMP_RST 0x01
241 
246 #define GYRO6_USER_CTRL_FIFO_EN 0x40
247 #define GYRO6_USER_CTRL_I2C_IF_DIS 0x10
248 #define GYRO6_USER_CTRL_FIFO_RST 0x04
249 #define GYRO6_USER_CTRL_SIG_COND_RST 0x01
250 
255 #define GYRO6_PWR_MGMT_1_DEVICE_RESET 0x80
256 #define GYRO6_PWR_MGMT_1_SLEEP 0x40
257 #define GYRO6_PWR_MGMT_1_GYRO_STANDBY 0x10
258 #define GYRO6_PWR_MGMT_1_INTERNAL_OSC 0x00
259 #define GYRO6_PWR_MGMT_1_AUTO_SEL_CLOCK 0x01
260 #define GYRO6_PWR_MGMT_1_STOP_CLOCK 0x07
261 
266 #define GYRO6_PWR_MGMT_2_DISABLE_X_GYRO 0x04
267 #define GYRO6_PWR_MGMT_2_DISABLE_Y_GYRO 0x02
268 #define GYRO6_PWR_MGMT_2_DISABLE_Z_GYRO 0x01
269 
274 #define GYRO6_DEVICE_ID 0xB5
275 
281 #define GYRO6_SET_DEV_ADDR_0 0x68
282 #define GYRO6_SET_DEV_ADDR_1 0x69
283 
292 #define GYRO6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
293 #define GYRO6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
294  // gyro6_set
296 
311 #define GYRO6_MAP_MIKROBUS( cfg, mikrobus ) \
312  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
313  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
314  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
315  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
316  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
317  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
318  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
319  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
320  // gyro6_map // gyro6
323 
328 typedef enum
329 {
333 } gyro6_drv_t;
334 
339 typedef err_t ( *gyro6_master_io_t )( struct gyro6_s*, uint8_t, uint8_t*, uint8_t );
345 typedef struct gyro6_s
346 {
347  digital_out_t pwm;
349  digital_in_t int_pin;
351  i2c_master_t i2c;
352  spi_master_t spi;
354  uint8_t slave_address;
355  pin_name_t chip_select;
361 } gyro6_t;
362 
367 typedef struct
368 {
369  pin_name_t scl;
370  pin_name_t sda;
371  pin_name_t miso;
372  pin_name_t mosi;
373  pin_name_t sck;
374  pin_name_t cs;
375  pin_name_t pwm;
376  pin_name_t int_pin;
378  uint32_t i2c_speed;
379  uint8_t i2c_address;
381  uint32_t spi_speed;
382  spi_master_mode_t spi_mode;
383  spi_master_chip_select_polarity_t cs_polarity;
387 } gyro6_cfg_t;
388 
393 typedef enum
394 {
395  GYRO6_OK = 0,
397 
399 
415 void gyro6_cfg_setup ( gyro6_cfg_t *cfg );
416 
432 
447 err_t gyro6_init ( gyro6_t *ctx, gyro6_cfg_t *cfg );
448 
462 err_t gyro6_default_cfg ( gyro6_t *ctx );
463 
479 err_t gyro6_generic_write ( gyro6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
480 
496 err_t gyro6_generic_read ( gyro6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
497 
511 err_t gyro6_write_register ( gyro6_t *ctx, uint8_t reg, uint8_t data_in );
512 
526 err_t gyro6_read_register ( gyro6_t *ctx, uint8_t reg, uint8_t *data_out );
527 
536 uint8_t gyro6_get_int_pin ( gyro6_t *ctx );
537 
547 void gyro6_set_pwm_pin ( gyro6_t *ctx, uint8_t state );
548 
560 err_t gyro6_check_communication ( gyro6_t *ctx );
561 
574 err_t gyro6_read_die_temperature ( gyro6_t *ctx, float *temperature );
575 
590 err_t gyro6_get_axis ( gyro6_t *ctx, float *x_axis, float *y_axis, float *z_axis );
591 
606 err_t gyro6_set_low_power_mode ( gyro6_t *ctx, uint8_t sample_rate, uint8_t average );
607 
608 #ifdef __cplusplus
609 }
610 #endif
611 #endif // GYRO6_H
612  // gyro6
614 
615 // ------------------------------------------------------------------------ END
GYRO6_OK
Definition: gyro6.h:395
gyro6_s::slave_address
uint8_t slave_address
Definition: gyro6.h:354
gyro6_cfg_t::pwm
pin_name_t pwm
Definition: gyro6.h:375
gyro6_init
err_t gyro6_init(gyro6_t *ctx, gyro6_cfg_t *cfg)
Gyro 6 initialization function.
gyro6_s::pwm
digital_out_t pwm
Definition: gyro6.h:347
gyro6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: gyro6.h:378
gyro6_s
Gyro 6 Click context object.
Definition: gyro6.h:345
spi_specifics.h
This file contains SPI specific macros, functions, etc.
gyro6_read_register
err_t gyro6_read_register(gyro6_t *ctx, uint8_t reg, uint8_t *data_out)
Gyro 6 read register function.
gyro6_cfg_t::cs
pin_name_t cs
Definition: gyro6.h:374
gyro6_s::chip_select
pin_name_t chip_select
Definition: gyro6.h:355
gyro6_cfg_setup
void gyro6_cfg_setup(gyro6_cfg_t *cfg)
Gyro 6 configuration object setup function.
gyro6_t
struct gyro6_s gyro6_t
Gyro 6 Click context object.
gyro6_cfg_t::spi_speed
uint32_t spi_speed
Definition: gyro6.h:381
gyro6_read_die_temperature
err_t gyro6_read_die_temperature(gyro6_t *ctx, float *temperature)
Gyro 6 read DIE temperature function.
gyro6_cfg_t::sck
pin_name_t sck
Definition: gyro6.h:373
gyro6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gyro6.h:382
gyro6_s::drv_sel
gyro6_drv_t drv_sel
Definition: gyro6.h:356
gyro6_s::write_f
gyro6_master_io_t write_f
Definition: gyro6.h:358
gyro6_return_value_t
gyro6_return_value_t
Gyro 6 Click return value data.
Definition: gyro6.h:393
gyro6_s::spi
spi_master_t spi
Definition: gyro6.h:352
gyro6_cfg_t::drv_sel
gyro6_drv_t drv_sel
Definition: gyro6.h:385
gyro6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gyro6.h:383
GYRO6_DRV_SEL_SPI
Definition: gyro6.h:330
gyro6_set_pwm_pin
void gyro6_set_pwm_pin(gyro6_t *ctx, uint8_t state)
Gyro 6 set PWM pin function.
gyro6_check_communication
err_t gyro6_check_communication(gyro6_t *ctx)
Gyro 6 check communication function.
gyro6_cfg_t::mosi
pin_name_t mosi
Definition: gyro6.h:372
gyro6_s::int_pin
digital_in_t int_pin
Definition: gyro6.h:349
gyro6_cfg_t::miso
pin_name_t miso
Definition: gyro6.h:371
GYRO6_ERROR
Definition: gyro6.h:396
gyro6_cfg_t::scl
pin_name_t scl
Definition: gyro6.h:369
gyro6_s::read_f
gyro6_master_io_t read_f
Definition: gyro6.h:359
gyro6_generic_write
err_t gyro6_generic_write(gyro6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Gyro 6 data writing function.
gyro6_cfg_t::i2c_address
uint8_t i2c_address
Definition: gyro6.h:379
gyro6_drv_t
gyro6_drv_t
Gyro 6 Click driver selector.
Definition: gyro6.h:328
GYRO6_DRV_SEL_I2C
Definition: gyro6.h:331
gyro6_drv_interface_selection
void gyro6_drv_interface_selection(gyro6_cfg_t *cfg, gyro6_drv_t drv_sel)
Gyro 6 driver interface setup function.
gyro6_master_io_t
err_t(* gyro6_master_io_t)(struct gyro6_s *, uint8_t, uint8_t *, uint8_t)
Gyro 6 Click driver interface.
Definition: gyro6.h:339
gyro6_set_low_power_mode
err_t gyro6_set_low_power_mode(gyro6_t *ctx, uint8_t sample_rate, uint8_t average)
Gyro 6 set low power mode function.
gyro6_s::i2c
i2c_master_t i2c
Definition: gyro6.h:351
gyro6_generic_read
err_t gyro6_generic_read(gyro6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Gyro 6 data reading function.
gyro6_get_axis
err_t gyro6_get_axis(gyro6_t *ctx, float *x_axis, float *y_axis, float *z_axis)
Gyro 6 get axis function.
gyro6_default_cfg
err_t gyro6_default_cfg(gyro6_t *ctx)
Gyro 6 default configuration function.
gyro6_cfg_t::int_pin
pin_name_t int_pin
Definition: gyro6.h:376
gyro6_write_register
err_t gyro6_write_register(gyro6_t *ctx, uint8_t reg, uint8_t data_in)
Gyro 6 write register function.
gyro6_cfg_t::sda
pin_name_t sda
Definition: gyro6.h:370
gyro6_get_int_pin
uint8_t gyro6_get_int_pin(gyro6_t *ctx)
Gyro 6 get INT pin function.
gyro6_cfg_t
Gyro 6 Click configuration object.
Definition: gyro6.h:367