@@ -111,6 +111,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
111
111
// Always set the backlight type in case we're reusing memory.
112
112
self -> backlight_inout .base .type = & mp_type_NoneType ;
113
113
if (backlight_pin != NULL && common_hal_mcu_pin_is_free (backlight_pin )) {
114
+ // Avoid PWM types and functions when the module isn't enabled
115
+ #if (CIRCUITPY_PULSIO )
114
116
pwmout_result_t result = common_hal_pulseio_pwmout_construct (& self -> backlight_pwm , backlight_pin , 0 , 50000 , false);
115
117
if (result != PWMOUT_OK ) {
116
118
self -> backlight_inout .base .type = & digitalio_digitalinout_type ;
@@ -120,6 +122,12 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
120
122
self -> backlight_pwm .base .type = & pulseio_pwmout_type ;
121
123
common_hal_pulseio_pwmout_never_reset (& self -> backlight_pwm );
122
124
}
125
+ #else
126
+ // Otherwise default to digital
127
+ self -> backlight_inout .base .type = & digitalio_digitalinout_type ;
128
+ common_hal_digitalio_digitalinout_construct (& self -> backlight_inout , backlight_pin );
129
+ common_hal_never_reset_pin (backlight_pin );
130
+ #endif
123
131
}
124
132
if (!self -> auto_brightness && (self -> backlight_inout .base .type != & mp_type_NoneType ||
125
133
brightness_command != NO_BRIGHTNESS_COMMAND )) {
@@ -164,9 +172,21 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self,
164
172
brightness = 1.0 - brightness ;
165
173
}
166
174
bool ok = false;
167
- if (self -> backlight_pwm .base .type == & pulseio_pwmout_type ) {
175
+
176
+ // Avoid PWM types and functions when the module isn't enabled
177
+ #if (CIRCUITPY_PULSIO )
178
+ bool ispwm = (self -> backlight_pwm .base .type == & pulseio_pwmout_type ) ? true : false;
179
+ #else
180
+ bool ispwm = false;
181
+ #endif
182
+
183
+ if (ispwm ) {
184
+ #if (CIRCUITPY_PULSIO )
168
185
common_hal_pulseio_pwmout_set_duty_cycle (& self -> backlight_pwm , (uint16_t ) (0xffff * brightness ));
169
186
ok = true;
187
+ #else
188
+ ok = false;
189
+ #endif
170
190
} else if (self -> backlight_inout .base .type == & digitalio_digitalinout_type ) {
171
191
common_hal_digitalio_digitalinout_set_value (& self -> backlight_inout , brightness > 0.99 );
172
192
ok = true;
@@ -392,12 +412,16 @@ void displayio_display_background(displayio_display_obj_t* self) {
392
412
393
413
void release_display (displayio_display_obj_t * self ) {
394
414
release_display_core (& self -> core );
415
+ #if (CIRCUITPY_PULSIO )
395
416
if (self -> backlight_pwm .base .type == & pulseio_pwmout_type ) {
396
417
common_hal_pulseio_pwmout_reset_ok (& self -> backlight_pwm );
397
- common_hal_pulseio_pwmout_deinit (& self -> backlight_pwm );
418
+ common_hal_pulseio_pwmout_deinit (& self -> backlight_pwm );
398
419
} else if (self -> backlight_inout .base .type == & digitalio_digitalinout_type ) {
399
420
common_hal_digitalio_digitalinout_deinit (& self -> backlight_inout );
400
421
}
422
+ #else
423
+ common_hal_digitalio_digitalinout_deinit (& self -> backlight_inout );
424
+ #endif
401
425
}
402
426
403
427
void reset_display (displayio_display_obj_t * self ) {
0 commit comments