kopia lustrzana https://github.com/felHR85/UsbSerial
CP2130 ids and closeSPI method added
rodzic
c437f77816
commit
a1480886cd
|
@ -0,0 +1,32 @@
|
|||
package com.felhr.deviceids;
|
||||
|
||||
public class CP2130Ids
|
||||
{
|
||||
private static final ConcreteDevice[] cp2130Devices = new ConcreteDevice[]{
|
||||
new ConcreteDevice(0x10C4, 0x87a0),
|
||||
};
|
||||
|
||||
public static boolean isDeviceSupported(int vendorId, int productId)
|
||||
{
|
||||
for(int i=0;i<=cp2130Devices.length-1;i++)
|
||||
{
|
||||
if(cp2130Devices[i].vendorId == vendorId && cp2130Devices[i].productId == productId )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class ConcreteDevice
|
||||
{
|
||||
public int vendorId;
|
||||
public int productId;
|
||||
|
||||
public ConcreteDevice(int vendorId, int productId)
|
||||
{
|
||||
this.vendorId = vendorId;
|
||||
this.productId = productId;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -158,6 +158,14 @@ public class CP2130SpiDevice extends UsbSpiDevice
|
|||
return data[currentChannel] & 0x07;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeSPI()
|
||||
{
|
||||
killWorkingThread();
|
||||
killWriteThread();
|
||||
connection.releaseInterface(mInterface);
|
||||
}
|
||||
|
||||
private boolean openCP2130()
|
||||
{
|
||||
if(connection.claimInterface(mInterface, true))
|
||||
|
|
|
@ -3,7 +3,8 @@ package com.felhr.usbserial;
|
|||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbEndpoint;
|
||||
import android.hardware.usb.UsbRequest;
|
||||
|
||||
import com.felhr.deviceids.CP2130Ids;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
|
@ -32,7 +33,21 @@ public abstract class UsbSpiDevice implements UsbSpiInterface
|
|||
this.serialBuffer = new SerialBuffer(false);
|
||||
}
|
||||
|
||||
//TODO: Factory methods
|
||||
public static UsbSpiDevice createUsbSerialDevice(UsbDevice device, UsbDeviceConnection connection)
|
||||
{
|
||||
return createUsbSerialDevice(device, connection, -1);
|
||||
}
|
||||
|
||||
public static UsbSpiDevice createUsbSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
|
||||
{
|
||||
int vid = device.getVendorId();
|
||||
int pid = device.getProductId();
|
||||
|
||||
if(CP2130Ids.isDeviceSupported(vid, pid))
|
||||
return new CP2130SpiDevice(device, connection, iface);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -62,6 +77,9 @@ public abstract class UsbSpiDevice implements UsbSpiInterface
|
|||
@Override
|
||||
public abstract int getSelectedSlave();
|
||||
|
||||
@Override
|
||||
public abstract void closeSPI();
|
||||
|
||||
protected class WriteThread extends Thread
|
||||
{
|
||||
private UsbEndpoint outEndpoint;
|
||||
|
|
|
@ -19,6 +19,7 @@ public interface UsbSpiInterface
|
|||
void setClock(int clockDivider);
|
||||
void selectSlave(int nSlave);
|
||||
void setMISOCallback(UsbMISOCallback misoCallback);
|
||||
void closeSPI();
|
||||
|
||||
// Status information
|
||||
int getClockDivider();
|
||||
|
|
Ładowanie…
Reference in New Issue