magneto11  2.0.0.0
magneto11.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 MAGNETO11_H
29 #define MAGNETO11_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 MAGNETO11_REG_DATA_LSB 0x00
70 #define MAGNETO11_REG_DATA_MSB 0x01
71 #define MAGNETO11_REG_CONFIG 0x02
72 #define MAGNETO11_REG_OFFSET_LSB 0x03
73 #define MAGNETO11_REG_OFFSET_MSB 0x04
74 #define MAGNETO11_REG_SENSITIVITY 0x0B
75  // magneto11_reg
77 
92 #define MAGNETO11_DATA_RESOLUTION 0x03FF
93 #define MAGNETO11_DATA_OCF_MASK 0x0800
94 #define MAGNETO11_DATA_PARITY_MASK 0x0400
95 
100 #define MAGNETO11_SENSITIVITY_RES_50mT 0x00
101 #define MAGNETO11_SENSITIVITY_RES_25mT 0x01
102 #define MAGNETO11_SENSITIVITY_RES_12p5mT 0x02
103 #define MAGNETO11_SENSITIVITY_RES_18p75mT 0x03
104 #define MAGNETO11_SENSITIVITY_RES_MASK 0x03
105 #define MAGNETO11_SENSITIVITY_LSB_50mT 0.09766
106 #define MAGNETO11_SENSITIVITY_LSB_25mT 0.04883
107 #define MAGNETO11_SENSITIVITY_LSB_12p5mT 0.02441
108 #define MAGNETO11_SENSITIVITY_LSB_18p75mT 0.03662
109 
114 #define MAGNETO11_CONFIG_SPEED_FAST 0x00
115 #define MAGNETO11_CONFIG_SPEED_SLOW 0x04
116 #define MAGNETO11_CONFIG_POLARITY_NORMAL 0x00
117 #define MAGNETO11_CONFIG_POLARITY_REVERSED 0x02
118 #define MAGNETO11_CONFIG_OP_NORMAL 0x00
119 #define MAGNETO11_CONFIG_OP_POWER_DOWN 0x01
120 
126 #define MAGNETO11_DEV_ADDR_GND 0x56
127 #define MAGNETO11_DEV_ADDR_VCC 0x57
128  // magneto11_set
130 
145 #define MAGNETO11_MAP_MIKROBUS( cfg, mikrobus ) \
146  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
147  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
148  // magneto11_map // magneto11
151 
156 typedef struct
157 {
158  // Modules
159  i2c_master_t i2c;
161  // I2C slave address
162  uint8_t slave_address;
164 } magneto11_t;
165 
170 typedef struct
171 {
172  pin_name_t scl;
173  pin_name_t sda;
175  uint32_t i2c_speed;
176  uint8_t i2c_address;
179 
184 typedef enum
185 {
187  MAGNETO11_ERROR = -1
188 
190 
207 
223 
238 
254 err_t magneto11_generic_write ( magneto11_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
255 
271 err_t magneto11_generic_read ( magneto11_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
272 
284 err_t magneto11_get_magnetic_field ( magneto11_t *ctx, float *mag_field );
285 
297 err_t magneto11_get_offset ( magneto11_t *ctx, uint16_t *offset );
298 
310 err_t magneto11_set_config ( magneto11_t *ctx, uint8_t config );
311 
326 err_t magneto11_set_sensitivity ( magneto11_t *ctx, uint8_t sensitivity );
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 #endif // MAGNETO11_H
332  // magneto11
334 
335 // ------------------------------------------------------------------------ END
magneto11_cfg_t::scl
pin_name_t scl
Definition: magneto11.h:172
magneto11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: magneto11.h:175
magneto11_default_cfg
err_t magneto11_default_cfg(magneto11_t *ctx)
Magneto 11 default configuration function.
MAGNETO11_OK
@ MAGNETO11_OK
Definition: magneto11.h:186
magneto11_return_value_t
magneto11_return_value_t
Magneto 11 Click return value data.
Definition: magneto11.h:185
magneto11_set_config
err_t magneto11_set_config(magneto11_t *ctx, uint8_t config)
Magneto 11 set config function.
magneto11_generic_write
err_t magneto11_generic_write(magneto11_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Magneto 11 I2C writing function.
magneto11_cfg_t::sda
pin_name_t sda
Definition: magneto11.h:173
magneto11_t
Magneto 11 Click context object.
Definition: magneto11.h:157
magneto11_t::i2c
i2c_master_t i2c
Definition: magneto11.h:159
magneto11_generic_read
err_t magneto11_generic_read(magneto11_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Magneto 11 I2C reading function.
magneto11_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto11.h:176
magneto11_get_magnetic_field
err_t magneto11_get_magnetic_field(magneto11_t *ctx, float *mag_field)
Magneto 11 get magnetic field function.
magneto11_cfg_t
Magneto 11 Click configuration object.
Definition: magneto11.h:171
magneto11_get_offset
err_t magneto11_get_offset(magneto11_t *ctx, uint16_t *offset)
Magneto 11 get offset function.
magneto11_t::slave_address
uint8_t slave_address
Definition: magneto11.h:162
magneto11_set_sensitivity
err_t magneto11_set_sensitivity(magneto11_t *ctx, uint8_t sensitivity)
Magneto 11 set sensitivity function.
MAGNETO11_ERROR
@ MAGNETO11_ERROR
Definition: magneto11.h:187
magneto11_cfg_setup
void magneto11_cfg_setup(magneto11_cfg_t *cfg)
Magneto 11 configuration object setup function.
magneto11_init
err_t magneto11_init(magneto11_t *ctx, magneto11_cfg_t *cfg)
Magneto 11 initialization function.