8000 Merge pull request #3682 from microDev1/pcnt-reset · rpavlik/circuitpython@5f84b79 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 5f84b79

Browse files
authored
Merge pull request adafruit#3682 from microDev1/pcnt-reset
ESP32S2: Reset PCNT on user code reload
2 parents a47dea4 + ff41180 commit 5f84b79

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

ports/esp32s2/peripherals/pcnt.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@
2929
#define PCNT_UNIT_ACTIVE 1
3030
#define PCNT_UNIT_INACTIVE 0
3131

32-
static uint8_t pcnt_state[4];
32+
static uint8_t pcnt_unit_state[4];
33+
34+
void peripherals_pcnt_reset(void) {
35+
for (uint8_t i = 0; i<=3; i++) {
36+
pcnt_unit_state[i] = PCNT_UNIT_INACTIVE;
37+
}
38+
}
3339

3440
int peripherals_pcnt_init(pcnt_config_t pcnt_config) {
3541
// Look for available pcnt unit
3642
for (uint8_t i = 0; i<=3; i++) {
37-
if (pcnt_state[i] == PCNT_UNIT_INACTIVE) {
43+
if (pcnt_unit_state[i] == PCNT_UNIT_INACTIVE) {
3844
pcnt_config.unit = (pcnt_unit_t)i;
39-
pcnt_state[i] = PCNT_UNIT_ACTIVE;
45+
pcnt_unit_state[i] = PCNT_UNIT_ACTIVE;
4046
break;
4147
} else if (i == 3) {
4248
return -1;
@@ -46,10 +52,6 @@ int peripherals_pcnt_init(pcnt_config_t pcnt_config) {
4652
// Initialize PCNT unit
4753
pcnt_unit_config(&pcnt_config);
4854

49-
// Configure and enable the input filter
50-
pcnt_set_filter_value(pcnt_config.unit, 100);
51-
pcnt_filter_enable(pcnt_config.unit);
52-
5355
// Initialize PCNT's counter
5456
pcnt_counter_pause(pcnt_config.unit);
5557
pcnt_counter_clear(pcnt_config.unit);
@@ -61,6 +63,6 @@ int peripherals_pcnt_init(pcnt_config_t pcnt_config) {
6163
}
6264

6365
void peripherals_pcnt_deinit(pcnt_unit_t* unit) {
64-
pcnt_state[*unit] = PCNT_UNIT_INACTIVE;
66+
pcnt_unit_state[*unit] = PCNT_UNIT_INACTIVE;
6567
*unit = PCNT_UNIT_MAX;
6668
}

ports/esp32s2/peripherals/pcnt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131

3232
extern int peripherals_pcnt_init(pcnt_config_t pcnt_config);
3333
extern void peripherals_pcnt_deinit(pcnt_unit_t* unit);
34+
extern void peripherals_pcnt_reset(void);
3435

3536
#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H

ports/esp32s2/supervisor/port.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "shared-bindings/rtc/__init__.h"
5050

5151
#include "peripherals/rmt.h"
52+
#include "peripherals/pcnt.h"
5253
#include "components/heap/include/esp_heap_caps.h"
5354
#include "components/soc/soc/esp32s2/include/soc/cache_memory.h"
5455

@@ -117,6 +118,10 @@ void reset_port(void) {
117118
uart_reset();
118119
#endif
119120

121+
#if defined(CIRCUITPY_COUNTIO) || defined(CIRCUITPY_ROTARYIO)
122+
peripherals_pcnt_reset();
123+
#endif
124+
120125
#if CIRCUITPY_RTC
121126
rtc_reset();
122127
#endif

0 commit comments

Comments
 (0)
0