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 
41 #ifdef PREINIT_SUPPORTED
42 #include "preinit.h"
43 #endif
44 
45 #ifdef MikroCCoreVersion
46  #if MikroCCoreVersion >= 1
47  #include "delays.h"
48  #endif
49 #endif
50 
51 #include "drv_digital_out.h"
52 #include "drv_digital_in.h"
53 #include "drv_analog_in.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define POLLUTION_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.ena = MIKROBUS( mikrobus, MIKROBUS_RST )
68 
74 #define POLLUTION_RETVAL uint8_t
75 
76 #define POLLUTION_OK 0x00
77 #define POLLUTION_INIT_ERROR 0xFF
78  // End group macro
81 
82 // --------------------------------------------------------------- PUBLIC TYPES
91 typedef uint16_t pollution_data_t;
92 
96 typedef struct
97 {
98  // Output pins
99 
100  digital_out_t ena;
101 
102  // Modules
103 
104  analog_in_t adc;
105 
106 } pollution_t;
107 
111 typedef struct
112 {
113  // Communication gpio pins
114 
115  pin_name_t an_pin;
116 
117  // Additional gpio pins
118 
119  pin_name_t ena;
120 
121  // Static variable
122 
123  analog_in_resolution_t resolution; // Resolution
124  float vref; // VRef
125 
127  // End types group
129 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
135 #ifdef __cplusplus
136 extern "C"{
137 #endif
138 
148 
158 
177 
187 
197 
207 
222 
233 
244 
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 #endif // _POLLUTION_H_
260  // End public_function group
263 
264 // ------------------------------------------------------------------------ END
pollution_data_t
uint16_t pollution_data_t
Analog data type.
Definition: pollution.h:91
pollution_cfg_t::ena
pin_name_t ena
Definition: pollution.h:119
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:100
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:112
pollution_cfg_t::an_pin
pin_name_t an_pin
Definition: pollution.h:115
pollution_t::adc
analog_in_t adc
Definition: pollution.h:104
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:123
pollution_cfg_t::vref
float vref
Definition: pollution.h:124
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:97
POLLUTION_RETVAL
#define POLLUTION_RETVAL
Definition: pollution.h:74
pollution_cfg_setup
void pollution_cfg_setup(pollution_cfg_t *cfg)
Config Object Initialization function.