keylock  2.0.0.0
keylock.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef KEYLOCK_H
36 #define KEYLOCK_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define KEYLOCK_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.out1= MIKROBUS( mikrobus, MIKROBUS_AN ); \
53  cfg.out2= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54  cfg.out3= MIKROBUS( mikrobus, MIKROBUS_INT );
55 
61 #define KEYLOCK_RETVAL uint8_t
62 
63 #define KEYLOCK_OK 0x00
64 #define KEYLOCK_INIT_ERROR 0xFF
65 
71 #define KEYLOCK_KEY_POS_1 1
72 #define KEYLOCK_KEY_POS_2 2
73 #define KEYLOCK_KEY_POS_3 3
74 
80 #define KEYLOCK_ERROR_FLAG 0
81  // End group macro
84 // --------------------------------------------------------------- PUBLIC TYPES
93 typedef struct
94 {
95  // Input pins
96 
97  digital_in_t out1;
98  digital_in_t out2;
99  digital_in_t out3;
100 
101 } keylock_t;
102 
106 typedef struct
107 {
108  // Additional gpio pins
109 
110  pin_name_t out1;
111  pin_name_t out2;
112  pin_name_t out3;
113 
114 } keylock_cfg_t;
115  // End types group
117 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
118 
124 #ifdef __cplusplus
125 extern "C"{
126 #endif
127 
136 void keylock_cfg_setup ( keylock_cfg_t *cfg );
137 
147 
164 uint8_t keylock_check_pin ( keylock_t *ctx, uint8_t pin );
165 
175 uint8_t keylock_get_position ( keylock_t *ctx );
176 
187 uint8_t keylock_check_an_state ( keylock_t *ctx );
188 
199 uint8_t keylock_check_pwm_state ( keylock_t *ctx );
200 
211 uint8_t keylock_check_int_state ( keylock_t *ctx );
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 #endif // _KEYLOCK_H_
217  // End public_function group
220 
221 // ------------------------------------------------------------------------- END
KEYLOCK_RETVAL keylock_init(keylock_t *ctx, keylock_cfg_t *cfg)
Initialization function.
uint8_t keylock_check_pwm_state(keylock_t *ctx)
Checks PWM pin state.
Click configuration structure definition.
Definition: keylock.h:106
Click ctx object definition.
Definition: keylock.h:93
void keylock_cfg_setup(keylock_cfg_t *cfg)
Config Object Initialization function.
pin_name_t out1
Definition: keylock.h:110
digital_in_t out3
Definition: keylock.h:99
digital_in_t out2
Definition: keylock.h:98
#define KEYLOCK_RETVAL
Definition: keylock.h:61
pin_name_t out3
Definition: keylock.h:112
uint8_t keylock_check_int_state(keylock_t *ctx)
Checks INT pin state.
pin_name_t out2
Definition: keylock.h:111
uint8_t keylock_check_pin(keylock_t *ctx, uint8_t pin)
Checks pin state.
uint8_t keylock_get_position(keylock_t *ctx)
Gets key position.
digital_in_t out1
Definition: keylock.h:97
uint8_t keylock_check_an_state(keylock_t *ctx)
Checks AN pin state.