PatchworkOS  19e446b
A non-POSIX operating system.
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
12typedef 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 */
62
63/**
64 * @brief Keyboard structure.
65 * @struct kbd_t
66 */
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 */
83kbd_t* kbd_new(const char* name);
84
85/**
86 * @brief Frees a keyboard.
87 *
88 * @param kbd The keyboard to free.
89 */
90void 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 */
99void 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 */
107void kbd_release(kbd_t* kbd, keycode_t code);
108
109/** @} */
#define MAX_PATH
Maximum length of filepaths.
Definition MAX_PATH.h:11
EFI_PHYSICAL_ADDRESS buffer
Definition main.c:237
static fd_t kbd
Definition dwm.c:23
void kbd_release(kbd_t *kbd, keycode_t code)
Push a keyboard release event to the keyboard event queue.
Definition kbd.c:270
#define KBD_CLIENT_BUFFER_SIZE
Size of the keyboard client buffer.
Definition kbd.h:50
void kbd_press(kbd_t *kbd, keycode_t code)
Push a keyboard press event to the keyboard event queue.
Definition kbd.c:252
void kbd_free(kbd_t *kbd)
Frees a keyboard.
Definition kbd.c:225
kbd_t * kbd_new(const char *name)
Allocate and initialize a new keyboard.
Definition kbd.c:150
keycode_t
Keyboard keycode type.
Definition kbd.h:29
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
Directory entry structure.
Definition dentry.h:155
FIFO Buffer.
Definition fifo.h:20
Keyboard event client structure.
Definition kbd.h:57
list_entry_t entry
Definition kbd.h:58
fifo_t fifo
Definition kbd.h:59
Keyboard structure.
Definition kbd.h:68
list_t files
Definition kbd.h:74
lock_t lock
Definition kbd.h:72
list_t clients
Definition kbd.h:71
dentry_t * dir
Definition kbd.h:73
wait_queue_t waitQueue
Definition kbd.h:70
A entry in a doubly linked list.
Definition list.h:37
A doubly linked list.
Definition list.h:46
A simple ticket lock implementation.
Definition lock.h:44
The primitive that threads block on.
Definition wait.h:185