Skip to content

Commit 5419c23

Browse files
committed
simplify and clarify PWMOut shared resource conflict errors
1 parent 868d62f commit 5419c23

5 files changed

Lines changed: 7 additions & 15 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
144144

145145
// We want variable frequency but another class has already claim a fixed frequency.
146146
if (variable_frequency) {
147-
return PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE;
147+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
148148
}
149149

150150
// Another pin is already using this output.
@@ -153,7 +153,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
153153
}
154154

155155
if (frequency != _pwm_sm_frequencies[flexpwm_index][submodule]) {
156-
return PWMOUT_INVALID_FREQUENCY_ON_PIN;
156+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
157157
}
158158

159159
// Submodule is already running at our target frequency and the output

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ pwmout_result_t pwmout_allocate(uint8_t slice, uint8_t ab_channel, bool variable
7878
if (target_slice_frequencies[slice] > 0) {
7979
// If we want to change frequency then we can't share.
8080
if (variable_frequency) {
81-
return PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE;
81+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
8282
}
8383
// If the other user wants a variable frequency then we can't share either.
8484
if ((slice_variable_frequency & (1 << slice)) != 0) {
8585
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
8686
}
8787
// If we're both fixed frequency but we don't match target frequencies then we can't share.
8888
if (target_slice_frequencies[slice] != frequency) {
89-
return PWMOUT_INVALID_FREQUENCY_ON_PIN;
89+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
9090
}
9191
}
9292

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
7474
}
7575
// If the frequencies are the same it's ok
7676
if (tim_frequencies[tim_index] != frequency) {
77-
last_failure = PWMOUT_INVALID_FREQUENCY_ON_PIN;
77+
last_failure = PWMOUT_INTERNAL_RESOURCES_IN_USE;
7878
continue; // keep looking
7979
}
8080
// you can't put a variable frequency on a partially reserved timer
8181
if (variable_frequency) {
82-
last_failure = PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE;
82+
last_failure = PWMOUT_INTERNAL_RESOURCES_IN_USE;
8383
continue; // keep looking
8484
}
8585
first_time_setup = false; // skip setting up the timer

shared-bindings/pwmio/PWMOut.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,8 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) {
2525
case PWMOUT_INVALID_FREQUENCY:
2626
mp_arg_error_invalid(MP_QSTR_frequency);
2727
break;
28-
case PWMOUT_INVALID_FREQUENCY_ON_PIN:
29-
mp_arg_error_invalid(MP_QSTR_frequency);
30-
break;
31-
case PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE:
32-
mp_arg_error_invalid(MP_QSTR_variable_frequency);
33-
break;
3428
case PWMOUT_INTERNAL_RESOURCES_IN_USE:
35-
mp_raise_RuntimeError(MP_ERROR_TEXT("Internal resource(s) in use"));
29+
mp_raise_RuntimeError(MP_ERROR_TEXT("Conflicting settings for shared resource"));
3630
break;
3731
default:
3832
case PWMOUT_INITIALIZATION_ERROR:

shared-bindings/pwmio/PWMOut.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ typedef enum pwmout_result_t {
1515
PWMOUT_OK,
1616
PWMOUT_INVALID_PIN,
1717
PWMOUT_INVALID_FREQUENCY,
18-
PWMOUT_INVALID_FREQUENCY_ON_PIN,
19-
PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE,
2018
PWMOUT_INTERNAL_RESOURCES_IN_USE,
2119
PWMOUT_INITIALIZATION_ERROR,
2220
} pwmout_result_t;

0 commit comments

Comments
 (0)