@@ -45,7 +45,6 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
4545 mp_obj_t framebuffer , uint16_t width , uint16_t height ,
4646 uint16_t rotation , uint16_t color_depth ,
4747 uint8_t bytes_per_cell ,
48- const mcu_pin_obj_t * backlight_pin , mp_float_t brightness , bool auto_brightness ,
4948 bool auto_refresh , uint16_t native_frames_per_second ) {
5049 // Turn off auto-refresh as we init.
5150 self -> auto_refresh = false;
@@ -58,33 +57,13 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
5857 displayio_display_core_construct (& self -> core , NULL , width , height , ram_width , ram_height , 0 , 0 , rotation ,
5958 color_depth , false, false, bytes_per_cell , false, false);
6059
61- self -> auto_brightness = auto_brightness ;
6260 self -> first_manual_refresh = !auto_refresh ;
6361
6462 self -> native_frames_per_second = native_frames_per_second ;
6563 self -> native_ms_per_frame = 1000 / native_frames_per_second ;
6664
6765 supervisor_start_terminal (width , height );
6866
69- // Always set the backlight type in case we're reusing memory.
70- self -> backlight_inout .base .type = & mp_type_NoneType ;
71- if (backlight_pin != NULL && common_hal_mcu_pin_is_free (backlight_pin )) {
72- pwmout_result_t result = common_hal_pulseio_pwmout_construct (& self -> backlight_pwm , backlight_pin , 0 , 50000 , false);
73- if (result != PWMOUT_OK ) {
74- self -> backlight_inout .base .type = & digitalio_digitalinout_type ;
75- common_hal_digitalio_digitalinout_construct (& self -> backlight_inout , backlight_pin );
76- common_hal_never_reset_pin (backlight_pin );
77- } else {
78- self -> backlight_pwm .base .type = & pulseio_pwmout_type ;
79- common_hal_pulseio_pwmout_never_reset (& self -> backlight_pwm );
80- }
81- }
82- if (!self -> auto_brightness && (self -> framebuffer_protocol -> set_brightness != NULL || self -> backlight_inout .base .type != & mp_type_NoneType )) {
83- common_hal_framebufferio_framebufferdisplay_set_brightness (self , brightness );
84- } else {
85- self -> current_brightness = -1.0 ;
86- }
87-
8867 // Set the group after initialization otherwise we may send pixels while we delay in
8968 // initialization.
9069 common_hal_framebufferio_framebufferdisplay_show (self , & circuitpython_splash );
@@ -104,33 +83,31 @@ uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_fr
10483}
10584
10685bool common_hal_framebufferio_framebufferdisplay_get_auto_brightness (framebufferio_framebufferdisplay_obj_t * self ) {
107- return self -> auto_brightness ;
86+ if (self -> framebuffer_protocol -> get_auto_brightness ) {
87+ return self -> framebuffer_protocol -> get_auto_brightness (self -> framebuffer );
88+ }
89+ return true;
10890}
10991
110- void common_hal_framebufferio_framebufferdisplay_set_auto_brightness (framebufferio_framebufferdisplay_obj_t * self , bool auto_brightness ) {
111- self -> auto_brightness = auto_brightness ;
92+ bool common_hal_framebufferio_framebufferdisplay_set_auto_brightness (framebufferio_framebufferdisplay_obj_t * self , bool auto_brightness ) {
93+ if (self -> framebuffer_protocol -> set_auto_brightness ) {
94+ return self -> framebuffer_protocol -> set_auto_brightness (self -> framebuffer , auto_brightness );
95+ }
96+ return false;
11297}
11398
11499mp_float_t common_hal_framebufferio_framebufferdisplay_get_brightness (framebufferio_framebufferdisplay_obj_t * self ) {
115- return self -> current_brightness ;
100+ if (self -> framebuffer_protocol -> set_brightness ) {
101+ return self -> framebuffer_protocol -> get_brightness (self -> framebuffer );
102+ }
103+ return -1 ;
116104}
117105
118106bool common_hal_framebufferio_framebufferdisplay_set_brightness (framebufferio_framebufferdisplay_obj_t * self , mp_float_t brightness ) {
119- self -> updating_backlight = true;
120107 bool ok = false;
121108 if (self -> framebuffer_protocol -> set_brightness ) {
122109 self -> framebuffer_protocol -> set_brightness (self -> framebuffer , brightness );
123110 ok = true;
124- } else if (self -> backlight_pwm .base .type == & pulseio_pwmout_type ) {
125- common_hal_pulseio_pwmout_set_duty_cycle (& self -> backlight_pwm , (uint16_t ) (0xffff * brightness ));
126- ok = true;
127- } else if (self -> backlight_inout .base .type == & digitalio_digitalinout_type ) {
128- common_hal_digitalio_digitalinout_set_value (& self -> backlight_inout , brightness > 0.99 );
129- ok = true;
130- }
131- self -> updating_backlight = false;
132- if (ok ) {
133- self -> current_brightness = brightness ;
134111 }
135112 return ok ;
136113}
@@ -295,17 +272,8 @@ void common_hal_framebufferio_framebufferdisplay_set_auto_refresh(framebufferio_
295272}
296273
297274STATIC void _update_backlight (framebufferio_framebufferdisplay_obj_t * self ) {
298- if (!self -> auto_brightness || self -> updating_backlight ) {
299- return ;
300- }
301- if (supervisor_ticks_ms64 () - self -> last_backlight_refresh < 100 ) {
302- return ;
303- }
304275 // TODO(tannewt): Fade the backlight based on it's existing value and a target value. The target
305276 // should account for ambient light when possible.
306- common_hal_framebufferio_framebufferdisplay_set_brightness (self , 1.0 );
307-
308- self -> last_backlight_refresh = supervisor_ticks_ms64 ();
309277}
310278
311279void framebufferio_framebufferdisplay_background (framebufferio_framebufferdisplay_obj_t * self ) {
@@ -318,18 +286,11 @@ void framebufferio_framebufferdisplay_background(framebufferio_framebufferdispla
318286
319287void release_framebufferdisplay (framebufferio_framebufferdisplay_obj_t * self ) {
320288 release_display_core (& self -> core );
321- if (self -> backlight_pwm .base .type == & pulseio_pwmout_type ) {
322- common_hal_pulseio_pwmout_reset_ok (& self -> backlight_pwm );
323- common_hal_pulseio_pwmout_deinit (& self -> backlight_pwm );
324- } else if (self -> backlight_inout .base .type == & digitalio_digitalinout_type ) {
325- common_hal_digitalio_digitalinout_deinit (& self -> backlight_inout );
326- }
327289 self -> framebuffer_protocol -> deinit (self -> framebuffer );
328290}
329291
330292void reset_framebufferdisplay (framebufferio_framebufferdisplay_obj_t * self ) {
331293 self -> auto_refresh = true;
332- self -> auto_brightness = true;
333294 common_hal_framebufferio_framebufferdisplay_show (self , NULL );
334295}
335296
0 commit comments