keylock2  2.0.0.0
keylock2.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 KEYLOCK2_H
36 #define KEYLOCK2_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_in.h"
49 
50 // -------------------------------------------------------------- PUBLIC MACROS
60 #define KEYLOCK2_MAP_MIKROBUS( cfg, mikrobus ) \
61  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
62  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
63  cfg.in3 = MIKROBUS( mikrobus, MIKROBUS_INT );
64 
70 #define KEYLOCK2_RETVAL uint8_t
71 
72 #define KEYLOCK2_OK 0x00
73 #define KEYLOCK2_INIT_ERROR 0xFF
74 
80 #define KEYLOCK2_STATE_RST_PIN 0x01
81 #define KEYLOCK2_STATE_PWM_PIN 0x02
82 #define KEYLOCK2_STATE_INT_PIN 0x03
83 
89 #define KEYLOCK2_POSITION_1 0x01
90 #define KEYLOCK2_POSITION_2 0x02
91 #define KEYLOCK2_POSITION_3 0x03
92  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  // Input pins
107 
108  digital_in_t in1;
109  digital_in_t in2;
110  digital_in_t in3;
111 
112 } keylock2_t;
113 
117 typedef struct
118 {
119  // Additional gpio pins
120 
121  pin_name_t in1;
122  pin_name_t in2;
123  pin_name_t in3;
124 
126  // End types group
128 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129 
135 #ifdef __cplusplus
136 extern "C"{
137 #endif
138 
148 
159 
167 uint8_t keylock2_get_pin_state ( keylock2_t *ctx, uint8_t pin );
168 
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 #endif // _KEYLOCK2_H_
183  // End public_function group
186 
187 // ------------------------------------------------------------------------- END
keylock2_t
Click ctx object definition.
Definition: keylock2.h:105
keylock2_cfg_t
Click configuration structure definition.
Definition: keylock2.h:118
keylock2_get_position
uint8_t keylock2_get_position(keylock2_t *ctx)
Get Pin State.
keylock2_cfg_t::in1
pin_name_t in1
Definition: keylock2.h:121
keylock2_init
KEYLOCK2_RETVAL keylock2_init(keylock2_t *ctx, keylock2_cfg_t *cfg)
Initialization function.
keylock2_t::in1
digital_in_t in1
Definition: keylock2.h:108
keylock2_get_pin_state
uint8_t keylock2_get_pin_state(keylock2_t *ctx, uint8_t pin)
Get Pin State.
KEYLOCK2_RETVAL
#define KEYLOCK2_RETVAL
Definition: keylock2.h:70
keylock2_cfg_t::in3
pin_name_t in3
Definition: keylock2.h:123
keylock2_cfg_t::in2
pin_name_t in2
Definition: keylock2.h:122
keylock2_t::in3
digital_in_t in3
Definition: keylock2.h:110
keylock2_t::in2
digital_in_t in2
Definition: keylock2.h:109
keylock2_cfg_setup
void keylock2_cfg_setup(keylock2_cfg_t *cfg)
Config Object Initialization function.