Skip to content

Commit

Permalink
Consolidate PWMOUT error enum
Browse files Browse the repository at this point in the history
We already consolidated the resulting message
  • Loading branch information
tannewt committed Jan 25, 2024
1 parent 9538e00 commit 1b25e64
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 28 deletions.
7 changes: 1 addition & 6 deletions ports/atmel-samd/common-hal/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
// one output so we start with the TCs to see if they work.
int8_t direction = -1;
uint8_t start = NUM_TIMERS_PER_PIN - 1;
bool found = false;
if (variable_frequency) {
direction = 1;
start = 0;
Expand All @@ -162,7 +161,6 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
continue;
}
if (t->is_tc) {
found = true;
Tc *tc = tc_insts[t->index];
if (tc->COUNT16.CTRLA.bit.ENABLE == 0 && t->wave_output == 1) {
timer = t;
Expand All @@ -178,10 +176,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
}

if (timer == NULL) {
if (found) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
}
return PWMOUT_ALL_TIMERS_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}

uint8_t resolution = 0;
Expand Down
4 changes: 2 additions & 2 deletions ports/espressif/common-hal/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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.
return PWMOUT_ALL_TIMERS_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}

// Find a viable channel
Expand All @@ -114,7 +114,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
}
}
if (channel_index == INDEX_EMPTY) {
return PWMOUT_ALL_CHANNELS_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}

// Run configuration
Expand Down
4 changes: 2 additions & 2 deletions ports/mimxrt10xx/common-hal/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
if (((flexpwm->MCTRL >> PWM_MCTRL_RUN_SHIFT) & sm_mask) != 0) {
// Another output has claimed this submodule for variable frequency already.
if ((_pwm_variable_frequency[flexpwm_index] & sm_mask) != 0) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}

// We want variable frequency but another class has already claim a fixed frequency.
Expand All @@ -199,7 +199,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,

// Another pin is already using this output.
if ((flexpwm->OUTEN & outen_mask) != 0) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}

if (frequency != _pwm_sm_frequencies[flexpwm_index][submodule]) {
Expand Down
2 changes: 1 addition & 1 deletion ports/nrf/common-hal/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
&channel, &pwm_already_in_use, NULL);

if (self->pwm == NULL) {
return PWMOUT_ALL_TIMERS_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}

self->channel = channel;
Expand Down
8 changes: 4 additions & 4 deletions ports/raspberrypi/common-hal/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,21 @@ pwmout_result_t pwmout_allocate(uint8_t slice, uint8_t ab_channel, bool variable

// Check the channel first.
if ((channel_use & channel_use_mask) != 0) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}
// Now check if the slice is in use and if we can share with it.
if (target_slice_frequencies[slice] > 0) {
// If we want to change frequency then we can't share.
if (variable_frequency) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
return PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE;
}
// If the other user wants a variable frequency then we can't share either.
if ((slice_variable_frequency & (1 << slice)) != 0) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}
// If we're both fixed frequency but we don't match target frequencies then we can't share.
if (target_slice_frequencies[slice] != frequency) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
return PWMOUT_INVALID_FREQUENCY_ON_PIN;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ports/silabs/common-hal/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
}

if (self->tim == NULL) {
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
}

self->duty_cycle = duty;
Expand Down
4 changes: 2 additions & 2 deletions ports/stm/common-hal/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
if (tim_index < TIM_BANK_ARRAY_LEN && tim_channels_taken[tim_index] != 0) {
// Timer has already been reserved by an internal module
if (stm_peripherals_timer_is_reserved(mcu_tim_banks[tim_index])) {
last_failure = PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
last_failure = PWMOUT_INTERNAL_RESOURCES_IN_USE;
continue; // keep looking
}
// is it the same channel? (or all channels reserved by a var-freq)
if (tim_channels_taken[tim_index] & (1 << tim_channel_index)) {
last_failure = PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
last_failure = PWMOUT_INTERNAL_RESOURCES_IN_USE;
continue; // keep looking, might be another viable option
}
// If the frequencies are the same it's ok
Expand Down
8 changes: 1 addition & 7 deletions shared-bindings/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,7 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) {
case PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE:
mp_arg_error_invalid(MP_QSTR_variable_frequency);
break;
case PWMOUT_ALL_TIMERS_ON_PIN_IN_USE:
mp_raise_RuntimeError(MP_ERROR_TEXT("Internal resource(s) in use"));
break;
case PWMOUT_ALL_TIMERS_IN_USE:
mp_raise_RuntimeError(MP_ERROR_TEXT("Internal resource(s) in use"));
break;
case PWMOUT_ALL_CHANNELS_IN_USE:
case PWMOUT_INTERNAL_RESOURCES_IN_USE:
mp_raise_RuntimeError(MP_ERROR_TEXT("Internal resource(s) in use"));
break;
default:
Expand Down
4 changes: 1 addition & 3 deletions shared-bindings/pwmio/PWMOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ typedef enum pwmout_result_t {
PWMOUT_INVALID_FREQUENCY,
PWMOUT_INVALID_FREQUENCY_ON_PIN,
PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE,
PWMOUT_ALL_TIMERS_ON_PIN_IN_USE,
PWMOUT_ALL_TIMERS_IN_USE,
PWMOUT_ALL_CHANNELS_IN_USE,
PWMOUT_INTERNAL_RESOURCES_IN_USE,
PWMOUT_INITIALIZATION_ERROR,
} pwmout_result_t;

Expand Down

0 comments on commit 1b25e64

Please sign in to comment.