shared-pin 0.1.0

An abstraction to share rust embedded_hal pins between functions.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 17.62 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 944.02 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • hacknus/shared-pin-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hacknus

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:

[dependencies]
shared-bus = "0.1.0"

Imports:

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

Definitions:


pub fn do_something_with_the_cloned_pin<PIN>(pin: PIN)
    where PIN: OuputPin
{
    pin.set_high();
    // ...
}

pub struct Device<PIN> {
    pin: PIN,
}

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

Usage:

{
    let mut shared_output_pin_1 = SharedPin::new(output_pin);
    let mut shared_output_pin_2 = shared_output_pin_1.clone();
    let mut shared_output_pin_3 = shared_output_pin_1.clone();
    do_something_with_the_cloned_pin(shared_output_pin_2);
    let mut device = Device::new(shared_output_pin_3);
    device.pin.set_low();
    
    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