Skip to content

feat: add cu-linux-resources and igrates Linux/std components to consume centralized serial/I2C/GPIO resources#790

Merged
gbin merged 29 commits into
masterfrom
yang/feat/cu_linux_resources
Feb 11, 2026
Merged

feat: add cu-linux-resources and igrates Linux/std components to consume centralized serial/I2C/GPIO resources#790
gbin merged 29 commits into
masterfrom
yang/feat/cu_linux_resources

Conversation

@makeecat

@makeecat makeecat commented Feb 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR introduces a new shared resource crate, cu-linux-resources, and migrates several Linux/std components to consume centralized serial/I2C/GPIO resources instead of opening devices ad hoc.

Changes

  • Added new workspace crate: components/res/cu_linux_resources (cu-linux-resources package, cu_linux_resources module path).
  • New LinuxResources bundle can register:
    • serial via LinuxSerialPort
    • i2c via LinuxI2c
    • gpio_out via LinuxOutputPin
    • gpio_in via LinuxInputPin
  • Supports config aliases/fallbacks:
    • Serial: serial_path or device, with baudrate and timeout_ms
    • I2C: i2c_bus or bus
    • GPIO out: gpio_out_pin or pin
    • GPIO in: gpio_in_pin
  • Migrated components to use these resource types and optional resource bindings:
    • Bridges: cu_crsf, cu_msp_bridge
    • Sinks: cu_lewansoul, cu_rp_gpio
    • Sources: cu_rp_encoder, cu_wt901
  • Updated docs/examples to show provider: cu_linux_resources::LinuxResources and resource wiring (e.g. <bundle>.serial, <bundle>.gpio_in).
  • StdSerialBundle compatibility remains in CRSF/MSP bridges, now backed by LinuxSerialPort.

Testing

  • just std-ci
  • just lint
  • cargo +stable nextest run --workspace --all-targets
  • just nostd-ci

Checklist

  • I have updated docs or examples where needed
  • I have added or updated tests where needed
  • I have considered platform impact (Linux/macOS/Windows/embedded)
  • I have considered config/logging changes (if applicable)
  • This change is not a breaking change (or I documented it below)

Breaking changes (if any)

  • Custom resource providers/bindings: resource concrete types changed to cu_linux_resources wrappers (LinuxSerialPort, LinuxI2c, LinuxOutputPin, LinuxInputPin), so type-matching bindings may need updates.
  • if migrating CRSF from legacy StdSerialBundle to LinuxResources without explicit baudrate, default may differ (420000 legacy vs 115200 LinuxResources).

Additional context

N/A

@makeecat makeecat self-assigned this Feb 7, 2026
@makeecat makeecat changed the title Yang/feat/cu linux resources feat: add cu-linux-resources and igrates Linux/std components to consume centralized serial/I2C/GPIO resources Feb 7, 2026
@makeecat makeecat force-pushed the yang/feat/cu_linux_resources branch from 433e5e6 to fac6ac2 Compare February 7, 2026 21:42

@gbin gbin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is going in the right direction but it looks half done. The users of the serial ports should just get a serial port, no adapter needed from both std and nostd implementations. (but if I missed some hard requirement please comment)

Comment thread components/bridges/cu_crsf/src/lib.rs Outdated
Comment thread components/bridges/cu_crsf/src/lib.rs Outdated
Ok(FromStd::new(port))
pub struct LockedSerial<T>(pub T);

impl<T> LockedSerial<T> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied same change for MSP: removed bridge-local serial wrapper and kept resource acquisition as Owned<S> from bundle mapping

@@ -403,53 +413,23 @@ impl ResourceBundle for StdSerialBundle {
))
})?;
let device = cfg

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serial setup remains in bundle config/provider, and bridge user path is now uniform without extra adapter code


/// Wrapper for resources that are logically exclusive/owned by a single
/// component but still need to satisfy `Sync` bounds at registration time.
pub struct Exclusive<T>(T);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is basically what the users of the bundle should be using? Why do we need to wrap it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the bundle-level wrapper users should use when needed. We still need Exclusive<T> at registration because ResourceManager::add_owned requires T: Send + Sync. I kept that adaptation centralized in cu_linux_resources, added embedded-io 0.7 forwarding, added a test

@makeecat

makeecat commented Feb 9, 2026

Copy link
Copy Markdown
Collaborator Author

It is going in the right direction but it looks half done. The users of the serial ports should just get a serial port, no adapter needed from both std and nostd implementations. (but if I missed some hard requirement please comment)

Serial consumer-side adapters were removed; serial adaptation now lives in bundle/resource layer only, with no-std migration to cu_linux_resources::Exclusive<T> and validation across affected crates/examples.

@makeecat makeecat requested a review from gbin February 9, 2026 20:46

@gbin gbin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I think the LLM doesn't understand at all what we are trying to do here.

Comment thread components/bridges/cu_crsf/src/lib.rs Outdated
Comment thread components/bridges/cu_msp_bridge/src/lib.rs Outdated
Comment thread components/bridges/cu_msp_bridge/src/lib.rs Outdated
Comment thread components/sinks/cu_lewansoul/src/lib.rs
Comment thread components/sinks/cu_lewansoul/src/lib.rs Outdated
Comment thread components/sinks/cu_rp_gpio/src/lib.rs
Comment thread components/sinks/cu_rp_gpio/src/lib.rs
Comment thread components/sources/cu_rp_encoder/src/lib.rs Outdated
Comment thread components/sources/cu_wt901/src/lib.rs
@makeecat makeecat requested a review from gbin February 10, 2026 13:42
Comment thread components/res/cu_linux_resources/src/lib.rs Outdated
Comment thread components/bridges/cu_msp_bridge/README.md
@gbin

gbin commented Feb 10, 2026

Copy link
Copy Markdown
Collaborator

I would just expose a set of hardcoded peripherals in the bundle for now:

like /dev/ttyACM0 /dev/ttyACM1 /dev/ttyACM2 then /dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 then /dev/i2c-0 /dev/i2c-1 /dev/i2c-2 ...

you can imagine those as "slots" the tasks can take

in just dag it should exactly look like this but with a bunch of unused resources
image

@makeecat makeecat force-pushed the yang/feat/cu_linux_resources branch from 2e3f782 to 6ef7695 Compare February 10, 2026 16:41
@makeecat makeecat requested a review from gbin February 10, 2026 19:52
Comment thread components/bridges/cu_msp_bridge/README.md Outdated
Comment thread components/bridges/cu_msp_bridge/README.md Outdated
Comment thread components/res/cu_linux_resources/src/lib.rs Outdated
@makeecat makeecat requested a review from gbin February 11, 2026 00:10
@gbin gbin merged commit facce0f into master Feb 11, 2026
23 checks passed
@gbin gbin deleted the yang/feat/cu_linux_resources branch February 11, 2026 03:16
@makeecat

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants