@@ -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