Line data Source code
1 1 : /*
2 : * Copyright (c) 2019 Intel Corporation
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @ingroup ps2_interface
10 : * @brief Main header file for PS/2 (Personal System/2) driver API.
11 : */
12 :
13 : #ifndef ZEPHYR_INCLUDE_DRIVERS_PS2_H_
14 : #define ZEPHYR_INCLUDE_DRIVERS_PS2_H_
15 :
16 : #include <errno.h>
17 : #include <zephyr/types.h>
18 : #include <stddef.h>
19 : #include <zephyr/device.h>
20 :
21 : #ifdef __cplusplus
22 : extern "C" {
23 : #endif
24 :
25 : /**
26 : * @brief Interfaces for PS/2 devices.
27 : * @defgroup ps2_interface PS/2
28 : * @ingroup io_interfaces
29 : *
30 : * Callers of this API are responsible for setting the typematic rate
31 : * and decode keys using their desired scan code tables.
32 : *
33 : * @{
34 : */
35 :
36 : /**
37 : * @brief PS/2 callback called when user types or click a mouse.
38 : *
39 : * @param dev Pointer to the device structure for the driver instance.
40 : * @param data Data byte passed pack to the user.
41 : */
42 1 : typedef void (*ps2_callback_t)(const struct device *dev, uint8_t data);
43 :
44 : /**
45 : * @cond INTERNAL_HIDDEN
46 : *
47 : * PS2 driver API definition and system call entry points
48 : *
49 : * (Internal use only.)
50 : */
51 : typedef int (*ps2_config_t)(const struct device *dev,
52 : ps2_callback_t callback_isr);
53 : typedef int (*ps2_read_t)(const struct device *dev, uint8_t *value);
54 : typedef int (*ps2_write_t)(const struct device *dev, uint8_t value);
55 : typedef int (*ps2_disable_callback_t)(const struct device *dev);
56 : typedef int (*ps2_enable_callback_t)(const struct device *dev);
57 :
58 : __subsystem struct ps2_driver_api {
59 : ps2_config_t config;
60 : ps2_read_t read;
61 : ps2_write_t write;
62 : ps2_disable_callback_t disable_callback;
63 : ps2_enable_callback_t enable_callback;
64 : };
65 : /**
66 : * @endcond
67 : */
68 :
69 : /**
70 : * @brief Configure a ps2 instance.
71 : *
72 : * @param dev Pointer to the device structure for the driver instance.
73 : * @param callback_isr called when PS/2 devices reply to a configuration
74 : * command or when a mouse/keyboard send data to the client application.
75 : *
76 : * @retval 0 If successful.
77 : * @retval Negative errno code if failure.
78 : */
79 1 : __syscall int ps2_config(const struct device *dev,
80 : ps2_callback_t callback_isr);
81 :
82 : static inline int z_impl_ps2_config(const struct device *dev,
83 : ps2_callback_t callback_isr)
84 : {
85 : const struct ps2_driver_api *api =
86 : (struct ps2_driver_api *)dev->api;
87 :
88 : return api->config(dev, callback_isr);
89 : }
90 :
91 : /**
92 : * @brief Write to PS/2 device.
93 : *
94 : * @param dev Pointer to the device structure for the driver instance.
95 : * @param value Data for the PS2 device.
96 : *
97 : * @retval 0 If successful.
98 : * @retval Negative errno code if failure.
99 : */
100 1 : __syscall int ps2_write(const struct device *dev, uint8_t value);
101 :
102 : static inline int z_impl_ps2_write(const struct device *dev, uint8_t value)
103 : {
104 : const struct ps2_driver_api *api =
105 : (const struct ps2_driver_api *)dev->api;
106 :
107 : return api->write(dev, value);
108 : }
109 :
110 : /**
111 : * @brief Read slave-to-host values from PS/2 device.
112 : * @param dev Pointer to the device structure for the driver instance.
113 : * @param value Pointer used for reading the PS/2 device.
114 : *
115 : * @retval 0 If successful.
116 : * @retval Negative errno code if failure.
117 : */
118 1 : __syscall int ps2_read(const struct device *dev, uint8_t *value);
119 :
120 : static inline int z_impl_ps2_read(const struct device *dev, uint8_t *value)
121 : {
122 : const struct ps2_driver_api *api =
123 : (const struct ps2_driver_api *)dev->api;
124 :
125 : return api->read(dev, value);
126 : }
127 :
128 : /**
129 : * @brief Enables callback.
130 : * @param dev Pointer to the device structure for the driver instance.
131 : *
132 : * @retval 0 If successful.
133 : * @retval Negative errno code if failure.
134 : */
135 1 : __syscall int ps2_enable_callback(const struct device *dev);
136 :
137 : static inline int z_impl_ps2_enable_callback(const struct device *dev)
138 : {
139 : const struct ps2_driver_api *api =
140 : (const struct ps2_driver_api *)dev->api;
141 :
142 : if (api->enable_callback == NULL) {
143 : return -ENOSYS;
144 : }
145 :
146 : return api->enable_callback(dev);
147 : }
148 :
149 : /**
150 : * @brief Disables callback.
151 : * @param dev Pointer to the device structure for the driver instance.
152 : *
153 : * @retval 0 If successful.
154 : * @retval Negative errno code if failure.
155 : */
156 1 : __syscall int ps2_disable_callback(const struct device *dev);
157 :
158 : static inline int z_impl_ps2_disable_callback(const struct device *dev)
159 : {
160 : const struct ps2_driver_api *api =
161 : (const struct ps2_driver_api *)dev->api;
162 :
163 : if (api->disable_callback == NULL) {
164 : return -ENOSYS;
165 : }
166 :
167 : return api->disable_callback(dev);
168 : }
169 :
170 : #ifdef __cplusplus
171 : }
172 : #endif
173 :
174 : /**
175 : * @}
176 : */
177 :
178 : #include <zephyr/syscalls/ps2.h>
179 :
180 : #endif /* ZEPHYR_INCLUDE_DRIVERS_PS2_H_ */
|