pub trait DisplayBus: ErrorType {
// Required methods
async fn write_cmd(&mut self, cmd: &[u8]) -> Result<(), Self::Error>;
async fn write_cmd_with_params(
&mut self,
cmd: &[u8],
params: &[u8],
) -> Result<(), Self::Error>;
async fn write_pixels(
&mut self,
cmd: &[u8],
data: &[u8],
metadata: Metadata,
) -> Result<(), DisplayError<Self::Error>>;
// Provided method
fn set_reset(
&mut self,
reset: bool,
) -> Result<(), DisplayError<Self::Error>> { ... }
}Expand description
The core interface for all display bus implementations.
This trait serves as the abstraction layer between the high-level drawing logic and the low-level transport protocol. It accommodates a wide range of hardware, from simple 2-wire interfaces to complex high-speed buses.
The interface distinguishes between two types of traffic:
- Commands: Small, latency-sensitive messages used for configuration (handled by
write_cmdandwrite_cmd_with_params). - Pixels: Large, throughput-critical data streams used for changing the visual content
(handled by
write_pixels).
This separation allows for optimizations. For instance, write_pixels accepts Metadata,
enabling the underlying implementation to utilize hardware accelerators (like DMA or QSPI
peripherals) that can handle address setting and bulk data transfer efficiently.
Required Methods§
Sourceasync fn write_cmd(&mut self, cmd: &[u8]) -> Result<(), Self::Error>
async fn write_cmd(&mut self, cmd: &[u8]) -> Result<(), Self::Error>
Writes a command to the display.
This is typically used for setting registers or sending configuration opcodes.
Sourceasync fn write_cmd_with_params(
&mut self,
cmd: &[u8],
params: &[u8],
) -> Result<(), Self::Error>
async fn write_cmd_with_params( &mut self, cmd: &[u8], params: &[u8], ) -> Result<(), Self::Error>
Writes a command followed immediately by its parameters.
This guarantees an atomic transaction where the command and parameters are sent without interruption. This is critical for many display controllers that expect the parameter bytes to immediately follow the command byte while the Chip Select (CS) line remains active.
Sourceasync fn write_pixels(
&mut self,
cmd: &[u8],
data: &[u8],
metadata: Metadata,
) -> Result<(), DisplayError<Self::Error>>
async fn write_pixels( &mut self, cmd: &[u8], data: &[u8], metadata: Metadata, ) -> Result<(), DisplayError<Self::Error>>
Writes a stream of pixel data to the display.
§Arguments
cmd- The memory write command (e.g.,0x2Cfor standard MIPI DCS).data- The raw pixel data bytes.metadata- Contextual information about this transfer, including the target area and frame boundaries.
Implementations should use the metadata to handle frame synchronization (VSYNC/TE) before
sending the pixel data.
Provided Methods§
Sourcefn set_reset(&mut self, reset: bool) -> Result<(), DisplayError<Self::Error>>
fn set_reset(&mut self, reset: bool) -> Result<(), DisplayError<Self::Error>>
Resets the screen via the bus (optional).
Note: This method should only be implemented if the hardware has a physical Reset pin.
Avoid adding a Pin field to your DisplayBus wrapper for this purpose; use LCDResetOption
instead.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.