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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define C3DHALL8_REG_MAGNETIC_X_MSB 0x00
60 #define C3DHALL8_REG_MAGNETIC_Y_MSB 0x01
61 #define C3DHALL8_REG_MAGENTIC_Z_MSB 0x02
62 #define C3DHALL8_REG_TEMPERATURE_MSB 0x03
63 #define C3DHALL8_REG_MAGNETIC_XY_LSB 0x04
64 #define C3DHALL8_REG_TEMPERATURE_Z_LSB 0x05
65 #define C3DHALL8_REG_STATUS 0x06
66 #define C3DHALL8_REG_LOWER_THRESHOLD_X_MSB 0x07
67 #define C3DHALL8_REG_UPPER_THRESHOLD_X_MSB 0x08
68 #define C3DHALL8_REG_LOWER_THRESHOLD_Y_MSB 0x09
69 #define C3DHALL8_REG_UPPER_THRESHOLD_Y_MSB 0x0A
70 #define C3DHALL8_REG_LOWER_THRESHOLD_Z_MSB 0x0B
71 #define C3DHALL8_REG_UPPER_THRESHOLD_Z_MSB 0x0C
72 #define C3DHALL8_REG_THRESHOLDS_X_LSB 0x0D
73 #define C3DHALL8_REG_THRESHOLDS_Y_LSB 0x0E
74 #define C3DHALL8_REG_THRESHOLDS_Z_LSB 0x0F
75 #define C3DHALL8_REG_CONFIG_1 0x10
76 #define C3DHALL8_REG_MOD1 0x11
77 #define C3DHALL8_REG_MOD2 0x13
78 #define C3DHALL8_REG_CONFIG_2 0x14
79 #define C3DHALL8_REG_VERSION 0x16
80  // c3dhall8_reg
82 
97 #define C3DHALL8_RX_BUFFER 0x17
98 
104 #define C3DHALL8_SET_DEV_ADDR 0x35
105  // c3dhall8_set
107 
122 #define C3DHALL8_MAP_MIKROBUS( cfg, mikrobus ) \
123  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
124  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
125  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
126  // c3dhall8_map // c3dhall8
129 
134 typedef struct
135 {
136  // Input pins
137  digital_in_t int_pin;
139  // Modules
140  i2c_master_t i2c;
142  // I2C slave address
143  uint8_t slave_address;
145  uint8_t receiver_buff[ C3DHALL8_RX_BUFFER ];
146 
147 } c3dhall8_t;
148 
153 typedef struct
154 {
155  pin_name_t scl;
156  pin_name_t sda;
158  pin_name_t int_pin;
160  uint32_t i2c_speed;
161  uint8_t i2c_address;
164 
169 typedef struct
170 {
171  float x_axis;
172  float y_axis;
173  float z_axis;
174  float temperature;
175 
177 
182 typedef enum
183 {
185  C3DHALL8_ERROR = -1
186 
188 
207 
225 
242 
259 err_t c3dhall8_generic_write ( c3dhall8_t *ctx, uint8_t reg, uint8_t tx_buf );
260 
277 err_t c3dhall8_generic_read ( c3dhall8_t *ctx, uint8_t reg, uint8_t *rx_buf );
278 
292 
306 
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 #endif // C3DHALL8_H
325  // c3dhall8
327 
328 // ------------------------------------------------------------------------ END
C3DHALL8_RX_BUFFER
#define C3DHALL8_RX_BUFFER
3D Hall 8 receiver_buff length
Definition: c3dhall8.h:97
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:174
c3dhall8_cfg_t::sda
pin_name_t sda
Definition: c3dhall8.h:156
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:183
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:184
c3dhall8_cfg_t::int_pin
pin_name_t int_pin
Definition: c3dhall8.h:158
c3dhall8_data_t::y_axis
float y_axis
Definition: c3dhall8.h:172
c3dhall8_cfg_t::scl
pin_name_t scl
Definition: c3dhall8.h:155
c3dhall8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: c3dhall8.h:160
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:173
c3dhall8_cfg_t::i2c_address
uint8_t i2c_address
Definition: c3dhall8.h:161
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:185
c3dhall8_data_t
3D Hall 8 Click data object.
Definition: c3dhall8.h:170
c3dhall8_t::i2c
i2c_master_t i2c
Definition: c3dhall8.h:140
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:154
c3dhall8_t::slave_address
uint8_t slave_address
Definition: c3dhall8.h:143
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:135
c3dhall8_data_t::x_axis
float x_axis
Definition: c3dhall8.h:171
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:137