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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_analog_in.h"
38 #include "drv_i2c_master.h"
39 
61 #define MAGNETO9_SET_DEV_ADDR 0x4D
62 
67 #define MAGNETO9_ADC_RESOLUTION 0x0FFF
68 #define MAGNETO9_VREF_5V 5.0
69 
74 #define MAGNETO9_QUIESCENT_VOUT 2.5
75 #define MAGNETO9_AN_SENSITIVITY_V_PER_G 0.009
76 #define MAGNETO9_GAUSS_TO_MILITESLA 0.1
77 
85 #define MAGNETO9_VOLTAGE_TO_FIELD_STRENGTH( voltage ) ( ( ( voltage - MAGNETO9_QUIESCENT_VOUT ) / \
86  MAGNETO9_AN_SENSITIVITY_V_PER_G ) * \
87  MAGNETO9_GAUSS_TO_MILITESLA )
88  // magneto9_set
90 
105 #define MAGNETO9_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
107  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
108  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
109  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
110  // magneto9_map // magneto9
113 
118 typedef struct
119 {
120  digital_in_t pwm;
122  analog_in_t adc;
123  i2c_master_t i2c;
125  uint8_t slave_address;
127 } magneto9_t;
128 
133 typedef struct
134 {
135  pin_name_t an;
136  pin_name_t pwm;
137  pin_name_t scl;
138  pin_name_t sda;
140  uint32_t i2c_speed;
141  uint8_t i2c_address;
143  analog_in_resolution_t resolution;
144  float vref;
147 
152 typedef enum
153 {
155  MAGNETO9_ERROR = -1
156 
158 
174 void magneto9_cfg_setup ( magneto9_cfg_t *cfg );
175 
190 err_t magneto9_init ( magneto9_t *ctx, magneto9_cfg_t *cfg );
191 
204 err_t magneto9_read_an_pin_value ( magneto9_t *ctx, uint16_t *data_out );
205 
220 err_t magneto9_read_an_pin_voltage ( magneto9_t *ctx, float *data_out );
221 
234 err_t magneto9_read_raw_adc ( magneto9_t *ctx, uint16_t *raw_adc );
235 
249 err_t magneto9_read_adc_voltage ( magneto9_t *ctx, float *voltage );
250 
259 uint8_t magneto9_get_pwm_pin ( magneto9_t *ctx );
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // MAGNETO9_H
265  // magneto9
267 
268 // ------------------------------------------------------------------------ END
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:151
MAGNETO9_OK
Definition: magneto9.h:153
magneto9_get_pwm_pin
uint8_t magneto9_get_pwm_pin(magneto9_t *ctx)
Magneto 9 get PWM pin function.
MAGNETO9_ERROR
Definition: magneto9.h:154
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_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
Magneto 9 Click configuration object.
Definition: magneto9.h:132
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_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:117