GC9A01A Display Driver
A Rust library for interfacing with the GC9A01A display using the embedded-hal and embedded-graphics crates.
Features
- Hardware SPI interface
- RGB and BGR support
- Display orientation support
- Drawing images and individual pixels
- Frame buffer for efficient display updates
Getting Started
Prerequisites
- Rust toolchain
embedded-halcrateembedded-graphicscrate
Installation
Add the following to your Cargo.toml:
[]
= "0.2"
= "0.7"
= { = "path/to/your/gc9a01a" }
Example
Here's an example of how to use the driver to initialize the display:
// Initialize LCD pins
let lcd_dc = pins.gp8.into_push_pull_output;
let lcd_cs = pins.gp9.into_push_pull_output;
let lcd_clk = pins.gp10.;
let lcd_mosi = pins.gp11.;
let lcd_rst = pins.gp12.into_push_pull_output_in_state;
let mut _lcd_bl = pins.gp25.into_push_pull_output_in_state;
// Initialize SPI
let spi = new;
let spi = spi.init;
// Initialize the display
let mut display = GC9A01Anew;
display.init.unwrap;
display.set_orientation.unwrap;
API Documentation
Instruction Enum
Enumeration of instructions for the GC9A01A display.
GC9A01A Struct
Driver for the GC9A01A display.
new(spi, dc, cs, rst, rgb, width, height) -> Self: Creates a new driver instance.init(&mut self, delay: &mut impl DelayMs<u8>) -> Result<(), ()>: Initializes the display.set_orientation(&mut self, orientation: &Orientation) -> Result<(), ()>: Sets the display orientation.write_pixel(&mut self, x: u16, y: u16, color: u16) -> Result<(), ()>: Sets a pixel color at the given coordinates.draw_image(&mut self, image_data: &[u8]) -> Result<(), ()>: Draws an image from a slice of RGB565 data.show(&mut self, buffer: &[u8]) -> Result<(), ()>: Displays the provided buffer on the screen.show_region(&mut self, buffer: &[u8], top_left_x: u16, top_left_y: u16, width: u16, height: u16) -> Result<(), ()>: Updates only the specified region of the display with the provided buffer.
Orientation Enum
Display orientation options.
PortraitLandscapePortraitSwappedLandscapeSwapped
FrameBuffer Struct
A structure representing a frame buffer.
new(buffer: &mut [u8], width: u32, height: u32) -> Self: Creates a new frame buffer.get_buffer(&self) -> &[u8]: Returns a reference to the buffer.clear(&mut self, color: Rgb565): Clears the frame buffer with the specified color.copy_region(&mut self, src_buffer: &[u8], src_top_left: Point, src_size: Size, dest_top_left: Point): Copies a region from another buffer into this buffer.
Contributing
- Fork the repository.
- Create a feature branch (
git checkout -b feature-branch). - Commit your changes (
git commit -am 'Add new feature'). - Push to the branch (
git push origin feature-branch). - Create a new Pull Request.
License
This project is licensed under the MIT License.
Acknowledgments
License
This project is licensed under the MIT License. See the LICENSE file for more details.