gyro8 2.1.0.0
gyro8.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 GYRO8_H
29#define GYRO8_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_spi_master.h"
52#include "spi_specifics.h"
53
74#define GYRO8_REG_RATE 0x01
75#define GYRO8_REG_TEMP 0x07
76#define GYRO8_REG_RATE_STATUS_1 0x09
77#define GYRO8_REG_RATE_STATUS_2 0x0A
78#define GYRO8_REG_ACC_STATUS 0x0F
79#define GYRO8_REG_TEST 0x15
80#define GYRO8_REG_RESET_CONTROL 0x16
81#define GYRO8_REG_SERIAL_ID0 0x18
82#define GYRO8_REG_SERIAL_ID1 0x19
83#define GYRO8_REG_COMMON_STATUS 0x1B
84#define GYRO8_REG_ID 0x1D
85#define GYRO8_REG_STATUS_SUMMARY 0x1F
86
87 // gyro8_reg
88
103#define GYRO8_ID 0x0500
104
109#define GYRO8_TEMP_SENS 14.7f
110#define GYRO8_TEMP_OFFSET 60.0f
111#define GYRO8_GYRO_SENS 50.0f
112
121#define GYRO8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
122#define GYRO8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
123
124 // gyro8_set
125
140#define GYRO8_MAP_MIKROBUS( cfg, mikrobus ) \
141 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
142 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
143 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
144 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
145 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
146
147 // gyro8_map
148 // gyro8
149
154typedef struct
155{
156 // Output pins
157 digital_out_t rst;
159 // Modules
160 spi_master_t spi;
162 pin_name_t chip_select;
164} gyro8_t;
165
170typedef struct
171{
172 // Communication gpio pins
173 pin_name_t miso;
174 pin_name_t mosi;
175 pin_name_t sck;
176 pin_name_t cs;
178 // Additional gpio pins
179 pin_name_t rst;
181 // static variable
182 uint32_t spi_speed;
183 spi_master_mode_t spi_mode;
184 spi_master_chip_select_polarity_t cs_polarity;
187
192typedef enum
193{
195 GYRO8_ERROR = -1
196
198
215
229err_t gyro8_init ( gyro8_t *ctx, gyro8_cfg_t *cfg );
230
244
257err_t gyro8_write_register ( gyro8_t *ctx, uint8_t reg, uint16_t data_in );
258
271err_t gyro8_read_register ( gyro8_t *ctx, uint8_t reg, uint16_t *data_out );
272
282void gyro8_set_rst_pin ( gyro8_t *ctx, uint8_t state );
283
293
305
317err_t gyro8_read_serial_id ( gyro8_t *ctx, uint32_t *serial_id );
318
330err_t gyro8_read_temperature ( gyro8_t *ctx, float *temperature );
331
343err_t gyro8_read_angular_rate ( gyro8_t *ctx, float *rate );
344
345#ifdef __cplusplus
346}
347#endif
348#endif // GYRO8_H
349
350 // gyro8
351
352// ------------------------------------------------------------------------ END
err_t gyro8_init(gyro8_t *ctx, gyro8_cfg_t *cfg)
Gyro 8 initialization function.
err_t gyro8_default_cfg(gyro8_t *ctx)
Gyro 8 default configuration function.
err_t gyro8_read_temperature(gyro8_t *ctx, float *temperature)
Gyro 8 read temperature function.
err_t gyro8_check_communication(gyro8_t *ctx)
Gyro 8 check communication function.
err_t gyro8_read_angular_rate(gyro8_t *ctx, float *rate)
Gyro 8 read angular rate function.
void gyro8_reset_device(gyro8_t *ctx)
Gyro 8 reset device function.
err_t gyro8_read_register(gyro8_t *ctx, uint8_t reg, uint16_t *data_out)
Gyro 8 read register function.
void gyro8_set_rst_pin(gyro8_t *ctx, uint8_t state)
Gyro 8 set rst pin function.
void gyro8_cfg_setup(gyro8_cfg_t *cfg)
Gyro 8 configuration object setup function.
err_t gyro8_write_register(gyro8_t *ctx, uint8_t reg, uint16_t data_in)
Gyro 8 write register function.
err_t gyro8_read_serial_id(gyro8_t *ctx, uint32_t *serial_id)
Gyro 8 read serial id function.
gyro8_return_value_t
Gyro 8 Click return value data.
Definition gyro8.h:193
@ GYRO8_ERROR
Definition gyro8.h:195
@ GYRO8_OK
Definition gyro8.h:194
This file contains SPI specific macros, functions, etc.
Gyro 8 Click configuration object.
Definition gyro8.h:171
spi_master_chip_select_polarity_t cs_polarity
Definition gyro8.h:184
pin_name_t sck
Definition gyro8.h:175
spi_master_mode_t spi_mode
Definition gyro8.h:183
pin_name_t mosi
Definition gyro8.h:174
uint32_t spi_speed
Definition gyro8.h:182
pin_name_t miso
Definition gyro8.h:173
pin_name_t rst
Definition gyro8.h:179
pin_name_t cs
Definition gyro8.h:176
Gyro 8 Click context object.
Definition gyro8.h:155
spi_master_t spi
Definition gyro8.h:160
digital_out_t rst
Definition gyro8.h:157
pin_name_t chip_select
Definition gyro8.h:162