Skip to content

Remove old pcnt, rmt and timer group drivers #8909

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

Merged
merged 3 commits into from
Feb 13, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/protomatter
18 changes: 2 additions & 16 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,6 @@ msgstr ""
msgid "All I2C peripherals are in use"
msgstr ""

#: ports/espressif/common-hal/countio/Counter.c
#: ports/espressif/common-hal/frequencyio/FrequencyIn.c
#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c
msgid "All PCNT units in use"
msgstr ""

#: ports/atmel-samd/common-hal/canio/Listener.c
#: ports/espressif/common-hal/canio/Listener.c
#: ports/stm/common-hal/canio/Listener.c
Expand Down Expand Up @@ -529,10 +523,6 @@ msgstr ""
#: ports/atmel-samd/common-hal/pulseio/PulseIn.c
#: ports/atmel-samd/common-hal/pulseio/PulseOut.c
#: ports/cxd56/common-hal/pulseio/PulseOut.c
#: ports/espressif/common-hal/frequencyio/FrequencyIn.c
#: ports/espressif/common-hal/neopixel_write/__init__.c
#: ports/espressif/common-hal/pulseio/PulseIn.c
#: ports/espressif/common-hal/pulseio/PulseOut.c
#: ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
#: ports/nrf/common-hal/pulseio/PulseIn.c ports/nrf/peripherals/nrf/timers.c
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
Expand Down Expand Up @@ -735,7 +725,7 @@ msgstr ""

#: shared-bindings/storage/__init__.c shared-bindings/usb_cdc/__init__.c
#: shared-bindings/usb_hid/__init__.c shared-bindings/usb_midi/__init__.c
#: shared-bindings/uvc/__init__.c
#: shared-bindings/usb_video/__init__.c
msgid "Cannot change USB devices now"
msgstr ""

Expand Down Expand Up @@ -827,10 +817,6 @@ msgstr ""
msgid "Coordinate arrays types have different sizes"
msgstr ""

#: ports/espressif/common-hal/neopixel_write/__init__.c
msgid "Could not retrieve clock"
msgstr ""

#: shared-bindings/_bleio/Adapter.c
msgid "Could not set address"
msgstr ""
Expand Down Expand Up @@ -1134,7 +1120,7 @@ msgstr ""
msgid "Input taking too long"
msgstr ""

#: ports/espressif/common-hal/neopixel_write/__init__.c py/moderrno.c
#: py/moderrno.c
msgid "Input/output error"
msgstr ""

Expand Down
9 changes: 3 additions & 6 deletions ports/espressif/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ INC += \
-isystem esp-idf/components/driver/deprecated \
-isystem esp-idf/components/driver/dac/include \
-isystem esp-idf/components/driver/gpio/include \
-isystem esp-idf/components/driver/gptimer/include \
-isystem esp-idf/components/driver/i2c/include \
-isystem esp-idf/components/driver/i2s/include \
-isystem esp-idf/components/driver/$(IDF_TARGET)/include \
-isystem esp-idf/components/driver/ledc/include \
-isystem esp-idf/components/driver/pcnt/include \
-isystem esp-idf/components/driver/rmt/include \
-isystem esp-idf/components/driver/spi/include \
-isystem esp-idf/components/driver/temperature_sensor/include \
-isystem esp-idf/components/driver/touch_sensor/include \
Expand Down Expand Up @@ -280,8 +283,6 @@ SRC_C += \
boards/$(BOARD)/pins.c \
shared/netutils/netutils.c \
peripherals/i2c.c \
peripherals/rmt.c \
peripherals/timer.c \
peripherals/$(IDF_TARGET)/pins.c

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

ifneq ($(CIRCUITPY_COUNTIO),0)
SRC_C += peripherals/pcnt.c
endif

ifneq ($(CIRCUITPY_TOUCHIO_USE_NATIVE),0)
SRC_C += peripherals/touch.c
endif
Expand Down
11 changes: 0 additions & 11 deletions ports/espressif/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,9 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#if CIRCUITPY_DISPLAYIO
#include "shared-module/displayio/__init__.h"
#endif

#if CIRCUITPY_PULSEIO
#include "common-hal/pulseio/PulseIn.h"
#endif

void port_background_tick(void) {
// Zero delay in case FreeRTOS wants to switch to something else.
vTaskDelay(0);
#if CIRCUITPY_PULSEIO
pulsein_background();
#endif
}

void port_background_task(void) {
Expand Down
2 changes: 2 additions & 0 deletions ports/espressif/boards/deneyap_kart_1a_v2/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CIRCUITPY_ESP_PSRAM_FREQ = 80m

CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_BLEIO = 0
CIRCUITPY_CODEOP=0
CIRCUITPY_PARALLELDISPLAYBUS = 0

OPTIMIZATION_FLAGS = -Os
1 change: 1 addition & 0 deletions ports/espressif/boards/lolin_s3_mini/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CIRCUITPY_ESP_PSRAM_FREQ = 80m
OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_BLEIO = 0
CIRCUITPY_CODEOP=0
CIRCUITPY_PARALLELDISPLAYBUS = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CIRCUITPY_ESP_PSRAM_FREQ = 80m
OPTIMIZATION_FLAGS = -Os
CIRCUITPY_ESPCAMERA = 0
CIRCUITPY_BITMAPFILTER = 0
CIRCUITPY_BLEIO = 0
CIRCUITPY_CODEOP=0
CIRCUITPY_PARALLELDISPLAYBUS = 0

# Include these Python libraries in firmware.
Expand Down
12 changes: 10 additions & 2 deletions ports/espressif/common-hal/audiobusio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ void port_i2s_allocate_init(i2s_t *self, bool left_justified) {
if (err == ESP_ERR_NOT_FOUND) {
mp_raise_RuntimeError(MP_ERROR_TEXT("Peripheral in use"));
}
self->playing = false;
self->paused = false;
self->stopping = false;

i2s_event_callbacks_t callbacks = {
.on_recv = NULL,
Expand All @@ -157,6 +160,8 @@ void port_i2s_deinit(i2s_t *self) {
}

void port_i2s_play(i2s_t *self, mp_obj_t sample, bool loop) {
// Pause to disable the I2S channel so we can adjust the clock.
port_i2s_pause(self);
self->sample = sample;
self->loop = loop;
self->bytes_per_sample = audiosample_bits_per_sample(sample) / 8;
Expand Down Expand Up @@ -204,6 +209,9 @@ void port_i2s_play(i2s_t *self, mp_obj_t sample, bool loop) {
}

bool port_i2s_playing(i2s_t *self) {
// TODO: Reason about stopping. This check leads to cases where the DMA is
// "playing" but the common-hal thinks it isn't and skips pausing. Probably
// best to move this functionality into I2SOut directly.
return self->playing && !self->stopping;
}

Expand All @@ -219,14 +227,14 @@ void port_i2s_stop(i2s_t *self) {
}

void port_i2s_pause(i2s_t *self) {
if (!self->paused) {
if (self->playing && !self->paused) {
self->paused = true;
CHECK_ESP_RESULT(i2s_channel_disable(self->handle));
}
}

void port_i2s_resume(i2s_t *self) {
if (self->paused) {
if (self->playing && self->paused) {
self->paused = false;
CHECK_ESP_RESULT(i2s_channel_enable(self->handle));
}
Expand Down
4 changes: 2 additions & 2 deletions ports/espressif/common-hal/audiobusio/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ typedef struct {
mp_obj_t *sample;
bool left_justified;
bool loop;
bool paused;
bool playing;
bool paused; // True when the I2S channel is configured but disabled.
bool playing; // True when the I2S channel is configured.
bool stopping;
bool samples_signed;
int8_t bytes_per_sample;
Expand Down
50 changes: 29 additions & 21 deletions ports/espressif/common-hal/countio/Counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "shared-bindings/countio/Counter.h"
#include "common-hal/microcontroller/Pin.h"

#include "bindings/espidf/__init__.h"

#include "py/runtime.h"

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

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

// Initialize PCNT unit
const int8_t unit = peripherals_pcnt_init(&pcnt_config);
if (unit == -1) {
mp_raise_RuntimeError(MP_ERROR_TEXT("All PCNT units in use"));
}
// initialize PCNT
CHECK_ESP_RESULT(pcnt_new_unit(&unit_config, &self->unit));

self->pin = pin->number;
pcnt_chan_config_t channel_config = {
.edge_gpio_num = self->pin,
.level_gpio_num = -1
};
CHECK_ESP_RESULT(pcnt_new_channel(self->unit, &channel_config, &self->channel));
pcnt_channel_edge_action_t pos = (edge == EDGE_RISE || edge == EDGE_RISE_AND_FALL) ? PCNT_CHANNEL_EDGE_ACTION_INCREASE : PCNT_CHANNEL_EDGE_ACTION_HOLD;
pcnt_channel_edge_action_t neg = (edge == EDGE_FALL || edge == EDGE_RISE_AND_FALL) ? PCNT_CHANNEL_EDGE_ACTION_INCREASE : PCNT_CHANNEL_EDGE_ACTION_HOLD;
pcnt_channel_set_edge_action(self->channel, pos, neg);

gpio_pullup_dis(pin->number);
gpio_pulldown_dis(pin->number);
Expand All @@ -64,29 +67,34 @@ void common_hal_countio_counter_construct(countio_counter_obj_t *self,
gpio_pulldown_en(pin->number);
}

self->unit = (pcnt_unit_t)unit;

pcnt_unit_enable(self->unit);
pcnt_unit_start(self->unit);
}

bool common_hal_countio_counter_deinited(countio_counter_obj_t *self) {
return self->unit == PCNT_UNIT_MAX;
return self->unit == NULL;
}

void common_hal_countio_counter_deinit(countio_counter_obj_t *self) {
if (common_hal_countio_counter_deinited(self)) {
return;
}
pcnt_unit_disable(self->unit);
pcnt_del_channel(self->channel);
reset_pin_number(self->pin);
peripherals_pcnt_deinit(&self->unit);
pcnt_del_unit(self->unit);
self->unit = NULL;
}

mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t *self) {
int16_t count;
pcnt_get_counter_value(self->unit, &count);
int count;
pcnt_unit_get_count(self->unit, &count);
return count + self->count;
}

void common_hal_countio_counter_set_count(countio_counter_obj_t *self,
mp_int_t new_count) {
self->count = new_count;
pcnt_counter_clear(self->unit);
pcnt_unit_clear_count(self->unit);
}
12 changes: 5 additions & 7 deletions ports/espressif/common-hal/countio/Counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@
* THE SOFTWARE.
*/

#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COUNTIO_COUNTER_H
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COUNTIO_COUNTER_H
#pragma once

#include "py/obj.h"
#include "peripherals/pcnt.h"
#include "driver/pulse_cnt.h"

typedef struct {
mp_obj_base_t base;
uint8_t pin;
pcnt_unit_handle_t unit;
pcnt_channel_handle_t channel;
mp_int_t count;
pcnt_unit_t unit;
uint8_t pin;
} countio_counter_obj_t;

#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_COUNTIO_COUNT_H
Loading