-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e41c707
commit ec59869
Showing
1 changed file
with
30 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |