@@ -218,16 +218,22 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in)
218218}
219219MP_DEFINE_CONST_FUN_OBJ_2 (displayio_display_show_obj , displayio_display_obj_show );
220220
221- //| .. method:: refresh(*, target_frames_per_second=None , minimum_frames_per_second=1)
221+ //| .. method:: refresh(*, target_frames_per_second=60 , minimum_frames_per_second=1)
222222//|
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.
223+ //| When auto refresh is off, waits for the target frame rate and then refreshes the display,
224+ //| returning True. If the call has taken too long since the last refresh call for the given
225+ //| target frame rate, then the refresh returns False immediately without updating the screen to
226+ //| hopefully help getting caught up.
227+ //|
228+ //| If the time since the last successful refresh is below the minimum frame rate, then an
229+ //| exception will be raised. Set minimum_frames_per_second to 0 to disable.
227230//|
228231//| When auto refresh is on, updates the display immediately. (The display will also update
229232//| without calls to this.)
230233//|
234+ //| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
235+ //| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second.
236+ //|
231237STATIC mp_obj_t displayio_display_obj_refresh (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
232238 enum { ARG_target_frames_per_second , ARG_minimum_frames_per_second };
233239 static const mp_arg_t allowed_args [] = {
@@ -238,8 +244,12 @@ STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos
238244 mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
239245
240246 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 );
242- return mp_const_none ;
247+ uint32_t maximum_ms_per_real_frame = 0xffffffff ;
248+ mp_int_t minimum_frames_per_second = args [ARG_minimum_frames_per_second ].u_int ;
249+ if (minimum_frames_per_second > 0 ) {
250+ maximum_ms_per_real_frame = 1000 / minimum_frames_per_second ;
251+ }
252+ 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 ));
243253}
244254MP_DEFINE_CONST_FUN_OBJ_KW (displayio_display_refresh_obj , 1 , displayio_display_obj_refresh );
245255
0 commit comments