Skip to content

Commit b1609ab

Browse files
committed
Remove old pcnt, rmt and timer group drivers
The new ones handle resource tracking for us. They also do a better job running when the flash cache is disabled, which is the source of bugs when interacting with flash over USB. Fixes #6998 and fixes #8379
1 parent c6d195a commit b1609ab

34 files changed

+486
-911
lines changed

locale/circuitpython.pot

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,6 @@ msgstr ""
476476
msgid "All I2C peripherals are in use"
477477
msgstr ""
478478

479-
#: ports/espressif/common-hal/countio/Counter.c
480-
#: ports/espressif/common-hal/frequencyio/FrequencyIn.c
481-
#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c
482-
msgid "All PCNT units in use"
483-
msgstr ""
484-
485479
#: ports/atmel-samd/common-hal/canio/Listener.c
486480
#: ports/espressif/common-hal/canio/Listener.c
487481
#: ports/stm/common-hal/canio/Listener.c
@@ -529,10 +523,6 @@ msgstr ""
529523
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
530524
#: ports/atmel-samd/common-hal/pulseio/PulseOut.c
531525
#: ports/cxd56/common-hal/pulseio/PulseOut.c
532-
#: ports/espressif/common-hal/frequencyio/FrequencyIn.c
533-
#: ports/espressif/common-hal/neopixel_write/__init__.c
534-
#: ports/espressif/common-hal/pulseio/PulseIn.c
535-
#: ports/espressif/common-hal/pulseio/PulseOut.c
536526
#: ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
537527
#: ports/nrf/common-hal/pulseio/PulseIn.c ports/nrf/peripherals/nrf/timers.c
538528
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
@@ -735,7 +725,7 @@ msgstr ""
735725

736726
#: shared-bindings/storage/__init__.c shared-bindings/usb_cdc/__init__.c
737727
#: shared-bindings/usb_hid/__init__.c shared-bindings/usb_midi/__init__.c
738-
#: shared-bindings/uvc/__init__.c
728+
#: shared-bindings/usb_video/__init__.c
739729
msgid "Cannot change USB devices now"
740730
msgstr ""
741731

@@ -827,10 +817,6 @@ msgstr ""
827817
msgid "Coordinate arrays types have different sizes"
828818
msgstr ""
829819

830-
#: ports/espressif/common-hal/neopixel_write/__init__.c
831-
msgid "Could not retrieve clock"
832-
msgstr ""
833-
834820
#: shared-bindings/_bleio/Adapter.c
835821
msgid "Could not set address"
836822
msgstr ""
@@ -1134,7 +1120,7 @@ msgstr ""
11341120
msgid "Input taking too long"
11351121
msgstr ""
11361122

1137-
#: ports/espressif/common-hal/neopixel_write/__init__.c py/moderrno.c
1123+
#: py/moderrno.c
11381124
msgid "Input/output error"
11391125
msgstr ""
11401126

ports/espressif/Makefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ INC += \
7979
-isystem esp-idf/components/driver/deprecated \
8080
-isystem esp-idf/components/driver/dac/include \
8181
-isystem esp-idf/components/driver/gpio/include \
82+
-isystem esp-idf/components/driver/gptimer/include \
8283
-isystem esp-idf/components/driver/i2c/include \
8384
-isystem esp-idf/components/driver/i2s/include \
8485
-isystem esp-idf/components/driver/$(IDF_TARGET)/include \
8586
-isystem esp-idf/components/driver/ledc/include \
87+
-isystem esp-idf/components/driver/pcnt/include \
88+
-isystem esp-idf/components/driver/rmt/include \
8689
-isystem esp-idf/components/driver/spi/include \
8790
-isystem esp-idf/components/driver/temperature_sensor/include \
8891
-isystem esp-idf/components/driver/touch_sensor/include \
@@ -280,8 +283,6 @@ SRC_C += \
280283
boards/$(BOARD)/pins.c \
281284
shared/netutils/netutils.c \
282285
peripherals/i2c.c \
283-
peripherals/rmt.c \
284-
peripherals/timer.c \
285286
peripherals/$(IDF_TARGET)/pins.c
286287

287288
SRC_C += $(wildcard common-hal/espidf/*.c)
@@ -290,10 +291,6 @@ ifneq ($(CIRCUITPY_ESP_USB_SERIAL_JTAG),0)
290291
SRC_C += supervisor/usb_serial_jtag.c
291292
endif
292293

293-
ifneq ($(CIRCUITPY_COUNTIO),0)
294-
SRC_C += peripherals/pcnt.c
295-
endif
296-
297294
ifneq ($(CIRCUITPY_TOUCHIO_USE_NATIVE),0)
298295
SRC_C += peripherals/touch.c
299296
endif

ports/espressif/background.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,9 @@
3232
#include "freertos/FreeRTOS.h"
3333
#include "freertos/task.h"
3434

35-
#if CIRCUITPY_DISPLAYIO
36-
#include "shared-module/displayio/__init__.h"
37-
#endif
38-
39-
#if CIRCUITPY_PULSEIO
40-
#include "common-hal/pulseio/PulseIn.h"
41-
#endif
42-
4335
void port_background_tick(void) {
4436
// Zero delay in case FreeRTOS wants to switch to something else.
4537
vTaskDelay(0);
46-
#if CIRCUITPY_PULSEIO
47-
pulsein_background();
48-
#endif
4938
}
5039

5140
void port_background_task(void) {

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include "shared-bindings/countio/Counter.h"
2929
#include "common-hal/microcontroller/Pin.h"
3030

31+
#include "bindings/espidf/__init__.h"
32+
3133
#include "py/runtime.h"
3234

3335
#include "driver/gpio.h"
@@ -36,25 +38,26 @@ void common_hal_countio_counter_construct(countio_counter_obj_t *self,
3638
const mcu_pin_obj_t *pin, countio_edge_t edge, digitalio_pull_t pull) {
3739
claim_pin(pin);
3840

39-
// Prepare configuration for the PCNT unit
40-
pcnt_config_t pcnt_config = {
41-
// Set PCNT input signal and control GPIOs
42-
.pulse_gpio_num = pin->number,
43-
.ctrl_gpio_num = PCNT_PIN_NOT_USED,
44-
.channel = PCNT_CHANNEL_0,
45-
// What to do on the rising / falling edge of pulse input?
46-
// If EDGE_RISE_AND_FALL, both modeswill do PCNT_COUNT_INC.
47-
.pos_mode = (edge == EDGE_FALL) ? PCNT_COUNT_DIS : PCNT_COUNT_INC, // Count up unless only fall
48-
.neg_mode = (edge == EDGE_RISE) ? PCNT_COUNT_DIS : PCNT_COUNT_INC, // Count up unless only rise
41+
pcnt_unit_config_t unit_config = {
42+
// Set counter limit
43+
.low_limit = -1,
44+
.high_limit = INT16_MAX
4945
};
46+
// The pulse count driver automatically counts roll overs.
47+
unit_config.flags.accum_count = true;
5048

51-
// Initialize PCNT unit
52-
const int8_t unit = peripherals_pcnt_init(&pcnt_config);
53-
if (unit == -1) {
54-
mp_raise_RuntimeError(MP_ERROR_TEXT("All PCNT units in use"));
55-
}
49+
// initialize PCNT
50+
CHECK_ESP_RESULT(pcnt_new_unit(&unit_config, &self->unit));
5651

5752
self->pin = pin->number;
53+
pcnt_chan_config_t channel_config = {
54+
.edge_gpio_num = self->pin,
55+
.level_gpio_num = -1
56+
};
57+
CHECK_ESP_RESULT(pcnt_new_channel(self->unit, &channel_config, &self->channel));
58+
pcnt_channel_edge_action_t pos = (edge == EDGE_RISE || edge == EDGE_RISE_AND_FALL) ? PCNT_CHANNEL_EDGE_ACTION_INCREASE : PCNT_CHANNEL_EDGE_ACTION_HOLD;
59+
pcnt_channel_edge_action_t neg = (edge == EDGE_FALL || edge == EDGE_RISE_AND_FALL) ? PCNT_CHANNEL_EDGE_ACTION_INCREASE : PCNT_CHANNEL_EDGE_ACTION_HOLD;
60+
pcnt_channel_set_edge_action(self->channel, pos, neg);
5861

5962
gpio_pullup_dis(pin->number);
6063
gpio_pulldown_dis(pin->number);
@@ -64,29 +67,34 @@ void common_hal_countio_counter_construct(countio_counter_obj_t *self,
6467
gpio_pulldown_en(pin->number);
6568
}
6669

67-
self->unit = (pcnt_unit_t)unit;
70+
71+
pcnt_unit_enable(self->unit);
72+
pcnt_unit_start(self->unit);
6873
}
6974

7075
bool common_hal_countio_counter_deinited(countio_counter_obj_t *self) {
71-
return self->unit == PCNT_UNIT_MAX;
76+
return self->unit == NULL;
7277
}
7378

7479
void common_hal_countio_counter_deinit(countio_counter_obj_t *self) {
7580
if (common_hal_countio_counter_deinited(self)) {
7681
return;
7782
}
83+
pcnt_unit_disable(self->unit);
84+
pcnt_del_channel(self->channel);
7885
reset_pin_number(self->pin);
79-
peripherals_pcnt_deinit(&self->unit);
86+
pcnt_del_unit(self->unit);
87+
self->unit = NULL;
8088
}
8189

8290
mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t *self) {
83-
int16_t count;
84-
pcnt_get_counter_value(self->unit, &count);
91+
int count;
92+
pcnt_unit_get_count(self->unit, &count);
8593
return count + self->count;
8694
}
8795

8896
void common_hal_countio_counter_set_count(countio_counter_obj_t *self,
8997
mp_int_t new_count) {
9098
self->count = new_count;
91-
pcnt_counter_clear(self->unit);
99+
pcnt_unit_clear_count(self->unit);
92100
}

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COUNTIO_COUNTER_H
28-
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COUNTIO_COUNTER_H
27+
#pragma once
2928

3029
#include "py/obj.h"
31-
#include "peripherals/pcnt.h"
30+
#include "driver/pulse_cnt.h"
3231

3332
typedef struct {
3433
mp_obj_base_t base;
35-
uint8_t pin;
34+
pcnt_unit_handle_t unit;
35+
pcnt_channel_handle_t channel;
3636
mp_int_t count;
37-
pcnt_unit_t unit;
37+
uint8_t pin;
3838
} countio_counter_obj_t;
39-
40-
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COUNTIO_COUNT_H

0 commit comments

Comments
 (0)