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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define COMPASS6_REG_SELFTEST_RSP 0x0C
70 #define COMPASS6_REG_INFO_VERSION 0x0D
71 #define COMPASS6_REG_INFO_ALPS 0x0E
72 #define COMPASS6_REG_WHO_I_AM 0x0F
73 #define COMPASS6_REG_OUTPUT_X_LSB 0x10
74 #define COMPASS6_REG_OUTPUT_X_MSB 0x11
75 #define COMPASS6_REG_OUTPUT_Y_LSB 0x12
76 #define COMPASS6_REG_OUTPUT_Y_MSB 0x13
77 #define COMPASS6_REG_OUTPUT_Z_LSB 0x14
78 #define COMPASS6_REG_OUTPUT_Z_MSB 0x15
79 #define COMPASS6_REG_STATUS 0x18
80 #define COMPASS6_REG_FIFO_PTR_STATUS 0x19
81 #define COMPASS6_REG_CTRL1 0x1B
82 #define COMPASS6_REG_CTRL2 0x1C
83 #define COMPASS6_REG_CTRL3 0x1D
84 #define COMPASS6_REG_CTRL4 0x1E
85 #define COMPASS6_REG_OFFSET_X_LSB 0x20
86 #define COMPASS6_REG_OFFSET_X_MSB 0x21
87 #define COMPASS6_REG_OFFSET_Y_LSB 0x22
88 #define COMPASS6_REG_OFFSET_Y_MSB 0x23
89 #define COMPASS6_REG_OFFSET_Z_LSB 0x24
90 #define COMPASS6_REG_OFFSET_Z_MSB 0x25
91 #define COMPASS6_REG_THR_L 0x26
92 #define COMPASS6_REG_THR_H 0x27
93 #define COMPASS6_REG_TEMPERATURE_VAL 0x31
94  // compass6_reg
96 
111 #define COMPASS6_WHO_AM_I 0x49
112 #define COMPASS6_VERSION 0x11
113 #define COMPASS6_ALPS 0x15
114 
120 #define COMPASS6_SET_DEV_ADDR 0x0C
121  // compass6_set
123 
138 #define COMPASS6_MAP_MIKROBUS( cfg, mikrobus ) \
139  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
140  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
141  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
142  // compass6_map // compass6
145 
150 typedef struct
151 {
152  // Input pins
153  digital_in_t rdy;
155  // Modules
156  i2c_master_t i2c;
158  // I2C slave address
159  uint8_t slave_address;
161 } compass6_t;
162 
167 typedef struct
168 {
169  pin_name_t scl;
170  pin_name_t sda;
172  pin_name_t rdy;
174  uint32_t i2c_speed;
175  uint8_t i2c_address;
178 
183 typedef enum
184 {
186  COMPASS6_ERROR = -1
187 
189 
194 typedef struct
195 {
196  int16_t x;
197  int16_t y;
198  int16_t z;
201 
218 
234 
249 
262 err_t compass6_generic_write ( compass6_t *ctx, uint8_t reg, uint8_t tx_data );
263 
276 err_t compass6_generic_read ( compass6_t *ctx, uint8_t reg, uint8_t *rx_data );
277 
286 
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 #endif // COMPASS6_H
305  // compass6
307 
308 // ------------------------------------------------------------------------ END
compass6_cfg_t
Compass 6 Click configuration object.
Definition: compass6.h:168
compass6_axes_t::z
int16_t z
Definition: compass6.h:198
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:185
compass6_t::rdy
digital_in_t rdy
Definition: compass6.h:153
COMPASS6_ERROR
@ COMPASS6_ERROR
Definition: compass6.h:186
compass6_t::i2c
i2c_master_t i2c
Definition: compass6.h:156
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:184
compass6_cfg_t::sda
pin_name_t sda
Definition: compass6.h:170
compass6_axes_t::x
int16_t x
Definition: compass6.h:196
compass6_cfg_t::i2c_address
uint8_t i2c_address
Definition: compass6.h:175
compass6_axes_t
Compass 6 Click axes data.
Definition: compass6.h:195
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:172
compass6_cfg_t::scl
pin_name_t scl
Definition: compass6.h:169
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:197
compass6_t
Compass 6 Click context object.
Definition: compass6.h:151
compass6_t::slave_address
uint8_t slave_address
Definition: compass6.h:159
compass6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: compass6.h:174