Skip to content

drivers: add mipi_dbi_rpi_pico_pio #91350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Maravus
Copy link

@Maravus Maravus commented Jun 10, 2025

Add mipi_dbi driver for MIPI_DBI_MODE_8080_BUS_8/9/16_BIT using PIO and DMA.
The implementation allows splitting the parallel data pins. Max 4 splits are possible as there are 4 state machines per PIO instance.

In general it works quite nice.
image

There is a topic to discuss though, how to determine the end of a transmission. For the data bytes one has to wait for the DMAs to finish, next the FIFOs have to be empty and at the end the PIOs need to be finished before pulling cs line high. Same for the CMD byte. There only one byte is transferred and one needs to wait only for the PIOs to finish.
The wait time is dependent on the clock div, the PIO instructions and the system clock. Right now a sleep is used. But this introduces quite a delay as context switching is possible.
image

One could adapt the PIO instructions to also toggle the cmd line but then one would need at least 2 PIO state machines, and it would add some additional clock cycles (probably not a big issue as it is really fast anyway).

Compared to mipi_dbi_bitbang it is currently still much faster. On my 320x240 display an animation is faded in with ~12fps. With the bitbang driver it reaches only ~3fps. Tested with an rp2040 at 125MHz.

@Maravus Maravus force-pushed the add-mipi-dbi-rpi-pico-pio branch 2 times, most recently from 0b9adcf to ccc4852 Compare June 10, 2025 10:37
const char *failed_pin = NULL;
int ret = 0;

mipi_dbi_pio_configure(dev);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check return code

Comment on lines 198 to 250
switch (split_count) {
case 4:
SET_SM_PROGRAM(3, splits[0].pin_count + splits[1].pin_count + splits[2].pin_count)
case 3:
SET_SM_PROGRAM(2, splits[0].pin_count + splits[1].pin_count)
case 2:
SET_SM_PROGRAM(1, splits[0].pin_count)
case 1:
CONFIG_SM_PROGRAM(0, 0, 1, 2)
/* 0: pull ifempty block side 1 [1] */
split->sm.program_instructions[0] = 0x99e0;
/* 1: out pins, #pins side 0 [1] */
split->sm.program_instructions[1] = 0x7100 | split->pin_count;
default:
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the fallthrough are intentional but please mark them as such (__fallthrough;)

.cmd_data = GPIO_DT_SPEC_INST_GET_OR(n, dc_gpios, {}), \
.reset = GPIO_DT_SPEC_INST_GET_OR(n, reset_gpios, {}), \
}; \
BUILD_ASSERT(DT_INST_PROP_LEN(n, data_gpios) < MIPI_DBI_MAX_DATA_BUS_WIDTH, \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BUILD_ASSERT(DT_INST_PROP_LEN(n, data_gpios) < MIPI_DBI_MAX_DATA_BUS_WIDTH, \
BUILD_ASSERT(DT_INST_PROP_LEN(n, data_gpios) <= MIPI_DBI_MAX_DATA_BUS_WIDTH, \

Comment on lines 42 to 43
GPIO pins used for the parallel data bus. This must have as many entries as the bus is wide
of the selected mipi-mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

second sentence is very oddly worded

switch (split->sm.sm) {
case 0:
split->dma.config.dma_slot =
data->pio == pio0 ? RPI_PICO_DMA_SLOT_PIO0_TX0 : RPI_PICO_DMA_SLOT_PIO1_TX0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of rp2350, there are three PIOs, so please consider supporting it if possible.

@pdgendt
Copy link
Contributor

pdgendt commented Jun 27, 2025

Do not use fixed commits, squash and force push.

@Maravus Maravus force-pushed the add-mipi-dbi-rpi-pico-pio branch 2 times, most recently from ac5eea3 to 504e3d9 Compare June 27, 2025 09:34
@pdgendt pdgendt dismissed their stale review June 27, 2025 09:35

comment addressed

@pdgendt
Copy link
Contributor

pdgendt commented Jun 27, 2025

Would be nice if this driver could be built in CI

@Maravus Maravus force-pushed the add-mipi-dbi-rpi-pico-pio branch 2 times, most recently from f9ab134 to 68078d0 Compare June 27, 2025 10:36
@Maravus Maravus force-pushed the add-mipi-dbi-rpi-pico-pio branch 4 times, most recently from 35406d8 to 2622e6c Compare July 14, 2025 09:43
Add mipi_dbi driver for MIPI_DBI_MODE_8080_BUS_8/9/16_BIT using PIO and DMA

Signed-off-by: Christoph Schnetzler <schnetzler.christoph@gmail.com>
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants