pcnt reset on reload

This commit is contained in:
microDev 2020-11-12 16:30:30 +05:30
parent a47dea4922
commit ff41180237
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
3 changed files with 16 additions and 8 deletions

View File

@ -29,14 +29,20 @@
#define PCNT_UNIT_ACTIVE 1 #define PCNT_UNIT_ACTIVE 1
#define PCNT_UNIT_INACTIVE 0 #define PCNT_UNIT_INACTIVE 0
static uint8_t pcnt_state[4]; static uint8_t pcnt_unit_state[4];
void peripherals_pcnt_reset(void) {
for (uint8_t i = 0; i<=3; i++) {
pcnt_unit_state[i] = PCNT_UNIT_INACTIVE;
}
}
int peripherals_pcnt_init(pcnt_config_t pcnt_config) { int peripherals_pcnt_init(pcnt_config_t pcnt_config) {
// Look for available pcnt unit // Look for available pcnt unit
for (uint8_t i = 0; i<=3; i++) { for (uint8_t i = 0; i<=3; i++) {
if (pcnt_state[i] == PCNT_UNIT_INACTIVE) { if (pcnt_unit_state[i] == PCNT_UNIT_INACTIVE) {
pcnt_config.unit = (pcnt_unit_t)i; pcnt_config.unit = (pcnt_unit_t)i;
pcnt_state[i] = PCNT_UNIT_ACTIVE; pcnt_unit_state[i] = PCNT_UNIT_ACTIVE;
break; break;
} else if (i == 3) { } else if (i == 3) {
return -1; return -1;
@ -46,10 +52,6 @@ int peripherals_pcnt_init(pcnt_config_t pcnt_config) {
// Initialize PCNT unit // Initialize PCNT unit
pcnt_unit_config(&pcnt_config); pcnt_unit_config(&pcnt_config);
// Configure and enable the input filter
pcnt_set_filter_value(pcnt_config.unit, 100);
pcnt_filter_enable(pcnt_config.unit);
// Initialize PCNT's counter // Initialize PCNT's counter
pcnt_counter_pause(pcnt_config.unit); pcnt_counter_pause(pcnt_config.unit);
pcnt_counter_clear(pcnt_config.unit); pcnt_counter_clear(pcnt_config.unit);
@ -61,6 +63,6 @@ int peripherals_pcnt_init(pcnt_config_t pcnt_config) {
} }
void peripherals_pcnt_deinit(pcnt_unit_t* unit) { void peripherals_pcnt_deinit(pcnt_unit_t* unit) {
pcnt_state[*unit] = PCNT_UNIT_INACTIVE; pcnt_unit_state[*unit] = PCNT_UNIT_INACTIVE;
*unit = PCNT_UNIT_MAX; *unit = PCNT_UNIT_MAX;
} }

View File

@ -31,5 +31,6 @@
extern int peripherals_pcnt_init(pcnt_config_t pcnt_config); extern int peripherals_pcnt_init(pcnt_config_t pcnt_config);
extern void peripherals_pcnt_deinit(pcnt_unit_t* unit); extern void peripherals_pcnt_deinit(pcnt_unit_t* unit);
extern void peripherals_pcnt_reset(void);
#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H #endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H

View File

@ -49,6 +49,7 @@
#include "shared-bindings/rtc/__init__.h" #include "shared-bindings/rtc/__init__.h"
#include "peripherals/rmt.h" #include "peripherals/rmt.h"
#include "peripherals/pcnt.h"
#include "components/heap/include/esp_heap_caps.h" #include "components/heap/include/esp_heap_caps.h"
#include "components/soc/soc/esp32s2/include/soc/cache_memory.h" #include "components/soc/soc/esp32s2/include/soc/cache_memory.h"
@ -117,6 +118,10 @@ void reset_port(void) {
uart_reset(); uart_reset();
#endif #endif
#if defined(CIRCUITPY_COUNTIO) || defined(CIRCUITPY_ROTARYIO)
peripherals_pcnt_reset();
#endif
#if CIRCUITPY_RTC #if CIRCUITPY_RTC
rtc_reset(); rtc_reset();
#endif #endif