diff options
| author | Lucian Copeland <hierophect@gmail.com> | 2020-04-30 14:46:51 -0400 |
|---|---|---|
| committer | Lucian Copeland <hierophect@gmail.com> | 2020-04-30 14:47:50 -0400 |
| commit | 4f71bd295d65335b540e50c2066fe8eed1ffda35 (patch) | |
| tree | f350234791aeaab1b2155a43c873ceb9cfbadceb /shared-module/displayio/Display.c | |
| parent | 2d7cf4b792afa1b6755b9575b84cae4b65ae7ab9 (diff) | |
Make PulseIO optional within DisplayIO
Diffstat (limited to 'shared-module/displayio/Display.c')
| -rw-r--r-- | shared-module/displayio/Display.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index aaddbb471..60058d226 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -111,6 +111,8 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, // Always set the backlight type in case we're reusing memory. self->backlight_inout.base.type = &mp_type_NoneType; if (backlight_pin != NULL && common_hal_mcu_pin_is_free(backlight_pin)) { + // Avoid PWM types and functions when the module isn't enabled + #if (CIRCUITPY_PULSIO) pwmout_result_t result = common_hal_pulseio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 50000, false); if (result != PWMOUT_OK) { self->backlight_inout.base.type = &digitalio_digitalinout_type; @@ -120,6 +122,12 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, self->backlight_pwm.base.type = &pulseio_pwmout_type; common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm); } + #else + // Otherwise default to digital + self->backlight_inout.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&self->backlight_inout, backlight_pin); + common_hal_never_reset_pin(backlight_pin); + #endif } if (!self->auto_brightness && (self->backlight_inout.base.type != &mp_type_NoneType || brightness_command != NO_BRIGHTNESS_COMMAND)) { @@ -164,9 +172,21 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, brightness = 1.0-brightness; } bool ok = false; - if (self->backlight_pwm.base.type == &pulseio_pwmout_type) { + + // Avoid PWM types and functions when the module isn't enabled + #if (CIRCUITPY_PULSIO) + bool ispwm = (self->backlight_pwm.base.type == &pulseio_pwmout_type) ? true : false; + #else + bool ispwm = false; + #endif + + if (ispwm) { + #if (CIRCUITPY_PULSIO) common_hal_pulseio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness)); ok = true; + #else + ok = false; + #endif } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { common_hal_digitalio_digitalinout_set_value(&self->backlight_inout, brightness > 0.99); ok = true; @@ -392,12 +412,16 @@ void displayio_display_background(displayio_display_obj_t* self) { void release_display(displayio_display_obj_t* self) { release_display_core(&self->core); + #if (CIRCUITPY_PULSIO) if (self->backlight_pwm.base.type == &pulseio_pwmout_type) { common_hal_pulseio_pwmout_reset_ok(&self->backlight_pwm); - common_hal_pulseio_pwmout_deinit(&self->backlight_pwm); + common_hal_pulseio_pwmout_deinit(&self->backlight_pwm); } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { common_hal_digitalio_digitalinout_deinit(&self->backlight_inout); } + #else + common_hal_digitalio_digitalinout_deinit(&self->backlight_inout); + #endif } void reset_display(displayio_display_obj_t* self) { |
