Skip to content

Commit f80d08e

Browse files
committed
Make dot clock displays with a masked portion on the left work
1 parent 3684640 commit f80d08e

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ void common_hal_dotclockframebuffer_framebuffer_construct(dotclockframebuffer_fr
175175

176176
self->frequency = frequency;
177177
self->row_stride = 2 * (width + overscan_left);
178+
self->first_pixel_offset = 2 * overscan_left;
178179
self->refresh_rate = frequency / (width + hsync_front_porch + hsync_back_porch) / (height + vsync_front_porch + vsync_back_porch);
179-
self->bufinfo.buf = (uint8_t *)fb + 2 * overscan_left; // first line starts after overscan_left pixels
180-
self->bufinfo.len = 2 * (cfg->timings.h_res * cfg->timings.v_res - overscan_left); // no overscan after last line
180+
self->bufinfo.buf = (uint8_t *)fb;
181+
self->bufinfo.len = 2 * (cfg->timings.h_res * cfg->timings.v_res);
181182
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
182183

183184
// LCD_CAM.lcd_ctrl2.lcd_vsync_idle_pol = _vsync_polarity;
@@ -202,7 +203,7 @@ bool common_hal_dotclockframebuffer_framebuffer_deinitialized(dotclockframebuffe
202203

203204

204205
mp_int_t common_hal_dotclockframebuffer_framebuffer_get_width(dotclockframebuffer_framebuffer_obj_t *self) {
205-
return self->panel_config.timings.h_res;
206+
return self->panel_config.timings.h_res - self->first_pixel_offset / 2;
206207
}
207208

208209
mp_int_t common_hal_dotclockframebuffer_framebuffer_get_height(dotclockframebuffer_framebuffer_obj_t *self) {
@@ -217,6 +218,10 @@ mp_int_t common_hal_dotclockframebuffer_framebuffer_get_row_stride(dotclockframe
217218
return self->row_stride;
218219
}
219220

221+
mp_int_t common_hal_dotclockframebuffer_framebuffer_get_first_pixel_offset(dotclockframebuffer_framebuffer_obj_t *self) {
222+
return self->first_pixel_offset;
223+
}
224+
220225
void common_hal_dotclockframebuffer_framebuffer_refresh(dotclockframebuffer_framebuffer_obj_t *self) {
221226
Cache_WriteBack_Addr((uint32_t)(self->bufinfo.buf), self->bufinfo.len);
222227
}

ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typedef struct dotclockframebuffer_framebuffer_obj {
3939
mp_buffer_info_t bufinfo;
4040
mp_int_t row_stride;
4141
uint32_t frequency, refresh_rate;
42+
uint32_t first_pixel_offset;
4243
uint64_t used_pins_mask;
4344
volatile int32_t frame_count;
4445
esp_lcd_rgb_panel_config_t panel_config;

shared-bindings/dotclockframebuffer/DotClockFramebuffer.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ MP_DEFINE_CONST_FUN_OBJ_1(dotclockframebuffer_framebuffer_get_row_stride_obj, do
269269
MP_PROPERTY_GETTER(dotclockframebuffer_framebuffer_row_stride_obj,
270270
(mp_obj_t)&dotclockframebuffer_framebuffer_get_row_stride_obj);
271271

272+
//| first_pixel_offset: int
273+
//| """The first_pixel_offset of the display, in bytes
274+
//|
275+
//| Due to overscan or alignment requirements, the memory address for row N+1 may not be exactly ``2*width`` bytes after the memory address for row N.
276+
//| This property gives the stride in **bytes**.
277+
//|
278+
//| On Espressif this value is **guaranteed** to be a multiple of the 2 (i.e., it is a whole number of pixels)"""
279+
//|
280+
STATIC mp_obj_t dotclockframebuffer_framebuffer_get_first_pixel_offset(mp_obj_t self_in) {
281+
dotclockframebuffer_framebuffer_obj_t *self = (dotclockframebuffer_framebuffer_obj_t *)self_in;
282+
check_for_deinit(self);
283+
return MP_OBJ_NEW_SMALL_INT(common_hal_dotclockframebuffer_framebuffer_get_first_pixel_offset(self));
284+
}
285+
MP_DEFINE_CONST_FUN_OBJ_1(dotclockframebuffer_framebuffer_get_first_pixel_offset_obj, dotclockframebuffer_framebuffer_get_first_pixel_offset);
286+
287+
MP_PROPERTY_GETTER(dotclockframebuffer_framebuffer_first_pixel_offset_obj,
288+
(mp_obj_t)&dotclockframebuffer_framebuffer_get_first_pixel_offset_obj);
289+
272290
STATIC mp_int_t dotclockframebuffer_framebuffer_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
273291
dotclockframebuffer_framebuffer_obj_t *self = (dotclockframebuffer_framebuffer_obj_t *)self_in;
274292
// a readonly framebuffer would be unusual but not impossible
@@ -331,6 +349,11 @@ STATIC int dotclockframebuffer_framebuffer_get_row_stride_proto(mp_obj_t self_in
331349
return common_hal_dotclockframebuffer_framebuffer_get_row_stride(self);
332350
}
333351

352+
STATIC int dotclockframebuffer_framebuffer_get_first_pixel_offset_proto(mp_obj_t self_in) {
353+
dotclockframebuffer_framebuffer_obj_t *self = (dotclockframebuffer_framebuffer_obj_t *)self_in;
354+
return common_hal_dotclockframebuffer_framebuffer_get_first_pixel_offset(self);
355+
}
356+
334357
STATIC const framebuffer_p_t dotclockframebuffer_framebuffer_proto = {
335358
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer)
336359
.get_bufinfo = dotclockframebuffer_framebuffer_get_bufinfo,
@@ -340,6 +363,7 @@ STATIC const framebuffer_p_t dotclockframebuffer_framebuffer_proto = {
340363
.get_height = dotclockframebuffer_framebuffer_get_height_proto,
341364
.get_color_depth = dotclockframebuffer_framebuffer_get_color_depth_proto,
342365
.get_row_stride = dotclockframebuffer_framebuffer_get_row_stride_proto,
366+
.get_first_pixel_offset = dotclockframebuffer_framebuffer_get_first_pixel_offset_proto,
343367
.get_bytes_per_cell = dotclockframebuffer_framebuffer_get_bytes_per_cell_proto,
344368
.get_native_frames_per_second = dotclockframebuffer_framebuffer_get_native_frames_per_second_proto,
345369
.swapbuffers = dotclockframebuffer_framebuffer_swapbuffers,
@@ -351,6 +375,7 @@ STATIC const mp_rom_map_elem_t dotclockframebuffer_framebuffer_locals_dict_table
351375
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&dotclockframebuffer_framebuffer_width_obj) },
352376
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&dotclockframebuffer_framebuffer_height_obj) },
353377
{ MP_ROM_QSTR(MP_QSTR_row_stride), MP_ROM_PTR(&dotclockframebuffer_framebuffer_row_stride_obj) },
378+
{ MP_ROM_QSTR(MP_QSTR_first_pixel_offset), MP_ROM_PTR(&dotclockframebuffer_framebuffer_first_pixel_offset_obj) },
354379
{ MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&dotclockframebuffer_framebuffer_frequency_obj) },
355380
{ MP_ROM_QSTR(MP_QSTR_refresh_rate), MP_ROM_PTR(&dotclockframebuffer_framebuffer_refresh_rate_obj) },
356381
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&dotclockframebuffer_framebuffer_refresh_obj) },

shared-bindings/dotclockframebuffer/DotClockFramebuffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ mp_int_t common_hal_dotclockframebuffer_framebuffer_get_height(dotclockframebuff
5656
mp_int_t common_hal_dotclockframebuffer_framebuffer_get_frequency(dotclockframebuffer_framebuffer_obj_t *self);
5757
mp_int_t common_hal_dotclockframebuffer_framebuffer_get_refresh_rate(dotclockframebuffer_framebuffer_obj_t *self);
5858
mp_int_t common_hal_dotclockframebuffer_framebuffer_get_row_stride(dotclockframebuffer_framebuffer_obj_t *self);
59+
mp_int_t common_hal_dotclockframebuffer_framebuffer_get_first_pixel_offset(dotclockframebuffer_framebuffer_obj_t *self);
5960
void common_hal_dotclockframebuffer_framebuffer_refresh(dotclockframebuffer_framebuffer_obj_t *self);

shared-module/framebufferio/FramebufferDisplay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
8585
}
8686

8787
self->framebuffer_protocol->get_bufinfo(self->framebuffer, &self->bufinfo);
88-
size_t framebuffer_size = self->first_pixel_offset + self->row_stride * self->core.height;
88+
size_t framebuffer_size = self->first_pixel_offset + self->row_stride * (self->core.height - 1) + self->core.width * self->core.colorspace.depth / 8;
8989

9090
mp_arg_validate_length_min(self->bufinfo.len, framebuffer_size, MP_QSTR_framebuffer);
9191

0 commit comments

Comments
 (0)