c3dhall8  2.0.0.0
c3dhall8.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 C3DHALL8_H
29 #define C3DHALL8_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 C3DHALL8_REG_MAGNETIC_X_MSB 0x00
70 #define C3DHALL8_REG_MAGNETIC_Y_MSB 0x01
71 #define C3DHALL8_REG_MAGENTIC_Z_MSB 0x02
72 #define C3DHALL8_REG_TEMPERATURE_MSB 0x03
73 #define C3DHALL8_REG_MAGNETIC_XY_LSB 0x04
74 #define C3DHALL8_REG_TEMPERATURE_Z_LSB 0x05
75 #define C3DHALL8_REG_STATUS 0x06
76 #define C3DHALL8_REG_LOWER_THRESHOLD_X_MSB 0x07
77 #define C3DHALL8_REG_UPPER_THRESHOLD_X_MSB 0x08
78 #define C3DHALL8_REG_LOWER_THRESHOLD_Y_MSB 0x09
79 #define C3DHALL8_REG_UPPER_THRESHOLD_Y_MSB 0x0A
80 #define C3DHALL8_REG_LOWER_THRESHOLD_Z_MSB 0x0B
81 #define C3DHALL8_REG_UPPER_THRESHOLD_Z_MSB 0x0C
82 #define C3DHALL8_REG_THRESHOLDS_X_LSB 0x0D
83 #define C3DHALL8_REG_THRESHOLDS_Y_LSB 0x0E
84 #define C3DHALL8_REG_THRESHOLDS_Z_LSB 0x0F
85 #define C3DHALL8_REG_CONFIG_1 0x10
86 #define C3DHALL8_REG_MOD1 0x11
87 #define C3DHALL8_REG_MOD2 0x13
88 #define C3DHALL8_REG_CONFIG_2 0x14
89 #define C3DHALL8_REG_VERSION 0x16
90  // c3dhall8_reg
92 
107 #define C3DHALL8_RX_BUFFER 0x17
108 
114 #define C3DHALL8_SET_DEV_ADDR 0x35
115  // c3dhall8_set
117 
132 #define C3DHALL8_MAP_MIKROBUS( cfg, mikrobus ) \
133  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
134  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
135  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
136  // c3dhall8_map // c3dhall8
139 
144 typedef struct
145 {
146  // Input pins
147  digital_in_t int_pin;
149  // Modules
150  i2c_master_t i2c;
152  // I2C slave address
153  uint8_t slave_address;
155  uint8_t receiver_buff[ C3DHALL8_RX_BUFFER ];
156 
157 } c3dhall8_t;
158 
163 typedef struct
164 {
165  pin_name_t scl;
166  pin_name_t sda;
168  pin_name_t int_pin;
170  uint32_t i2c_speed;
171  uint8_t i2c_address;
174 
179 typedef struct
180 {
181  float x_axis;
182  float y_axis;
183  float z_axis;
184  float temperature;
185 
187 
192 typedef enum
193 {
195  C3DHALL8_ERROR = -1
196 
198 
217 
235 
252 
269 err_t c3dhall8_generic_write ( c3dhall8_t *ctx, uint8_t reg, uint8_t tx_buf );
270 
287 err_t c3dhall8_generic_read ( c3dhall8_t *ctx, uint8_t reg, uint8_t *rx_buf );
288 
302 
316 
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 #endif // C3DHALL8_H
335  // c3dhall8
337 
338 // ------------------------------------------------------------------------ END
C3DHALL8_RX_BUFFER
#define C3DHALL8_RX_BUFFER
3D Hall 8 receiver_buff length
Definition: c3dhall8.h:107
c3dhall8_generic_write
err_t c3dhall8_generic_write(c3dhall8_t *ctx, uint8_t reg, uint8_t tx_buf)
3D Hall 8 I2C writing function.
c3dhall8_data_t::temperature
float temperature
Definition: c3dhall8.h:184
c3dhall8_cfg_t::sda
pin_name_t sda
Definition: c3dhall8.h:166
c3dhall8_cfg_setup
void c3dhall8_cfg_setup(c3dhall8_cfg_t *cfg)
3D Hall 8 configuration object setup function.
ismtx_return_value_t
ismtx_return_value_t
3D Hall 8 Click return value data.
Definition: c3dhall8.h:193
c3dhall8_init
err_t c3dhall8_init(c3dhall8_t *ctx, c3dhall8_cfg_t *cfg)
3D Hall 8 initialization function.
C3DHALL8_OK
@ C3DHALL8_OK
Definition: c3dhall8.h:194
c3dhall8_cfg_t::int_pin
pin_name_t int_pin
Definition: c3dhall8.h:168
c3dhall8_data_t::y_axis
float y_axis
Definition: c3dhall8.h:182
c3dhall8_cfg_t::scl
pin_name_t scl
Definition: c3dhall8.h:165
c3dhall8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c3dhall8.h:170
c3dhall8_generic_read
err_t c3dhall8_generic_read(c3dhall8_t *ctx, uint8_t reg, uint8_t *rx_buf)
3D Hall 8 I2C reading function.
c3dhall8_data_t::z_axis
float z_axis
Definition: c3dhall8.h:183
c3dhall8_cfg_t::i2c_address
uint8_t i2c_address
Definition: c3dhall8.h:171
c3dhall8_read_sensor_data
void c3dhall8_read_sensor_data(c3dhall8_t *ctx, c3dhall8_data_t *sensor_data)
Reading sensor data function.
C3DHALL8_ERROR
@ C3DHALL8_ERROR
Definition: c3dhall8.h:195
c3dhall8_data_t
3D Hall 8 Click data object.
Definition: c3dhall8.h:180
c3dhall8_t::i2c
i2c_master_t i2c
Definition: c3dhall8.h:150
c3dhall8_default_cfg
err_t c3dhall8_default_cfg(c3dhall8_t *ctx)
3D Hall 8 default configuration function.
c3dhall8_cfg_t
3D Hall 8 Click configuration object.
Definition: c3dhall8.h:164
c3dhall8_t::slave_address
uint8_t slave_address
Definition: c3dhall8.h:153
c3dhall8_get_xyz_magnetic_matching
float c3dhall8_get_xyz_magnetic_matching(c3dhall8_t *ctx, c3dhall8_data_t sensor_data)
Calculating magnetic matching.
c3dhall8_t
3D Hall 8 Click context object.
Definition: c3dhall8.h:145
c3dhall8_data_t::x_axis
float x_axis
Definition: c3dhall8.h:181
c3dhall8_get_xy_magnetic_matching
float c3dhall8_get_xy_magnetic_matching(c3dhall8_t *ctx, c3dhall8_data_t sensor_data)
Calculating magnetic matching.
c3dhall8_t::int_pin
digital_in_t int_pin
Definition: c3dhall8.h:147