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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define GYRO8_REG_RATE 0x01
61 #define GYRO8_REG_TEMP 0x07
62 #define GYRO8_REG_RATE_STATUS_1 0x09
63 #define GYRO8_REG_RATE_STATUS_2 0x0A
64 #define GYRO8_REG_ACC_STATUS 0x0F
65 #define GYRO8_REG_TEST 0x15
66 #define GYRO8_REG_RESET_CONTROL 0x16
67 #define GYRO8_REG_SERIAL_ID0 0x18
68 #define GYRO8_REG_SERIAL_ID1 0x19
69 #define GYRO8_REG_COMMON_STATUS 0x1B
70 #define GYRO8_REG_ID 0x1D
71 #define GYRO8_REG_STATUS_SUMMARY 0x1F
72  // gyro8_reg
74 
89 #define GYRO8_ID 0x0500
90 
95 #define GYRO8_TEMP_SENS 14.7f
96 #define GYRO8_TEMP_OFFSET 60.0f
97 #define GYRO8_GYRO_SENS 50.0f
98 
107 #define GYRO8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
108 #define GYRO8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
109  // gyro8_set
111 
126 #define GYRO8_MAP_MIKROBUS( cfg, mikrobus ) \
127  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
128  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
129  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
130  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
131  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
132  // gyro8_map // gyro8
135 
140 typedef struct
141 {
142  // Output pins
143  digital_out_t rst;
145  // Modules
146  spi_master_t spi;
148  pin_name_t chip_select;
150 } gyro8_t;
151 
156 typedef struct
157 {
158  // Communication gpio pins
159  pin_name_t miso;
160  pin_name_t mosi;
161  pin_name_t sck;
162  pin_name_t cs;
164  // Additional gpio pins
165  pin_name_t rst;
167  // static variable
168  uint32_t spi_speed;
169  spi_master_mode_t spi_mode;
170  spi_master_chip_select_polarity_t cs_polarity;
172 } gyro8_cfg_t;
173 
178 typedef enum
179 {
180  GYRO8_OK = 0,
181  GYRO8_ERROR = -1
182 
184 
201 
215 err_t gyro8_init ( gyro8_t *ctx, gyro8_cfg_t *cfg );
216 
229 err_t gyro8_default_cfg ( gyro8_t *ctx );
230 
243 err_t gyro8_write_register ( gyro8_t *ctx, uint8_t reg, uint16_t data_in );
244 
257 err_t gyro8_read_register ( gyro8_t *ctx, uint8_t reg, uint16_t *data_out );
258 
268 void gyro8_set_rst_pin ( gyro8_t *ctx, uint8_t state );
269 
279 
291 
303 err_t gyro8_read_serial_id ( gyro8_t *ctx, uint32_t *serial_id );
304 
316 err_t gyro8_read_temperature ( gyro8_t *ctx, float *temperature );
317 
329 err_t gyro8_read_angular_rate ( gyro8_t *ctx, float *rate );
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 #endif // GYRO8_H
335  // gyro8
337 
338 // ------------------------------------------------------------------------ END
gyro8_cfg_t::rst
pin_name_t rst
Definition: gyro8.h:165
gyro8_t::rst
digital_out_t rst
Definition: gyro8.h:143
gyro8_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gyro8.h:169
gyro8_cfg_t::cs
pin_name_t cs
Definition: gyro8.h:162
gyro8_cfg_setup
void gyro8_cfg_setup(gyro8_cfg_t *cfg)
Gyro 8 configuration object setup function.
gyro8_reset_device
void gyro8_reset_device(gyro8_t *ctx)
Gyro 8 reset device function.
gyro8_set_rst_pin
void gyro8_set_rst_pin(gyro8_t *ctx, uint8_t state)
Gyro 8 set rst pin function.
gyro8_read_serial_id
err_t gyro8_read_serial_id(gyro8_t *ctx, uint32_t *serial_id)
Gyro 8 read serial id function.
gyro8_read_temperature
err_t gyro8_read_temperature(gyro8_t *ctx, float *temperature)
Gyro 8 read temperature function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
gyro8_cfg_t::sck
pin_name_t sck
Definition: gyro8.h:161
gyro8_init
err_t gyro8_init(gyro8_t *ctx, gyro8_cfg_t *cfg)
Gyro 8 initialization function.
gyro8_read_register
err_t gyro8_read_register(gyro8_t *ctx, uint8_t reg, uint16_t *data_out)
Gyro 8 read register function.
gyro8_return_value_t
gyro8_return_value_t
Gyro 8 Click return value data.
Definition: gyro8.h:179
gyro8_check_communication
err_t gyro8_check_communication(gyro8_t *ctx)
Gyro 8 check communication function.
GYRO8_OK
@ GYRO8_OK
Definition: gyro8.h:180
gyro8_t
Gyro 8 Click context object.
Definition: gyro8.h:141
GYRO8_ERROR
@ GYRO8_ERROR
Definition: gyro8.h:181
gyro8_cfg_t::spi_speed
uint32_t spi_speed
Definition: gyro8.h:168
gyro8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gyro8.h:170
gyro8_default_cfg
err_t gyro8_default_cfg(gyro8_t *ctx)
Gyro 8 default configuration function.
gyro8_t::chip_select
pin_name_t chip_select
Definition: gyro8.h:148
gyro8_cfg_t::mosi
pin_name_t mosi
Definition: gyro8.h:160
gyro8_cfg_t::miso
pin_name_t miso
Definition: gyro8.h:159
gyro8_write_register
err_t gyro8_write_register(gyro8_t *ctx, uint8_t reg, uint16_t data_in)
Gyro 8 write register function.
gyro8_read_angular_rate
err_t gyro8_read_angular_rate(gyro8_t *ctx, float *rate)
Gyro 8 read angular rate function.
gyro8_cfg_t
Gyro 8 Click configuration object.
Definition: gyro8.h:157
gyro8_t::spi
spi_master_t spi
Definition: gyro8.h:146