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 "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_analog_in.h"
48 #include "drv_i2c_master.h"
49 
70 #define MAGNETO12_ADC_RESOLUTION 0x0FFF
71 #define MAGNETO12_VREF_5V 5.0
72 #define MAGNETO12_FULL_CIRCLE 360.0
73 #define MAGNETO12_SATURATION_ERROR 0.04
74 
80 #define MAGNETO12_SET_DEV_ADDR 0x4D
81  // magneto12_set
83 
98 #define MAGNETO12_MAP_MIKROBUS( cfg, mikrobus ) \
99  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
100  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
101  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
102  // magneto12_map // magneto12
105 
110 typedef enum
111 {
116 
121 typedef struct
122 {
123  analog_in_t adc;
124  i2c_master_t i2c;
126  uint8_t slave_address;
127  pin_name_t chip_select;
128  float vref;
131 } magneto12_t;
132 
137 typedef struct
138 {
139  pin_name_t an;
140  pin_name_t scl;
141  pin_name_t sda;
143  analog_in_resolution_t resolution;
144  float vref;
146  uint32_t i2c_speed;
147  uint8_t i2c_address;
152 
157 typedef enum
158 {
160  MAGNETO12_ERROR = -1
161 
163 
180 
196 
212 
225 err_t magneto12_read_raw_adc ( magneto12_t *ctx, uint16_t *raw_adc );
226 
239 err_t magneto12_read_voltage ( magneto12_t *ctx, float *voltage );
240 
253 err_t magneto12_set_vref ( magneto12_t *ctx, float vref );
254 
267 err_t magneto12_read_angle ( magneto12_t *ctx, float *angle );
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 #endif // MAGNETO12_H
273  // magneto12
275 
276 // ------------------------------------------------------------------------ END
magneto12_cfg_t::sda
pin_name_t sda
Definition: magneto12.h:141
magneto12_return_value_t
magneto12_return_value_t
Magneto 12 Click return value data.
Definition: magneto12.h:158
MAGNETO12_ERROR
@ MAGNETO12_ERROR
Definition: magneto12.h:160
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:113
magneto12_t::drv_sel
magneto12_drv_t drv_sel
Definition: magneto12.h:129
magneto12_cfg_t::scl
pin_name_t scl
Definition: magneto12.h:140
magneto12_t::i2c
i2c_master_t i2c
Definition: magneto12.h:124
magneto12_t
Magneto 12 Click context object.
Definition: magneto12.h:122
magneto12_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto12.h:147
MAGNETO12_DRV_SEL_ADC
@ MAGNETO12_DRV_SEL_ADC
Definition: magneto12.h:112
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:139
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:111
magneto12_cfg_t::resolution
analog_in_resolution_t resolution
Definition: magneto12.h:143
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:149
magneto12_t::adc
analog_in_t adc
Definition: magneto12.h:123
magneto12_t::slave_address
uint8_t slave_address
Definition: magneto12.h:126
magneto12_cfg_t
Magneto 12 Click configuration object.
Definition: magneto12.h:138
MAGNETO12_OK
@ MAGNETO12_OK
Definition: magneto12.h:159
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:144
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:146
magneto12_t::vref
float vref
Definition: magneto12.h:128
magneto12_t::chip_select
pin_name_t chip_select
Definition: magneto12.h:127