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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
63 #define GYRO4_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
65  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
66  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define GYRO4_RETVAL uint8_t
76 
77 #define GYRO4_OK 0x00
78 #define GYRO4_INIT_ERROR 0xFF
79 
85 #define GYRO4_REG_WHO_AM_I 0x00
86 #define GYRO4_REG_TEMP_OUT_L 0x01
87 #define GYRO4_REG_TEMP_OUT_H 0x02
88 #define GYRO4_REG_OUT_X_L 0x03
89 #define GYRO4_REG_OUT_X_H 0x04
90 #define GYRO4_REG_OUT_Y_L 0x05
91 #define GYRO4_REG_OUT_Y_H 0x06
92 #define GYRO4_REG_DATA_STATUS_OIS 0x0A
93 #define GYRO4_REG_CTRL1_OIS 0x0B
94 #define GYRO4_REG_CTRL2_OIS 0x0C
95 #define GYRO4_REG_CTRL3_OIS 0x0D
96 #define GYRO4_REG_CTRL4_OIS 0x0E
97 #define GYRO4_REG_OFF_X 0x0F
98 #define GYRO4_REG_OFF_Y 0x10
99 #define GYRO4_REG_OIS_CFG 0x1F
100 
106 #define GYRO4_POWER_DOWN_MODE 0x01
107 #define GYRO4_SLEEP_MODE 0x02
108 #define GYRO4_NORMAL_MODE 0x03
109 
115 #define GYRO4_100_DPS 0x01
116 #define GYRO4_200_DPS 0x02
117  // End group macro
120 // --------------------------------------------------------------- PUBLIC TYPES
129 typedef struct
130 {
131  // Output pins
132 
133  digital_out_t cs;
134 
135  // Input pins
136 
137  digital_in_t int_pin;
138 
139  // Modules
140 
141  spi_master_t spi;
142  pin_name_t chip_select;
143  uint8_t aux_buffer [ 6 ];
144 
145 } gyro4_t;
146 
150 typedef struct
151 {
152  // Communication gpio pins
153 
154  pin_name_t miso;
155  pin_name_t mosi;
156  pin_name_t sck;
157  pin_name_t cs;
158 
159  // Additional gpio pins
160 
161  pin_name_t int_pin;
162 
163  // static variable
164 
165  uint32_t spi_speed;
166  spi_master_mode_t spi_mode;
167  spi_master_chip_select_polarity_t cs_polarity;
168 
169 } gyro4_cfg_t;
170  // End types group
172 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
173 
178 #ifdef __cplusplus
179 extern "C"{
180 #endif
181 
191 
200 
212 void gyro4_generic_transfer ( gyro4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
213 
224 uint8_t gyro4_int_get( gyro4_t *ctx );
225 
235 void gyro4_cs_set( gyro4_t *ctx, uint8_t pin_state );
236 
250 uint8_t gyro4_spi_get ( gyro4_t *ctx, uint8_t register_address, uint8_t * register_buffer, uint16_t n_registers );
251 
264 uint8_t gyro4_spi_set ( gyro4_t *ctx, uint8_t register_address, uint8_t data_in );
265 
284 uint8_t gyro4_initialize ( gyro4_t *ctx );
285 
297 uint8_t gyro4_get_temperature ( gyro4_t *ctx, float * temperature );
298 
311 uint8_t gyro4_get_axes( gyro4_t *ctx, float * x_axis, float * y_axis );
312 
323 uint8_t gyro4_software_reset ( gyro4_t *ctx );
324 
337 uint8_t gyro4_set_power_mode ( gyro4_t *ctx, uint8_t power_mode );
338 
350 uint8_t gyro4_set_full_scale_range( gyro4_t *ctx, uint8_t full_scale_range );
351 
352 #ifdef __cplusplus
353 }
354 #endif
355 #endif // _GYRO4_H_
356  // End public_function group
359 
360 // ------------------------------------------------------------------------- END
gyro4_cfg_t::sck
pin_name_t sck
Definition: gyro4.h:156
gyro4_set_power_mode
uint8_t gyro4_set_power_mode(gyro4_t *ctx, uint8_t power_mode)
Setting power mode.
gyro4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: gyro4.h:166
gyro4_cs_set
void gyro4_cs_set(gyro4_t *ctx, uint8_t pin_state)
Setting CS pin state.
gyro4_int_get
uint8_t gyro4_int_get(gyro4_t *ctx)
Getting INT pin state.
gyro4_initialize
uint8_t gyro4_initialize(gyro4_t *ctx)
Device initialization.
gyro4_cfg_setup
void gyro4_cfg_setup(gyro4_cfg_t *cfg)
Config Object Initialization function.
gyro4_cfg_t::int_pin
pin_name_t int_pin
Definition: gyro4.h:161
gyro4_cfg_t::spi_speed
uint32_t spi_speed
Definition: gyro4.h:165
gyro4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gyro4.h:167
gyro4_cfg_t::mosi
pin_name_t mosi
Definition: gyro4.h:155
gyro4_t
Click ctx object definition.
Definition: gyro4.h:130
gyro4_software_reset
uint8_t gyro4_software_reset(gyro4_t *ctx)
Performing software reset.
gyro4_spi_get
uint8_t gyro4_spi_get(gyro4_t *ctx, uint8_t register_address, uint8_t *register_buffer, uint16_t n_registers)
Getting register content.
gyro4_t::cs
digital_out_t cs
Definition: gyro4.h:133
gyro4_get_axes
uint8_t gyro4_get_axes(gyro4_t *ctx, float *x_axis, float *y_axis)
Getting axes values.
gyro4_get_temperature
uint8_t gyro4_get_temperature(gyro4_t *ctx, float *temperature)
Getting die temperature value.
gyro4_t::spi
spi_master_t spi
Definition: gyro4.h:141
gyro4_init
GYRO4_RETVAL gyro4_init(gyro4_t *ctx, gyro4_cfg_t *cfg)
Initialization function.
GYRO4_RETVAL
#define GYRO4_RETVAL
Definition: gyro4.h:75
gyro4_t::chip_select
pin_name_t chip_select
Definition: gyro4.h:142
gyro4_spi_set
uint8_t gyro4_spi_set(gyro4_t *ctx, uint8_t register_address, uint8_t data_in)
Setting register content.
gyro4_cfg_t::cs
pin_name_t cs
Definition: gyro4.h:157
gyro4_set_full_scale_range
uint8_t gyro4_set_full_scale_range(gyro4_t *ctx, uint8_t full_scale_range)
Settinf full scale range.
gyro4_t::int_pin
digital_in_t int_pin
Definition: gyro4.h:137
gyro4_cfg_t
Click configuration structure definition.
Definition: gyro4.h:151
gyro4_cfg_t::miso
pin_name_t miso
Definition: gyro4.h:154
gyro4_generic_transfer
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.