Merge pull request #833 from rhooper/master

Fix for Issue #770 - Provide a better error message when timers are s…
This commit is contained in:
Dan Halbert 2018-05-14 16:36:43 -04:00 committed by GitHub
commit d655e2194c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -151,6 +151,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
// one output so we start with the TCs to see if they work. // one output so we start with the TCs to see if they work.
int8_t direction = -1; int8_t direction = -1;
uint8_t start = NUM_TIMERS_PER_PIN - 1; uint8_t start = NUM_TIMERS_PER_PIN - 1;
bool found = false;
if (variable_frequency) { if (variable_frequency) {
direction = 1; direction = 1;
start = 0; start = 0;
@ -162,6 +163,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
continue; continue;
} }
if (t->is_tc) { if (t->is_tc) {
found = true;
Tc* tc = tc_insts[t->index]; Tc* tc = tc_insts[t->index];
if (tc->COUNT16.CTRLA.bit.ENABLE == 0 && t->wave_output == 1) { if (tc->COUNT16.CTRLA.bit.ENABLE == 0 && t->wave_output == 1) {
timer = t; timer = t;
@ -177,7 +179,11 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
} }
if (timer == NULL) { if (timer == NULL) {
mp_raise_RuntimeError("All timers in use"); if (found) {
mp_raise_ValueError("All timers for this pin are in use");
} else {
mp_raise_RuntimeError("All timers in use");
}
return; return;
} }