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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 
68 #define LIGHTHZ_PIN_STATE_LOW 0
69 #define LIGHTHZ_PIN_STATE_HIGH 1
70 
75 #define LIGHTHZ_SENS_POWER_DOWN 0
76 #define LIGHTHZ_SENS_1X 1
77 #define LIGHTHZ_SENS_10X 2
78 #define LIGHTHZ_SENS_100X 3
79 
84 #define LIGHTHZ_FSCALE_1 0
85 #define LIGHTHZ_FSCALE_2 1
86 #define LIGHTHZ_FSCALE_10 2
87 #define LIGHTHZ_FSCALE_100 3
88 
93 #define LIGHTHZ_DELAY_US 10
94 #define LIGHTHZ_MAX_COUNTS_PER_S 100000ul
95 #define LIGHTHZ_SAMPLE_COUNTS 100
96  // lighthz_set
98 
113 #define LIGHTHZ_MAP_MIKROBUS( cfg, mikrobus ) \
114  cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
115  cfg.s3 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
116  cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
117  cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
118  cfg.freq = MIKROBUS( mikrobus, MIKROBUS_INT )
119  // lighthz_map // lighthz
122 
127 typedef struct
128 {
129  digital_out_t s1;
130  digital_out_t s3;
131  digital_out_t s2;
132  digital_out_t s0;
134  digital_in_t freq;
136 } lighthz_t;
137 
142 typedef struct
143 {
144  pin_name_t s1;
145  pin_name_t s3;
146  pin_name_t s2;
147  pin_name_t s0;
148  pin_name_t freq;
150 } lighthz_cfg_t;
151 
156 typedef enum
157 {
159  LIGHTHZ_ERROR = -1
160 
162 
179 
193 err_t lighthz_init ( lighthz_t *ctx, lighthz_cfg_t *cfg );
194 
205 void lighthz_set_s0_pin ( lighthz_t *ctx, uint8_t state );
206 
217 void lighthz_set_s1_pin ( lighthz_t *ctx, uint8_t state );
218 
229 void lighthz_set_s2_pin ( lighthz_t *ctx, uint8_t state );
230 
241 void lighthz_set_s3_pin ( lighthz_t *ctx, uint8_t state );
242 
255 void lighthz_set_sensitivity ( lighthz_t *ctx, uint8_t mode );
256 
269 void lighthz_set_frequency_scaling ( lighthz_t *ctx, uint8_t mode );
270 
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 #endif // LIGHTHZ_H
285  // lighthz
287 
288 // ------------------------------------------------------------------------ END
lighthz_t::freq
digital_in_t freq
Definition: lighthz.h:134
lighthz_t
LightHz Click context object.
Definition: lighthz.h:128
LIGHTHZ_ERROR
@ LIGHTHZ_ERROR
Definition: lighthz.h:159
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:144
lighthz_t::s3
digital_out_t s3
Definition: lighthz.h:130
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:157
lighthz_t::s2
digital_out_t s2
Definition: lighthz.h:131
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:158
lighthz_t::s0
digital_out_t s0
Definition: lighthz.h:132
lighthz_cfg_t::s2
pin_name_t s2
Definition: lighthz.h:146
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:145
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:143
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:148
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:129
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:147