@@ -138,21 +138,23 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
138
138
const mcu_pin_obj_t * green_dp , const mcu_pin_obj_t * green_dn ,
139
139
const mcu_pin_obj_t * blue_dp , const mcu_pin_obj_t * blue_dn ,
140
140
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
+ }
141
144
145
+ bool color_framebuffer = color_depth >= 8 ;
142
146
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 )) {
144
149
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 )) {
146
152
timing = & dvi_timing_800x480p_60hz ;
147
153
} 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 );
150
156
}
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 );
156
158
}
157
159
158
160
bool invert_diffpairs = clk_dn -> number < clk_dp -> number ;
@@ -214,12 +216,12 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
214
216
self -> height = height ;
215
217
216
218
size_t tmds_bufs_per_scanline ;
217
- if (color_depth >= 8 ) {
219
+ size_t scanline_width = width ;
220
+ if (color_framebuffer ) {
218
221
dvi_vertical_repeat = 2 ;
219
222
dvi_monochrome_tmds = false;
220
- self -> width /= 2 ;
221
- self -> height /= 2 ;
222
223
tmds_bufs_per_scanline = 3 ;
224
+ scanline_width *= 2 ;
223
225
} else {
224
226
dvi_vertical_repeat = 1 ;
225
227
dvi_monochrome_tmds = true;
@@ -233,8 +235,7 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
233
235
}
234
236
self -> pitch /= sizeof (uint32_t );
235
237
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 ;
238
239
size_t total_allocation_size = sizeof (uint32_t ) * (framebuffer_size + DVI_N_TMDS_BUFFERS * self -> tmdsbuf_size );
239
240
self -> allocation = allocate_memory (total_allocation_size , false, true);
240
241
if (self -> allocation == NULL ) {
0 commit comments