Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: request.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)request.fth 1.1 07/01/24 | |
43 | purpose: USB HID requests | |
44 | copyright: Copyright 2007 Sun Microsystems, Inc. All Rights Reserved | |
45 | \ See license at end of file | |
46 | ||
47 | hex | |
48 | headers | |
49 | ||
50 | \ >dr-request constants specific to HID | |
51 | h# 01 constant GET_REPORT | |
52 | h# 02 constant GET_IDLE | |
53 | h# 03 constant GET_PROTOCOL | |
54 | h# 09 constant SET_REPORT | |
55 | h# 0a constant SET_IDLE | |
56 | h# 0b constant SET_PROTOCOL | |
57 | ||
58 | \ >dr-value constants specific to HID | |
59 | h# 0100 constant REPORT_IN | |
60 | h# 0200 constant REPORT_OUT | |
61 | h# 0300 constant REPORT_FEATURE | |
62 | ||
63 | \ Keyboard report and LED buffers | |
64 | 8 constant /kbd-buf | |
65 | 1 constant /led-buf | |
66 | 0 value kbd-buf | |
67 | 0 value led-buf | |
68 | ||
69 | : init-kbd-buf ( -- ) | |
70 | kbd-buf 0= if | |
71 | /kbd-buf /led-buf + dma-alloc | |
72 | dup to kbd-buf /kbd-buf + to led-buf | |
73 | then | |
74 | ; | |
75 | : free-kbd-buf ( -- ) | |
76 | kbd-buf if | |
77 | kbd-buf /kbd-buf /led-buf + dma-free | |
78 | 0 to kbd-buf 0 to led-buf | |
79 | then | |
80 | ; | |
81 | ||
82 | : set-boot-protocol ( -- error? ) | |
83 | 0 0 my-address ( interface ) 0 DR_HIDD DR_OUT or SET_PROTOCOL | |
84 | control-set-nostat | |
85 | ; | |
86 | ||
87 | : set-idle ( ms -- error? ) | |
88 | >r 0 0 my-address ( interface ) r> 4 / 8 << ( 4ms ) DR_HIDD DR_OUT or SET_IDLE | |
89 | control-set-nostat | |
90 | ; | |
91 | ||
92 | \ Key modifiers | |
93 | ||
94 | 0 value led-state | |
95 | 1 constant led-mask-num-lock | |
96 | 2 constant led-mask-caps-lock | |
97 | 4 constant led-mask-scroll-lock | |
98 | ||
99 | : numlk? ( -- flag ) led-state led-mask-num-lock and 0<> ; | |
100 | : caps-lock? ( -- flag ) led-state led-mask-caps-lock and 0<> ; | |
101 | : scroll-lock? ( -- flag ) led-state led-mask-scroll-lock and 0<> ; | |
102 | ||
103 | ||
104 | \ Keyboard LEDs | |
105 | ||
106 | : (set-leds) ( led -- ) | |
107 | led-buf c! | |
108 | led-buf /led-buf my-address ( interface ) REPORT_OUT DR_HIDD DR_OUT or SET_REPORT | |
109 | control-set-nostat drop | |
110 | ; | |
111 | : set-leds ( led-mask -- ) dup to led-state (set-leds) ; | |
112 | : toggle-leds ( led-mask -- ) led-state xor set-leds ; | |
113 | ||
114 | ||
115 | \ Retrieve usb keyboard report data. | |
116 | ||
117 | : begin-scan ( -- ) | |
118 | kbd-buf /kbd-buf intr-in-pipe intr-in-interval begin-intr-in | |
119 | ; | |
120 | : end-scan ( -- ) end-intr-in ; | |
121 | ||
122 | : get-data? ( adr len -- actual ) | |
123 | intr-in? if nip nip restart-intr-in exit then \ USB error; restart | |
124 | ?dup if ( adr len actual ) | |
125 | min tuck kbd-buf -rot move ( actual ) | |
126 | restart-intr-in ( actual ) | |
127 | else | |
128 | 2drop 0 ( actual ) | |
129 | then | |
130 | ; | |
131 | ||
132 | \ Sun adds ability to detect keyboard country from HID descriptor | |
133 | \ for Sun type 6 and type 7 keyboards. This capability will be lost | |
134 | \ in type 7c keyboards (which no longer have a country code), but | |
135 | \ we still have to support existing hardware. | |
136 | \ | |
137 | \ We read the HID descriptor from the interface. See HID device | |
138 | \ class specification, from: | |
139 | \ http://www.usb.org/developers/devclass_docs/HID1_11.pdf | |
140 | \ Section 6.2.1 HID Descriptor defines this structure. Offset | |
141 | \ 4 (listed as 4/1, offset 4, one byte long) is the bCountryCode | |
142 | \ which this routine returns. | |
143 | \ | |
144 | \ This method gets called infrequently, so we do our own alloc/free | |
145 | \ rather than doing a top-level alloc/free like kbd-buf. | |
146 | ||
147 | h# 10 constant /HID_DESC | |
148 | ||
149 | : get-kbd-cntry-id ( -- country-code ) | |
150 | /HID_DESC dma-alloc dup /HID_DESC ( addr addr len ) | |
151 | ||
152 | 0 0 DR_HIDD DR_INTERFACE get-desc 2drop ( addr ) | |
153 | dup 4 + c@ swap ( country-code addr ) | |
154 | /HID_DESC dma-free ( country-code ) | |
155 | ; | |
156 | ||
157 | \ LICENSE_BEGIN | |
158 | \ Copyright (c) 2006 FirmWorks | |
159 | \ | |
160 | \ Permission is hereby granted, free of charge, to any person obtaining | |
161 | \ a copy of this software and associated documentation files (the | |
162 | \ "Software"), to deal in the Software without restriction, including | |
163 | \ without limitation the rights to use, copy, modify, merge, publish, | |
164 | \ distribute, sublicense, and/or sell copies of the Software, and to | |
165 | \ permit persons to whom the Software is furnished to do so, subject to | |
166 | \ the following conditions: | |
167 | \ | |
168 | \ The above copyright notice and this permission notice shall be | |
169 | \ included in all copies or substantial portions of the Software. | |
170 | \ | |
171 | \ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
172 | \ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
173 | \ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
174 | \ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
175 | \ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
176 | \ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
177 | \ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
178 | \ | |
179 | \ LICENSE_END |