magneto9  2.0.0.0
magneto9.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 MAGNETO9_H
29 #define MAGNETO9_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 
75 #define MAGNETO9_SET_DEV_ADDR 0x4D
76 
81 #define MAGNETO9_ADC_RESOLUTION 0x0FFF
82 #define MAGNETO9_VREF_5V 5.0
83 
88 #define MAGNETO9_QUIESCENT_VOUT 2.5
89 #define MAGNETO9_AN_SENSITIVITY_V_PER_G 0.009
90 #define MAGNETO9_GAUSS_TO_MILITESLA 0.1
91 
99 #define MAGNETO9_VOLTAGE_TO_FIELD_STRENGTH( voltage ) ( ( ( voltage - MAGNETO9_QUIESCENT_VOUT ) / \
100  MAGNETO9_AN_SENSITIVITY_V_PER_G ) * \
101  MAGNETO9_GAUSS_TO_MILITESLA )
102  // magneto9_set
104 
119 #define MAGNETO9_MAP_MIKROBUS( cfg, mikrobus ) \
120  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
121  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
124  // magneto9_map // magneto9
127 
132 typedef struct
133 {
134  digital_in_t pwm;
136  analog_in_t adc;
137  i2c_master_t i2c;
139  uint8_t slave_address;
141 } magneto9_t;
142 
147 typedef struct
148 {
149  pin_name_t an;
150  pin_name_t pwm;
151  pin_name_t scl;
152  pin_name_t sda;
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
157  analog_in_resolution_t resolution;
158  float vref;
161 
166 typedef enum
167 {
169  MAGNETO9_ERROR = -1
170 
172 
189 
205 
218 err_t magneto9_read_an_pin_value ( magneto9_t *ctx, uint16_t *data_out );
219 
234 err_t magneto9_read_an_pin_voltage ( magneto9_t *ctx, float *data_out );
235 
248 err_t magneto9_read_raw_adc ( magneto9_t *ctx, uint16_t *raw_adc );
249 
263 err_t magneto9_read_adc_voltage ( magneto9_t *ctx, float *voltage );
264 
274 
275 #ifdef __cplusplus
276 }
277 #endif
278 #endif // MAGNETO9_H
279  // magneto9
281 
282 // ------------------------------------------------------------------------ END
magneto9_t::adc
analog_in_t adc
Definition: magneto9.h:136
magneto9_init
err_t magneto9_init(magneto9_t *ctx, magneto9_cfg_t *cfg)
Magneto 9 initialization function.
magneto9_return_value_t
magneto9_return_value_t
Magneto 9 Click return value data.
Definition: magneto9.h:167
magneto9_t::slave_address
uint8_t slave_address
Definition: magneto9.h:139
magneto9_cfg_t::sda
pin_name_t sda
Definition: magneto9.h:152
MAGNETO9_OK
@ MAGNETO9_OK
Definition: magneto9.h:168
magneto9_get_pwm_pin
uint8_t magneto9_get_pwm_pin(magneto9_t *ctx)
Magneto 9 get PWM pin function.
MAGNETO9_ERROR
@ MAGNETO9_ERROR
Definition: magneto9.h:169
magneto9_read_raw_adc
err_t magneto9_read_raw_adc(magneto9_t *ctx, uint16_t *raw_adc)
Magneto 9 read raw ADC function.
magneto9_cfg_setup
void magneto9_cfg_setup(magneto9_cfg_t *cfg)
Magneto 9 configuration object setup function.
magneto9_cfg_t::vref
float vref
Definition: magneto9.h:158
magneto9_cfg_t::pwm
pin_name_t pwm
Definition: magneto9.h:150
magneto9_read_an_pin_voltage
err_t magneto9_read_an_pin_voltage(magneto9_t *ctx, float *data_out)
Magneto 9 read AN pin voltage level function.
magneto9_cfg_t::scl
pin_name_t scl
Definition: magneto9.h:151
magneto9_t::pwm
digital_in_t pwm
Definition: magneto9.h:134
magneto9_cfg_t
Magneto 9 Click configuration object.
Definition: magneto9.h:148
magneto9_read_an_pin_value
err_t magneto9_read_an_pin_value(magneto9_t *ctx, uint16_t *data_out)
Magneto 9 read AN pin value function.
magneto9_cfg_t::i2c_address
uint8_t i2c_address
Definition: magneto9.h:155
magneto9_cfg_t::resolution
analog_in_resolution_t resolution
Definition: magneto9.h:157
magneto9_read_adc_voltage
err_t magneto9_read_adc_voltage(magneto9_t *ctx, float *voltage)
Magneto 9 read ADC voltage function.
magneto9_t
Magneto 9 Click context object.
Definition: magneto9.h:133
magneto9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: magneto9.h:154
magneto9_t::i2c
i2c_master_t i2c
Definition: magneto9.h:137
magneto9_cfg_t::an
pin_name_t an
Definition: magneto9.h:149