Skip to content

Commit b08714b

Browse files
committed
Take in framebuffer resolution, not output res
Fixes #7911
1 parent 1a4e1d1 commit b08714b

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

ports/raspberrypi/bindings/picodvi/Framebuffer.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
//| blue_dn: microcontroller.Pin,
5454
//| color_depth: int = 8,
5555
//| ) -> None:
56-
//| """Create a Framebuffer object with the given dimensions (640x480 or 800x480). Memory is
56+
//| """Create a Framebuffer object with the given dimensions. Memory is
5757
//| allocated outside of onto the heap and then moved outside on VM
5858
//| end.
5959
//|
@@ -67,22 +67,22 @@
6767
//| less than dn for all pairs or dp must be greater than dn for all pairs.
6868
//|
6969
//| The framebuffer pixel format varies depending on color_depth:
70+
//|
7071
//| * 1 - Each bit is a pixel. Either white (1) or black (0).
7172
//| * 2 - Each 2 bits is a pixels. Grayscale between white (0x3) and black (0x0).
7273
//| * 8 - Each byte is a pixels in RGB332 format.
7374
//| * 16 - Each two bytes are a pixel in RGB565 format.
7475
//|
75-
//| Monochrome framebuffers (color_depth=1 or 2) will be full resolution.
76-
//| Color framebuffers will be half resolution and pixels will be
77-
//| duplicated to create a signal with the target dimensions.
76+
//| Two output resolutions are currently supported, 640x480 and 800x480.
77+
//| Monochrome framebuffers (color_depth=1 or 2) must be full resolution.
78+
//| Color framebuffers must be half resolution (320x240 or 400x240) and
79+
//| pixels will be duplicated to create the signal.
7880
//|
7981
//| A Framebuffer is often used in conjunction with a
8082
//| `framebufferio.FramebufferDisplay`.
8183
//|
82-
//| :param int width: the width of the target display signal. It will be halved when
83-
//| color_depth >= 8 when creating the framebuffer. Only 640 or 800 is currently supported.
84-
//| :param int height: the height of the target display signal. It will be halved when
85-
//| color_depth >= 8 when creating the framebuffer. Only 480 is currently supported.
84+
//| :param int width: the width of the target display signal. Only 320, 400, 640 or 800 is currently supported depending on color_depth.
85+
//| :param int height: the height of the target display signal. Only 240 or 480 is currently supported depenting on color_depth.
8686
//| :param ~microcontroller.Pin clk_dp: the positive clock signal pin
8787
//| :param ~microcontroller.Pin clk_dn: the negative clock signal pin
8888
//| :param ~microcontroller.Pin red_dp: the positive red signal pin

ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
void board_init(void) {
3434
picodvi_framebuffer_obj_t *fb = &allocate_display_bus()->picodvi;
3535
fb->base.type = &picodvi_framebuffer_type;
36-
common_hal_picodvi_framebuffer_construct(fb, 640, 480,
36+
common_hal_picodvi_framebuffer_construct(fb, 320, 240,
3737
&pin_GPIO17, &pin_GPIO16,
3838
&pin_GPIO19, &pin_GPIO18,
3939
&pin_GPIO21, &pin_GPIO20,

ports/raspberrypi/common-hal/picodvi/Framebuffer.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,23 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
138138
const mcu_pin_obj_t *green_dp, const mcu_pin_obj_t *green_dn,
139139
const mcu_pin_obj_t *blue_dp, const mcu_pin_obj_t *blue_dn,
140140
mp_uint_t color_depth) {
141+
if (active_picodvi != NULL) {
142+
mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q in use"), MP_QSTR_picodvi);
143+
}
141144

145+
bool color_framebuffer = color_depth >= 8;
142146
const struct dvi_timing *timing = NULL;
143-
if (width == 640 && height == 480) {
147+
if ((!color_framebuffer && width == 640 && height == 480) ||
148+
(color_framebuffer && width == 320 && height == 240)) {
144149
timing = &dvi_timing_640x480p_60hz;
145-
} else if (width == 800 && height == 480) {
150+
} else if ((!color_framebuffer && width == 800 && height == 480) ||
151+
(color_framebuffer && width == 400 && height == 240)) {
146152
timing = &dvi_timing_800x480p_60hz;
147153
} else {
148-
if (height == 480) {
149-
mp_raise_ValueError_varg(translate("%q must be %d"), MP_QSTR_width, 480);
154+
if (height != 480 && height != 240) {
155+
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_height);
150156
}
151-
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_height);
152-
}
153-
154-
if (active_picodvi != NULL) {
155-
mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q in use"), MP_QSTR_picodvi);
157+
mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_width);
156158
}
157159

158160
bool invert_diffpairs = clk_dn->number < clk_dp->number;
@@ -214,12 +216,12 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
214216
self->height = height;
215217

216218
size_t tmds_bufs_per_scanline;
217-
if (color_depth >= 8) {
219+
size_t scanline_width = width;
220+
if (color_framebuffer) {
218221
dvi_vertical_repeat = 2;
219222
dvi_monochrome_tmds = false;
220-
self->width /= 2;
221-
self->height /= 2;
222223
tmds_bufs_per_scanline = 3;
224+
scanline_width *= 2;
223225
} else {
224226
dvi_vertical_repeat = 1;
225227
dvi_monochrome_tmds = true;
@@ -233,8 +235,7 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
233235
}
234236
self->pitch /= sizeof(uint32_t);
235237
size_t framebuffer_size = self->pitch * self->height;
236-
// use width here because it hasn't been downsized for the frame buffer
237-
self->tmdsbuf_size = tmds_bufs_per_scanline * width / DVI_SYMBOLS_PER_WORD + 1;
238+
self->tmdsbuf_size = tmds_bufs_per_scanline * scanline_width / DVI_SYMBOLS_PER_WORD + 1;
238239
size_t total_allocation_size = sizeof(uint32_t) * (framebuffer_size + DVI_N_TMDS_BUFFERS * self->tmdsbuf_size);
239240
self->allocation = allocate_memory(total_allocation_size, false, true);
240241
if (self->allocation == NULL) {

0 commit comments

Comments
 (0)