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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
64 #define COMPASS5_DEVICE_ID_NUM 0X0C
65 #define COMPASS5_COMPANI_ID_NUM 0X48
66 #define COMPASS5_COMPANI_ID 0x00
67 #define COMPASS5_DEVICE_ID 0x01
68 
73 #define COMPASS5_DATA_STATUS_1 0x10
74 
79 #define COMPASS5_X_AXIS_DATA_L 0x11
80 #define COMPASS5_X_AXIS_DATA_H 0x12
81 #define COMPASS5_Y_AXIS_DATA_L 0x13
82 #define COMPASS5_Y_AXIS_DATA_H 0x14
83 #define COMPASS5_Z_AXIS_DATA_L 0x15
84 #define COMPASS5_Z_AXIS_DATA_H 0x16
85 
90 #define COMPASS5_DUMMY_TMPS 0x17
91 #define COMPASS5_DATA_STATUS_2 0x18
92 
97 #define COMPASS5_DUMMY_CNTL1 0x30
98 #define COMPASS5_CONTROL_2_SETTINGS 0x31
99 #define COMPASS5_CONTROL_3_SETTINGS 0x32
100 #define COMPASS5_TEST_TS1 0x33
101 #define COMPASS5_TEST_TS2 0x34
102  // compass5_reg
104 
119 #define COMPASS5_MODE_POWER_DOWN 0x00
120 #define COMPASS5_MODE_SINGLE_MEASUREMENT 0x01
121 #define COMPASS5_MODE_CON_MEASUREMENT_10HZ 0x02
122 #define COMPASS5_MODE_CON_MEASUREMENT_20HZ 0x04
123 #define COMPASS5_MODE_CON_MEASUREMENT_50HZ 0x06
124 #define COMPASS5_MODE_CON_MEASUREMENT_100HZ 0x08
125 #define COMPASS5_MODE_SELF_TEST 0x10
126 
131 #define COMPASS5_SRST_BIT 0x01
132 #define COMPASS5_HOFL_BIT 0x08
133 #define COMPASS5_DOR_BIT 0x02
134 #define COMPASS5_DRDY_BIT 0x01
135 
140 #define COMPASS5_DATA_NO_READY 0x00
141 #define COMPASS5_DATA_READY 0x01
142 
147 #define COMPASS5_BIT_MASK_BIT0 0x01
148 
154 #define COMPASS5_SET_DEV_ADDR 0x0C
155  // compass5_set
157 
172 #define COMPASS5_MAP_MIKROBUS( cfg, mikrobus ) \
173  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
174  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
175 
176  // compass5_map // compass5
178 
183 typedef struct
184 {
185  // Modules
186  i2c_master_t i2c;
188  // I2C slave address
189  uint8_t slave_address;
191 } compass5_t;
192 
197 typedef struct
198 {
199  pin_name_t scl;
200  pin_name_t sda;
202  uint32_t i2c_speed;
203  uint8_t i2c_address;
206 
211 typedef enum
212 {
214  COMPASS5_ERROR = -1
215 
217 
234 void compass5_cfg_setup ( compass5_cfg_t *cfg );
235 
251 err_t compass5_init ( compass5_t *ctx, compass5_cfg_t *cfg );
252 
269 err_t compass5_generic_write ( compass5_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
270 
287 err_t compass5_generic_read ( compass5_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
288 
300 void compass5_write_byte ( compass5_t *ctx, uint8_t reg, uint8_t tx_data );
301 
312 uint8_t compass5_read_byte ( compass5_t *ctx, uint8_t reg );
313 
323 void compass5_sw_reset ( compass5_t *ctx );
324 
336 void compass5_get_id ( compass5_t *ctx, uint8_t *company_id, uint8_t *device_id );
337 
347 uint8_t compass5_check_data_ready ( compass5_t *ctx );
348 
358 uint8_t compass5_check_data_overrun ( compass5_t *ctx );
359 
371 uint8_t compass5_set_operation_mode ( compass5_t *ctx, uint8_t op_mode );
372 
382 uint8_t compass5_get_operation_mode ( compass5_t *ctx );
383 
396 void compass5_measurement_axis ( compass5_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z );
397 
410 void compass5_get_mag_data ( compass5_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z );
411 #ifdef __cplusplus
412 }
413 #endif
414 #endif // COMPASS5_H
415  // compass5
417 
418 // ------------------------------------------------------------------------ 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:210
COMPASS5_OK
Definition: compass5.h:212
COMPASS5_ERROR
Definition: compass5.h:213
compass5_cfg_t
Compass 5 Click configuration object.
Definition: compass5.h:196
compass5_set_operation_mode
uint8_t compass5_set_operation_mode(compass5_t *ctx, uint8_t op_mode)
Compass 5 set operation mode function.
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.
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
Compass 5 Click context object.
Definition: compass5.h:182
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_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.