Rev 826 | Rev 1034 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
519 | mauro | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * Massimiliano Giorgi <massy@gandalf.sssup.it> |
||
11 | * Luca Abeni <luca@gandalf.sssup.it> |
||
12 | * Mauro Marinoni <mauro.marinoni@unipv.it> |
||
13 | * (see the web pages for full authors list) |
||
14 | * |
||
15 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
16 | * |
||
17 | * http://www.sssup.it |
||
18 | * http://retis.sssup.it |
||
19 | * http://shark.sssup.it |
||
20 | */ |
||
21 | |||
22 | #ifndef __KEYB_H__ |
||
23 | #define __KEYB_H__ |
||
24 | |||
25 | #include <kernel/const.h> |
||
26 | #include <kernel/model.h> |
||
27 | |||
28 | #ifdef __cplusplus |
||
29 | extern "C" { |
||
30 | #endif |
||
31 | |||
32 | #include "keycode.h" |
||
33 | |||
34 | typedef struct { |
||
35 | BYTE useAltGr; |
||
36 | char keyMap [TABLE_KEY_SIZE]; |
||
37 | char keyShiftMap[TABLE_KEY_SIZE]; |
||
38 | char keyAltGrMap[TABLE_KEY_SIZE]; |
||
39 | } KEYB_MAP; |
||
40 | |||
41 | extern KEYB_MAP keyMaps[]; |
||
42 | |||
43 | #define KEYMAP_US 0 |
||
44 | #define KEYMAP_IT 1 |
||
45 | |||
46 | /* Key Status */ |
||
749 | mauro | 47 | #define KEY_RELEASED 1 |
48 | #define KEY_PRESSED 2 |
||
49 | #define KEY_REPEATED 4 |
||
519 | mauro | 50 | |
51 | /* Ascii Codes */ |
||
52 | #define BACKSPACE 0x08 |
||
53 | #define ENTER 0x0d |
||
54 | #define DELETE 0x18 |
||
55 | #define ESC 0x1b |
||
56 | #define TAB 0x09 |
||
57 | |||
58 | /* Flag Codes */ |
||
59 | #define ALTR_BIT 0x01 |
||
60 | #define ALTL_BIT 0x02 |
||
61 | #define CNTR_BIT 0x04 |
||
62 | #define CNTL_BIT 0x08 |
||
63 | #define SHFL_BIT 0x10 |
||
64 | #define SHFR_BIT 0x20 |
||
65 | #define SCAN_BIT 0x40 |
||
66 | |||
67 | typedef struct { |
||
68 | BYTE ascii; |
||
69 | BYTE scan; |
||
70 | BYTE flag; |
||
71 | BYTE status; |
||
72 | } KEY_EVT; |
||
73 | |||
826 | mauro | 74 | #define isReleased(k) ( ((k)->status & KEY_RELEASED) != 0 ) |
75 | #define isPressed(k) ( ((k)->status & KEY_PRESSED) != 0 ) |
||
76 | #define isRepeated(k) ( ((k)->status & KEY_REPEATED) != 0 ) |
||
519 | mauro | 77 | |
826 | mauro | 78 | #define isScanCode(k) ((k)->flag & SCAN_BIT) |
79 | #define isLeftShift(k) ((k)->flag & SHFL_BIT) |
||
80 | #define isRightShift(k) ((k)->flag & SHFR_BIT) |
||
81 | #define isLeftCtrl(k) ((k)->flag & CNTL_BIT) |
||
82 | #define isRightCtrl(k) ((k)->flag & CNTR_BIT) |
||
83 | #define isLeftAlt(k) ((k)->flag & ALTL_BIT) |
||
84 | #define isRightAlt(k) ((k)->flag & ALTR_BIT) |
||
519 | mauro | 85 | |
86 | #define keyb_getchar() keyb_getch(BLOCK) |
||
87 | |||
523 | mauro | 88 | /* |
89 | * keyboard initialization |
||
90 | */ |
||
91 | |||
92 | /* the KEYB_PARMS structure used by KEYB26_init() */ |
||
519 | mauro | 93 | typedef struct keyb_parms { |
94 | TASK_MODEL *tm; |
||
95 | unsigned char keymap; |
||
96 | void (*ctrlcfunc)(KEY_EVT *k); |
||
1015 | mauro | 97 | int softrepeat; |
519 | mauro | 98 | } KEYB_PARMS; |
99 | |||
100 | #define KEYB_DEFAULT ((unsigned long)(-1)) /*+ used for default params +*/ |
||
101 | |||
102 | #define BASE_KEYB {(TASK_MODEL *)KEYB_DEFAULT, \ |
||
523 | mauro | 103 | (unsigned char)KEYB_DEFAULT, \ |
1015 | mauro | 104 | (void *)KEYB_DEFAULT, \ |
105 | (int) KEYB_DEFAULT} |
||
519 | mauro | 106 | |
107 | #define keyb_default_parm(m) (m).tm = (TASK_MODEL *) KEYB_DEFAULT, \ |
||
108 | (m).keymap = (unsigned char) KEYB_DEFAULT, \ |
||
1015 | mauro | 109 | (m).ctrlcfunc = (void *) KEYB_DEFAULT, \ |
110 | (m).softrepeat = (int) KEYB_DEFAULT |
||
519 | mauro | 111 | |
523 | mauro | 112 | #define keyb_def_map(s,m) (s).keymap = (m) |
113 | #define keyb_def_ctrlC(s,f) (s).ctrlcfunc = (f) |
||
114 | #define keyb_def_task(s,m) (s).tm = (TASK_MODEL *)(m) |
||
1015 | mauro | 115 | #define keyb_def_srepeat(s,r) (s).softrepeat = (r) |
523 | mauro | 116 | |
549 | mauro | 117 | int KEYB26_installed(void); |
519 | mauro | 118 | int KEYB26_init(KEYB_PARMS *s); |
119 | int KEYB26_close(void); |
||
120 | |||
121 | BYTE keyb_getch(BYTE wait); |
||
122 | int keyb_getcode(KEY_EVT *k, BYTE wait); |
||
123 | void keyb_hook(KEY_EVT k, void (*f)(KEY_EVT *k), unsigned char l); |
||
826 | mauro | 124 | void keyb_enable(void); |
125 | void keyb_disable(void); |
||
519 | mauro | 126 | int keyb_set_map(unsigned char m); |
127 | int keyb_get_map(void); |
||
128 | |||
129 | #ifdef __cplusplus |
||
130 | }; |
||
131 | #endif |
||
132 | |||
133 | #endif |