Skip to content

Commit

Permalink
[lib] Refactor adapter class names
Browse files Browse the repository at this point in the history
  • Loading branch information
3cky committed Jul 13, 2020
1 parent 45e192c commit 7ff10d2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;

import com.github.ykc3.android.usbi2c.adapter.UsbI2cCh341Adapter;
import com.github.ykc3.android.usbi2c.adapter.UsbI2cCp2112Adapter;
import com.github.ykc3.android.usbi2c.adapter.UsbI2cTinyAdapter;
import com.github.ykc3.android.usbi2c.adapter.Ch341UsbI2cAdapter;
import com.github.ykc3.android.usbi2c.adapter.Cp2112UsbI2cAdapter;
import com.github.ykc3.android.usbi2c.adapter.TinyUsbI2cAdapter;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -92,9 +92,9 @@ public static Builder create(UsbManager usbManager) {
*/
public static List<Class<? extends UsbI2cAdapter>> getSupportedUsbI2cAdapters() {
List<Class<? extends UsbI2cAdapter>> usbI2cAdapters = new ArrayList<>();
usbI2cAdapters.add(UsbI2cTinyAdapter.class);
usbI2cAdapters.add(UsbI2cCp2112Adapter.class);
usbI2cAdapters.add(UsbI2cCh341Adapter.class);
usbI2cAdapters.add(TinyUsbI2cAdapter.class);
usbI2cAdapters.add(Cp2112UsbI2cAdapter.class);
usbI2cAdapters.add(Ch341UsbI2cAdapter.class);
return usbI2cAdapters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;

abstract class UsbI2cBaseAdapter implements UsbI2cAdapter {
abstract class BaseUsbI2cAdapter implements UsbI2cAdapter {
// Linux kernel flags
static final int I2C_M_RD = 0x01; // read data, from slave to master

Expand All @@ -46,10 +46,10 @@ abstract class UsbI2cBaseAdapter implements UsbI2cAdapter {

protected final ReentrantLock accessLock = new ReentrantLock();

protected abstract class UsbI2cBaseDevice implements UsbI2cDevice {
protected abstract class BaseUsbI2cDevice implements UsbI2cDevice {
final int address;

UsbI2cBaseDevice(int address) {
BaseUsbI2cDevice(int address) {
this.address = (address & 0x7f);
}

Expand Down Expand Up @@ -110,9 +110,9 @@ public void writeRegBuffer(int reg, byte[] buffer, int length) throws IOExceptio
try {
accessLock.lock();
int len = Math.min(length, MAX_MESSAGE_SIZE);
UsbI2cBaseAdapter.this.buffer[0] = (byte) reg;
System.arraycopy(buffer, 0, UsbI2cBaseAdapter.this.buffer, 1, len);
write(UsbI2cBaseAdapter.this.buffer, len + 1);
BaseUsbI2cAdapter.this.buffer[0] = (byte) reg;
System.arraycopy(buffer, 0, BaseUsbI2cAdapter.this.buffer, 1, len);
write(BaseUsbI2cAdapter.this.buffer, len + 1);
} finally {
accessLock.unlock();
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public void write(byte[] buffer, int length) throws IOException {
protected abstract void deviceRead(byte[] buffer, int length) throws IOException;
}

UsbI2cBaseAdapter(UsbI2cManager i2cManager, UsbDevice usbDevice) {
BaseUsbI2cAdapter(UsbI2cManager i2cManager, UsbDevice usbDevice) {
this.i2cManager = i2cManager;
this.usbDevice = usbDevice;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* CH341 is a USB bus convert chip, providing UART, printer port, parallel and synchronous serial with
* 2-wire or 4-wire through USB bus (http://www.anok.ceti.pl/download/ch341ds1.pdf).
*/
public class UsbI2cCh341Adapter extends UsbI2cBaseAdapter {
public class Ch341UsbI2cAdapter extends BaseUsbI2cAdapter {
private static final int CH341_I2C_LOW_SPEED = 0; // low speed - 20kHz
private static final int CH341_I2C_STANDARD_SPEED = 1; // standard speed - 100kHz
private static final int CH341_I2C_FAST_SPEED = 2; // fast speed - 400kHz
Expand All @@ -58,8 +58,8 @@ public class UsbI2cCh341Adapter extends UsbI2cBaseAdapter {
private UsbEndpoint usbReadEndpoint;
private UsbEndpoint usbWriteEndpoint;

class UsbI2cCh341Device extends UsbI2cBaseDevice {
UsbI2cCh341Device(int address) {
class Ch341UsbI2cDevice extends BaseUsbI2cDevice {
Ch341UsbI2cDevice(int address) {
super(address);
}

Expand All @@ -80,13 +80,13 @@ protected void deviceWrite(byte[] buffer, int length) throws IOException {
}


public UsbI2cCh341Adapter(UsbI2cManager i2cManager, UsbDevice usbDevice) {
public Ch341UsbI2cAdapter(UsbI2cManager i2cManager, UsbDevice usbDevice) {
super(i2cManager, usbDevice);
}

@Override
public UsbI2cDevice getDevice(int address) {
return new UsbI2cCh341Device(address);
return new Ch341UsbI2cDevice(address);
}

@Override
Expand Down Expand Up @@ -238,7 +238,7 @@ private int transferBulkData(byte[] writeData, int writeLength,
*/
private int readBulkData(byte[] data, int length) throws IOException {
int res = usbDeviceConnection.bulkTransfer(usbReadEndpoint, data,
length, UsbI2cBaseAdapter.USB_TIMEOUT_MILLIS);
length, BaseUsbI2cAdapter.USB_TIMEOUT_MILLIS);
if (res < 0) {
throw new IOException("Bulk read error, result: " + res);
}
Expand All @@ -254,7 +254,7 @@ private int readBulkData(byte[] data, int length) throws IOException {
*/
private void writeBulkData(byte[] data, int length) throws IOException {
int res = usbDeviceConnection.bulkTransfer(usbWriteEndpoint, data, length,
UsbI2cBaseAdapter.USB_TIMEOUT_MILLIS);
BaseUsbI2cAdapter.USB_TIMEOUT_MILLIS);
if (res < 0) {
throw new IOException("Bulk write error, result: " + res);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* Programming Interface Specification:
* https://www.silabs.com/documents/public/application-notes/an495-cp2112-interface-specification.pdf
*/
public class UsbI2cCp2112Adapter extends UsbI2cBaseAdapter {
public class Cp2112UsbI2cAdapter extends BaseUsbI2cAdapter {
// HID feature request GET_REPORT code
private static final int HID_FEATURE_REQUEST_REPORT_GET = 0x01;
// HID feature request SET_REPORT code
Expand Down Expand Up @@ -88,8 +88,8 @@ public class UsbI2cCp2112Adapter extends UsbI2cBaseAdapter {
private UsbEndpoint usbReadEndpoint;
private UsbEndpoint usbWriteEndpoint;

class UsbI2cCp2112Device extends UsbI2cBaseDevice {
UsbI2cCp2112Device(int address) {
class Cp2112UsbI2cDevice extends BaseUsbI2cDevice {
Cp2112UsbI2cDevice(int address) {
super(address);
}

Expand All @@ -109,13 +109,13 @@ protected void deviceWrite(byte[] buffer, int length) throws IOException {
}
}

public UsbI2cCp2112Adapter(UsbI2cManager manager, UsbDevice usbDevice) {
public Cp2112UsbI2cAdapter(UsbI2cManager manager, UsbDevice usbDevice) {
super(manager, usbDevice);
}

@Override
public UsbI2cDevice getDevice(int address) {
return new UsbI2cCp2112Device(address);
return new Cp2112UsbI2cDevice(address);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Cheap and simple I2C to USB interface (http://www.harbaum.org/till/i2c_tiny_usb).
*/
public class UsbI2cTinyAdapter extends UsbI2cBaseAdapter {
public class TinyUsbI2cAdapter extends BaseUsbI2cAdapter {

// Commands via USB, must match command ids in the firmware
private static final int CMD_ECHO = 0;
Expand All @@ -44,10 +44,10 @@ public class UsbI2cTinyAdapter extends UsbI2cBaseAdapter {

private static final int USB_RECIP_INTERFACE = 0x01;

class UsbI2cTinyDevice extends UsbI2cBaseDevice {
class TinyUsbI2cDevice extends BaseUsbI2cDevice {
private final byte[] regBuffer = new byte[1];

UsbI2cTinyDevice(int address) {
TinyUsbI2cDevice(int address) {
super(address);
}

Expand All @@ -71,13 +71,13 @@ protected void deviceWrite(byte[] buffer, int length) throws IOException {
}
}

public UsbI2cTinyAdapter(UsbI2cManager manager, UsbDevice usbDevice) {
public TinyUsbI2cAdapter(UsbI2cManager manager, UsbDevice usbDevice) {
super(manager, usbDevice);
}

@Override
public UsbI2cDevice getDevice(int address) {
return new UsbI2cTinyDevice(address);
return new TinyUsbI2cDevice(address);
}

private void usbRead(int cmd, int value, int index, byte[] data, int len) throws IOException {
Expand Down

0 comments on commit 7ff10d2

Please sign in to comment.