]> rtime.felk.cvut.cz Git - lincan.git/blob - embedded/libs4c/kbd/kbd_dev_ops.c
Included ARM LPC21xx related code from uLan project. The snapshot date is 2008-07-05
[lincan.git] / embedded / libs4c / kbd / kbd_dev_ops.c
1 #include <string.h>
2 #include "kbd.h"
3
4 #ifdef _DEVICE_H
5 /* create the microwindows keyboard device */
6
7 KBDDEVICE kbddev = {
8         kbd_Open,
9         kbd_Close,
10         kbd_GetModifierInfo,
11         kbd_Read,
12         kbd_Poll
13 };
14 #endif /* _DEVICE_H */
15
16 /**
17  * kbd_Open - Open the keyboard
18  * @pkd:        Pointer to keyboard device
19  */
20 int
21 kbd_Open(KBDDEVICE *pkd)
22 {
23         key_last_changed=0;
24         key_mod=0;
25         key_hit=0;
26         key_use_timer=0;
27         memset(key_down_arr,0,sizeof(key_down_arr));
28         kbd_setio();
29         return 1;
30 }
31
32 /**
33  * mx1_kbd_Close - Closes keyboard
34  */
35 void
36 kbd_Close(void)
37 {
38 }
39
40 /**
41  * mx1_kbd_Poll - Polls for keyboard events
42  *
43  * Returns non-zero value if change is detected.
44  */
45 int
46 kbd_Poll(void)
47 {
48         if(key_hit)
49                 return 1;
50         if(kbd_scan())
51                 kbd_down();
52         return key_hit?1:0;
53 }
54
55 /**
56  * kbd_GetModifierInfo - Returns the possible modifiers for the keyboard
57  * @modifiers:          If non-NULL, ones in defined modifiers bits are returned.
58  * @curmodifiers:       If non-NULL, ones in actually active modifiers
59  *                      bits are returned.
60  */
61 void
62 kbd_GetModifierInfo(kbd_keymod_t *modifiers, kbd_keymod_t *curmodifiers)
63 {
64         if (modifiers)
65                 *modifiers = 0;         /* no modifiers available */
66         if (curmodifiers)
67                 *curmodifiers = key_mod&~KBDMOD_SGM_SC;
68 }
69
70 /**
71  * mx1_kbd_Read - Reads resolved MWKEY value, modifiers and scancode
72  * @buf:                If non-NULL, resolved MWKEY is stored here
73  * @modifiers:          If non-NULL, ones in actually active modifiers
74  *                      bits are returned
75  * @scancode:           If non-NULL, scancode of resolved key is stored
76  *                      here
77  *
78  * This function reads one keystroke from the keyboard, and the current state
79  * of the modifier keys (ALT, SHIFT, etc).  Returns -1 on error, 0 if no data
80  * is ready, 1 on a keypress, and 2 on keyrelease.
81  * This is a non-blocking call.
82  */
83 int
84 kbd_Read(kbd_key_t *buf, kbd_keymod_t *modifiers, kbd_scan_code_t *scancode)
85 {
86         int ret;
87         if(!key_hit) {
88                 if(kbd_scan()){
89                         kbd_down();
90                 }
91         }
92         if(modifiers)
93                 *modifiers = key_mod&~KBDMOD_SGM_SC;
94         if(!key_hit)
95                 return 0;
96         if(scancode)
97                 *scancode = key_last_changed;
98         if(buf)
99                 *buf = kbd_scan2key(key_last_changed);
100         ret=key_hit;
101         key_hit=0;
102         return ret;
103 }