Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4616

SDK • Fastest OLED write?

$
0
0
As hinted at in my other recent thread, I have a Pico (RP2040) wired up to a 320x240 OLED. Two bytes of color per pixel. I timed the writing of the buffer to the display and it's almost 20ms, which is kind of disappointing. PIO is the fastest way to do this, right? That's what I'm using. I can only improve the speed by bumping up the Pico clock, right?

Code pilfered from one of the Pico examples.

Code:

;; Copyright (c) 2020 Raspberry Pi (Trading) Ltd.;; SPDX-License-Identifier: BSD-3-Clause;.program st7789_lcd.side_set 1; This is just a simple clocked serial TX. At 125 MHz system clock we can; sustain up to 62.5 Mbps.; Data on OUT pin 0; Clock on side-set pin 0.wrap_target    out pins, 1   side 0 ; stall here if no data (clock low)    nop           side 1.wrap% c-sdk {// For optimal use of DMA bandwidth we would use an autopull threshold of 32,// but we are using a threshold of 8 here (consume 1 byte from each FIFO entry// and discard the remainder) to make things easier for software on the other sidestatic inline void st7789_lcd_program_init(PIO pio, uint sm, uint offset, bool cpol, uint data_pin, uint clk_pin, float clk_div) {    pio_gpio_init(pio, data_pin);    pio_gpio_init(pio, clk_pin);    pio_sm_set_consecutive_pindirs(pio, sm, data_pin, 1, true);    pio_sm_set_consecutive_pindirs(pio, sm, clk_pin, 1, true);    pio_sm_config c = st7789_lcd_program_get_default_config(offset);    sm_config_set_sideset_pins(&c, clk_pin);    sm_config_set_out_pins(&c, data_pin, 1);    sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);    sm_config_set_clkdiv(&c, clk_div);    sm_config_set_out_shift(&c, false, true, 8);// The pin muxes can be configured to invert the output (among other things    // and this is a cheesy way to get CPOL=1    gpio_set_outover(clk_pin, cpol ? GPIO_OVERRIDE_INVERT : GPIO_OVERRIDE_NORMAL);    pio_sm_init(pio, sm, offset, &c);    pio_sm_set_enabled(pio, sm, true);}// Making use of the narrow store replication behaviour on RP2040 to get the// data left-justified (as we are using shift-to-left to get MSB-first serial)static inline void st7789_lcd_put(PIO pio, uint sm, uint8_t x) {    while (pio_sm_is_tx_fifo_full(pio, sm))        ;    *(volatile uint8_t*)&pio->txf[sm] = x;}// SM is done when it stalls on an empty FIFOstatic inline void st7789_lcd_wait_idle(PIO pio, uint sm) {    uint32_t sm_stall_mask = 1u << (sm + PIO_FDEBUG_TXSTALL_LSB);    pio->fdebug = sm_stall_mask;    while (!(pio->fdebug & sm_stall_mask))        ;}%}

Statistics: Posted by Mike**K — Sun Feb 23, 2025 11:10 pm — Replies 5 — Views 120



Viewing all articles
Browse latest Browse all 4616

Trending Articles