Skip to content

Commit 78d049d

Browse files
committed
Fix pwm reset spew, protect against null reference in led status
1 parent 14b3b51 commit 78d049d

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232

3333
#define INDEX_EMPTY 0xFF
3434

35+
STATIC bool not_first_reset = false;
3536
STATIC uint32_t reserved_timer_freq[LEDC_TIMER_MAX];
3637
STATIC uint8_t reserved_channels[LEDC_CHANNEL_MAX];
3738
STATIC bool never_reset_tim[LEDC_TIMER_MAX];
3839
STATIC bool never_reset_chan[LEDC_CHANNEL_MAX];
3940

4041
void pwmout_reset(void) {
4142
for (size_t i = 0; i < LEDC_CHANNEL_MAX; i++ ) {
42-
if (reserved_channels[i] != INDEX_EMPTY) {
43+
if (reserved_channels[i] != INDEX_EMPTY && not_first_reset) {
4344
ledc_stop(LEDC_LOW_SPEED_MODE, i, 0);
4445
}
4546
if (!never_reset_chan[i]) {
@@ -54,6 +55,7 @@ void pwmout_reset(void) {
5455
reserved_timer_freq[i] = 0;
5556
}
5657
}
58+
not_first_reset = true;
5759
}
5860

5961
pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,

supervisor/shared/rgb_led_status.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,20 +387,22 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
387387
if (!status->ok) {
388388
status->total_exception_cycle = EXCEPTION_TYPE_LENGTH_MS * 3 + LINE_NUMBER_TOGGLE_LENGTH * status->digit_sum + LINE_NUMBER_TOGGLE_LENGTH * num_places;
389389
}
390-
if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_IndentationError)) {
391-
status->exception_color = INDENTATION_ERROR;
392-
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_SyntaxError)) {
393-
status->exception_color = SYNTAX_ERROR;
394-
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_NameError)) {
395-
status->exception_color = NAME_ERROR;
396-
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_OSError)) {
397-
status->exception_color = OS_ERROR;
398-
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_ValueError)) {
399-
status->exception_color = VALUE_ERROR;
400-
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_MpyError)) {
401-
status->exception_color = MPY_ERROR;
402-
} else {
403-
status->exception_color = OTHER_ERROR;
390+
if (result->exception_type) {
391+
if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_IndentationError)) {
392+
status->exception_color = INDENTATION_ERROR;
393+
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_SyntaxError)) {
394+
status->exception_color = SYNTAX_ERROR;
395+
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_NameError)) {
396+
status->exception_color = NAME_ERROR;
397+
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_OSError)) {
398+
status->exception_color = OS_ERROR;
399+
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_ValueError)) {
400+
status->exception_color = VALUE_ERROR;
401+
} else if (mp_obj_is_subclass_fast(result->exception_type, &mp_type_MpyError)) {
402+
status->exception_color = MPY_ERROR;
403+
} else {
404+
status->exception_color = OTHER_ERROR;
405+
}
404406
}
405407
#endif
406408
}

0 commit comments

Comments
 (0)