compass5  2.0.0.0
compass5.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 COMPASS5_H
29 #define COMPASS5_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 
78 #define COMPASS5_DEVICE_ID_NUM 0X0C
79 #define COMPASS5_COMPANI_ID_NUM 0X48
80 #define COMPASS5_COMPANI_ID 0x00
81 #define COMPASS5_DEVICE_ID 0x01
82 
87 #define COMPASS5_DATA_STATUS_1 0x10
88 
93 #define COMPASS5_X_AXIS_DATA_L 0x11
94 #define COMPASS5_X_AXIS_DATA_H 0x12
95 #define COMPASS5_Y_AXIS_DATA_L 0x13
96 #define COMPASS5_Y_AXIS_DATA_H 0x14
97 #define COMPASS5_Z_AXIS_DATA_L 0x15
98 #define COMPASS5_Z_AXIS_DATA_H 0x16
99 
104 #define COMPASS5_DUMMY_TMPS 0x17
105 #define COMPASS5_DATA_STATUS_2 0x18
106 
111 #define COMPASS5_DUMMY_CNTL1 0x30
112 #define COMPASS5_CONTROL_2_SETTINGS 0x31
113 #define COMPASS5_CONTROL_3_SETTINGS 0x32
114 #define COMPASS5_TEST_TS1 0x33
115 #define COMPASS5_TEST_TS2 0x34
116  // compass5_reg
118 
133 #define COMPASS5_MODE_POWER_DOWN 0x00
134 #define COMPASS5_MODE_SINGLE_MEASUREMENT 0x01
135 #define COMPASS5_MODE_CON_MEASUREMENT_10HZ 0x02
136 #define COMPASS5_MODE_CON_MEASUREMENT_20HZ 0x04
137 #define COMPASS5_MODE_CON_MEASUREMENT_50HZ 0x06
138 #define COMPASS5_MODE_CON_MEASUREMENT_100HZ 0x08
139 #define COMPASS5_MODE_SELF_TEST 0x10
140 
145 #define COMPASS5_SRST_BIT 0x01
146 #define COMPASS5_HOFL_BIT 0x08
147 #define COMPASS5_DOR_BIT 0x02
148 #define COMPASS5_DRDY_BIT 0x01
149 
154 #define COMPASS5_DATA_NO_READY 0x00
155 #define COMPASS5_DATA_READY 0x01
156 
161 #define COMPASS5_BIT_MASK_BIT0 0x01
162 
168 #define COMPASS5_SET_DEV_ADDR 0x0C
169  // compass5_set
171 
186 #define COMPASS5_MAP_MIKROBUS( cfg, mikrobus ) \
187  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
188  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
189 
190  // compass5_map // compass5
192 
197 typedef struct
198 {
199  // Modules
200  i2c_master_t i2c;
202  // I2C slave address
203  uint8_t slave_address;
205 } compass5_t;
206 
211 typedef struct
212 {
213  pin_name_t scl;
214  pin_name_t sda;
216  uint32_t i2c_speed;
217  uint8_t i2c_address;
220 
225 typedef enum
226 {
228  COMPASS5_ERROR = -1
229 
231 
249 
266 
283 err_t compass5_generic_write ( compass5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
284 
301 err_t compass5_generic_read ( compass5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
302 
314 void compass5_write_byte ( compass5_t *ctx, uint8_t reg, uint8_t tx_data );
315 
326 uint8_t compass5_read_byte ( compass5_t *ctx, uint8_t reg );
327 
338 
350 void compass5_get_id ( compass5_t *ctx, uint8_t *company_id, uint8_t *device_id );
351 
362 
373 
385 uint8_t compass5_set_operation_mode ( compass5_t *ctx, uint8_t op_mode );
386 
397 
410 void compass5_measurement_axis ( compass5_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z );
411 
424 void compass5_get_mag_data ( compass5_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z );
425 #ifdef __cplusplus
426 }
427 #endif
428 #endif // COMPASS5_H
429  // compass5
431 
432 // ------------------------------------------------------------------------ END
compass5_check_data_ready
uint8_t compass5_check_data_ready(compass5_t *ctx)
Compass 5 check data ready function.
compass5_get_mag_data
void compass5_get_mag_data(compass5_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z)
Compass 5 full measurement axis function.
compass5_read_byte
uint8_t compass5_read_byte(compass5_t *ctx, uint8_t reg)
Compass 5 read 1 byte function.
compass5_return_value_t
compass5_return_value_t
Compass 5 Click return value data.
Definition: compass5.h:226
COMPASS5_OK
@ COMPASS5_OK
Definition: compass5.h:227
COMPASS5_ERROR
@ COMPASS5_ERROR
Definition: compass5.h:228
compass5_cfg_t
Compass 5 Click configuration object.
Definition: compass5.h:212
compass5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: compass5.h:216
compass5_set_operation_mode
uint8_t compass5_set_operation_mode(compass5_t *ctx, uint8_t op_mode)
Compass 5 set operation mode function.
compass5_cfg_t::i2c_address
uint8_t i2c_address
Definition: compass5.h:217
compass5_cfg_t::scl
pin_name_t scl
Definition: compass5.h:213
compass5_check_data_overrun
uint8_t compass5_check_data_overrun(compass5_t *ctx)
Compass 5 check data overrun function.
compass5_get_id
void compass5_get_id(compass5_t *ctx, uint8_t *company_id, uint8_t *device_id)
Compass 5 get ID function.
compass5_t::i2c
i2c_master_t i2c
Definition: compass5.h:200
device_id
uint8_t device_id
Definition: main.c:28
compass5_generic_write
err_t compass5_generic_write(compass5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Compass 5 I2C writing function.
compass5_sw_reset
void compass5_sw_reset(compass5_t *ctx)
Compass 5 software reset function.
compass5_get_operation_mode
uint8_t compass5_get_operation_mode(compass5_t *ctx)
Compass 5 get operation mode function.
compass5_cfg_setup
void compass5_cfg_setup(compass5_cfg_t *cfg)
Compass 5 configuration object setup function.
compass5_t::slave_address
uint8_t slave_address
Definition: compass5.h:203
compass5_t
Compass 5 Click context object.
Definition: compass5.h:198
compass5_measurement_axis
void compass5_measurement_axis(compass5_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z)
Compass 5 full measurement axis function.
compass5_write_byte
void compass5_write_byte(compass5_t *ctx, uint8_t reg, uint8_t tx_data)
Compass 5 write byte function.
company_id
uint8_t company_id
Definition: main.c:29
compass5_cfg_t::sda
pin_name_t sda
Definition: compass5.h:214
compass5_generic_read
err_t compass5_generic_read(compass5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Compass 5 I2C reading function.
compass5_init
err_t compass5_init(compass5_t *ctx, compass5_cfg_t *cfg)
Compass 5 initialization function.