Skip to main content

Crate co5300

Crate co5300 

Source
Expand description

§Chipone CO5300 AMOLED Display Controller Driver

A no_std driver for the CO5300, following the CO5300 datasheet V0.01 (Chipone, 24 July 2023). The driver speaks commands; how they reach the chip is up to an Interface implementation, so the same driver runs over:

  • 4-wire SPI with a D/C pin: SpiInterface, on embedded-hal SpiDevice and OutputPin;
  • single-line SPI with the datasheet’s instruction/address framing: FramedSpiInterface;
  • Quad-SPI, through your HAL’s half-duplex transfer and the qspi framing helper;
  • a MIPI-DSI panel IO, such as ESP-IDF’s esp_lcd_panel_io_tx_param/tx_color (see below).

Enable the async feature for an async driver (asynch::Co5300) on AsyncInterface, and the embedded-graphics feature for a DrawTarget that writes straight to the chip’s frame memory, without a frame buffer in the host.

use co5300::{Co5300, Config, SpiInterface};

let iface = SpiInterface::new(spi, dc);
let mut display = Co5300::new(iface, Config::new(410, 502));

// After a hardware reset (`co5300::reset`): sleep out, RGB565, full brightness, display on.
display.init(&mut delay, &[])?;

// Fill the top-left 4 x 2 pixels with red (RGB565, MSB first).
display.set_window(0, 0, 4, 2)?;
display.write_pixels(&[0xF8, 0x00].repeat(8))?;

§Panel initialization

The CO5300 drives many different AMOLED panels; their power, gamma and timing settings live in the manufacturer command pages and come from the panel vendor, not from the chip datasheet. Co5300::init therefore only sends the chip-level commands the datasheet requires and accepts a panel-specific command list, sent first:

ⓘ
const PANEL: &[PanelCommand] = &[
    (0xFE, &[0x20]), // vendor page, unlock, settings ...
    (0xFE, &[0x00]),
];
display.init(&mut delay, PANEL)?;

panel::ESPRESSIF_DEFAULT holds the default sequence of Espressif’s esp_lcd_co5300 component.

§Window alignment

CASET and RASET require an even start and an even length (datasheet sections 7.5.21 and 7.5.22). Co5300::set_window rejects other windows with Error::InvalidWindow; the embedded-graphics target widens them, see its documentation.

§MIPI-DSI: ESP-IDF panel IO

On a board where the CO5300 hangs off MIPI-DSI (such as the Kode Dot below), the ESP-IDF DSI bus stays in charge; an adapter in the board crate forwards the two calls:

ⓘ
struct PanelIo(esp_lcd_panel_io_handle_t);

impl co5300::Interface for PanelIo {
    type Error = EspError;
    // MIPI-DSI: no SetSPIMode (C4h) in `init`.
    const SPI_RAM_WRITE: bool = false;

    fn write_command(&mut self, command: u8, params: &[u8]) -> Result<(), EspError> {
        esp!(unsafe {
            esp_lcd_panel_io_tx_param(self.0, command.into(), params.as_ptr().cast(), params.len())
        })
    }

    fn write_pixels(&mut self, command: u8, data: &[u8]) -> Result<(), EspError> {
        esp!(unsafe {
            esp_lcd_panel_io_tx_color(self.0, command.into(), data.as_ptr().cast(), data.len())
        })
    }
}

When the pixels come from a DPI frame buffer (video mode), only the command path is used.

§Board: Kode Dot

The Kode Dot (ESP32-P4) drives the CO5300 over MIPI-DSI; ESP-IDF owns the DSI bus, the DPI interface and the frame buffer. The panel is 410 × 502 pixels (KODE_DOT in the handheld screen constants), so use Config::new(410, 502). Before init:

  1. The panel supply VCI_EN comes from TCA6408A pin P7: latch P7 high, then make it an output, then wait 20 ms.
  2. Reset is shared with the touch controller on GPIO7: low for 10 ms, high, then wait 120 ms (reset does exactly this).
  3. The DSI PHY LDO runs at 2.5 V.

The datasheet lists resolutions up to 480 lines (and 192 × 960); 502 lines is the board’s value, not one of the datasheet’s.

Re-exports§

pub use co5300_registers as registers;

Modules§

asynchasync
Async driver on AsyncInterface.
graphicsembedded-graphics
An embedded-graphics DrawTarget on the blocking driver.
panel
Panel-specific command lists for Co5300::init.
qspi
Quad-SPI framing, independent of any HAL.

Structs§

AddressRange
An inclusive column or row range, the parameters of CASET (2Ah) and RASET (2Bh).
Co5300
Blocking CO5300 driver.
Config
Display geometry and the settings Co5300::init applies.
CtrlDisplay
WRCTRLD (53h), datasheet section 7.5.40.
FramedSpiInterface
The CO5300 on a single-line SPI bus (CSX, SCL, SDI), using the Quad-SPI interface’s Standard SPI framing (datasheet section 5.2.2, “QSPI 1-wire write”).
Madctl
MADCTL (36h), datasheet section 7.5.29.
SpiInterface
The CO5300 on a 4-wire SPI bus: CSX, SCL, SDI and the D/CX pin.

Enums§

AclMode
The ACL (auto current limit) setting in AclControl, datasheet section 7.5.42.
Command
The user command set (CMD1), datasheet section 7.4 “Command List”.
EnhancementLevel
The sunlight readable enhancement level in ColorEnhance, datasheet section 7.5.44.
Error
A driver error.
PixelFormat
A pixel format in Colmod, datasheet section 7.5.32.
SpiError
An error of SpiInterface: either the SPI device or the D/C pin failed.
TearingEffect
The tearing effect output mode (TEON, 35h).

Constants§

RESET_LOW_MS
How long reset holds RESX low, in milliseconds.
RESET_WAIT_MS
How long reset waits after releasing RESX, in milliseconds.
SLEEP_OUT_TO_DISPLAY_ON_MS
The wait between SLPOUT and DISPON, in milliseconds (T4, section 5.6.2).
SLEEP_WAIT_MS
The wait after SLPIN or SLPOUT before the next command, in milliseconds (sections 7.5.11 and 7.5.12).
SOFTWARE_RESET_WAIT_MS
The wait after SWRESET before SLPOUT when reset in Sleep Out mode, in milliseconds (section 7.5.2). Other commands may follow after 5 ms.

Traits§

AsyncInterfaceasync
The async twin of Interface.
Interface
A transport that carries CO5300 commands and pixel data.

Functions§

reset
Resets the chip through its active-low RESX pin: low for RESET_LOW_MS, high, then a wait of RESET_WAIT_MS.

Type Aliases§

PanelCommand
A panel-specific command: the command code and its parameter bytes.