@@ -111,6 +111,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
111111 // Always set the backlight type in case we're reusing memory.
112112 self -> backlight_inout .base .type = & mp_type_NoneType ;
113113 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 )
114116 pwmout_result_t result = common_hal_pulseio_pwmout_construct (& self -> backlight_pwm , backlight_pin , 0 , 50000 , false);
115117 if (result != PWMOUT_OK ) {
116118 self -> backlight_inout .base .type = & digitalio_digitalinout_type ;
@@ -120,6 +122,12 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self,
120122 self -> backlight_pwm .base .type = & pulseio_pwmout_type ;
121123 common_hal_pulseio_pwmout_never_reset (& self -> backlight_pwm );
122124 }
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
123131 }
124132 if (!self -> auto_brightness && (self -> backlight_inout .base .type != & mp_type_NoneType ||
125133 brightness_command != NO_BRIGHTNESS_COMMAND )) {
@@ -164,9 +172,21 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self,
164172 brightness = 1.0 - brightness ;
165173 }
166174 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 )
168185 common_hal_pulseio_pwmout_set_duty_cycle (& self -> backlight_pwm , (uint16_t ) (0xffff * brightness ));
169186 ok = true;
187+ #else
188+ ok = false;
189+ #endif
170190 } else if (self -> backlight_inout .base .type == & digitalio_digitalinout_type ) {
171191 common_hal_digitalio_digitalinout_set_value (& self -> backlight_inout , brightness > 0.99 );
172192 ok = true;
@@ -392,12 +412,16 @@ void displayio_display_background(displayio_display_obj_t* self) {
392412
393413void release_display (displayio_display_obj_t * self ) {
394414 release_display_core (& self -> core );
415+ #if (CIRCUITPY_PULSIO )
395416 if (self -> backlight_pwm .base .type == & pulseio_pwmout_type ) {
396417 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 );
398419 } else if (self -> backlight_inout .base .type == & digitalio_digitalinout_type ) {
399420 common_hal_digitalio_digitalinout_deinit (& self -> backlight_inout );
400421 }
422+ #else
423+ common_hal_digitalio_digitalinout_deinit (& self -> backlight_inout );
424+ #endif
401425}
402426
403427void reset_display (displayio_display_obj_t * self ) {
0 commit comments