]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/hidsystem/drvApplePS2Keyboard/ApplePS2Keyboard.h
0db532e58fe28adc1893de2514cc101d02a33fc7
[apple/xnu.git] / iokit / Drivers / hidsystem / drvApplePS2Keyboard / ApplePS2Keyboard.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #ifndef _APPLEPS2KEYBOARD_H
24 #define _APPLEPS2KEYBOARD_H
25
26 #include <IOKit/ps2/ApplePS2KeyboardDevice.h>
27 #include <IOKit/hidsystem/IOHIKeyboard.h>
28
29 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 // Definitions used to keep track of key state. Key up/down state is tracked
31 // in a bit list. Bits are set for key-down, and cleared for key-up. The bit
32 // vector and macros for it's manipulation are defined here.
33 //
34
35 #define KBV_NUM_KEYCODES 128
36 #define KBV_BITS_PER_UNIT 32 // for UInt32
37 #define KBV_BITS_MASK 31
38 #define KBV_BITS_SHIFT 5 // 1<<5 == 32, for cheap divide
39 #define KBV_NUNITS ((KBV_NUM_KEYCODES + \
40 (KBV_BITS_PER_UNIT-1))/KBV_BITS_PER_UNIT)
41
42 #define KBV_KEYDOWN(n, bits) \
43 (bits)[((n)>>KBV_BITS_SHIFT)] |= (1 << ((n) & KBV_BITS_MASK))
44
45 #define KBV_KEYUP(n, bits) \
46 (bits)[((n)>>KBV_BITS_SHIFT)] &= ~(1 << ((n) & KBV_BITS_MASK))
47
48 #define KBV_IS_KEYDOWN(n, bits) \
49 (((bits)[((n)>>KBV_BITS_SHIFT)] & (1 << ((n) & KBV_BITS_MASK))) != 0)
50
51 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 // ApplePS2Keyboard Class Declaration
53 //
54
55 class ApplePS2Keyboard : public IOHIKeyboard
56 {
57 OSDeclareDefaultStructors(ApplePS2Keyboard);
58
59 private:
60 ApplePS2KeyboardDevice * _device;
61 UInt32 _keyBitVector[KBV_NUNITS];
62 UInt8 _extendCount;
63 UInt8 _interruptHandlerInstalled:1;
64 UInt8 _ledState;
65
66 virtual bool dispatchKeyboardEventWithScancode(UInt8 scanCode);
67 virtual void setCommandByte(UInt8 setBits, UInt8 clearBits);
68 virtual void setLEDs(UInt8 ledState);
69 virtual void setKeyboardEnable(bool enable);
70
71 protected:
72 virtual const unsigned char * defaultKeymapOfLength(UInt32 * length);
73 virtual void setAlphaLockFeedback(bool locked);
74 virtual UInt32 maxKeyCodes();
75
76 public:
77 virtual bool init(OSDictionary * properties);
78 virtual ApplePS2Keyboard * probe(IOService * provider, SInt32 * score);
79
80 virtual bool start(IOService * provider);
81 virtual void stop(IOService * provider);
82
83 virtual void interruptOccurred(UInt8 scanCode);
84
85 virtual UInt32 deviceType();
86 virtual UInt32 interfaceID();
87 };
88
89 #endif /* _APPLEPS2KEYBOARD_H */