magneto12  2.0.0.0
magneto12.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 MAGNETO12_H
29 #define MAGNETO12_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_analog_in.h"
52 #include "drv_i2c_master.h"
53 
74 #define MAGNETO12_ADC_RESOLUTION 0x0FFF
75 #define MAGNETO12_VREF_5V 5.0
76 #define MAGNETO12_FULL_CIRCLE 360.0
77 #define MAGNETO12_SATURATION_ERROR 0.04
78 
84 #define MAGNETO12_SET_DEV_ADDR 0x4D
85  // magneto12_set
87 
102 #define MAGNETO12_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
104  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
105  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
106  // magneto12_map // magneto12
109 
114 typedef enum
115 {
120 
125 typedef struct
126 {
127  analog_in_t adc;
128  i2c_master_t i2c;
130  uint8_t slave_address;
131  pin_name_t chip_select;
132  float vref;
135 } magneto12_t;
136 
141 typedef struct
142 {
143  pin_name_t an;
144  pin_name_t scl;
145  pin_name_t sda;
147  analog_in_resolution_t resolution;
148  float vref;
150  uint32_t i2c_speed;
151  uint8_t i2c_address;
156 
161 typedef enum
162 {
164  MAGNETO12_ERROR = -1
165 
167 
184 
200 
216 
229 err_t magneto12_read_raw_adc ( magneto12_t *ctx, uint16_t *raw_adc );
230 
243 err_t magneto12_read_voltage ( magneto12_t *ctx, float *voltage );
244 
257 err_t magneto12_set_vref ( magneto12_t *ctx, float vref );
258 
271 err_t magneto12_read_angle ( magneto12_t *ctx, float *angle );
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 #endif // MAGNETO12_H
277  // magneto12
279 
280 // ------------------------------------------------------------------------ END
magneto12_cfg_t::sda
pin_name_t sda
Definition: magneto12.h:145
magneto12_return_value_t
magneto12_return_value_t
Magneto 12 Click return value data.
Definition: magneto12.h:162
MAGNETO12_ERROR
@ MAGNETO12_ERROR
Definition: magneto12.h:164
magneto12_read_voltage
err_t magneto12_read_voltage(magneto12_t *ctx, float *voltage)
Magneto 12 read voltage level function.
MAGNETO12_DRV_SEL_I2C
@ MAGNETO12_DRV_SEL_I2C
Definition: magneto12.h:117
magneto12_t::drv_sel
magneto12_drv_t drv_sel
Definition: magneto12.h:133
magneto12_cfg_t::scl
pin_name_t scl
Definition: magneto12.h:144
magneto12_t::i2c
i2c_master_t i2c
Definition: magneto12.h:128
magneto12_t
Magneto 12 Click context object.
Definition: magneto12.h:126
magneto12_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto12.h:151
MAGNETO12_DRV_SEL_ADC
@ MAGNETO12_DRV_SEL_ADC
Definition: magneto12.h:116
magneto12_init
err_t magneto12_init(magneto12_t *ctx, magneto12_cfg_t *cfg)
Magneto 12 initialization function.
magneto12_cfg_t::an
pin_name_t an
Definition: magneto12.h:143
magneto12_set_vref
err_t magneto12_set_vref(magneto12_t *ctx, float vref)
Magneto 12 set vref function.
magneto12_drv_t
magneto12_drv_t
Magneto 12 Click driver selector.
Definition: magneto12.h:115
magneto12_cfg_t::resolution
analog_in_resolution_t resolution
Definition: magneto12.h:147
magneto12_read_angle
err_t magneto12_read_angle(magneto12_t *ctx, float *angle)
Magneto 12 read angle function.
magneto12_cfg_t::drv_sel
magneto12_drv_t drv_sel
Definition: magneto12.h:153
magneto12_t::adc
analog_in_t adc
Definition: magneto12.h:127
magneto12_t::slave_address
uint8_t slave_address
Definition: magneto12.h:130
magneto12_cfg_t
Magneto 12 Click configuration object.
Definition: magneto12.h:142
MAGNETO12_OK
@ MAGNETO12_OK
Definition: magneto12.h:163
magneto12_read_raw_adc
err_t magneto12_read_raw_adc(magneto12_t *ctx, uint16_t *raw_adc)
Magneto 12 read raw ADC value function.
magneto12_cfg_t::vref
float vref
Definition: magneto12.h:148
magneto12_cfg_setup
void magneto12_cfg_setup(magneto12_cfg_t *cfg)
Magneto 12 configuration object setup function.
magneto12_drv_interface_selection
void magneto12_drv_interface_selection(magneto12_cfg_t *cfg, magneto12_drv_t drv_sel)
Magneto 12 driver interface setup function.
magneto12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: magneto12.h:150
magneto12_t::vref
float vref
Definition: magneto12.h:132
magneto12_t::chip_select
pin_name_t chip_select
Definition: magneto12.h:131