Skip to content

Commit b90a16b

Browse files
authored
Merge pull request #5255 from tannewt/fix_rp_countio
Fix RP2 countio reset
2 parents f71d9e0 + 6e7e703 commit b90a16b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

ports/raspberrypi/common-hal/countio/Counter.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "common-hal/countio/Counter.h"
1+
#include "shared-bindings/countio/Counter.h"
22

33
#include "py/runtime.h"
44
#include "py/mpstate.h"
@@ -48,6 +48,15 @@ void common_hal_countio_counter_construct(countio_counter_obj_t *self,
4848
pwm_set_enabled(self->slice_num, true);
4949
}
5050

51+
52+
void reset_countio(void) {
53+
for (size_t i = 0; i < NUM_PWM_SLICES; i++) {
54+
if (MP_STATE_PORT(counting)[i] != NULL) {
55+
common_hal_countio_counter_deinit(MP_STATE_PORT(counting)[i]);
56+
}
57+
}
58+
}
59+
5160
bool common_hal_countio_counter_deinited(countio_counter_obj_t *self) {
5261
return self->pin_a == 0;
5362
}

ports/raspberrypi/common-hal/countio/Counter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ typedef struct {
1616

1717
void counter_interrupt_handler();
1818

19+
void reset_countio(void);
20+
1921
#endif // MICROPY_INCLUDED_RASPBERRRYPI_COMMON_HAL_COUNTIO_COUNTER_H

ports/raspberrypi/supervisor/port.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "shared-bindings/audiopwmio/PWMAudioOut.h"
3737
#include "shared-bindings/busio/I2C.h"
3838
#include "shared-bindings/busio/SPI.h"
39+
#include "shared-bindings/countio/Counter.h"
3940
#include "shared-bindings/microcontroller/__init__.h"
4041
#include "shared-bindings/rtc/__init__.h"
4142
#include "shared-bindings/pwmio/PWMOut.h"
@@ -135,6 +136,10 @@ void reset_port(void) {
135136
reset_uart();
136137
#endif
137138

139+
#if CIRCUITPY_COUNTIO
140+
reset_countio();
141+
#endif
142+
138143
#if CIRCUITPY_PWMIO
139144
pwmout_reset();
140145
#endif

0 commit comments

Comments
 (0)