Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeechey committed Feb 24, 2025
1 parent e41c707 commit ec59869
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions lib/io/hyped_spi/src/cs.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
use hyped_gpio::HypedGpioOutputPin;

/// Wrapper around a GPIO pin that is used as a Chip Select (CS) pin for an SPI device
pub struct HypedSpiCsPin<P: HypedGpioOutputPin> {
pin: P,
}

impl<P: HypedGpioOutputPin> HypedSpiCsPin<P> {
/// Create a new Chip Select pin
pub fn new(pin: P) -> Self {
Self { pin }
}

/// Set the Chip Select pin to the active state (low)
pub fn set_active(&mut self) {
self.pin.set_low();
}

/// Set the Chip Select pin to the inactive state (high)
pub fn set_inactive(&mut self) {
self.pin.set_high();
}
}

impl<P: HypedGpioOutputPin> Drop for HypedSpiCsPin<P> {
/// Set the Chip Select pin to the inactive state when the Chip Select pin is dropped
fn drop(&mut self) {
self.set_inactive();
}
}
use hyped_gpio::HypedGpioOutputPin;

/// Wrapper around a GPIO pin that is used as a Chip Select (CS) pin for an SPI device
pub struct HypedSpiCsPin<P: HypedGpioOutputPin> {
pin: P,
}

impl<P: HypedGpioOutputPin> HypedSpiCsPin<P> {
/// Create a new Chip Select pin
pub fn new(pin: P) -> Self {
Self { pin }
}

/// Set the Chip Select pin to the active state (low)
pub fn set_active(&mut self) {
self.pin.set_low();
}

/// Set the Chip Select pin to the inactive state (high)
pub fn set_inactive(&mut self) {
self.pin.set_high();
}
}

impl<P: HypedGpioOutputPin> Drop for HypedSpiCsPin<P> {
/// Set the Chip Select pin to the inactive state when the Chip Select pin is dropped
fn drop(&mut self) {
self.set_inactive();
}
}

0 comments on commit ec59869

Please sign in to comment.