lighthz  2.1.0.0
lighthz.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 LIGHTHZ_H
29 #define LIGHTHZ_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 
72 #define LIGHTHZ_PIN_STATE_LOW 0
73 #define LIGHTHZ_PIN_STATE_HIGH 1
74 
79 #define LIGHTHZ_SENS_POWER_DOWN 0
80 #define LIGHTHZ_SENS_1X 1
81 #define LIGHTHZ_SENS_10X 2
82 #define LIGHTHZ_SENS_100X 3
83 
88 #define LIGHTHZ_FSCALE_1 0
89 #define LIGHTHZ_FSCALE_2 1
90 #define LIGHTHZ_FSCALE_10 2
91 #define LIGHTHZ_FSCALE_100 3
92 
97 #define LIGHTHZ_DELAY_US 10
98 #define LIGHTHZ_MAX_COUNTS_PER_S 100000ul
99 #define LIGHTHZ_SAMPLE_COUNTS 100
100  // lighthz_set
102 
117 #define LIGHTHZ_MAP_MIKROBUS( cfg, mikrobus ) \
118  cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
119  cfg.s3 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
120  cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
121  cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
122  cfg.freq = MIKROBUS( mikrobus, MIKROBUS_INT )
123  // lighthz_map // lighthz
126 
131 typedef struct
132 {
133  digital_out_t s1;
134  digital_out_t s3;
135  digital_out_t s2;
136  digital_out_t s0;
138  digital_in_t freq;
140 } lighthz_t;
141 
146 typedef struct
147 {
148  pin_name_t s1;
149  pin_name_t s3;
150  pin_name_t s2;
151  pin_name_t s0;
152  pin_name_t freq;
154 } lighthz_cfg_t;
155 
160 typedef enum
161 {
163  LIGHTHZ_ERROR = -1
164 
166 
183 
197 err_t lighthz_init ( lighthz_t *ctx, lighthz_cfg_t *cfg );
198 
209 void lighthz_set_s0_pin ( lighthz_t *ctx, uint8_t state );
210 
221 void lighthz_set_s1_pin ( lighthz_t *ctx, uint8_t state );
222 
233 void lighthz_set_s2_pin ( lighthz_t *ctx, uint8_t state );
234 
245 void lighthz_set_s3_pin ( lighthz_t *ctx, uint8_t state );
246 
259 void lighthz_set_sensitivity ( lighthz_t *ctx, uint8_t mode );
260 
273 void lighthz_set_frequency_scaling ( lighthz_t *ctx, uint8_t mode );
274 
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 #endif // LIGHTHZ_H
289  // lighthz
291 
292 // ------------------------------------------------------------------------ END
lighthz_t::freq
digital_in_t freq
Definition: lighthz.h:138
lighthz_t
LightHz Click context object.
Definition: lighthz.h:132
LIGHTHZ_ERROR
@ LIGHTHZ_ERROR
Definition: lighthz.h:163
lighthz_cfg_setup
void lighthz_cfg_setup(lighthz_cfg_t *cfg)
LightHz configuration object setup function.
lighthz_cfg_t::s1
pin_name_t s1
Definition: lighthz.h:148
lighthz_t::s3
digital_out_t s3
Definition: lighthz.h:134
lighthz_set_s3_pin
void lighthz_set_s3_pin(lighthz_t *ctx, uint8_t state)
LightHz set s3 pin function.
lighthz_return_value_t
lighthz_return_value_t
LightHz Click return value data.
Definition: lighthz.h:161
lighthz_t::s2
digital_out_t s2
Definition: lighthz.h:135
lighthz_get_freq_pin
uint8_t lighthz_get_freq_pin(lighthz_t *ctx)
LightHz get freq pin function.
LIGHTHZ_OK
@ LIGHTHZ_OK
Definition: lighthz.h:162
lighthz_t::s0
digital_out_t s0
Definition: lighthz.h:136
lighthz_cfg_t::s2
pin_name_t s2
Definition: lighthz.h:150
lighthz_set_s2_pin
void lighthz_set_s2_pin(lighthz_t *ctx, uint8_t state)
LightHz set s2 pin function.
lighthz_cfg_t::s3
pin_name_t s3
Definition: lighthz.h:149
lighthz_init
err_t lighthz_init(lighthz_t *ctx, lighthz_cfg_t *cfg)
LightHz initialization function.
lighthz_set_frequency_scaling
void lighthz_set_frequency_scaling(lighthz_t *ctx, uint8_t mode)
LightHz set frequency scaling function.
lighthz_cfg_t
LightHz Click configuration object.
Definition: lighthz.h:147
lighthz_set_s1_pin
void lighthz_set_s1_pin(lighthz_t *ctx, uint8_t state)
LightHz set s1 pin function.
lighthz_cfg_t::freq
pin_name_t freq
Definition: lighthz.h:152
lighthz_set_s0_pin
void lighthz_set_s0_pin(lighthz_t *ctx, uint8_t state)
LightHz set s0 pin function.
lighthz_t::s1
digital_out_t s1
Definition: lighthz.h:133
lighthz_set_sensitivity
void lighthz_set_sensitivity(lighthz_t *ctx, uint8_t mode)
LightHz set sensitivity function.
lighthz_cfg_t::s0
pin_name_t s0
Definition: lighthz.h:151