@@ -109,6 +109,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
109109 // Always set the backlight type in case we're reusing memory.
110110 self -> backlight_inout .base .type = & mp_type_NoneType ;
111111 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 )
112114 pwmout_result_t result = common_hal_pulseio_pwmout_construct (& self -> backlight_pwm , backlight_pin , 0 , 50000 , false);
113115 if (result != PWMOUT_OK ) {
114116 self -> backlight_inout .base .type = & digitalio_digitalinout_type ;
@@ -118,6 +120,12 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
118120 self -> backlight_pwm .base .type = & pulseio_pwmout_type ;
119121 common_hal_pulseio_pwmout_never_reset (& self -> backlight_pwm );
120122 }
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
121129 }
122130 if (!self -> auto_brightness && (self -> backlight_inout .base .type != & mp_type_NoneType ||
123131 brightness_command != NO_BRIGHTNESS_COMMAND )) {
@@ -162,9 +170,21 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self,
162170 brightness = 1.0 - brightness ;
163171 }
164172 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 )
166183 common_hal_pulseio_pwmout_set_duty_cycle (& self -> backlight_pwm , (uint16_t ) (0xffff * brightness ));
167184 ok = true;
185+ #else
186+ ok = false;
187+ #endif
168188 } else if (self -> backlight_inout .base .type == & digitalio_digitalinout_type ) {
169189 common_hal_digitalio_digitalinout_set_value (& self -> backlight_inout , brightness > 0.99 );
170190 ok = true;
@@ -390,12 +410,16 @@ void displayio_display_background(displayio_display_obj_t* self) {
390410
391411void release_display (displayio_display_obj_t * self ) {
392412 release_display_core (& self -> core );
413+ #if (CIRCUITPY_PULSEIO )
393414 if (self -> backlight_pwm .base .type == & pulseio_pwmout_type ) {
394415 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 );
396417 } else if (self -> backlight_inout .base .type == & digitalio_digitalinout_type ) {
397418 common_hal_digitalio_digitalinout_deinit (& self -> backlight_inout );
398419 }
420+ #else
421+ common_hal_digitalio_digitalinout_deinit (& self -> backlight_inout );
422+ #endif
399423}
400424
401425void reset_display (displayio_display_obj_t * self ) {
0 commit comments