jAER project on SourceForge

ch.unizh.ini.jaer.projects.opticalflow.usbinterface
Class SiLabsC8051F320_OpticalFlowHardwareInterface

java.lang.Object
  extended by ch.unizh.ini.jaer.projects.opticalflow.usbinterface.SiLabsC8051F320_OpticalFlowHardwareInterface
All Implemented Interfaces:
MotionChipInterface, de.thesycon.usbio.PnPNotifyInterface, de.thesycon.usbio.UsbIoErrorCodes, BiasgenHardwareInterface, HardwareInterface

public class SiLabsC8051F320_OpticalFlowHardwareInterface
extends java.lang.Object
implements MotionChipInterface, de.thesycon.usbio.UsbIoErrorCodes, de.thesycon.usbio.PnPNotifyInterface

Servo motor controller using USBIO driver access to SiLabsC8051F320 device.

Author:
tobi

Nested Class Summary
protected  class SiLabsC8051F320_OpticalFlowHardwareInterface.MotionReader
          This reader reads data from the motion chip
 
Field Summary
protected  de.thesycon.usbio.structs.USB_DEVICE_DESCRIPTOR deviceDescriptor
          the USBIO device descriptor
protected  int gDevList
          the devlist handle for USBIO
static java.lang.String GUID
          driver GUID (Globally unique ID, for this USB driver instance
protected  de.thesycon.usbio.UsbIo gUsbIo
          the UsbIo interface to the device.
protected  int numberOfStringDescriptors
           
static short PID
          OpticalFlowBoard Product ID
protected  de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor1
          the first USB string descriptor (Vendor name) (if available)
protected  de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor2
          the second USB string descriptor (Product name) (if available)
protected  de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor3
          the third USB string descriptor (Serial number) (if available)
static short VID
          Optical flow board vendor ID (This is Thesycon's VID)
 
Fields inherited from interface de.thesycon.usbio.UsbIoErrorCodes
USBIO_ERR_ADDITIONAL_EVENT_SIGNALLED, USBIO_ERR_ALREADY_BOUND, USBIO_ERR_ALREADY_CONFIGURED, USBIO_ERR_BABBLE_DETECTED, USBIO_ERR_BAD_START_FRAME, USBIO_ERR_BTSTUFF, USBIO_ERR_BUFFER_OVERRUN, USBIO_ERR_BUFFER_UNDERRUN, USBIO_ERR_BULK_RESTRICTION, USBIO_ERR_CANCELED, USBIO_ERR_CONTROL_NOT_SUPPORTED, USBIO_ERR_CONTROL_RESTRICTION, USBIO_ERR_CRC, USBIO_ERR_DATA_BUFFER_ERROR, USBIO_ERR_DATA_OVERRUN, USBIO_ERR_DATA_TOGGLE_MISMATCH, USBIO_ERR_DATA_UNDERRUN, USBIO_ERR_DEMO_EXPIRED, USBIO_ERR_DEV_NOT_RESPONDING, USBIO_ERR_DEVICE_GONE, USBIO_ERR_DEVICE_NOT_FOUND, USBIO_ERR_DEVICE_NOT_OPEN, USBIO_ERR_DEVICE_NOT_PRESENT, USBIO_ERR_ENDPOINT_HALTED, USBIO_ERR_EP0_RESTRICTION, USBIO_ERR_ERROR_BUSY, USBIO_ERR_ERROR_SHORT_TRANSFER, USBIO_ERR_FAILED, USBIO_ERR_FIFO, USBIO_ERR_FRAME_CONTROL_NOT_OWNED, USBIO_ERR_FRAME_CONTROL_OWNED, USBIO_ERR_INSUFFICIENT_RESOURCES, USBIO_ERR_INTERFACE_NOT_FOUND, USBIO_ERR_INTERNAL_HC_ERROR, USBIO_ERR_INTERRUPT_RESTRICTION, USBIO_ERR_INVALID_CONFIGURATION_DESCRIPTOR, USBIO_ERR_INVALID_DEVICE_STATE, USBIO_ERR_INVALID_DIRECTION, USBIO_ERR_INVALID_FUNCTION_PARAM, USBIO_ERR_INVALID_INBUFFER, USBIO_ERR_INVALID_IOCTL, USBIO_ERR_INVALID_ISO_PACKET, USBIO_ERR_INVALID_OUTBUFFER, USBIO_ERR_INVALID_PARAM, USBIO_ERR_INVALID_PARAMETER, USBIO_ERR_INVALID_PIPE_FLAGS, USBIO_ERR_INVALID_PIPE_HANDLE, USBIO_ERR_INVALID_POWER_STATE, USBIO_ERR_INVALID_RECIPIENT, USBIO_ERR_INVALID_TYPE, USBIO_ERR_INVALID_URB_FUNCTION, USBIO_ERR_ISO_NA_LATE_USBPORT, USBIO_ERR_ISO_NOT_ACCESSED_BY_HW, USBIO_ERR_ISO_NOT_ACCESSED_LATE, USBIO_ERR_ISO_RESTRICTION, USBIO_ERR_ISO_TD_ERROR, USBIO_ERR_ISOCH_REQUEST_FAILED, USBIO_ERR_LOAD_SETUP_API_FAILED, USBIO_ERR_NO_BANDWIDTH, USBIO_ERR_NO_MEMORY, USBIO_ERR_NO_SUCH_DEVICE_INSTANCE, USBIO_ERR_NOT_ACCESSED, USBIO_ERR_NOT_BOUND, USBIO_ERR_NOT_CONFIGURED, USBIO_ERR_NOT_SUPPORTED, USBIO_ERR_OPEN_PIPES, USBIO_ERR_OUT_OF_ADDRESS_SPACE, USBIO_ERR_OUT_OF_MEMORY, USBIO_ERR_PENDING_REQUESTS, USBIO_ERR_PID_CHECK_FAILURE, USBIO_ERR_PIPE_NOT_FOUND, USBIO_ERR_PIPE_RESTRICTION, USBIO_ERR_PIPE_SIZE_RESTRICTION, USBIO_ERR_POOL_EMPTY, USBIO_ERR_POWER_DOWN, USBIO_ERR_REQUEST_FAILED, USBIO_ERR_RESERVED1, USBIO_ERR_RESERVED2, USBIO_ERR_SET_CONFIG_FAILED, USBIO_ERR_SET_CONFIGURATION_FAILED, USBIO_ERR_STALL_PID, USBIO_ERR_STATUS_NOT_MAPPED, USBIO_ERR_SUCCESS, USBIO_ERR_TIMEOUT, USBIO_ERR_TOO_MUCH_ISO_PACKETS, USBIO_ERR_UNEXPECTED_PID, USBIO_ERR_USBD_BUFFER_TOO_SMALL, USBIO_ERR_USBD_INTERFACE_NOT_FOUND, USBIO_ERR_USBD_TIMEOUT, USBIO_ERR_VERSION_MISMATCH, USBIO_ERR_VID_RESTRICTION, USBIO_ERR_XACT_ERROR
 
Constructor Summary
SiLabsC8051F320_OpticalFlowHardwareInterface(int n)
          Creates a new instance of SiLabsC8051F320_USBIO_ServoController
 
Method Summary
 void close()
          Closes the device.
 void flashConfiguration(Biasgen biasgen)
          flashes the configuration in non-volatile storage so they will be reloaded on reset or powerup.
 byte[] formatConfigurationBytes(Biasgen biasgen)
          Formats and returns the bytes that should be sent to set a particular configuration.
 MotionData getData()
          returns MotionData from the device
 short getDID()
           
 int getNumberOfStringDescriptors()
          returns number of string descriptors
 short getPID()
           
 java.lang.String[] getStringDescriptors()
          return the string USB descriptors for the device
 java.lang.String getTypeName()
          get text name of interface, e.g.
 short getVID()
           
 int[] getVIDPID()
          return the USB VID/PID of the interface
protected  boolean hasStringIdentifier()
          checks if device has a string identifier that is a non-empty string
 boolean isOpen()
          reports if interface is open().
 void onAdd()
           
 void onRemove()
           
 void open()
          constrcuts a new USB connection, opens it.
 void openUsbIo()
          This method does the hard work of opening the device, downloading the firmware, making sure everything is OK.
 void sendConfiguration(Biasgen biasgen)
          sends the pot values, but uses a local cache to only send those values that have changed
 void sendVendorRequest(byte request, short value, short index)
          sends a vender request without any data.
 void sendVendorRequest(byte request, short value, short index, de.thesycon.usbio.structs.USBIO_DATA_BUFFER dataBuffer)
          sends a vender request with data.
 void setCaptureMode(int mode)
          sets the data to be captured in each frame.
 void setPowerDown(boolean powerDown)
          sends the powerdown vendor request to power down the chip.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GUID

public static final java.lang.String GUID
driver GUID (Globally unique ID, for this USB driver instance

See Also:
Constant Field Values

VID

public static final short VID
Optical flow board vendor ID (This is Thesycon's VID)

See Also:
Constant Field Values

PID

public static final short PID
OpticalFlowBoard Product ID

See Also:
Constant Field Values

stringDescriptor1

protected de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor1
the first USB string descriptor (Vendor name) (if available)


stringDescriptor2

protected de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor2
the second USB string descriptor (Product name) (if available)


stringDescriptor3

protected de.thesycon.usbio.structs.USB_STRING_DESCRIPTOR stringDescriptor3
the third USB string descriptor (Serial number) (if available)


numberOfStringDescriptors

protected int numberOfStringDescriptors

deviceDescriptor

protected de.thesycon.usbio.structs.USB_DEVICE_DESCRIPTOR deviceDescriptor
the USBIO device descriptor


gUsbIo

protected de.thesycon.usbio.UsbIo gUsbIo
the UsbIo interface to the device. This is assigned on construction by the factory which uses it to open the device. here is used for all USBIO access to the device


gDevList

protected int gDevList
the devlist handle for USBIO

Constructor Detail

SiLabsC8051F320_OpticalFlowHardwareInterface

public SiLabsC8051F320_OpticalFlowHardwareInterface(int n)
Creates a new instance of SiLabsC8051F320_USBIO_ServoController

Parameters:
n - the number of the interface, in range returned by OpticalFlowHardwareInterfaceFactory.getNumInterfacesAvailable().
Method Detail

onAdd

public void onAdd()
Specified by:
onAdd in interface de.thesycon.usbio.PnPNotifyInterface

onRemove

public void onRemove()
Specified by:
onRemove in interface de.thesycon.usbio.PnPNotifyInterface

close

public void close()
Closes the device. Never throws an exception.

Specified by:
close in interface HardwareInterface

getNumberOfStringDescriptors

public int getNumberOfStringDescriptors()
returns number of string descriptors

Returns:
number of string descriptors: 2 for TmpDiff128, 3 for MonitorSequencer

hasStringIdentifier

protected boolean hasStringIdentifier()
checks if device has a string identifier that is a non-empty string

Returns:
false if not, true if there is one

open

public void open()
constrcuts a new USB connection, opens it.

Specified by:
open in interface HardwareInterface

openUsbIo

public void openUsbIo()
               throws HardwareInterfaceException
This method does the hard work of opening the device, downloading the firmware, making sure everything is OK. This method is synchronized to prevent multiple threads from trying to open at the same time, e.g. a GUI thread and the main thread. Opening the device after it has already been opened has no effect.

Throws:
HardwareInterfaceException - if there is a problem. Diagnostics are printed to stderr.
See Also:
close()

getStringDescriptors

public java.lang.String[] getStringDescriptors()
return the string USB descriptors for the device

Returns:
String[] of length 2 of USB descriptor strings.

getVIDPID

public int[] getVIDPID()
return the USB VID/PID of the interface

Returns:
int[] of length 2 containing the Vendor ID (VID) and Product ID (PID) of the device. First element is VID, second element is PID.

getVID

public short getVID()

getPID

public short getPID()

getDID

public short getDID()
Returns:
bcdDevice (the binary coded decimel device version

isOpen

public boolean isOpen()
reports if interface is open().

Specified by:
isOpen in interface HardwareInterface
Returns:
true if already open

getTypeName

public java.lang.String getTypeName()
Description copied from interface: HardwareInterface
get text name of interface, e.g. "CypressFX2" or "SiLabsC8051F320"

Specified by:
getTypeName in interface HardwareInterface

sendVendorRequest

public void sendVendorRequest(byte request,
                              short value,
                              short index)
                       throws HardwareInterfaceException
sends a vender request without any data. Thread safe.

Parameters:
request - the vendor request byte, identifies the request on the device
value - the value of the request (bValue USB field)
index - the "index" of the request (bIndex USB field)
Throws:
HardwareInterfaceException

sendVendorRequest

public void sendVendorRequest(byte request,
                              short value,
                              short index,
                              de.thesycon.usbio.structs.USBIO_DATA_BUFFER dataBuffer)
                       throws HardwareInterfaceException
sends a vender request with data. Thread-safe.

Parameters:
request - the vendor request byte, identifies the request on the device
value - the value of the request (bValue USB field)
index - the "index" of the request (bIndex USB field)
dataBuffer - the data which is to be transmitted to the device
Throws:
HardwareInterfaceException

getData

public MotionData getData()
                   throws java.util.concurrent.TimeoutException
returns MotionData from the device

Specified by:
getData in interface MotionChipInterface
Returns:
MotionData for one frame
Throws:
TimeOutException - when request for exchange with Reader thread times out. Timeout duration is set by DATA_TIMEOUT_MS.
java.util.concurrent.TimeoutException

setPowerDown

public void setPowerDown(boolean powerDown)
                  throws HardwareInterfaceException
Description copied from interface: BiasgenHardwareInterface
sends the powerdown vendor request to power down the chip.

Typically this method toggles the powerDown pin correctly to ensure on-chip biasgen is powered up. Chip may have been plugged in without being powered up. If powerdown is true, simply sets powerdown high. If powerdown is false, powerdown is toggled high and then low, to make sure a nagative transistion occurs. This transistion is necessary to ensure the startup circuit starts up the masterbias again.

Specified by:
setPowerDown in interface BiasgenHardwareInterface
Parameters:
powerDown - true to power OFF the biasgen, false to power on
Throws:
HardwareInterfaceException

sendConfiguration

public void sendConfiguration(Biasgen biasgen)
                       throws HardwareInterfaceException
sends the pot values, but uses a local cache to only send those values that have changed

Specified by:
sendConfiguration in interface BiasgenHardwareInterface
Parameters:
biasgen - the biasgen we are sending for
Throws:
HardwareInterfaceException

flashConfiguration

public void flashConfiguration(Biasgen biasgen)
                        throws HardwareInterfaceException
Description copied from interface: BiasgenHardwareInterface
flashes the configuration in non-volatile storage so they will be reloaded on reset or powerup.

Specified by:
flashConfiguration in interface BiasgenHardwareInterface
Parameters:
biasgen - holds the configuration values
Throws:
HardwareInterfaceException

setCaptureMode

public void setCaptureMode(int mode)
sets the data to be captured in each frame. The mode bits defined for the chip, e.g. Motion18, define which data will be requested. The returned MotionData will signify which data it has.

Specified by:
setCaptureMode in interface MotionChipInterface
Parameters:
mode - the mode
See Also:
Motion18

formatConfigurationBytes

public byte[] formatConfigurationBytes(Biasgen biasgen)
Description copied from interface: BiasgenHardwareInterface
Formats and returns the bytes that should be sent to set a particular configuration.

Specified by:
formatConfigurationBytes in interface BiasgenHardwareInterface
Parameters:
biasgen - the source of the configuration.
Returns:
the array to be sent.

jAER project on SourceForge