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 
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 MAGNETO6_REG_MAGNETIC_X_MSB 0x00
70 #define MAGNETO6_REG_MAGNETIC_Y_MSB 0x01
71 #define MAGNETO6_REG_MAGNETIC_Z_MSB 0x02
72 #define MAGNETO6_REG_TEMPERATURE_MSB 0x03
73 #define MAGNETO6_REG_MAGNETIC_XY_LSB 0x04
74 #define MAGNETO6_REG_TEMPERATURE_Z_LSB 0x05
75 #define MAGNETO6_REG_DIAG 0x06
76 #define MAGNETO6_REG_CONFIG 0x10
77 #define MAGNETO6_REG_MOD1 0x11
78 #define MAGNETO6_REG_MOD2 0x13
79 #define MAGNETO6_REG_VERSION 0x16
80  // magneto6_reg
82 
97 #define MAGNETO6_CONFIG_DISABLE_TEMP 0x80
98 #define MAGNETO6_CONFIG_ENABLE_ANGULAR_XY 0x40
99 #define MAGNETO6_CONFIG_TRIGGER_DISABLE 0x00
100 #define MAGNETO6_CONFIG_TRIGGER_MSB 0x10
101 #define MAGNETO6_CONFIG_TRIGGER_REG_READ 0x20
102 #define MAGNETO6_CONFIG_TRIGGER_MASK 0x30
103 #define MAGNETO6_CONFIG_SHORT_RANGE_SENS_EN 0x08
104 #define MAGNETO6_CONFIG_TL_COMP_TC0 0x00
105 #define MAGNETO6_CONFIG_TL_COMP_TC1 0x02
106 #define MAGNETO6_CONFIG_TL_COMP_TC2 0x04
107 #define MAGNETO6_CONFIG_TL_COMP_TC3 0x06
108 #define MAGNETO6_CONFIG_TL_COMP_MASK 0x06
109 #define MAGNETO6_CONFIG_PARITY_BIT 0x01
110 
115 #define MAGNETO6_MOD1_FUSE_PARITY 0x80
116 #define MAGNETO6_MOD1_I2C_ADDR_0 0x00
117 #define MAGNETO6_MOD1_I2C_ADDR_1 0x20
118 #define MAGNETO6_MOD1_I2C_ADDR_2 0x40
119 #define MAGNETO6_MOD1_I2C_ADDR_3 0x60
120 #define MAGNETO6_MOD1_I2C_ADDR_MASK 0x60
121 #define MAGNETO6_MOD1_1BYTE_READ_EN 0x10
122 #define MAGNETO6_MOD1_COLLISION_AVOID 0x08
123 #define MAGNETO6_MOD1_INT_DISABLE 0x04
124 #define MAGNETO6_MOD1_MODE_LOW_POWER 0x00
125 #define MAGNETO6_MOD1_MODE_MASTER 0x01
126 #define MAGNETO6_MOD1_MODE_FAST 0x03
127 #define MAGNETO6_MOD1_MODE_MASK 0x03
128 
133 #define MAGNETO6_MOD2_FUPDATE_SLOW 0x80
134 #define MAGNETO6_MOD2_FACTORY_MASK 0x7F
135 
140 #define MAGNETO6_DIAG_BUS_PARITY 0x80
141 #define MAGNETO6_DIAG_FUSE_PARITY 0x40
142 #define MAGNETO6_DIAG_CFG_PARITY 0x20
143 #define MAGNETO6_DIAG_T_BIT 0x10
144 #define MAGNETO6_DIAG_PD3_FLAG 0x08
145 #define MAGNETO6_DIAG_PD0_FLAG 0x04
146 #define MAGNETO6_DIAG_FRAME_COUNTER_MASK 0x03
147 
152 #define MAGNETO6_VERSION_FACTORY_MASK 0xC0
153 #define MAGNETO6_VERSION_TYPE_MASK 0x30
154 #define MAGNETO6_VERSION_HWV_MASK 0x0F
155 
160 #define MAGNETO6_TEMP_25_DIGIT 1180
161 #define MAGNETO6_TEMP_25 25
162 #define MAGNETO6_TEMP_RES 0.24f
163 #define MAGNETO6_MAGNETIC_RES_MILLI_T 0.13f
164 
169 #define MAGNETO6_I2C_TIMEOUT 100000ul
170 
176 #define MAGNETO6_DEVICE_ADDRESS_0 0x35
177 #define MAGNETO6_DEVICE_ADDRESS_1 0x22
178 #define MAGNETO6_DEVICE_ADDRESS_2 0x78
179 #define MAGNETO6_DEVICE_ADDRESS_3 0x44
180  // magneto6_set
182 
197 #define MAGNETO6_MAP_MIKROBUS( cfg, mikrobus ) \
198  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
199  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
200  cfg.ien = MIKROBUS( mikrobus, MIKROBUS_CS ); \
201  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
202  // magneto6_map // magneto6
205 
210 typedef struct
211 {
212  float x_data;
213  float y_data;
214  float z_data;
215  float temperature;
218 
223 typedef struct
224 {
225  // Output pins
226  digital_out_t ien;
228  // Input pins
229  digital_in_t int_pin;
231  // Modules
232  pin_name_t scl;
233  pin_name_t sda;
235  uint8_t i2c_started;
237  // I2C slave address
238  uint8_t slave_address;
240 } magneto6_t;
241 
246 typedef struct
247 {
248  pin_name_t scl;
249  pin_name_t sda;
251  pin_name_t ien;
252  pin_name_t int_pin;
254  uint8_t i2c_address;
257 
262 typedef enum
263 {
265  MAGNETO6_ERROR = -1
266 
268 
285 
300 
314 
327 err_t magneto6_write_reg ( magneto6_t *ctx, uint8_t reg, uint8_t data_in );
328 
343 err_t magneto6_read_reg ( magneto6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
344 
354 void magneto6_set_ien_pin ( magneto6_t *ctx, uint8_t state );
355 
365 
380 
381 #ifdef __cplusplus
382 }
383 #endif
384 #endif // MAGNETO6_H
385  // magneto6
387 
388 // ------------------------------------------------------------------------ END
magneto6_data_t::temperature
float temperature
Definition: magneto6.h:215
magneto6_t::slave_address
uint8_t slave_address
Definition: magneto6.h:238
magneto6_data_t::z_data
float z_data
Definition: magneto6.h:214
magneto6_cfg_t::ien
pin_name_t ien
Definition: magneto6.h:251
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:248
magneto6_t::ien
digital_out_t ien
Definition: magneto6.h:226
magneto6_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto6.h:254
MAGNETO6_OK
@ MAGNETO6_OK
Definition: magneto6.h:264
magneto6_cfg_t::int_pin
pin_name_t int_pin
Definition: magneto6.h:252
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:211
magneto6_cfg_t::sda
pin_name_t sda
Definition: magneto6.h:249
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:263
MAGNETO6_ERROR
@ MAGNETO6_ERROR
Definition: magneto6.h:265
magneto6_data_t::y_data
float y_data
Definition: magneto6.h:213
magneto6_t::int_pin
digital_in_t int_pin
Definition: magneto6.h:229
magneto6_t::scl
pin_name_t scl
Definition: magneto6.h:232
magneto6_t::i2c_started
uint8_t i2c_started
Definition: magneto6.h:235
magneto6_cfg_t
Magneto 6 Click configuration object.
Definition: magneto6.h:247
magneto6_t
Magneto 6 Click context object.
Definition: magneto6.h:224
magneto6_data_t::x_data
float x_data
Definition: magneto6.h:212
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:233