shtan  2.0.0.0
shtan.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  */
34 #ifndef SHTAN_H
35 #define SHTAN_H
36 
37 #include "drv_digital_out.h"
38 #include "drv_digital_in.h"
39 #include "drv_analog_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
42 
52 #define SHTAN_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
54  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
55  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
56 
62 #define SHTAN_RETVAL uint8_t
63 
64 #define SHTAN_OK 0x00
65 #define SHTAN_INIT_ERROR 0xFF
66 
72 #define SHTAN_SET_ADC_MODE_TEMP 0
73 #define SHTAN_SET_ADC_MODE_HUM 1
74 
75 #define SHTAN_V_REF_2_048_mV 2.048
76 #define SHTAN_V_REF_3_0_mV 3.0
77 #define SHTAN_V_REF_3_3_mV 3.3
78 
79 #define SHTAN_V_DD_3_3_mV 3.3
80 #define SHTAN_V_DD_5_0_mV 5.0
81 
82 #define SHTAN_ADC_RES_10_BIT 1024.0
83 #define SHTAN_ADC_RES_12_BIT 4096.0
84 #define SHTAN_ADC_RES_14_BIT 16383.0
85  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef uint16_t shtan_data_t;
97 
101 typedef struct
102 {
103  // Output pins
104 
105  digital_out_t rst;
106  digital_out_t cs;
107 
108  // Modules
109 
110  analog_in_t adc;
111 
112 } shtan_t;
113 
117 typedef struct
118 {
119  // Communication gpio pins
120 
121  pin_name_t an_pin;
122 
123  // Additional gpio pins
124 
125  pin_name_t rst;
126  pin_name_t cs;
127 
128  // static variable
129 
130  analog_in_resolution_t resolution; // Resolution
131  float vref; // VRef
132 
133 } shtan_cfg_t;
134  // End types group
136 
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
144 #ifdef __cplusplus
145 extern "C"{
146 #endif
147 
156 void shtan_cfg_setup ( shtan_cfg_t *cfg );
157 
167 
175 void shtan_default_cfg ( shtan_t *ctx );
176 
186 
200 void shtan_set_mode ( shtan_t *ctx, uint8_t adc_mode );
201 
214 void shtan_reset ( shtan_t *ctx );
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 #endif // _SHTAN_H_
220  // End public_function group
223 
224 // ------------------------------------------------------------------------ END
void shtan_cfg_setup(shtan_cfg_t *cfg)
Config Object Initialization function.
pin_name_t an_pin
Definition: shtan.h:121
pin_name_t cs
Definition: shtan.h:126
#define SHTAN_RETVAL
Definition: shtan.h:62
uint8_t adc_mode
Definition: main.c:36
uint16_t shtan_data_t
Analog data type.
Definition: shtan.h:96
pin_name_t rst
Definition: shtan.h:125
analog_in_t adc
Definition: shtan.h:110
analog_in_resolution_t resolution
Definition: shtan.h:130
Click configuration structure definition.
Definition: shtan.h:117
void shtan_set_mode(shtan_t *ctx, uint8_t adc_mode)
Set ADC mode function.
SHTAN_RETVAL shtan_init(shtan_t *ctx, shtan_cfg_t *cfg)
Initialization function.
float vref
Definition: shtan.h:131
digital_out_t cs
Definition: shtan.h:106
Click ctx object definition.
Definition: shtan.h:101
digital_out_t rst
Definition: shtan.h:105
shtan_data_t shtan_generic_read(shtan_t *ctx)
Generic read function.
void shtan_default_cfg(shtan_t *ctx)
Click Default Configuration function.
void shtan_reset(shtan_t *ctx)
Hardware reset function.