The classic T-Beam's red LED on GPIO4 is wired active-low (anode to V+, cathode to GPIO). Release v1.3.0 drove it as active-high, so the LED sat lit at idle and dimmed briefly on TX/RX instead of flashing on activity. Express the polarity where it physically lives — at the pin — via a new generic InvertedPin<P> wrapper that swaps set_high/set_low. SimpleLed stays polarity-agnostic and every other board's code path is byte-for-byte unchanged from v1.3.0. Empirically verified against hardware on both T-Beam boards: classic red LED is now dark at idle and flashes on TX/RX; Supreme blue LED behaves unchanged.
31 lines
983 B
Rust
31 lines
983 B
Rust
//! Generic `OutputPin` wrapper that inverts logic levels.
|
|
//!
|
|
//! When a peripheral is wired active-low (LED anode to V+, cathode to GPIO;
|
|
//! reset line idle-high, etc.) the physical polarity is a property of the
|
|
//! board, not of the driver. Wrapping the pin in `InvertedPin` lets drivers
|
|
//! keep "set_high = assert" semantics while the board file expresses the
|
|
//! wiring reality at construction time.
|
|
//!
|
|
//! ```ignore
|
|
//! let pin = Output::new(p.GPIO4, Level::High, OutputConfig::default()); // off
|
|
//! let led = SimpleLed(InvertedPin(pin)); // driver sees normal polarity
|
|
//! ```
|
|
|
|
use embedded_hal::digital::{ErrorType, OutputPin};
|
|
|
|
pub struct InvertedPin<P>(pub P);
|
|
|
|
impl<P: ErrorType> ErrorType for InvertedPin<P> {
|
|
type Error = P::Error;
|
|
}
|
|
|
|
impl<P: OutputPin> OutputPin for InvertedPin<P> {
|
|
fn set_low(&mut self) -> Result<(), Self::Error> {
|
|
self.0.set_high()
|
|
}
|
|
|
|
fn set_high(&mut self) -> Result<(), Self::Error> {
|
|
self.0.set_low()
|
|
}
|
|
}
|