Fix PWMOut non-error handling and never reset

This commit is contained in:
Dan Halbert 2021-03-19 09:57:21 -04:00
parent 8293e1eedc
commit 1512ca520b
5 changed files with 13 additions and 11 deletions

View File

@ -753,10 +753,6 @@ msgstr ""
msgid "Could not initialize UART"
msgstr ""
#: ports/esp32s2/common-hal/pwmio/PWMOut.c
msgid "Could not initialize timer"
msgstr ""
#: ports/stm/common-hal/pwmio/PWMOut.c
msgid "Could not re-init channel"
msgstr ""

View File

@ -33,6 +33,8 @@
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "esp_log.h"
displayio_fourwire_obj_t board_display_obj;
#define DELAY 0x80

View File

@ -92,7 +92,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
}
}
if (timer_index == INDEX_EMPTY) {
// Running out of timers isn't pin related on ESP32S2 so we can't re-use error messages
// Running out of timers isn't pin related on ESP32S2.
return PWMOUT_ALL_TIMERS_IN_USE;
}
@ -115,7 +115,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
self->tim_handle.clk_cfg = LEDC_AUTO_CLK;
if (ledc_timer_config(&(self->tim_handle)) != ESP_OK) {
mp_raise_ValueError(translate("Could not initialize timer"));
return PWMOUT_INITIALIZATION_ERROR;
}
self->chan_handle.channel = channel_index;
@ -148,6 +148,8 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
never_reset_tim[self->tim_handle.timer_num] = true;
never_reset_chan[self->chan_handle.channel] = true;
never_reset_pin_number(self->pin_number);
}
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {

View File

@ -103,6 +103,8 @@ STATIC mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args,
self->base.type = &pwmio_pwmout_type;
pwmout_result_t result = common_hal_pwmio_pwmout_construct(self, pin, duty_cycle, frequency, variable_frequency);
switch (result) {
case PWMOUT_OK:
break;
case PWMOUT_INVALID_PIN:
mp_raise_ValueError(translate("Invalid pin"));
break;

View File

@ -111,7 +111,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
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_PULSEIO)
#if (CIRCUITPY_PWMIO)
pwmout_result_t result = common_hal_pwmio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 50000, false);
if (result != PWMOUT_OK) {
self->backlight_inout.base.type = &digitalio_digitalinout_type;
@ -173,14 +173,14 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self,
bool ok = false;
// Avoid PWM types and functions when the module isn't enabled
#if (CIRCUITPY_PULSEIO)
#if (CIRCUITPY_PWMIO)
bool ispwm = (self->backlight_pwm.base.type == &pwmio_pwmout_type) ? true : false;
#else
bool ispwm = false;
#endif
if (ispwm) {
#if (CIRCUITPY_PULSEIO)
#if (CIRCUITPY_PWMIO)
common_hal_pwmio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t)(0xffff * brightness));
ok = true;
#else
@ -410,7 +410,7 @@ STATIC void _update_backlight(displayio_display_obj_t *self) {
if (supervisor_ticks_ms64() - self->last_backlight_refresh < 100) {
return;
}
// TODO(tannewt): Fade the backlight based on it's existing value and a target value. The target
// TODO(tannewt): Fade the backlight based on its existing value and a target value. The target
// should account for ambient light when possible.
common_hal_displayio_display_set_brightness(self, 1.0);
@ -428,7 +428,7 @@ void displayio_display_background(displayio_display_obj_t *self) {
void release_display(displayio_display_obj_t *self) {
common_hal_displayio_display_set_auto_refresh(self, false);
release_display_core(&self->core);
#if (CIRCUITPY_PULSEIO)
#if (CIRCUITPY_PWMIO)
if (self->backlight_pwm.base.type == &pwmio_pwmout_type) {
common_hal_pwmio_pwmout_reset_ok(&self->backlight_pwm);
common_hal_pwmio_pwmout_deinit(&self->backlight_pwm);