Skip to content

Commit d655e21

Browse files
authored
Merge pull request adafruit#833 from rhooper/master
Fix for Issue adafruit#770 - Provide a better error message when timers are s…
2 parents 321f882 + a0954b9 commit d655e21

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • ports/atmel-samd/common-hal/pulseio

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
151151
// one output so we start with the TCs to see if they work.
152152
int8_t direction = -1;
153153
uint8_t start = NUM_TIMERS_PER_PIN - 1;
154+
bool found = false;
154155
if (variable_frequency) {
155156
direction = 1;
156157
start = 0;
@@ -162,6 +163,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
162163
continue;
163164
}
164165
if (t->is_tc) {
166+
found = true;
165167
Tc* tc = tc_insts[t->index];
166168
if (tc->COUNT16.CTRLA.bit.ENABLE == 0 && t->wave_output == 1) {
167169
timer = t;
@@ -177,7 +179,11 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
177179
}
178180

179181
if (timer == NULL) {
180-
mp_raise_RuntimeError("All timers in use");
182+
if (found) {
183+
mp_raise_ValueError("All timers for this pin are in use");
184+
} else {
185+
mp_raise_RuntimeError("All timers in use");
186+
}
181187
return;
182188
}
183189

0 commit comments

Comments
 (0)