Skip to content

Commit 1b25e64

Browse files
committed
Consolidate PWMOUT error enum
We already consolidated the resulting message
1 parent 9538e00 commit 1b25e64

File tree

9 files changed

+15
-28
lines changed

9 files changed

+15
-28
lines changed

ports/atmel-samd/common-hal/pwmio/PWMOut.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
150150
// one output so we start with the TCs to see if they work.
151151
int8_t direction = -1;
152152
uint8_t start = NUM_TIMERS_PER_PIN - 1;
153-
bool found = false;
154153
if (variable_frequency) {
155154
direction = 1;
156155
start = 0;
@@ -162,7 +161,6 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
162161
continue;
163162
}
164163
if (t->is_tc) {
165-
found = true;
166164
Tc *tc = tc_insts[t->index];
167165
if (tc->COUNT16.CTRLA.bit.ENABLE == 0 && t->wave_output == 1) {
168166
timer = t;
@@ -178,10 +176,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
178176
}
179177

180178
if (timer == NULL) {
181-
if (found) {
182-
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
183-
}
184-
return PWMOUT_ALL_TIMERS_IN_USE;
179+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
185180
}
186181

187182
uint8_t resolution = 0;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
103103
}
104104
if (timer_index == INDEX_EMPTY) {
105105
// Running out of timers isn't pin related on ESP32S2.
106-
return PWMOUT_ALL_TIMERS_IN_USE;
106+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
107107
}
108108

109109
// Find a viable channel
@@ -114,7 +114,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
114114
}
115115
}
116116
if (channel_index == INDEX_EMPTY) {
117-
return PWMOUT_ALL_CHANNELS_IN_USE;
117+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
118118
}
119119

120120
// Run configuration

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
189189
if (((flexpwm->MCTRL >> PWM_MCTRL_RUN_SHIFT) & sm_mask) != 0) {
190190
// Another output has claimed this submodule for variable frequency already.
191191
if ((_pwm_variable_frequency[flexpwm_index] & sm_mask) != 0) {
192-
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
192+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
193193
}
194194

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

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

205205
if (frequency != _pwm_sm_frequencies[flexpwm_index][submodule]) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
220220
&channel, &pwm_already_in_use, NULL);
221221

222222
if (self->pwm == NULL) {
223-
return PWMOUT_ALL_TIMERS_IN_USE;
223+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
224224
}
225225

226226
self->channel = channel;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,21 @@ pwmout_result_t pwmout_allocate(uint8_t slice, uint8_t ab_channel, bool variable
119119

120120
// Check the channel first.
121121
if ((channel_use & channel_use_mask) != 0) {
122-
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
122+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
123123
}
124124
// Now check if the slice is in use and if we can share with it.
125125
if (target_slice_frequencies[slice] > 0) {
126126
// If we want to change frequency then we can't share.
127127
if (variable_frequency) {
128-
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
128+
return PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE;
129129
}
130130
// If the other user wants a variable frequency then we can't share either.
131131
if ((slice_variable_frequency & (1 << slice)) != 0) {
132-
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
132+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
133133
}
134134
// If we're both fixed frequency but we don't match target frequencies then we can't share.
135135
if (target_slice_frequencies[slice] != frequency) {
136-
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
136+
return PWMOUT_INVALID_FREQUENCY_ON_PIN;
137137
}
138138
}
139139

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
8383
}
8484

8585
if (self->tim == NULL) {
86-
return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
86+
return PWMOUT_INTERNAL_RESOURCES_IN_USE;
8787
}
8888

8989
self->duty_cycle = duty;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self,
110110
if (tim_index < TIM_BANK_ARRAY_LEN && tim_channels_taken[tim_index] != 0) {
111111
// Timer has already been reserved by an internal module
112112
if (stm_peripherals_timer_is_reserved(mcu_tim_banks[tim_index])) {
113-
last_failure = PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
113+
last_failure = PWMOUT_INTERNAL_RESOURCES_IN_USE;
114114
continue; // keep looking
115115
}
116116
// is it the same channel? (or all channels reserved by a var-freq)
117117
if (tim_channels_taken[tim_index] & (1 << tim_channel_index)) {
118-
last_failure = PWMOUT_ALL_TIMERS_ON_PIN_IN_USE;
118+
last_failure = PWMOUT_INTERNAL_RESOURCES_IN_USE;
119119
continue; // keep looking, might be another viable option
120120
}
121121
// If the frequencies are the same it's ok

shared-bindings/pwmio/PWMOut.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) {
5151
case PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE:
5252
mp_arg_error_invalid(MP_QSTR_variable_frequency);
5353
break;
54-
case PWMOUT_ALL_TIMERS_ON_PIN_IN_USE:
55-
mp_raise_RuntimeError(MP_ERROR_TEXT("Internal resource(s) in use"));
56-
break;
57-
case PWMOUT_ALL_TIMERS_IN_USE:
58-
mp_raise_RuntimeError(MP_ERROR_TEXT("Internal resource(s) in use"));
59-
break;
60-
case PWMOUT_ALL_CHANNELS_IN_USE:
54+
case PWMOUT_INTERNAL_RESOURCES_IN_USE:
6155
mp_raise_RuntimeError(MP_ERROR_TEXT("Internal resource(s) in use"));
6256
break;
6357
default:

shared-bindings/pwmio/PWMOut.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ typedef enum pwmout_result_t {
3838
PWMOUT_INVALID_FREQUENCY,
3939
PWMOUT_INVALID_FREQUENCY_ON_PIN,
4040
PWMOUT_VARIABLE_FREQUENCY_NOT_AVAILABLE,
41-
PWMOUT_ALL_TIMERS_ON_PIN_IN_USE,
42-
PWMOUT_ALL_TIMERS_IN_USE,
43-
PWMOUT_ALL_CHANNELS_IN_USE,
41+
PWMOUT_INTERNAL_RESOURCES_IN_USE,
4442
PWMOUT_INITIALIZATION_ERROR,
4543
} pwmout_result_t;
4644

0 commit comments

Comments
 (0)