pollution  2.0.0.0
pollution.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
34 #ifndef POLLUTION_H
35 #define POLLUTION_H
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_analog_in.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define POLLUTION_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
63  cfg.ena = MIKROBUS( mikrobus, MIKROBUS_RST )
64 
70 #define POLLUTION_RETVAL uint8_t
71 
72 #define POLLUTION_OK 0x00
73 #define POLLUTION_INIT_ERROR 0xFF
74  // End group macro
77 
78 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef uint16_t pollution_data_t;
88 
92 typedef struct
93 {
94  // Output pins
95 
96  digital_out_t ena;
97 
98  // Modules
99 
100  analog_in_t adc;
101 
102 } pollution_t;
103 
107 typedef struct
108 {
109  // Communication gpio pins
110 
111  pin_name_t an_pin;
112 
113  // Additional gpio pins
114 
115  pin_name_t ena;
116 
117  // Static variable
118 
119  analog_in_resolution_t resolution; // Resolution
120  float vref; // VRef
121 
123  // End types group
125 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
131 #ifdef __cplusplus
132 extern "C"{
133 #endif
134 
144 
154 
173 
183 
193 
203 
218 
229 
240 
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // _POLLUTION_H_
256  // End public_function group
259 
260 // ------------------------------------------------------------------------ END
pollution_data_t
uint16_t pollution_data_t
Analog data type.
Definition: pollution.h:87
pollution_cfg_t::ena
pin_name_t ena
Definition: pollution.h:115
pollution_default_cfg
void pollution_default_cfg(pollution_t *ctx)
Click Default Configuration function.
pollution_get_corrected_resistance
float pollution_get_corrected_resistance(pollution_t *ctx)
Get the corrected resistance of the sensor function.
pollution_t::ena
digital_out_t ena
Definition: pollution.h:96
pollution_get_resistance
float pollution_get_resistance(pollution_t *ctx)
Get the resistance of the sensor function.
pollution_cfg_t
Click configuration structure definition.
Definition: pollution.h:108
pollution_cfg_t::an_pin
pin_name_t an_pin
Definition: pollution.h:111
pollution_t::adc
analog_in_t adc
Definition: pollution.h:100
pollution_init
POLLUTION_RETVAL pollution_init(pollution_t *ctx, pollution_cfg_t *cfg)
Initialization function.
pollution_disable
void pollution_disable(pollution_t *ctx)
Disable sensor function.
pollution_measure_load_voltage
float pollution_measure_load_voltage(pollution_t *ctx)
Measure load voltage form ADC function.
pollution_reset
void pollution_reset(pollution_t *ctx)
Reset sensor function.
pollution_cfg_t::resolution
analog_in_resolution_t resolution
Definition: pollution.h:119
pollution_cfg_t::vref
float vref
Definition: pollution.h:120
pollution_generic_read
pollution_data_t pollution_generic_read(pollution_t *ctx)
Generic read function.
pollution_enable
void pollution_enable(pollution_t *ctx)
Enable sensor function.
pollution_t
Click ctx object definition.
Definition: pollution.h:93
POLLUTION_RETVAL
#define POLLUTION_RETVAL
Definition: pollution.h:70
pollution_cfg_setup
void pollution_cfg_setup(pollution_cfg_t *cfg)
Config Object Initialization function.