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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_analog_in.h"
38 #include "drv_i2c_master.h"
39 
60 #define MAGNETO12_ADC_RESOLUTION 0x0FFF
61 #define MAGNETO12_VREF_5V 5.0
62 #define MAGNETO12_FULL_CIRCLE 360.0
63 #define MAGNETO12_SATURATION_ERROR 0.04
64 
70 #define MAGNETO12_SET_DEV_ADDR 0x4D
71  // magneto12_set
73 
88 #define MAGNETO12_MAP_MIKROBUS( cfg, mikrobus ) \
89  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
90  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
91  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
92  // magneto12_map // magneto12
95 
100 typedef enum
101 {
106 
111 typedef struct
112 {
113  analog_in_t adc;
114  i2c_master_t i2c;
116  uint8_t slave_address;
117  pin_name_t chip_select;
118  float vref;
121 } magneto12_t;
122 
127 typedef struct
128 {
129  pin_name_t an;
130  pin_name_t scl;
131  pin_name_t sda;
133  analog_in_resolution_t resolution;
134  float vref;
136  uint32_t i2c_speed;
137  uint8_t i2c_address;
142 
147 typedef enum
148 {
150  MAGNETO12_ERROR = -1
151 
153 
170 
186 
202 
215 err_t magneto12_read_raw_adc ( magneto12_t *ctx, uint16_t *raw_adc );
216 
229 err_t magneto12_read_voltage ( magneto12_t *ctx, float *voltage );
230 
243 err_t magneto12_set_vref ( magneto12_t *ctx, float vref );
244 
257 err_t magneto12_read_angle ( magneto12_t *ctx, float *angle );
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 #endif // MAGNETO12_H
263  // magneto12
265 
266 // ------------------------------------------------------------------------ END
magneto12_cfg_t::sda
pin_name_t sda
Definition: magneto12.h:131
magneto12_return_value_t
magneto12_return_value_t
Magneto 12 Click return value data.
Definition: magneto12.h:148
MAGNETO12_ERROR
@ MAGNETO12_ERROR
Definition: magneto12.h:150
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:103
magneto12_t::drv_sel
magneto12_drv_t drv_sel
Definition: magneto12.h:119
magneto12_cfg_t::scl
pin_name_t scl
Definition: magneto12.h:130
magneto12_t::i2c
i2c_master_t i2c
Definition: magneto12.h:114
magneto12_t
Magneto 12 Click context object.
Definition: magneto12.h:112
magneto12_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto12.h:137
MAGNETO12_DRV_SEL_ADC
@ MAGNETO12_DRV_SEL_ADC
Definition: magneto12.h:102
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:129
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:101
magneto12_cfg_t::resolution
analog_in_resolution_t resolution
Definition: magneto12.h:133
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:139
magneto12_t::adc
analog_in_t adc
Definition: magneto12.h:113
magneto12_t::slave_address
uint8_t slave_address
Definition: magneto12.h:116
magneto12_cfg_t
Magneto 12 Click configuration object.
Definition: magneto12.h:128
MAGNETO12_OK
@ MAGNETO12_OK
Definition: magneto12.h:149
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:134
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:136
magneto12_t::vref
float vref
Definition: magneto12.h:118
magneto12_t::chip_select
pin_name_t chip_select
Definition: magneto12.h:117