51
51
//| Most people should not use this class directly. Use a specific display driver instead that will
52
52
//| contain the initialization sequence at minimum.
53
53
//|
54
- //| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, bytes_per_cell=1, reverse_pixels_in_byte=False, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness_command=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False)
54
+ //| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, bytes_per_cell=1, reverse_pixels_in_byte=False, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness_command=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False, auto_refresh=True, native_frames_per_second=60 )
55
55
//|
56
56
//| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
57
57
//|
102
102
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
103
103
//| :param bool single_byte_bounds: Display column and row commands use single bytes
104
104
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
105
+ //| :param bool auto_refresh: Automatically refresh the screen
106
+ //| :param int native_frames_per_second: Number of display refreshes per second that occur with the given init_sequence.
105
107
//|
106
108
STATIC mp_obj_t displayio_display_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
107
- enum { ARG_display_bus , ARG_init_sequence , ARG_width , ARG_height , ARG_colstart , ARG_rowstart , ARG_rotation , ARG_color_depth , ARG_grayscale , ARG_pixels_in_byte_share_row , ARG_bytes_per_cell , ARG_reverse_pixels_in_byte , ARG_set_column_command , ARG_set_row_command , ARG_write_ram_command , ARG_set_vertical_scroll , ARG_backlight_pin , ARG_brightness_command , ARG_brightness , ARG_auto_brightness , ARG_single_byte_bounds , ARG_data_as_commands };
109
+ enum { ARG_display_bus , ARG_init_sequence , ARG_width , ARG_height , ARG_colstart , ARG_rowstart , ARG_rotation , ARG_color_depth , ARG_grayscale , ARG_pixels_in_byte_share_row , ARG_bytes_per_cell , ARG_reverse_pixels_in_byte , ARG_set_column_command , ARG_set_row_command , ARG_write_ram_command , ARG_set_vertical_scroll , ARG_backlight_pin , ARG_brightness_command , ARG_brightness , ARG_auto_brightness , ARG_single_byte_bounds , ARG_data_as_commands , ARG_auto_refresh , ARG_native_frames_per_second };
108
110
static const mp_arg_t allowed_args [] = {
109
111
{ MP_QSTR_display_bus , MP_ARG_REQUIRED | MP_ARG_OBJ },
110
112
{ MP_QSTR_init_sequence , MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -128,6 +130,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
128
130
{ MP_QSTR_auto_brightness , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = false} },
129
131
{ MP_QSTR_single_byte_bounds , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = false} },
130
132
{ MP_QSTR_data_as_commands , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = false} },
133
+ { MP_QSTR_auto_refresh , MP_ARG_BOOL | MP_ARG_KW_ONLY , {.u_bool = true} },
134
+ { MP_QSTR_native_frames_per_second , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 60 } },
131
135
};
132
136
mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
133
137
mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
@@ -178,7 +182,9 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
178
182
brightness ,
179
183
args [ARG_auto_brightness ].u_bool ,
180
184
args [ARG_single_byte_bounds ].u_bool ,
181
- args [ARG_data_as_commands ].u_bool
185
+ args [ARG_data_as_commands ].u_bool ,
186
+ args [ARG_auto_refresh ].u_bool ,
187
+ args [ARG_native_frames_per_second ].u_int
182
188
);
183
189
184
190
return self ;
@@ -214,14 +220,28 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show
214
220
215
221
//| .. method:: refresh(*, target_frames_per_second=None, minimum_frames_per_second=1)
216
222
//|
217
- //| Waits for the target frame rate and then refreshes the display. If the call is too late for the given target frame rate, then the refresh returns immediately without updating the screen to hopefully help getting caught up. If the current frame rate is below the minimum frame rate, then an exception will be raised.
223
+ //| When auto refresh is off, waits for the target frame rate and then refreshes the display. If
224
+ //| the call is too late for the given target frame rate, then the refresh returns immediately
225
+ //| without updating the screen to hopefully help getting caught up. If the current frame rate
226
+ //| is below the minimum frame rate, then an exception will be raised.
218
227
//|
219
- STATIC mp_obj_t displayio_display_obj_refresh (mp_obj_t self_in ) {
220
- displayio_display_obj_t * self = native_display (self_in );
221
- common_hal_displayio_display_refresh (self );
228
+ //| When auto refresh is on, updates the display immediately. (The display will also update
229
+ //| without calls to this.)
230
+ //|
231
+ STATIC mp_obj_t displayio_display_obj_refresh (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
232
+ enum { ARG_target_frames_per_second , ARG_minimum_frames_per_second };
233
+ static const mp_arg_t allowed_args [] = {
234
+ { MP_QSTR_target_frames_per_second , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 60 } },
235
+ { MP_QSTR_minimum_frames_per_second , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
236
+ };
237
+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
238
+ mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
239
+
240
+ displayio_display_obj_t * self = native_display (pos_args [0 ]);
241
+ common_hal_displayio_display_refresh (self , 1000 / args [ARG_target_frames_per_second ].u_int , 1000 / args [ARG_minimum_frames_per_second ].u_int );
222
242
return mp_const_none ;
223
243
}
224
- MP_DEFINE_CONST_FUN_OBJ_1 ( displayio_display_refresh_soon_obj , displayio_display_obj_refresh_soon );
244
+ MP_DEFINE_CONST_FUN_OBJ_KW ( displayio_display_refresh_obj , 1 , displayio_display_obj_refresh );
225
245
226
246
//| .. attribute:: auto_refresh
227
247
//|
@@ -376,7 +396,7 @@ const mp_obj_property_t displayio_display_rotation_obj = {
376
396
//|
377
397
STATIC mp_obj_t displayio_display_obj_get_bus (mp_obj_t self_in ) {
378
398
displayio_display_obj_t * self = native_display (self_in );
379
- return self -> bus ;
399
+ return common_hal_displayio_display_get_bus ( self ) ;
380
400
}
381
401
MP_DEFINE_CONST_FUN_OBJ_1 (displayio_display_get_bus_obj , displayio_display_obj_get_bus );
382
402
@@ -412,18 +432,18 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po
412
432
if (bufinfo .typecode != BYTEARRAY_TYPECODE ) {
413
433
mp_raise_ValueError (translate ("Buffer is not a bytearray." ));
414
434
}
415
- if (self -> colorspace .depth != 16 ) {
435
+ if (self -> core . colorspace .depth != 16 ) {
416
436
mp_raise_ValueError (translate ("Display must have a 16 bit colorspace." ));
417
437
}
418
438
419
439
displayio_area_t area = {
420
440
.x1 = 0 ,
421
441
.y1 = y ,
422
- .x2 = self -> width ,
442
+ .x2 = self -> core . width ,
423
443
.y2 = y + 1
424
444
};
425
- uint8_t pixels_per_word = (sizeof (uint32_t ) * 8 ) / self -> colorspace .depth ;
426
- uint16_t buffer_size = self -> width / pixels_per_word ;
445
+ uint8_t pixels_per_word = (sizeof (uint32_t ) * 8 ) / self -> core . colorspace .depth ;
446
+ uint16_t buffer_size = self -> core . width / pixels_per_word ;
427
447
uint16_t pixels_per_buffer = displayio_area_size (& area );
428
448
if (pixels_per_buffer % pixels_per_word ) {
429
449
buffer_size += 1 ;
@@ -440,21 +460,17 @@ STATIC mp_obj_t displayio_display_obj_fill_row(size_t n_args, const mp_obj_t *po
440
460
mask [k ] = 0x00000000 ;
441
461
}
442
462
443
- displayio_display_fill_area ( self , & area , mask , result_buffer );
463
+ displayio_display_core_fill_area ( & self -> core , & area , mask , result_buffer );
444
464
return result ;
445
465
} else {
446
466
mp_raise_ValueError (translate ("Buffer is too small" ));
447
467
}
448
468
}
449
469
MP_DEFINE_CONST_FUN_OBJ_KW (displayio_display_fill_row_obj , 1 , displayio_display_obj_fill_row );
450
470
451
-
452
-
453
-
454
471
STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table [] = {
455
472
{ MP_ROM_QSTR (MP_QSTR_show ), MP_ROM_PTR (& displayio_display_show_obj ) },
456
- { MP_ROM_QSTR (MP_QSTR_refresh_soon ), MP_ROM_PTR (& displayio_display_refresh_soon_obj ) },
457
- { MP_ROM_QSTR (MP_QSTR_wait_for_frame ), MP_ROM_PTR (& displayio_display_wait_for_frame_obj ) },
473
+ { MP_ROM_QSTR (MP_QSTR_refresh ), MP_ROM_PTR (& displayio_display_refresh_obj ) },
458
474
{ MP_ROM_QSTR (MP_QSTR_fill_row ), MP_ROM_PTR (& displayio_display_fill_row_obj ) },
459
475
460
476
{ MP_ROM_QSTR (MP_QSTR_auto_refresh ), MP_ROM_PTR (& displayio_display_auto_refresh_obj ) },
0 commit comments