1
0
mirror of https://github.com/mik3y/usb-serial-for-android synced 2025-06-07 16:06:10 +00:00

relax CH340 initialization

controlIn(0x95, 0x0706) result includes control line values
This commit is contained in:
Kai Morich 2019-02-23 16:10:11 +01:00 committed by kai-morich
parent 2cad1fd5a2
commit 5096d6940c

View File

@ -141,7 +141,7 @@ public class Ch34xSerialDriver implements UsbSerialDriver {
int ret = controlIn(request, value, 0, buffer); int ret = controlIn(request, value, 0, buffer);
if (ret < 0) { if (ret < 0) {
throw new IOException("Faild send cmd [" + msg + "]"); throw new IOException("Failed send cmd [" + msg + "]");
} }
if (ret != expected.length) { if (ret != expected.length) {
@ -155,14 +155,14 @@ public class Ch34xSerialDriver implements UsbSerialDriver {
int current = buffer[i] & 0xff; int current = buffer[i] & 0xff;
if (expected[i] != current) { if (expected[i] != current) {
throw new IOException("Expected 0x" + Integer.toHexString(expected[i]) + " bytes, but get 0x" + Integer.toHexString(current) + " [" + msg + "]"); throw new IOException("Expected 0x" + Integer.toHexString(expected[i]) + " byte, but get 0x" + Integer.toHexString(current) + " [" + msg + "]");
} }
} }
} }
private void writeHandshakeByte() throws IOException { private void writeHandshakeByte() throws IOException {
if (controlOut(0xa4, ~((dtr ? 1 << 5 : 0) | (rts ? 1 << 6 : 0)), 0) < 0) { if (controlOut(0xa4, ~((dtr ? 1 << 5 : 0) | (rts ? 1 << 6 : 0)), 0) < 0) {
throw new IOException("Faild to set handshake byte"); throw new IOException("Failed to set handshake byte");
} }
} }
@ -181,7 +181,8 @@ public class Ch34xSerialDriver implements UsbSerialDriver {
throw new IOException("Init failed: #5"); throw new IOException("Init failed: #5");
} }
checkState("init #6", 0x95, 0x0706, new int[]{0xff, 0xee}); checkState("init #6", 0x95, 0x0706, new int[]{-1/*0xf?*/, 0xee});
if (controlOut(0xa1, 0x501f, 0xd90a) < 0) { if (controlOut(0xa1, 0x501f, 0xd90a) < 0) {
throw new IOException("Init failed: #7"); throw new IOException("Init failed: #7");