magneto10  2.0.0.0
magneto10.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 MAGNETO10_H
29 #define MAGNETO10_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 MAGNETO10_REG_STAT1 0x00
70 #define MAGNETO10_REG_X_LSB 0x01
71 #define MAGNETO10_REG_X_MSB 0x02
72 #define MAGNETO10_REG_Y_LSB 0x03
73 #define MAGNETO10_REG_Y_MSB 0x04
74 #define MAGNETO10_REG_Z_LSB 0x05
75 #define MAGNETO10_REG_Z_MSB 0x06
76 #define MAGNETO10_REG_STAT2 0x07
77 #define MAGNETO10_REG_T_LSB 0x08
78 #define MAGNETO10_REG_T_MSB 0x09
79 #define MAGNETO10_REG_CID 0x0A
80 #define MAGNETO10_REG_DID 0x0B
81 #define MAGNETO10_REG_CTRL 0x10
82 #define MAGNETO10_REG_RST 0x11
83 #define MAGNETO10_REG_OSR_DIG_FILT 0x14
84 #define MAGNETO10_REG_T_EN_DIG_FILT_Z 0x15
85  // magneto10_reg
87 
102 #define MAGNETO10_MODE_IDLE 0x00
103 #define MAGNETO10_MODE_SINGLE_MEAS 0x01
104 #define MAGNETO10_MODE_CONT_MEAS_10HZ 0x02
105 #define MAGNETO10_MODE_CONT_MEAS_20HZ 0x03
106 #define MAGNETO10_MODE_CONT_MEAS_50HZ 0x04
107 #define MAGNETO10_MODE_CONT_MEAS_100HZ 0x05
108 #define MAGNETO10_MODE_SELF_TEST 0x06
109 #define MAGNETO10_MODE_CONT_MEAS_200HZ 0x0A
110 #define MAGNETO10_MODE_CONT_MEAS_500HZ 0x0B
111 #define MAGNETO10_MODE_CONT_MEAS_800HZ 0x0C
112 #define MAGNETO10_MODE_CONT_MEAS_1400HZ 0x0D
113 #define MAGNETO10_MODE_POWER_DOWN 0x0F
114 
119 #define MAGNETO10_COMPANY_ID 0x98
120 #define MAGNETO10_DEVICE_ID 0xBA
121 
126 #define MAGNETO10_RESET 0x06
127 
132 #define MAGNETO10_STAT1_RT 0x08
133 #define MAGNETO10_STAT1_DRDY 0x01
134 #define MAGNETO10_STAT2_DOR 0x02
135 #define MAGNETO10_STAT2_HOVF 0x01
136 
141 #define MAGNETO10_TEMPERATURE_RES 50.0
142 #define MAGNETO10_TEMPERATURE_ENABLE 0x01
143 #define MAGNETO10_TEMPERATURE_DISABLE 0x00
144 #define MAGNETO10_TEMPERATURE_EN_MASK 0x20
145 
150 #define MAGNETO10_MAG_FLUX_RESOLUTION 0.15
151 
157 #define MAGNETO10_SET_DEV_ADDR 0x0C
158  // magneto10_set
160 
175 #define MAGNETO10_MAP_MIKROBUS( cfg, mikrobus ) \
176  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
177  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
178  // magneto10_map // magneto10
181 
186 typedef struct
187 {
188  // Modules
189  i2c_master_t i2c;
191  // I2C slave address
192  uint8_t slave_address;
194 } magneto10_t;
195 
200 typedef struct
201 {
202  pin_name_t scl;
203  pin_name_t sda;
205  uint32_t i2c_speed;
206  uint8_t i2c_address;
209 
214 typedef enum
215 {
217  MAGNETO10_ERROR = -1
218 
220 
237 
253 
268 
283 err_t magneto10_mem_write_single ( magneto10_t *ctx, uint8_t reg, uint8_t tx_data );
284 
300 err_t magneto10_mem_write_multiple ( magneto10_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
301 
316 err_t magneto10_mem_direct_read ( magneto10_t *ctx, uint8_t *rx_buf, uint8_t rx_len );
317 
333 err_t magneto10_mem_read ( magneto10_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
334 
348 
362 
378 err_t magneto10_get_magnetic_flux ( magneto10_t *ctx, float *x_axis, float *y_axis, float *z_axis );
379 
392 err_t magneto10_get_temperature ( magneto10_t *ctx, float *temperature );
393 
406 
420 err_t magneto10_set_operating_mode ( magneto10_t *ctx, uint8_t mode );
421 
435 err_t magneto10_enable_temperature_sensor ( magneto10_t *ctx, uint8_t enable );
436 
437 #ifdef __cplusplus
438 }
439 #endif
440 #endif // MAGNETO10_H
441  // magneto10
443 
444 // ------------------------------------------------------------------------ END
magneto10_enable_temperature_sensor
err_t magneto10_enable_temperature_sensor(magneto10_t *ctx, uint8_t enable)
Magneto 10 enable temperature sensor function.
magneto10_mem_direct_read
err_t magneto10_mem_direct_read(magneto10_t *ctx, uint8_t *rx_buf, uint8_t rx_len)
Magneto 10 mem direct read function.
magneto10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: magneto10.h:205
magneto10_mem_read
err_t magneto10_mem_read(magneto10_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Magneto 10 mem read function.
magneto10_check_communication
err_t magneto10_check_communication(magneto10_t *ctx)
Magneto 10 check communication function.
magneto10_check_data_ready
err_t magneto10_check_data_ready(magneto10_t *ctx)
Magneto 10 check data ready function.
magneto10_cfg_setup
void magneto10_cfg_setup(magneto10_cfg_t *cfg)
Magneto 10 configuration object setup function.
magneto10_t
Magneto 10 Click context object.
Definition: magneto10.h:187
magneto10_mem_write_multiple
err_t magneto10_mem_write_multiple(magneto10_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Magneto 10 mem write multiple function.
magneto10_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto10.h:206
magneto10_t::i2c
i2c_master_t i2c
Definition: magneto10.h:189
magneto10_init
err_t magneto10_init(magneto10_t *ctx, magneto10_cfg_t *cfg)
Magneto 10 initialization function.
magneto10_t::slave_address
uint8_t slave_address
Definition: magneto10.h:192
magneto10_get_temperature
err_t magneto10_get_temperature(magneto10_t *ctx, float *temperature)
Magneto 10 get temperature function.
magneto10_set_operating_mode
err_t magneto10_set_operating_mode(magneto10_t *ctx, uint8_t mode)
Magneto 10 set operating mode function.
magneto10_cfg_t
Magneto 10 Click configuration object.
Definition: magneto10.h:201
magneto10_cfg_t::sda
pin_name_t sda
Definition: magneto10.h:203
magneto10_get_magnetic_flux
err_t magneto10_get_magnetic_flux(magneto10_t *ctx, float *x_axis, float *y_axis, float *z_axis)
Magneto 10 get magnetic flux function.
MAGNETO10_OK
@ MAGNETO10_OK
Definition: magneto10.h:216
magneto10_mem_write_single
err_t magneto10_mem_write_single(magneto10_t *ctx, uint8_t reg, uint8_t tx_data)
Magneto 10 mem write single function.
magneto10_default_cfg
err_t magneto10_default_cfg(magneto10_t *ctx)
Magneto 10 default configuration function.
magneto10_return_value_t
magneto10_return_value_t
Magneto 10 Click return value data.
Definition: magneto10.h:215
magneto10_cfg_t::scl
pin_name_t scl
Definition: magneto10.h:202
MAGNETO10_ERROR
@ MAGNETO10_ERROR
Definition: magneto10.h:217
magneto10_reset
err_t magneto10_reset(magneto10_t *ctx)
Magneto 10 reset function.