Skip to content

Add FTDI MPSSE programmer support with multiple backends#19

Merged
ArthurHeymans merged 5 commits intomasterfrom
nativeFTDI
Feb 9, 2026
Merged

Add FTDI MPSSE programmer support with multiple backends#19
ArthurHeymans merged 5 commits intomasterfrom
nativeFTDI

Conversation

@ArthurHeymans
Copy link
Owner

This PR adds comprehensive FTDI MPSSE programmer support with three different backends to support various deployment scenarios:

Key Changes

Three Backend Implementations

  1. std backend (default): Uses C libftdi1 bindings via the ftdi crate
  2. native backend: Pure-Rust implementation using rs-ftdi + nusb
  3. wasm backend: WebUSB support for browser use via nusb + maybe_async

All three backends share the same public API and protocol definitions, making them interchangeable based on feature flags.

FTDI Device Support

  • FT2232H (dual channel, 60 MHz)
  • FT4232H (quad channel, 60 MHz)
  • FT232H (single channel, 60 MHz)
  • FT4233H (quad channel, 60 MHz)
  • Common development boards (TUMPA, JTAGkey, Google Servo, etc.)

Implementation Details

  • MPSSE (Multi-Protocol Synchronous Serial Engine) configuration via USB control transfers
  • Configurable SPI clock speeds (1-30 MHz for high-speed devices)
  • Support for multiple channels (A/B/C/D depending on device)
  • Proper handling of FTDI modem status bytes in bulk transfers
  • 4-byte addressing support (software handled)

WASM Integration

  • Added WebUSB device picker for FTDI devices in the browser UI
  • Async/sync dual-mode support using maybe_async
  • Device type, channel, and clock speed selection in the web interface
  • Proper async shutdown handling for WebUSB connections

Bug Fixes

  • Fixed SFDP parser to correctly set erase block counts based on chip density
  • Added From<String> implementation for error type conversions

Configuration

  • New ftdi-native feature to use pure-Rust backend instead of C libftdi1
  • New all-programmers-native feature set for all-Rust builds
  • Flexible configuration options: device type, interface, divisor, GPIO pins

Add optional native Rust FTDI backend using rs-ftdi crate as an
alternative to C libftdi1 bindings. Introduces `ftdi-native` and
`all-programmers-native` feature flags to enable pure-Rust FTDI MPSSE
implementation backed by nusb.

- Add native_device and native_error modules with same public API
- Implement FtdiDevice wrapper using rs-ftdi for MPSSE operations
- Add feature flags for build-time backend selection
- Maintain backward compatibility with existing libftdi1 backend

Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
…icate FtdiConfig

Add a WebUSB backend for the FTDI MPSSE programmer using nusb with
maybe_async, following the same pattern as CH341A and CH347 WASM
implementations. Integrates into the web UI with device type, channel,
and SPI clock selection.

Fix a bug in the SFDP parser where EraseBlock::new() created all erase
types with count=1, causing them to be misclassified as chip erase
operations. This made erase fail with InvalidAlignment for any chip not
in the database. Use EraseBlock::with_count() with the correct count
derived from chip density.

Extract the triplicated FtdiConfig struct into protocol.rs as a single
shared definition. Add From<String> to all FtdiError types to bridge
the config validation errors. Filter the WASM channel selector based on
device_type.channel_count().
Merge the separate native_device.rs and wasm_device.rs into a single
rsftdi_device.rs using maybe-async for compile-time sync/async selection.
Remove the now-redundant wasm_device.rs and wasm_error.rs files. Update
lib.rs module routing and Cargo.toml dependencies (add rs-ftdi git dep
with WASM branch, js-sys, wasm-bindgen, web-sys for WebUSB support).
…fg gates

When --all-features is enabled (as in CI), both 'native' and 'wasm'
features are active simultaneously. Using not(feature = "wasm") to
guard native-only code caused parse_options, Ftdi::open, and
FtdiDeviceInfo to be excluded on native targets. Switch to
not(target_arch = "wasm32") so native code compiles correctly
regardless of which features are enabled.
@ArthurHeymans ArthurHeymans merged commit a41a985 into master Feb 9, 2026
5 checks passed
@ArthurHeymans ArthurHeymans deleted the nativeFTDI branch February 9, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant