PatchworkOS  966e257
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/sysfs.h>
4#include <kernel/sched/wait.h>
5
6#include <stdint.h>
7#include <sys/kbd.h>
8
9/**
10 * @brief Keyboard abstraction.
11 * @defgroup kernel_drivers_abstract_kbd Keyboard Abstraction
12 * @ingroup kernel_drivers_abstract
13 *
14 * Keyboard devices are exposed as `/dev/kbd/[id]` directories, containing the following files:
15 * - `events`: A read-only pollable file that can be read to receive keyboard events as `kbd_event_t` structs.
16 * - `name`: A read-only file that contains the keyboard driver specified name (e.g. "PS/2")
17 *
18 * @{
19 */
20
21/**
22 * @brief Maximum number of queued keyboard events.
23 */
24#define KBD_MAX_EVENT 32
25
26/**
27 * @brief Keyboard structure.
28 * @struct kbd_t
29 */
42
43/**
44 * @brief Allocate and initialize a keyboard structure.
45 *
46 * Will make the keyboard available under `/dev/kbd/[id]`.
47 *
48 * @param name Driver specified name of the keyboard device.
49 * @return On success, the new keyboard structure. On failure, `NULL` and `errno` is set.
50 */
51kbd_t* kbd_new(const char* name);
52
53/**
54 * @brief Free and deinitialize a keyboard structure.
55 *
56 * Removes the keyboard from `/dev/kbd/[id]`.
57 *
58 * @param kbd Pointer to the keyboard structure to free.
59 */
60void kbd_free(kbd_t* kbd);
61
62/**
63 * @brief Push a keyboard event to the keyboard event queue.
64 *
65 * The event will be made available to user space by reading the `stream` file.
66 *
67 * @param kbd Pointer to the keyboard structure.
68 * @param type The type of the keyboard event.
69 * @param code The keycode of the keyboard event.
70 */
72
73/** @} */
static fd_t kbd
Definition dwm.c:23
#define KBD_MAX_EVENT
Maximum number of queued keyboard events.
Definition kbd.h:24
void kbd_push(kbd_t *kbd, kbd_event_type_t type, keycode_t code)
Push a keyboard event to the keyboard event queue.
Definition kbd.c:179
void kbd_free(kbd_t *kbd)
Free and deinitialize a keyboard structure.
Definition kbd.c:154
kbd_t * kbd_new(const char *name)
Allocate and initialize a keyboard structure.
Definition kbd.c:87
keycode_t
Keyboard keycode type.
Definition kbd.h:27
kbd_mods_t
Keyboard modifiers type.
Definition kbd.h:297
kbd_event_type_t
Keyboard event type.
Definition kbd.h:286
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Directory entry structure.
Definition dentry.h:84
Keyboard event structure.
Definition kbd.h:313
Keyboard structure.
Definition kbd.h:31
lock_t lock
Definition kbd.h:37
dentry_t * eventsFile
Definition kbd.h:39
dentry_t * dir
Definition kbd.h:38
uint64_t writeIndex
Definition kbd.h:34
wait_queue_t waitQueue
Definition kbd.h:36
dentry_t * nameFile
Definition kbd.h:40
kbd_mods_t mods
Definition kbd.h:35
char * name
Definition kbd.h:32
A simple ticket lock implementation.
Definition lock.h:43
The primitive that threads block on.
Definition wait.h:182