### Configure DisplayDriver with Fluent Builder API Source: https://context7.com/decaday/display-driver/llms.txt Shows the fluent builder pattern for pre-configuring display settings such as color format and orientation before initialization. Also provides an example of direct construction for manual initialization. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption}; use display_driver_st7735::{St7735, spec::generic::Generic128x160Type1}; use display_driver_spi::SpiDisplayBus; // Create bus and panel let bus = SpiDisplayBus::new(spi_device, dc_pin); let panel = St7735::::new(LCDResetOption::new_pin(rst)); // Use builder to configure before initialization let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) // Set 16-bit color .with_orientation(Orientation::Deg270) // Set landscape orientation .init(&mut delay) .await .unwrap(); // Alternative: Direct construction without builder let mut display_direct = DisplayDriver::new(bus, panel); display_direct.init(&mut delay).await.unwrap(); display_direct.set_color_format(ColorFormat::RGB565).await.unwrap(); display_direct.set_orientation(Orientation::Deg90).await.unwrap(); ``` -------------------------------- ### ST7789 Monitor UI Demo (STM32H7B0) Source: https://github.com/decaday/display-driver/blob/master/examples/README.md Showcases a Computer Monitor UI demo on a 135x240 ST7789 display with a modern dark theme. This example utilizes embedded-graphics and FrameBuffer for rendering. ```Rust use embedded_graphics::prelude::*; use embedded_graphics::FrameBuffer; use embedded_graphics::pixelcolor::Rgb565; // Assuming necessary UI elements and display setup are available // This is a placeholder for the actual code fn main() { // ... setup display ... // let mut ui = ComputerMonitorUI::new(); // ui.draw(&mut display); // ... update display ... } // struct ComputerMonitorUI { // // ... UI elements ... // } // impl ComputerMonitorUI { // fn new() -> Self { // // ... initialization ... // } // fn draw(&mut self, display: &mut D) { // // ... drawing logic ... // } // } ``` -------------------------------- ### ST7735 Animation Demo (STM32H7B0) Source: https://github.com/decaday/display-driver/blob/master/examples/README.md A creative animation demo for a 128x128 ST7735 display, featuring FPS control set at 30 FPS. This example utilizes embedded-graphics and FrameBuffer. ```Rust use embedded_graphics::prelude::*; use embedded_graphics::FrameBuffer; use embedded_graphics::pixelcolor::Rgb565; // Assuming animation frames and display setup are available // This is a placeholder for the actual code fn main() { let mut frame_count = 0; let target_fps = 30; let frame_duration_micros = 1_000_000 / target_fps; // ... setup display ... loop { let start_time = micros(); // Assuming a micros() function is available // ... draw next animation frame ... // draw_frame(frame_count, &mut display); frame_count += 1; let elapsed_time = micros() - start_time; if elapsed_time < frame_duration_micros { sleep_micros(frame_duration_micros - elapsed_time); } } } // fn draw_frame(frame: u32, display: &mut D) { // // ... logic to draw a specific animation frame ... // } // fn micros() -> u32 { // // ... implementation to get current time in microseconds ... // } // fn sleep_micros(duration: u32) { // // ... implementation to sleep for a duration in microseconds ... // } ``` -------------------------------- ### GC9A01 Concentric Gradient Demo (STM32H7B0) Source: https://github.com/decaday/display-driver/blob/master/examples/README.md A demo featuring a concentric gradient with ordered dithering for the GC9A01 display (240x240). This example leverages embedded-graphics, FrameBuffer, and dithering techniques. ```Rust use embedded_graphics::prelude::*; use embedded_graphics::FrameBuffer; use embedded_graphics::pixelcolor::Rgb565; use embedded_graphics::image::Image; // Assuming necessary dithering and gradient logic are available // This is a placeholder for the actual code fn main() { // ... setup display ... // let gradient = create_concentric_gradient(); // let dithered_image = apply_ordered_dithering(&gradient); // display.draw(dithered_image.into_iter()); // ... update display ... } // fn create_concentric_gradient() -> impl ImageSource { // // ... gradient generation ... // } // fn apply_ordered_dithering(image: &impl ImageSource) -> impl ImageSource { // // ... dithering implementation ... // } ``` -------------------------------- ### Implement Custom ST7735 Panel Specification Source: https://github.com/decaday/display-driver/blob/master/panels/st7735/README.md This example shows how to define a custom `Spec` for the ST7735 driver when built-in generic or vendor specs do not match the display's requirements. It involves defining the panel's physical dimensions, offsets, color inversion, and BGR order, and then implementing the `St7735Spec` trait. ```rust use display_driver_st7735::{PanelSpec, St7735Spec, impl_st7735_initr}; // 1. Define your type pub struct MyCustomPanel; // 2. Configure Resolution & Offsets impl PanelSpec for MyCustomPanel { const PHYSICAL_WIDTH: u16 = 128; const PHYSICAL_HEIGHT: u16 = 160; // Panel Offset const PHYSICAL_X_OFFSET: u16 = 2; const PHYSICAL_Y_OFFSET: u16 = 1; // Optional Panel offset in pixels when the screen is rotated 180° or 270°. // Used for panels that are not physically centered within the frame. // If undefined, defaults to PHYSICAL_X_OFFSET / PHYSICAL_Y_OFFSET. const PHYSICAL_X_OFFSET_ROTATED: u16 = 2; const PHYSICAL_Y_OFFSET_ROTATED: u16 = 3; // Set true if colors are inverted (White is Black) const INVERTED: bool = true; // Set true if Red and Blue are swapped (BGR Order) const BGR: bool = true; } // 3. Implement St7735Spec // Option A: Use default "InitR" sequence (Easiest) impl_st7735_initr!(MyCustomPanel); // Option B: manual implementation (Advanced) // Include Gamma, Power, Frame Rate etc. // impl St7735Spec for MyCustomPanel { // ... define const FRMCTR1_PARAMS, etc. // } ``` -------------------------------- ### Draw Ferris Picture with ST7735 (STM32H7B0) Source: https://github.com/decaday/display-driver/blob/master/examples/README.md Demonstrates drawing a Ferris picture on a 160x80 ST7735 display using embedded-graphics and FrameBuffer. This example is specific to the XX096T_IF09 display controller. ```Rust use embedded_graphics::prelude::*; use embedded_graphics::image::Image; use embedded_graphics::pixelcolor::Rgb565; use embedded_graphics_simulator::Display; // Assuming necessary display driver and image data are available // This is a placeholder for the actual code fn main() { // ... setup display ... // let ferris_image = Image::new(Ferris, Point::zero()); // display.draw(ferris_image.into_iter()); // ... update display ... } ``` -------------------------------- ### Rotate Display with ST7735 (STM32H7B0) Source: https://github.com/decaday/display-driver/blob/master/examples/README.md Tests display rotation functionality for 160x80 and 128x128 ST7735 displays. It checks for offsets by rotating the display in four directions. This example uses embedded-graphics and FrameBuffer. ```Rust use embedded_graphics::prelude::*; use embedded_graphics::FrameBuffer; use embedded_graphics::pixelcolor::Rgb565; // Assuming necessary display driver and rotation logic are available // This is a placeholder for the actual code fn main() { // ... setup display ... // rotate_display(DisplayRotation::Degrees90); // ... verify display content ... // rotate_display(DisplayRotation::Degrees180); // ... verify display content ... // rotate_display(DisplayRotation::Degrees270); // ... verify display content ... // rotate_display(DisplayRotation::Degrees0); // ... verify display content ... } // fn rotate_display(rotation: DisplayRotation) { // // ... implementation to rotate the display ... // } ``` -------------------------------- ### Initialize Display Driver Source: https://github.com/decaday/display-driver/blob/master/README.md Demonstrates the initialization of a display driver using the `display-driver` framework. It configures reset options, creates a panel instance with a specific specification (e.g., `Generic128x160Type1` for ST7735), and binds it to a bus. The driver is then initialized with color format and orientation settings before writing frame data. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption}; // The `Spec` (Generic128x160Type1) defines the hardware-specific constants (Gamma, Voltage). use display_driver_st7735::{St7735, spec::generic::Generic128x160Type1}; // 1. Configure Reset let reset_opt = LCDResetOption::new_pin(reset_pin); // 2. Create the Panel instance using a Generic Spec (e.g., Generic128x160Type1) let panel = St7735::::new(reset_opt); // 3. Bind Bus and Panel, Configure, and Initialize // The driver orchestrates the logic, delegating transport to 'bus' and commands to 'panel'. let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) // This framework automatically handles offsets. .with_orientation(Orientation::Deg90) .init(&mut delay).await.unwrap(); // Now you can use `display` to draw: display.write_frame(fb).await.unwrap(); ``` -------------------------------- ### Define and Execute Initialization Sequences in Rust Source: https://context7.com/decaday/display-driver/llms.txt Demonstrates how to use the InitStep enum to define custom display controller initialization sequences. It supports commands, delays, conditional logic, and nested sequences, which are executed via the sequenced_init function. ```rust use display_driver::panel::initseq::{InitStep, sequenced_init}; const MY_INIT_SEQUENCE: &[InitStep<'static>] = &[ InitStep::SingleCommand(0x11), InitStep::DelayMs(120), InitStep::CommandWithParams(0x3A, &[0x55]), InitStep::select_cmd(true, 0x21, 0x20), InitStep::maybe_cmd_with(0xB1, Some(&[0x01, 0x2C, 0x2D])), InitStep::Nested(&[ InitStep::SingleCommand(0x29), InitStep::DelayMs(20), ]), InitStep::Nop, ]; sequenced_init( MY_INIT_SEQUENCE.iter().copied(), &mut delay, &mut bus ).await.unwrap(); ``` -------------------------------- ### Initialize and Operate DisplayDriver in Rust Source: https://context7.com/decaday/display-driver/llms.txt Demonstrates the initialization of a DisplayDriver using a SPI bus and ST7789 panel. It covers writing framebuffers, updating specific pixel areas, and modifying display settings like orientation and color format at runtime. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption, Area, FrameControl}; use display_driver_st7789::{St7789, spec::generic::Generic240x320Type1}; use display_driver_spi::SpiDisplayBus; // Create the SPI bus with DC (Data/Command) pin let spi_device = embedded_hal_bus::spi::ExclusiveDevice::new_no_delay(spi, cs_pin).unwrap(); let bus = SpiDisplayBus::new(spi_device, dc_pin); // Create the panel with a reset pin let panel = St7789::::new(LCDResetOption::new_pin(reset_pin)); // Initialize the display using the builder pattern let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) .with_orientation(Orientation::Deg90) .init(&mut delay) .await .unwrap(); // Write a full framebuffer to the display let framebuffer: [u8; 240 * 320 * 2] = [0xFF; 240 * 320 * 2]; // White screen display.write_frame(&framebuffer).await.unwrap(); // Write pixels to a specific area let area = Area::new(10, 10, 100, 50); // x=10, y=10, width=100, height=50 let pixels: [u8; 100 * 50 * 2] = [0x00; 100 * 50 * 2]; // Black rectangle display.write_pixels(area, FrameControl::new_standalone(), &pixels).await.unwrap(); // Change orientation at runtime display.set_orientation(Orientation::Deg180).await.unwrap(); // Set color format display.set_color_format(ColorFormat::RGB888).await.unwrap(); ``` -------------------------------- ### Initialize and Configure CO5300 Display Driver Source: https://github.com/decaday/display-driver/blob/master/panels/co5300/README.md Demonstrates how to instantiate the Co5300 driver using a specific panel spec and the DisplayDriver builder pattern. It covers setting up the reset pin, color format, orientation, and performing basic drawing operations. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption, FrameControl, Area}; use display_driver_co5300::{Co5300, spec::AM196Q410502LK_196}; // Configure Reset let reset_opt = LCDResetOption::new_pin(reset_pin); // Create the Panel instance using a Spec let panel = Co5300::::new(reset_opt); // Create the DisplayDriver using builder pattern let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) .with_orientation(Orientation::Portrait) .init(&mut delay).await.unwrap(); display.panel().set_brightness(display.bus(), 200).await.unwrap(); // Draw display.write_pixels( Area::from_origin(100, 100), FrameControl::new_first(), partial_buffer, ); ``` -------------------------------- ### Initialize GC9A01 Display Driver with Display-Driver Crate (Rust) Source: https://github.com/decaday/display-driver/blob/master/panels/gc9a01/README.md Demonstrates how to initialize the GC9A01 display driver using the `display-driver` crate. It involves configuring reset options, creating a panel instance with a generic specification, and then binding the bus and panel to the `DisplayDriver`. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption}; // The `Spec` (Generic240x240Type1) defines the hardware-specific constants (Gamma, Voltage). use display_driver_gc9a01::{Gc9a01, spec::{Generic240x240Type1}}; // 1. Configure Reset let reset_opt = LCDResetOption::new_pin(reset_pin); // 2. Create the Panel instance using a Generic Spec let panel = Gc9a01::::new(reset_opt); // 3. Bind Bus and Panel, Configure, and Initialize // The driver orchestrates the logic, delegating transport to 'bus' and commands to 'panel'. let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) // This framework automatically handles offsets. .with_orientation(Orientation::Deg0) .init(&mut delay).await.unwrap(); // Now you can use `display` to draw: display.write_frame(fb).await.unwrap(); ``` -------------------------------- ### Initialize SpiDisplayBus in Rust Source: https://github.com/decaday/display-driver/blob/master/buses/spi/README.md Demonstrates the initialization of the SpiDisplayBus for SPI displays requiring a Data/Command (DC) pin. It requires an implementation of `embedded_hal::spi::SpiDevice` and `embedded_hal::digital::OutputPin` for the SPI communication and DC pin control, respectively. ```rust use display_driver_spi::SpiDisplayBus; use embedded_hal::digital::OutputPin; use embedded_hal_async::spi::SpiDevice; // let spi = ...; // implement SpiDevice // let dc = ...; // implement OutputPin let bus = SpiDisplayBus::new(spi, dc); ``` -------------------------------- ### Initialize ST7735 TFT Display Driver Source: https://context7.com/decaday/display-driver/llms.txt Demonstrates the initialization and frame buffer writing for the ST7735 controller. It supports various generic screen configurations and requires an SPI bus and reset pin. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption}; use display_driver_st7735::{St7735, spec::generic::*}; use display_driver_spi::SpiDisplayBus; let panel = St7735::::new(LCDResetOption::new_pin(rst)); let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) .with_orientation(Orientation::Deg0) .init(&mut delay) .await .unwrap(); let mut framebuffer = [0u8; 128 * 128 * 2]; display.write_frame(&framebuffer).await.unwrap(); ``` -------------------------------- ### Initialize ST7789 Display Driver with display-driver Crate (Rust) Source: https://github.com/decaday/display-driver/blob/master/panels/st7789/README.md Demonstrates how to initialize the ST7789 display driver using the `display-driver` crate. It involves configuring reset options, creating a `St7789` panel instance with a specific `Spec`, and then binding it to `DisplayDriver` with color format and orientation settings. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption}; // The `Spec` (Generic240x240Type1) defines the hardware-specific constants (Gamma, Voltage). use display_driver_st7789::{St7789, spec::generic::Generic240x240Type1}; // 1. Configure Reset let reset_opt = LCDResetOption::new_pin(reset_pin); // 2. Create the Panel instance using a Spec let panel = St7789::::new(reset_opt); // 3. Bind Bus and Panel, Configure, and Initialize let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) .with_orientation(Orientation::Portrait) .init(&mut delay).await.unwrap(); // Now you can use `display` to draw: display.write_frame(fb).await.unwrap(); ``` -------------------------------- ### Implement Custom Panel Specification Source: https://github.com/decaday/display-driver/blob/master/panels/co5300/README.md Shows how to support a new AMOLED panel by implementing the PanelSpec and Co5300Spec traits. This allows defining custom resolutions, offsets, and initialization parameters required for specific hardware. ```rust use display_driver_co5300::{Co5300Spec, PanelSpec}; pub struct MyNewPanel; impl PanelSpec for MyNewPanel { const PHYSICAL_WIDTH: u16 = 454; const PHYSICAL_HEIGHT: u16 = 454; const PHYSICAL_X_OFFSET: u16 = 0; const PHYSICAL_Y_OFFSET: u16 = 0; } impl Co5300Spec for MyNewPanel { const INIT_PAGE_PARAM: u8 = 0x00; const IGNORE_ID_CHECK: bool = true; } ``` -------------------------------- ### Initialize CO5300 AMOLED Display Driver Source: https://context7.com/decaday/display-driver/llms.txt Configures the CO5300 AMOLED controller. Note that this driver enforces 2-pixel coordinate alignment for proper rendering. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption}; use display_driver_co5300::{Co5300, spec::generic::Generic466x466Type1}; use display_driver_spi::SpiDisplayBus; let panel = Co5300::::new(LCDResetOption::new_pin(rst)); let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) .init(&mut delay) .await .unwrap(); display.set_brightness(128).await.unwrap(); ``` -------------------------------- ### Configure SPI Bus with SpiDisplayBus in Rust Source: https://context7.com/decaday/display-driver/llms.txt This Rust code configures an SPI peripheral for a display, setting frequency and creating an SPI device with chip select. It then initializes SpiDisplayBus, which uses a DC pin for command/data distinction, preparing it for a display driver. ```rust use display_driver_spi::SpiDisplayBus; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::spi::{self, Spi}; use embassy_stm32::time::Hertz; // Configure SPI peripheral let mut spi_config: spi::Config = Default::default(); spi_config.frequency = Hertz(10_000_000); // 10 MHz // Create SPI instance (TX only for write-only displays) let spi = Spi::new_txonly( p.SPI4, // SPI peripheral p.PE12, // SCK pin p.PE14, // MOSI pin p.DMA1_CH0, // DMA channel spi_config ); // Configure GPIO pins let dc = Output::new(p.PE13, Level::Low, Speed::High); // Data/Command pin let cs = Output::new(p.PE9, Level::High, Speed::High); // Chip Select pin // Create SPI device with chip select let spi_device = embedded_hal_bus::spi::ExclusiveDevice::new_no_delay(spi, cs).unwrap(); // Create the display bus let bus = SpiDisplayBus::new(spi_device, dc); // The bus is now ready to be used with a DisplayDriver ``` -------------------------------- ### Initialize ST7789 Display Driver in Rust Source: https://context7.com/decaday/display-driver/llms.txt This Rust code initializes the ST7789 display controller driver, supporting various panel sizes via the `Spec` trait. It demonstrates creating the driver with a reset option, configuring color format and orientation, and performing basic operations like setting brightness and invert mode. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption}; use display_driver_st7789::{St7789, spec::generic::*}; use display_driver_spi::SpiDisplayBus; // Available generic specs for ST7789: // - Generic240x320Type1: 240x320, offset=(0,0), inverted, RGB // - Generic240x240Type1: 240x240, offset=(0,0)/(0,80), inverted, RGB // - Generic135x240Type1: 135x240, offset=(52,40)/(53,40), inverted, RGB // - Generic240x280Type1: 240x280 (1.69"), offset=(0,20), inverted, RGB // - Generic172x320Type1: 172x320 (1.47"), offset=(34,0), inverted, RGB // - Generic170x320Type1: 170x320, offset=(35,0), inverted, RGB // Create ST7789 driver with 135x240 specification let panel = St7789::::new(LCDResetOption::new_pin(rst)); // Initialize with display driver let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) .with_orientation(Orientation::Deg0) .init(&mut delay) .await .unwrap(); // Set display brightness (0-255, if supported) display.set_brightness(200).await.unwrap(); // Access panel directly for advanced features display.panel.set_invert_mode(&mut display.bus, true).await.unwrap(); display.panel.set_bgr_order(&mut display.bus, true).await.unwrap(); ``` -------------------------------- ### Initialize GC9A01 Round Display Driver Source: https://context7.com/decaday/display-driver/llms.txt Initializes the GC9A01 controller for circular displays. Includes brightness control and frame buffer management for 240x240 resolution. ```rust use display_driver::{ColorFormat, DisplayDriver, Orientation, LCDResetOption}; use display_driver_gc9a01::{Gc9a01, spec::generic::Generic240x240Type1}; use display_driver_spi::SpiDisplayBus; let panel = Gc9a01::::new(LCDResetOption::new_pin(rst)); let mut display = DisplayDriver::builder(bus, panel) .with_color_format(ColorFormat::RGB565) .with_orientation(Orientation::Deg0) .init(&mut delay) .await .unwrap(); display.set_brightness(255).await.unwrap(); let mut framebuffer = [0u8; 240 * 240 * 2]; display.write_frame(&framebuffer).await.unwrap(); ``` -------------------------------- ### Configure Custom Display Panels with PanelSpec Source: https://context7.com/decaday/display-driver/llms.txt Implement the PanelSpec trait to define hardware-specific parameters such as dimensions, offsets, and inversion modes. This allows the driver to support custom display panels. ```rust use display_driver_mipidcs::PanelSpec; use display_driver_st7789::St7789Spec; // Define a custom spec for a specific ST7789 panel pub struct MyCustomST7789Panel; impl PanelSpec for MyCustomST7789Panel { const PHYSICAL_WIDTH: u16 = 240; const PHYSICAL_HEIGHT: u16 = 280; const PHYSICAL_X_OFFSET: u16 = 0; const PHYSICAL_Y_OFFSET: u16 = 20; const PHYSICAL_X_OFFSET_ROTATED: u16 = 0; const PHYSICAL_Y_OFFSET_ROTATED: u16 = 20; const INVERT_TRANSPOSED_OFFSET: bool = false; const INVERTED: bool = true; const BGR: bool = false; } // Implement St7789Spec with tuning parameters impl St7789Spec for MyCustomST7789Panel { const PORCTRL_PARAMS: [u8; 5] = [0x0C, 0x0C, 0x00, 0x33, 0x33]; const GCTRL_PARAM: u8 = 0x35; const VCOMS_PARAM: u8 = 0x19; const LCMCTRL_PARAM: u8 = 0x2C; const VRHS_PARAM: u8 = 0x12; const VDVS_PARAM: u8 = 0x20; const FRCTRL2_PARAM: u8 = 0x0F; const PWCTRL1_PARAMS: [u8; 2] = [0xA4, 0xA1]; const PVGAMCTRL_PARAMS: [u8; 14] = [ 0xD0, 0x04, 0x0D, 0x11, 0x13, 0x2B, 0x3F, 0x54, 0x4C, 0x18, 0x0D, 0x0B, 0x1F, 0x23 ]; const NVGAMCTRL_PARAMS: [u8; 14] = [ 0xD0, 0x04, 0x0C, 0x11, 0x13, 0x2C, 0x3F, 0x44, 0x51, 0x2F, 0x1F, 0x1F, 0x20, 0x23 ]; } // Use custom spec with driver let panel = St7789::::new(reset_opt); ``` -------------------------------- ### Manage Display Orientation Source: https://context7.com/decaday/display-driver/llms.txt Handles screen rotation and coordinate system transposition. The framework automatically adjusts offsets based on the selected orientation. ```rust use display_driver::Orientation; let landscape = Orientation::Deg90; let transposed = landscape.is_transposed(); display.set_orientation(Orientation::Deg90).await.unwrap(); ``` -------------------------------- ### Execute Solid Color Fill Operations Source: https://context7.com/decaday/display-driver/llms.txt Perform efficient screen filling using either hardware-accelerated bus commands or software-based batching. Supports conversion from embedded-graphics color types. ```rust use display_driver::{Area, SolidColor, ColorFormat}; use embedded_graphics_core::pixelcolor::{Rgb565, Rgb888}; // Create solid colors from embedded-graphics colors let red: SolidColor = Rgb565::RED.into(); let blue: SolidColor = Rgb565::BLUE.into(); let white: SolidColor = Rgb888::WHITE.into(); // Fill using hardware acceleration (if bus supports BusHardwareFill) let area = Area::new(0, 0, 100, 100); display.fill_solid_via_bus(red, area).await.unwrap(); // Fill entire screen via hardware display.fill_screen_via_bus(blue).await.unwrap(); // Software batch fill (works with any bus supporting BusBytesIo) // The const generic N specifies the buffer size for batching display.fill_solid_batch::<1024>(white, area).await.unwrap(); display.fill_screen_batch::<2048>(blue).await.unwrap(); ``` -------------------------------- ### Configure Address Mode (MADCTL) in Rust Source: https://context7.com/decaday/display-driver/llms.txt Shows how to manage display orientation, mirroring, and color order using the AddressMode bitflags. Developers can construct modes from orientations or manual bit manipulation to control hardware-level memory access. ```rust use display_driver_mipidcs::dcs_types::AddressMode; use display_driver::Orientation; let mode = AddressMode::from_orientation(Orientation::Deg90); let custom_mode = AddressMode::MV | AddressMode::MX | AddressMode::BGR; let mode = AddressMode::new_simple(true, false, true, true); let mut mode = AddressMode::empty(); mode.set(AddressMode::BGR, true); mode.set_orientation(Orientation::Deg180); display.panel.set_address_mode( &mut display.bus, mode, Some(Orientation::Deg90) ).await.unwrap(); ``` -------------------------------- ### Configure Color Formats Source: https://context7.com/decaday/display-driver/llms.txt Defines pixel color formats ranging from 1-bit binary to 24-bit RGB. Provides helper methods to retrieve bit/byte depth and update display settings. ```rust use display_driver::ColorFormat; let rgb565 = ColorFormat::RGB565; let bits = rgb565.size_bits(); let bytes = rgb565.size_bytes(); display.set_color_format(ColorFormat::RGB565).await.unwrap(); ``` -------------------------------- ### Implement SimpleDisplayBus for SPI/I2C Source: https://context7.com/decaday/display-driver/llms.txt Implement the `SimpleDisplayBus` trait for straightforward serial buses like SPI or I2C. This provides an automatic implementation for the more general `DisplayBus` trait. Requires defining an error type and implementing `write_cmds` and `write_data` methods. ```rust use display_driver::bus::{DisplayBus, SimpleDisplayBus, ErrorType, Metadata, FrameControl}; use display_driver::{Area, DisplayError, SolidColor}; // Simple approach: Implement SimpleDisplayBus for automatic DisplayBus impl struct MySimpleBus { // Your hardware resources } impl ErrorType for MySimpleBus { type Error = MyBusError; } impl SimpleDisplayBus for MySimpleBus { async fn write_cmds(&mut self, cmds: &[u8]) -> Result<(), Self::Error> { // Set DC low, send command bytes Ok(()) } async fn write_data(&mut self, data: &[u8]) -> Result<(), Self::Error> { // Set DC high, send data bytes Ok(()) } // Optional: override for atomic command+params async fn write_cmd_with_params( &mut self, cmd: &[u8], params: &[u8] ) -> Result<(), Self::Error> { self.write_cmds(cmd).await?; self.write_data(params).await } } ``` -------------------------------- ### Manage Frame Synchronization and Metadata Source: https://context7.com/decaday/display-driver/llms.txt Use FrameControl and Metadata to coordinate multi-part frame transfers and VSYNC synchronization. This ensures data integrity during partial screen updates. ```rust use display_driver::{Area, FrameControl, Metadata}; // FrameControl marks frame boundaries for VSYNC/TE synchronization let standalone = FrameControl::new_standalone(); // Single complete frame let first = FrameControl::new_first(); // Start of multi-part frame let last = FrameControl::new_last(); // End of multi-part frame // Metadata carries transfer context let full_screen = Metadata::new_full_screen(240, 320); let continue_stream = Metadata::new_continue_stream(); let custom = Metadata::new_from_parts( Some(Area::new(10, 10, 100, 100)), FrameControl::new_standalone() ); // Used internally by write_pixels let area = Area::new(0, 0, 240, 160); display.write_pixels(area, FrameControl::new_first(), &buffer_part1).await.unwrap(); display.write_pixels(area, FrameControl::new_last(), &buffer_part2).await.unwrap(); ``` -------------------------------- ### Implement Custom GC9A01 Panel Specification (Rust) Source: https://github.com/decaday/display-driver/blob/master/panels/gc9a01/README.md Shows how to define a custom panel specification for the GC9A01 driver by implementing the `PanelSpec` and `Gc9a01Spec` traits. This allows for custom resolution, offsets, and color order configurations. ```rust use display_driver_gc9a01::{PanelSpec, Gc9a01Spec}; // 1. Define your type pub struct MyCustomPanel; // 2. Configure Resolution & Offsets impl PanelSpec for MyCustomPanel { const PHYSICAL_WIDTH: u16 = 240; const PHYSICAL_HEIGHT: u16 = 240; // Panel Offset const PHYSICAL_X_OFFSET: u16 = 0; const PHYSICAL_Y_OFFSET: u16 = 0; // Set true if Red and Blue are swapped (BGR Order) const BGR: bool = true; // For other optional settings, please refer to the code comments. } // 3. Implement Gc9a01Spec marker trait impl Gc9a01Spec for MyCustomPanel {} ``` -------------------------------- ### Configure LCD Reset Options with LCDResetOption in Rust Source: https://context7.com/decaday/display-driver/llms.txt This Rust code demonstrates various ways to configure LCD reset behavior using the LCDResetOption enum. It covers GPIO pins (active high/low), software reset commands, bus-based resets, and disabling reset entirely. ```rust use display_driver::panel::reset::{LCDResetOption, NoResetPin}; use embassy_stm32::gpio::{Level, Output, Speed}; // Option 1: Reset via GPIO pin (active low - most common) let rst_pin = Output::new(p.PE15, Level::High, Speed::High); let reset_opt = LCDResetOption::new_pin(rst_pin); // Option 2: Reset via GPIO pin with explicit active level let rst_pin = Output::new(p.PE15, Level::Low, Speed::High); let reset_opt = LCDResetOption::new_pin_with_level(rst_pin, true); // Active high // Option 3: Software reset via command (0x01) let reset_opt: LCDResetOption = LCDResetOption::new_software(); // Option 4: Reset via the bus interface (if hardware supports it) let reset_opt: LCDResetOption = LCDResetOption::new_bus(); // Option 5: No reset (display already initialized or no reset pin available) let reset_opt: LCDResetOption = LCDResetOption::none(); // Use with panel driver let panel = St7789::::new(reset_opt); // Release the pin later if needed let released_pin = reset_opt.release(); // Returns Option

``` -------------------------------- ### Integrate Embedded Graphics with Framebuffers in Rust Source: https://context7.com/decaday/display-driver/llms.txt Illustrates how to use the embedded-graphics crate to draw shapes and text onto a framebuffer. The resulting buffer is then transmitted to the display driver for efficient rendering. ```rust use embedded_graphics::framebuffer::{buffer_size, Framebuffer}; use embedded_graphics::pixelcolor::{raw::{BigEndian, RawU16}, Rgb565}; use embedded_graphics::prelude::*; let mut fb = Framebuffer::(128, 128) }>::new(); fb.clear(Rgb565::BLACK).unwrap(); Circle::new(Point::new(60, 60), 40) .into_styled(PrimitiveStyle::with_fill(Rgb565::RED)) .draw(&mut fb) .unwrap(); display.write_frame(fb.data()).await.unwrap(); ``` -------------------------------- ### Implement Custom ST7789 Display Spec (Rust) Source: https://github.com/decaday/display-driver/blob/master/panels/st7789/README.md Shows how to define a custom `Spec` for the ST7789 display driver when built-in options are insufficient. This involves implementing `PanelSpec` to define resolution and offsets, and then using `impl_st7789_generic!` or manually implementing `St7789Spec` for initialization parameters. ```rust use display_driver_st7789::{PanelSpec, St7789Spec, impl_st7789_generic}; // 1. Define your type pub struct MyCustomPanel; // 2. Configure Resolution & Offsets impl PanelSpec for MyCustomPanel { const PHYSICAL_WIDTH: u16 = 240; const PHYSICAL_HEIGHT: u16 = 240; const PHYSICAL_X_OFFSET: u16 = 0; const PHYSICAL_Y_OFFSET: u16 = 0; // Optional: Offset when rotated 90/270 degrees const PHYSICAL_X_OFFSET_ROTATED: u16 = 0; const PHYSICAL_Y_OFFSET_ROTATED: u16 = 80; const INVERTED: bool = true; // IPS panels usually need this const BGR: bool = false; } // 3. Implement St7789Spec // Option A: Use default generic initialization parameters impl_st7789_generic!(MyCustomPanel); // Option B: Manual implementation for fine-tuning // impl St7789Spec for MyCustomPanel { // const PORCTRL_PARAMS: [u8; 5] = ...; // ... // } ``` -------------------------------- ### Implement DisplayBus for Complex Buses Source: https://context7.com/decaday/display-driver/llms.txt Implement the `DisplayBus` trait directly for complex or custom hardware interfaces. This allows for more control over transactions, including atomic command-parameter writes and optimized pixel transfers using metadata for frame control and ROI. ```rust // Advanced approach: Implement DisplayBus directly for complex buses impl DisplayBus for MyAdvancedBus { async fn write_cmd(&mut self, cmd: &[u8]) -> Result<(), Self::Error> { // Send command Ok(()) } async fn write_cmd_with_params( &mut self, cmd: &[u8], params: &[u8] ) -> Result<(), Self::Error> { // Atomic command + params transaction Ok(()) } async fn write_pixels( &mut self, cmd: &[u8], data: &[u8], metadata: Metadata, ) -> Result<(), DisplayError> { // Handle frame sync using metadata.frame_control // Use metadata.area for ROI-aware transfers // Leverage DMA or hardware acceleration Ok(()) } } ``` -------------------------------- ### Define Rectangular Regions with Area Source: https://context7.com/decaday/display-driver/llms.txt The Area struct manages rectangular regions for partial display updates. It supports creation from coordinates, origins, or tuples and integrates with embedded-graphics primitives. ```rust use display_driver::Area; // Create an area at position (10, 20) with size 100x50 let area = Area::new(10, 20, 100, 50); // Create an area from origin (0, 0) let fullscreen = Area::from_origin(240, 320); // Create from a size tuple let area_from_tuple = Area::from_origin_size((128, 128)); // Access area properties let (x, y) = area.position(); // (10, 20) let (x1, y1) = area.bottom_right(); // (109, 69) let total = area.total_pixels(); // 5000 // Use with embedded-graphics Rectangle (when feature enabled) use embedded_graphics_core::primitives::Rectangle; let rect: Rectangle = area.into(); let area_from_rect: Area = rect.into(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.