magneto6  2.1.0.0
magneto6.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 MAGNETO6_H
29 #define MAGNETO6_H
30 
31 #ifdef __cplusplus
32 extern "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 MAGNETO6_REG_MAGNETIC_X_MSB 0x00
74 #define MAGNETO6_REG_MAGNETIC_Y_MSB 0x01
75 #define MAGNETO6_REG_MAGNETIC_Z_MSB 0x02
76 #define MAGNETO6_REG_TEMPERATURE_MSB 0x03
77 #define MAGNETO6_REG_MAGNETIC_XY_LSB 0x04
78 #define MAGNETO6_REG_TEMPERATURE_Z_LSB 0x05
79 #define MAGNETO6_REG_DIAG 0x06
80 #define MAGNETO6_REG_CONFIG 0x10
81 #define MAGNETO6_REG_MOD1 0x11
82 #define MAGNETO6_REG_MOD2 0x13
83 #define MAGNETO6_REG_VERSION 0x16
84  // magneto6_reg
86 
101 #define MAGNETO6_CONFIG_DISABLE_TEMP 0x80
102 #define MAGNETO6_CONFIG_ENABLE_ANGULAR_XY 0x40
103 #define MAGNETO6_CONFIG_TRIGGER_DISABLE 0x00
104 #define MAGNETO6_CONFIG_TRIGGER_MSB 0x10
105 #define MAGNETO6_CONFIG_TRIGGER_REG_READ 0x20
106 #define MAGNETO6_CONFIG_TRIGGER_MASK 0x30
107 #define MAGNETO6_CONFIG_SHORT_RANGE_SENS_EN 0x08
108 #define MAGNETO6_CONFIG_TL_COMP_TC0 0x00
109 #define MAGNETO6_CONFIG_TL_COMP_TC1 0x02
110 #define MAGNETO6_CONFIG_TL_COMP_TC2 0x04
111 #define MAGNETO6_CONFIG_TL_COMP_TC3 0x06
112 #define MAGNETO6_CONFIG_TL_COMP_MASK 0x06
113 #define MAGNETO6_CONFIG_PARITY_BIT 0x01
114 
119 #define MAGNETO6_MOD1_FUSE_PARITY 0x80
120 #define MAGNETO6_MOD1_I2C_ADDR_0 0x00
121 #define MAGNETO6_MOD1_I2C_ADDR_1 0x20
122 #define MAGNETO6_MOD1_I2C_ADDR_2 0x40
123 #define MAGNETO6_MOD1_I2C_ADDR_3 0x60
124 #define MAGNETO6_MOD1_I2C_ADDR_MASK 0x60
125 #define MAGNETO6_MOD1_1BYTE_READ_EN 0x10
126 #define MAGNETO6_MOD1_COLLISION_AVOID 0x08
127 #define MAGNETO6_MOD1_INT_DISABLE 0x04
128 #define MAGNETO6_MOD1_MODE_LOW_POWER 0x00
129 #define MAGNETO6_MOD1_MODE_MASTER 0x01
130 #define MAGNETO6_MOD1_MODE_FAST 0x03
131 #define MAGNETO6_MOD1_MODE_MASK 0x03
132 
137 #define MAGNETO6_MOD2_FUPDATE_SLOW 0x80
138 #define MAGNETO6_MOD2_FACTORY_MASK 0x7F
139 
144 #define MAGNETO6_DIAG_BUS_PARITY 0x80
145 #define MAGNETO6_DIAG_FUSE_PARITY 0x40
146 #define MAGNETO6_DIAG_CFG_PARITY 0x20
147 #define MAGNETO6_DIAG_T_BIT 0x10
148 #define MAGNETO6_DIAG_PD3_FLAG 0x08
149 #define MAGNETO6_DIAG_PD0_FLAG 0x04
150 #define MAGNETO6_DIAG_FRAME_COUNTER_MASK 0x03
151 
156 #define MAGNETO6_VERSION_FACTORY_MASK 0xC0
157 #define MAGNETO6_VERSION_TYPE_MASK 0x30
158 #define MAGNETO6_VERSION_HWV_MASK 0x0F
159 
164 #define MAGNETO6_TEMP_25_DIGIT 1180
165 #define MAGNETO6_TEMP_25 25
166 #define MAGNETO6_TEMP_RES 0.24f
167 #define MAGNETO6_MAGNETIC_RES_MILLI_T 0.13f
168 
173 #define MAGNETO6_I2C_TIMEOUT 100000ul
174 
180 #define MAGNETO6_DEVICE_ADDRESS_0 0x35
181 #define MAGNETO6_DEVICE_ADDRESS_1 0x22
182 #define MAGNETO6_DEVICE_ADDRESS_2 0x78
183 #define MAGNETO6_DEVICE_ADDRESS_3 0x44
184  // magneto6_set
186 
201 #define MAGNETO6_MAP_MIKROBUS( cfg, mikrobus ) \
202  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
203  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
204  cfg.ien = MIKROBUS( mikrobus, MIKROBUS_CS ); \
205  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
206  // magneto6_map // magneto6
209 
214 typedef struct
215 {
216  float x_data;
217  float y_data;
218  float z_data;
219  float temperature;
222 
227 typedef struct
228 {
229  // Output pins
230  digital_out_t ien;
232  // Input pins
233  digital_in_t int_pin;
235  // Modules
236  pin_name_t scl;
237  pin_name_t sda;
239  uint8_t i2c_started;
241  // I2C slave address
242  uint8_t slave_address;
244 } magneto6_t;
245 
250 typedef struct
251 {
252  pin_name_t scl;
253  pin_name_t sda;
255  pin_name_t ien;
256  pin_name_t int_pin;
258  uint8_t i2c_address;
261 
266 typedef enum
267 {
269  MAGNETO6_ERROR = -1
270 
272 
289 
304 
318 
331 err_t magneto6_write_reg ( magneto6_t *ctx, uint8_t reg, uint8_t data_in );
332 
347 err_t magneto6_read_reg ( magneto6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
348 
358 void magneto6_set_ien_pin ( magneto6_t *ctx, uint8_t state );
359 
369 
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 #endif // MAGNETO6_H
389  // magneto6
391 
392 // ------------------------------------------------------------------------ END
magneto6_data_t::temperature
float temperature
Definition: magneto6.h:219
magneto6_t::slave_address
uint8_t slave_address
Definition: magneto6.h:242
magneto6_data_t::z_data
float z_data
Definition: magneto6.h:218
magneto6_cfg_t::ien
pin_name_t ien
Definition: magneto6.h:255
magneto6_get_int_pin
uint8_t magneto6_get_int_pin(magneto6_t *ctx)
Magneto 6 get int pin function.
magneto6_default_cfg
err_t magneto6_default_cfg(magneto6_t *ctx)
Magneto 6 default configuration function.
magneto6_read_reg
err_t magneto6_read_reg(magneto6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Magneto 6 read reg function.
magneto6_cfg_setup
void magneto6_cfg_setup(magneto6_cfg_t *cfg)
Magneto 6 configuration object setup function.
magneto6_cfg_t::scl
pin_name_t scl
Definition: magneto6.h:252
magneto6_t::ien
digital_out_t ien
Definition: magneto6.h:230
magneto6_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto6.h:258
MAGNETO6_OK
@ MAGNETO6_OK
Definition: magneto6.h:268
magneto6_cfg_t::int_pin
pin_name_t int_pin
Definition: magneto6.h:256
magneto6_set_ien_pin
void magneto6_set_ien_pin(magneto6_t *ctx, uint8_t state)
Magneto 6 set ien pin function.
magneto6_data_t
Magneto 6 Click data object.
Definition: magneto6.h:215
magneto6_cfg_t::sda
pin_name_t sda
Definition: magneto6.h:253
magneto6_read_data
err_t magneto6_read_data(magneto6_t *ctx, magneto6_data_t *data_out)
Magneto 6 read data function.
magneto6_return_value_t
magneto6_return_value_t
Magneto 6 Click return value data.
Definition: magneto6.h:267
MAGNETO6_ERROR
@ MAGNETO6_ERROR
Definition: magneto6.h:269
magneto6_data_t::y_data
float y_data
Definition: magneto6.h:217
magneto6_t::int_pin
digital_in_t int_pin
Definition: magneto6.h:233
magneto6_t::scl
pin_name_t scl
Definition: magneto6.h:236
magneto6_t::i2c_started
uint8_t i2c_started
Definition: magneto6.h:239
magneto6_cfg_t
Magneto 6 Click configuration object.
Definition: magneto6.h:251
magneto6_t
Magneto 6 Click context object.
Definition: magneto6.h:228
magneto6_data_t::x_data
float x_data
Definition: magneto6.h:216
magneto6_init
err_t magneto6_init(magneto6_t *ctx, magneto6_cfg_t *cfg)
Magneto 6 initialization function.
magneto6_write_reg
err_t magneto6_write_reg(magneto6_t *ctx, uint8_t reg, uint8_t data_in)
Magneto 6 write reg function.
magneto6_t::sda
pin_name_t sda
Definition: magneto6.h:237