kopia lustrzana https://github.com/mik3y/usb-serial-for-android
Add support for Cr50 (Chromebook CCD)
rodzic
80a555a189
commit
9fdb31ee75
|
@ -0,0 +1,96 @@
|
||||||
|
package com.hoho.android.usbserial.driver;
|
||||||
|
|
||||||
|
import android.hardware.usb.UsbConstants;
|
||||||
|
import android.hardware.usb.UsbDevice;
|
||||||
|
import android.hardware.usb.UsbEndpoint;
|
||||||
|
import android.hardware.usb.UsbInterface;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ChromeCcdSerialDriver implements UsbSerialDriver{
|
||||||
|
|
||||||
|
private final String TAG = ChromeCcdSerialDriver.class.getSimpleName();
|
||||||
|
|
||||||
|
private final UsbDevice mDevice;
|
||||||
|
private final List<UsbSerialPort> mPorts;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UsbDevice getDevice() {
|
||||||
|
return mDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UsbSerialPort> getPorts() {
|
||||||
|
return mPorts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChromeCcdSerialDriver(UsbDevice mDevice) {
|
||||||
|
this.mDevice = mDevice;
|
||||||
|
mPorts = new ArrayList<UsbSerialPort>();
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
mPorts.add(new ChromeCcdSerialPort(mDevice, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ChromeCcdSerialPort extends CommonUsbSerialPort {
|
||||||
|
private UsbInterface mDataInterface;
|
||||||
|
|
||||||
|
public ChromeCcdSerialPort(UsbDevice device, int portNumber) {
|
||||||
|
super(device, portNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void openInt() throws IOException {
|
||||||
|
Log.d(TAG, "claiming interfaces, count=" + mDevice.getInterfaceCount());
|
||||||
|
mDataInterface = mDevice.getInterface(mPortNumber);
|
||||||
|
if (!mConnection.claimInterface(mDataInterface, true)) {
|
||||||
|
throw new IOException("Could not claim shared control/data interface");
|
||||||
|
}
|
||||||
|
Log.d(TAG, "endpoint count=" + mDataInterface.getEndpointCount());
|
||||||
|
for (int i = 0; i < mDataInterface.getEndpointCount(); ++i) {
|
||||||
|
UsbEndpoint ep = mDataInterface.getEndpoint(i);
|
||||||
|
if ((ep.getDirection() == UsbConstants.USB_DIR_IN) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) {
|
||||||
|
mReadEndpoint = ep;
|
||||||
|
} else if ((ep.getDirection() == UsbConstants.USB_DIR_OUT) && (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)) {
|
||||||
|
mWriteEndpoint = ep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void closeInt() {
|
||||||
|
try {
|
||||||
|
mConnection.releaseInterface(mDataInterface);
|
||||||
|
} catch(Exception ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UsbSerialDriver getDriver() {
|
||||||
|
return ChromeCcdSerialDriver.this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumSet<ControlLine> getControlLines() throws IOException {
|
||||||
|
return EnumSet.noneOf(ControlLine.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumSet<ControlLine> getSupportedControlLines() throws IOException {
|
||||||
|
return EnumSet.noneOf(ControlLine.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Integer, int[]> getSupportedDevices() {
|
||||||
|
final Map<Integer, int[]> supportedDevices = new LinkedHashMap<>();
|
||||||
|
supportedDevices.put(UsbId.VENDOR_GOOGLE, new int[]{
|
||||||
|
UsbId.GOOGLE_CR50,
|
||||||
|
});
|
||||||
|
return supportedDevices;
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,9 @@ public final class UsbId {
|
||||||
public static final int PROLIFIC_PL2303GE = 0x23e3; // "
|
public static final int PROLIFIC_PL2303GE = 0x23e3; // "
|
||||||
public static final int PROLIFIC_PL2303GS = 0x23f3; // "
|
public static final int PROLIFIC_PL2303GS = 0x23f3; // "
|
||||||
|
|
||||||
|
public static final int VENDOR_GOOGLE = 0x18d1;
|
||||||
|
public static final int GOOGLE_CR50 = 0x5014;
|
||||||
|
|
||||||
public static final int VENDOR_QINHENG = 0x1a86;
|
public static final int VENDOR_QINHENG = 0x1a86;
|
||||||
public static final int QINHENG_CH340 = 0x7523;
|
public static final int QINHENG_CH340 = 0x7523;
|
||||||
public static final int QINHENG_CH341A = 0x5523;
|
public static final int QINHENG_CH341A = 0x5523;
|
||||||
|
|
|
@ -38,6 +38,7 @@ public class UsbSerialProber {
|
||||||
probeTable.addDriver(ProlificSerialDriver.class);
|
probeTable.addDriver(ProlificSerialDriver.class);
|
||||||
probeTable.addDriver(Ch34xSerialDriver.class);
|
probeTable.addDriver(Ch34xSerialDriver.class);
|
||||||
probeTable.addDriver(GsmModemSerialDriver.class);
|
probeTable.addDriver(GsmModemSerialDriver.class);
|
||||||
|
probeTable.addDriver(ChromeCcdSerialDriver.class);
|
||||||
return probeTable;
|
return probeTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue