Hello,
Samuel Thibault, le Fri 11 Jan 2008 11:09:23 +, a écrit :
> Samuel Thibault, le Fri 11 Jan 2008 00:23:12 +, a écrit :
> > I would like to implement support for braille devices, and for this I'd
> > need to first implement a USB serial device (FTDI chip). Has anybody
> > worked on that already?
>
> Ok, was easier than expected, Here is a patch. The serial support is
> incomplete however because qemu still lacks support for flow control and
> modem lines.
>
> You will notice in tty_serial_init that I made the baud values more
> relaxed. This is because with divisor/baud conversions, things never get
> exact, so we need to be laxist with the value. For instance here with
> FTDI, the base divisor is 4800/2, so for 57600 bps the guest needs
> to choose between divisors 416 and 417, which bring to either 57692bps
> or 57553bps but not exactly 57600bps. It happens that Linux chooses
> divisor 416, hence 57692bps. Of course, the higher the speed, the worse
> things get. The 1.1 factor is the smallest factor I could find between
> usual bps values, notably B110, B134 and B150.
Here is an updated version, that takes parameters, so as to be able to
notably provide the product ID.
Samuel
? .vl.c.swp
? stvJqKpr
Index: Makefile
===
RCS file: /sources/qemu/qemu/Makefile,v
retrieving revision 1.140
diff -u -p -r1.140 Makefile
--- Makefile6 Jan 2008 18:27:12 - 1.140
+++ Makefile13 Jan 2008 01:54:17 -
@@ -57,7 +57,7 @@ OBJS+=i2c.o smbus.o smbus_eeprom.o max73
OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o
OBJS+=scsi-disk.o cdrom.o
OBJS+=scsi-generic.o
-OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o
+OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o usb-serial.o
OBJS+=sd.o ssi-sd.o
ifdef CONFIG_WIN32
Index: vl.c
===
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.395
diff -u -p -r1.395 vl.c
--- vl.c8 Jan 2008 19:32:16 - 1.395
+++ vl.c13 Jan 2008 01:54:21 -
@@ -2237,45 +2237,33 @@ static void tty_serial_init(int fd, int
#endif
tcgetattr (fd, &tty);
-switch(speed) {
-case 50:
+#define MARGIN 1.1
+if (speed <= 50 * MARGIN)
spd = B50;
-break;
-case 75:
+else if (speed <= 75 * MARGIN)
spd = B75;
-break;
-case 300:
+else if (speed <= 300 * MARGIN)
spd = B300;
-break;
-case 600:
+else if (speed <= 600 * MARGIN)
spd = B600;
-break;
-case 1200:
+else if (speed <= 1200 * MARGIN)
spd = B1200;
-break;
-case 2400:
+else if (speed <= 2400 * MARGIN)
spd = B2400;
-break;
-case 4800:
+else if (speed <= 4800 * MARGIN)
spd = B4800;
-break;
-case 9600:
+else if (speed <= 9600 * MARGIN)
spd = B9600;
-break;
-case 19200:
+else if (speed <= 19200 * MARGIN)
spd = B19200;
-break;
-case 38400:
+else if (speed <= 38400 * MARGIN)
spd = B38400;
-break;
-case 57600:
+else if (speed <= 57600 * MARGIN)
spd = B57600;
-break;
-default:
-case 115200:
+else if (speed <= 115200 * MARGIN)
+spd = B115200;
+else
spd = B115200;
-break;
-}
cfsetispeed(&tty, spd);
cfsetospeed(&tty, spd);
@@ -5196,6 +5184,8 @@ static int usb_device_add(const char *de
dev = usb_msd_init(p);
} else if (!strcmp(devname, "wacom-tablet")) {
dev = usb_wacom_init();
+} else if (strstart(devname, "serial:", &p)) {
+ dev = usb_serial_init(p);
} else {
return -1;
}
Index: hw/usb-serial.c
===
RCS file: hw/usb-serial.c
diff -N hw/usb-serial.c
--- /dev/null 1 Jan 1970 00:00:00 -
+++ hw/usb-serial.c 13 Jan 2008 01:54:21 -
@@ -0,0 +1,549 @@
+/*
+ * FTDI FT232BM Device emulation
+ *
+ * Copyright (c) 2006 CodeSourcery.
+ * Copyright (c) 2008 Samuel Thibault <[EMAIL PROTECTED]>
+ * Written by Paul Brook, reused for FTDI by Samuel Thibault
+ *
+ * This code is licenced under the LGPL.
+ */
+
+#include "qemu-common.h"
+#include "usb.h"
+#include "qemu-char.h"
+
+//#define DEBUG_Serial
+
+#ifdef DEBUG_Serial
+#define DPRINTF(fmt, args...) \
+do { printf("usb-serial: " fmt , ##args); } while (0)
+#else
+#define DPRINTF(fmt, args...) do {} while(0)
+#endif
+
+#define RECV_BUF 384
+#define SEND_BUF 128// Not used for now
+
+/* Commands */
+#define FTDI_RESET 0
+#define FTDI_SET_MDM_CTRL 1
+#define FTDI_SET_FLOW_CTRL 2
+#define FTDI_SET_BAUD 3
+#define FTDI_SET_DATA 4
+#define FTDI_GET_MDM_ST5
+#define FTDI_SET_EVENT_CHR 6
+#define FTDI_SET_ERROR_CHR 7
+#define FTDI_SET_LATENCY 9
+#define FTDI_GET_LATENCY