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 )
73 
79 #define GYRO4_RETVAL uint8_t
80 
81 #define GYRO4_OK 0x00
82 #define GYRO4_INIT_ERROR 0xFF
83 
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
104 
110 #define GYRO4_POWER_DOWN_MODE 0x01
111 #define GYRO4_SLEEP_MODE 0x02
112 #define GYRO4_NORMAL_MODE 0x03
113 
119 #define GYRO4_100_DPS 0x01
120 #define GYRO4_200_DPS 0x02
121  // End group macro
124 // --------------------------------------------------------------- PUBLIC TYPES
133 typedef 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 
154 typedef 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 
173 } gyro4_cfg_t;
174  // End types group
176 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
177 
182 #ifdef __cplusplus
183 extern "C"{
184 #endif
185 
195 
204 
216 void gyro4_generic_transfer ( gyro4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
217 
228 uint8_t gyro4_int_get( gyro4_t *ctx );
229 
239 void gyro4_cs_set( gyro4_t *ctx, uint8_t pin_state );
240 
254 uint8_t gyro4_spi_get ( gyro4_t *ctx, uint8_t register_address, uint8_t * register_buffer, uint16_t n_registers );
255 
268 uint8_t gyro4_spi_set ( gyro4_t *ctx, uint8_t register_address, uint8_t data_in );
269 
288 uint8_t gyro4_initialize ( gyro4_t *ctx );
289 
301 uint8_t gyro4_get_temperature ( gyro4_t *ctx, float * temperature );
302 
315 uint8_t gyro4_get_axes( gyro4_t *ctx, float * x_axis, float * y_axis );
316 
327 uint8_t gyro4_software_reset ( gyro4_t *ctx );
328 
341 uint8_t gyro4_set_power_mode ( gyro4_t *ctx, uint8_t power_mode );
342 
354 uint8_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  // End public_function group
363 
364 // ------------------------------------------------------------------------- END
gyro4_cfg_t::sck
pin_name_t sck
Definition: gyro4.h:160
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:170
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:165
gyro4_cfg_t::spi_speed
uint32_t spi_speed
Definition: gyro4.h:169
gyro4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: gyro4.h:171
gyro4_cfg_t::mosi
pin_name_t mosi
Definition: gyro4.h:159
gyro4_t
Click ctx object definition.
Definition: gyro4.h:134
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:137
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:145
gyro4_init
GYRO4_RETVAL gyro4_init(gyro4_t *ctx, gyro4_cfg_t *cfg)
Initialization function.
GYRO4_RETVAL
#define GYRO4_RETVAL
Definition: gyro4.h:79
gyro4_t::chip_select
pin_name_t chip_select
Definition: gyro4.h:146
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:161
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:141
gyro4_cfg_t
Click configuration structure definition.
Definition: gyro4.h:155
gyro4_cfg_t::miso
pin_name_t miso
Definition: gyro4.h:158
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.