PHPackages                             microscrap/usb-drivers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. microscrap/usb-drivers

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

microscrap/usb-drivers
======================

The Official ScrapyardIO USB Drivers package.

0.5.0(1mo ago)00MITPHP ^8.3

Since Jul 6Compare

[ Source](https://github.com/microscrap/scrapyard-usb-drivers)[ Packagist](https://packagist.org/packages/microscrap/usb-drivers)[ Docs](https://scrapyard-io.projectsaturnstudios.com)[ RSS](/packages/microscrap-usb-drivers/feed)WikiDiscussions Synced 1mo ago

READMEChangelogDependencies (10)Versions (4)Used By (0)

microscrap/usb-drivers - The Official ScrapyardIO USB Drivers package
=====================================================================

[](#microscrapusb-drivers---the-official-scrapyardio-usb-drivers-package)

PHP driver package that provides the `usb` carrier for the [ScrapyardIO framework](https://github.com/scrapyard-io/framework) GPIO stack. It drives FTDI USB adapters (FT232H, FT2232HL, FT232RL) through [`ext-ftdi`](https://github.com/php-io-extensions/ftdi), tunnelling SPI, I²C, and digital GPIO over MPSSE and running UART as plain async serial.

This package includes:

- The `ScrapyardIOUSBManager` carrier manager, auto-discovered by the framework via the `#[CarrierDriver('usb')]` attribute
- MPSSE-backed protocol drivers for SPI, I²C, and digital input/output
- A libftdi-backed UART driver (no MPSSE) for serial-only workflows
- Digital pin ride-along on SPI/I²C buses — control DC/RESET/BUSY pins on the same FTDI adapter that carries the bus

Requirements
------------

[](#requirements)

- PHP 8.3+
- [`ext-ftdi`](https://github.com/php-io-extensions/ftdi) ^0.4.2 — the PHP FTDI extension (requires **libftdi1** at runtime)
    - Debian/Ubuntu/Raspberry Pi OS: `libftdi1-2` (dev package for builds: `libftdi1-dev`)
    - macOS: `brew install libftdi`
- [`microscrap/ftdi`](https://github.com/microscrap/ftdi) ^0.5.0 — global `ftdi_*` helpers (installed automatically)
- [`microscrap/mpsse`](https://github.com/microscrap/mpsse) ^0.5.0 — **required for SPI, I²C, and digital GPIO** (suggested; UART works without it)

### Currently Supported devices

[](#currently-supported-devices)

DeviceMPSSE `device()` value (SPI/I²C/GPIO)UART `device()` valueProduct IDFT232H`ft232h``FtdiProductId::FT232H->value``0x6014`FT2232HL`ft2232hl-a` (channel A) / `ft2232hl-b` (channel B)`FtdiProductId::FT2232HL->value``0x6010`FT232RL— (no MPSSE engine)`FtdiProductId::RS232L->value``0x6001`Note, these are the only devices so far I've tested. There shouldn't be any reason why any other MPSSE-enabled devices wouldn't work if there is a valid product id hex for the device. You could make a pull request with the missing device, or use custom logic that doesn't use the MpsseSupportedDevices enum.

The two protocol families address devices differently:

- **SPI / I²C / GPIO** go through `Microscrap\Bindings\MPSSE\Enums\MpsseSupportedDevice`, which picks the exact MPSSE engine (channel A or B) and its product ID together. The FT2232HL has **two independent MPSSE engines**, so `ft2232hl-a` and `ft2232hl-b` are addressed separately.
- **UART** goes through `Microscrap\Bindings\FTDI\Enums\FtdiProductId`, which is only the raw product ID — there is **one UART per chip** regardless of how many MPSSE engines it has, so the FT2232HL is addressed as a single `FtdiProductId::FT2232HL`, not per channel.

Installation
------------

[](#installation)

Install the FTDI extension first (see [php-io-extensions/ftdi](https://github.com/php-io-extensions/ftdi)):

```
pie install php-io-extensions/ftdi
```

Confirm it is loaded:

```
php -m | grep ftdi
```

Install the driver package:

```
composer require microscrap/usb-drivers
```

If your workflow includes SPI, I²C, or digital GPIO (anything other than UART), install the MPSSE package as well:

```
composer require microscrap/mpsse
```

The manager enforces these prerequisites at runtime and throws a `GPIOException` with install instructions when one is missing.

How it works
------------

[](#how-it-works)

The framework resolves the `usb` carrier through attribute-based discovery — no manual registration:

```
GPIO::spi('usb')->…->create()
  └─ SPIConnectionFactory            (scrapyard-io/framework)
       └─ GPIOCarriers::usb('spi')
            └─ ScrapyardIOUSBManager  (#[CarrierDriver('usb')], this package)
                 └─ MPSSESPIDriver
                      └─ microscrap/mpsse → microscrap/ftdi → ext-ftdi → libftdi1

```

Each GPIO protocol maps to a driver in this package:

ProtocolDriverBackend`spi``MPSSESPIDriver`MPSSE, modes SPI0–SPI3`i2c``MPSSEI2CDriver`MPSSE with full ACK/NACK sequencing`digital-in``MPSSEDigitalInputDriver`MPSSE GPIO mode, polled edge events`digital-out``MPSSEDigitalOutputDriver`MPSSE GPIO mode`uart``FTDIUartDriver`Plain async serial via `ftdi_*` helpers — **no MPSSE**UART is intentionally kept off MPSSE: `FTDIUartDriver` resets the chip to async-serial bitmode on open (`ftdi_set_bitmode($context, 0x00, 0x00)`) so that multi-protocol parts like the FT232H release D0/D1 back to TX/RX even if a previous session left MPSSE enabled.

Usage
-----

[](#usage)

All examples go through the framework's `GPIO` facade with the `usb` driver.

### SPI

[](#spi)

```
