Skip to content

Commit e13a123

Browse files
franciscomunozandrewboie
authored andcommitted
API: kscan: Add API for Keyboard scan matrix
-kscan_config -kscan_enable_callback -kscan_disable_callback Signed-off-by: Francisco Munoz <[email protected]>
1 parent 24508a7 commit e13a123

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

include/drivers/kscan.h

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright (c) 2019 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief Public API for Keyboard scan matrix devices.
10+
* The scope of this API is simply to report which key event was triggered
11+
* and users can later decode keys using their desired scan code tables in
12+
* their application. In additon, typematic rate and delay can easily be
13+
* implemented using a timer if desired.
14+
*/
15+
16+
#ifndef ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_
17+
#define ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_
18+
19+
#include <zephyr/types.h>
20+
#include <stddef.h>
21+
#include <device.h>
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
/**
28+
* @brief KSCAN APIs
29+
* @defgroup kscan_interface Keyboard Scan Driver APIs
30+
* @ingroup io_interfaces
31+
* @{
32+
*/
33+
34+
/**
35+
* @brief Keyboard scan callback called when user press/release
36+
* a key on a matrix keyboard.
37+
*
38+
* @param dev Pointer to the device structure for the driver instance.
39+
* @param data Data byte passed pack to the user.
40+
* @param col Describes column change.
41+
* @param row Describes row change.
42+
* @param pressed Describes the kind of key event.
43+
*/
44+
typedef void (*kscan_callback_t)(struct device *dev, u8_t row, u8_t column,
45+
bool pressed);
46+
47+
/**
48+
* @cond INTERNAL_HIDDEN
49+
*
50+
* Keyboard scan driver API definition and system call entry points.
51+
*
52+
* (Internal use only.)
53+
*/
54+
typedef int (*kscan_config_t)(struct device *dev,
55+
kscan_callback_t callback);
56+
typedef int (*kscan_disable_callback_t)(struct device *dev);
57+
typedef int (*kscan_enable_callback_t)(struct device *dev);
58+
59+
struct kscan_driver_api {
60+
kscan_config_t config;
61+
kscan_disable_callback_t disable_callback;
62+
kscan_enable_callback_t enable_callback;
63+
};
64+
/**
65+
* @endcond
66+
*/
67+
68+
/**
69+
* @brief Configure a Keyboard scan instance.
70+
*
71+
* @param dev Pointer to the device structure for the driver instance.
72+
* @param callback called when keyboard devices reply to to a keyboard
73+
* event susch as key pressed/released.
74+
*
75+
* @retval 0 If successful.
76+
* @retval Negative errno code if failure.
77+
*/
78+
__syscall int kscan_config(struct device *dev,
79+
kscan_callback_t callback);
80+
81+
static inline int z_impl_kscan_config(struct device *dev,
82+
kscan_callback_t callback)
83+
{
84+
const struct kscan_driver_api *api =
85+
(struct kscan_driver_api *)dev->driver_api;
86+
87+
return api->config(dev, callback);
88+
}
89+
/**
90+
* @brief Enables callback.
91+
* @param dev Pointer to the device structure for the driver instance.
92+
*
93+
* @retval 0 If successful.
94+
* @retval Negative errno code if failure.
95+
*/
96+
__syscall int kscan_enable_callback(struct device *dev);
97+
98+
static inline int z_impl_kscan_enable_callback(struct device *dev)
99+
{
100+
const struct kscan_driver_api *api =
101+
(const struct kscan_driver_api *)dev->driver_api;
102+
103+
if (api->enable_callback == NULL) {
104+
return -ENOTSUP;
105+
}
106+
107+
return api->enable_callback(dev);
108+
}
109+
110+
/**
111+
* @brief Disables callback.
112+
* @param dev Pointer to the device structure for the driver instance.
113+
*
114+
* @retval 0 If successful.
115+
* @retval Negative errno code if failure.
116+
*/
117+
__syscall int kscan_disable_callback(struct device *dev);
118+
119+
static inline int z_impl_kscan_disable_callback(struct device *dev)
120+
{
121+
const struct kscan_driver_api *api =
122+
(const struct kscan_driver_api *)dev->driver_api;
123+
124+
if (api->disable_callback == NULL) {
125+
return -ENOTSUP;
126+
}
127+
128+
return api->disable_callback(dev);
129+
}
130+
131+
#ifdef __cplusplus
132+
}
133+
#endif
134+
135+
/**
136+
* @}
137+
*/
138+
139+
#include <syscalls/kscan.h>
140+
141+
#endif /* ZEPHYR_INCLUDE_DRIVERS_KB_SCAN_H_ */

0 commit comments

Comments
 (0)