compass8  2.1.0.0
compass8.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 COMPASS8_H
29 #define COMPASS8_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 COMPASS8_REG_WIA1 0x00
70 #define COMPASS8_REG_WIA2 0x01
71 #define COMPASS8_REG_RSV1 0x02
72 #define COMPASS8_REG_RSV2 0x03
73 #define COMPASS8_REG_ST1 0x10
74 #define COMPASS8_REG_HXH 0x11
75 #define COMPASS8_REG_HXL 0x12
76 #define COMPASS8_REG_HYH 0x13
77 #define COMPASS8_REG_HYL 0x14
78 #define COMPASS8_REG_HZH 0x15
79 #define COMPASS8_REG_HZL 0x16
80 #define COMPASS8_REG_TMPS 0x17
81 #define COMPASS8_REG_ST2 0x18
82 #define COMPASS8_REG_CNTL1 0x30
83 #define COMPASS8_REG_CNTL2 0x31
84 #define COMPASS8_REG_CNTL3 0x32
85 #define COMPASS8_REG_TS1 0x33
86 #define COMPASS8_REG_TS2 0x34
87  // compass8_reg
89 
104 #define COMPASS8_ST1_DATA_NORMAL 0x00
105 #define COMPASS8_ST1_DATA_READY 0x01
106 #define COMPASS8_ST1_DOR_NORMAL 0x00
107 #define COMPASS8_ST1_DOR_OVR 0x02
108 
113 #define COMPASS8_CNTL1_WM_STEP_1 0x00
114 #define COMPASS8_CNTL1_WM_STEP_2 0x01
115 #define COMPASS8_CNTL1_WM_STEP_3 0x02
116 #define COMPASS8_CNTL1_ITS_OFF 0x00
117 #define COMPASS8_CNTL1_ITS_LOW 0x20
118 #define COMPASS8_CNTL1_ITS_HIGH 0x40
119 #define COMPASS8_CNTL1_ITS_HIGH1 0x60
120 
125 #define COMPASS8_CNTL2_MODE_PD 0x00
126 #define COMPASS8_CNTL2_MODE_SNGL 0x01
127 #define COMPASS8_CNTL2_MODE_CONT1 0x02
128 #define COMPASS8_CNTL2_MODE_CONT2 0x04
129 #define COMPASS8_CNTL2_MODE_CONT3 0x05
130 #define COMPASS8_CNTL2_MODE_CONT4 0x08
131 #define COMPASS8_CNTL2_MODE_CONT5 0x0E
132 #define COMPASS8_CNTL2_MODE_BITMASK 0x0F
133 #define COMPASS8_CNTL2_MODE_ST 0x10
134 #define COMPASS8_CNTL2_IBIP_DIS 0x00
135 #define COMPASS8_CNTL2_IBIP_EN 0x20
136 #define COMPASS8_CNTL2_SDR_DIS 0x00
137 #define COMPASS8_CNTL2_SDR_EN 0x40
138 #define COMPASS8_CNTL2_FIFO_DIS 0x00
139 #define COMPASS8_CNTL2_FIFO_EN 0x80
140 
145 #define COMPASS8_CNTL3_SRST_NORMAL 0x00
146 #define COMPASS8_CNTL3_SRST_RESET 0x01
147 
152 #define COMPASS8_COMPANY_ID 0x48
153 #define COMPASS8_DEVICE_ID 0x0E
154 
159 #define COMPASS8_MAG_AXIS_SENS 0.125f
160 
166 #define COMPASS8_DEVICE_ADDRESS 0x0E
167  // compass8_set
169 
184 #define COMPASS8_MAP_MIKROBUS( cfg, mikrobus ) \
185  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
186  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
187  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
188  // compass8_map // compass8
191 
196 typedef struct
197 {
198  // Output pins
199  digital_out_t en;
201  // Modules
202  i2c_master_t i2c;
204  // I2C slave address
205  uint8_t slave_address;
207 } compass8_t;
208 
213 typedef struct
214 {
215  pin_name_t scl;
216  pin_name_t sda;
218  pin_name_t en;
220  uint32_t i2c_speed;
221  uint8_t i2c_address;
224 
229 typedef struct
230 {
231  float x;
232  float y;
233  float z;
236 
241 typedef enum
242 {
244  COMPASS8_ERROR = -1
245 
247 
264 
279 
293 
303 
313 
328 err_t compass8_generic_write ( compass8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
329 
344 err_t compass8_generic_read ( compass8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
345 
357 err_t compass8_get_company_id ( compass8_t *ctx, uint8_t *company_id );
358 
370 err_t compass8_get_device_id ( compass8_t *ctx, uint8_t *device_id );
371 
383 
398 err_t compass8_get_raw_data ( compass8_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z );
399 
414 
427 err_t compass8_set_operation_mode ( compass8_t *ctx, uint8_t op_mode );
428 
441 err_t compass8_get_operation_mode ( compass8_t *ctx, uint8_t *op_mode );
442 
456 err_t compass8_set_control ( compass8_t *ctx, uint8_t ctrl_reg, uint8_t data_in );
457 
470 
471 #ifdef __cplusplus
472 }
473 #endif
474 #endif // COMPASS8_H
475  // compass8
477 
478 // ------------------------------------------------------------------------ END
compass8_cfg_t::scl
pin_name_t scl
Definition: compass8.h:215
compass8_sw_reset
err_t compass8_sw_reset(compass8_t *ctx)
Compass 8 soft reset function.
compass8_generic_read
err_t compass8_generic_read(compass8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Compass 8 I2C reading function.
compass8_cfg_t
Compass 8 Click configuration object.
Definition: compass8.h:214
compass8_get_device_id
err_t compass8_get_device_id(compass8_t *ctx, uint8_t *device_id)
Compass 8 get device ID function.
compass8_return_value_t
compass8_return_value_t
Compass 8 Click return value data.
Definition: compass8.h:242
compass8_set_operation_mode
err_t compass8_set_operation_mode(compass8_t *ctx, uint8_t op_mode)
Compass 8 set operation mode function.
compass8_device_enable
void compass8_device_enable(compass8_t *ctx)
Compass 8 device enable function.
COMPASS8_ERROR
@ COMPASS8_ERROR
Definition: compass8.h:244
compass8_get_operation_mode
err_t compass8_get_operation_mode(compass8_t *ctx, uint8_t *op_mode)
Compass 8 get operation mode function.
compass8_t::slave_address
uint8_t slave_address
Definition: compass8.h:205
compass8_axes_t::x
float x
Definition: compass8.h:231
compass8_cfg_t::i2c_address
uint8_t i2c_address
Definition: compass8.h:221
compass8_device_disable
void compass8_device_disable(compass8_t *ctx)
Compass 8 device disable function.
compass8_cfg_t::en
pin_name_t en
Definition: compass8.h:218
compass8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: compass8.h:220
compass8_get_magnetic_data
err_t compass8_get_magnetic_data(compass8_t *ctx, compass8_axes_t *axis)
Compass 8 get magnetic data function.
compass8_t::en
digital_out_t en
Definition: compass8.h:199
compass8_axes_t::z
float z
Definition: compass8.h:233
compass8_get_raw_data
err_t compass8_get_raw_data(compass8_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z)
Compass 8 get mag raw data function.
compass8_axes_t
Compass 8 Click axes magnetic flux density data.
Definition: compass8.h:230
compass8_cfg_setup
void compass8_cfg_setup(compass8_cfg_t *cfg)
Compass 8 configuration object setup function.
compass8_t::i2c
i2c_master_t i2c
Definition: compass8.h:202
compass8_t
Compass 8 Click context object.
Definition: compass8.h:197
compass8_init
err_t compass8_init(compass8_t *ctx, compass8_cfg_t *cfg)
Compass 8 initialization function.
COMPASS8_OK
@ COMPASS8_OK
Definition: compass8.h:243
compass8_axes_t::y
float y
Definition: compass8.h:232
compass8_wait_data_ready
err_t compass8_wait_data_ready(compass8_t *ctx)
Compass 8 wait data ready function.
compass8_get_company_id
err_t compass8_get_company_id(compass8_t *ctx, uint8_t *company_id)
Compass 8 get company ID function.
compass8_cfg_t::sda
pin_name_t sda
Definition: compass8.h:216
compass8_default_cfg
err_t compass8_default_cfg(compass8_t *ctx)
Compass 8 default configuration function.
compass8_generic_write
err_t compass8_generic_write(compass8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Compass 8 I2C writing function.
compass8_set_control
err_t compass8_set_control(compass8_t *ctx, uint8_t ctrl_reg, uint8_t data_in)
Compass 8 set control function.