Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RP2 countio reset #5255

Merged
merged 1 commit into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion ports/raspberrypi/common-hal/countio/Counter.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "common-hal/countio/Counter.h"
#include "shared-bindings/countio/Counter.h"

#include "py/runtime.h"
#include "py/mpstate.h"
Expand Down Expand Up @@ -48,6 +48,15 @@ void common_hal_countio_counter_construct(countio_counter_obj_t *self,
pwm_set_enabled(self->slice_num, true);
}


void reset_countio(void) {
for (size_t i = 0; i < NUM_PWM_SLICES; i++) {
if (MP_STATE_PORT(counting)[i] != NULL) {
common_hal_countio_counter_deinit(MP_STATE_PORT(counting)[i]);
}
}
}

bool common_hal_countio_counter_deinited(countio_counter_obj_t *self) {
return self->pin_a == 0;
}
Expand Down
2 changes: 2 additions & 0 deletions ports/raspberrypi/common-hal/countio/Counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ typedef struct {

void counter_interrupt_handler();

void reset_countio(void);

#endif // MICROPY_INCLUDED_RASPBERRRYPI_COMMON_HAL_COUNTIO_COUNTER_H
5 changes: 5 additions & 0 deletions ports/raspberrypi/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "shared-bindings/audiopwmio/PWMAudioOut.h"
#include "shared-bindings/busio/I2C.h"
#include "shared-bindings/busio/SPI.h"
#include "shared-bindings/countio/Counter.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/rtc/__init__.h"
#include "shared-bindings/pwmio/PWMOut.h"
Expand Down Expand Up @@ -135,6 +136,10 @@ void reset_port(void) {
reset_uart();
#endif

#if CIRCUITPY_COUNTIO
reset_countio();
#endif

#if CIRCUITPY_PWMIO
pwmout_reset();
#endif
Expand Down