@@ -215,28 +215,33 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in)
215215}
216216MP_DEFINE_CONST_FUN_OBJ_2 (displayio_display_show_obj , displayio_display_obj_show );
217217
218- //| def refresh(self, *, target_frames_per_second: int = 60 , minimum_frames_per_second: int = 1) -> bool:
218+ //| def refresh(self, *, target_frames_per_second: Optional[ int] = None , minimum_frames_per_second: int = 1) -> bool:
219219//| """When auto refresh is off, waits for the target frame rate and then refreshes the display,
220220//| returning True. If the call has taken too long since the last refresh call for the given
221221//| target frame rate, then the refresh returns False immediately without updating the screen to
222222//| hopefully help getting caught up.
223223//|
224224//| If the time since the last successful refresh is below the minimum frame rate, then an
225- //| exception will be raised. Set minimum_frames_per_second to 0 to disable.
225+ //| exception will be raised. Set ``minimum_frames_per_second`` to 0 to disable.
226+ //|
227+ //| When auto refresh is off, ``display.refresh()`` or ``display.refresh(target_frames_per_second=None)``
228+ //| will update the display immediately.
226229//|
227230//| When auto refresh is on, updates the display immediately. (The display will also update
228231//| without calls to this.)
229232//|
230233//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
234+ //| Set to `None` for immediate refresh.
231235//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second."""
232236//| ...
233237//|
234238STATIC mp_obj_t displayio_display_obj_refresh (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
235239 enum { ARG_target_frames_per_second , ARG_minimum_frames_per_second };
236240 static const mp_arg_t allowed_args [] = {
237- { MP_QSTR_target_frames_per_second , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 60 } },
241+ { MP_QSTR_target_frames_per_second , MP_ARG_OBJ | MP_ARG_KW_ONLY , {.u_obj = mp_const_none } },
238242 { MP_QSTR_minimum_frames_per_second , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 1 } },
239243 };
244+
240245 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
241246 mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
242247
@@ -246,8 +251,18 @@ STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos
246251 if (minimum_frames_per_second > 0 ) {
247252 maximum_ms_per_real_frame = 1000 / minimum_frames_per_second ;
248253 }
249- return mp_obj_new_bool (common_hal_displayio_display_refresh (self , 1000 / args [ARG_target_frames_per_second ].u_int , maximum_ms_per_real_frame ));
254+
255+ uint32_t target_ms_per_frame ;
256+ if (args [ARG_target_frames_per_second ].u_obj == mp_const_none ) {
257+ target_ms_per_frame = 0xffffffff ;
258+ }
259+ else {
260+ target_ms_per_frame = 1000 / mp_obj_get_int (args [ARG_target_frames_per_second ].u_obj );
261+ }
262+
263+ return mp_obj_new_bool (common_hal_displayio_display_refresh (self , target_ms_per_frame , maximum_ms_per_real_frame ));
250264}
265+
251266MP_DEFINE_CONST_FUN_OBJ_KW (displayio_display_refresh_obj , 1 , displayio_display_obj_refresh );
252267
253268//| auto_refresh: bool
0 commit comments