summaryrefslogtreecommitdiff
path: root/ports/raspberrypi/common-hal/countio/Counter.c
diff options
context:
space:
mode:
authorgamblor21 <mark.komus@gmail.com>2021-03-02 19:32:06 -0600
committergamblor21 <mark.komus@gmail.com>2021-03-02 19:32:06 -0600
commit4246cc3f6d718e2f28fbeb73fc8c3c39dfb9d7f0 (patch)
tree0c8f6401adf2a899e8f86967344501e3fe6c1c3f /ports/raspberrypi/common-hal/countio/Counter.c
parentd7bc8a46a5f244069c2bc9b62961bc43dcee03a7 (diff)
Counter and PWMOut slice conflict check
Diffstat (limited to 'ports/raspberrypi/common-hal/countio/Counter.c')
-rw-r--r--ports/raspberrypi/common-hal/countio/Counter.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/ports/raspberrypi/common-hal/countio/Counter.c b/ports/raspberrypi/common-hal/countio/Counter.c
index 4a1ccad0c..69629a084 100644
--- a/ports/raspberrypi/common-hal/countio/Counter.c
+++ b/ports/raspberrypi/common-hal/countio/Counter.c
@@ -4,6 +4,8 @@
#include "py/mpstate.h"
#include "supervisor/shared/translate.h"
+#include "common-hal/pwmio/PWMOut.h"
+
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h"
#include "src/rp2_common/hardware_irq/include/hardware/irq.h"
@@ -23,6 +25,11 @@ void common_hal_countio_counter_construct(countio_counter_obj_t* self,
mp_raise_RuntimeError(translate("PWM slice already in use"));
}
+ uint8_t channel = pwm_gpio_to_channel(self->pin_a);
+ if (!pwmio_claim_slice_channels(self->slice_num)) {
+ mp_raise_RuntimeError(translate("PWM slice channel A already in use"));
+ }
+
pwm_clear_irq(self->slice_num);
pwm_set_irq_enabled(self->slice_num, true);
irq_set_exclusive_handler(PWM_IRQ_WRAP, counter_interrupt_handler);
@@ -53,6 +60,8 @@ void common_hal_countio_counter_deinit(countio_counter_obj_t* self) {
pwm_set_enabled(self->slice_num, false);
pwm_set_irq_enabled(self->slice_num, false);
+ pwmio_release_slice_channels(self->slice_num);
+
reset_pin_number(self->pin_a);
MP_STATE_PORT(counting)[self->slice_num] = NULL;