Portability lets firmware logic work across different microcontroller platforms with limited adaptation. In embedded Rust, traits such as embedded-hal’s OutputPin give drivers a shared interface even when hardware abstraction layers use different GPIO designs. section 3.5.4
pub trait OutputPin {
/// The error type returned by the methods.
type Error;
/// Set the pin to high logic level.
fn set_high(&mut self) -> Result<(), Self::Error>;
/// Set the pin to low logic level.
fn set_low(&mut self) -> Result<(), Self::Error>;
}
OutputPin defines the shared high- and low-level operations that platform-specific pin implementations can provide. section 3.5.4
One LED driver, different platforms
A blink_led function can use OutputPin and a delay provider without knowing the chip architecture. Cortex-M and RISC-V applications supply their own LED and delay instances; the blinking logic remains unchanged. Trait-based interfaces also allow mock pins and delays to record calls in unit tests. section 3.5.4
The same pattern extends beyond GPIO: a UART echo function can use shared read and write traits with platform-specific UART instances. section 3.5.4








