Statistics
| Branch: | Revision:

root / hw / baum.c @ 6693665a

History | View | Annotate | Download (19.7 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 2e4d9fb1 aurel32
        qemu_mod_timer(baum->cellCount_timer, qemu_get_clock(vm_clock) + ticks_per_sec / 10);
339 2e4d9fb1 aurel32
        for (i = 0; i < baum->x * baum->y ; i++) {
340 2e4d9fb1 aurel32
            EAT(c);
341 2e4d9fb1 aurel32
            cells[i] = c;
342 2e4d9fb1 aurel32
            if ((c & (BRLAPI_DOT7|BRLAPI_DOT8))
343 2e4d9fb1 aurel32
                    == (BRLAPI_DOT7|BRLAPI_DOT8)) {
344 2e4d9fb1 aurel32
                cursor = i + 1;
345 2e4d9fb1 aurel32
                c &= ~(BRLAPI_DOT7|BRLAPI_DOT8);
346 2e4d9fb1 aurel32
            }
347 2e4d9fb1 aurel32
            if (!(c = nabcc_translation[c]))
348 2e4d9fb1 aurel32
                c = '?';
349 2e4d9fb1 aurel32
            text[i] = c;
350 2e4d9fb1 aurel32
        }
351 2e4d9fb1 aurel32
        qemu_del_timer(baum->cellCount_timer);
352 2e4d9fb1 aurel32
353 2e4d9fb1 aurel32
        memset(zero, 0, sizeof(zero));
354 2e4d9fb1 aurel32
355 2e4d9fb1 aurel32
        brlapi_writeArguments_t wa = {
356 2e4d9fb1 aurel32
            .displayNumber = BRLAPI_DISPLAY_DEFAULT,
357 2e4d9fb1 aurel32
            .regionBegin = 1,
358 2e4d9fb1 aurel32
            .regionSize = baum->x * baum->y,
359 4f72c4dd Blue Swirl
            .text = (char *)text,
360 2e4d9fb1 aurel32
            .textSize = baum->x * baum->y,
361 2e4d9fb1 aurel32
            .andMask = zero,
362 2e4d9fb1 aurel32
            .orMask = cells,
363 2e4d9fb1 aurel32
            .cursor = cursor,
364 4f72c4dd Blue Swirl
            .charset = (char *)"ISO-8859-1",
365 2e4d9fb1 aurel32
        };
366 2e4d9fb1 aurel32
367 2e4d9fb1 aurel32
        if (brlapi__write(baum->brlapi, &wa) == -1)
368 2e4d9fb1 aurel32
            brlapi_perror("baum brlapi_write");
369 2e4d9fb1 aurel32
        break;
370 2e4d9fb1 aurel32
    }
371 2e4d9fb1 aurel32
    case BAUM_REQ_SetMode:
372 2e4d9fb1 aurel32
    {
373 2e4d9fb1 aurel32
        uint8_t mode, setting;
374 2e4d9fb1 aurel32
        DPRINTF("SetMode\n");
375 2e4d9fb1 aurel32
        EAT(mode);
376 2e4d9fb1 aurel32
        EAT(setting);
377 2e4d9fb1 aurel32
        /* ignore */
378 2e4d9fb1 aurel32
        break;
379 2e4d9fb1 aurel32
    }
380 2e4d9fb1 aurel32
    case BAUM_REQ_SetProtocol:
381 2e4d9fb1 aurel32
    {
382 2e4d9fb1 aurel32
        uint8_t protocol;
383 2e4d9fb1 aurel32
        DPRINTF("SetProtocol\n");
384 2e4d9fb1 aurel32
        EAT(protocol);
385 2e4d9fb1 aurel32
        /* ignore */
386 2e4d9fb1 aurel32
        break;
387 2e4d9fb1 aurel32
    }
388 2e4d9fb1 aurel32
    case BAUM_REQ_GetDeviceIdentity:
389 2e4d9fb1 aurel32
    {
390 2e4d9fb1 aurel32
        uint8_t identity[17] = { BAUM_RSP_DeviceIdentity,
391 2e4d9fb1 aurel32
            'B','a','u','m',' ','V','a','r','i','o' };
392 2e4d9fb1 aurel32
        DPRINTF("GetDeviceIdentity\n");
393 2e4d9fb1 aurel32
        identity[11] = '0' + baum->x / 10;
394 2e4d9fb1 aurel32
        identity[12] = '0' + baum->x % 10;
395 2e4d9fb1 aurel32
        baum_write_packet(baum, identity, sizeof(identity));
396 2e4d9fb1 aurel32
        break;
397 2e4d9fb1 aurel32
    }
398 2e4d9fb1 aurel32
    case BAUM_REQ_GetVersionNumber:
399 2e4d9fb1 aurel32
    {
400 2e4d9fb1 aurel32
        uint8_t version[] = { BAUM_RSP_VersionNumber, 1 }; /* ? */
401 2e4d9fb1 aurel32
        DPRINTF("GetVersionNumber\n");
402 2e4d9fb1 aurel32
        baum_write_packet(baum, version, sizeof(version));
403 2e4d9fb1 aurel32
        break;
404 2e4d9fb1 aurel32
    }
405 2e4d9fb1 aurel32
    case BAUM_REQ_GetSerialNumber:
406 2e4d9fb1 aurel32
    {
407 2e4d9fb1 aurel32
        uint8_t serial[] = { BAUM_RSP_SerialNumber,
408 2e4d9fb1 aurel32
            '0','0','0','0','0','0','0','0' };
409 2e4d9fb1 aurel32
        DPRINTF("GetSerialNumber\n");
410 2e4d9fb1 aurel32
        baum_write_packet(baum, serial, sizeof(serial));
411 2e4d9fb1 aurel32
        break;
412 2e4d9fb1 aurel32
    }
413 2e4d9fb1 aurel32
    case BAUM_REQ_GetKeys:
414 2e4d9fb1 aurel32
    {
415 2e4d9fb1 aurel32
        DPRINTF("Get%0#2x\n", req);
416 2e4d9fb1 aurel32
        /* ignore */
417 2e4d9fb1 aurel32
        break;
418 2e4d9fb1 aurel32
    }
419 2e4d9fb1 aurel32
    default:
420 2e4d9fb1 aurel32
        DPRINTF("unrecognized request %0#2x\n", req);
421 2e4d9fb1 aurel32
        do
422 2e4d9fb1 aurel32
            if (!len--)
423 2e4d9fb1 aurel32
                return 0;
424 2e4d9fb1 aurel32
        while (*cur++ != ESC);
425 2e4d9fb1 aurel32
        cur--;
426 2e4d9fb1 aurel32
        break;
427 2e4d9fb1 aurel32
    }
428 2e4d9fb1 aurel32
    return cur - buf;
429 2e4d9fb1 aurel32
}
430 2e4d9fb1 aurel32
431 2e4d9fb1 aurel32
/* The other end is writing some data.  Store it and try to interpret */
432 2e4d9fb1 aurel32
static int baum_write(CharDriverState *chr, const uint8_t *buf, int len)
433 2e4d9fb1 aurel32
{
434 2e4d9fb1 aurel32
    BaumDriverState *baum = chr->opaque;
435 2e4d9fb1 aurel32
    int tocopy, cur, eaten, orig_len = len;
436 2e4d9fb1 aurel32
437 2e4d9fb1 aurel32
    if (!len)
438 2e4d9fb1 aurel32
        return 0;
439 2e4d9fb1 aurel32
    if (!baum->brlapi)
440 2e4d9fb1 aurel32
        return len;
441 2e4d9fb1 aurel32
442 2e4d9fb1 aurel32
    while (len) {
443 2e4d9fb1 aurel32
        /* Complete our buffer as much as possible */
444 2e4d9fb1 aurel32
        tocopy = len;
445 2e4d9fb1 aurel32
        if (tocopy > BUF_SIZE - baum->in_buf_used)
446 2e4d9fb1 aurel32
            tocopy = BUF_SIZE - baum->in_buf_used;
447 2e4d9fb1 aurel32
448 2e4d9fb1 aurel32
        memcpy(baum->in_buf + baum->in_buf_used, buf, tocopy);
449 2e4d9fb1 aurel32
        baum->in_buf_used += tocopy;
450 2e4d9fb1 aurel32
        buf += tocopy;
451 2e4d9fb1 aurel32
        len -= tocopy;
452 2e4d9fb1 aurel32
453 2e4d9fb1 aurel32
        /* Interpret it as much as possible */
454 2e4d9fb1 aurel32
        cur = 0;
455 2e4d9fb1 aurel32
        while (cur < baum->in_buf_used &&
456 2e4d9fb1 aurel32
                (eaten = baum_eat_packet(baum, baum->in_buf + cur, baum->in_buf_used - cur)))
457 2e4d9fb1 aurel32
            cur += eaten;
458 2e4d9fb1 aurel32
459 2e4d9fb1 aurel32
        /* Shift the remainder */
460 2e4d9fb1 aurel32
        if (cur) {
461 2e4d9fb1 aurel32
            memmove(baum->in_buf, baum->in_buf + cur, baum->in_buf_used - cur);
462 2e4d9fb1 aurel32
            baum->in_buf_used -= cur;
463 2e4d9fb1 aurel32
        }
464 2e4d9fb1 aurel32
465 2e4d9fb1 aurel32
        /* And continue if any data left */
466 2e4d9fb1 aurel32
    }
467 2e4d9fb1 aurel32
    return orig_len;
468 2e4d9fb1 aurel32
}
469 2e4d9fb1 aurel32
470 2e4d9fb1 aurel32
/* The other end sent us some event */
471 2e4d9fb1 aurel32
static void baum_send_event(CharDriverState *chr, int event)
472 2e4d9fb1 aurel32
{
473 2e4d9fb1 aurel32
    BaumDriverState *baum = chr->opaque;
474 2e4d9fb1 aurel32
    switch (event) {
475 2e4d9fb1 aurel32
    case CHR_EVENT_BREAK:
476 2e4d9fb1 aurel32
        break;
477 2e4d9fb1 aurel32
    case CHR_EVENT_RESET:
478 2e4d9fb1 aurel32
        /* Reset state */
479 2e4d9fb1 aurel32
        baum->in_buf_used = 0;
480 2e4d9fb1 aurel32
        break;
481 2e4d9fb1 aurel32
    }
482 2e4d9fb1 aurel32
}
483 2e4d9fb1 aurel32
484 2e4d9fb1 aurel32
/* Send the key code to the other end */
485 2e4d9fb1 aurel32
static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) {
486 2e4d9fb1 aurel32
    uint8_t packet[] = { type, value };
487 2e4d9fb1 aurel32
    DPRINTF("writing key %x %x\n", type, value);
488 2e4d9fb1 aurel32
    baum_write_packet(baum, packet, sizeof(packet));
489 2e4d9fb1 aurel32
}
490 2e4d9fb1 aurel32
491 2e4d9fb1 aurel32
/* We got some data on the BrlAPI socket */
492 2e4d9fb1 aurel32
static void baum_chr_read(void *opaque)
493 2e4d9fb1 aurel32
{
494 2e4d9fb1 aurel32
    BaumDriverState *baum = opaque;
495 2e4d9fb1 aurel32
    brlapi_keyCode_t code;
496 2e4d9fb1 aurel32
    int ret;
497 2e4d9fb1 aurel32
    if (!baum->brlapi)
498 2e4d9fb1 aurel32
        return;
499 2e4d9fb1 aurel32
    while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) {
500 2e4d9fb1 aurel32
        DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code);
501 2e4d9fb1 aurel32
        /* Emulate */
502 2e4d9fb1 aurel32
        switch (code & BRLAPI_KEY_TYPE_MASK) {
503 2e4d9fb1 aurel32
        case BRLAPI_KEY_TYPE_CMD:
504 2e4d9fb1 aurel32
            switch (code & BRLAPI_KEY_CMD_BLK_MASK) {
505 2e4d9fb1 aurel32
            case BRLAPI_KEY_CMD_ROUTE:
506 2e4d9fb1 aurel32
                baum_send_key(baum, BAUM_RSP_RoutingKey, (code & BRLAPI_KEY_CMD_ARG_MASK)+1);
507 2e4d9fb1 aurel32
                baum_send_key(baum, BAUM_RSP_RoutingKey, 0);
508 2e4d9fb1 aurel32
                break;
509 2e4d9fb1 aurel32
            case 0:
510 2e4d9fb1 aurel32
                switch (code & BRLAPI_KEY_CMD_ARG_MASK) {
511 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_FWINLT:
512 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2);
513 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
514 2e4d9fb1 aurel32
                    break;
515 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_FWINRT:
516 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR2);
517 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
518 2e4d9fb1 aurel32
                    break;
519 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_LNUP:
520 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR1);
521 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
522 2e4d9fb1 aurel32
                    break;
523 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_LNDN:
524 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR3);
525 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
526 2e4d9fb1 aurel32
                    break;
527 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_TOP:
528 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TR1);
529 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
530 2e4d9fb1 aurel32
                    break;
531 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_BOT:
532 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL3|BAUM_TR3);
533 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
534 2e4d9fb1 aurel32
                    break;
535 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_TOP_LEFT:
536 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1);
537 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
538 2e4d9fb1 aurel32
                    break;
539 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_BOT_LEFT:
540 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR3);
541 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
542 2e4d9fb1 aurel32
                    break;
543 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_HOME:
544 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1|BAUM_TR3);
545 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
546 2e4d9fb1 aurel32
                    break;
547 2e4d9fb1 aurel32
                case BRLAPI_KEY_CMD_PREFMENU:
548 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TL3|BAUM_TR1);
549 2e4d9fb1 aurel32
                    baum_send_key(baum, BAUM_RSP_TopKeys, 0);
550 2e4d9fb1 aurel32
                    break;
551 2e4d9fb1 aurel32
                }
552 2e4d9fb1 aurel32
            }
553 2e4d9fb1 aurel32
            break;
554 2e4d9fb1 aurel32
        case BRLAPI_KEY_TYPE_SYM:
555 2e4d9fb1 aurel32
            break;
556 2e4d9fb1 aurel32
        }
557 2e4d9fb1 aurel32
    }
558 2e4d9fb1 aurel32
    if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) {
559 2e4d9fb1 aurel32
        brlapi_perror("baum: brlapi_readKey");
560 2e4d9fb1 aurel32
        brlapi__closeConnection(baum->brlapi);
561 2e4d9fb1 aurel32
        free(baum->brlapi);
562 2e4d9fb1 aurel32
        baum->brlapi = NULL;
563 2e4d9fb1 aurel32
    }
564 2e4d9fb1 aurel32
}
565 2e4d9fb1 aurel32
566 2e4d9fb1 aurel32
CharDriverState *chr_baum_init(void)
567 2e4d9fb1 aurel32
{
568 2e4d9fb1 aurel32
    BaumDriverState *baum;
569 2e4d9fb1 aurel32
    CharDriverState *chr;
570 2e4d9fb1 aurel32
    brlapi_handle_t *handle;
571 2e4d9fb1 aurel32
#ifdef CONFIG_SDL
572 2e4d9fb1 aurel32
    SDL_SysWMinfo info;
573 2e4d9fb1 aurel32
#endif
574 2e4d9fb1 aurel32
    int tty;
575 2e4d9fb1 aurel32
576 2e4d9fb1 aurel32
    baum = qemu_mallocz(sizeof(BaumDriverState));
577 2e4d9fb1 aurel32
    baum->chr = chr = qemu_mallocz(sizeof(CharDriverState));
578 2e4d9fb1 aurel32
579 2e4d9fb1 aurel32
    chr->opaque = baum;
580 2e4d9fb1 aurel32
    chr->chr_write = baum_write;
581 2e4d9fb1 aurel32
    chr->chr_send_event = baum_send_event;
582 2e4d9fb1 aurel32
    chr->chr_accept_input = baum_accept_input;
583 2e4d9fb1 aurel32
584 2e4d9fb1 aurel32
    handle = qemu_mallocz(brlapi_getHandleSize());
585 2e4d9fb1 aurel32
    baum->brlapi = handle;
586 2e4d9fb1 aurel32
587 2e4d9fb1 aurel32
    baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL);
588 2e4d9fb1 aurel32
    if (baum->brlapi_fd == -1) {
589 2e4d9fb1 aurel32
        brlapi_perror("baum_init: brlapi_openConnection");
590 2e4d9fb1 aurel32
        goto fail_handle;
591 2e4d9fb1 aurel32
    }
592 2e4d9fb1 aurel32
593 2e4d9fb1 aurel32
    baum->cellCount_timer = qemu_new_timer(vm_clock, baum_cellCount_timer_cb, baum);
594 2e4d9fb1 aurel32
595 2e4d9fb1 aurel32
    if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) {
596 2e4d9fb1 aurel32
        brlapi_perror("baum_init: brlapi_getDisplaySize");
597 2e4d9fb1 aurel32
        goto fail;
598 2e4d9fb1 aurel32
    }
599 2e4d9fb1 aurel32
600 2e4d9fb1 aurel32
#ifdef CONFIG_SDL
601 2e4d9fb1 aurel32
    memset(&info, 0, sizeof(info));
602 2e4d9fb1 aurel32
    SDL_VERSION(&info.version);
603 2e4d9fb1 aurel32
    if (SDL_GetWMInfo(&info))
604 2e4d9fb1 aurel32
        tty = info.info.x11.wmwindow;
605 2e4d9fb1 aurel32
    else
606 2e4d9fb1 aurel32
#endif
607 2e4d9fb1 aurel32
        tty = BRLAPI_TTY_DEFAULT;
608 2e4d9fb1 aurel32
609 2e4d9fb1 aurel32
    if (brlapi__enterTtyMode(handle, tty, NULL) == -1) {
610 2e4d9fb1 aurel32
        brlapi_perror("baum_init: brlapi_enterTtyMode");
611 2e4d9fb1 aurel32
        goto fail;
612 2e4d9fb1 aurel32
    }
613 2e4d9fb1 aurel32
614 2e4d9fb1 aurel32
    qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
615 2e4d9fb1 aurel32
616 2e4d9fb1 aurel32
    qemu_chr_reset(chr);
617 2e4d9fb1 aurel32
618 2e4d9fb1 aurel32
    return chr;
619 2e4d9fb1 aurel32
620 2e4d9fb1 aurel32
fail:
621 2e4d9fb1 aurel32
    qemu_free_timer(baum->cellCount_timer);
622 2e4d9fb1 aurel32
    brlapi__closeConnection(handle);
623 260cfc43 aurel32
fail_handle:
624 2e4d9fb1 aurel32
    free(handle);
625 2e4d9fb1 aurel32
    free(chr);
626 2e4d9fb1 aurel32
    free(baum);
627 2e4d9fb1 aurel32
    return NULL;
628 2e4d9fb1 aurel32
}
629 2e4d9fb1 aurel32
630 2e4d9fb1 aurel32
USBDevice *usb_baum_init(void)
631 2e4d9fb1 aurel32
{
632 2e4d9fb1 aurel32
    /* USB Product ID of Super Vario 40 */
633 2e4d9fb1 aurel32
    return usb_serial_init("productid=FE72:braille");
634 2e4d9fb1 aurel32
}