Skip to content

Commit 4f71bd2

Browse files
committed
Make PulseIO optional within DisplayIO
1 parent 2d7cf4b commit 4f71bd2

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

ports/stm/mpconfigport.mk

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,19 @@ ifeq ($(MCU_SERIES),H7)
2222
CIRCUITPY_ANALOGIO = 0
2323
CIRCUITPY_NEOPIXEL_WRITE = 0
2424
CIRCUITPY_PULSEIO = 0
25-
CIRCUITPY_OS = 1
2625
CIRCUITPY_NVM = 0
2726
CIRCUITPY_AUDIOBUSIO = 0
2827
CIRCUITPY_AUDIOIO = 0
2928
CIRCUITPY_ROTARYIO = 0
3029
CIRCUITPY_RTC = 0
3130
CIRCUITPY_FREQUENCYIO = 0
3231
CIRCUITPY_I2CSLAVE = 0
33-
# shared-module modules that still need prerequisites filled
34-
CIRCUITPY_DISPLAYIO = 0 # Requires SPI, PulseIO, and common-hal module (stub ok)
35-
CIRCUITPY_RANDOM = 0 # Requires OS
36-
CIRCUITPY_STORAGE = 0 # Requires OS, filesystem
3732
endif
3833

3934
ifeq ($(MCU_SERIES),F7)
4035
# Not yet implemented common-hal modules:
4136
CIRCUITPY_ANALOGIO = 0
4237
CIRCUITPY_NEOPIXEL_WRITE = 0
43-
CIRCUITPY_PULSEIO = 1
44-
CIRCUITPY_OS = 1
4538
CIRCUITPY_NVM = 0
4639
CIRCUITPY_AUDIOBUSIO = 0
4740
CIRCUITPY_AUDIOIO = 0
@@ -50,7 +43,4 @@ ifeq ($(MCU_SERIES),F7)
5043
CIRCUITPY_FREQUENCYIO = 0
5144
CIRCUITPY_I2CSLAVE = 0
5245
# shared-module modules that still need prerequisites filled
53-
CIRCUITPY_DISPLAYIO = 0 # Requires SPI, PulseIO, and common-hal module (stub ok)
54-
CIRCUITPY_RANDOM = 0 # Requires OS
55-
CIRCUITPY_STORAGE = 0 # Requires OS, filesystem
5646
endif

shared-module/displayio/Display.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

393413
void 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

403427
void reset_display(displayio_display_obj_t* self) {

0 commit comments

Comments
 (0)