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
32extern "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 C3DHALL8_REG_MAGNETIC_X_MSB 0x00
74#define C3DHALL8_REG_MAGNETIC_Y_MSB 0x01
75#define C3DHALL8_REG_MAGENTIC_Z_MSB 0x02
76#define C3DHALL8_REG_TEMPERATURE_MSB 0x03
77#define C3DHALL8_REG_MAGNETIC_XY_LSB 0x04
78#define C3DHALL8_REG_TEMPERATURE_Z_LSB 0x05
79#define C3DHALL8_REG_STATUS 0x06
80#define C3DHALL8_REG_LOWER_THRESHOLD_X_MSB 0x07
81#define C3DHALL8_REG_UPPER_THRESHOLD_X_MSB 0x08
82#define C3DHALL8_REG_LOWER_THRESHOLD_Y_MSB 0x09
83#define C3DHALL8_REG_UPPER_THRESHOLD_Y_MSB 0x0A
84#define C3DHALL8_REG_LOWER_THRESHOLD_Z_MSB 0x0B
85#define C3DHALL8_REG_UPPER_THRESHOLD_Z_MSB 0x0C
86#define C3DHALL8_REG_THRESHOLDS_X_LSB 0x0D
87#define C3DHALL8_REG_THRESHOLDS_Y_LSB 0x0E
88#define C3DHALL8_REG_THRESHOLDS_Z_LSB 0x0F
89#define C3DHALL8_REG_CONFIG_1 0x10
90#define C3DHALL8_REG_MOD1 0x11
91#define C3DHALL8_REG_MOD2 0x13
92#define C3DHALL8_REG_CONFIG_2 0x14
93#define C3DHALL8_REG_VERSION 0x16
94
95 // c3dhall8_reg
96
111#define C3DHALL8_RX_BUFFER 0x17
112
118#define C3DHALL8_SET_DEV_ADDR 0x35
119
120 // c3dhall8_set
121
136#define C3DHALL8_MAP_MIKROBUS( cfg, mikrobus ) \
137 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
138 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
139 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
140
141 // c3dhall8_map
142 // c3dhall8
143
148typedef struct
149{
150 // Input pins
151 digital_in_t int_pin;
153 // Modules
154 i2c_master_t i2c;
156 // I2C slave address
159 uint8_t receiver_buff[ C3DHALL8_RX_BUFFER ];
160
161} c3dhall8_t;
162
167typedef struct
168{
169 pin_name_t scl;
170 pin_name_t sda;
172 pin_name_t int_pin;
174 uint32_t i2c_speed;
175 uint8_t i2c_address;
178
183typedef struct
184{
185 float x_axis;
186 float y_axis;
187 float z_axis;
189
191
196typedef enum
197{
199 C3DHALL8_ERROR = -1
200
202
221
239
256
273err_t c3dhall8_generic_write ( c3dhall8_t *ctx, uint8_t reg, uint8_t tx_buf );
274
291err_t c3dhall8_generic_read ( c3dhall8_t *ctx, uint8_t reg, uint8_t *rx_buf );
292
306
320
334
335#ifdef __cplusplus
336}
337#endif
338#endif // C3DHALL8_H
339
340 // c3dhall8
341
342// ------------------------------------------------------------------------ END
ismtx_return_value_t
3D Hall 8 Click return value data.
Definition c3dhall8.h:197
@ C3DHALL8_OK
Definition c3dhall8.h:198
@ C3DHALL8_ERROR
Definition c3dhall8.h:199
#define C3DHALL8_RX_BUFFER
3D Hall 8 receiver_buff length
Definition c3dhall8.h:111
err_t c3dhall8_generic_write(c3dhall8_t *ctx, uint8_t reg, uint8_t tx_buf)
3D Hall 8 I2C writing function.
err_t c3dhall8_default_cfg(c3dhall8_t *ctx)
3D Hall 8 default configuration function.
err_t c3dhall8_init(c3dhall8_t *ctx, c3dhall8_cfg_t *cfg)
3D Hall 8 initialization function.
float c3dhall8_get_xyz_magnetic_matching(c3dhall8_t *ctx, c3dhall8_data_t sensor_data)
Calculating magnetic matching.
void c3dhall8_cfg_setup(c3dhall8_cfg_t *cfg)
3D Hall 8 configuration object setup function.
float c3dhall8_get_xy_magnetic_matching(c3dhall8_t *ctx, c3dhall8_data_t sensor_data)
Calculating magnetic matching.
err_t c3dhall8_generic_read(c3dhall8_t *ctx, uint8_t reg, uint8_t *rx_buf)
3D Hall 8 I2C reading function.
void c3dhall8_read_sensor_data(c3dhall8_t *ctx, c3dhall8_data_t *sensor_data)
Reading sensor data function.
3D Hall 8 Click configuration object.
Definition c3dhall8.h:168
uint32_t i2c_speed
Definition c3dhall8.h:174
pin_name_t scl
Definition c3dhall8.h:169
pin_name_t int_pin
Definition c3dhall8.h:172
pin_name_t sda
Definition c3dhall8.h:170
uint8_t i2c_address
Definition c3dhall8.h:175
3D Hall 8 Click data object.
Definition c3dhall8.h:184
float z_axis
Definition c3dhall8.h:187
float x_axis
Definition c3dhall8.h:185
float y_axis
Definition c3dhall8.h:186
float temperature
Definition c3dhall8.h:188
3D Hall 8 Click context object.
Definition c3dhall8.h:149
digital_in_t int_pin
Definition c3dhall8.h:151
i2c_master_t i2c
Definition c3dhall8.h:154
uint8_t slave_address
Definition c3dhall8.h:157