Skip to content

Commit

Permalink
Merge pull request felHR85#255 from TheSven73/fix-microchip-v2
Browse files Browse the repository at this point in the history
Correctly determine Microchip pid:vid 04d8:000a device class
  • Loading branch information
felHR85 authored Jul 7, 2019
2 parents 58bc4a4 + 6180eb4 commit d0232ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
24 changes: 22 additions & 2 deletions usbserial/src/main/java/com/felhr/deviceids/FTDISioIds.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.felhr.deviceids;

import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbInterface;

import static com.felhr.deviceids.Helpers.createTable;
import static com.felhr.deviceids.Helpers.createDevice;

Expand Down Expand Up @@ -251,7 +254,6 @@ private FTDISioIds()
createDevice(0x03eb, 0x2109),
createDevice(0x0456, 0xf000),
createDevice(0x0456, 0xf001),
createDevice(0x04d8, 0x000a),
createDevice(0x0584, 0xb020),
createDevice(0x0647, 0x0100),
createDevice(0x06CE, 0x8311),
Expand Down Expand Up @@ -560,7 +562,25 @@ private FTDISioIds()
createDevice(0x0403, 0x0) //fake FTDI reprogrammed by driver
);

public static boolean isDeviceSupported(int vendorId, int productId) {
private static boolean isMicrochipFtdi(UsbDevice dev) {
if (dev.getVendorId() != 0x04d8 || dev.getProductId() != 0x000a)
return false;
for (int i = 0; i < dev.getInterfaceCount(); i++) {
UsbInterface intf = dev.getInterface(i);
if (intf.getInterfaceClass() == 0xff && intf.getInterfaceSubclass() == 0xff &&
intf.getInterfaceProtocol() == 0x00)
return true;
}
return false;
}

public static boolean isDeviceSupported(UsbDevice dev) {
return Helpers.exists(ftdiDevices, dev.getVendorId(), dev.getProductId()) ||
isMicrochipFtdi(dev);

}

static boolean isDeviceIdSupported(int vendorId, int productId) {
return Helpers.exists(ftdiDevices, vendorId, productId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static UsbSerialDevice createUsbSerialDevice(UsbDevice device, UsbDeviceC
int vid = device.getVendorId();
int pid = device.getProductId();

if(FTDISioIds.isDeviceSupported(vid, pid))
if(FTDISioIds.isDeviceSupported(device))
return new FTDISerialDevice(device, connection, iface);
else if(CP210xIds.isDeviceSupported(vid, pid))
return new CP2102SerialDevice(device, connection, iface);
Expand Down Expand Up @@ -107,7 +107,7 @@ public static boolean isSupported(UsbDevice device)
int vid = device.getVendorId();
int pid = device.getProductId();

if(FTDISioIds.isDeviceSupported(vid, pid))
if(FTDISioIds.isDeviceSupported(device))
return true;
else if(CP210xIds.isDeviceSupported(vid, pid))
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testLongPacking() {

for (TestCase tc : cases) {
Assert.assertTrue(CP210xIds.isDeviceSupported(tc.vendor, tc.product));
Assert.assertFalse(FTDISioIds.isDeviceSupported(tc.vendor, tc.product));
Assert.assertFalse(FTDISioIds.isDeviceIdSupported(tc.vendor, tc.product));
}
}

Expand Down

0 comments on commit d0232ed

Please sign in to comment.