mpsse
index
/usr/lib/python2.6/dist-packages/mpsse.py
Module Docs

 
Modules
       
pylibmpsse

 
Classes
       
MPSSE

 
class MPSSE
    Python class wrapper for libmpsse.
 
  Methods defined here:
__init__(self, mode=None, frequency=100000, endianess=0)
Class constructor.
 
@mode      - The MPSSE mode to use, one of: SPI0, SPI1, SPI2, SPI3, I2C, GPIO, BITBANG, None.
             If None, no attempt will be made to connect to the FTDI chip. Use this if you want to call the Open method manually.
@frequency - The frequency to use for the specified serial protocol, in hertz (default: 100KHz).
@endianess - The endianess of data transfers, one of: MSB, LSB (default: MSB).
 
Returns None.
Open(self, vid, pid, mode, frequency=100000, endianess=0, interface=1, description=None, serial=None, index=0)
Opens the specified FTDI device.
Called internally by __init__ if the __init__ mode is not None.
 
@vid         - FTDI USB vendor ID.
@pid         - FTDI USB product ID.
@mode        - The MPSSE mode to use, one of: SPI0, SPI1, SPI2, SPI3, I2C, GPIO, BITBANG.
@frequency   - The frequency to use for the specified serial protocol, in hertz (default: 100KHz).
@endianess   - The endianess of data transfers, one of: MSB, LSB (default: MSB).
@interface   - The interface to use on the FTDI chip, one of: IFACE_A, IFACE_B, IFACE_C, IFACE_D, IFACE_ANY (default: IFACE_A).
@description - FTDI device product description (default: None).
@serial      - FTDI device serial number (default: None).
@index       - Number of matching device to open if there are more than one, starts with zero (default: 0).
 
Returns MPSSE_OK on success.
Raises an exeption on failure.
Close(self)
Closes the FTDI device connection, deinitializes libftdi, and frees the libmpsse context.
 
Returns None.
EnableBitmode(self, tf)
Enables/disables bitwise data transfers.
Called internally by ReadBits and WriteBites.
 
@tf - Set to 1 to enable bitwise transfers, 0 to disable.
 
Returns None.
ErrorString(self)
Returns the last libftdi error string.
FlushAfterRead(self, tf)
Enables / disables the explicit flushing of the recieve buffer after each read operation.
 
@tf - Set to 1 to enable flushing, 0 to disable (disabled by default).
 
Returns None.
GetAck(self)
Returns the last received ACK bit.
 
Returns one of: ACK, NACK.
GetClock(self)
Returns the currently configured clock rate, in hertz.
GetDescription(self)
Returns the description of the FTDI chip, if any. 
This will only be populated if __init__ was used to open the device.
GetPid(self)
Returns the product ID of the FTDI chip.
GetVid(self)
Returns the vendor ID of the FTDI chip.
PinHigh(self, pin)
Sets the specified GPIO pin high.
 
@pin - Pin number 0 - 11 in GPIO mode.
       In all other modes, one of: GPIOL0, GPIOL1, GPIOL2, GPIOL3, GPIOH0, GPIOH1, GPIOH2, GPIOH3, GPIOH4, GPIOH5, GPIOH6, GPIOH7.
 
Returns MPSSE_OK on success.
Raises an exception on failure.
PinLow(self, pin)
Sets the specified GPIO pin low.
 
@pin - Pin number 0 - 11 in GPIO mode.
       In all other modes, one of: GPIOL0, GPIOL1, GPIOL2, GPIOL3, GPIOH0, GPIOH1, GPIOH2, GPIOH3, GPIOH4, GPIOH5, GPIOH6, GPIOH7.
 
Returns MPSSE_OK on success.
Raises an exception on failure.
PinState(self, pin, state=-1)
Checks the current state of the pins.
For use in BITBANG mode only.
 
@pin   - The pin number whose state you want to check. 
@state - The value returned by ReadPins. If not specified, ReadPins will be called automatically.
 
Returns a 1 if the pin is high, 0 if the pin is low.
Read(self, size)
Reads bytes over the selected serial protocol.
 
@size - Number of bytes to read.
 
Returns a string of size bytes.
ReadBits(self, n)
Performs a bitwise read of up to 8 bits at a time.
 
@n - Number of bits to read.
 
Returns an integer value with the read bits set.
ReadPins(self)
Reads the current state of the chip's pins.
For use in BITBANG mode only.
 
Returns an integer with the corresponding pin's bits set.
SendAcks(self)
Causes all subsequent I2C read operations to respond with an acknowledgement.
 
Returns None.
SendNacks(self)
Causes all subsequent I2C read operations to respond with a no-acknowledgement.
 
Returns None.
SetAck(self, ack)
Sets the transmitted ACK bit.
For use only in I2C mode.
 
@ack - One of: ACK, NACK.
 
Returns None.
SetCSIdle(self, idle)
Sets the idle state of the chip select pin.
 
@idle - Set to 1 to idle high, 0 to idle low (CS idles high by default).
 
Returns None.
SetClock(self, frequency)
Sets the appropriate divisor for the desired clock frequency.
Called internally by __init__ and Open.
 
@frequency - The desired clock frequency, in hertz.
 
Returns MPSSE_OK on success.
Raises an exception on failure.
SetDirection(self, direction)
Sets the input/output direction of pins as determined by direction (1 = Output, 0 = Input). 
For use in BITBANG mode only.
 
@direction -  Byte indicating input/output direction of each bit (1 is output, 0 is input). 
 
Returns MPSSE_OK on success.
Raises an exception on failure.
SetLoopback(self, enable)
Enable / disable internal loopback. Loopback is disabled by default.
 
@enable - Set to 1 to enable loopback, 0 to disable (disabled by default).
 
Returns MPSSE_OK on success.
Raises an exception on failure.
SetMode(self, mode, endianess)
Sets the appropriate transmit and receive commands based on the requested mode and byte order.
Called internally by __init__ and Open.
 
@mode      - The MPSSE mode to use, one of: SPI0, SPI1, SPI2, SPI3, I2C, GPIO, BITBANG.
@endianess - The endianess of data transfers, one of: MSB, LSB.
 
Returns MPSSE_OK on success.
Raises an exception on failure.
Start(self)
Send data start condition.
 
Returns MPSSE_OK on success.
Raises an exception on failure.
Stop(self)
Send data stop condition.
 
Returns MPSSE_OK on success.
Raises an exception on failure.
Transfer(self, data)
Transfers data over the selected serial protocol.
For use only in SPI0, SPI1, SPI2, SPI3 modes.
 
@data - A string of bytes to be written.
 
Returns a string of len(data) bytes.
Tristate(self)
Puts all I/O pins into a tristate mode (FT232H only).
Version(self)
Returns the libmpsse version number.
High nibble is major, low nibble is minor.
Write(self, data)
Writes bytes out via the selected serial protocol.
 
@data - A string of bytes to be written.
 
Returns MPSSE_OK on success.
Raises an exception on failure.
WriteBits(self, bits, n)
Performs a bitwise write of up to 8 bits at a time.
 
@bits - An integer of bits to be written.
@n    - Transmit n number of least-significant bits.
 
Returns MPSSE_OK on success.
Raises an exception on failure.
WritePins(self, data)
Writes a new state to the chip's pins.
For use in BITBANG mode only.
 
@data - An integer with the bits set to the desired pin states (1 = output, 0 = input).
 
Returns MPSSE_OK on success.
Raises an exception on failure.

 
Data
        ACK = 0
BITBANG = 7
FIFTEEN_MHZ = 15000000
FIVE_MHZ = 5000000
FOUR_HUNDRED_KHZ = 400000
GPIO = 6
GPIOH0 = 4
GPIOH1 = 5
GPIOH2 = 6
GPIOH3 = 7
GPIOH4 = 8
GPIOH5 = 9
GPIOH6 = 10
GPIOH7 = 11
GPIOL0 = 0
GPIOL1 = 1
GPIOL2 = 2
GPIOL3 = 3
I2C = 5
IFACE_A = 1
IFACE_ANY = 0
IFACE_B = 2
IFACE_C = 3
IFACE_D = 4
LSB = 8
MPSSE_FAIL = -1
MPSSE_OK = 0
MSB = 0
NACK = 1
ONE_HUNDRED_KHZ = 100000
ONE_MHZ = 1000000
SIX_MHZ = 6000000
SPI0 = 1
SPI1 = 2
SPI2 = 3
SPI3 = 4
TEN_MHZ = 10000000
THIRTY_MHZ = 30000000
TWELVE_MHZ = 12000000
TWO_MHZ = 2000000