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
32extern "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
86 // 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
107 // magneto12_map
108 // magneto12
109
120
125typedef struct
126{
127 analog_in_t adc;
128 i2c_master_t i2c;
131 pin_name_t chip_select;
132 float vref;
136
141typedef 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
167
184
200
216
229err_t magneto12_read_raw_adc ( magneto12_t *ctx, uint16_t *raw_adc );
230
243err_t magneto12_read_voltage ( magneto12_t *ctx, float *voltage );
244
257err_t magneto12_set_vref ( magneto12_t *ctx, float vref );
258
271err_t magneto12_read_angle ( magneto12_t *ctx, float *angle );
272
273#ifdef __cplusplus
274}
275#endif
276#endif // MAGNETO12_H
277
278 // magneto12
279
280// ------------------------------------------------------------------------ END
void magneto12_drv_interface_selection(magneto12_cfg_t *cfg, magneto12_drv_t drv_sel)
Magneto 12 driver interface setup function.
err_t magneto12_read_raw_adc(magneto12_t *ctx, uint16_t *raw_adc)
Magneto 12 read raw ADC value function.
err_t magneto12_init(magneto12_t *ctx, magneto12_cfg_t *cfg)
Magneto 12 initialization function.
err_t magneto12_set_vref(magneto12_t *ctx, float vref)
Magneto 12 set vref function.
err_t magneto12_read_voltage(magneto12_t *ctx, float *voltage)
Magneto 12 read voltage level function.
void magneto12_cfg_setup(magneto12_cfg_t *cfg)
Magneto 12 configuration object setup function.
err_t magneto12_read_angle(magneto12_t *ctx, float *angle)
Magneto 12 read angle function.
magneto12_return_value_t
Magneto 12 Click return value data.
Definition magneto12.h:162
@ MAGNETO12_ERROR
Definition magneto12.h:164
@ MAGNETO12_OK
Definition magneto12.h:163
magneto12_drv_t
Magneto 12 Click driver selector.
Definition magneto12.h:115
@ MAGNETO12_DRV_SEL_ADC
Definition magneto12.h:116
@ MAGNETO12_DRV_SEL_I2C
Definition magneto12.h:117
Magneto 12 Click configuration object.
Definition magneto12.h:142
analog_in_resolution_t resolution
Definition magneto12.h:147
float vref
Definition magneto12.h:148
uint32_t i2c_speed
Definition magneto12.h:150
magneto12_drv_t drv_sel
Definition magneto12.h:153
pin_name_t scl
Definition magneto12.h:144
pin_name_t sda
Definition magneto12.h:145
pin_name_t an
Definition magneto12.h:143
uint8_t i2c_address
Definition magneto12.h:151
Magneto 12 Click context object.
Definition magneto12.h:126
float vref
Definition magneto12.h:132
i2c_master_t i2c
Definition magneto12.h:128
magneto12_drv_t drv_sel
Definition magneto12.h:133
uint8_t slave_address
Definition magneto12.h:130
pin_name_t chip_select
Definition magneto12.h:131
analog_in_t adc
Definition magneto12.h:127