keylock  2.0.0.0
keylock.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 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef KEYLOCK_H
36 #define KEYLOCK_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define KEYLOCK_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.out1= MIKROBUS( mikrobus, MIKROBUS_AN ); \
63  cfg.out2= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg.out3= MIKROBUS( mikrobus, MIKROBUS_INT );
65 
71 #define KEYLOCK_RETVAL uint8_t
72 
73 #define KEYLOCK_OK 0x00
74 #define KEYLOCK_INIT_ERROR 0xFF
75 
81 #define KEYLOCK_KEY_POS_1 1
82 #define KEYLOCK_KEY_POS_2 2
83 #define KEYLOCK_KEY_POS_3 3
84 
90 #define KEYLOCK_ERROR_FLAG 0
91  // End group macro
94 // --------------------------------------------------------------- PUBLIC TYPES
103 typedef struct
104 {
105  // Input pins
106 
107  digital_in_t out1;
108  digital_in_t out2;
109  digital_in_t out3;
110 
111 } keylock_t;
112 
116 typedef struct
117 {
118  // Additional gpio pins
119 
120  pin_name_t out1;
121  pin_name_t out2;
122  pin_name_t out3;
123 
124 } keylock_cfg_t;
125  // End types group
127 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
128 
134 #ifdef __cplusplus
135 extern "C"{
136 #endif
137 
147 
157 
174 uint8_t keylock_check_pin ( keylock_t *ctx, uint8_t pin );
175 
186 
198 
210 
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 #endif // _KEYLOCK_H_
227  // End public_function group
230 
231 // ------------------------------------------------------------------------- END
keylock_t
Click ctx object definition.
Definition: keylock.h:104
keylock_t::out2
digital_in_t out2
Definition: keylock.h:108
keylock_check_int_state
uint8_t keylock_check_int_state(keylock_t *ctx)
Checks INT pin state.
keylock_check_pwm_state
uint8_t keylock_check_pwm_state(keylock_t *ctx)
Checks PWM pin state.
keylock_check_pin
uint8_t keylock_check_pin(keylock_t *ctx, uint8_t pin)
Checks pin state.
keylock_t::out3
digital_in_t out3
Definition: keylock.h:109
keylock_cfg_setup
void keylock_cfg_setup(keylock_cfg_t *cfg)
Config Object Initialization function.
keylock_t::out1
digital_in_t out1
Definition: keylock.h:107
KEYLOCK_RETVAL
#define KEYLOCK_RETVAL
Definition: keylock.h:71
keylock_cfg_t::out3
pin_name_t out3
Definition: keylock.h:122
keylock_init
KEYLOCK_RETVAL keylock_init(keylock_t *ctx, keylock_cfg_t *cfg)
Initialization function.
keylock_cfg_t::out1
pin_name_t out1
Definition: keylock.h:120
keylock_get_position
uint8_t keylock_get_position(keylock_t *ctx)
Gets key position.
keylock_check_an_state
uint8_t keylock_check_an_state(keylock_t *ctx)
Checks AN pin state.
keylock_cfg_t::out2
pin_name_t out2
Definition: keylock.h:121
keylock_cfg_t
Click configuration structure definition.
Definition: keylock.h:117