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 
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 COMPASS8_REG_WIA1 0x00
74 #define COMPASS8_REG_WIA2 0x01
75 #define COMPASS8_REG_RSV1 0x02
76 #define COMPASS8_REG_RSV2 0x03
77 #define COMPASS8_REG_ST1 0x10
78 #define COMPASS8_REG_HXH 0x11
79 #define COMPASS8_REG_HXL 0x12
80 #define COMPASS8_REG_HYH 0x13
81 #define COMPASS8_REG_HYL 0x14
82 #define COMPASS8_REG_HZH 0x15
83 #define COMPASS8_REG_HZL 0x16
84 #define COMPASS8_REG_TMPS 0x17
85 #define COMPASS8_REG_ST2 0x18
86 #define COMPASS8_REG_CNTL1 0x30
87 #define COMPASS8_REG_CNTL2 0x31
88 #define COMPASS8_REG_CNTL3 0x32
89 #define COMPASS8_REG_TS1 0x33
90 #define COMPASS8_REG_TS2 0x34
91  // compass8_reg
93 
108 #define COMPASS8_ST1_DATA_NORMAL 0x00
109 #define COMPASS8_ST1_DATA_READY 0x01
110 #define COMPASS8_ST1_DOR_NORMAL 0x00
111 #define COMPASS8_ST1_DOR_OVR 0x02
112 
117 #define COMPASS8_CNTL1_WM_STEP_1 0x00
118 #define COMPASS8_CNTL1_WM_STEP_2 0x01
119 #define COMPASS8_CNTL1_WM_STEP_3 0x02
120 #define COMPASS8_CNTL1_ITS_OFF 0x00
121 #define COMPASS8_CNTL1_ITS_LOW 0x20
122 #define COMPASS8_CNTL1_ITS_HIGH 0x40
123 #define COMPASS8_CNTL1_ITS_HIGH1 0x60
124 
129 #define COMPASS8_CNTL2_MODE_PD 0x00
130 #define COMPASS8_CNTL2_MODE_SNGL 0x01
131 #define COMPASS8_CNTL2_MODE_CONT1 0x02
132 #define COMPASS8_CNTL2_MODE_CONT2 0x04
133 #define COMPASS8_CNTL2_MODE_CONT3 0x05
134 #define COMPASS8_CNTL2_MODE_CONT4 0x08
135 #define COMPASS8_CNTL2_MODE_CONT5 0x0E
136 #define COMPASS8_CNTL2_MODE_BITMASK 0x0F
137 #define COMPASS8_CNTL2_MODE_ST 0x10
138 #define COMPASS8_CNTL2_IBIP_DIS 0x00
139 #define COMPASS8_CNTL2_IBIP_EN 0x20
140 #define COMPASS8_CNTL2_SDR_DIS 0x00
141 #define COMPASS8_CNTL2_SDR_EN 0x40
142 #define COMPASS8_CNTL2_FIFO_DIS 0x00
143 #define COMPASS8_CNTL2_FIFO_EN 0x80
144 
149 #define COMPASS8_CNTL3_SRST_NORMAL 0x00
150 #define COMPASS8_CNTL3_SRST_RESET 0x01
151 
156 #define COMPASS8_COMPANY_ID 0x48
157 #define COMPASS8_DEVICE_ID 0x0E
158 
163 #define COMPASS8_MAG_AXIS_SENS 0.125f
164 
170 #define COMPASS8_DEVICE_ADDRESS 0x0E
171  // compass8_set
173 
188 #define COMPASS8_MAP_MIKROBUS( cfg, mikrobus ) \
189  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
190  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
191  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
192  // compass8_map // compass8
195 
200 typedef struct
201 {
202  // Output pins
203  digital_out_t en;
205  // Modules
206  i2c_master_t i2c;
208  // I2C slave address
209  uint8_t slave_address;
211 } compass8_t;
212 
217 typedef struct
218 {
219  pin_name_t scl;
220  pin_name_t sda;
222  pin_name_t en;
224  uint32_t i2c_speed;
225  uint8_t i2c_address;
228 
233 typedef struct
234 {
235  float x;
236  float y;
237  float z;
240 
245 typedef enum
246 {
248  COMPASS8_ERROR = -1
249 
251 
268 
283 
297 
307 
317 
332 err_t compass8_generic_write ( compass8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
333 
348 err_t compass8_generic_read ( compass8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
349 
361 err_t compass8_get_company_id ( compass8_t *ctx, uint8_t *company_id );
362 
374 err_t compass8_get_device_id ( compass8_t *ctx, uint8_t *device_id );
375 
387 
402 err_t compass8_get_raw_data ( compass8_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z );
403 
418 
431 err_t compass8_set_operation_mode ( compass8_t *ctx, uint8_t op_mode );
432 
445 err_t compass8_get_operation_mode ( compass8_t *ctx, uint8_t *op_mode );
446 
460 err_t compass8_set_control ( compass8_t *ctx, uint8_t ctrl_reg, uint8_t data_in );
461 
474 
475 #ifdef __cplusplus
476 }
477 #endif
478 #endif // COMPASS8_H
479  // compass8
481 
482 // ------------------------------------------------------------------------ END
compass8_cfg_t::scl
pin_name_t scl
Definition: compass8.h:219
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:218
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:246
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:248
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:209
compass8_axes_t::x
float x
Definition: compass8.h:235
compass8_cfg_t::i2c_address
uint8_t i2c_address
Definition: compass8.h:225
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:222
compass8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: compass8.h:224
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:203
compass8_axes_t::z
float z
Definition: compass8.h:237
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:234
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:206
compass8_t
Compass 8 Click context object.
Definition: compass8.h:201
compass8_init
err_t compass8_init(compass8_t *ctx, compass8_cfg_t *cfg)
Compass 8 initialization function.
COMPASS8_OK
@ COMPASS8_OK
Definition: compass8.h:247
compass8_axes_t::y
float y
Definition: compass8.h:236
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:220
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.