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 
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 
71 #define MAGNETO9_SET_DEV_ADDR 0x4D
72 
77 #define MAGNETO9_ADC_RESOLUTION 0x0FFF
78 #define MAGNETO9_VREF_5V 5.0
79 
84 #define MAGNETO9_QUIESCENT_VOUT 2.5
85 #define MAGNETO9_AN_SENSITIVITY_V_PER_G 0.009
86 #define MAGNETO9_GAUSS_TO_MILITESLA 0.1
87 
95 #define MAGNETO9_VOLTAGE_TO_FIELD_STRENGTH( voltage ) ( ( ( voltage - MAGNETO9_QUIESCENT_VOUT ) / \
96  MAGNETO9_AN_SENSITIVITY_V_PER_G ) * \
97  MAGNETO9_GAUSS_TO_MILITESLA )
98  // magneto9_set
100 
115 #define MAGNETO9_MAP_MIKROBUS( cfg, mikrobus ) \
116  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
117  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
118  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
119  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
120  // magneto9_map // magneto9
123 
128 typedef struct
129 {
130  digital_in_t pwm;
132  analog_in_t adc;
133  i2c_master_t i2c;
135  uint8_t slave_address;
137 } magneto9_t;
138 
143 typedef struct
144 {
145  pin_name_t an;
146  pin_name_t pwm;
147  pin_name_t scl;
148  pin_name_t sda;
150  uint32_t i2c_speed;
151  uint8_t i2c_address;
153  analog_in_resolution_t resolution;
154  float vref;
157 
162 typedef enum
163 {
165  MAGNETO9_ERROR = -1
166 
168 
185 
201 
214 err_t magneto9_read_an_pin_value ( magneto9_t *ctx, uint16_t *data_out );
215 
230 err_t magneto9_read_an_pin_voltage ( magneto9_t *ctx, float *data_out );
231 
244 err_t magneto9_read_raw_adc ( magneto9_t *ctx, uint16_t *raw_adc );
245 
259 err_t magneto9_read_adc_voltage ( magneto9_t *ctx, float *voltage );
260 
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 #endif // MAGNETO9_H
275  // magneto9
277 
278 // ------------------------------------------------------------------------ END
magneto9_t::adc
analog_in_t adc
Definition: magneto9.h:132
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:163
magneto9_t::slave_address
uint8_t slave_address
Definition: magneto9.h:135
magneto9_cfg_t::sda
pin_name_t sda
Definition: magneto9.h:148
MAGNETO9_OK
@ MAGNETO9_OK
Definition: magneto9.h:164
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:165
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:154
magneto9_cfg_t::pwm
pin_name_t pwm
Definition: magneto9.h:146
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:147
magneto9_t::pwm
digital_in_t pwm
Definition: magneto9.h:130
magneto9_cfg_t
Magneto 9 Click configuration object.
Definition: magneto9.h:144
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:151
magneto9_cfg_t::resolution
analog_in_resolution_t resolution
Definition: magneto9.h:153
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:129
magneto9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: magneto9.h:150
magneto9_t::i2c
i2c_master_t i2c
Definition: magneto9.h:133
magneto9_cfg_t::an
pin_name_t an
Definition: magneto9.h:145