KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
keyboard.h
Go to the documentation of this file.
1 /* KallistiOS ##version##
2 
3  dc/maple/keyboard.h
4  Copyright (C) 2000-2002 Jordan DeLong and Dan Potter
5  Copyright (C) 2012 Lawrence Sebald
6 
7 */
8 
9 /** \file dc/maple/keyboard.h
10  \brief Definitions for using the keyboard device.
11 
12  This file contains the definitions needed to access the Maple keyboard
13  device. Obviously, this corresponds to the MAPLE_FUNC_KEYBOARD function
14  code.
15 
16  \author Jordan DeLong
17  \author Dan Potter
18  \author Lawrence Sebald
19 */
20 
21 #ifndef __DC_MAPLE_KEYBOARD_H
22 #define __DC_MAPLE_KEYBOARD_H
23 
24 #include <sys/cdefs.h>
25 __BEGIN_DECLS
26 
27 #include <arch/types.h>
28 #include <dc/maple.h>
29 
30 /** \defgroup kbd_mods Keyboard modifier keys
31 
32  These are the various modifiers that can be pressed on the keyboard, and are
33  reflected in the modifiers field of kbd_cond_t.
34  @{
35 */
36 #define KBD_MOD_LCTRL (1<<0)
37 #define KBD_MOD_LSHIFT (1<<1)
38 #define KBD_MOD_LALT (1<<2)
39 #define KBD_MOD_S1 (1<<3)
40 #define KBD_MOD_RCTRL (1<<4)
41 #define KBD_MOD_RSHIFT (1<<5)
42 #define KBD_MOD_RALT (1<<6)
43 #define KBD_MOD_S2 (1<<7)
44 /** @} */
45 
46 /** \defgroup kbd_leds Keyboard LEDs
47 
48  This is the LEDs that can be turned on and off on the keyboard. This list
49  may not be exhaustive. Think of these sorta like an extension of the
50  modifiers list.
51  @{
52 */
53 #define KBD_LED_NUMLOCK (1<<0)
54 #define KBD_LED_CAPSLOCK (1<<1)
55 #define KBD_LED_SCRLOCK (1<<2)
56 /** @} */
57 
58 /** \defgroup kbd_keys Keyboard keys
59 
60  This is the list of keys that are on the keyboard that may be pressed. The
61  keyboard returns keys in this format.
62  @{
63 */
64 #define KBD_KEY_NONE 0x00
65 #define KBD_KEY_ERROR 0x01
66 #define KBD_KEY_A 0x04
67 #define KBD_KEY_B 0x05
68 #define KBD_KEY_C 0x06
69 #define KBD_KEY_D 0x07
70 #define KBD_KEY_E 0x08
71 #define KBD_KEY_F 0x09
72 #define KBD_KEY_G 0x0a
73 #define KBD_KEY_H 0x0b
74 #define KBD_KEY_I 0x0c
75 #define KBD_KEY_J 0x0d
76 #define KBD_KEY_K 0x0e
77 #define KBD_KEY_L 0x0f
78 #define KBD_KEY_M 0x10
79 #define KBD_KEY_N 0x11
80 #define KBD_KEY_O 0x12
81 #define KBD_KEY_P 0x13
82 #define KBD_KEY_Q 0x14
83 #define KBD_KEY_R 0x15
84 #define KBD_KEY_S 0x16
85 #define KBD_KEY_T 0x17
86 #define KBD_KEY_U 0x18
87 #define KBD_KEY_V 0x19
88 #define KBD_KEY_W 0x1a
89 #define KBD_KEY_X 0x1b
90 #define KBD_KEY_Y 0x1c
91 #define KBD_KEY_Z 0x1d
92 #define KBD_KEY_1 0x1e
93 #define KBD_KEY_2 0x1f
94 #define KBD_KEY_3 0x20
95 #define KBD_KEY_4 0x21
96 #define KBD_KEY_5 0x22
97 #define KBD_KEY_6 0x23
98 #define KBD_KEY_7 0x24
99 #define KBD_KEY_8 0x25
100 #define KBD_KEY_9 0x26
101 #define KBD_KEY_0 0x27
102 #define KBD_KEY_ENTER 0x28
103 #define KBD_KEY_ESCAPE 0x29
104 #define KBD_KEY_BACKSPACE 0x2a
105 #define KBD_KEY_TAB 0x2b
106 #define KBD_KEY_SPACE 0x2c
107 #define KBD_KEY_MINUS 0x2d
108 #define KBD_KEY_PLUS 0x2e
109 #define KBD_KEY_LBRACKET 0x2f
110 #define KBD_KEY_RBRACKET 0x30
111 #define KBD_KEY_BACKSLASH 0x31
112 #define KBD_KEY_SEMICOLON 0x33
113 #define KBD_KEY_QUOTE 0x34
114 #define KBD_KEY_TILDE 0x35
115 #define KBD_KEY_COMMA 0x36
116 #define KBD_KEY_PERIOD 0x37
117 #define KBD_KEY_SLASH 0x38
118 #define KBD_KEY_CAPSLOCK 0x39
119 #define KBD_KEY_F1 0x3a
120 #define KBD_KEY_F2 0x3b
121 #define KBD_KEY_F3 0x3c
122 #define KBD_KEY_F4 0x3d
123 #define KBD_KEY_F5 0x3e
124 #define KBD_KEY_F6 0x3f
125 #define KBD_KEY_F7 0x40
126 #define KBD_KEY_F8 0x41
127 #define KBD_KEY_F9 0x42
128 #define KBD_KEY_F10 0x43
129 #define KBD_KEY_F11 0x44
130 #define KBD_KEY_F12 0x45
131 #define KBD_KEY_PRINT 0x46
132 #define KBD_KEY_SCRLOCK 0x47
133 #define KBD_KEY_PAUSE 0x48
134 #define KBD_KEY_INSERT 0x49
135 #define KBD_KEY_HOME 0x4a
136 #define KBD_KEY_PGUP 0x4b
137 #define KBD_KEY_DEL 0x4c
138 #define KBD_KEY_END 0x4d
139 #define KBD_KEY_PGDOWN 0x4e
140 #define KBD_KEY_RIGHT 0x4f
141 #define KBD_KEY_LEFT 0x50
142 #define KBD_KEY_DOWN 0x51
143 #define KBD_KEY_UP 0x52
144 #define KBD_KEY_PAD_NUMLOCK 0x53
145 #define KBD_KEY_PAD_DIVIDE 0x54
146 #define KBD_KEY_PAD_MULTIPLY 0x55
147 #define KBD_KEY_PAD_MINUS 0x56
148 #define KBD_KEY_PAD_PLUS 0x57
149 #define KBD_KEY_PAD_ENTER 0x58
150 #define KBD_KEY_PAD_1 0x59
151 #define KBD_KEY_PAD_2 0x5a
152 #define KBD_KEY_PAD_3 0x5b
153 #define KBD_KEY_PAD_4 0x5c
154 #define KBD_KEY_PAD_5 0x5d
155 #define KBD_KEY_PAD_6 0x5e
156 #define KBD_KEY_PAD_7 0x5f
157 #define KBD_KEY_PAD_8 0x60
158 #define KBD_KEY_PAD_9 0x61
159 #define KBD_KEY_PAD_0 0x62
160 #define KBD_KEY_PAD_PERIOD 0x63
161 #define KBD_KEY_S3 0x65
162 /** @} */
163 
164 /** \defgroup kbd_regions Keyboard region codes
165 
166  This is the list of possible values for the "region" field in the
167  kbd_state_t structure.
168  @{
169 */
170 #define KBD_REGION_JP 1 /**< \brief Japanese keyboard */
171 #define KBD_REGION_US 2 /**< \brief US keyboard */
172 /** @} */
173 
174 /** \brief Size of a keyboard queue.
175 
176  Each keyboard queue will hold this many elements. Once the queue fills, no
177  new elements will be placed on the queue. As long as you check the queue
178  relatively frequently, the default of 16 should be plenty.
179 
180  \note This <strong>MUST</strong> be a power of two.
181 */
182 #define KBD_QUEUE_SIZE 16
183 
184 /** \brief Keyboard keymap.
185 
186  This structure represents a mapping from raw key values to ASCII values, if
187  appropriate. This handles base values as well as shifted values.
188 
189  \headerfile dc/maple/keyboard.h
190 */
191 typedef struct kbd_keymap {
192  uint8 base[256];
194 } kbd_keymap_t;
195 
196 /** \brief Keyboard raw condition structure.
197 
198  This structure is what the keyboard responds with as its current status.
199 
200  \headerfile dc/maple/keyboard.h
201 */
202 typedef struct {
203  uint8 modifiers; /**< \brief Bitmask of set modifiers. */
204  uint8 leds; /**< \brief Bitmask of set LEDs */
205  uint8 keys[6]; /**< \brief Key codes for currently pressed keys. */
206 } kbd_cond_t;
207 
208 /** \brief Keyboard status structure.
209 
210  This structure holds information about the current status of the keyboard
211  device. This is what maple_dev_status() will return.
212 
213  \headerfile dc/maple/keyboard.h
214 */
215 typedef struct kbd_state {
216  /** \brief The lastest raw condition of the keyboard. */
218 
219  /** \brief Key array.
220 
221  This array lists the state of all possible keys on the keyboard. It can
222  be used for key repeat and debouncing. This will be non-zero if the key
223  is currently being pressed.
224 
225  \see kbd_keys
226  */
227  uint8 matrix[256];
228 
229  /** \brief Modifier key status. */
231 
232  /** \brief Keyboard type/region. */
233  int region;
234 
235  /** \brief Individual keyboard queue.
236  You should not access this variable directly. Please use the appropriate
237  function to access it. */
239  int queue_tail; /**< \brief Key queue tail. */
240  int queue_head; /**< \brief Key queue head. */
241  int queue_len; /**< \brief Current length of queue. */
242 } kbd_state_t;
243 
244 /** \brief Activate or deactivate global key queueing.
245 
246  This function will turn the internal keyboard queueing on or off. Note that
247  there is only one queue for the whole system, no matter how many keyboards
248  are attached, and the queue is of fairly limited length. Turning queueing
249  off is useful (for instance) in a game where individual keypresses don't
250  mean as much as having the keys up or down does.
251 
252  You can clear the queue (without popping all the keys off) by setting the
253  active value to a different value than it was.
254 
255  The queue is by default on, unless you turn it off.
256 
257  \param active Set to non-zero to activate the queue.
258  \note The global queue does not account for non-US
259  keyboard layouts and is deprecated. Please use the
260  individual queues instead for future code.
261 */
262 void kbd_set_queue(int active) __attribute__((deprecated));
263 
264 /** \brief Pop a key off the global keyboard queue.
265 
266  This function pops the front off of the keyboard queue, and returns the
267  value to the caller. The value returned will be the ASCII value of the key
268  pressed (accounting for the shift keys being pressed).
269 
270  If a key does not have an ASCII value associated with it, the raw key code
271  will be returned, shifted up by 8 bits.
272 
273  \return The value at the front of the queue, or -1 if there
274  are no keys in the queue or queueing is off.
275  \note This function does not account for non-US keyboard
276  layouts properly (for compatibility with old code),
277  and is deprecated. Use the individual keyboard
278  queues instead to properly account for non-US
279  keyboards.
280  \see kbd_queue_pop()
281 */
282 int kbd_get_key() __attribute__((deprecated));
283 
284 /** \brief Pop a key off a specific keyboard's queue.
285 
286  This function pops the front element off of the specified keyboard queue,
287  and returns the value of that key to the caller.
288 
289  If the xlat parameter is non-zero and the key represents an ISO-8859-1
290  character, that is the value that will be returned from this function.
291  Otherwise if xlat is non-zero, it will be the raw key code, shifted up by 8
292  bits.
293 
294  If the xlat parameter is zero, the lower 8 bits of the returned value will
295  be the raw key code. The next 8 bits will be the modifier keys that were
296  down when the key was pressed (a bitfield of KBD_MOD_* values). The next 3
297  bits will be the lock key status (a bitfield of KBD_LED_* values).
298 
299  \param dev The keyboard device to read from.
300  \param xlat Set to non-zero to do key translation. Otherwise,
301  you'll simply get the raw key value. Raw key values
302  are not mapped at all, so you are responsible for
303  figuring out what it is by the region.
304 
305  \return The value at the front of the queue, or -1 if there
306  are no keys in the queue.
307 */
308 int kbd_queue_pop(maple_device_t *dev, int xlat);
309 
310 /* \cond */
311 /* Init / Shutdown */
312 int kbd_init();
313 void kbd_shutdown();
314 /* \endcond */
315 
316 __END_DECLS
317 
318 #endif /* __DC_MAPLE_KEYBOARD_H */
319 
320 
Common integer types.
void kbd_set_queue(int active) __attribute__((deprecated))
Activate or deactivate global key queueing.
kbd_cond_t cond
The lastest raw condition of the keyboard.
Definition: keyboard.h:217
int kbd_get_key() __attribute__((deprecated))
Pop a key off the global keyboard queue.
One maple device.
Definition: maple.h:237
struct kbd_keymap kbd_keymap_t
Keyboard keymap.
Maple Bus driver interface.
int shift_keys
Modifier key status.
Definition: keyboard.h:230
uint8 matrix[256]
Key array.
Definition: keyboard.h:227
uint8 modifiers
Bitmask of set modifiers.
Definition: keyboard.h:203
Keyboard raw condition structure.
Definition: keyboard.h:202
int queue_head
Key queue head.
Definition: keyboard.h:240
#define KBD_QUEUE_SIZE
Size of a keyboard queue.
Definition: keyboard.h:182
uint32 key_queue[KBD_QUEUE_SIZE]
Individual keyboard queue. You should not access this variable directly. Please use the appropriate f...
Definition: keyboard.h:238
unsigned long uint32
32-bit unsigned integer
Definition: types.h:28
Keyboard keymap.
Definition: keyboard.h:191
struct kbd_state kbd_state_t
Keyboard status structure.
uint8 shifted[256]
Definition: keyboard.h:193
int queue_tail
Key queue tail.
Definition: keyboard.h:239
int kbd_queue_pop(maple_device_t *dev, int xlat)
Pop a key off a specific keyboard's queue.
int queue_len
Current length of queue.
Definition: keyboard.h:241
unsigned char uint8
8-bit unsigned integer
Definition: types.h:30
int region
Keyboard type/region.
Definition: keyboard.h:233
Keyboard status structure.
Definition: keyboard.h:215
uint8 leds
Bitmask of set LEDs.
Definition: keyboard.h:204
uint8 base[256]
Definition: keyboard.h:192