/*
* QEMU Baum Braille Device
*
- * Copyright (c) 2008 Samuel Thibault
+ * Copyright (c) 2008, 2010-2011, 2016 Samuel Thibault
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* THE SOFTWARE.
*/
#include "qemu/osdep.h"
+#include "qapi/error.h"
#include "qemu-common.h"
#include "sysemu/char.h"
#include "qemu/timer.h"
#include "hw/usb.h"
+#include "ui/console.h"
#include <brlapi.h>
#include <brlapi_constants.h>
#include <brlapi_keycodes.h>
-#ifdef CONFIG_SDL
-#include <SDL_syswm.h>
-#endif
#if 0
#define DPRINTF(fmt, ...) \
#define BUF_SIZE 256
typedef struct {
- CharDriverState *chr;
+ Chardev parent;
brlapi_handle_t *brlapi;
int brlapi_fd;
unsigned int x, y;
+ bool deferred_init;
uint8_t in_buf[BUF_SIZE];
uint8_t in_buf_used;
uint8_t out_buf_used, out_buf_ptr;
QEMUTimer *cellCount_timer;
-} BaumDriverState;
+} BaumChardev;
+
+#define TYPE_CHARDEV_BRAILLE "chardev-braille"
+#define BAUM_CHARDEV(obj) OBJECT_CHECK(BaumChardev, (obj), TYPE_CHARDEV_BRAILLE)
/* Let's assume NABCC by default */
-static const uint8_t nabcc_translation[256] = {
- [0] = ' ',
+enum way {
+ DOTS2ASCII,
+ ASCII2DOTS
+};
+static const uint8_t nabcc_translation[2][256] = {
#ifndef BRLAPI_DOTS
#define BRLAPI_DOTS(d1,d2,d3,d4,d5,d6,d7,d8) \
((d1?BRLAPI_DOT1:0)|\
(d7?BRLAPI_DOT7:0)|\
(d8?BRLAPI_DOT8:0))
#endif
- [BRLAPI_DOTS(1,0,0,0,0,0,0,0)] = 'a',
- [BRLAPI_DOTS(1,1,0,0,0,0,0,0)] = 'b',
- [BRLAPI_DOTS(1,0,0,1,0,0,0,0)] = 'c',
- [BRLAPI_DOTS(1,0,0,1,1,0,0,0)] = 'd',
- [BRLAPI_DOTS(1,0,0,0,1,0,0,0)] = 'e',
- [BRLAPI_D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0,0)] = '8',
- [BRLAPI_DOTS(0,0,1,0,1,0,0,0)] = '9',
-
- [BRLAPI_DOTS(0,0,0,1,0,1,0,0)] = '.',
- [BRLAPI_DOTS(0,0,1,1,0,1,0,0)] = '+',
- [BRLAPI_DOTS(0,0,1,0,0,1,0,0)] = '-',
- [BRLAPI_DOTS(1,0,0,0,0,1,0,0)] = '*',
- [BRLAPI_DOTS(0,0,1,1,0,0,0,0)] = '/',
- [BRLAPI_DOTS(1,1,1,0,1,1,0,0)] = '(',
- [BRLAPI_DOTS(0,1,1,1,1,1,0,0)] = ')',
-
- [BRLAPI_DOTS(1,1,1,1,0,1,0,0)] = '&',
- [BRLAPI_DOTS(0,0,1,1,1,1,0,0)] = '#',
-
- [BRLAPI_DOTS(0,0,0,0,0,1,0,0)] = ',',
- [BRLAPI_DOTS(0,0,0,0,1,1,0,0)] = ';',
- [BRLAPI_DOTS(1,0,0,0,1,1,0,0)] = ':',
- [BRLAPI_DOTS(0,1,1,1,0,1,0,0)] = '!',
- [BRLAPI_DOTS(1,0,0,1,1,1,0,0)] = '?',
- [BRLAPI_DOTS(0,0,0,0,1,0,0,0)] = '"',
- [BRLAPI_DOTS(0,0,1,0,0,0,0,0)] ='\'',
- [BRLAPI_DOTS(0,0,0,1,0,0,0,0)] = '`',
- [BRLAPI_DOTS(0,0,0,1,1,0,1,0)] = '^',
- [BRLAPI_DOTS(0,0,0,1,1,0,0,0)] = '~',
- [BRLAPI_DOTS(0,1,0,1,0,1,1,0)] = '[',
- [BRLAPI_DOTS(1,1,0,1,1,1,1,0)] = ']',
- [BRLAPI_DOTS(0,1,0,1,0,1,0,0)] = '{',
- [BRLAPI_DOTS(1,1,0,1,1,1,0,0)] = '}',
- [BRLAPI_DOTS(1,1,1,1,1,1,0,0)] = '=',
- [BRLAPI_DOTS(1,1,0,0,0,1,0,0)] = '<',
- [BRLAPI_DOTS(0,0,1,1,1,0,0,0)] = '>',
- [BRLAPI_DOTS(1,1,0,1,0,1,0,0)] = '$',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O(BRLAPI_DOTS(1, 1, 0, 1, 1, 1, 0, 0), '}'),
+ DO(BRLAPI_DOTS(1, 1, 1, 1, 1, 1, 0, 0), '='),
+ DO(BRLAPI_DOTS(1, 1, 0, 0, 0, 1, 0, 0), '<'),
+ DO(BRLAPI_DOTS(0, 0, 1, 1, 1, 0, 0, 0), '>'),
+ DO(BRLAPI_DOTS(1, 1, 0, 1, 0, 1, 0, 0), '$'),
+ DO(BRLAPI_DOTS(1, 0, 0, 1, 0, 1, 0, 0), '%'),
+ DO(BRLAPI_DOTS(0, 0, 0, 1, 0, 0, 1, 0), '@'),
+ DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 1, 0, 0), '|'),
+ DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 1, 1, 0), '\\'),
+ DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 1, 0, 0), '_'),
};
+/* The guest OS has started discussing with us, finish initializing BrlAPI */
+static int baum_deferred_init(BaumChardev *baum)
+{
+ int tty = BRLAPI_TTY_DEFAULT;
+ QemuConsole *con;
+
+ if (baum->deferred_init) {
+ return 1;
+ }
+
+ if (brlapi__getDisplaySize(baum->brlapi, &baum->x, &baum->y) == -1) {
+ brlapi_perror("baum: brlapi__getDisplaySize");
+ return 0;
+ }
+
+ con = qemu_console_lookup_by_index(0);
+ if (con && qemu_console_is_graphic(con)) {
+ tty = qemu_console_get_window_id(con);
+ if (tty == -1)
+ tty = BRLAPI_TTY_DEFAULT;
+ }
+
+ if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) {
+ brlapi_perror("baum: brlapi__enterTtyMode");
+ return 0;
+ }
+ baum->deferred_init = 1;
+ return 1;
+}
+
/* The serial port can receive more of our data */
-static void baum_accept_input(struct CharDriverState *chr)
+static void baum_chr_accept_input(struct Chardev *chr)
{
- BaumDriverState *baum = chr->opaque;
+ BaumChardev *baum = BAUM_CHARDEV(chr);
int room, first;
if (!baum->out_buf_used)
}
/* We want to send a packet */
-static void baum_write_packet(BaumDriverState *baum, const uint8_t *buf, int len)
+static void baum_write_packet(BaumChardev *baum, const uint8_t *buf, int len)
{
+ Chardev *chr = CHARDEV(baum);
uint8_t io_buf[1 + 2 * len], *cur = io_buf;
int room;
*cur++ = ESC;
while (len--)
if ((*cur++ = *buf++) == ESC)
*cur++ = ESC;
- room = qemu_chr_be_can_write(baum->chr);
+ room = qemu_chr_be_can_write(chr);
len = cur - io_buf;
if (len <= room) {
/* Fits */
- qemu_chr_be_write(baum->chr, io_buf, len);
+ qemu_chr_be_write(chr, io_buf, len);
} else {
int first;
uint8_t out;
/* Can't fit all, send what can be, and store the rest. */
- qemu_chr_be_write(baum->chr, io_buf, room);
+ qemu_chr_be_write(chr, io_buf, room);
len -= room;
cur = io_buf + room;
if (len > BUF_SIZE - baum->out_buf_used) {
/* Called when the other end seems to have a wrong idea of our display size */
static void baum_cellCount_timer_cb(void *opaque)
{
- BaumDriverState *baum = opaque;
+ BaumChardev *baum = BAUM_CHARDEV(opaque);
uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y };
DPRINTF("Timeout waiting for DisplayData, sending cell count\n");
baum_write_packet(baum, cell_count, sizeof(cell_count));
}
/* Try to interpret a whole incoming packet */
-static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len)
+static int baum_eat_packet(BaumChardev *baum, const uint8_t *buf, int len)
{
const uint8_t *cur = buf;
uint8_t req = 0;
/* Allow 100ms to complete the DisplayData packet */
timer_mod(baum->cellCount_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
- get_ticks_per_sec() / 10);
+ NANOSECONDS_PER_SECOND / 10);
for (i = 0; i < baum->x * baum->y ; i++) {
EAT(c);
cells[i] = c;
cursor = i + 1;
c &= ~(BRLAPI_DOT7|BRLAPI_DOT8);
}
- if (!(c = nabcc_translation[c]))
+ c = nabcc_translation[DOTS2ASCII][c];
+ if (!c) {
c = '?';
+ }
text[i] = c;
}
timer_del(baum->cellCount_timer);
}
/* The other end is writing some data. Store it and try to interpret */
-static int baum_write(CharDriverState *chr, const uint8_t *buf, int len)
+static int baum_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
- BaumDriverState *baum = chr->opaque;
+ BaumChardev *baum = BAUM_CHARDEV(chr);
int tocopy, cur, eaten, orig_len = len;
if (!len)
return 0;
if (!baum->brlapi)
return len;
+ if (!baum_deferred_init(baum))
+ return len;
while (len) {
/* Complete our buffer as much as possible */
}
/* Send the key code to the other end */
-static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) {
+static void baum_send_key(BaumChardev *baum, uint8_t type, uint8_t value)
+{
uint8_t packet[] = { type, value };
DPRINTF("writing key %x %x\n", type, value);
baum_write_packet(baum, packet, sizeof(packet));
}
+static void baum_send_key2(BaumChardev *baum, uint8_t type, uint8_t value,
+ uint8_t value2)
+{
+ uint8_t packet[] = { type, value, value2 };
+ DPRINTF("writing key %x %x\n", type, value);
+ baum_write_packet(baum, packet, sizeof(packet));
+}
+
/* We got some data on the BrlAPI socket */
static void baum_chr_read(void *opaque)
{
- BaumDriverState *baum = opaque;
+ BaumChardev *baum = BAUM_CHARDEV(opaque);
brlapi_keyCode_t code;
int ret;
if (!baum->brlapi)
return;
+ if (!baum_deferred_init(baum))
+ return;
while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) {
DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code);
/* Emulate */
}
break;
case BRLAPI_KEY_TYPE_SYM:
- break;
+ {
+ brlapi_keyCode_t keysym = code & BRLAPI_KEY_CODE_MASK;
+ if (keysym < 0x100) {
+ uint8_t dots = nabcc_translation[ASCII2DOTS][keysym];
+ if (dots) {
+ baum_send_key2(baum, BAUM_RSP_EntryKeys, 0, dots);
+ baum_send_key2(baum, BAUM_RSP_EntryKeys, 0, 0);
+ }
+ }
+ break;
+ }
}
}
if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) {
}
}
-static void baum_close(struct CharDriverState *chr)
+static void baum_chr_free(Chardev *chr)
{
- BaumDriverState *baum = chr->opaque;
+ BaumChardev *baum = BAUM_CHARDEV(chr);
timer_free(baum->cellCount_timer);
if (baum->brlapi) {
brlapi__closeConnection(baum->brlapi);
g_free(baum->brlapi);
}
- g_free(baum);
}
-static CharDriverState *chr_baum_init(const char *id,
- ChardevBackend *backend,
- ChardevReturn *ret,
- Error **errp)
+static void baum_chr_open(Chardev *chr,
+ ChardevBackend *backend,
+ bool *be_opened,
+ Error **errp)
{
- ChardevCommon *common = backend->u.braille.data;
- BaumDriverState *baum;
- CharDriverState *chr;
+ BaumChardev *baum = BAUM_CHARDEV(chr);
brlapi_handle_t *handle;
-#if defined(CONFIG_SDL)
-#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
- SDL_SysWMinfo info;
-#endif
-#endif
- int tty;
-
- chr = qemu_chr_alloc(common, errp);
- if (!chr) {
- return NULL;
- }
- baum = g_malloc0(sizeof(BaumDriverState));
- baum->chr = chr;
-
- chr->opaque = baum;
- chr->chr_write = baum_write;
- chr->chr_accept_input = baum_accept_input;
- chr->chr_close = baum_close;
handle = g_malloc0(brlapi_getHandleSize());
baum->brlapi = handle;
if (baum->brlapi_fd == -1) {
error_setg(errp, "brlapi__openConnection: %s",
brlapi_strerror(brlapi_error_location()));
- goto fail_handle;
+ g_free(handle);
+ return;
}
+ baum->deferred_init = 0;
baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum);
- if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) {
- error_setg(errp, "brlapi__getDisplaySize: %s",
- brlapi_strerror(brlapi_error_location()));
- goto fail;
- }
-
-#if defined(CONFIG_SDL)
-#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
- memset(&info, 0, sizeof(info));
- SDL_VERSION(&info.version);
- if (SDL_GetWMInfo(&info))
- tty = info.info.x11.wmwindow;
- else
-#endif
-#endif
- tty = BRLAPI_TTY_DEFAULT;
-
- if (brlapi__enterTtyMode(handle, tty, NULL) == -1) {
- error_setg(errp, "brlapi__enterTtyMode: %s",
- brlapi_strerror(brlapi_error_location()));
- goto fail;
- }
-
qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum);
+}
- return chr;
+static void char_braille_class_init(ObjectClass *oc, void *data)
+{
+ ChardevClass *cc = CHARDEV_CLASS(oc);
-fail:
- timer_free(baum->cellCount_timer);
- brlapi__closeConnection(handle);
-fail_handle:
- g_free(handle);
- g_free(chr);
- g_free(baum);
- return NULL;
+ cc->open = baum_chr_open;
+ cc->chr_write = baum_chr_write;
+ cc->chr_accept_input = baum_chr_accept_input;
+ cc->chr_free = baum_chr_free;
}
+static const TypeInfo char_braille_type_info = {
+ .name = TYPE_CHARDEV_BRAILLE,
+ .parent = TYPE_CHARDEV,
+ .instance_size = sizeof(BaumChardev),
+ .class_init = char_braille_class_init,
+};
+
static void register_types(void)
{
- register_char_driver("braille", CHARDEV_BACKEND_KIND_BRAILLE, NULL,
- chr_baum_init);
+ static const CharDriver driver = {
+ .kind = CHARDEV_BACKEND_KIND_BRAILLE,
+ };
+
+ register_char_driver(&driver);
+ type_register_static(&char_braille_type_info);
}
type_init(register_types);