OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
keyboard.h
Go to the documentation of this file.
1/**
2 * @file keyboard.h
3 * @brief Kernel generic keyboard interface.
4 */
5#ifndef _SYS_KEYBOARD_H
6#define _SYS_KEYBOARD_H
7
8#include <stdbool.h>
9#include "keycode.h"
10
11/**
12 * @brief struct to hold state of the keyboard in terms of modifier keys
13 */
15 bool shift; /**< is shift pressed */
16 bool ctrl; /**< is ctrl pressed */
17 bool alt; /**< is alt or altgr pressed */
18 bool caps; /**< is caps toggled */
19};
20
21/**
22 * @brief typedef for generic hal polling function pointer.
23 *
24 * This allows us, when initializing the keyboard to pass a polling function (e.g.
25 * ps2_poll) dynamically.
26 */
27typedef bool (*hal_poll_func_t)(void);
28
29/**
30 * @brief struct that holds a keyboard event
31 *
32 */
34 bool pressed; /**< whether key was pressed or released */
35 enum KEYCODE keycode; /**< the keycode of the key which was pressed */
36};
37
38/**
39 * @brief function to initialize the kernel keyboard system
40 * @param poll generic HAL keyboard polling function
41 * @return whether initialization passed or failed
42 */
44
45/**
46 * @brief function to poll the keyboard for available events
47 * @returns true if new data has been pushed to event queue
48 * @note typically is called from irq.c, direct polling is slow
49 */
50bool keyboard_poll();
51
52/**
53 * @brief pop an event from the keyboard event queue.
54 * @param event buffer to store new event data in
55 * @returns whether there was any data in queue to pop
56 */
57bool keyboard_pop_event(struct keyboard_event *event);
58/**
59 * @brief push event to the keyboard event queue
60 * @param event event to push to the queue
61 * @note can be used to simulate keypresses.
62 * @note This function is typically called directly from the HAL keyboard driver. See
63 * ps2_keyboard.c for an example.
64 */
65void keyboard_push_event(struct keyboard_event event);
66
67/**
68 * @brief get the current modifier state of the keyboard
69 * @returns a pointer to the keyboard's struct keyboard_state
70 *
71 */
73
74#endif
void keyboard_push_event(struct keyboard_event event)
push event to the keyboard event queue
Definition keyboard.c:62
struct keyboard_state * keyboard_get_state()
get the current modifier state of the keyboard
Definition keyboard.c:72
bool(* hal_poll_func_t)(void)
typedef for generic hal polling function pointer.
Definition keyboard.h:27
int keyboard_init(hal_poll_func_t poll)
function to initialize the kernel keyboard system
Definition keyboard.c:16
bool keyboard_pop_event(struct keyboard_event *event)
pop an event from the keyboard event queue.
Definition keyboard.c:27
bool keyboard_poll()
function to poll the keyboard for available events
Definition keyboard.c:23
KEYCODE
Definition keycode.h:4
#define bool
Definition stdbool.h:4
struct that holds a keyboard event
Definition keyboard.h:33
bool pressed
Definition keyboard.h:34
enum KEYCODE keycode
Definition keyboard.h:35
struct to hold state of the keyboard in terms of modifier keys
Definition keyboard.h:14
bool shift
Definition keyboard.h:15
bool ctrl
Definition keyboard.h:16
bool caps
Definition keyboard.h:18
bool alt
Definition keyboard.h:17