Subversion Repositories shark

Rev

Rev 1015 | 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
 
1034 mauro 74
#define set_keyevt(k,a,c,f,s)   (k)->ascii  = a, \
75
                                (k)->scan   = c, \
76
                                (k)->flag   = f, \
77
                                (k)->status = s
78
 
826 mauro 79
#define isReleased(k)   ( ((k)->status & KEY_RELEASED) != 0 )
80
#define isPressed(k)    ( ((k)->status & KEY_PRESSED) != 0 )
81
#define isRepeated(k)   ( ((k)->status & KEY_REPEATED) != 0 )
519 mauro 82
 
826 mauro 83
#define isScanCode(k)   ((k)->flag & SCAN_BIT)
84
#define isLeftShift(k)  ((k)->flag & SHFL_BIT)
85
#define isRightShift(k) ((k)->flag & SHFR_BIT)
86
#define isLeftCtrl(k)   ((k)->flag & CNTL_BIT)
87
#define isRightCtrl(k)  ((k)->flag & CNTR_BIT)
88
#define isLeftAlt(k)    ((k)->flag & ALTL_BIT)
89
#define isRightAlt(k)   ((k)->flag & ALTR_BIT)
519 mauro 90
 
91
#define keyb_getchar()  keyb_getch(BLOCK)
92
 
523 mauro 93
/*
94
 * keyboard initialization
95
 */
96
 
97
/* the KEYB_PARMS structure used by KEYB26_init() */
519 mauro 98
typedef struct keyb_parms {
99
        TASK_MODEL *tm;
100
        unsigned char keymap;
101
        void  (*ctrlcfunc)(KEY_EVT *k);
1015 mauro 102
        int softrepeat;
519 mauro 103
} KEYB_PARMS;
104
 
105
#define KEYB_DEFAULT ((unsigned long)(-1))   /*+ used for default params +*/
106
 
107
#define BASE_KEYB       {(TASK_MODEL *)KEYB_DEFAULT, \
523 mauro 108
                         (unsigned char)KEYB_DEFAULT, \
1015 mauro 109
                         (void *)KEYB_DEFAULT, \
110
                         (int) KEYB_DEFAULT}
519 mauro 111
 
112
#define keyb_default_parm(m)    (m).tm = (TASK_MODEL *) KEYB_DEFAULT, \
113
                                (m).keymap = (unsigned char) KEYB_DEFAULT,  \
1015 mauro 114
                                (m).ctrlcfunc = (void *) KEYB_DEFAULT, \
115
                                (m).softrepeat = (int) KEYB_DEFAULT
519 mauro 116
 
523 mauro 117
#define keyb_def_map(s,m)       (s).keymap = (m)
118
#define keyb_def_ctrlC(s,f)     (s).ctrlcfunc = (f)
119
#define keyb_def_task(s,m)      (s).tm = (TASK_MODEL *)(m)
1015 mauro 120
#define keyb_def_srepeat(s,r)   (s).softrepeat = (r)
523 mauro 121
 
549 mauro 122
int  KEYB26_installed(void);
519 mauro 123
int  KEYB26_init(KEYB_PARMS *s);
124
int  KEYB26_close(void);
125
 
126
BYTE keyb_getch(BYTE wait);
127
int  keyb_getcode(KEY_EVT *k, BYTE wait);
1034 mauro 128
int  keyb_hook(KEY_EVT k, void (*f)(KEY_EVT *k), unsigned char l);
129
int  keyb_unhook(int index);
826 mauro 130
void keyb_enable(void);
131
void keyb_disable(void);
519 mauro 132
int  keyb_set_map(unsigned char m);
133
int  keyb_get_map(void);
134
 
135
#ifdef __cplusplus
136
};
137
#endif
138
 
139
#endif