PatchworkOS
19e446b
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
kbd.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
kernel/fs/devfs.h
>
4
#include <
kernel/sched/wait.h
>
5
#include <
kernel/sync/lock.h
>
6
#include <
kernel/utils/fifo.h
>
7
8
#include <
stdint.h
>
9
#include <
sys/kbd.h
>
10
#include <
sys/proc.h
>
11
12
typedef
struct
kbd
kbd_t
;
13
14
/**
15
* @brief Keyboard abstraction.
16
* @defgroup kernel_drivers_abstract_kbd Keyboard Abstraction
17
* @ingroup kernel_drivers_abstract
18
*
19
* Keyboard devices are exposed as a `/dev/kbd/[id]/` directory, containing the below files.
20
*
21
* ## name
22
*
23
* A read-only file that contains the driver defined name of the keyboard device.
24
*
25
* ## events
26
*
27
* A readable and pollable file that provides a stream of keyboard events represented as integer keycodes suffixed with
28
* a `_` or `^` to indicate press or release respectively.
29
*
30
* The below example shows a press of the `1` key, its subsequent release, and then a press of the `A` key.
31
*
32
* ```
33
* 30_30^5_
34
* ```
35
*
36
* If no events are available to read, the read call will block until an event is available unless the file is opened in
37
* non-blocking mode in which case the read will fail with `EAGAIN`.
38
*
39
* @note The format is specified such that if `scan()` is used with "%u%c" the `scan()` call does not require any
40
* "ungets".
41
*
42
* @see libstd_sys_kbd for keycode definitions.
43
*
44
* @{
45
*/
46
47
/**
48
* @brief Size of the keyboard client buffer.
49
*/
50
#define KBD_CLIENT_BUFFER_SIZE 512
51
52
/**
53
* @brief Keyboard event client structure.
54
* @struct kbd_client_t
55
*/
56
typedef
struct
kbd_client
57
{
58
list_entry_t
entry
;
59
fifo_t
fifo
;
60
uint8_t
buffer
[
KBD_CLIENT_BUFFER_SIZE
];
61
}
kbd_client_t
;
62
63
/**
64
* @brief Keyboard structure.
65
* @struct kbd_t
66
*/
67
typedef
struct
kbd
68
{
69
char
name[
MAX_PATH
];
70
wait_queue_t
waitQueue
;
71
list_t
clients
;
72
lock_t
lock
;
73
dentry_t
*
dir
;
74
list_t
files
;
75
}
kbd_t
;
76
77
/**
78
* @brief Allocate and initialize a new keyboard.
79
*
80
* @param name The driver specified name of the keyboard.
81
* @return On success, the new keyboard. On failure, `NULL` and `errno` is set.
82
*/
83
kbd_t
*
kbd_new
(
const
char
* name);
84
85
/**
86
* @brief Frees a keyboard.
87
*
88
* @param kbd The keyboard to free.
89
*/
90
void
kbd_free
(
kbd_t
*
kbd
);
91
92
/**
93
* @brief Push a keyboard press event to the keyboard event queue.
94
*
95
* @param kbd The keyboard.
96
* @param type The type of event.
97
* @param code The keycode of the event.
98
*/
99
void
kbd_press
(
kbd_t
*
kbd
,
keycode_t
code);
100
101
/**
102
* @brief Push a keyboard release event to the keyboard event queue.
103
*
104
* @param kbd The keyboard.
105
* @param code The keycode to release.
106
*/
107
void
kbd_release
(
kbd_t
*
kbd
,
keycode_t
code);
108
109
/** @} */
MAX_PATH
#define MAX_PATH
Maximum length of filepaths.
Definition
MAX_PATH.h:11
buffer
EFI_PHYSICAL_ADDRESS buffer
Definition
main.c:237
devfs.h
kbd
static fd_t kbd
Definition
dwm.c:23
fifo.h
kbd_release
void kbd_release(kbd_t *kbd, keycode_t code)
Push a keyboard release event to the keyboard event queue.
Definition
kbd.c:270
KBD_CLIENT_BUFFER_SIZE
#define KBD_CLIENT_BUFFER_SIZE
Size of the keyboard client buffer.
Definition
kbd.h:50
kbd_press
void kbd_press(kbd_t *kbd, keycode_t code)
Push a keyboard press event to the keyboard event queue.
Definition
kbd.c:252
kbd_free
void kbd_free(kbd_t *kbd)
Frees a keyboard.
Definition
kbd.c:225
kbd_new
kbd_t * kbd_new(const char *name)
Allocate and initialize a new keyboard.
Definition
kbd.c:150
keycode_t
keycode_t
Keyboard keycode type.
Definition
kbd.h:29
kbd.h
lock.h
proc.h
stdint.h
uint8_t
__UINT8_TYPE__ uint8_t
Definition
stdint.h:11
dentry_t
Directory entry structure.
Definition
dentry.h:155
fifo_t
FIFO Buffer.
Definition
fifo.h:20
kbd_client_t
Keyboard event client structure.
Definition
kbd.h:57
kbd_client_t::entry
list_entry_t entry
Definition
kbd.h:58
kbd_client_t::fifo
fifo_t fifo
Definition
kbd.h:59
kbd_t
Keyboard structure.
Definition
kbd.h:68
kbd_t::files
list_t files
Definition
kbd.h:74
kbd_t::lock
lock_t lock
Definition
kbd.h:72
kbd_t::clients
list_t clients
Definition
kbd.h:71
kbd_t::dir
dentry_t * dir
Definition
kbd.h:73
kbd_t::waitQueue
wait_queue_t waitQueue
Definition
kbd.h:70
list_entry_t
A entry in a doubly linked list.
Definition
list.h:37
list_t
A doubly linked list.
Definition
list.h:46
lock_t
A simple ticket lock implementation.
Definition
lock.h:44
wait_queue_t
The primitive that threads block on.
Definition
wait.h:185
wait.h
include
kernel
drivers
abstract
kbd.h
Generated on Sat Jan 24 2026 10:59:24 for PatchworkOS by
1.9.8