From d8ef9a127b4914f7d9b50131c15e653aef94cb8f Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 5 Nov 2020 10:10:39 +0530 Subject: rename pcnt_handler to pcnt --- ports/esp32s2/Makefile | 2 +- ports/esp32s2/common-hal/countio/Counter.c | 5 ++- ports/esp32s2/common-hal/countio/Counter.h | 2 +- ports/esp32s2/peripherals/pcnt.c | 67 ++++++++++++++++++++++++++++++ ports/esp32s2/peripherals/pcnt.h | 35 ++++++++++++++++ ports/esp32s2/peripherals/pcnt_handler.c | 67 ------------------------------ ports/esp32s2/peripherals/pcnt_handler.h | 35 ---------------- 7 files changed, 107 insertions(+), 106 deletions(-) create mode 100644 ports/esp32s2/peripherals/pcnt.c create mode 100644 ports/esp32s2/peripherals/pcnt.h delete mode 100644 ports/esp32s2/peripherals/pcnt_handler.c delete mode 100644 ports/esp32s2/peripherals/pcnt_handler.h diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile index 56f0d46a3..55d6e91d4 100644 --- a/ports/esp32s2/Makefile +++ b/ports/esp32s2/Makefile @@ -188,7 +188,7 @@ SRC_C += \ lib/utils/pyexec.c \ lib/utils/stdout_helpers.c \ lib/utils/sys_stdio_mphal.c \ - peripherals/pcnt_handler.c \ + peripherals/pcnt.c \ peripherals/pins.c \ peripherals/rmt.c \ supervisor/shared/memory.c diff --git a/ports/esp32s2/common-hal/countio/Counter.c b/ports/esp32s2/common-hal/countio/Counter.c index 435762473..81f9f7ad2 100644 --- a/ports/esp32s2/common-hal/countio/Counter.c +++ b/ports/esp32s2/common-hal/countio/Counter.c @@ -42,7 +42,8 @@ void common_hal_countio_counter_construct(countio_counter_obj_t* self, .neg_mode = PCNT_COUNT_DIS, // Keep the counter value on the negative edge }; // Initialize PCNT unit - pcnt_handler_init(&pcnt_config); + // This also sets pcnt_config.unit + peripherals_pcnt_init(&pcnt_config); self->pin = pin->number; self->unit = pcnt_config.unit; @@ -57,7 +58,7 @@ void common_hal_countio_counter_deinit(countio_counter_obj_t* self) { return; } reset_pin_number(self->pin); - pcnt_handler_deinit(&self->unit); + peripherals_pcnt_deinit(&self->unit); } mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t* self) { diff --git a/ports/esp32s2/common-hal/countio/Counter.h b/ports/esp32s2/common-hal/countio/Counter.h index 63d1eb98b..20fe5b83e 100644 --- a/ports/esp32s2/common-hal/countio/Counter.h +++ b/ports/esp32s2/common-hal/countio/Counter.h @@ -28,7 +28,7 @@ #define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_COUNTIO_COUNTER_H #include "py/obj.h" -#include "pcnt_handler.h" +#include "peripherals/pcnt.h" typedef struct { mp_obj_base_t base; diff --git a/ports/esp32s2/peripherals/pcnt.c b/ports/esp32s2/peripherals/pcnt.c new file mode 100644 index 000000000..e7eb32c1d --- /dev/null +++ b/ports/esp32s2/peripherals/pcnt.c @@ -0,0 +1,67 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "peripherals/pcnt.h" + +#include "py/runtime.h" +#include "supervisor/shared/translate.h" + +#define PCNT_UNIT_ACTIVE 1 +#define PCNT_UNIT_INACTIVE 0 + +static uint8_t pcnt_state[4]; + +void peripherals_pcnt_init(pcnt_config_t* pcnt_config) { + // Look for available pcnt unit + for (uint8_t i = 0; i<=3; i++) { + if (pcnt_state[i] == PCNT_UNIT_INACTIVE) { + pcnt_config->unit = (pcnt_unit_t)i; + pcnt_state[i] = PCNT_UNIT_ACTIVE; + break; + } else if (i == 3) { + mp_raise_RuntimeError(translate("All PCNT units in use")); + } + } + + // Initialize PCNT unit + 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 + pcnt_counter_pause(pcnt_config->unit); + pcnt_counter_clear(pcnt_config->unit); + + // Everything is set up, now go to counting + pcnt_counter_resume(pcnt_config->unit); +} + +void peripherals_pcnt_deinit(pcnt_unit_t* unit) { + pcnt_state[*unit] = PCNT_UNIT_INACTIVE; + *unit = PCNT_UNIT_MAX; +} diff --git a/ports/esp32s2/peripherals/pcnt.h b/ports/esp32s2/peripherals/pcnt.h new file mode 100644 index 000000000..64072501c --- /dev/null +++ b/ports/esp32s2/peripherals/pcnt.h @@ -0,0 +1,35 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H +#define MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H + +#include "driver/pcnt.h" + +extern void peripherals_pcnt_init(pcnt_config_t* pcnt_config); +extern void peripherals_pcnt_deinit(pcnt_unit_t* unit); + +#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H diff --git a/ports/esp32s2/peripherals/pcnt_handler.c b/ports/esp32s2/peripherals/pcnt_handler.c deleted file mode 100644 index 5a0cc9a7c..000000000 --- a/ports/esp32s2/peripherals/pcnt_handler.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 microDev - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "pcnt_handler.h" - -#include "py/runtime.h" -#include "supervisor/shared/translate.h" - -#define PCNT_UNIT_ACTIVE 1 -#define PCNT_UNIT_INACTIVE 0 - -static uint8_t pcnt_state[4]; - -void pcnt_handler_init(pcnt_config_t* pcnt_config) { - // Look for available pcnt unit - for (uint8_t i = 0; i<=3; i++) { - if (pcnt_state[i] == PCNT_UNIT_INACTIVE) { - pcnt_config->unit = (pcnt_unit_t)i; - pcnt_state[i] = PCNT_UNIT_ACTIVE; - break; - } else if (i == 3) { - mp_raise_RuntimeError(translate("All PCNT units in use")); - } - } - - // Initialize PCNT unit - 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 - pcnt_counter_pause(pcnt_config->unit); - pcnt_counter_clear(pcnt_config->unit); - - // Everything is set up, now go to counting - pcnt_counter_resume(pcnt_config->unit); -} - -void pcnt_handler_deinit(pcnt_unit_t* unit) { - pcnt_state[*unit] = PCNT_UNIT_INACTIVE; - *unit = PCNT_UNIT_MAX; -} diff --git a/ports/esp32s2/peripherals/pcnt_handler.h b/ports/esp32s2/peripherals/pcnt_handler.h deleted file mode 100644 index f44ee1f83..000000000 --- a/ports/esp32s2/peripherals/pcnt_handler.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 microDev - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H -#define MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H - -#include "driver/pcnt.h" - -extern void pcnt_handler_init(pcnt_config_t* pcnt_config); -extern void pcnt_handler_deinit(pcnt_unit_t* unit); - -#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H -- cgit v1.2.3