Skip to content

Commit 50e9f46

Browse files
committed
hw:add keypad driver header file
Signed-off-by: Ajay Bhargav <[email protected]>
1 parent 7a2f218 commit 50e9f46

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

include/hw/keypad.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @file keypad.h
3+
* @author Ajay Bhargav ([email protected])
4+
* @brief Keypad driver API
5+
*
6+
* @copyright Copyright (c) 2025 Waybyte Solutions
7+
*
8+
*/
9+
#ifndef __HW_KEYPAD_H__
10+
#define __HW_KEYPAD_H__
11+
12+
#include <stdint.h>
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
enum keyevent_e {
19+
KEYPAD_EVENT_PRESS = 1,
20+
KEYPAD_EVENT_RELEASE = 2,
21+
};
22+
23+
/**
24+
* @brief Keypad callback function
25+
*
26+
* @param id [in] Key ID
27+
* @param event [in] Event type @ref keyevent_e
28+
* @param ctx [in] User context
29+
*
30+
*/
31+
typedef void (*keypad_callback_f)(int id, int event, void *ctx);
32+
33+
/**
34+
* @brief Initialize keypad function
35+
*
36+
* @param in_mask [in] bitwise mask for KEYINx (col) pins, unused currently
37+
* @param out_mask [in] bitwise mask for KEYOUTx (row) pins, unused currently
38+
* @return 0 on success, negative value on error
39+
*/
40+
int keypad_init(int in_mask, int out_mask);
41+
42+
/**
43+
* @brief Set keypad callback function
44+
*
45+
* @param id [in] Key ID
46+
* @param cb [in] Callback function
47+
* @param mask [in] Mask for event type @ref keyevent_e
48+
* @param ctx [in] User context
49+
* @return 0 on success, negative value on error
50+
*/
51+
int keypad_set_cb(int id, keypad_callback_f cb, uint32_t mask, void *ctx);
52+
53+
/**
54+
* @brief Get keypad state
55+
*
56+
* @param id [in] Key ID
57+
* @return true if key is pressed, false if key is released
58+
*/
59+
int keypad_get_state(int id);
60+
61+
/**
62+
* @brief Deinitialize keypad function
63+
*
64+
* @return 0 on success, negative value on error
65+
*/
66+
int keypad_deinit(void);
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
72+
#endif /* __HW_KEYPAD_H__ */

0 commit comments

Comments
 (0)