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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define COMPASS6_REG_SELFTEST_RSP 0x0C
60 #define COMPASS6_REG_INFO_VERSION 0x0D
61 #define COMPASS6_REG_INFO_ALPS 0x0E
62 #define COMPASS6_REG_WHO_I_AM 0x0F
63 #define COMPASS6_REG_OUTPUT_X_LSB 0x10
64 #define COMPASS6_REG_OUTPUT_X_MSB 0x11
65 #define COMPASS6_REG_OUTPUT_Y_LSB 0x12
66 #define COMPASS6_REG_OUTPUT_Y_MSB 0x13
67 #define COMPASS6_REG_OUTPUT_Z_LSB 0x14
68 #define COMPASS6_REG_OUTPUT_Z_MSB 0x15
69 #define COMPASS6_REG_STATUS 0x18
70 #define COMPASS6_REG_FIFO_PTR_STATUS 0x19
71 #define COMPASS6_REG_CTRL1 0x1B
72 #define COMPASS6_REG_CTRL2 0x1C
73 #define COMPASS6_REG_CTRL3 0x1D
74 #define COMPASS6_REG_CTRL4 0x1E
75 #define COMPASS6_REG_OFFSET_X_LSB 0x20
76 #define COMPASS6_REG_OFFSET_X_MSB 0x21
77 #define COMPASS6_REG_OFFSET_Y_LSB 0x22
78 #define COMPASS6_REG_OFFSET_Y_MSB 0x23
79 #define COMPASS6_REG_OFFSET_Z_LSB 0x24
80 #define COMPASS6_REG_OFFSET_Z_MSB 0x25
81 #define COMPASS6_REG_THR_L 0x26
82 #define COMPASS6_REG_THR_H 0x27
83 #define COMPASS6_REG_TEMPERATURE_VAL 0x31
84  // compass6_reg
86 
101 #define COMPASS6_WHO_AM_I 0x49
102 #define COMPASS6_VERSION 0x11
103 #define COMPASS6_ALPS 0x15
104 
110 #define COMPASS6_SET_DEV_ADDR 0x0C
111  // compass6_set
113 
128 #define COMPASS6_MAP_MIKROBUS( cfg, mikrobus ) \
129  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
130  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
131  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
132  // compass6_map // compass6
135 
140 typedef struct
141 {
142  // Input pins
143  digital_in_t rdy;
145  // Modules
146  i2c_master_t i2c;
148  // I2C slave address
149  uint8_t slave_address;
151 } compass6_t;
152 
157 typedef struct
158 {
159  pin_name_t scl;
160  pin_name_t sda;
162  pin_name_t rdy;
164  uint32_t i2c_speed;
165  uint8_t i2c_address;
168 
173 typedef enum
174 {
176  COMPASS6_ERROR = -1
177 
179 
184 typedef struct
185 {
186  int16_t x;
187  int16_t y;
188  int16_t z;
191 
207 void compass6_cfg_setup ( compass6_cfg_t *cfg );
208 
223 err_t compass6_init ( compass6_t *ctx, compass6_cfg_t *cfg );
224 
238 err_t compass6_default_cfg ( compass6_t *ctx );
239 
252 err_t compass6_generic_write ( compass6_t *ctx, uint8_t reg, uint8_t tx_data );
253 
266 err_t compass6_generic_read ( compass6_t *ctx, uint8_t reg, uint8_t *rx_data );
267 
275 uint8_t compass6_data_ready ( compass6_t *ctx );
276 
289 err_t compass6_get_axes_data ( compass6_t *ctx, compass6_axes_t *axes_data );
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 #endif // COMPASS6_H
295  // compass6
297 
298 // ------------------------------------------------------------------------ END
compass6_cfg_t
Compass 6 Click configuration object.
Definition: compass6.h:156
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
Definition: compass6.h:174
COMPASS6_ERROR
Definition: compass6.h:175
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:172
compass6_axes_t
Compass 6 Click axes data.
Definition: compass6.h:183
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_setup
void compass6_cfg_setup(compass6_cfg_t *cfg)
Compass 6 configuration object setup function.
compass6_t
Compass 6 Click context object.
Definition: compass6.h:139