geomagnetic 2.0.0.0
geomagnetic.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 GEOMAGNETIC_H
36#define GEOMAGNETIC_H
37
38#include "drv_digital_in.h"
39#include "drv_i2c_master.h"
40#include "drv_spi_master.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
53#define GEOMAGNETIC_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
57 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
58 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
59 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
60 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67#define GEOMAGNETIC_MASTER_I2C 0
68#define GEOMAGNETIC_MASTER_SPI 1
75#define GEOMAGNETIC_RETVAL uint8_t
76
77#define GEOMAGNETIC_OK 0x00
78#define GEOMAGNETIC_INIT_ERROR 0xFF
85#define GEOMAG_DUMMY 0x00
86#define GEOMAG_SPI_INTERFACE 0x00
87#define GEOMAG_I2C_INTERFACE 0x01
88#define GEOMAG_READ_CMD 0x80
89#define GEOMAG_DEV_ADDR 0x10
90#define GEOMAG_ID_REG 0x40
91#define GEOMAG_RESERVED1_REG 0x41
92#define GEOMAG_DATAX_LSB_REG 0x42
93#define GEOMAG_DATAX_MSB_REG 0x43
94#define GEOMAG_DATAY_LSB_REG 0x44
95#define GEOMAG_DATAY_MSB_REG 0x45
96#define GEOMAG_DATAZ_LSB_REG 0x46
97#define GEOMAG_DATAZ_MSB_REG 0x47
98#define GEOMAG_RHALL_LSB_REG 0x48
99#define GEOMAG_RHALL_MSB_REG 0x49
100#define GEOMAG_INTERRUPT_STATUS_REG 0x4A
101#define GEOMAG_POWER_AND_RESET_CON_REG 0x4B
102#define GEOMAG_DATARATE_AND_OPMODE_CON_REG 0x4C
103#define GEOMAG_INTERR_AND_AXIS_EN_REG 0x4D
104#define GEOMAG_INTERR_AND_CHANNEL_EN_REG 0x4E
105#define GEOMAG_LOW_THRESHOLD_REG 0x4F
106#define GEOMAG_HIGH_THRESHOLD_REG 0x50
107#define GEOMAG_REPETITION_XY_CON_REG 0x51
108#define GEOMAG_REPETITION_Z_CON_REG 0x52
109#define GEOMAG_RESERVED2_REG 0x53
110#define GEOMAG_RESERVED3_REG 0x54
111#define GEOMAG_RESERVED4_REG 0x55
112#define GEOMAG_RESERVED5_REG 0x56
113#define GEOMAG_RESERVED6_REG 0x57
114#define GEOMAG_RESERVED7_REG 0x58
115#define GEOMAG_RESERVED8_REG 0x59
116#define GEOMAG_RESERVED9_REG 0x5A
117#define GEOMAG_RESERVED10_REG 0x5B
118#define GEOMAG_RESERVED11_REG 0x5C
119#define GEOMAG_RESERVED12_REG 0x5D
120#define GEOMAG_RESERVED13_REG 0x5E
121#define GEOMAG_RESERVED14_REG 0x5F
122#define GEOMAG_RESERVED15_REG 0x60
123#define GEOMAG_RESERVED16_REG 0x61
124#define GEOMAG_RESERVED17_REG 0x62
125#define GEOMAG_RESERVED18_REG 0x63
126#define GEOMAG_RESERVED19_REG 0x64
127#define GEOMAG_RESERVED20_REG 0x65
128#define GEOMAG_RESERVED21_REG 0x66
129#define GEOMAG_RESERVED22_REG 0x67
130#define GEOMAG_RESERVED23_REG 0x68
131#define GEOMAG_RESERVED24_REG 0x69
132#define GEOMAG_RESERVED25_REG 0x6A
133#define GEOMAG_RESERVED26_REG 0x6B
134#define GEOMAG_RESERVED27_REG 0x6C
135#define GEOMAG_RESERVED28_REG 0x6D
136#define GEOMAG_RESERVED29_REG 0x6E
137#define GEOMAG_RESERVED30_REG 0x6F
138#define GEOMAG_RESERVED31_REG 0x70
139#define GEOMAG_RESERVED32_REG 0x71
140#define GEOMAG_OK 0x00
141#define GEOMAG_ADDR_ERR 0x01
142#define GEOMAG_INTERRUPT_OCCURED 0x02
143#define GEOMAG_NBYTES_ERR 0x03
144#define GEOMAG_DATA_READY 0x01
145#define GEOMAG_DATA_NOT_READY 0x00
146#define GEOMAG_SUSPEND_MODE_SPI4_EN 0x00
147#define GEOMAG_SLEEP_MODE 0x01
148#define GEOMAG_SOFT_RESET_EN 0x82
149#define GEOMAG_SPI3_EN 0x04
150#define GEOMAG_NORMAL_OPMODE_DR_10HZ 0x00
151#define GEOMAG_FORCED_OPMODE 0x02
152#define GEOMAG_SLEEP_OPMODE 0x06
153#define GEOMAG_DR_2HZ 0x08
154#define GEOMAG_DR_6HZ 0x10
155#define GEOMAG_DR_8HZ 0x18
156#define GEOMAG_DR_15HZ 0x20
157#define GEOMAG_DR_20HZ 0x28
158#define GEOMAG_DR_25HZ 0x30
159#define GEOMAG_DR_30HZ 0x38
160#define GEOMAG_INTERR_DISABLED_THRESHOLDS_ENABLED 0x00
161#define GEOMAG_LOWTHRESHOLD_X_DISABLED 0x01
162#define GEOMAG_LOWTHRESHOLD_Y_DISABLED 0x02
163#define GEOMAG_LOWTHRESHOLD_Z_DISABLED 0x04
164#define GEOMAG_HIGHTHRESHOLD_X_DISABLED 0x08
165#define GEOMAG_HIGHTHRESHOLD_Y_DISABLED 0x10
166#define GEOMAG_HIGHTHRESHOLD_Z_DISABLED 0x20
167#define GEOMAG_OVERFLOW_PIN_IND_EN 0x40
168#define GEOMAG_DATAOVERRUN_IND_EN 0x80
169#define GEOMAG_CHANNELS_ENABLED_INTERR_DATAREADY_ACTIVE_LOW 0x00
170#define GEOMAG_INTERR_PIN_ACTIVE_HIGH 0x01
171#define GEOMAG_INTERR_LATCHED 0x02
172#define GEOMAG_DATAREADY_ACTIVE_HIGH 0x04
173#define GEOMAG_CHANNEL_X_DISABLED 0x08
174#define GEOMAG_CHANNEL_Y_DISABLED 0x10
175#define GEOMAG_CHANNEL_Z_DISABLED 0x20
176#define GEOMAG_INTERR_PIN_EN 0x40
177#define GEOMAG_DATAREADY_PIN_EN 0x80 // End group macro
181// --------------------------------------------------------------- PUBLIC TYPES
190typedef uint8_t geomagnetic_select_t;
191
195typedef void ( *geomagnetic_master_io_t )( struct geomagnetic_s*, uint8_t, uint8_t*, uint8_t );
196
200typedef struct
201{
202 uint16_t x_axis;
203 uint16_t y_axis;
204 uint16_t z_axis;
205
207
211typedef struct geomagnetic_s
212{
213 // Output pins
214
215 digital_out_t cs;
216
217 // Input pins
218
219 digital_in_t int_pin;
220
221 // Modules
222
223 i2c_master_t i2c;
224 spi_master_t spi;
225
226 // ctx variable
227
229 pin_name_t chip_select;
233
235
239typedef struct
240{
241 // Communication gpio pins
242
243 pin_name_t scl;
244 pin_name_t sda;
245 pin_name_t miso;
246 pin_name_t mosi;
247 pin_name_t sck;
248 pin_name_t cs;
249
250 // Additional gpio pins
251
252 pin_name_t int_pin;
253
254 // static variable
255
256 uint32_t i2c_speed;
257 uint8_t i2c_address;
258
259 uint32_t spi_speed;
260 spi_master_mode_t spi_mode;
261 spi_master_chip_select_polarity_t cs_polarity;
262
264
266 // End types group
268// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
274#ifdef __cplusplus
275extern "C"{
276#endif
277
287
297
306
317void geomagnetic_generic_write ( geomagnetic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
318
329void geomagnetic_generic_read ( geomagnetic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
330
340GEOMAGNETIC_RETVAL geomagnetic_write_byte ( geomagnetic_t *ctx, uint8_t input_data, uint8_t address );
341
352GEOMAGNETIC_RETVAL geomagnetic_read_data ( geomagnetic_t *ctx, uint8_t *out_buf, uint8_t address, uint8_t len );
353
362
373*geomag_axis, uint16_t *resolution_hall );
374
383
392
401
411
412#ifdef __cplusplus
413}
414#endif
415#endif // _GEOMAGNETIC_H_
416 // End public_function group
419
420// ------------------------------------------------------------------------- END
#define GEOMAGNETIC_RETVAL
Definition: geomagnetic.h:75
GEOMAGNETIC_RETVAL geomagnetic_write_byte(geomagnetic_t *ctx, uint8_t input_data, uint8_t address)
Write byte function.
GEOMAGNETIC_RETVAL geomagnetic_init(geomagnetic_t *ctx, geomagnetic_cfg_t *cfg)
Initialization function.
uint8_t get_interrupt(geomagnetic_t *ctx)
Get interrupt function.
void geomagnetic_software_reset(geomagnetic_t *ctx)
Software reset function.
void geomagnetic_generic_read(geomagnetic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void geomagnetic_cfg_setup(geomagnetic_cfg_t *cfg)
Config Object Initialization function.
void geomagnetic_generic_write(geomagnetic_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
GEOMAGNETIC_RETVAL geomagnetic_check_interrupt(geomagnetic_t *ctx)
Check interrupt function.
void geomagnetic_read_axis_data(geomagnetic_t *ctx, geomagnetic_axis_t *geomag_axis, uint16_t *resolution_hall)
Read axis data function.
uint8_t geomagnetic_check_ready(geomagnetic_t *ctx)
Check ready function.
GEOMAGNETIC_RETVAL geomagnetic_read_data(geomagnetic_t *ctx, uint8_t *out_buf, uint8_t address, uint8_t len)
Read data function.
void geomagnetic_default_cfg(geomagnetic_t *ctx)
Click Default Configuration function.
void geomagnetic_power_on_reset(geomagnetic_t *ctx)
Power ON reset function.
struct geomagnetic_s geomagnetic_t
Click ctx object definition.
void(* geomagnetic_master_io_t)(struct geomagnetic_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: geomagnetic.h:195
uint8_t geomagnetic_select_t
Communication type.
Definition: geomagnetic.h:190
GeoMagnetic axis structure.
Definition: geomagnetic.h:201
uint16_t z_axis
Definition: geomagnetic.h:204
uint16_t x_axis
Definition: geomagnetic.h:202
uint16_t y_axis
Definition: geomagnetic.h:203
Click configuration structure definition.
Definition: geomagnetic.h:240
geomagnetic_select_t sel
Definition: geomagnetic.h:263
uint32_t i2c_speed
Definition: geomagnetic.h:256
spi_master_chip_select_polarity_t cs_polarity
Definition: geomagnetic.h:261
pin_name_t sck
Definition: geomagnetic.h:247
spi_master_mode_t spi_mode
Definition: geomagnetic.h:260
pin_name_t mosi
Definition: geomagnetic.h:246
uint32_t spi_speed
Definition: geomagnetic.h:259
pin_name_t scl
Definition: geomagnetic.h:243
pin_name_t int_pin
Definition: geomagnetic.h:252
pin_name_t miso
Definition: geomagnetic.h:245
pin_name_t sda
Definition: geomagnetic.h:244
pin_name_t cs
Definition: geomagnetic.h:248
uint8_t i2c_address
Definition: geomagnetic.h:257
Click ctx object definition.
Definition: geomagnetic.h:212
digital_out_t cs
Definition: geomagnetic.h:215
geomagnetic_master_io_t read_f
Definition: geomagnetic.h:231
spi_master_t spi
Definition: geomagnetic.h:224
digital_in_t int_pin
Definition: geomagnetic.h:219
i2c_master_t i2c
Definition: geomagnetic.h:223
uint8_t slave_address
Definition: geomagnetic.h:228
geomagnetic_master_io_t write_f
Definition: geomagnetic.h:230
pin_name_t chip_select
Definition: geomagnetic.h:229
geomagnetic_select_t master_sel
Definition: geomagnetic.h:232