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
32extern "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
101 // 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
124 // lighthz_map
125 // lighthz
126
131typedef 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
146typedef 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;
155
160typedef enum
161{
163 LIGHTHZ_ERROR = -1
164
166
183
198
209void lighthz_set_s0_pin ( lighthz_t *ctx, uint8_t state );
210
221void lighthz_set_s1_pin ( lighthz_t *ctx, uint8_t state );
222
233void lighthz_set_s2_pin ( lighthz_t *ctx, uint8_t state );
234
245void lighthz_set_s3_pin ( lighthz_t *ctx, uint8_t state );
246
259void lighthz_set_sensitivity ( lighthz_t *ctx, uint8_t mode );
260
273void lighthz_set_frequency_scaling ( lighthz_t *ctx, uint8_t mode );
274
284
285#ifdef __cplusplus
286}
287#endif
288#endif // LIGHTHZ_H
289
290 // lighthz
291
292// ------------------------------------------------------------------------ END
void lighthz_set_sensitivity(lighthz_t *ctx, uint8_t mode)
LightHz set sensitivity function.
void lighthz_set_s1_pin(lighthz_t *ctx, uint8_t state)
LightHz set s1 pin function.
err_t lighthz_init(lighthz_t *ctx, lighthz_cfg_t *cfg)
LightHz initialization function.
uint8_t lighthz_get_freq_pin(lighthz_t *ctx)
LightHz get freq pin function.
void lighthz_set_frequency_scaling(lighthz_t *ctx, uint8_t mode)
LightHz set frequency scaling function.
void lighthz_set_s3_pin(lighthz_t *ctx, uint8_t state)
LightHz set s3 pin function.
void lighthz_cfg_setup(lighthz_cfg_t *cfg)
LightHz configuration object setup function.
void lighthz_set_s0_pin(lighthz_t *ctx, uint8_t state)
LightHz set s0 pin function.
void lighthz_set_s2_pin(lighthz_t *ctx, uint8_t state)
LightHz set s2 pin function.
lighthz_return_value_t
LightHz Click return value data.
Definition lighthz.h:161
@ LIGHTHZ_ERROR
Definition lighthz.h:163
@ LIGHTHZ_OK
Definition lighthz.h:162
LightHz Click configuration object.
Definition lighthz.h:147
pin_name_t s2
Definition lighthz.h:150
pin_name_t s3
Definition lighthz.h:149
pin_name_t s0
Definition lighthz.h:151
pin_name_t s1
Definition lighthz.h:148
pin_name_t freq
Definition lighthz.h:152
LightHz Click context object.
Definition lighthz.h:132
digital_out_t s3
Definition lighthz.h:134
digital_out_t s2
Definition lighthz.h:135
digital_out_t s1
Definition lighthz.h:133
digital_out_t s0
Definition lighthz.h:136
digital_in_t freq
Definition lighthz.h:138