FtdiI2cBus
Description
The FtdiI2cBus object is an I2cBus implementation to communicate with an FT232H-based IC2 bus via USB. In addition to reading and writing to the I2C bus it allows controlling the GPIO lines of the FT232H chip.
- › Inherits:
Overview
Properties
Methods
Signals
Enumerations
Properties
channel
This property holds the I2C channel to operate on. Usually only one device with one channel is connected so the default value can be used.
- › Type:
UnsignedInteger
- › Default:
0- › Signal:
channelChanged()
- › Attributes:
Writable
error
This property holds the most recently occurred error or FtdiI2cBus.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.
- › Type:
- › Signal:
errorChanged()
- › Attributes:
Readonly
errorString
This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.
- › Type:
String
- › Signal:
errorStringChanged()
- › Attributes:
Readonly
gpioPinStates
This property holds the states of the 12 GPIOs pins while each pin is represented by one bit.
- › Type:
UnsignedInteger
- › Signal:
gpioPinStatesChanged()
- › Attributes:
Readonly, Requires Polling
latency
This property holds the value for the FTDI latency timer in the range of [1..255]. The latency timer inside the FTDI device is used to flush small transmit buffers. Without this timer the host would not receive any data until the transmit buffer of the device is full (64 bytes). This allows the device to be better optimized for protocols requiring faster response times from short data packets.
- › Type:
UnsignedInteger
- › Default:
16- › Signal:
latencyChanged()
- › Attributes:
Writable
useFastOperations
This property holds whether to use MPSSE fast read/write operations. Disable if you encounter communication problems.
- › Type:
Boolean
- › Default:
true- › Signal:
useFastOperationsChanged()
- › Attributes:
Writable
Methods
pollGpioPinStates()
This method polls the gpioPinStates property. It is called automatically when using a Polling property modifier on this property and usually does not have to be called manually.
readGpioPin(SignedInteger pin)
This method reads the specified GPIO pin. This method is provided for convenience only. Consider a declarative approach by polling and evaluating the gpioPinStates property.
- › Returns:
Boolean
writeGpioPin(SignedInteger pin, Boolean state)
This method sets the specified GPIO pin to the specified state.
- › Returns:
Boolean
Signals
errorOccurred()
This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.
Enumerations
Error
This enumeration describes all errors which can occur in FtdiI2cBus objects. The most recently occurred error is stored in the error property.
Name |
Value |
Description |
|---|---|---|
|
|
No error occurred or was detected. |
|
|
Device could not be opened. |
|
|
Failed to read the specified number of bytes from configured address. |
|
|
Failed to write the specified number of bytes to configured address. |
|
|
Failed to read GPIO states. |
|
|
Failed to write GPIO states. |
Example
import InCore.Foundation 2.5
import InCore.IO 2.5
Application {
FtdiI2cBus {
Polling on gpioPinStates { }
// read lower 8 GPIO channels
onGpioPinStatesChanged: console.log("GPIO 1-8:", gpioPinStates & 0xff)
// switch on LED attached to GPIO 13
onCompleted: writeGpioPin(13, 1)
}
}