Download the PHP package microscrap/scrapyard-usb without Composer
On this page you can find all versions of the php package microscrap/scrapyard-usb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download microscrap/scrapyard-usb
More information about microscrap/scrapyard-usb
Files in microscrap/scrapyard-usb
Package scrapyard-usb
Short Description USB connection drivers for the ScrapyardIO GPIO framework: MPSSE digital, I2C and SPI plus FTDI UART over ext-ftdi
License MIT
Informations about the package scrapyard-usb
microscrap/scrapyard-usb
The FTDI adapter for scrapyard-io/framework: the usb driver for I2C, SPI, digital pins and UART over an FTDI USB board such as the FT232H. It works on any machine with a USB port, including a Mac.
| Protocol | Engine | Device names |
|---|---|---|
| I2C, SPI, digital | MPSSE | ft232h, ft2232hl-a, ft2232hl-b, ft4232hl-a … ft4232hl-d |
| UART | FTDI serial | product name (ft232h, ft2232h, ft4232h, ft232r, ft230x, …) or USB product id (0x6014) |
There is no PWM driver.
Requirements
- PHP 8.4 or newer, on Linux or macOS
- libftdi1 and libusb-1.0:
- Debian and Ubuntu:
apt install libftdi1-dev libusb-1.0-0-dev pkg-config - macOS:
brew install libftdi
- Debian and Ubuntu:
ext-ftdi0.9:pie install php-io-extensions/ftdiscrapyard-io/framework0.9, or just thegpio/*components it is split into-
On Linux, access to the USB device. For example, add
/etc/udev/rules.d/99-ftdi.rules:Then reload udev and add your user to
plugdev. When libftdi opens an interface it detaches the kernel'sftdi_siodriver, so the board's/dev/ttyUSBnode disappears while this adapter holds it.
Installation
The service provider is discovered automatically and registers usb on the DigitalIO, I2C, SPI and UART managers. Make it the default in config/gpio.php, or name it at each call.
Usage
An FT232H runs one of these at a time, so each example below is a separate board, or the same board after disconnect().
SPI, with chip select on D4 (0) and a data/command pin on D5 (1):
I2C:
Serial, on the chip's UART engine:
The framework's README covers the transports, the event loop and via(). What this adapter adds:
One engine per interface
An FTDI interface runs its MPSSE engine or its UART engine, never both. Once one is registered, opening the other on the same interface throws GPIOLevelException::ftdiEngineBusy before any USB traffic. disconnect() frees the interface for the other engine.
A UART on an FT2232H or FT4232H uses interface A, the same interface as ft2232hl-a / ft4232hl-a.
Shared MPSSE context
I2C and SPI open the interface and hand it to the usb digital driver, so the spare lines are pins at once with no connectTo(). Connect I2C or SPI first: SPI refuses an interface the digital driver opened on its own.
Digital pins
- FTDI pins have no interrupt, so edges are level changes between samples.
- A watched input is sampled on a loop timer every 10 ms; set another interval with
pollEvery($ms). Blockinglisten()samples at the same interval.
I2C
- The default clock is 400 kHz; set another with
connectTo('ft232h')->clockRate(MPSSEClockRate::ONE_MHZ). - Framing matches Linux
I2C_RDWR:writeRead()uses a repeated START, andbulkWrite()puts each chunk behind its own START with one STOP at the end.
SPI
- Chip selects are pins: 0-3 are D4-D7, and 4-11 are C0-C7. D3, the engine's own chip select, stays high.
- Every chip select starts high when the bus registers. A pin used as a chip select is an output from then on.
- The bus clock comes from
speed($hz)on the connection, or fromclockRate()(default 400 kHz).speed($hz)on a slave gives it its own clock, and the engine switches clocks between slaves as needed.
UART
- Reads are sized to 10 ms of line data, so a device that streams constantly cannot hold a caller or the loop.
- Sends are asynchronous USB transfers, and a send that wrote less than it was given throws.
- A device unplugged mid-read throws instead of returning silence.
- A watched port is sampled every 10 ms, because USB completions cannot wake the event loop.
dtr()andrts()drive the modem lines. Both are released when the port opens.close()waits up to a second for a running send to finish.
Offloading
libusb holds the device for this process, so via() jobs cannot move to another process:
- A job runs in a loop fiber against the real device.
- Its USB traffic takes turns with everything else on the interface.
via()accepts no target name.
Testing
The suite uses scripted serial and MPSSE links and recorded command streams, so it runs without a board.
tests/Digital/Ft232hDigitalIOTest.php drives all twelve pins of a real FT232H with nothing wired to them. When no board answers it skips itself.
License
MIT. See LICENSE.
All versions of scrapyard-usb with dependencies
ext-ftdi Version ^0.8.0
gpio/contracts Version ^0.8.0
gpio/digital Version ^0.8.0
gpio/i2c Version ^0.8.0
gpio/nuts-and-bolts Version ^0.8.0
gpio/spi Version ^0.8.0
gpio/uart Version ^0.8.0
microscrap/ftdi Version ^0.8.0
microscrap/mpsse Version ^0.8.0
venusian-voyager/nuts-and-bolts Version ^0.8.0