| Crates.io | gc9d01 |
| lib.rs | gc9d01 |
| version | 0.0.1 |
| created_at | 2025-08-17 05:59:40.449354+00 |
| updated_at | 2025-08-17 05:59:40.449354+00 |
| description | A no_std async/sync driver for GC9D01 LCD displays with embedded-graphics support |
| homepage | |
| repository | https://github.com/IvanLi-CN/gc9d01-rs |
| max_upload_size | |
| id | 1799151 |
| size | 48,152 |
A no_std Rust driver for the GC9D01 LCD display controller with full embedded-graphics support. This driver provides both async and sync APIs, making it suitable for modern embedded frameworks like Embassy as well as traditional blocking applications.
Add this to your Cargo.toml:
[dependencies]
gc9d01 = "0.1"
embedded-graphics = "0.8"
# For async support
gc9d01 = { version = "0.1", features = ["async"] }
use gc9d01::{GC9D01, Config, Orientation};
use embedded_graphics::{
pixelcolor::Rgb565,
prelude::*,
primitives::{Circle, PrimitiveStyle},
};
// Create display configuration
let config = Config {
width: 160,
height: 40,
orientation: Orientation::Portrait,
rgb: false,
inverted: false,
dx: 0,
dy: 0,
};
// Initialize display (async example)
let mut display = GC9D01::new(
config, spi_device, dc_pin, rst_pin,
buffer, frame_buffer
);
display.init().await?;
// Draw with embedded-graphics
Circle::new(Point::new(80, 20), 30)
.into_styled(PrimitiveStyle::with_fill(Rgb565::RED))
.draw(&mut display)?;
// Flush to screen
display.flush().await?;
This repository includes comprehensive examples for different use cases:
examples/stm32g4-direct-spi-90-complex-patterns/examples/stm32g4-embedded-graphics/examples/stm32g4/All examples use this pin configuration:
| Function | Pin | Description |
|---|---|---|
| SCK | PB3 | SPI Clock |
| MOSI | PA7 | SPI Data |
| CS | PA4 | Chip Select (active low) |
| DC | PB0 | Data/Command select |
| RST | PC4 | Reset (active low) |
# Basic functionality test
cd examples/stm32g4
cargo run
# embedded-graphics demo
cd examples/stm32g4-embedded-graphics
cargo run
# High-performance patterns
cd examples/stm32g4-direct-spi-90-complex-patterns
cargo run
This driver provides full DrawTarget implementation, supporting:
use embedded_graphics::{
mono_font::{ascii::FONT_6X10, MonoTextStyle},
pixelcolor::Rgb565,
prelude::*,
primitives::{Rectangle, PrimitiveStyle},
text::Text,
};
// Draw a rectangle
Rectangle::new(Point::new(10, 10), Size::new(50, 30))
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLUE))
.draw(&mut display)?;
// Draw text
let text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
Text::new("Hello GC9D01!", Point::new(20, 25), text_style)
.draw(&mut display)?;
The driver supports multiple orientations with automatic coordinate transformation:
use gc9d01::Orientation;
let config = Config {
orientation: Orientation::Portrait, // 0°
// orientation: Orientation::Landscape, // 90°
// orientation: Orientation::PortraitSwapped, // 180°
// orientation: Orientation::LandscapeSwapped, // 270°
..Default::default()
};
For maximum performance, use the frame buffer architecture:
// Allocate buffers
static DISPLAY_BUFFER: [u8; gc9d01::BUF_SIZE] = [0; gc9d01::BUF_SIZE];
static FRAME_BUFFER: [Rgb565; 6400] = [Rgb565::BLACK; 6400]; // 160x40
// Create display with frame buffer
let mut display = GC9D01::new(
config, spi_device, dc_pin, rst_pin,
&mut DISPLAY_BUFFER, &mut FRAME_BUFFER
);
async - Enable async/await support (requires embedded-hal-async)defmt - Enable defmt logging support[dependencies]
gc9d01 = { version = "0.1", features = ["async", "defmt"] }
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is dual-licensed under either:
at your option.