root / hw / baum.c @ 3d53f5c3
History | View | Annotate | Download (20 kB)
1 | 2e4d9fb1 | aurel32 | /*
|
---|---|---|---|
2 | 2e4d9fb1 | aurel32 | * QEMU Baum Braille Device
|
3 | 2e4d9fb1 | aurel32 | *
|
4 | 2e4d9fb1 | aurel32 | * Copyright (c) 2008 Samuel Thibault
|
5 | 2e4d9fb1 | aurel32 | *
|
6 | 2e4d9fb1 | aurel32 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 2e4d9fb1 | aurel32 | * of this software and associated documentation files (the "Software"), to deal
|
8 | 2e4d9fb1 | aurel32 | * in the Software without restriction, including without limitation the rights
|
9 | 2e4d9fb1 | aurel32 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 2e4d9fb1 | aurel32 | * copies of the Software, and to permit persons to whom the Software is
|
11 | 2e4d9fb1 | aurel32 | * furnished to do so, subject to the following conditions:
|
12 | 2e4d9fb1 | aurel32 | *
|
13 | 2e4d9fb1 | aurel32 | * The above copyright notice and this permission notice shall be included in
|
14 | 2e4d9fb1 | aurel32 | * all copies or substantial portions of the Software.
|
15 | 2e4d9fb1 | aurel32 | *
|
16 | 2e4d9fb1 | aurel32 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 2e4d9fb1 | aurel32 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 2e4d9fb1 | aurel32 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 2e4d9fb1 | aurel32 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 2e4d9fb1 | aurel32 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 2e4d9fb1 | aurel32 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 2e4d9fb1 | aurel32 | * THE SOFTWARE.
|
23 | 2e4d9fb1 | aurel32 | */
|
24 | 2e4d9fb1 | aurel32 | #include "qemu-common.h" |
25 | 2e4d9fb1 | aurel32 | #include "qemu-char.h" |
26 | 2e4d9fb1 | aurel32 | #include "qemu-timer.h" |
27 | 2e4d9fb1 | aurel32 | #include "usb.h" |
28 | c78eae61 | aurel32 | #include "baum.h" |
29 | 2e4d9fb1 | aurel32 | #include <brlapi.h> |
30 | 2e4d9fb1 | aurel32 | #include <brlapi_constants.h> |
31 | 2e4d9fb1 | aurel32 | #include <brlapi_keycodes.h> |
32 | 2e4d9fb1 | aurel32 | #ifdef CONFIG_SDL
|
33 | 6693665a | Stefan Weil | #include <SDL_syswm.h> |
34 | 2e4d9fb1 | aurel32 | #endif
|
35 | 2e4d9fb1 | aurel32 | |
36 | 2e4d9fb1 | aurel32 | #if 0
|
37 | 2e4d9fb1 | aurel32 | #define DPRINTF(fmt, ...) \
|
38 | 2e4d9fb1 | aurel32 | printf(fmt, ## __VA_ARGS__)
|
39 | 2e4d9fb1 | aurel32 | #else
|
40 | 2e4d9fb1 | aurel32 | #define DPRINTF(fmt, ...)
|
41 | 2e4d9fb1 | aurel32 | #endif
|
42 | 2e4d9fb1 | aurel32 | |
43 | 2e4d9fb1 | aurel32 | #define ESC 0x1B |
44 | 2e4d9fb1 | aurel32 | |
45 | 2e4d9fb1 | aurel32 | #define BAUM_REQ_DisplayData 0x01 |
46 | 2e4d9fb1 | aurel32 | #define BAUM_REQ_GetVersionNumber 0x05 |
47 | 2e4d9fb1 | aurel32 | #define BAUM_REQ_GetKeys 0x08 |
48 | 2e4d9fb1 | aurel32 | #define BAUM_REQ_SetMode 0x12 |
49 | 2e4d9fb1 | aurel32 | #define BAUM_REQ_SetProtocol 0x15 |
50 | 2e4d9fb1 | aurel32 | #define BAUM_REQ_GetDeviceIdentity 0x84 |
51 | 2e4d9fb1 | aurel32 | #define BAUM_REQ_GetSerialNumber 0x8A |
52 | 2e4d9fb1 | aurel32 | |
53 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_CellCount 0x01 |
54 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_VersionNumber 0x05 |
55 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_ModeSetting 0x11 |
56 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_CommunicationChannel 0x16 |
57 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_PowerdownSignal 0x17 |
58 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_HorizontalSensors 0x20 |
59 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_VerticalSensors 0x21 |
60 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_RoutingKeys 0x22 |
61 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_Switches 0x23 |
62 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_TopKeys 0x24 |
63 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_HorizontalSensor 0x25 |
64 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_VerticalSensor 0x26 |
65 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_RoutingKey 0x27 |
66 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_FrontKeys6 0x28 |
67 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_BackKeys6 0x29 |
68 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_CommandKeys 0x2B |
69 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_FrontKeys10 0x2C |
70 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_BackKeys10 0x2D |
71 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_EntryKeys 0x33 |
72 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_JoyStick 0x34 |
73 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_ErrorCode 0x40 |
74 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_InfoBlock 0x42 |
75 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_DeviceIdentity 0x84 |
76 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_SerialNumber 0x8A |
77 | 2e4d9fb1 | aurel32 | #define BAUM_RSP_BluetoothName 0x8C |
78 | 2e4d9fb1 | aurel32 | |
79 | 2e4d9fb1 | aurel32 | #define BAUM_TL1 0x01 |
80 | 2e4d9fb1 | aurel32 | #define BAUM_TL2 0x02 |
81 | 2e4d9fb1 | aurel32 | #define BAUM_TL3 0x04 |
82 | 2e4d9fb1 | aurel32 | #define BAUM_TR1 0x08 |
83 | 2e4d9fb1 | aurel32 | #define BAUM_TR2 0x10 |
84 | 2e4d9fb1 | aurel32 | #define BAUM_TR3 0x20 |
85 | 2e4d9fb1 | aurel32 | |
86 | 2e4d9fb1 | aurel32 | #define BUF_SIZE 256 |
87 | 2e4d9fb1 | aurel32 | |
88 | 2e4d9fb1 | aurel32 | typedef struct { |
89 | 2e4d9fb1 | aurel32 | CharDriverState *chr; |
90 | 2e4d9fb1 | aurel32 | |
91 | 2e4d9fb1 | aurel32 | brlapi_handle_t *brlapi; |
92 | 2e4d9fb1 | aurel32 | int brlapi_fd;
|
93 | 4f72c4dd | Blue Swirl | unsigned int x, y; |
94 | 2e4d9fb1 | aurel32 | |
95 | 2e4d9fb1 | aurel32 | uint8_t in_buf[BUF_SIZE]; |
96 | 2e4d9fb1 | aurel32 | uint8_t in_buf_used; |
97 | 2e4d9fb1 | aurel32 | uint8_t out_buf[BUF_SIZE]; |
98 | 2e4d9fb1 | aurel32 | uint8_t out_buf_used, out_buf_ptr; |
99 | 2e4d9fb1 | aurel32 | |
100 | 2e4d9fb1 | aurel32 | QEMUTimer *cellCount_timer; |
101 | 2e4d9fb1 | aurel32 | } BaumDriverState; |
102 | 2e4d9fb1 | aurel32 | |
103 | 2e4d9fb1 | aurel32 | /* Let's assume NABCC by default */
|
104 | 2e4d9fb1 | aurel32 | static const uint8_t nabcc_translation[256] = { |
105 | 2e4d9fb1 | aurel32 | [0] = ' ', |
106 | 2e4d9fb1 | aurel32 | #ifndef BRLAPI_DOTS
|
107 | 2e4d9fb1 | aurel32 | #define BRLAPI_DOTS(d1,d2,d3,d4,d5,d6,d7,d8) \
|
108 | 2e4d9fb1 | aurel32 | ((d1?BRLAPI_DOT1:0)|\
|
109 | 2e4d9fb1 | aurel32 | (d2?BRLAPI_DOT2:0)|\
|
110 | 2e4d9fb1 | aurel32 | (d3?BRLAPI_DOT3:0)|\
|
111 | 2e4d9fb1 | aurel32 | (d4?BRLAPI_DOT4:0)|\
|
112 | 2e4d9fb1 | aurel32 | (d5?BRLAPI_DOT5:0)|\
|
113 | 2e4d9fb1 | aurel32 | (d6?BRLAPI_DOT6:0)|\
|
114 | 2e4d9fb1 | aurel32 | (d7?BRLAPI_DOT7:0)|\
|
115 | 2e4d9fb1 | aurel32 | (d8?BRLAPI_DOT8:0))
|
116 | 2e4d9fb1 | aurel32 | #endif
|
117 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,0,0,0,0,0)] = 'a', |
118 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,0,0,0,0,0)] = 'b', |
119 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,1,0,0,0,0)] = 'c', |
120 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,1,1,0,0,0)] = 'd', |
121 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,0,1,0,0,0)] = 'e', |
122 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,1,0,0,0,0)] = 'f', |
123 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,1,1,0,0,0)] = 'g', |
124 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,0,1,0,0,0)] = 'h', |
125 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,1,0,0,0,0)] = 'i', |
126 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,1,1,0,0,0)] = 'j', |
127 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,0,0,0,0,0)] = 'k', |
128 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,0,0,0,0,0)] = 'l', |
129 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,1,0,0,0,0)] = 'm', |
130 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,1,1,0,0,0)] = 'n', |
131 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,0,1,0,0,0)] = 'o', |
132 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,1,0,0,0,0)] = 'p', |
133 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,1,1,0,0,0)] = 'q', |
134 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,0,1,0,0,0)] = 'r', |
135 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,1,0,0,0,0)] = 's', |
136 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,1,1,0,0,0)] = 't', |
137 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,0,0,1,0,0)] = 'u', |
138 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,0,0,1,0,0)] = 'v', |
139 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,1,1,1,0,0)] = 'w', |
140 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,1,0,1,0,0)] = 'x', |
141 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,1,1,1,0,0)] = 'y', |
142 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,0,1,1,0,0)] = 'z', |
143 | 2e4d9fb1 | aurel32 | |
144 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,0,0,0,1,0)] = 'A', |
145 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,0,0,0,1,0)] = 'B', |
146 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,1,0,0,1,0)] = 'C', |
147 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,1,1,0,1,0)] = 'D', |
148 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,0,1,0,1,0)] = 'E', |
149 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,1,0,0,1,0)] = 'F', |
150 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,1,1,0,1,0)] = 'G', |
151 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,0,1,0,1,0)] = 'H', |
152 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,1,0,0,1,0)] = 'I', |
153 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,1,1,0,1,0)] = 'J', |
154 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,0,0,0,1,0)] = 'K', |
155 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,0,0,0,1,0)] = 'L', |
156 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,1,0,0,1,0)] = 'M', |
157 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,1,1,0,1,0)] = 'N', |
158 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,0,1,0,1,0)] = 'O', |
159 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,1,0,0,1,0)] = 'P', |
160 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,1,1,0,1,0)] = 'Q', |
161 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,0,1,0,1,0)] = 'R', |
162 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,1,0,0,1,0)] = 'S', |
163 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,1,1,0,1,0)] = 'T', |
164 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,0,0,1,1,0)] = 'U', |
165 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,0,0,1,1,0)] = 'V', |
166 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,1,1,1,1,0)] = 'W', |
167 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,1,0,1,1,0)] = 'X', |
168 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,1,1,1,1,0)] = 'Y', |
169 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,1,0,1,1,1,0)] = 'Z', |
170 | 2e4d9fb1 | aurel32 | |
171 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,1,0,1,1,0,0)] = '0', |
172 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,0,0,0,0,0)] = '1', |
173 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,0,0,0,0,0)] = '2', |
174 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,0,1,0,0,0)] = '3', |
175 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,0,1,1,0,0)] = '4', |
176 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,0,0,1,0,0)] = '5', |
177 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,0,1,0,0,0)] = '6', |
178 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,0,1,1,0,0)] = '7', |
179 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,0,0,1,0,0)] = '8', |
180 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,1,0,1,0,0,0)] = '9', |
181 | 2e4d9fb1 | aurel32 | |
182 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,1,0,1,0,0)] = '.', |
183 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,1,1,0,1,0,0)] = '+', |
184 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,1,0,0,1,0,0)] = '-', |
185 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,0,0,1,0,0)] = '*', |
186 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,1,1,0,0,0,0)] = '/', |
187 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,0,1,1,0,0)] = '(', |
188 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,1,1,1,0,0)] = ')', |
189 | 2e4d9fb1 | aurel32 | |
190 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,1,0,1,0,0)] = '&', |
191 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,1,1,1,1,0,0)] = '#', |
192 | 2e4d9fb1 | aurel32 | |
193 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,0,0,1,0,0)] = ',', |
194 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,0,1,1,0,0)] = ';', |
195 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,0,1,1,0,0)] = ':', |
196 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,1,1,0,1,0,0)] = '!', |
197 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,1,1,1,0,0)] = '?', |
198 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,0,1,0,0,0)] = '"', |
199 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,1,0,0,0,0,0)] ='\'', |
200 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,1,0,0,0,0)] = '`', |
201 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,1,1,0,1,0)] = '^', |
202 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,1,1,0,0,0)] = '~', |
203 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,1,0,1,1,0)] = '[', |
204 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,1,1,1,1,0)] = ']', |
205 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,1,0,1,0,1,0,0)] = '{', |
206 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,1,1,1,0,0)] = '}', |
207 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,1,1,1,1,0,0)] = '=', |
208 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,0,0,1,0,0)] = '<', |
209 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,1,1,1,0,0,0)] = '>', |
210 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,1,0,1,0,0)] = '$', |
211 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,0,0,1,0,1,0,0)] = '%', |
212 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,1,0,0,1,0)] = '@', |
213 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,0,1,1,0,0)] = '|', |
214 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(1,1,0,0,1,1,1,0)] ='\\', |
215 | 2e4d9fb1 | aurel32 | [BRLAPI_DOTS(0,0,0,1,1,1,0,0)] = '_', |
216 | 2e4d9fb1 | aurel32 | }; |
217 | 2e4d9fb1 | aurel32 | |
218 | 2e4d9fb1 | aurel32 | /* The serial port can receive more of our data */
|
219 | 2e4d9fb1 | aurel32 | static void baum_accept_input(struct CharDriverState *chr) |
220 | 2e4d9fb1 | aurel32 | { |
221 | 2e4d9fb1 | aurel32 | BaumDriverState *baum = chr->opaque; |
222 | 2e4d9fb1 | aurel32 | int room, first;
|
223 | 2e4d9fb1 | aurel32 | |
224 | 2e4d9fb1 | aurel32 | if (!baum->out_buf_used)
|
225 | 2e4d9fb1 | aurel32 | return;
|
226 | 2e4d9fb1 | aurel32 | room = qemu_chr_can_read(chr); |
227 | 2e4d9fb1 | aurel32 | if (!room)
|
228 | 2e4d9fb1 | aurel32 | return;
|
229 | 2e4d9fb1 | aurel32 | if (room > baum->out_buf_used)
|
230 | 2e4d9fb1 | aurel32 | room = baum->out_buf_used; |
231 | 2e4d9fb1 | aurel32 | |
232 | 2e4d9fb1 | aurel32 | first = BUF_SIZE - baum->out_buf_ptr; |
233 | 2e4d9fb1 | aurel32 | if (room > first) {
|
234 | 2e4d9fb1 | aurel32 | qemu_chr_read(chr, baum->out_buf + baum->out_buf_ptr, first); |
235 | 2e4d9fb1 | aurel32 | baum->out_buf_ptr = 0;
|
236 | 2e4d9fb1 | aurel32 | baum->out_buf_used -= first; |
237 | 2e4d9fb1 | aurel32 | room -= first; |
238 | 2e4d9fb1 | aurel32 | } |
239 | 2e4d9fb1 | aurel32 | qemu_chr_read(chr, baum->out_buf + baum->out_buf_ptr, room); |
240 | 2e4d9fb1 | aurel32 | baum->out_buf_ptr += room; |
241 | 2e4d9fb1 | aurel32 | baum->out_buf_used -= room; |
242 | 2e4d9fb1 | aurel32 | } |
243 | 2e4d9fb1 | aurel32 | |
244 | 2e4d9fb1 | aurel32 | /* We want to send a packet */
|
245 | 2e4d9fb1 | aurel32 | static void baum_write_packet(BaumDriverState *baum, const uint8_t *buf, int len) |
246 | 2e4d9fb1 | aurel32 | { |
247 | 2e4d9fb1 | aurel32 | uint8_t io_buf[1 + 2 * len], *cur = io_buf; |
248 | 2e4d9fb1 | aurel32 | int room;
|
249 | 2e4d9fb1 | aurel32 | *cur++ = ESC; |
250 | 2e4d9fb1 | aurel32 | while (len--)
|
251 | 2e4d9fb1 | aurel32 | if ((*cur++ = *buf++) == ESC)
|
252 | 2e4d9fb1 | aurel32 | *cur++ = ESC; |
253 | 2e4d9fb1 | aurel32 | room = qemu_chr_can_read(baum->chr); |
254 | 2e4d9fb1 | aurel32 | len = cur - io_buf; |
255 | 2e4d9fb1 | aurel32 | if (len <= room) {
|
256 | 2e4d9fb1 | aurel32 | /* Fits */
|
257 | 2e4d9fb1 | aurel32 | qemu_chr_read(baum->chr, io_buf, len); |
258 | 2e4d9fb1 | aurel32 | } else {
|
259 | 2e4d9fb1 | aurel32 | int first;
|
260 | 2e4d9fb1 | aurel32 | uint8_t out; |
261 | 2e4d9fb1 | aurel32 | /* Can't fit all, send what can be, and store the rest. */
|
262 | 2e4d9fb1 | aurel32 | qemu_chr_read(baum->chr, io_buf, room); |
263 | 2e4d9fb1 | aurel32 | len -= room; |
264 | 2e4d9fb1 | aurel32 | cur = io_buf + room; |
265 | 2e4d9fb1 | aurel32 | if (len > BUF_SIZE - baum->out_buf_used) {
|
266 | 2e4d9fb1 | aurel32 | /* Can't even store it, drop the previous data... */
|
267 | 2e4d9fb1 | aurel32 | assert(len <= BUF_SIZE); |
268 | 2e4d9fb1 | aurel32 | baum->out_buf_used = 0;
|
269 | 2e4d9fb1 | aurel32 | baum->out_buf_ptr = 0;
|
270 | 2e4d9fb1 | aurel32 | } |
271 | 2e4d9fb1 | aurel32 | out = baum->out_buf_ptr; |
272 | 2e4d9fb1 | aurel32 | baum->out_buf_used += len; |
273 | 2e4d9fb1 | aurel32 | first = BUF_SIZE - baum->out_buf_ptr; |
274 | 2e4d9fb1 | aurel32 | if (len > first) {
|
275 | 2e4d9fb1 | aurel32 | memcpy(baum->out_buf + out, cur, first); |
276 | 2e4d9fb1 | aurel32 | out = 0;
|
277 | 2e4d9fb1 | aurel32 | len -= first; |
278 | 2e4d9fb1 | aurel32 | cur += first; |
279 | 2e4d9fb1 | aurel32 | } |
280 | 2e4d9fb1 | aurel32 | memcpy(baum->out_buf + out, cur, len); |
281 | 2e4d9fb1 | aurel32 | } |
282 | 2e4d9fb1 | aurel32 | } |
283 | 2e4d9fb1 | aurel32 | |
284 | 2e4d9fb1 | aurel32 | /* Called when the other end seems to have a wrong idea of our display size */
|
285 | 2e4d9fb1 | aurel32 | static void baum_cellCount_timer_cb(void *opaque) |
286 | 2e4d9fb1 | aurel32 | { |
287 | 2e4d9fb1 | aurel32 | BaumDriverState *baum = opaque; |
288 | 2e4d9fb1 | aurel32 | uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y }; |
289 | 2e4d9fb1 | aurel32 | DPRINTF("Timeout waiting for DisplayData, sending cell count\n");
|
290 | 2e4d9fb1 | aurel32 | baum_write_packet(baum, cell_count, sizeof(cell_count));
|
291 | 2e4d9fb1 | aurel32 | } |
292 | 2e4d9fb1 | aurel32 | |
293 | 2e4d9fb1 | aurel32 | /* Try to interpret a whole incoming packet */
|
294 | 2e4d9fb1 | aurel32 | static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len) |
295 | 2e4d9fb1 | aurel32 | { |
296 | 2e4d9fb1 | aurel32 | const uint8_t *cur = buf;
|
297 | 2e4d9fb1 | aurel32 | uint8_t req = 0;
|
298 | 2e4d9fb1 | aurel32 | |
299 | 2e4d9fb1 | aurel32 | if (!len--)
|
300 | 2e4d9fb1 | aurel32 | return 0; |
301 | 2e4d9fb1 | aurel32 | if (*cur++ != ESC) {
|
302 | 2e4d9fb1 | aurel32 | while (*cur != ESC) {
|
303 | 2e4d9fb1 | aurel32 | if (!len--)
|
304 | 2e4d9fb1 | aurel32 | return 0; |
305 | 2e4d9fb1 | aurel32 | cur++; |
306 | 2e4d9fb1 | aurel32 | } |
307 | 2e4d9fb1 | aurel32 | DPRINTF("Dropped %d bytes!\n", cur - buf);
|
308 | 2e4d9fb1 | aurel32 | } |
309 | 2e4d9fb1 | aurel32 | |
310 | 2e4d9fb1 | aurel32 | #define EAT(c) do {\ |
311 | 2e4d9fb1 | aurel32 | if (!len--) \
|
312 | 2e4d9fb1 | aurel32 | return 0; \ |
313 | 2e4d9fb1 | aurel32 | if ((c = *cur++) == ESC) { \
|
314 | 2e4d9fb1 | aurel32 | if (!len--) \
|
315 | 2e4d9fb1 | aurel32 | return 0; \ |
316 | 2e4d9fb1 | aurel32 | if (*cur++ != ESC) { \
|
317 | 2e4d9fb1 | aurel32 | DPRINTF("Broken packet %#2x, tossing\n", req); \
|
318 | 2e4d9fb1 | aurel32 | if (qemu_timer_pending(baum->cellCount_timer)) { \
|
319 | 2e4d9fb1 | aurel32 | qemu_del_timer(baum->cellCount_timer); \ |
320 | 2e4d9fb1 | aurel32 | baum_cellCount_timer_cb(baum); \ |
321 | 2e4d9fb1 | aurel32 | } \ |
322 | 2e4d9fb1 | aurel32 | return (cur - 2 - buf); \ |
323 | 2e4d9fb1 | aurel32 | } \ |
324 | 2e4d9fb1 | aurel32 | } \ |
325 | 2e4d9fb1 | aurel32 | } while (0) |
326 | 2e4d9fb1 | aurel32 | |
327 | 2e4d9fb1 | aurel32 | EAT(req); |
328 | 2e4d9fb1 | aurel32 | switch (req) {
|
329 | 2e4d9fb1 | aurel32 | case BAUM_REQ_DisplayData:
|
330 | 2e4d9fb1 | aurel32 | { |
331 | 2e4d9fb1 | aurel32 | uint8_t cells[baum->x * baum->y], c; |
332 | 2e4d9fb1 | aurel32 | uint8_t text[baum->x * baum->y]; |
333 | 2e4d9fb1 | aurel32 | uint8_t zero[baum->x * baum->y]; |
334 | 2e4d9fb1 | aurel32 | int cursor = BRLAPI_CURSOR_OFF;
|
335 | 2e4d9fb1 | aurel32 | int i;
|
336 | 2e4d9fb1 | aurel32 | |
337 | 2e4d9fb1 | aurel32 | /* Allow 100ms to complete the DisplayData packet */
|
338 | 6ee093c9 | Juan Quintela | qemu_mod_timer(baum->cellCount_timer, qemu_get_clock(vm_clock) + |
339 | 6ee093c9 | Juan Quintela | get_ticks_per_sec() / 10);
|
340 | 2e4d9fb1 | aurel32 | for (i = 0; i < baum->x * baum->y ; i++) { |
341 | 2e4d9fb1 | aurel32 | EAT(c); |
342 | 2e4d9fb1 | aurel32 | cells[i] = c; |
343 | 2e4d9fb1 | aurel32 | if ((c & (BRLAPI_DOT7|BRLAPI_DOT8))
|
344 | 2e4d9fb1 | aurel32 | == (BRLAPI_DOT7|BRLAPI_DOT8)) { |
345 | 2e4d9fb1 | aurel32 | cursor = i + 1;
|
346 | 2e4d9fb1 | aurel32 | c &= ~(BRLAPI_DOT7|BRLAPI_DOT8); |
347 | 2e4d9fb1 | aurel32 | } |
348 | 2e4d9fb1 | aurel32 | if (!(c = nabcc_translation[c]))
|
349 | 2e4d9fb1 | aurel32 | c = '?';
|
350 | 2e4d9fb1 | aurel32 | text[i] = c; |
351 | 2e4d9fb1 | aurel32 | } |
352 | 2e4d9fb1 | aurel32 | qemu_del_timer(baum->cellCount_timer); |
353 | 2e4d9fb1 | aurel32 | |
354 | 2e4d9fb1 | aurel32 | memset(zero, 0, sizeof(zero)); |
355 | 2e4d9fb1 | aurel32 | |
356 | 2e4d9fb1 | aurel32 | brlapi_writeArguments_t wa = { |
357 | 2e4d9fb1 | aurel32 | .displayNumber = BRLAPI_DISPLAY_DEFAULT, |
358 | 2e4d9fb1 | aurel32 | .regionBegin = 1,
|
359 | 2e4d9fb1 | aurel32 | .regionSize = baum->x * baum->y, |
360 | 4f72c4dd | Blue Swirl | .text = (char *)text,
|
361 | 2e4d9fb1 | aurel32 | .textSize = baum->x * baum->y, |
362 | 2e4d9fb1 | aurel32 | .andMask = zero, |
363 | 2e4d9fb1 | aurel32 | .orMask = cells, |
364 | 2e4d9fb1 | aurel32 | .cursor = cursor, |
365 | 4f72c4dd | Blue Swirl | .charset = (char *)"ISO-8859-1", |
366 | 2e4d9fb1 | aurel32 | }; |
367 | 2e4d9fb1 | aurel32 | |
368 | 2e4d9fb1 | aurel32 | if (brlapi__write(baum->brlapi, &wa) == -1) |
369 | 2e4d9fb1 | aurel32 | brlapi_perror("baum brlapi_write");
|
370 | 2e4d9fb1 | aurel32 | break;
|
371 | 2e4d9fb1 | aurel32 | } |
372 | 2e4d9fb1 | aurel32 | case BAUM_REQ_SetMode:
|
373 | 2e4d9fb1 | aurel32 | { |
374 | 2e4d9fb1 | aurel32 | uint8_t mode, setting; |
375 | 2e4d9fb1 | aurel32 | DPRINTF("SetMode\n");
|
376 | 2e4d9fb1 | aurel32 | EAT(mode); |
377 | 2e4d9fb1 | aurel32 | EAT(setting); |
378 | 2e4d9fb1 | aurel32 | /* ignore */
|
379 | 2e4d9fb1 | aurel32 | break;
|
380 | 2e4d9fb1 | aurel32 | } |
381 | 2e4d9fb1 | aurel32 | case BAUM_REQ_SetProtocol:
|
382 | 2e4d9fb1 | aurel32 | { |
383 | 2e4d9fb1 | aurel32 | uint8_t protocol; |
384 | 2e4d9fb1 | aurel32 | DPRINTF("SetProtocol\n");
|
385 | 2e4d9fb1 | aurel32 | EAT(protocol); |
386 | 2e4d9fb1 | aurel32 | /* ignore */
|
387 | 2e4d9fb1 | aurel32 | break;
|
388 | 2e4d9fb1 | aurel32 | } |
389 | 2e4d9fb1 | aurel32 | case BAUM_REQ_GetDeviceIdentity:
|
390 | 2e4d9fb1 | aurel32 | { |
391 | 2e4d9fb1 | aurel32 | uint8_t identity[17] = { BAUM_RSP_DeviceIdentity,
|
392 | 2e4d9fb1 | aurel32 | 'B','a','u','m',' ','V','a','r','i','o' }; |
393 | 2e4d9fb1 | aurel32 | DPRINTF("GetDeviceIdentity\n");
|
394 | 2e4d9fb1 | aurel32 | identity[11] = '0' + baum->x / 10; |
395 | 2e4d9fb1 | aurel32 | identity[12] = '0' + baum->x % 10; |
396 | 2e4d9fb1 | aurel32 | baum_write_packet(baum, identity, sizeof(identity));
|
397 | 2e4d9fb1 | aurel32 | break;
|
398 | 2e4d9fb1 | aurel32 | } |
399 | 2e4d9fb1 | aurel32 | case BAUM_REQ_GetVersionNumber:
|
400 | 2e4d9fb1 | aurel32 | { |
401 | 2e4d9fb1 | aurel32 | uint8_t version[] = { BAUM_RSP_VersionNumber, 1 }; /* ? */ |
402 | 2e4d9fb1 | aurel32 | DPRINTF("GetVersionNumber\n");
|
403 | 2e4d9fb1 | aurel32 | baum_write_packet(baum, version, sizeof(version));
|
404 | 2e4d9fb1 | aurel32 | break;
|
405 | 2e4d9fb1 | aurel32 | } |
406 | 2e4d9fb1 | aurel32 | case BAUM_REQ_GetSerialNumber:
|
407 | 2e4d9fb1 | aurel32 | { |
408 | 2e4d9fb1 | aurel32 | uint8_t serial[] = { BAUM_RSP_SerialNumber, |
409 | 2e4d9fb1 | aurel32 | '0','0','0','0','0','0','0','0' }; |
410 | 2e4d9fb1 | aurel32 | DPRINTF("GetSerialNumber\n");
|
411 | 2e4d9fb1 | aurel32 | baum_write_packet(baum, serial, sizeof(serial));
|
412 | 2e4d9fb1 | aurel32 | break;
|
413 | 2e4d9fb1 | aurel32 | } |
414 | 2e4d9fb1 | aurel32 | case BAUM_REQ_GetKeys:
|
415 | 2e4d9fb1 | aurel32 | { |
416 | 2e4d9fb1 | aurel32 | DPRINTF("Get%0#2x\n", req);
|
417 | 2e4d9fb1 | aurel32 | /* ignore */
|
418 | 2e4d9fb1 | aurel32 | break;
|
419 | 2e4d9fb1 | aurel32 | } |
420 | 2e4d9fb1 | aurel32 | default:
|
421 | 2e4d9fb1 | aurel32 | DPRINTF("unrecognized request %0#2x\n", req);
|
422 | 2e4d9fb1 | aurel32 | do
|
423 | 2e4d9fb1 | aurel32 | if (!len--)
|
424 | 2e4d9fb1 | aurel32 | return 0; |
425 | 2e4d9fb1 | aurel32 | while (*cur++ != ESC);
|
426 | 2e4d9fb1 | aurel32 | cur--; |
427 | 2e4d9fb1 | aurel32 | break;
|
428 | 2e4d9fb1 | aurel32 | } |
429 | 2e4d9fb1 | aurel32 | return cur - buf;
|
430 | 2e4d9fb1 | aurel32 | } |
431 | 2e4d9fb1 | aurel32 | |
432 | 2e4d9fb1 | aurel32 | /* The other end is writing some data. Store it and try to interpret */
|
433 | 2e4d9fb1 | aurel32 | static int baum_write(CharDriverState *chr, const uint8_t *buf, int len) |
434 | 2e4d9fb1 | aurel32 | { |
435 | 2e4d9fb1 | aurel32 | BaumDriverState *baum = chr->opaque; |
436 | 2e4d9fb1 | aurel32 | int tocopy, cur, eaten, orig_len = len;
|
437 | 2e4d9fb1 | aurel32 | |
438 | 2e4d9fb1 | aurel32 | if (!len)
|
439 | 2e4d9fb1 | aurel32 | return 0; |
440 | 2e4d9fb1 | aurel32 | if (!baum->brlapi)
|
441 | 2e4d9fb1 | aurel32 | return len;
|
442 | 2e4d9fb1 | aurel32 | |
443 | 2e4d9fb1 | aurel32 | while (len) {
|
444 | 2e4d9fb1 | aurel32 | /* Complete our buffer as much as possible */
|
445 | 2e4d9fb1 | aurel32 | tocopy = len; |
446 | 2e4d9fb1 | aurel32 | if (tocopy > BUF_SIZE - baum->in_buf_used)
|
447 | 2e4d9fb1 | aurel32 | tocopy = BUF_SIZE - baum->in_buf_used; |
448 | 2e4d9fb1 | aurel32 | |
449 | 2e4d9fb1 | aurel32 | memcpy(baum->in_buf + baum->in_buf_used, buf, tocopy); |
450 | 2e4d9fb1 | aurel32 | baum->in_buf_used += tocopy; |
451 | 2e4d9fb1 | aurel32 | buf += tocopy; |
452 | 2e4d9fb1 | aurel32 | len -= tocopy; |
453 | 2e4d9fb1 | aurel32 | |
454 | 2e4d9fb1 | aurel32 | /* Interpret it as much as possible */
|
455 | 2e4d9fb1 | aurel32 | cur = 0;
|
456 | 2e4d9fb1 | aurel32 | while (cur < baum->in_buf_used &&
|
457 | 2e4d9fb1 | aurel32 | (eaten = baum_eat_packet(baum, baum->in_buf + cur, baum->in_buf_used - cur))) |
458 | 2e4d9fb1 | aurel32 | cur += eaten; |
459 | 2e4d9fb1 | aurel32 | |
460 | 2e4d9fb1 | aurel32 | /* Shift the remainder */
|
461 | 2e4d9fb1 | aurel32 | if (cur) {
|
462 | 2e4d9fb1 | aurel32 | memmove(baum->in_buf, baum->in_buf + cur, baum->in_buf_used - cur); |
463 | 2e4d9fb1 | aurel32 | baum->in_buf_used -= cur; |
464 | 2e4d9fb1 | aurel32 | } |
465 | 2e4d9fb1 | aurel32 | |
466 | 2e4d9fb1 | aurel32 | /* And continue if any data left */
|
467 | 2e4d9fb1 | aurel32 | } |
468 | 2e4d9fb1 | aurel32 | return orig_len;
|
469 | 2e4d9fb1 | aurel32 | } |
470 | 2e4d9fb1 | aurel32 | |
471 | 2e4d9fb1 | aurel32 | /* The other end sent us some event */
|
472 | 2e4d9fb1 | aurel32 | static void baum_send_event(CharDriverState *chr, int event) |
473 | 2e4d9fb1 | aurel32 | { |
474 | 2e4d9fb1 | aurel32 | BaumDriverState *baum = chr->opaque; |
475 | 2e4d9fb1 | aurel32 | switch (event) {
|
476 | 2e4d9fb1 | aurel32 | case CHR_EVENT_BREAK:
|
477 | 2e4d9fb1 | aurel32 | break;
|
478 | b6b8df56 | Amit Shah | case CHR_EVENT_OPENED:
|
479 | 2e4d9fb1 | aurel32 | /* Reset state */
|
480 | 2e4d9fb1 | aurel32 | baum->in_buf_used = 0;
|
481 | 2e4d9fb1 | aurel32 | break;
|
482 | 2e4d9fb1 | aurel32 | } |
483 | 2e4d9fb1 | aurel32 | } |
484 | 2e4d9fb1 | aurel32 | |
485 | 2e4d9fb1 | aurel32 | /* Send the key code to the other end */
|
486 | 2e4d9fb1 | aurel32 | static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) { |
487 | 2e4d9fb1 | aurel32 | uint8_t packet[] = { type, value }; |
488 | 2e4d9fb1 | aurel32 | DPRINTF("writing key %x %x\n", type, value);
|
489 | 2e4d9fb1 | aurel32 | baum_write_packet(baum, packet, sizeof(packet));
|
490 | 2e4d9fb1 | aurel32 | } |
491 | 2e4d9fb1 | aurel32 | |
492 | 2e4d9fb1 | aurel32 | /* We got some data on the BrlAPI socket */
|
493 | 2e4d9fb1 | aurel32 | static void baum_chr_read(void *opaque) |
494 | 2e4d9fb1 | aurel32 | { |
495 | 2e4d9fb1 | aurel32 | BaumDriverState *baum = opaque; |
496 | 2e4d9fb1 | aurel32 | brlapi_keyCode_t code; |
497 | 2e4d9fb1 | aurel32 | int ret;
|
498 | 2e4d9fb1 | aurel32 | if (!baum->brlapi)
|
499 | 2e4d9fb1 | aurel32 | return;
|
500 | 2e4d9fb1 | aurel32 | while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) { |
501 | 2e4d9fb1 | aurel32 | DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code); |
502 | 2e4d9fb1 | aurel32 | /* Emulate */
|
503 | 2e4d9fb1 | aurel32 | switch (code & BRLAPI_KEY_TYPE_MASK) {
|
504 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_TYPE_CMD:
|
505 | 2e4d9fb1 | aurel32 | switch (code & BRLAPI_KEY_CMD_BLK_MASK) {
|
506 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_ROUTE:
|
507 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_RoutingKey, (code & BRLAPI_KEY_CMD_ARG_MASK)+1);
|
508 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_RoutingKey, 0);
|
509 | 2e4d9fb1 | aurel32 | break;
|
510 | 2e4d9fb1 | aurel32 | case 0: |
511 | 2e4d9fb1 | aurel32 | switch (code & BRLAPI_KEY_CMD_ARG_MASK) {
|
512 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_FWINLT:
|
513 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2); |
514 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
515 | 2e4d9fb1 | aurel32 | break;
|
516 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_FWINRT:
|
517 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR2); |
518 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
519 | 2e4d9fb1 | aurel32 | break;
|
520 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_LNUP:
|
521 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR1); |
522 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
523 | 2e4d9fb1 | aurel32 | break;
|
524 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_LNDN:
|
525 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR3); |
526 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
527 | 2e4d9fb1 | aurel32 | break;
|
528 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_TOP:
|
529 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TR1); |
530 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
531 | 2e4d9fb1 | aurel32 | break;
|
532 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_BOT:
|
533 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL3|BAUM_TR3); |
534 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
535 | 2e4d9fb1 | aurel32 | break;
|
536 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_TOP_LEFT:
|
537 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1); |
538 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
539 | 2e4d9fb1 | aurel32 | break;
|
540 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_BOT_LEFT:
|
541 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR3); |
542 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
543 | 2e4d9fb1 | aurel32 | break;
|
544 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_HOME:
|
545 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1|BAUM_TR3); |
546 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
547 | 2e4d9fb1 | aurel32 | break;
|
548 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_CMD_PREFMENU:
|
549 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TL3|BAUM_TR1); |
550 | 2e4d9fb1 | aurel32 | baum_send_key(baum, BAUM_RSP_TopKeys, 0);
|
551 | 2e4d9fb1 | aurel32 | break;
|
552 | 2e4d9fb1 | aurel32 | } |
553 | 2e4d9fb1 | aurel32 | } |
554 | 2e4d9fb1 | aurel32 | break;
|
555 | 2e4d9fb1 | aurel32 | case BRLAPI_KEY_TYPE_SYM:
|
556 | 2e4d9fb1 | aurel32 | break;
|
557 | 2e4d9fb1 | aurel32 | } |
558 | 2e4d9fb1 | aurel32 | } |
559 | 2e4d9fb1 | aurel32 | if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) { |
560 | 2e4d9fb1 | aurel32 | brlapi_perror("baum: brlapi_readKey");
|
561 | 2e4d9fb1 | aurel32 | brlapi__closeConnection(baum->brlapi); |
562 | 49cd8046 | Jean-Christophe DUBOIS | qemu_free(baum->brlapi); |
563 | 2e4d9fb1 | aurel32 | baum->brlapi = NULL;
|
564 | 2e4d9fb1 | aurel32 | } |
565 | 2e4d9fb1 | aurel32 | } |
566 | 2e4d9fb1 | aurel32 | |
567 | 2c7faf31 | Samuel Thibault | static void baum_close(struct CharDriverState *chr) |
568 | 2c7faf31 | Samuel Thibault | { |
569 | 2c7faf31 | Samuel Thibault | BaumDriverState *baum = chr->opaque; |
570 | 2c7faf31 | Samuel Thibault | |
571 | 2c7faf31 | Samuel Thibault | qemu_free_timer(baum->cellCount_timer); |
572 | 2c7faf31 | Samuel Thibault | if (baum->brlapi) {
|
573 | 2c7faf31 | Samuel Thibault | brlapi__closeConnection(baum->brlapi); |
574 | 2c7faf31 | Samuel Thibault | qemu_free(baum->brlapi); |
575 | 2c7faf31 | Samuel Thibault | } |
576 | 2c7faf31 | Samuel Thibault | qemu_free(baum); |
577 | 2c7faf31 | Samuel Thibault | } |
578 | 2c7faf31 | Samuel Thibault | |
579 | dc1c21e6 | Gerd Hoffmann | CharDriverState *chr_baum_init(QemuOpts *opts) |
580 | 2e4d9fb1 | aurel32 | { |
581 | 2e4d9fb1 | aurel32 | BaumDriverState *baum; |
582 | 2e4d9fb1 | aurel32 | CharDriverState *chr; |
583 | 2e4d9fb1 | aurel32 | brlapi_handle_t *handle; |
584 | 2e4d9fb1 | aurel32 | #ifdef CONFIG_SDL
|
585 | 2e4d9fb1 | aurel32 | SDL_SysWMinfo info; |
586 | 2e4d9fb1 | aurel32 | #endif
|
587 | 2e4d9fb1 | aurel32 | int tty;
|
588 | 2e4d9fb1 | aurel32 | |
589 | 2e4d9fb1 | aurel32 | baum = qemu_mallocz(sizeof(BaumDriverState));
|
590 | 2e4d9fb1 | aurel32 | baum->chr = chr = qemu_mallocz(sizeof(CharDriverState));
|
591 | 2e4d9fb1 | aurel32 | |
592 | 2e4d9fb1 | aurel32 | chr->opaque = baum; |
593 | 2e4d9fb1 | aurel32 | chr->chr_write = baum_write; |
594 | 2e4d9fb1 | aurel32 | chr->chr_send_event = baum_send_event; |
595 | 2e4d9fb1 | aurel32 | chr->chr_accept_input = baum_accept_input; |
596 | 2c7faf31 | Samuel Thibault | chr->chr_close = baum_close; |
597 | 2e4d9fb1 | aurel32 | |
598 | 2e4d9fb1 | aurel32 | handle = qemu_mallocz(brlapi_getHandleSize()); |
599 | 2e4d9fb1 | aurel32 | baum->brlapi = handle; |
600 | 2e4d9fb1 | aurel32 | |
601 | 2e4d9fb1 | aurel32 | baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL); |
602 | 2e4d9fb1 | aurel32 | if (baum->brlapi_fd == -1) { |
603 | 2e4d9fb1 | aurel32 | brlapi_perror("baum_init: brlapi_openConnection");
|
604 | 2e4d9fb1 | aurel32 | goto fail_handle;
|
605 | 2e4d9fb1 | aurel32 | } |
606 | 2e4d9fb1 | aurel32 | |
607 | 2e4d9fb1 | aurel32 | baum->cellCount_timer = qemu_new_timer(vm_clock, baum_cellCount_timer_cb, baum); |
608 | 2e4d9fb1 | aurel32 | |
609 | 2e4d9fb1 | aurel32 | if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) { |
610 | 2e4d9fb1 | aurel32 | brlapi_perror("baum_init: brlapi_getDisplaySize");
|
611 | 2e4d9fb1 | aurel32 | goto fail;
|
612 | 2e4d9fb1 | aurel32 | } |
613 | 2e4d9fb1 | aurel32 | |
614 | 2e4d9fb1 | aurel32 | #ifdef CONFIG_SDL
|
615 | 2e4d9fb1 | aurel32 | memset(&info, 0, sizeof(info)); |
616 | 2e4d9fb1 | aurel32 | SDL_VERSION(&info.version); |
617 | 2e4d9fb1 | aurel32 | if (SDL_GetWMInfo(&info))
|
618 | 2e4d9fb1 | aurel32 | tty = info.info.x11.wmwindow; |
619 | 2e4d9fb1 | aurel32 | else
|
620 | 2e4d9fb1 | aurel32 | #endif
|
621 | 2e4d9fb1 | aurel32 | tty = BRLAPI_TTY_DEFAULT; |
622 | 2e4d9fb1 | aurel32 | |
623 | 2e4d9fb1 | aurel32 | if (brlapi__enterTtyMode(handle, tty, NULL) == -1) { |
624 | 2e4d9fb1 | aurel32 | brlapi_perror("baum_init: brlapi_enterTtyMode");
|
625 | 2e4d9fb1 | aurel32 | goto fail;
|
626 | 2e4d9fb1 | aurel32 | } |
627 | 2e4d9fb1 | aurel32 | |
628 | 2e4d9fb1 | aurel32 | qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
|
629 | 2e4d9fb1 | aurel32 | |
630 | 127338e6 | Amit Shah | qemu_chr_generic_open(chr); |
631 | 2e4d9fb1 | aurel32 | |
632 | 2e4d9fb1 | aurel32 | return chr;
|
633 | 2e4d9fb1 | aurel32 | |
634 | 2e4d9fb1 | aurel32 | fail:
|
635 | 2e4d9fb1 | aurel32 | qemu_free_timer(baum->cellCount_timer); |
636 | 2e4d9fb1 | aurel32 | brlapi__closeConnection(handle); |
637 | 260cfc43 | aurel32 | fail_handle:
|
638 | 49cd8046 | Jean-Christophe DUBOIS | qemu_free(handle); |
639 | 49cd8046 | Jean-Christophe DUBOIS | qemu_free(chr); |
640 | 49cd8046 | Jean-Christophe DUBOIS | qemu_free(baum); |
641 | 2e4d9fb1 | aurel32 | return NULL; |
642 | 2e4d9fb1 | aurel32 | } |