summaryrefslogtreecommitdiffstats
path: root/devices/input.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-27 11:51:08 +0200
committermanuel <manuel@mausz.at>2012-03-27 11:51:08 +0200
commit4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch)
tree868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /devices/input.c
parenteae0bd57f0a26314a94785061888d193d186944a (diff)
downloadprogos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz
progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2
progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip
reorganize file structure to match the upstream requirements
Diffstat (limited to 'devices/input.c')
-rw-r--r--devices/input.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/devices/input.c b/devices/input.c
new file mode 100644
index 0000000..4a12160
--- /dev/null
+++ b/devices/input.c
@@ -0,0 +1,52 @@
1#include "devices/input.h"
2#include <debug.h>
3#include "devices/intq.h"
4#include "devices/serial.h"
5
6/* Stores keys from the keyboard and serial port. */
7static struct intq buffer;
8
9/* Initializes the input buffer. */
10void
11input_init (void)
12{
13 intq_init (&buffer);
14}
15
16/* Adds a key to the input buffer.
17 Interrupts must be off and the buffer must not be full. */
18void
19input_putc (uint8_t key)
20{
21 ASSERT (intr_get_level () == INTR_OFF);
22 ASSERT (!intq_full (&buffer));
23
24 intq_putc (&buffer, key);
25 serial_notify ();
26}
27
28/* Retrieves a key from the input buffer.
29 If the buffer is empty, waits for a key to be pressed. */
30uint8_t
31input_getc (void)
32{
33 enum intr_level old_level;
34 uint8_t key;
35
36 old_level = intr_disable ();
37 key = intq_getc (&buffer);
38 serial_notify ();
39 intr_set_level (old_level);
40
41 return key;
42}
43
44/* Returns true if the input buffer is full,
45 false otherwise.
46 Interrupts must be off. */
47bool
48input_full (void)
49{
50 ASSERT (intr_get_level () == INTR_OFF);
51 return intq_full (&buffer);
52}