Skip to content

Add RP2350 support for 320x240 8bit color #9636

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

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
mp_raise_msg_varg(&mp_type_RuntimeError, MP_ERROR_TEXT("%q in use"), MP_QSTR_picodvi);
}

if (!(width == 640 && height == 480) && !(width == 320 && height == 240 && color_depth == 16)) {
if (!(width == 640 && height == 480) && !(width == 320 && height == 240 && (color_depth == 16 || color_depth == 8))) {
mp_raise_ValueError_varg(MP_ERROR_TEXT("Invalid %q and %q"), MP_QSTR_width, MP_QSTR_height);
}

Expand Down Expand Up @@ -243,11 +243,14 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
DMA_CH0_CTRL_TRIG_INCR_READ_BITS |
DMA_CH0_CTRL_TRIG_EN_BITS;
uint32_t dma_pixel_ctrl;
// We do 16 bit transfers when pixel doubling and the memory bus will
// duplicate the 16 bits to produce 32 bits for the HSTX. HSTX config is the
// same.
if (pixel_doubled) {
dma_pixel_ctrl = dma_ctrl | DMA_SIZE_16 << DMA_CH0_CTRL_TRIG_DATA_SIZE_LSB;
// We do color_depth size transfers when pixel doubling. The memory bus will
// duplicate the 16 bits to produce 32 bits for the HSTX.
if (color_depth == 16) {
dma_pixel_ctrl = dma_ctrl | DMA_SIZE_16 << DMA_CH0_CTRL_TRIG_DATA_SIZE_LSB;
} else {
dma_pixel_ctrl = dma_ctrl | DMA_SIZE_8 << DMA_CH0_CTRL_TRIG_DATA_SIZE_LSB;
}
} else {
dma_pixel_ctrl = dma_ctrl | DMA_SIZE_32 << DMA_CH0_CTRL_TRIG_DATA_SIZE_LSB;
}
Expand Down Expand Up @@ -287,7 +290,9 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
self->dma_commands[command_word++] = dma_pixel_ctrl;
self->dma_commands[command_word++] = dma_write_addr;
row /= 2;
transfer_count *= 2;
// When pixel doubling, we do one transfer per pixel and it gets
// mirrored into the rest of the word.
transfer_count = self->width;
}
self->dma_commands[command_word++] = transfer_count;
uint32_t *row_start = &self->framebuffer[row * self->pitch];
Expand Down Expand Up @@ -341,10 +346,17 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
(color_depth - 1) << HSTX_CTRL_EXPAND_TMDS_L0_NBITS_LSB |
rot << HSTX_CTRL_EXPAND_TMDS_L0_ROT_LSB;
}
size_t shifts_before_empty = ((32 / color_depth) % 32);
if (pixel_doubled && color_depth == 8) {
// All but 320x240 at 8bits will shift through all 32 bits. We are only
// doubling so we only need 16 bits (2 x 8) to get our doubled pixel.
shifts_before_empty = 2;
}

// Pixels come in 32 bits at a time. color_depth dictates the number
// of pixels per word. Control symbols (RAW) are an entire 32-bit word.
hstx_ctrl_hw->expand_shift =
((32 / color_depth) % 32) << HSTX_CTRL_EXPAND_SHIFT_ENC_N_SHIFTS_LSB |
shifts_before_empty << HSTX_CTRL_EXPAND_SHIFT_ENC_N_SHIFTS_LSB |
color_depth << HSTX_CTRL_EXPAND_SHIFT_ENC_SHIFT_LSB |
1 << HSTX_CTRL_EXPAND_SHIFT_RAW_N_SHIFTS_LSB |
0 << HSTX_CTRL_EXPAND_SHIFT_RAW_SHIFT_LSB;
Expand Down
Loading