c3dhall9 2.0.0.0
c3dhall9.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 C3DHALL9_H
29#define C3DHALL9_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 C3DHALL9_REG_EEPROM_02 0x02
74#define C3DHALL9_REG_EEPROM_03 0x03
75#define C3DHALL9_REG_EEPROM_0D 0x0D
76#define C3DHALL9_REG_EEPROM_0E 0x0E
77#define C3DHALL9_REG_EEPROM_0F 0x0F
78#define C3DHALL9_REG_VOLATILE_27 0x27
79#define C3DHALL9_REG_VOLATILE_28 0x28
80#define C3DHALL9_REG_VOLATILE_29 0x29
81
82 // c3dhall9_reg
83
98#define C3DHALL9_EEPROM_02_ENABLE_Z 0x00000100ul
99#define C3DHALL9_EEPROM_02_ENABLE_Y 0x00000080ul
100#define C3DHALL9_EEPROM_02_ENABLE_X 0x00000040ul
101#define C3DHALL9_VOLATILE_27_ACTIVE_MODE 0x00000000ul
102#define C3DHALL9_VOLATILE_27_SLEEP_MODE 0x00000001ul
103#define C3DHALL9_VOLATILE_27_LOW_POWER_MODE 0x00000002ul
104#define C3DHALL9_VOLATILE_27_I2C_SINGLE 0x00000000ul
105#define C3DHALL9_VOLATILE_27_I2C_FAST_LOOP 0x00000004ul
106#define C3DHALL9_VOLATILE_27_I2C_FULL_LOOP 0x00000008ul
107
112#define C3DHALL9_12BIT_RESOLUTION 0x1000
113#define C3DHALL9_SIGN_BIT 0x0800
114#define C3DHALL9_DATA_READY_BIT 0x0080
115#define C3DHALL9_GAUSS_RESOLUTION 4
116#define C3DHALL9_TEMPERATURE_MULTIPLIER 302
117#define C3DHALL9_TEMPERATURE_SUBTRACTOR 1702
118#define C3DHALL9_TEMPERATURE_SUBTRACTOR 1702
119#define C3DHALL9_HALF_CICRLE_DEGREES 180.0
120#define C3DHALL9_MATH_TWO_PI 6.28318530717958
121
127#define C3DHALL9_SET_DEV_ADDR 0x60
128
129 // c3dhall9_set
130
145#define C3DHALL9_MAP_MIKROBUS( cfg, mikrobus ) \
146 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
147 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
148 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
149 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
150
151 // c3dhall9_map
152 // c3dhall9
153
158typedef struct
159{
160 // Output pins
161 digital_out_t en;
163 // Input pins
164 digital_in_t int_pin;
166 // Modules
167 i2c_master_t i2c;
169 // I2C slave address
172} c3dhall9_t;
173
178typedef struct
179{
180 pin_name_t scl;
181 pin_name_t sda;
183 pin_name_t en;
184 pin_name_t int_pin;
186 uint32_t i2c_speed;
187 uint8_t i2c_address;
190
195typedef enum
196{
198 C3DHALL9_ERROR = -1
199
201
206typedef struct
207{
208 float x_axis;
209 float y_axis;
210 float z_axis;
211 float angle_xy;
212 float angle_xz;
213 float angle_yz;
215
217
234
250
265
279err_t c3dhall9_write_register ( c3dhall9_t *ctx, uint8_t reg, uint32_t data_in );
280
294err_t c3dhall9_read_register ( c3dhall9_t *ctx, uint8_t reg, uint32_t *data_out );
295
305
315
325
342
343#ifdef __cplusplus
344}
345#endif
346#endif // C3DHALL9_H
347
348 // c3dhall9
349
350// ------------------------------------------------------------------------ END
c3dhall9_return_value_t
3D Hall 9 Click return value data.
Definition c3dhall9.h:196
@ C3DHALL9_OK
Definition c3dhall9.h:197
@ C3DHALL9_ERROR
Definition c3dhall9.h:198
err_t c3dhall9_read_register(c3dhall9_t *ctx, uint8_t reg, uint32_t *data_out)
3D Hall 9 I2C reading function.
void c3dhall9_disable_chip(c3dhall9_t *ctx)
3D Hall 9 disable chip function.
err_t c3dhall9_read_data(c3dhall9_t *ctx, c3dhall9_data_t *data_out)
3D Hall 9 read data function.
uint8_t c3dhall9_get_int_pin(c3dhall9_t *ctx)
3D Hall 9 get int pin function.
err_t c3dhall9_default_cfg(c3dhall9_t *ctx)
3D Hall 9 default configuration function.
void c3dhall9_enable_chip(c3dhall9_t *ctx)
3D Hall 9 enable chip function.
void c3dhall9_cfg_setup(c3dhall9_cfg_t *cfg)
3D Hall 9 configuration object setup function.
err_t c3dhall9_write_register(c3dhall9_t *ctx, uint8_t reg, uint32_t data_in)
3D Hall 9 I2C writing function.
err_t c3dhall9_init(c3dhall9_t *ctx, c3dhall9_cfg_t *cfg)
3D Hall 9 initialization function.
3D Hall 9 Click configuration object.
Definition c3dhall9.h:179
uint32_t i2c_speed
Definition c3dhall9.h:186
pin_name_t scl
Definition c3dhall9.h:180
pin_name_t en
Definition c3dhall9.h:183
pin_name_t int_pin
Definition c3dhall9.h:184
pin_name_t sda
Definition c3dhall9.h:181
uint8_t i2c_address
Definition c3dhall9.h:187
3D Hall 9 Click data object.
Definition c3dhall9.h:207
float z_axis
Definition c3dhall9.h:210
float angle_xz
Definition c3dhall9.h:212
float angle_xy
Definition c3dhall9.h:211
float x_axis
Definition c3dhall9.h:208
float y_axis
Definition c3dhall9.h:209
float angle_yz
Definition c3dhall9.h:213
float temperature
Definition c3dhall9.h:214
3D Hall 9 Click context object.
Definition c3dhall9.h:159
digital_in_t int_pin
Definition c3dhall9.h:164
i2c_master_t i2c
Definition c3dhall9.h:167
digital_out_t en
Definition c3dhall9.h:161
uint8_t slave_address
Definition c3dhall9.h:170