Detab
[AROS.git] / arch / i386-pc / drivers / keyboard / kbd.h
bloba16e5ea8c2e099e540f2199877c249d8932022cc
1 #ifndef HIDD_KBD_H
2 #define HIDD_KBD_H
4 /*
5 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: Include for the kbd HIDD.
9 Lang: English.
12 #ifndef EXEC_LIBRARIES_H
13 # include <exec/libraries.h>
14 #endif
16 #ifndef OOP_OOP_H
17 # include <oop/oop.h>
18 #endif
20 #ifndef EXEC_SEMAPHORES_H
21 # include <exec/semaphores.h>
22 #endif
24 #include <exec/interrupts.h>
25 #include <dos/bptr.h>
26 /****************************************************************************************/
28 #define KBD_STATUS_OBF 0x01 /* keyboard output buffer full */
29 #define KBD_STATUS_IBF 0x02 /* keyboard input buffer full */
30 #define KBD_STATUS_MOUSE_OBF 0x20 /* Mouse output buffer full */
31 #define KBD_STATUS_GTO 0x40 /* General receive/xmit timeout */
32 #define KBD_STATUS_PERR 0x80 /* Parity error */
34 #define KBD_CTRLCMD_READ_MODE 0x20
35 #define KBD_CTRLCMD_WRITE_MODE 0x60
36 #define KBD_CTRLCMD_GET_VERSION 0xA1
37 #define KBD_CTRLCMD_MOUSE_DISABLE 0xA7
38 #define KBD_CTRLCMD_MOUSE_ENABLE 0xA8
39 #define KBD_CTRLCMD_TEST_MOUSE 0xA9
40 #define KBD_CTRLCMD_SELF_TEST 0xAA
41 #define KBD_CTRLCMD_KBD_TEST 0xAB
42 #define KBD_CTRLCMD_KBD_DISABLE 0xAD
43 #define KBD_CTRLCMD_KBD_ENABLE 0xAE
44 #define KBD_CTRLCMD_WRITE_AUX_OBFU 0xD3
45 #define KBD_CTRLCMD_WRITE_MOUSE 0xD4
47 #define KBD_OUTCMD_SET_LEDS 0xED
48 #define KBD_OUTCMD_SET_RATE 0xF3
49 #define KBD_OUTCMD_ENABLE 0xF4
50 #define KBD_OUTCMD_DISABLE 0xF5
51 #define KBD_OUTCMD_RESET 0xFF
53 #define KBD_STATUS_REG 0x64
54 #define KBD_CONTROL_REG 0x64
55 #define KBD_DATA_REG 0x60
57 #define KBD_REPLY_POR 0xAA /* Power on reset */
58 #define KBD_REPLY_ACK 0xFA /* Command ACK */
59 #define KBD_REPLY_RESEND 0xFE /* Command NACK, send the cmd again */
61 #define KBD_MODE_KBD_INT 0x01 /* Keyboard data generate IRQ1 */
62 #define KBD_MODE_MOUSE_INT 0x02 /* Mouse data generate IRQ12 */
63 #define KBD_MODE_SYS 0x04 /* The system flag (?) */
64 #define KBD_MODE_NO_KEYLOCK 0x08 /* The keylock doesn't affect the keyboard if set */
65 #define KBD_MODE_DISABLE_KBD 0x10 /* Disable keyboard interface */
66 #define KBD_MODE_DISABLE_MOUSE 0x20 /* Disable mouse interface */
67 #define KBD_MODE_KCC 0x40 /* Scan code conversion to PC format */
68 #define KBD_MODE_RFU 0x80
70 /****************************************************************************************/
72 static inline unsigned char inb(unsigned short port)
75 unsigned char _v;
77 __asm__ __volatile__
78 ("inb %w1,%0"
79 : "=a" (_v)
80 : "Nd" (port)
83 return _v;
86 /****************************************************************************************/
88 static inline void outb(unsigned char value, unsigned short port)
90 __asm__ __volatile__
91 ("outb %b0,%w1"
93 : "a" (value), "Nd" (port)
97 /****************************************************************************************/
99 #define kbd_read_input() inb(KBD_DATA_REG)
100 #define kbd_read_status() inb(KBD_STATUS_REG)
101 #define kbd_write_output(val) outb(val, KBD_DATA_REG)
102 #define kbd_write_command(val) outb(val, KBD_CONTROL_REG)
104 /****************************************************************************************/
106 /***** Kbd HIDD *******************/
108 /* IDs */
109 #define IID_Hidd_HwKbd "hidd.kbd.hw"
110 #define CLID_Hidd_HwKbd "hidd.kbd.hw"
112 /* misc */
114 struct abdescr
116 STRPTR interfaceid;
117 OOP_AttrBase *attrbase;
120 struct kbd_staticdata
122 struct SignalSemaphore sema; /* Protexting this whole struct */
124 OOP_Class *kbdclass;
126 OOP_Object *kbdhidd;
128 OOP_AttrBase hiddKbdAB;
129 struct Interrupt irq;
131 BPTR cs_SegList;
132 struct Library *cs_OOPBase;
135 struct kbdbase
137 struct Library library;
139 struct kbd_staticdata ksd;
142 struct kbd_data
144 VOID (*kbd_callback)(APTR, UWORD);
145 APTR callbackdata;
147 ULONG kbd_keystate;
148 WORD prev_amigacode;
149 UWORD prev_keycode;
152 /****************************************************************************************/
154 BOOL obtainattrbases(struct abdescr *abd, struct Library *OOPBase);
155 VOID releaseattrbases(struct abdescr *abd, struct Library *OOPBase);
157 /****************************************************************************************/
159 #define XSD(cl) (&((struct kbdbase *)cl->UserData)->ksd)
161 /****************************************************************************************/
163 #endif /* HIDD_KBD_H */