@@ -45,7 +45,6 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
45
45
mp_obj_t framebuffer , uint16_t width , uint16_t height ,
46
46
uint16_t rotation , uint16_t color_depth ,
47
47
uint8_t bytes_per_cell ,
48
- const mcu_pin_obj_t * backlight_pin , mp_float_t brightness , bool auto_brightness ,
49
48
bool auto_refresh , uint16_t native_frames_per_second ) {
50
49
// Turn off auto-refresh as we init.
51
50
self -> auto_refresh = false;
@@ -58,33 +57,13 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
58
57
displayio_display_core_construct (& self -> core , NULL , width , height , ram_width , ram_height , 0 , 0 , rotation ,
59
58
color_depth , false, false, bytes_per_cell , false, false);
60
59
61
- self -> auto_brightness = auto_brightness ;
62
60
self -> first_manual_refresh = !auto_refresh ;
63
61
64
62
self -> native_frames_per_second = native_frames_per_second ;
65
63
self -> native_ms_per_frame = 1000 / native_frames_per_second ;
66
64
67
65
supervisor_start_terminal (width , height );
68
66
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
-
88
67
// Set the group after initialization otherwise we may send pixels while we delay in
89
68
// initialization.
90
69
common_hal_framebufferio_framebufferdisplay_show (self , & circuitpython_splash );
@@ -104,33 +83,31 @@ uint16_t common_hal_framebufferio_framebufferdisplay_get_height(framebufferio_fr
104
83
}
105
84
106
85
bool 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;
108
90
}
109
91
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;
112
97
}
113
98
114
99
mp_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 ;
116
104
}
117
105
118
106
bool common_hal_framebufferio_framebufferdisplay_set_brightness (framebufferio_framebufferdisplay_obj_t * self , mp_float_t brightness ) {
119
- self -> updating_backlight = true;
120
107
bool ok = false;
121
108
if (self -> framebuffer_protocol -> set_brightness ) {
122
109
self -> framebuffer_protocol -> set_brightness (self -> framebuffer , brightness );
123
110
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 ;
134
111
}
135
112
return ok ;
136
113
}
@@ -295,17 +272,8 @@ void common_hal_framebufferio_framebufferdisplay_set_auto_refresh(framebufferio_
295
272
}
296
273
297
274
STATIC 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
- }
304
275
// TODO(tannewt): Fade the backlight based on it's existing value and a target value. The target
305
276
// 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 ();
309
277
}
310
278
311
279
void framebufferio_framebufferdisplay_background (framebufferio_framebufferdisplay_obj_t * self ) {
@@ -318,18 +286,11 @@ void framebufferio_framebufferdisplay_background(framebufferio_framebufferdispla
318
286
319
287
void release_framebufferdisplay (framebufferio_framebufferdisplay_obj_t * self ) {
320
288
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
- }
327
289
self -> framebuffer_protocol -> deinit (self -> framebuffer );
328
290
}
329
291
330
292
void reset_framebufferdisplay (framebufferio_framebufferdisplay_obj_t * self ) {
331
293
self -> auto_refresh = true;
332
- self -> auto_brightness = true;
333
294
common_hal_framebufferio_framebufferdisplay_show (self , NULL );
334
295
}
335
296
0 commit comments