Skip to content

Commit 1512ca5

Browse files
committed
Fix PWMOut non-error handling and never reset
1 parent 8293e1e commit 1512ca5

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

locale/circuitpython.pot

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,6 @@ msgstr ""
753753
msgid "Could not initialize UART"
754754
msgstr ""
755755

756-
#: ports/esp32s2/common-hal/pwmio/PWMOut.c
757-
msgid "Could not initialize timer"
758-
msgstr ""
759-
760756
#: ports/stm/common-hal/pwmio/PWMOut.c
761757
msgid "Could not re-init channel"
762758
msgstr ""

ports/esp32s2/boards/adafruit_funhouse/board.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "shared-module/displayio/__init__.h"
3434
#include "shared-module/displayio/mipi_constants.h"
3535

36+
#include "esp_log.h"
37+
3638
displayio_fourwire_obj_t board_display_obj;
3739

3840
#define DELAY 0x80

ports/esp32s2/common-hal/pwmio/PWMOut.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
9292
}
9393
}
9494
if (timer_index == INDEX_EMPTY) {
95-
// Running out of timers isn't pin related on ESP32S2 so we can't re-use error messages
95+
// Running out of timers isn't pin related on ESP32S2.
9696
return PWMOUT_ALL_TIMERS_IN_USE;
9797
}
9898

@@ -115,7 +115,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
115115
self->tim_handle.clk_cfg = LEDC_AUTO_CLK;
116116

117117
if (ledc_timer_config(&(self->tim_handle)) != ESP_OK) {
118-
mp_raise_ValueError(translate("Could not initialize timer"));
118+
return PWMOUT_INITIALIZATION_ERROR;
119119
}
120120

121121
self->chan_handle.channel = channel_index;
@@ -148,6 +148,8 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
148148
void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
149149
never_reset_tim[self->tim_handle.timer_num] = true;
150150
never_reset_chan[self->chan_handle.channel] = true;
151+
152+
never_reset_pin_number(self->pin_number);
151153
}
152154

153155
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {

shared-bindings/pwmio/PWMOut.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ STATIC mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args,
103103
self->base.type = &pwmio_pwmout_type;
104104
pwmout_result_t result = common_hal_pwmio_pwmout_construct(self, pin, duty_cycle, frequency, variable_frequency);
105105
switch (result) {
106+
case PWMOUT_OK:
107+
break;
106108
case PWMOUT_INVALID_PIN:
107109
mp_raise_ValueError(translate("Invalid pin"));
108110
break;

shared-module/displayio/Display.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self,
111111
self->backlight_inout.base.type = &mp_type_NoneType;
112112
if (backlight_pin != NULL && common_hal_mcu_pin_is_free(backlight_pin)) {
113113
// Avoid PWM types and functions when the module isn't enabled
114-
#if (CIRCUITPY_PULSEIO)
114+
#if (CIRCUITPY_PWMIO)
115115
pwmout_result_t result = common_hal_pwmio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 50000, false);
116116
if (result != PWMOUT_OK) {
117117
self->backlight_inout.base.type = &digitalio_digitalinout_type;
@@ -173,14 +173,14 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self,
173173
bool ok = false;
174174

175175
// Avoid PWM types and functions when the module isn't enabled
176-
#if (CIRCUITPY_PULSEIO)
176+
#if (CIRCUITPY_PWMIO)
177177
bool ispwm = (self->backlight_pwm.base.type == &pwmio_pwmout_type) ? true : false;
178178
#else
179179
bool ispwm = false;
180180
#endif
181181

182182
if (ispwm) {
183-
#if (CIRCUITPY_PULSEIO)
183+
#if (CIRCUITPY_PWMIO)
184184
common_hal_pwmio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t)(0xffff * brightness));
185185
ok = true;
186186
#else
@@ -410,7 +410,7 @@ STATIC void _update_backlight(displayio_display_obj_t *self) {
410410
if (supervisor_ticks_ms64() - self->last_backlight_refresh < 100) {
411411
return;
412412
}
413-
// TODO(tannewt): Fade the backlight based on it's existing value and a target value. The target
413+
// TODO(tannewt): Fade the backlight based on its existing value and a target value. The target
414414
// should account for ambient light when possible.
415415
common_hal_displayio_display_set_brightness(self, 1.0);
416416

@@ -428,7 +428,7 @@ void displayio_display_background(displayio_display_obj_t *self) {
428428
void release_display(displayio_display_obj_t *self) {
429429
common_hal_displayio_display_set_auto_refresh(self, false);
430430
release_display_core(&self->core);
431-
#if (CIRCUITPY_PULSEIO)
431+
#if (CIRCUITPY_PWMIO)
432432
if (self->backlight_pwm.base.type == &pwmio_pwmout_type) {
433433
common_hal_pwmio_pwmout_reset_ok(&self->backlight_pwm);
434434
common_hal_pwmio_pwmout_deinit(&self->backlight_pwm);

0 commit comments

Comments
 (0)