gyro4 2.0.0.0
gyro4.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef GYRO4_H
36#define GYRO4_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_spi_master.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
53#define GYRO4_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
65#define GYRO4_RETVAL uint8_t
66
67#define GYRO4_OK 0x00
68#define GYRO4_INIT_ERROR 0xFF
75#define GYRO4_REG_WHO_AM_I 0x00
76#define GYRO4_REG_TEMP_OUT_L 0x01
77#define GYRO4_REG_TEMP_OUT_H 0x02
78#define GYRO4_REG_OUT_X_L 0x03
79#define GYRO4_REG_OUT_X_H 0x04
80#define GYRO4_REG_OUT_Y_L 0x05
81#define GYRO4_REG_OUT_Y_H 0x06
82#define GYRO4_REG_DATA_STATUS_OIS 0x0A
83#define GYRO4_REG_CTRL1_OIS 0x0B
84#define GYRO4_REG_CTRL2_OIS 0x0C
85#define GYRO4_REG_CTRL3_OIS 0x0D
86#define GYRO4_REG_CTRL4_OIS 0x0E
87#define GYRO4_REG_OFF_X 0x0F
88#define GYRO4_REG_OFF_Y 0x10
89#define GYRO4_REG_OIS_CFG 0x1F
96#define GYRO4_POWER_DOWN_MODE 0x01
97#define GYRO4_SLEEP_MODE 0x02
98#define GYRO4_NORMAL_MODE 0x03
105#define GYRO4_100_DPS 0x01
106#define GYRO4_200_DPS 0x02 // End group macro
110// --------------------------------------------------------------- PUBLIC TYPES
119typedef struct
120{
121 // Output pins
122
123 digital_out_t cs;
124
125 // Input pins
126
127 digital_in_t int_pin;
128
129 // Modules
130
131 spi_master_t spi;
132 pin_name_t chip_select;
133 uint8_t aux_buffer [ 6 ];
134
135} gyro4_t;
136
140typedef struct
141{
142 // Communication gpio pins
143
144 pin_name_t miso;
145 pin_name_t mosi;
146 pin_name_t sck;
147 pin_name_t cs;
148
149 // Additional gpio pins
150
151 pin_name_t int_pin;
152
153 // static variable
154
155 uint32_t spi_speed;
156 spi_master_mode_t spi_mode;
157 spi_master_chip_select_polarity_t cs_polarity;
158
160 // End types group
162// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163
168#ifdef __cplusplus
169extern "C"{
170#endif
171
181
190
202void gyro4_generic_transfer ( gyro4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
203
214uint8_t gyro4_int_get( gyro4_t *ctx );
215
225void gyro4_cs_set( gyro4_t *ctx, uint8_t pin_state );
226
240uint8_t gyro4_spi_get ( gyro4_t *ctx, uint8_t register_address, uint8_t * register_buffer, uint16_t n_registers );
241
254uint8_t gyro4_spi_set ( gyro4_t *ctx, uint8_t register_address, uint8_t data_in );
255
274uint8_t gyro4_initialize ( gyro4_t *ctx );
275
287uint8_t gyro4_get_temperature ( gyro4_t *ctx, float * temperature );
288
301uint8_t gyro4_get_axes( gyro4_t *ctx, float * x_axis, float * y_axis );
302
314
327uint8_t gyro4_set_power_mode ( gyro4_t *ctx, uint8_t power_mode );
328
340uint8_t gyro4_set_full_scale_range( gyro4_t *ctx, uint8_t full_scale_range );
341
342#ifdef __cplusplus
343}
344#endif
345#endif // _GYRO4_H_
346 // End public_function group
349
350// ------------------------------------------------------------------------- END
#define GYRO4_RETVAL
Definition: gyro4.h:65
GYRO4_RETVAL gyro4_init(gyro4_t *ctx, gyro4_cfg_t *cfg)
Initialization function.
uint8_t gyro4_get_temperature(gyro4_t *ctx, float *temperature)
Getting die temperature value.
uint8_t gyro4_get_axes(gyro4_t *ctx, float *x_axis, float *y_axis)
Getting axes values.
uint8_t gyro4_set_power_mode(gyro4_t *ctx, uint8_t power_mode)
Setting power mode.
void gyro4_generic_transfer(gyro4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void gyro4_cs_set(gyro4_t *ctx, uint8_t pin_state)
Setting CS pin state.
uint8_t gyro4_initialize(gyro4_t *ctx)
Device initialization.
uint8_t gyro4_set_full_scale_range(gyro4_t *ctx, uint8_t full_scale_range)
Settinf full scale range.
uint8_t gyro4_spi_get(gyro4_t *ctx, uint8_t register_address, uint8_t *register_buffer, uint16_t n_registers)
Getting register content.
uint8_t gyro4_int_get(gyro4_t *ctx)
Getting INT pin state.
void gyro4_cfg_setup(gyro4_cfg_t *cfg)
Config Object Initialization function.
uint8_t gyro4_software_reset(gyro4_t *ctx)
Performing software reset.
uint8_t gyro4_spi_set(gyro4_t *ctx, uint8_t register_address, uint8_t data_in)
Setting register content.
Click configuration structure definition.
Definition: gyro4.h:141
spi_master_chip_select_polarity_t cs_polarity
Definition: gyro4.h:157
pin_name_t sck
Definition: gyro4.h:146
spi_master_mode_t spi_mode
Definition: gyro4.h:156
pin_name_t mosi
Definition: gyro4.h:145
uint32_t spi_speed
Definition: gyro4.h:155
pin_name_t int_pin
Definition: gyro4.h:151
pin_name_t miso
Definition: gyro4.h:144
pin_name_t cs
Definition: gyro4.h:147
Click ctx object definition.
Definition: gyro4.h:120
digital_out_t cs
Definition: gyro4.h:123
spi_master_t spi
Definition: gyro4.h:131
digital_in_t int_pin
Definition: gyro4.h:127
pin_name_t chip_select
Definition: gyro4.h:132