Shared pin abstraction for embedded rust

crates.io Docs Rust

This is a simple abstraction for embedded rust applications to share a pin between different functions. It uses an Rc<RefCell<Pin>> to share the embedded_hal::digital::v2 pin.
Should be able to be passed on to any function that expects an OutputPin or an InputPin

Example:

Put this into your cargo.toml: toml [dependencies] shared-bus = "0.1.0"

Imports: rust use embedded_hal::digital::v2::OutputPin; use shared_pin::SharedPin;

Definitions: ```rust

pub fn dosomethingwiththeclonedpin(pin: PIN) where PIN: OuputPin { pin.sethigh(); // ... }

pub struct Device { pin: PIN, }

impl Device where PIN: OutputPin { pub fn new(pin: PIN) -> Self { Self { pin: PIN, } } }

```

Usage: ```rust { let mut sharedoutputpin1 = SharedPin::new(outputpin); let mut sharedoutputpin2 = sharedoutputpin1.clone(); let mut sharedoutputpin3 = sharedoutputpin1.clone(); dosomethingwiththeclonedpin(sharedoutputpin2); let mut device = Device::new(sharedoutputpin3); device.pin.setlow();

let mut shared_input_pin_1 = SharedPin::new(input_pin);
let mut shared_input_pin_2 = shared_input_pin_1.clone();
let mut shared_input_pin_3 = shared_input_pin_1.clone();

if shared_input_pin_3.is_low() {
    // ...
}

} ```

TODO: - [ ] make thread safe for freeRTOS