compass6  2.0.0.0
compass6.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef COMPASS6_H
29 #define COMPASS6_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define COMPASS6_REG_SELFTEST_RSP 0x0C
74 #define COMPASS6_REG_INFO_VERSION 0x0D
75 #define COMPASS6_REG_INFO_ALPS 0x0E
76 #define COMPASS6_REG_WHO_I_AM 0x0F
77 #define COMPASS6_REG_OUTPUT_X_LSB 0x10
78 #define COMPASS6_REG_OUTPUT_X_MSB 0x11
79 #define COMPASS6_REG_OUTPUT_Y_LSB 0x12
80 #define COMPASS6_REG_OUTPUT_Y_MSB 0x13
81 #define COMPASS6_REG_OUTPUT_Z_LSB 0x14
82 #define COMPASS6_REG_OUTPUT_Z_MSB 0x15
83 #define COMPASS6_REG_STATUS 0x18
84 #define COMPASS6_REG_FIFO_PTR_STATUS 0x19
85 #define COMPASS6_REG_CTRL1 0x1B
86 #define COMPASS6_REG_CTRL2 0x1C
87 #define COMPASS6_REG_CTRL3 0x1D
88 #define COMPASS6_REG_CTRL4 0x1E
89 #define COMPASS6_REG_OFFSET_X_LSB 0x20
90 #define COMPASS6_REG_OFFSET_X_MSB 0x21
91 #define COMPASS6_REG_OFFSET_Y_LSB 0x22
92 #define COMPASS6_REG_OFFSET_Y_MSB 0x23
93 #define COMPASS6_REG_OFFSET_Z_LSB 0x24
94 #define COMPASS6_REG_OFFSET_Z_MSB 0x25
95 #define COMPASS6_REG_THR_L 0x26
96 #define COMPASS6_REG_THR_H 0x27
97 #define COMPASS6_REG_TEMPERATURE_VAL 0x31
98  // compass6_reg
100 
115 #define COMPASS6_WHO_AM_I 0x49
116 #define COMPASS6_VERSION 0x11
117 #define COMPASS6_ALPS 0x15
118 
124 #define COMPASS6_SET_DEV_ADDR 0x0C
125  // compass6_set
127 
142 #define COMPASS6_MAP_MIKROBUS( cfg, mikrobus ) \
143  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
144  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
145  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
146  // compass6_map // compass6
149 
154 typedef struct
155 {
156  // Input pins
157  digital_in_t rdy;
159  // Modules
160  i2c_master_t i2c;
162  // I2C slave address
163  uint8_t slave_address;
165 } compass6_t;
166 
171 typedef struct
172 {
173  pin_name_t scl;
174  pin_name_t sda;
176  pin_name_t rdy;
178  uint32_t i2c_speed;
179  uint8_t i2c_address;
182 
187 typedef enum
188 {
190  COMPASS6_ERROR = -1
191 
193 
198 typedef struct
199 {
200  int16_t x;
201  int16_t y;
202  int16_t z;
205 
222 
238 
253 
266 err_t compass6_generic_write ( compass6_t *ctx, uint8_t reg, uint8_t tx_data );
267 
280 err_t compass6_generic_read ( compass6_t *ctx, uint8_t reg, uint8_t *rx_data );
281 
290 
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 #endif // COMPASS6_H
309  // compass6
311 
312 // ------------------------------------------------------------------------ END
compass6_cfg_t
Compass 6 Click configuration object.
Definition: compass6.h:172
compass6_axes_t::z
int16_t z
Definition: compass6.h:202
compass6_default_cfg
err_t compass6_default_cfg(compass6_t *ctx)
Compass 6 default configuration function.
compass6_init
err_t compass6_init(compass6_t *ctx, compass6_cfg_t *cfg)
Compass 6 initialization function.
compass6_data_ready
uint8_t compass6_data_ready(compass6_t *ctx)
Get data ready pin state.
compass6_generic_read
err_t compass6_generic_read(compass6_t *ctx, uint8_t reg, uint8_t *rx_data)
Compass 6 I2C reading function.
COMPASS6_OK
@ COMPASS6_OK
Definition: compass6.h:189
compass6_t::rdy
digital_in_t rdy
Definition: compass6.h:157
COMPASS6_ERROR
@ COMPASS6_ERROR
Definition: compass6.h:190
compass6_t::i2c
i2c_master_t i2c
Definition: compass6.h:160
compass6_get_axes_data
err_t compass6_get_axes_data(compass6_t *ctx, compass6_axes_t *axes_data)
Magnetic axes data reading.
compass6_return_value_t
compass6_return_value_t
Compass 6 Click return value data.
Definition: compass6.h:188
compass6_cfg_t::sda
pin_name_t sda
Definition: compass6.h:174
compass6_axes_t::x
int16_t x
Definition: compass6.h:200
compass6_cfg_t::i2c_address
uint8_t i2c_address
Definition: compass6.h:179
compass6_axes_t
Compass 6 Click axes data.
Definition: compass6.h:199
compass6_generic_write
err_t compass6_generic_write(compass6_t *ctx, uint8_t reg, uint8_t tx_data)
Compass 6 I2C writing function.
compass6_cfg_t::rdy
pin_name_t rdy
Definition: compass6.h:176
compass6_cfg_t::scl
pin_name_t scl
Definition: compass6.h:173
compass6_cfg_setup
void compass6_cfg_setup(compass6_cfg_t *cfg)
Compass 6 configuration object setup function.
compass6_axes_t::y
int16_t y
Definition: compass6.h:201
compass6_t
Compass 6 Click context object.
Definition: compass6.h:155
compass6_t::slave_address
uint8_t slave_address
Definition: compass6.h:163
compass6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: compass6.h:178