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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define GYRO4_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
79#define GYRO4_RETVAL uint8_t
80
81#define GYRO4_OK 0x00
82#define GYRO4_INIT_ERROR 0xFF
89#define GYRO4_REG_WHO_AM_I 0x00
90#define GYRO4_REG_TEMP_OUT_L 0x01
91#define GYRO4_REG_TEMP_OUT_H 0x02
92#define GYRO4_REG_OUT_X_L 0x03
93#define GYRO4_REG_OUT_X_H 0x04
94#define GYRO4_REG_OUT_Y_L 0x05
95#define GYRO4_REG_OUT_Y_H 0x06
96#define GYRO4_REG_DATA_STATUS_OIS 0x0A
97#define GYRO4_REG_CTRL1_OIS 0x0B
98#define GYRO4_REG_CTRL2_OIS 0x0C
99#define GYRO4_REG_CTRL3_OIS 0x0D
100#define GYRO4_REG_CTRL4_OIS 0x0E
101#define GYRO4_REG_OFF_X 0x0F
102#define GYRO4_REG_OFF_Y 0x10
103#define GYRO4_REG_OIS_CFG 0x1F
110#define GYRO4_POWER_DOWN_MODE 0x01
111#define GYRO4_SLEEP_MODE 0x02
112#define GYRO4_NORMAL_MODE 0x03
119#define GYRO4_100_DPS 0x01
120#define GYRO4_200_DPS 0x02
123 // End group macro
124// --------------------------------------------------------------- PUBLIC TYPES
133typedef struct
134{
135 // Output pins
136
137 digital_out_t cs;
138
139 // Input pins
140
141 digital_in_t int_pin;
142
143 // Modules
144
145 spi_master_t spi;
146 pin_name_t chip_select;
147 uint8_t aux_buffer [ 6 ];
148
149} gyro4_t;
150
154typedef struct
155{
156 // Communication gpio pins
157
158 pin_name_t miso;
159 pin_name_t mosi;
160 pin_name_t sck;
161 pin_name_t cs;
162
163 // Additional gpio pins
164
165 pin_name_t int_pin;
166
167 // static variable
168
169 uint32_t spi_speed;
170 spi_master_mode_t spi_mode;
171 spi_master_chip_select_polarity_t cs_polarity;
172
174
175 // End types group
176// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
177
182#ifdef __cplusplus
183extern "C"{
184#endif
185
195
204
216void gyro4_generic_transfer ( gyro4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
217
228uint8_t gyro4_int_get( gyro4_t *ctx );
229
239void gyro4_cs_set( gyro4_t *ctx, uint8_t pin_state );
240
254uint8_t gyro4_spi_get ( gyro4_t *ctx, uint8_t register_address, uint8_t * register_buffer, uint16_t n_registers );
255
268uint8_t gyro4_spi_set ( gyro4_t *ctx, uint8_t register_address, uint8_t data_in );
269
288uint8_t gyro4_initialize ( gyro4_t *ctx );
289
301uint8_t gyro4_get_temperature ( gyro4_t *ctx, float * temperature );
302
315uint8_t gyro4_get_axes( gyro4_t *ctx, float * x_axis, float * y_axis );
316
328
341uint8_t gyro4_set_power_mode ( gyro4_t *ctx, uint8_t power_mode );
342
354uint8_t gyro4_set_full_scale_range( gyro4_t *ctx, uint8_t full_scale_range );
355
356#ifdef __cplusplus
357}
358#endif
359#endif // _GYRO4_H_
360
361 // End public_function group
363
364// ------------------------------------------------------------------------- END
#define GYRO4_RETVAL
Definition gyro4.h:79
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:155
spi_master_chip_select_polarity_t cs_polarity
Definition gyro4.h:171
pin_name_t sck
Definition gyro4.h:160
spi_master_mode_t spi_mode
Definition gyro4.h:170
pin_name_t mosi
Definition gyro4.h:159
uint32_t spi_speed
Definition gyro4.h:169
pin_name_t int_pin
Definition gyro4.h:165
pin_name_t miso
Definition gyro4.h:158
pin_name_t cs
Definition gyro4.h:161
Click ctx object definition.
Definition gyro4.h:134
digital_out_t cs
Definition gyro4.h:137
spi_master_t spi
Definition gyro4.h:145
digital_in_t int_pin
Definition gyro4.h:141
pin_name_t chip_select
Definition gyro4.h:146