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