From 5ccf4731e04c1ecf4008228ef6083829f4f3345d Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Wed, 14 Aug 2024 14:29:27 -0700 Subject: [PATCH 001/252] Initial commit for ADI MAX32690 support. Still many modules to implement/unstub, but builds clean. --- .gitmodules | 3 + ports/analog/Makefile | 261 +++++++++++ ports/analog/README.md | 52 +++ ports/analog/background.c | 28 ++ ports/analog/background.h | 10 + ports/analog/boards/APARD/README.md | 14 + ports/analog/boards/APARD/board.c | 9 + ports/analog/boards/APARD/mpconfigboard.h | 31 ++ ports/analog/boards/APARD/mpconfigboard.mk | 18 + ports/analog/boards/APARD/pins.c | 125 ++++++ ports/analog/common-hal/board/__init__.c | 5 + ports/analog/common-hal/microcontroller/Pin.c | 34 ++ ports/analog/common-hal/microcontroller/Pin.h | 14 + .../common-hal/microcontroller/Processor.c | 36 ++ .../common-hal/microcontroller/Processor.h | 16 + .../common-hal/microcontroller/__init__.c | 410 ++++++++++++++++++ ports/analog/common-hal/os/__init__.c | 50 +++ ports/analog/linking/max32690_cktpy.ld | 160 +++++++ ports/analog/mpconfigport.h | 36 ++ ports/analog/mpconfigport.mk | 85 ++++ ports/analog/mphalport.c | 15 + ports/analog/mphalport.h | 22 + ports/analog/msdk | 1 + ports/analog/peripherals/max32690/pins.c | 119 +++++ ports/analog/peripherals/max32690/pins.h | 114 +++++ ports/analog/peripherals/pins.h | 34 ++ ports/analog/qstrdefsport.h | 10 + ports/analog/supervisor/cpu.s | 27 ++ ports/analog/supervisor/internal_flash.c | 289 ++++++++++++ ports/analog/supervisor/internal_flash.h | 16 + ports/analog/supervisor/port.c | 167 +++++++ ports/analog/supervisor/serial.c | 61 +++ tools/ci_fetch_deps.py | 6 + 33 files changed, 2278 insertions(+) create mode 100644 ports/analog/Makefile create mode 100644 ports/analog/README.md create mode 100644 ports/analog/background.c create mode 100644 ports/analog/background.h create mode 100644 ports/analog/boards/APARD/README.md create mode 100644 ports/analog/boards/APARD/board.c create mode 100644 ports/analog/boards/APARD/mpconfigboard.h create mode 100644 ports/analog/boards/APARD/mpconfigboard.mk create mode 100644 ports/analog/boards/APARD/pins.c create mode 100644 ports/analog/common-hal/board/__init__.c create mode 100644 ports/analog/common-hal/microcontroller/Pin.c create mode 100644 ports/analog/common-hal/microcontroller/Pin.h create mode 100644 ports/analog/common-hal/microcontroller/Processor.c create mode 100644 ports/analog/common-hal/microcontroller/Processor.h create mode 100644 ports/analog/common-hal/microcontroller/__init__.c create mode 100644 ports/analog/common-hal/os/__init__.c create mode 100644 ports/analog/linking/max32690_cktpy.ld create mode 100644 ports/analog/mpconfigport.h create mode 100644 ports/analog/mpconfigport.mk create mode 100644 ports/analog/mphalport.c create mode 100644 ports/analog/mphalport.h create mode 160000 ports/analog/msdk create mode 100644 ports/analog/peripherals/max32690/pins.c create mode 100644 ports/analog/peripherals/max32690/pins.h create mode 100644 ports/analog/peripherals/pins.h create mode 100644 ports/analog/qstrdefsport.h create mode 100644 ports/analog/supervisor/cpu.s create mode 100644 ports/analog/supervisor/internal_flash.c create mode 100644 ports/analog/supervisor/internal_flash.h create mode 100644 ports/analog/supervisor/port.c create mode 100644 ports/analog/supervisor/serial.c diff --git a/.gitmodules b/.gitmodules index 9382a1a6ffbf..600c7d8a32a4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -407,3 +407,6 @@ [submodule "frozen/Adafruit_CircuitPython_Wiznet5k"] path = frozen/Adafruit_CircuitPython_Wiznet5k url = https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k +[submodule "ports/analog/msdk"] + path = ports/analog/msdk + url = https://github.com/analogdevicesinc/msdk.git diff --git a/ports/analog/Makefile b/ports/analog/Makefile new file mode 100644 index 000000000000..b348a57d237f --- /dev/null +++ b/ports/analog/Makefile @@ -0,0 +1,261 @@ +# This file is part of the CircuitPython project: https://circuitpython.org +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# Includes mpconfigboard.mk & mpconfigport.mk, +# along with numerous other shared environment makefiles. +include ../../py/circuitpy_mkenv.mk + +CROSS_COMPILE = arm-none-eabi- + +# MCU_SERIES e.g. "max32" +# MCU_VARIANT e.g. "max32690" +# defined in mpconfigboard.mk +MCU_SERIES_LOWER := $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]') +MCU_SERIES_UPPER := $(shell echo $(MCU_SERIES) | tr '[:lower:]' '[:upper:]') +MCU_VARIANT_LOWER := $(shell echo $(MCU_VARIANT) | tr '[:upper:]' '[:lower:]') +MCU_VARIANT_UPPER := $(shell echo $(MCU_VARIANT) | tr '[:lower:]' '[:upper:]') + +# ******************************************************************************* +#### MSDK INCLUDES #### +# Necessary for msdk makefiles +TARGET := $(MCU_VARIANT_UPPER) +TARGET_UC := $(MCU_VARIANT_UPPER) +TARGET_LC := $(MCU_VARIANT_LOWER) + +MSDK_ROOT = ./msdk +MSDK_LIBS = $(MSDK_ROOT)/Libraries +CMSIS_ROOT = $(MSDK_LIBS)/CMSIS +ADI_PERIPH = $(MSDK_ROOT)/Libraries/PeriphDrivers +ADI_MISC_DRIVERS_DIR ?= $(MSDK_LIBS)/MiscDrivers +ADI_BOARD_DIR = $(MSDK_LIBS)/Boards/$(MCU_VARIANT_UPPER)/$(BOARD) + +# For debugging the build +ifneq ($(BUILD_VERBOSE),"") +$(info MSDK_ROOT is $(MSDK_ROOT)) +$(info MSDK_LIBS is $(MSDK_LIBS)) +$(info CMSIS_ROOT is $(CMSIS_ROOT)) +$(info ADI_PERIPH is $(ADI_PERIPH)) +$(info ADI_MISC_DRIVERS_DIR is $(ADI_MISC_DRIVERS_DIR)) +$(info ADI_BOARD_DIR is $(ADI_BOARD_DIR)) +$(info MAXIM_PATH is $(MAXIM_PATH)) +endif + +# ----------------- +# Sources & Include +# ----------------- +# Define max32 die type for PeriphDriver Includes +# default to me18 for max32690 +# more info: +# https://analogdevicesinc.github.io/msdk//USERGUIDE/#die-types-to-part-numbers +ifeq ($(MCU_VARIANT_LOWER), "max32690") +DIE_TYPE=me18 +else +DIE_TYPE=me18 +endif + +PERIPH_SRC = $(ADI_PERIPH)/Source + +INC += -I. +INC += -I../.. +INC += -I$(BUILD) +INC += -I$(BUILD)/genhdr +INC += -I./../../lib/cmsis/inc +INC += -I./boards/ +INC += -I./boards/$(BOARD) +INC += -I./peripherals/ +INC += -I../../lib/mp-readline + +INC += \ + -I$(TOP)/$(BOARD_PATH) \ + -I$(TOP)/lib/cmsis/inc \ + -I$(CMSIS_ROOT)/Include \ + -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Include \ + -I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \ + -I$(PERIPH_SRC)/SYS \ + -I$(PERIPH_SRC)/GPIO \ + -I$(PERIPH_SRC)/CTB \ + -I$(PERIPH_SRC)/ICC \ + -I$(PERIPH_SRC)/FLC \ + -I$(PERIPH_SRC)/UART \ + +INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC + +SRC_MAX32 += \ + $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/heap.c \ + $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/system_$(MCU_VARIANT_LOWER).c \ + $(PERIPH_SRC)/SYS/mxc_assert.c \ + $(PERIPH_SRC)/SYS/mxc_delay.c \ + $(PERIPH_SRC)/SYS/mxc_lock.c \ + $(PERIPH_SRC)/SYS/nvic_table.c \ + $(PERIPH_SRC)/SYS/pins_$(DIE_TYPE).c \ + $(PERIPH_SRC)/SYS/sys_$(DIE_TYPE).c \ + $(PERIPH_SRC)/CTB/ctb_$(DIE_TYPE).c \ + $(PERIPH_SRC)/CTB/ctb_reva.c \ + $(PERIPH_SRC)/CTB/ctb_common.c \ + $(PERIPH_SRC)/FLC/flc_common.c \ + $(PERIPH_SRC)/FLC/flc_$(DIE_TYPE).c \ + $(PERIPH_SRC)/FLC/flc_reva.c \ + $(PERIPH_SRC)/GPIO/gpio_common.c \ + $(PERIPH_SRC)/GPIO/gpio_$(DIE_TYPE).c \ + $(PERIPH_SRC)/GPIO/gpio_reva.c \ + $(PERIPH_SRC)/ICC/icc_$(DIE_TYPE).c \ + $(PERIPH_SRC)/ICC/icc_reva.c \ + $(PERIPH_SRC)/UART/uart_common.c \ + $(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \ + $(PERIPH_SRC)/UART/uart_revb.c \ + +SRC_C += $(SRC_MAX32) \ + boards/$(BOARD)/board.c \ + boards/$(BOARD)/pins.c \ + peripherals/$(MCU_VARIANT_LOWER)/pins.c \ + +# ******************************************************************************* +### Compiler & Linker Flags ### +COMPILER ?= GCC + +ifeq ($(COMPILER), GCC) + +STARTUPFILE = $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC/startup_$(MCU_VARIANT_LOWER).s +# STARTUPFILE = $(ADI_BOARD_DIR)/Source/startup_$(MCU_VARIANT_LOWER).s + +# CircuitPython custom linkerfile (necessary for build steps & filesystems) +LINKERFILE = linking/$(MCU_VARIANT_LOWER)_cktpy.ld +LDFLAGS += -nostartfiles -specs=nosys.specs -specs=nano.specs +endif + +SRC_S += supervisor/cpu.s \ + $(STARTUPFILE) + +# Needed to compile some MAX32 headers +CFLAGS += -D$(MCU_VARIANT_UPPER) \ + -DTARGET_REV=0x4131 \ + -DTARGET=$(MCU_VARIANT_UPPER) \ + -DIAR_PRAGMAS=0 \ + # -DFLASH_ORIGIN=0x10000000 \ + # -DFLASH_SIZE=0x340000 \ + # -DSRAM_ORIGIN=0x20000000 \ + # -DSRAM_SIZE=0x100000 \ + +CPU_CORE=cortex-m4 +CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=hard -mfpu=fpv4-sp-d16 + +# NOTE: Start with DEBUG ONLY settings for now +ifeq ($(DEBUG),) +DEBUG ?= 1 +endif + +ifeq ($(DEBUG),1) +CFLAGS += -ggdb3 +COPT = -Og +else +COPT += -O2 +endif + + +# TinyUSB CFLAGS +CFLAGS += \ + -DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \ + -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \ + +# TODO: Add for TinyUSB once our PR goes through for MAX32 devices +# Add TinyUSB +# INC += -I../../lib/tinyusb/src +# INC += -I../../supervisor/shared/usb +# SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c + +SRC_C += \ + boards/$(BOARD)/board.c \ + background.c \ + mphalport.c \ + +CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostartfiles $(BASE_CFLAGS) $(COPT) + +# Suppress some warnings for MSDK +CFLAGS += -Wno-error=unused-parameter \ + -Wno-error=old-style-declaration \ + -Wno-error=sign-compare \ + -Wno-error=strict-prototypes \ + -Wno-error=cast-qual \ + -Wno-unused-variable \ + -Wno-lto-type-mismatch \ + -Wno-cast-align \ + -Wno-nested-externs \ + -Wno-sign-compare + +LDFLAGS += $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections +LIBS := -lgcc -lc + +# If not using CKTPY mathlib, use toolchain mathlib +ifndef INTERNAL_LIBM +LIBS += -lm +endif + +# ******************************************************************************* +### PORT-DEFINED BUILD RULES ### +# This section attempts to build the Python core, the supervisor, and any +# port-provided source code. +# +# QSTR sources are provided for the initial build step, which generates +# Python constants to represent C data which gets passed into the GC. + +SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ + $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ + $(addprefix common-hal/, $(SRC_COMMON_HAL)) + +SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) + +# There are duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED, +# because a few modules have files both in common-hal/ and shared-module/. +# Doing a $(sort ...) removes duplicates as part of sorting. +SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)) + +# OBJ includes +OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o)) +ifeq ($(INTERNAL_LIBM),1) +OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o)) +endif +OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) + +# List of sources for qstr extraction +SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_CIRCUITPY_COMMON) \ + $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED) $(SRC_MOD) +# Sources that only hold QSTRs after pre-processing. +SRC_QSTR_PREPROCESSOR += + +# Default build target +all: $(BUILD)/firmware.elf + +clean-max32: + rm -rf build-* + +# Optional flash option when running within an installed MSDK to use OpenOCD +# Mainline OpenOCD does not yet have the MAX32's flash algorithm integrated. +# If the MSDK is installed, flash-msdk can be run to utilize the the modified +# openocd with the algorithms +MAXIM_PATH := $(subst \,/,$(MAXIM_PATH)) +flash-msdk: + $(MAXIM_PATH)/Tools/OpenOCD/openocd -s $(MAXIM_PATH)/Tools/OpenOCD/scripts \ + -f interface/cmsis-dap.cfg -f target/$(MCU_VARIANT_LOWER).cfg \ + -c "program $(BUILD)/$(PROJECT).elf verify; init; reset; exit" + +# flash target using JLink +JLINK_DEVICE = $(MCU_VARIANT_LOWER) +flash: flash-jlink + +$(BUILD)/firmware.elf: $(OBJ) $(LINKERFILE) + $(STEPECHO) "LINK $@" + $(Q)echo $(OBJ) > $(BUILD)/firmware.objs + $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--print-memory-usage -Wl,--start-group $(LIBS) -Wl,--end-group + $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINKERFILE) $(BUILD) + +# ******************************************************************************* +### CKTPY BUILD RULES ### +include $(TOP)/py/mkrules.mk diff --git a/ports/analog/README.md b/ports/analog/README.md new file mode 100644 index 000000000000..0e5d3f7d2951 --- /dev/null +++ b/ports/analog/README.md @@ -0,0 +1,52 @@ +# Analog Devices "MAX32" MCUs + +This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. These devices are mostly ARM Cortex-M4-based and focus on delivering performance at low-power levels. Currently this port only supports MAX32690. + +### Structure of this port + +- **`boards/:`** Board-specific definitions including pins, board initialization, etc. +- **`common-hal/:`** Port-specific implementations of CircuitPython common-hal APIs. When a new module is enabled, this is often where the implementation is found. Expected functions for modules in `common-hal` are usually found in `shared-bindings/` or `shared-module/` in the CircuitPy root directory. +- **`linking/:`** Linkerfiles customized for CircuitPython. These are distinct from the linkerfiles used in MSDK as they adopt the structure required by CircuitPython. They may also omit unused features and memory sections, e.g. Mailboxes, RISC-V Flash, & Hyperbus RAM for MAX32690. +- **`msdk:/`** SDK for MAX32 devices. More info on our GitHub: [Analog Devices MSDK GitHub](https://github.com/analogdevicesinc/msdk) +- **`peripherals:/`** Helper files for peripherals such as clocks, gpio, etc. These files tend to be specific to vendor SDKs and provide some useful functions for the common-hal interfaces. +- **`supervisor/:`** Implementation files for the CircuitPython supervisor. This includes port setup, usb, and a filesystem on a storage medium such as SD Card/eMMC, QSPI Flash, or internal flash memory. Currently the internal flash is used. + +- `. :` Build system and high-level interface to the CircuitPython core for the ADI port. + +### Building for MAX32 devices + +Ensure CircuitPython dependencies are up-to-date by following the CircuitPython introduction on Adafruit's Website: [Building CircuitPython - Introduction](https://learn.adafruit.com/building-circuitpython/introduction). In particular, it is necessary to fetch all submodules (including the ARM Toolchain inside MSDK) and build the `mpy-cross` compiler. + +Ensure the MSDK's ARM toolchain is contained on your PATH. This can be done in MinGW or WSL by exporting a prefix to the PATH variable: + + $ export MSDK_GNU_PATH=/ports/analog/msdk/Tools/GNUTools/10.3/bin + $ export PATH=$MSDK_GNU_PATH:$PATH + +This needs to be done each time you open a command environment to build CircuitPython. + +Once you have built `mpy-cross` and set up your build system for CircuitPython, you can build for MAX32 devices using the following commands: + + $ cd ports/analog + $ make BOARD= + +Be aware the build may take a long time without parallelizing via the `-jN` flag, where N is the # of cores on your machine. + +### Flashing the board + +Universal instructions on flashing MAX32 devices this project can be found in the **[MSDK User Guide](https://analogdevicesinc.github.io/msdk/USERGUIDE/)**. + +In addition, a user may flash the device by calling `make` with the `flash-msdk` target from within the `ports/analog` directory, as below: + + $ make BOARD= flash-msdk + +This requires the following: +- A MAX32625PICO is connected to the PC via USB +- The PICO board shows up as a "DAPLINK" drive which implements the CMSIS-DAP interface. +- The PICO board is connected to the target board via a 10-pin SWD ribbon cable. + - If SWD connectors are not keyed, the P1 indicator (red line) on the SWD ribbon cable should match the P1 indicator on the board silkscreen near the 10-pin SWD connector. + +[**Section in Progress.**] + +### Using the REPL + +[**Section in Progress. Review & Testing are needed.**] diff --git a/ports/analog/background.c b/ports/analog/background.c new file mode 100644 index 000000000000..ccf71bf77bf5 --- /dev/null +++ b/ports/analog/background.c @@ -0,0 +1,28 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "py/runtime.h" +#include "supervisor/filesystem.h" +#include "supervisor/usb.h" +#include "supervisor/shared/stack.h" + +//TODO: IMPLEMENT + +void port_background_task(void) { + return; +} + +void port_background_tick(void) { + return; +} + +void port_start_background_tick(void) { + return; +} + +void port_finish_background_tick(void) { + return; +} diff --git a/ports/analog/background.h b/ports/analog/background.h new file mode 100644 index 000000000000..8fbe98bd9d8e --- /dev/null +++ b/ports/analog/background.h @@ -0,0 +1,10 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#ifndef MICROPY_INCLUDED_BACKGROUND_H +#define MICROPY_INCLUDED_BACKGROUND_H + +#endif // MICROPY_INCLUDED_BACKGROUND_H diff --git a/ports/analog/boards/APARD/README.md b/ports/analog/boards/APARD/README.md new file mode 100644 index 000000000000..8768ed93d56d --- /dev/null +++ b/ports/analog/boards/APARD/README.md @@ -0,0 +1,14 @@ +# AD-APARD32690-SL + +This board features the MAX32690, a dual-core ARM Cortex-M4/RISC-V MCU with 3MiB Flash, 1MiB SRAM. The board also has support for 10BASE-T1L Ethernet, Wifi, Bluetooth, USB, and Security via MAXQ1065. However, most of these features are not yet available for this CircuitPython port (USB will be added soon; others are currently unplanned). + +### Onboard connectors & peripherals + +This board comes in a form-factor similar to an Arduino Mega, enabling Arduino-style shield boards to be plugged in and evaluated with the MAX32690. This vastly opens up the options for easily plugging peripherals into the board, especially when combined with the two Pmod:tm: connectors, P8 (SPI) and P13 (I2C). + +### Product Resources + +For more info about AD-APARD32690-SL, visit our product webpages for datasheets, User Guides, Software, and Design Documents: + +[AD-APARD32690-SL Product Webpage](https://www.analog.com/en/resources/evaluation-hardware-and-software/evaluation-boards-kits/ad-apard32690-sl.html) +[AD-APARD32690-SL User Guide](https://wiki.analog.com/resources/eval/user-guides/ad-apard32690-sl) diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c new file mode 100644 index 000000000000..b44a1ae51e04 --- /dev/null +++ b/ports/analog/boards/APARD/board.c @@ -0,0 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/APARD/mpconfigboard.h new file mode 100644 index 000000000000..b22c7ab9ecc6 --- /dev/null +++ b/ports/analog/boards/APARD/mpconfigboard.h @@ -0,0 +1,31 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2016 Glenn Ruben Bakke +// SPDX-FileCopyrightText: Copyright (c) 2018 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define MICROPY_HW_BOARD_NAME "APARD32690" +#define MICROPY_HW_MCU_NAME "max32690" + +#define FLASH_SIZE (0x300000) // 3MiB +#define FLASH_PAGE_SIZE (0x4000) // 16384 byte pages (16 KiB) + +#define BOARD_HAS_CRYSTAL 1 + +// todo: figure out a way to smartly set this up based on storage considerations +#if INTERNAL_FLASH_FILESYSTEM +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x10032000) // for MAX32690 +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64 * 1024) // 64K +#else +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) +#endif diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk new file mode 100644 index 000000000000..7e5465e69422 --- /dev/null +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -0,0 +1,18 @@ +# This file is part of the CircuitPython project: https://circuitpython.org +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +INTERNAL_FLASH_FILESYSTEM = 1 +# FLASH: 0x10000000 to 0x10340000 +# SRAM: 0x20000000 to 0x20100000 + +USB_PRODUCT = "MAX32690 APARD" +USB_MANUFACTURER = "Analog Devices, Inc." +# CFLAGS+=-DEXT_FLASH_MX25 + +MCU_SERIES=max32 +MCU_VARIANT=max32690 + +CFLAGS += -DHAS_TRNG=1 diff --git a/ports/analog/boards/APARD/pins.c b/ports/analog/boards/APARD/pins.c new file mode 100644 index 000000000000..ddd2afdafe58 --- /dev/null +++ b/ports/analog/boards/APARD/pins.c @@ -0,0 +1,125 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + //P0 + { MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_P0_16) }, + { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_P0_17) }, + { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_P0_18) }, + { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_P0_19) }, + { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_P0_20) }, + { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_P0_21) }, + { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_P0_22) }, + { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_P0_23) }, + { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_P0_24) }, + { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_P0_25) }, + { MP_ROM_QSTR(MP_QSTR_PA26), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_P0_27) }, + { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_PA29), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_P0_31) }, + //P1 + { MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_P1_11) }, + { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_P1_12) }, + { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_P1_13) }, + { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_P1_14) }, + { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_P1_16) }, + { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_P1_17) }, + { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_P1_18) }, + { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_P1_19) }, + { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_P1_20) }, + { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_P1_21) }, + { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_P1_22) }, + { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_P1_23) }, + { MP_ROM_QSTR(MP_QSTR_PB24), MP_ROM_PTR(&pin_P1_24) }, + { MP_ROM_QSTR(MP_QSTR_PB25), MP_ROM_PTR(&pin_P1_25) }, + { MP_ROM_QSTR(MP_QSTR_PB26), MP_ROM_PTR(&pin_P1_26) }, + { MP_ROM_QSTR(MP_QSTR_PB27), MP_ROM_PTR(&pin_P1_27) }, + { MP_ROM_QSTR(MP_QSTR_PB28), MP_ROM_PTR(&pin_P1_28) }, + { MP_ROM_QSTR(MP_QSTR_PB29), MP_ROM_PTR(&pin_P1_29) }, + { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_P1_30) }, + { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_P1_31) }, + //P2 + { MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_PC09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_P2_10) }, + { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_P2_11) }, + { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_P2_12) }, + { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_P2_13) }, + { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_P2_14) }, + { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_P2_15) }, + { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_P2_16) }, + { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_P2_17) }, + { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_P2_18) }, + { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_P2_19) }, + { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_P2_20) }, + { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_P2_21) }, + { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_P2_22) }, + { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_P2_23) }, + { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_P2_24) }, + { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_P2_25) }, + { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_P2_26) }, + { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_P2_27) }, + { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_P2_28) }, + { MP_ROM_QSTR(MP_QSTR_PC29), MP_ROM_PTR(&pin_P2_29) }, + { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_P2_30) }, + { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_P2_31) }, + //P3 + { MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_P3_09) }, + //P4 + { MP_ROM_QSTR(MP_QSTR_PE00), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_PE01), MP_ROM_PTR(&pin_P4_01) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/analog/common-hal/board/__init__.c b/ports/analog/common-hal/board/__init__.c new file mode 100644 index 000000000000..bcae8371c18c --- /dev/null +++ b/ports/analog/common-hal/board/__init__.c @@ -0,0 +1,5 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2018 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c new file mode 100644 index 000000000000..bc1ef9d70efc --- /dev/null +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -0,0 +1,34 @@ + +#include + +#include "shared-bindings/microcontroller/Pin.h" +// #include "shared-bindings/digitalio/DigitalInOut.h" + + +// #include "gpio.h" + + +//FIXME: Implement +void reset_all_pins(void) { + return; +} + +// FIXME: Implement +void reset_pin_number(uint8_t pin) { + return; +} + +// FIXME: Implement +void claim_pin(const mcu_pin_obj_t *pin) { + return; +} + +// FIXME: Implement +bool pin_number_is_free(uint8_t pin_number) { + return true; +} + +// FIXME: Implement +void never_reset_pin_number(uint8_t pin_number) { + return; +} diff --git a/ports/analog/common-hal/microcontroller/Pin.h b/ports/analog/common-hal/microcontroller/Pin.h new file mode 100644 index 000000000000..6089a94e0c11 --- /dev/null +++ b/ports/analog/common-hal/microcontroller/Pin.h @@ -0,0 +1,14 @@ + +#pragma once + +#include "py/mphal.h" + +#include "peripherals/pins.h" + +void reset_all_pins(void); +// reset_pin_number takes the pin number instead of the pointer so that objects don't +// need to store a full pointer. +void reset_pin_number(uint8_t pin); +void claim_pin(const mcu_pin_obj_t *pin); +bool pin_number_is_free(uint8_t pin_number); +void never_reset_pin_number(uint8_t pin_number); diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c new file mode 100644 index 000000000000..1bdcceeeb74c --- /dev/null +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -0,0 +1,36 @@ + + +#include +#include "py/runtime.h" + +#if CIRCUITPY_ALARM +#include "common-hal/alarm/__init__.h" +#endif + +#include "common-hal/microcontroller/Processor.h" +#include "shared-bindings/microcontroller/ResetReason.h" + +#include "system_max32690.h" + +// +float common_hal_mcu_processor_get_temperature(void) { + return NAN; +} + +// TODO: Determine if there's a means of getting core voltage +float common_hal_mcu_processor_get_voltage(void) { + return NAN; +} + +uint32_t common_hal_mcu_processor_get_frequency(void) { + return SystemCoreClock; +} + +void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { + return; +} + +// TODO: May need to add reset reason in alarm / deepsleep cases +mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { + return RESET_REASON_UNKNOWN; +} diff --git a/ports/analog/common-hal/microcontroller/Processor.h b/ports/analog/common-hal/microcontroller/Processor.h new file mode 100644 index 000000000000..aab7727550a9 --- /dev/null +++ b/ports/analog/common-hal/microcontroller/Processor.h @@ -0,0 +1,16 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 12 + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + // Stores no state currently. +} mcu_processor_obj_t; diff --git a/ports/analog/common-hal/microcontroller/__init__.c b/ports/analog/common-hal/microcontroller/__init__.c new file mode 100644 index 000000000000..f15ef9bcecc3 --- /dev/null +++ b/ports/analog/common-hal/microcontroller/__init__.c @@ -0,0 +1,410 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "py/mphal.h" +#include "py/obj.h" +#include "py/runtime.h" + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/microcontroller/Processor.h" + +// #include "shared-bindings/nvm/ByteArray.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/microcontroller/Processor.h" +#include "supervisor/port.h" +#include "supervisor/filesystem.h" +#include "supervisor/shared/safe_mode.h" + + +#include "max32690.h" +/** NOTE: It is not advised to directly include the below! + * These are includes taken care of by the core cmsis file. + * e.g. "max32690.h". Since CMSIS is compiled as lib, these are + * included there as for example. +*/ +// #include "core_cmFunc.h" // For enable/disable interrupts +// #include "core_cm4.h" // For NVIC_SystemReset +// #include "core_cmInstr.h" // For __DMB Data Memory Barrier + +void common_hal_mcu_delay_us(uint32_t delay) { + // uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq() / 1000000UL; + // delay *= ticks_per_us; + // SysTick->VAL = 0UL; + // SysTick->LOAD = delay; + // SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; + // while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) { + // } + // SysTick->CTRL = 0UL; +} + +volatile uint32_t nesting_count = 0; + +void common_hal_mcu_disable_interrupts(void) { + __disable_irq(); + __DMB(); + nesting_count++; +} + +void common_hal_mcu_enable_interrupts(void) { + if (nesting_count == 0) { + // This is very very bad because it means there was mismatched disable/enables. + reset_into_safe_mode(SAFE_MODE_INTERRUPT_ERROR); + } + nesting_count--; + if (nesting_count > 0) { + return; + } + __DMB(); + __enable_irq(); +} + +static bool next_reset_to_bootloader = false; + +void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { + if (runmode == RUNMODE_SAFE_MODE) { + safe_mode_on_next_reset(SAFE_MODE_PROGRAMMATIC); + } + if (runmode == RUNMODE_BOOTLOADER) { + next_reset_to_bootloader = true; + } +} + +void common_hal_mcu_reset(void) { + + if (next_reset_to_bootloader) { + reset_to_bootloader(); + } else { + NVIC_SystemReset(); + } +} + +// The singleton microcontroller.Processor object, bound to microcontroller.cpu +// It currently only has properties, and no state. +const mcu_processor_obj_t common_hal_mcu_processor_obj = { + .base = { + .type = &mcu_processor_type, + }, +}; + +// This maps MCU pin names to pin objects. +static const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { + #if defined(PIN_PA01) && !defined(IGNORE_PIN_PA01) + { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) }, + #endif + #if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02) + { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) }, + #endif + #if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03) + { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) }, + #endif + #if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04) + { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) }, + #endif + #if defined(PIN_PA05) && !defined(IGNORE_PIN_PA05) + { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) }, + #endif + #if defined(PIN_PA06) && !defined(IGNORE_PIN_PA06) + { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) }, + #endif + #if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07) + { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) }, + #endif + #if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) + { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) }, + #endif + #if defined(PIN_PA09) && !defined(IGNORE_PIN_PA09) + { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) }, + #endif + #if defined(PIN_PA10) && !defined(IGNORE_PIN_PA10) + { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) }, + #endif + #if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11) + { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) }, + #endif + #if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12) + { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) }, + #endif + #if defined(PIN_PA13) && !defined(IGNORE_PIN_PA13) + { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) }, + #endif + #if defined(PIN_PA14) && !defined(IGNORE_PIN_PA14) + { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) }, + #endif + #if defined(PIN_PA15) && !defined(IGNORE_PIN_PA15) + { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) }, + #endif + #if defined(PIN_PA16) && !defined(IGNORE_PIN_PA16) + { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_PA16) }, + #endif + #if defined(PIN_PA17) && !defined(IGNORE_PIN_PA17) + { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_PA17) }, + #endif + #if defined(PIN_PA18) && !defined(IGNORE_PIN_PA18) + { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_PA18) }, + #endif + #if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19) + { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) }, + #endif + #if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20) + { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) }, + #endif + #if defined(PIN_PA21) && !defined(IGNORE_PIN_PA21) + { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_PA21) }, + #endif + #if defined(PIN_PA22) && !defined(IGNORE_PIN_PA22) + { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_PA22) }, + #endif + #if defined(PIN_PA23) && !defined(IGNORE_PIN_PA23) + { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_PA23) }, + #endif + #if defined(PIN_PA24) && !defined(IGNORE_PIN_PA24) + { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_PA24) }, + #endif + #if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25) + { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) }, + #endif + #if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27) + { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) }, + #endif + #if defined(PIN_PA28) && !defined(IGNORE_PIN_PA28) + { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_PA28) }, + #endif + #if defined(PIN_PA30) && !defined(IGNORE_PIN_PA30) + { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_PA30) }, + #endif + #if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31) + { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) }, + #endif + + #if defined(PIN_PB01) && !defined(IGNORE_PIN_PB01) + { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) }, + #endif + #if defined(PIN_PB02) && !defined(IGNORE_PIN_PB02) + { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) }, + #endif + #if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03) + { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }, + #endif + #if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04) + { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) }, + #endif + #if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05) + { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) }, + #endif + #if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06) + { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) }, + #endif + #if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07) + { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) }, + #endif + #if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08) + { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) }, + #endif + #if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09) + { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) }, + #endif + #if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10) + { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) }, + #endif + #if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11) + { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) }, + #endif + #if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12) + { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) }, + #endif + #if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13) + { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) }, + #endif + #if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14) + { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) }, + #endif + #if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15) + { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) }, + #endif + #if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16) + { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) }, + #endif + #if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17) + { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) }, + #endif + #if defined(PIN_PB18) && !defined(IGNORE_PIN_PB18) + { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_PB18) }, + #endif + #if defined(PIN_PB19) && !defined(IGNORE_PIN_PB19) + { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_PB19) }, + #endif + #if defined(PIN_PB20) && !defined(IGNORE_PIN_PB20) + { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_PB20) }, + #endif + #if defined(PIN_PB21) && !defined(IGNORE_PIN_PB21) + { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_PB21) }, + #endif + #if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22) + { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) }, + #endif + #if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23) + { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) }, + #endif + #if defined(PIN_PB24) && !defined(IGNORE_PIN_PB24) + { MP_ROM_QSTR(MP_QSTR_PB24), MP_ROM_PTR(&pin_PB24) }, + #endif + #if defined(PIN_PB25) && !defined(IGNORE_PIN_PB25) + { MP_ROM_QSTR(MP_QSTR_PB25), MP_ROM_PTR(&pin_PB25) }, + #endif + #if defined(PIN_PB26) && !defined(IGNORE_PIN_PB26) + { MP_ROM_QSTR(MP_QSTR_PB26), MP_ROM_PTR(&pin_PB26) }, + #endif + #if defined(PIN_PB27) && !defined(IGNORE_PIN_PB27) + { MP_ROM_QSTR(MP_QSTR_PB27), MP_ROM_PTR(&pin_PB27) }, + #endif + #if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28) + { MP_ROM_QSTR(MP_QSTR_PB28), MP_ROM_PTR(&pin_PB28) }, + #endif + #if defined(PIN_PB29) && !defined(IGNORE_PIN_PB29) + { MP_ROM_QSTR(MP_QSTR_PB29), MP_ROM_PTR(&pin_PB29) }, + #endif + #if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30) + { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) }, + #endif + #if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31) + { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) }, + #endif + + #if defined(PIN_PC01) && !defined(IGNORE_PIN_PC01) + { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) }, + #endif + #if defined(PIN_PC02) && !defined(IGNORE_PIN_PC02) + { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) }, + #endif + #if defined(PIN_PC03) && !defined(IGNORE_PIN_PC03) + { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) }, + #endif + #if defined(PIN_PC04) && !defined(IGNORE_PIN_PC04) + { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_PC04) }, + #endif + #if defined(PIN_PC05) && !defined(IGNORE_PIN_PC05) + { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) }, + #endif + #if defined(PIN_PC06) && !defined(IGNORE_PIN_PC06) + { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, + #endif + #if defined(PIN_PC07) && !defined(IGNORE_PIN_PC07) + { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, + #endif + #if defined(PIN_PC10) && !defined(IGNORE_PIN_PC10) + { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) }, + #endif + #if defined(PIN_PC11) && !defined(IGNORE_PIN_PC11) + { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) }, + #endif + #if defined(PIN_PC12) && !defined(IGNORE_PIN_PC12) + { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) }, + #endif + #if defined(PIN_PC13) && !defined(IGNORE_PIN_PC13) + { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, + #endif + #if defined(PIN_PC14) && !defined(IGNORE_PIN_PC14) + { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_PC14) }, + #endif + #if defined(PIN_PC15) && !defined(IGNORE_PIN_PC15) + { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_PC15) }, + #endif + #if defined(PIN_PC16) && !defined(IGNORE_PIN_PC16) + { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_PC16) }, + #endif + #if defined(PIN_PC17) && !defined(IGNORE_PIN_PC17) + { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_PC17) }, + #endif + #if defined(PIN_PC18) && !defined(IGNORE_PIN_PC18) + { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_PC18) }, + #endif + #if defined(PIN_PC19) && !defined(IGNORE_PIN_PC19) + { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_PC19) }, + #endif + #if defined(PIN_PC20) && !defined(IGNORE_PIN_PC20) + { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_PC20) }, + #endif + #if defined(PIN_PC21) && !defined(IGNORE_PIN_PC21) + { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_PC21) }, + #endif + #if defined(PIN_PC22) && !defined(IGNORE_PIN_PC22) + { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_PC22) }, + #endif + #if defined(PIN_PC23) && !defined(IGNORE_PIN_PC23) + { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_PC23) }, + #endif + #if defined(PIN_PC24) && !defined(IGNORE_PIN_PC24) + { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_PC24) }, + #endif + #if defined(PIN_PC25) && !defined(IGNORE_PIN_PC25) + { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_PC25) }, + #endif + #if defined(PIN_PC26) && !defined(IGNORE_PIN_PC26) + { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_PC26) }, + #endif + #if defined(PIN_PC27) && !defined(IGNORE_PIN_PC27) + { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_PC27) }, + #endif + #if defined(PIN_PC28) && !defined(IGNORE_PIN_PC28) + { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_PC28) }, + #endif + #if defined(PIN_PC30) && !defined(IGNORE_PIN_PC30) + { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_PC30) }, + #endif + #if defined(PIN_PC31) && !defined(IGNORE_PIN_PC31) + { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_PC31) }, + #endif + + #if defined(PIN_PD01) && !defined(IGNORE_PIN_PD01) + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) }, + #endif + #if defined(PIN_PD02) && !defined(IGNORE_PIN_PD02) + { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_PD02) }, + #endif + #if defined(PIN_PD03) && !defined(IGNORE_PIN_PD03) + { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_PD03) }, + #endif + #if defined(PIN_PD04) && !defined(IGNORE_PIN_PD04) + { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_PD04) }, + #endif + #if defined(PIN_PD05) && !defined(IGNORE_PIN_PD05) + { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_PD05) }, + #endif + #if defined(PIN_PD06) && !defined(IGNORE_PIN_PD06) + { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_PD06) }, + #endif + #if defined(PIN_PD07) && !defined(IGNORE_PIN_PD07) + { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_PD07) }, + #endif + #if defined(PIN_PD08) && !defined(IGNORE_PIN_PD08) + { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) }, + #endif + #if defined(PIN_PD09) && !defined(IGNORE_PIN_PD09) + { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) }, + #endif + + #if defined(PIN_PE01) && !defined(IGNORE_PIN_PE01) + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD02) }, + #endif + #if defined(PIN_PE02) && !defined(IGNORE_PIN_PD02) + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD02) }, + #endif + +}; +MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table); + +// #if CIRCUITPY_INTERNAL_NVM_SIZE > 0 +// // The singleton nvm.ByteArray object. +// const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { +// .base = { +// .type = &nvm_bytearray_type, +// }, +// .len = NVM_BYTEARRAY_BUFFER_SIZE, +// .start_address = (uint8_t *)(CIRCUITPY_INTERNAL_NVM_START_ADDR) +// }; +// #endif diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c new file mode 100644 index 000000000000..97ce98cb9e1e --- /dev/null +++ b/ports/analog/common-hal/os/__init__.c @@ -0,0 +1,50 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "genhdr/mpversion.h" +#include "py/mpconfig.h" +#include "py/objstr.h" +#include "py/objtuple.h" + +#include "py/mperrno.h" +#include "py/runtime.h" + +// #include "peripherals/periph.h" + +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "max32"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "max32"); + +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + +bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { + #if (HAS_TRNG) + //todo: implement + #else + #endif + return false; +} diff --git a/ports/analog/linking/max32690_cktpy.ld b/ports/analog/linking/max32690_cktpy.ld new file mode 100644 index 000000000000..3ecc0b991f2f --- /dev/null +++ b/ports/analog/linking/max32690_cktpy.ld @@ -0,0 +1,160 @@ +MEMORY { + ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K + FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M + FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 200K + FLASH_FS (rw) : ORIGIN = 0x10032000, LENGTH = 64K + FLASH_FIRMWARE (rx) : ORIGIN = 0x10042000, LENGTH = 0x002BE000 + RAM (rwx): ORIGIN = 0x20000000, LENGTH = 1M +} +/* FLASH FIRMWARE: 0x10300000 (end) - 0x10042000 = 0x002BE000 */ + +ENTRY(Reset_Handler) + +SECTIONS { + .rom : + { + KEEP(*(.rom_vector)) + *(.rom_handlers*) + } > ROM + + /* Place ISR vector in a separate flash section */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + EXCLUDE_FILE (*riscv.o) *(.text*) /* program code, exclude RISCV code */ + } >FLASH_ISR + + .text : + { + . = ALIGN(4); + _text = .; + *(.rodata*) /* read-only data: "const" */ + + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + /* C++ Exception handling */ + KEEP(*(.eh_frame*)) + . = ALIGN(4); + _etext = .; + } > FLASH_FIRMWARE + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH_FIRMWARE + + /* Binary import */ + .bin_storage : + { + FILL(0xFF) + _bin_start_ = .; + KEEP(*(.bin_storage_img)) + _bin_end_ = .; + . = ALIGN(4); + } > FLASH_FIRMWARE + + /* it's used for C++ exception handling */ + /* we need to keep this to avoid overlapping */ + .ARM.exidx : + { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > FLASH_FIRMWARE + + .data : + { + . = ALIGN(4); + _data = .; + _sdata = .; + + *(vtable) + *(.data*) /*read-write initialized data: initialized global variable*/ + + /* These array sections are used by __libc_init_array to call static C++ constructors */ + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + /* Run the flash programming functions from SRAM */ + *(.flashprog) + + . = ALIGN(4); + _edata = .; + } > RAM AT>FLASH_FIRMWARE + __load_data = LOADADDR(.data); + + .bss : + { + . = ALIGN(4); + _sbss = .; /* Provide _sbss for Cktpy */ + _bss = .; + + *(.bss*) /*read-write zero initialized data: uninitialized global variable*/ + *(COMMON) + + . = ALIGN(4); + _ebss = .; + _ezero = .; /* Provide _ezero /_ebss for CktPython (same as ebss) */ + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + __estack = __StackLimit; /* Provide _estack for CktPython */ + + .heap (COPY): + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + *(.heap*) + __HeapLimit = ABSOLUTE(__StackLimit); + } > RAM + + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack") +} diff --git a/ports/analog/mpconfigport.h b/ports/analog/mpconfigport.h new file mode 100644 index 000000000000..bb9f8b6ac368 --- /dev/null +++ b/ports/analog/mpconfigport.h @@ -0,0 +1,36 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2015 Glenn Ruben Bakke +// SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include + +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + + +// 24kiB stack +#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 +// uint8_t _ld_default_stack_size; +// #define CIRCUITPY_DEFAULT_STACK_SIZE ((uint32_t)&_ld_default_stack_size) + +// Also includes mpconfigboard.h +#include "py/circuitpy_mpconfig.h" + +// Board flags: +#ifndef BOARD_OVERWRITE_SWD +#define BOARD_OVERWRITE_SWD (0) +#endif +#ifndef BOARD_VTOR_DEFER +#define BOARD_VTOR_DEFER (0) +#endif +#ifndef BOARD_NO_VBUS_SENSE +#define BOARD_NO_VBUS_SENSE (0) +#endif +#ifndef BOARD_NO_USB_OTG_ID_SENSE +#define BOARD_NO_USB_OTG_ID_SENSE (0) +#endif diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk new file mode 100644 index 000000000000..3c68a62884fd --- /dev/null +++ b/ports/analog/mpconfigport.mk @@ -0,0 +1,85 @@ +# This file is part of the CircuitPython project: https://circuitpython.org +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +CHIP_FAMILY ?= max32 + +# Necessary to build CircuitPython +USB_NUM_ENDPOINT_PAIRS ?= 0 +LONGINT_IMPL ?= MPZ +INTERNAL_LIBM ?= 1 + +#################################################################################### +# Suggested config for first-time porting +#################################################################################### +# These modules are implemented in ports//common-hal: + +# Typically the first module to create +CIRCUITPY_MICROCONTROLLER = 1 +# Typically the second module to create +CIRCUITPY_DIGITALIO = 0 +# Other modules: +CIRCUITPY_ANALOGIO = 0 +CIRCUITPY_BUSIO = 0 +CIRCUITPY_COUNTIO = 0 +CIRCUITPY_NEOPIXEL_WRITE = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_OS = 1 +CIRCUITPY_NVM = 0 +CIRCUITPY_AUDIOBUSIO = 0 +CIRCUITPY_AUDIOIO = 0 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_RTC = 0 +CIRCUITPY_SDCARDIO = 0 +CIRCUITPY_FRAMEBUFFERIO = 0 +CIRCUITPY_FREQUENCYIO = 0 +CIRCUITPY_I2CTARGET = 0 +# Requires SPI, PulseIO (stub ok): +CIRCUITPY_DISPLAYIO = 0 + +# These modules are implemented in shared-module/ - they can be included in +# any port once their prerequisites in common-hal are complete. +# Requires DigitalIO: +CIRCUITPY_BITBANGIO = 0 +# Requires neopixel_write or SPI (dotstar) +CIRCUITPY_PIXELBUF = 0 +# Requires OS +CIRCUITPY_RANDOM = 0 +# Requires OS, filesystem +CIRCUITPY_STORAGE = 0 +# Requires Microcontroller +CIRCUITPY_TOUCHIO = 0 +# Requires UART! +CIRCUITPY_CONSOLE_UART = 0 +# Requires USB +CIRCUITPY_USB_DEVICE = 0 +CIRCUITPY_USB_CDC = 0 +CIRCUITPY_USB_HID = 0 +CIRCUITPY_USB_MIDI = 0 +# Does nothing without I2C +CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 +# No requirements, but takes extra flash +CIRCUITPY_ULAB = 0 +#################################################################################### +# Required for clean building (additional CircuittPython Defaults) +#################################################################################### +# Enabled by default +CIRCUITPY_PWMIO = 0 +# Depends on BUSIO +# CIRCUITPY_BLEIO = 0 +CIRCUITPY_BLEIO_HCI = 0 +CIRCUITPY_KEYPAD = 0 +CIRCUITPY_BUSDEVICE = 0 + +# TinyUSB will be added later. +CIRCUITPY_TINYUSB = 0 +CIRCUITPY_PYUSB = 0 + +INTERNAL_FLASH_FILESYSTEM = 1 +SPI_FLASH_FILESYSTEM = 0 +QSPI_FLASH_FILESYSTEM = 0 + +# TODO: Review flash filesystem funcs before flashing +DISABLE_FILESYSTEM = 0 diff --git a/ports/analog/mphalport.c b/ports/analog/mphalport.c new file mode 100644 index 000000000000..1bbcf605b007 --- /dev/null +++ b/ports/analog/mphalport.c @@ -0,0 +1,15 @@ + +#include "mphalport.h" +#include "cmsis_gcc.h" + + +// TODO: Define tick & other port functions + + +void mp_hal_disable_all_interrupts(void) { + __disable_irq(); +} + +void mp_hal_enable_all_interrupts(void) { + __enable_irq(); +} diff --git a/ports/analog/mphalport.h b/ports/analog/mphalport.h new file mode 100644 index 000000000000..8dba63d82ff0 --- /dev/null +++ b/ports/analog/mphalport.h @@ -0,0 +1,22 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "py/obj.h" +#include "lib/oofatfs/ff.h" +#include "supervisor/shared/tick.h" + +// TODO: Define tick & other port functions +// Global millisecond tick count (driven by SysTick interrupt). +static inline mp_uint_t mp_hal_ticks_ms(void) { + return supervisor_ticks_ms32(); +} + +void mp_hal_set_interrupt_char(int c); + +void mp_hal_disable_all_interrupts(void); +void mp_hal_enable_all_interrupts(void); diff --git a/ports/analog/msdk b/ports/analog/msdk new file mode 160000 index 000000000000..608acf33e95a --- /dev/null +++ b/ports/analog/msdk @@ -0,0 +1 @@ +Subproject commit 608acf33e95a994d548b8223955952c4749acaac diff --git a/ports/analog/peripherals/max32690/pins.c b/ports/analog/peripherals/max32690/pins.c new file mode 100644 index 000000000000..4f26d9d1f6d6 --- /dev/null +++ b/ports/analog/peripherals/max32690/pins.c @@ -0,0 +1,119 @@ +#include "py/obj.h" +#include "py/mphal.h" +#include "peripherals/pins.h" + +#include "gpio.h" +#include "gpio_regs.h" + +const mcu_pin_obj_t pin_P0_00 = PIN(MXC_GPIO_PORT_0, 0); +const mcu_pin_obj_t pin_P0_01 = PIN(MXC_GPIO_PORT_0, 1); +const mcu_pin_obj_t pin_P0_02 = PIN(MXC_GPIO_PORT_0, 2); +const mcu_pin_obj_t pin_P0_03 = PIN(MXC_GPIO_PORT_0, 3); +const mcu_pin_obj_t pin_P0_04 = PIN(MXC_GPIO_PORT_0, 4); +const mcu_pin_obj_t pin_P0_05 = PIN(MXC_GPIO_PORT_0, 5); +const mcu_pin_obj_t pin_P0_06 = PIN(MXC_GPIO_PORT_0, 6); +const mcu_pin_obj_t pin_P0_07 = PIN(MXC_GPIO_PORT_0, 7); +const mcu_pin_obj_t pin_P0_08 = PIN(MXC_GPIO_PORT_0, 8); +const mcu_pin_obj_t pin_P0_09 = PIN(MXC_GPIO_PORT_0, 9); +const mcu_pin_obj_t pin_P0_10 = PIN(MXC_GPIO_PORT_0, 10); +const mcu_pin_obj_t pin_P0_11 = PIN(MXC_GPIO_PORT_0, 11); +const mcu_pin_obj_t pin_P0_12 = PIN(MXC_GPIO_PORT_0, 12); +const mcu_pin_obj_t pin_P0_13 = PIN(MXC_GPIO_PORT_0, 13); +const mcu_pin_obj_t pin_P0_14 = PIN(MXC_GPIO_PORT_0, 14); +const mcu_pin_obj_t pin_P0_15 = PIN(MXC_GPIO_PORT_0, 15); +const mcu_pin_obj_t pin_P0_16 = PIN(MXC_GPIO_PORT_0, 16); +const mcu_pin_obj_t pin_P0_17 = PIN(MXC_GPIO_PORT_0, 17); +const mcu_pin_obj_t pin_P0_18 = PIN(MXC_GPIO_PORT_0, 18); +const mcu_pin_obj_t pin_P0_19 = PIN(MXC_GPIO_PORT_0, 19); +const mcu_pin_obj_t pin_P0_20 = PIN(MXC_GPIO_PORT_0, 20); +const mcu_pin_obj_t pin_P0_21 = PIN(MXC_GPIO_PORT_0, 21); +const mcu_pin_obj_t pin_P0_22 = PIN(MXC_GPIO_PORT_0, 22); +const mcu_pin_obj_t pin_P0_23 = PIN(MXC_GPIO_PORT_0, 23); +const mcu_pin_obj_t pin_P0_24 = PIN(MXC_GPIO_PORT_0, 24); +const mcu_pin_obj_t pin_P0_25 = PIN(MXC_GPIO_PORT_0, 25); +const mcu_pin_obj_t pin_P0_26 = PIN(MXC_GPIO_PORT_0, 26); +const mcu_pin_obj_t pin_P0_27 = PIN(MXC_GPIO_PORT_0, 27); +const mcu_pin_obj_t pin_P0_28 = PIN(MXC_GPIO_PORT_0, 28); +const mcu_pin_obj_t pin_P0_29 = PIN(MXC_GPIO_PORT_0, 29); +const mcu_pin_obj_t pin_P0_30 = PIN(MXC_GPIO_PORT_0, 30); +const mcu_pin_obj_t pin_P0_31 = PIN(MXC_GPIO_PORT_0, 31); + +const mcu_pin_obj_t pin_P1_00 = PIN(MXC_GPIO_PORT_1, 0); +const mcu_pin_obj_t pin_P1_01 = PIN(MXC_GPIO_PORT_1, 1); +const mcu_pin_obj_t pin_P1_02 = PIN(MXC_GPIO_PORT_1, 2); +const mcu_pin_obj_t pin_P1_03 = PIN(MXC_GPIO_PORT_1, 3); +const mcu_pin_obj_t pin_P1_04 = PIN(MXC_GPIO_PORT_1, 4); +const mcu_pin_obj_t pin_P1_05 = PIN(MXC_GPIO_PORT_1, 5); +const mcu_pin_obj_t pin_P1_06 = PIN(MXC_GPIO_PORT_1, 6); +const mcu_pin_obj_t pin_P1_07 = PIN(MXC_GPIO_PORT_1, 7); +const mcu_pin_obj_t pin_P1_08 = PIN(MXC_GPIO_PORT_1, 8); +const mcu_pin_obj_t pin_P1_09 = PIN(MXC_GPIO_PORT_1, 9); +const mcu_pin_obj_t pin_P1_10 = PIN(MXC_GPIO_PORT_1, 10); +const mcu_pin_obj_t pin_P1_11 = PIN(MXC_GPIO_PORT_1, 11); +const mcu_pin_obj_t pin_P1_12 = PIN(MXC_GPIO_PORT_1, 12); +const mcu_pin_obj_t pin_P1_13 = PIN(MXC_GPIO_PORT_1, 13); +const mcu_pin_obj_t pin_P1_14 = PIN(MXC_GPIO_PORT_1, 14); +const mcu_pin_obj_t pin_P1_15 = PIN(MXC_GPIO_PORT_1, 15); +const mcu_pin_obj_t pin_P1_16 = PIN(MXC_GPIO_PORT_1, 16); +const mcu_pin_obj_t pin_P1_17 = PIN(MXC_GPIO_PORT_1, 17); +const mcu_pin_obj_t pin_P1_18 = PIN(MXC_GPIO_PORT_1, 18); +const mcu_pin_obj_t pin_P1_19 = PIN(MXC_GPIO_PORT_1, 19); +const mcu_pin_obj_t pin_P1_20 = PIN(MXC_GPIO_PORT_1, 20); +const mcu_pin_obj_t pin_P1_21 = PIN(MXC_GPIO_PORT_1, 21); +const mcu_pin_obj_t pin_P1_22 = PIN(MXC_GPIO_PORT_1, 22); +const mcu_pin_obj_t pin_P1_23 = PIN(MXC_GPIO_PORT_1, 23); +const mcu_pin_obj_t pin_P1_24 = PIN(MXC_GPIO_PORT_1, 24); +const mcu_pin_obj_t pin_P1_25 = PIN(MXC_GPIO_PORT_1, 25); +const mcu_pin_obj_t pin_P1_26 = PIN(MXC_GPIO_PORT_1, 26); +const mcu_pin_obj_t pin_P1_27 = PIN(MXC_GPIO_PORT_1, 27); +const mcu_pin_obj_t pin_P1_28 = PIN(MXC_GPIO_PORT_1, 28); +const mcu_pin_obj_t pin_P1_29 = PIN(MXC_GPIO_PORT_1, 29); +const mcu_pin_obj_t pin_P1_30 = PIN(MXC_GPIO_PORT_1, 30); +const mcu_pin_obj_t pin_P1_31 = PIN(MXC_GPIO_PORT_1, 31); + +const mcu_pin_obj_t pin_P2_00 = PIN(MXC_GPIO_PORT_2, 0); +const mcu_pin_obj_t pin_P2_01 = PIN(MXC_GPIO_PORT_2, 1); +const mcu_pin_obj_t pin_P2_02 = PIN(MXC_GPIO_PORT_2, 2); +const mcu_pin_obj_t pin_P2_03 = PIN(MXC_GPIO_PORT_2, 3); +const mcu_pin_obj_t pin_P2_04 = PIN(MXC_GPIO_PORT_2, 4); +const mcu_pin_obj_t pin_P2_05 = PIN(MXC_GPIO_PORT_2, 5); +const mcu_pin_obj_t pin_P2_06 = PIN(MXC_GPIO_PORT_2, 6); +const mcu_pin_obj_t pin_P2_07 = PIN(MXC_GPIO_PORT_2, 7); +const mcu_pin_obj_t pin_P2_08 = PIN(MXC_GPIO_PORT_2, 8); +const mcu_pin_obj_t pin_P2_09 = PIN(MXC_GPIO_PORT_2, 9); +const mcu_pin_obj_t pin_P2_10 = PIN(MXC_GPIO_PORT_2, 10); +const mcu_pin_obj_t pin_P2_11 = PIN(MXC_GPIO_PORT_2, 11); +const mcu_pin_obj_t pin_P2_12 = PIN(MXC_GPIO_PORT_2, 12); +const mcu_pin_obj_t pin_P2_13 = PIN(MXC_GPIO_PORT_2, 13); +const mcu_pin_obj_t pin_P2_14 = PIN(MXC_GPIO_PORT_2, 14); +const mcu_pin_obj_t pin_P2_15 = PIN(MXC_GPIO_PORT_2, 15); +const mcu_pin_obj_t pin_P2_16 = PIN(MXC_GPIO_PORT_2, 16); +const mcu_pin_obj_t pin_P2_17 = PIN(MXC_GPIO_PORT_2, 17); +const mcu_pin_obj_t pin_P2_18 = PIN(MXC_GPIO_PORT_2, 18); +const mcu_pin_obj_t pin_P2_19 = PIN(MXC_GPIO_PORT_2, 19); +const mcu_pin_obj_t pin_P2_20 = PIN(MXC_GPIO_PORT_2, 20); +const mcu_pin_obj_t pin_P2_21 = PIN(MXC_GPIO_PORT_2, 21); +const mcu_pin_obj_t pin_P2_22 = PIN(MXC_GPIO_PORT_2, 22); +const mcu_pin_obj_t pin_P2_23 = PIN(MXC_GPIO_PORT_2, 23); +const mcu_pin_obj_t pin_P2_24 = PIN(MXC_GPIO_PORT_2, 24); +const mcu_pin_obj_t pin_P2_25 = PIN(MXC_GPIO_PORT_2, 25); +const mcu_pin_obj_t pin_P2_26 = PIN(MXC_GPIO_PORT_2, 26); +const mcu_pin_obj_t pin_P2_27 = PIN(MXC_GPIO_PORT_2, 27); +const mcu_pin_obj_t pin_P2_28 = PIN(MXC_GPIO_PORT_2, 28); +const mcu_pin_obj_t pin_P2_29 = PIN(MXC_GPIO_PORT_2, 29); +const mcu_pin_obj_t pin_P2_30 = PIN(MXC_GPIO_PORT_2, 30); +const mcu_pin_obj_t pin_P2_31 = PIN(MXC_GPIO_PORT_2, 31); + +const mcu_pin_obj_t pin_P3_00 = PIN(MXC_GPIO_PORT_3, 0); +const mcu_pin_obj_t pin_P3_01 = PIN(MXC_GPIO_PORT_3, 1); +const mcu_pin_obj_t pin_P3_02 = PIN(MXC_GPIO_PORT_3, 2); +const mcu_pin_obj_t pin_P3_03 = PIN(MXC_GPIO_PORT_3, 3); +const mcu_pin_obj_t pin_P3_04 = PIN(MXC_GPIO_PORT_3, 4); +const mcu_pin_obj_t pin_P3_05 = PIN(MXC_GPIO_PORT_3, 5); +const mcu_pin_obj_t pin_P3_06 = PIN(MXC_GPIO_PORT_3, 6); +const mcu_pin_obj_t pin_P3_07 = PIN(MXC_GPIO_PORT_3, 7); +const mcu_pin_obj_t pin_P3_08 = PIN(MXC_GPIO_PORT_3, 8); +const mcu_pin_obj_t pin_P3_09 = PIN(MXC_GPIO_PORT_3, 9); + +const mcu_pin_obj_t pin_P4_00 = PIN(MXC_GPIO_PORT_4, 0); +const mcu_pin_obj_t pin_P4_01 = PIN(MXC_GPIO_PORT_4, 1); diff --git a/ports/analog/peripherals/max32690/pins.h b/ports/analog/peripherals/max32690/pins.h new file mode 100644 index 000000000000..9b5cc303ee5c --- /dev/null +++ b/ports/analog/peripherals/max32690/pins.h @@ -0,0 +1,114 @@ +#pragma once + +extern const mcu_pin_obj_t pin_P0_00; +extern const mcu_pin_obj_t pin_P0_01; +extern const mcu_pin_obj_t pin_P0_02; +extern const mcu_pin_obj_t pin_P0_03; +extern const mcu_pin_obj_t pin_P0_04; +extern const mcu_pin_obj_t pin_P0_05; +extern const mcu_pin_obj_t pin_P0_06; +extern const mcu_pin_obj_t pin_P0_07; +extern const mcu_pin_obj_t pin_P0_08; +extern const mcu_pin_obj_t pin_P0_09; +extern const mcu_pin_obj_t pin_P0_10; +extern const mcu_pin_obj_t pin_P0_11; +extern const mcu_pin_obj_t pin_P0_12; +extern const mcu_pin_obj_t pin_P0_13; +extern const mcu_pin_obj_t pin_P0_14; +extern const mcu_pin_obj_t pin_P0_15; +extern const mcu_pin_obj_t pin_P0_16; +extern const mcu_pin_obj_t pin_P0_17; +extern const mcu_pin_obj_t pin_P0_18; +extern const mcu_pin_obj_t pin_P0_19; +extern const mcu_pin_obj_t pin_P0_20; +extern const mcu_pin_obj_t pin_P0_21; +extern const mcu_pin_obj_t pin_P0_22; +extern const mcu_pin_obj_t pin_P0_23; +extern const mcu_pin_obj_t pin_P0_24; +extern const mcu_pin_obj_t pin_P0_25; +extern const mcu_pin_obj_t pin_P0_26; +extern const mcu_pin_obj_t pin_P0_27; +extern const mcu_pin_obj_t pin_P0_28; +extern const mcu_pin_obj_t pin_P0_29; +extern const mcu_pin_obj_t pin_P0_30; +extern const mcu_pin_obj_t pin_P0_31; + +extern const mcu_pin_obj_t pin_P1_00; +extern const mcu_pin_obj_t pin_P1_01; +extern const mcu_pin_obj_t pin_P1_02; +extern const mcu_pin_obj_t pin_P1_03; +extern const mcu_pin_obj_t pin_P1_04; +extern const mcu_pin_obj_t pin_P1_05; +extern const mcu_pin_obj_t pin_P1_06; +extern const mcu_pin_obj_t pin_P1_07; +extern const mcu_pin_obj_t pin_P1_08; +extern const mcu_pin_obj_t pin_P1_09; +extern const mcu_pin_obj_t pin_P1_10; +extern const mcu_pin_obj_t pin_P1_11; +extern const mcu_pin_obj_t pin_P1_12; +extern const mcu_pin_obj_t pin_P1_13; +extern const mcu_pin_obj_t pin_P1_14; +extern const mcu_pin_obj_t pin_P1_15; +extern const mcu_pin_obj_t pin_P1_16; +extern const mcu_pin_obj_t pin_P1_17; +extern const mcu_pin_obj_t pin_P1_18; +extern const mcu_pin_obj_t pin_P1_19; +extern const mcu_pin_obj_t pin_P1_20; +extern const mcu_pin_obj_t pin_P1_21; +extern const mcu_pin_obj_t pin_P1_22; +extern const mcu_pin_obj_t pin_P1_23; +extern const mcu_pin_obj_t pin_P1_24; +extern const mcu_pin_obj_t pin_P1_25; +extern const mcu_pin_obj_t pin_P1_26; +extern const mcu_pin_obj_t pin_P1_27; +extern const mcu_pin_obj_t pin_P1_28; +extern const mcu_pin_obj_t pin_P1_29; +extern const mcu_pin_obj_t pin_P1_30; +extern const mcu_pin_obj_t pin_P1_31; + +extern const mcu_pin_obj_t pin_P2_00; +extern const mcu_pin_obj_t pin_P2_01; +extern const mcu_pin_obj_t pin_P2_02; +extern const mcu_pin_obj_t pin_P2_03; +extern const mcu_pin_obj_t pin_P2_04; +extern const mcu_pin_obj_t pin_P2_05; +extern const mcu_pin_obj_t pin_P2_06; +extern const mcu_pin_obj_t pin_P2_07; +extern const mcu_pin_obj_t pin_P2_08; +extern const mcu_pin_obj_t pin_P2_09; +extern const mcu_pin_obj_t pin_P2_10; +extern const mcu_pin_obj_t pin_P2_11; +extern const mcu_pin_obj_t pin_P2_12; +extern const mcu_pin_obj_t pin_P2_13; +extern const mcu_pin_obj_t pin_P2_14; +extern const mcu_pin_obj_t pin_P2_15; +extern const mcu_pin_obj_t pin_P2_16; +extern const mcu_pin_obj_t pin_P2_17; +extern const mcu_pin_obj_t pin_P2_18; +extern const mcu_pin_obj_t pin_P2_19; +extern const mcu_pin_obj_t pin_P2_20; +extern const mcu_pin_obj_t pin_P2_21; +extern const mcu_pin_obj_t pin_P2_22; +extern const mcu_pin_obj_t pin_P2_23; +extern const mcu_pin_obj_t pin_P2_24; +extern const mcu_pin_obj_t pin_P2_25; +extern const mcu_pin_obj_t pin_P2_26; +extern const mcu_pin_obj_t pin_P2_27; +extern const mcu_pin_obj_t pin_P2_28; +extern const mcu_pin_obj_t pin_P2_29; +extern const mcu_pin_obj_t pin_P2_30; +extern const mcu_pin_obj_t pin_P2_31; + +extern const mcu_pin_obj_t pin_P3_00; +extern const mcu_pin_obj_t pin_P3_01; +extern const mcu_pin_obj_t pin_P3_02; +extern const mcu_pin_obj_t pin_P3_03; +extern const mcu_pin_obj_t pin_P3_04; +extern const mcu_pin_obj_t pin_P3_05; +extern const mcu_pin_obj_t pin_P3_06; +extern const mcu_pin_obj_t pin_P3_07; +extern const mcu_pin_obj_t pin_P3_08; +extern const mcu_pin_obj_t pin_P3_09; + +extern const mcu_pin_obj_t pin_P4_00; // BTLDR Stimulus +extern const mcu_pin_obj_t pin_P4_01; diff --git a/ports/analog/peripherals/pins.h b/ports/analog/peripherals/pins.h new file mode 100644 index 000000000000..ae471dc29e18 --- /dev/null +++ b/ports/analog/peripherals/pins.h @@ -0,0 +1,34 @@ + + +#pragma once + +// STD includes +#include +#include + +// CktPy includes +#include "py/obj.h" + +// HAL includes +// #include "gpio.h" + +typedef struct { + mp_obj_base_t base; + const uint8_t port; + const uint8_t pad; + // const uint8_t level : 4; // FIXME: Find how to include the VDDIO/VDDIOH level +} mcu_pin_obj_t; + +extern const mp_obj_type_t mcu_pin_type; + +#define NO_PIN (0xFF) // for non-connected pins + +#define PIN(pin_port, pin_pad) \ + { \ + { &mcu_pin_type }, \ + .port = pin_port, \ + .pad = pin_pad, \ + } + +// TODO: Create macros for detecting MCU VARIANT +#include "max32690/pins.h" diff --git a/ports/analog/qstrdefsport.h b/ports/analog/qstrdefsport.h new file mode 100644 index 000000000000..2d2c26092348 --- /dev/null +++ b/ports/analog/qstrdefsport.h @@ -0,0 +1,10 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Adafruit Industries LLC +// +// SPDX-License-Identifier: MIT + +// Do not use #pragma once in this file; it will cause a warning during qstr generation. + +// qstrs specific to this port +// *FORMAT-OFF* diff --git a/ports/analog/supervisor/cpu.s b/ports/analog/supervisor/cpu.s new file mode 100644 index 000000000000..9e6807a5e2e9 --- /dev/null +++ b/ports/analog/supervisor/cpu.s @@ -0,0 +1,27 @@ +.syntax unified +.cpu cortex-m4 +.thumb +.text +.align 2 + +@ uint cpu_get_regs_and_sp(r0=uint regs[10]) +.global cpu_get_regs_and_sp +.thumb +.thumb_func +.type cpu_get_regs_and_sp, %function +cpu_get_regs_and_sp: +@ store registers into given array +str r4, [r0], #4 +str r5, [r0], #4 +str r6, [r0], #4 +str r7, [r0], #4 +str r8, [r0], #4 +str r9, [r0], #4 +str r10, [r0], #4 +str r11, [r0], #4 +str r12, [r0], #4 +str r13, [r0], #4 + +@ return the sp +mov r0, sp +bx lr diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c new file mode 100644 index 000000000000..a8c10076d3bf --- /dev/null +++ b/ports/analog/supervisor/internal_flash.c @@ -0,0 +1,289 @@ + +#include "supervisor/internal_flash.h" + +#include +#include + +#include "extmod/vfs.h" +#include "extmod/vfs_fat.h" + +#include "py/obj.h" +#include "py/mphal.h" +#include "py/runtime.h" + +#include "supervisor/filesystem.h" +#include "supervisor/flash.h" +#include "supervisor/shared/safe_mode.h" + +#if CIRCUITPY_USB_DEVICE +#include "supervisor/usb.h" +#endif + +// MAX32 HAL Includes +#include "flc.h" +#include "flc_reva.h" +#include "icc.h" // includes icc_.c for MSDK die type +#include "mxc_device.h" + +/** TODO: + * - Verify all necessary Filesystem MACROs are defined in mpconfigport.h + * + * NOTE: + * ANY function which modifies flash contents must execute from a crit section. + * This is because FLC functions are loc'd in RAM, and any ISR executing + * from Flash will trigger a HardFault. + * + * An alternative would be to initialize with NVIC_SetRAM(), + * which makes ISRs execute from RAM. + * + * NOTE: + * Additionally, any code that modifies flash contents must disable the + * cache. Turn off ICC0 any time flash is to be modified. Remember to re-enable if using. + * + * For Maxim devices which include an additional RISC-V processor, this shall be ignored. + * Therefore only ICC0 need be used for the purpose of these functions. + */ + +#define NO_CACHE 0xffffffff +#define MAX_CACHE 0x4000 + +typedef struct { + uint32_t base_addr; + uint32_t sector_size; + uint32_t num_sectors; +} flash_layout_t; + +#ifdef MAX32690 +static const flash_layout_t flash_layout[] = { + { 0x1000000, 0x4000, 192}, + { 0x1030000, 0x2000, 32 }, +}; +static uint8_t _flash_cache[0x4000] __attribute__((aligned(4))); +#endif + +// Address of the flash sector currently being cached +static uint32_t _cache_addr_in_flash = NO_CACHE; + +static inline int32_t block2addr(uint32_t block) { + if (block > 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { + return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; + } + else return -1; +} + +int flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { + // This function should return -1 in the event of errors. + if (addr >= flash_layout[0].base_addr) { + uint32_t sector_index = 0; + if (MP_ARRAY_SIZE(flash_layout) == 1) { + sector_index = (addr - flash_layout[0].base_addr) / flash_layout[0].sector_size; + if (sector_index >= flash_layout[0].num_sectors) { + return -1; + } + if (start_addr) { + *start_addr = flash_layout[0].base_addr + (sector_index * flash_layout[0].sector_size); + } + if (size) { + *size = flash_layout[0].sector_size; + } + return sector_index; + } + + for (uint8_t i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) { + for (uint8_t j = 0; j < flash_layout[i].num_sectors; ++j) { + uint32_t sector_start_next = flash_layout[i].base_addr + + (j + 1) * flash_layout[i].sector_size; + if (addr < sector_start_next) { + if (start_addr) { + *start_addr = flash_layout[i].base_addr + + j * flash_layout[i].sector_size; + } + if (size) { + *size = flash_layout[i].sector_size; + } + return sector_index; + } + ++sector_index; + } + } + } + return -1; +} + +void supervisor_flash_init(void) { + // No initialization needed. + // Pay attention to the note at the top of this file! +} + +uint32_t supervisor_flash_get_block_size(void) { + return FILESYSTEM_BLOCK_SIZE; +} + +uint32_t supervisor_flash_get_block_count(void) { + return INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS; +} + +// Flush the flash page that is currently cached +void port_internal_flash_flush(void) { + // Flash has not been cached + if (_cache_addr_in_flash == NO_CACHE) { + return; + } + uint32_t sector_start, sector_size = 0xffffffff; + + // Clear & enable flash interrupt flags + MXC_FLC_EnableInt(MXC_F_FLC_INTR_DONEIE | MXC_F_FLC_INTR_AFIE); + + // Figure out the sector of flash we're targeting + if (flash_get_sector_info(_cache_addr_in_flash, §or_start, §or_size) == -1) { + // If not in valid sector, just release the cache and return + supervisor_flash_release_cache(); + return; + } + + // if invalid sector or sector size > the size of our cache, reset with flash fail + if (sector_size > sizeof(_flash_cache) || sector_start == 0xffffffff) { + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + // skip if the data in cache is the same as what's already there + if (memcmp(_flash_cache, (void *)_cache_addr_in_flash, FLASH_PAGE_SIZE) != 0) { + uint32_t error; + + // buffer for the page of flash + uint32_t page_buffer[FLASH_PAGE_SIZE >> 2] = { + 0xFFFFFFFF + }; // bytes per page / 4 bytes = # of uint32_t + + // Unlock Flash + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_UNLOCKED; + + /*** ERASE FLASH PAGE ***/ + MXC_CRITICAL( + // buffer the page + MXC_FLC_Read(sector_start, page_buffer, sector_size); + // Erase page & error check + error = MXC_FLC_PageErase(sector_start); + ); + if (error != E_NO_ERROR) { + // lock flash & reset + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + /*** RE-WRITE FLASH PAGE w/ CACHE DATA ***/ + MXC_CRITICAL( + // ret = program the flash page with cache data (for loop) + for (uint32_t i = 0; i < (sector_size >> 2); i++) { + error = MXC_FLC_Write32(_cache_addr_in_flash + 4 * i, _flash_cache[i]); + } + ); + if (error != E_NO_ERROR) { + // lock flash & reset + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + // Lock flash & exit + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + } + +} + +mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { + // Find the address of the block we want to read + int src_addr = block2addr(block); + if (src_addr == -1) { + // bad block num + return false; + } + + uint32_t sector_size, sector_start; + if (flash_get_sector_info(src_addr, §or_start, §or_size) == -1) { + // bad sector idx + return false; + } + + // Find how many blocks left in sector + uint32_t blocks_in_sector = (sector_size - (src_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; + + // If the whole read is inside the cache, then read cache + if (num_blocks <= blocks_in_sector && _cache_addr_in_flash == sector_start) { + memcpy(dest, (_flash_cache + (src_addr - sector_start)), FILESYSTEM_BLOCK_SIZE * num_blocks); + } else { + supervisor_flash_flush(); + /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking + * than memcpy does. Will use it for now. + */ + MXC_FLC_Read((int)dest, (int *)src_addr, FILESYSTEM_BLOCK_SIZE * num_blocks); + } + return 0; // success +} + +mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { + uint32_t count=0; + uint32_t sector_size=0; + uint32_t sector_start=0; + + while (num_blocks > 0) { + const int32_t dest_addr = block2addr(block_num); + // bad block number passed in + if (dest_addr == -1) { + return false; + } + + // Implementation is from STM port + // NOTE: May replace later, but this port had a method + // that seemed to make sense across multiple devices. + if (flash_get_sector_info(dest_addr, §or_start, §or_size) == -1) { + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + // fail if sector size is greater than cache size + if (sector_size > sizeof(_flash_cache)) { + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + // Find the number of blocks left within this sector + // BLOCK_NUM = (SECTOR SIZE - BLOCK OFFSET within sector)) / BLOCK_SIZE + count = (sector_size - (dest_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; + count = MIN(num_blocks, count); + + // if we're not at the start of a sector, copy the whole sector to cache + if (_cache_addr_in_flash != sector_start) { + // Flush cache first + supervisor_flash_flush(); + + _cache_addr_in_flash = sector_start; + + // Copy the whole sector into cache + memcpy(_flash_cache, (void *)sector_start, sector_size); + } + + // Overwrite the cache with source data passed in + memcpy(_flash_cache + (dest_addr - sector_start), src, count * FILESYSTEM_BLOCK_SIZE); + + block_num += count; + src += count * FILESYSTEM_BLOCK_SIZE; + num_blocks -= count; + } + return 0; // success +} + +void supervisor_flash_release_cache(void) { + // Flush the cache for ARM M4 + MXC_ICC_Flush(MXC_ICC0); + MXC_ICC_Flush(MXC_ICC1); + + // Clear the line fill buffer by reading 2 pages from flash + volatile uint32_t *line_addr; + volatile uint32_t line; + line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE); + line = *line_addr; + line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE + MXC_FLASH_PAGE_SIZE); + line = *line_addr; + (void)line; // Silence build warnings that this variable is not used. + + // Invalidate the current cache + _cache_addr_in_flash = NO_CACHE; +} diff --git a/ports/analog/supervisor/internal_flash.h b/ports/analog/supervisor/internal_flash.h new file mode 100644 index 000000000000..e59fd2af2408 --- /dev/null +++ b/ports/analog/supervisor/internal_flash.h @@ -0,0 +1,16 @@ + +#pragma once + +#include +#include + +#include "py/mpconfig.h" + +/** Sections defined in linker files under "linking" */ +#ifdef MAX32690 +#define MAX32_FLASH_SIZE 0x300000 // 3 MB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64K +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10032000 // Load into the last MB of code/data storage??? +#endif + +#define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c new file mode 100644 index 000000000000..cf63b3a261f4 --- /dev/null +++ b/ports/analog/supervisor/port.c @@ -0,0 +1,167 @@ +/****************************************************************************** + * + * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. All Rights Reserved. + * (now owned by Analog Devices, Inc.), + * Copyright (C) 2023 Analog Devices, Inc. All Rights Reserved. This software + * is proprietary to Analog Devices, Inc. and its licensors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/** + * @file port.c + * @author Brandon Hurst @ Analog Devices, Inc. + * @brief Functions required for a basic CircuitPython port + * @date 2024-07-30 + * + * @copyright Copyright (c) 2024 + */ + +#include +#include "supervisor/board.h" +#include "supervisor/port.h" + +#include +// #include "gpio.h" +#include "mxc_assert.h" +#include "mxc_delay.h" +#include "mxc_device.h" +#include "mxc_pins.h" +#include "mxc_sys.h" +#include "uart.h" + +/** Linker variables defined.... + * _estack: end of the stack + * _ebss: end of BSS section + * _ezero: same as ebss (acc. to main.c) + */ +extern uint32_t _ezero; +extern uint32_t _estack; +extern uint32_t _ebss; // Stored at the end of the bss section (which includes the heap). +extern uint32_t _ld_heap_start, _ld_heap_end, _ld_stack_top, _ld_stack_bottom; + +// defined by cmsis core files +void NVIC_SystemReset(void) NORETURN; + +safe_mode_t port_init(void) { + return SAFE_MODE_NONE; +} + +void HAL_Delay(uint32_t delay_ms) { +} + +uint32_t HAL_GetTick(void) { + return 1000; +} + +void SysTick_Handler(void) { +} + +void reset_to_bootloader(void) { + NVIC_SystemReset(); +} + + +void reset_cpu(void) { + NVIC_SystemReset(); +} + +void reset_port(void) { + // MXC_GPIO_Reset(MXC_GPIO0); + // MXC_GPIO_Reset(MXC_GPIO1); +} + +uint32_t *port_heap_get_bottom(void) { + return (uint32_t *)0xAAAAAAAA; +} + +uint32_t *port_heap_get_top(void) { + return (uint32_t *)0xAAAAAAAF; +} + +uint32_t *port_stack_get_limit(void) { + #pragma GCC diagnostic push + + #pragma GCC diagnostic ignored "-Warray-bounds" + // return port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t); + return port_stack_get_top() - (0 + 0) / sizeof(uint32_t); + #pragma GCC diagnostic pop +} + +uint32_t *port_stack_get_top(void) { + return (uint32_t *)0xB000000; +} + + +// Place the word to save just after our BSS section that gets blanked. +void port_set_saved_word(uint32_t value) { + _ebss = value; +} + +uint32_t port_get_saved_word(void) { + return _ebss; +} + +// __attribute__((used)) void MemManage_Handler(void) { +// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +// while (true) { +// asm ("nop;"); +// } +// } + +// __attribute__((used)) void BusFault_Handler(void) { +// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +// while (true) { +// asm ("nop;"); +// } +// } + +// __attribute__((used)) void UsageFault_Handler(void) { +// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +// while (true) { +// asm ("nop;"); +// } +// } + +// __attribute__((used)) void HardFault_Handler(void) { +// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +// while (true) { +// asm ("nop;"); +// } +// } + +uint64_t port_get_raw_ticks(uint8_t *subticks) { + return 1000; +} + +// Enable 1/1024 second tick. +void port_enable_tick(void) { +} + +// Disable 1/1024 second tick. +void port_disable_tick(void) { +} + +void port_interrupt_after_ticks(uint32_t ticks) { + // todo: implement isr after rtc ticks +} + +void port_idle_until_interrupt(void) { + __WFI(); +} + +// Required by __libc_init_array in startup code if we are compiling using +// -nostdlib/-nostartfiles. +void _init(void) { +} diff --git a/ports/analog/supervisor/serial.c b/ports/analog/supervisor/serial.c new file mode 100644 index 000000000000..7f485a35204c --- /dev/null +++ b/ports/analog/supervisor/serial.c @@ -0,0 +1,61 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "py/mphal.h" +#include +#include "supervisor/shared/serial.h" + +#define MAX32_SERIAL 0 + +#if MAX32_SERIAL +// TODO: Switch this to using DEBUG_UART. +#endif + +void port_serial_init(void) { + #if MAX32_SERIAL + // huart2.Instance = USART2; + // huart2.Init.BaudRate = 115200; + // huart2.Init.WordLength = UART_WORDLENGTH_8B; + // huart2.Init.StopBits = UART_STOPBITS_1; + // huart2.Init.Parity = UART_PARITY_NONE; + // huart2.Init.Mode = UART_MODE_TX_RX; + // huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; + // huart2.Init.OverSampling = UART_OVERSAMPLING_16; + // if (HAL_UART_Init(&huart2) == HAL_OK) { + // stm32f4_peripherals_status_led(1, 1); + // } + #endif +} + +bool port_serial_connected(void) { + return true; +} + +char port_serial_read(void) { + #if MAX32_SERIAL + // uint8_t data; + // HAL_UART_Receive(&huart2, &data, 1, 500); + // return data; + #else + return -1; + #endif +} + +// There is no easy way to find the number of pending characters, so just say there's 1. +uint32_t port_serial_bytes_available(void) { + #if MAX32_SERIAL + // return __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) ? 1 : 0; + #else + return 0; + #endif +} + +void port_serial_write_substring(const char *text, uint32_t len) { + #if MAX32_SERIAL + // HAL_UART_Transmit(&huart2, (uint8_t *)text, len, 5000); + #endif +} diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index cbae4b3ff5e0..778a90c31b63 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -46,6 +46,12 @@ def matching_submodules(s): # Submodules needed by port builds outside of their ports directory. # Should we try and detect these? PORT_DEPS = { + "analog": [ + "extmod/ulab/", + "/lib/tlsf/", + "lib/tinyusb/", + "lib/protomatter", + ], "atmel-samd": [ "extmod/ulab/", "lib/adafruit_floppy/", From 6d816ef28711cba788706950e13f25d46bd60a4f Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Thu, 15 Aug 2024 23:10:01 -0700 Subject: [PATCH 002/252] - Added 1/1024 s tick based on 4096 Hz RTC. - Added simple status LED for initial testing - Generally cleaned up & implemented supervisor/port.c - Added some additional commenting from supervisor headers - Fixed a linkerscript issue copying .text into FLASH_ISR --- ports/analog/Makefile | 7 +- ports/analog/background.c | 37 ++- ports/analog/boards/APARD/board.c | 20 +- ports/analog/linking/max32690_cktpy.ld | 19 +- ports/analog/mpconfigport.mk | 18 +- ports/analog/mphalport.c | 9 +- ports/analog/supervisor/internal_flash.h | 2 +- ports/analog/supervisor/max32_port.h | 31 +++ ports/analog/supervisor/port.c | 314 +++++++++++++++++------ 9 files changed, 351 insertions(+), 106 deletions(-) create mode 100644 ports/analog/supervisor/max32_port.h diff --git a/ports/analog/Makefile b/ports/analog/Makefile index b348a57d237f..b7ed00f0b691 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -75,10 +75,11 @@ INC += \ -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Include \ -I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \ -I$(PERIPH_SRC)/SYS \ - -I$(PERIPH_SRC)/GPIO \ -I$(PERIPH_SRC)/CTB \ - -I$(PERIPH_SRC)/ICC \ -I$(PERIPH_SRC)/FLC \ + -I$(PERIPH_SRC)/GPIO \ + -I$(PERIPH_SRC)/ICC \ + -I$(PERIPH_SRC)/RTC \ -I$(PERIPH_SRC)/UART \ INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC @@ -103,6 +104,8 @@ SRC_MAX32 += \ $(PERIPH_SRC)/GPIO/gpio_reva.c \ $(PERIPH_SRC)/ICC/icc_$(DIE_TYPE).c \ $(PERIPH_SRC)/ICC/icc_reva.c \ + $(PERIPH_SRC)/RTC/rtc_$(DIE_TYPE).c \ + $(PERIPH_SRC)/RTC/rtc_reva.c \ $(PERIPH_SRC)/UART/uart_common.c \ $(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \ $(PERIPH_SRC)/UART/uart_revb.c \ diff --git a/ports/analog/background.c b/ports/analog/background.c index ccf71bf77bf5..f08eb00a7123 100644 --- a/ports/analog/background.c +++ b/ports/analog/background.c @@ -9,20 +9,41 @@ #include "supervisor/usb.h" #include "supervisor/shared/stack.h" -//TODO: IMPLEMENT +#include "supervisor/max32_port.h" -void port_background_task(void) { - return; -} +/** NOTE: ALL "ticks" refer to a 1/1024 s period */ +static int status_led_ticks=0; + +extern mxc_gpio_cfg_t led_pin[]; +extern const unsigned int num_leds; +extern mxc_gpio_cfg_t pb_pin[]; +extern const unsigned int num_pbs; + +// This function is where port-specific background +// tasks should be performed +// Execute port specific actions during background tick. Only if ticks are enabled. void port_background_tick(void) { - return; + status_led_ticks++; + + // Set an LED approx. 1/s + if (status_led_ticks > 1024) + { + MXC_GPIO_OutToggle(led_pin[0].port, led_pin[0].mask); + status_led_ticks = 0; + } } -void port_start_background_tick(void) { - return; +// Execute port specific actions during background tasks. This is before the +// background callback system and happens *very* often. Use +// port_background_tick() when possible. +void port_background_task(void) { } +// Take port specific actions at the beginning and end of background ticks. +// This is used e.g., to set a monitoring pin for debug purposes. "Actual +// work" should be done in port_background_tick() instead. +void port_start_background_tick(void) { +} void port_finish_background_tick(void) { - return; } diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c index b44a1ae51e04..cd69f369579a 100644 --- a/ports/analog/boards/APARD/board.c +++ b/ports/analog/boards/APARD/board.c @@ -6,4 +6,22 @@ #include "supervisor/board.h" -// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. +// DEFAULT: Using the weak-defined supervisor/shared/board.c functions + +/***** OPTIONAL BOARD-SPECIFIC FUNTIONS from supervisor/board.h *****/ +// Returns true if the user initiates safe mode in a board specific way. +// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific +// way. +// bool board_requests_safe_mode(void); + +// Initializes board related state once on start up. +// void board_init(void); + +// Reset the state of off MCU components such as neopixels. +// void reset_board(void); + +// Deinit the board. This should put the board in deep sleep durable, low power +// state. It should not prevent the user access method from working (such as +// disabling USB, BLE or flash) because CircuitPython may continue to run. +// void board_deinit(void); +/*******************************************************************/ diff --git a/ports/analog/linking/max32690_cktpy.ld b/ports/analog/linking/max32690_cktpy.ld index 3ecc0b991f2f..423bfc321168 100644 --- a/ports/analog/linking/max32690_cktpy.ld +++ b/ports/analog/linking/max32690_cktpy.ld @@ -1,9 +1,9 @@ MEMORY { ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M - FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 200K - FLASH_FS (rw) : ORIGIN = 0x10032000, LENGTH = 64K - FLASH_FIRMWARE (rx) : ORIGIN = 0x10042000, LENGTH = 0x002BE000 + FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 16K + FLASH_FS (rw) : ORIGIN = 0x10004000, LENGTH = 64K + FLASH_FIRMWARE (rx) : ORIGIN = 0x10014000, LENGTH = 0x10030000 - 80K RAM (rwx): ORIGIN = 0x20000000, LENGTH = 1M } /* FLASH FIRMWARE: 0x10300000 (end) - 0x10042000 = 0x002BE000 */ @@ -21,14 +21,18 @@ SECTIONS { .isr_vector : { . = ALIGN(4); - KEEP(*(.isr_vector)) /* Startup code */ - EXCLUDE_FILE (*riscv.o) *(.text*) /* program code, exclude RISCV code */ + /* Startup code */ + KEEP(*(.isr_vector*)) } >FLASH_ISR .text : { . = ALIGN(4); _text = .; + + /* program code, exclude RISCV code */ + EXCLUDE_FILE (*riscv.o) *(.text*) + *(.rodata*) /* read-only data: "const" */ KEEP(*(.init)) @@ -142,17 +146,20 @@ SECTIONS { * size of stack_dummy section */ __StackTop = ORIGIN(RAM) + LENGTH(RAM); __StackLimit = __StackTop - SIZEOF(.stack_dummy); - __estack = __StackLimit; /* Provide _estack for CktPython */ + _estack = __StackLimit; /* Provide _estack for CktPython */ .heap (COPY): { . = ALIGN(4); + __heap = .; PROVIDE ( end = . ); PROVIDE ( _end = . ); *(.heap*) __HeapLimit = ABSOLUTE(__StackLimit); } > RAM + __eheap = __HeapLimit; + PROVIDE(__stack = __StackTop); /* Check if data + heap + stack exceeds RAM limit */ diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 3c68a62884fd..c4a6234f664e 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -11,6 +11,13 @@ USB_NUM_ENDPOINT_PAIRS ?= 0 LONGINT_IMPL ?= MPZ INTERNAL_LIBM ?= 1 +INTERNAL_FLASH_FILESYSTEM = 1 +SPI_FLASH_FILESYSTEM = 0 +QSPI_FLASH_FILESYSTEM = 0 + +# TODO: Review flash filesystem funcs before flashing +DISABLE_FILESYSTEM = 0 + #################################################################################### # Suggested config for first-time porting #################################################################################### @@ -31,6 +38,7 @@ CIRCUITPY_NVM = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOIO = 0 CIRCUITPY_ROTARYIO = 0 +#todo: implement time/date based on RTC sec/subsec CIRCUITPY_RTC = 0 CIRCUITPY_SDCARDIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 @@ -60,8 +68,9 @@ CIRCUITPY_USB_HID = 0 CIRCUITPY_USB_MIDI = 0 # Does nothing without I2C CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 + # No requirements, but takes extra flash -CIRCUITPY_ULAB = 0 +CIRCUITPY_ULAB = 1 #################################################################################### # Required for clean building (additional CircuittPython Defaults) #################################################################################### @@ -76,10 +85,3 @@ CIRCUITPY_BUSDEVICE = 0 # TinyUSB will be added later. CIRCUITPY_TINYUSB = 0 CIRCUITPY_PYUSB = 0 - -INTERNAL_FLASH_FILESYSTEM = 1 -SPI_FLASH_FILESYSTEM = 0 -QSPI_FLASH_FILESYSTEM = 0 - -# TODO: Review flash filesystem funcs before flashing -DISABLE_FILESYSTEM = 0 diff --git a/ports/analog/mphalport.c b/ports/analog/mphalport.c index 1bbcf605b007..d4e63ec67393 100644 --- a/ports/analog/mphalport.c +++ b/ports/analog/mphalport.c @@ -1,10 +1,15 @@ #include "mphalport.h" -#include "cmsis_gcc.h" +#include "py/mphal.h" +// includes __enable/__disable interrupts +#include "mxc_sys.h" -// TODO: Define tick & other port functions +#include "shared-bindings/microcontroller/__init__.h" +void mp_hal_delay_us(mp_uint_t delay) { + common_hal_mcu_delay_us(delay); +} void mp_hal_disable_all_interrupts(void) { __disable_irq(); diff --git a/ports/analog/supervisor/internal_flash.h b/ports/analog/supervisor/internal_flash.h index e59fd2af2408..ef944fbffed5 100644 --- a/ports/analog/supervisor/internal_flash.h +++ b/ports/analog/supervisor/internal_flash.h @@ -10,7 +10,7 @@ #ifdef MAX32690 #define MAX32_FLASH_SIZE 0x300000 // 3 MB #define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64K -#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10032000 // Load into the last MB of code/data storage??? +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10040000 // Load into the last MB of code/data storage??? #endif #define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) diff --git a/ports/analog/supervisor/max32_port.h b/ports/analog/supervisor/max32_port.h new file mode 100644 index 000000000000..25641a5dddbc --- /dev/null +++ b/ports/analog/supervisor/max32_port.h @@ -0,0 +1,31 @@ + +#ifndef MAX32_PORT_H +#define MAX32_PORT_H + +#include + +#include "mxc_sys.h" +#include "mxc_pins.h" +#include "gpio.h" +#include "mxc_assert.h" + +/** Linker variables defined.... + * _estack: end of the stack + * _ebss: end of BSS section + * _ezero: same as ebss (acc. to main.c) + */ +extern uint32_t _ezero; +extern uint32_t _estack; +extern uint32_t _ebss; // Stored at the end of the bss section (which includes the heap). +extern uint32_t __stack, __heap; + +extern uint32_t SystemCoreClock; + +// Tick timer should be 1/1024 s. RTC Oscillator is usually 32.768 kHz ERTCO. +#define TICKS_PER_SEC 1024 + +#ifdef MAX32690 +#define SUBSEC_PER_TICK 8 // 12-bit ssec register, ticks @ 4096 Hz +#endif + +#endif //MAX32_PORT_H diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index cf63b3a261f4..fd6bc1806aeb 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -29,139 +29,297 @@ */ #include +#include +#include "supervisor/background_callback.h" #include "supervisor/board.h" #include "supervisor/port.h" -#include -// #include "gpio.h" -#include "mxc_assert.h" +#include "common-hal/microcontroller/Pin.h" +#include "shared-bindings/microcontroller/__init__.h" + +//todo: pack the below definitions into their own module +//todo: under peripherals/gpio, peripherals/clocks, etc. + +// Sys includes +#include "max32_port.h" + +// Timers #include "mxc_delay.h" -#include "mxc_device.h" -#include "mxc_pins.h" -#include "mxc_sys.h" -#include "uart.h" - -/** Linker variables defined.... - * _estack: end of the stack - * _ebss: end of BSS section - * _ezero: same as ebss (acc. to main.c) - */ -extern uint32_t _ezero; -extern uint32_t _estack; -extern uint32_t _ebss; // Stored at the end of the bss section (which includes the heap). -extern uint32_t _ld_heap_start, _ld_heap_end, _ld_stack_top, _ld_stack_bottom; +#include "rtc.h" + +//todo: define an LED HAL +// #include "peripherals/led.h" + +#ifdef MAX32690 +// Board-level setup for MAX32690 +// clang-format off +const mxc_gpio_cfg_t pb_pin[] = { + { MXC_GPIO1, MXC_GPIO_PIN_27, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, +}; +const unsigned int num_pbs = (sizeof(pb_pin) / sizeof(mxc_gpio_cfg_t)); + +const mxc_gpio_cfg_t led_pin[] = { + { MXC_GPIO2, MXC_GPIO_PIN_1, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO0, MXC_GPIO_PIN_11, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO0, MXC_GPIO_PIN_12, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, +}; +const unsigned int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); +// clang-format on +#endif + +// For caching rtc data for ticks +static uint32_t subsec, sec = 0; // defined by cmsis core files -void NVIC_SystemReset(void) NORETURN; +extern void NVIC_SystemReset(void) NORETURN; safe_mode_t port_init(void) { - return SAFE_MODE_NONE; -} + int err = E_NO_ERROR; -void HAL_Delay(uint32_t delay_ms) { -} + // Enable GPIO (enables clocks + common init for ports) + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + err = MXC_GPIO_Init(0x1 << i); + if (err) { + return SAFE_MODE_PROGRAMMATIC; + } + } -uint32_t HAL_GetTick(void) { - return 1000; -} + // Init Board LEDs + /* setup GPIO for the LED */ + for (int i = 0; i < num_leds; i++) { + // Set the output value + MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); -void SysTick_Handler(void) { -} + if (MXC_GPIO_Config(&led_pin[i]) != E_NO_ERROR) { + return SAFE_MODE_PROGRAMMATIC; + } + } -void reset_to_bootloader(void) { - NVIC_SystemReset(); -} + // Turn on one LED to indicate Sign of Life + MXC_GPIO_OutSet(led_pin[0].port, led_pin[0].mask); + + // Init RTC w/ 0sec, 0subsec + // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s + err = MXC_RTC_Init(0, 0); + if (err) { + return SAFE_MODE_SDK_FATAL_ERROR; + } + NVIC_EnableIRQ(RTC_IRQn); + + // todo: init periph clocks / console here when ready + MXC_RTC_Start(); + return SAFE_MODE_NONE; +} +// Reset the MCU completely void reset_cpu(void) { + // includes MCU reset request + awaits on memory bus NVIC_SystemReset(); } +// Reset MCU state void reset_port(void) { - // MXC_GPIO_Reset(MXC_GPIO0); - // MXC_GPIO_Reset(MXC_GPIO1); -} + int err; + // Reset GPIO Ports + // Enable GPIO (enables clocks + common init for ports) + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + err = MXC_GPIO_Reset(0x1 << i); + if (err) { + // todo: indicate some gpio error + continue; + } + } -uint32_t *port_heap_get_bottom(void) { - return (uint32_t *)0xAAAAAAAA; + // TODO: Reset peripheral clocks + + // Reset 1/1024 tick timer + MXC_RTC_Stop(); + MXC_RTC_ClearFlags(0xFFFFFFFF); + MXC_RTC_Init(0,0); } -uint32_t *port_heap_get_top(void) { - return (uint32_t *)0xAAAAAAAF; +// Reset to the bootloader +// note: not implemented since max32 requires external stim ignals to +// activate bootloaders +// todo: check if there's a method to jump to it +void reset_to_bootloader(void) { + NVIC_SystemReset(); + while (true) { + asm ("nop;"); + } } +/** Acquire values of stack & heap starts & limits + * Return variables defined by linkerscript. + */ uint32_t *port_stack_get_limit(void) { + // ignore array bounds GCC warnings for stack here #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Warray-bounds" - // return port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t); - return port_stack_get_top() - (0 + 0) / sizeof(uint32_t); + + // NOTE: Only return how much stack we have alloted for CircuitPython + return (uint32_t *)(port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t)); + // return _estack; + + // end GCC diagnostic disable #pragma GCC diagnostic pop } - uint32_t *port_stack_get_top(void) { - return (uint32_t *)0xB000000; + return (uint32_t *)__stack; +} +uint32_t *port_heap_get_bottom(void) { + return (uint32_t *)__heap; +} +uint32_t *port_heap_get_top(void) { + return port_stack_get_limit(); } - -// Place the word to save just after our BSS section that gets blanked. +/** Save & retrieve a word from memory over a reset cycle. + * Used for safe mode + */ void port_set_saved_word(uint32_t value) { _ebss = value; } - uint32_t port_get_saved_word(void) { return _ebss; } -// __attribute__((used)) void MemManage_Handler(void) { -// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); -// while (true) { -// asm ("nop;"); -// } -// } - -// __attribute__((used)) void BusFault_Handler(void) { -// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); -// while (true) { -// asm ("nop;"); -// } -// } - -// __attribute__((used)) void UsageFault_Handler(void) { -// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); -// while (true) { -// asm ("nop;"); -// } -// } - -// __attribute__((used)) void HardFault_Handler(void) { -// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); -// while (true) { -// asm ("nop;"); -// } -// } - +// Raw monotonic tick count since startup. +// NOTE (rollover): +// seconds reg is 32 bits, can hold up to 2^32-1 +// theref. rolls over after ~136 years uint64_t port_get_raw_ticks(uint8_t *subticks) { - return 1000; + // Ensure we can read from ssec register as soon as we can + // MXC function does cross-tick / busy checking of RTC controller + __disable_irq(); + MXC_RTC_GetTime(&sec, &subsec); + __enable_irq(); + + // Return ticks given total subseconds + // ticks = TICKS/s * s + subsec/ subs/tick + uint64_t raw_ticks = ((uint64_t)TICKS_PER_SEC) * sec + (subsec / SUBSEC_PER_TICK); + + if (subticks) { + // subticks may only be filled to a resn of 1/4096 in some cases + // e.g. multiply by 32 / 8 = 4 to get true 1/32768 subticks + *subticks = (32 / (SUBSEC_PER_TICK)) * (subsec - (subsec / SUBSEC_PER_TICK)); + } + + return raw_ticks; } // Enable 1/1024 second tick. void port_enable_tick(void) { + MXC_RTC_Start(); } // Disable 1/1024 second tick. void port_disable_tick(void) { + MXC_RTC_Stop(); } +// Wake the CPU after a given # of ticks or sooner void port_interrupt_after_ticks(uint32_t ticks) { - // todo: implement isr after rtc ticks + // Stop RTC & store current time & ticks + port_disable_tick(); + port_get_raw_ticks(NULL); + + uint32_t target_sec = (ticks / TICKS_PER_SEC); + uint32_t target_ssec = (ticks - (target_sec * TICKS_PER_SEC)) * SUBSEC_PER_TICK; + + // Set up alarm configuration + // if alarm is greater than 1 s, + // use the ToD alarm --> resol. to closest second + // else + // use Ssec alarm --> resn. to 1/1024 s. (down to a full tick) + if (target_sec > 0) { + if (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | + MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { + // todo: signal some RTC error! + } + + if (MXC_RTC_SetTimeofdayAlarm(target_sec) != E_NO_ERROR) { + // todo: signal some RTC error! + } + if (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { + // todo: signal some RTC error! + } + } + else { + if (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | + MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { + // todo: signal some RTC error! + } + + if (MXC_RTC_SetSubsecondAlarm(target_ssec) != E_NO_ERROR) { + // todo: signal some RTC error! + } + + if (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) { + // todo: signal some RTC error! + } + } + port_enable_tick(); +} + +void RTC_IRQHandler(void) { + // Read flags to clear + int flags = MXC_RTC_GetFlags(); + + if (flags & MXC_F_RTC_CTRL_TOD_ALARM) { + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); + while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {} + } + + if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) { + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); + while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {} + } } void port_idle_until_interrupt(void) { - __WFI(); + // Check if alarm triggers before we even got here + if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { + return; + } + + common_hal_mcu_disable_interrupts(); + if (!background_callback_pending()) { + __WFI(); + } + common_hal_mcu_enable_interrupts(); +} + +__attribute__((used)) void MemManage_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} + +__attribute__((used)) void BusFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} + +__attribute__((used)) void UsageFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} + +__attribute__((used)) void HardFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } } -// Required by __libc_init_array in startup code if we are compiling using -// -nostdlib/-nostartfiles. +// Required by libc _init_array loops in startup code +// if we are compiling using "-nostdlib/-nostartfiles" void _init(void) { } From d61cf6e399ad10859bfc15a4b27a1e4a41ed6251 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 20 Aug 2024 13:23:36 -0700 Subject: [PATCH 003/252] - (build): Added tinyUSB src/inc, DMA & RTC from MSDK. - (build): added hex & bin targets for executable. - (build): temporarily modified .ld due to issue exiting MAX32 ROM code - (flash): added flash target for jlink & msdk, along with helper files under tools/ - Reorganized mpconfigport.mk for clarity - Moved flash driver & LED/PB definitions to board files (mpconfigboard._) --- lib/tinyusb | 2 +- ports/analog/Makefile | 58 ++++++++++++------ ports/analog/README.md | 4 +- ports/analog/background.c | 16 ++--- ports/analog/boards/APARD/mpconfigboard.h | 10 +++- ports/analog/linking/max32690_cktpy.ld | 55 ++++++++++------- ports/analog/mpconfigport.h | 5 +- ports/analog/mpconfigport.mk | 72 ++++++++++++----------- ports/analog/mphalport.h | 3 +- ports/analog/supervisor/internal_flash.c | 49 ++++++++++----- ports/analog/supervisor/internal_flash.h | 7 --- ports/analog/tools/connect-gdb.txt | 16 +++++ ports/analog/tools/flash-halt-openocd.bat | 5 ++ ports/analog/tools/flash_max32.jlink | 6 ++ 14 files changed, 192 insertions(+), 116 deletions(-) create mode 100644 ports/analog/tools/connect-gdb.txt create mode 100644 ports/analog/tools/flash-halt-openocd.bat create mode 100644 ports/analog/tools/flash_max32.jlink diff --git a/lib/tinyusb b/lib/tinyusb index ea64dd499961..5f519819bad9 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit ea64dd4999618ce14aea90118ee9218b4aefeba6 +Subproject commit 5f519819bad94b1d19364b485c314b412199fba0 diff --git a/ports/analog/Makefile b/ports/analog/Makefile index b7ed00f0b691..151299a8792a 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -76,9 +76,11 @@ INC += \ -I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \ -I$(PERIPH_SRC)/SYS \ -I$(PERIPH_SRC)/CTB \ + -I$(PERIPH_SRC)/DMA \ -I$(PERIPH_SRC)/FLC \ -I$(PERIPH_SRC)/GPIO \ -I$(PERIPH_SRC)/ICC \ + -I$(PERIPH_SRC)/TMR \ -I$(PERIPH_SRC)/RTC \ -I$(PERIPH_SRC)/UART \ @@ -96,6 +98,9 @@ SRC_MAX32 += \ $(PERIPH_SRC)/CTB/ctb_$(DIE_TYPE).c \ $(PERIPH_SRC)/CTB/ctb_reva.c \ $(PERIPH_SRC)/CTB/ctb_common.c \ + $(PERIPH_SRC)/DMA/dma_reva.c \ + $(PERIPH_SRC)/DMA/dma_revb.c \ + $(PERIPH_SRC)/DMA/dma_$(DIE_TYPE).c \ $(PERIPH_SRC)/FLC/flc_common.c \ $(PERIPH_SRC)/FLC/flc_$(DIE_TYPE).c \ $(PERIPH_SRC)/FLC/flc_reva.c \ @@ -106,6 +111,9 @@ SRC_MAX32 += \ $(PERIPH_SRC)/ICC/icc_reva.c \ $(PERIPH_SRC)/RTC/rtc_$(DIE_TYPE).c \ $(PERIPH_SRC)/RTC/rtc_reva.c \ + $(PERIPH_SRC)/TMR/tmr_common.c \ + $(PERIPH_SRC)/TMR/tmr_revb.c \ + $(PERIPH_SRC)/TMR/tmr_$(DIE_TYPE).c \ $(PERIPH_SRC)/UART/uart_common.c \ $(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \ $(PERIPH_SRC)/UART/uart_revb.c \ @@ -126,7 +134,7 @@ STARTUPFILE = $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC/startup # CircuitPython custom linkerfile (necessary for build steps & filesystems) LINKERFILE = linking/$(MCU_VARIANT_LOWER)_cktpy.ld -LDFLAGS += -nostartfiles -specs=nosys.specs -specs=nano.specs +LDFLAGS += -nostartfiles -specs=nano.specs endif SRC_S += supervisor/cpu.s \ @@ -137,13 +145,14 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET_REV=0x4131 \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ + -DRISCV_LOAD=0 \ # -DFLASH_ORIGIN=0x10000000 \ # -DFLASH_SIZE=0x340000 \ # -DSRAM_ORIGIN=0x20000000 \ # -DSRAM_SIZE=0x100000 \ CPU_CORE=cortex-m4 -CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=hard -mfpu=fpv4-sp-d16 +CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=softfp -mfpu=fpv4-sp-d16 # NOTE: Start with DEBUG ONLY settings for now ifeq ($(DEBUG),) @@ -154,7 +163,7 @@ ifeq ($(DEBUG),1) CFLAGS += -ggdb3 COPT = -Og else -COPT += -O2 +COPT += -O0 #opt completely off to start endif @@ -165,9 +174,9 @@ CFLAGS += \ # TODO: Add for TinyUSB once our PR goes through for MAX32 devices # Add TinyUSB -# INC += -I../../lib/tinyusb/src -# INC += -I../../supervisor/shared/usb -# SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c +INC += -I../../lib/tinyusb/src +INC += -I../../supervisor/shared/usb +SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c SRC_C += \ boards/$(BOARD)/board.c \ @@ -182,13 +191,14 @@ CFLAGS += -Wno-error=unused-parameter \ -Wno-error=sign-compare \ -Wno-error=strict-prototypes \ -Wno-error=cast-qual \ - -Wno-unused-variable \ - -Wno-lto-type-mismatch \ - -Wno-cast-align \ - -Wno-nested-externs \ - -Wno-sign-compare + -Wno-error=unused-variable \ + -Wno-error=lto-type-mismatch \ + -Wno-error=cast-align \ + -Wno-error=nested-externs \ + -Wno-error=sign-compare \ -LDFLAGS += $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections +ENTRY = Reset_Handler +LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections LIBS := -lgcc -lc # If not using CKTPY mathlib, use toolchain mathlib @@ -234,7 +244,7 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_CIRCUITPY_COMMON) \ SRC_QSTR_PREPROCESSOR += # Default build target -all: $(BUILD)/firmware.elf +all: $(BUILD)/firmware.elf $(BUILD)/firmware.hex $(BUILD)/firmware.bin clean-max32: rm -rf build-* @@ -247,18 +257,32 @@ MAXIM_PATH := $(subst \,/,$(MAXIM_PATH)) flash-msdk: $(MAXIM_PATH)/Tools/OpenOCD/openocd -s $(MAXIM_PATH)/Tools/OpenOCD/scripts \ -f interface/cmsis-dap.cfg -f target/$(MCU_VARIANT_LOWER).cfg \ - -c "program $(BUILD)/$(PROJECT).elf verify; init; reset; exit" + -c "program $(BUILD)/firmware.elf verify; init; reset; exit" # flash target using JLink JLINK_DEVICE = $(MCU_VARIANT_LOWER) -flash: flash-jlink -$(BUILD)/firmware.elf: $(OBJ) $(LINKERFILE) +JLINKEXE ?= JLink.exe +JLINKEXE += -if SWD -device ${JLINK_DEVICE} -speed 10000 +COMMAND_FILE := tools/flash_max32.jlink + +flash-jlink: $(BUILD)/firmware.bin + @$(JLINKEXE) -device $(MCU_VARIANT_UPPER) -NoGui 1 -CommandFile ${COMMAND_FILE} + +$(BUILD)/firmware.elf: $(OBJ) $(STEPECHO) "LINK $@" - $(Q)echo $(OBJ) > $(BUILD)/firmware.objs + $(Q)echo $^ > $(BUILD)/firmware.objs $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--print-memory-usage -Wl,--start-group $(LIBS) -Wl,--end-group $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINKERFILE) $(BUILD) +$(BUILD)/firmware.hex: $(BUILD)/firmware.elf + $(STEPECHO) "Create $@" + $(Q)$(OBJCOPY) -O ihex $^ $@ + +$(BUILD)/firmware.bin: $(BUILD)/firmware.elf + $(STEPECHO) "Create $@" + $(Q)$(OBJCOPY) -O binary $^ $@ + # ******************************************************************************* ### CKTPY BUILD RULES ### include $(TOP)/py/mkrules.mk diff --git a/ports/analog/README.md b/ports/analog/README.md index 0e5d3f7d2951..603a22f9fd4b 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -45,8 +45,6 @@ This requires the following: - The PICO board is connected to the target board via a 10-pin SWD ribbon cable. - If SWD connectors are not keyed, the P1 indicator (red line) on the SWD ribbon cable should match the P1 indicator on the board silkscreen near the 10-pin SWD connector. -[**Section in Progress.**] - ### Using the REPL -[**Section in Progress. Review & Testing are needed.**] +[**Section in Progress. USB support needs implementation & test.**] diff --git a/ports/analog/background.c b/ports/analog/background.c index f08eb00a7123..8dad8c4e351d 100644 --- a/ports/analog/background.c +++ b/ports/analog/background.c @@ -9,17 +9,17 @@ #include "supervisor/usb.h" #include "supervisor/shared/stack.h" -#include "supervisor/max32_port.h" +#include "max32_port.h" + +// From boards/$(BOARD)/board.c +extern const mxc_gpio_cfg_t pb_pin[]; +extern const int num_pbs; +extern const mxc_gpio_cfg_t led_pin[]; +extern const int num_leds; /** NOTE: ALL "ticks" refer to a 1/1024 s period */ static int status_led_ticks=0; -extern mxc_gpio_cfg_t led_pin[]; -extern const unsigned int num_leds; - -extern mxc_gpio_cfg_t pb_pin[]; -extern const unsigned int num_pbs; - // This function is where port-specific background // tasks should be performed // Execute port specific actions during background tick. Only if ticks are enabled. @@ -29,7 +29,7 @@ void port_background_tick(void) { // Set an LED approx. 1/s if (status_led_ticks > 1024) { - MXC_GPIO_OutToggle(led_pin[0].port, led_pin[0].mask); + MXC_GPIO_OutToggle(led_pin[2].port, led_pin[2].mask); status_led_ticks = 0; } } diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/APARD/mpconfigboard.h index b22c7ab9ecc6..87baa0120994 100644 --- a/ports/analog/boards/APARD/mpconfigboard.h +++ b/ports/analog/boards/APARD/mpconfigboard.h @@ -22,10 +22,16 @@ #define BOARD_HAS_CRYSTAL 1 -// todo: figure out a way to smartly set this up based on storage considerations +#define NUM_GPIO_PORTS 4 + #if INTERNAL_FLASH_FILESYSTEM -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x10032000) // for MAX32690 +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102FC000) // for MAX32690 #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64 * 1024) // 64K + +#define MAX32_FLASH_SIZE 0x300000 // 3 MiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64KiB +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102FC000 // Load into the last MiB of code/data storage + #else #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) #endif diff --git a/ports/analog/linking/max32690_cktpy.ld b/ports/analog/linking/max32690_cktpy.ld index 423bfc321168..e80a14d53c90 100644 --- a/ports/analog/linking/max32690_cktpy.ld +++ b/ports/analog/linking/max32690_cktpy.ld @@ -1,38 +1,51 @@ MEMORY { ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M - FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 16K - FLASH_FS (rw) : ORIGIN = 0x10004000, LENGTH = 64K - FLASH_FIRMWARE (rx) : ORIGIN = 0x10014000, LENGTH = 0x10030000 - 80K - RAM (rwx): ORIGIN = 0x20000000, LENGTH = 1M + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 2992K + FLASH_ISR (rx) : ORIGIN = 0x102EC000, LENGTH = 16K + FLASH_FS (rx) : ORIGIN = 0x102FC000, LENGTH = 64K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 1M } -/* FLASH FIRMWARE: 0x10300000 (end) - 0x10042000 = 0x002BE000 */ - -ENTRY(Reset_Handler) +/* Minimum flash page is 16K */ +/* FLASH FIRMWARE: 3072K [3MB] - 16K - 64K = 2992K */ SECTIONS { .rom : { - KEEP(*(.rom_vector)) - *(.rom_handlers*) + KEEP(*(.rom_vector*)) + KEEP(*(.rom_handlers*)) } > ROM + + /** FIXME: can't place this in its own section for some reason + * system doesn't exit ROM code unless *(.isr_vector) + * is placed in the beginning of .text, + * even if .text is moved upward and *(.isr_vector) is + * placed at 0x10000000. + **/ + /* Place ISR vector in a separate flash section */ - .isr_vector : - { - . = ALIGN(4); - /* Startup code */ - KEEP(*(.isr_vector*)) - } >FLASH_ISR + /* .isr_vector : */ + /* { */ + /* ISR Vector beginning of .text */ + /* KEEP(*(.isr_vector)) */ + /* KEEP(*(.isr_vector*)) */ + /* } > FLASH_ISR */ .text : { . = ALIGN(4); _text = .; - /* program code, exclude RISCV code */ - EXCLUDE_FILE (*riscv.o) *(.text*) + /* ISR Vector beginning of .text */ + /** fixme: may want to move this to FLASH_ISR long-term */ + KEEP(*(.isr_vector)) + KEEP(*(.isr_vector*)) + + . = ALIGN(4); + /* program code; exclude RISCV code */ + EXCLUDE_FILE (*riscv.o) *(.text*) *(.rodata*) /* read-only data: "const" */ KEEP(*(.init)) @@ -146,21 +159,21 @@ SECTIONS { * size of stack_dummy section */ __StackTop = ORIGIN(RAM) + LENGTH(RAM); __StackLimit = __StackTop - SIZEOF(.stack_dummy); + + _stack = __StackTop; _estack = __StackLimit; /* Provide _estack for CktPython */ .heap (COPY): { . = ALIGN(4); - __heap = .; + _heap = .; PROVIDE ( end = . ); PROVIDE ( _end = . ); *(.heap*) __HeapLimit = ABSOLUTE(__StackLimit); } > RAM - __eheap = __HeapLimit; - - PROVIDE(__stack = __StackTop); + _eheap = __HeapLimit; /* Check if data + heap + stack exceeds RAM limit */ ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack") diff --git a/ports/analog/mpconfigport.h b/ports/analog/mpconfigport.h index bb9f8b6ac368..cadfbddbc55b 100644 --- a/ports/analog/mpconfigport.h +++ b/ports/analog/mpconfigport.h @@ -12,11 +12,8 @@ #define MICROPY_PY_FUNCTION_ATTRS (1) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - -// 24kiB stack +// 24KiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 -// uint8_t _ld_default_stack_size; -// #define CIRCUITPY_DEFAULT_STACK_SIZE ((uint32_t)&_ld_default_stack_size) // Also includes mpconfigboard.h #include "py/circuitpy_mpconfig.h" diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index c4a6234f664e..b67622935183 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -15,7 +15,7 @@ INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 -# TODO: Review flash filesystem funcs before flashing +# TODO: TEST filesystem & general bringup! DISABLE_FILESYSTEM = 0 #################################################################################### @@ -24,60 +24,62 @@ DISABLE_FILESYSTEM = 0 # These modules are implemented in ports//common-hal: # Typically the first module to create -CIRCUITPY_MICROCONTROLLER = 1 +CIRCUITPY_MICROCONTROLLER ?= 1 # Typically the second module to create -CIRCUITPY_DIGITALIO = 0 -# Other modules: -CIRCUITPY_ANALOGIO = 0 -CIRCUITPY_BUSIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_NEOPIXEL_WRITE = 0 -CIRCUITPY_PULSEIO = 0 -CIRCUITPY_OS = 1 -CIRCUITPY_NVM = 0 -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_AUDIOIO = 0 -CIRCUITPY_ROTARYIO = 0 -#todo: implement time/date based on RTC sec/subsec -CIRCUITPY_RTC = 0 -CIRCUITPY_SDCARDIO = 0 -CIRCUITPY_FRAMEBUFFERIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CTARGET = 0 +CIRCUITPY_DIGITALIO ?= 0 + +# Plan to implement +CIRCUITPY_BUSIO ?= 0 +CIRCUITPY_OS ?= 1 +CIRCUITPY_RTC ?= 0 + +# Other modules (may or may not implement): +CIRCUITPY_ANALOGIO ?= 0 +CIRCUITPY_AUDIOBUSIO ?= 0 +CIRCUITPY_AUDIOIO ?= 0 +CIRCUITPY_COUNTIO ?= 0 +CIRCUITPY_NEOPIXEL_WRITE ?= 0 +CIRCUITPY_FREQUENCYIO ?= 0 +CIRCUITPY_I2CTARGET ?= 0 +CIRCUITPY_PULSEIO ?= 0 +CIRCUITPY_PWMIO ?= 0 +CIRCUITPY_NVM ?= 0 +CIRCUITPY_ROTARYIO ?= 0 +CIRCUITPY_SDCARDIO ?= 0 +CIRCUITPY_FRAMEBUFFERIO ?= 0 # Requires SPI, PulseIO (stub ok): -CIRCUITPY_DISPLAYIO = 0 +CIRCUITPY_DISPLAYIO ?= 0 # These modules are implemented in shared-module/ - they can be included in # any port once their prerequisites in common-hal are complete. # Requires DigitalIO: -CIRCUITPY_BITBANGIO = 0 +CIRCUITPY_BITBANGIO ?= 0 # Requires neopixel_write or SPI (dotstar) -CIRCUITPY_PIXELBUF = 0 +CIRCUITPY_PIXELBUF ?= 0 # Requires OS -CIRCUITPY_RANDOM = 0 +CIRCUITPY_RANDOM ?= 0 # Requires OS, filesystem -CIRCUITPY_STORAGE = 0 +CIRCUITPY_STORAGE ?= 0 # Requires Microcontroller -CIRCUITPY_TOUCHIO = 0 -# Requires UART! -CIRCUITPY_CONSOLE_UART = 0 +CIRCUITPY_TOUCHIO ?= 0 +# Requires UART +CIRCUITPY_CONSOLE_UART ?= 0 # Requires USB -CIRCUITPY_USB_DEVICE = 0 -CIRCUITPY_USB_CDC = 0 -CIRCUITPY_USB_HID = 0 -CIRCUITPY_USB_MIDI = 0 +CIRCUITPY_USB_DEVICE ?= 0 +CIRCUITPY_USB_CDC ?= 0 +CIRCUITPY_USB_HID ?= 0 +CIRCUITPY_USB_MIDI ?= 0 # Does nothing without I2C CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 # No requirements, but takes extra flash CIRCUITPY_ULAB = 1 + #################################################################################### # Required for clean building (additional CircuittPython Defaults) #################################################################################### -# Enabled by default -CIRCUITPY_PWMIO = 0 + # Depends on BUSIO -# CIRCUITPY_BLEIO = 0 CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_BUSDEVICE = 0 diff --git a/ports/analog/mphalport.h b/ports/analog/mphalport.h index 8dba63d82ff0..5efd78736e78 100644 --- a/ports/analog/mphalport.h +++ b/ports/analog/mphalport.h @@ -10,8 +10,7 @@ #include "lib/oofatfs/ff.h" #include "supervisor/shared/tick.h" -// TODO: Define tick & other port functions -// Global millisecond tick count (driven by SysTick interrupt). +// Global millisecond tick count static inline mp_uint_t mp_hal_ticks_ms(void) { return supervisor_ticks_ms32(); } diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c index a8c10076d3bf..97fe21d4a52c 100644 --- a/ports/analog/supervisor/internal_flash.c +++ b/ports/analog/supervisor/internal_flash.c @@ -26,11 +26,11 @@ #include "mxc_device.h" /** TODO: - * - Verify all necessary Filesystem MACROs are defined in mpconfigport.h + * Test! * * NOTE: * ANY function which modifies flash contents must execute from a crit section. - * This is because FLC functions are loc'd in RAM, and any ISR executing + * This is because FLC functions are loc'd in RAM, and an ISR executing * from Flash will trigger a HardFault. * * An alternative would be to initialize with NVIC_SetRAM(), @@ -54,10 +54,14 @@ typedef struct { } flash_layout_t; #ifdef MAX32690 +// struct layout is the actual layout of flash +// FS Code will use INTERNAL_FLASH_FILESYSTEM_START_ADDR +// and won't conflict with ISR vector in first 16 KiB of flash static const flash_layout_t flash_layout[] = { - { 0x1000000, 0x4000, 192}, - { 0x1030000, 0x2000, 32 }, + { 0x10000000, 0x4000, 192}, + // { 0x10300000, 0x2000, 32 }, // RISC-V flash }; +// Cache a full 16K sector static uint8_t _flash_cache[0x4000] __attribute__((aligned(4))); #endif @@ -65,12 +69,13 @@ static uint8_t _flash_cache[0x4000] __attribute__((aligned(4))); static uint32_t _cache_addr_in_flash = NO_CACHE; static inline int32_t block2addr(uint32_t block) { - if (block > 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { + if (block >= 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; } else return -1; } +// Get index, start addr, & size of the flash sector where addr lies int flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { // This function should return -1 in the event of errors. if (addr >= flash_layout[0].base_addr) { @@ -78,17 +83,24 @@ int flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { if (MP_ARRAY_SIZE(flash_layout) == 1) { sector_index = (addr - flash_layout[0].base_addr) / flash_layout[0].sector_size; if (sector_index >= flash_layout[0].num_sectors) { - return -1; + return -1; // addr is not in flash } if (start_addr) { *start_addr = flash_layout[0].base_addr + (sector_index * flash_layout[0].sector_size); } + else { + return -1; // start_addr is NULL + } if (size) { *size = flash_layout[0].sector_size; } + else { + return -1; //size is NULL + } return sector_index; } + // algorithm for multiple flash sections for (uint8_t i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) { for (uint8_t j = 0; j < flash_layout[i].num_sectors; ++j) { uint32_t sector_start_next = flash_layout[i].base_addr @@ -123,7 +135,7 @@ uint32_t supervisor_flash_get_block_count(void) { return INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS; } -// Flush the flash page that is currently cached +// Write back to Flash the page that is currently cached void port_internal_flash_flush(void) { // Flash has not been cached if (_cache_addr_in_flash == NO_CACHE) { @@ -186,10 +198,11 @@ void port_internal_flash_flush(void) { // Lock flash & exit MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; - } - + } // finished flushing cache + // todo: verify no other flash operation (e.g. flushing HW cache) is needed to complete this } +// Read flash blocks, using cache if it contains the right data mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { // Find the address of the block we want to read int src_addr = block2addr(block); @@ -208,9 +221,10 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n uint32_t blocks_in_sector = (sector_size - (src_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; // If the whole read is inside the cache, then read cache - if (num_blocks <= blocks_in_sector && _cache_addr_in_flash == sector_start) { + if ( (num_blocks <= blocks_in_sector) && (_cache_addr_in_flash == sector_start) ) { memcpy(dest, (_flash_cache + (src_addr - sector_start)), FILESYSTEM_BLOCK_SIZE * num_blocks); } else { + // flush the cache & read the flash data directly supervisor_flash_flush(); /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking * than memcpy does. Will use it for now. @@ -220,6 +234,9 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n return 0; // success } +// Write to flash blocks, using cache if it is targeting the right page (and large enough) +// todo: most of this fn is taken from the ST driver. +// todo: look at other ports and see if I can adapt it at all mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { uint32_t count=0; uint32_t sector_size=0; @@ -251,7 +268,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, // if we're not at the start of a sector, copy the whole sector to cache if (_cache_addr_in_flash != sector_start) { - // Flush cache first + // Flush cache first before we overwrite it supervisor_flash_flush(); _cache_addr_in_flash = sector_start; @@ -270,10 +287,13 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, return 0; // success } +// Empty the fs cache void supervisor_flash_release_cache(void) { - // Flush the cache for ARM M4 + // Invalidate the current FS cache + _cache_addr_in_flash = NO_CACHE; + + // Flush the hardware cache for ARM M4 MXC_ICC_Flush(MXC_ICC0); - MXC_ICC_Flush(MXC_ICC1); // Clear the line fill buffer by reading 2 pages from flash volatile uint32_t *line_addr; @@ -283,7 +303,4 @@ void supervisor_flash_release_cache(void) { line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE + MXC_FLASH_PAGE_SIZE); line = *line_addr; (void)line; // Silence build warnings that this variable is not used. - - // Invalidate the current cache - _cache_addr_in_flash = NO_CACHE; } diff --git a/ports/analog/supervisor/internal_flash.h b/ports/analog/supervisor/internal_flash.h index ef944fbffed5..1b4091e9a4fd 100644 --- a/ports/analog/supervisor/internal_flash.h +++ b/ports/analog/supervisor/internal_flash.h @@ -6,11 +6,4 @@ #include "py/mpconfig.h" -/** Sections defined in linker files under "linking" */ -#ifdef MAX32690 -#define MAX32_FLASH_SIZE 0x300000 // 3 MB -#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64K -#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10040000 // Load into the last MB of code/data storage??? -#endif - #define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) diff --git a/ports/analog/tools/connect-gdb.txt b/ports/analog/tools/connect-gdb.txt new file mode 100644 index 000000000000..ced4bdf6af3a --- /dev/null +++ b/ports/analog/tools/connect-gdb.txt @@ -0,0 +1,16 @@ +For connecting GDB... + +// Set symbol & exec to .elf +arm-none-eabi-gdb --se=build-APARD/firmware.elf + +// connect to remote on local machine TCP port :3333 +target extended-remote localhost:3333 + +// reset halt the MCU +monitor reset halt + +// set a breakpoint on main & hit it +b main +continue + +// now...time to mess around! diff --git a/ports/analog/tools/flash-halt-openocd.bat b/ports/analog/tools/flash-halt-openocd.bat new file mode 100644 index 000000000000..ae30cdff0b97 --- /dev/null +++ b/ports/analog/tools/flash-halt-openocd.bat @@ -0,0 +1,5 @@ +:: Flash the target MCU via OpenOCD, +:: then reset halt to prepare for gdb connection +:: waits for gdb connection on localhost port 3333; see connect-gdb.txt for more info +:: leave this process open if you're connecting gdb +openocd -s $MAXIM_PATH/Tools/OpenOCD/scripts -f interface/cmsis-dap.cfg -f target/max32690.cfg -c "program build-APARD/firmware.elf verify; init; reset halt" diff --git a/ports/analog/tools/flash_max32.jlink b/ports/analog/tools/flash_max32.jlink new file mode 100644 index 000000000000..4c9cbacb96fe --- /dev/null +++ b/ports/analog/tools/flash_max32.jlink @@ -0,0 +1,6 @@ +si 1 +erase +loadbin build-APARD/firmware.bin 0x10000000 +r +g +exit From 426288e217ca9016571f454009438061c7f3902f Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 20 Aug 2024 13:32:18 -0700 Subject: [PATCH 004/252] - Fixed stack & heap variables from linkerscript causing HardFaults. Placed in supervisor/port.c - Moved LEDs & PBs from supervisor/port.c to boards/$(BOARD)/board.c for APARD - Reviewed Processor.c in common-hal/microcontroller - Prepared stubs for common-hal/microcontroller/Pin.c --- ports/analog/boards/APARD/board.c | 37 +++++++++++- ports/analog/boards/APARD/mpconfigboard.mk | 7 ++- ports/analog/common-hal/microcontroller/Pin.c | 51 ++++++++++++---- .../common-hal/microcontroller/Processor.c | 14 +++-- .../common-hal/microcontroller/__init__.c | 23 ++++---- ports/analog/{supervisor => }/max32_port.h | 12 +++- ports/analog/supervisor/port.c | 58 ++++++------------- 7 files changed, 129 insertions(+), 73 deletions(-) rename ports/analog/{supervisor => }/max32_port.h (85%) diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c index cd69f369579a..a075ec67d501 100644 --- a/ports/analog/boards/APARD/board.c +++ b/ports/analog/boards/APARD/board.c @@ -5,6 +5,24 @@ // SPDX-License-Identifier: MIT #include "supervisor/board.h" +#include "supervisor/port.h" +#include "mpconfigboard.h" +#include "max32_port.h" + +// Board-level setup for MAX32690 +// clang-format off +const mxc_gpio_cfg_t pb_pin[] = { + { MXC_GPIO1, MXC_GPIO_PIN_27, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, +}; +const int num_pbs = (sizeof(pb_pin) / sizeof(mxc_gpio_cfg_t)); + +const mxc_gpio_cfg_t led_pin[] = { + { MXC_GPIO2, MXC_GPIO_PIN_1, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO0, MXC_GPIO_PIN_11, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO0, MXC_GPIO_PIN_12, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, +}; +const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); +// clang-format on // DEFAULT: Using the weak-defined supervisor/shared/board.c functions @@ -15,7 +33,23 @@ // bool board_requests_safe_mode(void); // Initializes board related state once on start up. -// void board_init(void); +void board_init(void) { + // Enable GPIO (enables clocks + common init for ports) + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + MXC_GPIO_Init(0x1 << i); + } + + // Init Board LEDs + /* setup GPIO for the LED */ + for (int i = 0; i < num_leds; i++) { + // Set the output value + MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); + MXC_GPIO_Config(&led_pin[i]); + } + + // Turn on one LED to indicate Sign of Life + MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); +} // Reset the state of off MCU components such as neopixels. // void reset_board(void); @@ -24,4 +58,5 @@ // state. It should not prevent the user access method from working (such as // disabling USB, BLE or flash) because CircuitPython may continue to run. // void board_deinit(void); + /*******************************************************************/ diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index 7e5465e69422..874c3c14e394 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -5,13 +5,18 @@ # SPDX-License-Identifier: MIT INTERNAL_FLASH_FILESYSTEM = 1 -# FLASH: 0x10000000 to 0x10340000 +# FLASH: 0x10000000 to 0x10300000 (ARM) # SRAM: 0x20000000 to 0x20100000 USB_PRODUCT = "MAX32690 APARD" USB_MANUFACTURER = "Analog Devices, Inc." + +# NOTE: Not implementing external flash for now # CFLAGS+=-DEXT_FLASH_MX25 +# define 13 bytes UID for memory safety (buffer gets passed as a raw ptr) +COMMON_HAL_MCU_PROCESSOR_UID_LENGTH = 13 + MCU_SERIES=max32 MCU_VARIANT=max32690 diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index bc1ef9d70efc..6826b18e036f 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -2,33 +2,62 @@ #include #include "shared-bindings/microcontroller/Pin.h" -// #include "shared-bindings/digitalio/DigitalInOut.h" +#include "mpconfigboard.h" +#include "pins.h" +#include "mxc_sys.h" +#include "max32690.h" +#include "gpio.h" -// #include "gpio.h" - - -//FIXME: Implement void reset_all_pins(void) { - return; + // todo: this is not a good method for this long-term + // Pins should be individually reset to account for never_reset pins like SWD + for (int i = 0; i < NUM_GPIO_PORTS; i++) { + MXC_GPIO_Reset(i); + } } -// FIXME: Implement +// todo: Implement void reset_pin_number(uint8_t pin) { - return; } -// FIXME: Implement +// todo: Implement void claim_pin(const mcu_pin_obj_t *pin) { return; } -// FIXME: Implement +// todo: Implement bool pin_number_is_free(uint8_t pin_number) { return true; } -// FIXME: Implement + +// todo: Implement void never_reset_pin_number(uint8_t pin_number) { return; } + +//todo: implement +uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { + return 0; +} + +// todo: implement +bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { + return true; +} + +void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { +} + +void common_hal_reset_pin(const mcu_pin_obj_t *pin) { +} + +void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { +} + +void common_hal_mcu_pin_claim_number(uint8_t pin_no) { +} + +void common_hal_mcu_pin_reset_number(uint8_t pin_no) { +} diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c index 1bdcceeeb74c..339770f9fd24 100644 --- a/ports/analog/common-hal/microcontroller/Processor.c +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -10,14 +10,15 @@ #include "common-hal/microcontroller/Processor.h" #include "shared-bindings/microcontroller/ResetReason.h" -#include "system_max32690.h" +#include "max32_port.h" -// +// No means of getting core temperature for currently supported devices float common_hal_mcu_processor_get_temperature(void) { return NAN; } -// TODO: Determine if there's a means of getting core voltage +// MAX32690 can measure VCORE +// TODO: (low prior.) Implement ADC API under "peripherals" and use API to measure VCORE float common_hal_mcu_processor_get_voltage(void) { return NAN; } @@ -26,11 +27,16 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { return SystemCoreClock; } +// NOTE: COMMON_HAL_MCU_PROCESSOR_UID_LENGTH is defined in mpconfigboard.h +// Use this per device to make sure raw_id is an appropriate minimum number of bytes void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { + MXC_SYS_GetUSN(raw_id, NULL); // NULL checksum will not be verified by AES return; } -// TODO: May need to add reset reason in alarm / deepsleep cases mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { + #if CIRCUITPY_ALARM + // TODO: (low prior.) add reset reason in alarm / deepsleep cases (should require alarm peripheral API in "peripherals") + #endif return RESET_REASON_UNKNOWN; } diff --git a/ports/analog/common-hal/microcontroller/__init__.c b/ports/analog/common-hal/microcontroller/__init__.c index f15ef9bcecc3..aff2dc2fd497 100644 --- a/ports/analog/common-hal/microcontroller/__init__.c +++ b/ports/analog/common-hal/microcontroller/__init__.c @@ -22,24 +22,20 @@ #include "max32690.h" +#include "mxc_delay.h" + /** NOTE: It is not advised to directly include the below! * These are includes taken care of by the core cmsis file. * e.g. "max32690.h". Since CMSIS is compiled as lib, these are * included there as for example. */ -// #include "core_cmFunc.h" // For enable/disable interrupts -// #include "core_cm4.h" // For NVIC_SystemReset -// #include "core_cmInstr.h" // For __DMB Data Memory Barrier +// #include // For enable/disable interrupts +// #include // For NVIC_SystemReset +// #include // For __DMB Data Memory Barrier (flush DBUS activity) void common_hal_mcu_delay_us(uint32_t delay) { - // uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq() / 1000000UL; - // delay *= ticks_per_us; - // SysTick->VAL = 0UL; - // SysTick->LOAD = delay; - // SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; - // while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) { - // } - // SysTick->CTRL = 0UL; + + MXC_Delay(MXC_DELAY_USEC(delay)); } volatile uint32_t nesting_count = 0; @@ -59,7 +55,7 @@ void common_hal_mcu_enable_interrupts(void) { if (nesting_count > 0) { return; } - __DMB(); + __DMB(); // flush internal DBUS before proceeding __enable_irq(); } @@ -75,7 +71,6 @@ void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { } void common_hal_mcu_reset(void) { - if (next_reset_to_bootloader) { reset_to_bootloader(); } else { @@ -398,6 +393,8 @@ static const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { }; MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table); + +/** NOTE: Not implemented yet */ // #if CIRCUITPY_INTERNAL_NVM_SIZE > 0 // // The singleton nvm.ByteArray object. // const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { diff --git a/ports/analog/supervisor/max32_port.h b/ports/analog/max32_port.h similarity index 85% rename from ports/analog/supervisor/max32_port.h rename to ports/analog/max32_port.h index 25641a5dddbc..ec6d29ad80f8 100644 --- a/ports/analog/supervisor/max32_port.h +++ b/ports/analog/max32_port.h @@ -4,10 +4,18 @@ #include -#include "mxc_sys.h" +#include "mxc_assert.h" +#include "mxc_delay.h" +#include "mxc_device.h" #include "mxc_pins.h" +#include "mxc_sys.h" + #include "gpio.h" -#include "mxc_assert.h" + +#ifdef MQAX32690 +#include "system_max32690.h" +#include "max32690.h" +#endif /** Linker variables defined.... * _estack: end of the stack diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index fd6bc1806aeb..21f4b6504cca 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -47,26 +47,19 @@ #include "mxc_delay.h" #include "rtc.h" +// Externs defined by linker .ld file +extern uint32_t _stack, _heap, _estack, _eheap; +extern uint32_t _ebss; + +// From boards/$(BOARD)/board.c +extern const mxc_gpio_cfg_t pb_pin[]; +extern const int num_pbs; +extern const mxc_gpio_cfg_t led_pin[]; +extern const int num_leds; + //todo: define an LED HAL // #include "peripherals/led.h" -#ifdef MAX32690 -// Board-level setup for MAX32690 -// clang-format off -const mxc_gpio_cfg_t pb_pin[] = { - { MXC_GPIO1, MXC_GPIO_PIN_27, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, -}; -const unsigned int num_pbs = (sizeof(pb_pin) / sizeof(mxc_gpio_cfg_t)); - -const mxc_gpio_cfg_t led_pin[] = { - { MXC_GPIO2, MXC_GPIO_PIN_1, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, - { MXC_GPIO0, MXC_GPIO_PIN_11, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, - { MXC_GPIO0, MXC_GPIO_PIN_12, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, -}; -const unsigned int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); -// clang-format on -#endif - // For caching rtc data for ticks static uint32_t subsec, sec = 0; @@ -96,7 +89,7 @@ safe_mode_t port_init(void) { } // Turn on one LED to indicate Sign of Life - MXC_GPIO_OutSet(led_pin[0].port, led_pin[0].mask); + MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); // Init RTC w/ 0sec, 0subsec // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s @@ -120,23 +113,9 @@ void reset_cpu(void) { // Reset MCU state void reset_port(void) { - int err; - // Reset GPIO Ports - // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ - err = MXC_GPIO_Reset(0x1 << i); - if (err) { - // todo: indicate some gpio error - continue; - } - } - - // TODO: Reset peripheral clocks + reset_all_pins(); - // Reset 1/1024 tick timer - MXC_RTC_Stop(); - MXC_RTC_ClearFlags(0xFFFFFFFF); - MXC_RTC_Init(0,0); + // todo: may need rtc-related resets here later } // Reset to the bootloader @@ -154,22 +133,19 @@ void reset_to_bootloader(void) { * Return variables defined by linkerscript. */ uint32_t *port_stack_get_limit(void) { - // ignore array bounds GCC warnings for stack here + // ignore array bounds GCC warnings #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" // NOTE: Only return how much stack we have alloted for CircuitPython - return (uint32_t *)(port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t)); - // return _estack; - - // end GCC diagnostic disable + return port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t); #pragma GCC diagnostic pop } uint32_t *port_stack_get_top(void) { - return (uint32_t *)__stack; + return &_stack; } uint32_t *port_heap_get_bottom(void) { - return (uint32_t *)__heap; + return &_heap; } uint32_t *port_heap_get_top(void) { return port_stack_get_limit(); From 79ed8ab8793f4015f57bc71f1a7c7ab5b4de50d8 Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Fri, 23 Aug 2024 14:39:44 -0700 Subject: [PATCH 005/252] -Added USB via tinyUSB. Still need to test/debug before REPL is ready. - Enabled USB-based modules & dependencies in mpconfigport.mk --- ports/analog/Makefile | 19 +++- ports/analog/README.md | 3 +- ports/analog/boards/APARD/board.c | 13 +++ ports/analog/boards/APARD/mpconfigboard.mk | 9 +- ports/analog/common-hal/microcontroller/Pin.c | 96 ++++++++++++++----- ports/analog/common-hal/microcontroller/Pin.h | 5 +- ports/analog/mpconfigport.mk | 24 ++--- ports/analog/supervisor/usb.c | 40 ++++++++ 8 files changed, 160 insertions(+), 49 deletions(-) create mode 100644 ports/analog/supervisor/usb.c diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 151299a8792a..7a684711546d 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -166,17 +166,30 @@ else COPT += -O0 #opt completely off to start endif - # TinyUSB CFLAGS +ifeq ($(CIRCUITPY_TINYUSB),1) CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \ -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \ + -DCFG_TUSB_OS=OPT_OS_NONE \ + -DCFG_TUD_TASK_QUEUE_SZ=32 -# TODO: Add for TinyUSB once our PR goes through for MAX32 devices -# Add TinyUSB +# Add TinyUSB sources INC += -I../../lib/tinyusb/src INC += -I../../supervisor/shared/usb SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c +endif + +ifeq ($(CIRCUITPY_USB_DEVICE),1) +CFLAGS += \ + -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ + -DCFG_TUD_CDC_TX_BUFSIZE=1024 \ + -DCFG_TUD_MSC_BUFSIZE=4096 \ + -DCFG_TUD_MIDI_RX_BUFSIZE=128 \ + -DCFG_TUD_MIDI_TX_BUFSIZE=128 \ + -DCFG_TUD_VENDOR_RX_BUFSIZE=128 \ + -DCFG_TUD_VENDOR_TX_BUFSIZE=128 +endif SRC_C += \ boards/$(BOARD)/board.c \ diff --git a/ports/analog/README.md b/ports/analog/README.md index 603a22f9fd4b..1650fad1cac5 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -9,7 +9,8 @@ This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. Thes - **`linking/:`** Linkerfiles customized for CircuitPython. These are distinct from the linkerfiles used in MSDK as they adopt the structure required by CircuitPython. They may also omit unused features and memory sections, e.g. Mailboxes, RISC-V Flash, & Hyperbus RAM for MAX32690. - **`msdk:/`** SDK for MAX32 devices. More info on our GitHub: [Analog Devices MSDK GitHub](https://github.com/analogdevicesinc/msdk) - **`peripherals:/`** Helper files for peripherals such as clocks, gpio, etc. These files tend to be specific to vendor SDKs and provide some useful functions for the common-hal interfaces. -- **`supervisor/:`** Implementation files for the CircuitPython supervisor. This includes port setup, usb, and a filesystem on a storage medium such as SD Card/eMMC, QSPI Flash, or internal flash memory. Currently the internal flash is used. +- **`supervisor/:`** Implementation files for the CircuitPython supervisor. This includes port setup, usb, and a filesystem on a storage medium such as SD Card/eMMC, QSPI Flash, or internal flash memory. Currently the internal flash is used. This folder is the most important part of a port's core functionality for CircuitPython. +- **`supervisor/port.c:`** Port-specific startup code including clock initialization, console startup, etc. - `. :` Build system and high-level interface to the CircuitPython core for the ADI port. diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c index a075ec67d501..972bdcee6f8c 100644 --- a/ports/analog/boards/APARD/board.c +++ b/ports/analog/boards/APARD/board.c @@ -32,8 +32,21 @@ const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); // way. // bool board_requests_safe_mode(void); +volatile uint32_t system_ticks = 0; + +void SysTick_Handler(void) { + system_ticks++; +} + +uint32_t board_millis(void) { + return system_ticks; +} + // Initializes board related state once on start up. void board_init(void) { + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000);\ + // Enable GPIO (enables clocks + common init for ports) for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ MXC_GPIO_Init(0x1 << i); diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index 874c3c14e394..16c8ac72581d 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -8,8 +8,13 @@ INTERNAL_FLASH_FILESYSTEM = 1 # FLASH: 0x10000000 to 0x10300000 (ARM) # SRAM: 0x20000000 to 0x20100000 -USB_PRODUCT = "MAX32690 APARD" -USB_MANUFACTURER = "Analog Devices, Inc." +USB_MANUFACTURER="Analog Devices, Inc." +USB_PRODUCT="MAX32690 APARD" + +# Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim +USB_VID=0x0456 +# USB_VID=0x0B6A +USB_PID=0x003C # NOTE: Not implementing external flash for now # CFLAGS+=-DEXT_FLASH_MX25 diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 6826b18e036f..e11c9413c907 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -8,56 +8,104 @@ #include "mxc_sys.h" #include "max32690.h" #include "gpio.h" +#include "gpio_regs.h" + +// Structs to represent GPIO ports & valid pins/pads +#ifdef MAX32690 +// todo: special constraints are applied to GPIO4 for MAX32690. Tend to these later (low prior) +static mxc_gpio_regs_t* ports[NUM_GPIO_PORTS] = { MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3}; +#endif + +static uint32_t claimed_pins[NUM_GPIO_PORTS]; +static uint32_t never_reset_pins[NUM_GPIO_PORTS]; + +#define INVALID_PIN 0xFF // id for invalid pin void reset_all_pins(void) { - // todo: this is not a good method for this long-term - // Pins should be individually reset to account for never_reset pins like SWD + // reset all pins except for never_reset_pins for (int i = 0; i < NUM_GPIO_PORTS; i++) { - MXC_GPIO_Reset(i); + for (int j = 0; j < 32; j++) { + if (!(never_reset_pins[i] & (1 << j))) { + reset_pin_number(i, j); + } + } + // set claimed pins to never_reset pins + claimed_pins[i] = never_reset_pins[i]; } } -// todo: Implement -void reset_pin_number(uint8_t pin) { -} +void reset_pin_number(uint8_t pin_port, uint8_t pin_pad) { + if (pin_port == INVALID_PIN || pin_port > NUM_GPIO_PORTS) { + return; + } -// todo: Implement -void claim_pin(const mcu_pin_obj_t *pin) { - return; -} + uint32_t mask = 1 << (pin_pad); -// todo: Implement -bool pin_number_is_free(uint8_t pin_number) { - return true; -} + /** START: RESET LOGIC for GPIOs */ + // Switch to I/O mode first + ports[pin_port]->en0_set = mask; + + // set GPIO configuration enable bits to I/O + ports[pin_port]->en0_clr = mask; + ports[pin_port]->en1_clr = mask; + ports[pin_port]->en2_clr = mask; + + // enable input mode GPIOn_INEN.pin = 1 + ports[pin_port]->inen |= mask; + + // High Impedance mode enable (GPIOn_PADCTRL1 = 0, _PADCTRL0 = 0), pu/pd disable + ports[pin_port]->padctrl0 &= ~mask; + ports[pin_port]->padctrl1 &= ~mask; + // Output mode disable GPIOn_OUTEN = 0 + ports[pin_port]->outen |= mask; -// todo: Implement -void never_reset_pin_number(uint8_t pin_number) { - return; + // Interrupt disable GPIOn_INTEN = 0 + ports[pin_port]->inten &= ~mask; + /** END: RESET LOGIC for GPIOs */ } -//todo: implement uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { - return 0; + if (pin == NULL) { + return INVALID_PIN; + } + + // most max32 gpio ports have 32 pins + // todo: create a struct to encode # of pins for each port, since some GPIO ports differ + return pin->port * 32 + pin->pad; } -// todo: implement bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { - return true; + if (pin == NULL) { + return true; + } + return !(claimed_pins[pin->port] & (pin->pad)); } void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { + if ((pin != NULL) && (pin->pad != INVALID_PIN)) { + never_reset_pins[pin->port] |= (1 << pin->pad); + + // any never reset pin must also be claimed + claimed_pins[pin->port] |= (1 << pin->pad); + } } void common_hal_reset_pin(const mcu_pin_obj_t *pin) { -} + if (pin == NULL) { + return; + } -void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { + reset_pin_number(pin->port, pin->pad); } -void common_hal_mcu_pin_claim_number(uint8_t pin_no) { +void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { + if (pin == NULL) { + return; + } + claimed_pins[pin->port] |= (1 << pin->pad); } void common_hal_mcu_pin_reset_number(uint8_t pin_no) { + reset_pin_number(pin_no / 32, pin_no & 32); } diff --git a/ports/analog/common-hal/microcontroller/Pin.h b/ports/analog/common-hal/microcontroller/Pin.h index 6089a94e0c11..55d4081f3a6b 100644 --- a/ports/analog/common-hal/microcontroller/Pin.h +++ b/ports/analog/common-hal/microcontroller/Pin.h @@ -8,7 +8,4 @@ void reset_all_pins(void); // reset_pin_number takes the pin number instead of the pointer so that objects don't // need to store a full pointer. -void reset_pin_number(uint8_t pin); -void claim_pin(const mcu_pin_obj_t *pin); -bool pin_number_is_free(uint8_t pin_number); -void never_reset_pin_number(uint8_t pin_number); +void reset_pin_number(uint8_t pin_port, uint8_t pin_pad); diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index b67622935183..689ae445b7fe 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -15,22 +15,27 @@ INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 -# TODO: TEST filesystem & general bringup! +# TODO: Test/Debug fs & general bringup DISABLE_FILESYSTEM = 0 +# TODO: Test/Debug TinyUSB! +# Builds clean; need to test +CIRCUITPY_TINYUSB = 1 +CIRCUITPY_USB_DEVICE ?= 1 +CIRCUITPY_USB_CDC ?= 1 +CIRCUITPY_USB_HID ?= 0 +CIRCUITPY_USB_MIDI ?= 0 + #################################################################################### # Suggested config for first-time porting #################################################################################### # These modules are implemented in ports//common-hal: -# Typically the first module to create -CIRCUITPY_MICROCONTROLLER ?= 1 # Typically the second module to create CIRCUITPY_DIGITALIO ?= 0 # Plan to implement CIRCUITPY_BUSIO ?= 0 -CIRCUITPY_OS ?= 1 CIRCUITPY_RTC ?= 0 # Other modules (may or may not implement): @@ -58,17 +63,10 @@ CIRCUITPY_BITBANGIO ?= 0 CIRCUITPY_PIXELBUF ?= 0 # Requires OS CIRCUITPY_RANDOM ?= 0 -# Requires OS, filesystem -CIRCUITPY_STORAGE ?= 0 # Requires Microcontroller CIRCUITPY_TOUCHIO ?= 0 # Requires UART CIRCUITPY_CONSOLE_UART ?= 0 -# Requires USB -CIRCUITPY_USB_DEVICE ?= 0 -CIRCUITPY_USB_CDC ?= 0 -CIRCUITPY_USB_HID ?= 0 -CIRCUITPY_USB_MIDI ?= 0 # Does nothing without I2C CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 @@ -83,7 +81,3 @@ CIRCUITPY_ULAB = 1 CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_BUSDEVICE = 0 - -# TinyUSB will be added later. -CIRCUITPY_TINYUSB = 0 -CIRCUITPY_PYUSB = 0 diff --git a/ports/analog/supervisor/usb.c b/ports/analog/supervisor/usb.c new file mode 100644 index 000000000000..2fd1545bdb1b --- /dev/null +++ b/ports/analog/supervisor/usb.c @@ -0,0 +1,40 @@ + +#include "supervisor/usb.h" +#include "common-hal/microcontroller/Pin.h" + +#include "py/mpconfig.h" + +#include "lib/tinyusb/src/device/usbd.h" + +// max32 includes +#include "mxc_sys.h" +#include "gcr_regs.h" +#include "mcr_regs.h" + +void init_usb_hardware(void) { + // USB GPIOs are non-configurable on MAX32 devices + // No need to add them to the never_reset list for mcu/Pin API. + + // 1 ms SysTick initialized in board.c + // todo: consider moving SysTick initialization here? + + // Enable requisite clocks & power for USB + MXC_SYS_ClockSourceEnable(MXC_SYS_CLOCK_IPO); + MXC_MCR->ldoctrl |= MXC_F_MCR_LDOCTRL_0P9EN; + MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_USB); + MXC_SYS_Reset_Periph(MXC_SYS_RESET0_USB); + + // Supervisor calls TinyUSB's dcd_init, + // which initializes the USB PHY. + // Dep. on CIRCUITPY_TINYUSB and CIRCUITPY_USB_DEVICE + + // Interrupt enables are left to TUSB depending on the device class + // todo: confirm with testing! +} + +void USB_IRQHandler(void) +{ + // Schedules USB background callback + // appropriate to a given device class via TinyUSB lib + usb_irq_handler(0); +} From 94d0c99e61610d1a4f96e12416dca15fdfed1adb Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Mon, 26 Aug 2024 15:09:37 -0700 Subject: [PATCH 006/252] Fixed USB endpoint speed issue w/ configuration setting --- ports/analog/Makefile | 40 +++++++++++++--------- ports/analog/boards/APARD/mpconfigboard.mk | 12 ++++--- ports/analog/mpconfigport.mk | 1 - 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 7a684711546d..20ea99f5de62 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -82,7 +82,7 @@ INC += \ -I$(PERIPH_SRC)/ICC \ -I$(PERIPH_SRC)/TMR \ -I$(PERIPH_SRC)/RTC \ - -I$(PERIPH_SRC)/UART \ + -I$(PERIPH_SRC)/UART INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC @@ -116,12 +116,12 @@ SRC_MAX32 += \ $(PERIPH_SRC)/TMR/tmr_$(DIE_TYPE).c \ $(PERIPH_SRC)/UART/uart_common.c \ $(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \ - $(PERIPH_SRC)/UART/uart_revb.c \ + $(PERIPH_SRC)/UART/uart_revb.c SRC_C += $(SRC_MAX32) \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ - peripherals/$(MCU_VARIANT_LOWER)/pins.c \ + peripherals/$(MCU_VARIANT_LOWER)/pins.c # ******************************************************************************* ### Compiler & Linker Flags ### @@ -145,11 +145,11 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET_REV=0x4131 \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ - -DRISCV_LOAD=0 \ - # -DFLASH_ORIGIN=0x10000000 \ - # -DFLASH_SIZE=0x340000 \ - # -DSRAM_ORIGIN=0x20000000 \ - # -DSRAM_SIZE=0x100000 \ + -DRISCV_LOAD=0 +# -DFLASH_ORIGIN=0x10000000 \ +# -DFLASH_SIZE=0x340000 \ +# -DSRAM_ORIGIN=0x20000000 \ +# -DSRAM_SIZE=0x100000 CPU_CORE=cortex-m4 CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=softfp -mfpu=fpv4-sp-d16 @@ -171,8 +171,9 @@ ifeq ($(CIRCUITPY_TINYUSB),1) CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \ -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \ - -DCFG_TUSB_OS=OPT_OS_NONE \ - -DCFG_TUD_TASK_QUEUE_SZ=32 + -DCFG_TUSB_OS=OPT_OS_NONE + +# -DCFG_TUD_TASK_QUEUE_SZ=32 # Add TinyUSB sources INC += -I../../lib/tinyusb/src @@ -182,15 +183,20 @@ endif ifeq ($(CIRCUITPY_USB_DEVICE),1) CFLAGS += \ - -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ -DCFG_TUD_CDC_TX_BUFSIZE=1024 \ - -DCFG_TUD_MSC_BUFSIZE=4096 \ - -DCFG_TUD_MIDI_RX_BUFSIZE=128 \ - -DCFG_TUD_MIDI_TX_BUFSIZE=128 \ - -DCFG_TUD_VENDOR_RX_BUFSIZE=128 \ - -DCFG_TUD_VENDOR_TX_BUFSIZE=128 + -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ + -DCFG_TUD_MSC_BUFSIZE=4096 endif +ifdef CIRCUITPY_USB_VENDOR +CFLASGS += \ + -DCFG_TUD_VENDOR_RX_BUFSIZE=1024 \ + -DCFG_TUD_VENDOR_TX_BUFSIZE=1024 +endif + +# -DCFG_TUD_MIDI_RX_BUFSIZE=128 +# -DCFG_TUD_MIDI_TX_BUFSIZE=128 + SRC_C += \ boards/$(BOARD)/board.c \ background.c \ @@ -208,7 +214,7 @@ CFLAGS += -Wno-error=unused-parameter \ -Wno-error=lto-type-mismatch \ -Wno-error=cast-align \ -Wno-error=nested-externs \ - -Wno-error=sign-compare \ + -Wno-error=sign-compare ENTRY = Reset_Handler LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index 16c8ac72581d..749c30465679 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -4,23 +4,25 @@ # # SPDX-License-Identifier: MIT -INTERNAL_FLASH_FILESYSTEM = 1 +INTERNAL_FLASH_FILESYSTEM=1 # FLASH: 0x10000000 to 0x10300000 (ARM) # SRAM: 0x20000000 to 0x20100000 -USB_MANUFACTURER="Analog Devices, Inc." -USB_PRODUCT="MAX32690 APARD" - # Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim USB_VID=0x0456 # USB_VID=0x0B6A USB_PID=0x003C +USB_MANUFACTURER="Analog Devices, Inc." +USB_PRODUCT="MAX32690 APARD" +# Num endpt pairs for a given device +USB_NUM_ENDPOINT_PAIRS=12 +USB_HIGHSPEED=1 # NOTE: Not implementing external flash for now # CFLAGS+=-DEXT_FLASH_MX25 # define 13 bytes UID for memory safety (buffer gets passed as a raw ptr) -COMMON_HAL_MCU_PROCESSOR_UID_LENGTH = 13 +COMMON_HAL_MCU_PROCESSOR_UID_LENGTH=13 MCU_SERIES=max32 MCU_VARIANT=max32690 diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 689ae445b7fe..0fb490cc150b 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -7,7 +7,6 @@ CHIP_FAMILY ?= max32 # Necessary to build CircuitPython -USB_NUM_ENDPOINT_PAIRS ?= 0 LONGINT_IMPL ?= MPZ INTERNAL_LIBM ?= 1 From 3b4638e3557f64627c7278332f17dc64d97699ae Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Mon, 2 Sep 2024 13:22:06 -0700 Subject: [PATCH 007/252] Fixed some RTC alarm setup issues; tick interrupts now function as expected. --- ports/analog/boards/APARD/mpconfigboard.mk | 17 ++- ports/analog/max32_port.h | 5 +- ports/analog/mpconfigport.mk | 4 +- ports/analog/supervisor/port.c | 132 +++++++++++---------- ports/analog/tools/connect-gdb.txt | 16 --- ports/analog/tools/flash-halt-openocd.bat | 5 - 6 files changed, 83 insertions(+), 96 deletions(-) delete mode 100644 ports/analog/tools/connect-gdb.txt delete mode 100644 ports/analog/tools/flash-halt-openocd.bat diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index 749c30465679..e49d695761c3 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -4,27 +4,26 @@ # # SPDX-License-Identifier: MIT +MCU_SERIES=max32 +MCU_VARIANT=max32690 + INTERNAL_FLASH_FILESYSTEM=1 # FLASH: 0x10000000 to 0x10300000 (ARM) # SRAM: 0x20000000 to 0x20100000 +#### USB CONFIGURATION # Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim USB_VID=0x0456 # USB_VID=0x0B6A USB_PID=0x003C USB_MANUFACTURER="Analog Devices, Inc." USB_PRODUCT="MAX32690 APARD" -# Num endpt pairs for a given device USB_NUM_ENDPOINT_PAIRS=12 USB_HIGHSPEED=1 +### + +# define UID len for memory safety (buffer gets passed as a raw ptr) +COMMON_HAL_MCU_PROCESSOR_UID_LENGTH=30 # NOTE: Not implementing external flash for now # CFLAGS+=-DEXT_FLASH_MX25 - -# define 13 bytes UID for memory safety (buffer gets passed as a raw ptr) -COMMON_HAL_MCU_PROCESSOR_UID_LENGTH=13 - -MCU_SERIES=max32 -MCU_VARIANT=max32690 - -CFLAGS += -DHAS_TRNG=1 diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index ec6d29ad80f8..214e975b719b 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -12,7 +12,7 @@ #include "gpio.h" -#ifdef MQAX32690 +#ifdef MAX32690 #include "system_max32690.h" #include "max32690.h" #endif @@ -33,7 +33,8 @@ extern uint32_t SystemCoreClock; #define TICKS_PER_SEC 1024 #ifdef MAX32690 -#define SUBSEC_PER_TICK 8 // 12-bit ssec register, ticks @ 4096 Hz +// 12-bit ssec register, ticks @ 4096 Hz +#define SUBSEC_PER_TICK 4 #endif #endif //MAX32_PORT_H diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 0fb490cc150b..f9b50477bc23 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -10,6 +10,9 @@ CHIP_FAMILY ?= max32 LONGINT_IMPL ?= MPZ INTERNAL_LIBM ?= 1 +# Req'd for OS; all max32 have TRNG +CFLAGS += -DHAS_TRNG=1 + INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 @@ -18,7 +21,6 @@ QSPI_FLASH_FILESYSTEM = 0 DISABLE_FILESYSTEM = 0 # TODO: Test/Debug TinyUSB! -# Builds clean; need to test CIRCUITPY_TINYUSB = 1 CIRCUITPY_USB_DEVICE ?= 1 CIRCUITPY_USB_CDC ?= 1 diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 21f4b6504cca..31a46b8de8b8 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -47,6 +47,11 @@ #include "mxc_delay.h" #include "rtc.h" +// msec to RTC subsec ticks (4 kHz) +#define MSEC_TO_SS_ALARM(x) \ + (0 - ((x * 4096) / \ + 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */ + // Externs defined by linker .ld file extern uint32_t _stack, _heap, _estack, _eheap; extern uint32_t _ebss; @@ -60,8 +65,9 @@ extern const int num_leds; //todo: define an LED HAL // #include "peripherals/led.h" -// For caching rtc data for ticks +// For saving rtc data for ticks static uint32_t subsec, sec = 0; +static uint32_t tick_flag = 0; // defined by cmsis core files extern void NVIC_SystemReset(void) NORETURN; @@ -91,20 +97,43 @@ safe_mode_t port_init(void) { // Turn on one LED to indicate Sign of Life MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); + // Enable clock to RTC peripheral + MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_ERTCO_EN; + while(!(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_ERTCO_RDY)); + + NVIC_EnableIRQ(RTC_IRQn); + NVIC_EnableIRQ(USB_IRQn); + // Init RTC w/ 0sec, 0subsec // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s - err = MXC_RTC_Init(0, 0); - if (err) { - return SAFE_MODE_SDK_FATAL_ERROR; - } - NVIC_EnableIRQ(RTC_IRQn); + while( MXC_RTC_Init(0,0) != E_SUCCESS ) {}; - // todo: init periph clocks / console here when ready + // enable 1 sec RTC SSEC alarm + MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); + MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(1000)); + MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); + + // Enable RTC + while ( MXC_RTC_Start() != E_SUCCESS ) {}; - MXC_RTC_Start(); return SAFE_MODE_NONE; } +void RTC_IRQHandler(void) { + // Read flags to clear + int flags = MXC_RTC_GetFlags(); + + if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) { + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); + } + + if (flags & MXC_F_RTC_CTRL_TOD_ALARM) { + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); + } + + tick_flag = 1; +} + // Reset the MCU completely void reset_cpu(void) { // includes MCU reset request + awaits on memory bus @@ -114,18 +143,15 @@ void reset_cpu(void) { // Reset MCU state void reset_port(void) { reset_all_pins(); - - // todo: may need rtc-related resets here later } // Reset to the bootloader // note: not implemented since max32 requires external stim ignals to // activate bootloaders -// todo: check if there's a method to jump to it void reset_to_bootloader(void) { NVIC_SystemReset(); while (true) { - asm ("nop;"); + __NOP(); } } @@ -169,7 +195,14 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { // Ensure we can read from ssec register as soon as we can // MXC function does cross-tick / busy checking of RTC controller __disable_irq(); - MXC_RTC_GetTime(&sec, &subsec); + if (MXC_RTC->ctrl & MXC_F_RTC_CTRL_EN) { + // NOTE: RTC_GetTime always returns BUSY if RTC is not running + while( (MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR ); + } + else { + sec = MXC_RTC->sec; + subsec = MXC_RTC->ssec; + } __enable_irq(); // Return ticks given total subseconds @@ -197,71 +230,44 @@ void port_disable_tick(void) { // Wake the CPU after a given # of ticks or sooner void port_interrupt_after_ticks(uint32_t ticks) { + uint32_t ticks_msec = 0; // Stop RTC & store current time & ticks port_disable_tick(); port_get_raw_ticks(NULL); - uint32_t target_sec = (ticks / TICKS_PER_SEC); - uint32_t target_ssec = (ticks - (target_sec * TICKS_PER_SEC)) * SUBSEC_PER_TICK; - - // Set up alarm configuration - // if alarm is greater than 1 s, - // use the ToD alarm --> resol. to closest second - // else - // use Ssec alarm --> resn. to 1/1024 s. (down to a full tick) - if (target_sec > 0) { - if (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | - MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { - // todo: signal some RTC error! - } + ticks_msec = 1000 * ticks / TICKS_PER_SEC; - if (MXC_RTC_SetTimeofdayAlarm(target_sec) != E_NO_ERROR) { - // todo: signal some RTC error! - } - if (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { - // todo: signal some RTC error! - } - } - else { - if (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | - MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { - // todo: signal some RTC error! - } + while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | + MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {}; - if (MXC_RTC_SetSubsecondAlarm(target_ssec) != E_NO_ERROR) { - // todo: signal some RTC error! - } - - if (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) { - // todo: signal some RTC error! - } - } - port_enable_tick(); -} + // Clear the flag to be set by the RTC Handler + tick_flag = 0; -void RTC_IRQHandler(void) { - // Read flags to clear - int flags = MXC_RTC_GetFlags(); + // Subsec alarm is the starting/reload value of the SSEC counter. + // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0 + while ( MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec) ) == E_BUSY) {} + while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {} - if (flags & MXC_F_RTC_CTRL_TOD_ALARM) { - MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); - while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {} - } + NVIC_EnableIRQ(RTC_IRQn); - if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) { - MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); - while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {} - } + port_enable_tick(); } void port_idle_until_interrupt(void) { - // Check if alarm triggers before we even got here - if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { - return; - } + #if CIRCUITPY_RTC + // Check if alarm triggers before we even got here + if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { + return; + } + #endif + // Interrupts should be disabled to ensure the ISR queue is flushed + // WFI still returns as long as the interrupt flag toggles; + // only when we re-enable interrupts will the ISR function trigger common_hal_mcu_disable_interrupts(); if (!background_callback_pending()) { + __DSB(); + /** DEBUG: may comment out WFI for debugging port functions */ __WFI(); } common_hal_mcu_enable_interrupts(); diff --git a/ports/analog/tools/connect-gdb.txt b/ports/analog/tools/connect-gdb.txt deleted file mode 100644 index ced4bdf6af3a..000000000000 --- a/ports/analog/tools/connect-gdb.txt +++ /dev/null @@ -1,16 +0,0 @@ -For connecting GDB... - -// Set symbol & exec to .elf -arm-none-eabi-gdb --se=build-APARD/firmware.elf - -// connect to remote on local machine TCP port :3333 -target extended-remote localhost:3333 - -// reset halt the MCU -monitor reset halt - -// set a breakpoint on main & hit it -b main -continue - -// now...time to mess around! diff --git a/ports/analog/tools/flash-halt-openocd.bat b/ports/analog/tools/flash-halt-openocd.bat deleted file mode 100644 index ae30cdff0b97..000000000000 --- a/ports/analog/tools/flash-halt-openocd.bat +++ /dev/null @@ -1,5 +0,0 @@ -:: Flash the target MCU via OpenOCD, -:: then reset halt to prepare for gdb connection -:: waits for gdb connection on localhost port 3333; see connect-gdb.txt for more info -:: leave this process open if you're connecting gdb -openocd -s $MAXIM_PATH/Tools/OpenOCD/scripts -f interface/cmsis-dap.cfg -f target/max32690.cfg -c "program build-APARD/firmware.elf verify; init; reset halt" From 1c0205d1a5e68227bdfe978a8e27d5be44f9d746 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 3 Sep 2024 09:33:41 -0700 Subject: [PATCH 008/252] Reorganized some build files & commented out WFI to debug USB. USB enumerates but has some issues starting interfaces for CDC/MSC/HID. --- ports/analog/Makefile | 30 +++++++++--------------------- ports/analog/mpconfigport.mk | 13 +++++++------ ports/analog/supervisor/port.c | 4 ++-- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 20ea99f5de62..7c3e1cb80117 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -167,36 +167,24 @@ COPT += -O0 #opt completely off to start endif # TinyUSB CFLAGS -ifeq ($(CIRCUITPY_TINYUSB),1) CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \ -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \ - -DCFG_TUSB_OS=OPT_OS_NONE - -# -DCFG_TUD_TASK_QUEUE_SZ=32 - -# Add TinyUSB sources -INC += -I../../lib/tinyusb/src -INC += -I../../supervisor/shared/usb -SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c -endif - -ifeq ($(CIRCUITPY_USB_DEVICE),1) -CFLAGS += \ + -DCFG_TUSB_OS=OPT_OS_NONE \ -DCFG_TUD_CDC_TX_BUFSIZE=1024 \ -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ - -DCFG_TUD_MSC_BUFSIZE=4096 -endif - -ifdef CIRCUITPY_USB_VENDOR -CFLASGS += \ + -DCFG_TUD_MSC_BUFSIZE=4096 \ + -DCFG_TUD_MIDI_RX_BUFSIZE=128 \ + -DCFG_TUD_MIDI_TX_BUFSIZE=128 \ -DCFG_TUD_VENDOR_RX_BUFSIZE=1024 \ -DCFG_TUD_VENDOR_TX_BUFSIZE=1024 -endif -# -DCFG_TUD_MIDI_RX_BUFSIZE=128 -# -DCFG_TUD_MIDI_TX_BUFSIZE=128 +# Add TinyUSB sources +INC += -I../../lib/tinyusb/src +INC += -I../../supervisor/shared/usb +SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c +# Add port sources incl. any board functions SRC_C += \ boards/$(BOARD)/board.c \ background.c \ diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index f9b50477bc23..32881729c7a9 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -17,15 +17,16 @@ INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 -# TODO: Test/Debug fs & general bringup +# TODO: Test/Debug fs once USB-MSC is ready DISABLE_FILESYSTEM = 0 # TODO: Test/Debug TinyUSB! -CIRCUITPY_TINYUSB = 1 -CIRCUITPY_USB_DEVICE ?= 1 -CIRCUITPY_USB_CDC ?= 1 -CIRCUITPY_USB_HID ?= 0 -CIRCUITPY_USB_MIDI ?= 0 +# CIRCUITPY_TINYUSB = 1 +# CIRCUITPY_USB_DEVICE ?= 1 +# CIRCUITPY_USB_CDC ?= 1 +# CIRCUITPY_USB_VENDOR ?=1 +# CIRCUITPY_USB_HID ?= 0 +# CIRCUITPY_USB_MIDI ?= 0 #################################################################################### # Suggested config for first-time porting diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 31a46b8de8b8..730d85124259 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -163,7 +163,7 @@ uint32_t *port_stack_get_limit(void) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" - // NOTE: Only return how much stack we have alloted for CircuitPython + // NOTE: Only return how much stack we have allotted for CircuitPython return port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t); #pragma GCC diagnostic pop } @@ -268,7 +268,7 @@ void port_idle_until_interrupt(void) { if (!background_callback_pending()) { __DSB(); /** DEBUG: may comment out WFI for debugging port functions */ - __WFI(); + // __WFI(); } common_hal_mcu_enable_interrupts(); } From 4848bf680574a89714bdc62ee6818896563e2401 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 3 Sep 2024 13:02:24 -0700 Subject: [PATCH 009/252] - Fixed USB endpoint descriptor problems. All USB classes should now be usable. - Had to adjust some shared modules to account for MAX32 devices not supporting IN/OUT endpoints on the same EP # --- ports/analog/boards/APARD/mpconfigboard.mk | 4 +++- ports/analog/mpconfigport.mk | 10 +--------- shared-module/storage/__init__.c | 5 +++++ shared-module/usb_cdc/__init__.c | 5 +++++ shared-module/usb_hid/__init__.c | 6 ++++++ shared-module/usb_midi/__init__.c | 6 ++++++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index e49d695761c3..cbd2e97d9058 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -18,8 +18,10 @@ USB_VID=0x0456 USB_PID=0x003C USB_MANUFACTURER="Analog Devices, Inc." USB_PRODUCT="MAX32690 APARD" -USB_NUM_ENDPOINT_PAIRS=12 USB_HIGHSPEED=1 + +# NOTE: MAX32 devices do not support IN/OUT pairs on the same EP +USB_NUM_ENDPOINT_PAIRS=12 ### # define UID len for memory safety (buffer gets passed as a raw ptr) diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 32881729c7a9..fe250e282751 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -17,17 +17,9 @@ INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 -# TODO: Test/Debug fs once USB-MSC is ready +# TODO: Test/Debug FS DISABLE_FILESYSTEM = 0 -# TODO: Test/Debug TinyUSB! -# CIRCUITPY_TINYUSB = 1 -# CIRCUITPY_USB_DEVICE ?= 1 -# CIRCUITPY_USB_CDC ?= 1 -# CIRCUITPY_USB_VENDOR ?=1 -# CIRCUITPY_USB_HID ?= 0 -# CIRCUITPY_USB_MIDI ?= 0 - #################################################################################### # Suggested config for first-time porting #################################################################################### diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 12486aff752f..850b7a33fc90 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -92,6 +92,11 @@ size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t * descriptor_buf[MSC_IN_ENDPOINT_INDEX] = 0x80 | (USB_MSC_EP_NUM_IN ? USB_MSC_EP_NUM_IN : descriptor_counts->current_endpoint); descriptor_counts->num_in_endpoints++; + // Some TinyUSB devices have issues with bi-directional endpoints + #ifdef TUD_ENDPOINT_ONE_DIRECTION_ONLY + descriptor_counts->current_endpoint++; + #endif + descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = USB_MSC_EP_NUM_OUT ? USB_MSC_EP_NUM_OUT : descriptor_counts->current_endpoint; descriptor_counts->num_out_endpoints++; diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 502d8fa620e0..0248c0f180fd 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -192,6 +192,11 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *desc ? (USB_CDC_EP_NUM_DATA_IN ? USB_CDC_EP_NUM_DATA_IN : descriptor_counts->current_endpoint) : (USB_CDC2_EP_NUM_DATA_IN ? USB_CDC2_EP_NUM_DATA_IN : descriptor_counts->current_endpoint)); descriptor_counts->num_in_endpoints++; + // Some TinyUSB devices have issues with bi-directional endpoints + #ifdef TUD_ENDPOINT_ONE_DIRECTION_ONLY + descriptor_counts->current_endpoint++; + #endif + descriptor_buf[CDC_DATA_OUT_ENDPOINT_INDEX] = console ? (USB_CDC_EP_NUM_DATA_OUT ? USB_CDC_EP_NUM_DATA_OUT : descriptor_counts->current_endpoint) diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index b007bc3ac2d4..4d0d5fc2e3d5 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -172,6 +172,12 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *desc descriptor_buf[HID_IN_ENDPOINT_INDEX] = 0x80 | (USB_HID_EP_NUM_IN ? USB_HID_EP_NUM_IN : descriptor_counts->current_endpoint); descriptor_counts->num_in_endpoints++; + + // Some TinyUSB devices have issues with bi-directional endpoints + #ifdef TUD_ENDPOINT_ONE_DIRECTION_ONLY + descriptor_counts->current_endpoint++; + #endif + descriptor_buf[HID_OUT_ENDPOINT_INDEX] = USB_HID_EP_NUM_OUT ? USB_HID_EP_NUM_OUT : descriptor_counts->current_endpoint; descriptor_counts->num_out_endpoints++; diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index e0853e4e2a7a..3808801ff7e1 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -176,6 +176,12 @@ size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *des descriptor_buf[MIDI_STREAMING_IN_ENDPOINT_INDEX] = 0x80 | (USB_MIDI_EP_NUM_IN ? USB_MIDI_EP_NUM_IN : descriptor_counts->current_endpoint); descriptor_counts->num_in_endpoints++; + + // Some TinyUSB devices have issues with bi-directional endpoints + #ifdef TUD_ENDPOINT_ONE_DIRECTION_ONLY + descriptor_counts->current_endpoint++; + #endif + descriptor_buf[MIDI_STREAMING_OUT_ENDPOINT_INDEX] = USB_MIDI_EP_NUM_OUT ? USB_MIDI_EP_NUM_OUT : descriptor_counts->current_endpoint; descriptor_counts->num_out_endpoints++; From 003b7c52f6be9e4851eeedb334315a4001aeb865 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Thu, 5 Sep 2024 17:48:38 -0600 Subject: [PATCH 010/252] - Fixed USB issues. REPL & CIRCUITPY: drive now function correctly! - Fixed bugs with Internal Flash filesystem. Files now write & read back correctly. - Added copyright headers for all files. --- ports/analog/Makefile | 1 + ports/analog/README.md | 12 +- ports/analog/background.c | 1 + ports/analog/background.h | 1 + ports/analog/boards/APARD/README.md | 22 ++ ports/analog/boards/APARD/board.c | 4 +- ports/analog/boards/APARD/mpconfigboard.h | 23 +- ports/analog/boards/APARD/mpconfigboard.mk | 1 + ports/analog/boards/APARD/pins.c | 1 + ports/analog/common-hal/microcontroller/Pin.c | 5 + ports/analog/common-hal/microcontroller/Pin.h | 5 + .../common-hal/microcontroller/Processor.c | 6 +- .../common-hal/microcontroller/__init__.c | 1 + ports/analog/linking/max32690_cktpy.ld | 10 +- ports/analog/max32_port.h | 5 + ports/analog/mpconfigport.mk | 6 +- ports/analog/mphalport.c | 5 + ports/analog/mphalport.h | 2 +- ports/analog/peripherals/led.h | 5 + ports/analog/peripherals/max32690/pins.c | 6 + ports/analog/peripherals/max32690/pins.h | 6 + ports/analog/peripherals/pins.h | 6 +- ports/analog/supervisor/cpu.s | 7 + ports/analog/supervisor/internal_flash.c | 215 +++++++----------- ports/analog/supervisor/internal_flash.h | 6 + ports/analog/supervisor/serial.c | 51 +++-- ports/analog/supervisor/usb.c | 10 +- 27 files changed, 243 insertions(+), 180 deletions(-) create mode 100644 ports/analog/peripherals/led.h diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 7c3e1cb80117..072d9f866219 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -1,6 +1,7 @@ # This file is part of the CircuitPython project: https://circuitpython.org # # SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. # # SPDX-License-Identifier: MIT diff --git a/ports/analog/README.md b/ports/analog/README.md index 1650fad1cac5..e2bd38b66472 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -38,7 +38,9 @@ Universal instructions on flashing MAX32 devices this project can be found in th In addition, a user may flash the device by calling `make` with the `flash-msdk` target from within the `ports/analog` directory, as below: - $ make BOARD= flash-msdk +``` +$ make BOARD= flash-msdk +``` This requires the following: - A MAX32625PICO is connected to the PC via USB @@ -48,4 +50,10 @@ This requires the following: ### Using the REPL -[**Section in Progress. USB support needs implementation & test.**] +Once the device is plugged in, it will enumerate via USB as both a USB Serial Device (CDC) and a Mass Storage Device (MSC). You can connect to the Python REPL with your favorite Serial Monitor program e.g. TeraTerm, VS Code, Putty, etc. Use any buadrate with 8-bit, No Parity, 1 Stop Bit (8N1) settings. From this point forward, you can run Python code on the MCU! If you want help with learning CircuitPython-specific code or learning Python in general, a good place to start is Adafruit's ["Welcome to CircuitPython"](https://learn.adafruit.com/welcome-to-circuitpython/) guide. + +### Editing code.py + +Python code may be executed from `code.py` the `CIRCUITPY:` drive. When editing this file, please be aware that some text editors will work better than others. A list of suggested text editors can be found at Adafruit's guide here: https://learn.adafruit.com/welcome-to-circuitpython/recommended-editors + +Once you save `code.py`, it gets written back to the device you are running Circuitpython on, and will automatically run and output it's result to the REPL. You can also automatically reload and run code.py any time from the REPL by pressing CTRL+D. diff --git a/ports/analog/background.c b/ports/analog/background.c index 8dad8c4e351d..ad3063b7feb9 100644 --- a/ports/analog/background.c +++ b/ports/analog/background.c @@ -1,6 +1,7 @@ // This file is part of the CircuitPython project: https://circuitpython.org // // SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. // // SPDX-License-Identifier: MIT diff --git a/ports/analog/background.h b/ports/analog/background.h index 8fbe98bd9d8e..d32f2b0dc2c3 100644 --- a/ports/analog/background.h +++ b/ports/analog/background.h @@ -1,6 +1,7 @@ // This file is part of the CircuitPython project: https://circuitpython.org // // SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. // // SPDX-License-Identifier: MIT diff --git a/ports/analog/boards/APARD/README.md b/ports/analog/boards/APARD/README.md index 8768ed93d56d..04f28ca4502b 100644 --- a/ports/analog/boards/APARD/README.md +++ b/ports/analog/boards/APARD/README.md @@ -12,3 +12,25 @@ For more info about AD-APARD32690-SL, visit our product webpages for datasheets, [AD-APARD32690-SL Product Webpage](https://www.analog.com/en/resources/evaluation-hardware-and-software/evaluation-boards-kits/ad-apard32690-sl.html) [AD-APARD32690-SL User Guide](https://wiki.analog.com/resources/eval/user-guides/ad-apard32690-sl) + +#### Building for this board + +To build for this board, ensure you are in the `ports/analog` directory and run the following command. Note that passing in the `-jN` flag, where N is the # of cores on your machine, can speed up compile times. + +``` +make BOARD=APARD +``` + +#### Flashing this board + +To flash the board, run the following command if using the MAX32625PICO: + +``` +make BOARD=APARD flash-msdk +``` + +If using Segger JLink, please run the following command instead: + +``` +make BOARD=APARD flash-jlink +``` diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c index 972bdcee6f8c..c24ff5a08e83 100644 --- a/ports/analog/boards/APARD/board.c +++ b/ports/analog/boards/APARD/board.c @@ -1,6 +1,6 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc // // SPDX-License-Identifier: MIT @@ -26,7 +26,7 @@ const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); // DEFAULT: Using the weak-defined supervisor/shared/board.c functions -/***** OPTIONAL BOARD-SPECIFIC FUNTIONS from supervisor/board.h *****/ +/***** OPTIONAL BOARD-SPECIFIC FUNCTIONS from supervisor/board.h *****/ // Returns true if the user initiates safe mode in a board specific way. // Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific // way. diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/APARD/mpconfigboard.h index 87baa0120994..972ca72abeba 100644 --- a/ports/analog/boards/APARD/mpconfigboard.h +++ b/ports/analog/boards/APARD/mpconfigboard.h @@ -1,6 +1,7 @@ // This file is part of the CircuitPython project: https://circuitpython.org // // SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices Inc. // // SPDX-License-Identifier: MIT @@ -20,18 +21,18 @@ #define FLASH_SIZE (0x300000) // 3MiB #define FLASH_PAGE_SIZE (0x4000) // 16384 byte pages (16 KiB) -#define BOARD_HAS_CRYSTAL 1 +#define BOARD_HAS_CRYSTAL 1 +#define NUM_GPIO_PORTS 4 +#define CONSOLE_UART MXC_UART0 -#define NUM_GPIO_PORTS 4 - -#if INTERNAL_FLASH_FILESYSTEM -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102FC000) // for MAX32690 -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64 * 1024) // 64K +// #if INTERNAL_FLASH_FILESYSTEM +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102E0000) // for MAX32690 +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (128 * 1024) // 64K #define MAX32_FLASH_SIZE 0x300000 // 3 MiB -#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64KiB -#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102FC000 // Load into the last MiB of code/data storage +#define INTERNAL_FLASH_FILESYSTEM_SIZE CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102E0000 // Load into the last MiB of code/data storage -#else -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) -#endif +// #else +// #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) +// #endif diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index cbd2e97d9058..7cc54ccfc6dd 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -1,6 +1,7 @@ # This file is part of the CircuitPython project: https://circuitpython.org # # SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc # # SPDX-License-Identifier: MIT diff --git a/ports/analog/boards/APARD/pins.c b/ports/analog/boards/APARD/pins.c index ddd2afdafe58..89bc41832751 100644 --- a/ports/analog/boards/APARD/pins.c +++ b/ports/analog/boards/APARD/pins.c @@ -1,6 +1,7 @@ // This file is part of the CircuitPython project: https://circuitpython.org // // SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. // // SPDX-License-Identifier: MIT diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index e11c9413c907..65949045cdcc 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -1,3 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #include diff --git a/ports/analog/common-hal/microcontroller/Pin.h b/ports/analog/common-hal/microcontroller/Pin.h index 55d4081f3a6b..169586e7e903 100644 --- a/ports/analog/common-hal/microcontroller/Pin.h +++ b/ports/analog/common-hal/microcontroller/Pin.h @@ -1,3 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #pragma once diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c index 339770f9fd24..e28388e58596 100644 --- a/ports/analog/common-hal/microcontroller/Processor.c +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -1,4 +1,8 @@ - +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #include #include "py/runtime.h" diff --git a/ports/analog/common-hal/microcontroller/__init__.c b/ports/analog/common-hal/microcontroller/__init__.c index aff2dc2fd497..bbdb686195ca 100644 --- a/ports/analog/common-hal/microcontroller/__init__.c +++ b/ports/analog/common-hal/microcontroller/__init__.c @@ -2,6 +2,7 @@ // // SPDX-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries // SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc // // SPDX-License-Identifier: MIT diff --git a/ports/analog/linking/max32690_cktpy.ld b/ports/analog/linking/max32690_cktpy.ld index e80a14d53c90..9b32121a135a 100644 --- a/ports/analog/linking/max32690_cktpy.ld +++ b/ports/analog/linking/max32690_cktpy.ld @@ -1,9 +1,15 @@ +/** This file is part of the CircuitPython project: https://circuitpython.org +* +* SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices Inc. +* +* SPDX-License-Identifier: MIT +*/ + MEMORY { ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 2992K - FLASH_ISR (rx) : ORIGIN = 0x102EC000, LENGTH = 16K - FLASH_FS (rx) : ORIGIN = 0x102FC000, LENGTH = 64K + FLASH_FS (rx) : ORIGIN = 0x102E0000, LENGTH = 128K RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 1M } /* Minimum flash page is 16K */ diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index 214e975b719b..0ded32e5b820 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -1,3 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT #ifndef MAX32_PORT_H #define MAX32_PORT_H diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index fe250e282751..60b18a5249a2 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -1,6 +1,7 @@ # This file is part of the CircuitPython project: https://circuitpython.org # # SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. # # SPDX-License-Identifier: MIT @@ -14,11 +15,6 @@ INTERNAL_LIBM ?= 1 CFLAGS += -DHAS_TRNG=1 INTERNAL_FLASH_FILESYSTEM = 1 -SPI_FLASH_FILESYSTEM = 0 -QSPI_FLASH_FILESYSTEM = 0 - -# TODO: Test/Debug FS -DISABLE_FILESYSTEM = 0 #################################################################################### # Suggested config for first-time porting diff --git a/ports/analog/mphalport.c b/ports/analog/mphalport.c index d4e63ec67393..8f305d6325e5 100644 --- a/ports/analog/mphalport.c +++ b/ports/analog/mphalport.c @@ -1,3 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #include "mphalport.h" #include "py/mphal.h" diff --git a/ports/analog/mphalport.h b/ports/analog/mphalport.h index 5efd78736e78..3cd3e00c6e18 100644 --- a/ports/analog/mphalport.h +++ b/ports/analog/mphalport.h @@ -1,6 +1,6 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc // // SPDX-License-Identifier: MIT diff --git a/ports/analog/peripherals/led.h b/ports/analog/peripherals/led.h new file mode 100644 index 000000000000..ff05be051bb2 --- /dev/null +++ b/ports/analog/peripherals/led.h @@ -0,0 +1,5 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT diff --git a/ports/analog/peripherals/max32690/pins.c b/ports/analog/peripherals/max32690/pins.c index 4f26d9d1f6d6..b6c4e993553b 100644 --- a/ports/analog/peripherals/max32690/pins.c +++ b/ports/analog/peripherals/max32690/pins.c @@ -1,3 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT + #include "py/obj.h" #include "py/mphal.h" #include "peripherals/pins.h" diff --git a/ports/analog/peripherals/max32690/pins.h b/ports/analog/peripherals/max32690/pins.h index 9b5cc303ee5c..44022decdf71 100644 --- a/ports/analog/peripherals/max32690/pins.h +++ b/ports/analog/peripherals/max32690/pins.h @@ -1,3 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT + #pragma once extern const mcu_pin_obj_t pin_P0_00; diff --git a/ports/analog/peripherals/pins.h b/ports/analog/peripherals/pins.h index ae471dc29e18..313addc1f205 100644 --- a/ports/analog/peripherals/pins.h +++ b/ports/analog/peripherals/pins.h @@ -1,4 +1,8 @@ - +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT #pragma once diff --git a/ports/analog/supervisor/cpu.s b/ports/analog/supervisor/cpu.s index 9e6807a5e2e9..7cb8291045f1 100644 --- a/ports/analog/supervisor/cpu.s +++ b/ports/analog/supervisor/cpu.s @@ -1,3 +1,10 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT + .syntax unified .cpu cortex-m4 .thumb diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c index 97fe21d4a52c..2b9b51967734 100644 --- a/ports/analog/supervisor/internal_flash.c +++ b/ports/analog/supervisor/internal_flash.c @@ -1,8 +1,16 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George +// SPDX-FileCopyrightText: Copyright (c) 2020 Lucian Copeland for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT #include "supervisor/internal_flash.h" #include #include +#include #include "extmod/vfs.h" #include "extmod/vfs_fat.h" @@ -14,20 +22,19 @@ #include "supervisor/filesystem.h" #include "supervisor/flash.h" #include "supervisor/shared/safe_mode.h" - #if CIRCUITPY_USB_DEVICE #include "supervisor/usb.h" #endif +#include "mpconfigboard.h" + // MAX32 HAL Includes #include "flc.h" #include "flc_reva.h" #include "icc.h" // includes icc_.c for MSDK die type #include "mxc_device.h" -/** TODO: - * Test! - * +/** * NOTE: * ANY function which modifies flash contents must execute from a crit section. * This is because FLC functions are loc'd in RAM, and an ISR executing @@ -44,13 +51,10 @@ * Therefore only ICC0 need be used for the purpose of these functions. */ -#define NO_CACHE 0xffffffff -#define MAX_CACHE 0x4000 - typedef struct { - uint32_t base_addr; - uint32_t sector_size; - uint32_t num_sectors; + const uint32_t base_addr; + const uint32_t sector_size; + const uint32_t num_sectors; } flash_layout_t; #ifdef MAX32690 @@ -58,15 +62,15 @@ typedef struct { // FS Code will use INTERNAL_FLASH_FILESYSTEM_START_ADDR // and won't conflict with ISR vector in first 16 KiB of flash static const flash_layout_t flash_layout[] = { - { 0x10000000, 0x4000, 192}, + { 0x10000000, FLASH_PAGE_SIZE, 192}, // { 0x10300000, 0x2000, 32 }, // RISC-V flash }; -// Cache a full 16K sector -static uint8_t _flash_cache[0x4000] __attribute__((aligned(4))); -#endif +// must be able to hold a full page (for re-writing upon erase) +static uint32_t page_buffer[FLASH_PAGE_SIZE / 4] = {0x0}; -// Address of the flash sector currently being cached -static uint32_t _cache_addr_in_flash = NO_CACHE; +#else +#error "Invalid BOARD. Please set BOARD equal to any board under 'boards/'." +#endif static inline int32_t block2addr(uint32_t block) { if (block >= 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { @@ -135,150 +139,100 @@ uint32_t supervisor_flash_get_block_count(void) { return INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS; } -// Write back to Flash the page that is currently cached void port_internal_flash_flush(void) { - // Flash has not been cached - if (_cache_addr_in_flash == NO_CACHE) { - return; - } - uint32_t sector_start, sector_size = 0xffffffff; - - // Clear & enable flash interrupt flags - MXC_FLC_EnableInt(MXC_F_FLC_INTR_DONEIE | MXC_F_FLC_INTR_AFIE); - - // Figure out the sector of flash we're targeting - if (flash_get_sector_info(_cache_addr_in_flash, §or_start, §or_size) == -1) { - // If not in valid sector, just release the cache and return - supervisor_flash_release_cache(); - return; - } - - // if invalid sector or sector size > the size of our cache, reset with flash fail - if (sector_size > sizeof(_flash_cache) || sector_start == 0xffffffff) { - reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); - } - - // skip if the data in cache is the same as what's already there - if (memcmp(_flash_cache, (void *)_cache_addr_in_flash, FLASH_PAGE_SIZE) != 0) { - uint32_t error; - - // buffer for the page of flash - uint32_t page_buffer[FLASH_PAGE_SIZE >> 2] = { - 0xFFFFFFFF - }; // bytes per page / 4 bytes = # of uint32_t - - // Unlock Flash - MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_UNLOCKED; - - /*** ERASE FLASH PAGE ***/ - MXC_CRITICAL( - // buffer the page - MXC_FLC_Read(sector_start, page_buffer, sector_size); - // Erase page & error check - error = MXC_FLC_PageErase(sector_start); - ); - if (error != E_NO_ERROR) { - // lock flash & reset - MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; - reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); - } - /*** RE-WRITE FLASH PAGE w/ CACHE DATA ***/ - MXC_CRITICAL( - // ret = program the flash page with cache data (for loop) - for (uint32_t i = 0; i < (sector_size >> 2); i++) { - error = MXC_FLC_Write32(_cache_addr_in_flash + 4 * i, _flash_cache[i]); - } - ); - if (error != E_NO_ERROR) { - // lock flash & reset - MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; - reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); - } + // Flush all instruction cache + // ME18 has bug where top-level sysctrl flush bit only works one. + // Have to use low-level flush bits for each ICC instance. + MXC_ICC_Flush(MXC_ICC0); + MXC_ICC_Flush(MXC_ICC1); - // Lock flash & exit - MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; - } // finished flushing cache - // todo: verify no other flash operation (e.g. flushing HW cache) is needed to complete this + // Clear the line fill buffer by reading 2 pages from flash + volatile uint32_t *line_addr; + volatile uint32_t line; + line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE); + line = *line_addr; + line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE + MXC_FLASH_PAGE_SIZE); + line = *line_addr; + (void)line; // Silence build warnings that this variable is not used. } // Read flash blocks, using cache if it contains the right data +// return 0 on success, non-zero on error mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { // Find the address of the block we want to read int src_addr = block2addr(block); if (src_addr == -1) { // bad block num - return false; + return 1; } uint32_t sector_size, sector_start; if (flash_get_sector_info(src_addr, §or_start, §or_size) == -1) { // bad sector idx - return false; + return 2; } - // Find how many blocks left in sector - uint32_t blocks_in_sector = (sector_size - (src_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; - - // If the whole read is inside the cache, then read cache - if ( (num_blocks <= blocks_in_sector) && (_cache_addr_in_flash == sector_start) ) { - memcpy(dest, (_flash_cache + (src_addr - sector_start)), FILESYSTEM_BLOCK_SIZE * num_blocks); - } else { - // flush the cache & read the flash data directly - supervisor_flash_flush(); - /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking - * than memcpy does. Will use it for now. - */ - MXC_FLC_Read((int)dest, (int *)src_addr, FILESYSTEM_BLOCK_SIZE * num_blocks); - } + /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking + * than memcpy does. Will use it for now. + */ + MXC_FLC_Read( src_addr, dest, FILESYSTEM_BLOCK_SIZE * num_blocks ); + return 0; // success } -// Write to flash blocks, using cache if it is targeting the right page (and large enough) -// todo: most of this fn is taken from the ST driver. -// todo: look at other ports and see if I can adapt it at all +// Write to flash blocks +// return 0 on success, non-zero on error mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { - uint32_t count=0; - uint32_t sector_size=0; - uint32_t sector_start=0; + uint32_t error, blocks_left, count, page_start, page_size = 0; while (num_blocks > 0) { - const int32_t dest_addr = block2addr(block_num); + uint32_t dest_addr = block2addr(block_num); // bad block number passed in if (dest_addr == -1) { - return false; - } - - // Implementation is from STM port - // NOTE: May replace later, but this port had a method - // that seemed to make sense across multiple devices. - if (flash_get_sector_info(dest_addr, §or_start, §or_size) == -1) { - reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + return 1; } - // fail if sector size is greater than cache size - if (sector_size > sizeof(_flash_cache)) { + if (flash_get_sector_info(dest_addr, &page_start, &page_size) == -1) { reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); } // Find the number of blocks left within this sector - // BLOCK_NUM = (SECTOR SIZE - BLOCK OFFSET within sector)) / BLOCK_SIZE - count = (sector_size - (dest_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; - count = MIN(num_blocks, count); + // BLOCKS_LEFT = (SECTOR_SIZE - BLOCK_OFFSET within sector)) / BLOCK_SIZE + blocks_left = (page_size - (dest_addr - page_start)) / FILESYSTEM_BLOCK_SIZE; + count = MIN(num_blocks, blocks_left); - // if we're not at the start of a sector, copy the whole sector to cache - if (_cache_addr_in_flash != sector_start) { - // Flush cache first before we overwrite it - supervisor_flash_flush(); + MXC_ICC_Disable(MXC_ICC0); - _cache_addr_in_flash = sector_start; + // Buffer the page of flash to erase + MXC_FLC_Read(page_start , page_buffer, page_size); - // Copy the whole sector into cache - memcpy(_flash_cache, (void *)sector_start, sector_size); + // Erase flash page + MXC_CRITICAL( + error = MXC_FLC_PageErase(dest_addr); + ); + if (error != E_NO_ERROR) { + // lock flash & reset + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); } - // Overwrite the cache with source data passed in - memcpy(_flash_cache + (dest_addr - sector_start), src, count * FILESYSTEM_BLOCK_SIZE); + // Copy new src data into the page buffer + // fill the new data in at the offset dest_addr - page_start + // account for uint32_t page_buffer vs uint8_t src + memcpy( (page_buffer + (dest_addr - page_start) / 4), src, count * FILESYSTEM_BLOCK_SIZE); + + // Write new page buffer back into flash + MXC_CRITICAL( + error = MXC_FLC_Write(page_start, page_size, page_buffer); + ); + if (error != E_NO_ERROR) { + // lock flash & reset + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + MXC_ICC_Enable(MXC_ICC0); block_num += count; src += count * FILESYSTEM_BLOCK_SIZE; @@ -289,18 +243,5 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, // Empty the fs cache void supervisor_flash_release_cache(void) { - // Invalidate the current FS cache - _cache_addr_in_flash = NO_CACHE; - - // Flush the hardware cache for ARM M4 - MXC_ICC_Flush(MXC_ICC0); - - // Clear the line fill buffer by reading 2 pages from flash - volatile uint32_t *line_addr; - volatile uint32_t line; - line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE); - line = *line_addr; - line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE + MXC_FLASH_PAGE_SIZE); - line = *line_addr; - (void)line; // Silence build warnings that this variable is not used. + supervisor_flash_flush(); } diff --git a/ports/analog/supervisor/internal_flash.h b/ports/analog/supervisor/internal_flash.h index 1b4091e9a4fd..cc25f80be770 100644 --- a/ports/analog/supervisor/internal_flash.h +++ b/ports/analog/supervisor/internal_flash.h @@ -1,3 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT #pragma once diff --git a/ports/analog/supervisor/serial.c b/ports/analog/supervisor/serial.c index 7f485a35204c..871e6cd0fe72 100644 --- a/ports/analog/supervisor/serial.c +++ b/ports/analog/supervisor/serial.c @@ -2,6 +2,7 @@ // // SPDX-FileCopyrightText: Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries // SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) Brandon Hurst, Analog Devices, Inc. // // SPDX-License-Identifier: MIT @@ -9,25 +10,24 @@ #include #include "supervisor/shared/serial.h" +#include "uart.h" +#include "uart_regs.h" + +#ifndef MAX32_SERIAL #define MAX32_SERIAL 0 +#endif #if MAX32_SERIAL -// TODO: Switch this to using DEBUG_UART. +#ifdef MAX32690 +#define CONSOLE_UART MXC_UART0 +#endif #endif void port_serial_init(void) { #if MAX32_SERIAL - // huart2.Instance = USART2; - // huart2.Init.BaudRate = 115200; - // huart2.Init.WordLength = UART_WORDLENGTH_8B; - // huart2.Init.StopBits = UART_STOPBITS_1; - // huart2.Init.Parity = UART_PARITY_NONE; - // huart2.Init.Mode = UART_MODE_TX_RX; - // huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - // huart2.Init.OverSampling = UART_OVERSAMPLING_16; - // if (HAL_UART_Init(&huart2) == HAL_OK) { - // stm32f4_peripherals_status_led(1, 1); - // } + MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_IBRO_EN; + while( !(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_IBRO_RDY) ); + MXC_UART_Init(CONSOLE_UART, 115200, MXC_UART_IBRO_CLK); #endif } @@ -40,15 +40,27 @@ char port_serial_read(void) { // uint8_t data; // HAL_UART_Receive(&huart2, &data, 1, 500); // return data; + uint8_t rData; + + mxc_uart_req_t uart_req = { + .uart = CONSOLE_UART, + .rxCnt = 0, + .txCnt = 0, + .txData = NULL, + .rxData = &rData, + .txLen = 0, + .rxLen = 1 + }; + MXC_UART_Transaction(&uart_req); + return rData; #else return -1; #endif } -// There is no easy way to find the number of pending characters, so just say there's 1. uint32_t port_serial_bytes_available(void) { #if MAX32_SERIAL - // return __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) ? 1 : 0; + return MXC_UART_GetRXFIFOAvailable(CONSOLE_UART); #else return 0; #endif @@ -56,6 +68,15 @@ uint32_t port_serial_bytes_available(void) { void port_serial_write_substring(const char *text, uint32_t len) { #if MAX32_SERIAL - // HAL_UART_Transmit(&huart2, (uint8_t *)text, len, 5000); + mxc_uart_req_t uart_req = { + .uart = CONSOLE_UART, + .rxCnt = 0, + .txCnt = 0, + .txData = (const unsigned char *)text, + .rxData = NULL, + .txLen = len, + .rxLen = 0 + }; + MXC_UART_Transaction(&uart_req); #endif } diff --git a/ports/analog/supervisor/usb.c b/ports/analog/supervisor/usb.c index 2fd1545bdb1b..f156669ad386 100644 --- a/ports/analog/supervisor/usb.c +++ b/ports/analog/supervisor/usb.c @@ -1,3 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2018 hathach for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #include "supervisor/usb.h" #include "common-hal/microcontroller/Pin.h" @@ -16,7 +22,6 @@ void init_usb_hardware(void) { // No need to add them to the never_reset list for mcu/Pin API. // 1 ms SysTick initialized in board.c - // todo: consider moving SysTick initialization here? // Enable requisite clocks & power for USB MXC_SYS_ClockSourceEnable(MXC_SYS_CLOCK_IPO); @@ -26,10 +31,9 @@ void init_usb_hardware(void) { // Supervisor calls TinyUSB's dcd_init, // which initializes the USB PHY. - // Dep. on CIRCUITPY_TINYUSB and CIRCUITPY_USB_DEVICE + // Depending on CIRCUITPY_TINYUSB and CIRCUITPY_USB_DEVICE // Interrupt enables are left to TUSB depending on the device class - // todo: confirm with testing! } void USB_IRQHandler(void) From 5e923038f3591a44364946edbe9c6164371b3f21 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Fri, 13 Sep 2024 18:24:47 -0500 Subject: [PATCH 011/252] Initial audio effects commit --- locale/circuitpython.pot | 8 +- ports/raspberrypi/mpconfigport.mk | 2 +- py/circuitpy_defns.mk | 6 + py/circuitpy_mpconfig.mk | 3 + shared-bindings/audioeffects/Echo.c | 245 +++++++++++++++++++++ shared-bindings/audioeffects/Echo.h | 33 +++ shared-bindings/audioeffects/__init__.c | 33 +++ shared-bindings/audioeffects/__init__.h | 7 + shared-module/audioeffects/Echo.c | 189 ++++++++++++++++ shared-module/audioeffects/Echo.h | 47 ++++ shared-module/audioeffects/__init__.c | 5 + shared-module/audioeffects/__init__.h | 7 + shared-module/audioeffects/effects_utils.c | 8 + shared-module/audioeffects/effects_utils.h | 58 +++++ 14 files changed, 648 insertions(+), 3 deletions(-) create mode 100644 shared-bindings/audioeffects/Echo.c create mode 100644 shared-bindings/audioeffects/Echo.h create mode 100644 shared-bindings/audioeffects/__init__.c create mode 100644 shared-bindings/audioeffects/__init__.h create mode 100644 shared-module/audioeffects/Echo.c create mode 100644 shared-module/audioeffects/Echo.h create mode 100644 shared-module/audioeffects/__init__.c create mode 100644 shared-module/audioeffects/__init__.h create mode 100644 shared-module/audioeffects/effects_utils.c create mode 100644 shared-module/audioeffects/effects_utils.h diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 25d4a2831228..f2dbe39b4ead 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -2500,7 +2500,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audioeffects/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" @@ -2847,6 +2847,10 @@ msgstr "" msgid "data type not understood" msgstr "" +#: shared-bindings/audioeffects/Echo.c +msgid "decay must be between 0 and 1" +msgstr "" + #: py/parsenum.c msgid "decimal numbers not supported" msgstr "" @@ -3242,7 +3246,7 @@ msgstr "" msgid "input must be a dense ndarray" msgstr "" -#: extmod/ulab/code/user/user.c +#: extmod/ulab/code/user/user.c shared-bindings/_eve/__init__.c msgid "input must be an ndarray" msgstr "" diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index ab72ddc4f05b..ebf9cf5e3a50 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -22,7 +22,7 @@ CIRCUITPY_PWMIO ?= 1 CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_DISPLAYIO) CIRCUITPY_ROTARYIO ?= 1 CIRCUITPY_ROTARYIO_SOFTENCODER = 1 -CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12 +CIRCUITPY_SYNTHIO_MAX_CHANNELS = 24 CIRCUITPY_USB_HOST ?= 1 CIRCUITPY_USB_VIDEO ?= 1 diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 6d7848997cac..5386ce74d892 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -131,6 +131,9 @@ endif ifeq ($(CIRCUITPY_AUDIOCORE),1) SRC_PATTERNS += audiocore/% endif +ifeq ($(CIRCUITPY_AUDIOEFFECTS),1) +SRC_PATTERNS += audioeffects/% +endif ifeq ($(CIRCUITPY_AUDIOMIXER),1) SRC_PATTERNS += audiomixer/% endif @@ -617,6 +620,8 @@ SRC_SHARED_MODULE_ALL = \ audiocore/RawSample.c \ audiocore/WaveFile.c \ audiocore/__init__.c \ + audioeffects/Echo.c \ + audioeffects/__init__.c \ audioio/__init__.c \ audiomixer/Mixer.c \ audiomixer/MixerVoice.c \ @@ -857,6 +862,7 @@ $(filter $(SRC_PATTERNS), \ displayio/display_core.c \ os/getenv.c \ usb/utf16le.c \ + audioeffects/effects_utils.c \ ) SRC_COMMON_HAL_INTERNAL = \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 81d46270f8f9..de130b3fdbdf 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -141,6 +141,9 @@ CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG) CIRCUITPY_AUDIOMP3 ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_AUDIOCORE)) CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3) +CIRCUITPY_AUDIOEFFECTS ?= 0 +CFLAGS += -DCIRCUITPY_AUDIOEFFECTS=$(CIRCUITPY_AUDIOEFFECTS) + CIRCUITPY_AURORA_EPAPER ?= 0 CFLAGS += -DCIRCUITPY_AURORA_EPAPER=$(CIRCUITPY_AURORA_EPAPER) diff --git a/shared-bindings/audioeffects/Echo.c b/shared-bindings/audioeffects/Echo.c new file mode 100644 index 000000000000..bc37b59b64f2 --- /dev/null +++ b/shared-bindings/audioeffects/Echo.c @@ -0,0 +1,245 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + +#include + +#include "shared-bindings/audioeffects/Echo.h" +#include "shared-module/audioeffects/Echo.h" + +#include "shared/runtime/context_manager_helpers.h" +#include "py/binary.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/util.h" + +#define DECAY_DEFAULT 0.7f + +//| class Echo: +//| """An Echo effect""" +//| +static mp_obj_t audioeffects_echo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_delay_ms, ARG_decay, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 50 } }, + { MP_QSTR_decay, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1024} }, + { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, + { MP_QSTR_bits_per_sample, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, + { MP_QSTR_samples_signed, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, + { MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1 } }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_int_t delay_ms = mp_arg_validate_int_range(args[ARG_delay_ms].u_int, 1, 4000, MP_QSTR_delay_ms); + + mp_float_t decay = (args[ARG_decay].u_obj == MP_OBJ_NULL) + ? (mp_float_t)DECAY_DEFAULT + : mp_obj_get_float(args[ARG_decay].u_obj); + mp_arg_validate_float_range(decay, 0.0f, 1.0f, MP_QSTR_decay); + + mp_int_t channel_count = mp_arg_validate_int_range(args[ARG_channel_count].u_int, 1, 2, MP_QSTR_channel_count); + mp_int_t sample_rate = mp_arg_validate_int_min(args[ARG_sample_rate].u_int, 1, MP_QSTR_sample_rate); + mp_int_t bits_per_sample = args[ARG_bits_per_sample].u_int; + if (bits_per_sample != 8 && bits_per_sample != 16) { + mp_raise_ValueError(MP_ERROR_TEXT("bits_per_sample must be 8 or 16")); + } + + audioeffects_echo_obj_t *self = mp_obj_malloc(audioeffects_echo_obj_t, &audioeffects_echo_type); + common_hal_audioeffects_echo_construct(self, delay_ms, decay, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + + return MP_OBJ_FROM_PTR(self); +} + +//| def deinit(self) -> None: +//| """Deinitialises the Echo and releases any hardware resources for reuse.""" +//| ... +static mp_obj_t audioeffects_echo_deinit(mp_obj_t self_in) { + audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_audioeffects_echo_deinit(self); + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_deinit_obj, audioeffects_echo_deinit); + +static void check_for_deinit(audioeffects_echo_obj_t *self) { + if (common_hal_audioeffects_echo_deinited(self)) { + raise_deinited_error(); + } +} + +//| def __enter__(self) -> Echo: +//| """No-op used by Context Managers.""" +//| ... +// Provided by context manager helper. + +//| def __exit__(self) -> None: +//| """Automatically deinitializes the hardware when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info.""" +//| ... +static mp_obj_t audioeffects_echo_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_audioeffects_echo_deinit(args[0]); + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioeffects_echo___exit___obj, 4, 4, audioeffects_echo_obj___exit__); + + +//| delay_ms: int +//| """Delay of the echo in microseconds. (read-only)""" +//| +static mp_obj_t audioeffects_echo_obj_get_delay_ms(mp_obj_t self_in) { + audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return mp_obj_new_float(common_hal_audioeffects_echo_get_delay_ms(self)); + +} +MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_get_delay_ms_obj, audioeffects_echo_obj_get_delay_ms); + +static mp_obj_t audioeffects_echo_obj_set_delay_ms(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_delay_ms }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_delay_ms, MP_ARG_INT | MP_ARG_REQUIRED, {} }, + }; + audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_int_t delay_ms = mp_arg_validate_int_range(args[ARG_delay_ms].u_int, 1, 4000, MP_QSTR_delay_ms); + + common_hal_audioeffects_echo_set_delay_ms(self, delay_ms); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audioeffects_echo_set_delay_ms_obj, 1, audioeffects_echo_obj_set_delay_ms); + +MP_PROPERTY_GETSET(audioeffects_echo_delay_ms_obj, + (mp_obj_t)&audioeffects_echo_get_delay_ms_obj, + (mp_obj_t)&audioeffects_echo_set_delay_ms_obj); + + + +//| decay: float +//| """The rate the echo decays between 0 and 1.""" +static mp_obj_t audioeffects_echo_obj_get_decay(mp_obj_t self_in) { + return mp_obj_new_float(common_hal_audioeffects_echo_get_decay(self_in)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_get_decay_obj, audioeffects_echo_obj_get_decay); + +static mp_obj_t audioeffects_echo_obj_set_decay(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_decay }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_decay, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + }; + audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_float_t decay = mp_obj_get_float(args[ARG_decay].u_obj); + + if (decay > 1 || decay < 0) { + mp_raise_ValueError(MP_ERROR_TEXT("decay must be between 0 and 1")); + } + + common_hal_audioeffects_echo_set_decay(self, decay); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audioeffects_echo_set_decay_obj, 1, audioeffects_echo_obj_set_decay); + +MP_PROPERTY_GETSET(audioeffects_echo_decay_obj, + (mp_obj_t)&audioeffects_echo_get_decay_obj, + (mp_obj_t)&audioeffects_echo_set_decay_obj); + + +//| playing: bool +//| """True when any voice is being output. (read-only)""" +static mp_obj_t audioeffects_echo_obj_get_playing(mp_obj_t self_in) { + audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_audioeffects_echo_get_playing(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_get_playing_obj, audioeffects_echo_obj_get_playing); + +MP_PROPERTY_GETTER(audioeffects_echo_playing_obj, + (mp_obj_t)&audioeffects_echo_get_playing_obj); + +//| def play( +//| self, sample: circuitpython_typing.AudioSample, *, voice: int = 0, loop: bool = False +//| ) -> None: +//| """Plays the sample once when loop=False and continuously when loop=True. +//| Does not block. Use `playing` to block. +//| +//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, `audiomixer.Mixer` or `audiomp3.MP3Decoder`. +//| +//| The sample must match the Effect's encoding settings given in the constructor.""" +//| ... +static mp_obj_t audioeffects_echo_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_sample, ARG_loop }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_sample, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + { MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + }; + audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + + mp_obj_t sample = args[ARG_sample].u_obj; + common_hal_audioeffects_echo_play(self, sample, args[ARG_loop].u_bool); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audioeffects_echo_play_obj, 1, audioeffects_echo_obj_play); + +//| def stop_voice(self, voice: int = 0) -> None: +//| """Stops playback of the sample.""" +//| ... +//| +static mp_obj_t audioeffects_echo_obj_stop(mp_obj_t self_in) { + audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); + + common_hal_audioeffects_echo_stop(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_stop_obj, audioeffects_echo_obj_stop); + + + +static const mp_rom_map_elem_t audioeffects_echo_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioeffects_echo_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audioeffects_echo___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audioeffects_echo_play_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&audioeffects_echo_stop_obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audioeffects_echo_playing_obj) }, + { MP_ROM_QSTR(MP_QSTR_delay_ms), MP_ROM_PTR(&audioeffects_echo_delay_ms_obj) }, + { MP_ROM_QSTR(MP_QSTR_decay), MP_ROM_PTR(&audioeffects_echo_decay_obj) }, +}; +static MP_DEFINE_CONST_DICT(audioeffects_echo_locals_dict, audioeffects_echo_locals_dict_table); + +static const audiosample_p_t audioeffects_echo_proto = { + MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample) + .sample_rate = (audiosample_sample_rate_fun)common_hal_audioeffects_echo_get_sample_rate, + .bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audioeffects_echo_get_bits_per_sample, + .channel_count = (audiosample_channel_count_fun)common_hal_audioeffects_echo_get_channel_count, + .reset_buffer = (audiosample_reset_buffer_fun)audioeffects_echo_reset_buffer, + .get_buffer = (audiosample_get_buffer_fun)audioeffects_echo_get_buffer, + .get_buffer_structure = (audiosample_get_buffer_structure_fun)audioeffects_echo_get_buffer_structure, +}; + +MP_DEFINE_CONST_OBJ_TYPE( + audioeffects_echo_type, + MP_QSTR_Echo, + MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS, + make_new, audioeffects_echo_make_new, + locals_dict, &audioeffects_echo_locals_dict, + protocol, &audioeffects_echo_proto + ); diff --git a/shared-bindings/audioeffects/Echo.h b/shared-bindings/audioeffects/Echo.h new file mode 100644 index 000000000000..7a6fa9ee3c4f --- /dev/null +++ b/shared-bindings/audioeffects/Echo.h @@ -0,0 +1,33 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "shared-module/audioeffects/Echo.h" + +extern const mp_obj_type_t audioeffects_echo_type; + +void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, + uint32_t delay_ms, mp_float_t decay, + uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, + uint8_t channel_count, uint32_t sample_rate); + +void common_hal_audioeffects_echo_deinit(audioeffects_echo_obj_t *self); +bool common_hal_audioeffects_echo_deinited(audioeffects_echo_obj_t *self); + +uint32_t common_hal_audioeffects_echo_get_sample_rate(audioeffects_echo_obj_t *self); +uint8_t common_hal_audioeffects_echo_get_channel_count(audioeffects_echo_obj_t *self); +uint8_t common_hal_audioeffects_echo_get_bits_per_sample(audioeffects_echo_obj_t *self); + +uint32_t common_hal_audioeffects_echo_get_delay_ms(audioeffects_echo_obj_t *self); +void common_hal_audioeffects_echo_set_delay_ms(audioeffects_echo_obj_t *self, uint32_t delay_ms); + +mp_float_t common_hal_audioeffects_echo_get_decay(audioeffects_echo_obj_t *self); +void common_hal_audioeffects_echo_set_decay(audioeffects_echo_obj_t *self, mp_float_t decay); + +bool common_hal_audioeffects_echo_get_playing(audioeffects_echo_obj_t *self); +void common_hal_audioeffects_echo_play(audioeffects_echo_obj_t *self, mp_obj_t sample, bool loop); +void common_hal_audioeffects_echo_stop(audioeffects_echo_obj_t *self); diff --git a/shared-bindings/audioeffects/__init__.c b/shared-bindings/audioeffects/__init__.c new file mode 100644 index 000000000000..f1ead918c0d2 --- /dev/null +++ b/shared-bindings/audioeffects/__init__.c @@ -0,0 +1,33 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/audioeffects/__init__.h" +#include "shared-bindings/audioeffects/Echo.h" + +//| """Support for audio effects +//| +//| The `audioeffects` module contains classes to provide access to audio effects. +//| +//| """ + +static const mp_rom_map_elem_t audioeffects_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audioeffects) }, + { MP_ROM_QSTR(MP_QSTR_Echo), MP_ROM_PTR(&audioeffects_echo_type) }, +}; + +static MP_DEFINE_CONST_DICT(audioeffects_module_globals, audioeffects_module_globals_table); + +const mp_obj_module_t audioeffects_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&audioeffects_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_audioeffects, audioeffects_module); diff --git a/shared-bindings/audioeffects/__init__.h b/shared-bindings/audioeffects/__init__.h new file mode 100644 index 000000000000..3bc9246e5bbf --- /dev/null +++ b/shared-bindings/audioeffects/__init__.h @@ -0,0 +1,7 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + +#pragma once diff --git a/shared-module/audioeffects/Echo.c b/shared-module/audioeffects/Echo.c new file mode 100644 index 000000000000..302fd72a9f81 --- /dev/null +++ b/shared-module/audioeffects/Echo.c @@ -0,0 +1,189 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT +#include "shared-bindings/audioeffects/Echo.h" + +#include +#include "py/runtime.h" +#include "effects_utils.h" + + +void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, uint32_t delay_ms, mp_float_t decay, uint32_t buffer_size, uint8_t bits_per_sample, + bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { + + self->bits_per_sample = bits_per_sample; + self->samples_signed = samples_signed; + self->channel_count = channel_count; + self->sample_rate = sample_rate; + + // check that buffer_size <= echo_buffer_size + self->buffer_len = buffer_size; + self->buffer = m_malloc(self->buffer_len); + if (self->buffer == NULL) { + common_hal_audioeffects_echo_deinit(self); + m_malloc_fail(self->buffer_len); + } + memset(self->buffer, 0, self->buffer_len); + + self->decay = (uint16_t)(decay * (1 << 15)); + + // calculate buffer size for the set delay + self->delay_ms = delay_ms; + self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * sizeof(uint32_t); + + self->echo_buffer = m_malloc(self->echo_buffer_len); + if (self->echo_buffer == NULL) { + common_hal_audioeffects_echo_deinit(self); + m_malloc_fail(self->echo_buffer_len); + } + memset(self->echo_buffer, 0, self->echo_buffer_len); + + // read is where we store the incoming sample + // write is what we send to the outgoing buffer + self->echo_buffer_read_pos = self->buffer_len / sizeof(uint32_t); + self->echo_buffer_write_pos = 0; +} + +bool common_hal_audioeffects_echo_deinited(audioeffects_echo_obj_t *self) { + if (self->echo_buffer == NULL) { + return true; + } + return false; +} + +void common_hal_audioeffects_echo_deinit(audioeffects_echo_obj_t *self) { + if (common_hal_audioeffects_echo_deinited(self)) { + return; + } + self->echo_buffer = NULL; + self->buffer = NULL; +} + + +uint32_t common_hal_audioeffects_echo_get_delay_ms(audioeffects_echo_obj_t *self) { + return self->delay_ms; +} + +void common_hal_audioeffects_echo_set_delay_ms(audioeffects_echo_obj_t *self, uint32_t delay_ms) { + self->delay_ms = delay_ms; + self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * sizeof(uint32_t); + + self->echo_buffer = m_realloc(self->echo_buffer, self->echo_buffer_len); + if (self->echo_buffer == NULL) { + common_hal_audioeffects_echo_deinit(self); + m_malloc_fail(self->echo_buffer_len); + } + + uint32_t max_ebuf_length = self->echo_buffer_len / sizeof(uint32_t); + + if (self->echo_buffer_read_pos > max_ebuf_length) { + self->echo_buffer_read_pos = 0; + self->echo_buffer_write_pos = max_ebuf_length - (self->buffer_len / sizeof(uint32_t)); + } else if (self->echo_buffer_write_pos > max_ebuf_length) { + self->echo_buffer_read_pos = self->buffer_len / sizeof(uint32_t); + self->echo_buffer_write_pos = 0; + } +} + +mp_float_t common_hal_audioeffects_echo_get_decay(audioeffects_echo_obj_t *self) { + return (mp_float_t)self->decay / (1 << 15); +} + +void common_hal_audioeffects_echo_set_decay(audioeffects_echo_obj_t *self, mp_float_t decay) { + self->decay = (uint16_t)(decay * (1 << 15)); +} + +uint32_t common_hal_audioeffects_echo_get_sample_rate(audioeffects_echo_obj_t *self) { + return self->sample_rate; +} + +uint8_t common_hal_audioeffects_echo_get_channel_count(audioeffects_echo_obj_t *self) { + return self->channel_count; +} + +uint8_t common_hal_audioeffects_echo_get_bits_per_sample(audioeffects_echo_obj_t *self) { + return self->bits_per_sample; +} + +void audioeffects_echo_reset_buffer(audioeffects_echo_obj_t *self, + bool single_channel_output, + uint8_t channel) { + +} + +bool common_hal_audioeffects_echo_get_playing(audioeffects_echo_obj_t *self) { + return self->sample != NULL; +} + +void common_hal_audioeffects_echo_play(audioeffects_echo_obj_t *self, mp_obj_t sample, bool loop) { + // check buffer size vs our buffer length + self->sample = sample; + return; +} + +void common_hal_audioeffects_echo_stop(audioeffects_echo_obj_t *self) { + self->sample = NULL; + memset(self->echo_buffer, 0, self->echo_buffer_len); // clear echo + return; +} + +audioio_get_buffer_result_t audioeffects_echo_get_buffer(audioeffects_echo_obj_t *self, bool single_channel_output, uint8_t channel, + uint8_t **buffer, uint32_t *buffer_length) { + + *buffer_length = self->buffer_len; + *buffer = (uint8_t *)self->buffer; + + if (self->sample == NULL) { + + } else { + // Get the sample's buffer + uint32_t *sample_buffer; + uint32_t sample_buffer_len; + + // audioio_get_buffer_result_t result = + audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&sample_buffer, &sample_buffer_len); + + uint32_t n = MIN(sample_buffer_len / sizeof(uint32_t), (self->buffer_len / sizeof(uint32_t))); + *buffer_length = n * sizeof(uint32_t); + + uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint32_t); + + // pass the sample thru to our buffer adding in the echo + for (uint32_t i = 0; i < n; i++) { + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + + uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; + self->buffer[i] = add16signed(mult16signed(echo, self->decay), sample_buffer[i]); + } + + // copy sample buffer to echo buf to play back later + // This now includes our current sound + previous echos + for (uint32_t i = 0; i < n; i++) { + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } + + self->echo_buffer[self->echo_buffer_write_pos++] = add16signed(sample_buffer[i], self->buffer[i]); + } + } + + return GET_BUFFER_MORE_DATA; +} + +void audioeffects_echo_get_buffer_structure(audioeffects_echo_obj_t *self, bool single_channel_output, + bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing) { + + if (self->sample != NULL) { + audiosample_get_buffer_structure(self->sample, single_channel_output, single_buffer, samples_signed, max_buffer_length, spacing); + *max_buffer_length = self->buffer_len; + } else { + *single_buffer = false; + *samples_signed = true; + *max_buffer_length = self->buffer_len; + *spacing = 1; + } +} diff --git a/shared-module/audioeffects/Echo.h b/shared-module/audioeffects/Echo.h new file mode 100644 index 000000000000..ec2b0e331725 --- /dev/null +++ b/shared-module/audioeffects/Echo.h @@ -0,0 +1,47 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT +#pragma once + +#include "py/obj.h" + +#include "shared-module/audiocore/__init__.h" + +extern const mp_obj_type_t audioeffects_echo_type; + +typedef struct { + mp_obj_base_t base; + uint32_t delay_ms; + uint16_t decay; + uint8_t bits_per_sample; + bool samples_signed; + uint8_t channel_count; + uint32_t sample_rate; + + uint32_t *buffer; + uint32_t buffer_len; // buffer in bytes + + uint32_t *echo_buffer; + uint32_t echo_buffer_len; // bytes + + uint32_t echo_buffer_read_pos; // words + uint32_t echo_buffer_write_pos; // words + + mp_obj_t sample; +} audioeffects_echo_obj_t; + +void audioeffects_echo_reset_buffer(audioeffects_echo_obj_t *self, + bool single_channel_output, + uint8_t channel); + +audioio_get_buffer_result_t audioeffects_echo_get_buffer(audioeffects_echo_obj_t *self, + bool single_channel_output, + uint8_t channel, + uint8_t **buffer, + uint32_t *buffer_length); // length in bytes + +void audioeffects_echo_get_buffer_structure(audioeffects_echo_obj_t *self, bool single_channel_output, + bool *single_buffer, bool *samples_signed, + uint32_t *max_buffer_length, uint8_t *spacing); diff --git a/shared-module/audioeffects/__init__.c b/shared-module/audioeffects/__init__.c new file mode 100644 index 000000000000..7b5abdb4ff31 --- /dev/null +++ b/shared-module/audioeffects/__init__.c @@ -0,0 +1,5 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT diff --git a/shared-module/audioeffects/__init__.h b/shared-module/audioeffects/__init__.h new file mode 100644 index 000000000000..3bc9246e5bbf --- /dev/null +++ b/shared-module/audioeffects/__init__.h @@ -0,0 +1,7 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + +#pragma once diff --git a/shared-module/audioeffects/effects_utils.c b/shared-module/audioeffects/effects_utils.c new file mode 100644 index 000000000000..742ab820b47f --- /dev/null +++ b/shared-module/audioeffects/effects_utils.c @@ -0,0 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + +#include +#include "py/runtime.h" diff --git a/shared-module/audioeffects/effects_utils.h b/shared-module/audioeffects/effects_utils.h new file mode 100644 index 000000000000..142ea779f330 --- /dev/null +++ b/shared-module/audioeffects/effects_utils.h @@ -0,0 +1,58 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + + +__attribute__((always_inline)) +static inline uint32_t add16signed(uint32_t a, uint32_t b) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) + return __QADD16(a, b); + #else + uint32_t result = 0; + for (int8_t i = 0; i < 2; i++) { + int16_t ai = a >> (sizeof(int16_t) * 8 * i); + int16_t bi = b >> (sizeof(int16_t) * 8 * i); + int32_t intermediate = (int32_t)ai + bi; + if (intermediate > SHRT_MAX) { + intermediate = SHRT_MAX; + } else if (intermediate < SHRT_MIN) { + intermediate = SHRT_MIN; + } + result |= (((uint32_t)intermediate) & 0xffff) << (sizeof(int16_t) * 8 * i); + } + return result; + #endif +} + +__attribute__((always_inline)) +static inline uint32_t mult16signed(uint32_t val, int32_t mul) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) + mul <<= 16; + int32_t hi, lo; + enum { bits = 16 }; // saturate to 16 bits + enum { shift = 15 }; // shift is done automatically + asm volatile ("smulwb %0, %1, %2" : "=r" (lo) : "r" (mul), "r" (val)); + asm volatile ("smulwt %0, %1, %2" : "=r" (hi) : "r" (mul), "r" (val)); + asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (lo) : "I" (bits), "r" (lo), "I" (shift)); + asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (hi) : "I" (bits), "r" (hi), "I" (shift)); + asm volatile ("pkhbt %0, %1, %2, lsl #16" : "=r" (val) : "r" (lo), "r" (hi)); // pack + return val; + #else + uint32_t result = 0; + float mod_mul = (float)mul / (float)((1 << 15) - 1); + for (int8_t i = 0; i < 2; i++) { + int16_t ai = (val >> (sizeof(uint16_t) * 8 * i)); + int32_t intermediate = (int32_t)(ai * mod_mul); + if (intermediate > SHRT_MAX) { + intermediate = SHRT_MAX; + } else if (intermediate < SHRT_MIN) { + intermediate = SHRT_MIN; + } + intermediate &= 0x0000FFFF; + result |= (((uint32_t)intermediate)) << (sizeof(int16_t) * 8 * i); + } + return result; + #endif +} From a950349180d97d7255b899377a0e3933f420e1ec Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sun, 15 Sep 2024 17:39:36 -0500 Subject: [PATCH 012/252] Changes to properly handle samples --- locale/circuitpython.pot | 16 ++ .../raspberry_pi_pico2/mpconfigboard.mk | 1 + shared-module/audioeffects/Echo.c | 166 ++++++++++++++---- shared-module/audioeffects/Echo.h | 6 + shared-module/audioeffects/effects_utils.h | 33 ++++ 5 files changed, 184 insertions(+), 38 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index f2dbe39b4ead..07ed2443d339 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1956,18 +1956,34 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" +#: shared-module/audioeffects/Echo.c +msgid "The sample's bits_per_sample does not match the effect's" +msgstr "" + #: shared-module/audiomixer/MixerVoice.c msgid "The sample's bits_per_sample does not match the mixer's" msgstr "" +#: shared-module/audioeffects/Echo.c +msgid "The sample's channel count does not match the effect's" +msgstr "" + #: shared-module/audiomixer/MixerVoice.c msgid "The sample's channel count does not match the mixer's" msgstr "" +#: shared-module/audioeffects/Echo.c +msgid "The sample's sample rate does not match the effect's" +msgstr "" + #: shared-module/audiomixer/MixerVoice.c msgid "The sample's sample rate does not match the mixer's" msgstr "" +#: shared-module/audioeffects/Echo.c +msgid "The sample's signedness does not match the effect's" +msgstr "" + #: shared-module/audiomixer/MixerVoice.c msgid "The sample's signedness does not match the mixer's" msgstr "" diff --git a/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk index 7a684716674d..4d31166875f1 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk @@ -10,4 +10,5 @@ CHIP_FAMILY = rp2 EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" CIRCUITPY__EVE = 1 +CIRCUITPY_AUDIOEFFECTS = 1 CIRCUITPY_ALARM = 0 diff --git a/shared-module/audioeffects/Echo.c b/shared-module/audioeffects/Echo.c index 302fd72a9f81..4817e0d0d24a 100644 --- a/shared-module/audioeffects/Echo.c +++ b/shared-module/audioeffects/Echo.c @@ -31,7 +31,7 @@ void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, uint3 // calculate buffer size for the set delay self->delay_ms = delay_ms; - self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * sizeof(uint32_t); + self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * (self->channel_count * (self->bits_per_sample / 8)); self->echo_buffer = m_malloc(self->echo_buffer_len); if (self->echo_buffer == NULL) { @@ -44,6 +44,12 @@ void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, uint3 // write is what we send to the outgoing buffer self->echo_buffer_read_pos = self->buffer_len / sizeof(uint32_t); self->echo_buffer_write_pos = 0; + + self->sample = NULL; + self->sample_remaining_buffer = NULL; + self->sample_buffer_length = 0; + self->loop = false; + self->more_data = false; } bool common_hal_audioeffects_echo_deinited(audioeffects_echo_obj_t *self) { @@ -68,7 +74,7 @@ uint32_t common_hal_audioeffects_echo_get_delay_ms(audioeffects_echo_obj_t *self void common_hal_audioeffects_echo_set_delay_ms(audioeffects_echo_obj_t *self, uint32_t delay_ms) { self->delay_ms = delay_ms; - self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * sizeof(uint32_t); + self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * (self->channel_count * (self->bits_per_sample / 8)); self->echo_buffer = m_realloc(self->echo_buffer, self->echo_buffer_len); if (self->echo_buffer == NULL) { @@ -118,59 +124,138 @@ bool common_hal_audioeffects_echo_get_playing(audioeffects_echo_obj_t *self) { } void common_hal_audioeffects_echo_play(audioeffects_echo_obj_t *self, mp_obj_t sample, bool loop) { - // check buffer size vs our buffer length + if (audiosample_sample_rate(sample) != self->sample_rate) { + mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match the effect's")); + } + if (audiosample_channel_count(sample) != self->channel_count) { + mp_raise_ValueError(MP_ERROR_TEXT("The sample's channel count does not match the effect's")); + } + if (audiosample_bits_per_sample(sample) != self->bits_per_sample) { + mp_raise_ValueError(MP_ERROR_TEXT("The sample's bits_per_sample does not match the effect's")); + } + bool single_buffer; + bool samples_signed; + uint32_t max_buffer_length; + uint8_t spacing; + audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing); + if (samples_signed != self->samples_signed) { + mp_raise_ValueError(MP_ERROR_TEXT("The sample's signedness does not match the effect's")); + } self->sample = sample; + self->loop = loop; + + audiosample_reset_buffer(self->sample, false, 0); + audioio_get_buffer_result_t result = audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&self->sample_remaining_buffer, &self->sample_buffer_length); + // Track length in terms of words. + self->sample_buffer_length /= sizeof(uint32_t); + self->more_data = result == GET_BUFFER_MORE_DATA; + return; } void common_hal_audioeffects_echo_stop(audioeffects_echo_obj_t *self) { self->sample = NULL; - memset(self->echo_buffer, 0, self->echo_buffer_len); // clear echo + // memset(self->echo_buffer, 0, self->echo_buffer_len); // clear echo + // memset(self->buffer, 0, self->buffer_len); return; } audioio_get_buffer_result_t audioeffects_echo_get_buffer(audioeffects_echo_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { - *buffer_length = self->buffer_len; - *buffer = (uint8_t *)self->buffer; - - if (self->sample == NULL) { - - } else { - // Get the sample's buffer - uint32_t *sample_buffer; - uint32_t sample_buffer_len; - - // audioio_get_buffer_result_t result = - audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&sample_buffer, &sample_buffer_len); - - uint32_t n = MIN(sample_buffer_len / sizeof(uint32_t), (self->buffer_len / sizeof(uint32_t))); - *buffer_length = n * sizeof(uint32_t); - - uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint32_t); - - // pass the sample thru to our buffer adding in the echo - for (uint32_t i = 0; i < n; i++) { - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; + uint32_t *word_buffer = (uint32_t *)self->buffer; + uint32_t length = self->buffer_len / sizeof(uint32_t); + uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint32_t); + + while (length != 0) { + if (self->sample_buffer_length == 0) { + if (!self->more_data) { + if (self->loop) { + if (self->sample) { + audiosample_reset_buffer(self->sample, false, 0); + } + } else { + self->sample = NULL; + } + } + if (self->sample) { + // Load another buffer + audioio_get_buffer_result_t result = audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&self->sample_remaining_buffer, &self->sample_buffer_length); + // Track length in terms of words. + self->sample_buffer_length /= sizeof(uint32_t); + self->more_data = result == GET_BUFFER_MORE_DATA; } - - uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - self->buffer[i] = add16signed(mult16signed(echo, self->decay), sample_buffer[i]); } - // copy sample buffer to echo buf to play back later - // This now includes our current sound + previous echos - for (uint32_t i = 0; i < n; i++) { - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + // If we have no sample keep the echo echoing + if (self->sample == NULL) { + if (MP_LIKELY(self->bits_per_sample == 16)) { + if (MP_LIKELY(self->samples_signed)) { + for (uint32_t i = 0; i < length; i++) { + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + + uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; + word_buffer[i] = mult16signed(echo, self->decay); + + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } + + self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; + } + } + } + length = 0; + } else { + uint32_t n = MIN(self->sample_buffer_length, length); + uint32_t *sample_src = self->sample_remaining_buffer; + + if (MP_LIKELY(self->bits_per_sample == 16)) { + if (MP_LIKELY(self->samples_signed)) { + for (uint32_t i = 0; i < n; i++) { + uint32_t sample_word = sample_src[i]; + uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; + word_buffer[i] = add16signed(mult16signed(echo, self->decay), sample_word); + self->echo_buffer[self->echo_buffer_write_pos++] = add16signed(sample_word, word_buffer[i]); + + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } + } + } else { + // for (uint32_t i = 0; i < n; i++) { + // uint32_t sample_word = sample_src[i]; + // sample_word = tosigned16(sample_word); + // word_buffer[i] = add16signed(mult16signed(sample_word, self->decay), word_buffer[i]); + // } + } + } else { + // uint16_t *hword_buffer = (uint16_t *)word_buffer; + // uint16_t *sample_hsrc = (uint16_t *)sample_src; + // for (uint32_t i = 0; i < n * 2; i++) { + // uint32_t sample_word = unpack8(sample_hsrc[i]); + // if (MP_LIKELY(!self->samples_signed)) { + // sample_word = tosigned16(sample_word); + // } + // sample_word = mult16signed(sample_word, self->decay); + // sample_word = add16signed(sample_word, unpack8(hword_buffer[i])); + // hword_buffer[i] = pack8(sample_word); + // } } - self->echo_buffer[self->echo_buffer_write_pos++] = add16signed(sample_buffer[i], self->buffer[i]); + length -= n; + word_buffer += n; + self->sample_remaining_buffer += n; + self->sample_buffer_length -= n; } } - + *buffer = (uint8_t *)self->buffer; + *buffer_length = self->buffer_len; return GET_BUFFER_MORE_DATA; } @@ -179,11 +264,16 @@ void audioeffects_echo_get_buffer_structure(audioeffects_echo_obj_t *self, bool if (self->sample != NULL) { audiosample_get_buffer_structure(self->sample, single_channel_output, single_buffer, samples_signed, max_buffer_length, spacing); + *single_buffer = false; *max_buffer_length = self->buffer_len; } else { - *single_buffer = false; + *single_buffer = true; *samples_signed = true; *max_buffer_length = self->buffer_len; - *spacing = 1; + if (single_channel_output) { + *spacing = self->channel_count; + } else { + *spacing = 1; + } } } diff --git a/shared-module/audioeffects/Echo.h b/shared-module/audioeffects/Echo.h index ec2b0e331725..a3931d23506e 100644 --- a/shared-module/audioeffects/Echo.h +++ b/shared-module/audioeffects/Echo.h @@ -23,6 +23,12 @@ typedef struct { uint32_t *buffer; uint32_t buffer_len; // buffer in bytes + uint32_t *sample_remaining_buffer; + uint32_t sample_buffer_length; + + bool loop; + bool more_data; + uint32_t *echo_buffer; uint32_t echo_buffer_len; // bytes diff --git a/shared-module/audioeffects/effects_utils.h b/shared-module/audioeffects/effects_utils.h index 142ea779f330..40bea1931dfe 100644 --- a/shared-module/audioeffects/effects_utils.h +++ b/shared-module/audioeffects/effects_utils.h @@ -56,3 +56,36 @@ static inline uint32_t mult16signed(uint32_t val, int32_t mul) { return result; #endif } + + +static inline uint32_t tounsigned8(uint32_t val) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) + return __UADD8(val, 0x80808080); + #else + return val ^ 0x80808080; + #endif +} + +static inline uint32_t tounsigned16(uint32_t val) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) + return __UADD16(val, 0x80008000); + #else + return val ^ 0x80008000; + #endif +} + +static inline uint32_t tosigned16(uint32_t val) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) + return __UADD16(val, 0x80008000); + #else + return val ^ 0x80008000; + #endif +} + +static inline uint32_t unpack8(uint16_t val) { + return ((val & 0xff00) << 16) | ((val & 0x00ff) << 8); +} + +static inline uint32_t pack8(uint32_t val) { + return ((val & 0xff000000) >> 16) | ((val & 0xff00) >> 8); +} From ac5ccdba7a4f2a883b6397209b60c4a033b3399a Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Tue, 17 Sep 2024 17:00:44 -0500 Subject: [PATCH 013/252] Renamed module --- py/circuitpy_defns.mk | 7 +- py/circuitpy_mpconfig.mk | 4 +- .../{audioeffects => audiodelays}/Echo.c | 138 ++++++++-------- shared-bindings/audiodelays/Echo.h | 33 ++++ shared-bindings/audiodelays/__init__.c | 33 ++++ .../{audioeffects => audiodelays}/__init__.h | 0 shared-bindings/audioeffects/Echo.h | 33 ---- shared-bindings/audioeffects/__init__.c | 33 ---- .../{audioeffects => audiodelays}/Echo.c | 153 ++++++++++-------- .../{audioeffects => audiodelays}/Echo.h | 10 +- .../{audioeffects => audiodelays}/__init__.c | 0 .../{audioeffects => audiodelays}/__init__.h | 0 shared-module/audioeffects/effects_utils.c | 8 - .../effects_utils.h => audiomixer/utils.h} | 3 +- 14 files changed, 232 insertions(+), 223 deletions(-) rename shared-bindings/{audioeffects => audiodelays}/Echo.c (53%) create mode 100644 shared-bindings/audiodelays/Echo.h create mode 100644 shared-bindings/audiodelays/__init__.c rename shared-bindings/{audioeffects => audiodelays}/__init__.h (100%) delete mode 100644 shared-bindings/audioeffects/Echo.h delete mode 100644 shared-bindings/audioeffects/__init__.c rename shared-module/{audioeffects => audiodelays}/Echo.c (56%) rename shared-module/{audioeffects => audiodelays}/Echo.h (76%) rename shared-module/{audioeffects => audiodelays}/__init__.c (100%) rename shared-module/{audioeffects => audiodelays}/__init__.h (100%) delete mode 100644 shared-module/audioeffects/effects_utils.c rename shared-module/{audioeffects/effects_utils.h => audiomixer/utils.h} (96%) diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 5386ce74d892..19f7cfabf044 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -132,7 +132,7 @@ ifeq ($(CIRCUITPY_AUDIOCORE),1) SRC_PATTERNS += audiocore/% endif ifeq ($(CIRCUITPY_AUDIOEFFECTS),1) -SRC_PATTERNS += audioeffects/% +SRC_PATTERNS += audiodelays/% endif ifeq ($(CIRCUITPY_AUDIOMIXER),1) SRC_PATTERNS += audiomixer/% @@ -620,8 +620,8 @@ SRC_SHARED_MODULE_ALL = \ audiocore/RawSample.c \ audiocore/WaveFile.c \ audiocore/__init__.c \ - audioeffects/Echo.c \ - audioeffects/__init__.c \ + audiodelays/Echo.c \ + audiodelays/__init__.c \ audioio/__init__.c \ audiomixer/Mixer.c \ audiomixer/MixerVoice.c \ @@ -862,7 +862,6 @@ $(filter $(SRC_PATTERNS), \ displayio/display_core.c \ os/getenv.c \ usb/utf16le.c \ - audioeffects/effects_utils.c \ ) SRC_COMMON_HAL_INTERNAL = \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index de130b3fdbdf..6a3b29baf32c 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -141,8 +141,8 @@ CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG) CIRCUITPY_AUDIOMP3 ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_AUDIOCORE)) CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3) -CIRCUITPY_AUDIOEFFECTS ?= 0 -CFLAGS += -DCIRCUITPY_AUDIOEFFECTS=$(CIRCUITPY_AUDIOEFFECTS) +CIRCUITPY_AUDIODELAYS ?= 0 +CFLAGS += -DCIRCUITPY_AUDIODELAYS=$(CIRCUITPY_AUDIODELAYS) CIRCUITPY_AURORA_EPAPER ?= 0 CFLAGS += -DCIRCUITPY_AURORA_EPAPER=$(CIRCUITPY_AURORA_EPAPER) diff --git a/shared-bindings/audioeffects/Echo.c b/shared-bindings/audiodelays/Echo.c similarity index 53% rename from shared-bindings/audioeffects/Echo.c rename to shared-bindings/audiodelays/Echo.c index bc37b59b64f2..58f4600d6df7 100644 --- a/shared-bindings/audioeffects/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -6,8 +6,8 @@ #include -#include "shared-bindings/audioeffects/Echo.h" -#include "shared-module/audioeffects/Echo.h" +#include "shared-bindings/audiodelays/Echo.h" +#include "shared-module/audiodelays/Echo.h" #include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" @@ -20,7 +20,7 @@ //| class Echo: //| """An Echo effect""" //| -static mp_obj_t audioeffects_echo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { +static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_delay_ms, ARG_decay, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; static const mp_arg_t allowed_args[] = { { MP_QSTR_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 50 } }, @@ -49,8 +49,8 @@ static mp_obj_t audioeffects_echo_make_new(const mp_obj_type_t *type, size_t n_a mp_raise_ValueError(MP_ERROR_TEXT("bits_per_sample must be 8 or 16")); } - audioeffects_echo_obj_t *self = mp_obj_malloc(audioeffects_echo_obj_t, &audioeffects_echo_type); - common_hal_audioeffects_echo_construct(self, delay_ms, decay, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + audiodelays_echo_obj_t *self = mp_obj_malloc(audiodelays_echo_obj_t, &audiodelays_echo_type); + common_hal_audiodelays_echo_construct(self, delay_ms, decay, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); return MP_OBJ_FROM_PTR(self); } @@ -58,15 +58,15 @@ static mp_obj_t audioeffects_echo_make_new(const mp_obj_type_t *type, size_t n_a //| def deinit(self) -> None: //| """Deinitialises the Echo and releases any hardware resources for reuse.""" //| ... -static mp_obj_t audioeffects_echo_deinit(mp_obj_t self_in) { - audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_audioeffects_echo_deinit(self); +static mp_obj_t audiodelays_echo_deinit(mp_obj_t self_in) { + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_audiodelays_echo_deinit(self); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_deinit_obj, audioeffects_echo_deinit); +static MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_deinit_obj, audiodelays_echo_deinit); -static void check_for_deinit(audioeffects_echo_obj_t *self) { - if (common_hal_audioeffects_echo_deinited(self)) { +static void check_for_deinit(audiodelays_echo_obj_t *self) { + if (common_hal_audiodelays_echo_deinited(self)) { raise_deinited_error(); } } @@ -80,61 +80,61 @@ static void check_for_deinit(audioeffects_echo_obj_t *self) { //| """Automatically deinitializes the hardware when exiting a context. See //| :ref:`lifetime-and-contextmanagers` for more info.""" //| ... -static mp_obj_t audioeffects_echo_obj___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t audiodelays_echo_obj___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; - common_hal_audioeffects_echo_deinit(args[0]); + common_hal_audiodelays_echo_deinit(args[0]); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioeffects_echo___exit___obj, 4, 4, audioeffects_echo_obj___exit__); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiodelays_echo___exit___obj, 4, 4, audiodelays_echo_obj___exit__); //| delay_ms: int //| """Delay of the echo in microseconds. (read-only)""" //| -static mp_obj_t audioeffects_echo_obj_get_delay_ms(mp_obj_t self_in) { - audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); +static mp_obj_t audiodelays_echo_obj_get_delay_ms(mp_obj_t self_in) { + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_float(common_hal_audioeffects_echo_get_delay_ms(self)); + return mp_obj_new_float(common_hal_audiodelays_echo_get_delay_ms(self)); } -MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_get_delay_ms_obj, audioeffects_echo_obj_get_delay_ms); +MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_delay_ms_obj, audiodelays_echo_obj_get_delay_ms); -static mp_obj_t audioeffects_echo_obj_set_delay_ms(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t audiodelays_echo_obj_set_delay_ms(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_delay_ms }; static const mp_arg_t allowed_args[] = { { MP_QSTR_delay_ms, MP_ARG_INT | MP_ARG_REQUIRED, {} }, }; - audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_int_t delay_ms = mp_arg_validate_int_range(args[ARG_delay_ms].u_int, 1, 4000, MP_QSTR_delay_ms); - common_hal_audioeffects_echo_set_delay_ms(self, delay_ms); + common_hal_audiodelays_echo_set_delay_ms(self, delay_ms); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_KW(audioeffects_echo_set_delay_ms_obj, 1, audioeffects_echo_obj_set_delay_ms); +MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_set_delay_ms_obj, 1, audiodelays_echo_obj_set_delay_ms); -MP_PROPERTY_GETSET(audioeffects_echo_delay_ms_obj, - (mp_obj_t)&audioeffects_echo_get_delay_ms_obj, - (mp_obj_t)&audioeffects_echo_set_delay_ms_obj); +MP_PROPERTY_GETSET(audiodelays_echo_delay_ms_obj, + (mp_obj_t)&audiodelays_echo_get_delay_ms_obj, + (mp_obj_t)&audiodelays_echo_set_delay_ms_obj); //| decay: float //| """The rate the echo decays between 0 and 1.""" -static mp_obj_t audioeffects_echo_obj_get_decay(mp_obj_t self_in) { - return mp_obj_new_float(common_hal_audioeffects_echo_get_decay(self_in)); +static mp_obj_t audiodelays_echo_obj_get_decay(mp_obj_t self_in) { + return mp_obj_new_float(common_hal_audiodelays_echo_get_decay(self_in)); } -MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_get_decay_obj, audioeffects_echo_obj_get_decay); +MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_decay_obj, audiodelays_echo_obj_get_decay); -static mp_obj_t audioeffects_echo_obj_set_decay(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t audiodelays_echo_obj_set_decay(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_decay }; static const mp_arg_t allowed_args[] = { { MP_QSTR_decay, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, }; - audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -144,28 +144,28 @@ static mp_obj_t audioeffects_echo_obj_set_decay(size_t n_args, const mp_obj_t *p mp_raise_ValueError(MP_ERROR_TEXT("decay must be between 0 and 1")); } - common_hal_audioeffects_echo_set_decay(self, decay); + common_hal_audiodelays_echo_set_decay(self, decay); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_KW(audioeffects_echo_set_decay_obj, 1, audioeffects_echo_obj_set_decay); +MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_set_decay_obj, 1, audiodelays_echo_obj_set_decay); -MP_PROPERTY_GETSET(audioeffects_echo_decay_obj, - (mp_obj_t)&audioeffects_echo_get_decay_obj, - (mp_obj_t)&audioeffects_echo_set_decay_obj); +MP_PROPERTY_GETSET(audiodelays_echo_decay_obj, + (mp_obj_t)&audiodelays_echo_get_decay_obj, + (mp_obj_t)&audiodelays_echo_set_decay_obj); //| playing: bool //| """True when any voice is being output. (read-only)""" -static mp_obj_t audioeffects_echo_obj_get_playing(mp_obj_t self_in) { - audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); +static mp_obj_t audiodelays_echo_obj_get_playing(mp_obj_t self_in) { + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - return mp_obj_new_bool(common_hal_audioeffects_echo_get_playing(self)); + return mp_obj_new_bool(common_hal_audiodelays_echo_get_playing(self)); } -MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_get_playing_obj, audioeffects_echo_obj_get_playing); +MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_playing_obj, audiodelays_echo_obj_get_playing); -MP_PROPERTY_GETTER(audioeffects_echo_playing_obj, - (mp_obj_t)&audioeffects_echo_get_playing_obj); +MP_PROPERTY_GETTER(audiodelays_echo_playing_obj, + (mp_obj_t)&audiodelays_echo_get_playing_obj); //| def play( //| self, sample: circuitpython_typing.AudioSample, *, voice: int = 0, loop: bool = False @@ -177,69 +177,69 @@ MP_PROPERTY_GETTER(audioeffects_echo_playing_obj, //| //| The sample must match the Effect's encoding settings given in the constructor.""" //| ... -static mp_obj_t audioeffects_echo_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t audiodelays_echo_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_sample, ARG_loop }; static const mp_arg_t allowed_args[] = { { MP_QSTR_sample, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, { MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; - audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); check_for_deinit(self); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t sample = args[ARG_sample].u_obj; - common_hal_audioeffects_echo_play(self, sample, args[ARG_loop].u_bool); + common_hal_audiodelays_echo_play(self, sample, args[ARG_loop].u_bool); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_KW(audioeffects_echo_play_obj, 1, audioeffects_echo_obj_play); +MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_play_obj, 1, audiodelays_echo_obj_play); //| def stop_voice(self, voice: int = 0) -> None: //| """Stops playback of the sample.""" //| ... //| -static mp_obj_t audioeffects_echo_obj_stop(mp_obj_t self_in) { - audioeffects_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); +static mp_obj_t audiodelays_echo_obj_stop(mp_obj_t self_in) { + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_audioeffects_echo_stop(self); + common_hal_audiodelays_echo_stop(self); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(audioeffects_echo_stop_obj, audioeffects_echo_obj_stop); +MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_stop_obj, audiodelays_echo_obj_stop); -static const mp_rom_map_elem_t audioeffects_echo_locals_dict_table[] = { +static const mp_rom_map_elem_t audiodelays_echo_locals_dict_table[] = { // Methods - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audioeffects_echo_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiodelays_echo_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audioeffects_echo___exit___obj) }, - { MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audioeffects_echo_play_obj) }, - { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&audioeffects_echo_stop_obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiodelays_echo___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audiodelays_echo_play_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&audiodelays_echo_stop_obj) }, // Properties - { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audioeffects_echo_playing_obj) }, - { MP_ROM_QSTR(MP_QSTR_delay_ms), MP_ROM_PTR(&audioeffects_echo_delay_ms_obj) }, - { MP_ROM_QSTR(MP_QSTR_decay), MP_ROM_PTR(&audioeffects_echo_decay_obj) }, + { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiodelays_echo_playing_obj) }, + { MP_ROM_QSTR(MP_QSTR_delay_ms), MP_ROM_PTR(&audiodelays_echo_delay_ms_obj) }, + { MP_ROM_QSTR(MP_QSTR_decay), MP_ROM_PTR(&audiodelays_echo_decay_obj) }, }; -static MP_DEFINE_CONST_DICT(audioeffects_echo_locals_dict, audioeffects_echo_locals_dict_table); +static MP_DEFINE_CONST_DICT(audiodelays_echo_locals_dict, audiodelays_echo_locals_dict_table); -static const audiosample_p_t audioeffects_echo_proto = { +static const audiosample_p_t audiodelays_echo_proto = { MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample) - .sample_rate = (audiosample_sample_rate_fun)common_hal_audioeffects_echo_get_sample_rate, - .bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audioeffects_echo_get_bits_per_sample, - .channel_count = (audiosample_channel_count_fun)common_hal_audioeffects_echo_get_channel_count, - .reset_buffer = (audiosample_reset_buffer_fun)audioeffects_echo_reset_buffer, - .get_buffer = (audiosample_get_buffer_fun)audioeffects_echo_get_buffer, - .get_buffer_structure = (audiosample_get_buffer_structure_fun)audioeffects_echo_get_buffer_structure, + .sample_rate = (audiosample_sample_rate_fun)common_hal_audiodelays_echo_get_sample_rate, + .bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audiodelays_echo_get_bits_per_sample, + .channel_count = (audiosample_channel_count_fun)common_hal_audiodelays_echo_get_channel_count, + .reset_buffer = (audiosample_reset_buffer_fun)audiodelays_echo_reset_buffer, + .get_buffer = (audiosample_get_buffer_fun)audiodelays_echo_get_buffer, + .get_buffer_structure = (audiosample_get_buffer_structure_fun)audiodelays_echo_get_buffer_structure, }; MP_DEFINE_CONST_OBJ_TYPE( - audioeffects_echo_type, + audiodelays_echo_type, MP_QSTR_Echo, MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS, - make_new, audioeffects_echo_make_new, - locals_dict, &audioeffects_echo_locals_dict, - protocol, &audioeffects_echo_proto + make_new, audiodelays_echo_make_new, + locals_dict, &audiodelays_echo_locals_dict, + protocol, &audiodelays_echo_proto ); diff --git a/shared-bindings/audiodelays/Echo.h b/shared-bindings/audiodelays/Echo.h new file mode 100644 index 000000000000..a303529c677e --- /dev/null +++ b/shared-bindings/audiodelays/Echo.h @@ -0,0 +1,33 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "shared-module/audiodelays/Echo.h" + +extern const mp_obj_type_t audiodelays_echo_type; + +void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, + uint32_t delay_ms, mp_float_t decay, + uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, + uint8_t channel_count, uint32_t sample_rate); + +void common_hal_audiodelays_echo_deinit(audiodelays_echo_obj_t *self); +bool common_hal_audiodelays_echo_deinited(audiodelays_echo_obj_t *self); + +uint32_t common_hal_audiodelays_echo_get_sample_rate(audiodelays_echo_obj_t *self); +uint8_t common_hal_audiodelays_echo_get_channel_count(audiodelays_echo_obj_t *self); +uint8_t common_hal_audiodelays_echo_get_bits_per_sample(audiodelays_echo_obj_t *self); + +uint32_t common_hal_audiodelays_echo_get_delay_ms(audiodelays_echo_obj_t *self); +void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, uint32_t delay_ms); + +mp_float_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self); +void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_float_t decay); + +bool common_hal_audiodelays_echo_get_playing(audiodelays_echo_obj_t *self); +void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sample, bool loop); +void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self); diff --git a/shared-bindings/audiodelays/__init__.c b/shared-bindings/audiodelays/__init__.c new file mode 100644 index 000000000000..4b0be7b75ad8 --- /dev/null +++ b/shared-bindings/audiodelays/__init__.c @@ -0,0 +1,33 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// +// SPDX-License-Identifier: MIT + +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/audiodelays/__init__.h" +#include "shared-bindings/audiodelays/Echo.h" + +//| """Support for audio delay effects +//| +//| The `audiodelays` module contains classes to provide access to audio delay effects. +//| +//| """ + +static const mp_rom_map_elem_t audiodelays_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audiodelays) }, + { MP_ROM_QSTR(MP_QSTR_Echo), MP_ROM_PTR(&audiodelays_echo_type) }, +}; + +static MP_DEFINE_CONST_DICT(audiodelays_module_globals, audiodelays_module_globals_table); + +const mp_obj_module_t audiodelays_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&audiodelays_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_audiodelays, audiodelays_module); diff --git a/shared-bindings/audioeffects/__init__.h b/shared-bindings/audiodelays/__init__.h similarity index 100% rename from shared-bindings/audioeffects/__init__.h rename to shared-bindings/audiodelays/__init__.h diff --git a/shared-bindings/audioeffects/Echo.h b/shared-bindings/audioeffects/Echo.h deleted file mode 100644 index 7a6fa9ee3c4f..000000000000 --- a/shared-bindings/audioeffects/Echo.h +++ /dev/null @@ -1,33 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus -// -// SPDX-License-Identifier: MIT - -#pragma once - -#include "shared-module/audioeffects/Echo.h" - -extern const mp_obj_type_t audioeffects_echo_type; - -void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, - uint32_t delay_ms, mp_float_t decay, - uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, - uint8_t channel_count, uint32_t sample_rate); - -void common_hal_audioeffects_echo_deinit(audioeffects_echo_obj_t *self); -bool common_hal_audioeffects_echo_deinited(audioeffects_echo_obj_t *self); - -uint32_t common_hal_audioeffects_echo_get_sample_rate(audioeffects_echo_obj_t *self); -uint8_t common_hal_audioeffects_echo_get_channel_count(audioeffects_echo_obj_t *self); -uint8_t common_hal_audioeffects_echo_get_bits_per_sample(audioeffects_echo_obj_t *self); - -uint32_t common_hal_audioeffects_echo_get_delay_ms(audioeffects_echo_obj_t *self); -void common_hal_audioeffects_echo_set_delay_ms(audioeffects_echo_obj_t *self, uint32_t delay_ms); - -mp_float_t common_hal_audioeffects_echo_get_decay(audioeffects_echo_obj_t *self); -void common_hal_audioeffects_echo_set_decay(audioeffects_echo_obj_t *self, mp_float_t decay); - -bool common_hal_audioeffects_echo_get_playing(audioeffects_echo_obj_t *self); -void common_hal_audioeffects_echo_play(audioeffects_echo_obj_t *self, mp_obj_t sample, bool loop); -void common_hal_audioeffects_echo_stop(audioeffects_echo_obj_t *self); diff --git a/shared-bindings/audioeffects/__init__.c b/shared-bindings/audioeffects/__init__.c deleted file mode 100644 index f1ead918c0d2..000000000000 --- a/shared-bindings/audioeffects/__init__.c +++ /dev/null @@ -1,33 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus -// -// SPDX-License-Identifier: MIT - -#include - -#include "py/obj.h" -#include "py/runtime.h" - -#include "shared-bindings/audioeffects/__init__.h" -#include "shared-bindings/audioeffects/Echo.h" - -//| """Support for audio effects -//| -//| The `audioeffects` module contains classes to provide access to audio effects. -//| -//| """ - -static const mp_rom_map_elem_t audioeffects_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audioeffects) }, - { MP_ROM_QSTR(MP_QSTR_Echo), MP_ROM_PTR(&audioeffects_echo_type) }, -}; - -static MP_DEFINE_CONST_DICT(audioeffects_module_globals, audioeffects_module_globals_table); - -const mp_obj_module_t audioeffects_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&audioeffects_module_globals, -}; - -MP_REGISTER_MODULE(MP_QSTR_audioeffects, audioeffects_module); diff --git a/shared-module/audioeffects/Echo.c b/shared-module/audiodelays/Echo.c similarity index 56% rename from shared-module/audioeffects/Echo.c rename to shared-module/audiodelays/Echo.c index 4817e0d0d24a..5212d8214a60 100644 --- a/shared-module/audioeffects/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -3,14 +3,14 @@ // SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus // // SPDX-License-Identifier: MIT -#include "shared-bindings/audioeffects/Echo.h" +#include "shared-bindings/audiodelays/Echo.h" #include #include "py/runtime.h" -#include "effects_utils.h" +#include "shared-module/audiomixer/utils.h" -void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, uint32_t delay_ms, mp_float_t decay, uint32_t buffer_size, uint8_t bits_per_sample, +void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t delay_ms, mp_float_t decay, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { self->bits_per_sample = bits_per_sample; @@ -22,7 +22,7 @@ void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, uint3 self->buffer_len = buffer_size; self->buffer = m_malloc(self->buffer_len); if (self->buffer == NULL) { - common_hal_audioeffects_echo_deinit(self); + common_hal_audiodelays_echo_deinit(self); m_malloc_fail(self->buffer_len); } memset(self->buffer, 0, self->buffer_len); @@ -35,7 +35,7 @@ void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, uint3 self->echo_buffer = m_malloc(self->echo_buffer_len); if (self->echo_buffer == NULL) { - common_hal_audioeffects_echo_deinit(self); + common_hal_audiodelays_echo_deinit(self); m_malloc_fail(self->echo_buffer_len); } memset(self->echo_buffer, 0, self->echo_buffer_len); @@ -52,15 +52,15 @@ void common_hal_audioeffects_echo_construct(audioeffects_echo_obj_t *self, uint3 self->more_data = false; } -bool common_hal_audioeffects_echo_deinited(audioeffects_echo_obj_t *self) { +bool common_hal_audiodelays_echo_deinited(audiodelays_echo_obj_t *self) { if (self->echo_buffer == NULL) { return true; } return false; } -void common_hal_audioeffects_echo_deinit(audioeffects_echo_obj_t *self) { - if (common_hal_audioeffects_echo_deinited(self)) { +void common_hal_audiodelays_echo_deinit(audiodelays_echo_obj_t *self) { + if (common_hal_audiodelays_echo_deinited(self)) { return; } self->echo_buffer = NULL; @@ -68,17 +68,17 @@ void common_hal_audioeffects_echo_deinit(audioeffects_echo_obj_t *self) { } -uint32_t common_hal_audioeffects_echo_get_delay_ms(audioeffects_echo_obj_t *self) { +uint32_t common_hal_audiodelays_echo_get_delay_ms(audiodelays_echo_obj_t *self) { return self->delay_ms; } -void common_hal_audioeffects_echo_set_delay_ms(audioeffects_echo_obj_t *self, uint32_t delay_ms) { +void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, uint32_t delay_ms) { self->delay_ms = delay_ms; self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * (self->channel_count * (self->bits_per_sample / 8)); self->echo_buffer = m_realloc(self->echo_buffer, self->echo_buffer_len); if (self->echo_buffer == NULL) { - common_hal_audioeffects_echo_deinit(self); + common_hal_audiodelays_echo_deinit(self); m_malloc_fail(self->echo_buffer_len); } @@ -93,37 +93,37 @@ void common_hal_audioeffects_echo_set_delay_ms(audioeffects_echo_obj_t *self, ui } } -mp_float_t common_hal_audioeffects_echo_get_decay(audioeffects_echo_obj_t *self) { +mp_float_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self) { return (mp_float_t)self->decay / (1 << 15); } -void common_hal_audioeffects_echo_set_decay(audioeffects_echo_obj_t *self, mp_float_t decay) { +void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_float_t decay) { self->decay = (uint16_t)(decay * (1 << 15)); } -uint32_t common_hal_audioeffects_echo_get_sample_rate(audioeffects_echo_obj_t *self) { +uint32_t common_hal_audiodelays_echo_get_sample_rate(audiodelays_echo_obj_t *self) { return self->sample_rate; } -uint8_t common_hal_audioeffects_echo_get_channel_count(audioeffects_echo_obj_t *self) { +uint8_t common_hal_audiodelays_echo_get_channel_count(audiodelays_echo_obj_t *self) { return self->channel_count; } -uint8_t common_hal_audioeffects_echo_get_bits_per_sample(audioeffects_echo_obj_t *self) { +uint8_t common_hal_audiodelays_echo_get_bits_per_sample(audiodelays_echo_obj_t *self) { return self->bits_per_sample; } -void audioeffects_echo_reset_buffer(audioeffects_echo_obj_t *self, +void audiodelays_echo_reset_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel) { } -bool common_hal_audioeffects_echo_get_playing(audioeffects_echo_obj_t *self) { +bool common_hal_audiodelays_echo_get_playing(audiodelays_echo_obj_t *self) { return self->sample != NULL; } -void common_hal_audioeffects_echo_play(audioeffects_echo_obj_t *self, mp_obj_t sample, bool loop) { +void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sample, bool loop) { if (audiosample_sample_rate(sample) != self->sample_rate) { mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match the effect's")); } @@ -153,14 +153,14 @@ void common_hal_audioeffects_echo_play(audioeffects_echo_obj_t *self, mp_obj_t s return; } -void common_hal_audioeffects_echo_stop(audioeffects_echo_obj_t *self) { +void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self) { self->sample = NULL; // memset(self->echo_buffer, 0, self->echo_buffer_len); // clear echo // memset(self->buffer, 0, self->buffer_len); return; } -audioio_get_buffer_result_t audioeffects_echo_get_buffer(audioeffects_echo_obj_t *self, bool single_channel_output, uint8_t channel, +audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { uint32_t *word_buffer = (uint32_t *)self->buffer; @@ -190,62 +190,81 @@ audioio_get_buffer_result_t audioeffects_echo_get_buffer(audioeffects_echo_obj_t // If we have no sample keep the echo echoing if (self->sample == NULL) { if (MP_LIKELY(self->bits_per_sample == 16)) { - if (MP_LIKELY(self->samples_signed)) { - for (uint32_t i = 0; i < length; i++) { - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - - uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - word_buffer[i] = mult16signed(echo, self->decay); - - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; - } + // sample signed/unsigned won't matter as we have no sample + for (uint32_t i = 0; i < length; i++) { + uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; + word_buffer[i] = mult16signed(echo, self->decay); + + self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } - self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; + } + } else { // bits per sample is 8 + uint16_t *hword_buffer = (uint16_t *)word_buffer; + uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; + for (uint32_t i = 0; i < length * 2; i++) { + uint32_t echo_word = unpack8(echo_hsrc[i]); + echo_word = mult16signed(echo_word, self->decay); + hword_buffer[i] = pack8(echo_word); + + echo_hsrc[self->echo_buffer_write_pos++] = hword_buffer[i]; + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; } } } length = 0; - } else { + } else { // we have a sample uint32_t n = MIN(self->sample_buffer_length, length); uint32_t *sample_src = self->sample_remaining_buffer; if (MP_LIKELY(self->bits_per_sample == 16)) { - if (MP_LIKELY(self->samples_signed)) { - for (uint32_t i = 0; i < n; i++) { - uint32_t sample_word = sample_src[i]; - uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - word_buffer[i] = add16signed(mult16signed(echo, self->decay), sample_word); - self->echo_buffer[self->echo_buffer_write_pos++] = add16signed(sample_word, word_buffer[i]); - - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; - } + for (uint32_t i = 0; i < n; i++) { + uint32_t sample_word = sample_src[i]; + if (MP_LIKELY(!self->samples_signed)) { + sample_word = tosigned16(sample_word); + } + uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; + word_buffer[i] = add16signed(mult16signed(echo, self->decay), sample_word); + self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; + + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } + } + } else { // bits per sample is 8 + uint16_t *hword_buffer = (uint16_t *)word_buffer; + uint16_t *sample_hsrc = (uint16_t *)sample_src; + uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; + for (uint32_t i = 0; i < n * 2; i++) { + uint32_t sample_word = unpack8(sample_hsrc[i]); + uint32_t echo_word = unpack8(echo_hsrc[i]); + if (MP_LIKELY(!self->samples_signed)) { + sample_word = tosigned16(sample_word); + } + echo_word = mult16signed(echo_word, self->decay); + sample_word = add16signed(sample_word, echo_word); + hword_buffer[i] = pack8(sample_word); + + echo_hsrc[self->echo_buffer_write_pos++] = pack8(add16signed(sample_word, unpack8(hword_buffer[i]))); + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; } - } else { - // for (uint32_t i = 0; i < n; i++) { - // uint32_t sample_word = sample_src[i]; - // sample_word = tosigned16(sample_word); - // word_buffer[i] = add16signed(mult16signed(sample_word, self->decay), word_buffer[i]); - // } } - } else { - // uint16_t *hword_buffer = (uint16_t *)word_buffer; - // uint16_t *sample_hsrc = (uint16_t *)sample_src; - // for (uint32_t i = 0; i < n * 2; i++) { - // uint32_t sample_word = unpack8(sample_hsrc[i]); - // if (MP_LIKELY(!self->samples_signed)) { - // sample_word = tosigned16(sample_word); - // } - // sample_word = mult16signed(sample_word, self->decay); - // sample_word = add16signed(sample_word, unpack8(hword_buffer[i])); - // hword_buffer[i] = pack8(sample_word); - // } } length -= n; @@ -259,7 +278,7 @@ audioio_get_buffer_result_t audioeffects_echo_get_buffer(audioeffects_echo_obj_t return GET_BUFFER_MORE_DATA; } -void audioeffects_echo_get_buffer_structure(audioeffects_echo_obj_t *self, bool single_channel_output, +void audiodelays_echo_get_buffer_structure(audiodelays_echo_obj_t *self, bool single_channel_output, bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing) { if (self->sample != NULL) { diff --git a/shared-module/audioeffects/Echo.h b/shared-module/audiodelays/Echo.h similarity index 76% rename from shared-module/audioeffects/Echo.h rename to shared-module/audiodelays/Echo.h index a3931d23506e..262fdf8d3a3e 100644 --- a/shared-module/audioeffects/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -9,7 +9,7 @@ #include "shared-module/audiocore/__init__.h" -extern const mp_obj_type_t audioeffects_echo_type; +extern const mp_obj_type_t audiodelays_echo_type; typedef struct { mp_obj_base_t base; @@ -36,18 +36,18 @@ typedef struct { uint32_t echo_buffer_write_pos; // words mp_obj_t sample; -} audioeffects_echo_obj_t; +} audiodelays_echo_obj_t; -void audioeffects_echo_reset_buffer(audioeffects_echo_obj_t *self, +void audiodelays_echo_reset_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel); -audioio_get_buffer_result_t audioeffects_echo_get_buffer(audioeffects_echo_obj_t *self, +audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length); // length in bytes -void audioeffects_echo_get_buffer_structure(audioeffects_echo_obj_t *self, bool single_channel_output, +void audiodelays_echo_get_buffer_structure(audiodelays_echo_obj_t *self, bool single_channel_output, bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing); diff --git a/shared-module/audioeffects/__init__.c b/shared-module/audiodelays/__init__.c similarity index 100% rename from shared-module/audioeffects/__init__.c rename to shared-module/audiodelays/__init__.c diff --git a/shared-module/audioeffects/__init__.h b/shared-module/audiodelays/__init__.h similarity index 100% rename from shared-module/audioeffects/__init__.h rename to shared-module/audiodelays/__init__.h diff --git a/shared-module/audioeffects/effects_utils.c b/shared-module/audioeffects/effects_utils.c deleted file mode 100644 index 742ab820b47f..000000000000 --- a/shared-module/audioeffects/effects_utils.c +++ /dev/null @@ -1,8 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus -// -// SPDX-License-Identifier: MIT - -#include -#include "py/runtime.h" diff --git a/shared-module/audioeffects/effects_utils.h b/shared-module/audiomixer/utils.h similarity index 96% rename from shared-module/audioeffects/effects_utils.h rename to shared-module/audiomixer/utils.h index 40bea1931dfe..f7dbdac7dd38 100644 --- a/shared-module/audioeffects/effects_utils.h +++ b/shared-module/audiomixer/utils.h @@ -1,10 +1,9 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// SPDX-FileCopyrightText: Copyright (c) 2018 Scott Shawcroft for Adafruit Industries, 2024 Mark Komus // // SPDX-License-Identifier: MIT - __attribute__((always_inline)) static inline uint32_t add16signed(uint32_t a, uint32_t b) { #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) From 3a189e75d9fc858d16598c39990a6c2a15064f28 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 18 Sep 2024 14:58:13 -0500 Subject: [PATCH 014/252] Work around an sdk bug This was already reported & fixed upstream, but the fix will not be in a released SDK until 2.0.1. It's easy enough to use our own workaround. Testing: without this bug fix, rotaryencoder did not work on a pico 2 Note: the cut&paste code was reindented by uncrustify, giving it a slightly different style than the upstream sdk code. --- .../raspberrypi/common-hal/rp2pio/StateMachine.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index bffc9400b34c..54fa13e498c5 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -57,6 +57,19 @@ static void *_interrupt_arg[NUM_PIOS][NUM_PIO_STATE_MACHINES]; static void rp2pio_statemachine_interrupt_handler(void); +// Workaround for sdk bug: https://github.com/raspberrypi/pico-sdk/issues/1878 +// This workaround can be removed when we upgrade to sdk 2.0.1 +static inline void sm_config_set_in_pin_count_issue1878(pio_sm_config *c, uint in_count) { + #if PICO_PIO_VERSION == 0 + // can't be changed from 32 on PIO v0 + ((void)c); + valid_params_if(HARDWARE_PIO, in_count == 32); + #else + valid_params_if(HARDWARE_PIO, in_count && in_count <= 32); + c->shiftctrl = (c->shiftctrl & ~PIO_SM0_SHIFTCTRL_IN_COUNT_BITS) | + ((in_count & 0x1fu) << PIO_SM0_SHIFTCTRL_IN_COUNT_LSB); + #endif +} static void rp2pio_statemachine_set_pull(uint32_t pull_pin_up, uint32_t pull_pin_down, uint32_t pins_we_use) { for (size_t i = 0; i < NUM_BANK0_GPIOS; i++) { bool used = pins_we_use & (1 << i); @@ -374,7 +387,7 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, sm_config_set_wrap(&c, wrap_target, wrap); sm_config_set_in_shift(&c, in_shift_right, auto_push, push_threshold); #if PICO_PIO_VERSION > 0 - sm_config_set_in_pin_count(&c, in_pin_count); + sm_config_set_in_pin_count_issue1878(&c, in_pin_count); #endif sm_config_set_out_shift(&c, out_shift_right, auto_pull, pull_threshold); From 4da22c5634011d3f1a9d5f03fce058a1cf0e60b4 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Wed, 18 Sep 2024 20:17:18 -0500 Subject: [PATCH 015/252] Add mix parameter --- shared-bindings/audiodelays/Echo.c | 54 +++++++++++++++++---- shared-bindings/audiodelays/Echo.h | 5 +- shared-module/audiodelays/Echo.c | 75 ++++++++++++++++++++---------- shared-module/audiodelays/Echo.h | 1 + 4 files changed, 101 insertions(+), 34 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 58f4600d6df7..ee4fbb2ec326 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -16,15 +16,17 @@ #include "shared-bindings/util.h" #define DECAY_DEFAULT 0.7f +#define MIX_DEFAULT 0.5f //| class Echo: //| """An Echo effect""" //| static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_delay_ms, ARG_decay, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; + enum { ARG_delay_ms, ARG_decay, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; static const mp_arg_t allowed_args[] = { { MP_QSTR_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 50 } }, { MP_QSTR_decay, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1024} }, { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, { MP_QSTR_bits_per_sample, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, @@ -42,6 +44,11 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar : mp_obj_get_float(args[ARG_decay].u_obj); mp_arg_validate_float_range(decay, 0.0f, 1.0f, MP_QSTR_decay); + mp_float_t mix = (args[ARG_mix].u_obj == MP_OBJ_NULL) + ? (mp_float_t)MIX_DEFAULT + : mp_obj_get_float(args[ARG_mix].u_obj); + mp_arg_validate_float_range(mix, 0.0f, 1.0f, MP_QSTR_mix); + mp_int_t channel_count = mp_arg_validate_int_range(args[ARG_channel_count].u_int, 1, 2, MP_QSTR_channel_count); mp_int_t sample_rate = mp_arg_validate_int_min(args[ARG_sample_rate].u_int, 1, MP_QSTR_sample_rate); mp_int_t bits_per_sample = args[ARG_bits_per_sample].u_int; @@ -50,7 +57,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar } audiodelays_echo_obj_t *self = mp_obj_malloc(audiodelays_echo_obj_t, &audiodelays_echo_type); - common_hal_audiodelays_echo_construct(self, delay_ms, decay, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + common_hal_audiodelays_echo_construct(self, delay_ms, decay, mix, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); return MP_OBJ_FROM_PTR(self); } @@ -120,8 +127,6 @@ MP_PROPERTY_GETSET(audiodelays_echo_delay_ms_obj, (mp_obj_t)&audiodelays_echo_get_delay_ms_obj, (mp_obj_t)&audiodelays_echo_set_delay_ms_obj); - - //| decay: float //| """The rate the echo decays between 0 and 1.""" static mp_obj_t audiodelays_echo_obj_get_decay(mp_obj_t self_in) { @@ -139,10 +144,7 @@ static mp_obj_t audiodelays_echo_obj_set_decay(size_t n_args, const mp_obj_t *po mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_float_t decay = mp_obj_get_float(args[ARG_decay].u_obj); - - if (decay > 1 || decay < 0) { - mp_raise_ValueError(MP_ERROR_TEXT("decay must be between 0 and 1")); - } + mp_arg_validate_float_range(decay, 0.0f, 1.0f, MP_QSTR_decay); common_hal_audiodelays_echo_set_decay(self, decay); @@ -155,6 +157,39 @@ MP_PROPERTY_GETSET(audiodelays_echo_decay_obj, (mp_obj_t)&audiodelays_echo_set_decay_obj); + + +//| mix: float +//| """The rate the echo mix between 0 and 1.""" +static mp_obj_t audiodelays_echo_obj_get_mix(mp_obj_t self_in) { + return mp_obj_new_float(common_hal_audiodelays_echo_get_mix(self_in)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_mix_obj, audiodelays_echo_obj_get_mix); + +static mp_obj_t audiodelays_echo_obj_set_mix(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_mix }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + }; + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_float_t mix = mp_obj_get_float(args[ARG_mix].u_obj); + mp_arg_validate_float_range(mix, 0.0f, 1.0f, MP_QSTR_mix); + + common_hal_audiodelays_echo_set_mix(self, mix); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_set_mix_obj, 1, audiodelays_echo_obj_set_mix); + +MP_PROPERTY_GETSET(audiodelays_echo_mix_obj, + (mp_obj_t)&audiodelays_echo_get_mix_obj, + (mp_obj_t)&audiodelays_echo_set_mix_obj); + + + //| playing: bool //| """True when any voice is being output. (read-only)""" static mp_obj_t audiodelays_echo_obj_get_playing(mp_obj_t self_in) { @@ -196,7 +231,7 @@ static mp_obj_t audiodelays_echo_obj_play(size_t n_args, const mp_obj_t *pos_arg } MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_play_obj, 1, audiodelays_echo_obj_play); -//| def stop_voice(self, voice: int = 0) -> None: +//| def stop(self) -> None: //| """Stops playback of the sample.""" //| ... //| @@ -222,6 +257,7 @@ static const mp_rom_map_elem_t audiodelays_echo_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiodelays_echo_playing_obj) }, { MP_ROM_QSTR(MP_QSTR_delay_ms), MP_ROM_PTR(&audiodelays_echo_delay_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_decay), MP_ROM_PTR(&audiodelays_echo_decay_obj) }, + { MP_ROM_QSTR(MP_QSTR_mix), MP_ROM_PTR(&audiodelays_echo_mix_obj) }, }; static MP_DEFINE_CONST_DICT(audiodelays_echo_locals_dict, audiodelays_echo_locals_dict_table); diff --git a/shared-bindings/audiodelays/Echo.h b/shared-bindings/audiodelays/Echo.h index a303529c677e..470e68a75320 100644 --- a/shared-bindings/audiodelays/Echo.h +++ b/shared-bindings/audiodelays/Echo.h @@ -11,7 +11,7 @@ extern const mp_obj_type_t audiodelays_echo_type; void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, - uint32_t delay_ms, mp_float_t decay, + uint32_t delay_ms, mp_float_t decay, mp_float_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate); @@ -28,6 +28,9 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, uint mp_float_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self); void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_float_t decay); +mp_float_t common_hal_audiodelays_echo_get_mix(audiodelays_echo_obj_t *self); +void common_hal_audiodelays_echo_set_mix(audiodelays_echo_obj_t *self, mp_float_t decay); + bool common_hal_audiodelays_echo_get_playing(audiodelays_echo_obj_t *self); void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sample, bool loop); void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self); diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 5212d8214a60..b4540423e4ed 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -10,7 +10,8 @@ #include "shared-module/audiomixer/utils.h" -void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t delay_ms, mp_float_t decay, uint32_t buffer_size, uint8_t bits_per_sample, +void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t delay_ms, mp_float_t decay, mp_float_t mix, + uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { self->bits_per_sample = bits_per_sample; @@ -28,6 +29,7 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ memset(self->buffer, 0, self->buffer_len); self->decay = (uint16_t)(decay * (1 << 15)); + self->mix = (uint16_t)(mix * (1 << 15)); // calculate buffer size for the set delay self->delay_ms = delay_ms; @@ -101,6 +103,15 @@ void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_floa self->decay = (uint16_t)(decay * (1 << 15)); } +mp_float_t common_hal_audiodelays_echo_get_mix(audiodelays_echo_obj_t *self) { + return (mp_float_t)self->mix / (1 << 15); +} + +void common_hal_audiodelays_echo_set_mix(audiodelays_echo_obj_t *self, mp_float_t mix) { + self->mix = (uint16_t)(mix * (1 << 15)); + mp_printf(&mp_plat_print, "mix %d\n", self->mix); +} + uint32_t common_hal_audiodelays_echo_get_sample_rate(audiodelays_echo_obj_t *self) { return self->sample_rate; } @@ -190,17 +201,25 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // If we have no sample keep the echo echoing if (self->sample == NULL) { if (MP_LIKELY(self->bits_per_sample == 16)) { - // sample signed/unsigned won't matter as we have no sample - for (uint32_t i = 0; i < length; i++) { - uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - word_buffer[i] = mult16signed(echo, self->decay); - - self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; + if (self->mix == 0) { // no effect and no sample sound + for (uint32_t i = 0; i < length; i++) { + word_buffer[i] = 0; } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + } else { + // sample signed/unsigned won't matter as we have no sample + for (uint32_t i = 0; i < length; i++) { + uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; + word_buffer[i] = mult16signed(echo, self->decay); + self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; + + word_buffer[i] = mult16signed(word_buffer[i], self->mix); + + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } } } @@ -227,20 +246,28 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * uint32_t *sample_src = self->sample_remaining_buffer; if (MP_LIKELY(self->bits_per_sample == 16)) { - for (uint32_t i = 0; i < n; i++) { - uint32_t sample_word = sample_src[i]; - if (MP_LIKELY(!self->samples_signed)) { - sample_word = tosigned16(sample_word); + if (self->mix == 0) { // sample only + for (uint32_t i = 0; i < n; i++) { + word_buffer[i] = sample_src[i]; } - uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - word_buffer[i] = add16signed(mult16signed(echo, self->decay), sample_word); - self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; - - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + } else { + for (uint32_t i = 0; i < n; i++) { + uint32_t sample_word = sample_src[i]; + if (MP_LIKELY(!self->samples_signed)) { + sample_word = tosigned16(sample_word); + } + uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; + word_buffer[i] = add16signed(mult16signed(echo, self->decay), sample_word); + self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; + + word_buffer[i] = add16signed(mult16signed(sample_word, 32768 - self->mix), mult16signed(word_buffer[i], self->mix)); + + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } } } } else { // bits per sample is 8 diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index 262fdf8d3a3e..1660c837c89f 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -15,6 +15,7 @@ typedef struct { mp_obj_base_t base; uint32_t delay_ms; uint16_t decay; + uint16_t mix; uint8_t bits_per_sample; bool samples_signed; uint8_t channel_count; From e9f8ed41dc600fa6b35b1a3d9a35a22effe13430 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 21 Mar 2024 13:41:35 -0700 Subject: [PATCH 016/252] Switch to IDF 5.2 I2C API Make busio.I2C use finalizers for reset instead of bulk reset. This makes it easier to track and free the memory that the IDF allocates internally for its "handle". --- ports/atmel-samd/common-hal/busio/I2C.c | 19 ++- ports/broadcom/common-hal/busio/I2C.c | 28 +--- ports/broadcom/common-hal/busio/I2C.h | 2 - ports/broadcom/supervisor/port.c | 2 - ports/cxd56/common-hal/busio/I2C.c | 6 + ports/espressif/Makefile | 1 - ports/espressif/common-hal/busio/I2C.c | 134 ++++++++++-------- ports/espressif/common-hal/busio/I2C.h | 6 +- ports/espressif/common-hal/espcamera/Camera.c | 15 +- ports/espressif/peripherals/i2c.c | 65 --------- ports/espressif/peripherals/i2c.h | 15 -- ports/espressif/supervisor/port.c | 2 - ports/mimxrt10xx/common-hal/busio/I2C.c | 21 +-- ports/mimxrt10xx/common-hal/busio/I2C.h | 2 - ports/mimxrt10xx/supervisor/port.c | 2 - ports/nordic/common-hal/busio/I2C.c | 30 ++-- ports/nordic/common-hal/busio/I2C.h | 2 - ports/nordic/supervisor/port.c | 2 - ports/raspberrypi/common-hal/busio/I2C.c | 19 +-- ports/raspberrypi/common-hal/busio/I2C.h | 2 - ports/raspberrypi/supervisor/port.c | 2 - ports/silabs/common-hal/busio/I2C.c | 19 +-- ports/silabs/common-hal/busio/I2C.h | 7 +- ports/silabs/supervisor/port.c | 2 - ports/stm/common-hal/busio/I2C.c | 32 ++--- ports/stm/common-hal/busio/I2C.h | 2 - ports/stm/supervisor/port.c | 2 - shared-bindings/bitbangio/I2C.c | 3 +- shared-bindings/busio/I2C.c | 8 +- shared-bindings/busio/I2C.h | 6 +- shared-module/displayio/__init__.c | 3 + 31 files changed, 169 insertions(+), 292 deletions(-) delete mode 100644 ports/espressif/peripherals/i2c.c delete mode 100644 ports/espressif/peripherals/i2c.h diff --git a/ports/atmel-samd/common-hal/busio/I2C.c b/ports/atmel-samd/common-hal/busio/I2C.c index 9c15848f568d..e55b4f589f28 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.c +++ b/ports/atmel-samd/common-hal/busio/I2C.c @@ -108,21 +108,29 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, mp_arg_error_invalid(MP_QSTR_frequency); } - self->sda_pin = sda->number; - self->scl_pin = scl->number; - claim_pin(sda); - claim_pin(scl); if (i2c_m_sync_enable(&self->i2c_desc) != ERR_NONE) { common_hal_busio_i2c_deinit(self); mp_raise_OSError(MP_EIO); } + + self->sda_pin = sda->number; + self->scl_pin = scl->number; + claim_pin(sda); + claim_pin(scl); + + // Prevent bulk sercom reset from resetting us. The finalizer will instead. + never_reset_sercom(self->i2c_desc.device.hw); } bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { return self->sda_pin == NO_PIN; } +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->sda_pin = NO_PIN; +} + void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { if (common_hal_busio_i2c_deinited(self)) { return; @@ -135,6 +143,7 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { reset_pin_number(self->scl_pin); self->sda_pin = NO_PIN; self->scl_pin = NO_PIN; + common_hal_busio_i2c_mark_deinit(self); } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { @@ -236,8 +245,6 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr, } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { - never_reset_sercom(self->i2c_desc.device.hw); - never_reset_pin_number(self->scl_pin); never_reset_pin_number(self->sda_pin); } diff --git a/ports/broadcom/common-hal/busio/I2C.c b/ports/broadcom/common-hal/busio/I2C.c index 29e7aa6713fa..77b0eb293038 100644 --- a/ports/broadcom/common-hal/busio/I2C.c +++ b/ports/broadcom/common-hal/busio/I2C.c @@ -23,28 +23,8 @@ static BSC0_Type *i2c[NUM_I2C] = {BSC0, BSC1, NULL, BSC3, BSC4, BSC5, BSC6, NULL static BSC0_Type *i2c[NUM_I2C] = {BSC0, BSC1, NULL}; #endif -static bool never_reset_i2c[NUM_I2C]; static bool i2c_in_use[NUM_I2C]; -void reset_i2c(void) { - // BSC2 is dedicated to the first HDMI output. - never_reset_i2c[2] = true; - i2c_in_use[2] = true; - #if BCM_VERSION == 2711 - // BSC7 is dedicated to the second HDMI output. - never_reset_i2c[7] = true; - i2c_in_use[7] = true; - #endif - for (size_t i = 0; i < NUM_I2C; i++) { - if (never_reset_i2c[i]) { - continue; - } - i2c_in_use[i] = false; - i2c[i]->C_b.I2CEN = false; - COMPLETE_MEMORY_READS; - } -} - void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { size_t instance_index = NUM_I2C; @@ -90,17 +70,21 @@ bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { return self->sda_pin == NULL; } +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->sda_pin = NULL; +} + void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { if (common_hal_busio_i2c_deinited(self)) { return; } - never_reset_i2c[self->index] = false; i2c_in_use[self->index] = false; common_hal_reset_pin(self->sda_pin); common_hal_reset_pin(self->scl_pin); self->sda_pin = NULL; self->scl_pin = NULL; + common_hal_busio_i2c_mark_deinit(self); } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { @@ -246,8 +230,6 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr, } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { - never_reset_i2c[self->index] = true; - common_hal_never_reset_pin(self->scl_pin); common_hal_never_reset_pin(self->sda_pin); } diff --git a/ports/broadcom/common-hal/busio/I2C.h b/ports/broadcom/common-hal/busio/I2C.h index 11416c0203fa..feecbd0d7864 100644 --- a/ports/broadcom/common-hal/busio/I2C.h +++ b/ports/broadcom/common-hal/busio/I2C.h @@ -23,5 +23,3 @@ typedef struct { bool finish_write; uint8_t last_write_data; } busio_i2c_obj_t; - -void reset_i2c(void); diff --git a/ports/broadcom/supervisor/port.c b/ports/broadcom/supervisor/port.c index 33b20b7c8647..54447d0d987c 100644 --- a/ports/broadcom/supervisor/port.c +++ b/ports/broadcom/supervisor/port.c @@ -13,7 +13,6 @@ #include "genhdr/mpversion.h" #include "common-hal/rtc/RTC.h" -#include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" @@ -66,7 +65,6 @@ safe_mode_t port_init(void) { void reset_port(void) { #if CIRCUITPY_BUSIO - reset_i2c(); reset_spi(); reset_uart(); #endif diff --git a/ports/cxd56/common-hal/busio/I2C.c b/ports/cxd56/common-hal/busio/I2C.c index 20ee4ac0f84a..671c93d3eb88 100644 --- a/ports/cxd56/common-hal/busio/I2C.c +++ b/ports/cxd56/common-hal/busio/I2C.c @@ -44,12 +44,18 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { reset_pin_number(self->scl_pin->number); reset_pin_number(self->sda_pin->number); + + common_hal_busio_i2c_mark_deinit(self); } bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { return self->i2c_dev == NULL; } +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->i2c_dev = NULL; +} + bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { if (common_hal_busio_i2c_deinited(self)) { return false; diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index e0bf48656dee..ec0946833cbc 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -392,7 +392,6 @@ SRC_C += \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ shared/netutils/netutils.c \ - peripherals/i2c.c \ peripherals/$(IDF_TARGET)/pins.c ifeq ($(CIRCUITPY_SSL),1) diff --git a/ports/espressif/common-hal/busio/I2C.c b/ports/espressif/common-hal/busio/I2C.c index 046d2ba2e233..3b12531cfc69 100644 --- a/ports/espressif/common-hal/busio/I2C.c +++ b/ports/espressif/common-hal/busio/I2C.c @@ -10,11 +10,12 @@ #include "components/driver/i2c/include/driver/i2c.h" +#include "bindings/espidf/__init__.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, - const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { + const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout_us) { // Pins 45 and 46 are "strapping" pins that impact start up behavior. They usually need to // be pulled-down so pulling them up for I2C is a bad idea. To make this hard, we don't // support I2C on these pins. @@ -60,44 +61,42 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, } #endif + + i2c_master_bus_config_t config = { + .i2c_port = -1, // auto + .sda_io_num = sda->number, + .scl_io_num = scl->number, + .clk_source = I2C_CLK_SRC_DEFAULT, + .glitch_ignore_cnt = 7, + .flags = { + #if CIRCUITPY_I2C_ALLOW_INTERNAL_PULL_UP + .enable_internal_pullup = true, /*!< Internal GPIO pull mode for I2C sda signal*/ + #else + .enable_internal_pullup = false, /*!< Internal GPIO pull mode for I2C sda signal*/ + #endif + } + }; + esp_err_t result = i2c_new_master_bus(&config, &self->handle); + + if (result == ESP_ERR_NOT_FOUND) { + mp_raise_ValueError(MP_ERROR_TEXT("All I2C peripherals are in use")); + } + CHECK_ESP_RESULT(result); + self->xSemaphore = xSemaphoreCreateMutex(); if (self->xSemaphore == NULL) { + i2c_del_master_bus(self->handle); + self->handle = NULL; mp_raise_RuntimeError(MP_ERROR_TEXT("Unable to create lock")); } self->sda_pin = sda; self->scl_pin = scl; - self->i2c_num = peripherals_i2c_get_free_num(); - self->has_lock = 0; - - if (self->i2c_num == I2C_NUM_MAX) { - mp_raise_ValueError(MP_ERROR_TEXT("All I2C peripherals are in use")); - } - - const i2c_config_t i2c_conf = { - .mode = I2C_MODE_MASTER, - .sda_io_num = self->sda_pin->number, - .scl_io_num = self->scl_pin->number, - #if CIRCUITPY_I2C_ALLOW_INTERNAL_PULL_UP - .sda_pullup_en = GPIO_PULLUP_ENABLE, /*!< Internal GPIO pull mode for I2C sda signal*/ - .scl_pullup_en = GPIO_PULLUP_ENABLE, /*!< Internal GPIO pull mode for I2C scl signal*/ - #else - .sda_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C sda signal*/ - .scl_pullup_en = GPIO_PULLUP_DISABLE, /*!< Internal GPIO pull mode for I2C scl signal*/ - #endif - - .master = { - .clk_speed = frequency, - } - }; - - // Initialize I2C. - esp_err_t err = peripherals_i2c_init(self->i2c_num, &i2c_conf); - if (err != ESP_OK) { - if (err == ESP_FAIL) { - mp_raise_OSError(MP_EIO); - } else { - mp_raise_RuntimeError(MP_ERROR_TEXT("init I2C")); - } + self->has_lock = false; + self->frequency = frequency; + self->timeout_ms = timeout_us / 1000; + // Round up timeout to nearest ms. + if (timeout_us % 1000 != 0) { + self->timeout_ms += 1; } claim_pin(sda); @@ -108,32 +107,27 @@ bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { return self->sda_pin == NULL; } +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->sda_pin = NULL; +} + void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { if (common_hal_busio_i2c_deinited(self)) { return; } - peripherals_i2c_deinit(self->i2c_num); + i2c_del_master_bus(self->handle); + self->handle = NULL; common_hal_reset_pin(self->sda_pin); common_hal_reset_pin(self->scl_pin); self->sda_pin = NULL; self->scl_pin = NULL; -} - -static esp_err_t i2c_zero_length_write(busio_i2c_obj_t *self, uint8_t addr, TickType_t timeout) { - // i2c_master_write_to_device() won't do zero-length writes, so we do it by hand. - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, addr << 1, true); - i2c_master_stop(cmd); - esp_err_t result = i2c_master_cmd_begin(self->i2c_num, cmd, timeout); - i2c_cmd_link_delete(cmd); - return result; + common_hal_busio_i2c_mark_deinit(self); } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { - esp_err_t result = i2c_zero_length_write(self, addr, pdMS_TO_TICKS(10)); + esp_err_t result = i2c_master_probe(self->handle, addr, 1); return result == ESP_OK; } @@ -170,28 +164,54 @@ static uint8_t convert_esp_err(esp_err_t result) { } } +static size_t _transaction_duration(size_t frequency, size_t len) { + size_t khz = frequency / 1000; + size_t bytes_per_ms = khz / 8; + // + 1 for the address byte + return (len + 1) / bytes_per_ms; +} + uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, const uint8_t *data, size_t len) { - return convert_esp_err(len == 0 - ? i2c_zero_length_write(self, addr, pdMS_TO_TICKS(1000)) - : i2c_master_write_to_device(self->i2c_num, (uint8_t)addr, data, len, pdMS_TO_TICKS(1000)) - ); + i2c_device_config_t dev_config = { + .dev_addr_length = I2C_ADDR_BIT_LEN_7, + .device_address = addr, + .scl_speed_hz = self->frequency + }; + i2c_master_dev_handle_t dev_handle; + CHECK_ESP_RESULT(i2c_master_bus_add_device(self->handle, &dev_config, &dev_handle)); + esp_err_t result = i2c_master_transmit(dev_handle, data, len, _transaction_duration(self->frequency, len) + self->timeout_ms); + CHECK_ESP_RESULT(i2c_master_bus_rm_device(dev_handle)); + return convert_esp_err(result); } uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, uint8_t *data, size_t len) { - return convert_esp_err( - i2c_master_read_from_device(self->i2c_num, (uint8_t)addr, data, len, pdMS_TO_TICKS(1000))); + i2c_device_config_t dev_config = { + .dev_addr_length = I2C_ADDR_BIT_LEN_7, + .device_address = addr, + .scl_speed_hz = self->frequency + }; + i2c_master_dev_handle_t dev_handle; + CHECK_ESP_RESULT(i2c_master_bus_add_device(self->handle, &dev_config, &dev_handle)); + esp_err_t result = i2c_master_receive(dev_handle, data, len, _transaction_duration(self->frequency, len) + self->timeout_ms); + CHECK_ESP_RESULT(i2c_master_bus_rm_device(dev_handle)); + return convert_esp_err(result); } uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr, uint8_t *out_data, size_t out_len, uint8_t *in_data, size_t in_len) { - return convert_esp_err( - i2c_master_write_read_device(self->i2c_num, (uint8_t)addr, - out_data, out_len, in_data, in_len, pdMS_TO_TICKS(1000))); + i2c_device_config_t dev_config = { + .dev_addr_length = I2C_ADDR_BIT_LEN_7, + .device_address = addr, + .scl_speed_hz = self->frequency + }; + i2c_master_dev_handle_t dev_handle; + CHECK_ESP_RESULT(i2c_master_bus_add_device(self->handle, &dev_config, &dev_handle)); + esp_err_t result = i2c_master_transmit_receive(dev_handle, out_data, out_len, in_data, in_len, _transaction_duration(self->frequency, out_len) + _transaction_duration(self->frequency, in_len) + self->timeout_ms); + CHECK_ESP_RESULT(i2c_master_bus_rm_device(dev_handle)); + return convert_esp_err(result); } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { - never_reset_i2c(self->i2c_num); - common_hal_never_reset_pin(self->scl_pin); common_hal_never_reset_pin(self->sda_pin); } diff --git a/ports/espressif/common-hal/busio/I2C.h b/ports/espressif/common-hal/busio/I2C.h index 6e040224ece2..25d9791f2521 100644 --- a/ports/espressif/common-hal/busio/I2C.h +++ b/ports/espressif/common-hal/busio/I2C.h @@ -13,13 +13,15 @@ #include "freertos/semphr.h" #include "py/obj.h" -#include "peripherals/i2c.h" +#include "driver/i2c_master.h" typedef struct { mp_obj_base_t base; const mcu_pin_obj_t *scl_pin; const mcu_pin_obj_t *sda_pin; - i2c_port_t i2c_num; + size_t timeout_ms; + size_t frequency; + i2c_master_bus_handle_t handle; SemaphoreHandle_t xSemaphore; bool has_lock; } busio_i2c_obj_t; diff --git a/ports/espressif/common-hal/espcamera/Camera.c b/ports/espressif/common-hal/espcamera/Camera.c index bcf4732fcd8b..22285166e56e 100644 --- a/ports/espressif/common-hal/espcamera/Camera.c +++ b/ports/espressif/common-hal/espcamera/Camera.c @@ -15,6 +15,19 @@ #include "shared-bindings/util.h" #include "common-hal/microcontroller/Pin.h" +// These two includes are needed to peek into the i2c handle to get the i2c port +// number. +#include "sdkconfig.h" +// Define these two macros if not defined so that we don't get the -Wundef +// warning from i2c_private.h +#ifndef CONFIG_I2C_ISR_IRAM_SAFE +#define CONFIG_I2C_ISR_IRAM_SAFE 0 +#endif +#ifndef CONFIG_PM_ENABLE +#define CONFIG_PM_ENABLE 0 +#endif +#include "esp-idf/components/driver/i2c/i2c_private.h" + #include "esp-camera/driver/private_include/cam_hal.h" #if !CONFIG_SPIRAM @@ -106,7 +119,7 @@ void common_hal_espcamera_camera_construct( self->camera_config.fb_count = framebuffer_count; self->camera_config.grab_mode = grab_mode; - self->camera_config.sccb_i2c_port = i2c->i2c_num; + self->camera_config.sccb_i2c_port = self->i2c->handle->base->port_num; i2c_lock(self); esp_err_t result = esp_camera_init(&self->camera_config); diff --git a/ports/espressif/peripherals/i2c.c b/ports/espressif/peripherals/i2c.c deleted file mode 100644 index 744aa07f43d2..000000000000 --- a/ports/espressif/peripherals/i2c.c +++ /dev/null @@ -1,65 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2020 microDev -// -// SPDX-License-Identifier: MIT - -#include "peripherals/i2c.h" - -typedef enum { - STATUS_FREE = 0, - STATUS_IN_USE, - STATUS_NEVER_RESET -} i2c_status_t; - -static i2c_status_t i2c_status[I2C_NUM_MAX]; - -void i2c_reset(void) { - for (i2c_port_t num = 0; num < (i2c_port_t)I2C_NUM_MAX; num++) { - if (i2c_status[num] == STATUS_IN_USE) { - i2c_driver_delete(num); - i2c_status[num] = STATUS_FREE; - } - } -} - -void never_reset_i2c(i2c_port_t num) { - i2c_status[num] = STATUS_NEVER_RESET; -} - -esp_err_t peripherals_i2c_init(i2c_port_t num, const i2c_config_t *i2c_conf) { - esp_err_t err = i2c_param_config(num, i2c_conf); - if (err != ESP_OK) { - return err; - } - size_t rx_buf_len = 0; - size_t tx_buf_len = 0; - #ifdef SOC_I2C_SUPPORT_SLAVE - if (i2c_conf->mode == I2C_MODE_SLAVE) { - rx_buf_len = 256; - tx_buf_len = 256; - } - #endif - return i2c_driver_install(num, i2c_conf->mode, rx_buf_len, tx_buf_len, 0); -} - -void peripherals_i2c_deinit(i2c_port_t num) { - i2c_reset_rx_fifo(num); - i2c_reset_tx_fifo(num); - i2c_driver_delete(num); - i2c_status[num] = STATUS_FREE; -} - -i2c_port_t peripherals_i2c_get_free_num(void) { - i2c_port_t i2c_num = I2C_NUM_MAX; - for (i2c_port_t num = 0; num < (int)I2C_NUM_MAX; num++) { - if (i2c_status[num] == STATUS_FREE) { - i2c_num = num; - break; - } - } - if (i2c_num != I2C_NUM_MAX) { - i2c_status[i2c_num] = STATUS_IN_USE; - } - return i2c_num; -} diff --git a/ports/espressif/peripherals/i2c.h b/ports/espressif/peripherals/i2c.h deleted file mode 100644 index a97889fe5acf..000000000000 --- a/ports/espressif/peripherals/i2c.h +++ /dev/null @@ -1,15 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2020 microDev -// -// SPDX-License-Identifier: MIT - -#pragma once - -#include "driver/i2c.h" - -extern void i2c_reset(void); -extern void never_reset_i2c(i2c_port_t num); -extern esp_err_t peripherals_i2c_init(i2c_port_t num, const i2c_config_t *i2c_conf); -extern void peripherals_i2c_deinit(i2c_port_t num); -extern i2c_port_t peripherals_i2c_get_free_num(void); diff --git a/ports/espressif/supervisor/port.c b/ports/espressif/supervisor/port.c index a662e279ce8e..b601f5347f08 100644 --- a/ports/espressif/supervisor/port.c +++ b/ports/espressif/supervisor/port.c @@ -24,7 +24,6 @@ #include "bindings/espulp/__init__.h" #include "common-hal/microcontroller/Pin.h" #include "common-hal/analogio/AnalogOut.h" -#include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" #include "common-hal/dualbank/__init__.h" @@ -343,7 +342,6 @@ void reset_port(void) { #endif #if CIRCUITPY_BUSIO - i2c_reset(); spi_reset(); uart_reset(); #endif diff --git a/ports/mimxrt10xx/common-hal/busio/I2C.c b/ports/mimxrt10xx/common-hal/busio/I2C.c index fb45553d4003..28a6b8ae5e35 100644 --- a/ports/mimxrt10xx/common-hal/busio/I2C.c +++ b/ports/mimxrt10xx/common-hal/busio/I2C.c @@ -27,16 +27,6 @@ // arrays use 0 based numbering: I2C1 is stored at index 0 static bool reserved_i2c[MP_ARRAY_SIZE(mcu_i2c_banks)]; -static bool never_reset_i2c[MP_ARRAY_SIZE(mcu_i2c_banks)]; - -void i2c_reset(void) { - for (uint i = 0; i < MP_ARRAY_SIZE(mcu_i2c_banks); i++) { - if (!never_reset_i2c[i]) { - reserved_i2c[i] = false; - LPI2C_MasterDeinit(mcu_i2c_banks[i]); - } - } -} static void config_periph_pin(const mcu_periph_obj_t *periph) { IOMUXC_SetPinMux( @@ -153,8 +143,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { - never_reset_i2c[self->sda->bank_idx - 1] = true; - common_hal_never_reset_pin(self->sda->pin); common_hal_never_reset_pin(self->scl->pin); } @@ -168,7 +156,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { return; } reserved_i2c[self->sda->bank_idx - 1] = false; - never_reset_i2c[self->sda->bank_idx - 1] = false; LPI2C_MasterDeinit(self->i2c); @@ -177,6 +164,11 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { self->sda = NULL; self->scl = NULL; + common_hal_busio_i2c_mark_deinit(self); +} + +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->sda = NULL; } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { @@ -187,9 +179,6 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { } bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { - if (common_hal_busio_i2c_deinited(self)) { - return false; - } bool grabbed_lock = false; // CRITICAL_SECTION_ENTER() if (!self->has_lock) { diff --git a/ports/mimxrt10xx/common-hal/busio/I2C.h b/ports/mimxrt10xx/common-hal/busio/I2C.h index 06b86cd2d340..153c2541090a 100644 --- a/ports/mimxrt10xx/common-hal/busio/I2C.h +++ b/ports/mimxrt10xx/common-hal/busio/I2C.h @@ -19,5 +19,3 @@ typedef struct { const mcu_periph_obj_t *scl; const mcu_periph_obj_t *sda; } busio_i2c_obj_t; - -void i2c_reset(void); diff --git a/ports/mimxrt10xx/supervisor/port.c b/ports/mimxrt10xx/supervisor/port.c index fe7ee14a3b7a..d7f7f280d195 100644 --- a/ports/mimxrt10xx/supervisor/port.c +++ b/ports/mimxrt10xx/supervisor/port.c @@ -22,7 +22,6 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/rtc/RTC.h" -#include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "shared-bindings/microcontroller/__init__.h" @@ -427,7 +426,6 @@ safe_mode_t port_init(void) { void reset_port(void) { #if CIRCUITPY_BUSIO - i2c_reset(); spi_reset(); #endif diff --git a/ports/nordic/common-hal/busio/I2C.c b/ports/nordic/common-hal/busio/I2C.c index 292f669f1704..54f5c1570419 100644 --- a/ports/nordic/common-hal/busio/I2C.c +++ b/ports/nordic/common-hal/busio/I2C.c @@ -23,7 +23,8 @@ #define I2C_MAX_XFER_LEN MIN(((1UL << TWIM0_EASYDMA_MAXCNT_SIZE) - 1), 1024) #define I2C_TIMEOUT 1000 // 1 second timeout -static twim_peripheral_t twim_peripherals[] = { +static + twim_peripheral_t twim_peripherals[] = { #if NRFX_CHECK(NRFX_TWIM0_ENABLED) // SPIM0 and TWIM0 share an address. { .twim = NRFX_TWIM_INSTANCE(0), @@ -40,28 +41,10 @@ static twim_peripheral_t twim_peripherals[] = { #endif }; -static bool never_reset[MP_ARRAY_SIZE(twim_peripherals)]; - -void i2c_reset(void) { - for (size_t i = 0; i < MP_ARRAY_SIZE(twim_peripherals); i++) { - if (never_reset[i]) { - continue; - } - nrfx_twim_uninit(&twim_peripherals[i].twim); - twim_peripherals[i].in_use = false; - } -} void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { - for (size_t i = 0; i < MP_ARRAY_SIZE(twim_peripherals); i++) { - if (self->twim_peripheral == &twim_peripherals[i]) { - never_reset[i] = true; - - never_reset_pin_number(self->scl_pin_number); - never_reset_pin_number(self->sda_pin_number); - break; - } - } + never_reset_pin_number(self->scl_pin_number); + never_reset_pin_number(self->sda_pin_number); } static uint8_t twi_error_to_mp(const nrfx_err_t err) { @@ -176,6 +159,11 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { self->scl_pin_number = NO_PIN; self->twim_peripheral->in_use = false; + common_hal_busio_i2c_mark_deinit(self); +} + +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->sda_pin_number = NO_PIN; } // nrfx_twim_tx doesn't support 0-length data so we fall back to the hal API diff --git a/ports/nordic/common-hal/busio/I2C.h b/ports/nordic/common-hal/busio/I2C.h index d94ff6929bc4..c1c1839f892d 100644 --- a/ports/nordic/common-hal/busio/I2C.h +++ b/ports/nordic/common-hal/busio/I2C.h @@ -25,5 +25,3 @@ typedef struct { uint8_t scl_pin_number; uint8_t sda_pin_number; } busio_i2c_obj_t; - -void i2c_reset(void); diff --git a/ports/nordic/supervisor/port.c b/ports/nordic/supervisor/port.c index 759cb8ed4259..ed371c6ad858 100644 --- a/ports/nordic/supervisor/port.c +++ b/ports/nordic/supervisor/port.c @@ -27,7 +27,6 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/alarm/time/TimeAlarm.h" #include "common-hal/analogio/AnalogIn.h" -#include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" #include "common-hal/rtc/RTC.h" @@ -190,7 +189,6 @@ safe_mode_t port_init(void) { void reset_port(void) { #if CIRCUITPY_BUSIO - i2c_reset(); spi_reset(); uart_reset(); #endif diff --git a/ports/raspberrypi/common-hal/busio/I2C.c b/ports/raspberrypi/common-hal/busio/I2C.c index d8e13344cfee..289beeee1504 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.c +++ b/ports/raspberrypi/common-hal/busio/I2C.c @@ -22,19 +22,8 @@ // One second #define BUS_TIMEOUT_US 1000000 -static bool never_reset_i2c[2]; static i2c_inst_t *i2c[2] = {i2c0, i2c1}; -void reset_i2c(void) { - for (size_t i = 0; i < 2; i++) { - if (never_reset_i2c[i]) { - continue; - } - - i2c_deinit(i2c[i]); - } -} - void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { self->peripheral = NULL; @@ -115,7 +104,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { if (common_hal_busio_i2c_deinited(self)) { return; } - never_reset_i2c[i2c_hw_index(self->peripheral)] = false; i2c_deinit(self->peripheral); @@ -123,6 +111,11 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { reset_pin_number(self->scl_pin); self->sda_pin = NO_PIN; self->scl_pin = NO_PIN; + common_hal_busio_i2c_mark_deinit(self); +} + +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->sda_pin = NO_PIN; } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { @@ -219,8 +212,6 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr, } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { - never_reset_i2c[i2c_hw_index(self->peripheral)] = true; - never_reset_pin_number(self->scl_pin); never_reset_pin_number(self->sda_pin); } diff --git a/ports/raspberrypi/common-hal/busio/I2C.h b/ports/raspberrypi/common-hal/busio/I2C.h index 9d97025c48e2..b02c1c54a31c 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.h +++ b/ports/raspberrypi/common-hal/busio/I2C.h @@ -22,5 +22,3 @@ typedef struct { uint8_t scl_pin; uint8_t sda_pin; } busio_i2c_obj_t; - -void reset_i2c(void); diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index 9a5250119633..ffa25d12404e 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -13,7 +13,6 @@ #include "bindings/rp2pio/StateMachine.h" #include "genhdr/mpversion.h" -#include "shared-bindings/busio/I2C.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/countio/Counter.h" #include "shared-bindings/microcontroller/__init__.h" @@ -367,7 +366,6 @@ safe_mode_t port_init(void) { void reset_port(void) { #if CIRCUITPY_BUSIO - reset_i2c(); reset_spi(); reset_uart(); #endif diff --git a/ports/silabs/common-hal/busio/I2C.c b/ports/silabs/common-hal/busio/I2C.c index 7934416b1274..443b2e94fc1d 100644 --- a/ports/silabs/common-hal/busio/I2C.c +++ b/ports/silabs/common-hal/busio/I2C.c @@ -30,17 +30,8 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -static I2CSPM_Init_TypeDef i2cspm_init; -static bool in_used = false; -static bool never_reset = false; - -// Reser I2C peripheral -void i2c_reset(void) { - if ((!never_reset) && in_used) { - I2C_Reset(DEFAULT_I2C_PERIPHERAL); - in_used = false; - } -} +STATIC I2CSPM_Init_TypeDef i2cspm_init; +STATIC bool in_used = false; // Construct I2C protocol, this function init i2c peripheral void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, @@ -80,7 +71,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, // Never reset I2C obj when reload void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { - never_reset = true; common_hal_never_reset_pin(self->sda); common_hal_never_reset_pin(self->scl); } @@ -102,6 +92,11 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { self->scl = NULL; self->i2cspm = NULL; in_used = false; + common_hal_busio_i2c_mark_deinit(self); +} + +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->sda = NULL; } // Probe device in I2C bus diff --git a/ports/silabs/common-hal/busio/I2C.h b/ports/silabs/common-hal/busio/I2C.h index 14f879ee445a..a225299280a8 100644 --- a/ports/silabs/common-hal/busio/I2C.h +++ b/ports/silabs/common-hal/busio/I2C.h @@ -24,8 +24,7 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_I2C_H -#define MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_I2C_H +#pragma once #include "common-hal/microcontroller/Pin.h" #include "peripherals/periph.h" @@ -40,7 +39,3 @@ typedef struct { const mcu_pin_obj_t *scl; const mcu_pin_obj_t *sda; } busio_i2c_obj_t; - -void i2c_reset(void); - -#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_I2C_H diff --git a/ports/silabs/supervisor/port.c b/ports/silabs/supervisor/port.c index d94093b3e1da..2409e907deac 100644 --- a/ports/silabs/supervisor/port.c +++ b/ports/silabs/supervisor/port.c @@ -33,7 +33,6 @@ #include "shared-bindings/microcontroller/__init__.h" #if CIRCUITPY_BUSIO -#include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" #endif @@ -160,7 +159,6 @@ void reset_port(void) { reset_all_pins(); #if CIRCUITPY_BUSIO - i2c_reset(); spi_reset(); uart_reset(); #endif diff --git a/ports/stm/common-hal/busio/I2C.c b/ports/stm/common-hal/busio/I2C.c index c58c1883df28..b1d9e0033935 100644 --- a/ports/stm/common-hal/busio/I2C.c +++ b/ports/stm/common-hal/busio/I2C.c @@ -40,26 +40,13 @@ // Arrays use 0 based numbering: I2C1 is stored at index 0 #define MAX_I2C 4 -static bool reserved_i2c[MAX_I2C]; -static bool never_reset_i2c[MAX_I2C]; +STATIC bool reserved_i2c[MAX_I2C]; #define ALL_CLOCKS 0xFF static void i2c_clock_enable(uint8_t mask); static void i2c_clock_disable(uint8_t mask); static void i2c_assign_irq(busio_i2c_obj_t *self, I2C_TypeDef *I2Cx); -void i2c_reset(void) { - uint16_t never_reset_mask = 0x00; - for (int i = 0; i < MAX_I2C; i++) { - if (!never_reset_i2c[i]) { - reserved_i2c[i] = false; - } else { - never_reset_mask |= 1 << i; - } - } - i2c_clock_disable(ALL_CLOCKS & ~(never_reset_mask)); -} - void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { @@ -163,15 +150,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { - for (size_t i = 0; i < MP_ARRAY_SIZE(mcu_i2c_banks); i++) { - if (self->handle.Instance == mcu_i2c_banks[i]) { - never_reset_i2c[i] = true; - - never_reset_pin_number(self->scl->pin->port, self->scl->pin->number); - never_reset_pin_number(self->sda->pin->port, self->sda->pin->number); - break; - } - } + never_reset_pin_number(self->scl->pin->port, self->scl->pin->number); + never_reset_pin_number(self->sda->pin->port, self->sda->pin->number); } bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { @@ -185,12 +165,16 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { i2c_clock_disable(1 << (self->sda->periph_index - 1)); reserved_i2c[self->sda->periph_index - 1] = false; - never_reset_i2c[self->sda->periph_index - 1] = false; reset_pin_number(self->sda->pin->port, self->sda->pin->number); reset_pin_number(self->scl->pin->port, self->scl->pin->number); self->sda = NULL; self->scl = NULL; + common_hal_busio_i2c_mark_deinit(self); +} + +void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self) { + self->sda = NULL; } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { diff --git a/ports/stm/common-hal/busio/I2C.h b/ports/stm/common-hal/busio/I2C.h index ff78ddb35af3..c79a077dcaba 100644 --- a/ports/stm/common-hal/busio/I2C.h +++ b/ports/stm/common-hal/busio/I2C.h @@ -22,5 +22,3 @@ typedef struct { const mcu_periph_obj_t *scl; const mcu_periph_obj_t *sda; } busio_i2c_obj_t; - -void i2c_reset(void); diff --git a/ports/stm/supervisor/port.c b/ports/stm/supervisor/port.c index 5b903044b61c..55402eb8b284 100644 --- a/ports/stm/supervisor/port.c +++ b/ports/stm/supervisor/port.c @@ -14,7 +14,6 @@ #include "shared-bindings/microcontroller/__init__.h" #if CIRCUITPY_BUSIO -#include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" #endif @@ -219,7 +218,6 @@ void reset_port(void) { #endif #if CIRCUITPY_BUSIO - i2c_reset(); spi_reset(); uart_reset(); #endif diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index 491833c27d45..102e43083d30 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -59,7 +59,8 @@ static mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mcu_pin_obj_t *scl = validate_obj_is_free_pin(args[ARG_scl].u_obj, MP_QSTR_scl); const mcu_pin_obj_t *sda = validate_obj_is_free_pin(args[ARG_sda].u_obj, MP_QSTR_sda); - bitbangio_i2c_obj_t *self = mp_obj_malloc(bitbangio_i2c_obj_t, &bitbangio_i2c_type); + bitbangio_i2c_obj_t *self = m_new_obj_with_finaliser(bitbangio_i2c_obj_t); + self->base.type = &bitbangio_i2c_type; shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int); return (mp_obj_t)self; } diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 8a1b832a7a8d..7146480235eb 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -42,7 +42,7 @@ //| :param ~microcontroller.Pin scl: The clock pin //| :param ~microcontroller.Pin sda: The data pin //| :param int frequency: The clock frequency in Hertz -//| :param int timeout: The maximum clock stretching timeut - (used only for +//| :param int timeout: The maximum clock stretching timeout - (used only for //| :class:`bitbangio.I2C`; ignored for :class:`busio.I2C`) //| """ //| ... @@ -62,6 +62,8 @@ static mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz const mcu_pin_obj_t *scl = validate_obj_is_free_pin(args[ARG_scl].u_obj, MP_QSTR_scl); const mcu_pin_obj_t *sda = validate_obj_is_free_pin(args[ARG_sda].u_obj, MP_QSTR_sda); + busio_i2c_obj_t *self = m_new_obj_with_finaliser(busio_i2c_obj_t); + self->base.type = &busio_i2c_type; common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int); return (mp_obj_t)self; #else @@ -96,12 +98,12 @@ static void check_for_deinit(busio_i2c_obj_t *self) { //| """Automatically deinitializes the hardware on context exit. See //| :ref:`lifetime-and-contextmanagers` for more info.""" //| ... -static mp_obj_t busio_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t busio_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; common_hal_busio_i2c_deinit(MP_OBJ_TO_PTR(args[0])); return mp_const_none; } -static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_i2c___exit___obj, 4, 4, busio_i2c_obj___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_i2c___exit___obj, 4, 4, busio_i2c_obj___exit__); static void check_lock(busio_i2c_obj_t *self) { asm (""); diff --git a/shared-bindings/busio/I2C.h b/shared-bindings/busio/I2C.h index da505436b086..55f2d0f01085 100644 --- a/shared-bindings/busio/I2C.h +++ b/shared-bindings/busio/I2C.h @@ -19,11 +19,15 @@ extern void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, - uint32_t timeout); + uint32_t timeout_ms); extern void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self); extern bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self); +// Mark as deinit without deiniting. This is used by displayio after copying the +// object elsewhere and prevents the heap from deiniting the object. +extern void common_hal_busio_i2c_mark_deinit(busio_i2c_obj_t *self); + extern bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self); extern bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self); extern void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self); diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 8b3c9556f488..3e1246b08760 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -12,6 +12,7 @@ #include "shared/runtime/interrupt_char.h" #include "py/runtime.h" #include "shared-bindings/board/__init__.h" +#include "shared-bindings/busio/I2C.h" #include "shared-bindings/displayio/Bitmap.h" #include "shared-bindings/displayio/Group.h" #include "shared-bindings/displayio/Palette.h" @@ -236,6 +237,8 @@ void reset_displays(void) { display_buses[j].i2cdisplay_bus.bus = &i2c->inline_bus; } } + // Mark the old i2c object so it is considered deinit. + common_hal_busio_i2c_mark_deinit(original_i2c); } #endif #if CIRCUITPY_RGBMATRIX From eff544c16c8a376a80c3aa5d13f5b3b1dcfea81b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 20 Sep 2024 17:48:17 -0400 Subject: [PATCH 017/252] espressif: get new I2C driver working - Starts with @tannewt's changes. - Make sure proper component is being compiled. - Added `I2C.probe()` as a visible new method. This was a hidden common-hal method, but the C version of adafruit_bus_device could not use it because it needs to call probe via a Python method call. So make it visible. It's useful, and `I2C.scan()` could be phased out, since now `.scan()` can be implemented in Python with `.probe()`. - set clock-stretching timeout on espressif to a minimum of 1 second. In all impls of busio.I2C()`, the timeout is ignored and is set to a fixed 1 second. @tannewt's new code was using the passed-in value, which was often too short. To do: - switch esp-camera to new-driver version. We have to use the same I2C driver everywhere. - Check about I2CTarget. --- ports/espressif/CMakeLists.txt | 2 +- ports/espressif/Makefile | 3 +- ports/espressif/common-hal/busio/I2C.c | 24 ++++++++------- ports/espressif/mpconfigport.mk | 3 +- ports/silabs/common-hal/busio/I2C.c | 4 +-- ports/stm/common-hal/busio/I2C.c | 2 +- shared-bindings/bitbangio/I2C.c | 21 +++++++++++-- shared-bindings/busio/I2C.c | 26 ++++++++++++---- .../i2c_device/I2CDevice.c | 30 +++++-------------- 9 files changed, 68 insertions(+), 47 deletions(-) diff --git a/ports/espressif/CMakeLists.txt b/ports/espressif/CMakeLists.txt index 2a34574db05b..5fdd7e0ebadf 100644 --- a/ports/espressif/CMakeLists.txt +++ b/ports/espressif/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.16) set(ENV{IDF_PATH} ${CMAKE_SOURCE_DIR}/esp-idf) # The component list here determines what options we get in menuconfig and what the ninja file can build. -set(COMPONENTS bt driver esp_driver_dac esp_driver_gpio esp_driver_gptimer esp_driver_i2s esp_driver_ledc esp_driver_pcnt esp_driver_rmt esp_driver_spi esp_driver_tsens esp_driver_uart esp-tls esp_adc_cal esp_event esp_netif esp_psram esp_wifi esptool_py freertos log lwip main mbedtls mdns soc ulp usb wpa_supplicant esp-camera esp_lcd vfs esp_vfs_console) +set(COMPONENTS bt driver esp_driver_dac esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_i2s esp_driver_ledc esp_driver_pcnt esp_driver_rmt esp_driver_spi esp_driver_tsens esp_driver_uart esp-tls esp_adc_cal esp_event esp_netif esp_psram esp_wifi esptool_py freertos log lwip main mbedtls mdns soc ulp usb wpa_supplicant esp-camera esp_lcd vfs esp_vfs_console) set(EXTRA_COMPONENT_DIRS "esp-protocols/components/mdns" "esp-camera") include($ENV{IDF_PATH}/tools/cmake/project.cmake) diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index ec0946833cbc..15c56e605db3 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -65,7 +65,6 @@ INC += \ -isystem esp-idf/components/bt/host/nimble/nimble/porting/nimble/include \ -isystem esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/include \ -isystem esp-idf/components/bt/host/nimble/port/include \ - -isystem esp-idf/components/driver/i2c/include \ -isystem esp-idf/components/driver/touch_sensor/include \ -isystem esp-idf/components/driver/touch_sensor/$(IDF_TARGET)/include \ -isystem esp-idf/components/driver/twai/include \ @@ -613,7 +612,7 @@ ifeq ($(IDF_TARGET),esp32) BINARY_BLOBS += esp-idf/components/esp_phy/lib/$(IDF_TARGET)/librtc.a endif -ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_gpio esp_driver_gptimer esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log newlib nvs_flash pthread soc spi_flash vfs esp_vfs_console +ESP_IDF_COMPONENTS_LINK = $(IDF_TARGET_ARCH) $(CHIP_COMPONENTS) app_update bootloader_support driver esp_driver_gpio esp_driver_gptimer esp_driver_i2c esp_driver_ledc esp_driver_spi esp_driver_uart efuse esp_adc esp_app_format esp_common esp_event esp_hw_support esp_mm esp_partition esp_pm esp_ringbuf esp_rom esp_system esp_timer freertos hal heap log newlib nvs_flash pthread soc spi_flash vfs esp_vfs_console ifneq ($(CIRCUITPY_WIFI),0) ESP_IDF_COMPONENTS_LINK += esp_coex esp_netif esp-tls esp_wifi lwip mbedtls mdns wpa_supplicant esp_phy endif diff --git a/ports/espressif/common-hal/busio/I2C.c b/ports/espressif/common-hal/busio/I2C.c index 3b12531cfc69..d0f9089d6952 100644 --- a/ports/espressif/common-hal/busio/I2C.c +++ b/ports/espressif/common-hal/busio/I2C.c @@ -93,11 +93,15 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, self->scl_pin = scl; self->has_lock = false; self->frequency = frequency; - self->timeout_ms = timeout_us / 1000; - // Round up timeout to nearest ms. - if (timeout_us % 1000 != 0) { - self->timeout_ms += 1; - } + + // Ignore the passed-in clock-stretching timeout. It is not used, as documented in shared-bindings. + // Instead use 1000 ms, which is standard across ports. + // self->timeout_ms = timeout_us / 1000; + // // Round up timeout to nearest ms. + // if (timeout_us % 1000 != 0) { + // self->timeout_ms += 1; + // } + self->timeout_ms = 1000; claim_pin(sda); claim_pin(scl); @@ -164,11 +168,11 @@ static uint8_t convert_esp_err(esp_err_t result) { } } -static size_t _transaction_duration(size_t frequency, size_t len) { +static size_t _transaction_duration_ms(size_t frequency, size_t len) { size_t khz = frequency / 1000; size_t bytes_per_ms = khz / 8; // + 1 for the address byte - return (len + 1) / bytes_per_ms; + return (len + 1) / bytes_per_ms + 1000; } uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, const uint8_t *data, size_t len) { @@ -179,7 +183,7 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, const u }; i2c_master_dev_handle_t dev_handle; CHECK_ESP_RESULT(i2c_master_bus_add_device(self->handle, &dev_config, &dev_handle)); - esp_err_t result = i2c_master_transmit(dev_handle, data, len, _transaction_duration(self->frequency, len) + self->timeout_ms); + esp_err_t result = i2c_master_transmit(dev_handle, data, len, _transaction_duration_ms(self->frequency, len) + self->timeout_ms); CHECK_ESP_RESULT(i2c_master_bus_rm_device(dev_handle)); return convert_esp_err(result); } @@ -192,7 +196,7 @@ uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, uint8_t }; i2c_master_dev_handle_t dev_handle; CHECK_ESP_RESULT(i2c_master_bus_add_device(self->handle, &dev_config, &dev_handle)); - esp_err_t result = i2c_master_receive(dev_handle, data, len, _transaction_duration(self->frequency, len) + self->timeout_ms); + esp_err_t result = i2c_master_receive(dev_handle, data, len, _transaction_duration_ms(self->frequency, len) + self->timeout_ms); CHECK_ESP_RESULT(i2c_master_bus_rm_device(dev_handle)); return convert_esp_err(result); } @@ -206,7 +210,7 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr, }; i2c_master_dev_handle_t dev_handle; CHECK_ESP_RESULT(i2c_master_bus_add_device(self->handle, &dev_config, &dev_handle)); - esp_err_t result = i2c_master_transmit_receive(dev_handle, out_data, out_len, in_data, in_len, _transaction_duration(self->frequency, out_len) + _transaction_duration(self->frequency, in_len) + self->timeout_ms); + esp_err_t result = i2c_master_transmit_receive(dev_handle, out_data, out_len, in_data, in_len, _transaction_duration_ms(self->frequency, out_len) + _transaction_duration_ms(self->frequency, in_len) + self->timeout_ms); CHECK_ESP_RESULT(i2c_master_bus_rm_device(dev_handle)); return convert_esp_err(result); } diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index 0d98f7bdab6b..c8f0a661cae0 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -37,7 +37,8 @@ CIRCUITPY_BLEIO ?= 1 CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_CANIO ?= 1 CIRCUITPY_COUNTIO ?= 1 -CIRCUITPY_ESPCAMERA ?= 1 +############ TEMPORARY while working on new I2C driver +CIRCUITPY_ESPCAMERA ?= 0 CIRCUITPY_ESPIDF ?= 1 CIRCUITPY_ESPULP ?= 1 CIRCUITPY_FRAMEBUFFERIO ?= 1 diff --git a/ports/silabs/common-hal/busio/I2C.c b/ports/silabs/common-hal/busio/I2C.c index 443b2e94fc1d..adfaee8e4e91 100644 --- a/ports/silabs/common-hal/busio/I2C.c +++ b/ports/silabs/common-hal/busio/I2C.c @@ -30,8 +30,8 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -STATIC I2CSPM_Init_TypeDef i2cspm_init; -STATIC bool in_used = false; +static I2CSPM_Init_TypeDef i2cspm_init; +static bool in_used = false; // Construct I2C protocol, this function init i2c peripheral void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, diff --git a/ports/stm/common-hal/busio/I2C.c b/ports/stm/common-hal/busio/I2C.c index b1d9e0033935..7df96e5d2799 100644 --- a/ports/stm/common-hal/busio/I2C.c +++ b/ports/stm/common-hal/busio/I2C.c @@ -40,7 +40,7 @@ // Arrays use 0 based numbering: I2C1 is stored at index 0 #define MAX_I2C 4 -STATIC bool reserved_i2c[MAX_I2C]; +static bool reserved_i2c[MAX_I2C]; #define ALL_CLOCKS 0xFF static void i2c_clock_enable(uint8_t mask); diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index 102e43083d30..c1e42511e975 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -59,8 +59,7 @@ static mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mcu_pin_obj_t *scl = validate_obj_is_free_pin(args[ARG_scl].u_obj, MP_QSTR_scl); const mcu_pin_obj_t *sda = validate_obj_is_free_pin(args[ARG_sda].u_obj, MP_QSTR_sda); - bitbangio_i2c_obj_t *self = m_new_obj_with_finaliser(bitbangio_i2c_obj_t); - self->base.type = &bitbangio_i2c_type; + bitbangio_i2c_obj_t *self = mp_obj_malloc_with_finaliser(bitbangio_i2c_obj_t, &bitbangio_i2c_type); shared_module_bitbangio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int); return (mp_obj_t)self; } @@ -103,6 +102,23 @@ static void check_lock(bitbangio_i2c_obj_t *self) { } } +//| def probe(self, address: int) -> List[int]: +//| """Check if a device at the specified address responds. +//| +//| :param int address: 7-bit device address +//| :return: ``True`` if a device at ``address`` responds; ``False`` otherwise +//| :rtype: bool""" +//| ... +static mp_obj_t bitbangio_i2c_probe(mp_obj_t self_in, mp_obj_t address_obj) { + bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + check_lock(self); + + const uint16_t addr = mp_obj_get_int(address_obj); + return mp_obj_new_bool(shared_module_bitbangio_i2c_probe(self, addr)); +} +MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_i2c_probe_obj, bitbangio_i2c_probe); + //| def scan(self) -> List[int]: //| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of //| those that respond. A device responds if it pulls the SDA line low after @@ -331,6 +347,7 @@ static const mp_rom_map_elem_t bitbangio_i2c_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&bitbangio_i2c_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&bitbangio_i2c_obj___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_probe), MP_ROM_PTR(&bitbangio_i2c_probe_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&bitbangio_i2c_scan_obj) }, { MP_ROM_QSTR(MP_QSTR_try_lock), MP_ROM_PTR(&bitbangio_i2c_try_lock_obj) }, diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 7146480235eb..243054e8e18d 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -48,7 +48,6 @@ //| ... static mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if CIRCUITPY_BUSIO_I2C - busio_i2c_obj_t *self = mp_obj_malloc(busio_i2c_obj_t, &busio_i2c_type); enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout }; static const mp_arg_t allowed_args[] = { { MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -62,8 +61,7 @@ static mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz const mcu_pin_obj_t *scl = validate_obj_is_free_pin(args[ARG_scl].u_obj, MP_QSTR_scl); const mcu_pin_obj_t *sda = validate_obj_is_free_pin(args[ARG_sda].u_obj, MP_QSTR_sda); - busio_i2c_obj_t *self = m_new_obj_with_finaliser(busio_i2c_obj_t); - self->base.type = &busio_i2c_type; + busio_i2c_obj_t *self = mp_obj_malloc_with_finaliser(busio_i2c_obj_t, &busio_i2c_type); common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int); return (mp_obj_t)self; #else @@ -98,12 +96,12 @@ static void check_for_deinit(busio_i2c_obj_t *self) { //| """Automatically deinitializes the hardware on context exit. See //| :ref:`lifetime-and-contextmanagers` for more info.""" //| ... -STATIC mp_obj_t busio_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t busio_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; common_hal_busio_i2c_deinit(MP_OBJ_TO_PTR(args[0])); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_i2c___exit___obj, 4, 4, busio_i2c_obj___exit__); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_i2c___exit___obj, 4, 4, busio_i2c_obj___exit__); static void check_lock(busio_i2c_obj_t *self) { asm (""); @@ -112,6 +110,23 @@ static void check_lock(busio_i2c_obj_t *self) { } } +//| def probe(self, address: int) -> List[int]: +//| """Check if a device at the specified address responds. +//| +//| :param int address: 7-bit device address +//| :return: ``True`` if a device at ``address`` responds; ``False`` otherwise +//| :rtype: bool""" +//| ... +static mp_obj_t busio_i2c_probe(mp_obj_t self_in, mp_obj_t address_obj) { + busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + check_lock(self); + + const uint16_t addr = mp_obj_get_int(address_obj); + return mp_obj_new_bool(common_hal_busio_i2c_probe(self, addr)); +} +MP_DEFINE_CONST_FUN_OBJ_2(busio_i2c_probe_obj, busio_i2c_probe); + //| def scan(self) -> List[int]: //| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a //| list of those that respond. @@ -366,6 +381,7 @@ static const mp_rom_map_elem_t busio_i2c_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&busio_i2c_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&busio_i2c___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_probe), MP_ROM_PTR(&busio_i2c_probe_obj) }, { MP_ROM_QSTR(MP_QSTR_scan), MP_ROM_PTR(&busio_i2c_scan_obj) }, { MP_ROM_QSTR(MP_QSTR_try_lock), MP_ROM_PTR(&busio_i2c_try_lock_obj) }, diff --git a/shared-module/adafruit_bus_device/i2c_device/I2CDevice.c b/shared-module/adafruit_bus_device/i2c_device/I2CDevice.c index 0795e29f3829..e01875452b11 100644 --- a/shared-module/adafruit_bus_device/i2c_device/I2CDevice.c +++ b/shared-module/adafruit_bus_device/i2c_device/I2CDevice.c @@ -41,30 +41,14 @@ void common_hal_adafruit_bus_device_i2cdevice_unlock(adafruit_bus_device_i2cdevi void common_hal_adafruit_bus_device_i2cdevice_probe_for_device(adafruit_bus_device_i2cdevice_obj_t *self) { common_hal_adafruit_bus_device_i2cdevice_lock(self); - mp_buffer_info_t write_bufinfo; - mp_obj_t write_buffer = mp_obj_new_bytearray_of_zeros(0); - mp_get_buffer_raise(write_buffer, &write_bufinfo, MP_BUFFER_READ); + mp_obj_t dest[3]; + mp_load_method(self->i2c, MP_QSTR_probe, dest); + dest[2] = MP_OBJ_NEW_SMALL_INT(self->device_address); + const bool found = mp_obj_is_true(mp_call_method_n_kw(1, 0, dest)); - mp_obj_t dest[4]; - - /* catch exceptions that may be thrown while probing for the device */ - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - mp_load_method(self->i2c, MP_QSTR_writeto, dest); - dest[2] = MP_OBJ_NEW_SMALL_INT(self->device_address); - dest[3] = write_buffer; - mp_call_method_n_kw(2, 0, dest); - nlr_pop(); - } else { - common_hal_adafruit_bus_device_i2cdevice_unlock(self); + common_hal_adafruit_bus_device_i2cdevice_unlock(self); - if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_OSError))) { - mp_raise_ValueError_varg(MP_ERROR_TEXT("No I2C device at address: 0x%x"), self->device_address); - } else { - /* In case we receive an unrelated exception pass it up */ - nlr_raise(MP_OBJ_FROM_PTR(nlr.ret_val)); - } + if (!found) { + mp_raise_ValueError_varg(MP_ERROR_TEXT("No I2C device at address: 0x%x"), self->device_address); } - - common_hal_adafruit_bus_device_i2cdevice_unlock(self); } From d88b0c7840373588587fc0b9900428c272f62720 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 21 Sep 2024 15:51:38 -0500 Subject: [PATCH 018/252] Change mix to BlockInput --- shared-bindings/audiodelays/Echo.c | 14 +++---------- shared-bindings/audiodelays/Echo.h | 6 +++--- shared-module/audiodelays/Echo.c | 32 ++++++++++++++++++++---------- shared-module/audiodelays/Echo.h | 3 ++- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index ee4fbb2ec326..1ef5bfc1e7b1 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -44,11 +44,6 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar : mp_obj_get_float(args[ARG_decay].u_obj); mp_arg_validate_float_range(decay, 0.0f, 1.0f, MP_QSTR_decay); - mp_float_t mix = (args[ARG_mix].u_obj == MP_OBJ_NULL) - ? (mp_float_t)MIX_DEFAULT - : mp_obj_get_float(args[ARG_mix].u_obj); - mp_arg_validate_float_range(mix, 0.0f, 1.0f, MP_QSTR_mix); - mp_int_t channel_count = mp_arg_validate_int_range(args[ARG_channel_count].u_int, 1, 2, MP_QSTR_channel_count); mp_int_t sample_rate = mp_arg_validate_int_min(args[ARG_sample_rate].u_int, 1, MP_QSTR_sample_rate); mp_int_t bits_per_sample = args[ARG_bits_per_sample].u_int; @@ -57,7 +52,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar } audiodelays_echo_obj_t *self = mp_obj_malloc(audiodelays_echo_obj_t, &audiodelays_echo_type); - common_hal_audiodelays_echo_construct(self, delay_ms, decay, mix, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + common_hal_audiodelays_echo_construct(self, delay_ms, decay, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); return MP_OBJ_FROM_PTR(self); } @@ -162,7 +157,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_decay_obj, //| mix: float //| """The rate the echo mix between 0 and 1.""" static mp_obj_t audiodelays_echo_obj_get_mix(mp_obj_t self_in) { - return mp_obj_new_float(common_hal_audiodelays_echo_get_mix(self_in)); + return common_hal_audiodelays_echo_get_mix(self_in); } MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_mix_obj, audiodelays_echo_obj_get_mix); @@ -175,10 +170,7 @@ static mp_obj_t audiodelays_echo_obj_set_mix(size_t n_args, const mp_obj_t *pos_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_float_t mix = mp_obj_get_float(args[ARG_mix].u_obj); - mp_arg_validate_float_range(mix, 0.0f, 1.0f, MP_QSTR_mix); - - common_hal_audiodelays_echo_set_mix(self, mix); + common_hal_audiodelays_echo_set_mix(self, args[ARG_mix].u_obj); return mp_const_none; } diff --git a/shared-bindings/audiodelays/Echo.h b/shared-bindings/audiodelays/Echo.h index 470e68a75320..df9be6407cb6 100644 --- a/shared-bindings/audiodelays/Echo.h +++ b/shared-bindings/audiodelays/Echo.h @@ -11,7 +11,7 @@ extern const mp_obj_type_t audiodelays_echo_type; void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, - uint32_t delay_ms, mp_float_t decay, mp_float_t mix, + uint32_t delay_ms, mp_float_t decay, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate); @@ -28,8 +28,8 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, uint mp_float_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self); void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_float_t decay); -mp_float_t common_hal_audiodelays_echo_get_mix(audiodelays_echo_obj_t *self); -void common_hal_audiodelays_echo_set_mix(audiodelays_echo_obj_t *self, mp_float_t decay); +mp_obj_t common_hal_audiodelays_echo_get_mix(audiodelays_echo_obj_t *self); +void common_hal_audiodelays_echo_set_mix(audiodelays_echo_obj_t *self, mp_obj_t arg); bool common_hal_audiodelays_echo_get_playing(audiodelays_echo_obj_t *self); void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sample, bool loop); diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index b4540423e4ed..da60eb4a580e 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -10,7 +10,7 @@ #include "shared-module/audiomixer/utils.h" -void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t delay_ms, mp_float_t decay, mp_float_t mix, +void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t delay_ms, mp_float_t decay, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { @@ -29,7 +29,11 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ memset(self->buffer, 0, self->buffer_len); self->decay = (uint16_t)(decay * (1 << 15)); - self->mix = (uint16_t)(mix * (1 << 15)); + + if (mix == MP_OBJ_NULL) { + mix = mp_obj_new_float(0.5); + } + synthio_block_assign_slot(mix, &self->mix, MP_QSTR_mix); // calculate buffer size for the set delay self->delay_ms = delay_ms; @@ -103,13 +107,12 @@ void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_floa self->decay = (uint16_t)(decay * (1 << 15)); } -mp_float_t common_hal_audiodelays_echo_get_mix(audiodelays_echo_obj_t *self) { - return (mp_float_t)self->mix / (1 << 15); +mp_obj_t common_hal_audiodelays_echo_get_mix(audiodelays_echo_obj_t *self) { + return self->mix.obj; } -void common_hal_audiodelays_echo_set_mix(audiodelays_echo_obj_t *self, mp_float_t mix) { - self->mix = (uint16_t)(mix * (1 << 15)); - mp_printf(&mp_plat_print, "mix %d\n", self->mix); +void common_hal_audiodelays_echo_set_mix(audiodelays_echo_obj_t *self, mp_obj_t arg) { + synthio_block_assign_slot(arg, &self->mix, MP_QSTR_mix); } uint32_t common_hal_audiodelays_echo_get_sample_rate(audiodelays_echo_obj_t *self) { @@ -177,6 +180,13 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * uint32_t *word_buffer = (uint32_t *)self->buffer; uint32_t length = self->buffer_len / sizeof(uint32_t); uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint32_t); + mp_float_t f_mix = synthio_block_slot_get(&self->mix); + if (f_mix > 1.0) { + f_mix = 1.0; + } else if (f_mix < 0.0) { + f_mix = 0.0; + } + uint16_t mix = (uint16_t)(f_mix * (1 << 15)); while (length != 0) { if (self->sample_buffer_length == 0) { @@ -201,7 +211,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // If we have no sample keep the echo echoing if (self->sample == NULL) { if (MP_LIKELY(self->bits_per_sample == 16)) { - if (self->mix == 0) { // no effect and no sample sound + if (mix == 0) { // no effect and no sample sound for (uint32_t i = 0; i < length; i++) { word_buffer[i] = 0; } @@ -212,7 +222,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * word_buffer[i] = mult16signed(echo, self->decay); self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; - word_buffer[i] = mult16signed(word_buffer[i], self->mix); + word_buffer[i] = mult16signed(word_buffer[i], mix); if (self->echo_buffer_read_pos >= echo_buf_len) { self->echo_buffer_read_pos = 0; @@ -246,7 +256,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * uint32_t *sample_src = self->sample_remaining_buffer; if (MP_LIKELY(self->bits_per_sample == 16)) { - if (self->mix == 0) { // sample only + if (mix == 0) { // sample only for (uint32_t i = 0; i < n; i++) { word_buffer[i] = sample_src[i]; } @@ -260,7 +270,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * word_buffer[i] = add16signed(mult16signed(echo, self->decay), sample_word); self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; - word_buffer[i] = add16signed(mult16signed(sample_word, 32768 - self->mix), mult16signed(word_buffer[i], self->mix)); + word_buffer[i] = add16signed(mult16signed(sample_word, 32768 - mix), mult16signed(word_buffer[i], mix)); if (self->echo_buffer_read_pos >= echo_buf_len) { self->echo_buffer_read_pos = 0; diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index 1660c837c89f..a3bf1d484be5 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -8,6 +8,7 @@ #include "py/obj.h" #include "shared-module/audiocore/__init__.h" +#include "shared-module/synthio/block.h" extern const mp_obj_type_t audiodelays_echo_type; @@ -15,7 +16,7 @@ typedef struct { mp_obj_base_t base; uint32_t delay_ms; uint16_t decay; - uint16_t mix; + synthio_block_slot_t mix; uint8_t bits_per_sample; bool samples_signed; uint8_t channel_count; From 839ae402e34f71310ef518479e13593ca997d6a9 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Sun, 22 Sep 2024 09:48:11 -0600 Subject: [PATCH 019/252] Added digitalio module. --- ports/analog/boards/APARD/mpconfigboard.h | 2 +- ports/analog/boards/APARD/pins.c | 216 +++++----- .../common-hal/digitalio/DigitalInOut.c | 201 +++++++++ .../common-hal/digitalio/DigitalInOut.h | 15 + ports/analog/common-hal/digitalio/__init__.c | 7 + ports/analog/common-hal/microcontroller/Pin.c | 45 +- .../common-hal/microcontroller/__init__.c | 404 +++++++++--------- ports/analog/mpconfigport.mk | 2 +- ports/analog/peripherals/max32690/pins.c | 220 +++++----- ports/analog/peripherals/pins.h | 22 +- 10 files changed, 678 insertions(+), 456 deletions(-) create mode 100644 ports/analog/common-hal/digitalio/DigitalInOut.c create mode 100644 ports/analog/common-hal/digitalio/DigitalInOut.h create mode 100644 ports/analog/common-hal/digitalio/__init__.c diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/APARD/mpconfigboard.h index 972ca72abeba..0e09a4ede674 100644 --- a/ports/analog/boards/APARD/mpconfigboard.h +++ b/ports/analog/boards/APARD/mpconfigboard.h @@ -22,7 +22,7 @@ #define FLASH_PAGE_SIZE (0x4000) // 16384 byte pages (16 KiB) #define BOARD_HAS_CRYSTAL 1 -#define NUM_GPIO_PORTS 4 +#define NUM_GPIO_PORTS 5 #define CONSOLE_UART MXC_UART0 // #if INTERNAL_FLASH_FILESYSTEM diff --git a/ports/analog/boards/APARD/pins.c b/ports/analog/boards/APARD/pins.c index 89bc41832751..5b736385dc58 100644 --- a/ports/analog/boards/APARD/pins.c +++ b/ports/analog/boards/APARD/pins.c @@ -10,117 +10,117 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS //P0 - { MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_P0_00) }, - { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_P0_01) }, - { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_P0_02) }, - { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_P0_03) }, - { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_P0_04) }, - { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_P0_05) }, - { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_P0_06) }, - { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_P0_07) }, - { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_P0_08) }, - { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_P0_09) }, - { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_P0_10) }, - { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_P0_11) }, - { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_P0_12) }, - { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_P0_13) }, - { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_P0_14) }, - { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_P0_15) }, - { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_P0_16) }, - { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_P0_17) }, - { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_P0_18) }, - { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_P0_19) }, - { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_P0_20) }, - { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_P0_21) }, - { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_P0_22) }, - { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_P0_23) }, - { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_P0_24) }, - { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_P0_25) }, - { MP_ROM_QSTR(MP_QSTR_PA26), MP_ROM_PTR(&pin_P0_26) }, - { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_P0_27) }, - { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_P0_28) }, - { MP_ROM_QSTR(MP_QSTR_PA29), MP_ROM_PTR(&pin_P0_29) }, - { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_P0_30) }, - { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_P0_31) }, + { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) }, + { MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) }, + { MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) }, + { MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) }, + { MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) }, + { MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) }, + { MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) }, + { MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) }, + { MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) }, + { MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) }, + { MP_ROM_QSTR(MP_QSTR_P0_26), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) }, + { MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, //P1 - { MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_P1_00) }, - { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_P1_01) }, - { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_P1_02) }, - { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_P1_03) }, - { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_P1_04) }, - { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_P1_05) }, - { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_P1_06) }, - { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_P1_07) }, - { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_P1_08) }, - { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_P1_09) }, - { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_P1_10) }, - { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_P1_11) }, - { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_P1_12) }, - { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_P1_13) }, - { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_P1_14) }, - { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_P1_15) }, - { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_P1_16) }, - { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_P1_17) }, - { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_P1_18) }, - { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_P1_19) }, - { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_P1_20) }, - { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_P1_21) }, - { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_P1_22) }, - { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_P1_23) }, - { MP_ROM_QSTR(MP_QSTR_PB24), MP_ROM_PTR(&pin_P1_24) }, - { MP_ROM_QSTR(MP_QSTR_PB25), MP_ROM_PTR(&pin_P1_25) }, - { MP_ROM_QSTR(MP_QSTR_PB26), MP_ROM_PTR(&pin_P1_26) }, - { MP_ROM_QSTR(MP_QSTR_PB27), MP_ROM_PTR(&pin_P1_27) }, - { MP_ROM_QSTR(MP_QSTR_PB28), MP_ROM_PTR(&pin_P1_28) }, - { MP_ROM_QSTR(MP_QSTR_PB29), MP_ROM_PTR(&pin_P1_29) }, - { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_P1_30) }, - { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_P1_31) }, + { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, + { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, + { MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) }, + { MP_ROM_QSTR(MP_QSTR_P1_14), MP_ROM_PTR(&pin_P1_14) }, + { MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_P1_16), MP_ROM_PTR(&pin_P1_16) }, + { MP_ROM_QSTR(MP_QSTR_P1_17), MP_ROM_PTR(&pin_P1_17) }, + { MP_ROM_QSTR(MP_QSTR_P1_18), MP_ROM_PTR(&pin_P1_18) }, + { MP_ROM_QSTR(MP_QSTR_P1_19), MP_ROM_PTR(&pin_P1_19) }, + { MP_ROM_QSTR(MP_QSTR_P1_20), MP_ROM_PTR(&pin_P1_20) }, + { MP_ROM_QSTR(MP_QSTR_P1_21), MP_ROM_PTR(&pin_P1_21) }, + { MP_ROM_QSTR(MP_QSTR_P1_22), MP_ROM_PTR(&pin_P1_22) }, + { MP_ROM_QSTR(MP_QSTR_P1_23), MP_ROM_PTR(&pin_P1_23) }, + { MP_ROM_QSTR(MP_QSTR_P1_24), MP_ROM_PTR(&pin_P1_24) }, + { MP_ROM_QSTR(MP_QSTR_P1_25), MP_ROM_PTR(&pin_P1_25) }, + { MP_ROM_QSTR(MP_QSTR_P1_26), MP_ROM_PTR(&pin_P1_26) }, + { MP_ROM_QSTR(MP_QSTR_P1_27), MP_ROM_PTR(&pin_P1_27) }, + { MP_ROM_QSTR(MP_QSTR_P1_28), MP_ROM_PTR(&pin_P1_28) }, + { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, + { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, + { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, //P2 - { MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_P2_00) }, - { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_P2_01) }, - { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_P2_02) }, - { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_P2_03) }, - { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_P2_04) }, - { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_P2_05) }, - { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_P2_06) }, - { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_P2_07) }, - { MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_P2_08) }, - { MP_ROM_QSTR(MP_QSTR_PC09), MP_ROM_PTR(&pin_P2_09) }, - { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_P2_10) }, - { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_P2_11) }, - { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_P2_12) }, - { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_P2_13) }, - { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_P2_14) }, - { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_P2_15) }, - { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_P2_16) }, - { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_P2_17) }, - { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_P2_18) }, - { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_P2_19) }, - { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_P2_20) }, - { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_P2_21) }, - { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_P2_22) }, - { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_P2_23) }, - { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_P2_24) }, - { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_P2_25) }, - { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_P2_26) }, - { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_P2_27) }, - { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_P2_28) }, - { MP_ROM_QSTR(MP_QSTR_PC29), MP_ROM_PTR(&pin_P2_29) }, - { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_P2_30) }, - { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_P2_31) }, + { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_P2_08), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_P2_09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, + { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, + { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, + { MP_ROM_QSTR(MP_QSTR_P2_13), MP_ROM_PTR(&pin_P2_13) }, + { MP_ROM_QSTR(MP_QSTR_P2_14), MP_ROM_PTR(&pin_P2_14) }, + { MP_ROM_QSTR(MP_QSTR_P2_15), MP_ROM_PTR(&pin_P2_15) }, + { MP_ROM_QSTR(MP_QSTR_P2_16), MP_ROM_PTR(&pin_P2_16) }, + { MP_ROM_QSTR(MP_QSTR_P2_17), MP_ROM_PTR(&pin_P2_17) }, + { MP_ROM_QSTR(MP_QSTR_P2_18), MP_ROM_PTR(&pin_P2_18) }, + { MP_ROM_QSTR(MP_QSTR_P2_19), MP_ROM_PTR(&pin_P2_19) }, + { MP_ROM_QSTR(MP_QSTR_P2_20), MP_ROM_PTR(&pin_P2_20) }, + { MP_ROM_QSTR(MP_QSTR_P2_21), MP_ROM_PTR(&pin_P2_21) }, + { MP_ROM_QSTR(MP_QSTR_P2_22), MP_ROM_PTR(&pin_P2_22) }, + { MP_ROM_QSTR(MP_QSTR_P2_23), MP_ROM_PTR(&pin_P2_23) }, + { MP_ROM_QSTR(MP_QSTR_P2_24), MP_ROM_PTR(&pin_P2_24) }, + { MP_ROM_QSTR(MP_QSTR_P2_25), MP_ROM_PTR(&pin_P2_25) }, + { MP_ROM_QSTR(MP_QSTR_P2_26), MP_ROM_PTR(&pin_P2_26) }, + { MP_ROM_QSTR(MP_QSTR_P2_27), MP_ROM_PTR(&pin_P2_27) }, + { MP_ROM_QSTR(MP_QSTR_P2_28), MP_ROM_PTR(&pin_P2_28) }, + { MP_ROM_QSTR(MP_QSTR_P2_29), MP_ROM_PTR(&pin_P2_29) }, + { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, + { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, //P3 - { MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_P3_00) }, - { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_P3_01) }, - { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_P3_02) }, - { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_P3_03) }, - { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_P3_04) }, - { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_P3_05) }, - { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_P3_06) }, - { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_P3_07) }, - { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_P3_08) }, - { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_P3_09) }, + { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, //P4 - { MP_ROM_QSTR(MP_QSTR_PE00), MP_ROM_PTR(&pin_P4_00) }, - { MP_ROM_QSTR(MP_QSTR_PE01), MP_ROM_PTR(&pin_P4_01) }, + { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c new file mode 100644 index 000000000000..59a242239e0d --- /dev/null +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -0,0 +1,201 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/Pin.h" + +#include "gpio_reva.h" + +extern mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS]; + +void common_hal_digitalio_digitalinout_never_reset( + digitalio_digitalinout_obj_t *self) { + common_hal_never_reset_pin(self->pin); +} + +bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) { + return self->pin == NULL; +} + +digitalinout_result_t common_hal_digitalio_digitalinout_construct( + digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) { + + common_hal_mcu_pin_claim(pin); + self->pin = pin; + + mxc_gpio_cfg_t new_gpio_cfg = { + .port = gpio_ports[self->pin->port], + .mask = (self->pin->mask), + .vssel = self->pin->level, + .func = MXC_GPIO_FUNC_IN, + .drvstr = MXC_GPIO_DRVSTR_0, + .pad = MXC_GPIO_PAD_NONE, + }; + MXC_GPIO_Config(&new_gpio_cfg); + + return DIGITALINOUT_OK; +} + +void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) { + if (common_hal_digitalio_digitalinout_deinited(self)) { + return; + } + + reset_pin_number(self->pin->port, self->pin->mask); + self->pin = NULL; +} + +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) +{ + mxc_gpio_regs_t* port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); + return common_hal_digitalio_digitalinout_set_pull(self, pull); +} + +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( + digitalio_digitalinout_obj_t *self, bool value, + digitalio_drive_mode_t drive_mode) +{ + mxc_gpio_regs_t* port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); + common_hal_digitalio_digitalinout_set_value(self, value); + + // todo (low): MSDK Hardware does not support open-drain configuration except + // todo (low): when directly managed by a peripheral such as I2C. + // todo (low): find a way to signal this perhaps to any upstream code + if (drive_mode != DRIVE_MODE_PUSH_PULL) { + return DIGITALINOUT_OK; + } + return DIGITALINOUT_OK; +} + +digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( + digitalio_digitalinout_obj_t *self) { + + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + // Check that I/O mode is enabled and we don't have in AND out on at the same time + MP_STATIC_ASSERT(!( (port->en0 & mask) && (port->inen & mask) && (port->outen & mask) )); + + if ( (port->en0 & mask) && (port->outen & mask) ) + { + return DIRECTION_OUTPUT; + } + else if ( (port->en0 & mask) && (port->inen & mask) ) + { + return DIRECTION_INPUT; + } + + // do not try to drive a pin which has an odd configuration here + else return DIRECTION_INPUT; +} + +void common_hal_digitalio_digitalinout_set_value( + digitalio_digitalinout_obj_t *self, bool value) +{ + digitalio_direction_t dir = + common_hal_digitalio_digitalinout_get_direction(self); + + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + if (dir == DIRECTION_OUTPUT) { + if (value == true) { + MXC_GPIO_OutSet(port, mask); + } + else { + MXC_GPIO_OutClr(port, mask); + } + } +} + +bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self) +{ + digitalio_direction_t dir = + common_hal_digitalio_digitalinout_get_direction(self); + + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + if (dir == DIRECTION_INPUT) { + return (MXC_GPIO_InGet(port, mask)); + } + else { + return ( (port->out & mask) == true); + } +} + +digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( + digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) { + + // On MAX32, drive mode is not configurable + // and should always be push-pull unless managed by a peripheral like I2C + return DIGITALINOUT_OK; +} + +digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( + digitalio_digitalinout_obj_t *self) { + return DRIVE_MODE_PUSH_PULL; +} + +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + if ( (port->en0 & mask) && (port->inen & mask) ) { + // PULL_NONE, PULL_UP, or PULL_DOWN + switch (pull) { + case PULL_NONE: + port->padctrl0 &= ~(mask); + port->padctrl1 &= ~(mask); + break; + case PULL_UP: + port->padctrl0 |= mask; + port->padctrl1 &= ~(mask); + break; + case PULL_DOWN: + port->padctrl0 &= ~(mask); + port->padctrl1 |= mask; + break; + default: + break; + } + return DIGITALINOUT_OK; + } + else { + return DIGITALINOUT_PIN_BUSY; + } +} + +digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( + digitalio_digitalinout_obj_t *self) { + + bool pin_padctrl0 = (gpio_ports[self->pin->port]->padctrl0) & ( self->pin->mask); + bool pin_padctrl1 = (gpio_ports[self->pin->port]->padctrl1) & ( self->pin->mask); + + if ( (pin_padctrl0) && !(pin_padctrl1) ) { + return PULL_UP; + } + else if ( !(pin_padctrl0) && pin_padctrl1 ) { + return PULL_DOWN; + } + else if ( !(pin_padctrl0) && !(pin_padctrl1) ) { + return PULL_NONE; + } + + // Shouldn't happen, (value 0b11 is reserved) + else { + return PULL_NONE; + } +} diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.h b/ports/analog/common-hal/digitalio/DigitalInOut.h new file mode 100644 index 000000000000..f58b23832b19 --- /dev/null +++ b/ports/analog/common-hal/digitalio/DigitalInOut.h @@ -0,0 +1,15 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "common-hal/microcontroller/Pin.h" + +typedef struct { + mp_obj_base_t base; + const mcu_pin_obj_t *pin; +} digitalio_digitalinout_obj_t; diff --git a/ports/analog/common-hal/digitalio/__init__.c b/ports/analog/common-hal/digitalio/__init__.c new file mode 100644 index 000000000000..fa222ed01f03 --- /dev/null +++ b/ports/analog/common-hal/digitalio/__init__.c @@ -0,0 +1,7 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Adafruit Industries LLC +// +// SPDX-License-Identifier: MIT + +// No digitalio module functions. diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 65949045cdcc..7259c0effe8a 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -11,17 +11,20 @@ #include "pins.h" #include "mxc_sys.h" -#include "max32690.h" #include "gpio.h" #include "gpio_regs.h" -// Structs to represent GPIO ports & valid pins/pads +#include "common-hal/microcontroller/Pin.h" + +static uint32_t claimed_pins[NUM_GPIO_PORTS]; + +// todo (low): try moving this to an extern in the board support #ifdef MAX32690 -// todo: special constraints are applied to GPIO4 for MAX32690. Tend to these later (low prior) -static mxc_gpio_regs_t* ports[NUM_GPIO_PORTS] = { MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3}; +#include "max32690.h" +mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = + {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; #endif -static uint32_t claimed_pins[NUM_GPIO_PORTS]; static uint32_t never_reset_pins[NUM_GPIO_PORTS]; #define INVALID_PIN 0xFF // id for invalid pin @@ -48,25 +51,25 @@ void reset_pin_number(uint8_t pin_port, uint8_t pin_pad) { /** START: RESET LOGIC for GPIOs */ // Switch to I/O mode first - ports[pin_port]->en0_set = mask; + gpio_ports[pin_port]->en0_set = mask; // set GPIO configuration enable bits to I/O - ports[pin_port]->en0_clr = mask; - ports[pin_port]->en1_clr = mask; - ports[pin_port]->en2_clr = mask; + gpio_ports[pin_port]->en0_clr = mask; + gpio_ports[pin_port]->en1_clr = mask; + gpio_ports[pin_port]->en2_clr = mask; // enable input mode GPIOn_INEN.pin = 1 - ports[pin_port]->inen |= mask; + gpio_ports[pin_port]->inen |= mask; // High Impedance mode enable (GPIOn_PADCTRL1 = 0, _PADCTRL0 = 0), pu/pd disable - ports[pin_port]->padctrl0 &= ~mask; - ports[pin_port]->padctrl1 &= ~mask; + gpio_ports[pin_port]->padctrl0 &= ~mask; + gpio_ports[pin_port]->padctrl1 &= ~mask; // Output mode disable GPIOn_OUTEN = 0 - ports[pin_port]->outen |= mask; + gpio_ports[pin_port]->outen |= mask; // Interrupt disable GPIOn_INTEN = 0 - ports[pin_port]->inten &= ~mask; + gpio_ports[pin_port]->inten &= ~mask; /** END: RESET LOGIC for GPIOs */ } @@ -77,22 +80,22 @@ uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { // most max32 gpio ports have 32 pins // todo: create a struct to encode # of pins for each port, since some GPIO ports differ - return pin->port * 32 + pin->pad; + return pin->port * 32 + pin->mask; } bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { if (pin == NULL) { return true; } - return !(claimed_pins[pin->port] & (pin->pad)); + return !(claimed_pins[pin->port] & (pin->mask)); } void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { - if ((pin != NULL) && (pin->pad != INVALID_PIN)) { - never_reset_pins[pin->port] |= (1 << pin->pad); + if ((pin != NULL) && (pin->mask != INVALID_PIN)) { + never_reset_pins[pin->port] |= (1 << pin->mask); // any never reset pin must also be claimed - claimed_pins[pin->port] |= (1 << pin->pad); + claimed_pins[pin->port] |= (1 << pin->mask); } } @@ -101,14 +104,14 @@ void common_hal_reset_pin(const mcu_pin_obj_t *pin) { return; } - reset_pin_number(pin->port, pin->pad); + reset_pin_number(pin->port, pin->mask); } void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { if (pin == NULL) { return; } - claimed_pins[pin->port] |= (1 << pin->pad); + claimed_pins[pin->port] |= (1 << pin->mask); } void common_hal_mcu_pin_reset_number(uint8_t pin_no) { diff --git a/ports/analog/common-hal/microcontroller/__init__.c b/ports/analog/common-hal/microcontroller/__init__.c index bbdb686195ca..207ddbe52f37 100644 --- a/ports/analog/common-hal/microcontroller/__init__.c +++ b/ports/analog/common-hal/microcontroller/__init__.c @@ -1,10 +1,10 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries -// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries -// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// SP3_X-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries +// SP3_X-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// SP3_X-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc // -// SPDX-License-Identifier: MIT +// SP3_X-License-Identifier: MIT #include "py/mphal.h" #include "py/obj.h" @@ -89,306 +89,306 @@ const mcu_processor_obj_t common_hal_mcu_processor_obj = { // This maps MCU pin names to pin objects. static const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { - #if defined(PIN_PA01) && !defined(IGNORE_PIN_PA01) - { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) }, + #if defined(PIN_P0_01) && !defined(IGNORE_PIN_P0_01) + { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, #endif - #if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02) - { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) }, + #if defined(PIN_P0_02) && !defined(IGNORE_PIN_P0_02) + { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, #endif - #if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03) - { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) }, + #if defined(PIN_P0_03) && !defined(IGNORE_PIN_P0_03) + { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, #endif - #if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04) - { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) }, + #if defined(PIN_P0_04) && !defined(IGNORE_PIN_P0_04) + { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, #endif - #if defined(PIN_PA05) && !defined(IGNORE_PIN_PA05) - { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) }, + #if defined(PIN_P0_05) && !defined(IGNORE_PIN_P0_05) + { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, #endif - #if defined(PIN_PA06) && !defined(IGNORE_PIN_PA06) - { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) }, + #if defined(PIN_P0_06) && !defined(IGNORE_PIN_P0_06) + { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, #endif - #if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07) - { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) }, + #if defined(PIN_P0_07) && !defined(IGNORE_PIN_P0_07) + { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, #endif - #if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) - { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) }, + #if defined(PIN_P0_08) && !defined(IGNORE_PIN_P0_08) + { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, #endif - #if defined(PIN_PA09) && !defined(IGNORE_PIN_PA09) - { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) }, + #if defined(PIN_P0_09) && !defined(IGNORE_PIN_P0_09) + { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, #endif - #if defined(PIN_PA10) && !defined(IGNORE_PIN_PA10) - { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) }, + #if defined(PIN_P0_10) && !defined(IGNORE_PIN_P0_10) + { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, #endif - #if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11) - { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) }, + #if defined(PIN_P0_11) && !defined(IGNORE_PIN_P0_11) + { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, #endif - #if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12) - { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) }, + #if defined(PIN_P0_12) && !defined(IGNORE_PIN_P0_12) + { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, #endif - #if defined(PIN_PA13) && !defined(IGNORE_PIN_PA13) - { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) }, + #if defined(PIN_P0_13) && !defined(IGNORE_PIN_P0_13) + { MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) }, #endif - #if defined(PIN_PA14) && !defined(IGNORE_PIN_PA14) - { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) }, + #if defined(PIN_P0_14) && !defined(IGNORE_PIN_P0_14) + { MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) }, #endif - #if defined(PIN_PA15) && !defined(IGNORE_PIN_PA15) - { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) }, + #if defined(PIN_P0_15) && !defined(IGNORE_PIN_P0_15) + { MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) }, #endif - #if defined(PIN_PA16) && !defined(IGNORE_PIN_PA16) - { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_PA16) }, + #if defined(PIN_P0_16) && !defined(IGNORE_PIN_P0_16) + { MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) }, #endif - #if defined(PIN_PA17) && !defined(IGNORE_PIN_PA17) - { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_PA17) }, + #if defined(PIN_P0_17) && !defined(IGNORE_PIN_P0_17) + { MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) }, #endif - #if defined(PIN_PA18) && !defined(IGNORE_PIN_PA18) - { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_PA18) }, + #if defined(PIN_P0_18) && !defined(IGNORE_PIN_P0_18) + { MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) }, #endif - #if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19) - { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) }, + #if defined(PIN_P0_19) && !defined(IGNORE_PIN_P0_19) + { MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) }, #endif - #if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20) - { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) }, + #if defined(PIN_P0_20) && !defined(IGNORE_PIN_P0_20) + { MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) }, #endif - #if defined(PIN_PA21) && !defined(IGNORE_PIN_PA21) - { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_PA21) }, + #if defined(PIN_P0_21) && !defined(IGNORE_PIN_P0_21) + { MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) }, #endif - #if defined(PIN_PA22) && !defined(IGNORE_PIN_PA22) - { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_PA22) }, + #if defined(PIN_P0_22) && !defined(IGNORE_PIN_P0_22) + { MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) }, #endif - #if defined(PIN_PA23) && !defined(IGNORE_PIN_PA23) - { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_PA23) }, + #if defined(PIN_P0_23) && !defined(IGNORE_PIN_P0_23) + { MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) }, #endif - #if defined(PIN_PA24) && !defined(IGNORE_PIN_PA24) - { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_PA24) }, + #if defined(PIN_P0_24) && !defined(IGNORE_PIN_P0_24) + { MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) }, #endif - #if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25) - { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) }, + #if defined(PIN_P0_25) && !defined(IGNORE_PIN_P0_25) + { MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) }, #endif - #if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27) - { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) }, + #if defined(PIN_P0_27) && !defined(IGNORE_PIN_P0_27) + { MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) }, #endif - #if defined(PIN_PA28) && !defined(IGNORE_PIN_PA28) - { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_PA28) }, + #if defined(PIN_P0_28) && !defined(IGNORE_PIN_P0_28) + { MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) }, #endif - #if defined(PIN_PA30) && !defined(IGNORE_PIN_PA30) - { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_PA30) }, + #if defined(PIN_P0_30) && !defined(IGNORE_PIN_P0_30) + { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, #endif - #if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31) - { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) }, + #if defined(PIN_P0_31) && !defined(IGNORE_PIN_P0_31) + { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, #endif - #if defined(PIN_PB01) && !defined(IGNORE_PIN_PB01) - { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) }, + #if defined(PIN_P1_01) && !defined(IGNORE_PIN_P1_01) + { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, #endif - #if defined(PIN_PB02) && !defined(IGNORE_PIN_PB02) - { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) }, + #if defined(PIN_P1_02) && !defined(IGNORE_PIN_P1_02) + { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, #endif - #if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03) - { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }, + #if defined(PIN_P1_03) && !defined(IGNORE_PIN_P1_03) + { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, #endif - #if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04) - { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) }, + #if defined(PIN_P1_04) && !defined(IGNORE_PIN_P1_04) + { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, #endif - #if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05) - { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) }, + #if defined(PIN_P1_05) && !defined(IGNORE_PIN_P1_05) + { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, #endif - #if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06) - { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) }, + #if defined(PIN_P1_06) && !defined(IGNORE_PIN_P1_06) + { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, #endif - #if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07) - { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) }, + #if defined(PIN_P1_07) && !defined(IGNORE_PIN_P1_07) + { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, #endif - #if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08) - { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) }, + #if defined(PIN_P1_08) && !defined(IGNORE_PIN_P1_08) + { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, #endif - #if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09) - { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) }, + #if defined(PIN_P1_09) && !defined(IGNORE_PIN_P1_09) + { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, #endif - #if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10) - { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) }, + #if defined(PIN_P1_10) && !defined(IGNORE_PIN_P1_10) + { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, #endif - #if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11) - { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) }, + #if defined(PIN_P1_11) && !defined(IGNORE_PIN_P1_11) + { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, #endif - #if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12) - { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) }, + #if defined(PIN_P1_12) && !defined(IGNORE_PIN_P1_12) + { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, #endif - #if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13) - { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) }, + #if defined(PIN_P1_13) && !defined(IGNORE_PIN_P1_13) + { MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) }, #endif - #if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14) - { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) }, + #if defined(PIN_P1_14) && !defined(IGNORE_PIN_P1_14) + { MP_ROM_QSTR(MP_QSTR_P1_14), MP_ROM_PTR(&pin_P1_14) }, #endif - #if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15) - { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) }, + #if defined(PIN_P1_15) && !defined(IGNORE_PIN_P1_15) + { MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) }, #endif - #if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16) - { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) }, + #if defined(PIN_P1_16) && !defined(IGNORE_PIN_P1_16) + { MP_ROM_QSTR(MP_QSTR_P1_16), MP_ROM_PTR(&pin_P1_16) }, #endif - #if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17) - { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) }, + #if defined(PIN_P1_17) && !defined(IGNORE_PIN_P1_17) + { MP_ROM_QSTR(MP_QSTR_P1_17), MP_ROM_PTR(&pin_P1_17) }, #endif - #if defined(PIN_PB18) && !defined(IGNORE_PIN_PB18) - { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_PB18) }, + #if defined(PIN_P1_18) && !defined(IGNORE_PIN_P1_18) + { MP_ROM_QSTR(MP_QSTR_P1_18), MP_ROM_PTR(&pin_P1_18) }, #endif - #if defined(PIN_PB19) && !defined(IGNORE_PIN_PB19) - { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_PB19) }, + #if defined(PIN_P1_19) && !defined(IGNORE_PIN_P1_19) + { MP_ROM_QSTR(MP_QSTR_P1_19), MP_ROM_PTR(&pin_P1_19) }, #endif - #if defined(PIN_PB20) && !defined(IGNORE_PIN_PB20) - { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_PB20) }, + #if defined(PIN_P1_20) && !defined(IGNORE_PIN_P1_20) + { MP_ROM_QSTR(MP_QSTR_P1_20), MP_ROM_PTR(&pin_P1_20) }, #endif - #if defined(PIN_PB21) && !defined(IGNORE_PIN_PB21) - { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_PB21) }, + #if defined(PIN_P1_21) && !defined(IGNORE_PIN_P1_21) + { MP_ROM_QSTR(MP_QSTR_P1_21), MP_ROM_PTR(&pin_P1_21) }, #endif - #if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22) - { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) }, + #if defined(PIN_P1_22) && !defined(IGNORE_PIN_P1_22) + { MP_ROM_QSTR(MP_QSTR_P1_22), MP_ROM_PTR(&pin_P1_22) }, #endif - #if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23) - { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) }, + #if defined(PIN_P1_23) && !defined(IGNORE_PIN_P1_23) + { MP_ROM_QSTR(MP_QSTR_P1_23), MP_ROM_PTR(&pin_P1_23) }, #endif - #if defined(PIN_PB24) && !defined(IGNORE_PIN_PB24) - { MP_ROM_QSTR(MP_QSTR_PB24), MP_ROM_PTR(&pin_PB24) }, + #if defined(PIN_P1_24) && !defined(IGNORE_PIN_P1_24) + { MP_ROM_QSTR(MP_QSTR_P1_24), MP_ROM_PTR(&pin_P1_24) }, #endif - #if defined(PIN_PB25) && !defined(IGNORE_PIN_PB25) - { MP_ROM_QSTR(MP_QSTR_PB25), MP_ROM_PTR(&pin_PB25) }, + #if defined(PIN_P1_25) && !defined(IGNORE_PIN_P1_25) + { MP_ROM_QSTR(MP_QSTR_P1_25), MP_ROM_PTR(&pin_P1_25) }, #endif - #if defined(PIN_PB26) && !defined(IGNORE_PIN_PB26) - { MP_ROM_QSTR(MP_QSTR_PB26), MP_ROM_PTR(&pin_PB26) }, + #if defined(PIN_P1_26) && !defined(IGNORE_PIN_P1_26) + { MP_ROM_QSTR(MP_QSTR_P1_26), MP_ROM_PTR(&pin_P1_26) }, #endif - #if defined(PIN_PB27) && !defined(IGNORE_PIN_PB27) - { MP_ROM_QSTR(MP_QSTR_PB27), MP_ROM_PTR(&pin_PB27) }, + #if defined(PIN_P1_27) && !defined(IGNORE_PIN_P1_27) + { MP_ROM_QSTR(MP_QSTR_P1_27), MP_ROM_PTR(&pin_P1_27) }, #endif - #if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28) - { MP_ROM_QSTR(MP_QSTR_PB28), MP_ROM_PTR(&pin_PB28) }, + #if defined(PIN_P1_28) && !defined(IGNORE_PIN_P1_28) + { MP_ROM_QSTR(MP_QSTR_P1_28), MP_ROM_PTR(&pin_P1_28) }, #endif - #if defined(PIN_PB29) && !defined(IGNORE_PIN_PB29) - { MP_ROM_QSTR(MP_QSTR_PB29), MP_ROM_PTR(&pin_PB29) }, + #if defined(PIN_P1_29) && !defined(IGNORE_PIN_P1_29) + { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, #endif - #if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30) - { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) }, + #if defined(PIN_P1_30) && !defined(IGNORE_PIN_P1_30) + { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, #endif - #if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31) - { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) }, + #if defined(PIN_P1_31) && !defined(IGNORE_PIN_P1_31) + { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, #endif - #if defined(PIN_PC01) && !defined(IGNORE_PIN_PC01) - { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) }, + #if defined(PIN_P2_01) && !defined(IGNORE_PIN_P2_01) + { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, #endif - #if defined(PIN_PC02) && !defined(IGNORE_PIN_PC02) - { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) }, + #if defined(PIN_P2_02) && !defined(IGNORE_PIN_P2_02) + { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, #endif - #if defined(PIN_PC03) && !defined(IGNORE_PIN_PC03) - { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) }, + #if defined(PIN_P2_03) && !defined(IGNORE_PIN_P2_03) + { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, #endif - #if defined(PIN_PC04) && !defined(IGNORE_PIN_PC04) - { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_PC04) }, + #if defined(PIN_P2_04) && !defined(IGNORE_PIN_P2_04) + { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, #endif - #if defined(PIN_PC05) && !defined(IGNORE_PIN_PC05) - { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) }, + #if defined(PIN_P2_05) && !defined(IGNORE_PIN_P2_05) + { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, #endif - #if defined(PIN_PC06) && !defined(IGNORE_PIN_PC06) - { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, + #if defined(PIN_P2_06) && !defined(IGNORE_PIN_P2_06) + { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, #endif - #if defined(PIN_PC07) && !defined(IGNORE_PIN_PC07) - { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, + #if defined(PIN_P2_07) && !defined(IGNORE_PIN_P2_07) + { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, #endif - #if defined(PIN_PC10) && !defined(IGNORE_PIN_PC10) - { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) }, + #if defined(PIN_P2_10) && !defined(IGNORE_PIN_P2_10) + { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, #endif - #if defined(PIN_PC11) && !defined(IGNORE_PIN_PC11) - { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) }, + #if defined(PIN_P2_11) && !defined(IGNORE_PIN_P2_11) + { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, #endif - #if defined(PIN_PC12) && !defined(IGNORE_PIN_PC12) - { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) }, + #if defined(PIN_P2_12) && !defined(IGNORE_PIN_P2_12) + { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, #endif - #if defined(PIN_PC13) && !defined(IGNORE_PIN_PC13) - { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, + #if defined(PIN_P2_13) && !defined(IGNORE_PIN_P2_13) + { MP_ROM_QSTR(MP_QSTR_P2_13), MP_ROM_PTR(&pin_P2_13) }, #endif - #if defined(PIN_PC14) && !defined(IGNORE_PIN_PC14) - { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_PC14) }, + #if defined(PIN_P2_14) && !defined(IGNORE_PIN_P2_14) + { MP_ROM_QSTR(MP_QSTR_P2_14), MP_ROM_PTR(&pin_P2_14) }, #endif - #if defined(PIN_PC15) && !defined(IGNORE_PIN_PC15) - { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_PC15) }, + #if defined(PIN_P2_15) && !defined(IGNORE_PIN_P2_15) + { MP_ROM_QSTR(MP_QSTR_P2_15), MP_ROM_PTR(&pin_P2_15) }, #endif - #if defined(PIN_PC16) && !defined(IGNORE_PIN_PC16) - { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_PC16) }, + #if defined(PIN_P2_16) && !defined(IGNORE_PIN_P2_16) + { MP_ROM_QSTR(MP_QSTR_P2_16), MP_ROM_PTR(&pin_P2_16) }, #endif - #if defined(PIN_PC17) && !defined(IGNORE_PIN_PC17) - { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_PC17) }, + #if defined(PIN_P2_17) && !defined(IGNORE_PIN_P2_17) + { MP_ROM_QSTR(MP_QSTR_P2_17), MP_ROM_PTR(&pin_P2_17) }, #endif - #if defined(PIN_PC18) && !defined(IGNORE_PIN_PC18) - { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_PC18) }, + #if defined(PIN_P2_18) && !defined(IGNORE_PIN_P2_18) + { MP_ROM_QSTR(MP_QSTR_P2_18), MP_ROM_PTR(&pin_P2_18) }, #endif - #if defined(PIN_PC19) && !defined(IGNORE_PIN_PC19) - { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_PC19) }, + #if defined(PIN_P2_19) && !defined(IGNORE_PIN_P2_19) + { MP_ROM_QSTR(MP_QSTR_P2_19), MP_ROM_PTR(&pin_P2_19) }, #endif - #if defined(PIN_PC20) && !defined(IGNORE_PIN_PC20) - { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_PC20) }, + #if defined(PIN_P2_20) && !defined(IGNORE_PIN_P2_20) + { MP_ROM_QSTR(MP_QSTR_P2_20), MP_ROM_PTR(&pin_P2_20) }, #endif - #if defined(PIN_PC21) && !defined(IGNORE_PIN_PC21) - { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_PC21) }, + #if defined(PIN_P2_21) && !defined(IGNORE_PIN_P2_21) + { MP_ROM_QSTR(MP_QSTR_P2_21), MP_ROM_PTR(&pin_P2_21) }, #endif - #if defined(PIN_PC22) && !defined(IGNORE_PIN_PC22) - { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_PC22) }, + #if defined(PIN_P2_22) && !defined(IGNORE_PIN_P2_22) + { MP_ROM_QSTR(MP_QSTR_P2_22), MP_ROM_PTR(&pin_P2_22) }, #endif - #if defined(PIN_PC23) && !defined(IGNORE_PIN_PC23) - { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_PC23) }, + #if defined(PIN_P2_23) && !defined(IGNORE_PIN_P2_23) + { MP_ROM_QSTR(MP_QSTR_P2_23), MP_ROM_PTR(&pin_P2_23) }, #endif - #if defined(PIN_PC24) && !defined(IGNORE_PIN_PC24) - { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_PC24) }, + #if defined(PIN_P2_24) && !defined(IGNORE_PIN_P2_24) + { MP_ROM_QSTR(MP_QSTR_P2_24), MP_ROM_PTR(&pin_P2_24) }, #endif - #if defined(PIN_PC25) && !defined(IGNORE_PIN_PC25) - { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_PC25) }, + #if defined(PIN_P2_25) && !defined(IGNORE_PIN_P2_25) + { MP_ROM_QSTR(MP_QSTR_P2_25), MP_ROM_PTR(&pin_P2_25) }, #endif - #if defined(PIN_PC26) && !defined(IGNORE_PIN_PC26) - { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_PC26) }, + #if defined(PIN_P2_26) && !defined(IGNORE_PIN_P2_26) + { MP_ROM_QSTR(MP_QSTR_P2_26), MP_ROM_PTR(&pin_P2_26) }, #endif - #if defined(PIN_PC27) && !defined(IGNORE_PIN_PC27) - { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_PC27) }, + #if defined(PIN_P2_27) && !defined(IGNORE_PIN_P2_27) + { MP_ROM_QSTR(MP_QSTR_P2_27), MP_ROM_PTR(&pin_P2_27) }, #endif - #if defined(PIN_PC28) && !defined(IGNORE_PIN_PC28) - { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_PC28) }, + #if defined(PIN_P2_28) && !defined(IGNORE_PIN_P2_28) + { MP_ROM_QSTR(MP_QSTR_P2_28), MP_ROM_PTR(&pin_P2_28) }, #endif - #if defined(PIN_PC30) && !defined(IGNORE_PIN_PC30) - { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_PC30) }, + #if defined(PIN_P2_30) && !defined(IGNORE_PIN_P2_30) + { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, #endif - #if defined(PIN_PC31) && !defined(IGNORE_PIN_PC31) - { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_PC31) }, + #if defined(PIN_P2_31) && !defined(IGNORE_PIN_P2_31) + { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, #endif - #if defined(PIN_PD01) && !defined(IGNORE_PIN_PD01) - { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) }, + #if defined(PIN_P3_01) && !defined(IGNORE_PIN_P3_01) + { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, #endif - #if defined(PIN_PD02) && !defined(IGNORE_PIN_PD02) - { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_PD02) }, + #if defined(PIN_P3_02) && !defined(IGNORE_PIN_P3_02) + { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, #endif - #if defined(PIN_PD03) && !defined(IGNORE_PIN_PD03) - { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_PD03) }, + #if defined(PIN_P3_03) && !defined(IGNORE_PIN_P3_03) + { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, #endif - #if defined(PIN_PD04) && !defined(IGNORE_PIN_PD04) - { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_PD04) }, + #if defined(PIN_P3_04) && !defined(IGNORE_PIN_P3_04) + { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, #endif - #if defined(PIN_PD05) && !defined(IGNORE_PIN_PD05) - { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_PD05) }, + #if defined(PIN_P3_05) && !defined(IGNORE_PIN_P3_05) + { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, #endif - #if defined(PIN_PD06) && !defined(IGNORE_PIN_PD06) - { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_PD06) }, + #if defined(PIN_P3_06) && !defined(IGNORE_PIN_P3_06) + { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, #endif - #if defined(PIN_PD07) && !defined(IGNORE_PIN_PD07) - { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_PD07) }, + #if defined(PIN_P3_07) && !defined(IGNORE_PIN_P3_07) + { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, #endif - #if defined(PIN_PD08) && !defined(IGNORE_PIN_PD08) - { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) }, + #if defined(PIN_P3_08) && !defined(IGNORE_PIN_P3_08) + { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, #endif - #if defined(PIN_PD09) && !defined(IGNORE_PIN_PD09) - { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) }, + #if defined(PIN_P3_09) && !defined(IGNORE_PIN_P3_09) + { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, #endif - #if defined(PIN_PE01) && !defined(IGNORE_PIN_PE01) - { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD02) }, + #if defined(PIN_P4_01) && !defined(IGNORE_PIN_P4_01) + { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_02) }, #endif - #if defined(PIN_PE02) && !defined(IGNORE_PIN_PD02) - { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD02) }, + #if defined(PIN_P4_02) && !defined(IGNORE_PIN_P4_02) + { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_02) }, #endif }; diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 60b18a5249a2..f2cc8bd7aea0 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -22,7 +22,7 @@ INTERNAL_FLASH_FILESYSTEM = 1 # These modules are implemented in ports//common-hal: # Typically the second module to create -CIRCUITPY_DIGITALIO ?= 0 +CIRCUITPY_DIGITALIO ?= 1 # Plan to implement CIRCUITPY_BUSIO ?= 0 diff --git a/ports/analog/peripherals/max32690/pins.c b/ports/analog/peripherals/max32690/pins.c index b6c4e993553b..7550dc549efa 100644 --- a/ports/analog/peripherals/max32690/pins.c +++ b/ports/analog/peripherals/max32690/pins.c @@ -7,119 +7,117 @@ #include "py/obj.h" #include "py/mphal.h" #include "peripherals/pins.h" +#include "max32690.h" -#include "gpio.h" -#include "gpio_regs.h" +const mcu_pin_obj_t pin_P0_00 = PIN(0, 0); +const mcu_pin_obj_t pin_P0_01 = PIN(0, 1); +const mcu_pin_obj_t pin_P0_02 = PIN(0, 2); +const mcu_pin_obj_t pin_P0_03 = PIN(0, 3); +const mcu_pin_obj_t pin_P0_04 = PIN(0, 4); +const mcu_pin_obj_t pin_P0_05 = PIN(0, 5); +const mcu_pin_obj_t pin_P0_06 = PIN(0, 6); +const mcu_pin_obj_t pin_P0_07 = PIN(0, 7); +const mcu_pin_obj_t pin_P0_08 = PIN(0, 8); +const mcu_pin_obj_t pin_P0_09 = PIN(0, 9); +const mcu_pin_obj_t pin_P0_10 = PIN(0, 10); +const mcu_pin_obj_t pin_P0_11 = PIN(0, 11); +const mcu_pin_obj_t pin_P0_12 = PIN(0, 12); +const mcu_pin_obj_t pin_P0_13 = PIN(0, 13); +const mcu_pin_obj_t pin_P0_14 = PIN(0, 14); +const mcu_pin_obj_t pin_P0_15 = PIN(0, 15); +const mcu_pin_obj_t pin_P0_16 = PIN(0, 16); +const mcu_pin_obj_t pin_P0_17 = PIN(0, 17); +const mcu_pin_obj_t pin_P0_18 = PIN(0, 18); +const mcu_pin_obj_t pin_P0_19 = PIN(0, 19); +const mcu_pin_obj_t pin_P0_20 = PIN(0, 20); +const mcu_pin_obj_t pin_P0_21 = PIN(0, 21); +const mcu_pin_obj_t pin_P0_22 = PIN(0, 22); +const mcu_pin_obj_t pin_P0_23 = PIN(0, 23); +const mcu_pin_obj_t pin_P0_24 = PIN(0, 24); +const mcu_pin_obj_t pin_P0_25 = PIN(0, 25); +const mcu_pin_obj_t pin_P0_26 = PIN(0, 26); +const mcu_pin_obj_t pin_P0_27 = PIN(0, 27); +const mcu_pin_obj_t pin_P0_28 = PIN(0, 28); +const mcu_pin_obj_t pin_P0_29 = PIN(0, 29); +const mcu_pin_obj_t pin_P0_30 = PIN(0, 30); +const mcu_pin_obj_t pin_P0_31 = PIN(0, 31); -const mcu_pin_obj_t pin_P0_00 = PIN(MXC_GPIO_PORT_0, 0); -const mcu_pin_obj_t pin_P0_01 = PIN(MXC_GPIO_PORT_0, 1); -const mcu_pin_obj_t pin_P0_02 = PIN(MXC_GPIO_PORT_0, 2); -const mcu_pin_obj_t pin_P0_03 = PIN(MXC_GPIO_PORT_0, 3); -const mcu_pin_obj_t pin_P0_04 = PIN(MXC_GPIO_PORT_0, 4); -const mcu_pin_obj_t pin_P0_05 = PIN(MXC_GPIO_PORT_0, 5); -const mcu_pin_obj_t pin_P0_06 = PIN(MXC_GPIO_PORT_0, 6); -const mcu_pin_obj_t pin_P0_07 = PIN(MXC_GPIO_PORT_0, 7); -const mcu_pin_obj_t pin_P0_08 = PIN(MXC_GPIO_PORT_0, 8); -const mcu_pin_obj_t pin_P0_09 = PIN(MXC_GPIO_PORT_0, 9); -const mcu_pin_obj_t pin_P0_10 = PIN(MXC_GPIO_PORT_0, 10); -const mcu_pin_obj_t pin_P0_11 = PIN(MXC_GPIO_PORT_0, 11); -const mcu_pin_obj_t pin_P0_12 = PIN(MXC_GPIO_PORT_0, 12); -const mcu_pin_obj_t pin_P0_13 = PIN(MXC_GPIO_PORT_0, 13); -const mcu_pin_obj_t pin_P0_14 = PIN(MXC_GPIO_PORT_0, 14); -const mcu_pin_obj_t pin_P0_15 = PIN(MXC_GPIO_PORT_0, 15); -const mcu_pin_obj_t pin_P0_16 = PIN(MXC_GPIO_PORT_0, 16); -const mcu_pin_obj_t pin_P0_17 = PIN(MXC_GPIO_PORT_0, 17); -const mcu_pin_obj_t pin_P0_18 = PIN(MXC_GPIO_PORT_0, 18); -const mcu_pin_obj_t pin_P0_19 = PIN(MXC_GPIO_PORT_0, 19); -const mcu_pin_obj_t pin_P0_20 = PIN(MXC_GPIO_PORT_0, 20); -const mcu_pin_obj_t pin_P0_21 = PIN(MXC_GPIO_PORT_0, 21); -const mcu_pin_obj_t pin_P0_22 = PIN(MXC_GPIO_PORT_0, 22); -const mcu_pin_obj_t pin_P0_23 = PIN(MXC_GPIO_PORT_0, 23); -const mcu_pin_obj_t pin_P0_24 = PIN(MXC_GPIO_PORT_0, 24); -const mcu_pin_obj_t pin_P0_25 = PIN(MXC_GPIO_PORT_0, 25); -const mcu_pin_obj_t pin_P0_26 = PIN(MXC_GPIO_PORT_0, 26); -const mcu_pin_obj_t pin_P0_27 = PIN(MXC_GPIO_PORT_0, 27); -const mcu_pin_obj_t pin_P0_28 = PIN(MXC_GPIO_PORT_0, 28); -const mcu_pin_obj_t pin_P0_29 = PIN(MXC_GPIO_PORT_0, 29); -const mcu_pin_obj_t pin_P0_30 = PIN(MXC_GPIO_PORT_0, 30); -const mcu_pin_obj_t pin_P0_31 = PIN(MXC_GPIO_PORT_0, 31); +const mcu_pin_obj_t pin_P1_00 = PIN(1, 0); +const mcu_pin_obj_t pin_P1_01 = PIN(1, 1); +const mcu_pin_obj_t pin_P1_02 = PIN(1, 2); +const mcu_pin_obj_t pin_P1_03 = PIN(1, 3); +const mcu_pin_obj_t pin_P1_04 = PIN(1, 4); +const mcu_pin_obj_t pin_P1_05 = PIN(1, 5); +const mcu_pin_obj_t pin_P1_06 = PIN(1, 6); +const mcu_pin_obj_t pin_P1_07 = PIN(1, 7); +const mcu_pin_obj_t pin_P1_08 = PIN(1, 8); +const mcu_pin_obj_t pin_P1_09 = PIN(1, 9); +const mcu_pin_obj_t pin_P1_10 = PIN(1, 10); +const mcu_pin_obj_t pin_P1_11 = PIN(1, 11); +const mcu_pin_obj_t pin_P1_12 = PIN(1, 12); +const mcu_pin_obj_t pin_P1_13 = PIN(1, 13); +const mcu_pin_obj_t pin_P1_14 = PIN(1, 14); +const mcu_pin_obj_t pin_P1_15 = PIN(1, 15); +const mcu_pin_obj_t pin_P1_16 = PIN(1, 16); +const mcu_pin_obj_t pin_P1_17 = PIN(1, 17); +const mcu_pin_obj_t pin_P1_18 = PIN(1, 18); +const mcu_pin_obj_t pin_P1_19 = PIN(1, 19); +const mcu_pin_obj_t pin_P1_20 = PIN(1, 20); +const mcu_pin_obj_t pin_P1_21 = PIN(1, 21); +const mcu_pin_obj_t pin_P1_22 = PIN(1, 22); +const mcu_pin_obj_t pin_P1_23 = PIN(1, 23); +const mcu_pin_obj_t pin_P1_24 = PIN(1, 24); +const mcu_pin_obj_t pin_P1_25 = PIN(1, 25); +const mcu_pin_obj_t pin_P1_26 = PIN(1, 26); +const mcu_pin_obj_t pin_P1_27 = PIN(1, 27); +const mcu_pin_obj_t pin_P1_28 = PIN(1, 28); +const mcu_pin_obj_t pin_P1_29 = PIN(1, 29); +const mcu_pin_obj_t pin_P1_30 = PIN(1, 30); +const mcu_pin_obj_t pin_P1_31 = PIN(1, 31); -const mcu_pin_obj_t pin_P1_00 = PIN(MXC_GPIO_PORT_1, 0); -const mcu_pin_obj_t pin_P1_01 = PIN(MXC_GPIO_PORT_1, 1); -const mcu_pin_obj_t pin_P1_02 = PIN(MXC_GPIO_PORT_1, 2); -const mcu_pin_obj_t pin_P1_03 = PIN(MXC_GPIO_PORT_1, 3); -const mcu_pin_obj_t pin_P1_04 = PIN(MXC_GPIO_PORT_1, 4); -const mcu_pin_obj_t pin_P1_05 = PIN(MXC_GPIO_PORT_1, 5); -const mcu_pin_obj_t pin_P1_06 = PIN(MXC_GPIO_PORT_1, 6); -const mcu_pin_obj_t pin_P1_07 = PIN(MXC_GPIO_PORT_1, 7); -const mcu_pin_obj_t pin_P1_08 = PIN(MXC_GPIO_PORT_1, 8); -const mcu_pin_obj_t pin_P1_09 = PIN(MXC_GPIO_PORT_1, 9); -const mcu_pin_obj_t pin_P1_10 = PIN(MXC_GPIO_PORT_1, 10); -const mcu_pin_obj_t pin_P1_11 = PIN(MXC_GPIO_PORT_1, 11); -const mcu_pin_obj_t pin_P1_12 = PIN(MXC_GPIO_PORT_1, 12); -const mcu_pin_obj_t pin_P1_13 = PIN(MXC_GPIO_PORT_1, 13); -const mcu_pin_obj_t pin_P1_14 = PIN(MXC_GPIO_PORT_1, 14); -const mcu_pin_obj_t pin_P1_15 = PIN(MXC_GPIO_PORT_1, 15); -const mcu_pin_obj_t pin_P1_16 = PIN(MXC_GPIO_PORT_1, 16); -const mcu_pin_obj_t pin_P1_17 = PIN(MXC_GPIO_PORT_1, 17); -const mcu_pin_obj_t pin_P1_18 = PIN(MXC_GPIO_PORT_1, 18); -const mcu_pin_obj_t pin_P1_19 = PIN(MXC_GPIO_PORT_1, 19); -const mcu_pin_obj_t pin_P1_20 = PIN(MXC_GPIO_PORT_1, 20); -const mcu_pin_obj_t pin_P1_21 = PIN(MXC_GPIO_PORT_1, 21); -const mcu_pin_obj_t pin_P1_22 = PIN(MXC_GPIO_PORT_1, 22); -const mcu_pin_obj_t pin_P1_23 = PIN(MXC_GPIO_PORT_1, 23); -const mcu_pin_obj_t pin_P1_24 = PIN(MXC_GPIO_PORT_1, 24); -const mcu_pin_obj_t pin_P1_25 = PIN(MXC_GPIO_PORT_1, 25); -const mcu_pin_obj_t pin_P1_26 = PIN(MXC_GPIO_PORT_1, 26); -const mcu_pin_obj_t pin_P1_27 = PIN(MXC_GPIO_PORT_1, 27); -const mcu_pin_obj_t pin_P1_28 = PIN(MXC_GPIO_PORT_1, 28); -const mcu_pin_obj_t pin_P1_29 = PIN(MXC_GPIO_PORT_1, 29); -const mcu_pin_obj_t pin_P1_30 = PIN(MXC_GPIO_PORT_1, 30); -const mcu_pin_obj_t pin_P1_31 = PIN(MXC_GPIO_PORT_1, 31); +const mcu_pin_obj_t pin_P2_00 = PIN(2, 0); +const mcu_pin_obj_t pin_P2_01 = PIN(2, 1); +const mcu_pin_obj_t pin_P2_02 = PIN(2, 2); +const mcu_pin_obj_t pin_P2_03 = PIN(2, 3); +const mcu_pin_obj_t pin_P2_04 = PIN(2, 4); +const mcu_pin_obj_t pin_P2_05 = PIN(2, 5); +const mcu_pin_obj_t pin_P2_06 = PIN(2, 6); +const mcu_pin_obj_t pin_P2_07 = PIN(2, 7); +const mcu_pin_obj_t pin_P2_08 = PIN(2, 8); +const mcu_pin_obj_t pin_P2_09 = PIN(2, 9); +const mcu_pin_obj_t pin_P2_10 = PIN(2, 10); +const mcu_pin_obj_t pin_P2_11 = PIN(2, 11); +const mcu_pin_obj_t pin_P2_12 = PIN(2, 12); +const mcu_pin_obj_t pin_P2_13 = PIN(2, 13); +const mcu_pin_obj_t pin_P2_14 = PIN(2, 14); +const mcu_pin_obj_t pin_P2_15 = PIN(2, 15); +const mcu_pin_obj_t pin_P2_16 = PIN(2, 16); +const mcu_pin_obj_t pin_P2_17 = PIN(2, 17); +const mcu_pin_obj_t pin_P2_18 = PIN(2, 18); +const mcu_pin_obj_t pin_P2_19 = PIN(2, 19); +const mcu_pin_obj_t pin_P2_20 = PIN(2, 20); +const mcu_pin_obj_t pin_P2_21 = PIN(2, 21); +const mcu_pin_obj_t pin_P2_22 = PIN(2, 22); +const mcu_pin_obj_t pin_P2_23 = PIN(2, 23); +const mcu_pin_obj_t pin_P2_24 = PIN(2, 24); +const mcu_pin_obj_t pin_P2_25 = PIN(2, 25); +const mcu_pin_obj_t pin_P2_26 = PIN(2, 26); +const mcu_pin_obj_t pin_P2_27 = PIN(2, 27); +const mcu_pin_obj_t pin_P2_28 = PIN(2, 28); +const mcu_pin_obj_t pin_P2_29 = PIN(2, 29); +const mcu_pin_obj_t pin_P2_30 = PIN(2, 30); +const mcu_pin_obj_t pin_P2_31 = PIN(2, 31); -const mcu_pin_obj_t pin_P2_00 = PIN(MXC_GPIO_PORT_2, 0); -const mcu_pin_obj_t pin_P2_01 = PIN(MXC_GPIO_PORT_2, 1); -const mcu_pin_obj_t pin_P2_02 = PIN(MXC_GPIO_PORT_2, 2); -const mcu_pin_obj_t pin_P2_03 = PIN(MXC_GPIO_PORT_2, 3); -const mcu_pin_obj_t pin_P2_04 = PIN(MXC_GPIO_PORT_2, 4); -const mcu_pin_obj_t pin_P2_05 = PIN(MXC_GPIO_PORT_2, 5); -const mcu_pin_obj_t pin_P2_06 = PIN(MXC_GPIO_PORT_2, 6); -const mcu_pin_obj_t pin_P2_07 = PIN(MXC_GPIO_PORT_2, 7); -const mcu_pin_obj_t pin_P2_08 = PIN(MXC_GPIO_PORT_2, 8); -const mcu_pin_obj_t pin_P2_09 = PIN(MXC_GPIO_PORT_2, 9); -const mcu_pin_obj_t pin_P2_10 = PIN(MXC_GPIO_PORT_2, 10); -const mcu_pin_obj_t pin_P2_11 = PIN(MXC_GPIO_PORT_2, 11); -const mcu_pin_obj_t pin_P2_12 = PIN(MXC_GPIO_PORT_2, 12); -const mcu_pin_obj_t pin_P2_13 = PIN(MXC_GPIO_PORT_2, 13); -const mcu_pin_obj_t pin_P2_14 = PIN(MXC_GPIO_PORT_2, 14); -const mcu_pin_obj_t pin_P2_15 = PIN(MXC_GPIO_PORT_2, 15); -const mcu_pin_obj_t pin_P2_16 = PIN(MXC_GPIO_PORT_2, 16); -const mcu_pin_obj_t pin_P2_17 = PIN(MXC_GPIO_PORT_2, 17); -const mcu_pin_obj_t pin_P2_18 = PIN(MXC_GPIO_PORT_2, 18); -const mcu_pin_obj_t pin_P2_19 = PIN(MXC_GPIO_PORT_2, 19); -const mcu_pin_obj_t pin_P2_20 = PIN(MXC_GPIO_PORT_2, 20); -const mcu_pin_obj_t pin_P2_21 = PIN(MXC_GPIO_PORT_2, 21); -const mcu_pin_obj_t pin_P2_22 = PIN(MXC_GPIO_PORT_2, 22); -const mcu_pin_obj_t pin_P2_23 = PIN(MXC_GPIO_PORT_2, 23); -const mcu_pin_obj_t pin_P2_24 = PIN(MXC_GPIO_PORT_2, 24); -const mcu_pin_obj_t pin_P2_25 = PIN(MXC_GPIO_PORT_2, 25); -const mcu_pin_obj_t pin_P2_26 = PIN(MXC_GPIO_PORT_2, 26); -const mcu_pin_obj_t pin_P2_27 = PIN(MXC_GPIO_PORT_2, 27); -const mcu_pin_obj_t pin_P2_28 = PIN(MXC_GPIO_PORT_2, 28); -const mcu_pin_obj_t pin_P2_29 = PIN(MXC_GPIO_PORT_2, 29); -const mcu_pin_obj_t pin_P2_30 = PIN(MXC_GPIO_PORT_2, 30); -const mcu_pin_obj_t pin_P2_31 = PIN(MXC_GPIO_PORT_2, 31); +const mcu_pin_obj_t pin_P3_00 = PIN(3, 0); +const mcu_pin_obj_t pin_P3_01 = PIN(3, 1); +const mcu_pin_obj_t pin_P3_02 = PIN(3, 2); +const mcu_pin_obj_t pin_P3_03 = PIN(3, 3); +const mcu_pin_obj_t pin_P3_04 = PIN(3, 4); +const mcu_pin_obj_t pin_P3_05 = PIN(3, 5); +const mcu_pin_obj_t pin_P3_06 = PIN(3, 6); +const mcu_pin_obj_t pin_P3_07 = PIN(3, 7); +const mcu_pin_obj_t pin_P3_08 = PIN(3, 8); +const mcu_pin_obj_t pin_P3_09 = PIN(3, 9); -const mcu_pin_obj_t pin_P3_00 = PIN(MXC_GPIO_PORT_3, 0); -const mcu_pin_obj_t pin_P3_01 = PIN(MXC_GPIO_PORT_3, 1); -const mcu_pin_obj_t pin_P3_02 = PIN(MXC_GPIO_PORT_3, 2); -const mcu_pin_obj_t pin_P3_03 = PIN(MXC_GPIO_PORT_3, 3); -const mcu_pin_obj_t pin_P3_04 = PIN(MXC_GPIO_PORT_3, 4); -const mcu_pin_obj_t pin_P3_05 = PIN(MXC_GPIO_PORT_3, 5); -const mcu_pin_obj_t pin_P3_06 = PIN(MXC_GPIO_PORT_3, 6); -const mcu_pin_obj_t pin_P3_07 = PIN(MXC_GPIO_PORT_3, 7); -const mcu_pin_obj_t pin_P3_08 = PIN(MXC_GPIO_PORT_3, 8); -const mcu_pin_obj_t pin_P3_09 = PIN(MXC_GPIO_PORT_3, 9); - -const mcu_pin_obj_t pin_P4_00 = PIN(MXC_GPIO_PORT_4, 0); -const mcu_pin_obj_t pin_P4_01 = PIN(MXC_GPIO_PORT_4, 1); +const mcu_pin_obj_t pin_P4_00 = PIN(4, 0); +const mcu_pin_obj_t pin_P4_01 = PIN(4, 1); diff --git a/ports/analog/peripherals/pins.h b/ports/analog/peripherals/pins.h index 313addc1f205..efee60a2962a 100644 --- a/ports/analog/peripherals/pins.h +++ b/ports/analog/peripherals/pins.h @@ -14,25 +14,23 @@ #include "py/obj.h" // HAL includes -// #include "gpio.h" +#include "gpio.h" +#include "gpio_regs.h" typedef struct { mp_obj_base_t base; - const uint8_t port; - const uint8_t pad; - // const uint8_t level : 4; // FIXME: Find how to include the VDDIO/VDDIOH level + uint8_t port; + uint32_t mask; // the pad # target e.g. P0.01 is Port=0, Mask=1 + mxc_gpio_vssel_t level; } mcu_pin_obj_t; extern const mp_obj_type_t mcu_pin_type; -#define NO_PIN (0xFF) // for non-connected pins +#define PIN(pin_port, pin_mask) { {&mcu_pin_type}, .port = pin_port, .mask = 1UL< Date: Sun, 22 Sep 2024 13:12:17 -0500 Subject: [PATCH 020/252] Delay and Decay to BlockInput --- shared-bindings/audiodelays/Echo.c | 40 ++++++----------- shared-bindings/audiodelays/Echo.h | 12 +++--- shared-module/audiodelays/Echo.c | 69 ++++++++++++++++++------------ shared-module/audiodelays/Echo.h | 9 ++-- 4 files changed, 67 insertions(+), 63 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 1ef5bfc1e7b1..0119b15690f6 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -22,12 +22,13 @@ //| """An Echo effect""" //| static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_delay_ms, ARG_decay, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; + enum { ARG_max_delay_ms, ARG_delay_ms, ARG_decay, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 50 } }, + { MP_QSTR_max_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 50 } }, + { MP_QSTR_delay_ms, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_decay, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1024} }, + { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 512} }, { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, { MP_QSTR_bits_per_sample, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, { MP_QSTR_samples_signed, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, @@ -37,12 +38,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_int_t delay_ms = mp_arg_validate_int_range(args[ARG_delay_ms].u_int, 1, 4000, MP_QSTR_delay_ms); - - mp_float_t decay = (args[ARG_decay].u_obj == MP_OBJ_NULL) - ? (mp_float_t)DECAY_DEFAULT - : mp_obj_get_float(args[ARG_decay].u_obj); - mp_arg_validate_float_range(decay, 0.0f, 1.0f, MP_QSTR_decay); + mp_int_t max_delay_ms = mp_arg_validate_int_range(args[ARG_max_delay_ms].u_int, 1, 4000, MP_QSTR_max_delay_ms); mp_int_t channel_count = mp_arg_validate_int_range(args[ARG_channel_count].u_int, 1, 2, MP_QSTR_channel_count); mp_int_t sample_rate = mp_arg_validate_int_min(args[ARG_sample_rate].u_int, 1, MP_QSTR_sample_rate); @@ -52,7 +48,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar } audiodelays_echo_obj_t *self = mp_obj_malloc(audiodelays_echo_obj_t, &audiodelays_echo_type); - common_hal_audiodelays_echo_construct(self, delay_ms, decay, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + common_hal_audiodelays_echo_construct(self, max_delay_ms, args[ARG_delay_ms].u_obj, args[ARG_decay].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); return MP_OBJ_FROM_PTR(self); } @@ -90,13 +86,13 @@ static mp_obj_t audiodelays_echo_obj___exit__(size_t n_args, const mp_obj_t *arg static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiodelays_echo___exit___obj, 4, 4, audiodelays_echo_obj___exit__); -//| delay_ms: int +//| delay_ms: BlockInput //| """Delay of the echo in microseconds. (read-only)""" //| static mp_obj_t audiodelays_echo_obj_get_delay_ms(mp_obj_t self_in) { audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_float(common_hal_audiodelays_echo_get_delay_ms(self)); + return common_hal_audiodelays_echo_get_delay_ms(self); } MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_delay_ms_obj, audiodelays_echo_obj_get_delay_ms); @@ -104,15 +100,13 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_delay_ms_obj, audiodelays_echo_ob static mp_obj_t audiodelays_echo_obj_set_delay_ms(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_delay_ms }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_delay_ms, MP_ARG_INT | MP_ARG_REQUIRED, {} }, + { MP_QSTR_delay_ms, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, }; audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_int_t delay_ms = mp_arg_validate_int_range(args[ARG_delay_ms].u_int, 1, 4000, MP_QSTR_delay_ms); - - common_hal_audiodelays_echo_set_delay_ms(self, delay_ms); + common_hal_audiodelays_echo_set_delay_ms(self, args[ARG_delay_ms].u_obj); return mp_const_none; } @@ -122,10 +116,10 @@ MP_PROPERTY_GETSET(audiodelays_echo_delay_ms_obj, (mp_obj_t)&audiodelays_echo_get_delay_ms_obj, (mp_obj_t)&audiodelays_echo_set_delay_ms_obj); -//| decay: float +//| decay: BlockInput //| """The rate the echo decays between 0 and 1.""" static mp_obj_t audiodelays_echo_obj_get_decay(mp_obj_t self_in) { - return mp_obj_new_float(common_hal_audiodelays_echo_get_decay(self_in)); + return common_hal_audiodelays_echo_get_decay(self_in); } MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_decay_obj, audiodelays_echo_obj_get_decay); @@ -138,10 +132,7 @@ static mp_obj_t audiodelays_echo_obj_set_decay(size_t n_args, const mp_obj_t *po mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_float_t decay = mp_obj_get_float(args[ARG_decay].u_obj); - mp_arg_validate_float_range(decay, 0.0f, 1.0f, MP_QSTR_decay); - - common_hal_audiodelays_echo_set_decay(self, decay); + common_hal_audiodelays_echo_set_decay(self, args[ARG_decay].u_obj); return mp_const_none; } @@ -151,10 +142,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_decay_obj, (mp_obj_t)&audiodelays_echo_get_decay_obj, (mp_obj_t)&audiodelays_echo_set_decay_obj); - - - -//| mix: float +//| mix: BlockInput //| """The rate the echo mix between 0 and 1.""" static mp_obj_t audiodelays_echo_obj_get_mix(mp_obj_t self_in) { return common_hal_audiodelays_echo_get_mix(self_in); diff --git a/shared-bindings/audiodelays/Echo.h b/shared-bindings/audiodelays/Echo.h index df9be6407cb6..a1035a7ea7a0 100644 --- a/shared-bindings/audiodelays/Echo.h +++ b/shared-bindings/audiodelays/Echo.h @@ -10,8 +10,8 @@ extern const mp_obj_type_t audiodelays_echo_type; -void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, - uint32_t delay_ms, mp_float_t decay, mp_obj_t mix, +void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t max_delay_ms, + mp_obj_t delay_ms, mp_obj_t decay, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate); @@ -22,11 +22,11 @@ uint32_t common_hal_audiodelays_echo_get_sample_rate(audiodelays_echo_obj_t *sel uint8_t common_hal_audiodelays_echo_get_channel_count(audiodelays_echo_obj_t *self); uint8_t common_hal_audiodelays_echo_get_bits_per_sample(audiodelays_echo_obj_t *self); -uint32_t common_hal_audiodelays_echo_get_delay_ms(audiodelays_echo_obj_t *self); -void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, uint32_t delay_ms); +mp_obj_t common_hal_audiodelays_echo_get_delay_ms(audiodelays_echo_obj_t *self); +void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_obj_t delay_ms); -mp_float_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self); -void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_float_t decay); +mp_obj_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self); +void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_obj_t decay); mp_obj_t common_hal_audiodelays_echo_get_mix(audiodelays_echo_obj_t *self); void common_hal_audiodelays_echo_set_mix(audiodelays_echo_obj_t *self, mp_obj_t arg); diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index da60eb4a580e..fcb664f6ce4f 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -10,7 +10,8 @@ #include "shared-module/audiomixer/utils.h" -void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t delay_ms, mp_float_t decay, mp_obj_t mix, +void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t max_delay_ms, + mp_obj_t delay_ms, mp_obj_t decay, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { @@ -19,7 +20,6 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ self->channel_count = channel_count; self->sample_rate = sample_rate; - // check that buffer_size <= echo_buffer_size self->buffer_len = buffer_size; self->buffer = m_malloc(self->buffer_len); if (self->buffer == NULL) { @@ -28,7 +28,15 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ } memset(self->buffer, 0, self->buffer_len); - self->decay = (uint16_t)(decay * (1 << 15)); + if (decay == MP_OBJ_NULL) { + decay = mp_obj_new_float(0.7); + } + synthio_block_assign_slot(decay, &self->decay, MP_QSTR_decay); + + if (delay_ms == MP_OBJ_NULL) { + delay_ms = mp_obj_new_float(0.05); + } + synthio_block_assign_slot(delay_ms, &self->delay_ms, MP_QSTR_delay_ms); if (mix == MP_OBJ_NULL) { mix = mp_obj_new_float(0.5); @@ -36,15 +44,18 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ synthio_block_assign_slot(mix, &self->mix, MP_QSTR_mix); // calculate buffer size for the set delay - self->delay_ms = delay_ms; - self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * (self->channel_count * (self->bits_per_sample / 8)); + mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); + self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); - self->echo_buffer = m_malloc(self->echo_buffer_len); + // Set the echo buffer for the max possible delay + self->max_delay_ms = max_delay_ms; + self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); + self->echo_buffer = m_malloc(self->max_echo_buffer_len); if (self->echo_buffer == NULL) { common_hal_audiodelays_echo_deinit(self); - m_malloc_fail(self->echo_buffer_len); + m_malloc_fail(self->max_echo_buffer_len); } - memset(self->echo_buffer, 0, self->echo_buffer_len); + memset(self->echo_buffer, 0, self->max_echo_buffer_len); // read is where we store the incoming sample // write is what we send to the outgoing buffer @@ -74,19 +85,15 @@ void common_hal_audiodelays_echo_deinit(audiodelays_echo_obj_t *self) { } -uint32_t common_hal_audiodelays_echo_get_delay_ms(audiodelays_echo_obj_t *self) { - return self->delay_ms; +mp_obj_t common_hal_audiodelays_echo_get_delay_ms(audiodelays_echo_obj_t *self) { + return self->delay_ms.obj; } -void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, uint32_t delay_ms) { - self->delay_ms = delay_ms; - self->echo_buffer_len = self->sample_rate / 1000.0f * self->delay_ms * (self->channel_count * (self->bits_per_sample / 8)); +void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_obj_t delay_ms) { + synthio_block_assign_slot(delay_ms, &self->delay_ms, MP_QSTR_delay_ms); - self->echo_buffer = m_realloc(self->echo_buffer, self->echo_buffer_len); - if (self->echo_buffer == NULL) { - common_hal_audiodelays_echo_deinit(self); - m_malloc_fail(self->echo_buffer_len); - } + mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); + self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); uint32_t max_ebuf_length = self->echo_buffer_len / sizeof(uint32_t); @@ -99,12 +106,12 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, uint } } -mp_float_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self) { - return (mp_float_t)self->decay / (1 << 15); +mp_obj_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self) { + return self->decay.obj; } -void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_float_t decay) { - self->decay = (uint16_t)(decay * (1 << 15)); +void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_obj_t decay) { + synthio_block_assign_slot(decay, &self->decay, MP_QSTR_decay); } mp_obj_t common_hal_audiodelays_echo_get_mix(audiodelays_echo_obj_t *self) { @@ -169,8 +176,6 @@ void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sam void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self) { self->sample = NULL; - // memset(self->echo_buffer, 0, self->echo_buffer_len); // clear echo - // memset(self->buffer, 0, self->buffer_len); return; } @@ -188,6 +193,14 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } uint16_t mix = (uint16_t)(f_mix * (1 << 15)); + mp_float_t f_decay = synthio_block_slot_get(&self->decay); + if (f_decay > 1.0) { + f_decay = 1.0; + } else if (f_decay < 0.0) { + f_decay = 0.0; + } + uint16_t decay = (uint16_t)(f_decay * (1 << 15)); + while (length != 0) { if (self->sample_buffer_length == 0) { if (!self->more_data) { @@ -219,7 +232,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // sample signed/unsigned won't matter as we have no sample for (uint32_t i = 0; i < length; i++) { uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - word_buffer[i] = mult16signed(echo, self->decay); + word_buffer[i] = mult16signed(echo, decay); self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; word_buffer[i] = mult16signed(word_buffer[i], mix); @@ -238,7 +251,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; for (uint32_t i = 0; i < length * 2; i++) { uint32_t echo_word = unpack8(echo_hsrc[i]); - echo_word = mult16signed(echo_word, self->decay); + echo_word = mult16signed(echo_word, decay); hword_buffer[i] = pack8(echo_word); echo_hsrc[self->echo_buffer_write_pos++] = hword_buffer[i]; @@ -267,7 +280,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * sample_word = tosigned16(sample_word); } uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - word_buffer[i] = add16signed(mult16signed(echo, self->decay), sample_word); + word_buffer[i] = add16signed(mult16signed(echo, decay), sample_word); self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; word_buffer[i] = add16signed(mult16signed(sample_word, 32768 - mix), mult16signed(word_buffer[i], mix)); @@ -290,7 +303,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * if (MP_LIKELY(!self->samples_signed)) { sample_word = tosigned16(sample_word); } - echo_word = mult16signed(echo_word, self->decay); + echo_word = mult16signed(echo_word, decay); sample_word = add16signed(sample_word, echo_word); hword_buffer[i] = pack8(sample_word); diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index a3bf1d484be5..aafb40f182e2 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -14,16 +14,18 @@ extern const mp_obj_type_t audiodelays_echo_type; typedef struct { mp_obj_base_t base; - uint32_t delay_ms; - uint16_t decay; + uint32_t max_delay_ms; + synthio_block_slot_t delay_ms; + synthio_block_slot_t decay; synthio_block_slot_t mix; + uint8_t bits_per_sample; bool samples_signed; uint8_t channel_count; uint32_t sample_rate; uint32_t *buffer; - uint32_t buffer_len; // buffer in bytes + uint32_t buffer_len; // max buffer in bytes uint32_t *sample_remaining_buffer; uint32_t sample_buffer_length; @@ -33,6 +35,7 @@ typedef struct { uint32_t *echo_buffer; uint32_t echo_buffer_len; // bytes + uint32_t max_echo_buffer_len; // bytes uint32_t echo_buffer_read_pos; // words uint32_t echo_buffer_write_pos; // words From 1f9b4b467715dd7225bc84cda2a6a7fc39a88d98 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Mon, 23 Sep 2024 07:13:10 -0600 Subject: [PATCH 021/252] Added max32690 EVKIT board & changed APARD board to apard32690 --- .../boards/{APARD => apard32690}/README.md | 0 .../boards/{APARD => apard32690}/board.c | 0 .../{APARD => apard32690}/mpconfigboard.h | 0 .../{APARD => apard32690}/mpconfigboard.mk | 0 .../boards/{APARD => apard32690}/pins.c | 0 ports/analog/boards/max32690evkit/board.c | 74 ++++++++++ .../boards/max32690evkit/mpconfigboard.h | 38 ++++++ .../boards/max32690evkit/mpconfigboard.mk | 32 +++++ ports/analog/boards/max32690evkit/pins.c | 126 ++++++++++++++++++ 9 files changed, 270 insertions(+) rename ports/analog/boards/{APARD => apard32690}/README.md (100%) rename ports/analog/boards/{APARD => apard32690}/board.c (100%) rename ports/analog/boards/{APARD => apard32690}/mpconfigboard.h (100%) rename ports/analog/boards/{APARD => apard32690}/mpconfigboard.mk (100%) rename ports/analog/boards/{APARD => apard32690}/pins.c (100%) create mode 100644 ports/analog/boards/max32690evkit/board.c create mode 100644 ports/analog/boards/max32690evkit/mpconfigboard.h create mode 100644 ports/analog/boards/max32690evkit/mpconfigboard.mk create mode 100644 ports/analog/boards/max32690evkit/pins.c diff --git a/ports/analog/boards/APARD/README.md b/ports/analog/boards/apard32690/README.md similarity index 100% rename from ports/analog/boards/APARD/README.md rename to ports/analog/boards/apard32690/README.md diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/apard32690/board.c similarity index 100% rename from ports/analog/boards/APARD/board.c rename to ports/analog/boards/apard32690/board.c diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/apard32690/mpconfigboard.h similarity index 100% rename from ports/analog/boards/APARD/mpconfigboard.h rename to ports/analog/boards/apard32690/mpconfigboard.h diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/apard32690/mpconfigboard.mk similarity index 100% rename from ports/analog/boards/APARD/mpconfigboard.mk rename to ports/analog/boards/apard32690/mpconfigboard.mk diff --git a/ports/analog/boards/APARD/pins.c b/ports/analog/boards/apard32690/pins.c similarity index 100% rename from ports/analog/boards/APARD/pins.c rename to ports/analog/boards/apard32690/pins.c diff --git a/ports/analog/boards/max32690evkit/board.c b/ports/analog/boards/max32690evkit/board.c new file mode 100644 index 000000000000..9a0c8278641f --- /dev/null +++ b/ports/analog/boards/max32690evkit/board.c @@ -0,0 +1,74 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" +#include "supervisor/port.h" +#include "mpconfigboard.h" +#include "max32_port.h" + +// Board-level setup for MAX32690 +// clang-format off +const mxc_gpio_cfg_t pb_pin[] = { + { MXC_GPIO4, MXC_GPIO_PIN_0, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, +}; +const int num_pbs = (sizeof(pb_pin) / sizeof(mxc_gpio_cfg_t)); + +const mxc_gpio_cfg_t led_pin[] = { + { MXC_GPIO0, MXC_GPIO_PIN_14, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO2, MXC_GPIO_PIN_12, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, +}; +const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); +// clang-format on + +// DEFAULT: Using the weak-defined supervisor/shared/board.c functions + +/***** OPTIONAL BOARD-SPECIFIC FUNCTIONS from supervisor/board.h *****/ +// Returns true if the user initiates safe mode in a board specific way. +// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific +// way. +// bool board_requests_safe_mode(void); + +volatile uint32_t system_ticks = 0; + +void SysTick_Handler(void) { + system_ticks++; +} + +uint32_t board_millis(void) { + return system_ticks; +} + +// Initializes board related state once on start up. +void board_init(void) { + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000);\ + + // Enable GPIO (enables clocks + common init for ports) + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + MXC_GPIO_Init(0x1 << i); + } + + // Init Board LEDs + /* setup GPIO for the LED */ + for (int i = 0; i < num_leds; i++) { + // Set the output value + MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); + MXC_GPIO_Config(&led_pin[i]); + } + + // Turn on one LED to indicate Sign of Life + MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); +} + +// Reset the state of off MCU components such as neopixels. +// void reset_board(void); + +// Deinit the board. This should put the board in deep sleep durable, low power +// state. It should not prevent the user access method from working (such as +// disabling USB, BLE or flash) because CircuitPython may continue to run. +// void board_deinit(void); + +/*******************************************************************/ diff --git a/ports/analog/boards/max32690evkit/mpconfigboard.h b/ports/analog/boards/max32690evkit/mpconfigboard.h new file mode 100644 index 000000000000..7ab6acf658d1 --- /dev/null +++ b/ports/analog/boards/max32690evkit/mpconfigboard.h @@ -0,0 +1,38 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices Inc. +// +// SPDX-License-Identifier: MIT + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2016 Glenn Ruben Bakke +// SPDX-FileCopyrightText: Copyright (c) 2018 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define MICROPY_HW_BOARD_NAME "MAX32690 EvKit" +#define MICROPY_HW_MCU_NAME "max32690" + +#define FLASH_SIZE (0x300000) // 3MiB +#define FLASH_PAGE_SIZE (0x4000) // 16384 byte pages (16 KiB) + +#define BOARD_HAS_CRYSTAL 1 +#define NUM_GPIO_PORTS 5 +#define CONSOLE_UART MXC_UART2 + +// #if INTERNAL_FLASH_FILESYSTEM +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102E0000) // for MAX32690 +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (128 * 1024) // 64K + +#define MAX32_FLASH_SIZE 0x300000 // 3 MiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102E0000 // Load into the last MiB of code/data storage + +// #else +// #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) +// #endif diff --git a/ports/analog/boards/max32690evkit/mpconfigboard.mk b/ports/analog/boards/max32690evkit/mpconfigboard.mk new file mode 100644 index 000000000000..4e6e766df5d2 --- /dev/null +++ b/ports/analog/boards/max32690evkit/mpconfigboard.mk @@ -0,0 +1,32 @@ +# This file is part of the CircuitPython project: https://circuitpython.org +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +# +# SPDX-License-Identifier: MIT + +MCU_SERIES=max32 +MCU_VARIANT=max32690 + +INTERNAL_FLASH_FILESYSTEM=1 +# FLASH: 0x10000000 to 0x10300000 (ARM) +# SRAM: 0x20000000 to 0x20100000 + +#### USB CONFIGURATION +# Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim +USB_VID=0x0456 +# USB_VID=0x0B6A +USB_PID=0x003C +USB_MANUFACTURER="Analog Devices, Inc." +USB_PRODUCT="MAX32690 EvKit" +USB_HIGHSPEED=1 + +# NOTE: MAX32 devices do not support IN/OUT pairs on the same EP +USB_NUM_ENDPOINT_PAIRS=12 +### + +# define UID len for memory safety (buffer gets passed as a raw ptr) +COMMON_HAL_MCU_PROCESSOR_UID_LENGTH=30 + +# NOTE: Not implementing external flash for now +# CFLAGS+=-DEXT_FLASH_MX25 diff --git a/ports/analog/boards/max32690evkit/pins.c b/ports/analog/boards/max32690evkit/pins.c new file mode 100644 index 000000000000..5b736385dc58 --- /dev/null +++ b/ports/analog/boards/max32690evkit/pins.c @@ -0,0 +1,126 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + //P0 + { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) }, + { MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) }, + { MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) }, + { MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) }, + { MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) }, + { MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) }, + { MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) }, + { MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) }, + { MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) }, + { MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) }, + { MP_ROM_QSTR(MP_QSTR_P0_26), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) }, + { MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, + //P1 + { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, + { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, + { MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) }, + { MP_ROM_QSTR(MP_QSTR_P1_14), MP_ROM_PTR(&pin_P1_14) }, + { MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_P1_16), MP_ROM_PTR(&pin_P1_16) }, + { MP_ROM_QSTR(MP_QSTR_P1_17), MP_ROM_PTR(&pin_P1_17) }, + { MP_ROM_QSTR(MP_QSTR_P1_18), MP_ROM_PTR(&pin_P1_18) }, + { MP_ROM_QSTR(MP_QSTR_P1_19), MP_ROM_PTR(&pin_P1_19) }, + { MP_ROM_QSTR(MP_QSTR_P1_20), MP_ROM_PTR(&pin_P1_20) }, + { MP_ROM_QSTR(MP_QSTR_P1_21), MP_ROM_PTR(&pin_P1_21) }, + { MP_ROM_QSTR(MP_QSTR_P1_22), MP_ROM_PTR(&pin_P1_22) }, + { MP_ROM_QSTR(MP_QSTR_P1_23), MP_ROM_PTR(&pin_P1_23) }, + { MP_ROM_QSTR(MP_QSTR_P1_24), MP_ROM_PTR(&pin_P1_24) }, + { MP_ROM_QSTR(MP_QSTR_P1_25), MP_ROM_PTR(&pin_P1_25) }, + { MP_ROM_QSTR(MP_QSTR_P1_26), MP_ROM_PTR(&pin_P1_26) }, + { MP_ROM_QSTR(MP_QSTR_P1_27), MP_ROM_PTR(&pin_P1_27) }, + { MP_ROM_QSTR(MP_QSTR_P1_28), MP_ROM_PTR(&pin_P1_28) }, + { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, + { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, + { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, + //P2 + { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_P2_08), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_P2_09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, + { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, + { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, + { MP_ROM_QSTR(MP_QSTR_P2_13), MP_ROM_PTR(&pin_P2_13) }, + { MP_ROM_QSTR(MP_QSTR_P2_14), MP_ROM_PTR(&pin_P2_14) }, + { MP_ROM_QSTR(MP_QSTR_P2_15), MP_ROM_PTR(&pin_P2_15) }, + { MP_ROM_QSTR(MP_QSTR_P2_16), MP_ROM_PTR(&pin_P2_16) }, + { MP_ROM_QSTR(MP_QSTR_P2_17), MP_ROM_PTR(&pin_P2_17) }, + { MP_ROM_QSTR(MP_QSTR_P2_18), MP_ROM_PTR(&pin_P2_18) }, + { MP_ROM_QSTR(MP_QSTR_P2_19), MP_ROM_PTR(&pin_P2_19) }, + { MP_ROM_QSTR(MP_QSTR_P2_20), MP_ROM_PTR(&pin_P2_20) }, + { MP_ROM_QSTR(MP_QSTR_P2_21), MP_ROM_PTR(&pin_P2_21) }, + { MP_ROM_QSTR(MP_QSTR_P2_22), MP_ROM_PTR(&pin_P2_22) }, + { MP_ROM_QSTR(MP_QSTR_P2_23), MP_ROM_PTR(&pin_P2_23) }, + { MP_ROM_QSTR(MP_QSTR_P2_24), MP_ROM_PTR(&pin_P2_24) }, + { MP_ROM_QSTR(MP_QSTR_P2_25), MP_ROM_PTR(&pin_P2_25) }, + { MP_ROM_QSTR(MP_QSTR_P2_26), MP_ROM_PTR(&pin_P2_26) }, + { MP_ROM_QSTR(MP_QSTR_P2_27), MP_ROM_PTR(&pin_P2_27) }, + { MP_ROM_QSTR(MP_QSTR_P2_28), MP_ROM_PTR(&pin_P2_28) }, + { MP_ROM_QSTR(MP_QSTR_P2_29), MP_ROM_PTR(&pin_P2_29) }, + { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, + { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, + //P3 + { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, + //P4 + { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From adef40c9f629843ecbc9353c12e6d709d9e79b9b Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Mon, 23 Sep 2024 09:30:16 -0600 Subject: [PATCH 022/252] Reordered mpconfigport.mk; replaced MXC_SYS includes with max32_port.h in microcontroller/Pin.c --- ports/analog/Makefile | 9 +++++++-- .../common-hal/digitalio/DigitalInOut.c | 5 +++-- ports/analog/common-hal/microcontroller/Pin.c | 6 ++---- ports/analog/mpconfigport.mk | 20 ++++++++----------- ports/analog/peripherals/led.h | 5 ----- ports/analog/supervisor/internal_flash.c | 2 +- ports/analog/supervisor/port.c | 6 ------ 7 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 ports/analog/peripherals/led.h diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 072d9f866219..766f0f78b930 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -147,6 +147,8 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ -DRISCV_LOAD=0 + +# todo: add these for linkerfiles later on so that it's easier to add new boards # -DFLASH_ORIGIN=0x10000000 \ # -DFLASH_SIZE=0x340000 \ # -DSRAM_ORIGIN=0x20000000 \ @@ -193,7 +195,9 @@ SRC_C += \ CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostartfiles $(BASE_CFLAGS) $(COPT) -# Suppress some warnings for MSDK +# Suppress some errors for MSDK +# cast-align warning will be suppressed; +# it gets generated by CircuitPy's TLSF memory allocator lib CFLAGS += -Wno-error=unused-parameter \ -Wno-error=old-style-declaration \ -Wno-error=sign-compare \ @@ -203,7 +207,8 @@ CFLAGS += -Wno-error=unused-parameter \ -Wno-error=lto-type-mismatch \ -Wno-error=cast-align \ -Wno-error=nested-externs \ - -Wno-error=sign-compare + -Wno-error=sign-compare \ + -Wno-cast-align \ ENTRY = Reset_Handler LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index 59a242239e0d..d23c90fdbc36 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -4,6 +4,7 @@ // // SPDX-License-Identifier: MIT +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE 1 #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/microcontroller/Pin.h" @@ -70,9 +71,9 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( // todo (low): MSDK Hardware does not support open-drain configuration except // todo (low): when directly managed by a peripheral such as I2C. - // todo (low): find a way to signal this perhaps to any upstream code + // todo (low): find a way to signal this to any upstream code if (drive_mode != DRIVE_MODE_PUSH_PULL) { - return DIGITALINOUT_OK; + return DIGITALINOUT_INVALID_DRIVE_MODE; } return DIGITALINOUT_OK; } diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 7259c0effe8a..22e3ce3899d9 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -10,9 +10,7 @@ #include "mpconfigboard.h" #include "pins.h" -#include "mxc_sys.h" -#include "gpio.h" -#include "gpio_regs.h" +#include "max32_port.h" #include "common-hal/microcontroller/Pin.h" @@ -79,7 +77,7 @@ uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { } // most max32 gpio ports have 32 pins - // todo: create a struct to encode # of pins for each port, since some GPIO ports differ + // todo (low prior.): encode # of pins for each port, since some GPIO ports differ return pin->port * 32 + pin->mask; } diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index f2cc8bd7aea0..348d61dc2892 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -21,9 +21,6 @@ INTERNAL_FLASH_FILESYSTEM = 1 #################################################################################### # These modules are implemented in ports//common-hal: -# Typically the second module to create -CIRCUITPY_DIGITALIO ?= 1 - # Plan to implement CIRCUITPY_BUSIO ?= 0 CIRCUITPY_RTC ?= 0 @@ -47,21 +44,20 @@ CIRCUITPY_DISPLAYIO ?= 0 # These modules are implemented in shared-module/ - they can be included in # any port once their prerequisites in common-hal are complete. +# No requirements, but takes extra flash +CIRCUITPY_ULAB = 1 # Requires DigitalIO: -CIRCUITPY_BITBANGIO ?= 0 -# Requires neopixel_write or SPI (dotstar) -CIRCUITPY_PIXELBUF ?= 0 +CIRCUITPY_BITBANGIO ?= 1 +# Requires Microcontroller +CIRCUITPY_TOUCHIO ?= 1 # Requires OS CIRCUITPY_RANDOM ?= 0 -# Requires Microcontroller -CIRCUITPY_TOUCHIO ?= 0 -# Requires UART +# Requires busio.UART CIRCUITPY_CONSOLE_UART ?= 0 # Does nothing without I2C CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 - -# No requirements, but takes extra flash -CIRCUITPY_ULAB = 1 +# Requires neopixel_write or SPI (dotstar) +CIRCUITPY_PIXELBUF ?= 0 #################################################################################### # Required for clean building (additional CircuittPython Defaults) diff --git a/ports/analog/peripherals/led.h b/ports/analog/peripherals/led.h deleted file mode 100644 index ff05be051bb2..000000000000 --- a/ports/analog/peripherals/led.h +++ /dev/null @@ -1,5 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. -// -// SPDX-License-Identifier: MIT diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c index 2b9b51967734..57dd7d8b45d4 100644 --- a/ports/analog/supervisor/internal_flash.c +++ b/ports/analog/supervisor/internal_flash.c @@ -187,7 +187,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t error, blocks_left, count, page_start, page_size = 0; while (num_blocks > 0) { - uint32_t dest_addr = block2addr(block_num); + int dest_addr = block2addr(block_num); // bad block number passed in if (dest_addr == -1) { return 1; diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 730d85124259..af929e074e8f 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -37,9 +37,6 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" -//todo: pack the below definitions into their own module -//todo: under peripherals/gpio, peripherals/clocks, etc. - // Sys includes #include "max32_port.h" @@ -62,9 +59,6 @@ extern const int num_pbs; extern const mxc_gpio_cfg_t led_pin[]; extern const int num_leds; -//todo: define an LED HAL -// #include "peripherals/led.h" - // For saving rtc data for ticks static uint32_t subsec, sec = 0; static uint32_t tick_flag = 0; From 01a220af0f0bb9f90feebdc875d889860d5c6b68 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 23 Sep 2024 21:24:30 -0500 Subject: [PATCH 023/252] Started simplifying getbuffer --- shared-module/audiodelays/Echo.c | 129 +++++++++++++++++-------------- 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index fcb664f6ce4f..7caa6c79f84e 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -43,10 +43,6 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ } synthio_block_assign_slot(mix, &self->mix, MP_QSTR_mix); - // calculate buffer size for the set delay - mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); - self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); - // Set the echo buffer for the max possible delay self->max_delay_ms = max_delay_ms; self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); @@ -57,9 +53,13 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ } memset(self->echo_buffer, 0, self->max_echo_buffer_len); + // calculate current echo buffer size for the set delay + mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); + self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); + // read is where we store the incoming sample // write is what we send to the outgoing buffer - self->echo_buffer_read_pos = self->buffer_len / sizeof(uint32_t); + self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); self->echo_buffer_write_pos = 0; self->sample = NULL; @@ -168,7 +168,7 @@ void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sam audiosample_reset_buffer(self->sample, false, 0); audioio_get_buffer_result_t result = audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&self->sample_remaining_buffer, &self->sample_buffer_length); // Track length in terms of words. - self->sample_buffer_length /= sizeof(uint32_t); + self->sample_buffer_length /= sizeof(uint16_t); self->more_data = result == GET_BUFFER_MORE_DATA; return; @@ -179,35 +179,48 @@ void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self) { return; } +#define RANGE_LOW (-28000) +#define RANGE_HIGH (28000) +#define RANGE_SHIFT (16) +#define RANGE_SCALE (0xfffffff / (32768 * 2 - RANGE_HIGH)) + +// dynamic range compression via a downward compressor with hard knee +// +// When the output value is within the range +-28000 (about 85% of full scale), +// it is unchanged. Otherwise, it undergoes a gain reduction so that the +// largest possible values, (+32768,-32767) * 2 (2 for echo and sample), +// still fit within the output range +// +// This produces a much louder overall volume with multiple voices, without +// much additional processing. +// +// https://en.wikipedia.org/wiki/Dynamic_range_compression +static +int16_t mix_down_sample(int32_t sample) { + if (sample < RANGE_LOW) { + sample = (((sample - RANGE_LOW) * RANGE_SCALE) >> RANGE_SHIFT) + RANGE_LOW; + } else if (sample > RANGE_HIGH) { + sample = (((sample - RANGE_HIGH) * RANGE_SCALE) >> RANGE_SHIFT) + RANGE_HIGH; + } + return sample; +} + audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { - uint32_t *word_buffer = (uint32_t *)self->buffer; - uint32_t length = self->buffer_len / sizeof(uint32_t); - uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint32_t); - mp_float_t f_mix = synthio_block_slot_get(&self->mix); - if (f_mix > 1.0) { - f_mix = 1.0; - } else if (f_mix < 0.0) { - f_mix = 0.0; - } - uint16_t mix = (uint16_t)(f_mix * (1 << 15)); + mp_float_t mix = MIN(1.0, MAX(synthio_block_slot_get(&self->mix), 0.0)); + mp_float_t decay = MIN(1.0, MAX(synthio_block_slot_get(&self->decay), 0.0)); - mp_float_t f_decay = synthio_block_slot_get(&self->decay); - if (f_decay > 1.0) { - f_decay = 1.0; - } else if (f_decay < 0.0) { - f_decay = 0.0; - } - uint16_t decay = (uint16_t)(f_decay * (1 << 15)); + int16_t *word_buffer = (int16_t *)self->buffer; + uint32_t length = self->buffer_len / sizeof(uint16_t); + int16_t *echo_buffer = (int16_t *)self->echo_buffer; + uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint16_t); while (length != 0) { if (self->sample_buffer_length == 0) { if (!self->more_data) { - if (self->loop) { - if (self->sample) { - audiosample_reset_buffer(self->sample, false, 0); - } + if (self->loop && self->sample) { + audiosample_reset_buffer(self->sample, false, 0); } else { self->sample = NULL; } @@ -216,7 +229,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // Load another buffer audioio_get_buffer_result_t result = audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&self->sample_remaining_buffer, &self->sample_buffer_length); // Track length in terms of words. - self->sample_buffer_length /= sizeof(uint32_t); + self->sample_buffer_length /= sizeof(uint16_t); // assuming 16 bit samples self->more_data = result == GET_BUFFER_MORE_DATA; } } @@ -224,18 +237,16 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // If we have no sample keep the echo echoing if (self->sample == NULL) { if (MP_LIKELY(self->bits_per_sample == 16)) { - if (mix == 0) { // no effect and no sample sound - for (uint32_t i = 0; i < length; i++) { - word_buffer[i] = 0; - } + if (mix <= 0.01) { // no sample sound and with no mix, no echo + memset(word_buffer, 0, length * sizeof(uint16_t)); } else { // sample signed/unsigned won't matter as we have no sample for (uint32_t i = 0; i < length; i++) { - uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - word_buffer[i] = mult16signed(echo, decay); - self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; + word_buffer[i] = echo_buffer[self->echo_buffer_read_pos++] * decay; - word_buffer[i] = mult16signed(word_buffer[i], mix); + echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; + + word_buffer[i] = word_buffer[i] * mix; if (self->echo_buffer_read_pos >= echo_buf_len) { self->echo_buffer_read_pos = 0; @@ -251,7 +262,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; for (uint32_t i = 0; i < length * 2; i++) { uint32_t echo_word = unpack8(echo_hsrc[i]); - echo_word = mult16signed(echo_word, decay); + echo_word = echo_word * decay; hword_buffer[i] = pack8(echo_word); echo_hsrc[self->echo_buffer_write_pos++] = hword_buffer[i]; @@ -263,27 +274,28 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } } + length = 0; } else { // we have a sample uint32_t n = MIN(self->sample_buffer_length, length); - uint32_t *sample_src = self->sample_remaining_buffer; + int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; if (MP_LIKELY(self->bits_per_sample == 16)) { - if (mix == 0) { // sample only + if (mix <= 0.01) { // sample only for (uint32_t i = 0; i < n; i++) { word_buffer[i] = sample_src[i]; } } else { for (uint32_t i = 0; i < n; i++) { - uint32_t sample_word = sample_src[i]; - if (MP_LIKELY(!self->samples_signed)) { + int32_t sample_word = sample_src[i]; + if (!self->samples_signed) { sample_word = tosigned16(sample_word); } - uint32_t echo = self->echo_buffer[self->echo_buffer_read_pos++]; - word_buffer[i] = add16signed(mult16signed(echo, decay), sample_word); - self->echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; - word_buffer[i] = add16signed(mult16signed(sample_word, 32768 - mix), mult16signed(word_buffer[i], mix)); + int32_t word = (echo_buffer[self->echo_buffer_read_pos++] * decay) + sample_word; + word_buffer[i] = mix_down_sample(word); + + echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; if (self->echo_buffer_read_pos >= echo_buf_len) { self->echo_buffer_read_pos = 0; @@ -291,6 +303,8 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * if (self->echo_buffer_write_pos >= echo_buf_len) { self->echo_buffer_write_pos = 0; } + + word_buffer[i] = (sample_word * (1.0 - mix)) + (word_buffer[i] * mix); } } } else { // bits per sample is 8 @@ -303,11 +317,11 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * if (MP_LIKELY(!self->samples_signed)) { sample_word = tosigned16(sample_word); } - echo_word = mult16signed(echo_word, decay); - sample_word = add16signed(sample_word, echo_word); + echo_word = echo_word * decay; + sample_word = sample_word + echo_word; hword_buffer[i] = pack8(sample_word); - echo_hsrc[self->echo_buffer_write_pos++] = pack8(add16signed(sample_word, unpack8(hword_buffer[i]))); + echo_hsrc[self->echo_buffer_write_pos++] = pack8(sample_word + unpack8(hword_buffer[i])); if (self->echo_buffer_read_pos >= echo_buf_len) { self->echo_buffer_read_pos = 0; } @@ -323,6 +337,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * self->sample_buffer_length -= n; } } + *buffer = (uint8_t *)self->buffer; *buffer_length = self->buffer_len; return GET_BUFFER_MORE_DATA; @@ -331,18 +346,12 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * void audiodelays_echo_get_buffer_structure(audiodelays_echo_obj_t *self, bool single_channel_output, bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing) { - if (self->sample != NULL) { - audiosample_get_buffer_structure(self->sample, single_channel_output, single_buffer, samples_signed, max_buffer_length, spacing); - *single_buffer = false; - *max_buffer_length = self->buffer_len; + *single_buffer = true; + *samples_signed = true; + *max_buffer_length = self->buffer_len; + if (single_channel_output) { + *spacing = self->channel_count; } else { - *single_buffer = true; - *samples_signed = true; - *max_buffer_length = self->buffer_len; - if (single_channel_output) { - *spacing = self->channel_count; - } else { - *spacing = 1; - } + *spacing = 1; } } From 810690a7edf174894b208f3ae1e950a18078fd72 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 24 Sep 2024 00:43:49 -0400 Subject: [PATCH 024/252] Remove CONFIG_LWIP_LOCAL_HOSTNAME from S3 boards --- ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig | 2 +- .../boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig | 2 +- .../espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig | 2 +- .../boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig | 2 +- ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig | 2 +- ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig | 2 +- ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig | 2 +- .../boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig | 2 +- ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig | 2 +- ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig | 2 +- ports/espressif/boards/arduino_nano_esp32s3/sdkconfig | 2 +- .../boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig | 2 +- ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig | 2 +- ports/espressif/boards/barduino/sdkconfig | 2 +- ports/espressif/boards/bpi_leaf_s3/sdkconfig | 2 +- ports/espressif/boards/bpi_picow_s3/sdkconfig | 2 +- ports/espressif/boards/brainboardz_neuron/sdkconfig | 2 +- ports/espressif/boards/circuitart_zero_s3/sdkconfig | 2 +- ports/espressif/boards/columbia-dsl-sensor/sdkconfig | 2 +- ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig | 2 +- ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig | 2 +- ports/espressif/boards/es3ink/sdkconfig | 2 +- ports/espressif/boards/espressif_esp32s3_box/sdkconfig | 2 +- ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig | 2 +- .../espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig | 2 +- .../boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig | 2 +- ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig | 2 +- .../espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig | 2 +- .../espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig | 2 +- .../espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig | 2 +- ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig | 2 +- ports/espressif/boards/espressif_esp32s3_eye/sdkconfig | 2 +- ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig | 2 +- ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig | 2 +- ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig | 2 +- ports/espressif/boards/firebeetle2_esp32s3/sdkconfig | 2 +- ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig | 2 +- ports/espressif/boards/lilygo_tdeck/sdkconfig | 2 +- ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig | 2 +- ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig | 2 +- ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig | 2 +- ports/espressif/boards/lilygo_twatch_s3/sdkconfig | 2 +- ports/espressif/boards/lolin_s3/sdkconfig | 2 +- ports/espressif/boards/lolin_s3_mini/sdkconfig | 2 +- ports/espressif/boards/lolin_s3_pro/sdkconfig | 2 +- ports/espressif/boards/m5stack_atoms3/sdkconfig | 2 +- ports/espressif/boards/m5stack_atoms3_lite/sdkconfig | 2 +- ports/espressif/boards/m5stack_atoms3u/sdkconfig | 2 +- ports/espressif/boards/m5stack_cardputer/sdkconfig | 2 +- ports/espressif/boards/m5stack_cores3/sdkconfig | 2 +- ports/espressif/boards/m5stack_dial/sdkconfig | 2 +- ports/espressif/boards/magiclick_s3_n4r2/sdkconfig | 2 +- ports/espressif/boards/makerfabs_tft7/sdkconfig | 2 +- ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig | 2 +- .../espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig | 2 +- ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig | 2 +- ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig | 2 +- ports/espressif/boards/sunton_esp32_8048S070/sdkconfig | 2 +- ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_bling/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_pros3/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig | 2 +- ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig | 2 +- ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig | 2 +- ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig | 2 +- ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig | 2 +- ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig | 2 +- ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig | 2 +- ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig | 2 +- ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig | 2 +- 76 files changed, 76 insertions(+), 76 deletions(-) diff --git a/ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig b/ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig index 1bddb7a89fbb..0dba94e67d4a 100644 --- a/ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig +++ b/ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig b/ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig index db95a623aa92..0349390f7a9f 100644 --- a/ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig +++ b/ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="matrixportal-s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="matrixportal-s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig b/ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig index 4b1cfa36412d..1ace5521170c 100644 --- a/ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig +++ b/ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="Metro-ESP32S3" +# CONFIG_LWIP_LOCAL_HOSTNAME="Metro-ESP32S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig b/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig +++ b/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig b/ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig +++ b/ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig b/ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig index 8e26f268e76a..35c640231020 100644 --- a/ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig +++ b/ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="qualia" +# CONFIG_LWIP_LOCAL_HOSTNAME="qualia" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig b/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig +++ b/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig index b2e5c546b825..4a5a5fb7b5b1 100644 --- a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig +++ b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="nano-esp32" +# CONFIG_LWIP_LOCAL_HOSTNAME="nano-esp32" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig b/ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig index 30ffa1a82961..f007132588f3 100644 --- a/ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig +++ b/ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="autosportlabs-esp32-can-x2" +# CONFIG_LWIP_LOCAL_HOSTNAME="autosportlabs-esp32-can-x2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/barduino/sdkconfig b/ports/espressif/boards/barduino/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/barduino/sdkconfig +++ b/ports/espressif/boards/barduino/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/bpi_leaf_s3/sdkconfig b/ports/espressif/boards/bpi_leaf_s3/sdkconfig index 6b3f2584c712..7a60d7734da0 100644 --- a/ports/espressif/boards/bpi_leaf_s3/sdkconfig +++ b/ports/espressif/boards/bpi_leaf_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="BPI-Leaf-S3" +# CONFIG_LWIP_LOCAL_HOSTNAME="BPI-Leaf-S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/bpi_picow_s3/sdkconfig b/ports/espressif/boards/bpi_picow_s3/sdkconfig index 914b07726400..d6cc7c8b06ce 100644 --- a/ports/espressif/boards/bpi_picow_s3/sdkconfig +++ b/ports/espressif/boards/bpi_picow_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="BPI-PicoW-S3" +# CONFIG_LWIP_LOCAL_HOSTNAME="BPI-PicoW-S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/brainboardz_neuron/sdkconfig b/ports/espressif/boards/brainboardz_neuron/sdkconfig index e553af17769f..8bafd1a93531 100755 --- a/ports/espressif/boards/brainboardz_neuron/sdkconfig +++ b/ports/espressif/boards/brainboardz_neuron/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="BrainBoardzNeuron" +# CONFIG_LWIP_LOCAL_HOSTNAME="BrainBoardzNeuron" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/circuitart_zero_s3/sdkconfig b/ports/espressif/boards/circuitart_zero_s3/sdkconfig index 0e6ef9fd17a6..5bed3ccaaea0 100644 --- a/ports/espressif/boards/circuitart_zero_s3/sdkconfig +++ b/ports/espressif/boards/circuitart_zero_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="CircuitART Zero S3" +# CONFIG_LWIP_LOCAL_HOSTNAME="CircuitART Zero S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/columbia-dsl-sensor/sdkconfig b/ports/espressif/boards/columbia-dsl-sensor/sdkconfig index 05d2603dfbaf..0bde2cec9981 100644 --- a/ports/espressif/boards/columbia-dsl-sensor/sdkconfig +++ b/ports/espressif/boards/columbia-dsl-sensor/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="columbia-dsl-sensor" +# CONFIG_LWIP_LOCAL_HOSTNAME="columbia-dsl-sensor" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig b/ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig +++ b/ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig b/ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig index 2d5e06f98510..ccd1e4b01431 100644 --- a/ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig +++ b/ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="DeneyapKart1A_v2" +# CONFIG_LWIP_LOCAL_HOSTNAME="DeneyapKart1A_v2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/es3ink/sdkconfig b/ports/espressif/boards/es3ink/sdkconfig index b023c59d0357..f2b04b79a94d 100644 --- a/ports/espressif/boards/es3ink/sdkconfig +++ b/ports/espressif/boards/es3ink/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="es3ink" +# CONFIG_LWIP_LOCAL_HOSTNAME="es3ink" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_box/sdkconfig b/ports/espressif/boards/espressif_esp32s3_box/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_box/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_box/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig b/ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig index 46e3a741091a..3d77264159c8 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-hacktablet" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-hacktablet" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig b/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig index eebef2db64d2..f683ee9a32b3 100644 --- a/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-eye" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-eye" # end of LWIP CONFIG_OV2640_SUPPORT=y # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig b/ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig index 75153e420204..a051f945c0ac 100644 --- a/ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-lcd-ev" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-lcd-ev" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig b/ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig index e3fc638ec056..f9bf089086fb 100644 --- a/ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-lcd-ev-v1.5" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-lcd-ev-v1.5" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/firebeetle2_esp32s3/sdkconfig b/ports/espressif/boards/firebeetle2_esp32s3/sdkconfig index 6c5d1f198661..45e6e934c41e 100644 --- a/ports/espressif/boards/firebeetle2_esp32s3/sdkconfig +++ b/ports/espressif/boards/firebeetle2_esp32s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" CONFIG_OV2640_SUPPORT=y CONFIG_OV7725_SUPPORT=y # end of LWIP diff --git a/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig b/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig index ab4e9875add9..28cae567fb21 100644 --- a/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig +++ b/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig @@ -8,7 +8,7 @@ # LWIP # CONFIG_ESP_PHY_ENABLE_USB=n -CONFIG_LWIP_LOCAL_HOSTNAME="HELTEC-ESP32S3-V3" +# CONFIG_LWIP_LOCAL_HOSTNAME="HELTEC-ESP32S3-V3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_tdeck/sdkconfig b/ports/espressif/boards/lilygo_tdeck/sdkconfig index 35bfb64a016c..0cb097e334fb 100644 --- a/ports/espressif/boards/lilygo_tdeck/sdkconfig +++ b/ports/espressif/boards/lilygo_tdeck/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="T-DECK" +# CONFIG_LWIP_LOCAL_HOSTNAME="T-DECK" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig b/ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig index 7c9743375931..f8b780115261 100644 --- a/ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig +++ b/ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="T-DISPLAY-S3" +# CONFIG_LWIP_LOCAL_HOSTNAME="T-DISPLAY-S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig b/ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig index 03805d7f206c..427facb83655 100644 --- a/ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig +++ b/ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="T-Display S3 Pro" +# CONFIG_LWIP_LOCAL_HOSTNAME="T-Display S3 Pro" # end of LWIP # diff --git a/ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig b/ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig +++ b/ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_twatch_s3/sdkconfig b/ports/espressif/boards/lilygo_twatch_s3/sdkconfig index 08b2b772c5cd..6ddf3e0e523c 100644 --- a/ports/espressif/boards/lilygo_twatch_s3/sdkconfig +++ b/ports/espressif/boards/lilygo_twatch_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="t-watch-s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="t-watch-s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_s3/sdkconfig b/ports/espressif/boards/lolin_s3/sdkconfig index b90e3fa57eda..f1fad05dfe92 100644 --- a/ports/espressif/boards/lolin_s3/sdkconfig +++ b/ports/espressif/boards/lolin_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3" +# CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_s3_mini/sdkconfig b/ports/espressif/boards/lolin_s3_mini/sdkconfig index 36be9c760edd..25aedac53fbd 100644 --- a/ports/espressif/boards/lolin_s3_mini/sdkconfig +++ b/ports/espressif/boards/lolin_s3_mini/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3-MINI" +# CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3-MINI" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_s3_pro/sdkconfig b/ports/espressif/boards/lolin_s3_pro/sdkconfig index 4dfe8da3fb06..a53c9631f17e 100755 --- a/ports/espressif/boards/lolin_s3_pro/sdkconfig +++ b/ports/espressif/boards/lolin_s3_pro/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3-PRO" +# CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3-PRO" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atoms3/sdkconfig b/ports/espressif/boards/m5stack_atoms3/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/m5stack_atoms3/sdkconfig +++ b/ports/espressif/boards/m5stack_atoms3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atoms3_lite/sdkconfig b/ports/espressif/boards/m5stack_atoms3_lite/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/m5stack_atoms3_lite/sdkconfig +++ b/ports/espressif/boards/m5stack_atoms3_lite/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atoms3u/sdkconfig b/ports/espressif/boards/m5stack_atoms3u/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/m5stack_atoms3u/sdkconfig +++ b/ports/espressif/boards/m5stack_atoms3u/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_cardputer/sdkconfig b/ports/espressif/boards/m5stack_cardputer/sdkconfig index b48116f764dc..d8c94423ebf8 100644 --- a/ports/espressif/boards/m5stack_cardputer/sdkconfig +++ b/ports/espressif/boards/m5stack_cardputer/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-cardputer" +# CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-cardputer" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_cores3/sdkconfig b/ports/espressif/boards/m5stack_cores3/sdkconfig index 2eb2f0a850b3..3eecd2c242c7 100644 --- a/ports/espressif/boards/m5stack_cores3/sdkconfig +++ b/ports/espressif/boards/m5stack_cores3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-cores3" +# CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-cores3" # end of LWIP # diff --git a/ports/espressif/boards/m5stack_dial/sdkconfig b/ports/espressif/boards/m5stack_dial/sdkconfig index 2938bb3bfa7f..53b647b41b36 100644 --- a/ports/espressif/boards/m5stack_dial/sdkconfig +++ b/ports/espressif/boards/m5stack_dial/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-dial" +# CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-dial" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig index 3e9b8e2f1737..9d7d5d7eca07 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig +++ b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig @@ -8,7 +8,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="MagiClick-ESP32S3" +# CONFIG_LWIP_LOCAL_HOSTNAME="MagiClick-ESP32S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/makerfabs_tft7/sdkconfig b/ports/espressif/boards/makerfabs_tft7/sdkconfig index 5853b29ae94e..53896532db88 100644 --- a/ports/espressif/boards/makerfabs_tft7/sdkconfig +++ b/ports/espressif/boards/makerfabs_tft7/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="matouch-tft" +# CONFIG_LWIP_LOCAL_HOSTNAME="matouch-tft" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig b/ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig index 3023ed221c35..25ff4f97acf1 100644 --- a/ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig +++ b/ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # Camera configuration # diff --git a/ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig b/ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig index deb1b88d7cac..12ba241a99b2 100644 --- a/ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig +++ b/ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_data_logger" +# CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_data_logger" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig index fe95b60d4c81..0d9061f59528 100644 --- a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig +++ b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_motion_s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_motion_s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig b/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig index 2c7a057567fa..8254944f07dd 100644 --- a/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig +++ b/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/sunton_esp32_8048S070/sdkconfig b/ports/espressif/boards/sunton_esp32_8048S070/sdkconfig index 61e94a741ffd..47527b994439 100644 --- a/ports/espressif/boards/sunton_esp32_8048S070/sdkconfig +++ b/ports/espressif/boards/sunton_esp32_8048S070/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="sunton-esp32-8048S070" +# CONFIG_LWIP_LOCAL_HOSTNAME="sunton-esp32-8048S070" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig b/ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig +++ b/ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_bling/sdkconfig b/ports/espressif/boards/unexpectedmaker_bling/sdkconfig index 8e693ad1cb4d..cf61f58eeb7e 100644 --- a/ports/espressif/boards/unexpectedmaker_bling/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_bling/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMBling" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMBling" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig b/ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig index eea8c00b59b9..368367dd5058 100644 --- a/ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMBlizzardS3" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMBlizzardS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig b/ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig index 3ccd3175c69d..9b9b72aa0646 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS3" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig b/ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig index df8f15b54391..024f68428c05 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS3 Neo" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS3 Neo" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig b/ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig index 815f002d3829..e8e8fb5f419f 100644 --- a/ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMNanoS3" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMNanoS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig b/ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig index 9de28080ff38..681b8f2a7424 100644 --- a/ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMOMGS3" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMOMGS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_pros3/sdkconfig b/ports/espressif/boards/unexpectedmaker_pros3/sdkconfig index 21b91a2199af..a2869b8f4ef7 100644 --- a/ports/espressif/boards/unexpectedmaker_pros3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_pros3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMProS3" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMProS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig b/ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig index 8eae792a5838..7dc9d93078a1 100644 --- a/ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMRGBT" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMRGBT" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig b/ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig index d08f76926e0d..92f790fb8e70 100644 --- a/ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS3" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig b/ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig index 12b5605f4e5d..b7aacb06ad4c 100644 --- a/ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyWATCHS3" +# CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyWATCHS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig index bcfb4d48ffef..c54343d3f05f 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="waveshare-esp32-s3-lcd-1-28" +# CONFIG_LWIP_LOCAL_HOSTNAME="waveshare-esp32-s3-lcd-1-28" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig index 19f833ad74ce..23cc49e8d47a 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig @@ -8,7 +8,7 @@ # LWIP # # CONFIG_LWIP_IPV6 is not set -CONFIG_LWIP_LOCAL_HOSTNAME="waveshare-esp32-s3-tiny" +# CONFIG_LWIP_LOCAL_HOSTNAME="waveshare-esp32-s3-tiny" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig index 608f7e6a11cd..664ece4170f9 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="ESP32-S3-Zero" +# CONFIG_LWIP_LOCAL_HOSTNAME="ESP32-S3-Zero" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig b/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig +++ b/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig b/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig index f5ef79768114..9fdc70b59aa9 100644 --- a/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig +++ b/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig @@ -7,7 +7,7 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" +# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config From 519832d57da367f2d6e38dfe28ae26b96902f118 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 24 Sep 2024 18:04:25 -0400 Subject: [PATCH 025/252] Remove all LWIP_HOSTNAME lines --- ports/espressif/boards/01space_lcd042_esp32c3/sdkconfig | 1 - ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig | 1 - .../boards/adafruit_feather_esp32c6_4mbflash_nopsram/sdkconfig | 1 - .../boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig | 1 - .../espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig | 1 - .../boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig | 1 - ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig | 1 - ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig | 1 - ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig | 1 - ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig | 1 - .../boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig | 1 - ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig | 1 - ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig | 1 - ports/espressif/boards/ai_thinker_esp32-c3s-2m/sdkconfig | 1 - ports/espressif/boards/ai_thinker_esp32-c3s/sdkconfig | 1 - ports/espressif/boards/arduino_nano_esp32s3/sdkconfig | 1 - .../boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig | 1 - ports/espressif/boards/artisense_rd00/sdkconfig | 1 - ports/espressif/boards/atmegazero_esp32s2/sdkconfig | 1 - ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig | 1 - ports/espressif/boards/barduino/sdkconfig | 1 - ports/espressif/boards/beetle-esp32-c3/sdkconfig | 1 - ports/espressif/boards/bpi_bit_s2/sdkconfig | 1 - ports/espressif/boards/bpi_leaf_s3/sdkconfig | 1 - ports/espressif/boards/bpi_picow_s3/sdkconfig | 1 - ports/espressif/boards/brainboardz_neuron/sdkconfig | 1 - ports/espressif/boards/circuitart_zero_s3/sdkconfig | 1 - ports/espressif/boards/columbia-dsl-sensor/sdkconfig | 1 - ports/espressif/boards/crumpspace_crumps2/sdkconfig | 1 - ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig | 1 - ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig | 1 - ports/espressif/boards/deneyap_kart_g/sdkconfig | 1 - ports/espressif/boards/deneyap_mini/sdkconfig | 1 - ports/espressif/boards/deneyap_mini_v2/sdkconfig | 1 - ports/espressif/boards/es3ink/sdkconfig | 1 - ports/espressif/boards/espressif_esp32c3_devkitm_1_n4/sdkconfig | 1 - ports/espressif/boards/espressif_esp32c6_devkitc_1_n8/sdkconfig | 1 - ports/espressif/boards/espressif_esp32c6_devkitm_1_n4/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s2_devkitc_1_n4/sdkconfig | 1 - .../espressif/boards/espressif_esp32s2_devkitc_1_n4r2/sdkconfig | 1 - .../espressif/boards/espressif_esp32s2_devkitc_1_n8r2/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_box/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig | 1 - .../espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig | 1 - .../espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig | 1 - .../espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig | 1 - .../boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_eye/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig | 1 - ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig | 1 - ports/espressif/boards/espressif_esp8684_devkitc_02_n4/sdkconfig | 1 - ports/espressif/boards/firebeetle2_esp32s3/sdkconfig | 1 - ports/espressif/boards/gravitech_cucumber_m/sdkconfig | 1 - ports/espressif/boards/gravitech_cucumber_ms/sdkconfig | 1 - ports/espressif/boards/gravitech_cucumber_r/sdkconfig | 1 - ports/espressif/boards/gravitech_cucumber_rs/sdkconfig | 1 - ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig | 1 - ports/espressif/boards/hiibot_iots2/sdkconfig | 1 - ports/espressif/boards/lilygo_tdeck/sdkconfig | 1 - ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig | 1 - ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig | 1 - ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig | 1 - ports/espressif/boards/lilygo_ttgo_t-01c3/sdkconfig | 1 - ports/espressif/boards/lilygo_ttgo_t-oi-plus/sdkconfig | 1 - ports/espressif/boards/lilygo_ttgo_t8_s2/sdkconfig | 1 - ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/sdkconfig | 1 - ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/sdkconfig | 1 - ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_4m/sdkconfig | 1 - ports/espressif/boards/lilygo_twatch_s3/sdkconfig | 1 - ports/espressif/boards/lolin_c3_mini/sdkconfig | 1 - ports/espressif/boards/lolin_c3_pico/sdkconfig | 1 - ports/espressif/boards/lolin_s2_mini/sdkconfig | 1 - ports/espressif/boards/lolin_s2_pico/sdkconfig | 1 - ports/espressif/boards/lolin_s3/sdkconfig | 1 - ports/espressif/boards/lolin_s3_mini/sdkconfig | 1 - ports/espressif/boards/lolin_s3_pro/sdkconfig | 1 - ports/espressif/boards/luatos_core_esp32c3/sdkconfig | 1 - ports/espressif/boards/luatos_core_esp32c3_ch343/sdkconfig | 1 - ports/espressif/boards/m5stack_atom_echo/sdkconfig | 1 - ports/espressif/boards/m5stack_atom_lite/sdkconfig | 1 - ports/espressif/boards/m5stack_atom_matrix/sdkconfig | 1 - ports/espressif/boards/m5stack_atom_u/sdkconfig | 1 - ports/espressif/boards/m5stack_atoms3/sdkconfig | 1 - ports/espressif/boards/m5stack_atoms3_lite/sdkconfig | 1 - ports/espressif/boards/m5stack_atoms3u/sdkconfig | 1 - ports/espressif/boards/m5stack_cardputer/sdkconfig | 1 - ports/espressif/boards/m5stack_core2/sdkconfig | 1 - ports/espressif/boards/m5stack_core_basic/sdkconfig | 1 - ports/espressif/boards/m5stack_core_fire/sdkconfig | 1 - ports/espressif/boards/m5stack_cores3/sdkconfig | 1 - ports/espressif/boards/m5stack_dial/sdkconfig | 1 - ports/espressif/boards/m5stack_m5paper/sdkconfig | 1 - ports/espressif/boards/m5stack_stamp_c3/sdkconfig | 1 - ports/espressif/boards/m5stack_stick_c/sdkconfig | 1 - ports/espressif/boards/m5stack_stick_c_plus/sdkconfig | 1 - ports/espressif/boards/m5stack_timer_camera_x/sdkconfig | 1 - ports/espressif/boards/magiclick_s3_n4r2/sdkconfig | 1 - ports/espressif/boards/maker_badge/sdkconfig | 1 - ports/espressif/boards/makerfabs_tft7/sdkconfig | 1 - ports/espressif/boards/makergo_esp32c3_supermini/sdkconfig | 1 - ports/espressif/boards/microdev_micro_c3/sdkconfig | 1 - ports/espressif/boards/microdev_micro_s2/sdkconfig | 1 - ports/espressif/boards/morpheans_morphesp-240/sdkconfig | 1 - ports/espressif/boards/nodemcu_esp32c2/sdkconfig | 1 - ports/espressif/boards/odt_pixelwing_esp32_s2/sdkconfig | 1 - ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig | 1 - ports/espressif/boards/seeed_xiao_esp32c3/sdkconfig | 1 - ports/espressif/boards/seeed_xiao_esp32c6/sdkconfig | 1 - ports/espressif/boards/sensebox_mcu_esp32s2/sdkconfig | 1 - ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig | 1 - ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig | 1 - ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig | 1 - ports/espressif/boards/spotpear_esp32c3_lcd_1_44/sdkconfig | 1 - ports/espressif/boards/sqfmi_watchy/sdkconfig | 1 - ports/espressif/boards/sunton_esp32_2424S012/sdkconfig | 1 - ports/espressif/boards/sunton_esp32_8048S070/sdkconfig | 1 - ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_bling/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_feathers2/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_feathers2_neo/sdkconfig | 1 - .../boards/unexpectedmaker_feathers2_prerelease/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_pros3/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_tinyc6/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_tinys2/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig | 1 - ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig | 1 - ports/espressif/boards/vidi_x/sdkconfig | 1 - ports/espressif/boards/waveshare_esp32_s2_pico_lcd/sdkconfig | 1 - ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig | 1 - ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig | 1 - ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig | 1 - ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig | 1 - ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig | 1 - ports/espressif/boards/waveshare_esp32s2_pico/sdkconfig | 1 - ports/espressif/boards/weact_esp32c6_n4/sdkconfig | 1 - ports/espressif/boards/weact_esp32c6_n8/sdkconfig | 1 - ports/espressif/boards/wemos_lolin32_lite/sdkconfig | 1 - ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig | 1 - ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig | 1 - 149 files changed, 149 deletions(-) diff --git a/ports/espressif/boards/01space_lcd042_esp32c3/sdkconfig b/ports/espressif/boards/01space_lcd042_esp32c3/sdkconfig index 3a08db70d5f0..e96286621603 100644 --- a/ports/espressif/boards/01space_lcd042_esp32c3/sdkconfig +++ b/ports/espressif/boards/01space_lcd042_esp32c3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="01Space-LCD042-ESP32C3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig b/ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig index 0dba94e67d4a..a12cbe62f148 100644 --- a/ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig +++ b/ports/espressif/boards/adafruit_esp32s3_camera/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # diff --git a/ports/espressif/boards/adafruit_feather_esp32c6_4mbflash_nopsram/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32c6_4mbflash_nopsram/sdkconfig index 0cc38a499d0d..e96286621603 100644 --- a/ports/espressif/boards/adafruit_feather_esp32c6_4mbflash_nopsram/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32c6_4mbflash_nopsram/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="Adafruit-Feather-ESP32C6" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32s3_4mbflash_2mbpsram/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32s3_nopsram/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig b/ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig b/ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig index 0349390f7a9f..e96286621603 100644 --- a/ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig +++ b/ports/espressif/boards/adafruit_matrixportal_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="matrixportal-s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig b/ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig index 1ace5521170c..e96286621603 100644 --- a/ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig +++ b/ports/espressif/boards/adafruit_metro_esp32s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="Metro-ESP32S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig b/ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig index aa82df2b813b..e96286621603 100644 --- a/ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig +++ b/ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="Adafruit-QTPy-ESP32C3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig b/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig +++ b/ports/espressif/boards/adafruit_qtpy_esp32s3_4mbflash_2mbpsram/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig b/ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig +++ b/ports/espressif/boards/adafruit_qtpy_esp32s3_nopsram/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig b/ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig index 35c640231020..e96286621603 100644 --- a/ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig +++ b/ports/espressif/boards/adafruit_qualia_s3_rgb666/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="qualia" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/ai_thinker_esp32-c3s-2m/sdkconfig b/ports/espressif/boards/ai_thinker_esp32-c3s-2m/sdkconfig index 411bc17724ae..e96286621603 100644 --- a/ports/espressif/boards/ai_thinker_esp32-c3s-2m/sdkconfig +++ b/ports/espressif/boards/ai_thinker_esp32-c3s-2m/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="AIThinker-ESP32C3S-2M" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/ai_thinker_esp32-c3s/sdkconfig b/ports/espressif/boards/ai_thinker_esp32-c3s/sdkconfig index 435604eb4b8a..e96286621603 100644 --- a/ports/espressif/boards/ai_thinker_esp32-c3s/sdkconfig +++ b/ports/espressif/boards/ai_thinker_esp32-c3s/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="AIThinker-ESP32C3S" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig b/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig +++ b/ports/espressif/boards/arduino_nano_esp32s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig index 4a5a5fb7b5b1..e96286621603 100644 --- a/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig +++ b/ports/espressif/boards/arduino_nano_esp32s3_inverted_statusled/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="nano-esp32" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/artisense_rd00/sdkconfig b/ports/espressif/boards/artisense_rd00/sdkconfig index 36749a928bd1..e96286621603 100644 --- a/ports/espressif/boards/artisense_rd00/sdkconfig +++ b/ports/espressif/boards/artisense_rd00/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="RD00-ESP32S2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/atmegazero_esp32s2/sdkconfig b/ports/espressif/boards/atmegazero_esp32s2/sdkconfig index 0748a66c5ca1..e96286621603 100644 --- a/ports/espressif/boards/atmegazero_esp32s2/sdkconfig +++ b/ports/espressif/boards/atmegazero_esp32s2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="ATMegaZero-Esp32s2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig b/ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig index f007132588f3..e96286621603 100644 --- a/ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig +++ b/ports/espressif/boards/autosportlabs_esp32_can_x2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="autosportlabs-esp32-can-x2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/barduino/sdkconfig b/ports/espressif/boards/barduino/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/barduino/sdkconfig +++ b/ports/espressif/boards/barduino/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/beetle-esp32-c3/sdkconfig b/ports/espressif/boards/beetle-esp32-c3/sdkconfig index 2b4299082a22..e96286621603 100644 --- a/ports/espressif/boards/beetle-esp32-c3/sdkconfig +++ b/ports/espressif/boards/beetle-esp32-c3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="beetle-esp32-c3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/bpi_bit_s2/sdkconfig b/ports/espressif/boards/bpi_bit_s2/sdkconfig index c9b6f75868d8..e96286621603 100644 --- a/ports/espressif/boards/bpi_bit_s2/sdkconfig +++ b/ports/espressif/boards/bpi_bit_s2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="BPI-BIT-S2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/bpi_leaf_s3/sdkconfig b/ports/espressif/boards/bpi_leaf_s3/sdkconfig index 7a60d7734da0..e96286621603 100644 --- a/ports/espressif/boards/bpi_leaf_s3/sdkconfig +++ b/ports/espressif/boards/bpi_leaf_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="BPI-Leaf-S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/bpi_picow_s3/sdkconfig b/ports/espressif/boards/bpi_picow_s3/sdkconfig index d6cc7c8b06ce..e96286621603 100644 --- a/ports/espressif/boards/bpi_picow_s3/sdkconfig +++ b/ports/espressif/boards/bpi_picow_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="BPI-PicoW-S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/brainboardz_neuron/sdkconfig b/ports/espressif/boards/brainboardz_neuron/sdkconfig index 8bafd1a93531..e96286621603 100755 --- a/ports/espressif/boards/brainboardz_neuron/sdkconfig +++ b/ports/espressif/boards/brainboardz_neuron/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="BrainBoardzNeuron" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/circuitart_zero_s3/sdkconfig b/ports/espressif/boards/circuitart_zero_s3/sdkconfig index 5bed3ccaaea0..e96286621603 100644 --- a/ports/espressif/boards/circuitart_zero_s3/sdkconfig +++ b/ports/espressif/boards/circuitart_zero_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="CircuitART Zero S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/columbia-dsl-sensor/sdkconfig b/ports/espressif/boards/columbia-dsl-sensor/sdkconfig index 0bde2cec9981..e96286621603 100644 --- a/ports/espressif/boards/columbia-dsl-sensor/sdkconfig +++ b/ports/espressif/boards/columbia-dsl-sensor/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="columbia-dsl-sensor" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/crumpspace_crumps2/sdkconfig b/ports/espressif/boards/crumpspace_crumps2/sdkconfig index e1f568a2d8d2..e96286621603 100644 --- a/ports/espressif/boards/crumpspace_crumps2/sdkconfig +++ b/ports/espressif/boards/crumpspace_crumps2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="CrumpS2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig b/ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig +++ b/ports/espressif/boards/cytron_maker_feather_aiot_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig b/ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig index ccd1e4b01431..e96286621603 100644 --- a/ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig +++ b/ports/espressif/boards/deneyap_kart_1a_v2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="DeneyapKart1A_v2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/deneyap_kart_g/sdkconfig b/ports/espressif/boards/deneyap_kart_g/sdkconfig index f239c3140522..e96286621603 100644 --- a/ports/espressif/boards/deneyap_kart_g/sdkconfig +++ b/ports/espressif/boards/deneyap_kart_g/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="DeneyapKartG" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/deneyap_mini/sdkconfig b/ports/espressif/boards/deneyap_mini/sdkconfig index 3bcde1ab9e68..e96286621603 100644 --- a/ports/espressif/boards/deneyap_mini/sdkconfig +++ b/ports/espressif/boards/deneyap_mini/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="DeneyapMini" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/deneyap_mini_v2/sdkconfig b/ports/espressif/boards/deneyap_mini_v2/sdkconfig index be30fb4463d9..e96286621603 100644 --- a/ports/espressif/boards/deneyap_mini_v2/sdkconfig +++ b/ports/espressif/boards/deneyap_mini_v2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="DeneyapMini_v2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/es3ink/sdkconfig b/ports/espressif/boards/es3ink/sdkconfig index f2b04b79a94d..e96286621603 100644 --- a/ports/espressif/boards/es3ink/sdkconfig +++ b/ports/espressif/boards/es3ink/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="es3ink" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32c3_devkitm_1_n4/sdkconfig b/ports/espressif/boards/espressif_esp32c3_devkitm_1_n4/sdkconfig index c4def86e6971..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32c3_devkitm_1_n4/sdkconfig +++ b/ports/espressif/boards/espressif_esp32c3_devkitm_1_n4/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="ESP32-C3-DevKitM-1" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32c6_devkitc_1_n8/sdkconfig b/ports/espressif/boards/espressif_esp32c6_devkitc_1_n8/sdkconfig index 54a547307565..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32c6_devkitc_1_n8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32c6_devkitc_1_n8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32c6" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32c6_devkitm_1_n4/sdkconfig b/ports/espressif/boards/espressif_esp32c6_devkitm_1_n4/sdkconfig index 30a4bea2cc68..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32c6_devkitm_1_n4/sdkconfig +++ b/ports/espressif/boards/espressif_esp32c6_devkitm_1_n4/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="ESP32-C6-DevKitM-1" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s2_devkitc_1_n4/sdkconfig b/ports/espressif/boards/espressif_esp32s2_devkitc_1_n4/sdkconfig index 57f0da698aa1..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s2_devkitc_1_n4/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s2_devkitc_1_n4/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s2_devkitc_1_n4r2/sdkconfig b/ports/espressif/boards/espressif_esp32s2_devkitc_1_n4r2/sdkconfig index 57f0da698aa1..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s2_devkitc_1_n4r2/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s2_devkitc_1_n4r2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s2_devkitc_1_n8r2/sdkconfig b/ports/espressif/boards/espressif_esp32s2_devkitc_1_n8r2/sdkconfig index 57f0da698aa1..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s2_devkitc_1_n8r2/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s2_devkitc_1_n8r2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_box/sdkconfig b/ports/espressif/boards/espressif_esp32s3_box/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_box/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_box/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig b/ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_box_lite/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n16/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n32r8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig index 3d77264159c8..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitc_1_n8r8_hacktablet/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-hacktablet" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_devkitm_1_n8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig b/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig index f683ee9a32b3..ac1c53571767 100644 --- a/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_eye/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-eye" # end of LWIP CONFIG_OV2640_SUPPORT=y # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig b/ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig index a051f945c0ac..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_lcd_ev/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-lcd-ev" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig b/ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig index f9bf089086fb..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_lcd_ev_v1.5/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3-lcd-ev-v1.5" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig +++ b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/espressif_esp8684_devkitc_02_n4/sdkconfig b/ports/espressif/boards/espressif_esp8684_devkitc_02_n4/sdkconfig index cf803dfc43aa..f53dd7f8795b 100644 --- a/ports/espressif/boards/espressif_esp8684_devkitc_02_n4/sdkconfig +++ b/ports/espressif/boards/espressif_esp8684_devkitc_02_n4/sdkconfig @@ -32,7 +32,6 @@ CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp8684" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/firebeetle2_esp32s3/sdkconfig b/ports/espressif/boards/firebeetle2_esp32s3/sdkconfig index 45e6e934c41e..49798548225e 100644 --- a/ports/espressif/boards/firebeetle2_esp32s3/sdkconfig +++ b/ports/espressif/boards/firebeetle2_esp32s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" CONFIG_OV2640_SUPPORT=y CONFIG_OV7725_SUPPORT=y # end of LWIP diff --git a/ports/espressif/boards/gravitech_cucumber_m/sdkconfig b/ports/espressif/boards/gravitech_cucumber_m/sdkconfig index ec6db5c72ea1..e96286621603 100644 --- a/ports/espressif/boards/gravitech_cucumber_m/sdkconfig +++ b/ports/espressif/boards/gravitech_cucumber_m/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="cucumber_m" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/gravitech_cucumber_ms/sdkconfig b/ports/espressif/boards/gravitech_cucumber_ms/sdkconfig index f3cc39cc6780..e96286621603 100644 --- a/ports/espressif/boards/gravitech_cucumber_ms/sdkconfig +++ b/ports/espressif/boards/gravitech_cucumber_ms/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="cucumber_ms" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/gravitech_cucumber_r/sdkconfig b/ports/espressif/boards/gravitech_cucumber_r/sdkconfig index e817a86205a1..e96286621603 100644 --- a/ports/espressif/boards/gravitech_cucumber_r/sdkconfig +++ b/ports/espressif/boards/gravitech_cucumber_r/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="cucumber_r" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/gravitech_cucumber_rs/sdkconfig b/ports/espressif/boards/gravitech_cucumber_rs/sdkconfig index 873eb7207a0f..e96286621603 100644 --- a/ports/espressif/boards/gravitech_cucumber_rs/sdkconfig +++ b/ports/espressif/boards/gravitech_cucumber_rs/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="cucumber_rs" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig b/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig index 28cae567fb21..a71099850d5f 100644 --- a/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig +++ b/ports/espressif/boards/heltec_esp32s3_wifi_lora_v3/sdkconfig @@ -8,7 +8,6 @@ # LWIP # CONFIG_ESP_PHY_ENABLE_USB=n -# CONFIG_LWIP_LOCAL_HOSTNAME="HELTEC-ESP32S3-V3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/hiibot_iots2/sdkconfig b/ports/espressif/boards/hiibot_iots2/sdkconfig index b2b83eb6e6c4..e96286621603 100644 --- a/ports/espressif/boards/hiibot_iots2/sdkconfig +++ b/ports/espressif/boards/hiibot_iots2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="HiiBot_IoTs2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_tdeck/sdkconfig b/ports/espressif/boards/lilygo_tdeck/sdkconfig index 0cb097e334fb..e96286621603 100644 --- a/ports/espressif/boards/lilygo_tdeck/sdkconfig +++ b/ports/espressif/boards/lilygo_tdeck/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="T-DECK" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig b/ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig index f8b780115261..e96286621603 100644 --- a/ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig +++ b/ports/espressif/boards/lilygo_tdisplay_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="T-DISPLAY-S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig b/ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig index 427facb83655..a12cbe62f148 100644 --- a/ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig +++ b/ports/espressif/boards/lilygo_tdisplay_s3_pro/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="T-Display S3 Pro" # end of LWIP # diff --git a/ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig b/ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig +++ b/ports/espressif/boards/lilygo_tembed_esp32s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_ttgo_t-01c3/sdkconfig b/ports/espressif/boards/lilygo_ttgo_t-01c3/sdkconfig index 54105bd51b39..e96286621603 100644 --- a/ports/espressif/boards/lilygo_ttgo_t-01c3/sdkconfig +++ b/ports/espressif/boards/lilygo_ttgo_t-01c3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="LILYGO TTGO T-01C3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_ttgo_t-oi-plus/sdkconfig b/ports/espressif/boards/lilygo_ttgo_t-oi-plus/sdkconfig index fc0f5c6edd20..e96286621603 100644 --- a/ports/espressif/boards/lilygo_ttgo_t-oi-plus/sdkconfig +++ b/ports/espressif/boards/lilygo_ttgo_t-oi-plus/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="LILYGO TTGO T-OI PLUS" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_ttgo_t8_s2/sdkconfig b/ports/espressif/boards/lilygo_ttgo_t8_s2/sdkconfig index 23f6593f1b23..e96286621603 100644 --- a/ports/espressif/boards/lilygo_ttgo_t8_s2/sdkconfig +++ b/ports/espressif/boards/lilygo_ttgo_t8_s2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="TTGO-T8-ESP32-S2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/sdkconfig b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/sdkconfig index 23f6593f1b23..e96286621603 100644 --- a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/sdkconfig +++ b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="TTGO-T8-ESP32-S2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/sdkconfig b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/sdkconfig index 61beea449b11..e96286621603 100644 --- a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/sdkconfig +++ b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="TTGO-TDISPLAY" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_4m/sdkconfig b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_4m/sdkconfig index 61beea449b11..e96286621603 100644 --- a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_4m/sdkconfig +++ b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_4m/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="TTGO-TDISPLAY" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lilygo_twatch_s3/sdkconfig b/ports/espressif/boards/lilygo_twatch_s3/sdkconfig index 6ddf3e0e523c..e96286621603 100644 --- a/ports/espressif/boards/lilygo_twatch_s3/sdkconfig +++ b/ports/espressif/boards/lilygo_twatch_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="t-watch-s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_c3_mini/sdkconfig b/ports/espressif/boards/lolin_c3_mini/sdkconfig index 932a4a2cbd04..e96286621603 100644 --- a/ports/espressif/boards/lolin_c3_mini/sdkconfig +++ b/ports/espressif/boards/lolin_c3_mini/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="lolin-c3-mini" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_c3_pico/sdkconfig b/ports/espressif/boards/lolin_c3_pico/sdkconfig index ba2885933e79..3d0800e10d9a 100644 --- a/ports/espressif/boards/lolin_c3_pico/sdkconfig +++ b/ports/espressif/boards/lolin_c3_pico/sdkconfig @@ -8,7 +8,6 @@ # LWIP # # CONFIG_LWIP_IPV6 is not set -CONFIG_LWIP_LOCAL_HOSTNAME="lolin-c3-pico" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_s2_mini/sdkconfig b/ports/espressif/boards/lolin_s2_mini/sdkconfig index ac239ca333e6..e96286621603 100644 --- a/ports/espressif/boards/lolin_s2_mini/sdkconfig +++ b/ports/espressif/boards/lolin_s2_mini/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="LS2Mini" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_s2_pico/sdkconfig b/ports/espressif/boards/lolin_s2_pico/sdkconfig index c2238c68143a..e96286621603 100644 --- a/ports/espressif/boards/lolin_s2_pico/sdkconfig +++ b/ports/espressif/boards/lolin_s2_pico/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="Lolin-S2Pico" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_s3/sdkconfig b/ports/espressif/boards/lolin_s3/sdkconfig index f1fad05dfe92..e96286621603 100644 --- a/ports/espressif/boards/lolin_s3/sdkconfig +++ b/ports/espressif/boards/lolin_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_s3_mini/sdkconfig b/ports/espressif/boards/lolin_s3_mini/sdkconfig index 25aedac53fbd..e96286621603 100644 --- a/ports/espressif/boards/lolin_s3_mini/sdkconfig +++ b/ports/espressif/boards/lolin_s3_mini/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3-MINI" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/lolin_s3_pro/sdkconfig b/ports/espressif/boards/lolin_s3_pro/sdkconfig index a53c9631f17e..e96286621603 100755 --- a/ports/espressif/boards/lolin_s3_pro/sdkconfig +++ b/ports/espressif/boards/lolin_s3_pro/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN-S3-PRO" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/luatos_core_esp32c3/sdkconfig b/ports/espressif/boards/luatos_core_esp32c3/sdkconfig index 7d94db0b5b13..e96286621603 100644 --- a/ports/espressif/boards/luatos_core_esp32c3/sdkconfig +++ b/ports/espressif/boards/luatos_core_esp32c3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="luatos-core-esp32c3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/luatos_core_esp32c3_ch343/sdkconfig b/ports/espressif/boards/luatos_core_esp32c3_ch343/sdkconfig index 7d94db0b5b13..e96286621603 100644 --- a/ports/espressif/boards/luatos_core_esp32c3_ch343/sdkconfig +++ b/ports/espressif/boards/luatos_core_esp32c3_ch343/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="luatos-core-esp32c3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atom_echo/sdkconfig b/ports/espressif/boards/m5stack_atom_echo/sdkconfig index 861e4ebad397..e96286621603 100644 --- a/ports/espressif/boards/m5stack_atom_echo/sdkconfig +++ b/ports/espressif/boards/m5stack_atom_echo/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskAtomEcho" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atom_lite/sdkconfig b/ports/espressif/boards/m5stack_atom_lite/sdkconfig index eaaf716a15ef..e96286621603 100644 --- a/ports/espressif/boards/m5stack_atom_lite/sdkconfig +++ b/ports/espressif/boards/m5stack_atom_lite/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskAtomLite" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atom_matrix/sdkconfig b/ports/espressif/boards/m5stack_atom_matrix/sdkconfig index 730f17de0e19..e96286621603 100644 --- a/ports/espressif/boards/m5stack_atom_matrix/sdkconfig +++ b/ports/espressif/boards/m5stack_atom_matrix/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskAtomMatrix" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atom_u/sdkconfig b/ports/espressif/boards/m5stack_atom_u/sdkconfig index 06d0f0169370..e96286621603 100644 --- a/ports/espressif/boards/m5stack_atom_u/sdkconfig +++ b/ports/espressif/boards/m5stack_atom_u/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskAtomU" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atoms3/sdkconfig b/ports/espressif/boards/m5stack_atoms3/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/m5stack_atoms3/sdkconfig +++ b/ports/espressif/boards/m5stack_atoms3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atoms3_lite/sdkconfig b/ports/espressif/boards/m5stack_atoms3_lite/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/m5stack_atoms3_lite/sdkconfig +++ b/ports/espressif/boards/m5stack_atoms3_lite/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_atoms3u/sdkconfig b/ports/espressif/boards/m5stack_atoms3u/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/m5stack_atoms3u/sdkconfig +++ b/ports/espressif/boards/m5stack_atoms3u/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_cardputer/sdkconfig b/ports/espressif/boards/m5stack_cardputer/sdkconfig index d8c94423ebf8..e96286621603 100644 --- a/ports/espressif/boards/m5stack_cardputer/sdkconfig +++ b/ports/espressif/boards/m5stack_cardputer/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-cardputer" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_core2/sdkconfig b/ports/espressif/boards/m5stack_core2/sdkconfig index c8ac5f43acf9..116258b906bf 100644 --- a/ports/espressif/boards/m5stack_core2/sdkconfig +++ b/ports/espressif/boards/m5stack_core2/sdkconfig @@ -29,7 +29,6 @@ CONFIG_ESP_REV_MIN_FULL=300 # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskCore2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_core_basic/sdkconfig b/ports/espressif/boards/m5stack_core_basic/sdkconfig index 5b7ecf870975..116258b906bf 100644 --- a/ports/espressif/boards/m5stack_core_basic/sdkconfig +++ b/ports/espressif/boards/m5stack_core_basic/sdkconfig @@ -29,7 +29,6 @@ CONFIG_ESP_REV_MIN_FULL=300 # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskCoreBasic" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_core_fire/sdkconfig b/ports/espressif/boards/m5stack_core_fire/sdkconfig index 0e7b9709383c..116258b906bf 100644 --- a/ports/espressif/boards/m5stack_core_fire/sdkconfig +++ b/ports/espressif/boards/m5stack_core_fire/sdkconfig @@ -29,7 +29,6 @@ CONFIG_ESP_REV_MIN_FULL=300 # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskCoreFire" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_cores3/sdkconfig b/ports/espressif/boards/m5stack_cores3/sdkconfig index 3eecd2c242c7..7c3c05764ba7 100644 --- a/ports/espressif/boards/m5stack_cores3/sdkconfig +++ b/ports/espressif/boards/m5stack_cores3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-cores3" # end of LWIP # diff --git a/ports/espressif/boards/m5stack_dial/sdkconfig b/ports/espressif/boards/m5stack_dial/sdkconfig index 53b647b41b36..e96286621603 100644 --- a/ports/espressif/boards/m5stack_dial/sdkconfig +++ b/ports/espressif/boards/m5stack_dial/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-dial" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_m5paper/sdkconfig b/ports/espressif/boards/m5stack_m5paper/sdkconfig index fbf94f27494a..116258b906bf 100644 --- a/ports/espressif/boards/m5stack_m5paper/sdkconfig +++ b/ports/espressif/boards/m5stack_m5paper/sdkconfig @@ -29,7 +29,6 @@ CONFIG_ESP_REV_MIN_FULL=300 # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5Paper" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_stamp_c3/sdkconfig b/ports/espressif/boards/m5stack_stamp_c3/sdkconfig index 87330ec13bd6..e96286621603 100644 --- a/ports/espressif/boards/m5stack_stamp_c3/sdkconfig +++ b/ports/espressif/boards/m5stack_stamp_c3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="m5stack-stamp-c3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_stick_c/sdkconfig b/ports/espressif/boards/m5stack_stick_c/sdkconfig index 2e72fdb21633..e96286621603 100644 --- a/ports/espressif/boards/m5stack_stick_c/sdkconfig +++ b/ports/espressif/boards/m5stack_stick_c/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskStickC" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_stick_c_plus/sdkconfig b/ports/espressif/boards/m5stack_stick_c_plus/sdkconfig index 54f50db25c3c..e96286621603 100644 --- a/ports/espressif/boards/m5stack_stick_c_plus/sdkconfig +++ b/ports/espressif/boards/m5stack_stick_c_plus/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskStickCPlus" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/m5stack_timer_camera_x/sdkconfig b/ports/espressif/boards/m5stack_timer_camera_x/sdkconfig index a600e00b31aa..116258b906bf 100644 --- a/ports/espressif/boards/m5stack_timer_camera_x/sdkconfig +++ b/ports/espressif/boards/m5stack_timer_camera_x/sdkconfig @@ -29,7 +29,6 @@ CONFIG_ESP_REV_MIN_FULL=300 # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="M5StackTimerX" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig index 9d7d5d7eca07..122e6f902469 100644 --- a/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig +++ b/ports/espressif/boards/magiclick_s3_n4r2/sdkconfig @@ -8,7 +8,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="MagiClick-ESP32S3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/maker_badge/sdkconfig b/ports/espressif/boards/maker_badge/sdkconfig index d62227df74f4..e96286621603 100644 --- a/ports/espressif/boards/maker_badge/sdkconfig +++ b/ports/espressif/boards/maker_badge/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="Maker_badge" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/makerfabs_tft7/sdkconfig b/ports/espressif/boards/makerfabs_tft7/sdkconfig index 53896532db88..e96286621603 100644 --- a/ports/espressif/boards/makerfabs_tft7/sdkconfig +++ b/ports/espressif/boards/makerfabs_tft7/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="matouch-tft" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/makergo_esp32c3_supermini/sdkconfig b/ports/espressif/boards/makergo_esp32c3_supermini/sdkconfig index dc7f10a362f9..e96286621603 100644 --- a/ports/espressif/boards/makergo_esp32c3_supermini/sdkconfig +++ b/ports/espressif/boards/makergo_esp32c3_supermini/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="makergo-esp32c3-supermini" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/microdev_micro_c3/sdkconfig b/ports/espressif/boards/microdev_micro_c3/sdkconfig index 9b13279bd385..e96286621603 100644 --- a/ports/espressif/boards/microdev_micro_c3/sdkconfig +++ b/ports/espressif/boards/microdev_micro_c3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="MicroDev-microC3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/microdev_micro_s2/sdkconfig b/ports/espressif/boards/microdev_micro_s2/sdkconfig index f6158eac3ecc..e96286621603 100644 --- a/ports/espressif/boards/microdev_micro_s2/sdkconfig +++ b/ports/espressif/boards/microdev_micro_s2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="MicroDev-microS2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/morpheans_morphesp-240/sdkconfig b/ports/espressif/boards/morpheans_morphesp-240/sdkconfig index b0a838eacc8b..e96286621603 100644 --- a/ports/espressif/boards/morpheans_morphesp-240/sdkconfig +++ b/ports/espressif/boards/morpheans_morphesp-240/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="MORPHESP-240" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/nodemcu_esp32c2/sdkconfig b/ports/espressif/boards/nodemcu_esp32c2/sdkconfig index ed7abbdd59b0..f53dd7f8795b 100644 --- a/ports/espressif/boards/nodemcu_esp32c2/sdkconfig +++ b/ports/espressif/boards/nodemcu_esp32c2/sdkconfig @@ -32,7 +32,6 @@ CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200 # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="nodemcu-esp32c2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/odt_pixelwing_esp32_s2/sdkconfig b/ports/espressif/boards/odt_pixelwing_esp32_s2/sdkconfig index 3017a9532f61..e96286621603 100644 --- a/ports/espressif/boards/odt_pixelwing_esp32_s2/sdkconfig +++ b/ports/espressif/boards/odt_pixelwing_esp32_s2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="PixelWing-ESP32S2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig b/ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig index 25ff4f97acf1..919f4d9f345f 100644 --- a/ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig +++ b/ports/espressif/boards/seeed_xiao_esp32_s3_sense/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # Camera configuration # diff --git a/ports/espressif/boards/seeed_xiao_esp32c3/sdkconfig b/ports/espressif/boards/seeed_xiao_esp32c3/sdkconfig index a593f1d17368..e96286621603 100644 --- a/ports/espressif/boards/seeed_xiao_esp32c3/sdkconfig +++ b/ports/espressif/boards/seeed_xiao_esp32c3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="seeed-xiao-esp32c3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/seeed_xiao_esp32c6/sdkconfig b/ports/espressif/boards/seeed_xiao_esp32c6/sdkconfig index a69b0b6c770b..e96286621603 100644 --- a/ports/espressif/boards/seeed_xiao_esp32c6/sdkconfig +++ b/ports/espressif/boards/seeed_xiao_esp32c6/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="seeed-xiao-esp32c6" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/sensebox_mcu_esp32s2/sdkconfig b/ports/espressif/boards/sensebox_mcu_esp32s2/sdkconfig index d8608c527c06..e96286621603 100644 --- a/ports/espressif/boards/sensebox_mcu_esp32s2/sdkconfig +++ b/ports/espressif/boards/sensebox_mcu_esp32s2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="senseBox MCU-S2 ESP32S2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig b/ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig index 12ba241a99b2..e96286621603 100644 --- a/ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig +++ b/ports/espressif/boards/smartbeedesigns_bee_data_logger/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_data_logger" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig index 0d9061f59528..e96286621603 100644 --- a/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig +++ b/ports/espressif/boards/smartbeedesigns_bee_motion_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_motion_s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig b/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig index 8254944f07dd..e96286621603 100644 --- a/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig +++ b/ports/espressif/boards/smartbeedesigns_bee_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="smartbeedesigns_bee_s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/spotpear_esp32c3_lcd_1_44/sdkconfig b/ports/espressif/boards/spotpear_esp32c3_lcd_1_44/sdkconfig index f3f2d53d3b86..e96286621603 100644 --- a/ports/espressif/boards/spotpear_esp32c3_lcd_1_44/sdkconfig +++ b/ports/espressif/boards/spotpear_esp32c3_lcd_1_44/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="spotpear-esp32c3-lcd-1-44" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/sqfmi_watchy/sdkconfig b/ports/espressif/boards/sqfmi_watchy/sdkconfig index 0eb5e8d4cb13..7d6572eeeee7 100644 --- a/ports/espressif/boards/sqfmi_watchy/sdkconfig +++ b/ports/espressif/boards/sqfmi_watchy/sdkconfig @@ -1,5 +1,4 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="Watchy" # end of LWIP diff --git a/ports/espressif/boards/sunton_esp32_2424S012/sdkconfig b/ports/espressif/boards/sunton_esp32_2424S012/sdkconfig index 5b7c8255a976..e96286621603 100644 --- a/ports/espressif/boards/sunton_esp32_2424S012/sdkconfig +++ b/ports/espressif/boards/sunton_esp32_2424S012/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="sunton-esp32-2424S012" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/sunton_esp32_8048S070/sdkconfig b/ports/espressif/boards/sunton_esp32_8048S070/sdkconfig index 47527b994439..e96286621603 100644 --- a/ports/espressif/boards/sunton_esp32_8048S070/sdkconfig +++ b/ports/espressif/boards/sunton_esp32_8048S070/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="sunton-esp32-8048S070" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig b/ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig +++ b/ports/espressif/boards/thingpulse_pendrive_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_bling/sdkconfig b/ports/espressif/boards/unexpectedmaker_bling/sdkconfig index cf61f58eeb7e..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_bling/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_bling/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMBling" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig b/ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig index 368367dd5058..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_blizzard_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMBlizzardS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_feathers2/sdkconfig b/ports/espressif/boards/unexpectedmaker_feathers2/sdkconfig index a1e5e03b7692..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers2/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_feathers2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_feathers2_neo/sdkconfig b/ports/espressif/boards/unexpectedmaker_feathers2_neo/sdkconfig index cc781c9a3dda..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers2_neo/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_feathers2_neo/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS2Neo" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_feathers2_prerelease/sdkconfig b/ports/espressif/boards/unexpectedmaker_feathers2_prerelease/sdkconfig index a1e5e03b7692..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers2_prerelease/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_feathers2_prerelease/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig b/ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig index 9b9b72aa0646..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_feathers3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig b/ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig index 024f68428c05..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_feathers3_neo/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS3 Neo" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig b/ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig index e8e8fb5f419f..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_nanos3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMNanoS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig b/ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig index 681b8f2a7424..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_omgs3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMOMGS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_pros3/sdkconfig b/ports/espressif/boards/unexpectedmaker_pros3/sdkconfig index a2869b8f4ef7..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_pros3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_pros3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMProS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig b/ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig index 7dc9d93078a1..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_rgbtouch_mini/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMRGBT" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_tinyc6/sdkconfig b/ports/espressif/boards/unexpectedmaker_tinyc6/sdkconfig index c989bb78dc71..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_tinyc6/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_tinyc6/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyC6" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_tinys2/sdkconfig b/ports/espressif/boards/unexpectedmaker_tinys2/sdkconfig index 647e33d8f5a9..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_tinys2/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_tinys2/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS2" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig b/ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig index 92f790fb8e70..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_tinys3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig b/ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig index b7aacb06ad4c..e96286621603 100644 --- a/ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig +++ b/ports/espressif/boards/unexpectedmaker_tinywatch_s3/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyWATCHS3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/vidi_x/sdkconfig b/ports/espressif/boards/vidi_x/sdkconfig index bdd999b4fc91..e96286621603 100644 --- a/ports/espressif/boards/vidi_x/sdkconfig +++ b/ports/espressif/boards/vidi_x/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="vidi-x" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/sdkconfig b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/sdkconfig index 7c86f9f8e37a..e96286621603 100644 --- a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="waveshare" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_geek/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig index c54343d3f05f..e96286621603 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_lcd_1_28/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="waveshare-esp32-s3-lcd-1-28" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_pico/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig index 23cc49e8d47a..3d0800e10d9a 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_tiny/sdkconfig @@ -8,7 +8,6 @@ # LWIP # # CONFIG_LWIP_IPV6 is not set -# CONFIG_LWIP_LOCAL_HOSTNAME="waveshare-esp32-s3-tiny" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig b/ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig index 664ece4170f9..e96286621603 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_s3_zero/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="ESP32-S3-Zero" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/waveshare_esp32s2_pico/sdkconfig b/ports/espressif/boards/waveshare_esp32s2_pico/sdkconfig index 7c86f9f8e37a..e96286621603 100644 --- a/ports/espressif/boards/waveshare_esp32s2_pico/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32s2_pico/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="waveshare" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/weact_esp32c6_n4/sdkconfig b/ports/espressif/boards/weact_esp32c6_n4/sdkconfig index 63084f9368da..e96286621603 100644 --- a/ports/espressif/boards/weact_esp32c6_n4/sdkconfig +++ b/ports/espressif/boards/weact_esp32c6_n4/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="WEACT-ESP32-C6" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/weact_esp32c6_n8/sdkconfig b/ports/espressif/boards/weact_esp32c6_n8/sdkconfig index 63084f9368da..e96286621603 100644 --- a/ports/espressif/boards/weact_esp32c6_n8/sdkconfig +++ b/ports/espressif/boards/weact_esp32c6_n8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="WEACT-ESP32-C6" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/wemos_lolin32_lite/sdkconfig b/ports/espressif/boards/wemos_lolin32_lite/sdkconfig index 72be49f97e8c..e96286621603 100644 --- a/ports/espressif/boards/wemos_lolin32_lite/sdkconfig +++ b/ports/espressif/boards/wemos_lolin32_lite/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN32Lite" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig b/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig +++ b/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config diff --git a/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig b/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig index 9fdc70b59aa9..e96286621603 100644 --- a/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig +++ b/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -# CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" # end of LWIP # end of Component config From 98b360a436daec7af3c40951f224fa4cb6c29a36 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Tue, 24 Sep 2024 21:25:43 -0500 Subject: [PATCH 026/252] Double buffering --- shared-module/audiodelays/Echo.c | 27 ++++++++++++++++++--------- shared-module/audiodelays/Echo.h | 5 +++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 7caa6c79f84e..159a9fcffd9e 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -21,12 +21,19 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ self->sample_rate = sample_rate; self->buffer_len = buffer_size; - self->buffer = m_malloc(self->buffer_len); - if (self->buffer == NULL) { + self->buffer[0] = m_malloc(self->buffer_len); + if (self->buffer[0] == NULL) { common_hal_audiodelays_echo_deinit(self); m_malloc_fail(self->buffer_len); } - memset(self->buffer, 0, self->buffer_len); + memset(self->buffer[0], 0, self->buffer_len); + self->buffer[1] = m_malloc(self->buffer_len); + if (self->buffer[1] == NULL) { + common_hal_audiodelays_echo_deinit(self); + m_malloc_fail(self->buffer_len); + } + memset(self->buffer[1], 0, self->buffer_len); + self->last_buf_idx = 1; if (decay == MP_OBJ_NULL) { decay = mp_obj_new_float(0.7); @@ -81,7 +88,8 @@ void common_hal_audiodelays_echo_deinit(audiodelays_echo_obj_t *self) { return; } self->echo_buffer = NULL; - self->buffer = NULL; + self->buffer[0] = NULL; + self->buffer[1] = NULL; } @@ -99,9 +107,9 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_o if (self->echo_buffer_read_pos > max_ebuf_length) { self->echo_buffer_read_pos = 0; - self->echo_buffer_write_pos = max_ebuf_length - (self->buffer_len / sizeof(uint32_t)); + self->echo_buffer_write_pos = max_ebuf_length - (self->buffer_len / sizeof(uint16_t)); } else if (self->echo_buffer_write_pos > max_ebuf_length) { - self->echo_buffer_read_pos = self->buffer_len / sizeof(uint32_t); + self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); self->echo_buffer_write_pos = 0; } } @@ -211,7 +219,8 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * mp_float_t mix = MIN(1.0, MAX(synthio_block_slot_get(&self->mix), 0.0)); mp_float_t decay = MIN(1.0, MAX(synthio_block_slot_get(&self->decay), 0.0)); - int16_t *word_buffer = (int16_t *)self->buffer; + self->last_buf_idx = !self->last_buf_idx; + int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx]; uint32_t length = self->buffer_len / sizeof(uint16_t); int16_t *echo_buffer = (int16_t *)self->echo_buffer; uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint16_t); @@ -338,7 +347,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } - *buffer = (uint8_t *)self->buffer; + *buffer = (uint8_t *)self->buffer[self->last_buf_idx]; *buffer_length = self->buffer_len; return GET_BUFFER_MORE_DATA; } @@ -346,7 +355,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * void audiodelays_echo_get_buffer_structure(audiodelays_echo_obj_t *self, bool single_channel_output, bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing) { - *single_buffer = true; + *single_buffer = false; *samples_signed = true; *max_buffer_length = self->buffer_len; if (single_channel_output) { diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index aafb40f182e2..b538716c45fd 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -24,7 +24,8 @@ typedef struct { uint8_t channel_count; uint32_t sample_rate; - uint32_t *buffer; + int8_t *buffer[2]; + uint8_t last_buf_idx; uint32_t buffer_len; // max buffer in bytes uint32_t *sample_remaining_buffer; @@ -33,7 +34,7 @@ typedef struct { bool loop; bool more_data; - uint32_t *echo_buffer; + int8_t *echo_buffer; uint32_t echo_buffer_len; // bytes uint32_t max_echo_buffer_len; // bytes From 0608932e630f646602e7f90d5e8a65a53cfcad3a Mon Sep 17 00:00:00 2001 From: sam blenny <68084116+samblenny@users.noreply.github.com> Date: Thu, 26 Sep 2024 17:59:59 +0000 Subject: [PATCH 027/252] update tinyusb to v0.17.0 (5217cee5) --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index 4349e99fb29d..5217cee5de4c 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 4349e99fb29dbc7d019aa2fbb6344864799d8c1b +Subproject commit 5217cee5de4cd555018da90f9f1bcc87fb1c1d3a From 50b2e40a543992c1a13cb5e8a32cb80204776117 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 26 Sep 2024 17:41:08 -0400 Subject: [PATCH 028/252] ports/espressif/common-hal/espcamera/Camera.c: check for unspecified pins --- .../boards/adafruit_esp32s3_camera/board.c | 1 - .../boards/seeed_xiao_esp32_s3_sense/board.c | 4 ---- ports/espressif/common-hal/espcamera/Camera.c | 21 ++++++++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ports/espressif/boards/adafruit_esp32s3_camera/board.c b/ports/espressif/boards/adafruit_esp32s3_camera/board.c index 027b7ca8b6e4..e0c357f04c80 100644 --- a/ports/espressif/boards/adafruit_esp32s3_camera/board.c +++ b/ports/espressif/boards/adafruit_esp32s3_camera/board.c @@ -16,7 +16,6 @@ #include "esp_log.h" #include "esp_err.h" -#include "driver/i2c.h" #define DELAY 0x80 diff --git a/ports/espressif/boards/seeed_xiao_esp32_s3_sense/board.c b/ports/espressif/boards/seeed_xiao_esp32_s3_sense/board.c index 6cc4f2e089ec..fea7fe2c3002 100644 --- a/ports/espressif/boards/seeed_xiao_esp32_s3_sense/board.c +++ b/ports/espressif/boards/seeed_xiao_esp32_s3_sense/board.c @@ -4,10 +4,6 @@ // // SPDX-License-Identifier: MIT -#include "supervisor/board.h" #include "mpconfigboard.h" -#include "esp_log.h" -#include "esp_err.h" -#include "driver/i2c.h" // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/common-hal/espcamera/Camera.c b/ports/espressif/common-hal/espcamera/Camera.c index 22285166e56e..a40b1eec6b6d 100644 --- a/ports/espressif/common-hal/espcamera/Camera.c +++ b/ports/espressif/common-hal/espcamera/Camera.c @@ -26,7 +26,12 @@ #ifndef CONFIG_PM_ENABLE #define CONFIG_PM_ENABLE 0 #endif -#include "esp-idf/components/driver/i2c/i2c_private.h" + +// i2c_private.h uses `#if` with some macros that may be undefined and taken as 0. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wundef" +#include "esp-idf/components/esp_driver_i2c/i2c_private.h" +#pragma GCC diagnostic pop #include "esp-camera/driver/private_include/cam_hal.h" @@ -90,13 +95,12 @@ void common_hal_espcamera_camera_construct( self->i2c = i2c; - self->camera_config.pin_pwdn = common_hal_mcu_pin_number(powerdown_pin); - self->camera_config.pin_reset = common_hal_mcu_pin_number(reset_pin); - self->camera_config.pin_xclk = common_hal_mcu_pin_number(external_clock_pin); + // These pins might be NULL because they were not specified. + self->camera_config.pin_pwdn = powerdown_pin ? common_hal_mcu_pin_number(powerdown_pin) : NO_PIN; + self->camera_config.pin_reset = reset_pin ? common_hal_mcu_pin_number(reset_pin) : NO_PIN; + self->camera_config.pin_xclk = external_clock_pin ? common_hal_mcu_pin_number(external_clock_pin) : NO_PIN; - self->camera_config.pin_sccb_sda = NO_PIN; - self->camera_config.pin_sccb_scl = NO_PIN; - /* sccb i2c port set below */ + self->camera_config.sccb_i2c_master_bus_handle = self->i2c->handle; self->camera_config.pin_d7 = data_pins[7]; self->camera_config.pin_d6 = data_pins[6]; @@ -119,7 +123,7 @@ void common_hal_espcamera_camera_construct( self->camera_config.fb_count = framebuffer_count; self->camera_config.grab_mode = grab_mode; - self->camera_config.sccb_i2c_port = self->i2c->handle->base->port_num; + i2c_lock(self); esp_err_t result = esp_camera_init(&self->camera_config); @@ -135,6 +139,7 @@ extern void common_hal_espcamera_camera_deinit(espcamera_camera_obj_t *self) { common_hal_pwmio_pwmout_deinit(&self->pwm); + // Does nothing if pin is NO_PIN (-1). reset_pin_number(self->camera_config.pin_pwdn); reset_pin_number(self->camera_config.pin_reset); reset_pin_number(self->camera_config.pin_xclk); From 7b1719783f7b1518d0dd1c8d032a6a0f948b1e70 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 26 Sep 2024 17:41:44 -0400 Subject: [PATCH 029/252] turn CIRCUITPY_ESPCAMERA back on --- ports/espressif/mpconfigport.mk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index c8f0a661cae0..0d98f7bdab6b 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -37,8 +37,7 @@ CIRCUITPY_BLEIO ?= 1 CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_CANIO ?= 1 CIRCUITPY_COUNTIO ?= 1 -############ TEMPORARY while working on new I2C driver -CIRCUITPY_ESPCAMERA ?= 0 +CIRCUITPY_ESPCAMERA ?= 1 CIRCUITPY_ESPIDF ?= 1 CIRCUITPY_ESPULP ?= 1 CIRCUITPY_FRAMEBUFFERIO ?= 1 From 74b5870dc03988dcd4b58bed90e25b5457e09af7 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 08:22:33 -0700 Subject: [PATCH 030/252] Moved GPIO ports to board.c to make it easy to add boards in the future. Added priority to remaining TODOs (low) --- ports/analog/boards/apard32690/board.c | 3 +++ ports/analog/boards/max32690evkit/board.c | 3 +++ ports/analog/common-hal/microcontroller/Pin.c | 8 ++------ ports/analog/common-hal/os/__init__.c | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ports/analog/boards/apard32690/board.c b/ports/analog/boards/apard32690/board.c index c24ff5a08e83..c8751aa37e79 100644 --- a/ports/analog/boards/apard32690/board.c +++ b/ports/analog/boards/apard32690/board.c @@ -10,6 +10,9 @@ #include "max32_port.h" // Board-level setup for MAX32690 +mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = + {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; + // clang-format off const mxc_gpio_cfg_t pb_pin[] = { { MXC_GPIO1, MXC_GPIO_PIN_27, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, diff --git a/ports/analog/boards/max32690evkit/board.c b/ports/analog/boards/max32690evkit/board.c index 9a0c8278641f..924eaeafef0e 100644 --- a/ports/analog/boards/max32690evkit/board.c +++ b/ports/analog/boards/max32690evkit/board.c @@ -10,6 +10,9 @@ #include "max32_port.h" // Board-level setup for MAX32690 +mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = + {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; + // clang-format off const mxc_gpio_cfg_t pb_pin[] = { { MXC_GPIO4, MXC_GPIO_PIN_0, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 22e3ce3899d9..29befaf5e5c0 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -16,12 +16,8 @@ static uint32_t claimed_pins[NUM_GPIO_PORTS]; -// todo (low): try moving this to an extern in the board support -#ifdef MAX32690 -#include "max32690.h" -mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = - {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; -#endif +// defined in board.c +extern mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS]; static uint32_t never_reset_pins[NUM_GPIO_PORTS]; diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c index 97ce98cb9e1e..04e561e61909 100644 --- a/ports/analog/common-hal/os/__init__.c +++ b/ports/analog/common-hal/os/__init__.c @@ -43,7 +43,7 @@ mp_obj_t common_hal_os_uname(void) { bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { #if (HAS_TRNG) - //todo: implement + //todo (low prior): implement #else #endif return false; From 10ddfe01c416a9d73678400fc8b0c8856e636cf6 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 08:51:06 -0700 Subject: [PATCH 031/252] Updated USB PID for max32690evkit --- locale/circuitpython.pot | 9 +++++---- ports/analog/boards/max32690evkit/mpconfigboard.mk | 2 +- tests/pyboard.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 25d4a2831228..106bca3d1f0b 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1179,6 +1179,7 @@ msgstr "" msgid "Interrupted by output function" msgstr "" +#: ports/espressif/common-hal/_bleio/Service.c #: ports/espressif/common-hal/espulp/ULP.c #: ports/espressif/common-hal/microcontroller/Processor.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c @@ -1303,6 +1304,7 @@ msgid "MAC address was invalid" msgstr "" #: ports/espressif/common-hal/_bleio/Characteristic.c +#: ports/espressif/common-hal/_bleio/Descriptor.c msgid "MITM security not supported" msgstr "" @@ -2238,14 +2240,12 @@ msgid "Update failed" msgstr "" #: ports/espressif/common-hal/_bleio/Characteristic.c -#: ports/espressif/common-hal/_bleio/Descriptor.c #: ports/nordic/common-hal/_bleio/Characteristic.c #: ports/nordic/common-hal/_bleio/Descriptor.c msgid "Value length != required fixed length" msgstr "" #: ports/espressif/common-hal/_bleio/Characteristic.c -#: ports/espressif/common-hal/_bleio/Descriptor.c #: ports/nordic/common-hal/_bleio/Characteristic.c #: ports/nordic/common-hal/_bleio/Descriptor.c msgid "Value length > max_length" @@ -3090,7 +3090,8 @@ msgstr "" msgid "function missing required positional argument #%d" msgstr "" -#: py/argcheck.c py/bc.c py/objnamedtuple.c shared-bindings/time/__init__.c +#: py/argcheck.c py/bc.c py/objnamedtuple.c shared-bindings/_eve/__init__.c +#: shared-bindings/time/__init__.c #, c-format msgid "function takes %d positional arguments but %d were given" msgstr "" @@ -3242,7 +3243,7 @@ msgstr "" msgid "input must be a dense ndarray" msgstr "" -#: extmod/ulab/code/user/user.c +#: extmod/ulab/code/user/user.c shared-bindings/_eve/__init__.c msgid "input must be an ndarray" msgstr "" diff --git a/ports/analog/boards/max32690evkit/mpconfigboard.mk b/ports/analog/boards/max32690evkit/mpconfigboard.mk index 4e6e766df5d2..61413216d817 100644 --- a/ports/analog/boards/max32690evkit/mpconfigboard.mk +++ b/ports/analog/boards/max32690evkit/mpconfigboard.mk @@ -16,7 +16,7 @@ INTERNAL_FLASH_FILESYSTEM=1 # Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim USB_VID=0x0456 # USB_VID=0x0B6A -USB_PID=0x003C +USB_PID=0x003D USB_MANUFACTURER="Analog Devices, Inc." USB_PRODUCT="MAX32690 EvKit" USB_HIGHSPEED=1 diff --git a/tests/pyboard.py b/tests/pyboard.py index 616773a313a1..582a1f894f8b 120000 --- a/tests/pyboard.py +++ b/tests/pyboard.py @@ -1 +1 @@ -../tools/cpboard.py \ No newline at end of file +../tools/cpboard.py From 85305210ee52f9bff3b655e2f2e605c7b8e0c510 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 09:06:33 -0700 Subject: [PATCH 032/252] Formatting fixes missed by local pre-commit runner --- ports/analog/background.c | 5 +- ports/analog/boards/apard32690/board.c | 12 ++-- ports/analog/boards/apard32690/pins.c | 10 +-- ports/analog/boards/max32690evkit/board.c | 8 +-- .../common-hal/digitalio/DigitalInOut.c | 62 ++++++++----------- ports/analog/common-hal/microcontroller/Pin.c | 6 +- .../common-hal/microcontroller/Processor.c | 2 +- ports/analog/common-hal/os/__init__.c | 4 +- ports/analog/supervisor/serial.c | 6 +- ports/analog/supervisor/usb.c | 3 +- 10 files changed, 53 insertions(+), 65 deletions(-) diff --git a/ports/analog/background.c b/ports/analog/background.c index ad3063b7feb9..ffad007ffa51 100644 --- a/ports/analog/background.c +++ b/ports/analog/background.c @@ -19,7 +19,7 @@ extern const mxc_gpio_cfg_t led_pin[]; extern const int num_leds; /** NOTE: ALL "ticks" refer to a 1/1024 s period */ -static int status_led_ticks=0; +static int status_led_ticks = 0; // This function is where port-specific background // tasks should be performed @@ -28,8 +28,7 @@ void port_background_tick(void) { status_led_ticks++; // Set an LED approx. 1/s - if (status_led_ticks > 1024) - { + if (status_led_ticks > 1024) { MXC_GPIO_OutToggle(led_pin[2].port, led_pin[2].mask); status_led_ticks = 0; } diff --git a/ports/analog/boards/apard32690/board.c b/ports/analog/boards/apard32690/board.c index c8751aa37e79..3cc10de29f1e 100644 --- a/ports/analog/boards/apard32690/board.c +++ b/ports/analog/boards/apard32690/board.c @@ -10,8 +10,8 @@ #include "max32_port.h" // Board-level setup for MAX32690 -mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = - {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; +mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS] = +{MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; // clang-format off const mxc_gpio_cfg_t pb_pin[] = { @@ -38,20 +38,20 @@ const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); volatile uint32_t system_ticks = 0; void SysTick_Handler(void) { - system_ticks++; + system_ticks++; } uint32_t board_millis(void) { - return system_ticks; + return system_ticks; } // Initializes board related state once on start up. void board_init(void) { // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000);\ + SysTick_Config(SystemCoreClock / 1000); \ // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { MXC_GPIO_Init(0x1 << i); } diff --git a/ports/analog/boards/apard32690/pins.c b/ports/analog/boards/apard32690/pins.c index 5b736385dc58..0486687d3347 100644 --- a/ports/analog/boards/apard32690/pins.c +++ b/ports/analog/boards/apard32690/pins.c @@ -9,7 +9,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - //P0 + // P0 { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, @@ -42,7 +42,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) }, { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, - //P1 + // P1 { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, @@ -75,7 +75,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, - //P2 + // P2 { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, @@ -108,7 +108,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P2_29), MP_ROM_PTR(&pin_P2_29) }, { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, - //P3 + // P3 { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, @@ -119,7 +119,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, - //P4 + // P4 { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, }; diff --git a/ports/analog/boards/max32690evkit/board.c b/ports/analog/boards/max32690evkit/board.c index 924eaeafef0e..76da5c0adccb 100644 --- a/ports/analog/boards/max32690evkit/board.c +++ b/ports/analog/boards/max32690evkit/board.c @@ -10,8 +10,8 @@ #include "max32_port.h" // Board-level setup for MAX32690 -mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = - {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; +mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS] = +{MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; // clang-format off const mxc_gpio_cfg_t pb_pin[] = { @@ -47,10 +47,10 @@ uint32_t board_millis(void) { // Initializes board related state once on start up. void board_init(void) { // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000);\ + SysTick_Config(SystemCoreClock / 1000); \ // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { MXC_GPIO_Init(0x1 << i); } diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index d23c90fdbc36..166021b44128 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -10,7 +10,7 @@ #include "gpio_reva.h" -extern mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS]; +extern mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS]; void common_hal_digitalio_digitalinout_never_reset( digitalio_digitalinout_obj_t *self) { @@ -50,9 +50,8 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( - digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) -{ - mxc_gpio_regs_t* port = gpio_ports[self->pin->port]; + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); @@ -61,9 +60,8 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( digitalio_digitalinout_obj_t *self, bool value, - digitalio_drive_mode_t drive_mode) -{ - mxc_gpio_regs_t* port = gpio_ports[self->pin->port]; + digitalio_drive_mode_t drive_mode) { + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); @@ -85,24 +83,21 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( uint32_t mask = self->pin->mask; // Check that I/O mode is enabled and we don't have in AND out on at the same time - MP_STATIC_ASSERT(!( (port->en0 & mask) && (port->inen & mask) && (port->outen & mask) )); + MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask))); - if ( (port->en0 & mask) && (port->outen & mask) ) - { + if ((port->en0 & mask) && (port->outen & mask)) { return DIRECTION_OUTPUT; - } - else if ( (port->en0 & mask) && (port->inen & mask) ) - { + } else if ((port->en0 & mask) && (port->inen & mask)) { return DIRECTION_INPUT; } - // do not try to drive a pin which has an odd configuration here - else return DIRECTION_INPUT; + else { + return DIRECTION_INPUT; + } } void common_hal_digitalio_digitalinout_set_value( - digitalio_digitalinout_obj_t *self, bool value) -{ + digitalio_digitalinout_obj_t *self, bool value) { digitalio_direction_t dir = common_hal_digitalio_digitalinout_get_direction(self); @@ -112,15 +107,13 @@ void common_hal_digitalio_digitalinout_set_value( if (dir == DIRECTION_OUTPUT) { if (value == true) { MXC_GPIO_OutSet(port, mask); - } - else { + } else { MXC_GPIO_OutClr(port, mask); } } } -bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self) -{ +bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self) { digitalio_direction_t dir = common_hal_digitalio_digitalinout_get_direction(self); @@ -128,10 +121,9 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s uint32_t mask = self->pin->mask; if (dir == DIRECTION_INPUT) { - return (MXC_GPIO_InGet(port, mask)); - } - else { - return ( (port->out & mask) == true); + return MXC_GPIO_InGet(port, mask); + } else { + return (port->out & mask) == true; } } @@ -154,7 +146,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - if ( (port->en0 & mask) && (port->inen & mask) ) { + if ((port->en0 & mask) && (port->inen & mask)) { // PULL_NONE, PULL_UP, or PULL_DOWN switch (pull) { case PULL_NONE: @@ -162,7 +154,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( port->padctrl1 &= ~(mask); break; case PULL_UP: - port->padctrl0 |= mask; + port->padctrl0 |= mask; port->padctrl1 &= ~(mask); break; case PULL_DOWN: @@ -173,8 +165,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( break; } return DIGITALINOUT_OK; - } - else { + } else { return DIGITALINOUT_PIN_BUSY; } } @@ -182,19 +173,16 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( digitalio_digitalinout_obj_t *self) { - bool pin_padctrl0 = (gpio_ports[self->pin->port]->padctrl0) & ( self->pin->mask); - bool pin_padctrl1 = (gpio_ports[self->pin->port]->padctrl1) & ( self->pin->mask); + bool pin_padctrl0 = (gpio_ports[self->pin->port]->padctrl0) & (self->pin->mask); + bool pin_padctrl1 = (gpio_ports[self->pin->port]->padctrl1) & (self->pin->mask); - if ( (pin_padctrl0) && !(pin_padctrl1) ) { + if ((pin_padctrl0) && !(pin_padctrl1)) { return PULL_UP; - } - else if ( !(pin_padctrl0) && pin_padctrl1 ) { + } else if (!(pin_padctrl0) && pin_padctrl1) { return PULL_DOWN; - } - else if ( !(pin_padctrl0) && !(pin_padctrl1) ) { + } else if (!(pin_padctrl0) && !(pin_padctrl1)) { return PULL_NONE; } - // Shouldn't happen, (value 0b11 is reserved) else { return PULL_NONE; diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 29befaf5e5c0..4545aa039c2f 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -17,7 +17,7 @@ static uint32_t claimed_pins[NUM_GPIO_PORTS]; // defined in board.c -extern mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS]; +extern mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS]; static uint32_t never_reset_pins[NUM_GPIO_PORTS]; @@ -31,8 +31,8 @@ void reset_all_pins(void) { reset_pin_number(i, j); } } - // set claimed pins to never_reset pins - claimed_pins[i] = never_reset_pins[i]; + // set claimed pins to never_reset pins + claimed_pins[i] = never_reset_pins[i]; } } diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c index e28388e58596..87d8047ff2cb 100644 --- a/ports/analog/common-hal/microcontroller/Processor.c +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -40,7 +40,7 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { #if CIRCUITPY_ALARM - // TODO: (low prior.) add reset reason in alarm / deepsleep cases (should require alarm peripheral API in "peripherals") + // TODO: (low prior.) add reset reason in alarm / deepsleep cases (should require alarm peripheral API in "peripherals") #endif return RESET_REASON_UNKNOWN; } diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c index 04e561e61909..1f89300c4c18 100644 --- a/ports/analog/common-hal/os/__init__.c +++ b/ports/analog/common-hal/os/__init__.c @@ -43,8 +43,8 @@ mp_obj_t common_hal_os_uname(void) { bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { #if (HAS_TRNG) - //todo (low prior): implement + // todo (low prior): implement #else #endif - return false; + return false; } diff --git a/ports/analog/supervisor/serial.c b/ports/analog/supervisor/serial.c index 871e6cd0fe72..536355e38f60 100644 --- a/ports/analog/supervisor/serial.c +++ b/ports/analog/supervisor/serial.c @@ -26,7 +26,9 @@ void port_serial_init(void) { #if MAX32_SERIAL MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_IBRO_EN; - while( !(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_IBRO_RDY) ); + while (!(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_IBRO_RDY)) { + ; + } MXC_UART_Init(CONSOLE_UART, 115200, MXC_UART_IBRO_CLK); #endif } @@ -76,7 +78,7 @@ void port_serial_write_substring(const char *text, uint32_t len) { .rxData = NULL, .txLen = len, .rxLen = 0 - }; + }; MXC_UART_Transaction(&uart_req); #endif } diff --git a/ports/analog/supervisor/usb.c b/ports/analog/supervisor/usb.c index f156669ad386..1624359ab51f 100644 --- a/ports/analog/supervisor/usb.c +++ b/ports/analog/supervisor/usb.c @@ -36,8 +36,7 @@ void init_usb_hardware(void) { // Interrupt enables are left to TUSB depending on the device class } -void USB_IRQHandler(void) -{ +void USB_IRQHandler(void) { // Schedules USB background callback // appropriate to a given device class via TinyUSB lib usb_irq_handler(0); From bdc77c5f7489d97adbe444059d28d512c845b813 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 09:15:49 -0700 Subject: [PATCH 033/252] Add "analog" to shared_bindings_matrix.py --- docs/shared_bindings_matrix.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index 33dfad01e986..2ddc43912aeb 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -31,6 +31,7 @@ from concurrent.futures import ThreadPoolExecutor SUPPORTED_PORTS = [ + "analog", "atmel-samd", "broadcom", "cxd56", From 3a73b18eabdbdcd25f751306bb7156d966b7e6db Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 09:33:29 -0700 Subject: [PATCH 034/252] More pre-commit fixes. --- ports/analog/peripherals/pins.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/analog/peripherals/pins.h b/ports/analog/peripherals/pins.h index efee60a2962a..3bd7d02bf46d 100644 --- a/ports/analog/peripherals/pins.h +++ b/ports/analog/peripherals/pins.h @@ -26,7 +26,7 @@ typedef struct { extern const mp_obj_type_t mcu_pin_type; -#define PIN(pin_port, pin_mask) { {&mcu_pin_type}, .port = pin_port, .mask = 1UL< Date: Fri, 27 Sep 2024 09:46:38 -0700 Subject: [PATCH 035/252] Manual pre-commit fix for all requisite files. --- ports/analog/boards/max32690evkit/pins.c | 10 +++--- ports/analog/max32_port.h | 2 +- ports/analog/supervisor/internal_flash.c | 21 ++++++------ ports/analog/supervisor/port.c | 43 +++++++++++++++--------- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ports/analog/boards/max32690evkit/pins.c b/ports/analog/boards/max32690evkit/pins.c index 5b736385dc58..0486687d3347 100644 --- a/ports/analog/boards/max32690evkit/pins.c +++ b/ports/analog/boards/max32690evkit/pins.c @@ -9,7 +9,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - //P0 + // P0 { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, @@ -42,7 +42,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) }, { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, - //P1 + // P1 { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, @@ -75,7 +75,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, - //P2 + // P2 { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, @@ -108,7 +108,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P2_29), MP_ROM_PTR(&pin_P2_29) }, { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, - //P3 + // P3 { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, @@ -119,7 +119,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, - //P4 + // P4 { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, }; diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index 0ded32e5b820..fe6d5e157fea 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -42,4 +42,4 @@ extern uint32_t SystemCoreClock; #define SUBSEC_PER_TICK 4 #endif -#endif //MAX32_PORT_H +#endif // MAX32_PORT_H diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c index 57dd7d8b45d4..8518b235566c 100644 --- a/ports/analog/supervisor/internal_flash.c +++ b/ports/analog/supervisor/internal_flash.c @@ -75,8 +75,9 @@ static uint32_t page_buffer[FLASH_PAGE_SIZE / 4] = {0x0}; static inline int32_t block2addr(uint32_t block) { if (block >= 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; + } else { + return -1; } - else return -1; } // Get index, start addr, & size of the flash sector where addr lies @@ -91,15 +92,13 @@ int flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { } if (start_addr) { *start_addr = flash_layout[0].base_addr + (sector_index * flash_layout[0].sector_size); - } - else { + } else { return -1; // start_addr is NULL } if (size) { *size = flash_layout[0].sector_size; - } - else { - return -1; //size is NULL + } else { + return -1; // size is NULL } return sector_index; } @@ -176,7 +175,7 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking * than memcpy does. Will use it for now. */ - MXC_FLC_Read( src_addr, dest, FILESYSTEM_BLOCK_SIZE * num_blocks ); + MXC_FLC_Read(src_addr, dest, FILESYSTEM_BLOCK_SIZE * num_blocks); return 0; // success } @@ -205,12 +204,12 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, MXC_ICC_Disable(MXC_ICC0); // Buffer the page of flash to erase - MXC_FLC_Read(page_start , page_buffer, page_size); + MXC_FLC_Read(page_start, page_buffer, page_size); // Erase flash page MXC_CRITICAL( error = MXC_FLC_PageErase(dest_addr); - ); + ); if (error != E_NO_ERROR) { // lock flash & reset MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; @@ -220,12 +219,12 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, // Copy new src data into the page buffer // fill the new data in at the offset dest_addr - page_start // account for uint32_t page_buffer vs uint8_t src - memcpy( (page_buffer + (dest_addr - page_start) / 4), src, count * FILESYSTEM_BLOCK_SIZE); + memcpy((page_buffer + (dest_addr - page_start) / 4), src, count * FILESYSTEM_BLOCK_SIZE); // Write new page buffer back into flash MXC_CRITICAL( error = MXC_FLC_Write(page_start, page_size, page_buffer); - ); + ); if (error != E_NO_ERROR) { // lock flash & reset MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index af929e074e8f..065ac3b3c437 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -46,8 +46,8 @@ // msec to RTC subsec ticks (4 kHz) #define MSEC_TO_SS_ALARM(x) \ - (0 - ((x * 4096) / \ - 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */ + (0 - ((x * 4096) / \ + 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */ // Externs defined by linker .ld file extern uint32_t _stack, _heap, _estack, _eheap; @@ -70,7 +70,7 @@ safe_mode_t port_init(void) { int err = E_NO_ERROR; // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { err = MXC_GPIO_Init(0x1 << i); if (err) { return SAFE_MODE_PROGRAMMATIC; @@ -93,14 +93,18 @@ safe_mode_t port_init(void) { // Enable clock to RTC peripheral MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_ERTCO_EN; - while(!(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_ERTCO_RDY)); + while (!(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_ERTCO_RDY)) { + ; + } NVIC_EnableIRQ(RTC_IRQn); NVIC_EnableIRQ(USB_IRQn); // Init RTC w/ 0sec, 0subsec // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s - while( MXC_RTC_Init(0,0) != E_SUCCESS ) {}; + while (MXC_RTC_Init(0, 0) != E_SUCCESS) { + } + ; // enable 1 sec RTC SSEC alarm MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); @@ -108,7 +112,9 @@ safe_mode_t port_init(void) { MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); // Enable RTC - while ( MXC_RTC_Start() != E_SUCCESS ) {}; + while (MXC_RTC_Start() != E_SUCCESS) { + } + ; return SAFE_MODE_NONE; } @@ -191,9 +197,10 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { __disable_irq(); if (MXC_RTC->ctrl & MXC_F_RTC_CTRL_EN) { // NOTE: RTC_GetTime always returns BUSY if RTC is not running - while( (MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR ); - } - else { + while ((MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR) { + ; + } + } else { sec = MXC_RTC->sec; subsec = MXC_RTC->ssec; } @@ -232,15 +239,19 @@ void port_interrupt_after_ticks(uint32_t ticks) { ticks_msec = 1000 * ticks / TICKS_PER_SEC; while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | - MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {}; + MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { + } + ; // Clear the flag to be set by the RTC Handler tick_flag = 0; // Subsec alarm is the starting/reload value of the SSEC counter. // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0 - while ( MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec) ) == E_BUSY) {} - while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {} + while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) == E_BUSY) { + } + while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) { + } NVIC_EnableIRQ(RTC_IRQn); @@ -249,10 +260,10 @@ void port_interrupt_after_ticks(uint32_t ticks) { void port_idle_until_interrupt(void) { #if CIRCUITPY_RTC - // Check if alarm triggers before we even got here - if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { - return; - } + // Check if alarm triggers before we even got here + if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { + return; + } #endif // Interrupts should be disabled to ensure the ISR queue is flushed From cce1fbb8cc10ca41849b17c007fbbad7cd70ac1e Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 09:57:01 -0700 Subject: [PATCH 036/252] Manual pre-commit fix for last delinquent file --- ports/analog/supervisor/port.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 065ac3b3c437..1c068cb22c1d 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -45,9 +45,8 @@ #include "rtc.h" // msec to RTC subsec ticks (4 kHz) -#define MSEC_TO_SS_ALARM(x) \ - (0 - ((x * 4096) / \ - 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */ +/* Converts a time in milleseconds to equivalent RSSA register value */ +#define MSEC_TO_SS_ALARM(x) (0 - ((x * 4096) / 1000)) // Externs defined by linker .ld file extern uint32_t _stack, _heap, _estack, _eheap; From 8e171f19d8167cbe0ab20a94a7b15d68f5e12bf4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 27 Sep 2024 18:16:55 -0400 Subject: [PATCH 037/252] Camera.c: remove unneeded #include logic --- ports/espressif/common-hal/espcamera/Camera.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/ports/espressif/common-hal/espcamera/Camera.c b/ports/espressif/common-hal/espcamera/Camera.c index a40b1eec6b6d..48a611cf9087 100644 --- a/ports/espressif/common-hal/espcamera/Camera.c +++ b/ports/espressif/common-hal/espcamera/Camera.c @@ -15,24 +15,6 @@ #include "shared-bindings/util.h" #include "common-hal/microcontroller/Pin.h" -// These two includes are needed to peek into the i2c handle to get the i2c port -// number. -#include "sdkconfig.h" -// Define these two macros if not defined so that we don't get the -Wundef -// warning from i2c_private.h -#ifndef CONFIG_I2C_ISR_IRAM_SAFE -#define CONFIG_I2C_ISR_IRAM_SAFE 0 -#endif -#ifndef CONFIG_PM_ENABLE -#define CONFIG_PM_ENABLE 0 -#endif - -// i2c_private.h uses `#if` with some macros that may be undefined and taken as 0. -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wundef" -#include "esp-idf/components/esp_driver_i2c/i2c_private.h" -#pragma GCC diagnostic pop - #include "esp-camera/driver/private_include/cam_hal.h" #if !CONFIG_SPIRAM From 14ddb6bdd5370da02a2666e62992a7fd06b3ad5c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 27 Sep 2024 16:45:55 -0700 Subject: [PATCH 038/252] Add IO4 and IO7 to Feather RP2350 These match the silkscreen but not the standard feather pin naming D12 and D13 are left so code is compatible. Brought up on the forums: https://forums.adafruit.com/viewtopic.php?p=1030324 --- ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c index 607698cc7467..064411271e2b 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c @@ -30,7 +30,9 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) }, { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) }, { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO7) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO7) }, From a851f102feb93a4253864bcf3d615500532409ba Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 28 Sep 2024 09:38:20 -0500 Subject: [PATCH 039/252] Error message for sample note matching made consistent --- locale/circuitpython.pot | 38 +++++++-------------------- shared-module/audiodelays/Echo.c | 10 +++---- shared-module/audiomixer/MixerVoice.c | 8 +++--- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 07ed2443d339..f0dfa2cc07b6 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1956,36 +1956,20 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audioeffects/Echo.c -msgid "The sample's bits_per_sample does not match the effect's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's bits_per_sample does not match" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's channel count does not match" msgstr "" -#: shared-module/audioeffects/Echo.c -msgid "The sample's channel count does not match the effect's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's sample rate does not match" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audioeffects/Echo.c -msgid "The sample's sample rate does not match the effect's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audioeffects/Echo.c -msgid "The sample's signedness does not match the effect's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's signedness does not match" msgstr "" #: supervisor/shared/safe_mode.c @@ -2516,7 +2500,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audioeffects/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" @@ -2863,10 +2847,6 @@ msgstr "" msgid "data type not understood" msgstr "" -#: shared-bindings/audioeffects/Echo.c -msgid "decay must be between 0 and 1" -msgstr "" - #: py/parsenum.c msgid "decimal numbers not supported" msgstr "" diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 159a9fcffd9e..294e1db5eb72 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -154,13 +154,13 @@ bool common_hal_audiodelays_echo_get_playing(audiodelays_echo_obj_t *self) { void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sample, bool loop) { if (audiosample_sample_rate(sample) != self->sample_rate) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match the effect's")); + mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match")); } if (audiosample_channel_count(sample) != self->channel_count) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's channel count does not match the effect's")); + mp_raise_ValueError(MP_ERROR_TEXT("The sample's channel count does not match")); } if (audiosample_bits_per_sample(sample) != self->bits_per_sample) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's bits_per_sample does not match the effect's")); + mp_raise_ValueError(MP_ERROR_TEXT("The sample's bits_per_sample does not match")); } bool single_buffer; bool samples_signed; @@ -168,7 +168,7 @@ void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sam uint8_t spacing; audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing); if (samples_signed != self->samples_signed) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's signedness does not match the effect's")); + mp_raise_ValueError(MP_ERROR_TEXT("The sample's signedness does not match")); } self->sample = sample; self->loop = loop; @@ -190,7 +190,7 @@ void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self) { #define RANGE_LOW (-28000) #define RANGE_HIGH (28000) #define RANGE_SHIFT (16) -#define RANGE_SCALE (0xfffffff / (32768 * 2 - RANGE_HIGH)) +#define RANGE_SCALE (0xfffffff / (32768 * 4 - RANGE_HIGH)) // dynamic range compression via a downward compressor with hard knee // diff --git a/shared-module/audiomixer/MixerVoice.c b/shared-module/audiomixer/MixerVoice.c index c32d37cdec28..f43a261d8968 100644 --- a/shared-module/audiomixer/MixerVoice.c +++ b/shared-module/audiomixer/MixerVoice.c @@ -32,13 +32,13 @@ void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *sel void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp_obj_t sample, bool loop) { if (audiosample_sample_rate(sample) != self->parent->sample_rate) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match the mixer's")); + mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match")); } if (audiosample_channel_count(sample) != self->parent->channel_count) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's channel count does not match the mixer's")); + mp_raise_ValueError(MP_ERROR_TEXT("The sample's channel count does not match")); } if (audiosample_bits_per_sample(sample) != self->parent->bits_per_sample) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's bits_per_sample does not match the mixer's")); + mp_raise_ValueError(MP_ERROR_TEXT("The sample's bits_per_sample does not match")); } bool single_buffer; bool samples_signed; @@ -47,7 +47,7 @@ void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing); if (samples_signed != self->parent->samples_signed) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's signedness does not match the mixer's")); + mp_raise_ValueError(MP_ERROR_TEXT("The sample's signedness does not match")); } self->sample = sample; self->loop = loop; From bbd3e016655587c1030a530230eee8900f3c72b5 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 28 Sep 2024 11:22:05 -0500 Subject: [PATCH 040/252] Comments and couple tweaks --- shared-module/audiodelays/Echo.c | 168 +++++++++++++++++++------------ shared-module/audiodelays/Echo.h | 2 +- 2 files changed, 106 insertions(+), 64 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 294e1db5eb72..9d8f0d866015 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -15,26 +15,46 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { - self->bits_per_sample = bits_per_sample; - self->samples_signed = samples_signed; - self->channel_count = channel_count; - self->sample_rate = sample_rate; + // Basic settings every effect and audio sample has + // These are the effects values, not the source sample(s) + self->bits_per_sample = bits_per_sample; // Most common is 16, but 8 is also supported in many places + self->samples_signed = samples_signed; // Are the samples we provide signed (common is true) + self->channel_count = channel_count; // Channels can be 1 for mono or 2 for stereo + self->sample_rate = sample_rate; // Sample rate for the effect, this generally needs to match all audio objects + + // To smooth things out as CircuitPython is doing other tasks most audio objects have a buffer + // A double buffer is set up here so the audio output can use DMA on buffer 1 while we + // write to and create buffer 2. + // This buffer is what is passed to the audio component that plays the effect. + // Samples are set sequentially. For stereo audio they are passed L/R/L/R/... + self->buffer_len = buffer_size; // in bytes - self->buffer_len = buffer_size; self->buffer[0] = m_malloc(self->buffer_len); if (self->buffer[0] == NULL) { common_hal_audiodelays_echo_deinit(self); m_malloc_fail(self->buffer_len); } memset(self->buffer[0], 0, self->buffer_len); + self->buffer[1] = m_malloc(self->buffer_len); if (self->buffer[1] == NULL) { common_hal_audiodelays_echo_deinit(self); m_malloc_fail(self->buffer_len); } memset(self->buffer[1], 0, self->buffer_len); - self->last_buf_idx = 1; + self->last_buf_idx = 1; // Which buffer to use first, toggle between 0 and 1 + + // Initialize other values most effects will need. + self->sample = NULL; // The current playing sample + self->sample_remaining_buffer = NULL; // Pointer to the start of the sample buffer we have not played + self->sample_buffer_length = 0; // How many samples do we have left to play (these may be 16 bit!) + self->loop = false; // When the sample is done do we loop to the start again or stop (e.g. in a wav file) + self->more_data = false; // Is there still more data to read from the sample or did we finish + + // The below section sets up the echo effect's starting values. For a different effect this section will change + + // If we did not receive a BlockInput we need to create a default float value if (decay == MP_OBJ_NULL) { decay = mp_obj_new_float(0.7); } @@ -50,9 +70,13 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ } synthio_block_assign_slot(mix, &self->mix, MP_QSTR_mix); - // Set the echo buffer for the max possible delay + // Many effects may need buffers of what was played this shows how it was done for the echo + // A maximum length buffer was created and then the current echo length can be dynamically changes + // without having to reallocate a large chunk of memory. + + // Allocate the echo buffer for the max possible delay self->max_delay_ms = max_delay_ms; - self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); + self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); // bytes self->echo_buffer = m_malloc(self->max_echo_buffer_len); if (self->echo_buffer == NULL) { common_hal_audiodelays_echo_deinit(self); @@ -60,20 +84,14 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ } memset(self->echo_buffer, 0, self->max_echo_buffer_len); - // calculate current echo buffer size for the set delay + // calculate current echo buffer size we use for the given delay mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); - // read is where we store the incoming sample + // read is where we store the incoming sample + previous echo // write is what we send to the outgoing buffer - self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); + self->echo_buffer_read_pos = self->buffer_len / (self->bits_per_sample / 8); self->echo_buffer_write_pos = 0; - - self->sample = NULL; - self->sample_remaining_buffer = NULL; - self->sample_buffer_length = 0; - self->loop = false; - self->more_data = false; } bool common_hal_audiodelays_echo_deinited(audiodelays_echo_obj_t *self) { @@ -153,6 +171,10 @@ bool common_hal_audiodelays_echo_get_playing(audiodelays_echo_obj_t *self) { } void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sample, bool loop) { + // When a sample is to be played we must ensure the samples values matches what we expect + // Then we reset the sample and get the first buffer to play + // The get_buffer function will actually process that data + if (audiosample_sample_rate(sample) != self->sample_rate) { mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match")); } @@ -170,19 +192,23 @@ void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sam if (samples_signed != self->samples_signed) { mp_raise_ValueError(MP_ERROR_TEXT("The sample's signedness does not match")); } + self->sample = sample; self->loop = loop; audiosample_reset_buffer(self->sample, false, 0); audioio_get_buffer_result_t result = audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&self->sample_remaining_buffer, &self->sample_buffer_length); - // Track length in terms of words. - self->sample_buffer_length /= sizeof(uint16_t); + + // Track remaining sample length in terms of bytes per sample + self->sample_buffer_length /= (self->bits_per_sample / 8); self->more_data = result == GET_BUFFER_MORE_DATA; return; } void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self) { + // When the sample is set to stop playing do any cleanup here + // For echo we clear the sample but the echo continues until the object reading our effect stops self->sample = NULL; return; } @@ -216,29 +242,37 @@ int16_t mix_down_sample(int32_t sample) { audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { + // get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required mp_float_t mix = MIN(1.0, MAX(synthio_block_slot_get(&self->mix), 0.0)); mp_float_t decay = MIN(1.0, MAX(synthio_block_slot_get(&self->decay), 0.0)); + // Switch our buffers to the other buffer self->last_buf_idx = !self->last_buf_idx; + + // If we are using 16 bit samples we need a 16 bit pointer, for 8 bit we can just use the buffer int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx]; - uint32_t length = self->buffer_len / sizeof(uint16_t); + uint32_t length = self->buffer_len / (self->bits_per_sample / 8); + int16_t *echo_buffer = (int16_t *)self->echo_buffer; - uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint16_t); + uint32_t echo_buf_len = self->echo_buffer_len / (self->bits_per_sample / 8); + // Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample while (length != 0) { + + // Check if there is no more sample to play if (self->sample_buffer_length == 0) { - if (!self->more_data) { - if (self->loop && self->sample) { + if (!self->more_data) { // The sample has indicated it has no more data to play + if (self->loop && self->sample) { // If we are supposed to loop reset the sample to the start audiosample_reset_buffer(self->sample, false, 0); - } else { + } else { // If we were not supposed to loop the sample, stop playing it but we still need to play the echo self->sample = NULL; } } if (self->sample) { - // Load another buffer + // Load another sample buffer to play audioio_get_buffer_result_t result = audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&self->sample_remaining_buffer, &self->sample_buffer_length); // Track length in terms of words. - self->sample_buffer_length /= sizeof(uint16_t); // assuming 16 bit samples + self->sample_buffer_length /= (self->bits_per_sample / 8); self->more_data = result == GET_BUFFER_MORE_DATA; } } @@ -246,10 +280,10 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // If we have no sample keep the echo echoing if (self->sample == NULL) { if (MP_LIKELY(self->bits_per_sample == 16)) { - if (mix <= 0.01) { // no sample sound and with no mix, no echo + if (mix <= 0.01) { // Mix of 0 is pure sample sound. We have no sample so no sound memset(word_buffer, 0, length * sizeof(uint16_t)); } else { - // sample signed/unsigned won't matter as we have no sample + // Since we have no sample we can just iterate over the our entire buffer for (uint32_t i = 0; i < length; i++) { word_buffer[i] = echo_buffer[self->echo_buffer_read_pos++] * decay; @@ -267,30 +301,36 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } else { // bits per sample is 8 - uint16_t *hword_buffer = (uint16_t *)word_buffer; - uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; - for (uint32_t i = 0; i < length * 2; i++) { - uint32_t echo_word = unpack8(echo_hsrc[i]); - echo_word = echo_word * decay; - hword_buffer[i] = pack8(echo_word); - - echo_hsrc[self->echo_buffer_write_pos++] = hword_buffer[i]; - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + /* Still to be updated + uint16_t *hword_buffer = (uint16_t *)word_buffer; + uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; + for (uint32_t i = 0; i < length * 2; i++) { + uint32_t echo_word = unpack8(echo_hsrc[i]); + echo_word = echo_word * decay; + hword_buffer[i] = pack8(echo_word); + + echo_hsrc[self->echo_buffer_write_pos++] = hword_buffer[i]; + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } } - } + */ } length = 0; - } else { // we have a sample + } else { + // we have a sample to play and echo + + // Determine how many bytes we can process to our buffer, the less of the sample we have left and our buffer remaining uint32_t n = MIN(self->sample_buffer_length, length); + int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; if (MP_LIKELY(self->bits_per_sample == 16)) { - if (mix <= 0.01) { // sample only + if (mix <= 0.01) { // if mix is zero pure sample only for (uint32_t i = 0; i < n; i++) { word_buffer[i] = sample_src[i]; } @@ -317,27 +357,29 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } } else { // bits per sample is 8 - uint16_t *hword_buffer = (uint16_t *)word_buffer; - uint16_t *sample_hsrc = (uint16_t *)sample_src; - uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; - for (uint32_t i = 0; i < n * 2; i++) { - uint32_t sample_word = unpack8(sample_hsrc[i]); - uint32_t echo_word = unpack8(echo_hsrc[i]); - if (MP_LIKELY(!self->samples_signed)) { - sample_word = tosigned16(sample_word); - } - echo_word = echo_word * decay; - sample_word = sample_word + echo_word; - hword_buffer[i] = pack8(sample_word); + /* to be updated + uint16_t *hword_buffer = (uint16_t *)word_buffer; + uint16_t *sample_hsrc = (uint16_t *)sample_src; + uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; + for (uint32_t i = 0; i < n * 2; i++) { + uint32_t sample_word = unpack8(sample_hsrc[i]); + uint32_t echo_word = unpack8(echo_hsrc[i]); + if (MP_LIKELY(!self->samples_signed)) { + sample_word = tosigned16(sample_word); + } + echo_word = echo_word * decay; + sample_word = sample_word + echo_word; + hword_buffer[i] = pack8(sample_word); - echo_hsrc[self->echo_buffer_write_pos++] = pack8(sample_word + unpack8(hword_buffer[i])); - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + echo_hsrc[self->echo_buffer_write_pos++] = pack8(sample_word + unpack8(hword_buffer[i])); + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } } - } + */ } length -= n; diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index b538716c45fd..f699b0934f4e 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -28,7 +28,7 @@ typedef struct { uint8_t last_buf_idx; uint32_t buffer_len; // max buffer in bytes - uint32_t *sample_remaining_buffer; + uint8_t *sample_remaining_buffer; uint32_t sample_buffer_length; bool loop; From 154ef2e36d34d5ee0bd869030d954e49736d7e91 Mon Sep 17 00:00:00 2001 From: sam blenny <68084116+samblenny@users.noreply.github.com> Date: Sun, 29 Sep 2024 18:20:11 +0000 Subject: [PATCH 041/252] Change USB NULL errors to short strings shared-module/usb/core/Device.c had several spots where it would raise a MicroPython exception with a NULL argument. That made it very difficult for CircuitPython code to attempt to recover from fault conditions caused by quirky USB device behavior. This adds short error strings to distinguish the different types of faults. --- shared-module/usb/core/Device.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/shared-module/usb/core/Device.c b/shared-module/usb/core/Device.c index 4ed0d410523e..70ec5a4c14a7 100644 --- a/shared-module/usb/core/Device.c +++ b/shared-module/usb/core/Device.c @@ -159,7 +159,7 @@ static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) { _xfer_result = 0xff; xfer->complete_cb = _transfer_done_cb; if (!tuh_edpt_xfer(xfer)) { - mp_raise_usb_core_USBError(NULL); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("Xfer")); } uint32_t start_time = supervisor_ticks_ms32(); while ((timeout == 0 || supervisor_ticks_ms32() - start_time < (uint32_t)timeout) && @@ -176,7 +176,7 @@ static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) { xfer_result_t result = _xfer_result; _xfer_result = 0xff; if (result == XFER_RESULT_STALLED) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("Pipe error")); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("Stall")); } if (result == 0xff) { tuh_edpt_abort_xfer(xfer->daddr, xfer->ep_addr); @@ -205,7 +205,7 @@ static bool _open_endpoint(usb_core_device_obj_t *self, mp_int_t endpoint) { } if (self->configuration_descriptor == NULL) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("No configuration set")); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("NoCfg")); } tusb_desc_configuration_t *desc_cfg = (tusb_desc_configuration_t *)self->configuration_descriptor; @@ -239,7 +239,8 @@ static bool _open_endpoint(usb_core_device_obj_t *self, mp_int_t endpoint) { mp_int_t common_hal_usb_core_device_write(usb_core_device_obj_t *self, mp_int_t endpoint, const uint8_t *buffer, mp_int_t len, mp_int_t timeout) { if (!_open_endpoint(self, endpoint)) { - mp_raise_usb_core_USBError(NULL); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("Endpt")); + return 0; } tuh_xfer_t xfer; xfer.daddr = self->device_number; @@ -251,7 +252,8 @@ mp_int_t common_hal_usb_core_device_write(usb_core_device_obj_t *self, mp_int_t mp_int_t common_hal_usb_core_device_read(usb_core_device_obj_t *self, mp_int_t endpoint, uint8_t *buffer, mp_int_t len, mp_int_t timeout) { if (!_open_endpoint(self, endpoint)) { - mp_raise_usb_core_USBError(NULL); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("Endpt")); + return 0; } tuh_xfer_t xfer; xfer.daddr = self->device_number; @@ -285,7 +287,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, _xfer_result = 0xff; if (!tuh_control_xfer(&xfer)) { - mp_raise_usb_core_USBError(NULL); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("Xfer")); } uint32_t start_time = supervisor_ticks_ms32(); while ((timeout == 0 || supervisor_ticks_ms32() - start_time < (uint32_t)timeout) && @@ -302,7 +304,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, xfer_result_t result = _xfer_result; _xfer_result = 0xff; if (result == XFER_RESULT_STALLED) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("Pipe error")); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("Stall")); } if (result == 0xff) { tuh_edpt_abort_xfer(xfer.daddr, xfer.ep_addr); From 90053fe8acfc46576b1d98b94647ac3243b0b3c7 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 29 Sep 2024 15:03:31 -0400 Subject: [PATCH 042/252] bring esp32-camera up to date --- ports/espressif/esp-camera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/esp-camera b/ports/espressif/esp-camera index d529ebdffb84..243560e94997 160000 --- a/ports/espressif/esp-camera +++ b/ports/espressif/esp-camera @@ -1 +1 @@ -Subproject commit d529ebdffb84131b1aadaec32a7373b319b70391 +Subproject commit 243560e94997c262565ed537154b0578b8ce2197 From 9116911a6ca227d016c61ebbd4b7d82fb48aeef7 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 29 Sep 2024 17:07:50 -0400 Subject: [PATCH 043/252] fix formatting --- ports/nordic/common-hal/busio/I2C.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/nordic/common-hal/busio/I2C.c b/ports/nordic/common-hal/busio/I2C.c index 54f5c1570419..bdfff3fa179a 100644 --- a/ports/nordic/common-hal/busio/I2C.c +++ b/ports/nordic/common-hal/busio/I2C.c @@ -21,10 +21,10 @@ // all TWI instances have the same max size // 16 bits for 840, 10 bits for 810, 8 bits for 832 #define I2C_MAX_XFER_LEN MIN(((1UL << TWIM0_EASYDMA_MAXCNT_SIZE) - 1), 1024) -#define I2C_TIMEOUT 1000 // 1 second timeout +// 1 second timeout +#define I2C_TIMEOUT 1000 -static - twim_peripheral_t twim_peripherals[] = { +static twim_peripheral_t twim_peripherals[] = { #if NRFX_CHECK(NRFX_TWIM0_ENABLED) // SPIM0 and TWIM0 share an address. { .twim = NRFX_TWIM_INSTANCE(0), From 3ed76982b5cfec23208a3636e6065eb6447f5173 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 29 Sep 2024 19:06:52 -0400 Subject: [PATCH 044/252] shrink some builds --- .../boards/feather_m4_express/mpconfigboard.h | 1 + .../feather_m4_express/mpconfigboard.mk | 2 +- .../boards/metro_m0_express/mpconfigboard.mk | 1 + .../boards/metro_m4_express/mpconfigboard.h | 2 + .../boards/metro_m4_express/mpconfigboard.mk | 1 + .../sparkfun_redboard_turbo/mpconfigboard.mk | 1 + .../trinket_m0_haxpress/mpconfigboard.h | 37 +++++++++++++++++++ .../trinket_m0_haxpress/mpconfigboard.mk | 2 + 8 files changed, 46 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h index 0ca05115204e..ff6256eea6da 100644 --- a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.h @@ -41,6 +41,7 @@ #define IGNORE_PIN_PA27 1 #define IGNORE_PIN_PB00 1 #define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 #define IGNORE_PIN_PB06 1 #define IGNORE_PIN_PB07 1 #define IGNORE_PIN_PB30 1 diff --git a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk index 377e4f4f0f82..16af70ef683f 100644 --- a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk @@ -12,8 +12,8 @@ LONGINT_IMPL = MPZ CIRCUITPY__EVE = 1 CIRCUITPY_FLOPPYIO = 0 -CIRCUITPY_SYNTHIO = 0 CIRCUITPY_JPEGIO = 0 +CIRCUITPY_SYNTHIO = 0 # We don't have room for the fonts for terminalio for certain languages, # so turn off terminalio, and if it's off and displayio is on, diff --git a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk index ea38dc9d538b..d758d6878fb7 100644 --- a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk @@ -10,4 +10,5 @@ SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C, W25Q16JVxQ" LONGINT_IMPL = MPZ +CIRCUITPY_CODEOP = 0 CIRCUITPY_RAINBOWIO = 0 diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h index c3074a5740d0..b7ca7986ded8 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.h @@ -48,3 +48,5 @@ #define IGNORE_PIN_PB04 1 #define IGNORE_PIN_PB05 1 #define IGNORE_PIN_PB23 1 +#define IGNORE_PIN_PB30 1 +#define IGNORE_PIN_PB31 1 diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk index 4f01c141e484..0567918884ac 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk @@ -11,6 +11,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C, W25Q16JVxQ" LONGINT_IMPL = MPZ CIRCUITPY__EVE = 1 +CIRCUITPY_CODEOP = 0 CIRCUITPY_FLOPPYIO = 0 CIRCUITPY_JPEGIO = 0 CIRCUITPY_SYNTHIO = 0 diff --git a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk index ef23e5602243..64049e8d5981 100755 --- a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk @@ -10,4 +10,5 @@ SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q32FV" LONGINT_IMPL = MPZ +CIRCUITPY_CODEOP = 0 CIRCUITPY_RAINBOWIO = 0 diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h index bc157d6c86bb..7eec1d64f8ef 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.h @@ -31,6 +31,43 @@ #define DEFAULT_UART_BUS_RX (&pin_PA07) #define DEFAULT_UART_BUS_TX (&pin_PA06) +#define IGNORE_PIN_PA03 1 +#define IGNORE_PIN_PA04 1 +#define IGNORE_PIN_PA12 1 +#define IGNORE_PIN_PA13 1 +#define IGNORE_PIN_PA14 1 +#define IGNORE_PIN_PA15 1 +#define IGNORE_PIN_PA18 1 +#define IGNORE_PIN_PA20 1 +#define IGNORE_PIN_PA21 1 +#define IGNORE_PIN_PA22 1 +#define IGNORE_PIN_PA23 1 // USB is always used internally so skip the pin objects for it. #define IGNORE_PIN_PA24 1 #define IGNORE_PIN_PA25 1 +#define IGNORE_PIN_PA27 1 +#define IGNORE_PIN_PA28 1 +#define IGNORE_PIN_PA30 1 +#define IGNORE_PIN_PA31 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB02 1 +#define IGNORE_PIN_PB03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB08 1 +#define IGNORE_PIN_PB09 1 +#define IGNORE_PIN_PB10 1 +#define IGNORE_PIN_PB11 1 +#define IGNORE_PIN_PB12 1 +#define IGNORE_PIN_PB13 1 +#define IGNORE_PIN_PB14 1 +#define IGNORE_PIN_PB15 1 +#define IGNORE_PIN_PB16 1 +#define IGNORE_PIN_PB17 1 +#define IGNORE_PIN_PB22 1 +#define IGNORE_PIN_PB23 1 +#define IGNORE_PIN_PB30 1 +#define IGNORE_PIN_PB31 1 +#define IGNORE_PIN_PB00 1 diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk index 028114091ecb..29b5865d419d 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk @@ -9,3 +9,5 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = W25Q32BV LONGINT_IMPL = MPZ + +CIRCUITPY_CODEOP = 0 From 6cc41f0bf94951b894e2c8e6ee4635fd55d37b2e Mon Sep 17 00:00:00 2001 From: sam blenny <68084116+samblenny@users.noreply.github.com> Date: Mon, 30 Sep 2024 01:18:18 +0000 Subject: [PATCH 045/252] return early after raising USBError This commit makes sure that functions in usb.core.Device return as soon as they raise a MicroPython exception rather than continuing on with whatever code would normally run. This will hopefully help to avoid things like dereferencing null pointers. --- shared-module/usb/core/Device.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shared-module/usb/core/Device.c b/shared-module/usb/core/Device.c index 70ec5a4c14a7..5965864a447b 100644 --- a/shared-module/usb/core/Device.c +++ b/shared-module/usb/core/Device.c @@ -160,6 +160,7 @@ static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) { xfer->complete_cb = _transfer_done_cb; if (!tuh_edpt_xfer(xfer)) { mp_raise_usb_core_USBError(MP_ERROR_TEXT("Xfer")); + return 0; } uint32_t start_time = supervisor_ticks_ms32(); while ((timeout == 0 || supervisor_ticks_ms32() - start_time < (uint32_t)timeout) && @@ -206,6 +207,7 @@ static bool _open_endpoint(usb_core_device_obj_t *self, mp_int_t endpoint) { if (self->configuration_descriptor == NULL) { mp_raise_usb_core_USBError(MP_ERROR_TEXT("NoCfg")); + return false; } tusb_desc_configuration_t *desc_cfg = (tusb_desc_configuration_t *)self->configuration_descriptor; @@ -288,6 +290,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, if (!tuh_control_xfer(&xfer)) { mp_raise_usb_core_USBError(MP_ERROR_TEXT("Xfer")); + return 0; } uint32_t start_time = supervisor_ticks_ms32(); while ((timeout == 0 || supervisor_ticks_ms32() - start_time < (uint32_t)timeout) && From a023f926c93c24b0098960ab3f2e4d7dbcba3835 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 29 Sep 2024 22:37:11 -0400 Subject: [PATCH 046/252] address review --- lib/tinyusb | 2 +- ports/atmel-samd/common-hal/busio/I2C.c | 6 ++---- ports/broadcom/common-hal/busio/I2C.c | 7 +++++-- ports/cxd56/common-hal/busio/I2C.c | 4 ++++ ports/espressif/common-hal/busio/I2C.c | 8 +++++--- ports/espressif/common-hal/espcamera/Camera.c | 4 ++++ ports/mimxrt10xx/common-hal/busio/I2C.c | 8 ++++++-- ports/nordic/common-hal/busio/I2C.c | 6 ++++-- ports/raspberrypi/common-hal/busio/I2C.c | 6 ++++-- ports/silabs/common-hal/busio/I2C.c | 5 +++-- ports/stm/common-hal/busio/I2C.c | 5 +++-- 11 files changed, 41 insertions(+), 20 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 4349e99fb29d..5217cee5de4c 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 4349e99fb29dbc7d019aa2fbb6344864799d8c1b +Subproject commit 5217cee5de4cd555018da90f9f1bcc87fb1c1d3a diff --git a/ports/atmel-samd/common-hal/busio/I2C.c b/ports/atmel-samd/common-hal/busio/I2C.c index e55b4f589f28..e13b5410ae32 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.c +++ b/ports/atmel-samd/common-hal/busio/I2C.c @@ -53,7 +53,8 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, uint32_t sda_pinmux, scl_pinmux; // Ensure the object starts in its deinit state. - self->sda_pin = NO_PIN; + common_hal_busio_i2c_mark_deinit(self); + Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); if (sercom == NULL) { raise_ValueError_invalid_pins(); @@ -108,7 +109,6 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, mp_arg_error_invalid(MP_QSTR_frequency); } - if (i2c_m_sync_enable(&self->i2c_desc) != ERR_NONE) { common_hal_busio_i2c_deinit(self); mp_raise_OSError(MP_EIO); @@ -141,8 +141,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { reset_pin_number(self->sda_pin); reset_pin_number(self->scl_pin); - self->sda_pin = NO_PIN; - self->scl_pin = NO_PIN; common_hal_busio_i2c_mark_deinit(self); } diff --git a/ports/broadcom/common-hal/busio/I2C.c b/ports/broadcom/common-hal/busio/I2C.c index 77b0eb293038..37d9758082c8 100644 --- a/ports/broadcom/common-hal/busio/I2C.c +++ b/ports/broadcom/common-hal/busio/I2C.c @@ -27,9 +27,14 @@ static bool i2c_in_use[NUM_I2C]; void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { + + // Ensure the object starts in its deinit state. + common_hal_busio_i2c_mark_deinit(self); + size_t instance_index = NUM_I2C; uint8_t scl_alt = 0; uint8_t sda_alt = 0; + for (scl_alt = 0; scl_alt < 6; scl_alt++) { if (scl->functions[scl_alt].type != PIN_FUNCTION_I2C || i2c_in_use[scl->functions[scl_alt].index] || @@ -82,8 +87,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { common_hal_reset_pin(self->sda_pin); common_hal_reset_pin(self->scl_pin); - self->sda_pin = NULL; - self->scl_pin = NULL; common_hal_busio_i2c_mark_deinit(self); } diff --git a/ports/cxd56/common-hal/busio/I2C.c b/ports/cxd56/common-hal/busio/I2C.c index 671c93d3eb88..fb33c242a036 100644 --- a/ports/cxd56/common-hal/busio/I2C.c +++ b/ports/cxd56/common-hal/busio/I2C.c @@ -16,6 +16,10 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { + + // Ensure the object starts in its deinit state. + common_hal_busio_i2c_mark_deinit(self); + if (frequency != I2C_SPEED_STANDARD && frequency != I2C_SPEED_FAST) { mp_arg_error_invalid(MP_QSTR_frequency); } diff --git a/ports/espressif/common-hal/busio/I2C.c b/ports/espressif/common-hal/busio/I2C.c index d0f9089d6952..88dffb5d2c82 100644 --- a/ports/espressif/common-hal/busio/I2C.c +++ b/ports/espressif/common-hal/busio/I2C.c @@ -16,6 +16,10 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout_us) { + + // Ensure the object starts in its deinit state. + common_hal_busio_i2c_mark_deinit(self); + // Pins 45 and 46 are "strapping" pins that impact start up behavior. They usually need to // be pulled-down so pulling them up for I2C is a bad idea. To make this hard, we don't // support I2C on these pins. @@ -125,13 +129,11 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { common_hal_reset_pin(self->sda_pin); common_hal_reset_pin(self->scl_pin); - self->sda_pin = NULL; - self->scl_pin = NULL; common_hal_busio_i2c_mark_deinit(self); } bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { - esp_err_t result = i2c_master_probe(self->handle, addr, 1); + esp_err_t result = i2c_master_probe(self->handle, addr, 10); return result == ESP_OK; } diff --git a/ports/espressif/common-hal/espcamera/Camera.c b/ports/espressif/common-hal/espcamera/Camera.c index 48a611cf9087..5b45a26951ed 100644 --- a/ports/espressif/common-hal/espcamera/Camera.c +++ b/ports/espressif/common-hal/espcamera/Camera.c @@ -78,6 +78,10 @@ void common_hal_espcamera_camera_construct( self->i2c = i2c; // These pins might be NULL because they were not specified. + // Note that common_hal_mcu_pin_number() returns NO_PIN (- =1) if pass NULL, but as a `uint8_t`, + // so it becomes 255. The camera driver expects non-specified pins to be < 0. + // So we have to set the pins to NO_PIN explicitly, + // instead of relying on the return value from common_hal_mcu_pin_number(). self->camera_config.pin_pwdn = powerdown_pin ? common_hal_mcu_pin_number(powerdown_pin) : NO_PIN; self->camera_config.pin_reset = reset_pin ? common_hal_mcu_pin_number(reset_pin) : NO_PIN; self->camera_config.pin_xclk = external_clock_pin ? common_hal_mcu_pin_number(external_clock_pin) : NO_PIN; diff --git a/ports/mimxrt10xx/common-hal/busio/I2C.c b/ports/mimxrt10xx/common-hal/busio/I2C.c index 28a6b8ae5e35..132b3083212a 100644 --- a/ports/mimxrt10xx/common-hal/busio/I2C.c +++ b/ports/mimxrt10xx/common-hal/busio/I2C.c @@ -66,6 +66,9 @@ static void i2c_check_pin_config(const mcu_pin_obj_t *pin, uint32_t pull) { void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { + // Ensure the object starts in its deinit state. + common_hal_busio_i2c_mark_deinit(self); + #if CIRCUITPY_REQUIRE_I2C_PULLUPS // Test that the pins are in a high state. (Hopefully indicating they are pulled up.) IOMUXC_SetPinMux(sda->mux_reg, IOMUXC_SW_MUX_CTL_PAD_MUX_MODE_ALT5, 0, 0, 0, 0); @@ -162,8 +165,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { common_hal_reset_pin(self->sda->pin); common_hal_reset_pin(self->scl->pin); - self->sda = NULL; - self->scl = NULL; common_hal_busio_i2c_mark_deinit(self); } @@ -179,6 +180,9 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { } bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { + if (common_hal_busio_i2c_deinited(self)) { + return false; + } bool grabbed_lock = false; // CRITICAL_SECTION_ENTER() if (!self->has_lock) { diff --git a/ports/nordic/common-hal/busio/I2C.c b/ports/nordic/common-hal/busio/I2C.c index bdfff3fa179a..3558fad165ba 100644 --- a/ports/nordic/common-hal/busio/I2C.c +++ b/ports/nordic/common-hal/busio/I2C.c @@ -74,6 +74,10 @@ static void twim_event_handler(nrfx_twim_evt_t const *p_event, void *p_context) } void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { + + // Ensure the object starts in its deinit state. + common_hal_busio_i2c_mark_deinit(self); + if (scl->number == sda->number) { raise_ValueError_invalid_pins(); } @@ -155,8 +159,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { reset_pin_number(self->sda_pin_number); reset_pin_number(self->scl_pin_number); - self->sda_pin_number = NO_PIN; - self->scl_pin_number = NO_PIN; self->twim_peripheral->in_use = false; common_hal_busio_i2c_mark_deinit(self); diff --git a/ports/raspberrypi/common-hal/busio/I2C.c b/ports/raspberrypi/common-hal/busio/I2C.c index 289beeee1504..3b7cf8662d90 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.c +++ b/ports/raspberrypi/common-hal/busio/I2C.c @@ -26,6 +26,10 @@ static i2c_inst_t *i2c[2] = {i2c0, i2c1}; void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { + + // Ensure object starts in its deinit state. + common_hal_busio_i2c_mark_deinit(self); + self->peripheral = NULL; // I2C pins have a regular pattern. SCL is always odd and SDA is even. They match up in pairs // so we can divide by two to get the instance. This pattern repeats. @@ -109,8 +113,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { reset_pin_number(self->sda_pin); reset_pin_number(self->scl_pin); - self->sda_pin = NO_PIN; - self->scl_pin = NO_PIN; common_hal_busio_i2c_mark_deinit(self); } diff --git a/ports/silabs/common-hal/busio/I2C.c b/ports/silabs/common-hal/busio/I2C.c index adfaee8e4e91..ae18f561c502 100644 --- a/ports/silabs/common-hal/busio/I2C.c +++ b/ports/silabs/common-hal/busio/I2C.c @@ -39,6 +39,9 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { + // Ensure the object starts in its deinit state. + common_hal_busio_i2c_mark_deinit(self); + if ((scl != NULL) && (sda != NULL)) { if (scl->function_list[ DEFAULT_I2C_PERIPHERAL == I2C1? FN_I2C1_SCL : FN_I2C0_SCL] == 1 && @@ -88,8 +91,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { I2C_Reset(self->i2cspm); common_hal_reset_pin(self->sda); common_hal_reset_pin(self->scl); - self->sda = NULL; - self->scl = NULL; self->i2cspm = NULL; in_used = false; common_hal_busio_i2c_mark_deinit(self); diff --git a/ports/stm/common-hal/busio/I2C.c b/ports/stm/common-hal/busio/I2C.c index 7df96e5d2799..e6957989cc72 100644 --- a/ports/stm/common-hal/busio/I2C.c +++ b/ports/stm/common-hal/busio/I2C.c @@ -50,6 +50,9 @@ static void i2c_assign_irq(busio_i2c_obj_t *self, I2C_TypeDef *I2Cx); void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { + // Ensure the object starts in its deinit state. + common_hal_busio_i2c_mark_deinit(self); + // Match pins to I2C objects I2C_TypeDef *I2Cx; uint8_t sda_len = MP_ARRAY_SIZE(mcu_i2c_sda_list); @@ -168,8 +171,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { reset_pin_number(self->sda->pin->port, self->sda->pin->number); reset_pin_number(self->scl->pin->port, self->scl->pin->number); - self->sda = NULL; - self->scl = NULL; common_hal_busio_i2c_mark_deinit(self); } From 3b07c3c7a72838079a16dd299d3a69585d0f6cf5 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Mon, 30 Sep 2024 09:08:10 +0200 Subject: [PATCH 047/252] support setups with all modules in src-directory --- tools/preprocess_frozen_modules.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/preprocess_frozen_modules.py b/tools/preprocess_frozen_modules.py index eb835961f67e..bfc43d018469 100755 --- a/tools/preprocess_frozen_modules.py +++ b/tools/preprocess_frozen_modules.py @@ -42,9 +42,13 @@ def version_string(path=None, *, valid_semver=False): return version -# Visit all the .py files in topdir. Replace any __version__ = "0.0.0-auto.0" type of info +# Visit all the .py files in topdir or src. Replace any __version__ = "0.0.0-auto.0" type of info # with actual version info derived from git. def copy_and_process(in_dir, out_dir): + # setuptools default: use modules from 'src' if the directory exists + src_dir = in_dir + os.path.sep + "src" + if os.path.exists(src_dir) and os.path.isdir(src_dir): + in_dir = src_dir for root, subdirs, files in os.walk(in_dir): # Skip library examples directory and subfolders. relative_path_parts = Path(root).relative_to(in_dir).parts From 280bbbe058f81346f854d8b9a85bc0a498b3b9e8 Mon Sep 17 00:00:00 2001 From: sam blenny <68084116+samblenny@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:08:39 +0000 Subject: [PATCH 048/252] update translations for usb.core.Device This is the result of a `pre-commit run --all-files` to fix the translation file changes which were causing a CI check fail. I'm not convinced this change is a good idea. I would prefer to set USBError.errno, if possible, but I don't know how to do that. --- locale/circuitpython.pot | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 0b19dce9c427..da74912e4c48 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -915,6 +915,10 @@ msgstr "" msgid "ESP-IDF memory allocation failed" msgstr "" +#: shared-module/usb/core/Device.c +msgid "Endpt" +msgstr "" + #: extmod/modre.c msgid "Error in regex" msgstr "" @@ -1445,10 +1449,6 @@ msgstr "" msgid "No bootloader present" msgstr "" -#: shared-module/usb/core/Device.c -msgid "No configuration set" -msgstr "" - #: shared-bindings/_bleio/PacketBuffer.c msgid "No connection: length cannot be determined" msgstr "" @@ -1518,6 +1518,10 @@ msgstr "" msgid "No usb host port initialized" msgstr "" +#: shared-module/usb/core/Device.c +msgid "NoCfg" +msgstr "" + #: ports/nordic/common-hal/_bleio/__init__.c msgid "Nordic system firmware out of memory" msgstr "" @@ -1726,10 +1730,6 @@ msgstr "" msgid "Pins must share PWM slice" msgstr "" -#: shared-module/usb/core/Device.c -msgid "Pipe error" -msgstr "" - #: py/builtinhelp.c msgid "Plus any modules on the filesystem\n" msgstr "" @@ -1941,6 +1941,10 @@ msgstr "" msgid "Stack overflow. Increase stack size." msgstr "" +#: shared-module/usb/core/Device.c +msgid "Stall" +msgstr "" + #: shared-bindings/alarm/time/TimeAlarm.c msgid "Supply one of monotonic_time or epoch_time" msgstr "" @@ -2301,6 +2305,10 @@ msgstr "" msgid "Writes not supported on Characteristic" msgstr "" +#: shared-module/usb/core/Device.c +msgid "Xfer" +msgstr "" + #: ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h #: ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h #: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h From 72052a4b5ed72914fe466deaa968adbbc029bb51 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Mon, 30 Sep 2024 11:16:38 -0400 Subject: [PATCH 049/252] Set default hostname proof of concept --- ports/espressif/common-hal/wifi/__init__.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index c2a63ceede72..30fee7010a73 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -16,6 +16,8 @@ #include "py/gc.h" #include "py/mpstate.h" #include "py/runtime.h" +#include "py/objstr.h" +#include "py/objint.h" #include "components/esp_wifi/include/esp_wifi.h" @@ -197,6 +199,19 @@ void common_hal_wifi_init(bool user_initiated) { ESP_LOGE(TAG, "WiFi error code: %x", result); return; } + // set the default lwip_local_hostname + // + // What happens if someone uses wifi.radio.hostname and then the + // interface is reset, I don't know if an interface reset is a thing + // but there is logic here to check for re-entry into the common_hal_wifi_init + // module. I would think we would want to carry the exising hostname across + // subsequent interface resets. + char cpy_default_hostname[80]; + uint8_t mac[6]; + esp_wifi_get_mac(ESP_IF_WIFI_STA, mac); + sprintf(cpy_default_hostname, "cpy_%s_%x", CIRCUITPY_BOARD_ID, (unsigned int)mac); + const char *default_lwip_local_hostname = cpy_default_hostname; + ESP_ERROR_CHECK(esp_netif_set_hostname(self->netif,default_lwip_local_hostname)); // set station mode to avoid the default SoftAP common_hal_wifi_radio_start_station(self); // start wifi From 0d5a234c98d570e6a436286aff612888b5baa398 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Mon, 30 Sep 2024 11:21:29 -0400 Subject: [PATCH 050/252] precommit run -all :/ someday I'll remember --- ports/espressif/common-hal/wifi/__init__.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index 30fee7010a73..9f574bcc6a8d 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -201,17 +201,17 @@ void common_hal_wifi_init(bool user_initiated) { } // set the default lwip_local_hostname // - // What happens if someone uses wifi.radio.hostname and then the + // What happens if someone uses wifi.radio.hostname and then the // interface is reset, I don't know if an interface reset is a thing // but there is logic here to check for re-entry into the common_hal_wifi_init - // module. I would think we would want to carry the exising hostname across + // module. I would think we would want to carry the existing hostname across // subsequent interface resets. char cpy_default_hostname[80]; uint8_t mac[6]; esp_wifi_get_mac(ESP_IF_WIFI_STA, mac); sprintf(cpy_default_hostname, "cpy_%s_%x", CIRCUITPY_BOARD_ID, (unsigned int)mac); const char *default_lwip_local_hostname = cpy_default_hostname; - ESP_ERROR_CHECK(esp_netif_set_hostname(self->netif,default_lwip_local_hostname)); + ESP_ERROR_CHECK(esp_netif_set_hostname(self->netif, default_lwip_local_hostname)); // set station mode to avoid the default SoftAP common_hal_wifi_radio_start_station(self); // start wifi From 70c0bf9254308526cab079e80c54ec0e989abd67 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 30 Sep 2024 10:25:59 -0500 Subject: [PATCH 051/252] 8 bit unsigned samples working --- shared-module/audiodelays/Echo.c | 172 ++++++++++++++++--------------- 1 file changed, 90 insertions(+), 82 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 9d8f0d866015..d8e17c87b61a 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -76,7 +76,7 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ // Allocate the echo buffer for the max possible delay self->max_delay_ms = max_delay_ms; - self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); // bytes + self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * 2);// (self->bits_per_sample / 8)); // bytes self->echo_buffer = m_malloc(self->max_echo_buffer_len); if (self->echo_buffer == NULL) { common_hal_audiodelays_echo_deinit(self); @@ -86,11 +86,11 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ // calculate current echo buffer size we use for the given delay mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); - self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); + self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * 2);// (self->bits_per_sample / 8)); // read is where we store the incoming sample + previous echo // write is what we send to the outgoing buffer - self->echo_buffer_read_pos = self->buffer_len / (self->bits_per_sample / 8); + self->echo_buffer_read_pos = self->buffer_len / 2;// (self->bits_per_sample / 8); self->echo_buffer_write_pos = 0; } @@ -119,9 +119,9 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_o synthio_block_assign_slot(delay_ms, &self->delay_ms, MP_QSTR_delay_ms); mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); - self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * (self->bits_per_sample / 8)); + self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * 2);// (self->bits_per_sample / 8)); - uint32_t max_ebuf_length = self->echo_buffer_len / sizeof(uint32_t); + uint32_t max_ebuf_length = self->echo_buffer_len / sizeof(uint16_t); if (self->echo_buffer_read_pos > max_ebuf_length) { self->echo_buffer_read_pos = 0; @@ -249,12 +249,15 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // Switch our buffers to the other buffer self->last_buf_idx = !self->last_buf_idx; - // If we are using 16 bit samples we need a 16 bit pointer, for 8 bit we can just use the buffer + // If we are using 16 bit samples we need a 16 bit pointer int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx]; + int8_t *hword_buffer = self->buffer[self->last_buf_idx]; uint32_t length = self->buffer_len / (self->bits_per_sample / 8); + // The echo buffer is always stored as a 16-bit value internally int16_t *echo_buffer = (int16_t *)self->echo_buffer; - uint32_t echo_buf_len = self->echo_buffer_len / (self->bits_per_sample / 8); + uint32_t echo_buf_len = self->echo_buffer_len / 2;// (self->bits_per_sample / 8); + // Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample while (length != 0) { @@ -279,45 +282,38 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // If we have no sample keep the echo echoing if (self->sample == NULL) { - if (MP_LIKELY(self->bits_per_sample == 16)) { - if (mix <= 0.01) { // Mix of 0 is pure sample sound. We have no sample so no sound - memset(word_buffer, 0, length * sizeof(uint16_t)); + if (mix <= 0.01) { // Mix of 0 is pure sample sound. We have no sample so no sound + if (self->samples_signed) { + memset(word_buffer, 0, length * (self->bits_per_sample / 8)); } else { - // Since we have no sample we can just iterate over the our entire buffer - for (uint32_t i = 0; i < length; i++) { - word_buffer[i] = echo_buffer[self->echo_buffer_read_pos++] * decay; - - echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; - - word_buffer[i] = word_buffer[i] * mix; - - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; + memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); + } + } else { + // Since we have no sample we can just iterate over the our entire remaining buffer + for (uint32_t i = 0; i < length; i++) { + int16_t echo = echo_buffer[self->echo_buffer_read_pos++] * decay; + echo_buffer[self->echo_buffer_write_pos++] = echo; + + if (MP_LIKELY(self->bits_per_sample == 16)) { + word_buffer[i] = echo * mix; + if (!self->samples_signed) { + word_buffer[i] ^= 0x8000; } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + } else { + echo = echo * mix; + hword_buffer[i] = echo; + if (!self->samples_signed) { + hword_buffer[i] ^= 0x80; } } - } - } else { // bits per sample is 8 - /* Still to be updated - uint16_t *hword_buffer = (uint16_t *)word_buffer; - uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; - for (uint32_t i = 0; i < length * 2; i++) { - uint32_t echo_word = unpack8(echo_hsrc[i]); - echo_word = echo_word * decay; - hword_buffer[i] = pack8(echo_word); - - echo_hsrc[self->echo_buffer_write_pos++] = hword_buffer[i]; - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; - } + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; } - */ + } } length = 0; @@ -328,62 +324,74 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * uint32_t n = MIN(self->sample_buffer_length, length); int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; + int8_t *sample_hsrc = (int8_t *)self->sample_remaining_buffer; - if (MP_LIKELY(self->bits_per_sample == 16)) { - if (mix <= 0.01) { // if mix is zero pure sample only - for (uint32_t i = 0; i < n; i++) { + if (mix <= 0.01) { // if mix is zero pure sample only + for (uint32_t i = 0; i < n; i++) { + if (MP_LIKELY(self->bits_per_sample == 16)) { word_buffer[i] = sample_src[i]; + } else { + hword_buffer[i] = sample_hsrc[i]; } - } else { - for (uint32_t i = 0; i < n; i++) { - int32_t sample_word = sample_src[i]; - if (!self->samples_signed) { - sample_word = tosigned16(sample_word); + } + } else { + for (uint32_t i = 0; i < n; i++) { + int32_t sample_word = 0; + if (MP_LIKELY(self->bits_per_sample == 16)) { + sample_word = sample_src[i]; + } else { + if (self->samples_signed) { + sample_word = sample_hsrc[i]; + } else { + // uint8_t s1 = sample_hsrc[i]; + // int8_t s2 = s1^0x80; + // sample_word = s2; + + sample_word = (int8_t)(((uint8_t)sample_hsrc[i]) ^ 0x80); } + } - int32_t word = (echo_buffer[self->echo_buffer_read_pos++] * decay) + sample_word; - word_buffer[i] = mix_down_sample(word); - - echo_buffer[self->echo_buffer_write_pos++] = word_buffer[i]; - - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; + int32_t echo = echo_buffer[self->echo_buffer_read_pos++] * decay; + int32_t word = echo + sample_word; + if (MP_LIKELY(self->bits_per_sample == 16)) { + word = mix_down_sample(word); + echo_buffer[self->echo_buffer_write_pos++] = (int16_t)word; + } else { + if (word > 127) { + word = 127; + } else if (word < -128) { + word = -128; } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; - } - - word_buffer[i] = (sample_word * (1.0 - mix)) + (word_buffer[i] * mix); + echo_buffer[self->echo_buffer_write_pos++] = (int8_t)word; } - } - } else { // bits per sample is 8 - /* to be updated - uint16_t *hword_buffer = (uint16_t *)word_buffer; - uint16_t *sample_hsrc = (uint16_t *)sample_src; - uint16_t *echo_hsrc = (uint16_t *)self->echo_buffer; - for (uint32_t i = 0; i < n * 2; i++) { - uint32_t sample_word = unpack8(sample_hsrc[i]); - uint32_t echo_word = unpack8(echo_hsrc[i]); - if (MP_LIKELY(!self->samples_signed)) { - sample_word = tosigned16(sample_word); - } - echo_word = echo_word * decay; - sample_word = sample_word + echo_word; - hword_buffer[i] = pack8(sample_word); - echo_hsrc[self->echo_buffer_write_pos++] = pack8(sample_word + unpack8(hword_buffer[i])); - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; + if (MP_LIKELY(self->bits_per_sample == 16)) { + word_buffer[i] = (sample_word * (1.0 - mix)) + (word * mix); + if (!self->samples_signed) { + word_buffer[i] ^= 0x8000; } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + } else { + int8_t mixed = (sample_word * (1.0 - mix)) + (word * mix); + ; + if (self->samples_signed) { + hword_buffer[i] = mixed; + } else { + hword_buffer[i] = (uint8_t)mixed ^ 0x80; } } - */ + + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } + } } length -= n; word_buffer += n; + hword_buffer += n; self->sample_remaining_buffer += n; self->sample_buffer_length -= n; } @@ -398,7 +406,7 @@ void audiodelays_echo_get_buffer_structure(audiodelays_echo_obj_t *self, bool si bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing) { *single_buffer = false; - *samples_signed = true; + *samples_signed = self->samples_signed; *max_buffer_length = self->buffer_len; if (single_channel_output) { *spacing = self->channel_count; From 00a149a2c137d1442f1c0264d315f4307a1a9b5b Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 30 Sep 2024 14:04:43 -0500 Subject: [PATCH 052/252] More comments and cleanup --- shared-module/audiodelays/Echo.c | 66 ++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index d8e17c87b61a..eb488ba9ed26 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -61,7 +61,7 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ synthio_block_assign_slot(decay, &self->decay, MP_QSTR_decay); if (delay_ms == MP_OBJ_NULL) { - delay_ms = mp_obj_new_float(0.05); + delay_ms = mp_obj_new_float(500.0); } synthio_block_assign_slot(delay_ms, &self->delay_ms, MP_QSTR_delay_ms); @@ -74,9 +74,9 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ // A maximum length buffer was created and then the current echo length can be dynamically changes // without having to reallocate a large chunk of memory. - // Allocate the echo buffer for the max possible delay + // Allocate the echo buffer for the max possible delay, echo is always 16-bit self->max_delay_ms = max_delay_ms; - self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * 2);// (self->bits_per_sample / 8)); // bytes + self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * sizeof(uint16_t)); // bytes self->echo_buffer = m_malloc(self->max_echo_buffer_len); if (self->echo_buffer == NULL) { common_hal_audiodelays_echo_deinit(self); @@ -86,11 +86,11 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ // calculate current echo buffer size we use for the given delay mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); - self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * 2);// (self->bits_per_sample / 8)); + self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * sizeof(uint16_t)); // read is where we store the incoming sample + previous echo // write is what we send to the outgoing buffer - self->echo_buffer_read_pos = self->buffer_len / 2;// (self->bits_per_sample / 8); + self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); self->echo_buffer_write_pos = 0; } @@ -164,6 +164,9 @@ void audiodelays_echo_reset_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel) { + memset(self->buffer[0], 0, self->buffer_len); + memset(self->buffer[1], 0, self->buffer_len); + memset(self->echo_buffer, 0, self->max_echo_buffer_len); } bool common_hal_audiodelays_echo_get_playing(audiodelays_echo_obj_t *self) { @@ -201,6 +204,7 @@ void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sam // Track remaining sample length in terms of bytes per sample self->sample_buffer_length /= (self->bits_per_sample / 8); + // Store if we have more data in the sample to retrieve self->more_data = result == GET_BUFFER_MORE_DATA; return; @@ -213,10 +217,10 @@ void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self) { return; } -#define RANGE_LOW (-28000) -#define RANGE_HIGH (28000) -#define RANGE_SHIFT (16) -#define RANGE_SCALE (0xfffffff / (32768 * 4 - RANGE_HIGH)) +#define RANGE_LOW_16 (-28000) +#define RANGE_HIGH_16 (28000) +#define RANGE_SHIFT_16 (16) +#define RANGE_SCALE_16 (0xfffffff / (32768 * 2 - RANGE_HIGH_16)) // 2 for echo+sample // dynamic range compression via a downward compressor with hard knee // @@ -231,10 +235,10 @@ void common_hal_audiodelays_echo_stop(audiodelays_echo_obj_t *self) { // https://en.wikipedia.org/wiki/Dynamic_range_compression static int16_t mix_down_sample(int32_t sample) { - if (sample < RANGE_LOW) { - sample = (((sample - RANGE_LOW) * RANGE_SCALE) >> RANGE_SHIFT) + RANGE_LOW; - } else if (sample > RANGE_HIGH) { - sample = (((sample - RANGE_HIGH) * RANGE_SCALE) >> RANGE_SHIFT) + RANGE_HIGH; + if (sample < RANGE_LOW_16) { + sample = (((sample - RANGE_LOW_16) * RANGE_SCALE_16) >> RANGE_SHIFT_16) + RANGE_LOW_16; + } else if (sample > RANGE_HIGH_16) { + sample = (((sample - RANGE_HIGH_16) * RANGE_SCALE_16) >> RANGE_SHIFT_16) + RANGE_HIGH_16; } return sample; } @@ -249,20 +253,18 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * // Switch our buffers to the other buffer self->last_buf_idx = !self->last_buf_idx; - // If we are using 16 bit samples we need a 16 bit pointer + // If we are using 16 bit samples we need a 16 bit pointer, 8 bit needs an 8 bit pointer int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx]; int8_t *hword_buffer = self->buffer[self->last_buf_idx]; uint32_t length = self->buffer_len / (self->bits_per_sample / 8); // The echo buffer is always stored as a 16-bit value internally int16_t *echo_buffer = (int16_t *)self->echo_buffer; - uint32_t echo_buf_len = self->echo_buffer_len / 2;// (self->bits_per_sample / 8); - + uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint16_t); // Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample while (length != 0) { - - // Check if there is no more sample to play + // Check if there is no more sample to play, we will either load more data, reset the sample if loop is on or clear the sample if (self->sample_buffer_length == 0) { if (!self->more_data) { // The sample has indicated it has no more data to play if (self->loop && self->sample) { // If we are supposed to loop reset the sample to the start @@ -286,10 +288,15 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * if (self->samples_signed) { memset(word_buffer, 0, length * (self->bits_per_sample / 8)); } else { - memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); + // For unsigned samples set to the middle which is "quiet" + if (MP_LIKELY(self->bits_per_sample == 16)) { + memset(word_buffer, 32768, length * (self->bits_per_sample / 8)); + } else { + memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); + } } } else { - // Since we have no sample we can just iterate over the our entire remaining buffer + // Since we have no sample we can just iterate over the our entire remaining buffer and finish for (uint32_t i = 0; i < length; i++) { int16_t echo = echo_buffer[self->echo_buffer_read_pos++] * decay; echo_buffer[self->echo_buffer_write_pos++] = echo; @@ -319,12 +326,11 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * length = 0; } else { // we have a sample to play and echo - // Determine how many bytes we can process to our buffer, the less of the sample we have left and our buffer remaining uint32_t n = MIN(self->sample_buffer_length, length); - int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; - int8_t *sample_hsrc = (int8_t *)self->sample_remaining_buffer; + int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; // for 16-bit samples + int8_t *sample_hsrc = (int8_t *)self->sample_remaining_buffer; // for 8-bit samples if (mix <= 0.01) { // if mix is zero pure sample only for (uint32_t i = 0; i < n; i++) { @@ -343,20 +349,19 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * if (self->samples_signed) { sample_word = sample_hsrc[i]; } else { - // uint8_t s1 = sample_hsrc[i]; - // int8_t s2 = s1^0x80; - // sample_word = s2; - + // Be careful here changing from an 8 bit unsigned to signed into a 32-bit signed sample_word = (int8_t)(((uint8_t)sample_hsrc[i]) ^ 0x80); } } int32_t echo = echo_buffer[self->echo_buffer_read_pos++] * decay; int32_t word = echo + sample_word; + if (MP_LIKELY(self->bits_per_sample == 16)) { word = mix_down_sample(word); echo_buffer[self->echo_buffer_write_pos++] = (int16_t)word; } else { + // Do not have mix_down for 8 bit so just hard cap samples into 1 byte if (word > 127) { word = 127; } else if (word < -128) { @@ -372,7 +377,6 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } else { int8_t mixed = (sample_word * (1.0 - mix)) + (word * mix); - ; if (self->samples_signed) { hword_buffer[i] = mixed; } else { @@ -389,6 +393,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } + // Update the remaining length and the buffer positions based on how much we wrote into our buffer length -= n; word_buffer += n; hword_buffer += n; @@ -397,14 +402,19 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } + // Finally pass our buffer and length to the calling audio function *buffer = (uint8_t *)self->buffer[self->last_buf_idx]; *buffer_length = self->buffer_len; + + // Echo always returns more data but some effects may return GET_BUFFER_DONE or GET_BUFFER_ERROR (see audiocore/__init__.h) return GET_BUFFER_MORE_DATA; } void audiodelays_echo_get_buffer_structure(audiodelays_echo_obj_t *self, bool single_channel_output, bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing) { + // Return information about the effect's buffer (not the sample's) + // These are used by calling audio objects to determine how to handle the effect's buffer *single_buffer = false; *samples_signed = self->samples_signed; *max_buffer_length = self->buffer_len; From e1ca12269d0849f1b2b601b5bd7c2d7338644e25 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Mon, 30 Sep 2024 15:41:11 -0400 Subject: [PATCH 053/252] Remove comment abount resetting concerns -thanks @anecdata --- ports/espressif/common-hal/wifi/__init__.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index 9f574bcc6a8d..4d8c74245e67 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -200,12 +200,6 @@ void common_hal_wifi_init(bool user_initiated) { return; } // set the default lwip_local_hostname - // - // What happens if someone uses wifi.radio.hostname and then the - // interface is reset, I don't know if an interface reset is a thing - // but there is logic here to check for re-entry into the common_hal_wifi_init - // module. I would think we would want to carry the existing hostname across - // subsequent interface resets. char cpy_default_hostname[80]; uint8_t mac[6]; esp_wifi_get_mac(ESP_IF_WIFI_STA, mac); From d62a9847e226bda8e2ebe7d283b7720671e73862 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 30 Sep 2024 21:52:24 -0400 Subject: [PATCH 054/252] broadcom: restore reset_i2c() and special handling of two I2C ports --- ports/broadcom/common-hal/busio/I2C.c | 22 ++++++++++++++++++++++ ports/broadcom/common-hal/busio/I2C.h | 2 ++ ports/broadcom/supervisor/port.c | 2 ++ 3 files changed, 26 insertions(+) diff --git a/ports/broadcom/common-hal/busio/I2C.c b/ports/broadcom/common-hal/busio/I2C.c index 37d9758082c8..6a77cec08af8 100644 --- a/ports/broadcom/common-hal/busio/I2C.c +++ b/ports/broadcom/common-hal/busio/I2C.c @@ -23,8 +23,28 @@ static BSC0_Type *i2c[NUM_I2C] = {BSC0, BSC1, NULL, BSC3, BSC4, BSC5, BSC6, NULL static BSC0_Type *i2c[NUM_I2C] = {BSC0, BSC1, NULL}; #endif +static bool never_reset_i2c[NUM_I2C]; static bool i2c_in_use[NUM_I2C]; +void reset_i2c(void) { + // BSC2 is dedicated to the first HDMI output. + never_reset_i2c[2] = true; + i2c_in_use[2] = true; + #if BCM_VERSION == 2711 + // BSC7 is dedicated to the second HDMI output. + never_reset_i2c[7] = true; + i2c_in_use[7] = true; + #endif + for (size_t i = 0; i < NUM_I2C; i++) { + if (never_reset_i2c[i]) { + continue; + } + i2c_in_use[i] = false; + i2c[i]->C_b.I2CEN = false; + COMPLETE_MEMORY_READS; + } +} + void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { @@ -233,6 +253,8 @@ uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr, } void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + never_reset_i2c[self->index] = true; + common_hal_never_reset_pin(self->scl_pin); common_hal_never_reset_pin(self->sda_pin); } diff --git a/ports/broadcom/common-hal/busio/I2C.h b/ports/broadcom/common-hal/busio/I2C.h index feecbd0d7864..11416c0203fa 100644 --- a/ports/broadcom/common-hal/busio/I2C.h +++ b/ports/broadcom/common-hal/busio/I2C.h @@ -23,3 +23,5 @@ typedef struct { bool finish_write; uint8_t last_write_data; } busio_i2c_obj_t; + +void reset_i2c(void); diff --git a/ports/broadcom/supervisor/port.c b/ports/broadcom/supervisor/port.c index 54447d0d987c..33b20b7c8647 100644 --- a/ports/broadcom/supervisor/port.c +++ b/ports/broadcom/supervisor/port.c @@ -13,6 +13,7 @@ #include "genhdr/mpversion.h" #include "common-hal/rtc/RTC.h" +#include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" @@ -65,6 +66,7 @@ safe_mode_t port_init(void) { void reset_port(void) { #if CIRCUITPY_BUSIO + reset_i2c(); reset_spi(); reset_uart(); #endif From 3c204608f6dca6cea5147403c74b9205d6aed5e3 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 30 Sep 2024 21:23:45 -0500 Subject: [PATCH 055/252] Fixed incorrectly updating sample remaining pointer --- shared-module/audiodelays/Echo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index eb488ba9ed26..6607ff2aaacd 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -397,7 +397,7 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * length -= n; word_buffer += n; hword_buffer += n; - self->sample_remaining_buffer += n; + self->sample_remaining_buffer += (n * (self->bits_per_sample / 8)); self->sample_buffer_length -= n; } } From 2bf1ed7fed399acaaf347ff53243ccd598bb4538 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 1 Oct 2024 08:44:14 -0700 Subject: [PATCH 056/252] - Move SysTick init from board_init to port_init. - Fix RTC issue with interrupt_after_ticks. - Move LED inidcator to STATUS_LED code. --- ports/analog/Makefile | 2 +- ports/analog/boards/apard32690/README.md | 2 +- ports/analog/boards/apard32690/board.c | 18 ------- .../analog/boards/apard32690/mpconfigboard.h | 2 + ports/analog/boards/max32690evkit/board.c | 18 ------- .../boards/max32690evkit/mpconfigboard.h | 3 ++ ports/analog/supervisor/port.c | 52 ++++++++++--------- 7 files changed, 34 insertions(+), 63 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 766f0f78b930..79eb7a49052d 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -259,7 +259,7 @@ SRC_QSTR_PREPROCESSOR += # Default build target all: $(BUILD)/firmware.elf $(BUILD)/firmware.hex $(BUILD)/firmware.bin -clean-max32: +clean-all: rm -rf build-* # Optional flash option when running within an installed MSDK to use OpenOCD diff --git a/ports/analog/boards/apard32690/README.md b/ports/analog/boards/apard32690/README.md index 04f28ca4502b..3e8464854cb3 100644 --- a/ports/analog/boards/apard32690/README.md +++ b/ports/analog/boards/apard32690/README.md @@ -18,7 +18,7 @@ For more info about AD-APARD32690-SL, visit our product webpages for datasheets, To build for this board, ensure you are in the `ports/analog` directory and run the following command. Note that passing in the `-jN` flag, where N is the # of cores on your machine, can speed up compile times. ``` -make BOARD=APARD +make BOARD=apard32690 ``` #### Flashing this board diff --git a/ports/analog/boards/apard32690/board.c b/ports/analog/boards/apard32690/board.c index 3cc10de29f1e..cfef4bfcf61a 100644 --- a/ports/analog/boards/apard32690/board.c +++ b/ports/analog/boards/apard32690/board.c @@ -47,24 +47,6 @@ uint32_t board_millis(void) { // Initializes board related state once on start up. void board_init(void) { - // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000); \ - - // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { - MXC_GPIO_Init(0x1 << i); - } - - // Init Board LEDs - /* setup GPIO for the LED */ - for (int i = 0; i < num_leds; i++) { - // Set the output value - MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); - MXC_GPIO_Config(&led_pin[i]); - } - - // Turn on one LED to indicate Sign of Life - MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); } // Reset the state of off MCU components such as neopixels. diff --git a/ports/analog/boards/apard32690/mpconfigboard.h b/ports/analog/boards/apard32690/mpconfigboard.h index 0e09a4ede674..19b75a79d810 100644 --- a/ports/analog/boards/apard32690/mpconfigboard.h +++ b/ports/analog/boards/apard32690/mpconfigboard.h @@ -36,3 +36,5 @@ // #else // #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) // #endif + + #define MICROPY_HW_LED_STATUS (&pin_P2_01) diff --git a/ports/analog/boards/max32690evkit/board.c b/ports/analog/boards/max32690evkit/board.c index 76da5c0adccb..ebb8b2da35fc 100644 --- a/ports/analog/boards/max32690evkit/board.c +++ b/ports/analog/boards/max32690evkit/board.c @@ -46,24 +46,6 @@ uint32_t board_millis(void) { // Initializes board related state once on start up. void board_init(void) { - // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000); \ - - // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { - MXC_GPIO_Init(0x1 << i); - } - - // Init Board LEDs - /* setup GPIO for the LED */ - for (int i = 0; i < num_leds; i++) { - // Set the output value - MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); - MXC_GPIO_Config(&led_pin[i]); - } - - // Turn on one LED to indicate Sign of Life - MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); } // Reset the state of off MCU components such as neopixels. diff --git a/ports/analog/boards/max32690evkit/mpconfigboard.h b/ports/analog/boards/max32690evkit/mpconfigboard.h index 7ab6acf658d1..e4395e8a0ae7 100644 --- a/ports/analog/boards/max32690evkit/mpconfigboard.h +++ b/ports/analog/boards/max32690evkit/mpconfigboard.h @@ -36,3 +36,6 @@ // #else // #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) // #endif + +#define MICROPY_HW_LED_STATUS (&pin_P2_12) +#define MICROPY_HW_LED_STATUS_INVERTED 1 diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 1c068cb22c1d..6ef3b350744e 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -68,6 +68,9 @@ extern void NVIC_SystemReset(void) NORETURN; safe_mode_t port_init(void) { int err = E_NO_ERROR; + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000); + // Enable GPIO (enables clocks + common init for ports) for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { err = MXC_GPIO_Init(0x1 << i); @@ -122,12 +125,18 @@ void RTC_IRQHandler(void) { // Read flags to clear int flags = MXC_RTC_GetFlags(); - if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) { - MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); - } - - if (flags & MXC_F_RTC_CTRL_TOD_ALARM) { - MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); + switch (flags) { + case MXC_F_RTC_CTRL_SSEC_ALARM: + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); + break; + case MXC_F_RTC_CTRL_TOD_ALARM: + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); + break; + case MXC_F_RTC_CTRL_RDY: + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_RDY); + break; + default: + break; } tick_flag = 1; @@ -145,7 +154,7 @@ void reset_port(void) { } // Reset to the bootloader -// note: not implemented since max32 requires external stim ignals to +// note: not implemented since max32 requires external signals to // activate bootloaders void reset_to_bootloader(void) { NVIC_SystemReset(); @@ -193,7 +202,6 @@ uint32_t port_get_saved_word(void) { uint64_t port_get_raw_ticks(uint8_t *subticks) { // Ensure we can read from ssec register as soon as we can // MXC function does cross-tick / busy checking of RTC controller - __disable_irq(); if (MXC_RTC->ctrl & MXC_F_RTC_CTRL_EN) { // NOTE: RTC_GetTime always returns BUSY if RTC is not running while ((MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR) { @@ -203,7 +211,6 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { sec = MXC_RTC->sec; subsec = MXC_RTC->ssec; } - __enable_irq(); // Return ticks given total subseconds // ticks = TICKS/s * s + subsec/ subs/tick @@ -220,41 +227,36 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { // Enable 1/1024 second tick. void port_enable_tick(void) { - MXC_RTC_Start(); + while ( MXC_RTC_Start() == E_BUSY ); } // Disable 1/1024 second tick. void port_disable_tick(void) { - MXC_RTC_Stop(); + while( MXC_RTC_Stop() == E_BUSY ); } // Wake the CPU after a given # of ticks or sooner void port_interrupt_after_ticks(uint32_t ticks) { uint32_t ticks_msec = 0; - // Stop RTC & store current time & ticks - port_disable_tick(); - port_get_raw_ticks(NULL); - ticks_msec = 1000 * ticks / TICKS_PER_SEC; + ticks_msec = (ticks / TICKS_PER_SEC) * 1000; - while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | - MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { - } - ; + // Disable RTC interrupts + MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | + MXC_F_RTC_CTRL_TOD_ALARM_IE | MXC_F_RTC_CTRL_RDY_IE); + + // Stop RTC & store current time & ticks + port_get_raw_ticks(NULL); // Clear the flag to be set by the RTC Handler tick_flag = 0; // Subsec alarm is the starting/reload value of the SSEC counter. // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0 - while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) == E_BUSY) { - } - while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) { - } + while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) != E_SUCCESS) {} - NVIC_EnableIRQ(RTC_IRQn); + MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); - port_enable_tick(); } void port_idle_until_interrupt(void) { From f030c37a14269aabf241858a5e38586ccc571720 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 1 Oct 2024 18:25:39 -0400 Subject: [PATCH 057/252] espressif/common-hal/_bleio/Characteristic.c: handle empty initial value --- .../common-hal/_bleio/Characteristic.c | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/ports/espressif/common-hal/_bleio/Characteristic.c b/ports/espressif/common-hal/_bleio/Characteristic.c index 34f221ac9bf5..6b842ad298cd 100644 --- a/ports/espressif/common-hal/_bleio/Characteristic.c +++ b/ports/espressif/common-hal/_bleio/Characteristic.c @@ -75,17 +75,23 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, self->flags |= BLE_GATT_CHR_F_WRITE_AUTHEN; } - if (gc_alloc_possible()) { - self->current_value = m_malloc(max_length); - } else { - self->current_value = port_malloc(max_length, false); - if (self->current_value == NULL) { - reset_into_safe_mode(SAFE_MODE_NO_HEAP); + // If max_length is 0, then no storage is allocated. + if (max_length > 0) { + if (gc_alloc_possible()) { + self->current_value = m_malloc(max_length); + } else { + self->current_value = port_malloc(max_length, false); + if (self->current_value == NULL) { + reset_into_safe_mode(SAFE_MODE_NO_HEAP); + } } } self->current_value_alloc = max_length; self->current_value_len = 0; + self->max_length = max_length; + self->fixed_length = fixed_length; + if (initial_value_bufinfo != NULL) { common_hal_bleio_characteristic_set_value(self, initial_value_bufinfo); } @@ -96,9 +102,6 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, self->descriptor_list = NULL; } - self->max_length = max_length; - self->fixed_length = fixed_length; - if (service->is_remote) { // If the service is remote, we're buffering incoming notifications and indications. self->handle = handle; @@ -109,23 +112,25 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, } bool common_hal_bleio_characteristic_deinited(bleio_characteristic_obj_t *self) { - return self->current_value == NULL; + return self->handle == BLEIO_HANDLE_INVALID; } void common_hal_bleio_characteristic_deinit(bleio_characteristic_obj_t *self) { if (common_hal_bleio_characteristic_deinited(self)) { return; } - if (self->current_value == NULL) { - return; - } + if (self->current_value != NULL) { + if (gc_nbytes(self->current_value) > 0) { + m_free(self->current_value); + } else { + port_free(self->current_value); + } - if (gc_nbytes(self->current_value) > 0) { - m_free(self->current_value); - } else { - port_free(self->current_value); + self->current_value = NULL; } - self->current_value = NULL; + + // Used to indicate deinit. + self->handle = BLEIO_HANDLE_INVALID; } mp_obj_tuple_t *common_hal_bleio_characteristic_get_descriptors(bleio_characteristic_obj_t *self) { @@ -172,7 +177,6 @@ void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, } } else { // Validate data length for local characteristics only. - // TODO: Test this once we can get servers going. if (self->fixed_length && bufinfo->len != self->max_length) { mp_raise_ValueError(MP_ERROR_TEXT("Value length != required fixed length")); } From a7f700e2d65cca10ff2fdd184f4f6a7693277b3d Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 1 Oct 2024 18:50:39 -0400 Subject: [PATCH 058/252] Optimize hostname variable size --- ports/espressif/common-hal/wifi/__init__.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index 4d8c74245e67..6b98db01938b 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -16,8 +16,6 @@ #include "py/gc.h" #include "py/mpstate.h" #include "py/runtime.h" -#include "py/objstr.h" -#include "py/objint.h" #include "components/esp_wifi/include/esp_wifi.h" @@ -42,6 +40,8 @@ wifi_radio_obj_t common_hal_wifi_radio_obj; #include "nvs_flash.h" #endif +#define MAC_ADDRESS_LENGTH 6 + static const char *TAG = "CP wifi"; static void schedule_background_on_cp_core(void *arg) { @@ -200,8 +200,8 @@ void common_hal_wifi_init(bool user_initiated) { return; } // set the default lwip_local_hostname - char cpy_default_hostname[80]; - uint8_t mac[6]; + char cpy_default_hostname[strlen(CIRCUITPY_BOARD_ID)+(MAC_ADDRESS_LENGTH*2)+6]; + uint8_t mac[MAC_ADDRESS_LENGTH]; esp_wifi_get_mac(ESP_IF_WIFI_STA, mac); sprintf(cpy_default_hostname, "cpy_%s_%x", CIRCUITPY_BOARD_ID, (unsigned int)mac); const char *default_lwip_local_hostname = cpy_default_hostname; From 923741c07d2752bf6017c7b409026ffa2a58968d Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 1 Oct 2024 19:00:38 -0400 Subject: [PATCH 059/252] pre-commit formatting --- ports/espressif/common-hal/wifi/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index 6b98db01938b..c0d547cc08fe 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -200,7 +200,7 @@ void common_hal_wifi_init(bool user_initiated) { return; } // set the default lwip_local_hostname - char cpy_default_hostname[strlen(CIRCUITPY_BOARD_ID)+(MAC_ADDRESS_LENGTH*2)+6]; + char cpy_default_hostname[strlen(CIRCUITPY_BOARD_ID) + (MAC_ADDRESS_LENGTH * 2) + 6]; uint8_t mac[MAC_ADDRESS_LENGTH]; esp_wifi_get_mac(ESP_IF_WIFI_STA, mac); sprintf(cpy_default_hostname, "cpy_%s_%x", CIRCUITPY_BOARD_ID, (unsigned int)mac); From 156d7a87d12bcfad39e4fb948d4536455126c858 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 1 Oct 2024 19:55:02 -0400 Subject: [PATCH 060/252] remove hostname from sdkconfig of newly added board --- ports/espressif/boards/sunton_esp32_8048S050/sdkconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/espressif/boards/sunton_esp32_8048S050/sdkconfig b/ports/espressif/boards/sunton_esp32_8048S050/sdkconfig index 71012f46188a..e96286621603 100644 --- a/ports/espressif/boards/sunton_esp32_8048S050/sdkconfig +++ b/ports/espressif/boards/sunton_esp32_8048S050/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_LWIP_LOCAL_HOSTNAME="sunton-esp32-8048S050" # end of LWIP # end of Component config From 4f87c178fb5c3e9903fb71ed0a09a78a7d1c5819 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 1 Oct 2024 17:00:33 -0700 Subject: [PATCH 061/252] - Changed board.c to match silkscreen. - Added digitalio handling for GPIO Port 4 (different on MAX32690). - Added MCR defs to max32_port.h. --- ports/analog/boards/apard32690/pins.c | 91 ++++++++------- ports/analog/boards/max32690evkit/pins.c | 89 +++++++------- .../common-hal/digitalio/DigitalInOut.c | 110 +++++++++++++----- ports/analog/max32_port.h | 29 +++++ 4 files changed, 203 insertions(+), 116 deletions(-) diff --git a/ports/analog/boards/apard32690/pins.c b/ports/analog/boards/apard32690/pins.c index 0486687d3347..f4970aff7aeb 100644 --- a/ports/analog/boards/apard32690/pins.c +++ b/ports/analog/boards/apard32690/pins.c @@ -10,16 +10,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS // P0 - { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, - { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, - { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, - { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, - { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, - { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, - { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, - { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, - { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, - { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P0_0), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_P0_1), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_P0_2), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P0_3), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P0_4), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P0_5), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P0_6), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P0_7), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P0_8), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P0_9), MP_ROM_PTR(&pin_P0_09) }, { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, @@ -43,16 +43,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, // P1 - { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, - { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, - { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, - { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, - { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, - { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, - { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, - { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, - { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, - { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_P1_0), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_P1_1), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_P1_2), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_P1_3), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_P1_4), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_P1_5), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_P1_6), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_P1_7), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_P1_8), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_P1_9), MP_ROM_PTR(&pin_P1_09) }, { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, @@ -76,16 +76,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, // P2 - { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, - { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, - { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, - { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, - { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, - { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, - { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, - { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, - { MP_ROM_QSTR(MP_QSTR_P2_08), MP_ROM_PTR(&pin_P2_08) }, - { MP_ROM_QSTR(MP_QSTR_P2_09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_P2_0), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_P2_1), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_P2_2), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_P2_3), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_P2_4), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_P2_5), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_P2_6), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_P2_7), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_P2_8), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_P2_9), MP_ROM_PTR(&pin_P2_09) }, { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, @@ -109,18 +109,25 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, // P3 - { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, - { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, - { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, - { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, - { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, - { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, - { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, - { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, - { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, - { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, + { MP_ROM_QSTR(MP_QSTR_P3_0), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_P3_1), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_P3_2), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_P3_3), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_P3_4), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_P3_5), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_P3_6), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_P3_7), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_P3_8), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_P3_9), MP_ROM_PTR(&pin_P3_09) }, // P4 - { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, - { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, + { MP_ROM_QSTR(MP_QSTR_P4_0), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_P4_1), MP_ROM_PTR(&pin_P4_01) }, + + // Silkscreen aliases + { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_S2), MP_ROM_PTR(&pin_P1_27) }, + }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/analog/boards/max32690evkit/pins.c b/ports/analog/boards/max32690evkit/pins.c index 0486687d3347..3270e4d62b2a 100644 --- a/ports/analog/boards/max32690evkit/pins.c +++ b/ports/analog/boards/max32690evkit/pins.c @@ -10,16 +10,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS // P0 - { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, - { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, - { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, - { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, - { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, - { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, - { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, - { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, - { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, - { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P0_0), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_P0_1), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_P0_2), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P0_3), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P0_4), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P0_5), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P0_6), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P0_7), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P0_8), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P0_9), MP_ROM_PTR(&pin_P0_09) }, { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, @@ -43,16 +43,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, // P1 - { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, - { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, - { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, - { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, - { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, - { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, - { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, - { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, - { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, - { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_P1_0), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_P1_1), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_P1_2), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_P1_3), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_P1_4), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_P1_5), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_P1_6), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_P1_7), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_P1_8), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_P1_9), MP_ROM_PTR(&pin_P1_09) }, { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, @@ -76,16 +76,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, // P2 - { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, - { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, - { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, - { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, - { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, - { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, - { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, - { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, - { MP_ROM_QSTR(MP_QSTR_P2_08), MP_ROM_PTR(&pin_P2_08) }, - { MP_ROM_QSTR(MP_QSTR_P2_09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_P2_0), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_P2_1), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_P2_2), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_P2_3), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_P2_4), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_P2_5), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_P2_6), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_P2_7), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_P2_8), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_P2_9), MP_ROM_PTR(&pin_P2_09) }, { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, @@ -109,18 +109,23 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, // P3 - { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, - { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, - { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, - { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, - { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, - { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, - { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, - { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, - { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, - { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, + { MP_ROM_QSTR(MP_QSTR_P3_0), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_P3_1), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_P3_2), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_P3_3), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_P3_4), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_P3_5), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_P3_6), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_P3_7), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_P3_8), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_P3_9), MP_ROM_PTR(&pin_P3_09) }, // P4 - { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, - { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, + { MP_ROM_QSTR(MP_QSTR_P4_0), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_P4_1), MP_ROM_PTR(&pin_P4_01) }, + + // Board silkscreen Aliases + { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P2_12) }, + { MP_ROM_QSTR(MP_QSTR_PB0), MP_ROM_PTR(&pin_P4_00) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index 166021b44128..c5d8bbd508db 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -8,7 +8,9 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/microcontroller/Pin.h" +#include "max32_port.h" #include "gpio_reva.h" +#include "mxc_errors.h" extern mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS]; @@ -53,8 +55,19 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + int err=E_NO_ERROR; - MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); + if (self->pin->port == 4) { + // Set GPIO(s) to input mode + MXC_MCR->gpio4_ctrl &= ~GPIO4_OUTEN_MASK(mask); + MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); + } + else { + err = MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); + } + if (err != E_NO_ERROR) { + return DIGITALINOUT_PIN_BUSY; + } return common_hal_digitalio_digitalinout_set_pull(self, pull); } @@ -64,7 +77,14 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); + if (self->pin->port == 4) { + // Set GPIO(s) to output mode + MXC_MCR->gpio4_ctrl |= GPIO4_OUTEN_MASK(mask); + MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); + } + else { + MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); + } common_hal_digitalio_digitalinout_set_value(self, value); // todo (low): MSDK Hardware does not support open-drain configuration except @@ -82,17 +102,27 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - // Check that I/O mode is enabled and we don't have in AND out on at the same time - MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask))); + if (self->pin->port < 4) { + // Check that I/O mode is enabled and we don't have in AND out on at the same time + MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask))); - if ((port->en0 & mask) && (port->outen & mask)) { - return DIRECTION_OUTPUT; - } else if ((port->en0 & mask) && (port->inen & mask)) { - return DIRECTION_INPUT; + if ((port->en0 & mask) && (port->outen & mask)) { + return DIRECTION_OUTPUT; + } else if ((port->en0 & mask) && (port->inen & mask)) { + return DIRECTION_INPUT; + } + // do not try to drive a pin which has an odd configuration here + else { + return DIRECTION_INPUT; + } } - // do not try to drive a pin which has an odd configuration here else { - return DIRECTION_INPUT; + if (MXC_MCR->gpio4_ctrl & GPIO4_OUTEN_MASK(mask)) { + return DIRECTION_OUTPUT; + } + else { + return DIRECTION_INPUT; + } } } @@ -121,15 +151,22 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s uint32_t mask = self->pin->mask; if (dir == DIRECTION_INPUT) { - return MXC_GPIO_InGet(port, mask); + if (self->pin->port == 4) { + return (bool)(MXC_MCR->gpio4_ctrl & GPIO4_DATAIN_MASK(mask)); + } + return (MXC_GPIO_InGet(port, mask) && mask); } else { - return (port->out & mask) == true; + return (MXC_GPIO_OutGet(port, mask) && mask); } } +/** FIXME: Implement open-drain by switching to input WITHOUT re-labeling the pin */ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) { + if (drive_mode == DRIVE_MODE_OPEN_DRAIN) { + common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); + } // On MAX32, drive mode is not configurable // and should always be push-pull unless managed by a peripheral like I2C return DIGITALINOUT_OK; @@ -146,30 +183,39 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - if ((port->en0 & mask) && (port->inen & mask)) { - // PULL_NONE, PULL_UP, or PULL_DOWN - switch (pull) { - case PULL_NONE: - port->padctrl0 &= ~(mask); - port->padctrl1 &= ~(mask); - break; - case PULL_UP: - port->padctrl0 |= mask; - port->padctrl1 &= ~(mask); - break; - case PULL_DOWN: - port->padctrl0 &= ~(mask); - port->padctrl1 |= mask; - break; - default: - break; - } + // padctrl registers only work in input mode + if (self->pin->port == 4) { + MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); return DIGITALINOUT_OK; - } else { - return DIGITALINOUT_PIN_BUSY; + } + else { + if ((mask & port->en0) & (mask & ~(port->outen))) { + // PULL_NONE, PULL_UP, or PULL_DOWN + switch (pull) { + case PULL_NONE: + port->padctrl0 &= ~(mask); + port->padctrl1 &= ~(mask); + break; + case PULL_UP: + port->padctrl0 |= mask; + port->padctrl1 &= ~(mask); + break; + case PULL_DOWN: + port->padctrl0 &= ~(mask); + port->padctrl1 |= mask; + break; + default: + break; + } + return DIGITALINOUT_OK; + } + else { + return DIGITALINOUT_PIN_BUSY; + } } } +/** FIXME: Account for GPIO4 handling here */ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( digitalio_digitalinout_obj_t *self) { diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index fe6d5e157fea..8781bd56238b 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -14,12 +14,41 @@ #include "mxc_device.h" #include "mxc_pins.h" #include "mxc_sys.h" +#include "mcr_regs.h" #include "gpio.h" #ifdef MAX32690 #include "system_max32690.h" #include "max32690.h" + +/** START: GPIO4 Handling specific to MAX32690 */ +#define GPIO4_PIN_MASK 0x00000003 +#define GPIO4_RESET_MASK 0xFFFFFF77 +#define GPIO4_OUTEN_MASK(mask) \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1))) +#define GPIO4_PULLDIS_MASK(mask) \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1))) +#define GPIO4_DATAOUT_MASK(mask) \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) +#define GPIO4_DATAOUT_GET_MASK(mask) \ + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \ + (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \ + mask) +#define GPIO4_DATAIN_MASK(mask) \ + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ + ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ + (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \ + mask) +#define GPIO4_AFEN_MASK(mask) \ + (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ + ((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1))) +/** END: GPIO4 Handling specific to MAX32690 */ + #endif /** Linker variables defined.... From 1c0122bf8d6d4a0b86af5eb849266975cb6d6d99 Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Tue, 1 Oct 2024 17:29:45 -0700 Subject: [PATCH 062/252] pre-commit formatting fixes --- .../common-hal/digitalio/DigitalInOut.c | 33 +++++++------------ ports/analog/max32_port.h | 32 +++++++++--------- ports/analog/supervisor/port.c | 11 +++++-- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index c5d8bbd508db..3861900d81cd 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -55,14 +55,13 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - int err=E_NO_ERROR; + int err = E_NO_ERROR; if (self->pin->port == 4) { // Set GPIO(s) to input mode MXC_MCR->gpio4_ctrl &= ~GPIO4_OUTEN_MASK(mask); MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); - } - else { + } else { err = MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); } if (err != E_NO_ERROR) { @@ -81,8 +80,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( // Set GPIO(s) to output mode MXC_MCR->gpio4_ctrl |= GPIO4_OUTEN_MASK(mask); MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); - } - else { + } else { MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); } common_hal_digitalio_digitalinout_set_value(self, value); @@ -110,17 +108,14 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( return DIRECTION_OUTPUT; } else if ((port->en0 & mask) && (port->inen & mask)) { return DIRECTION_INPUT; - } - // do not try to drive a pin which has an odd configuration here - else { + // do not try to drive a pin which has an odd configuration here + } else { return DIRECTION_INPUT; } - } - else { + } else { if (MXC_MCR->gpio4_ctrl & GPIO4_OUTEN_MASK(mask)) { return DIRECTION_OUTPUT; - } - else { + } else { return DIRECTION_INPUT; } } @@ -154,9 +149,9 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s if (self->pin->port == 4) { return (bool)(MXC_MCR->gpio4_ctrl & GPIO4_DATAIN_MASK(mask)); } - return (MXC_GPIO_InGet(port, mask) && mask); + return MXC_GPIO_InGet(port, mask) && mask; } else { - return (MXC_GPIO_OutGet(port, mask) && mask); + return MXC_GPIO_OutGet(port, mask) && mask; } } @@ -187,8 +182,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( if (self->pin->port == 4) { MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); return DIGITALINOUT_OK; - } - else { + } else { if ((mask & port->en0) & (mask & ~(port->outen))) { // PULL_NONE, PULL_UP, or PULL_DOWN switch (pull) { @@ -208,8 +202,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( break; } return DIGITALINOUT_OK; - } - else { + } else { return DIGITALINOUT_PIN_BUSY; } } @@ -228,9 +221,7 @@ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( return PULL_DOWN; } else if (!(pin_padctrl0) && !(pin_padctrl1)) { return PULL_NONE; - } - // Shouldn't happen, (value 0b11 is reserved) - else { + } else { return PULL_NONE; } } diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index 8781bd56238b..64c6915aa68d 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -26,27 +26,27 @@ #define GPIO4_PIN_MASK 0x00000003 #define GPIO4_RESET_MASK 0xFFFFFF77 #define GPIO4_OUTEN_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ - ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1))) + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1))) #define GPIO4_PULLDIS_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ - ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1))) + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1))) #define GPIO4_DATAOUT_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ - ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) #define GPIO4_DATAOUT_GET_MASK(mask) \ - ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ - ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \ - (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \ - mask) + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \ + (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1)))& \ + mask) #define GPIO4_DATAIN_MASK(mask) \ - ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ - ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ - (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \ - mask) + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ + ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ + (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1)))& \ + mask) #define GPIO4_AFEN_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ - ((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1))) + (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ + ((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1))) /** END: GPIO4 Handling specific to MAX32690 */ #endif diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 6ef3b350744e..cdbf88d2528d 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -227,12 +227,16 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { // Enable 1/1024 second tick. void port_enable_tick(void) { - while ( MXC_RTC_Start() == E_BUSY ); + while (MXC_RTC_Start() == E_BUSY) { + ; + } } // Disable 1/1024 second tick. void port_disable_tick(void) { - while( MXC_RTC_Stop() == E_BUSY ); + while (MXC_RTC_Stop() == E_BUSY) { + ; + } } // Wake the CPU after a given # of ticks or sooner @@ -253,7 +257,8 @@ void port_interrupt_after_ticks(uint32_t ticks) { // Subsec alarm is the starting/reload value of the SSEC counter. // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0 - while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) != E_SUCCESS) {} + while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) != E_SUCCESS) { + } MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); From af9321777d97d93712ba80cda4501410e0ea3f4f Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Tue, 1 Oct 2024 19:44:55 -0500 Subject: [PATCH 063/252] Documentation --- shared-bindings/audiodelays/Echo.c | 67 +++++++++++++++++++++++------- shared-module/audiodelays/Echo.c | 2 +- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 0119b15690f6..2704a2972fcf 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -21,10 +21,55 @@ //| class Echo: //| """An Echo effect""" //| +//| def __init__( +//| self, +//| max_delay_ms: int = 500, +//| delay_ms: BlockInput = 250.0, +//| decay: BlockInput = 0.7, +//| mix: BlockInput = 0.5, +//| buffer_size: int = 512, +//| sample_rate: int = 8000, +//| bits_per_sample: int = 16, +//| samples_signed: bool = True, +//| channel_count: int = 1, +//| ) -> None: +//| """Create a Echo effect that echos an audio sample every set number of microseconds. +//| +//| :param int max_delay_ms: The maximum delay the echo can be +//| :param BlockInput delay_ms: The current echo delay +//| :param BlockInput decay: The rate the echo fades. 0.0 = instant; 1.0 = never. +//| :param BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). +//| :param int buffer_size: The total size in bytes of the buffers to use +//| :param int sample_rate: The sample rate to be used +//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo. +//| :param int bits_per_sample: The bits per sample of the effect +//| :param bool samples_signed: Effect is signed (True) or unsigned (False) +//| +//| Playing adding an echo to a synth:: +//| +//| import time +//| import board +//| import audiobusio +//| import synthio +//| import audiodelays +//| +//| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22) +//| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100) +//| echo = audiodelays.Echo(max_delay_ms=1000, delay_ms=850, decay=0.65, buffer_size=1024, channel_count=1, sample_rate=44100, mix=0.7) +//| echo.play(synth) +//| audio.play(echo) +//| +//| note = synthio.Note(261) +//| while True: +//| synth.press(note) +//| time.sleep(0.25) +//| synth.release(note) +//| time.sleep(5)""" +//| ... static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_max_delay_ms, ARG_delay_ms, ARG_decay, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_max_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 50 } }, + { MP_QSTR_max_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 500 } }, { MP_QSTR_delay_ms, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_decay, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, @@ -54,7 +99,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar } //| def deinit(self) -> None: -//| """Deinitialises the Echo and releases any hardware resources for reuse.""" +//| """Deinitialises the Echo.""" //| ... static mp_obj_t audiodelays_echo_deinit(mp_obj_t self_in) { audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -75,7 +120,7 @@ static void check_for_deinit(audiodelays_echo_obj_t *self) { // Provided by context manager helper. //| def __exit__(self) -> None: -//| """Automatically deinitializes the hardware when exiting a context. See +//| """Automatically deinitializes when exiting a context. See //| :ref:`lifetime-and-contextmanagers` for more info.""" //| ... static mp_obj_t audiodelays_echo_obj___exit__(size_t n_args, const mp_obj_t *args) { @@ -117,7 +162,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_delay_ms_obj, (mp_obj_t)&audiodelays_echo_set_delay_ms_obj); //| decay: BlockInput -//| """The rate the echo decays between 0 and 1.""" +//| """The rate the echo decays between 0 and 1 where 1 is forever and 0 is no echo.""" static mp_obj_t audiodelays_echo_obj_get_decay(mp_obj_t self_in) { return common_hal_audiodelays_echo_get_decay(self_in); } @@ -143,7 +188,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_decay_obj, (mp_obj_t)&audiodelays_echo_set_decay_obj); //| mix: BlockInput -//| """The rate the echo mix between 0 and 1.""" +//| """The rate the echo mix between 0 and 1 where 0 is only sample and 1 is all effect.""" static mp_obj_t audiodelays_echo_obj_get_mix(mp_obj_t self_in) { return common_hal_audiodelays_echo_get_mix(self_in); } @@ -168,10 +213,8 @@ MP_PROPERTY_GETSET(audiodelays_echo_mix_obj, (mp_obj_t)&audiodelays_echo_get_mix_obj, (mp_obj_t)&audiodelays_echo_set_mix_obj); - - //| playing: bool -//| """True when any voice is being output. (read-only)""" +//| """True when the effect is playing a sample. (read-only)""" static mp_obj_t audiodelays_echo_obj_get_playing(mp_obj_t self_in) { audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); @@ -188,9 +231,7 @@ MP_PROPERTY_GETTER(audiodelays_echo_playing_obj, //| """Plays the sample once when loop=False and continuously when loop=True. //| Does not block. Use `playing` to block. //| -//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, `audiomixer.Mixer` or `audiomp3.MP3Decoder`. -//| -//| The sample must match the Effect's encoding settings given in the constructor.""" +//| The sample must match the encoding settings given in the constructor.""" //| ... static mp_obj_t audiodelays_echo_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_sample, ARG_loop }; @@ -212,7 +253,7 @@ static mp_obj_t audiodelays_echo_obj_play(size_t n_args, const mp_obj_t *pos_arg MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_play_obj, 1, audiodelays_echo_obj_play); //| def stop(self) -> None: -//| """Stops playback of the sample.""" +//| """Stops playback of the sample. The echo continues playing.""" //| ... //| static mp_obj_t audiodelays_echo_obj_stop(mp_obj_t self_in) { @@ -223,8 +264,6 @@ static mp_obj_t audiodelays_echo_obj_stop(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_stop_obj, audiodelays_echo_obj_stop); - - static const mp_rom_map_elem_t audiodelays_echo_locals_dict_table[] = { // Methods { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiodelays_echo_deinit_obj) }, diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 6607ff2aaacd..515317fb7cb8 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -61,7 +61,7 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ synthio_block_assign_slot(decay, &self->decay, MP_QSTR_decay); if (delay_ms == MP_OBJ_NULL) { - delay_ms = mp_obj_new_float(500.0); + delay_ms = mp_obj_new_float(250.0); } synthio_block_assign_slot(delay_ms, &self->delay_ms, MP_QSTR_delay_ms); From 8114191ee237aed2928a2187542d39b7063ae483 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 1 Oct 2024 18:01:45 -0700 Subject: [PATCH 064/252] more pre-commit fixes --- ports/analog/max32_port.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index 64c6915aa68d..c464dabb2844 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -26,26 +26,26 @@ #define GPIO4_PIN_MASK 0x00000003 #define GPIO4_RESET_MASK 0xFFFFFF77 #define GPIO4_OUTEN_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1))) #define GPIO4_PULLDIS_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1))) #define GPIO4_DATAOUT_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) #define GPIO4_DATAOUT_GET_MASK(mask) \ - ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \ - (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1)))& \ + (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \ mask) #define GPIO4_DATAIN_MASK(mask) \ ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ - (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1)))& \ + (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \ mask) #define GPIO4_AFEN_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ + (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ ((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1))) /** END: GPIO4 Handling specific to MAX32690 */ From e9f9d915fcb39f328cb48a497a1cc5d37b1af2ea Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 1 Oct 2024 18:04:19 -0700 Subject: [PATCH 065/252] final pre-commit fix --- ports/analog/max32_port.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index c464dabb2844..5d92fcfe6d3e 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -40,7 +40,7 @@ (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \ mask) #define GPIO4_DATAIN_MASK(mask) \ - ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \ mask) From 02baf37c5f3df9d60d0e1d0fe09a95bb8dcde7df Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Wed, 2 Oct 2024 09:16:25 -0700 Subject: [PATCH 066/252] Fix CI run issues with docs & tlsf submodule --- ports/analog/README.md | 10 +++++----- ports/analog/boards/apard32690/README.md | 8 ++++---- tools/ci_fetch_deps.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ports/analog/README.md b/ports/analog/README.md index e2bd38b66472..39d8db098dd0 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -2,7 +2,7 @@ This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. These devices are mostly ARM Cortex-M4-based and focus on delivering performance at low-power levels. Currently this port only supports MAX32690. -### Structure of this port +## Structure of this port - **`boards/:`** Board-specific definitions including pins, board initialization, etc. - **`common-hal/:`** Port-specific implementations of CircuitPython common-hal APIs. When a new module is enabled, this is often where the implementation is found. Expected functions for modules in `common-hal` are usually found in `shared-bindings/` or `shared-module/` in the CircuitPy root directory. @@ -14,7 +14,7 @@ This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. Thes - `. :` Build system and high-level interface to the CircuitPython core for the ADI port. -### Building for MAX32 devices +## Building for MAX32 devices Ensure CircuitPython dependencies are up-to-date by following the CircuitPython introduction on Adafruit's Website: [Building CircuitPython - Introduction](https://learn.adafruit.com/building-circuitpython/introduction). In particular, it is necessary to fetch all submodules (including the ARM Toolchain inside MSDK) and build the `mpy-cross` compiler. @@ -32,7 +32,7 @@ Once you have built `mpy-cross` and set up your build system for CircuitPython, Be aware the build may take a long time without parallelizing via the `-jN` flag, where N is the # of cores on your machine. -### Flashing the board +## Flashing the board Universal instructions on flashing MAX32 devices this project can be found in the **[MSDK User Guide](https://analogdevicesinc.github.io/msdk/USERGUIDE/)**. @@ -48,11 +48,11 @@ This requires the following: - The PICO board is connected to the target board via a 10-pin SWD ribbon cable. - If SWD connectors are not keyed, the P1 indicator (red line) on the SWD ribbon cable should match the P1 indicator on the board silkscreen near the 10-pin SWD connector. -### Using the REPL +## Using the REPL Once the device is plugged in, it will enumerate via USB as both a USB Serial Device (CDC) and a Mass Storage Device (MSC). You can connect to the Python REPL with your favorite Serial Monitor program e.g. TeraTerm, VS Code, Putty, etc. Use any buadrate with 8-bit, No Parity, 1 Stop Bit (8N1) settings. From this point forward, you can run Python code on the MCU! If you want help with learning CircuitPython-specific code or learning Python in general, a good place to start is Adafruit's ["Welcome to CircuitPython"](https://learn.adafruit.com/welcome-to-circuitpython/) guide. -### Editing code.py +## Editing code.py Python code may be executed from `code.py` the `CIRCUITPY:` drive. When editing this file, please be aware that some text editors will work better than others. A list of suggested text editors can be found at Adafruit's guide here: https://learn.adafruit.com/welcome-to-circuitpython/recommended-editors diff --git a/ports/analog/boards/apard32690/README.md b/ports/analog/boards/apard32690/README.md index 3e8464854cb3..960a26a007f2 100644 --- a/ports/analog/boards/apard32690/README.md +++ b/ports/analog/boards/apard32690/README.md @@ -2,18 +2,18 @@ This board features the MAX32690, a dual-core ARM Cortex-M4/RISC-V MCU with 3MiB Flash, 1MiB SRAM. The board also has support for 10BASE-T1L Ethernet, Wifi, Bluetooth, USB, and Security via MAXQ1065. However, most of these features are not yet available for this CircuitPython port (USB will be added soon; others are currently unplanned). -### Onboard connectors & peripherals +## Onboard connectors & peripherals This board comes in a form-factor similar to an Arduino Mega, enabling Arduino-style shield boards to be plugged in and evaluated with the MAX32690. This vastly opens up the options for easily plugging peripherals into the board, especially when combined with the two Pmod:tm: connectors, P8 (SPI) and P13 (I2C). -### Product Resources +## Product Resources For more info about AD-APARD32690-SL, visit our product webpages for datasheets, User Guides, Software, and Design Documents: [AD-APARD32690-SL Product Webpage](https://www.analog.com/en/resources/evaluation-hardware-and-software/evaluation-boards-kits/ad-apard32690-sl.html) [AD-APARD32690-SL User Guide](https://wiki.analog.com/resources/eval/user-guides/ad-apard32690-sl) -#### Building for this board +### Building for this board To build for this board, ensure you are in the `ports/analog` directory and run the following command. Note that passing in the `-jN` flag, where N is the # of cores on your machine, can speed up compile times. @@ -21,7 +21,7 @@ To build for this board, ensure you are in the `ports/analog` directory and run make BOARD=apard32690 ``` -#### Flashing this board +### Flashing this board To flash the board, run the following command if using the MAX32625PICO: diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index 778a90c31b63..a06631bb307e 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -48,7 +48,7 @@ def matching_submodules(s): PORT_DEPS = { "analog": [ "extmod/ulab/", - "/lib/tlsf/", + "lib/tlsf/", "lib/tinyusb/", "lib/protomatter", ], From 7570a75b724e5ac1a47e7fbe921026732cf7dc45 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Wed, 2 Oct 2024 10:18:13 -0700 Subject: [PATCH 067/252] - Add elf target for CI build. - Add ports/analog/README to toctree for Sphinx docs. --- docs/supported_ports.rst | 1 + ports/analog/mpconfigport.mk | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/supported_ports.rst b/docs/supported_ports.rst index 69eaa5ef1489..41f872864791 100644 --- a/docs/supported_ports.rst +++ b/docs/supported_ports.rst @@ -12,6 +12,7 @@ Additional testing is limited. .. toctree:: :maxdepth: 2 + ../ports/analog/README ../ports/atmel-samd/README ../ports/broadcom/README ../ports/cxd56/README diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 348d61dc2892..1b9655c7f33c 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -60,10 +60,13 @@ CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 CIRCUITPY_PIXELBUF ?= 0 #################################################################################### -# Required for clean building (additional CircuittPython Defaults) +# Required for clean building (additional CircuitPython Defaults) #################################################################################### # Depends on BUSIO CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_BUSDEVICE = 0 + +# For CircuitPython CI +CIRCUITPY_BUILD_EXTENSIONS ?= elf From d0dc144d4dc2958863c65c9ed98d71bbe41ceb46 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 3 Oct 2024 16:55:00 -0400 Subject: [PATCH 068/252] fix ble_serial_connected() --- devices/ble_hci/common-hal/_bleio/PacketBuffer.c | 4 ++++ ports/espressif/common-hal/_bleio/PacketBuffer.c | 4 ++++ ports/nordic/common-hal/_bleio/PacketBuffer.c | 4 ++++ shared-bindings/_bleio/PacketBuffer.h | 1 + supervisor/shared/bluetooth/serial.c | 2 +- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/devices/ble_hci/common-hal/_bleio/PacketBuffer.c b/devices/ble_hci/common-hal/_bleio/PacketBuffer.c index 97626205a62f..771a1509f392 100644 --- a/devices/ble_hci/common-hal/_bleio/PacketBuffer.c +++ b/devices/ble_hci/common-hal/_bleio/PacketBuffer.c @@ -247,3 +247,7 @@ void common_hal_bleio_packet_buffer_deinit(bleio_packet_buffer_obj_t *self) { ringbuf_deinit(&self->ringbuf); } } + +bool common_hal_bleio_packet_buffer_connected(bleio_packet_buffer_obj_t *self) { + return !common_hal_bleio_packet_buffer_deinited(self) && self->conn_handle != BLE_CONN_HANDLE_INVALID; +} diff --git a/ports/espressif/common-hal/_bleio/PacketBuffer.c b/ports/espressif/common-hal/_bleio/PacketBuffer.c index a6cbdc530699..1cc167cb5c80 100644 --- a/ports/espressif/common-hal/_bleio/PacketBuffer.c +++ b/ports/espressif/common-hal/_bleio/PacketBuffer.c @@ -440,3 +440,7 @@ void common_hal_bleio_packet_buffer_deinit(bleio_packet_buffer_obj_t *self) { ble_event_remove_handler(packet_buffer_on_ble_client_evt, self); ringbuf_deinit(&self->ringbuf); } + +bool common_hal_bleio_packet_buffer_connected(bleio_packet_buffer_obj_t *self) { + return !common_hal_bleio_packet_buffer_deinited(self) && self->conn_handle != BLEIO_HANDLE_INVALID; +} diff --git a/ports/nordic/common-hal/_bleio/PacketBuffer.c b/ports/nordic/common-hal/_bleio/PacketBuffer.c index f3058f6c23d9..db4307279ae1 100644 --- a/ports/nordic/common-hal/_bleio/PacketBuffer.c +++ b/ports/nordic/common-hal/_bleio/PacketBuffer.c @@ -485,3 +485,7 @@ void common_hal_bleio_packet_buffer_deinit(bleio_packet_buffer_obj_t *self) { ringbuf_deinit(&self->ringbuf); } } + +bool common_hal_bleio_packet_buffer_connected(bleio_packet_buffer_obj_t *self) { + return !common_hal_bleio_packet_buffer_deinited(self) && self->conn_handle != BLE_CONN_HANDLE_INVALID; +} diff --git a/shared-bindings/_bleio/PacketBuffer.h b/shared-bindings/_bleio/PacketBuffer.h index e9e642e2677e..1a872512da27 100644 --- a/shared-bindings/_bleio/PacketBuffer.h +++ b/shared-bindings/_bleio/PacketBuffer.h @@ -35,3 +35,4 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_ void common_hal_bleio_packet_buffer_flush(bleio_packet_buffer_obj_t *self); bool common_hal_bleio_packet_buffer_deinited(bleio_packet_buffer_obj_t *self); void common_hal_bleio_packet_buffer_deinit(bleio_packet_buffer_obj_t *self); +bool common_hal_bleio_packet_buffer_connected(bleio_packet_buffer_obj_t *self); diff --git a/supervisor/shared/bluetooth/serial.c b/supervisor/shared/bluetooth/serial.c index 42c9b4bb3877..86ff1738a2a8 100644 --- a/supervisor/shared/bluetooth/serial.c +++ b/supervisor/shared/bluetooth/serial.c @@ -156,7 +156,7 @@ void supervisor_stop_bluetooth_serial(void) { } bool ble_serial_connected(void) { - return _tx_packet_buffer.conn_handle != BLEIO_HANDLE_INVALID; + return common_hal_bleio_packet_buffer_connected(&_tx_packet_buffer); } uint32_t ble_serial_available(void) { From d0e8030986a1c0bb2dd18d5987016fcf8622ad90 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 3 Oct 2024 16:37:35 -0500 Subject: [PATCH 069/252] clear any pending interrupt flag While debugging, I found that on RP2040 the first looped background write on a StateMachine would be garbled: It the first few outputs would be as expected, but then the data would go back to the start of the buffer. I realized that this could be due to there already being a pending interrupt on this DMA channel that had occurred previously but never been acknowledged. In fact, by printing the value of `dma_hw->intr` before this, I could see that it was the case. After this change, both my special case reproducer from the related issue works, and the odd gaps in LED data transmission seen in the WIP code for TM1814 LEDs was fixed. I never saw this problem on Feather RP2350, only on Metro RP2040, but I don't know why. It would depend on what had previously happened to the DMA channel that ends up allocated to this PIO state machine. Less likely, it could depend on details of the DMA peripheral that changed between the chips. Closes: #9678 --- ports/raspberrypi/common-hal/rp2pio/StateMachine.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 8275215e0f40..4750f7da61d1 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -1038,6 +1038,8 @@ bool common_hal_rp2pio_statemachine_background_write(rp2pio_statemachine_obj_t * false); common_hal_mcu_disable_interrupts(); + // Acknowledge any previous pending interrupt + dma_hw->ints0 |= 1u << channel; MP_STATE_PORT(background_pio)[channel] = self; dma_hw->inte0 |= 1u << channel; irq_set_mask_enabled(1 << DMA_IRQ_0, true); From f5a8e3d1387a3c8da9dda5f7c82a1610f29024e9 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Thu, 3 Oct 2024 20:13:58 -0500 Subject: [PATCH 070/252] Calculate current delay for a BlockInput correctly --- shared-bindings/audiodelays/Echo.c | 4 ++-- shared-module/audiodelays/Echo.c | 33 +++++++++++++++++++++--------- shared-module/audiodelays/Echo.h | 3 +++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 2704a2972fcf..8be7f2a4b6de 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -33,7 +33,7 @@ //| samples_signed: bool = True, //| channel_count: int = 1, //| ) -> None: -//| """Create a Echo effect that echos an audio sample every set number of microseconds. +//| """Create a Echo effect that echos an audio sample every set number of milliseconds. //| //| :param int max_delay_ms: The maximum delay the echo can be //| :param BlockInput delay_ms: The current echo delay @@ -132,7 +132,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiodelays_echo___exit___obj, 4, 4, //| delay_ms: BlockInput -//| """Delay of the echo in microseconds. (read-only)""" +//| """Delay of the echo in milliseconds. (read-only)""" //| static mp_obj_t audiodelays_echo_obj_get_delay_ms(mp_obj_t self_in) { audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 515317fb7cb8..b66c682ef1b7 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -86,10 +86,11 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ // calculate current echo buffer size we use for the given delay mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); + self->current_delay_ms = f_delay_ms; self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * sizeof(uint16_t)); - // read is where we store the incoming sample + previous echo - // write is what we send to the outgoing buffer + // read is where we read previous echo from delay_ms ago to play back now + // write is where the store the latest playing sample to echo back later self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); self->echo_buffer_write_pos = 0; } @@ -119,17 +120,24 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_o synthio_block_assign_slot(delay_ms, &self->delay_ms, MP_QSTR_delay_ms); mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); - self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * 2);// (self->bits_per_sample / 8)); - uint32_t max_ebuf_length = self->echo_buffer_len / sizeof(uint16_t); + recalculate_delay(self, f_delay_ms); +} + +void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { + // Calculate the current echo buffer length in bytes - if (self->echo_buffer_read_pos > max_ebuf_length) { - self->echo_buffer_read_pos = 0; - self->echo_buffer_write_pos = max_ebuf_length - (self->buffer_len / sizeof(uint16_t)); - } else if (self->echo_buffer_write_pos > max_ebuf_length) { - self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); - self->echo_buffer_write_pos = 0; + uint32_t new_echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * sizeof(uint16_t); + + // Check if our new echo is too long for our maximum buffer + if (new_echo_buffer_len > self->max_echo_buffer_len) { + return; + } else if (new_echo_buffer_len < 0.0) { // or too short! + return; } + + self->echo_buffer_len = new_echo_buffer_len; + self->current_delay_ms = f_delay_ms; } mp_obj_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self) { @@ -250,6 +258,11 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * mp_float_t mix = MIN(1.0, MAX(synthio_block_slot_get(&self->mix), 0.0)); mp_float_t decay = MIN(1.0, MAX(synthio_block_slot_get(&self->decay), 0.0)); + uint32_t delay_ms = (uint32_t)synthio_block_slot_get(&self->delay_ms); + if (self->current_delay_ms != delay_ms) { + recalculate_delay(self, delay_ms); + } + // Switch our buffers to the other buffer self->last_buf_idx = !self->last_buf_idx; diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index f699b0934f4e..42f039f34359 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -16,6 +16,7 @@ typedef struct { mp_obj_base_t base; uint32_t max_delay_ms; synthio_block_slot_t delay_ms; + uint32_t current_delay_ms; synthio_block_slot_t decay; synthio_block_slot_t mix; @@ -44,6 +45,8 @@ typedef struct { mp_obj_t sample; } audiodelays_echo_obj_t; +void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms); + void audiodelays_echo_reset_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel); From 9432fb97b681e2f0da519f0d019c98f824f03494 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 3 Oct 2024 22:21:27 -0400 Subject: [PATCH 071/252] fix os.uname() values for rp2350 --- ports/raspberrypi/common-hal/os/__init__.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/common-hal/os/__init__.c b/ports/raspberrypi/common-hal/os/__init__.c index 28c8ed946717..d9ad1c238ff3 100644 --- a/ports/raspberrypi/common-hal/os/__init__.c +++ b/ports/raspberrypi/common-hal/os/__init__.c @@ -22,8 +22,8 @@ static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "rp2040"); -static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "rp2040"); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, MICROPY_HW_MCU_NAME); static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); From 7e72009ca6da9ba97e78a71380fe1140cefd5948 Mon Sep 17 00:00:00 2001 From: Diamond Rivero Date: Fri, 4 Oct 2024 11:01:14 +0800 Subject: [PATCH 072/252] remove 'mp_obj_property_t' usage remains --- extmod/vfs_fat.c | 19 +++++-------- .../bindings/rp2pio/StateMachine.c | 26 +++++------------- shared-bindings/displayio/OnDiskBitmap.c | 9 ++----- shared-bindings/keypad/__init__.c | 17 +++--------- shared-bindings/vectorio/Rectangle.c | 27 +++++++------------ 5 files changed, 28 insertions(+), 70 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 85541d3cf01d..9b579afaa97f 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -484,12 +484,9 @@ static mp_obj_t vfs_fat_getreadonly(mp_obj_t self_in) { return mp_obj_new_bool(!filesystem_is_writable_by_python(self)); } static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getreadonly_obj, vfs_fat_getreadonly); -static const mp_obj_property_t fat_vfs_readonly_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&fat_vfs_getreadonly_obj, - MP_ROM_NONE, - MP_ROM_NONE}, -}; + +MP_PROPERTY_GETTER(fat_vfs_readonly_obj, + (mp_obj_t)&fat_vfs_getreadonly_obj); #if MICROPY_FATFS_USE_LABEL static mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) { @@ -517,12 +514,10 @@ static mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) { return mp_const_none; } static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_setlabel_obj, vfs_fat_setlabel); -static const mp_obj_property_t fat_vfs_label_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&fat_vfs_getlabel_obj, - (mp_obj_t)&fat_vfs_setlabel_obj, - MP_ROM_NONE}, -}; + +MP_PROPERTY_GETSET(fat_vfs_label_obj, + (mp_obj_t)&fat_vfs_getlabel_obj, + (mp_obj_t)&fat_vfs_setlabel_obj); #endif static const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { diff --git a/ports/raspberrypi/bindings/rp2pio/StateMachine.c b/ports/raspberrypi/bindings/rp2pio/StateMachine.c index 806674ee4c3d..fd94ae5fe146 100644 --- a/ports/raspberrypi/bindings/rp2pio/StateMachine.c +++ b/ports/raspberrypi/bindings/rp2pio/StateMachine.c @@ -610,13 +610,8 @@ static mp_obj_t rp2pio_statemachine_obj_get_writing(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_writing_obj, rp2pio_statemachine_obj_get_writing); -const mp_obj_property_t rp2pio_statemachine_writing_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&rp2pio_statemachine_get_writing_obj, - MP_ROM_NONE, - MP_ROM_NONE}, -}; - +MP_PROPERTY_GETTER(rp2pio_statemachine_writing_obj, + (mp_obj_t)&rp2pio_statemachine_get_writing_obj); //| pending: int //| """Returns the number of pending buffers for background writing. @@ -628,12 +623,8 @@ static mp_obj_t rp2pio_statemachine_obj_get_pending(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_pending_obj, rp2pio_statemachine_obj_get_pending); -const mp_obj_property_t rp2pio_statemachine_pending_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&rp2pio_statemachine_get_pending_obj, - MP_ROM_NONE, - MP_ROM_NONE}, -}; +MP_PROPERTY_GETTER(rp2pio_statemachine_pending_obj, + (mp_obj_t)&rp2pio_statemachine_get_pending_obj); //| def readinto( //| self, @@ -847,13 +838,8 @@ static mp_obj_t rp2pio_statemachine_obj_get_txstall(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_txstall_obj, rp2pio_statemachine_obj_get_txstall); -const mp_obj_property_t rp2pio_statemachine_txstall_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&rp2pio_statemachine_get_txstall_obj, - MP_ROM_NONE, - MP_ROM_NONE}, -}; - +MP_PROPERTY_GETTER(rp2pio_statemachine_txstall_obj, + (mp_obj_t)&rp2pio_statemachine_get_txstall_obj); //| rxstall: bool //| """True when the state machine has stalled due to a full RX FIFO since the last diff --git a/shared-bindings/displayio/OnDiskBitmap.c b/shared-bindings/displayio/OnDiskBitmap.c index fea3763657e8..cb2e20c2d0fe 100644 --- a/shared-bindings/displayio/OnDiskBitmap.c +++ b/shared-bindings/displayio/OnDiskBitmap.c @@ -113,13 +113,8 @@ static mp_obj_t displayio_ondiskbitmap_obj_get_pixel_shader(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskbitmap_get_pixel_shader_obj, displayio_ondiskbitmap_obj_get_pixel_shader); -const mp_obj_property_t displayio_ondiskbitmap_pixel_shader_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&displayio_ondiskbitmap_get_pixel_shader_obj, - (mp_obj_t)MP_ROM_NONE, - (mp_obj_t)MP_ROM_NONE}, -}; - +MP_PROPERTY_GETTER(displayio_ondiskbitmap_pixel_shader_obj, + (mp_obj_t)&displayio_ondiskbitmap_get_pixel_shader_obj); static const mp_rom_map_elem_t displayio_ondiskbitmap_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_ondiskbitmap_height_obj) }, diff --git a/shared-bindings/keypad/__init__.c b/shared-bindings/keypad/__init__.c index 1a7151c61ea5..48d19d59d376 100644 --- a/shared-bindings/keypad/__init__.c +++ b/shared-bindings/keypad/__init__.c @@ -37,12 +37,8 @@ static mp_obj_t keypad_generic_get_key_count(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(keypad_generic_get_key_count_obj, keypad_generic_get_key_count); -const mp_obj_property_t keypad_generic_key_count_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&keypad_generic_get_key_count_obj, - MP_ROM_NONE, - MP_ROM_NONE}, -}; +MP_PROPERTY_GETTER(keypad_generic_key_count_obj, + (mp_obj_t)&keypad_generic_get_key_count_obj); static mp_obj_t keypad_generic_get_events(mp_obj_t self_in) { keypad_keymatrix_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -52,13 +48,8 @@ static mp_obj_t keypad_generic_get_events(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(keypad_generic_get_events_obj, keypad_generic_get_events); -const mp_obj_property_t keypad_generic_events_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&keypad_generic_get_events_obj, - MP_ROM_NONE, - MP_ROM_NONE}, -}; - +MP_PROPERTY_GETTER(keypad_generic_events_obj, + (mp_obj_t)&keypad_generic_get_events_obj); //| """Support for scanning keys and key matrices //| diff --git a/shared-bindings/vectorio/Rectangle.c b/shared-bindings/vectorio/Rectangle.c index d1f2e6193ce3..8949df7dd1e6 100644 --- a/shared-bindings/vectorio/Rectangle.c +++ b/shared-bindings/vectorio/Rectangle.c @@ -85,12 +85,9 @@ static mp_obj_t vectorio_rectangle_obj_set_width(mp_obj_t self_in, mp_obj_t widt } MP_DEFINE_CONST_FUN_OBJ_2(vectorio_rectangle_set_width_obj, vectorio_rectangle_obj_set_width); -const mp_obj_property_t vectorio_rectangle_width_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&vectorio_rectangle_get_width_obj, - (mp_obj_t)&vectorio_rectangle_set_width_obj, - MP_ROM_NONE}, -}; +MP_PROPERTY_GETSET(vectorio_rectangle_width_obj, + (mp_obj_t)&vectorio_rectangle_get_width_obj, + (mp_obj_t)&vectorio_rectangle_set_width_obj); //| height: int //| """The height of the rectangle in pixels.""" @@ -107,12 +104,9 @@ static mp_obj_t vectorio_rectangle_obj_set_height(mp_obj_t self_in, mp_obj_t hei } MP_DEFINE_CONST_FUN_OBJ_2(vectorio_rectangle_set_height_obj, vectorio_rectangle_obj_set_height); -const mp_obj_property_t vectorio_rectangle_height_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&vectorio_rectangle_get_height_obj, - (mp_obj_t)&vectorio_rectangle_set_height_obj, - MP_ROM_NONE}, -}; +MP_PROPERTY_GETSET(vectorio_rectangle_height_obj, + (mp_obj_t)&vectorio_rectangle_get_height_obj, + (mp_obj_t)&vectorio_rectangle_set_height_obj); //| color_index: int //| """The color_index of the rectangle in 1 based index of the palette.""" @@ -129,12 +123,9 @@ static mp_obj_t vectorio_rectangle_obj_set_color_index(mp_obj_t self_in, mp_obj_ } MP_DEFINE_CONST_FUN_OBJ_2(vectorio_rectangle_set_color_index_obj, vectorio_rectangle_obj_set_color_index); -const mp_obj_property_t vectorio_rectangle_color_index_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&vectorio_rectangle_get_color_index_obj, - (mp_obj_t)&vectorio_rectangle_set_color_index_obj, - MP_ROM_NONE}, -}; +MP_PROPERTY_GETSET(vectorio_rectangle_color_index_obj, + (mp_obj_t)&vectorio_rectangle_get_color_index_obj, + (mp_obj_t)&vectorio_rectangle_set_color_index_obj); // Documentation for properties inherited from VectorShape. From d976f832f107090e7fa4c2a4d3d63fa4b6a842b5 Mon Sep 17 00:00:00 2001 From: Diamond Rivero Date: Fri, 4 Oct 2024 11:14:46 +0800 Subject: [PATCH 073/252] fix formatting --- extmod/vfs_fat.c | 2 +- ports/raspberrypi/bindings/rp2pio/StateMachine.c | 4 ++-- shared-bindings/displayio/OnDiskBitmap.c | 2 +- shared-bindings/keypad/__init__.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 9b579afaa97f..930d5a2a6c96 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -485,7 +485,7 @@ static mp_obj_t vfs_fat_getreadonly(mp_obj_t self_in) { } static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getreadonly_obj, vfs_fat_getreadonly); -MP_PROPERTY_GETTER(fat_vfs_readonly_obj, +MP_PROPERTY_GETTER(fat_vfs_readonly_obj, (mp_obj_t)&fat_vfs_getreadonly_obj); #if MICROPY_FATFS_USE_LABEL diff --git a/ports/raspberrypi/bindings/rp2pio/StateMachine.c b/ports/raspberrypi/bindings/rp2pio/StateMachine.c index fd94ae5fe146..aa0f33789564 100644 --- a/ports/raspberrypi/bindings/rp2pio/StateMachine.c +++ b/ports/raspberrypi/bindings/rp2pio/StateMachine.c @@ -623,7 +623,7 @@ static mp_obj_t rp2pio_statemachine_obj_get_pending(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_pending_obj, rp2pio_statemachine_obj_get_pending); -MP_PROPERTY_GETTER(rp2pio_statemachine_pending_obj, +MP_PROPERTY_GETTER(rp2pio_statemachine_pending_obj, (mp_obj_t)&rp2pio_statemachine_get_pending_obj); //| def readinto( @@ -838,7 +838,7 @@ static mp_obj_t rp2pio_statemachine_obj_get_txstall(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_txstall_obj, rp2pio_statemachine_obj_get_txstall); -MP_PROPERTY_GETTER(rp2pio_statemachine_txstall_obj, +MP_PROPERTY_GETTER(rp2pio_statemachine_txstall_obj, (mp_obj_t)&rp2pio_statemachine_get_txstall_obj); //| rxstall: bool diff --git a/shared-bindings/displayio/OnDiskBitmap.c b/shared-bindings/displayio/OnDiskBitmap.c index cb2e20c2d0fe..e15ecd45a954 100644 --- a/shared-bindings/displayio/OnDiskBitmap.c +++ b/shared-bindings/displayio/OnDiskBitmap.c @@ -113,7 +113,7 @@ static mp_obj_t displayio_ondiskbitmap_obj_get_pixel_shader(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskbitmap_get_pixel_shader_obj, displayio_ondiskbitmap_obj_get_pixel_shader); -MP_PROPERTY_GETTER(displayio_ondiskbitmap_pixel_shader_obj, +MP_PROPERTY_GETTER(displayio_ondiskbitmap_pixel_shader_obj, (mp_obj_t)&displayio_ondiskbitmap_get_pixel_shader_obj); static const mp_rom_map_elem_t displayio_ondiskbitmap_locals_dict_table[] = { diff --git a/shared-bindings/keypad/__init__.c b/shared-bindings/keypad/__init__.c index 48d19d59d376..b29de197262f 100644 --- a/shared-bindings/keypad/__init__.c +++ b/shared-bindings/keypad/__init__.c @@ -37,7 +37,7 @@ static mp_obj_t keypad_generic_get_key_count(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(keypad_generic_get_key_count_obj, keypad_generic_get_key_count); -MP_PROPERTY_GETTER(keypad_generic_key_count_obj, +MP_PROPERTY_GETTER(keypad_generic_key_count_obj, (mp_obj_t)&keypad_generic_get_key_count_obj); static mp_obj_t keypad_generic_get_events(mp_obj_t self_in) { From d5d40267bf2b87017f087275c8acf7b34a97b563 Mon Sep 17 00:00:00 2001 From: Diamond Rivero Date: Fri, 4 Oct 2024 14:56:36 +0800 Subject: [PATCH 074/252] use 'mp_obj_property_getter_t' type --- shared-bindings/keypad/__init__.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/keypad/__init__.h b/shared-bindings/keypad/__init__.h index 7f8079ecdc92..fd193cee217c 100644 --- a/shared-bindings/keypad/__init__.h +++ b/shared-bindings/keypad/__init__.h @@ -17,5 +17,5 @@ mp_obj_t common_hal_keypad_generic_get_events(void *self); MP_DECLARE_CONST_FUN_OBJ_1(keypad_generic_reset_obj); -extern const mp_obj_property_t keypad_generic_events_obj; -extern const mp_obj_property_t keypad_generic_key_count_obj; +extern const mp_obj_property_getter_t keypad_generic_events_obj; +extern const mp_obj_property_getter_t keypad_generic_key_count_obj; From a19ddf57dfe5582f8f1ecd4810e4a1f1f5773a2f Mon Sep 17 00:00:00 2001 From: Diamond Rivero Date: Fri, 4 Oct 2024 15:38:13 +0800 Subject: [PATCH 075/252] add static 'MP_PROPERTY_GETTER(fat_vfs_readonly_obj, (mp_obj_t)&fat_vfs_getreadonly_obj);' --- extmod/vfs_fat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index 930d5a2a6c96..d91e04ceea5d 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -485,7 +485,7 @@ static mp_obj_t vfs_fat_getreadonly(mp_obj_t self_in) { } static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getreadonly_obj, vfs_fat_getreadonly); -MP_PROPERTY_GETTER(fat_vfs_readonly_obj, +static MP_PROPERTY_GETTER(fat_vfs_readonly_obj, (mp_obj_t)&fat_vfs_getreadonly_obj); #if MICROPY_FATFS_USE_LABEL From 2a8589471f11986383e35723b34f80797115a907 Mon Sep 17 00:00:00 2001 From: Diamond Rivero Date: Fri, 4 Oct 2024 16:55:35 +0800 Subject: [PATCH 076/252] add static to 'extmod/vfs_fat.c: fat_vfs_label_obj' --- extmod/vfs_fat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index d91e04ceea5d..929bd5fd98e0 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -515,7 +515,7 @@ static mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) { } static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_setlabel_obj, vfs_fat_setlabel); -MP_PROPERTY_GETSET(fat_vfs_label_obj, +static MP_PROPERTY_GETSET(fat_vfs_label_obj, (mp_obj_t)&fat_vfs_getlabel_obj, (mp_obj_t)&fat_vfs_setlabel_obj); #endif From cca8d00f6b5c04d1ee40afac507b963d81737267 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 5 Oct 2024 10:08:42 -0500 Subject: [PATCH 077/252] Doc and error messaging changes --- locale/circuitpython.pot | 14 +------------- shared-bindings/audiodelays/Echo.c | 7 +++---- shared-module/audiodelays/Echo.c | 8 ++++---- shared-module/audiomixer/MixerVoice.c | 8 ++++---- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index f0dfa2cc07b6..eca8fbf72277 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -1957,19 +1957,7 @@ msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" #: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match" -msgstr "" - -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match" -msgstr "" - -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match" -msgstr "" - -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match" +msgid "The sample's %q does not match" msgstr "" #: supervisor/shared/safe_mode.c diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 8be7f2a4b6de..647f4dd81877 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -14,6 +14,7 @@ #include "py/objproperty.h" #include "py/runtime.h" #include "shared-bindings/util.h" +#include "shared-module/synthio/block.h" #define DECAY_DEFAULT 0.7f #define MIX_DEFAULT 0.5f @@ -39,7 +40,7 @@ //| :param BlockInput delay_ms: The current echo delay //| :param BlockInput decay: The rate the echo fades. 0.0 = instant; 1.0 = never. //| :param BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). -//| :param int buffer_size: The total size in bytes of the buffers to use +//| :param int buffer_size: The total size in bytes of each of the two playback buffers to use //| :param int sample_rate: The sample rate to be used //| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo. //| :param int bits_per_sample: The bits per sample of the effect @@ -225,9 +226,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_playing_obj, audiodelays_echo_obj MP_PROPERTY_GETTER(audiodelays_echo_playing_obj, (mp_obj_t)&audiodelays_echo_get_playing_obj); -//| def play( -//| self, sample: circuitpython_typing.AudioSample, *, voice: int = 0, loop: bool = False -//| ) -> None: +//| def play(self, sample: circuitpython_typing.AudioSample, *, loop: bool = False) -> None: //| """Plays the sample once when loop=False and continuously when loop=True. //| Does not block. Use `playing` to block. //| diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index b66c682ef1b7..df6c2e8b0551 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -187,13 +187,13 @@ void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sam // The get_buffer function will actually process that data if (audiosample_sample_rate(sample) != self->sample_rate) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match")); + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_sample_rate); } if (audiosample_channel_count(sample) != self->channel_count) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's channel count does not match")); + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_channel_count); } if (audiosample_bits_per_sample(sample) != self->bits_per_sample) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's bits_per_sample does not match")); + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_bits_per_sample); } bool single_buffer; bool samples_signed; @@ -201,7 +201,7 @@ void common_hal_audiodelays_echo_play(audiodelays_echo_obj_t *self, mp_obj_t sam uint8_t spacing; audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing); if (samples_signed != self->samples_signed) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's signedness does not match")); + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_signedness); } self->sample = sample; diff --git a/shared-module/audiomixer/MixerVoice.c b/shared-module/audiomixer/MixerVoice.c index f43a261d8968..cba7544b1e65 100644 --- a/shared-module/audiomixer/MixerVoice.c +++ b/shared-module/audiomixer/MixerVoice.c @@ -32,13 +32,13 @@ void common_hal_audiomixer_mixervoice_set_level(audiomixer_mixervoice_obj_t *sel void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp_obj_t sample, bool loop) { if (audiosample_sample_rate(sample) != self->parent->sample_rate) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's sample rate does not match")); + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_sample_rate); } if (audiosample_channel_count(sample) != self->parent->channel_count) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's channel count does not match")); + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_channel_count); } if (audiosample_bits_per_sample(sample) != self->parent->bits_per_sample) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's bits_per_sample does not match")); + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_bits_per_sample); } bool single_buffer; bool samples_signed; @@ -47,7 +47,7 @@ void common_hal_audiomixer_mixervoice_play(audiomixer_mixervoice_obj_t *self, mp audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing); if (samples_signed != self->parent->samples_signed) { - mp_raise_ValueError(MP_ERROR_TEXT("The sample's signedness does not match")); + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_signedness); } self->sample = sample; self->loop = loop; From 146c13e6cecbe201c96529e1b4e51a9759cb9eeb Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 5 Oct 2024 11:25:27 -0500 Subject: [PATCH 078/252] Improved documentation --- shared-bindings/audiodelays/Echo.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index 647f4dd81877..d5371ba78851 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -25,21 +25,29 @@ //| def __init__( //| self, //| max_delay_ms: int = 500, -//| delay_ms: BlockInput = 250.0, -//| decay: BlockInput = 0.7, -//| mix: BlockInput = 0.5, +//| delay_ms: synthio.BlockInput = 250.0, +//| decay: synthio.BlockInput = 0.7, +//| mix: synthio.BlockInput = 0.5, //| buffer_size: int = 512, //| sample_rate: int = 8000, //| bits_per_sample: int = 16, //| samples_signed: bool = True, //| channel_count: int = 1, //| ) -> None: -//| """Create a Echo effect that echos an audio sample every set number of milliseconds. +//| """Create a Echo effect where you hear the original sample play back, at a lesser volume after +//| a set number of millisecond delay. The delay timing of the echo can be changed at runtime +//| with the delay_ms parameter but the delay can never exceed the max_delay_ms parameter. The +//| maximum delay you can set is limited by available memory. //| -//| :param int max_delay_ms: The maximum delay the echo can be -//| :param BlockInput delay_ms: The current echo delay -//| :param BlockInput decay: The rate the echo fades. 0.0 = instant; 1.0 = never. -//| :param BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). +//| Each time the echo plays back the volume is reduced by the decay setting (echo * decay). +//| +//| The mix parameter allows you to change how much of the unchanged sample passes through to +//| the output to how much of the effect audio you hear as the output. +//| +//| :param int max_delay_ms: The maximum time the echo can be in milliseconds +//| :param synthio.BlockInput delay_ms: The current time of the echo delay in milliseconds. Must be less the max_delay_ms +//| :param synthio.BlockInput decay: The rate the echo fades. 0.0 = instant; 1.0 = never. +//| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). //| :param int buffer_size: The total size in bytes of each of the two playback buffers to use //| :param int sample_rate: The sample rate to be used //| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo. @@ -132,7 +140,7 @@ static mp_obj_t audiodelays_echo_obj___exit__(size_t n_args, const mp_obj_t *arg static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiodelays_echo___exit___obj, 4, 4, audiodelays_echo_obj___exit__); -//| delay_ms: BlockInput +//| delay_ms: synthio.BlockInput //| """Delay of the echo in milliseconds. (read-only)""" //| static mp_obj_t audiodelays_echo_obj_get_delay_ms(mp_obj_t self_in) { @@ -162,7 +170,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_delay_ms_obj, (mp_obj_t)&audiodelays_echo_get_delay_ms_obj, (mp_obj_t)&audiodelays_echo_set_delay_ms_obj); -//| decay: BlockInput +//| decay: synthio.BlockInput //| """The rate the echo decays between 0 and 1 where 1 is forever and 0 is no echo.""" static mp_obj_t audiodelays_echo_obj_get_decay(mp_obj_t self_in) { return common_hal_audiodelays_echo_get_decay(self_in); @@ -188,7 +196,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_decay_obj, (mp_obj_t)&audiodelays_echo_get_decay_obj, (mp_obj_t)&audiodelays_echo_set_decay_obj); -//| mix: BlockInput +//| mix: synthio.BlockInput //| """The rate the echo mix between 0 and 1 where 0 is only sample and 1 is all effect.""" static mp_obj_t audiodelays_echo_obj_get_mix(mp_obj_t self_in) { return common_hal_audiodelays_echo_get_mix(self_in); From 1e4fbd94edfb3efe3de494c486eac91a9f52f60d Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 5 Oct 2024 21:58:11 +0300 Subject: [PATCH 079/252] Add MakerGo C6 SuperMini --- .../boards/makergo_esp32c6_supermini/board.c | 9 ++++ .../makergo_esp32c6_supermini/mpconfigboard.h | 19 ++++++++ .../mpconfigboard.mk | 8 ++++ .../boards/makergo_esp32c6_supermini/pins.c | 46 +++++++++++++++++++ .../makergo_esp32c6_supermini/sdkconfig | 14 ++++++ 5 files changed, 96 insertions(+) create mode 100644 ports/espressif/boards/makergo_esp32c6_supermini/board.c create mode 100644 ports/espressif/boards/makergo_esp32c6_supermini/mpconfigboard.h create mode 100644 ports/espressif/boards/makergo_esp32c6_supermini/mpconfigboard.mk create mode 100644 ports/espressif/boards/makergo_esp32c6_supermini/pins.c create mode 100644 ports/espressif/boards/makergo_esp32c6_supermini/sdkconfig diff --git a/ports/espressif/boards/makergo_esp32c6_supermini/board.c b/ports/espressif/boards/makergo_esp32c6_supermini/board.c new file mode 100644 index 000000000000..1055de509cfa --- /dev/null +++ b/ports/espressif/boards/makergo_esp32c6_supermini/board.c @@ -0,0 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2023 bill88t +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/makergo_esp32c6_supermini/mpconfigboard.h b/ports/espressif/boards/makergo_esp32c6_supermini/mpconfigboard.h new file mode 100644 index 000000000000..ed8dec14f0ae --- /dev/null +++ b/ports/espressif/boards/makergo_esp32c6_supermini/mpconfigboard.h @@ -0,0 +1,19 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Bill Sideris, independently providing these changes. +// +// SPDX-License-Identifier: MIT + +#pragma once + +// Board setup +#define MICROPY_HW_BOARD_NAME "Maker Go ESP32C6 Supermini" +#define MICROPY_HW_MCU_NAME "ESP32-C6" + +// Status LED +#define MICROPY_HW_NEOPIXEL (&pin_GPIO8) +#define MICROPY_HW_NEOPIXEL_COUNT (1) + +// Default bus pins +#define DEFAULT_UART_BUS_TX (&pin_GPIO17) +#define DEFAULT_UART_BUS_RX (&pin_GPIO16) diff --git a/ports/espressif/boards/makergo_esp32c6_supermini/mpconfigboard.mk b/ports/espressif/boards/makergo_esp32c6_supermini/mpconfigboard.mk new file mode 100644 index 000000000000..54078559d7be --- /dev/null +++ b/ports/espressif/boards/makergo_esp32c6_supermini/mpconfigboard.mk @@ -0,0 +1,8 @@ +CIRCUITPY_CREATOR_ID = 0x19981000 +CIRCUITPY_CREATION_ID = 0x00C60001 + +IDF_TARGET = esp32c6 + +CIRCUITPY_ESP_FLASH_MODE = qio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 4MB diff --git a/ports/espressif/boards/makergo_esp32c6_supermini/pins.c b/ports/espressif/boards/makergo_esp32c6_supermini/pins.c new file mode 100644 index 000000000000..b396e5bb1afa --- /dev/null +++ b/ports/espressif/boards/makergo_esp32c6_supermini/pins.c @@ -0,0 +1,46 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Bill Sideris, independently providing these changes. +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + // Left to Right top to bottom + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO17) }, + + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + + // Extras + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO8) }, + + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/makergo_esp32c6_supermini/sdkconfig b/ports/espressif/boards/makergo_esp32c6_supermini/sdkconfig new file mode 100644 index 000000000000..e96286621603 --- /dev/null +++ b/ports/espressif/boards/makergo_esp32c6_supermini/sdkconfig @@ -0,0 +1,14 @@ +# +# Espressif IoT Development Framework Configuration +# +# +# Component config +# +# +# LWIP +# +# end of LWIP + +# end of Component config + +# end of Espressif IoT Development Framework Configuration From 0fa3cd8632f0cf7cdcedd89f6566f6e2909591cf Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 5 Oct 2024 18:03:03 -0500 Subject: [PATCH 080/252] Removed utils.h which was not required --- shared-module/audiodelays/Echo.c | 2 - shared-module/audiomixer/utils.h | 90 -------------------------------- 2 files changed, 92 deletions(-) delete mode 100644 shared-module/audiomixer/utils.h diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index df6c2e8b0551..c234b10531c9 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -7,8 +7,6 @@ #include #include "py/runtime.h" -#include "shared-module/audiomixer/utils.h" - void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t max_delay_ms, mp_obj_t delay_ms, mp_obj_t decay, mp_obj_t mix, diff --git a/shared-module/audiomixer/utils.h b/shared-module/audiomixer/utils.h deleted file mode 100644 index f7dbdac7dd38..000000000000 --- a/shared-module/audiomixer/utils.h +++ /dev/null @@ -1,90 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2018 Scott Shawcroft for Adafruit Industries, 2024 Mark Komus -// -// SPDX-License-Identifier: MIT - -__attribute__((always_inline)) -static inline uint32_t add16signed(uint32_t a, uint32_t b) { - #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) - return __QADD16(a, b); - #else - uint32_t result = 0; - for (int8_t i = 0; i < 2; i++) { - int16_t ai = a >> (sizeof(int16_t) * 8 * i); - int16_t bi = b >> (sizeof(int16_t) * 8 * i); - int32_t intermediate = (int32_t)ai + bi; - if (intermediate > SHRT_MAX) { - intermediate = SHRT_MAX; - } else if (intermediate < SHRT_MIN) { - intermediate = SHRT_MIN; - } - result |= (((uint32_t)intermediate) & 0xffff) << (sizeof(int16_t) * 8 * i); - } - return result; - #endif -} - -__attribute__((always_inline)) -static inline uint32_t mult16signed(uint32_t val, int32_t mul) { - #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) - mul <<= 16; - int32_t hi, lo; - enum { bits = 16 }; // saturate to 16 bits - enum { shift = 15 }; // shift is done automatically - asm volatile ("smulwb %0, %1, %2" : "=r" (lo) : "r" (mul), "r" (val)); - asm volatile ("smulwt %0, %1, %2" : "=r" (hi) : "r" (mul), "r" (val)); - asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (lo) : "I" (bits), "r" (lo), "I" (shift)); - asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (hi) : "I" (bits), "r" (hi), "I" (shift)); - asm volatile ("pkhbt %0, %1, %2, lsl #16" : "=r" (val) : "r" (lo), "r" (hi)); // pack - return val; - #else - uint32_t result = 0; - float mod_mul = (float)mul / (float)((1 << 15) - 1); - for (int8_t i = 0; i < 2; i++) { - int16_t ai = (val >> (sizeof(uint16_t) * 8 * i)); - int32_t intermediate = (int32_t)(ai * mod_mul); - if (intermediate > SHRT_MAX) { - intermediate = SHRT_MAX; - } else if (intermediate < SHRT_MIN) { - intermediate = SHRT_MIN; - } - intermediate &= 0x0000FFFF; - result |= (((uint32_t)intermediate)) << (sizeof(int16_t) * 8 * i); - } - return result; - #endif -} - - -static inline uint32_t tounsigned8(uint32_t val) { - #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) - return __UADD8(val, 0x80808080); - #else - return val ^ 0x80808080; - #endif -} - -static inline uint32_t tounsigned16(uint32_t val) { - #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) - return __UADD16(val, 0x80008000); - #else - return val ^ 0x80008000; - #endif -} - -static inline uint32_t tosigned16(uint32_t val) { - #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) - return __UADD16(val, 0x80008000); - #else - return val ^ 0x80008000; - #endif -} - -static inline uint32_t unpack8(uint16_t val) { - return ((val & 0xff00) << 16) | ((val & 0x00ff) << 8); -} - -static inline uint32_t pack8(uint32_t val) { - return ((val & 0xff000000) >> 16) | ((val & 0xff00) >> 8); -} From 0ced12c36085ecd05804d0f55dc056a1c58e1e5e Mon Sep 17 00:00:00 2001 From: Diamond Rivero Date: Sat, 5 Oct 2024 00:53:24 +0000 Subject: [PATCH 081/252] Translated using Weblate (Filipino) Currently translated at 32.5% (325 of 1000 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/fil/ --- locale/fil.po | 58 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/locale/fil.po b/locale/fil.po index 23de4867284a..6aae57719103 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -6,8 +6,8 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-11-16 15:03+0000\n" -"Last-Translator: Jeff Epler \n" +"PO-Revision-Date: 2024-10-06 01:15+0000\n" +"Last-Translator: Diamond Rivero \n" "Language-Team: fil\n" "Language: fil\n" "MIME-Version: 1.0\n" @@ -15,13 +15,15 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1 && n != 2 && n != 3 && (n % 10 == 4 " "|| n % 10 == 6 || n % 10 == 9);\n" -"X-Generator: Weblate 5.2\n" +"X-Generator: Weblate 5.8-dev\n" #: main.c msgid "" "\n" "Code done running.\n" msgstr "" +"\n" +"Code ay tapos na sa pagtakbo\n" #: main.c msgid "" @@ -1762,6 +1764,8 @@ msgstr "" #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload.\n" msgstr "" +"Pindutin ang kahit anong key para pumasok sa REPL. Gamitin ang CTRL-D para " +"mag-reload\n" #: main.c msgid "Pretending to deep sleep until alarm, CTRL-C or file write.\n" @@ -1789,24 +1793,24 @@ msgstr "Pull hindi ginagamit kapag ang direksyon ay output." #: ports/raspberrypi/common-hal/countio/Counter.c msgid "RISE_AND_FALL not available on this chip" -msgstr "" +msgstr "RISE_AND_FALL ay hindi pwede sa chip na ito" #: shared-module/displayio/OnDiskBitmap.c msgid "RLE-compressed BMP not supported" -msgstr "" +msgstr "RLE-compressed BMP ay hindi suportado" #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" -msgstr "" +msgstr "Error sa RNG DeInit" #: ports/stm/common-hal/os/__init__.c msgid "RNG Init Error" -msgstr "" +msgstr "Error sa RNG Init" #: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c #: ports/nordic/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c msgid "RS485" -msgstr "" +msgstr "RS485" #: ports/espressif/common-hal/busio/UART.c #: ports/mimxrt10xx/common-hal/busio/UART.c @@ -1838,11 +1842,11 @@ msgstr "" #: supervisor/shared/bluetooth/bluetooth.c msgid "Reconnecting" -msgstr "" +msgstr "Kumokonekta" #: shared-bindings/epaperdisplay/EPaperDisplay.c msgid "Refresh too soon" -msgstr "" +msgstr "sobrang aga mag-refresh" #: shared-bindings/canio/RemoteTransmissionRequest.c msgid "RemoteTransmissionRequests limited to 8 bytes" @@ -1854,7 +1858,7 @@ msgstr "" #: ports/espressif/common-hal/espidf/__init__.c msgid "Requested resource not found" -msgstr "" +msgstr "Hiniling na resource ay hindi nakita" #: ports/atmel-samd/common-hal/audioio/AudioOut.c msgid "Right channel unsupported" @@ -1870,65 +1874,65 @@ msgstr "Tumatakbo sa safe mode! Hindi tumatakbo ang nai-save na code.\n" #: shared-module/sdcardio/SDCard.c msgid "SD card CSD format not supported" -msgstr "" +msgstr "SD card CSD na format ay hindi suportado" #: ports/cxd56/common-hal/sdioio/SDCard.c msgid "SDCard init" -msgstr "" +msgstr "pag-init ng SDCard" #: ports/stm/common-hal/sdioio/SDCard.c #, c-format msgid "SDIO GetCardInfo Error %d" -msgstr "" +msgstr "Error ng SDIO GetCardInfo %d" #: ports/espressif/common-hal/sdioio/SDCard.c #: ports/stm/common-hal/sdioio/SDCard.c #, c-format msgid "SDIO Init Error %x" -msgstr "" +msgstr "Error sa pag-init ng SDIO %x" #: ports/espressif/common-hal/busio/SPI.c msgid "SPI configuration failed" -msgstr "" +msgstr "Nabigo sa SPI configuration" #: ports/stm/common-hal/busio/SPI.c msgid "SPI init error" -msgstr "" +msgstr "error sa pag-init ng SPI" #: ports/raspberrypi/common-hal/busio/SPI.c msgid "SPI peripheral in use" -msgstr "" +msgstr "SPI peripheral ay ginagamit" #: ports/stm/common-hal/busio/SPI.c msgid "SPI re-init" -msgstr "" +msgstr "pag re-init ng SPI" #: shared-bindings/is31fl3741/FrameBuffer.c msgid "Scale dimensions must divide by 3" -msgstr "" +msgstr "Scale dimensions ay kailangan i-divide sa 3" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nordic/common-hal/_bleio/Adapter.c msgid "Scan already in progress. Stop with stop_scan." -msgstr "" +msgstr "Scan ay kasalukuyang ginagawa. Patigilin gamit ang stop_scan." #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c msgid "Serializer in use" -msgstr "Serializer ginagamit" +msgstr "Serializer ay ginagamit" #: shared-bindings/ssl/SSLContext.c msgid "Server side context cannot have hostname" -msgstr "" +msgstr "Server side context ay hindi pwede magkaroon ng hostname" #: ports/cxd56/common-hal/camera/Camera.c msgid "Size not supported" -msgstr "" +msgstr "Size ay hindi suportado" #: shared-bindings/alarm/SleepMemory.c shared-bindings/memorymap/AddressRange.c #: shared-bindings/nvm/ByteArray.c msgid "Slice and value different lengths." -msgstr "Slice at value iba't ibang haba." +msgstr "Slice at value ay iba iba ang haba." #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c #: shared-bindings/displayio/TileGrid.c @@ -1940,11 +1944,11 @@ msgstr "Hindi suportado ang Slices" #: ports/espressif/common-hal/socketpool/SocketPool.c #: ports/raspberrypi/common-hal/socketpool/SocketPool.c msgid "SocketPool can only be used with wifi.radio" -msgstr "" +msgstr "SocketPool ay pwede lang gamitin sa wifi.radio" #: shared-bindings/aesio/aes.c msgid "Source and destination buffers must be the same length" -msgstr "" +msgstr "Ang pinagmulan at patutunguhan ng buffer ay dapat na pareho ang haba" #: shared-bindings/paralleldisplaybus/ParallelBus.c msgid "Specify exactly one of data0 or data_pins" From e9bb5cf4de62de7ca36d6c63e4ce53d10b11980b Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sun, 6 Oct 2024 17:02:09 +0300 Subject: [PATCH 082/252] Do power led --- .../boards/makergo_esp32c6_supermini/board.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ports/espressif/boards/makergo_esp32c6_supermini/board.c b/ports/espressif/boards/makergo_esp32c6_supermini/board.c index 1055de509cfa..0b0fe888a564 100644 --- a/ports/espressif/boards/makergo_esp32c6_supermini/board.c +++ b/ports/espressif/boards/makergo_esp32c6_supermini/board.c @@ -5,5 +5,20 @@ // SPDX-License-Identifier: MIT #include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "driver/gpio.h" +#include "common-hal/microcontroller/Pin.h" + +bool espressif_board_reset_pin_number(gpio_num_t pin_number) { + if (pin_number == 15) { + /* + * Turn on the spare led on boot as a power indicator + */ + config_pin_as_output_with_level(pin_number, true); + return true; + } + return false; +} // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. From 1c58d7c29354a346df72a6046bd91839225c1d5a Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sun, 6 Oct 2024 17:03:15 +0300 Subject: [PATCH 083/252] Change the comment type --- ports/espressif/boards/makergo_esp32c6_supermini/board.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/espressif/boards/makergo_esp32c6_supermini/board.c b/ports/espressif/boards/makergo_esp32c6_supermini/board.c index 0b0fe888a564..8cb7168e0da8 100644 --- a/ports/espressif/boards/makergo_esp32c6_supermini/board.c +++ b/ports/espressif/boards/makergo_esp32c6_supermini/board.c @@ -12,9 +12,7 @@ bool espressif_board_reset_pin_number(gpio_num_t pin_number) { if (pin_number == 15) { - /* - * Turn on the spare led on boot as a power indicator - */ + // Turn on the spare led on boot as a power indicator. config_pin_as_output_with_level(pin_number, true); return true; } From 48e1327c0eb94decaf209c76d30cc2f8fcc18f8d Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sun, 6 Oct 2024 20:47:13 -0500 Subject: [PATCH 084/252] Fix about incorrectly recalculating delay --- shared-module/audiodelays/Echo.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index c234b10531c9..a5330098352a 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -125,7 +125,7 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_o void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { // Calculate the current echo buffer length in bytes - uint32_t new_echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * sizeof(uint16_t); + uint32_t new_echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * sizeof(uint16_t)); // Check if our new echo is too long for our maximum buffer if (new_echo_buffer_len > self->max_echo_buffer_len) { @@ -134,6 +134,11 @@ void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { return; } + // If the echo buffer is larger then our audio buffer weird things happen + if (new_echo_buffer_len < self->buffer_len) { + return; + } + self->echo_buffer_len = new_echo_buffer_len; self->current_delay_ms = f_delay_ms; } From 125faaec18d5b341c79c35d127f02ce7f7b93354 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 7 Oct 2024 08:43:42 -0500 Subject: [PATCH 085/252] Avoid crashing when printing DeepSleepRequest objects --- shared-bindings/alarm/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/alarm/__init__.c b/shared-bindings/alarm/__init__.c index 7cdc2f7750e5..e0ed0b9a396f 100644 --- a/shared-bindings/alarm/__init__.c +++ b/shared-bindings/alarm/__init__.c @@ -196,7 +196,7 @@ static mp_obj_t alarm_exit_and_deep_sleep_until_alarms(size_t n_args, const mp_o common_hal_alarm_set_deep_sleep_alarms(n_args, pos_args, num_dios, dios_array); // Raise an exception, which will be processed in main.c. - mp_raise_type_arg(&mp_type_DeepSleepRequest, NULL); + mp_raise_type(&mp_type_DeepSleepRequest); // Doesn't get here. return mp_const_none; From 5b771569d8afeac538eeef8f6918e8f18253926b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 7 Oct 2024 09:15:07 -0500 Subject: [PATCH 086/252] remove deprecated call in doc setup --- conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/conf.py b/conf.py index 7120fa3f00a3..6c30a43abb1f 100644 --- a/conf.py +++ b/conf.py @@ -277,7 +277,6 @@ def autoapi_prepare_jinja_env(jinja_env): import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the From 08bc84b4f4f786217caa90e3d8bab96d9eaa24d7 Mon Sep 17 00:00:00 2001 From: sam blenny <68084116+samblenny@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:50:22 +0000 Subject: [PATCH 087/252] revert usb.core.Device error message changes This puts the error messages back like they were, leaving the null pointer dereference fixes in place. --- locale/circuitpython.pot | 24 ++++++++---------------- shared-module/usb/core/Device.c | 14 +++++++------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index da74912e4c48..0b19dce9c427 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -915,10 +915,6 @@ msgstr "" msgid "ESP-IDF memory allocation failed" msgstr "" -#: shared-module/usb/core/Device.c -msgid "Endpt" -msgstr "" - #: extmod/modre.c msgid "Error in regex" msgstr "" @@ -1449,6 +1445,10 @@ msgstr "" msgid "No bootloader present" msgstr "" +#: shared-module/usb/core/Device.c +msgid "No configuration set" +msgstr "" + #: shared-bindings/_bleio/PacketBuffer.c msgid "No connection: length cannot be determined" msgstr "" @@ -1518,10 +1518,6 @@ msgstr "" msgid "No usb host port initialized" msgstr "" -#: shared-module/usb/core/Device.c -msgid "NoCfg" -msgstr "" - #: ports/nordic/common-hal/_bleio/__init__.c msgid "Nordic system firmware out of memory" msgstr "" @@ -1730,6 +1726,10 @@ msgstr "" msgid "Pins must share PWM slice" msgstr "" +#: shared-module/usb/core/Device.c +msgid "Pipe error" +msgstr "" + #: py/builtinhelp.c msgid "Plus any modules on the filesystem\n" msgstr "" @@ -1941,10 +1941,6 @@ msgstr "" msgid "Stack overflow. Increase stack size." msgstr "" -#: shared-module/usb/core/Device.c -msgid "Stall" -msgstr "" - #: shared-bindings/alarm/time/TimeAlarm.c msgid "Supply one of monotonic_time or epoch_time" msgstr "" @@ -2305,10 +2301,6 @@ msgstr "" msgid "Writes not supported on Characteristic" msgstr "" -#: shared-module/usb/core/Device.c -msgid "Xfer" -msgstr "" - #: ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.h #: ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.h #: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h diff --git a/shared-module/usb/core/Device.c b/shared-module/usb/core/Device.c index 5965864a447b..1a184f8b1b91 100644 --- a/shared-module/usb/core/Device.c +++ b/shared-module/usb/core/Device.c @@ -159,7 +159,7 @@ static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) { _xfer_result = 0xff; xfer->complete_cb = _transfer_done_cb; if (!tuh_edpt_xfer(xfer)) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("Xfer")); + mp_raise_usb_core_USBError(NULL); return 0; } uint32_t start_time = supervisor_ticks_ms32(); @@ -177,7 +177,7 @@ static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) { xfer_result_t result = _xfer_result; _xfer_result = 0xff; if (result == XFER_RESULT_STALLED) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("Stall")); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("Pipe error")); } if (result == 0xff) { tuh_edpt_abort_xfer(xfer->daddr, xfer->ep_addr); @@ -206,7 +206,7 @@ static bool _open_endpoint(usb_core_device_obj_t *self, mp_int_t endpoint) { } if (self->configuration_descriptor == NULL) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("NoCfg")); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("No configuration set")); return false; } @@ -241,7 +241,7 @@ static bool _open_endpoint(usb_core_device_obj_t *self, mp_int_t endpoint) { mp_int_t common_hal_usb_core_device_write(usb_core_device_obj_t *self, mp_int_t endpoint, const uint8_t *buffer, mp_int_t len, mp_int_t timeout) { if (!_open_endpoint(self, endpoint)) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("Endpt")); + mp_raise_usb_core_USBError(NULL); return 0; } tuh_xfer_t xfer; @@ -254,7 +254,7 @@ mp_int_t common_hal_usb_core_device_write(usb_core_device_obj_t *self, mp_int_t mp_int_t common_hal_usb_core_device_read(usb_core_device_obj_t *self, mp_int_t endpoint, uint8_t *buffer, mp_int_t len, mp_int_t timeout) { if (!_open_endpoint(self, endpoint)) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("Endpt")); + mp_raise_usb_core_USBError(NULL); return 0; } tuh_xfer_t xfer; @@ -289,7 +289,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, _xfer_result = 0xff; if (!tuh_control_xfer(&xfer)) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("Xfer")); + mp_raise_usb_core_USBError(NULL); return 0; } uint32_t start_time = supervisor_ticks_ms32(); @@ -307,7 +307,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, xfer_result_t result = _xfer_result; _xfer_result = 0xff; if (result == XFER_RESULT_STALLED) { - mp_raise_usb_core_USBError(MP_ERROR_TEXT("Stall")); + mp_raise_usb_core_USBError(MP_ERROR_TEXT("Pipe error")); } if (result == 0xff) { tuh_edpt_abort_xfer(xfer.daddr, xfer.ep_addr); From af947a50845ebdd1b574e9d2fac02e8c114251ed Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 7 Oct 2024 20:10:55 -0500 Subject: [PATCH 088/252] Enable for all 2350 boards --- ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk | 1 - ports/raspberrypi/mpconfigport.mk | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk index dbb6801d6a3b..43328dd47094 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk @@ -10,4 +10,3 @@ CHIP_FAMILY = rp2 EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" CIRCUITPY__EVE = 1 -CIRCUITPY_AUDIOEFFECTS = 1 diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index 6c8b7551e789..d619e78bd97a 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -64,6 +64,9 @@ CIRCUITPY_PICODVI ?= 1 # Our generic touchio uses a pull down and RP2350 A2 hardware doesn't work correctly. # So, turn touchio off because it doesn't work. CIRCUITPY_TOUCHIO = 0 + +# Audio effects +CIRCUITPY_AUDIOEFFECTS ?= 1 endif INTERNAL_LIBM = 1 From af7d8b7d949c99e70313626c2d82465021ddcbd9 Mon Sep 17 00:00:00 2001 From: Sola85 Date: Tue, 8 Oct 2024 09:03:08 +0200 Subject: [PATCH 089/252] epaperdisplay: fix delay when two_byte_sequence_length is true --- shared-module/epaperdisplay/EPaperDisplay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/epaperdisplay/EPaperDisplay.c b/shared-module/epaperdisplay/EPaperDisplay.c index 9f43195b8cf5..14fbc3341b5f 100644 --- a/shared-module/epaperdisplay/EPaperDisplay.c +++ b/shared-module/epaperdisplay/EPaperDisplay.c @@ -157,7 +157,7 @@ static void send_command_sequence(epaperdisplay_epaperdisplay_obj_t *self, uint16_t delay_length_ms = 0; if (delay) { data_size++; - delay_length_ms = *(cmd + 1 + data_size); + delay_length_ms = *(cmd + 1 + data_size + self->two_byte_sequence_length); if (delay_length_ms == 255) { delay_length_ms = 500; } From ff905d40afc5faafb88755b1f9c23dac86d00b35 Mon Sep 17 00:00:00 2001 From: DatanoiseTV Date: Tue, 8 Oct 2024 18:07:19 +0200 Subject: [PATCH 090/252] Add Datanoise PicoADK V2. --- .../boards/datanoise_picoadk_v2/board.c | 9 +++ .../datanoise_picoadk_v2/mpconfigboard.h | 21 +++++++ .../datanoise_picoadk_v2/mpconfigboard.mk | 13 ++++ .../pico-sdk-configboard.h | 12 ++++ .../boards/datanoise_picoadk_v2/pins.c | 62 +++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 ports/raspberrypi/boards/datanoise_picoadk_v2/board.c create mode 100644 ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/datanoise_picoadk_v2/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c diff --git a/ports/raspberrypi/boards/datanoise_picoadk_v2/board.c b/ports/raspberrypi/boards/datanoise_picoadk_v2/board.c new file mode 100644 index 000000000000..e6a868ab2122 --- /dev/null +++ b/ports/raspberrypi/boards/datanoise_picoadk_v2/board.c @@ -0,0 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h b/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h new file mode 100644 index 000000000000..339f1113176c --- /dev/null +++ b/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h @@ -0,0 +1,21 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define MICROPY_HW_BOARD_NAME "Datanoise PicoADK V2" +#define MICROPY_HW_MCU_NAME "rp2350a" + + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO9) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO18) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO12) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO20) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO13) +#define DEFAULT_UART_BUS_TX (&pin_GPIO12) diff --git a/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.mk b/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.mk new file mode 100644 index 000000000000..1b5c6c5d548c --- /dev/null +++ b/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.mk @@ -0,0 +1,13 @@ +USB_VID = 0x2E8A +USB_PID = 0x10AE +USB_PRODUCT = "PicoADK V2" +USB_MANUFACTURER = "Datanoise" + +CHIP_VARIANT = RP2350 +CHIP_PACKAGE = A +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "GD25Q32C,W25Q32JVxQ" + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD diff --git a/ports/raspberrypi/boards/datanoise_picoadk_v2/pico-sdk-configboard.h b/ports/raspberrypi/boards/datanoise_picoadk_v2/pico-sdk-configboard.h new file mode 100644 index 000000000000..ce5a7645b4e2 --- /dev/null +++ b/ports/raspberrypi/boards/datanoise_picoadk_v2/pico-sdk-configboard.h @@ -0,0 +1,12 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +// Put board-specific pico-sdk definitions here. This file must exist. + +// Allow extra time for xosc to start. +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 diff --git a/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c b/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c new file mode 100644 index 000000000000..8c2ab123f427 --- /dev/null +++ b/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c @@ -0,0 +1,62 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_CS0), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO12) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_MIDI_RX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_DIN), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_I2S_DOUT), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_I2S_BCLK), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_I2S_LRCLK), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_I2S_MCLK), MP_ROM_PTR(&pin_GPIO19) }, + + { MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_DAT0), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_DAT1), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_DAT2), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_DAT3), MP_ROM_PTR(&pin_GPIO25) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + + { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_D29), MP_ROM_PTR(&pin_GPIO19) } +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From b7f6f5c62d002ec3891caa95057a535f2fe30b56 Mon Sep 17 00:00:00 2001 From: DatanoiseTV Date: Tue, 8 Oct 2024 18:31:59 +0200 Subject: [PATCH 091/252] Rename Datanoise PicoADK V2 pins to be compatible with examples. --- ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c b/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c index 8c2ab123f427..ae58f8190b1a 100644 --- a/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c +++ b/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c @@ -42,12 +42,12 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_I2S_LRCLK), MP_ROM_PTR(&pin_GPIO18) }, { MP_ROM_QSTR(MP_QSTR_I2S_MCLK), MP_ROM_PTR(&pin_GPIO19) }, - { MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO20) }, - { MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO21) }, - { MP_ROM_QSTR(MP_QSTR_SDIO_DAT0), MP_ROM_PTR(&pin_GPIO22) }, - { MP_ROM_QSTR(MP_QSTR_SDIO_DAT1), MP_ROM_PTR(&pin_GPIO23) }, - { MP_ROM_QSTR(MP_QSTR_SDIO_DAT2), MP_ROM_PTR(&pin_GPIO24) }, - { MP_ROM_QSTR(MP_QSTR_SDIO_DAT3), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_CLOCK), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_COMMAND), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA0), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA1), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA3), MP_ROM_PTR(&pin_GPIO25) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, From b8d25e59c4e220bf8525b6272418e248bfeb822d Mon Sep 17 00:00:00 2001 From: DatanoiseTV Date: Tue, 8 Oct 2024 18:32:35 +0200 Subject: [PATCH 092/252] Remove old pins from Datanoise PicoADK V2. --- ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c b/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c index ae58f8190b1a..39c6c6054882 100644 --- a/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c +++ b/ports/raspberrypi/boards/datanoise_picoadk_v2/pins.c @@ -52,11 +52,6 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, - - { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO26) }, - { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_GPIO28) }, - { MP_ROM_QSTR(MP_QSTR_D29), MP_ROM_PTR(&pin_GPIO19) } + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) } }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 557ee26874f862250bc4a179b98fffc98e751506 Mon Sep 17 00:00:00 2001 From: Sylwester <6614616+DatanoiseTV@users.noreply.github.com> Date: Tue, 8 Oct 2024 20:48:47 +0200 Subject: [PATCH 093/252] Update ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h Co-authored-by: Dan Halbert --- .../raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h b/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h index 339f1113176c..d14f625d6185 100644 --- a/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h +++ b/ports/raspberrypi/boards/datanoise_picoadk_v2/mpconfigboard.h @@ -13,9 +13,9 @@ #define DEFAULT_I2C_BUS_SCL (&pin_GPIO9) #define DEFAULT_I2C_BUS_SDA (&pin_GPIO8) -#define DEFAULT_SPI_BUS_SCK (&pin_GPIO18) -#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO12) -#define DEFAULT_SPI_BUS_MISO (&pin_GPIO20) +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO6) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO3) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO4) #define DEFAULT_UART_BUS_RX (&pin_GPIO13) #define DEFAULT_UART_BUS_TX (&pin_GPIO12) From d2e82bd55b23b46d1b65992f7b6d7bf0821c2d1d Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 8 Oct 2024 16:29:35 -0400 Subject: [PATCH 094/252] conf.py: remove deprecated get_html_theme_path() --- conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/conf.py b/conf.py index 7120fa3f00a3..6c30a43abb1f 100644 --- a/conf.py +++ b/conf.py @@ -277,7 +277,6 @@ def autoapi_prepare_jinja_env(jinja_env): import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the From 04fd6ecf0bf2fac2b93fc7295bb6a17e761a2058 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 8 Oct 2024 13:37:54 -0700 Subject: [PATCH 095/252] Move RP2040 divider wrapper to RAM This fixes picodvi and will speed up division too. Fixes #9628 --- ports/raspberrypi/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index fd4da22ea08f..c0708acbc7ac 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -158,7 +158,7 @@ CFLAGS += \ -DPICO_DOUBLE_ROM=1 \ -DPICO_FLOAT_ROM=1 \ -DPICO_BITS_IN_RAM=0 \ - -DPICO_DIVIDER_IN_RAM=0 \ + -DPICO_DIVIDER_IN_RAM=1 \ -DPICO_DOUBLE_PROPAGATE_NANS=0 \ -DPICO_DOUBLE_IN_RAM=0 \ -DPICO_MEM_IN_RAM=0 \ From ed0e640fb8eb00fcac455034fe3eea18d07da81b Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 8 Oct 2024 15:01:47 -0700 Subject: [PATCH 096/252] MDNS hostname match DHCP. Fix collision mangling MDNS defaults to the hostname used by DHCP/LWIP since it is now unique. This makes it the same either way. This also updates esp-protocols (used for mdns) with a patch to ensure that mangled names are the ones that collide. (circuitpython.local collides but was causing cpy- to be mangled.) Fixes #6869 again. --- .gitmodules | 3 ++- ports/espressif/common-hal/mdns/Server.c | 7 +++---- ports/espressif/common-hal/mdns/Server.h | 1 - ports/espressif/common-hal/wifi/__init__.c | 15 ++++++++++++--- ports/espressif/esp-protocols | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.gitmodules b/.gitmodules index cf0e554e26ba..c01f23dbe6e1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -146,7 +146,8 @@ branch = circuitpython-v5.3.1 [submodule "ports/espressif/esp-protocols"] path = ports/espressif/esp-protocols - url = https://github.com/espressif/esp-protocols.git + url = https://github.com/adafruit/esp-protocols.git + branch = circuitpython [submodule "ports/espressif/esp-camera"] path = ports/espressif/esp-camera url = https://github.com/adafruit/esp32-camera.git diff --git a/ports/espressif/common-hal/mdns/Server.c b/ports/espressif/common-hal/mdns/Server.c index 81a4415cecd8..e8c34ee0885c 100644 --- a/ports/espressif/common-hal/mdns/Server.c +++ b/ports/espressif/common-hal/mdns/Server.c @@ -33,10 +33,9 @@ void mdns_server_construct(mdns_server_obj_t *self, bool workflow) { } _active_object = self; - uint8_t mac[6]; - esp_netif_get_mac(common_hal_wifi_radio_obj.netif, mac); - snprintf(self->default_hostname, sizeof(self->default_hostname), "cpy-%02x%02x%02x", mac[3], mac[4], mac[5]); - common_hal_mdns_server_set_hostname(self, self->default_hostname); + // Match the netif hostname set when `import wifi` was called. + esp_netif_get_hostname(common_hal_wifi_radio_obj.netif, &self->hostname); + common_hal_mdns_server_set_hostname(self, self->hostname); self->inited = true; diff --git a/ports/espressif/common-hal/mdns/Server.h b/ports/espressif/common-hal/mdns/Server.h index 42ffd878d13a..f364a539c917 100644 --- a/ports/espressif/common-hal/mdns/Server.h +++ b/ports/espressif/common-hal/mdns/Server.h @@ -12,7 +12,6 @@ typedef struct { mp_obj_base_t base; const char *hostname; const char *instance_name; - char default_hostname[sizeof("cpy-XXXXXX")]; // Track if this object owns access to the underlying MDNS service. bool inited; } mdns_server_obj_t; diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index c0d547cc08fe..710688b9d31c 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -199,11 +199,20 @@ void common_hal_wifi_init(bool user_initiated) { ESP_LOGE(TAG, "WiFi error code: %x", result); return; } - // set the default lwip_local_hostname - char cpy_default_hostname[strlen(CIRCUITPY_BOARD_ID) + (MAC_ADDRESS_LENGTH * 2) + 6]; + // Set the default lwip_local_hostname capped at 32 characters. We trim off + // the start of the board name (likely manufacturer) because the end is + // often more unique to the board. + size_t board_len = MIN(32 - ((MAC_ADDRESS_LENGTH * 2) + 6), strlen(CIRCUITPY_BOARD_ID)); + size_t board_trim = strlen(CIRCUITPY_BOARD_ID) - board_len; + // Avoid double _ in the hostname. + if (CIRCUITPY_BOARD_ID[board_trim] == '_') { + board_trim++; + } + + char cpy_default_hostname[board_len + (MAC_ADDRESS_LENGTH * 2) + 6]; uint8_t mac[MAC_ADDRESS_LENGTH]; esp_wifi_get_mac(ESP_IF_WIFI_STA, mac); - sprintf(cpy_default_hostname, "cpy_%s_%x", CIRCUITPY_BOARD_ID, (unsigned int)mac); + snprintf(cpy_default_hostname, sizeof(cpy_default_hostname), "cpy-%s-%x", CIRCUITPY_BOARD_ID + board_trim, (unsigned int)mac); const char *default_lwip_local_hostname = cpy_default_hostname; ESP_ERROR_CHECK(esp_netif_set_hostname(self->netif, default_lwip_local_hostname)); // set station mode to avoid the default SoftAP diff --git a/ports/espressif/esp-protocols b/ports/espressif/esp-protocols index ea54eef0d0fe..2f492c022890 160000 --- a/ports/espressif/esp-protocols +++ b/ports/espressif/esp-protocols @@ -1 +1 @@ -Subproject commit ea54eef0d0fe59bd53a49c916f87065518b957eb +Subproject commit 2f492c02289015ecbb36851dd1bd04e0eb0a9937 From 390c280d2b28c3ab3bb12437c98be59562dd8a86 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 8 Oct 2024 15:49:19 -0700 Subject: [PATCH 097/252] Turn off keypad demux on ESP32-C3 --- ports/espressif/mpconfigport.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index 4bc24a720ca5..e80c9654040b 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -136,6 +136,9 @@ CIRCUITPY_TOUCHIO_USE_NATIVE = 0 CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 +# No room in flash. +CIRCUITPY_KEYPAD_DEMUX = 0 + else ifeq ($(IDF_TARGET),esp32c6) # Modules CIRCUITPY_ESPCAMERA = 0 From ed563a1882fd09314d2008dabd72d4792344e5d5 Mon Sep 17 00:00:00 2001 From: Kamborio Date: Tue, 8 Oct 2024 07:44:43 +0000 Subject: [PATCH 098/252] Translated using Weblate (Spanish) Currently translated at 97.8% (978 of 1000 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/es/ --- locale/es.po | 191 ++++++++++++++++++++++++++------------------------- 1 file changed, 97 insertions(+), 94 deletions(-) diff --git a/locale/es.po b/locale/es.po index 2eea525f4124..309e00c224c5 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,15 +8,15 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-11-16 15:03+0000\n" -"Last-Translator: RubenD \n" +"PO-Revision-Date: 2024-10-09 08:15+0000\n" +"Last-Translator: Kamborio \n" "Language-Team: \n" "Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 5.2\n" +"X-Generator: Weblate 5.8-dev\n" #: main.c msgid "" @@ -107,7 +107,7 @@ msgstr "" #: ports/nordic/common-hal/watchdog/WatchDogTimer.c msgid "%q cannot be changed once mode is set to %q" -msgstr "" +msgstr "no se puede cambiar %q una vez que se establece el modo a %q" #: shared-bindings/microcontroller/Pin.c msgid "%q contains duplicate pins" @@ -171,7 +171,7 @@ msgstr "%q longitud debe ser >= %d" #: py/modsys.c py/objmodule.c py/runtime.c msgid "%q moved from %q to %q" -msgstr "" +msgstr "%q movido de %q a %q" #: py/argcheck.c msgid "%q must be %d" @@ -196,7 +196,7 @@ msgstr "%q debe ser <= %d" #: ports/espressif/common-hal/watchdog/WatchDogTimer.c msgid "%q must be <= %u" -msgstr "" +msgstr "%q debe ser <= %u" #: py/argcheck.c msgid "%q must be >= %d" @@ -212,7 +212,7 @@ msgstr "%q debe ser un bytearray o array de tipo 'h', 'H', 'b', o 'B'" #: shared-bindings/warnings/__init__.c msgid "%q must be a subclass of %q" -msgstr "" +msgstr "%q debe ser una subclase de %q" #: ports/espressif/common-hal/analogbufio/BufferedIn.c msgid "%q must be array of type 'H'" @@ -224,7 +224,7 @@ msgstr "%q debe ser una matriz de tipo 'h'" #: shared-bindings/audiobusio/PDMIn.c msgid "%q must be multiple of 8." -msgstr "" +msgstr "%q debe ser múltiplo de 8." #: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c #: shared-bindings/bitmapfilter/__init__.c shared-bindings/canio/CAN.c @@ -235,7 +235,7 @@ msgstr "%q debe ser del tipo %q o %q, y no %q" #: shared-bindings/jpegio/JpegDecoder.c msgid "%q must be of type %q, %q, or %q, not %q" -msgstr "" +msgstr "%q debe ser de tipo %q, %q, o %q, no %q" #: py/argcheck.c py/runtime.c shared-bindings/bitmapfilter/__init__.c #: shared-module/synthio/__init__.c @@ -261,7 +261,7 @@ msgstr "%q fuera de rango" #: py/objmodule.c py/runtime.c msgid "%q renamed %q" -msgstr "" +msgstr "%q renombrado %q" #: py/objrange.c py/objslice.c shared-bindings/random/__init__.c msgid "%q step cannot be zero" @@ -269,7 +269,7 @@ msgstr "%q paso no puede ser cero" #: shared-module/bitbangio/I2C.c msgid "%q too long" -msgstr "" +msgstr "%q demasiado largo" #: py/bc.c py/objnamedtuple.c msgid "%q() takes %d positional arguments but %d were given" @@ -277,7 +277,7 @@ msgstr "%q() toma %d argumentos posicionales pero %d fueron dados" #: shared-module/jpegio/JpegDecoder.c msgid "%q() without %q()" -msgstr "" +msgstr "%q() sin %q()" #: shared-bindings/usb_hid/Device.c msgid "%q, %q, and %q must all be the same length" @@ -415,7 +415,7 @@ msgstr "'await' fuera de la función" #: py/compile.c msgid "'break'/'continue' outside loop" -msgstr "" +msgstr "'break'/'continue' fuera del bucle" #: py/compile.c msgid "'data' requires at least 2 arguments" @@ -431,7 +431,7 @@ msgstr "'label' requiere 1 argumento" #: py/emitnative.c msgid "'not' not implemented" -msgstr "" +msgstr "'not' no implementado" #: py/compile.c msgid "'return' outside function" @@ -461,7 +461,7 @@ msgstr ", en %q\n" #: shared-bindings/epaperdisplay/EPaperDisplay.c #: shared-bindings/framebufferio/FramebufferDisplay.c msgid ".show(x) removed. Use .root_group = x" -msgstr "" +msgstr ".show(x) eliminado. Utiliza .root_group = x" #: py/objcomplex.c msgid "0.0 to a complex power" @@ -473,7 +473,7 @@ msgstr "pow() con 3 argumentos no soportado" #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "AP could not be started" -msgstr "" +msgstr "No se pudo iniciar el Punto de Acceso" #: shared-bindings/_bleio/Address.c shared-bindings/ipaddress/IPv4Address.c #, c-format @@ -642,7 +642,7 @@ msgstr "Por debajo de la tasa mínima de refrescamiento" #: ports/raspberrypi/common-hal/audiobusio/I2SOut.c msgid "Bit clock and word select must be sequential GPIO pins" -msgstr "" +msgstr "Reloj de bit y selección de palabra deben ser pines secuenciales GPIO" #: shared-bindings/bitmaptools/__init__.c msgid "Bitmap size and bits per value must match" @@ -687,7 +687,7 @@ msgstr "" #: shared-module/sdcardio/SDCard.c #, c-format msgid "Buffer must be a multiple of %d bytes" -msgstr "" +msgstr "El búfer debe ser múltiplo de %d bytes" #: shared-bindings/_bleio/PacketBuffer.c #, c-format @@ -881,7 +881,7 @@ msgstr "Trozo de datos debe seguir fmt chunk" #: shared-module/jpegio/JpegDecoder.c msgid "Data format error (may be broken data)" -msgstr "" +msgstr "Error de formato de datos (pueden ser datos incompletos)" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nordic/common-hal/_bleio/Adapter.c @@ -904,7 +904,7 @@ msgstr "Capacidad de destino es mas pequeña que destination_length." #: shared-module/jpegio/JpegDecoder.c msgid "Device error or wrong termination of input stream" -msgstr "" +msgstr "Error de dispositivo o terminación errónea del flujo de entrada" #: ports/nordic/common-hal/audiobusio/I2SOut.c msgid "Device in use" @@ -1156,7 +1156,7 @@ msgstr "La entrada está durando mucho tiempo" #: py/moderrno.c msgid "Input/output error" -msgstr "error Input/output" +msgstr "Error input/output" #: ports/espressif/common-hal/_bleio/__init__.c #: ports/nordic/common-hal/_bleio/__init__.c @@ -1170,11 +1170,11 @@ msgstr "Cifrado insuficiente" #: shared-module/jpegio/JpegDecoder.c msgid "Insufficient memory pool for the image" -msgstr "" +msgstr "Reserva de memoria insuficiente para la imagen" #: shared-module/jpegio/JpegDecoder.c msgid "Insufficient stream input buffer" -msgstr "" +msgstr "Búfer de flujo de entrada insuficiente" #: ports/espressif/common-hal/wifi/Radio.c msgid "Interface must be started" @@ -1208,7 +1208,7 @@ msgstr "Error interno #%d" #: ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c #: shared-bindings/pwmio/PWMOut.c msgid "Internal resource(s) in use" -msgstr "" +msgstr "Recurso(s) interno(s) en uso" #: supervisor/shared/safe_mode.c msgid "Internal watchdog timer expired." @@ -1220,7 +1220,7 @@ msgstr "Error de interrupción." #: shared-module/jpegio/JpegDecoder.c msgid "Interrupted by output function" -msgstr "" +msgstr "Interrumpido por resultado de función" #: ports/espressif/common-hal/_bleio/Service.c #: ports/espressif/common-hal/espulp/ULP.c @@ -1239,7 +1239,7 @@ msgstr "%q inválido" #: ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c #: shared-module/aurora_epaper/aurora_framebuffer.c msgid "Invalid %q and %q" -msgstr "" +msgstr "%q y %q no válidos" #: ports/atmel-samd/common-hal/microcontroller/Pin.c #: ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c @@ -1276,7 +1276,7 @@ msgstr "Inválido bits por valor" #: shared-module/os/getenv.c #, c-format msgid "Invalid byte %.*s" -msgstr "byte %.*s Inválido" +msgstr "Byte %.*s no válido" #: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c #, c-format @@ -1305,7 +1305,7 @@ msgstr "Tamaño incorrecto" #: shared-module/ssl/SSLSocket.c msgid "Invalid socket for TLS" -msgstr "socket invalido para TLS" +msgstr "Socket invalido para TLS" #: ports/espressif/common-hal/espidf/__init__.c msgid "Invalid state" @@ -1341,7 +1341,7 @@ msgstr "El Layer debe ser un grupo o una subclase de TileGrid" #: shared-bindings/audiocore/RawSample.c msgid "Length of %q must be an even multiple of channel_count * type_size" -msgstr "" +msgstr "La longitud de %q debe ser un múltiplo par de channel_count * type_size" #: ports/espressif/common-hal/espidf/__init__.c msgid "MAC address was invalid" @@ -1350,7 +1350,7 @@ msgstr "La dirección MAC es incorrecta" #: ports/espressif/common-hal/_bleio/Characteristic.c #: ports/espressif/common-hal/_bleio/Descriptor.c msgid "MITM security not supported" -msgstr "" +msgstr "Seguridad MITM no compatible" #: shared-bindings/is31fl3741/IS31FL3741.c msgid "Mapping must be a tuple" @@ -1395,7 +1395,7 @@ msgstr "Falta jmp_pin. %q[%u] salta en pin" #: shared-module/storage/__init__.c msgid "Mount point directory missing" -msgstr "" +msgstr "Falta el directorio de punto de montaje" #: shared-bindings/busio/UART.c shared-bindings/displayio/Group.c msgid "Must be a %q subclass." @@ -1403,7 +1403,7 @@ msgstr "Debe de ser una subclase de %q." #: ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c msgid "Must provide 5/6/5 RGB pins" -msgstr "" +msgstr "Debe proporcionar los pines RGB 5/6/5" #: ports/mimxrt10xx/common-hal/busio/SPI.c shared-bindings/busio/SPI.c msgid "Must provide MISO or MOSI pin" @@ -1467,7 +1467,7 @@ msgstr "No se encontró el canal DMA" #: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c msgid "No DMA pacing timer found" -msgstr "timer por establecedor de paso DMA no encontrado" +msgstr "Temporizador DMA no encontrado" #: shared-module/adafruit_bus_device/i2c_device/I2CDevice.c #, c-format @@ -1578,13 +1578,13 @@ msgstr "No reproduciendo" #: shared-module/jpegio/JpegDecoder.c msgid "Not supported JPEG standard" -msgstr "" +msgstr "Estándar JPEG no compatible" #: ports/espressif/common-hal/paralleldisplaybus/ParallelBus.c #: ports/espressif/common-hal/sdioio/SDCard.c #, c-format msgid "Number of data_pins must be %d or %d, not %d" -msgstr "" +msgstr "El número de data_pins debe ser %d o %d, no %d" #: shared-bindings/util.c msgid "" @@ -1720,7 +1720,7 @@ msgstr "Segmento del PWM canal A ya esta en uso" #: shared-module/jpegio/JpegDecoder.c msgid "Parameter error" -msgstr "" +msgstr "Error de parámetro" #: ports/espressif/common-hal/audiobusio/__init__.c msgid "Peripheral in use" @@ -1901,7 +1901,7 @@ msgstr "Canal derecho no soportado" #: shared-module/jpegio/JpegDecoder.c msgid "Right format but not supported" -msgstr "" +msgstr "Formato correcto pero no compatible" #: main.c msgid "Running in safe mode! Not running saved code.\n" @@ -1992,7 +1992,7 @@ msgstr "Especifique exactamente uno de data0 or data_pins" #: supervisor/shared/safe_mode.c msgid "Stack overflow. Increase stack size." -msgstr "" +msgstr "Desbordamiento de pila. Aumenta el tamaño de pila." #: shared-bindings/alarm/time/TimeAlarm.c msgid "Supply one of monotonic_time or epoch_time" @@ -2165,7 +2165,7 @@ msgstr "UUID valor no es un str, int o byte buffer" #: ports/raspberrypi/common-hal/memorymap/AddressRange.c msgid "Unable to access unaligned IO register" -msgstr "" +msgstr "Incapaz de acceder al registro no alineado de IO" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -2207,7 +2207,7 @@ msgstr "Imposible escribir en nvm." #: ports/raspberrypi/common-hal/memorymap/AddressRange.c msgid "Unable to write to read-only memory" -msgstr "" +msgstr "Incapaz de escribir en memoria de solo lectura" #: shared-bindings/alarm/SleepMemory.c msgid "Unable to write to sleep_memory." @@ -2300,12 +2300,12 @@ msgstr "Algoritmo hash no soportado" #: ports/espressif/common-hal/socketpool/Socket.c msgid "Unsupported socket type" -msgstr "" +msgstr "Tipo de socket no compatible" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/espressif/common-hal/dualbank/__init__.c msgid "Update failed" -msgstr "" +msgstr "Actualización fallida" #: ports/espressif/common-hal/_bleio/Characteristic.c #: ports/nordic/common-hal/_bleio/Characteristic.c @@ -2384,7 +2384,7 @@ msgstr "Usted presionó el botón A al iniciar." #: ports/espressif/boards/m5stack_m5paper/mpconfigboard.h msgid "You pressed button DOWN at start up." -msgstr "" +msgstr "Usted presionó el botón DOWN en el arranque." #: supervisor/shared/safe_mode.c msgid "You pressed the BOOT button at start up" @@ -2393,7 +2393,7 @@ msgstr "Usted presionó el botón BOOT al iniciar" #: ports/espressif/boards/adafruit_feather_esp32c6_4mbflash_nopsram/mpconfigboard.h #: ports/espressif/boards/adafruit_itsybitsy_esp32/mpconfigboard.h msgid "You pressed the BOOT button at start up." -msgstr "" +msgstr "Usted presionó el botón BOOT en el arranque." #: ports/espressif/boards/adafruit_huzzah32_breakout/mpconfigboard.h msgid "You pressed the GPIO0 button at start up." @@ -2470,15 +2470,15 @@ msgstr "arg debe ser tipo-user" #: extmod/ulab/code/numpy/numerical.c msgid "argsort argument must be an ndarray" -msgstr "El argumento para argsort debe ser un ndarray" +msgstr "el argumento para argsort debe ser un ndarray" #: extmod/ulab/code/numpy/numerical.c msgid "argsort is not implemented for flattened arrays" -msgstr "El argot no está implementado para arrays aplanados" +msgstr "argsort no está implementado para arrays aplanados" #: extmod/ulab/code/numpy/random/random.c msgid "argument must be None, an integer or a tuple of integers" -msgstr "" +msgstr "el argumento debe ser None, un entero o una tupla de enteros" #: py/compile.c msgid "argument name reused" @@ -2495,11 +2495,11 @@ msgstr "argumentos deben ser ndarrays" #: extmod/ulab/code/ndarray.c msgid "array and index length must be equal" -msgstr "Longitud del array e índice tienen que ser iguales" +msgstr "las longitudes del array e índice deben ser iguales" #: extmod/ulab/code/numpy/io/io.c msgid "array has too many dimensions" -msgstr "La matriz tiene demasiadas dimensiones" +msgstr "la matriz tiene demasiadas dimensiones" #: extmod/ulab/code/ndarray.c msgid "array is too big" @@ -2516,11 +2516,11 @@ msgstr "desborde de asm" #: py/compile.c msgid "async for/with outside async function" -msgstr "" +msgstr "async for/with fuera de función async" #: extmod/ulab/code/numpy/numerical.c msgid "attempt to get (arg)min/(arg)max of empty sequence" -msgstr "Intendo de obteber (arg)min/(arg)max de secuencia vacía" +msgstr "intento de obtener (arg)min/(arg)max de secuencia vacía" #: extmod/ulab/code/numpy/numerical.c msgid "attempt to get argmin/argmax of an empty sequence" @@ -2528,23 +2528,23 @@ msgstr "intento de obtener argmin/argmax de una secuencia vacía" #: py/objstr.c msgid "attributes not supported" -msgstr "" +msgstr "atributos no compatibles" #: extmod/ulab/code/ulab_tools.c msgid "axis is out of bounds" -msgstr "Eje está fuera de sus límites" +msgstr "eje está fuera de sus límites" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c msgid "axis must be None, or an integer" -msgstr "Eje tiene que ser None, o un entero" +msgstr "eje debe ser None, o un entero" #: extmod/ulab/code/numpy/numerical.c msgid "axis too long" -msgstr "Eje demasiado largo" +msgstr "eje demasiado largo" #: shared-bindings/bitmaptools/__init__.c msgid "background value out of range of target" -msgstr "El valor del fondo esta fuera del rango del objectivo" +msgstr "el valor del fondo esta fuera del rango del objetivo" #: py/builtinevex.c msgid "bad compile mode" @@ -2568,11 +2568,11 @@ msgstr "operacion binaria %q no implementada" #: shared-module/bitmapfilter/__init__.c msgid "bitmap size and depth must match" -msgstr "" +msgstr "el tamaño y profundidad del mapa de bits deben coincidir" #: shared-bindings/bitmaptools/__init__.c msgid "bitmap sizes must match" -msgstr "Los tamaños de los bitmap deben coincidir" +msgstr "los tamaños de los bitmap deben coincidir" #: extmod/modrandom.c msgid "bits must be 32 or less" @@ -2588,11 +2588,11 @@ msgstr "la rama no está dentro del rango" #: extmod/ulab/code/numpy/create.c extmod/ulab/code/utils/utils.c msgid "buffer is smaller than requested size" -msgstr "El buffer es mas pequeño que el requerido" +msgstr "el búfer es más pequeño que el tamaño solicitado" #: extmod/ulab/code/numpy/create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" -msgstr "El tamaño del buffer debe ser un múltiplo del tamaño del elemento" +msgstr "el tamaño del búfer debe ser un múltiplo del tamaño del elemento" #: shared-module/struct/__init__.c msgid "buffer size must match format" @@ -2600,7 +2600,7 @@ msgstr "el tamaño del buffer debe de coincidir con el formato" #: shared-bindings/bitbangio/SPI.c shared-bindings/busio/SPI.c msgid "buffer slices must be of equal length" -msgstr "Las secciones del buffer necesitan tener longitud igual" +msgstr "las secciones del búfer deben tener la misma longitud" #: py/modstruct.c shared-module/struct/__init__.c msgid "buffer too small" @@ -2724,7 +2724,7 @@ msgstr "no se puede convertir implícitamente '%q' a 'bool'" #: py/runtime.c msgid "can't import name %q" -msgstr "" +msgstr "no se puede importar el nombre %q" #: py/emitnative.c msgid "can't load from '%q'" @@ -2794,8 +2794,9 @@ msgid "cannot assign new shape" msgstr "no se puede asignar una nueva forma" #: extmod/ulab/code/ndarray_operators.c +#, fuzzy msgid "cannot cast output with casting rule" -msgstr "No se puede realizar cast de la salida sin una regla de cast" +msgstr "no se puede realizar cast de la salida sin una regla de cast" #: extmod/ulab/code/ndarray.c msgid "cannot convert complex to dtype" @@ -2835,15 +2836,15 @@ msgstr "chars buffer es demasiado pequeño" #: py/modbuiltins.c msgid "chr() arg not in range(0x110000)" -msgstr "El argumento de chr() esta fuera de rango(0x110000)" +msgstr "argumento chr() está fuera de rango(0x110000)" #: py/modbuiltins.c msgid "chr() arg not in range(256)" -msgstr "El argumento de chr() no esta en el rango(256)" +msgstr "argumento chr() no está en el rango(256)" #: shared-bindings/bitmaptools/__init__.c msgid "clip point must be (x,y) tuple" -msgstr "El punto de recorte debe ser una tupla (x, y)" +msgstr "el punto de recorte debe ser una tupla (x, y)" #: shared-bindings/msgpack/ExtType.c msgid "code outside range 0~127" @@ -2871,7 +2872,7 @@ msgstr "comparación entre int y uint" #: py/objcomplex.c msgid "complex divide by zero" -msgstr "" +msgstr "división compleja entre cero" #: py/objfloat.c py/parsenum.c msgid "complex values not supported" @@ -2899,7 +2900,7 @@ msgstr "los argumentos para convolve no deben estar vacíos" #: extmod/ulab/code/numpy/io/io.c msgid "corrupted file" -msgstr "Archivo corrompido" +msgstr "archivo corrompido" #: extmod/ulab/code/numpy/poly.c msgid "could not invert Vandermonde matrix" @@ -2911,7 +2912,7 @@ msgstr "no se pudo determinar la versión de la tarjeta SD" #: extmod/ulab/code/numpy/numerical.c msgid "cross is defined for 1D arrays of length 3" -msgstr "Cruce está definido para un array 1D de longitud 3" +msgstr "cruce está definido para un array 1D de longitud 3" #: extmod/ulab/code/scipy/optimize/optimize.c msgid "data must be iterable" @@ -2959,11 +2960,11 @@ msgstr "la secuencia de actualizacion del dict tiene una longitud incorrecta" #: extmod/ulab/code/numpy/numerical.c msgid "diff argument must be an ndarray" -msgstr "El argumento diff debe ser un ndarray" +msgstr "el argumento diff debe ser un ndarray" #: extmod/ulab/code/numpy/numerical.c msgid "differentiation order out of range" -msgstr "Orden de diferenciación fuera de rango" +msgstr "órden de diferenciación fuera de rango" #: extmod/ulab/code/numpy/transform.c msgid "dimensions do not match" @@ -2987,7 +2988,7 @@ msgstr "dtype debe ser float, o complex" #: extmod/ulab/code/ndarray_operators.c msgid "dtype of int32 is not supported" -msgstr "" +msgstr "dtype de int32 no compatible" #: py/objdeque.c msgid "empty" @@ -3086,7 +3087,7 @@ msgstr "el primer argumento debe ser una función" #: extmod/ulab/code/numpy/create.c msgid "first argument must be a tuple of ndarrays" -msgstr "Primer argumento tiene que ser una tupla de ndarrays" +msgstr "el primer argumento debe ser una tupla de ndarrays" #: extmod/ulab/code/numpy/transform.c extmod/ulab/code/numpy/vector.c msgid "first argument must be an ndarray" @@ -3122,7 +3123,7 @@ msgstr "font debe ser 2048 bytes de largo" #: extmod/moddeflate.c msgid "format" -msgstr "" +msgstr "formato" #: py/objstr.c msgid "format requires a dict" @@ -3151,7 +3152,7 @@ msgstr "la función tiene el mismo signo a extremos del intervalo" #: extmod/ulab/code/ndarray.c msgid "function is defined for ndarrays only" -msgstr "Función solo definida para ndarrays" +msgstr "función solo definida para ndarrays" #: extmod/ulab/code/numpy/carray/carray.c msgid "function is implemented for ndarrays only" @@ -3293,7 +3294,7 @@ msgstr "el tamaño del arreglo de entrada debe ser potencia de 2" #: extmod/ulab/code/numpy/create.c msgid "input arrays are not compatible" -msgstr "Arrays de entrada no son compactibles" +msgstr "matrices de entrada no son compatibles" #: extmod/ulab/code/numpy/poly.c msgid "input data must be an iterable" @@ -3326,11 +3327,11 @@ msgstr "entrada debe ser un ndarray de 1D" #: extmod/ulab/code/scipy/linalg/linalg.c extmod/ulab/code/user/user.c msgid "input must be a dense ndarray" -msgstr "Entrada tiene que ser un ndarray denso" +msgstr "la entrada debe ser un ndarray denso" #: extmod/ulab/code/user/user.c shared-bindings/_eve/__init__.c msgid "input must be an ndarray" -msgstr "Entrada tiene que ser un ndarray" +msgstr "la entrada debe ser un ndarray" #: extmod/ulab/code/numpy/carray/carray.c msgid "input must be an ndarray, or a scalar" @@ -3338,7 +3339,7 @@ msgstr "entrada debe ser una ndarray o un escalar" #: extmod/ulab/code/scipy/signal/signal.c msgid "input must be one-dimensional" -msgstr "Entrada tiene que ser unidimensional" +msgstr "la entrada debe ser unidimensional" #: extmod/ulab/code/ulab_tools.c msgid "input must be square matrix" @@ -3363,7 +3364,7 @@ msgstr "el intervalo debe ser der rango %s-%s" #: py/compile.c msgid "invalid arch" -msgstr "" +msgstr "arco no válido" #: shared-bindings/bitmaptools/__init__.c #, c-format @@ -3449,6 +3450,8 @@ msgstr "" #: py/argcheck.c msgid "keyword argument(s) not implemented - use normal args instead" msgstr "" +"argumento(s) de palabras clave no implementado - en su lugar utiliza " +"argumentos normales" #: py/emitinlinethumb.c py/emitinlinextensa.c msgid "label '%q' not defined" @@ -3480,7 +3483,7 @@ msgstr "variable local referenciada antes de la asignación" #: ports/espressif/common-hal/canio/CAN.c msgid "loopback + silent mode not supported by peripheral" -msgstr "Loopback + modo silencioso no están soportados por periférico" +msgstr "bucle de retorno + modo silencioso no admitidos por periférico" #: ports/espressif/common-hal/mdns/Server.c #: ports/raspberrypi/common-hal/mdns/Server.c @@ -3555,7 +3558,7 @@ msgstr "" #: extmod/modtime.c msgid "mktime needs a tuple of length 8 or 9" -msgstr "" +msgstr "mktime requiere una tupla de longitud 8 o 9" #: extmod/ulab/code/numpy/linalg/linalg.c msgid "mode must be complete, or reduced" @@ -3603,11 +3606,11 @@ msgstr "name no definido" #: py/qstr.c msgid "name too long" -msgstr "" +msgstr "nombre demasiado largo" #: py/persistentcode.c msgid "native code in .mpy unsupported" -msgstr "" +msgstr "código nativo .mpy no compatible" #: py/asmthumb.c msgid "native method too big" @@ -3866,7 +3869,7 @@ msgstr "ord() espera un carácter, pero encontró un string de longitud %d" #: extmod/ulab/code/utils/utils.c msgid "out array is too small" -msgstr "La matriz de salida es demasiado pequeña" +msgstr "la matriz de salida es demasiado pequeña" #: extmod/ulab/code/numpy/random/random.c msgid "out has wrong type" @@ -3898,11 +3901,11 @@ msgstr "fuera de rango del objetivo" #: extmod/ulab/code/numpy/random/random.c msgid "output array has wrong type" -msgstr "" +msgstr "matriz de salida tiene el tipo erróneo" #: extmod/ulab/code/numpy/random/random.c msgid "output array must be contiguous" -msgstr "" +msgstr "matriz de salida debe ser contiguo" #: py/objint_mpz.c msgid "overflow converting long int to machine word" @@ -4007,7 +4010,7 @@ msgstr "rgb_pins[%d] no está en el mismo puerto que el reloj" #: extmod/ulab/code/numpy/numerical.c msgid "roll argument must be an ndarray" -msgstr "Argumento enrolado tiene que ser un ndarray" +msgstr "argumento enrolado tiene que ser un ndarray" #: py/objstr.c msgid "rsplit(None,n)" @@ -4032,7 +4035,7 @@ msgstr "sin capacidades para el conjunto" #: extmod/ulab/code/numpy/random/random.c msgid "shape must be None, and integer or a tuple of integers" -msgstr "" +msgstr "shape debe ser None, un entero o una tupla de enteros" #: extmod/ulab/code/ndarray.c msgid "shape must be integer or tuple of integers" @@ -4056,7 +4059,7 @@ msgstr "el tamaño se define solo para ndarrays" #: extmod/ulab/code/numpy/random/random.c msgid "size must match out.shape when used together" -msgstr "" +msgstr "out.shape y el tamaño deben coincidir cuando se usan juntos" #: py/nativeglue.c msgid "slice unsupported" @@ -4120,7 +4123,7 @@ msgstr "operación stream no soportada" #: py/objarray.c py/objstr.c msgid "string argument without an encoding" -msgstr "" +msgstr "argumento de cadena de texto sin codificación" #: py/objstrunicode.c msgid "string index out of range" @@ -4145,7 +4148,7 @@ msgstr "error de sintaxis en JSON" #: extmod/modtime.c msgid "ticks interval overflow" -msgstr "" +msgstr "desbordamiento de intervalo de ticks" #: ports/nordic/common-hal/watchdog/WatchDogTimer.c msgid "timeout duration exceeded the maximum supported value" @@ -4230,7 +4233,7 @@ msgstr "twai_start devolvió esp-idf error #%d" #: shared-bindings/busio/UART.c shared-bindings/canio/CAN.c msgid "tx and rx cannot both be None" -msgstr "Ambos tx y rx no pueden ser None" +msgstr "ambos tx y rx no pueden ser None" #: py/objtype.c msgid "type '%q' is not an acceptable base type" @@ -4315,7 +4318,7 @@ msgstr "instrucción Xtensa '%s' con %d argumentos no soportada" #: shared-module/bitmapfilter/__init__.c msgid "unsupported bitmap depth" -msgstr "" +msgstr "profundidad de mapa de bits no compatible" #: shared-module/gifio/GifWriter.c msgid "unsupported colorspace for GifWriter" From 1543642dc2721f1804504ffe2a9024ef990917c2 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 9 Oct 2024 14:22:16 -0700 Subject: [PATCH 099/252] Fix mac address formatting and disable aesio for ESP --- ports/espressif/common-hal/wifi/__init__.c | 3 ++- ports/espressif/mpconfigport.mk | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ports/espressif/common-hal/wifi/__init__.c b/ports/espressif/common-hal/wifi/__init__.c index 710688b9d31c..1a4c014bfbc5 100644 --- a/ports/espressif/common-hal/wifi/__init__.c +++ b/ports/espressif/common-hal/wifi/__init__.c @@ -212,7 +212,8 @@ void common_hal_wifi_init(bool user_initiated) { char cpy_default_hostname[board_len + (MAC_ADDRESS_LENGTH * 2) + 6]; uint8_t mac[MAC_ADDRESS_LENGTH]; esp_wifi_get_mac(ESP_IF_WIFI_STA, mac); - snprintf(cpy_default_hostname, sizeof(cpy_default_hostname), "cpy-%s-%x", CIRCUITPY_BOARD_ID + board_trim, (unsigned int)mac); + snprintf(cpy_default_hostname, sizeof(cpy_default_hostname), "cpy-%s-%02x%02x%02x%02x%02x%02x", CIRCUITPY_BOARD_ID + board_trim, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + const char *default_lwip_local_hostname = cpy_default_hostname; ESP_ERROR_CHECK(esp_netif_set_hostname(self->netif, default_lwip_local_hostname)); // set station mode to avoid the default SoftAP diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index e80c9654040b..ffca0a057436 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -58,6 +58,9 @@ CIRCUITPY_WATCHDOG ?= 1 CIRCUITPY_WIFI ?= 1 CIRCUITPY_SOCKETPOOL_IPV6 ?= 1 +# Turn off aesio. It is a custom API that no one uses. +CIRCUITPY_AESIO = 0 + # Enable _eve module CIRCUITPY__EVE ?= 1 From 45a451012e5a6afe954eaacf0cb63803aa59a7d2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 9 Oct 2024 20:54:18 -0400 Subject: [PATCH 100/252] add __del__() to busio.I2C, which now has a finaliser --- shared-bindings/busio/I2C.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 243054e8e18d..1bd5821c8d79 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -379,6 +379,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_then_readfrom_obj, 1, busio_i2c_wri static const mp_rom_map_elem_t busio_i2c_locals_dict_table[] = { #if CIRCUITPY_BUSIO_I2C { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&busio_i2c_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&busio_i2c_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&busio_i2c___exit___obj) }, { MP_ROM_QSTR(MP_QSTR_probe), MP_ROM_PTR(&busio_i2c_probe_obj) }, From fb0ff7e5bdb4725bdb3363cc6d8a5f148e504bad Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 10 Oct 2024 10:22:15 -0700 Subject: [PATCH 101/252] Only disable aesio on C3 --- ports/espressif/mpconfigport.mk | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk index ffca0a057436..7f4b7600e364 100644 --- a/ports/espressif/mpconfigport.mk +++ b/ports/espressif/mpconfigport.mk @@ -58,9 +58,6 @@ CIRCUITPY_WATCHDOG ?= 1 CIRCUITPY_WIFI ?= 1 CIRCUITPY_SOCKETPOOL_IPV6 ?= 1 -# Turn off aesio. It is a custom API that no one uses. -CIRCUITPY_AESIO = 0 - # Enable _eve module CIRCUITPY__EVE ?= 1 @@ -140,6 +137,7 @@ CIRCUITPY_USB_DEVICE = 0 CIRCUITPY_ESP_USB_SERIAL_JTAG ?= 1 # No room in flash. +CIRCUITPY_AESIO = 0 CIRCUITPY_KEYPAD_DEMUX = 0 else ifeq ($(IDF_TARGET),esp32c6) From f5a49b41baac9eeb341513999cda37e366679490 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 10 Oct 2024 18:48:22 -0400 Subject: [PATCH 102/252] pin sphinx temporarily while debugging doc build --- requirements-doc.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-doc.txt b/requirements-doc.txt index 15df3b13780d..c0ff03ac7707 100644 --- a/requirements-doc.txt +++ b/requirements-doc.txt @@ -10,7 +10,7 @@ setuptools>=45 setuptools_scm # For sphinx -sphinx!=5.2.0.post0 +sphinx!=5.2.0.post0,<8.1.0 sphinx-autoapi sphinx-rtd-theme sphinxcontrib-svg2pdfconverter From 44645312795a7808236d71f03d5c3804a3d294d0 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Sat, 12 Oct 2024 10:30:42 -0500 Subject: [PATCH 103/252] Rename defn to add audiodelays --- ports/raspberrypi/mpconfigport.mk | 2 +- py/circuitpy_defns.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index d619e78bd97a..4f900821cf1f 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -66,7 +66,7 @@ CIRCUITPY_PICODVI ?= 1 CIRCUITPY_TOUCHIO = 0 # Audio effects -CIRCUITPY_AUDIOEFFECTS ?= 1 +CIRCUITPY_AUDIODELAYS ?= 1 endif INTERNAL_LIBM = 1 diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 19f7cfabf044..c2c9ffa6736e 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -131,7 +131,7 @@ endif ifeq ($(CIRCUITPY_AUDIOCORE),1) SRC_PATTERNS += audiocore/% endif -ifeq ($(CIRCUITPY_AUDIOEFFECTS),1) +ifeq ($(CIRCUITPY_AUDIODELAYS),1) SRC_PATTERNS += audiodelays/% endif ifeq ($(CIRCUITPY_AUDIOMIXER),1) From 433430f231609a2dd23781bc5c0228fe2471f639 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 12 Oct 2024 11:15:40 -0500 Subject: [PATCH 104/252] espressif: ipv6: Disable RDNSS Recursive DNS Server (RDNSS) is an extension of IPv6 Neighbor Discovery. It is one of several ways (in addition to DHCPv6) to inform a network node of a usable DNS server. In LWIP, it appears any RDNSS DNS server will overwrite a DNS server from DHCPv4 or manual configuration, whether or not CircuitPython has an IPv6 address configured. In the (default) case where DHCPv6 is disabled in CircuitPython, but the (apparently rare) case where a RDNSS advertisement is broadast, this means that DNS doesn't work, and it appears that assigning to the dns or ipv4_dns properties of the Radio object doesn't work (when in reality it's frequently being reset to the value from RDNSS) On my network, the same DNS server is advertised by DHCPv6, so with this change I still get a working v6 configuration with a v6 DNS server when I enable DHCPv6, but when configuring as v4 only (the default), the correct IPv4 DNS server setting happens and I can also manually change it by assigning .dns or .ipv4_dns. --- ports/espressif/esp-idf-config/sdkconfig.defaults | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/esp-idf-config/sdkconfig.defaults b/ports/espressif/esp-idf-config/sdkconfig.defaults index 2d8777838680..0fc26c165c76 100644 --- a/ports/espressif/esp-idf-config/sdkconfig.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig.defaults @@ -67,7 +67,7 @@ CONFIG_LWIP_SO_RCVBUF=y # IPv6 # CONFIG_LWIP_IPV6_AUTOCONFIG=y -CONFIG_LWIP_IPV6_RDNSS_MAX_DNS_SERVERS=2 +CONFIG_LWIP_IPV6_RDNSS_MAX_DNS_SERVERS=0 CONFIG_LWIP_IPV6_DHCP6=y # # TCP From fce71cb119f9e86bfe8762099c854815ad051575 Mon Sep 17 00:00:00 2001 From: arturo182 Date: Sun, 13 Oct 2024 00:20:16 +0200 Subject: [PATCH 105/252] Add missing ESP32-P4 GPIO defs --- ports/espressif/peripherals/esp32p4/pins.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ports/espressif/peripherals/esp32p4/pins.h b/ports/espressif/peripherals/esp32p4/pins.h index 5c106b316c07..59cf4258a40b 100644 --- a/ports/espressif/peripherals/esp32p4/pins.h +++ b/ports/espressif/peripherals/esp32p4/pins.h @@ -54,6 +54,14 @@ extern const mcu_pin_obj_t pin_GPIO19; extern const mcu_pin_obj_t pin_GPIO20; #define GPIO21_EXISTS 1 extern const mcu_pin_obj_t pin_GPIO21; +#define GPIO22_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO22; +#define GPIO23_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO23; +#define GPIO24_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO24; +#define GPIO25_EXISTS 1 +extern const mcu_pin_obj_t pin_GPIO25; #define GPIO26_EXISTS 1 extern const mcu_pin_obj_t pin_GPIO26; #define GPIO27_EXISTS 1 From 7a4676dc148822d2af00a37c916a49ad95668cd9 Mon Sep 17 00:00:00 2001 From: arturo182 Date: Sun, 13 Oct 2024 00:22:41 +0200 Subject: [PATCH 106/252] Add the Solder Party ESP32-P4 Stamp XL board --- .../solderparty_esp32p4_stamp_xl/board.c | 9 ++++ .../mpconfigboard.h | 20 ++++++++ .../mpconfigboard.mk | 14 ++++++ .../solderparty_esp32p4_stamp_xl/pins.c | 49 +++++++++++++++++++ .../solderparty_esp32p4_stamp_xl/sdkconfig | 0 5 files changed, 92 insertions(+) create mode 100644 ports/espressif/boards/solderparty_esp32p4_stamp_xl/board.c create mode 100644 ports/espressif/boards/solderparty_esp32p4_stamp_xl/mpconfigboard.h create mode 100644 ports/espressif/boards/solderparty_esp32p4_stamp_xl/mpconfigboard.mk create mode 100644 ports/espressif/boards/solderparty_esp32p4_stamp_xl/pins.c create mode 100644 ports/espressif/boards/solderparty_esp32p4_stamp_xl/sdkconfig diff --git a/ports/espressif/boards/solderparty_esp32p4_stamp_xl/board.c b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/board.c new file mode 100644 index 000000000000..a3a9eec04714 --- /dev/null +++ b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/board.c @@ -0,0 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/solderparty_esp32p4_stamp_xl/mpconfigboard.h b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/mpconfigboard.h new file mode 100644 index 000000000000..d6a8b734f622 --- /dev/null +++ b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/mpconfigboard.h @@ -0,0 +1,20 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2019 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "ESP32-P4 Stamp XL" +#define MICROPY_HW_MCU_NAME "ESP32P4" + +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO38) +#define DEFAULT_UART_BUS_TX (&pin_GPIO37) + +#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX +#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX diff --git a/ports/espressif/boards/solderparty_esp32p4_stamp_xl/mpconfigboard.mk b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/mpconfigboard.mk new file mode 100644 index 000000000000..7354998c96db --- /dev/null +++ b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/mpconfigboard.mk @@ -0,0 +1,14 @@ +# USB_VID = 0x303A +# USB_PID = 0x7003 +# USB_PRODUCT = "ESP32-P4 Stamp XL" +# USB_MANUFACTURER = "Solder Party" + +IDF_TARGET = esp32p4 + +CIRCUITPY_ESP_FLASH_SIZE = 16MB +CIRCUITPY_ESP_FLASH_MODE = opi +CIRCUITPY_ESP_FLASH_FREQ = 80m + +CIRCUITPY_ESP_PSRAM_SIZE = 32MB +CIRCUITPY_ESP_PSRAM_MODE = opi +CIRCUITPY_ESP_PSRAM_FREQ = 80m diff --git a/ports/espressif/boards/solderparty_esp32p4_stamp_xl/pins.c b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/pins.c new file mode 100644 index 000000000000..03f2d0dd2a3b --- /dev/null +++ b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/pins.c @@ -0,0 +1,49 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO24), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_IO25), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_IO27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_IO28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_IO29), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_IO30), MP_ROM_PTR(&pin_GPIO30) }, + { MP_ROM_QSTR(MP_QSTR_IO31), MP_ROM_PTR(&pin_GPIO31) }, + { MP_ROM_QSTR(MP_QSTR_IO32), MP_ROM_PTR(&pin_GPIO32) }, + { MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_IO47), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_IO48), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_IO49), MP_ROM_PTR(&pin_GPIO49) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/solderparty_esp32p4_stamp_xl/sdkconfig b/ports/espressif/boards/solderparty_esp32p4_stamp_xl/sdkconfig new file mode 100644 index 000000000000..e69de29bb2d1 From a0681c5006a29b3e7ca6c70096ed5da035e9b9aa Mon Sep 17 00:00:00 2001 From: hexthat Date: Sat, 12 Oct 2024 17:42:13 +0000 Subject: [PATCH 107/252] Translated using Weblate (Chinese (Hanyu Pinyin)) Currently translated at 100.0% (1000 of 1000 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/zh_Latn/ --- locale/zh_Latn_pinyin.po | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 46bec68f7549..fb72e473c68d 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-09-06 04:09+0000\n" +"PO-Revision-Date: 2024-10-13 18:16+0000\n" "Last-Translator: hexthat \n" "Language-Team: Chinese Hanyu Pinyin\n" "Language: zh_Latn_pinyin\n" @@ -431,7 +431,7 @@ msgstr "'label' xūyào 1 gè cānshù" #: py/emitnative.c msgid "'not' not implemented" -msgstr "" +msgstr "'not' wèi shíxiàn" #: py/compile.c msgid "'return' outside function" @@ -684,7 +684,7 @@ msgstr "Huǎnchōng qū chángdù%d tài dà. Tā bìxū xiǎoyú%d" #: shared-module/sdcardio/SDCard.c #, c-format msgid "Buffer must be a multiple of %d bytes" -msgstr "" +msgstr "huǎnchōngqū bìxū shì %d zìjié de bèishù" #: shared-bindings/_bleio/PacketBuffer.c #, c-format @@ -1578,7 +1578,7 @@ msgstr "bù zhīchí JPEG biāozhǔn" #: ports/espressif/common-hal/sdioio/SDCard.c #, c-format msgid "Number of data_pins must be %d or %d, not %d" -msgstr "" +msgstr "data_pins shù bìxū shì %d huò %d, érbùshì %d" #: shared-bindings/util.c msgid "" @@ -1915,7 +1915,7 @@ msgstr "SDIO GetCardInfo Cuòwù %d" #: ports/stm/common-hal/sdioio/SDCard.c #, c-format msgid "SDIO Init Error %x" -msgstr "" +msgstr "SDIO rècuòwù %x" #: ports/espressif/common-hal/busio/SPI.c msgid "SPI configuration failed" @@ -2463,7 +2463,7 @@ msgstr "wèi wéi pīn hé shù zǔ shí xiàn argsort" #: extmod/ulab/code/numpy/random/random.c msgid "argument must be None, an integer or a tuple of integers" -msgstr "" +msgstr "cānshù bìxū shì None, zhěngshù huò zhěngshù yuánzǔ" #: py/compile.c msgid "argument name reused" @@ -2701,7 +2701,7 @@ msgstr "bùnéng zài '%q' hé '%q' zhī jiān jìnxíng èr yuán yùnsuàn" #: py/emitnative.c msgid "can't do unary op of '%q'" -msgstr "" +msgstr "wúfǎ zhíxíng '%q' de yīyuán yùnsuàn" #: py/emitnative.c msgid "can't implicitly convert '%q' to 'bool'" @@ -3852,7 +3852,7 @@ msgstr "chū zhèn liè tài xiǎo" #: extmod/ulab/code/numpy/random/random.c msgid "out has wrong type" -msgstr "" +msgstr "out de lèixíng cuòwù" #: extmod/ulab/code/numpy/vector.c msgid "out keyword is not supported for complex dtype" @@ -3880,11 +3880,11 @@ msgstr "mù biāo fàn wéi wài" #: extmod/ulab/code/numpy/random/random.c msgid "output array has wrong type" -msgstr "" +msgstr "output array de lèixíng cuòwù" #: extmod/ulab/code/numpy/random/random.c msgid "output array must be contiguous" -msgstr "" +msgstr "output array bìxū shì liánxù de" #: py/objint_mpz.c msgid "overflow converting long int to machine word" @@ -4014,7 +4014,7 @@ msgstr "shè zhì bù shòu zhī chí" #: extmod/ulab/code/numpy/random/random.c msgid "shape must be None, and integer or a tuple of integers" -msgstr "" +msgstr "shape bìxū shì None, bìng qiěshì integer huò zhěngshù yuánzǔ" #: extmod/ulab/code/ndarray.c msgid "shape must be integer or tuple of integers" @@ -4038,7 +4038,7 @@ msgstr "dàxiǎo jǐn wèi ndarrays dìngyì" #: extmod/ulab/code/numpy/random/random.c msgid "size must match out.shape when used together" -msgstr "" +msgstr "yìqǐ shǐ yòngshí, size bìxū yǔ out.shape pǐpèi" #: py/nativeglue.c msgid "slice unsupported" From d2367ea58b27dbbd20749e6dbd665e316f2e3641 Mon Sep 17 00:00:00 2001 From: Sean Watson <105624573+aseanwatson@users.noreply.github.com> Date: Sun, 13 Oct 2024 11:17:52 -0700 Subject: [PATCH 108/252] Make edits suggested in issue 9714 --- shared-bindings/keypad/ShiftRegisterKeys.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shared-bindings/keypad/ShiftRegisterKeys.c b/shared-bindings/keypad/ShiftRegisterKeys.c index a0bcde96e94c..e0873a104769 100644 --- a/shared-bindings/keypad/ShiftRegisterKeys.c +++ b/shared-bindings/keypad/ShiftRegisterKeys.c @@ -53,13 +53,14 @@ //| //| Key number 0 is the first (or more properly, the zero-th) bit read. In the //| 74HC165, this bit is labeled ``Q7``. Key number 1 will be the value of ``Q6``, etc. -//| With multiple data pins, key numbers of the next pin are sequentially to the current pin. +//| Key numbers are sequenced such that there are ``key_count[0]`` values read from ``data[0]``, followed by ``key_count[1]`` values read from ``data[1]``, etc. //| //| An `EventQueue` is created when this object is created and is available in the `events` attribute. //| //| :param microcontroller.Pin clock: The shift register clock pin. //| The shift register should clock on a low-to-high transition. -//| :param Union[microcontroller.Pin, Sequence[microcontroller.Pin]] data: the incoming shift register data pin(s) +//| :param Union[microcontroller.Pin, Sequence[microcontroller.Pin]] data: the incoming shift register data pin(s). +//| When a ``microcontroller.Pin`` argument is given, it is logically equivalent to a one-element sequence. //| :param microcontroller.Pin latch: //| Pin used to latch parallel data going into the shift register. //| :param bool value_to_latch: Pin state to latch data being read. @@ -68,6 +69,7 @@ //| The default is ``True``, which is how the 74HC165 operates. The CD4021 latch is the opposite. //| Once the data is latched, it will be shifted out by toggling the clock pin. //| :param Union[int, Sequence[int]] key_count: number of data lines to clock in (per data pin) +//| When an ``int`` argument is given, it is logically equivalent to a one-element sequence. //| :param bool value_when_pressed: ``True`` if the pin reads high when the key is pressed. //| ``False`` if the pin reads low (is grounded) when the key is pressed. //| :param float interval: Scan keys no more often than ``interval`` to allow for debouncing. From e3228d00a94c9e15e20d5caa5cd77b6c6cd65d63 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 14 Oct 2024 10:00:08 -0500 Subject: [PATCH 109/252] Added frequency shift on echo option from @dcooperdalrymple --- shared-bindings/audiodelays/Echo.c | 39 ++++++- shared-bindings/audiodelays/Echo.h | 5 +- shared-module/audiodelays/Echo.c | 163 ++++++++++++++++++++++------- shared-module/audiodelays/Echo.h | 7 +- 4 files changed, 172 insertions(+), 42 deletions(-) diff --git a/shared-bindings/audiodelays/Echo.c b/shared-bindings/audiodelays/Echo.c index d5371ba78851..c0f1556ed75c 100644 --- a/shared-bindings/audiodelays/Echo.c +++ b/shared-bindings/audiodelays/Echo.c @@ -53,6 +53,7 @@ //| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo. //| :param int bits_per_sample: The bits per sample of the effect //| :param bool samples_signed: Effect is signed (True) or unsigned (False) +//| :param bool freq_shift: Do echos change frequency as the echo delay changes //| //| Playing adding an echo to a synth:: //| @@ -64,7 +65,7 @@ //| //| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22) //| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100) -//| echo = audiodelays.Echo(max_delay_ms=1000, delay_ms=850, decay=0.65, buffer_size=1024, channel_count=1, sample_rate=44100, mix=0.7) +//| echo = audiodelays.Echo(max_delay_ms=1000, delay_ms=850, decay=0.65, buffer_size=1024, channel_count=1, sample_rate=44100, mix=0.7, freq_shift=False) //| echo.play(synth) //| audio.play(echo) //| @@ -76,7 +77,7 @@ //| time.sleep(5)""" //| ... static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_max_delay_ms, ARG_delay_ms, ARG_decay, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; + enum { ARG_max_delay_ms, ARG_delay_ms, ARG_decay, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, ARG_freq_shift, }; static const mp_arg_t allowed_args[] = { { MP_QSTR_max_delay_ms, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 500 } }, { MP_QSTR_delay_ms, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, @@ -87,6 +88,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar { MP_QSTR_bits_per_sample, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, { MP_QSTR_samples_signed, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, { MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1 } }, + { MP_QSTR_freq_shift, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -102,7 +104,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar } audiodelays_echo_obj_t *self = mp_obj_malloc(audiodelays_echo_obj_t, &audiodelays_echo_type); - common_hal_audiodelays_echo_construct(self, max_delay_ms, args[ARG_delay_ms].u_obj, args[ARG_decay].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + common_hal_audiodelays_echo_construct(self, max_delay_ms, args[ARG_delay_ms].u_obj, args[ARG_decay].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate, args[ARG_freq_shift].u_bool); return MP_OBJ_FROM_PTR(self); } @@ -222,6 +224,36 @@ MP_PROPERTY_GETSET(audiodelays_echo_mix_obj, (mp_obj_t)&audiodelays_echo_get_mix_obj, (mp_obj_t)&audiodelays_echo_set_mix_obj); + + +//| freq_shift: bool +//| """Does the echo change frequencies as the delay changes.""" +static mp_obj_t audiodelays_echo_obj_get_freq_shift(mp_obj_t self_in) { + return mp_obj_new_bool(common_hal_audiodelays_echo_get_freq_shift(self_in)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audiodelays_echo_get_freq_shift_obj, audiodelays_echo_obj_get_freq_shift); + +static mp_obj_t audiodelays_echo_obj_set_freq_shift(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_freq_shift }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_freq_shift, MP_ARG_BOOL | MP_ARG_REQUIRED, {} }, + }; + audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + common_hal_audiodelays_echo_set_freq_shift(self, args[ARG_freq_shift].u_bool); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_set_freq_shift_obj, 1, audiodelays_echo_obj_set_freq_shift); + +MP_PROPERTY_GETSET(audiodelays_echo_freq_shift_obj, + (mp_obj_t)&audiodelays_echo_get_freq_shift_obj, + (mp_obj_t)&audiodelays_echo_set_freq_shift_obj); + + + //| playing: bool //| """True when the effect is playing a sample. (read-only)""" static mp_obj_t audiodelays_echo_obj_get_playing(mp_obj_t self_in) { @@ -284,6 +316,7 @@ static const mp_rom_map_elem_t audiodelays_echo_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_delay_ms), MP_ROM_PTR(&audiodelays_echo_delay_ms_obj) }, { MP_ROM_QSTR(MP_QSTR_decay), MP_ROM_PTR(&audiodelays_echo_decay_obj) }, { MP_ROM_QSTR(MP_QSTR_mix), MP_ROM_PTR(&audiodelays_echo_mix_obj) }, + { MP_ROM_QSTR(MP_QSTR_freq_shift), MP_ROM_PTR(&audiodelays_echo_freq_shift_obj) }, }; static MP_DEFINE_CONST_DICT(audiodelays_echo_locals_dict, audiodelays_echo_locals_dict_table); diff --git a/shared-bindings/audiodelays/Echo.h b/shared-bindings/audiodelays/Echo.h index a1035a7ea7a0..b276a328b3a2 100644 --- a/shared-bindings/audiodelays/Echo.h +++ b/shared-bindings/audiodelays/Echo.h @@ -13,7 +13,7 @@ extern const mp_obj_type_t audiodelays_echo_type; void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t max_delay_ms, mp_obj_t delay_ms, mp_obj_t decay, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, - uint8_t channel_count, uint32_t sample_rate); + uint8_t channel_count, uint32_t sample_rate, bool freq_shift); void common_hal_audiodelays_echo_deinit(audiodelays_echo_obj_t *self); bool common_hal_audiodelays_echo_deinited(audiodelays_echo_obj_t *self); @@ -25,6 +25,9 @@ uint8_t common_hal_audiodelays_echo_get_bits_per_sample(audiodelays_echo_obj_t * mp_obj_t common_hal_audiodelays_echo_get_delay_ms(audiodelays_echo_obj_t *self); void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_obj_t delay_ms); +bool common_hal_audiodelays_echo_get_freq_shift(audiodelays_echo_obj_t *self); +void common_hal_audiodelays_echo_set_freq_shift(audiodelays_echo_obj_t *self, bool freq_shift); + mp_obj_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self); void common_hal_audiodelays_echo_set_decay(audiodelays_echo_obj_t *self, mp_obj_t decay); diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index a5330098352a..3f45162cb5e9 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -1,6 +1,6 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus, Cooper Dalrymple // // SPDX-License-Identifier: MIT #include "shared-bindings/audiodelays/Echo.h" @@ -11,7 +11,10 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_t max_delay_ms, mp_obj_t delay_ms, mp_obj_t decay, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, - bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { + bool samples_signed, uint8_t channel_count, uint32_t sample_rate, bool freq_shift) { + + // Set whether the echo shifts frequencies as the delay changes like a doppler effect + self->freq_shift = freq_shift; // Basic settings every effect and audio sample has // These are the effects values, not the source sample(s) @@ -82,15 +85,17 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ } memset(self->echo_buffer, 0, self->max_echo_buffer_len); - // calculate current echo buffer size we use for the given delay + // calculate everything needed for the current delay mp_float_t f_delay_ms = synthio_block_slot_get(&self->delay_ms); - self->current_delay_ms = f_delay_ms; - self->echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * sizeof(uint16_t)); + recalculate_delay(self, f_delay_ms); // read is where we read previous echo from delay_ms ago to play back now // write is where the store the latest playing sample to echo back later self->echo_buffer_read_pos = self->buffer_len / sizeof(uint16_t); self->echo_buffer_write_pos = 0; + + // where we read the previous echo from delay_ms ago to play back now (for freq shift) + self->echo_buffer_left_pos = self->echo_buffer_right_pos = 0; } bool common_hal_audiodelays_echo_deinited(audiodelays_echo_obj_t *self) { @@ -109,7 +114,6 @@ void common_hal_audiodelays_echo_deinit(audiodelays_echo_obj_t *self) { self->buffer[1] = NULL; } - mp_obj_t common_hal_audiodelays_echo_get_delay_ms(audiodelays_echo_obj_t *self) { return self->delay_ms.obj; } @@ -123,23 +127,32 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_o } void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { - // Calculate the current echo buffer length in bytes + if (self->freq_shift) { + // Calculate the rate of iteration over the echo buffer with 8 sub-bits + self->echo_buffer_rate = MAX(self->max_delay_ms / f_delay_ms * 256.0f, 1.0); + self->echo_buffer_len = self->max_echo_buffer_len; + } else { + // Calculate the current echo buffer length in bytes + uint32_t new_echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * sizeof(uint16_t)); + + // Check if our new echo is too long for our maximum buffer + if (new_echo_buffer_len > self->max_echo_buffer_len) { + return; + } else if (new_echo_buffer_len < 0.0) { // or too short! + return; + } - uint32_t new_echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * sizeof(uint16_t)); + // If the echo buffer is larger then our audio buffer weird things happen + if (new_echo_buffer_len < self->buffer_len) { + return; + } - // Check if our new echo is too long for our maximum buffer - if (new_echo_buffer_len > self->max_echo_buffer_len) { - return; - } else if (new_echo_buffer_len < 0.0) { // or too short! - return; - } + self->echo_buffer_len = new_echo_buffer_len; - // If the echo buffer is larger then our audio buffer weird things happen - if (new_echo_buffer_len < self->buffer_len) { - return; + // Clear the now unused part of the buffer or some weird artifacts appear + memset(self->echo_buffer + self->echo_buffer_len, 0, self->max_echo_buffer_len - self->echo_buffer_len); } - self->echo_buffer_len = new_echo_buffer_len; self->current_delay_ms = f_delay_ms; } @@ -159,6 +172,16 @@ void common_hal_audiodelays_echo_set_mix(audiodelays_echo_obj_t *self, mp_obj_t synthio_block_assign_slot(arg, &self->mix, MP_QSTR_mix); } +bool common_hal_audiodelays_echo_get_freq_shift(audiodelays_echo_obj_t *self) { + return self->freq_shift; +} + +void common_hal_audiodelays_echo_set_freq_shift(audiodelays_echo_obj_t *self, bool freq_shift) { + self->freq_shift = freq_shift; + uint32_t delay_ms = (uint32_t)synthio_block_slot_get(&self->delay_ms); + recalculate_delay(self, delay_ms); +} + uint32_t common_hal_audiodelays_echo_get_sample_rate(audiodelays_echo_obj_t *self) { return self->sample_rate; } @@ -257,6 +280,10 @@ int16_t mix_down_sample(int32_t sample) { audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { + if (!single_channel_output) { + channel = 0; + } + // get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required mp_float_t mix = MIN(1.0, MAX(synthio_block_slot_get(&self->mix), 0.0)); mp_float_t decay = MIN(1.0, MAX(synthio_block_slot_get(&self->decay), 0.0)); @@ -278,6 +305,15 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * int16_t *echo_buffer = (int16_t *)self->echo_buffer; uint32_t echo_buf_len = self->echo_buffer_len / sizeof(uint16_t); + // Set our echo buffer position accounting for stereo + uint32_t echo_buffer_pos = 0; + if (self->freq_shift) { + echo_buffer_pos = self->echo_buffer_left_pos; + if (channel == 1) { + echo_buffer_pos = self->echo_buffer_right_pos; + } + } + // Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample while (length != 0) { // Check if there is no more sample to play, we will either load more data, reset the sample if loop is on or clear the sample @@ -314,27 +350,46 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } else { // Since we have no sample we can just iterate over the our entire remaining buffer and finish for (uint32_t i = 0; i < length; i++) { - int16_t echo = echo_buffer[self->echo_buffer_read_pos++] * decay; - echo_buffer[self->echo_buffer_write_pos++] = echo; + int16_t echo, word = 0; + uint32_t next_buffer_pos = 0; + + if (self->freq_shift) { + echo = echo_buffer[echo_buffer_pos >> 8]; + next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate; + + word = echo * decay; + for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { + echo_buffer[j % echo_buf_len] = word; + } + } else { + echo = echo_buffer[self->echo_buffer_read_pos++]; + word = echo * decay; + echo_buffer[self->echo_buffer_write_pos++] = word; + } + + word = echo * mix; if (MP_LIKELY(self->bits_per_sample == 16)) { - word_buffer[i] = echo * mix; + word_buffer[i] = word; if (!self->samples_signed) { word_buffer[i] ^= 0x8000; } } else { - echo = echo * mix; - hword_buffer[i] = echo; + hword_buffer[i] = (int8_t)word; if (!self->samples_signed) { hword_buffer[i] ^= 0x80; } } - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + if (self->freq_shift) { + echo_buffer_pos = next_buffer_pos % (echo_buf_len << 8); + } else { + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } } } } @@ -370,12 +425,26 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } - int32_t echo = echo_buffer[self->echo_buffer_read_pos++] * decay; - int32_t word = echo + sample_word; + int32_t echo, word = 0; + uint32_t next_buffer_pos = 0; + if (self->freq_shift) { + echo = echo_buffer[echo_buffer_pos >> 8]; + next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate; + word = echo * decay + sample_word; + } else { + echo = echo_buffer[self->echo_buffer_read_pos++]; + word = echo * decay + sample_word; + } if (MP_LIKELY(self->bits_per_sample == 16)) { word = mix_down_sample(word); - echo_buffer[self->echo_buffer_write_pos++] = (int16_t)word; + if (self->freq_shift) { + for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { + echo_buffer[j % echo_buf_len] = (int16_t)word; + } + } else { + echo_buffer[self->echo_buffer_write_pos++] = (int16_t)word; + } } else { // Do not have mix_down for 8 bit so just hard cap samples into 1 byte if (word > 127) { @@ -383,9 +452,17 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } else if (word < -128) { word = -128; } - echo_buffer[self->echo_buffer_write_pos++] = (int8_t)word; + if (self->freq_shift) { + for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { + echo_buffer[j % echo_buf_len] = (int8_t)word; + } + } else { + echo_buffer[self->echo_buffer_write_pos++] = (int8_t)word; + } } + word = echo + sample_word; + if (MP_LIKELY(self->bits_per_sample == 16)) { word_buffer[i] = (sample_word * (1.0 - mix)) + (word * mix); if (!self->samples_signed) { @@ -400,11 +477,15 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } - if (self->echo_buffer_read_pos >= echo_buf_len) { - self->echo_buffer_read_pos = 0; - } - if (self->echo_buffer_write_pos >= echo_buf_len) { - self->echo_buffer_write_pos = 0; + if (self->freq_shift) { + echo_buffer_pos = next_buffer_pos % (echo_buf_len << 8); + } else { + if (self->echo_buffer_read_pos >= echo_buf_len) { + self->echo_buffer_read_pos = 0; + } + if (self->echo_buffer_write_pos >= echo_buf_len) { + self->echo_buffer_write_pos = 0; + } } } } @@ -418,6 +499,14 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } } + if (self->freq_shift) { + if (channel == 0) { + self->echo_buffer_left_pos = echo_buffer_pos; + } else if (channel == 1) { + self->echo_buffer_right_pos = echo_buffer_pos; + } + } + // Finally pass our buffer and length to the calling audio function *buffer = (uint8_t *)self->buffer[self->last_buf_idx]; *buffer_length = self->buffer_len; diff --git a/shared-module/audiodelays/Echo.h b/shared-module/audiodelays/Echo.h index 42f039f34359..8742f83898a7 100644 --- a/shared-module/audiodelays/Echo.h +++ b/shared-module/audiodelays/Echo.h @@ -1,6 +1,6 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus +// SPDX-FileCopyrightText: Copyright (c) 2024 Mark Komus, Cooper Dalrymple // // SPDX-License-Identifier: MIT #pragma once @@ -34,6 +34,7 @@ typedef struct { bool loop; bool more_data; + bool freq_shift; // does the echo shift frequencies if delay changes int8_t *echo_buffer; uint32_t echo_buffer_len; // bytes @@ -42,6 +43,10 @@ typedef struct { uint32_t echo_buffer_read_pos; // words uint32_t echo_buffer_write_pos; // words + uint32_t echo_buffer_rate; // words << 8 + uint32_t echo_buffer_left_pos; // words << 8 + uint32_t echo_buffer_right_pos; // words << 8 + mp_obj_t sample; } audiodelays_echo_obj_t; From 064c2d8fff9696da9891954b7b071bf43f751378 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Mon, 14 Oct 2024 10:06:06 -0500 Subject: [PATCH 110/252] Fixed renaming the defines for audioeffects incorrectly --- ports/raspberrypi/mpconfigport.mk | 2 +- py/circuitpy_mpconfig.mk | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index 4f900821cf1f..d619e78bd97a 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -66,7 +66,7 @@ CIRCUITPY_PICODVI ?= 1 CIRCUITPY_TOUCHIO = 0 # Audio effects -CIRCUITPY_AUDIODELAYS ?= 1 +CIRCUITPY_AUDIOEFFECTS ?= 1 endif INTERNAL_LIBM = 1 diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 6a3b29baf32c..a8e44a12c941 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -141,7 +141,8 @@ CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG) CIRCUITPY_AUDIOMP3 ?= $(call enable-if-all,$(CIRCUITPY_FULL_BUILD) $(CIRCUITPY_AUDIOCORE)) CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3) -CIRCUITPY_AUDIODELAYS ?= 0 +CIRCUITPY_AUDIOEFFECTS ?= 0 +CIRCUITPY_AUDIODELAYS ?= $(CIRCUITPY_AUDIOEFFECTS) CFLAGS += -DCIRCUITPY_AUDIODELAYS=$(CIRCUITPY_AUDIODELAYS) CIRCUITPY_AURORA_EPAPER ?= 0 From 697fba2da978cd0435e86a5cb1263433700952a6 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 14 Oct 2024 20:41:34 -0400 Subject: [PATCH 111/252] ShiftRegisterKeys key_count value was wrong --- shared-bindings/keypad/ShiftRegisterKeys.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shared-bindings/keypad/ShiftRegisterKeys.c b/shared-bindings/keypad/ShiftRegisterKeys.c index a0bcde96e94c..740ad1352293 100644 --- a/shared-bindings/keypad/ShiftRegisterKeys.c +++ b/shared-bindings/keypad/ShiftRegisterKeys.c @@ -136,7 +136,8 @@ static mp_obj_t keypad_shiftregisterkeys_make_new(const mp_obj_type_t *type, siz size_t key_count_array[num_key_counts]; if (mp_obj_is_int(args[ARG_key_count].u_obj)) { - const size_t key_count = (size_t)mp_arg_validate_int_min(args[ARG_key_count].u_int, 1, MP_QSTR_key_count); + const size_t key_count = + (size_t)mp_arg_validate_int_min(mp_obj_get_int(args[ARG_key_count].u_obj), 1, MP_QSTR_key_count); key_count_array[0] = key_count; } else { for (size_t kc = 0; kc < num_key_counts; kc++) { From 419d4ab9ef40d4839860a90eae7f574629943001 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 15 Oct 2024 08:45:11 -0400 Subject: [PATCH 112/252] update GitHub Actions runners to use macos-13 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f9026830bb05..be09cff40634 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,7 +102,7 @@ jobs: cp-version: ${{ needs.scheduler.outputs.cp-version }} mpy-cross-mac: - runs-on: macos-12 + runs-on: macos-13 needs: scheduler if: needs.scheduler.outputs.ports != '{}' env: From ee339582e82b5f102845ce04fc323655440817a8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 15 Oct 2024 08:46:07 -0400 Subject: [PATCH 113/252] update GitHub Actions runners to use ubuntu-24.04 --- .github/workflows/build-board-custom.yml | 2 +- .github/workflows/build-boards.yml | 2 +- .github/workflows/build-mpy-cross.yml | 2 +- .github/workflows/build.yml | 4 ++-- .github/workflows/create-website-pr.yml | 2 +- .github/workflows/pre-commit.yml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-board-custom.yml b/.github/workflows/build-board-custom.yml index e479540be63a..b91ccbd2d28f 100644 --- a/.github/workflows/build-board-custom.yml +++ b/.github/workflows/build-board-custom.yml @@ -36,7 +36,7 @@ run-name: ${{ inputs.board }}-${{ inputs.language }}-${{ inputs.version }}${{ in jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Set up repository run: | diff --git a/.github/workflows/build-boards.yml b/.github/workflows/build-boards.yml index 07f362820799..be076e0789f8 100644 --- a/.github/workflows/build-boards.yml +++ b/.github/workflows/build-boards.yml @@ -17,7 +17,7 @@ on: jobs: board: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: CP_VERSION: ${{ inputs.cp-version }} strategy: diff --git a/.github/workflows/build-mpy-cross.yml b/.github/workflows/build-mpy-cross.yml index 26226d84e6af..9d94fb638ef5 100644 --- a/.github/workflows/build-mpy-cross.yml +++ b/.github/workflows/build-mpy-cross.yml @@ -14,7 +14,7 @@ on: jobs: build: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index be09cff40634..0f8b1b763817 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ concurrency: jobs: scheduler: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 outputs: docs: ${{ steps.set-matrix.outputs.docs }} ports: ${{ steps.set-matrix.outputs.ports }} @@ -158,7 +158,7 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} docs: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 needs: scheduler if: needs.scheduler.outputs.docs == 'True' env: diff --git a/.github/workflows/create-website-pr.yml b/.github/workflows/create-website-pr.yml index 050d1d394141..8f4cce7691c1 100644 --- a/.github/workflows/create-website-pr.yml +++ b/.github/workflows/create-website-pr.yml @@ -10,7 +10,7 @@ on: jobs: website: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Dump GitHub context run: echo "$GITHUB_CONTEXT" diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index ceeba5900d6a..b3517d748f5e 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -14,7 +14,7 @@ concurrency: jobs: pre-commit: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - name: Set up repository uses: actions/checkout@v4 From a791aaaeffec2cc144de5bd9d2e150c72ff6655e Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Tue, 15 Oct 2024 19:47:48 +0200 Subject: [PATCH 114/252] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ --- locale/ID.po | 32 ++++++++++++++++---------------- locale/cs.po | 18 +++--------------- locale/de_DE.po | 34 ++++++++++++++++++---------------- locale/el.po | 18 +++--------------- locale/en_GB.po | 32 ++++++++++++++++---------------- locale/es.po | 35 ++++++++++++++++++----------------- locale/fil.po | 32 ++++++++++++++++---------------- locale/fr.po | 33 +++++++++++++++++---------------- locale/hi.po | 18 +++--------------- locale/it_IT.po | 18 +++--------------- locale/ja.po | 27 ++++++++++++--------------- locale/ko.po | 18 +++--------------- locale/nl.po | 32 ++++++++++++++++---------------- locale/pl.po | 32 ++++++++++++++++---------------- locale/pt_BR.po | 35 ++++++++++++++++++----------------- locale/ru.po | 33 +++++++++++++++++---------------- locale/sv.po | 32 ++++++++++++++++---------------- locale/tr.po | 18 +++--------------- locale/zh_Latn_pinyin.po | 32 ++++++++++++++++---------------- 19 files changed, 230 insertions(+), 299 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 1eeba013506f..bea4d4b5e672 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -1985,21 +1985,9 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "Sampel bits_per_sampel tidak cocok dengan mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "Jumlah saluran sampel tidak cocok dengan mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "Tingkat sampel dari sampel tidak cocok dengan mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "signedness dari sampel tidak cocok dengan mixer" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2533,7 +2521,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" @@ -4388,6 +4376,18 @@ msgstr "zi harus berjenis float" msgid "zi must be of shape (n_section, 2)" msgstr "Zi harus berbentuk (n_section, 2)" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "Sampel bits_per_sampel tidak cocok dengan mixer" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "Jumlah saluran sampel tidak cocok dengan mixer" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "Tingkat sampel dari sampel tidak cocok dengan mixer" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "signedness dari sampel tidak cocok dengan mixer" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Panjang buffer harus kelipatan 512" diff --git a/locale/cs.po b/locale/cs.po index 0eaacb144612..19d738fa476d 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -1990,20 +1990,8 @@ msgstr "Výše uvedená výjimka byla přímá příčina následující výjimk msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Počet prvků rgb_pin musí být 6, 12, 18, 24, nebo 30" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" #: supervisor/shared/safe_mode.c @@ -2542,7 +2530,7 @@ msgstr "velikosti bitmapy musí odpovídat" msgid "bits must be 32 or less" msgstr "počet bitů nesmí přesáhnout 32" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 9f44b23c905f..c6f8ba97edee 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -2013,22 +2013,9 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Die Länge von rgb_pins muss 6, 12, 18, 24 oder 30 betragen" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" -"Das bits_per_sample des Samples stimmt nicht mit dem des Mixers überein" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "Die Kanalanzahl des Samples stimmt nicht mit der des Mischers überein" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "Die Abtastrate der Probe stimmt nicht mit der des Mischers überein" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "Der Vorzeichentyp des Samples stimmt nicht mit dem des Mixers überein" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2575,7 +2562,7 @@ msgstr "Bitmap-Größen müssen übereinstimmen" msgid "bits must be 32 or less" msgstr "bits müssen 32 oder kleiner sein" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "Es müssen 8 oder 16 bits_per_sample sein" @@ -4458,6 +4445,21 @@ msgstr "zi muss eine Gleitkommazahl sein" msgid "zi must be of shape (n_section, 2)" msgstr "zi muss die Form (n_section, 2) haben" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "" +#~ "Das bits_per_sample des Samples stimmt nicht mit dem des Mixers überein" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "" +#~ "Die Kanalanzahl des Samples stimmt nicht mit der des Mischers überein" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "Die Abtastrate der Probe stimmt nicht mit der des Mischers überein" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "" +#~ "Der Vorzeichentyp des Samples stimmt nicht mit dem des Mixers überein" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Die Pufferlänge muss ein vielfaches von 512 sein" diff --git a/locale/el.po b/locale/el.po index e3c643d73429..7201207d2a71 100644 --- a/locale/el.po +++ b/locale/el.po @@ -1993,20 +1993,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" #: supervisor/shared/safe_mode.c @@ -2539,7 +2527,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index ee7f399232d7..ea4b6bac8e74 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -1991,21 +1991,9 @@ msgstr "The above exception was the direct cause of the following exception:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "The length of rgb_pins must be 6, 12, 18, 24, or 30" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "The sample's bits_per_sample does not match the mixer's" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "The sample's channel count does not match the mixer's" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "The sample's sample rate does not match the mixer's" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "The sample's signedness does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2546,7 +2534,7 @@ msgstr "bitmap sizes must match" msgid "bits must be 32 or less" msgstr "bits must be 32 or less" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample must be 8 or 16" @@ -4406,6 +4394,18 @@ msgstr "zi must be of float type" msgid "zi must be of shape (n_section, 2)" msgstr "zi must be of shape (n_section, 2)" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "The sample's bits_per_sample does not match the mixer's" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "The sample's channel count does not match the mixer's" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "The sample's sample rate does not match the mixer's" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "The sample's signedness does not match the mixer's" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Buffer length must be a multiple of 512" diff --git a/locale/es.po b/locale/es.po index 309e00c224c5..146407aec1ba 100644 --- a/locale/es.po +++ b/locale/es.po @@ -1341,7 +1341,8 @@ msgstr "El Layer debe ser un grupo o una subclase de TileGrid" #: shared-bindings/audiocore/RawSample.c msgid "Length of %q must be an even multiple of channel_count * type_size" -msgstr "La longitud de %q debe ser un múltiplo par de channel_count * type_size" +msgstr "" +"La longitud de %q debe ser un múltiplo par de channel_count * type_size" #: ports/espressif/common-hal/espidf/__init__.c msgid "MAC address was invalid" @@ -2019,21 +2020,9 @@ msgstr "La excepción fue la causa directa de la excepción siguiente:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "La longitud de rgb_pins debe ser 6, 12, 18, 24, o 30" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "Los bits_per_sample del sample no igualan a los del mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "La cuenta de canales del sample no iguala a las del mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "El sample rate del sample no iguala al del mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "El signo del sample no iguala al del mixer" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2578,7 +2567,7 @@ msgstr "los tamaños de los bitmap deben coincidir" msgid "bits must be 32 or less" msgstr "los bits deben ser 32 o menos" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample debe ser 8 ó 16" @@ -4447,6 +4436,18 @@ msgstr "zi debe ser de tipo flotante" msgid "zi must be of shape (n_section, 2)" msgstr "zi debe ser una forma (n_section,2)" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "Los bits_per_sample del sample no igualan a los del mixer" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "La cuenta de canales del sample no iguala a las del mixer" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "El sample rate del sample no iguala al del mixer" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "El signo del sample no iguala al del mixer" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "El tamaño del buffer debe ser múltiplo de 512" diff --git a/locale/fil.po b/locale/fil.po index 6aae57719103..40d0f0e89308 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -1982,21 +1982,9 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "Ang bits_per_sample ng sample ay hindi tugma sa mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "Ang channel count ng sample ay hindi tugma sa mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "Ang sample rate ng sample ay hindi tugma sa mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "Ang signedness ng sample hindi tugma sa mixer" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2530,7 +2518,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample ay dapat 8 o 16" @@ -4398,6 +4386,18 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "Ang bits_per_sample ng sample ay hindi tugma sa mixer" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "Ang channel count ng sample ay hindi tugma sa mixer" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "Ang sample rate ng sample ay hindi tugma sa mixer" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "Ang signedness ng sample hindi tugma sa mixer" + #~ msgid "struct: index out of range" #~ msgstr "struct: index hindi maabot" diff --git a/locale/fr.po b/locale/fr.po index 5fb845d78963..513a0a5cd29a 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -2035,22 +2035,9 @@ msgstr "L'exception précédente est la cause directe de l'exception suivante:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "La taille de rgb_pins doit être 6, 12, 18, 24 ou 30" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" -"Le 'bits_per_sample' de l'échantillon ne correspond pas à celui du mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "Le canal de l'échantillon ne correspond pas à celui du mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "L'échantillonage de l'échantillon ne correspond pas à celui du mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "Le signe de l'échantillon ne correspond pas à celui du mixer" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2597,7 +2584,7 @@ msgstr "les tailles des images doivent correspondre" msgid "bits must be 32 or less" msgstr "les bits doivent être 32 ou moins" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "'bits_per_sample' doivent être 8 ou 16" @@ -4475,6 +4462,20 @@ msgstr "zi doit être de type float" msgid "zi must be of shape (n_section, 2)" msgstr "zi doit être de forme (n_section, 2)" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "" +#~ "Le 'bits_per_sample' de l'échantillon ne correspond pas à celui du mixer" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "Le canal de l'échantillon ne correspond pas à celui du mixer" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "" +#~ "L'échantillonage de l'échantillon ne correspond pas à celui du mixer" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "Le signe de l'échantillon ne correspond pas à celui du mixer" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "La longueur de la mémoire tampon doit être un multiple de 512" diff --git a/locale/hi.po b/locale/hi.po index bfdd57279d81..b0afb5b6226a 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -1967,20 +1967,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" #: supervisor/shared/safe_mode.c @@ -2513,7 +2501,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index be0e57c188a8..86323c737087 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -1980,20 +1980,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" #: supervisor/shared/safe_mode.c @@ -2528,7 +2516,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c #, fuzzy msgid "bits_per_sample must be 8 or 16" msgstr "i bit devono essere 7, 8 o 9" diff --git a/locale/ja.po b/locale/ja.po index d8cf41e228d5..326f8ccdd6af 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -1989,22 +1989,10 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "サンプルのbits_per_sampleがミキサーのそれと一致しません" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "サンプルレートがサンプルとミキサーで一致しません" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "符号の有無がサンプルとミキサーで一致しません" - #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." msgstr "" @@ -2536,7 +2524,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sampleは8または16でなければなりません" @@ -4396,6 +4384,15 @@ msgstr "ziはfloat値でなければなりません" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "サンプルのbits_per_sampleがミキサーのそれと一致しません" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "サンプルレートがサンプルとミキサーで一致しません" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "符号の有無がサンプルとミキサーで一致しません" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "バッファ長は512の倍数でなければなりません" diff --git a/locale/ko.po b/locale/ko.po index b7e43a9267fb..1480d003e71e 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -2044,20 +2044,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" #: supervisor/shared/safe_mode.c @@ -2591,7 +2579,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample은 8 또는 16이어야합니다." diff --git a/locale/nl.po b/locale/nl.po index 2d53144a4ff1..6ed5dbd204a6 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -1981,21 +1981,9 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "De lengte van rgb_pins moet 6, 12, 18, 24 of 30 zijn" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "De sample's bits_per_sample komen niet overeen met die van de mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "De sample's kanaal aantal komt niet overeen met die van de mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "De sample's sample rate komt niet overeen met die van de mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "De sample's signature komt niet overeen met die van de mixer" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2531,7 +2519,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample moet 8 of 16 zijn" @@ -4392,6 +4380,18 @@ msgstr "zi moet van type float zijn" msgid "zi must be of shape (n_section, 2)" msgstr "zi moet vorm (n_section, 2) hebben" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "De sample's bits_per_sample komen niet overeen met die van de mixer" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "De sample's kanaal aantal komt niet overeen met die van de mixer" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "De sample's sample rate komt niet overeen met die van de mixer" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "De sample's signature komt niet overeen met die van de mixer" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Buffer lengte moet een veelvoud van 512 zijn" diff --git a/locale/pl.po b/locale/pl.po index f14283541510..a886b5ce0806 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -1995,21 +1995,9 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "Wartość bits_per_sample nie pasuje do miksera" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "Liczba kanałów nie pasuje do miksera" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "Sample rate nie pasuje do miksera" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "Znak nie pasuje do miksera" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2543,7 +2531,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample musi być 8 lub 16" @@ -4400,6 +4388,18 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "Wartość bits_per_sample nie pasuje do miksera" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "Liczba kanałów nie pasuje do miksera" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "Sample rate nie pasuje do miksera" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "Znak nie pasuje do miksera" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Długość bufora musi być wielokrotnością 512" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index a99a50c89a48..37a2fed3ecaf 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -2019,21 +2019,9 @@ msgstr "A exceção acima foi a causa direta da seguinte exceção:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "O comprimento dos rgb_pins devem ser 6, 12, 18, 24, ou 30" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "A amostragem bits_per_sample não coincide com a do mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "A contagem da amostragem dos canais não coincide com o a do mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "A taxa de amostragem da amostra não coincide com a do mixer" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "A amostragem \"signedness\" não coincide com a do mixer" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2582,7 +2570,7 @@ msgstr "os tamanhos do bitmap devem coincidir" msgid "bits must be 32 or less" msgstr "bits deve ser 32 ou menos" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample deve ser 8 ou 16" @@ -4046,7 +4034,8 @@ msgstr "conjunto não suportado" #: extmod/ulab/code/numpy/random/random.c msgid "shape must be None, and integer or a tuple of integers" -msgstr "shape deve ser None, um número inteiro ou uma tupla de números inteiros" +msgstr "" +"shape deve ser None, um número inteiro ou uma tupla de números inteiros" #: extmod/ulab/code/ndarray.c msgid "shape must be integer or tuple of integers" @@ -4459,6 +4448,18 @@ msgstr "zi deve ser de um tipo float" msgid "zi must be of shape (n_section, 2)" msgstr "zi deve estar na forma (n_section, 2)" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "A amostragem bits_per_sample não coincide com a do mixer" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "A contagem da amostragem dos canais não coincide com o a do mixer" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "A taxa de amostragem da amostra não coincide com a do mixer" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "A amostragem \"signedness\" não coincide com a do mixer" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "O comprimento do Buffer deve ser um múltiplo de 512" diff --git a/locale/ru.po b/locale/ru.po index c2077dfa8588..d825a5fc2b75 100644 --- a/locale/ru.po +++ b/locale/ru.po @@ -2023,21 +2023,9 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Длина rgb_pins должна быть 6, 12, 18, 24 или 30" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "Bits_per_sample сэмпла не соответствует битам микшера" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "Количество каналов образца не совпадает с количеством каналов микшера" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "Частота дискретизации семпла не соответствует частоте микшера" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "Подпись семпла не совпадает с подписью микшера" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2585,7 +2573,7 @@ msgstr "Размеры растровых изображений должны с msgid "bits must be 32 or less" msgstr "биты должны быть 32 или менее" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample должно быть 8 или 16" @@ -4464,6 +4452,19 @@ msgstr "zi должно быть типа float" msgid "zi must be of shape (n_section, 2)" msgstr "zi должен иметь форму (n_section, 2)" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "Bits_per_sample сэмпла не соответствует битам микшера" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "" +#~ "Количество каналов образца не совпадает с количеством каналов микшера" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "Частота дискретизации семпла не соответствует частоте микшера" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "Подпись семпла не совпадает с подписью микшера" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Размер буфера должен быть кратен 512" diff --git a/locale/sv.po b/locale/sv.po index be6185a2009c..76b92be66381 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -2002,21 +2002,9 @@ msgstr "Ovanstående undantag var den direkta orsaken till följande undantag:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Längden på rgb_pins vara 6, 12, 18, 24 eller 30" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "Samplingens bits_per_sample matchar inte mixerns" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "Samplingens kanalantal matchar inte mixerns" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "Samplingens frekvens matchar inte mixerns" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "Samplingens signerad/osignerad stämmer inte med mixern" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2557,7 +2545,7 @@ msgstr "bitmappsstorlekar måste matcha" msgid "bits must be 32 or less" msgstr "bits måste vara 32 eller färre" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample måste vara 8 eller 16" @@ -4419,6 +4407,18 @@ msgstr "zi måste vara av typ float" msgid "zi must be of shape (n_section, 2)" msgstr "zi måste vara i formen (n_section, 2)" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "Samplingens bits_per_sample matchar inte mixerns" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "Samplingens kanalantal matchar inte mixerns" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "Samplingens frekvens matchar inte mixerns" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "Samplingens signerad/osignerad stämmer inte med mixern" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Buffertlängd måste vara en multipel av 512" diff --git a/locale/tr.po b/locale/tr.po index 247678ee6c81..b47a3cb27ab5 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -1989,20 +1989,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" msgstr "" #: supervisor/shared/safe_mode.c @@ -2535,7 +2523,7 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index fb72e473c68d..dd066165f242 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -2008,21 +2008,9 @@ msgstr "shàng shù yì cháng shì yǐ xià yì cháng de zhí jiē yuán yīn: msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Rgb_pins de chángdù bìxū wèi 6,12,18,24 huò 30" -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's bits_per_sample does not match the mixer's" -msgstr "Yàngběn de bits_per_sample yǔ hǔn yīn qì bù pǐpèi" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's channel count does not match the mixer's" -msgstr "Yàngběn de píndào jìshù yǔ hǔn yīn qì bù xiāngfú" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's sample rate does not match the mixer's" -msgstr "Yàngběn de yàngběn sùdù yǔ hǔn yīn qì de xiāngchà bù pǐpèi" - -#: shared-module/audiomixer/MixerVoice.c -msgid "The sample's signedness does not match the mixer's" -msgstr "Yàngběn de qiānmíng yǔ hǔn yīn qì de qiānmíng bù pǐpèi" +#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +msgid "The sample's %q does not match" +msgstr "" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." @@ -2563,7 +2551,7 @@ msgstr "wèi tú dà xiǎo bì xū pǐ pèi" msgid "bits must be 32 or less" msgstr "wèi bì xū shì 32 huò gèng shǎo" -#: shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "měi jiàn yàngběn bìxū wèi 8 huò 16" @@ -4431,6 +4419,18 @@ msgstr "zi bìxū wèi fú diǎn xíng" msgid "zi must be of shape (n_section, 2)" msgstr "zi bìxū jùyǒu xíngzhuàng (n_section,2)" +#~ msgid "The sample's bits_per_sample does not match the mixer's" +#~ msgstr "Yàngběn de bits_per_sample yǔ hǔn yīn qì bù pǐpèi" + +#~ msgid "The sample's channel count does not match the mixer's" +#~ msgstr "Yàngběn de píndào jìshù yǔ hǔn yīn qì bù xiāngfú" + +#~ msgid "The sample's sample rate does not match the mixer's" +#~ msgstr "Yàngběn de yàngběn sùdù yǔ hǔn yīn qì de xiāngchà bù pǐpèi" + +#~ msgid "The sample's signedness does not match the mixer's" +#~ msgstr "Yàngběn de qiānmíng yǔ hǔn yīn qì de qiānmíng bù pǐpèi" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Huǎnchōngqū chángdù bìxū wéi 512 de bèishù" From db0df0146ca4d3a508b8c9e2915343fbc59a515b Mon Sep 17 00:00:00 2001 From: Wellington Terumi Uemura Date: Wed, 16 Oct 2024 06:12:38 +0000 Subject: [PATCH 115/252] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (997 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/pt_BR/ --- locale/pt_BR.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 37a2fed3ecaf..1476cf6b3828 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-09-23 03:16+0000\n" +"PO-Revision-Date: 2024-10-16 21:15+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -14,7 +14,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 5.8-dev\n" +"X-Generator: Weblate 5.8-rc\n" #: main.c msgid "" @@ -2021,7 +2021,7 @@ msgstr "O comprimento dos rgb_pins devem ser 6, 12, 18, 24, ou 30" #: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" -msgstr "" +msgstr "Não há correspondência nas amostras %q" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." From 1def94c352e8843c819a1151a16e8dbc492b85c2 Mon Sep 17 00:00:00 2001 From: Andi Chandler Date: Tue, 15 Oct 2024 20:32:42 +0000 Subject: [PATCH 116/252] Translated using Weblate (English (United Kingdom)) Currently translated at 100.0% (997 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/en_GB/ --- locale/en_GB.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/en_GB.po b/locale/en_GB.po index ea4b6bac8e74..7c9576ac6af7 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2024-09-23 03:16+0000\n" +"PO-Revision-Date: 2024-10-16 21:15+0000\n" "Last-Translator: Andi Chandler \n" "Language-Team: none\n" "Language: en_GB\n" @@ -15,7 +15,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 5.8-dev\n" +"X-Generator: Weblate 5.8-rc\n" #: main.c msgid "" @@ -1993,7 +1993,7 @@ msgstr "The length of rgb_pins must be 6, 12, 18, 24, or 30" #: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" -msgstr "" +msgstr "The sample's %q does not match" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." From 6f3476d3d71ede0339bb70a89ccdf638f0ffe02e Mon Sep 17 00:00:00 2001 From: Dogus Cendek Date: Thu, 17 Oct 2024 15:02:35 +0300 Subject: [PATCH 117/252] Add cezerio dev ESP32C6 Add cezerio dev ESP32C6 --- .../boards/cezerio_dev_ESP32C6/board.c | 9 ++ .../cezerio_dev_ESP32C6/mpconfigboard.h | 27 +++++ .../cezerio_dev_ESP32C6/mpconfigboard.mk | 8 ++ .../boards/cezerio_dev_ESP32C6/pins.c | 101 ++++++++++++++++++ .../boards/cezerio_dev_ESP32C6/sdkconfig | 14 +++ 5 files changed, 159 insertions(+) create mode 100644 ports/espressif/boards/cezerio_dev_ESP32C6/board.c create mode 100644 ports/espressif/boards/cezerio_dev_ESP32C6/mpconfigboard.h create mode 100644 ports/espressif/boards/cezerio_dev_ESP32C6/mpconfigboard.mk create mode 100644 ports/espressif/boards/cezerio_dev_ESP32C6/pins.c create mode 100644 ports/espressif/boards/cezerio_dev_ESP32C6/sdkconfig diff --git a/ports/espressif/boards/cezerio_dev_ESP32C6/board.c b/ports/espressif/boards/cezerio_dev_ESP32C6/board.c new file mode 100644 index 000000000000..a3a9eec04714 --- /dev/null +++ b/ports/espressif/boards/cezerio_dev_ESP32C6/board.c @@ -0,0 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/cezerio_dev_ESP32C6/mpconfigboard.h b/ports/espressif/boards/cezerio_dev_ESP32C6/mpconfigboard.h new file mode 100644 index 000000000000..44171d1dc4dd --- /dev/null +++ b/ports/espressif/boards/cezerio_dev_ESP32C6/mpconfigboard.h @@ -0,0 +1,27 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2019 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "cezerio dev ESP32C6" +#define MICROPY_HW_MCU_NAME "ESP32C6" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO3) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO7) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO21) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO22) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO23) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO17) +#define DEFAULT_UART_BUS_TX (&pin_GPIO16) + +// For entering safe mode, use BOOT button +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9) diff --git a/ports/espressif/boards/cezerio_dev_ESP32C6/mpconfigboard.mk b/ports/espressif/boards/cezerio_dev_ESP32C6/mpconfigboard.mk new file mode 100644 index 000000000000..3acd161c3408 --- /dev/null +++ b/ports/espressif/boards/cezerio_dev_ESP32C6/mpconfigboard.mk @@ -0,0 +1,8 @@ +CIRCUITPY_CREATOR_ID = 0x11361206 +CIRCUITPY_CREATION_ID = 0x00C60001 + +IDF_TARGET = esp32c6 + +CIRCUITPY_ESP_FLASH_MODE = qio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 4MB diff --git a/ports/espressif/boards/cezerio_dev_ESP32C6/pins.c b/ports/espressif/boards/cezerio_dev_ESP32C6/pins.c new file mode 100644 index 000000000000..ed881ab1ac0c --- /dev/null +++ b/ports/espressif/boards/cezerio_dev_ESP32C6/pins.c @@ -0,0 +1,101 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) }, + + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_RGB), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) }, + + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_IMUSC), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IMUSD), MP_ROM_PTR(&pin_GPIO8) }, + + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) }, + + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO16) }, + + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO17) }, + + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_MATRIX), MP_ROM_PTR(&pin_GPIO18) }, + + { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO19) }, + + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_GPIO20) }, + + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_IO22), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_MO), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_IO23), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_MI), MP_ROM_PTR(&pin_GPIO23) }, + + { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/cezerio_dev_ESP32C6/sdkconfig b/ports/espressif/boards/cezerio_dev_ESP32C6/sdkconfig new file mode 100644 index 000000000000..e96286621603 --- /dev/null +++ b/ports/espressif/boards/cezerio_dev_ESP32C6/sdkconfig @@ -0,0 +1,14 @@ +# +# Espressif IoT Development Framework Configuration +# +# +# Component config +# +# +# LWIP +# +# end of LWIP + +# end of Component config + +# end of Espressif IoT Development Framework Configuration From 323aefc4ec0ef7099efd878761e5399e8028ce6d Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 17 Oct 2024 15:12:54 +0200 Subject: [PATCH 118/252] fixed doc of wifi.Network.authmode --- shared-bindings/wifi/Network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/wifi/Network.c b/shared-bindings/wifi/Network.c index 3b9c0b6116c1..1b5b3aac1456 100644 --- a/shared-bindings/wifi/Network.c +++ b/shared-bindings/wifi/Network.c @@ -76,8 +76,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_network_get_country_obj, wifi_network_get_country MP_PROPERTY_GETTER(wifi_network_country_obj, (mp_obj_t)&wifi_network_get_country_obj); -//| authmode: str -//| """String id of the authmode""" +//| authmode: Sequence[wifi.AuthMode] +//| """List of authmodes (wifi.AuthMode) used by the network """ //| static mp_obj_t wifi_network_get_authmode(mp_obj_t self) { return common_hal_wifi_network_get_authmode(self); From 6a2e6745891cfe049104f91b61d38cddde3896df Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 17 Oct 2024 12:30:28 -0500 Subject: [PATCH 119/252] Fix crash on assignment of wifi.radio.dns on raspberrypi boards --- ports/raspberrypi/common-hal/wifi/Radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index 3250ed4d7c7f..b34a7670b83c 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -574,7 +574,7 @@ void common_hal_wifi_radio_set_dns(wifi_radio_obj_t *self, mp_obj_t dns_addrs_ob addr.addr = IPADDR_NONE; } else { mp_obj_t dns_addr_obj = mp_obj_subscr(dns_addrs_obj, MP_OBJ_NEW_SMALL_INT(0), MP_OBJ_SENTINEL); - socketpool_resolve_host_raise(dns_addr_obj, &addr); + socketpool_resolve_host_raise(mp_obj_str_get_str(dns_addr_obj), &addr); } dns_setserver(0, &addr); } From 32c3d049c0456fbf3e1a4fefc4ca3babcb9ccf64 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 18 Oct 2024 13:01:24 -0500 Subject: [PATCH 120/252] adafruit_pixelbuf: Allow the buffer to be written in _transmit This permits modifying the brightness of TM1814 strips at runtime. --- shared-module/adafruit_pixelbuf/PixelBuf.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/shared-module/adafruit_pixelbuf/PixelBuf.c b/shared-module/adafruit_pixelbuf/PixelBuf.c index 0eb1afe9adb1..e62730b3cac3 100644 --- a/shared-module/adafruit_pixelbuf/PixelBuf.c +++ b/shared-module/adafruit_pixelbuf/PixelBuf.c @@ -30,13 +30,10 @@ void common_hal_adafruit_pixelbuf_pixelbuf_construct(pixelbuf_pixelbuf_obj_t *se self->auto_write = false; size_t pixel_len = self->pixel_count * self->bytes_per_pixel; - self->transmit_buffer_obj = mp_obj_new_bytes_of_zeros(header_len + pixel_len + trailer_len); - mp_obj_str_t *o = MP_OBJ_TO_PTR(self->transmit_buffer_obj); + self->transmit_buffer_obj = mp_obj_new_bytearray_of_zeros(header_len + pixel_len + trailer_len); + mp_obj_array_t *o = MP_OBJ_TO_PTR(self->transmit_buffer_obj); - // Abuse the bytes object a bit by mutating it's data by dropping the const. If the user's - // Python code holds onto it, they'll find out that it changes. At least this way it isn't - // mutable by the code itself. - uint8_t *transmit_buffer = (uint8_t *)o->data; + uint8_t *transmit_buffer = o->items; memcpy(transmit_buffer, header, header_len); memcpy(transmit_buffer + header_len + pixel_len, trailer, trailer_len); self->post_brightness_buffer = transmit_buffer + header_len; From 95b5d7a6cdfc0f85a7c17929880e46958d4860e3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 18 Oct 2024 16:09:46 -0400 Subject: [PATCH 121/252] Add errno.EROFS and errno.ENOSPC --- py/moderrno.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/py/moderrno.c b/py/moderrno.c index b5116bcadc7d..140ae1cc0a64 100644 --- a/py/moderrno.c +++ b/py/moderrno.c @@ -35,6 +35,7 @@ // This list can be defined per port in mpconfigport.h to tailor it to a // specific port's needs. If it's not defined then we provide a default. #ifndef MICROPY_PY_ERRNO_LIST +// CIRCUITPY-CHANGE: add ENOSPC and EROFS, because they are in mp_common_errno_to_str(). #define MICROPY_PY_ERRNO_LIST \ X(EPERM) \ X(ENOENT) \ @@ -47,6 +48,8 @@ X(ENODEV) \ X(EISDIR) \ X(EINVAL) \ + X(ENOSPC) \ + X(EROFS) \ X(EOPNOTSUPP) \ X(EADDRINUSE) \ X(ECONNABORTED) \ From ac0904e4bb98bdf4415b665d32046396ad606627 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 18 Oct 2024 16:16:16 -0400 Subject: [PATCH 122/252] improve _bleio.Connection.bind() doc, validation, and error messages --- locale/circuitpython.pot | 11 ++++++----- ports/espressif/common-hal/_bleio/__init__.c | 3 +++ ports/nordic/common-hal/_bleio/__init__.c | 3 +++ shared-bindings/_bleio/Connection.c | 8 +++++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 123902650b95..a6acb8a644fb 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -268,7 +268,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "" @@ -550,6 +551,10 @@ msgstr "" msgid "Already have all-matches listener" msgstr "" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3173,10 +3178,6 @@ msgstr "" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/ports/espressif/common-hal/_bleio/__init__.c b/ports/espressif/common-hal/_bleio/__init__.c index 328cf7ec552f..f3637a8fddb9 100644 --- a/ports/espressif/common-hal/_bleio/__init__.c +++ b/ports/espressif/common-hal/_bleio/__init__.c @@ -103,6 +103,9 @@ void check_nimble_error(int rc, const char *file, size_t line) { case BLE_HS_ENOTCONN: mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected")); return; + case BLE_HS_EALREADY: + mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Already in progress")); + return; default: #if CIRCUITPY_VERBOSE_BLE || CIRCUITPY_DEBUG if (file) { diff --git a/ports/nordic/common-hal/_bleio/__init__.c b/ports/nordic/common-hal/_bleio/__init__.c index 8c5a46d036e0..095723194cfb 100644 --- a/ports/nordic/common-hal/_bleio/__init__.c +++ b/ports/nordic/common-hal/_bleio/__init__.c @@ -35,6 +35,9 @@ void check_nrf_error(uint32_t err_code) { case NRF_ERROR_INVALID_PARAM: mp_raise_ValueError(MP_ERROR_TEXT("Invalid BLE parameter")); return; + case NRF_ERROR_INVALID_STATE: + mp_raise_bleio_BluetoothError(MP_ERROR_TEXT("Invalid state")); + return; case BLE_ERROR_INVALID_CONN_HANDLE: mp_raise_ConnectionError(MP_ERROR_TEXT("Not connected")); return; diff --git a/shared-bindings/_bleio/Connection.c b/shared-bindings/_bleio/Connection.c index becd275f761f..ec3f349fcb35 100644 --- a/shared-bindings/_bleio/Connection.c +++ b/shared-bindings/_bleio/Connection.c @@ -66,7 +66,10 @@ static MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_disconnect_obj, bleio_connecti //| def pair(self, *, bond: bool = True) -> None: -//| """Pair to the peer to improve security.""" +//| """Pair to the peer to improve security. +//| +//| **Limitation**: Currently ``bond``must be ``True``: bonding always occurs. +//| """ //| ... static mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_connection_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); @@ -79,6 +82,9 @@ static mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + if (args[ARG_bond].u_bool == false) { + mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q=%q"), MP_QSTR_bond, MP_QSTR_False); + } bleio_connection_ensure_connected(self); common_hal_bleio_connection_pair(self->connection, args[ARG_bond].u_bool); From ebca75d764c99ae4a368f4add660e2403421a186 Mon Sep 17 00:00:00 2001 From: Ettore Atalan Date: Sat, 19 Oct 2024 00:32:17 +0000 Subject: [PATCH 123/252] Translated using Weblate (German) Currently translated at 95.5% (953 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index c6f8ba97edee..b4177d57cfc8 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -6,14 +6,14 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-06-18 19:09+0000\n" -"Last-Translator: Xfox20 <136956349+Xfox20@users.noreply.github.com>\n" +"PO-Revision-Date: 2024-10-20 01:16+0000\n" +"Last-Translator: Ettore Atalan \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 5.6-dev\n" +"X-Generator: Weblate 5.8-rc\n" #: main.c msgid "" @@ -415,7 +415,7 @@ msgstr "'await' außerhalb einer Funktion" #: py/compile.c msgid "'break'/'continue' outside loop" -msgstr "'break'/'continue' ausserhalb einer Schleife" +msgstr "'break'/'continue' außerhalb der Schleife" #: py/compile.c msgid "'data' requires at least 2 arguments" @@ -431,7 +431,7 @@ msgstr "'label' erfordert genau ein Argument" #: py/emitnative.c msgid "'not' not implemented" -msgstr "" +msgstr "'not' nicht implementiert" #: py/compile.c msgid "'return' outside function" From 7990eb2ca7b60590a975c7a18886bef9040e8132 Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Mon, 21 Oct 2024 19:30:40 +0200 Subject: [PATCH 124/252] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ --- locale/ID.po | 11 ++++++----- locale/cs.po | 14 +++++++++----- locale/de_DE.po | 14 +++++++++----- locale/el.po | 11 ++++++----- locale/en_GB.po | 14 +++++++++----- locale/es.po | 14 +++++++++----- locale/fil.po | 11 ++++++----- locale/fr.po | 14 +++++++++----- locale/hi.po | 11 ++++++----- locale/it_IT.po | 11 ++++++----- locale/ja.po | 11 ++++++----- locale/ko.po | 11 ++++++----- locale/nl.po | 11 ++++++----- locale/pl.po | 11 ++++++----- locale/pt_BR.po | 14 +++++++++----- locale/ru.po | 14 +++++++++----- locale/sv.po | 14 +++++++++----- locale/tr.po | 11 ++++++----- locale/zh_Latn_pinyin.po | 14 +++++++++----- 19 files changed, 141 insertions(+), 95 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index bea4d4b5e672..4bc03c8ccd76 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -271,7 +271,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q, dan %q semuanya harus memiliki panjang yang sama" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "" @@ -553,6 +554,10 @@ msgstr "Sudah disebarkan." msgid "Already have all-matches listener" msgstr "" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3195,10 +3200,6 @@ msgstr "" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/locale/cs.po b/locale/cs.po index 19d738fa476d..5957c68696cf 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -279,7 +279,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q, a %q musí mít všechny shodnou délku" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -561,6 +562,10 @@ msgstr "Již propagujeme." msgid "Already have all-matches listener" msgstr "Již existuje posluchač pro všechny zprávy" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3204,10 +3209,6 @@ msgstr "" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "inicializace I2C" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "výchozí hodnoty musí být iterovatelné" @@ -4385,6 +4386,9 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "init I2C" +#~ msgstr "inicializace I2C" + #~ msgid "Buffer length must be a multiple of 512" #~ msgstr "Délka vyrovnávací paměti musí být násobkem 512" diff --git a/locale/de_DE.po b/locale/de_DE.po index b4177d57cfc8..26b6599bfef5 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -283,7 +283,8 @@ msgstr "%q() ohne %q()" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q und %q müssen alle die gleiche Länge haben" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -565,6 +566,10 @@ msgstr "Bereits am Anbieten (advertising)." msgid "Already have all-matches listener" msgstr "All-Matchers-Listener bereits vorhanden" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3250,10 +3255,6 @@ msgstr "Indizes müssen Integer sein" msgid "indices must be integers, slices, or Boolean lists" msgstr "Indizes müssen Integer, Slices oder Boolesche Listen sein" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "initialisiere I2C" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "Ausgangswerte müssen iterierbar sein" @@ -4445,6 +4446,9 @@ msgstr "zi muss eine Gleitkommazahl sein" msgid "zi must be of shape (n_section, 2)" msgstr "zi muss die Form (n_section, 2) haben" +#~ msgid "init I2C" +#~ msgstr "initialisiere I2C" + #~ msgid "The sample's bits_per_sample does not match the mixer's" #~ msgstr "" #~ "Das bits_per_sample des Samples stimmt nicht mit dem des Mixers überein" diff --git a/locale/el.po b/locale/el.po index 7201207d2a71..e9fdb50bbee7 100644 --- a/locale/el.po +++ b/locale/el.po @@ -283,7 +283,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q, και %q πρέπει να είναι όλα του ιδίου μήκους" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -565,6 +566,10 @@ msgstr "Ήδη διαφημίζουμε." msgid "Already have all-matches listener" msgstr "Ύπάρχει ήδη all-matches ακροατής" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3201,10 +3206,6 @@ msgstr "" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index 7c9576ac6af7..cafbd3dce09f 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -281,7 +281,8 @@ msgstr "%q() without %q()" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q, and %q must all be the same length" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -563,6 +564,10 @@ msgstr "Already advertising." msgid "Already have all-matches listener" msgstr "Already have all-matches listener" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3211,10 +3216,6 @@ msgstr "indices must be integers" msgid "indices must be integers, slices, or Boolean lists" msgstr "indices must be integers, slices, or Boolean lists" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "init I2C" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "initial values must be iterable" @@ -4394,6 +4395,9 @@ msgstr "zi must be of float type" msgid "zi must be of shape (n_section, 2)" msgstr "zi must be of shape (n_section, 2)" +#~ msgid "init I2C" +#~ msgstr "init I2C" + #~ msgid "The sample's bits_per_sample does not match the mixer's" #~ msgstr "The sample's bits_per_sample does not match the mixer's" diff --git a/locale/es.po b/locale/es.po index 146407aec1ba..02c5786788a2 100644 --- a/locale/es.po +++ b/locale/es.po @@ -283,7 +283,8 @@ msgstr "%q() sin %q()" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q, y %q deben tener la misma longitud" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -567,6 +568,10 @@ msgstr "Ya se encuentra publicando." msgid "Already have all-matches listener" msgstr "Ya se tiene un escucha de todas las coincidencias" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3249,10 +3254,6 @@ msgstr "indices deben ser enteros" msgid "indices must be integers, slices, or Boolean lists" msgstr "los índices deben ser enteros, particiones o listas de booleanos" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "inicializacion I2C" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "los valores iniciales deben permitir iteración" @@ -4436,6 +4437,9 @@ msgstr "zi debe ser de tipo flotante" msgid "zi must be of shape (n_section, 2)" msgstr "zi debe ser una forma (n_section,2)" +#~ msgid "init I2C" +#~ msgstr "inicializacion I2C" + #~ msgid "The sample's bits_per_sample does not match the mixer's" #~ msgstr "Los bits_per_sample del sample no igualan a los del mixer" diff --git a/locale/fil.po b/locale/fil.po index 40d0f0e89308..93735ffea9f6 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -272,7 +272,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "" @@ -555,6 +556,10 @@ msgstr "" msgid "Already have all-matches listener" msgstr "" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3203,10 +3208,6 @@ msgstr "ang mga indeks ay dapat na integer" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/locale/fr.po b/locale/fr.po index 513a0a5cd29a..0358ad0d6738 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -284,7 +284,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q, et %q doivent tous être de la même longueur" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -569,6 +570,10 @@ msgstr "S'annonce déjà." msgid "Already have all-matches listener" msgstr "Il y a déjà un auditeur all-matches" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3272,10 +3277,6 @@ msgid "indices must be integers, slices, or Boolean lists" msgstr "" "les indices doivent être des entiers, des tranches ou des listes booléennes" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "initialisation I2C" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "les valeurs initiales doivent être itérables" @@ -4462,6 +4463,9 @@ msgstr "zi doit être de type float" msgid "zi must be of shape (n_section, 2)" msgstr "zi doit être de forme (n_section, 2)" +#~ msgid "init I2C" +#~ msgstr "initialisation I2C" + #~ msgid "The sample's bits_per_sample does not match the mixer's" #~ msgstr "" #~ "Le 'bits_per_sample' de l'échantillon ne correspond pas à celui du mixer" diff --git a/locale/hi.po b/locale/hi.po index b0afb5b6226a..d57d4aea6859 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -270,7 +270,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "" @@ -552,6 +553,10 @@ msgstr "" msgid "Already have all-matches listener" msgstr "" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3175,10 +3180,6 @@ msgstr "" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index 86323c737087..c4f721660914 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -272,7 +272,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "" @@ -555,6 +556,10 @@ msgstr "" msgid "Already have all-matches listener" msgstr "Già in possesso di tutti i listener abbinati" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3200,10 +3205,6 @@ msgstr "gli indici devono essere interi" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/locale/ja.po b/locale/ja.po index 326f8ccdd6af..523eda2bb8ed 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -283,7 +283,8 @@ msgstr "%q() に %q() がありません" msgid "%q, %q, and %q must all be the same length" msgstr "%q と %q および %q はすべて同じ長さである必要があります" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -565,6 +566,10 @@ msgstr "すでにアドバータイズ中" msgid "Already have all-matches listener" msgstr "" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3203,10 +3208,6 @@ msgid "indices must be integers, slices, or Boolean lists" msgstr "" "インデクスは、整数、スライス、boolのリストのいずれかでなければなりません" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/locale/ko.po b/locale/ko.po index 1480d003e71e..1151b188bd2e 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -291,7 +291,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q 및 %q의 길이는 모두 같아야 합니다" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -589,6 +590,10 @@ msgstr "이미 광고 중입니다." msgid "Already have all-matches listener" msgstr "이미 모든 일치 리스너가 있습니다" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3253,10 +3258,6 @@ msgstr "" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/locale/nl.po b/locale/nl.po index 6ed5dbd204a6..d9e4dde06071 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -268,7 +268,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "" @@ -550,6 +551,10 @@ msgstr "Advertising is al bezig." msgid "Already have all-matches listener" msgstr "Heeft al een luisteraar voor 'all-matches'" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3197,10 +3202,6 @@ msgstr "indices moeten integers zijn" msgid "indices must be integers, slices, or Boolean lists" msgstr "indices moeten integers, segmenten (slices) of Boolean lijsten zijn" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "oorspronkelijke waarden moeten itereerbaar zijn" diff --git a/locale/pl.po b/locale/pl.po index a886b5ce0806..aaac9890fcd2 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -276,7 +276,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q oraz %q muszą być tej samej długośći" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -558,6 +559,10 @@ msgstr "" msgid "Already have all-matches listener" msgstr "" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3207,10 +3212,6 @@ msgid "indices must be integers, slices, or Boolean lists" msgstr "" "indeksy muszą być liczbami całkowitymi, wycinkami lub listami boolowskimi" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "wartości początkowe muszą być iterowalne" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 1476cf6b3828..e86d0c87ceb2 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -281,7 +281,8 @@ msgstr "%q() sem %q()" msgid "%q, %q, and %q must all be the same length" msgstr "todos os %q, %q, e %q devem ter mesmo comprimento" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -565,6 +566,10 @@ msgstr "Já está anunciando." msgid "Already have all-matches listener" msgstr "Já há um ouvinte com todas as correspondências" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3253,10 +3258,6 @@ msgstr "os índices devem ser inteiros" msgid "indices must be integers, slices, or Boolean lists" msgstr "os índices devem ser números inteiros, fatias ou listas booleanas" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "inicialização do I2C" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "os valores iniciais devem ser iteráveis" @@ -4448,6 +4449,9 @@ msgstr "zi deve ser de um tipo float" msgid "zi must be of shape (n_section, 2)" msgstr "zi deve estar na forma (n_section, 2)" +#~ msgid "init I2C" +#~ msgstr "inicialização do I2C" + #~ msgid "The sample's bits_per_sample does not match the mixer's" #~ msgstr "A amostragem bits_per_sample não coincide com a do mixer" diff --git a/locale/ru.po b/locale/ru.po index d825a5fc2b75..f59a8ec6b51d 100644 --- a/locale/ru.po +++ b/locale/ru.po @@ -283,7 +283,8 @@ msgstr "%q() без %q()" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q, и %q должны быть одной длинны" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -565,6 +566,10 @@ msgstr "Уже реклама." msgid "Already have all-matches listener" msgstr "Уже есть универсальный слушатель" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3258,10 +3263,6 @@ msgstr "индексы должны быть целыми числами" msgid "indices must be integers, slices, or Boolean lists" msgstr "индексы должны быть целыми числами, срезами или логическими списками" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "инициализация I2C" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "Начальные значения должны быть итерируемыми" @@ -4452,6 +4453,9 @@ msgstr "zi должно быть типа float" msgid "zi must be of shape (n_section, 2)" msgstr "zi должен иметь форму (n_section, 2)" +#~ msgid "init I2C" +#~ msgstr "инициализация I2C" + #~ msgid "The sample's bits_per_sample does not match the mixer's" #~ msgstr "Bits_per_sample сэмпла не соответствует битам микшера" diff --git a/locale/sv.po b/locale/sv.po index 76b92be66381..3b16112fa4d1 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -282,7 +282,8 @@ msgstr "%q() utan %q()" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q och %q måste vara lika långa" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -564,6 +565,10 @@ msgstr "Annonserar redan." msgid "Already have all-matches listener" msgstr "Har redan lyssnare för all-matchningar" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3224,10 +3229,6 @@ msgstr "index måste vara heltal" msgid "indices must be integers, slices, or Boolean lists" msgstr "index måste vara heltal, slices, eller Boolean-listor" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "I2C start" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "initialvärden måste vara iterable" @@ -4407,6 +4408,9 @@ msgstr "zi måste vara av typ float" msgid "zi must be of shape (n_section, 2)" msgstr "zi måste vara i formen (n_section, 2)" +#~ msgid "init I2C" +#~ msgstr "I2C start" + #~ msgid "The sample's bits_per_sample does not match the mixer's" #~ msgstr "Samplingens bits_per_sample matchar inte mixerns" diff --git a/locale/tr.po b/locale/tr.po index b47a3cb27ab5..35c45dac64e8 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -281,7 +281,8 @@ msgstr "" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q ve %q aynı uzunlukta olmalıdır" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -563,6 +564,10 @@ msgstr "Halihazırda duyuruluyor." msgid "Already have all-matches listener" msgstr "Tüm eşleşmelerle eşleşen dinleyiciniz var" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3197,10 +3202,6 @@ msgstr "" msgid "indices must be integers, slices, or Boolean lists" msgstr "" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index dd066165f242..ad0928eb52e2 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -283,7 +283,8 @@ msgstr "búdài %q() de %q()" msgid "%q, %q, and %q must all be the same length" msgstr "%q, %q, hé %q bì xū cháng dù xiāng tóng" -#: py/objint.c shared-bindings/storage/__init__.c +#: py/objint.c shared-bindings/_bleio/Connection.c +#: shared-bindings/storage/__init__.c msgid "%q=%q" msgstr "%q=%q" @@ -565,6 +566,10 @@ msgstr "Mùqián zhèngzài guǎngbō." msgid "Already have all-matches listener" msgstr "yǐjīng yǒu all-matches jiāntīng qì" +#: ports/espressif/common-hal/_bleio/__init__.c +msgid "Already in progress" +msgstr "" + #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c @@ -3231,10 +3236,6 @@ msgstr "suǒyǐn bìxū shì zhěngshù" msgid "indices must be integers, slices, or Boolean lists" msgstr "suǒyǐn bìxū shì zhěngshù, qiēpiàn huò bù'ěr zhí lièbiǎo" -#: ports/espressif/common-hal/busio/I2C.c -msgid "init I2C" -msgstr "chūshǐhuà I2C" - #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" msgstr "chūshǐ zhí bìxū shì kě diédài de" @@ -4419,6 +4420,9 @@ msgstr "zi bìxū wèi fú diǎn xíng" msgid "zi must be of shape (n_section, 2)" msgstr "zi bìxū jùyǒu xíngzhuàng (n_section,2)" +#~ msgid "init I2C" +#~ msgstr "chūshǐhuà I2C" + #~ msgid "The sample's bits_per_sample does not match the mixer's" #~ msgstr "Yàngběn de bits_per_sample yǔ hǔn yīn qì bù pǐpèi" From 1e2438927fca66fb5d775972fc4cd65e0ae55659 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 21 Oct 2024 10:57:48 -0700 Subject: [PATCH 125/252] Document picodvi differences RP2350 only support 640x480 output currently. Fixes #9736 --- .../bindings/picodvi/Framebuffer.c | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.c b/ports/raspberrypi/bindings/picodvi/Framebuffer.c index 7a8ca40f9f61..0ada4fba7cd9 100644 --- a/ports/raspberrypi/bindings/picodvi/Framebuffer.c +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.c @@ -41,9 +41,12 @@ //| This allocates a very large framebuffer and is most likely to succeed //| the earlier it is attempted. //| -//| Each dp and dn pair of pins must be neighboring, such as 19 and 20. -//| They must also be ordered the same way. In other words, dp must be -//| less than dn for all pairs or dp must be greater than dn for all pairs. +//| On RP2040, each dp and dn pair of pins must be neighboring, such as +//| 19 and 20. They must also be ordered the same way. In other words, +//| dp must be less than dn for all pairs or dp must be greater than dn +//| for all pairs. +//| +//| On RP2350, all pins must be an HSTX output but can be in any order. //| //| The framebuffer pixel format varies depending on color_depth: //| @@ -53,16 +56,24 @@ //| * 8 - Each byte is a pixels in RGB332 format. //| * 16 - Each two bytes are a pixel in RGB565 format. //| -//| Two output resolutions are currently supported, 640x480 and 800x480. -//| Monochrome framebuffers (color_depth=1 or 2) must be full resolution. -//| Color framebuffers must be half resolution (320x240 or 400x240) and -//| pixels will be duplicated to create the signal. +//| Output resolution support varies between the RP2040 and RP2350. +//| +//| On RP2040, two output resolutions are currently supported, 640x480 +//| and 800x480. Monochrome framebuffers (color_depth=1 or 2) must be +//| full resolution. Color framebuffers must be half resolution (320x240 +//| or 400x240) and pixels will be duplicated to create the signal. +//| +//| On RP2350, output resolution is always 640x480. Monochrome +//| framebuffers (color_depth=1 or 2) must be full resolution. 4-bit +//| color must also be full resolution. 8-bit color can be half or full +//| resolution. 16-bit color must be half resolution due to RAM +//| limitations. //| //| A Framebuffer is often used in conjunction with a //| `framebufferio.FramebufferDisplay`. //| -//| :param int width: the width of the target display signal. Only 320, 400, 640 or 800 is currently supported depending on color_depth. -//| :param int height: the height of the target display signal. Only 240 or 480 is currently supported depending on color_depth. +//| :param int width: the width of the target display signal. Only 320, 400, 640 or 800 is currently supported depending on color_depth and chip set. +//| :param int height: the height of the target display signal. Only 240 or 480 is currently supported depending on color_depth and chip set. //| :param ~microcontroller.Pin clk_dp: the positive clock signal pin //| :param ~microcontroller.Pin clk_dn: the negative clock signal pin //| :param ~microcontroller.Pin red_dp: the positive red signal pin @@ -72,7 +83,7 @@ //| :param ~microcontroller.Pin blue_dp: the positive blue signal pin //| :param ~microcontroller.Pin blue_dn: the negative blue signal pin //| :param int color_depth: the color depth of the framebuffer in bits. 1, 2 for grayscale -//| and 8 or 16 for color +//| and 4 (RP2350 only), 8 or 16 for color //| """ static mp_obj_t picodvi_framebuffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { From 361ffd0fda6b0fb34d5f3b7a2c297b867601d1d3 Mon Sep 17 00:00:00 2001 From: Sokromatrix Date: Tue, 22 Oct 2024 01:04:03 +0000 Subject: [PATCH 126/252] Translated using Weblate (German) Currently translated at 95.8% (956 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index 26b6599bfef5..4b8e8989be7d 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -6,8 +6,8 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-10-20 01:16+0000\n" -"Last-Translator: Ettore Atalan \n" +"PO-Revision-Date: 2024-10-22 01:04+0000\n" +"Last-Translator: Sokromatrix \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -3442,6 +3442,7 @@ msgstr "" #: py/argcheck.c msgid "keyword argument(s) not implemented - use normal args instead" msgstr "" +"Schlüsselwortargument(e) nicht umgesetzt - Nutze stattdessen normale args" #: py/emitinlinethumb.c py/emitinlinextensa.c msgid "label '%q' not defined" @@ -3947,11 +3948,11 @@ msgstr "Port muss >= 0 sein" #: py/compile.c msgid "positional arg after **" -msgstr "" +msgstr "Positionsargument nach **" #: py/compile.c msgid "positional arg after keyword arg" -msgstr "" +msgstr "Positionsargument nach Schlüsselwortargument" #: py/objint_mpz.c msgid "pow() 3rd argument cannot be 0" From 48a689fa43771a9321cc5d3cadcf947919f3d594 Mon Sep 17 00:00:00 2001 From: Ettore Atalan Date: Tue, 22 Oct 2024 01:03:51 +0000 Subject: [PATCH 127/252] Translated using Weblate (German) Currently translated at 95.8% (956 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index 4b8e8989be7d..b419bc94864e 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgstr "" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" "PO-Revision-Date: 2024-10-22 01:04+0000\n" -"Last-Translator: Sokromatrix \n" +"Last-Translator: Ettore Atalan \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -3598,7 +3598,7 @@ msgstr "Dieser Name ist nirgends definiert worden (Schreibweise kontrollieren)" #: py/qstr.c msgid "name too long" -msgstr "" +msgstr "Name zu lang" #: py/persistentcode.c msgid "native code in .mpy unsupported" From 2a0be8f809930a98813fde1dc2574e0f9cbf847e Mon Sep 17 00:00:00 2001 From: Andi Chandler Date: Mon, 21 Oct 2024 21:08:03 +0000 Subject: [PATCH 128/252] Translated using Weblate (English (United Kingdom)) Currently translated at 100.0% (997 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/en_GB/ --- locale/en_GB.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/en_GB.po b/locale/en_GB.po index cafbd3dce09f..e348de3da894 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2024-10-16 21:15+0000\n" +"PO-Revision-Date: 2024-10-22 01:04+0000\n" "Last-Translator: Andi Chandler \n" "Language-Team: none\n" "Language: en_GB\n" @@ -566,7 +566,7 @@ msgstr "Already have all-matches listener" #: ports/espressif/common-hal/_bleio/__init__.c msgid "Already in progress" -msgstr "" +msgstr "Already in progress" #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c From 3085f3bee7be752017b666f23214f84b1f100b4c Mon Sep 17 00:00:00 2001 From: Ettore Atalan Date: Tue, 22 Oct 2024 01:06:16 +0000 Subject: [PATCH 129/252] Translated using Weblate (German) Currently translated at 96.2% (960 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index b419bc94864e..e066e90f281b 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-10-22 01:04+0000\n" +"PO-Revision-Date: 2024-10-22 01:06+0000\n" "Last-Translator: Ettore Atalan \n" "Language: de_DE\n" "MIME-Version: 1.0\n" @@ -689,7 +689,7 @@ msgstr "Die Pufferlänge %d ist zu groß. Sie muss kleiner als %d sein" #: shared-module/sdcardio/SDCard.c #, c-format msgid "Buffer must be a multiple of %d bytes" -msgstr "" +msgstr "Puffer muss ein Vielfaches von %d Bytes sein" #: shared-bindings/_bleio/PacketBuffer.c #, c-format @@ -3215,7 +3215,7 @@ msgstr "import * nicht auf Modulebene" #: py/persistentcode.c msgid "incompatible .mpy arch" -msgstr "" +msgstr "inkompatible .mpy-Architektur" #: py/persistentcode.c msgid "incompatible .mpy file" @@ -3355,7 +3355,7 @@ msgstr "Das Intervall muss im Bereich %s-%s sein" #: py/compile.c msgid "invalid arch" -msgstr "" +msgstr "ungültige Architektur" #: shared-bindings/bitmaptools/__init__.c #, c-format @@ -3442,7 +3442,8 @@ msgstr "" #: py/argcheck.c msgid "keyword argument(s) not implemented - use normal args instead" msgstr "" -"Schlüsselwortargument(e) nicht umgesetzt - Nutze stattdessen normale args" +"Schlüsselwortargument(e) nicht umgesetzt - nutze stattdessen normale " +"Argumente" #: py/emitinlinethumb.c py/emitinlinextensa.c msgid "label '%q' not defined" From d22f9bc1a4b914b99f29b3c6769393b722c5a50d Mon Sep 17 00:00:00 2001 From: Sokromatrix Date: Tue, 22 Oct 2024 01:06:22 +0000 Subject: [PATCH 130/252] Translated using Weblate (German) Currently translated at 96.2% (960 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index e066e90f281b..cffcac8bcd7d 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgstr "" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" "PO-Revision-Date: 2024-10-22 01:06+0000\n" -"Last-Translator: Ettore Atalan \n" +"Last-Translator: Sokromatrix \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -904,7 +904,7 @@ msgstr "Die Zielkapazität ist kleiner als destination_length." #: shared-module/jpegio/JpegDecoder.c msgid "Device error or wrong termination of input stream" -msgstr "" +msgstr "Gerätefehler oder falsche Vernichtung des Eingangsstromes" #: ports/nordic/common-hal/audiobusio/I2SOut.c msgid "Device in use" From 16280c5cfaee03e75db16838e687350957cad27e Mon Sep 17 00:00:00 2001 From: Ettore Atalan Date: Tue, 22 Oct 2024 01:06:45 +0000 Subject: [PATCH 131/252] Translated using Weblate (German) Currently translated at 96.3% (961 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index cffcac8bcd7d..84e9eb668393 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -6,8 +6,8 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-10-22 01:06+0000\n" -"Last-Translator: Sokromatrix \n" +"PO-Revision-Date: 2024-10-22 01:07+0000\n" +"Last-Translator: Ettore Atalan \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -904,7 +904,7 @@ msgstr "Die Zielkapazität ist kleiner als destination_length." #: shared-module/jpegio/JpegDecoder.c msgid "Device error or wrong termination of input stream" -msgstr "Gerätefehler oder falsche Vernichtung des Eingangsstromes" +msgstr "Gerätefehler oder falsche Terminierung des Eingangsstroms" #: ports/nordic/common-hal/audiobusio/I2SOut.c msgid "Device in use" From 553e1945d384c92b074553966ddc12222e9caa69 Mon Sep 17 00:00:00 2001 From: Sokromatrix Date: Tue, 22 Oct 2024 01:07:24 +0000 Subject: [PATCH 132/252] Translated using Weblate (German) Currently translated at 96.3% (961 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index 84e9eb668393..f465614c6ef9 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgstr "" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" "PO-Revision-Date: 2024-10-22 01:07+0000\n" -"Last-Translator: Ettore Atalan \n" +"Last-Translator: Sokromatrix \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -1092,7 +1092,7 @@ msgstr "Gruppe schon benutzt" #: supervisor/shared/safe_mode.c msgid "Hard fault: memory access or instruction error." -msgstr "" +msgstr "Seitenfehler: Fehler beim Arbeitsspeicherzugriff oder bei Anweisung" #: ports/mimxrt10xx/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/UART.c ports/stm/common-hal/busio/I2C.c From 1f744391cc29474719d9900223d90d554bd8b459 Mon Sep 17 00:00:00 2001 From: Ettore Atalan Date: Tue, 22 Oct 2024 01:08:05 +0000 Subject: [PATCH 133/252] Translated using Weblate (German) Currently translated at 96.7% (965 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index f465614c6ef9..e845e658d52d 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -6,8 +6,8 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-10-22 01:07+0000\n" -"Last-Translator: Sokromatrix \n" +"PO-Revision-Date: 2024-10-22 01:09+0000\n" +"Last-Translator: Ettore Atalan \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -1092,7 +1092,7 @@ msgstr "Gruppe schon benutzt" #: supervisor/shared/safe_mode.c msgid "Hard fault: memory access or instruction error." -msgstr "Seitenfehler: Fehler beim Arbeitsspeicherzugriff oder bei Anweisung" +msgstr "Harter Fehler: Speicherzugriff- oder Anweisungsfehler." #: ports/mimxrt10xx/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/UART.c ports/stm/common-hal/busio/I2C.c @@ -1236,7 +1236,7 @@ msgstr "Ungültiger %q" #: ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c #: shared-module/aurora_epaper/aurora_framebuffer.c msgid "Invalid %q and %q" -msgstr "" +msgstr "Ungültiges %q und %q" #: ports/atmel-samd/common-hal/microcontroller/Pin.c #: ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c @@ -1347,7 +1347,7 @@ msgstr "MAC Adresse war ungültig" #: ports/espressif/common-hal/_bleio/Characteristic.c #: ports/espressif/common-hal/_bleio/Descriptor.c msgid "MITM security not supported" -msgstr "" +msgstr "MITM-Sicherheit wird nicht unterstützt" #: shared-bindings/is31fl3741/IS31FL3741.c msgid "Mapping must be a tuple" @@ -1392,7 +1392,7 @@ msgstr "jmp_pin fehlt. %q[%u] springt basierend auf dem Pin" #: shared-module/storage/__init__.c msgid "Mount point directory missing" -msgstr "" +msgstr "Einhängepunktverzeichnis fehlt" #: shared-bindings/busio/UART.c shared-bindings/displayio/Group.c msgid "Must be a %q subclass." From 3a14c01955b35842f8307b1f4be20aceb3924722 Mon Sep 17 00:00:00 2001 From: Sokromatrix Date: Tue, 22 Oct 2024 01:08:59 +0000 Subject: [PATCH 134/252] Translated using Weblate (German) Currently translated at 96.7% (965 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index e845e658d52d..542027241707 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgstr "" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" "PO-Revision-Date: 2024-10-22 01:09+0000\n" -"Last-Translator: Ettore Atalan \n" +"Last-Translator: Sokromatrix \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -1552,7 +1552,7 @@ msgstr "Kein Timer verfügbar" #: shared-module/usb/core/Device.c msgid "No usb host port initialized" -msgstr "" +msgstr "Kein initialisierter USB-Host-Port" #: ports/nordic/common-hal/_bleio/__init__.c msgid "Nordic system firmware out of memory" From 9e4dfe02bc817cac98a10aae9f20a4dfb2521674 Mon Sep 17 00:00:00 2001 From: Sokromatrix Date: Tue, 22 Oct 2024 01:09:10 +0000 Subject: [PATCH 135/252] Translated using Weblate (German) Currently translated at 96.9% (967 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index 542027241707..d36cfa7ee925 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -1773,7 +1773,7 @@ msgstr "Pins muss ein geteiltes PWM-Stück sein" #: shared-module/usb/core/Device.c msgid "Pipe error" -msgstr "" +msgstr "Pipe-Fehler" #: py/builtinhelp.c msgid "Plus any modules on the filesystem\n" @@ -1989,7 +1989,7 @@ msgstr "Gib genau einen von data0 oder data_pins an" #: supervisor/shared/safe_mode.c msgid "Stack overflow. Increase stack size." -msgstr "" +msgstr "Stapelüberlauf. Erhöhe die Stapelgröße." #: shared-bindings/alarm/time/TimeAlarm.c msgid "Supply one of monotonic_time or epoch_time" From aa9cd6d14c97276c3955b4748446ee5f7282f911 Mon Sep 17 00:00:00 2001 From: Ettore Atalan Date: Tue, 22 Oct 2024 01:09:02 +0000 Subject: [PATCH 136/252] Translated using Weblate (German) Currently translated at 96.9% (967 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index d36cfa7ee925..9710f0d53dec 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgstr "" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" "PO-Revision-Date: 2024-10-22 01:09+0000\n" -"Last-Translator: Sokromatrix \n" +"Last-Translator: Ettore Atalan \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -1552,7 +1552,7 @@ msgstr "Kein Timer verfügbar" #: shared-module/usb/core/Device.c msgid "No usb host port initialized" -msgstr "Kein initialisierter USB-Host-Port" +msgstr "Kein USB-Host-Port initialisiert" #: ports/nordic/common-hal/_bleio/__init__.c msgid "Nordic system firmware out of memory" From 1dd4d2255be45ca35be26c95505bf4e24d40c8b1 Mon Sep 17 00:00:00 2001 From: Ettore Atalan Date: Tue, 22 Oct 2024 01:09:50 +0000 Subject: [PATCH 137/252] Translated using Weblate (German) Currently translated at 97.1% (969 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index 9710f0d53dec..e3769a693b15 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-10-22 01:09+0000\n" +"PO-Revision-Date: 2024-10-22 01:10+0000\n" "Last-Translator: Ettore Atalan \n" "Language: de_DE\n" "MIME-Version: 1.0\n" @@ -1989,7 +1989,7 @@ msgstr "Gib genau einen von data0 oder data_pins an" #: supervisor/shared/safe_mode.c msgid "Stack overflow. Increase stack size." -msgstr "Stapelüberlauf. Erhöhe die Stapelgröße." +msgstr "Stapelüberlauf. Stapelgröße erhöhen." #: shared-bindings/alarm/time/TimeAlarm.c msgid "Supply one of monotonic_time or epoch_time" @@ -2071,7 +2071,7 @@ msgstr "Zu viele Kanäle im sample." #: ports/espressif/common-hal/_bleio/Characteristic.c msgid "Too many descriptors" -msgstr "" +msgstr "Zu viele Deskriptoren" #: shared-module/displayio/__init__.c msgid "Too many display busses; forgot displayio.release_displays() ?" From 298a67b1d2827b9bf3687e47ab88ce9ed95ecba3 Mon Sep 17 00:00:00 2001 From: Sokromatrix Date: Tue, 22 Oct 2024 01:09:56 +0000 Subject: [PATCH 138/252] Translated using Weblate (German) Currently translated at 97.1% (969 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index e3769a693b15..0e82ca98d38e 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgstr "" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" "PO-Revision-Date: 2024-10-22 01:10+0000\n" -"Last-Translator: Ettore Atalan \n" +"Last-Translator: Sokromatrix \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -2150,7 +2150,7 @@ msgstr "Der UUID-Wert ist kein str-, int- oder Byte-Puffer" #: ports/raspberrypi/common-hal/memorymap/AddressRange.c msgid "Unable to access unaligned IO register" -msgstr "" +msgstr "Zugriff auf nicht ausgerichtes IO-Register nicht möglich" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audioio/AudioOut.c From 5246053563e553cca8a33bbd9c311ac891c99c49 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Tue, 22 Oct 2024 09:17:58 -0500 Subject: [PATCH 139/252] Initial structure for biquad filter effect. --- py/circuitpy_defns.mk | 5 + py/circuitpy_mpconfig.mk | 2 + shared-bindings/audiofilters/Filter.c | 266 ++++++++++++++++++++++ shared-bindings/audiofilters/Filter.h | 33 +++ shared-bindings/audiofilters/__init__.c | 33 +++ shared-bindings/audiofilters/__init__.h | 7 + shared-module/audiofilters/Filter.c | 281 ++++++++++++++++++++++++ shared-module/audiofilters/Filter.h | 51 +++++ shared-module/audiofilters/__init__.c | 5 + shared-module/audiofilters/__init__.h | 7 + 10 files changed, 690 insertions(+) create mode 100644 shared-bindings/audiofilters/Filter.c create mode 100644 shared-bindings/audiofilters/Filter.h create mode 100644 shared-bindings/audiofilters/__init__.c create mode 100644 shared-bindings/audiofilters/__init__.h create mode 100644 shared-module/audiofilters/Filter.c create mode 100644 shared-module/audiofilters/Filter.h create mode 100644 shared-module/audiofilters/__init__.c create mode 100644 shared-module/audiofilters/__init__.h diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index c2c9ffa6736e..9d6c73064e0b 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -134,6 +134,9 @@ endif ifeq ($(CIRCUITPY_AUDIODELAYS),1) SRC_PATTERNS += audiodelays/% endif +ifeq ($(CIRCUITPY_AUDIOFILTERS),1) +SRC_PATTERNS += audiofilters/% +endif ifeq ($(CIRCUITPY_AUDIOMIXER),1) SRC_PATTERNS += audiomixer/% endif @@ -622,6 +625,8 @@ SRC_SHARED_MODULE_ALL = \ audiocore/__init__.c \ audiodelays/Echo.c \ audiodelays/__init__.c \ + audiofilters/Distortion.c \ + audiofilters/__init__.c \ audioio/__init__.c \ audiomixer/Mixer.c \ audiomixer/MixerVoice.c \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index a8e44a12c941..e42555291192 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -144,6 +144,8 @@ CFLAGS += -DCIRCUITPY_AUDIOMP3=$(CIRCUITPY_AUDIOMP3) CIRCUITPY_AUDIOEFFECTS ?= 0 CIRCUITPY_AUDIODELAYS ?= $(CIRCUITPY_AUDIOEFFECTS) CFLAGS += -DCIRCUITPY_AUDIODELAYS=$(CIRCUITPY_AUDIODELAYS) +CIRCUITPY_AUDIOFILTERS ?= $(CIRCUITPY_AUDIOEFFECTS) +CFLAGS += -DCIRCUITPY_AUDIOFILTERS=$(CIRCUITPY_AUDIOFILTERS) CIRCUITPY_AURORA_EPAPER ?= 0 CFLAGS += -DCIRCUITPY_AURORA_EPAPER=$(CIRCUITPY_AURORA_EPAPER) diff --git a/shared-bindings/audiofilters/Filter.c b/shared-bindings/audiofilters/Filter.c new file mode 100644 index 000000000000..f78c909d21bc --- /dev/null +++ b/shared-bindings/audiofilters/Filter.c @@ -0,0 +1,266 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Cooper Dalrymple +// +// SPDX-License-Identifier: MIT + +#include + +#include "shared-bindings/audiofilters/Filter.h" +#include "shared-module/audiofilters/Filter.h" + +#include "shared/runtime/context_manager_helpers.h" +#include "py/binary.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/util.h" +#include "shared-module/synthio/block.h" + +#define MIX_DEFAULT 1.0f + +//| class Filter: +//| """A Filter effect""" +//| +//| def __init__( +//| self, +//| biquad: synthio.Biquad = None, +//| mix: synthio.BlockInput = 1.0, +//| buffer_size: int = 512, +//| sample_rate: int = 8000, +//| bits_per_sample: int = 16, +//| samples_signed: bool = True, +//| channel_count: int = 1, +//| ) -> None: +//| """Create a Filter effect where the original sample is processed through a biquad filter +//| created by a synthio.Synthesizer object. This can be used to generate a low-pass, +//| high-pass, or band-pass filter. +//| +//| The mix parameter allows you to change how much of the unchanged sample passes through to +//| the output to how much of the effect audio you hear as the output. +//| +//| :param synthio.Biquad biquad: The normalized biquad filter object used to process the signal. +//| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). +//| :param int buffer_size: The total size in bytes of each of the two playback buffers to use +//| :param int sample_rate: The sample rate to be used +//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo. +//| :param int bits_per_sample: The bits per sample of the effect +//| :param bool samples_signed: Effect is signed (True) or unsigned (False) +//| +//| Playing adding a filter to a synth:: +//| +//| import time +//| import board +//| import audiobusio +//| import synthio +//| import audiofilters +//| +//| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22) +//| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100) +//| filter = audiofilters.Filter(biquad=synth.low_pass_filter(frequency=2000, q_factor=1.25), buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0) +//| filter.play(synth) +//| audio.play(filter) +//| +//| note = synthio.Note(261) +//| while True: +//| synth.press(note) +//| time.sleep(0.25) +//| synth.release(note) +//| time.sleep(5)""" +//| ... +static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_biquad, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_biquad, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 512} }, + { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, + { MP_QSTR_bits_per_sample, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, + { MP_QSTR_samples_signed, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, + { MP_QSTR_channel_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1 } }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_int_t channel_count = mp_arg_validate_int_range(args[ARG_channel_count].u_int, 1, 2, MP_QSTR_channel_count); + mp_int_t sample_rate = mp_arg_validate_int_min(args[ARG_sample_rate].u_int, 1, MP_QSTR_sample_rate); + mp_int_t bits_per_sample = args[ARG_bits_per_sample].u_int; + if (bits_per_sample != 8 && bits_per_sample != 16) { + mp_raise_ValueError(MP_ERROR_TEXT("bits_per_sample must be 8 or 16")); + } + + audiofilters_filter_obj_t *self = mp_obj_malloc(audiofilters_filter_obj_t, &audiofilters_filter_type); + common_hal_audiofilters_filter_construct(self, args[ARG_biquad].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + + return MP_OBJ_FROM_PTR(self); +} + +//| def deinit(self) -> None: +//| """Deinitialises the Filter.""" +//| ... +static mp_obj_t audiofilters_filter_deinit(mp_obj_t self_in) { + audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_audiofilters_filter_deinit(self); + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_deinit_obj, audiofilters_filter_deinit); + +static void check_for_deinit(audiofilters_filter_obj_t *self) { + if (common_hal_audiofilters_filter_deinited(self)) { + raise_deinited_error(); + } +} + +//| def __enter__(self) -> Filter: +//| """No-op used by Context Managers.""" +//| ... +// Provided by context manager helper. + +//| def __exit__(self) -> None: +//| """Automatically deinitializes when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info.""" +//| ... +static mp_obj_t audiofilters_filter_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_audiofilters_filter_deinit(args[0]); + return mp_const_none; +} +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiofilters_filter___exit___obj, 4, 4, audiofilters_filter_obj___exit__); + + +//| biquad: synthio.Biquad +//| """The normalized biquad filter object used to process the signal.""" +static mp_obj_t audiofilters_filter_obj_get_biquad(mp_obj_t self_in) { + return common_hal_audiofilters_filter_get_biquad(self_in); +} +MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_biquad_obj, audiofilters_filter_obj_get_biquad); + +static mp_obj_t audiofilters_filter_obj_set_biquad(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_biquad }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_biquad, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + }; + audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + common_hal_audiofilters_filter_set_biquad(self, args[ARG_biquad].u_obj); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_set_biquad_obj, 1, audiofilters_filter_obj_set_biquad); + +MP_PROPERTY_GETSET(audiofilters_filter_biquad_obj, + (mp_obj_t)&audiofilters_filter_get_biquad_obj, + (mp_obj_t)&audiofilters_filter_set_biquad_obj); + + +//| mix: synthio.BlockInput +//| """The rate the filtered signal mix between 0 and 1 where 0 is only sample and 1 is all effect.""" +static mp_obj_t audiofilters_filter_obj_get_mix(mp_obj_t self_in) { + return common_hal_audiofilters_filter_get_mix(self_in); +} +MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_mix_obj, audiofilters_filter_obj_get_mix); + +static mp_obj_t audiofilters_filter_obj_set_mix(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_mix }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + }; + audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + common_hal_audiofilters_filter_set_mix(self, args[ARG_mix].u_obj); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_set_mix_obj, 1, audiofilters_filter_obj_set_mix); + +MP_PROPERTY_GETSET(audiofilters_filter_mix_obj, + (mp_obj_t)&audiofilters_filter_get_mix_obj, + (mp_obj_t)&audiofilters_filter_set_mix_obj); + + +//| playing: bool +//| """True when the effect is playing a sample. (read-only)""" +static mp_obj_t audiofilters_filter_obj_get_playing(mp_obj_t self_in) { + audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_bool(common_hal_audiofilters_filter_get_playing(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_playing_obj, audiofilters_filter_obj_get_playing); + +MP_PROPERTY_GETTER(audiofilters_filter_playing_obj, + (mp_obj_t)&audiofilters_filter_get_playing_obj); + +//| def play(self, sample: circuitpython_typing.AudioSample, *, loop: bool = False) -> None: +//| """Plays the sample once when loop=False and continuously when loop=True. +//| Does not block. Use `playing` to block. +//| +//| The sample must match the encoding settings given in the constructor.""" +//| ... +static mp_obj_t audiofilters_filter_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_sample, ARG_loop }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_sample, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + { MP_QSTR_loop, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + }; + audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + + mp_obj_t sample = args[ARG_sample].u_obj; + common_hal_audiofilters_filter_play(self, sample, args[ARG_loop].u_bool); + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_play_obj, 1, audiofilters_filter_obj_play); + +//| def stop(self) -> None: +//| """Stops playback of the sample.""" +//| ... +//| +static mp_obj_t audiofilters_filter_obj_stop(mp_obj_t self_in) { + audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(self_in); + + common_hal_audiofilters_filter_stop(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_stop_obj, audiofilters_filter_obj_stop); + +static const mp_rom_map_elem_t audiofilters_filter_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiofilters_filter_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiofilters_filter___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_play), MP_ROM_PTR(&audiofilters_filter_play_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&audiofilters_filter_stop_obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiofilters_filter_playing_obj) }, + { MP_ROM_QSTR(MP_QSTR_biquad), MP_ROM_PTR(&audiofilters_filter_biquad_obj) }, + { MP_ROM_QSTR(MP_QSTR_mix), MP_ROM_PTR(&audiofilters_filter_mix_obj) }, +}; +static MP_DEFINE_CONST_DICT(audiofilters_filter_locals_dict, audiofilters_filter_locals_dict_table); + +static const audiosample_p_t audiofilters_filter_proto = { + MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample) + .sample_rate = (audiosample_sample_rate_fun)common_hal_audiofilters_filter_get_sample_rate, + .bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_audiofilters_filter_get_bits_per_sample, + .channel_count = (audiosample_channel_count_fun)common_hal_audiofilters_filter_get_channel_count, + .reset_buffer = (audiosample_reset_buffer_fun)audiofilters_filter_reset_buffer, + .get_buffer = (audiosample_get_buffer_fun)audiofilters_filter_get_buffer, + .get_buffer_structure = (audiosample_get_buffer_structure_fun)audiofilters_filter_get_buffer_structure, +}; + +MP_DEFINE_CONST_OBJ_TYPE( + audiofilters_filter_type, + MP_QSTR_Filter, + MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS, + make_new, audiofilters_filter_make_new, + locals_dict, &audiofilters_filter_locals_dict, + protocol, &audiofilters_filter_proto + ); diff --git a/shared-bindings/audiofilters/Filter.h b/shared-bindings/audiofilters/Filter.h new file mode 100644 index 000000000000..6a58b1ba1a96 --- /dev/null +++ b/shared-bindings/audiofilters/Filter.h @@ -0,0 +1,33 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Cooper Dalrymple +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "shared-module/audiofilters/Filter.h" + +extern const mp_obj_type_t audiofilters_filter_type; + +void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, + mp_obj_t biquad, mp_obj_t mix, + uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, + uint8_t channel_count, uint32_t sample_rate); + +void common_hal_audiofilters_filter_deinit(audiofilters_filter_obj_t *self); +bool common_hal_audiofilters_filter_deinited(audiofilters_filter_obj_t *self); + +uint32_t common_hal_audiofilters_filter_get_sample_rate(audiofilters_filter_obj_t *self); +uint8_t common_hal_audiofilters_filter_get_channel_count(audiofilters_filter_obj_t *self); +uint8_t common_hal_audiofilters_filter_get_bits_per_sample(audiofilters_filter_obj_t *self); + +mp_obj_t common_hal_audiofilters_filter_get_biquad(audiofilters_filter_obj_t *self); +void common_hal_audiofilters_filter_set_biquad(audiofilters_filter_obj_t *self, mp_obj_t arg); + +mp_obj_t common_hal_audiofilters_filter_get_mix(audiofilters_filter_obj_t *self); +void common_hal_audiofilters_filter_set_mix(audiofilters_filter_obj_t *self, mp_obj_t arg); + +bool common_hal_audiofilters_filter_get_playing(audiofilters_filter_obj_t *self); +void common_hal_audiofilters_filter_play(audiofilters_filter_obj_t *self, mp_obj_t sample, bool loop); +void common_hal_audiofilters_filter_stop(audiofilters_filter_obj_t *self); diff --git a/shared-bindings/audiofilters/__init__.c b/shared-bindings/audiofilters/__init__.c new file mode 100644 index 000000000000..c4124515b7d3 --- /dev/null +++ b/shared-bindings/audiofilters/__init__.c @@ -0,0 +1,33 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Cooper Dalrymple +// +// SPDX-License-Identifier: MIT + +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/audiofilters/__init__.h" +#include "shared-bindings/audiofilters/Filter.h" + +//| """Support for audio filter effects +//| +//| The `audiofilters` module contains classes to provide access to audio filter effects. +//| +//| """ + +static const mp_rom_map_elem_t audiofilters_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audiofilters) }, + { MP_ROM_QSTR(MP_QSTR_Filter), MP_ROM_PTR(&audiofilters_filter_type) }, +}; + +static MP_DEFINE_CONST_DICT(audiofilters_module_globals, audiofilters_module_globals_table); + +const mp_obj_module_t audiofilters_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&audiofilters_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_audiofilters, audiofilters_module); diff --git a/shared-bindings/audiofilters/__init__.h b/shared-bindings/audiofilters/__init__.h new file mode 100644 index 000000000000..29d2f6726559 --- /dev/null +++ b/shared-bindings/audiofilters/__init__.h @@ -0,0 +1,7 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Cooper Dalrymple +// +// SPDX-License-Identifier: MIT + +#pragma once diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c new file mode 100644 index 000000000000..da3d106379b9 --- /dev/null +++ b/shared-module/audiofilters/Filter.c @@ -0,0 +1,281 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Cooper Dalrymple +// +// SPDX-License-Identifier: MIT +#include "shared-bindings/audiofilters/Filter.h" + +#include +#include "py/runtime.h" + +void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, + mp_obj_t biquad, mp_obj_t mix, + uint32_t buffer_size, uint8_t bits_per_sample, + bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { + + // Basic settings every effect and audio sample has + // These are the effects values, not the source sample(s) + self->bits_per_sample = bits_per_sample; // Most common is 16, but 8 is also supported in many places + self->samples_signed = samples_signed; // Are the samples we provide signed (common is true) + self->channel_count = channel_count; // Channels can be 1 for mono or 2 for stereo + self->sample_rate = sample_rate; // Sample rate for the effect, this generally needs to match all audio objects + + // To smooth things out as CircuitPython is doing other tasks most audio objects have a buffer + // A double buffer is set up here so the audio output can use DMA on buffer 1 while we + // write to and create buffer 2. + // This buffer is what is passed to the audio component that plays the effect. + // Samples are set sequentially. For stereo audio they are passed L/R/L/R/... + self->buffer_len = buffer_size; // in bytes + + self->buffer[0] = m_malloc(self->buffer_len); + if (self->buffer[0] == NULL) { + common_hal_audiofilters_filter_deinit(self); + m_malloc_fail(self->buffer_len); + } + memset(self->buffer[0], 0, self->buffer_len); + + self->buffer[1] = m_malloc(self->buffer_len); + if (self->buffer[1] == NULL) { + common_hal_audiofilters_filter_deinit(self); + m_malloc_fail(self->buffer_len); + } + memset(self->buffer[1], 0, self->buffer_len); + + self->last_buf_idx = 1; // Which buffer to use first, toggle between 0 and 1 + + // Initialize other values most effects will need. + self->sample = NULL; // The current playing sample + self->sample_remaining_buffer = NULL; // Pointer to the start of the sample buffer we have not played + self->sample_buffer_length = 0; // How many samples do we have left to play (these may be 16 bit!) + self->loop = false; // When the sample is done do we loop to the start again or stop (e.g. in a wav file) + self->more_data = false; // Is there still more data to read from the sample or did we finish + + // The below section sets up the effect's starting values. + + if (biquad != MP_OBJ_NULL) { + biquad = mp_const_none; + } + synthio_biquad_filter_assign(biquad, &self->biquad); + + // If we did not receive a BlockInput we need to create a default float value + if (mix == MP_OBJ_NULL) { + mix = mp_obj_new_float(1.0); + } + synthio_block_assign_slot(mix, &self->mix, MP_QSTR_mix); +} + +bool common_hal_audiofilters_filter_deinited(audiofilters_filter_obj_t *self) { + if (self->buffer[0] == NULL) { + return true; + } + return false; +} + +void common_hal_audiofilters_filter_deinit(audiofilters_filter_obj_t *self) { + if (common_hal_audiofilters_filter_deinited(self)) { + return; + } + self->buffer[0] = NULL; + self->buffer[1] = NULL; +} + +mp_obj_t common_hal_audiofilters_filter_get_biquad(audiofilters_filter_obj_t *self) { + return self->biquad.obj; +} + +void common_hal_audiofilters_filter_set_biquad(audiofilters_filter_obj_t *self, mp_obj_t arg) { + synthio_biquad_filter_assign(arg, &self->biquad); +} + +mp_obj_t common_hal_audiofilters_filter_get_mix(audiofilters_filter_obj_t *self) { + return self->mix.obj; +} + +void common_hal_audiofilters_filter_set_mix(audiofilters_filter_obj_t *self, mp_obj_t arg) { + synthio_block_assign_slot(arg, &self->mix, MP_QSTR_mix); +} + +uint32_t common_hal_audiofilters_filter_get_sample_rate(audiofilters_filter_obj_t *self) { + return self->sample_rate; +} + +uint8_t common_hal_audiofilters_filter_get_channel_count(audiofilters_filter_obj_t *self) { + return self->channel_count; +} + +uint8_t common_hal_audiofilters_filter_get_bits_per_sample(audiofilters_filter_obj_t *self) { + return self->bits_per_sample; +} + +void audiofilters_filter_reset_buffer(audiofilters_filter_obj_t *self, + bool single_channel_output, + uint8_t channel) { + + memset(self->buffer[0], 0, self->buffer_len); + memset(self->buffer[1], 0, self->buffer_len); +} + +bool common_hal_audiofilters_filter_get_playing(audiofilters_filter_obj_t *self) { + return self->sample != NULL; +} + +void common_hal_audiofilters_filter_play(audiofilters_filter_obj_t *self, mp_obj_t sample, bool loop) { + // When a sample is to be played we must ensure the samples values matches what we expect + // Then we reset the sample and get the first buffer to play + // The get_buffer function will actually process that data + + if (audiosample_sample_rate(sample) != self->sample_rate) { + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_sample_rate); + } + if (audiosample_channel_count(sample) != self->channel_count) { + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_channel_count); + } + if (audiosample_bits_per_sample(sample) != self->bits_per_sample) { + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_bits_per_sample); + } + bool single_buffer; + bool samples_signed; + uint32_t max_buffer_length; + uint8_t spacing; + audiosample_get_buffer_structure(sample, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing); + if (samples_signed != self->samples_signed) { + mp_raise_ValueError_varg(MP_ERROR_TEXT("The sample's %q does not match"), MP_QSTR_signedness); + } + + self->sample = sample; + self->loop = loop; + + audiosample_reset_buffer(self->sample, false, 0); + audioio_get_buffer_result_t result = audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&self->sample_remaining_buffer, &self->sample_buffer_length); + + // Track remaining sample length in terms of bytes per sample + self->sample_buffer_length /= (self->bits_per_sample / 8); + // Store if we have more data in the sample to retrieve + self->more_data = result == GET_BUFFER_MORE_DATA; + + return; +} + +void common_hal_audiofilters_filter_stop(audiofilters_filter_obj_t *self) { + // When the sample is set to stop playing do any cleanup here + self->sample = NULL; + return; +} + +audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_obj_t *self, bool single_channel_output, uint8_t channel, + uint8_t **buffer, uint32_t *buffer_length) { + + if (!single_channel_output) { + channel = 0; + } + + // get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required + mp_float_t mix = MIN(1.0, MAX(synthio_block_slot_get(&self->mix), 0.0)); + + // Switch our buffers to the other buffer + self->last_buf_idx = !self->last_buf_idx; + + // If we are using 16 bit samples we need a 16 bit pointer, 8 bit needs an 8 bit pointer + int16_t *word_buffer = (int16_t *)self->buffer[self->last_buf_idx]; + int8_t *hword_buffer = self->buffer[self->last_buf_idx]; + uint32_t length = self->buffer_len / (self->bits_per_sample / 8); + + // Loop over the entire length of our buffer to fill it, this may require several calls to get data from the sample + while (length != 0) { + // Check if there is no more sample to play, we will either load more data, reset the sample if loop is on or clear the sample + if (self->sample_buffer_length == 0) { + if (!self->more_data) { // The sample has indicated it has no more data to play + if (self->loop && self->sample) { // If we are supposed to loop reset the sample to the start + audiosample_reset_buffer(self->sample, false, 0); + } else { // If we were not supposed to loop the sample, stop playing it + self->sample = NULL; + } + } + if (self->sample) { + // Load another sample buffer to play + audioio_get_buffer_result_t result = audiosample_get_buffer(self->sample, false, 0, (uint8_t **)&self->sample_remaining_buffer, &self->sample_buffer_length); + // Track length in terms of words. + self->sample_buffer_length /= (self->bits_per_sample / 8); + self->more_data = result == GET_BUFFER_MORE_DATA; + } + } + + // If we have a sample, filter it + if (self->sample != NULL) { + // Determine how many bytes we can process to our buffer, the less of the sample we have left and our buffer remaining + uint32_t n = MIN(self->sample_buffer_length, length); + + int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; // for 16-bit samples + int8_t *sample_hsrc = (int8_t *)self->sample_remaining_buffer; // for 8-bit samples + + if (mix <= 0.01) { // if mix is zero pure sample only + for (uint32_t i = 0; i < n; i++) { + if (MP_LIKELY(self->bits_per_sample == 16)) { + word_buffer[i] = sample_src[i]; + } else { + hword_buffer[i] = sample_hsrc[i]; + } + } + } else { + for (uint32_t i = 0; i < n; i++) { + int32_t sample_word = 0; + if (MP_LIKELY(self->bits_per_sample == 16)) { + sample_word = sample_src[i]; + } else { + if (self->samples_signed) { + sample_word = sample_hsrc[i]; + } else { + // Be careful here changing from an 8 bit unsigned to signed into a 32-bit signed + sample_word = (int8_t)(((uint8_t)sample_hsrc[i]) ^ 0x80); + } + } + + // TODO: Filter through synthio_biquad_filter_samples + + if (MP_LIKELY(self->bits_per_sample == 16)) { + word_buffer[i] = (sample_word * (1.0 - mix)) + (word * mix); + if (!self->samples_signed) { + word_buffer[i] ^= 0x8000; + } + } else { + int8_t mixed = (sample_word * (1.0 - mix)) + (word * mix); + if (self->samples_signed) { + hword_buffer[i] = mixed; + } else { + hword_buffer[i] = (uint8_t)mixed ^ 0x80; + } + } + } + } + + // Update the remaining length and the buffer positions based on how much we wrote into our buffer + length -= n; + word_buffer += n; + hword_buffer += n; + self->sample_remaining_buffer += (n * (self->bits_per_sample / 8)); + self->sample_buffer_length -= n; + } + } + + // Finally pass our buffer and length to the calling audio function + *buffer = (uint8_t *)self->buffer[self->last_buf_idx]; + *buffer_length = self->buffer_len; + + // Filter always returns more data but some effects may return GET_BUFFER_DONE or GET_BUFFER_ERROR (see audiocore/__init__.h) + return GET_BUFFER_MORE_DATA; +} + +void audiofilters_filter_get_buffer_structure(audiofilters_filter_obj_t *self, bool single_channel_output, + bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing) { + + // Return information about the effect's buffer (not the sample's) + // These are used by calling audio objects to determine how to handle the effect's buffer + *single_buffer = false; + *samples_signed = self->samples_signed; + *max_buffer_length = self->buffer_len; + if (single_channel_output) { + *spacing = self->channel_count; + } else { + *spacing = 1; + } +} diff --git a/shared-module/audiofilters/Filter.h b/shared-module/audiofilters/Filter.h new file mode 100644 index 000000000000..dc29743a5563 --- /dev/null +++ b/shared-module/audiofilters/Filter.h @@ -0,0 +1,51 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Cooper Dalrymple +// +// SPDX-License-Identifier: MIT +#pragma once + +#include "py/obj.h" + +#include "shared-module/audiocore/__init__.h" +#include "shared-module/synthio/block.h" +#include "shared-module/synthio/Biquad.h" + +extern const mp_obj_type_t audiofilters_filter_type; + +typedef struct { + mp_obj_base_t base; + biquad_filter_state biquad; + synthio_block_slot_t mix; + + uint8_t bits_per_sample; + bool samples_signed; + uint8_t channel_count; + uint32_t sample_rate; + + int8_t *buffer[2]; + uint8_t last_buf_idx; + uint32_t buffer_len; // max buffer in bytes + + uint8_t *sample_remaining_buffer; + uint32_t sample_buffer_length; + + bool loop; + bool more_data; + + mp_obj_t sample; +} audiofilters_filter_obj_t; + +void audiofilters_filter_reset_buffer(audiofilters_filter_obj_t *self, + bool single_channel_output, + uint8_t channel); + +audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_obj_t *self, + bool single_channel_output, + uint8_t channel, + uint8_t **buffer, + uint32_t *buffer_length); // length in bytes + +void audiofilters_filter_get_buffer_structure(audiofilters_filter_obj_t *self, bool single_channel_output, + bool *single_buffer, bool *samples_signed, + uint32_t *max_buffer_length, uint8_t *spacing); diff --git a/shared-module/audiofilters/__init__.c b/shared-module/audiofilters/__init__.c new file mode 100644 index 000000000000..83929b4c4fb8 --- /dev/null +++ b/shared-module/audiofilters/__init__.c @@ -0,0 +1,5 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Cooper Dalrymple +// +// SPDX-License-Identifier: MIT diff --git a/shared-module/audiofilters/__init__.h b/shared-module/audiofilters/__init__.h new file mode 100644 index 000000000000..29d2f6726559 --- /dev/null +++ b/shared-module/audiofilters/__init__.h @@ -0,0 +1,7 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Cooper Dalrymple +// +// SPDX-License-Identifier: MIT + +#pragma once From 1bf400d2dd3a315ae6f40f20d9cf4dd82f205734 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 22 Oct 2024 12:08:33 -0500 Subject: [PATCH 140/252] Rename `biquad` property to `filter`. --- py/circuitpy_defns.mk | 2 +- shared-bindings/audiofilters/Filter.c | 38 +++++++++++++-------------- shared-bindings/audiofilters/Filter.h | 6 ++--- shared-module/audiofilters/Filter.c | 20 ++++++++------ shared-module/audiofilters/Filter.h | 4 ++- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 9d6c73064e0b..61516561822c 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -625,7 +625,7 @@ SRC_SHARED_MODULE_ALL = \ audiocore/__init__.c \ audiodelays/Echo.c \ audiodelays/__init__.c \ - audiofilters/Distortion.c \ + audiofilters/Filter.c \ audiofilters/__init__.c \ audioio/__init__.c \ audiomixer/Mixer.c \ diff --git a/shared-bindings/audiofilters/Filter.c b/shared-bindings/audiofilters/Filter.c index f78c909d21bc..dd3b74f7854e 100644 --- a/shared-bindings/audiofilters/Filter.c +++ b/shared-bindings/audiofilters/Filter.c @@ -23,7 +23,7 @@ //| //| def __init__( //| self, -//| biquad: synthio.Biquad = None, +//| filter: synthio.Biquad = None, //| mix: synthio.BlockInput = 1.0, //| buffer_size: int = 512, //| sample_rate: int = 8000, @@ -38,7 +38,7 @@ //| The mix parameter allows you to change how much of the unchanged sample passes through to //| the output to how much of the effect audio you hear as the output. //| -//| :param synthio.Biquad biquad: The normalized biquad filter object used to process the signal. +//| :param synthio.Biquad filter: The normalized biquad filter object used to process the signal. //| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). //| :param int buffer_size: The total size in bytes of each of the two playback buffers to use //| :param int sample_rate: The sample rate to be used @@ -56,7 +56,7 @@ //| //| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22) //| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100) -//| filter = audiofilters.Filter(biquad=synth.low_pass_filter(frequency=2000, q_factor=1.25), buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0) +//| filter = audiofilters.Filter(filter=synth.low_pass_filter(frequency=2000, Q=1.25), buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0) //| filter.play(synth) //| audio.play(filter) //| @@ -68,9 +68,9 @@ //| time.sleep(5)""" //| ... static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_biquad, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; + enum { ARG_filter, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_biquad, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 512} }, { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, @@ -90,7 +90,7 @@ static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n } audiofilters_filter_obj_t *self = mp_obj_malloc(audiofilters_filter_obj_t, &audiofilters_filter_type); - common_hal_audiofilters_filter_construct(self, args[ARG_biquad].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + common_hal_audiofilters_filter_construct(self, args[ARG_filter].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); return MP_OBJ_FROM_PTR(self); } @@ -128,31 +128,31 @@ static mp_obj_t audiofilters_filter_obj___exit__(size_t n_args, const mp_obj_t * static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiofilters_filter___exit___obj, 4, 4, audiofilters_filter_obj___exit__); -//| biquad: synthio.Biquad +//| filter: synthio.Biquad //| """The normalized biquad filter object used to process the signal.""" -static mp_obj_t audiofilters_filter_obj_get_biquad(mp_obj_t self_in) { - return common_hal_audiofilters_filter_get_biquad(self_in); +static mp_obj_t audiofilters_filter_obj_get_filter(mp_obj_t self_in) { + return common_hal_audiofilters_filter_get_filter(self_in); } -MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_biquad_obj, audiofilters_filter_obj_get_biquad); +MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_filter_obj, audiofilters_filter_obj_get_filter); -static mp_obj_t audiofilters_filter_obj_set_biquad(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_biquad }; +static mp_obj_t audiofilters_filter_obj_set_filter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_filter }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_biquad, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, }; audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - common_hal_audiofilters_filter_set_biquad(self, args[ARG_biquad].u_obj); + common_hal_audiofilters_filter_set_filter(self, args[ARG_filter].u_obj); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_set_biquad_obj, 1, audiofilters_filter_obj_set_biquad); +MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_set_filter_obj, 1, audiofilters_filter_obj_set_filter); -MP_PROPERTY_GETSET(audiofilters_filter_biquad_obj, - (mp_obj_t)&audiofilters_filter_get_biquad_obj, - (mp_obj_t)&audiofilters_filter_set_biquad_obj); +MP_PROPERTY_GETSET(audiofilters_filter_filter_obj, + (mp_obj_t)&audiofilters_filter_get_filter_obj, + (mp_obj_t)&audiofilters_filter_set_filter_obj); //| mix: synthio.BlockInput @@ -241,7 +241,7 @@ static const mp_rom_map_elem_t audiofilters_filter_locals_dict_table[] = { // Properties { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiofilters_filter_playing_obj) }, - { MP_ROM_QSTR(MP_QSTR_biquad), MP_ROM_PTR(&audiofilters_filter_biquad_obj) }, + { MP_ROM_QSTR(MP_QSTR_filter), MP_ROM_PTR(&audiofilters_filter_filter_obj) }, { MP_ROM_QSTR(MP_QSTR_mix), MP_ROM_PTR(&audiofilters_filter_mix_obj) }, }; static MP_DEFINE_CONST_DICT(audiofilters_filter_locals_dict, audiofilters_filter_locals_dict_table); diff --git a/shared-bindings/audiofilters/Filter.h b/shared-bindings/audiofilters/Filter.h index 6a58b1ba1a96..739b625ee6c5 100644 --- a/shared-bindings/audiofilters/Filter.h +++ b/shared-bindings/audiofilters/Filter.h @@ -11,7 +11,7 @@ extern const mp_obj_type_t audiofilters_filter_type; void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, - mp_obj_t biquad, mp_obj_t mix, + mp_obj_t filter, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate); @@ -22,8 +22,8 @@ uint32_t common_hal_audiofilters_filter_get_sample_rate(audiofilters_filter_obj_ uint8_t common_hal_audiofilters_filter_get_channel_count(audiofilters_filter_obj_t *self); uint8_t common_hal_audiofilters_filter_get_bits_per_sample(audiofilters_filter_obj_t *self); -mp_obj_t common_hal_audiofilters_filter_get_biquad(audiofilters_filter_obj_t *self); -void common_hal_audiofilters_filter_set_biquad(audiofilters_filter_obj_t *self, mp_obj_t arg); +mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self); +void common_hal_audiofilters_filter_set_filter(audiofilters_filter_obj_t *self, mp_obj_t arg); mp_obj_t common_hal_audiofilters_filter_get_mix(audiofilters_filter_obj_t *self); void common_hal_audiofilters_filter_set_mix(audiofilters_filter_obj_t *self, mp_obj_t arg); diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index da3d106379b9..06788351c24f 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -9,7 +9,7 @@ #include "py/runtime.h" void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, - mp_obj_t biquad, mp_obj_t mix, + mp_obj_t filter, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { @@ -52,10 +52,11 @@ void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, // The below section sets up the effect's starting values. - if (biquad != MP_OBJ_NULL) { - biquad = mp_const_none; + if (filter == MP_OBJ_NULL) { + filter = mp_const_none; } - synthio_biquad_filter_assign(biquad, &self->biquad); + synthio_biquad_filter_assign(&self->filter_state, filter); + self->filter_obj = filter; // If we did not receive a BlockInput we need to create a default float value if (mix == MP_OBJ_NULL) { @@ -79,12 +80,13 @@ void common_hal_audiofilters_filter_deinit(audiofilters_filter_obj_t *self) { self->buffer[1] = NULL; } -mp_obj_t common_hal_audiofilters_filter_get_biquad(audiofilters_filter_obj_t *self) { - return self->biquad.obj; +mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self) { + return self->filter_obj; } -void common_hal_audiofilters_filter_set_biquad(audiofilters_filter_obj_t *self, mp_obj_t arg) { - synthio_biquad_filter_assign(arg, &self->biquad); +void common_hal_audiofilters_filter_set_filter(audiofilters_filter_obj_t *self, mp_obj_t arg) { + synthio_biquad_filter_assign(&self->filter_state, arg); + self->filter_obj = arg; } mp_obj_t common_hal_audiofilters_filter_get_mix(audiofilters_filter_obj_t *self) { @@ -113,6 +115,8 @@ void audiofilters_filter_reset_buffer(audiofilters_filter_obj_t *self, memset(self->buffer[0], 0, self->buffer_len); memset(self->buffer[1], 0, self->buffer_len); + + synthio_biquad_filter_reset(&self->filter_state); } bool common_hal_audiofilters_filter_get_playing(audiofilters_filter_obj_t *self) { diff --git a/shared-module/audiofilters/Filter.h b/shared-module/audiofilters/Filter.h index dc29743a5563..777f5a077de0 100644 --- a/shared-module/audiofilters/Filter.h +++ b/shared-module/audiofilters/Filter.h @@ -15,9 +15,11 @@ extern const mp_obj_type_t audiofilters_filter_type; typedef struct { mp_obj_base_t base; - biquad_filter_state biquad; + mp_obj_t filter_obj; synthio_block_slot_t mix; + biquad_filter_state filter_state; + uint8_t bits_per_sample; bool samples_signed; uint8_t channel_count; From db540c67ece8ac7dac816f4badce55fa4087826d Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 22 Oct 2024 12:09:07 -0500 Subject: [PATCH 141/252] Avoid processing sample if `filter` is `None`. --- shared-module/audiofilters/Filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index 06788351c24f..a537261af6ed 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -212,7 +212,7 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; // for 16-bit samples int8_t *sample_hsrc = (int8_t *)self->sample_remaining_buffer; // for 8-bit samples - if (mix <= 0.01) { // if mix is zero pure sample only + if (mix <= 0.01 || self->filter_obj == mp_const_none) { // if mix is zero pure sample only or no biquad filter object is provided for (uint32_t i = 0; i < n; i++) { if (MP_LIKELY(self->bits_per_sample == 16)) { word_buffer[i] = sample_src[i]; From e7c02bd56194a86d4c8a3d743555ddb9517b0b0d Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 22 Oct 2024 12:09:28 -0500 Subject: [PATCH 142/252] Biquad filter processing. --- shared-module/audiofilters/Filter.c | 101 ++++++++++++++++++++++------ shared-module/audiofilters/Filter.h | 2 + 2 files changed, 83 insertions(+), 20 deletions(-) diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index a537261af6ed..af353563a6c6 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -43,6 +43,22 @@ void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, self->last_buf_idx = 1; // Which buffer to use first, toggle between 0 and 1 + // This buffer will be used to process samples through the biquad filter + self->filter_buffer[0] = m_malloc(SYNTHIO_MAX_DUR * sizeof(int32_t)); + if (self->filter_buffer[0] == NULL) { + common_hal_audiofilters_filter_deinit(self); + m_malloc_fail(SYNTHIO_MAX_DUR * sizeof(int32_t)); + } + memset(self->filter_buffer[0], 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); + + // This buffer will be used to mix original sample with processed signal + self->filter_buffer[1] = m_malloc(SYNTHIO_MAX_DUR * sizeof(int32_t)); + if (self->filter_buffer[1] == NULL) { + common_hal_audiofilters_filter_deinit(self); + m_malloc_fail(SYNTHIO_MAX_DUR * sizeof(int32_t)); + } + memset(self->filter_buffer[1], 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); + // Initialize other values most effects will need. self->sample = NULL; // The current playing sample self->sample_remaining_buffer = NULL; // Pointer to the start of the sample buffer we have not played @@ -78,6 +94,8 @@ void common_hal_audiofilters_filter_deinit(audiofilters_filter_obj_t *self) { } self->buffer[0] = NULL; self->buffer[1] = NULL; + self->filter_buffer[0] = NULL; + self->filter_buffer[1] = NULL; } mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self) { @@ -115,6 +133,8 @@ void audiofilters_filter_reset_buffer(audiofilters_filter_obj_t *self, memset(self->buffer[0], 0, self->buffer_len); memset(self->buffer[1], 0, self->buffer_len); + memset(self->filter_buffer[0], 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); + memset(self->filter_buffer[1], 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); synthio_biquad_filter_reset(&self->filter_state); } @@ -166,6 +186,32 @@ void common_hal_audiofilters_filter_stop(audiofilters_filter_obj_t *self) { return; } +#define RANGE_LOW_16 (-28000) +#define RANGE_HIGH_16 (28000) +#define RANGE_SHIFT_16 (16) +#define RANGE_SCALE_16 (0xfffffff / (32768 * 2 - RANGE_HIGH_16)) // 2 for echo+sample + +// dynamic range compression via a downward compressor with hard knee +// +// When the output value is within the range +-28000 (about 85% of full scale), +// it is unchanged. Otherwise, it undergoes a gain reduction so that the +// largest possible values, (+32768,-32767) * 2 (2 for echo and sample), +// still fit within the output range +// +// This produces a much louder overall volume with multiple voices, without +// much additional processing. +// +// https://en.wikipedia.org/wiki/Dynamic_range_compression +static +int16_t mix_down_sample(int32_t sample) { + if (sample < RANGE_LOW_16) { + sample = (((sample - RANGE_LOW_16) * RANGE_SCALE_16) >> RANGE_SHIFT_16) + RANGE_LOW_16; + } else if (sample > RANGE_HIGH_16) { + sample = (((sample - RANGE_HIGH_16) * RANGE_SCALE_16) >> RANGE_SHIFT_16) + RANGE_HIGH_16; + } + return sample; +} + audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { @@ -221,34 +267,49 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o } } } else { - for (uint32_t i = 0; i < n; i++) { - int32_t sample_word = 0; - if (MP_LIKELY(self->bits_per_sample == 16)) { - sample_word = sample_src[i]; - } else { - if (self->samples_signed) { - sample_word = sample_hsrc[i]; + uint32_t i = 0; + while (i < n) { + uint32_t n_samples = MIN(SYNTHIO_MAX_DUR, n - i); + + // Fill filter buffer with samples + for (uint32_t j = 0; j < n_samples; j++) { + if (MP_LIKELY(self->bits_per_sample == 16)) { + self->filter_buffer[0][j] = sample_src[i + j]; } else { - // Be careful here changing from an 8 bit unsigned to signed into a 32-bit signed - sample_word = (int8_t)(((uint8_t)sample_hsrc[i]) ^ 0x80); + if (self->samples_signed) { + self->filter_buffer[0][j] = sample_hsrc[i + j]; + } else { + // Be careful here changing from an 8 bit unsigned to signed into a 32-bit signed + self->filter_buffer[0][j] = (int8_t)(((uint8_t)sample_hsrc[i + j]) ^ 0x80); + } } } - // TODO: Filter through synthio_biquad_filter_samples + // Copy original signal for mixing back in later + memcpy(self->filter_buffer[1], self->filter_buffer[0], n_samples); - if (MP_LIKELY(self->bits_per_sample == 16)) { - word_buffer[i] = (sample_word * (1.0 - mix)) + (word * mix); - if (!self->samples_signed) { - word_buffer[i] ^= 0x8000; - } - } else { - int8_t mixed = (sample_word * (1.0 - mix)) + (word * mix); - if (self->samples_signed) { - hword_buffer[i] = mixed; + // Process biquad filter + synthio_biquad_filter_samples(&self->filter_state, self->filter_buffer[0], n_samples); + + // Mix processed signal with original sample and transfer to output buffer + for (uint32_t j = 0; j < n_samples; j++) { + int32_t word = (self->filter_buffer[1][j] * (1.0 - mix)) + (self->filter_buffer[0][j] * mix); + if (MP_LIKELY(self->bits_per_sample == 16)) { + word_buffer[i + j] = mix_down_sample(word); + if (!self->samples_signed) { + word_buffer[i + j] ^= 0x8000; + } } else { - hword_buffer[i] = (uint8_t)mixed ^ 0x80; + int8_t mixed = word; + if (self->samples_signed) { + hword_buffer[i + j] = mixed; + } else { + hword_buffer[i + j] = (uint8_t)mixed ^ 0x80; + } } } + + i += n_samples; } } diff --git a/shared-module/audiofilters/Filter.h b/shared-module/audiofilters/Filter.h index 777f5a077de0..dd774e3dbf78 100644 --- a/shared-module/audiofilters/Filter.h +++ b/shared-module/audiofilters/Filter.h @@ -32,6 +32,8 @@ typedef struct { uint8_t *sample_remaining_buffer; uint32_t sample_buffer_length; + int32_t *filter_buffer[2]; + bool loop; bool more_data; From ab07f9ccda06aaa3d852a02b5e6e2fce29ebfcf2 Mon Sep 17 00:00:00 2001 From: Ettore Atalan Date: Tue, 22 Oct 2024 01:11:34 +0000 Subject: [PATCH 143/252] Translated using Weblate (German) Currently translated at 97.5% (973 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index 0e82ca98d38e..13a35b112550 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -6,14 +6,14 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-10-22 01:10+0000\n" -"Last-Translator: Sokromatrix \n" +"PO-Revision-Date: 2024-10-23 01:15+0000\n" +"Last-Translator: Ettore Atalan \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 5.8-rc\n" +"X-Generator: Weblate 5.8.2-dev\n" #: main.c msgid "" @@ -2150,7 +2150,7 @@ msgstr "Der UUID-Wert ist kein str-, int- oder Byte-Puffer" #: ports/raspberrypi/common-hal/memorymap/AddressRange.c msgid "Unable to access unaligned IO register" -msgstr "Zugriff auf nicht ausgerichtes IO-Register nicht möglich" +msgstr "Zugriff auf nicht ausgerichtetes EA-Register nicht möglich" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -2292,7 +2292,7 @@ msgstr "" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/espressif/common-hal/dualbank/__init__.c msgid "Update failed" -msgstr "" +msgstr "Aktualisierung fehlgeschlagen" #: ports/espressif/common-hal/_bleio/Characteristic.c #: ports/nordic/common-hal/_bleio/Characteristic.c @@ -2707,7 +2707,7 @@ msgstr "Eine binäre Operation zwischen '%q' und '%q' ist nicht möglich" #: py/emitnative.c msgid "can't do unary op of '%q'" -msgstr "" +msgstr "kann keine unäre Operation von '%q' durchführen" #: py/emitnative.c msgid "can't implicitly convert '%q' to 'bool'" From 48afaf2fcb9d56e33c00876dd60b304b771e08cd Mon Sep 17 00:00:00 2001 From: Sokromatrix Date: Tue, 22 Oct 2024 01:11:06 +0000 Subject: [PATCH 144/252] Translated using Weblate (German) Currently translated at 97.5% (973 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/de/ --- locale/de_DE.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/de_DE.po b/locale/de_DE.po index 13a35b112550..b6c187d18de9 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgstr "" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" "PO-Revision-Date: 2024-10-23 01:15+0000\n" -"Last-Translator: Ettore Atalan \n" +"Last-Translator: Sokromatrix \n" "Language: de_DE\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -2501,7 +2501,7 @@ msgstr "Array/Bytes auf der rechten Seite erforderlich" #: py/asmxtensa.c msgid "asm overflow" -msgstr "" +msgstr "ASM-Überlauf" #: py/compile.c msgid "async for/with outside async function" @@ -2601,7 +2601,7 @@ msgstr "Der Puffer ist zu klein für die angefragten Bytes" #: py/emitbc.c msgid "bytecode overflow" -msgstr "" +msgstr "Bytecode-Überlauf" #: py/objarray.c msgid "bytes length not a multiple of item size" From 9e8b3a6a838fdd6756ff6c222e6ab335bf42b84a Mon Sep 17 00:00:00 2001 From: Wellington Terumi Uemura Date: Tue, 22 Oct 2024 21:43:18 +0000 Subject: [PATCH 145/252] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (997 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/pt_BR/ --- locale/pt_BR.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/pt_BR.po b/locale/pt_BR.po index e86d0c87ceb2..1decf5e551b6 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-10-16 21:15+0000\n" +"PO-Revision-Date: 2024-10-23 01:15+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -14,7 +14,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 5.8-rc\n" +"X-Generator: Weblate 5.8.2-dev\n" #: main.c msgid "" @@ -568,7 +568,7 @@ msgstr "Já há um ouvinte com todas as correspondências" #: ports/espressif/common-hal/_bleio/__init__.c msgid "Already in progress" -msgstr "" +msgstr "Já em andamento" #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c From c7e87cfae3930a92ea279d8fff750da8377123aa Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 22 Oct 2024 21:33:28 -0500 Subject: [PATCH 146/252] Remove unnecessary double buffer on `filter_buffer`. --- shared-module/audiofilters/Filter.c | 39 +++++++++-------------------- shared-module/audiofilters/Filter.h | 2 +- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index af353563a6c6..86edb6cb0418 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -44,20 +44,12 @@ void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, self->last_buf_idx = 1; // Which buffer to use first, toggle between 0 and 1 // This buffer will be used to process samples through the biquad filter - self->filter_buffer[0] = m_malloc(SYNTHIO_MAX_DUR * sizeof(int32_t)); - if (self->filter_buffer[0] == NULL) { + self->filter_buffer = m_malloc(SYNTHIO_MAX_DUR * sizeof(int32_t)); + if (self->filter_buffer == NULL) { common_hal_audiofilters_filter_deinit(self); m_malloc_fail(SYNTHIO_MAX_DUR * sizeof(int32_t)); } - memset(self->filter_buffer[0], 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); - - // This buffer will be used to mix original sample with processed signal - self->filter_buffer[1] = m_malloc(SYNTHIO_MAX_DUR * sizeof(int32_t)); - if (self->filter_buffer[1] == NULL) { - common_hal_audiofilters_filter_deinit(self); - m_malloc_fail(SYNTHIO_MAX_DUR * sizeof(int32_t)); - } - memset(self->filter_buffer[1], 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); + memset(self->filter_buffer, 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); // Initialize other values most effects will need. self->sample = NULL; // The current playing sample @@ -94,8 +86,7 @@ void common_hal_audiofilters_filter_deinit(audiofilters_filter_obj_t *self) { } self->buffer[0] = NULL; self->buffer[1] = NULL; - self->filter_buffer[0] = NULL; - self->filter_buffer[1] = NULL; + self->filter_buffer = NULL; } mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self) { @@ -133,8 +124,7 @@ void audiofilters_filter_reset_buffer(audiofilters_filter_obj_t *self, memset(self->buffer[0], 0, self->buffer_len); memset(self->buffer[1], 0, self->buffer_len); - memset(self->filter_buffer[0], 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); - memset(self->filter_buffer[1], 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); + memset(self->filter_buffer, 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); synthio_biquad_filter_reset(&self->filter_state); } @@ -274,37 +264,32 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o // Fill filter buffer with samples for (uint32_t j = 0; j < n_samples; j++) { if (MP_LIKELY(self->bits_per_sample == 16)) { - self->filter_buffer[0][j] = sample_src[i + j]; + self->filter_buffer[j] = sample_src[i + j]; } else { if (self->samples_signed) { - self->filter_buffer[0][j] = sample_hsrc[i + j]; + self->filter_buffer[j] = sample_hsrc[i + j]; } else { // Be careful here changing from an 8 bit unsigned to signed into a 32-bit signed - self->filter_buffer[0][j] = (int8_t)(((uint8_t)sample_hsrc[i + j]) ^ 0x80); + self->filter_buffer[j] = (int8_t)(((uint8_t)sample_hsrc[i + j]) ^ 0x80); } } } - // Copy original signal for mixing back in later - memcpy(self->filter_buffer[1], self->filter_buffer[0], n_samples); - // Process biquad filter - synthio_biquad_filter_samples(&self->filter_state, self->filter_buffer[0], n_samples); + synthio_biquad_filter_samples(&self->filter_state, self->filter_buffer, n_samples); // Mix processed signal with original sample and transfer to output buffer for (uint32_t j = 0; j < n_samples; j++) { - int32_t word = (self->filter_buffer[1][j] * (1.0 - mix)) + (self->filter_buffer[0][j] * mix); if (MP_LIKELY(self->bits_per_sample == 16)) { - word_buffer[i + j] = mix_down_sample(word); + word_buffer[i + j] = mix_down_sample((sample_src[i + j] * (1.0 - mix)) + (self->filter_buffer[j] * mix)); if (!self->samples_signed) { word_buffer[i + j] ^= 0x8000; } } else { - int8_t mixed = word; if (self->samples_signed) { - hword_buffer[i + j] = mixed; + hword_buffer[i + j] = (int8_t)((sample_hsrc[i + j] * (1.0 - mix)) + (self->filter_buffer[j] * mix)); } else { - hword_buffer[i + j] = (uint8_t)mixed ^ 0x80; + hword_buffer[i + j] = (uint8_t)(((int8_t)(((uint8_t)sample_hsrc[i + j]) ^ 0x80) * (1.0 - mix)) + (self->filter_buffer[j] * mix)) ^ 0x80; } } } diff --git a/shared-module/audiofilters/Filter.h b/shared-module/audiofilters/Filter.h index dd774e3dbf78..b5d743a6c191 100644 --- a/shared-module/audiofilters/Filter.h +++ b/shared-module/audiofilters/Filter.h @@ -32,7 +32,7 @@ typedef struct { uint8_t *sample_remaining_buffer; uint32_t sample_buffer_length; - int32_t *filter_buffer[2]; + int32_t *filter_buffer; bool loop; bool more_data; From 8503318f4ab1a8bf57f3bfb04956c47c87750550 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 22 Oct 2024 21:41:37 -0500 Subject: [PATCH 147/252] Add `Optional` to `synthio.Biquad` in documentation to allow for `None` value. --- shared-bindings/audiofilters/Filter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared-bindings/audiofilters/Filter.c b/shared-bindings/audiofilters/Filter.c index dd3b74f7854e..457897909e0d 100644 --- a/shared-bindings/audiofilters/Filter.c +++ b/shared-bindings/audiofilters/Filter.c @@ -23,7 +23,7 @@ //| //| def __init__( //| self, -//| filter: synthio.Biquad = None, +//| filter: Optional[synthio.Biquad] = None, //| mix: synthio.BlockInput = 1.0, //| buffer_size: int = 512, //| sample_rate: int = 8000, @@ -38,7 +38,7 @@ //| The mix parameter allows you to change how much of the unchanged sample passes through to //| the output to how much of the effect audio you hear as the output. //| -//| :param synthio.Biquad filter: The normalized biquad filter object used to process the signal. +//| :param Optional[synthio.Biquad] filter: The normalized biquad filter object used to process the signal. //| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). //| :param int buffer_size: The total size in bytes of each of the two playback buffers to use //| :param int sample_rate: The sample rate to be used @@ -128,7 +128,7 @@ static mp_obj_t audiofilters_filter_obj___exit__(size_t n_args, const mp_obj_t * static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiofilters_filter___exit___obj, 4, 4, audiofilters_filter_obj___exit__); -//| filter: synthio.Biquad +//| filter: Optional[synthio.Biquad] //| """The normalized biquad filter object used to process the signal.""" static mp_obj_t audiofilters_filter_obj_get_filter(mp_obj_t self_in) { return common_hal_audiofilters_filter_get_filter(self_in); From bf780be81aff009e70520a2071a058a444ef6ac3 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 22 Oct 2024 23:02:44 -0400 Subject: [PATCH 148/252] CONFIG_ESP_SYSTEM_HW_STACK_GUARD=n for ESP32-C3 and ESP32-C6 --- ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults | 3 +++ ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults | 3 +++ 2 files changed, 6 insertions(+) diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults index bf9e57494c73..7718a705c784 100644 --- a/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults @@ -46,4 +46,7 @@ CONFIG_NEWLIB_NANO_FORMAT=y # end of Component config +# Workaround for https://github.com/espressif/esp-idf/issues/14456 +CONFIG_ESP_SYSTEM_HW_STACK_GUARD=n + # end of Espressif IoT Development Framework Configuration diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults index 85dde905f3ca..81df25182704 100644 --- a/ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults @@ -51,4 +51,7 @@ CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=4 # end of Component config +# Workaround for https://github.com/espressif/esp-idf/issues/14456 +CONFIG_ESP_SYSTEM_HW_STACK_GUARD=n + # end of Espressif IoT Development Framework Configuration From fb9a16d4f127e92d2f151a512c9b1bf38a064505 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 23 Oct 2024 09:25:54 -0400 Subject: [PATCH 149/252] shared-bindings/wifi/Radio.c: fix default values for start_dhcp_client args --- shared-bindings/wifi/Radio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 34e48925d3e7..97d09febcce0 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -732,8 +732,8 @@ MP_PROPERTY_GETTER(wifi_radio_stations_ap_obj, static mp_obj_t wifi_radio_start_dhcp_client(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ipv4, ARG_ipv6 }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_ipv4, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = MP_ROM_TRUE } }, - { MP_QSTR_ipv6, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = MP_ROM_FALSE } }, + { MP_QSTR_ipv4, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = true } }, + { MP_QSTR_ipv6, MP_ARG_KW_ONLY | MP_ARG_BOOL, { .u_bool = false } }, }; wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); From 9bda80b906ece9f401212ef46757b057b37d140c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 23 Oct 2024 10:17:49 -0700 Subject: [PATCH 150/252] Explicitly invalidate cache lines on RP2350 Clean alone can lead to crashes. Fixes #9746 --- ports/raspberrypi/supervisor/internal_flash.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/supervisor/internal_flash.c b/ports/raspberrypi/supervisor/internal_flash.c index 6502aa08b055..b667112b5880 100644 --- a/ports/raspberrypi/supervisor/internal_flash.c +++ b/ports/raspberrypi/supervisor/internal_flash.c @@ -51,7 +51,9 @@ static void save_psram_settings(void) { // We're about to invalidate the XIP cache, clean it first to commit any dirty writes to PSRAM uint8_t *maintenance_ptr = (uint8_t *)XIP_MAINTENANCE_BASE; for (int i = 1; i < 16 * 1024; i += 8) { - maintenance_ptr[i] = 0; + // Background info: https://forums.raspberrypi.com/viewtopic.php?t=378249 + maintenance_ptr[i] = 0; // Clean + maintenance_ptr[i - 1] = 0; // Explicitly invalidate } m1_timing = qmi_hw->m[1].timing; From 9186420d3d4d002fbce2fb257cf8d44d5e10e1e5 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 23 Oct 2024 13:43:23 -0400 Subject: [PATCH 151/252] turn off CONFIG_ESP_SYSTEM_HW_STACK_GUARD for all builds --- ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults | 3 --- ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults | 3 --- ports/espressif/esp-idf-config/sdkconfig.defaults | 1 + 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults index 7718a705c784..bf9e57494c73 100644 --- a/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults @@ -46,7 +46,4 @@ CONFIG_NEWLIB_NANO_FORMAT=y # end of Component config -# Workaround for https://github.com/espressif/esp-idf/issues/14456 -CONFIG_ESP_SYSTEM_HW_STACK_GUARD=n - # end of Espressif IoT Development Framework Configuration diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults index 81df25182704..85dde905f3ca 100644 --- a/ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig-esp32c6.defaults @@ -51,7 +51,4 @@ CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=4 # end of Component config -# Workaround for https://github.com/espressif/esp-idf/issues/14456 -CONFIG_ESP_SYSTEM_HW_STACK_GUARD=n - # end of Espressif IoT Development Framework Configuration diff --git a/ports/espressif/esp-idf-config/sdkconfig.defaults b/ports/espressif/esp-idf-config/sdkconfig.defaults index 0fc26c165c76..ed914b98995a 100644 --- a/ports/espressif/esp-idf-config/sdkconfig.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig.defaults @@ -39,6 +39,7 @@ CONFIG_PM_ENABLE=y # required for CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY CONFIG_ESP_MAIN_TASK_STACK_SIZE=16384 # CONFIG_ESP_TASK_WDT_INIT is not set # CONFIG_ESP_DEBUG_OCDAWARE is not set +# CONFIG_ESP_SYSTEM_HW_STACK_GUARD is not set # end of ESP System Settings From 01dc1db77079145c58e9e4610c8035895ebd68db Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 11:33:25 -0500 Subject: [PATCH 152/252] docs build: Ignore some generated files --- conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/conf.py b/conf.py index 6c30a43abb1f..9e185fd6a4de 100644 --- a/conf.py +++ b/conf.py @@ -225,6 +225,7 @@ def autoapi_prepare_jinja_env(jinja_env): "ports/nordic/peripherals", "ports/nordic/usb", "ports/raspberrypi/sdk", + "ports/raspberrypi/pioasm", "ports/raspberrypi/lib", "ports/silabs/gecko_sdk", "ports/silabs/tools", From ce0c1c77a4776ea055094c9ca8f0fa8b4e55a609 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 11:17:04 -0500 Subject: [PATCH 153/252] Add BlockBiquad BlockBiquad takes kind, f0 (center frequency) & Q (sharpness) block type arguments and calculates the actual filter coefficients every frame. This allows the filter characteristics f0 and Q to be changed dynamically from LFOs & arithmetic blocks. A new manual test demonstrates this on a host computer, playing a simple tone that is dynamically filtered. --- shared-bindings/synthio/BlockBiquad.c | 133 ++++++++++++++++++ shared-bindings/synthio/BlockBiquad.h | 28 ++++ shared-bindings/synthio/__init__.c | 3 + shared-module/synthio/Biquad.c | 14 +- shared-module/synthio/Biquad.h | 2 + shared-module/synthio/BlockBiquad.c | 107 ++++++++++++++ shared-module/synthio/BlockBiquad.h | 20 +++ shared-module/synthio/__init__.c | 12 +- shared-module/synthio/__init__.h | 2 +- .../synthio/note/blockfilter.py | 66 +++++++++ 10 files changed, 381 insertions(+), 6 deletions(-) create mode 100644 shared-bindings/synthio/BlockBiquad.c create mode 100644 shared-bindings/synthio/BlockBiquad.h create mode 100644 shared-module/synthio/BlockBiquad.c create mode 100644 shared-module/synthio/BlockBiquad.h create mode 100644 tests/circuitpython-manual/synthio/note/blockfilter.py diff --git a/shared-bindings/synthio/BlockBiquad.c b/shared-bindings/synthio/BlockBiquad.c new file mode 100644 index 000000000000..89589809e00d --- /dev/null +++ b/shared-bindings/synthio/BlockBiquad.c @@ -0,0 +1,133 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "py/enum.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/synthio/BlockBiquad.h" +#include "shared-bindings/util.h" + +//| class FilterType: +//| LOW_PASS: FilterType +//| HIGH_PASS: FilterType +//| BAND_PASS: FilterType +//| + +MAKE_ENUM_VALUE(synthio_filter_type, kind, LOW_PASS, SYNTHIO_LOW_PASS); +MAKE_ENUM_VALUE(synthio_filter_type, kind, HIGH_PASS, SYNTHIO_HIGH_PASS); +MAKE_ENUM_VALUE(synthio_filter_type, kind, BAND_PASS, SYNTHIO_BAND_PASS); + +MAKE_ENUM_MAP(synthio_filter) { + MAKE_ENUM_MAP_ENTRY(kind, LOW_PASS), + MAKE_ENUM_MAP_ENTRY(kind, HIGH_PASS), + MAKE_ENUM_MAP_ENTRY(kind, BAND_PASS), +}; + +static MP_DEFINE_CONST_DICT(synthio_filter_locals_dict, synthio_filter_locals_table); + +MAKE_PRINTER(synthio, synthio_filter); + +MAKE_ENUM_TYPE(synthio, FilterKind, synthio_filter); + +static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) { + return cp_enum_value(&synthio_filter_type, obj, arg_name); +} + +//| class BlockBiquad: +//| def _init__(kind: FilterKind, f0: BlockInput, Q: BlockInput = 0.7071067811865475): ... + +static const mp_arg_t block_biquad_properties[] = { + { MP_QSTR_kind, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } }, + { MP_QSTR_f0, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } }, + { MP_QSTR_Q, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL } }, +}; + +static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_kind, ARG_f0, ARG_Q }; + + mp_arg_val_t args[MP_ARRAY_SIZE(block_biquad_properties)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(block_biquad_properties), block_biquad_properties, args); + + if (args[ARG_Q].u_obj == MP_OBJ_NULL) { + args[ARG_Q].u_obj = mp_obj_new_float(MICROPY_FLOAT_CONST(0.7071067811865475)); + } + + synthio_filter_e kind = validate_synthio_filter(args[ARG_kind].u_obj, MP_QSTR_kind); + return common_hal_synthio_block_biquad_new(kind, args[ARG_f0].u_obj, args[ARG_Q].u_obj); +} + +//| +//| kind: BiquadKind +//| """The kind of filter (read-only)""" +static mp_obj_t synthio_block_biquad_get_kind(mp_obj_t self_in) { + synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); + return cp_enum_find(&synthio_filter_type, common_hal_synthio_block_biquad_get_kind(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_kind_obj, synthio_block_biquad_get_kind); + +MP_PROPERTY_GETTER(synthio_block_biquad_kind_obj, + (mp_obj_t)&synthio_block_biquad_get_kind_obj); + +//| +//| f0: BlockInput +//| """The central frequency (in Hz) of the filter""" +static mp_obj_t synthio_block_biquad_get_f0(mp_obj_t self_in) { + synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); + return common_hal_synthio_block_biquad_get_f0(self); +} +MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_f0_obj, synthio_block_biquad_get_f0); + +static mp_obj_t synthio_block_biquad_set_f0(mp_obj_t self_in, mp_obj_t arg) { + synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_synthio_block_biquad_set_f0(self, arg); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_f0_obj, synthio_block_biquad_set_f0); +MP_PROPERTY_GETSET(synthio_block_biquad_f0_obj, + (mp_obj_t)&synthio_block_biquad_get_f0_obj, + (mp_obj_t)&synthio_block_biquad_set_f0_obj); + + +//| +//| Q: BlockInput +//| """The sharpness (Q) of the filter""" +//| +static mp_obj_t synthio_block_biquad_get_Q(mp_obj_t self_in) { + synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); + return common_hal_synthio_block_biquad_get_Q(self); +} +MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_Q_obj, synthio_block_biquad_get_Q); + +static mp_obj_t synthio_block_biquad_set_Q(mp_obj_t self_in, mp_obj_t arg) { + synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_synthio_block_biquad_set_Q(self, arg); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_Q_obj, synthio_block_biquad_set_Q); +MP_PROPERTY_GETSET(synthio_block_biquad_Q_obj, + (mp_obj_t)&synthio_block_biquad_get_Q_obj, + (mp_obj_t)&synthio_block_biquad_set_Q_obj); + +static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_kind), MP_ROM_PTR(&synthio_block_biquad_kind_obj) }, + { MP_ROM_QSTR(MP_QSTR_f0), MP_ROM_PTR(&synthio_block_biquad_f0_obj) }, + { MP_ROM_QSTR(MP_QSTR_Q), MP_ROM_PTR(&synthio_block_biquad_Q_obj) }, +}; +static MP_DEFINE_CONST_DICT(synthio_block_biquad_locals_dict, synthio_block_biquad_locals_dict_table); + +static void block_biquad_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + (void)kind; + properties_print_helper(print, self_in, block_biquad_properties, MP_ARRAY_SIZE(block_biquad_properties)); +} + +MP_DEFINE_CONST_OBJ_TYPE( + synthio_block_biquad_type_obj, + MP_QSTR_BlockBiquad, + MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS, + make_new, synthio_block_biquad_make_new, + locals_dict, &synthio_block_biquad_locals_dict, + print, block_biquad_print + ); diff --git a/shared-bindings/synthio/BlockBiquad.h b/shared-bindings/synthio/BlockBiquad.h new file mode 100644 index 000000000000..458235d37715 --- /dev/null +++ b/shared-bindings/synthio/BlockBiquad.h @@ -0,0 +1,28 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "py/obj.h" + +extern const mp_obj_type_t synthio_block_biquad_type_obj; +extern const mp_obj_type_t synthio_filter_type; +typedef struct synthio_block_biquad synthio_block_biquad_t; + +typedef enum { + SYNTHIO_LOW_PASS, SYNTHIO_HIGH_PASS, SYNTHIO_BAND_PASS +} synthio_filter_e; + + +mp_obj_t common_hal_synthio_block_biquad_get_Q(synthio_block_biquad_t *self); +void common_hal_synthio_block_biquad_set_Q(synthio_block_biquad_t *self, mp_obj_t Q); + +mp_obj_t common_hal_synthio_block_biquad_get_f0(synthio_block_biquad_t *self); +void common_hal_synthio_block_biquad_set_f0(synthio_block_biquad_t *self, mp_obj_t f0); + +synthio_filter_e common_hal_synthio_block_biquad_get_kind(synthio_block_biquad_t *self); + +mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t f0, mp_obj_t Q); diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index fbc5cd559afb..fc490ff542f7 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -17,6 +17,7 @@ #include "shared-bindings/synthio/__init__.h" #include "shared-bindings/synthio/Biquad.h" +#include "shared-bindings/synthio/BlockBiquad.h" #include "shared-bindings/synthio/LFO.h" #include "shared-bindings/synthio/Math.h" #include "shared-bindings/synthio/MidiTrack.h" @@ -307,6 +308,8 @@ MP_DEFINE_CONST_FUN_OBJ_VAR(synthio_lfo_tick_obj, 1, synthio_lfo_tick); static const mp_rom_map_elem_t synthio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_synthio) }, { MP_ROM_QSTR(MP_QSTR_Biquad), MP_ROM_PTR(&synthio_biquad_type_obj) }, + { MP_ROM_QSTR(MP_QSTR_BlockBiquad), MP_ROM_PTR(&synthio_block_biquad_type_obj) }, + { MP_ROM_QSTR(MP_QSTR_FilterType), MP_ROM_PTR(&synthio_filter_type) }, { MP_ROM_QSTR(MP_QSTR_Math), MP_ROM_PTR(&synthio_math_type) }, { MP_ROM_QSTR(MP_QSTR_MathOperation), MP_ROM_PTR(&synthio_math_operation_type) }, { MP_ROM_QSTR(MP_QSTR_MidiTrack), MP_ROM_PTR(&synthio_miditrack_type) }, diff --git a/shared-module/synthio/Biquad.c b/shared-module/synthio/Biquad.c index 366d51645522..1418b86fd17b 100644 --- a/shared-module/synthio/Biquad.c +++ b/shared-module/synthio/Biquad.c @@ -6,6 +6,7 @@ #include #include "shared-bindings/synthio/Biquad.h" +#include "shared-bindings/synthio/BlockBiquad.h" #include "shared-module/synthio/Biquad.h" mp_obj_t common_hal_synthio_new_lpf(mp_float_t w0, mp_float_t Q) { @@ -74,20 +75,27 @@ mp_obj_t common_hal_synthio_new_bpf(mp_float_t w0, mp_float_t Q) { return namedtuple_make_new((const mp_obj_type_t *)&synthio_biquad_type_obj, MP_ARRAY_SIZE(out_args), 0, out_args); } -#define BIQUAD_SHIFT (15) static int32_t biquad_scale_arg_obj(mp_obj_t arg) { return (int32_t)MICROPY_FLOAT_C_FUN(round)(MICROPY_FLOAT_C_FUN(ldexp)(mp_obj_get_float(arg), BIQUAD_SHIFT)); } void synthio_biquad_filter_assign(biquad_filter_state *st, mp_obj_t biquad_obj) { - if (biquad_obj != mp_const_none) { - mp_arg_validate_type(biquad_obj, (const mp_obj_type_t *)&synthio_biquad_type_obj, MP_QSTR_filter); + if (biquad_obj == mp_const_none) { + return; + } + if (mp_obj_is_type(biquad_obj, &synthio_block_biquad_type_obj)) { + return; + } + if (mp_obj_is_type(biquad_obj, (const mp_obj_type_t *)&synthio_biquad_type_obj)) { mp_obj_tuple_t *biquad = (mp_obj_tuple_t *)MP_OBJ_TO_PTR(biquad_obj); st->a1 = biquad_scale_arg_obj(biquad->items[0]); st->a2 = biquad_scale_arg_obj(biquad->items[1]); st->b0 = biquad_scale_arg_obj(biquad->items[2]); st->b1 = biquad_scale_arg_obj(biquad->items[3]); st->b2 = biquad_scale_arg_obj(biquad->items[4]); + return; } + mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q or %q, not %q"), MP_QSTR_filter, MP_QSTR_Biquad, MP_QSTR_BlockBiquad, mp_obj_get_type(biquad_obj)->name); + } void synthio_biquad_filter_reset(biquad_filter_state *st) { diff --git a/shared-module/synthio/Biquad.h b/shared-module/synthio/Biquad.h index b33a6230caf8..a0dac47a2f93 100644 --- a/shared-module/synthio/Biquad.h +++ b/shared-module/synthio/Biquad.h @@ -8,6 +8,8 @@ #include "py/obj.h" +#define BIQUAD_SHIFT (15) + typedef struct { int32_t a1, a2, b0, b1, b2; int32_t x[2], y[2]; diff --git a/shared-module/synthio/BlockBiquad.c b/shared-module/synthio/BlockBiquad.c new file mode 100644 index 000000000000..bff2f43a9302 --- /dev/null +++ b/shared-module/synthio/BlockBiquad.c @@ -0,0 +1,107 @@ + +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include +#include "shared-bindings/synthio/BlockBiquad.h" +#include "shared-module/synthio/BlockBiquad.h" +#include "shared-module/synthio/block.h" + +typedef struct { + mp_float_t s, c; +} sincos_result_t; + +#define FOUR_OVER_PI (4 / M_PI) +static void fast_sincos(mp_float_t theta, sincos_result_t *result) { + mp_float_t x = (theta * FOUR_OVER_PI) - 1; + mp_float_t x2 = x * x, x3 = x2 * x, x4 = x2 * x2, x5 = x2 * x3; + mp_float_t c0 = 0.70708592, + c1x = -0.55535724 * x, + c2x2 = -0.21798592 * x2, + c3x3 = 0.05707685 * x3, + c4x4 = 0.0109 * x4, + c5x5 = -0.00171961 * x5; + + mp_float_t evens = c4x4 + c2x2 + c0, odds = c5x5 + c3x3 + c1x; + result->c = evens + odds; + result->s = evens - odds; +} + +mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t f0, mp_obj_t Q) { + synthio_block_biquad_t *self = mp_obj_malloc(synthio_block_biquad_t, &synthio_block_biquad_type_obj); + self->kind = kind; + synthio_block_assign_slot(f0, &self->f0, MP_QSTR_f0); + synthio_block_assign_slot(Q, &self->Q, MP_QSTR_Q); + return MP_OBJ_FROM_PTR(self); +} + +synthio_filter_e common_hal_synthio_block_biquad_get_kind(synthio_block_biquad_t *self) { + return self->kind; +} + +mp_obj_t common_hal_synthio_block_biquad_get_Q(synthio_block_biquad_t *self) { + return self->Q.obj; +} + +void common_hal_synthio_block_biquad_set_Q(synthio_block_biquad_t *self, mp_obj_t Q) { + synthio_block_assign_slot(Q, &self->Q, MP_QSTR_Q); +} + +mp_obj_t common_hal_synthio_block_biquad_get_f0(synthio_block_biquad_t *self) { + return self->f0.obj; +} + +void common_hal_synthio_block_biquad_set_f0(synthio_block_biquad_t *self, mp_obj_t f0) { + synthio_block_assign_slot(f0, &self->f0, MP_QSTR_f0); +} + +static int32_t biquad_scale_arg_float(mp_float_t arg) { + return (int32_t)MICROPY_FLOAT_C_FUN(round)(MICROPY_FLOAT_C_FUN(ldexp)(arg, BIQUAD_SHIFT)); +} + +void common_hal_synthio_block_biquad_tick(mp_obj_t self_in, biquad_filter_state *filter_state) { + synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); + + mp_float_t W0 = synthio_block_slot_get(&self->f0) * synthio_global_W_scale; + mp_float_t Q = synthio_block_slot_get(&self->Q); + + sincos_result_t sc; + fast_sincos(W0, &sc); + + mp_float_t alpha = sc.s / (2 * Q); + + mp_float_t a0, a1, a2, b0, b1, b2; + + a0 = 1 + alpha; + a1 = -2 * sc.c; + a2 = 1 - alpha; + + switch (self->kind) { + default: + case SYNTHIO_LOW_PASS: + b2 = b0 = (1 - sc.c) * .5; + b1 = 1 - sc.c; + break; + + case SYNTHIO_HIGH_PASS: + b2 = b0 = (1 + sc.c) * .5; + b1 = -(1 + sc.c); + break; + + case SYNTHIO_BAND_PASS: + b0 = alpha; + b1 = 0; + b2 = -b0; + } + + mp_float_t recip_a0 = 1 / a0; + + filter_state->a1 = biquad_scale_arg_float(a1 * recip_a0); + filter_state->a2 = biquad_scale_arg_float(a2 * recip_a0); + filter_state->b0 = biquad_scale_arg_float(b0 * recip_a0); + filter_state->b1 = biquad_scale_arg_float(b1 * recip_a0); + filter_state->b2 = biquad_scale_arg_float(b2 * recip_a0); +} diff --git a/shared-module/synthio/BlockBiquad.h b/shared-module/synthio/BlockBiquad.h new file mode 100644 index 000000000000..17fd5b7f816c --- /dev/null +++ b/shared-module/synthio/BlockBiquad.h @@ -0,0 +1,20 @@ + +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2023 Jeff Epler for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "shared-bindings/synthio/BlockBiquad.h" +#include "shared-module/synthio/Biquad.h" +#include "shared-module/synthio/block.h" + +typedef struct synthio_block_biquad { + mp_obj_base_t base; + synthio_filter_e kind; + synthio_block_slot_t f0, Q; +} synthio_block_biquad_t; + +void common_hal_synthio_block_biquad_tick(mp_obj_t self_in, biquad_filter_state *filter_state); diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index 630c3de86988..bd1ca7127a90 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -8,12 +8,15 @@ #include "shared-module/synthio/__init__.h" #include "shared-bindings/synthio/__init__.h" #include "shared-module/synthio/Biquad.h" +#include "shared-module/synthio/BlockBiquad.h" #include "shared-module/synthio/Note.h" #include "py/runtime.h" #include #include -mp_float_t synthio_global_rate_scale; +#define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846) + +mp_float_t synthio_global_rate_scale, synthio_global_W_scale; uint8_t synthio_global_tick; static const int16_t square_wave[] = {-32768, 32767}; @@ -335,6 +338,9 @@ void synthio_synth_synthesize(synthio_synth_t *synth, uint8_t **bufptr, uint32_t mp_obj_t filter_obj = synthio_synth_get_note_filter(note_obj); if (filter_obj != mp_const_none) { synthio_note_obj_t *note = MP_OBJ_TO_PTR(note_obj); + if (mp_obj_is_type(filter_obj, &synthio_block_biquad_type_obj)) { + common_hal_synthio_block_biquad_tick(filter_obj, ¬e->filter_state); + } synthio_biquad_filter_samples(¬e->filter_state, tmp_buffer32, dur); } @@ -490,7 +496,9 @@ uint32_t synthio_frequency_convert_scaled_to_dds(uint64_t frequency_scaled, int3 } void shared_bindings_synthio_lfo_tick(uint32_t sample_rate) { - synthio_global_rate_scale = (mp_float_t)SYNTHIO_MAX_DUR / sample_rate; + mp_float_t recip_sample_rate = MICROPY_FLOAT_CONST(1.) / sample_rate; + synthio_global_rate_scale = SYNTHIO_MAX_DUR * recip_sample_rate; + synthio_global_W_scale = (2 * MP_PI) * recip_sample_rate; synthio_global_tick++; } diff --git a/shared-module/synthio/__init__.h b/shared-module/synthio/__init__.h index b0bca1efcffe..d40e1df86854 100644 --- a/shared-module/synthio/__init__.h +++ b/shared-module/synthio/__init__.h @@ -88,6 +88,6 @@ int synthio_lfo_step(synthio_lfo_state_t *state, uint16_t dur); int synthio_sweep_step(synthio_lfo_state_t *state, uint16_t dur); int synthio_sweep_in_step(synthio_lfo_state_t *state, uint16_t dur); -extern mp_float_t synthio_global_rate_scale; +extern mp_float_t synthio_global_rate_scale, synthio_global_W_scale; extern uint8_t synthio_global_tick; void shared_bindings_synthio_lfo_tick(uint32_t sample_rate); diff --git a/tests/circuitpython-manual/synthio/note/blockfilter.py b/tests/circuitpython-manual/synthio/note/blockfilter.py new file mode 100644 index 000000000000..70f8a5006384 --- /dev/null +++ b/tests/circuitpython-manual/synthio/note/blockfilter.py @@ -0,0 +1,66 @@ +import sys + +sys.path.insert( + 0, f"{__file__.rpartition('/')[0] or '.'}/../../../../frozen/Adafruit_CircuitPython_Wave" +) + +import random +import audiocore +import synthio +from ulab import numpy as np +import adafruit_wave as wave + +random.seed(9) + +envelope = synthio.Envelope( + attack_time=0.15, decay_time=0, release_time=0.08, attack_level=1.0, sustain_level=1.0 +) + +SAMPLE_SIZE = 1024 +VOLUME = 14700 +sine = np.array( + np.sin(np.linspace(0, 2 * np.pi, SAMPLE_SIZE, endpoint=False)) * VOLUME, + dtype=np.int16, +) +noise = np.array([random.randint(-VOLUME, VOLUME) for i in range(SAMPLE_SIZE)], dtype=np.int16) +bend_out = np.linspace(0, 32767, num=SAMPLE_SIZE, endpoint=True, dtype=np.int16) +sweep = np.linspace(-32767, 32767, num=SAMPLE_SIZE, endpoint=True, dtype=np.int16) + +lfos_of_interest = [] + + +def synthesize(synth): + freq_sweep = synthio.LFO( + sweep, offset=synthio.midi_to_hz(72), scale=synthio.midi_to_hz(72), rate=1, once=True + ) + + for biquad in ( + None, + synthio.BlockBiquad(synthio.FilterType.LOW_PASS, freq_sweep), + synthio.BlockBiquad(synthio.FilterType.HIGH_PASS, freq_sweep), + synthio.BlockBiquad(synthio.FilterType.BAND_PASS, freq_sweep, Q=8), + ): + n = synthio.Note( + frequency=synthio.midi_to_hz(72), + envelope=envelope, + filter=biquad, + waveform=sine, + ) + + freq_sweep.retrigger() + synth.press(n) + print("n", n.frequency) + yield 24 * 6 + synth.release_all() + yield 24 + + +with wave.open("blockfilter.wav", "w") as f: + f.setnchannels(1) + f.setsampwidth(2) + f.setframerate(48000) + synth = synthio.Synthesizer(sample_rate=48000) + for n in synthesize(synth): + for i in range(n): + result, data = audiocore.get_buffer(synth) + f.writeframes(data) From 1fef6b4105734d1ab5d5ca88658e312d68877511 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 11:34:21 -0500 Subject: [PATCH 154/252] BlockBiquad: improve docs & make parameter names match old filter methods --- shared-bindings/synthio/BlockBiquad.c | 71 +++++++++++++++++---------- shared-bindings/synthio/BlockBiquad.h | 10 ++-- shared-module/synthio/BlockBiquad.c | 16 +++--- 3 files changed, 57 insertions(+), 40 deletions(-) diff --git a/shared-bindings/synthio/BlockBiquad.c b/shared-bindings/synthio/BlockBiquad.c index 89589809e00d..2e3976464902 100644 --- a/shared-bindings/synthio/BlockBiquad.c +++ b/shared-bindings/synthio/BlockBiquad.c @@ -11,9 +11,14 @@ #include "shared-bindings/util.h" //| class FilterType: +//| """The type of filter""" +//| //| LOW_PASS: FilterType +//| """A low-pass filter""" //| HIGH_PASS: FilterType +//| """A high-pass filter""" //| BAND_PASS: FilterType +//| """A band-pass filter""" //| MAKE_ENUM_VALUE(synthio_filter_type, kind, LOW_PASS, SYNTHIO_LOW_PASS); @@ -37,16 +42,28 @@ static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) { } //| class BlockBiquad: -//| def _init__(kind: FilterKind, f0: BlockInput, Q: BlockInput = 0.7071067811865475): ... +//| def __init__( +//| kind: FilterKind, frequency: BlockInput, q_factor: BlockInput = 0.7071067811865475 +//| ): +//| """Construct a biquad filter object with dynamic center frequency & q factor +//| +//| Since ``frequency`` and ``q_factor`` are `BlockInput`s, they can be varied dynamically. +//| Internally, this is evaluated as "direct form 1" biquad filter. +//| +//| The internal filter state x[] and y[] is not updated when the filter +//| coefficients change, and there is no theoretical justification for why +//| this should result in a stable filter output. However, in practice, +//| slowly varying the filter's characteristic frequency and sharpness +//| appears to work as you'd expect.""" static const mp_arg_t block_biquad_properties[] = { { MP_QSTR_kind, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } }, - { MP_QSTR_f0, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } }, + { MP_QSTR_frequency, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } }, { MP_QSTR_Q, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL } }, }; static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_kind, ARG_f0, ARG_Q }; + enum { ARG_kind, ARG_frequency, ARG_Q }; mp_arg_val_t args[MP_ARRAY_SIZE(block_biquad_properties)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(block_biquad_properties), block_biquad_properties, args); @@ -56,7 +73,7 @@ static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size } synthio_filter_e kind = validate_synthio_filter(args[ARG_kind].u_obj, MP_QSTR_kind); - return common_hal_synthio_block_biquad_new(kind, args[ARG_f0].u_obj, args[ARG_Q].u_obj); + return common_hal_synthio_block_biquad_new(kind, args[ARG_frequency].u_obj, args[ARG_Q].u_obj); } //| @@ -72,49 +89,49 @@ MP_PROPERTY_GETTER(synthio_block_biquad_kind_obj, (mp_obj_t)&synthio_block_biquad_get_kind_obj); //| -//| f0: BlockInput +//| frequency: BlockInput //| """The central frequency (in Hz) of the filter""" -static mp_obj_t synthio_block_biquad_get_f0(mp_obj_t self_in) { +static mp_obj_t synthio_block_biquad_get_frequency(mp_obj_t self_in) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_synthio_block_biquad_get_f0(self); + return common_hal_synthio_block_biquad_get_frequency(self); } -MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_f0_obj, synthio_block_biquad_get_f0); +MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_frequency_obj, synthio_block_biquad_get_frequency); -static mp_obj_t synthio_block_biquad_set_f0(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t synthio_block_biquad_set_frequency(mp_obj_t self_in, mp_obj_t arg) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_block_biquad_set_f0(self, arg); + common_hal_synthio_block_biquad_set_frequency(self, arg); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_f0_obj, synthio_block_biquad_set_f0); -MP_PROPERTY_GETSET(synthio_block_biquad_f0_obj, - (mp_obj_t)&synthio_block_biquad_get_f0_obj, - (mp_obj_t)&synthio_block_biquad_set_f0_obj); +MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_frequency_obj, synthio_block_biquad_set_frequency); +MP_PROPERTY_GETSET(synthio_block_biquad_frequency_obj, + (mp_obj_t)&synthio_block_biquad_get_frequency_obj, + (mp_obj_t)&synthio_block_biquad_set_frequency_obj); //| -//| Q: BlockInput -//| """The sharpness (Q) of the filter""" +//| q_factor: BlockInput +//| """The sharpness (q_factor) of the filter""" //| -static mp_obj_t synthio_block_biquad_get_Q(mp_obj_t self_in) { +static mp_obj_t synthio_block_biquad_get_q_factor(mp_obj_t self_in) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_synthio_block_biquad_get_Q(self); + return common_hal_synthio_block_biquad_get_q_factor(self); } -MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_Q_obj, synthio_block_biquad_get_Q); +MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_q_factor_obj, synthio_block_biquad_get_q_factor); -static mp_obj_t synthio_block_biquad_set_Q(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t synthio_block_biquad_set_q_factor(mp_obj_t self_in, mp_obj_t arg) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_block_biquad_set_Q(self, arg); + common_hal_synthio_block_biquad_set_q_factor(self, arg); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_Q_obj, synthio_block_biquad_set_Q); -MP_PROPERTY_GETSET(synthio_block_biquad_Q_obj, - (mp_obj_t)&synthio_block_biquad_get_Q_obj, - (mp_obj_t)&synthio_block_biquad_set_Q_obj); +MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_q_factor_obj, synthio_block_biquad_set_q_factor); +MP_PROPERTY_GETSET(synthio_block_biquad_q_factor_obj, + (mp_obj_t)&synthio_block_biquad_get_q_factor_obj, + (mp_obj_t)&synthio_block_biquad_set_q_factor_obj); static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_kind), MP_ROM_PTR(&synthio_block_biquad_kind_obj) }, - { MP_ROM_QSTR(MP_QSTR_f0), MP_ROM_PTR(&synthio_block_biquad_f0_obj) }, - { MP_ROM_QSTR(MP_QSTR_Q), MP_ROM_PTR(&synthio_block_biquad_Q_obj) }, + { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&synthio_block_biquad_frequency_obj) }, + { MP_ROM_QSTR(MP_QSTR_q_factor), MP_ROM_PTR(&synthio_block_biquad_q_factor_obj) }, }; static MP_DEFINE_CONST_DICT(synthio_block_biquad_locals_dict, synthio_block_biquad_locals_dict_table); diff --git a/shared-bindings/synthio/BlockBiquad.h b/shared-bindings/synthio/BlockBiquad.h index 458235d37715..133edb3be564 100644 --- a/shared-bindings/synthio/BlockBiquad.h +++ b/shared-bindings/synthio/BlockBiquad.h @@ -17,12 +17,12 @@ typedef enum { } synthio_filter_e; -mp_obj_t common_hal_synthio_block_biquad_get_Q(synthio_block_biquad_t *self); -void common_hal_synthio_block_biquad_set_Q(synthio_block_biquad_t *self, mp_obj_t Q); +mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self); +void common_hal_synthio_block_biquad_set_q_factor(synthio_block_biquad_t *self, mp_obj_t Q); -mp_obj_t common_hal_synthio_block_biquad_get_f0(synthio_block_biquad_t *self); -void common_hal_synthio_block_biquad_set_f0(synthio_block_biquad_t *self, mp_obj_t f0); +mp_obj_t common_hal_synthio_block_biquad_get_frequency(synthio_block_biquad_t *self); +void common_hal_synthio_block_biquad_set_frequency(synthio_block_biquad_t *self, mp_obj_t frequency); synthio_filter_e common_hal_synthio_block_biquad_get_kind(synthio_block_biquad_t *self); -mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t f0, mp_obj_t Q); +mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t frequency, mp_obj_t Q); diff --git a/shared-module/synthio/BlockBiquad.c b/shared-module/synthio/BlockBiquad.c index bff2f43a9302..6209be0bad5e 100644 --- a/shared-module/synthio/BlockBiquad.c +++ b/shared-module/synthio/BlockBiquad.c @@ -33,8 +33,8 @@ static void fast_sincos(mp_float_t theta, sincos_result_t *result) { mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t f0, mp_obj_t Q) { synthio_block_biquad_t *self = mp_obj_malloc(synthio_block_biquad_t, &synthio_block_biquad_type_obj); self->kind = kind; - synthio_block_assign_slot(f0, &self->f0, MP_QSTR_f0); - synthio_block_assign_slot(Q, &self->Q, MP_QSTR_Q); + synthio_block_assign_slot(f0, &self->f0, MP_QSTR_frequency); + synthio_block_assign_slot(Q, &self->Q, MP_QSTR_q_factor); return MP_OBJ_FROM_PTR(self); } @@ -42,20 +42,20 @@ synthio_filter_e common_hal_synthio_block_biquad_get_kind(synthio_block_biquad_t return self->kind; } -mp_obj_t common_hal_synthio_block_biquad_get_Q(synthio_block_biquad_t *self) { +mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self) { return self->Q.obj; } -void common_hal_synthio_block_biquad_set_Q(synthio_block_biquad_t *self, mp_obj_t Q) { - synthio_block_assign_slot(Q, &self->Q, MP_QSTR_Q); +void common_hal_synthio_block_biquad_set_q_factor(synthio_block_biquad_t *self, mp_obj_t q_factor) { + synthio_block_assign_slot(q_factor, &self->Q, MP_QSTR_q_factor); } -mp_obj_t common_hal_synthio_block_biquad_get_f0(synthio_block_biquad_t *self) { +mp_obj_t common_hal_synthio_block_biquad_get_frequency(synthio_block_biquad_t *self) { return self->f0.obj; } -void common_hal_synthio_block_biquad_set_f0(synthio_block_biquad_t *self, mp_obj_t f0) { - synthio_block_assign_slot(f0, &self->f0, MP_QSTR_f0); +void common_hal_synthio_block_biquad_set_frequency(synthio_block_biquad_t *self, mp_obj_t frequency) { + synthio_block_assign_slot(frequency, &self->f0, MP_QSTR_frequency); } static int32_t biquad_scale_arg_float(mp_float_t arg) { From 9df857d6d56cc6ed576f3894c2b84a9f9c8e99b3 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 11:43:24 -0500 Subject: [PATCH 155/252] lift version requirement on cryptography, espressif fixed it --- requirements-dev.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 050b61224119..113c54cc5998 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -25,9 +25,7 @@ intelhex # for building & testing natmods pyelftools -# for mbedtls certificate store -# version limit due to espressif -cryptography<36.1,>=2.1.4 +cryptography # for web workflow minify minify_html From 9e999bdfb5a2d38bff9b22999b86da14734c4352 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 11:45:42 -0500 Subject: [PATCH 156/252] need to actually build the files --- ports/unix/variants/coverage/mpconfigvariant.mk | 2 ++ py/circuitpy_defns.mk | 1 + 2 files changed, 3 insertions(+) diff --git a/ports/unix/variants/coverage/mpconfigvariant.mk b/ports/unix/variants/coverage/mpconfigvariant.mk index 9721c2803e25..628b0f5b9699 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.mk +++ b/ports/unix/variants/coverage/mpconfigvariant.mk @@ -56,6 +56,7 @@ SRC_BITMAP := \ shared-bindings/synthio/LFO.c \ shared-bindings/synthio/Note.c \ shared-bindings/synthio/Biquad.c \ + shared-bindings/synthio/BlockBiquad.c \ shared-bindings/synthio/Synthesizer.c \ shared-bindings/traceback/__init__.c \ shared-bindings/util.c \ @@ -87,6 +88,7 @@ SRC_BITMAP := \ shared-module/synthio/LFO.c \ shared-module/synthio/Note.c \ shared-module/synthio/Biquad.c \ + shared-module/synthio/BlockBiquad.c \ shared-module/synthio/Synthesizer.c \ shared-module/traceback/__init__.c \ shared-module/zlib/__init__.c \ diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 61516561822c..dc3d35d8df22 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -717,6 +717,7 @@ SRC_SHARED_MODULE_ALL = \ supervisor/__init__.c \ supervisor/StatusBar.c \ synthio/Biquad.c \ + synthio/BlockBiquad.c \ synthio/LFO.c \ synthio/Math.c \ synthio/MidiTrack.c \ From 2c7ae417d8466efe89c2a4deb26cde1903866bad Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 13:33:40 -0500 Subject: [PATCH 157/252] fix check-stubs errors --- shared-bindings/synthio/BlockBiquad.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shared-bindings/synthio/BlockBiquad.c b/shared-bindings/synthio/BlockBiquad.c index 2e3976464902..67706447a26c 100644 --- a/shared-bindings/synthio/BlockBiquad.c +++ b/shared-bindings/synthio/BlockBiquad.c @@ -35,7 +35,7 @@ static MP_DEFINE_CONST_DICT(synthio_filter_locals_dict, synthio_filter_locals_ta MAKE_PRINTER(synthio, synthio_filter); -MAKE_ENUM_TYPE(synthio, FilterKind, synthio_filter); +MAKE_ENUM_TYPE(synthio, FilterType, synthio_filter); static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) { return cp_enum_value(&synthio_filter_type, obj, arg_name); @@ -43,8 +43,11 @@ static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) { //| class BlockBiquad: //| def __init__( -//| kind: FilterKind, frequency: BlockInput, q_factor: BlockInput = 0.7071067811865475 -//| ): +//| self, +//| kind: FilterType, +//| frequency: BlockInput, +//| q_factor: BlockInput = 0.7071067811865475, +//| ) -> None: //| """Construct a biquad filter object with dynamic center frequency & q factor //| //| Since ``frequency`` and ``q_factor`` are `BlockInput`s, they can be varied dynamically. @@ -77,7 +80,7 @@ static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size } //| -//| kind: BiquadKind +//| kind: FilterType //| """The kind of filter (read-only)""" static mp_obj_t synthio_block_biquad_get_kind(mp_obj_t self_in) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); From 277c2b3a3253548bf4e97f8fc598585b25aab9e9 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 24 Oct 2024 12:00:18 -0700 Subject: [PATCH 158/252] Update msdk submodule to clear nvic/dma warnings --- ports/analog/msdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/analog/msdk b/ports/analog/msdk index 608acf33e95a..db69388844d2 160000 --- a/ports/analog/msdk +++ b/ports/analog/msdk @@ -1 +1 @@ -Subproject commit 608acf33e95a994d548b8223955952c4749acaac +Subproject commit db69388844d29e727cd245b90b54279341f77401 From 90c7f0b8ed7be8e5a2bf1dd174c5c33bd82e1e47 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 24 Oct 2024 12:23:26 -0700 Subject: [PATCH 159/252] Remove dma_revb.c from Makefile --- ports/analog/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 79eb7a49052d..9499c8eacd36 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -100,7 +100,6 @@ SRC_MAX32 += \ $(PERIPH_SRC)/CTB/ctb_reva.c \ $(PERIPH_SRC)/CTB/ctb_common.c \ $(PERIPH_SRC)/DMA/dma_reva.c \ - $(PERIPH_SRC)/DMA/dma_revb.c \ $(PERIPH_SRC)/DMA/dma_$(DIE_TYPE).c \ $(PERIPH_SRC)/FLC/flc_common.c \ $(PERIPH_SRC)/FLC/flc_$(DIE_TYPE).c \ From d19a191bc389b61eb6d40f7f858492c2f6fdc30a Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 24 Oct 2024 12:40:44 -0700 Subject: [PATCH 160/252] Add CONFIG_TRUSTED_EXECUTION_SECURE macro to Makefile --- ports/analog/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 9499c8eacd36..46dfc6a53b39 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -145,7 +145,8 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET_REV=0x4131 \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ - -DRISCV_LOAD=0 + -DRISCV_LOAD=0 \ + -DCONFIG_TRUSTED_EXECUTION_SECURE=0 # todo: add these for linkerfiles later on so that it's easier to add new boards # -DFLASH_ORIGIN=0x10000000 \ From 7d48b0161a5e706e65046ec1539b23435d081a7b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 24 Oct 2024 16:02:24 -0400 Subject: [PATCH 161/252] document different kinds of _bleio --- shared-bindings/_bleio/__init__.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/shared-bindings/_bleio/__init__.c b/shared-bindings/_bleio/__init__.c index c0cd439f7d92..049deb05cf73 100644 --- a/shared-bindings/_bleio/__init__.c +++ b/shared-bindings/_bleio/__init__.c @@ -33,7 +33,14 @@ //| `adafruit_ble `_ //| CircuitPython library instead, which builds on `_bleio`, and //| provides higher-level convenience functionality, including predefined beacons, clients, -//| servers.""" +//| servers. +//| +//| .. note:: `_bleio` uses native BLE capability on boards that support it, including Nordic nRF, +//| Espressif (except ESP32-S2 and ESP32-P4), and SiLabs. +//| On other boards, `_bleio`, if present, supports BLE using an AirLift co-processor. +//| Pico W boards do *not* support BLE using the on-board CYW43 co-processor, +//| but do support using an external AirLift. +//| """ //| adapter: Adapter //| """BLE Adapter used to manage device discovery and connections. From b03d396cfac3acdafc0095bd940132465cb968a5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 18:34:52 -0500 Subject: [PATCH 162/252] Fix doc build error --- shared-bindings/synthio/BlockBiquad.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shared-bindings/synthio/BlockBiquad.c b/shared-bindings/synthio/BlockBiquad.c index 67706447a26c..d0da68ba6e73 100644 --- a/shared-bindings/synthio/BlockBiquad.c +++ b/shared-bindings/synthio/BlockBiquad.c @@ -50,8 +50,9 @@ static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) { //| ) -> None: //| """Construct a biquad filter object with dynamic center frequency & q factor //| -//| Since ``frequency`` and ``q_factor`` are `BlockInput`s, they can be varied dynamically. -//| Internally, this is evaluated as "direct form 1" biquad filter. +//| Since ``frequency`` and ``q_factor`` are `BlockInput` objects, they can +//| be varied dynamically. Internally, this is evaluated as "direct form 1" +//| biquad filter. //| //| The internal filter state x[] and y[] is not updated when the filter //| coefficients change, and there is no theoretical justification for why From e891bce1292e72a1f102b04ffcf88f2a7dfefa0d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 20:47:50 -0500 Subject: [PATCH 163/252] Rename FilterType -> FilterMode --- shared-bindings/synthio/BlockBiquad.c | 58 +++++++++---------- shared-bindings/synthio/BlockBiquad.h | 8 +-- shared-bindings/synthio/__init__.c | 2 +- shared-module/synthio/BlockBiquad.c | 10 ++-- shared-module/synthio/BlockBiquad.h | 2 +- .../synthio/note/blockfilter.py | 6 +- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/shared-bindings/synthio/BlockBiquad.c b/shared-bindings/synthio/BlockBiquad.c index d0da68ba6e73..0d38eb3026ae 100644 --- a/shared-bindings/synthio/BlockBiquad.c +++ b/shared-bindings/synthio/BlockBiquad.c @@ -10,41 +10,41 @@ #include "shared-bindings/synthio/BlockBiquad.h" #include "shared-bindings/util.h" -//| class FilterType: +//| class FilterMode: //| """The type of filter""" //| -//| LOW_PASS: FilterType +//| LOW_PASS: FilterMode //| """A low-pass filter""" -//| HIGH_PASS: FilterType +//| HIGH_PASS: FilterMode //| """A high-pass filter""" -//| BAND_PASS: FilterType +//| BAND_PASS: FilterMode //| """A band-pass filter""" //| -MAKE_ENUM_VALUE(synthio_filter_type, kind, LOW_PASS, SYNTHIO_LOW_PASS); -MAKE_ENUM_VALUE(synthio_filter_type, kind, HIGH_PASS, SYNTHIO_HIGH_PASS); -MAKE_ENUM_VALUE(synthio_filter_type, kind, BAND_PASS, SYNTHIO_BAND_PASS); +MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, LOW_PASS, SYNTHIO_LOW_PASS); +MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, HIGH_PASS, SYNTHIO_HIGH_PASS); +MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, BAND_PASS, SYNTHIO_BAND_PASS); -MAKE_ENUM_MAP(synthio_filter) { - MAKE_ENUM_MAP_ENTRY(kind, LOW_PASS), - MAKE_ENUM_MAP_ENTRY(kind, HIGH_PASS), - MAKE_ENUM_MAP_ENTRY(kind, BAND_PASS), +MAKE_ENUM_MAP(synthio_filter_mode) { + MAKE_ENUM_MAP_ENTRY(mode, LOW_PASS), + MAKE_ENUM_MAP_ENTRY(mode, HIGH_PASS), + MAKE_ENUM_MAP_ENTRY(mode, BAND_PASS), }; -static MP_DEFINE_CONST_DICT(synthio_filter_locals_dict, synthio_filter_locals_table); +static MP_DEFINE_CONST_DICT(synthio_filter_mode_locals_dict, synthio_filter_mode_locals_table); -MAKE_PRINTER(synthio, synthio_filter); +MAKE_PRINTER(synthio, synthio_filter_mode); -MAKE_ENUM_TYPE(synthio, FilterType, synthio_filter); +MAKE_ENUM_TYPE(synthio, FilterMode, synthio_filter_mode); -static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) { - return cp_enum_value(&synthio_filter_type, obj, arg_name); +static synthio_filter_mode validate_synthio_filter_mode(mp_obj_t obj, qstr arg_name) { + return cp_enum_value(&synthio_filter_mode_type, obj, arg_name); } //| class BlockBiquad: //| def __init__( //| self, -//| kind: FilterType, +//| mode: FilterMode, //| frequency: BlockInput, //| q_factor: BlockInput = 0.7071067811865475, //| ) -> None: @@ -61,13 +61,13 @@ static synthio_filter_e validate_synthio_filter(mp_obj_t obj, qstr arg_name) { //| appears to work as you'd expect.""" static const mp_arg_t block_biquad_properties[] = { - { MP_QSTR_kind, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } }, + { MP_QSTR_mode, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } }, { MP_QSTR_frequency, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL } }, { MP_QSTR_Q, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL } }, }; static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_kind, ARG_frequency, ARG_Q }; + enum { ARG_mode, ARG_frequency, ARG_Q }; mp_arg_val_t args[MP_ARRAY_SIZE(block_biquad_properties)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(block_biquad_properties), block_biquad_properties, args); @@ -76,21 +76,21 @@ static mp_obj_t synthio_block_biquad_make_new(const mp_obj_type_t *type_in, size args[ARG_Q].u_obj = mp_obj_new_float(MICROPY_FLOAT_CONST(0.7071067811865475)); } - synthio_filter_e kind = validate_synthio_filter(args[ARG_kind].u_obj, MP_QSTR_kind); - return common_hal_synthio_block_biquad_new(kind, args[ARG_frequency].u_obj, args[ARG_Q].u_obj); + synthio_filter_mode mode = validate_synthio_filter_mode(args[ARG_mode].u_obj, MP_QSTR_mode); + return common_hal_synthio_block_biquad_new(mode, args[ARG_frequency].u_obj, args[ARG_Q].u_obj); } //| -//| kind: FilterType -//| """The kind of filter (read-only)""" -static mp_obj_t synthio_block_biquad_get_kind(mp_obj_t self_in) { +//| mode: FilterMode +//| """The mode of filter (read-only)""" +static mp_obj_t synthio_block_biquad_get_mode(mp_obj_t self_in) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); - return cp_enum_find(&synthio_filter_type, common_hal_synthio_block_biquad_get_kind(self)); + return cp_enum_find(&synthio_filter_mode_type, common_hal_synthio_block_biquad_get_mode(self)); } -MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_kind_obj, synthio_block_biquad_get_kind); +MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_mode_obj, synthio_block_biquad_get_mode); -MP_PROPERTY_GETTER(synthio_block_biquad_kind_obj, - (mp_obj_t)&synthio_block_biquad_get_kind_obj); +MP_PROPERTY_GETTER(synthio_block_biquad_mode_obj, + (mp_obj_t)&synthio_block_biquad_get_mode_obj); //| //| frequency: BlockInput @@ -133,7 +133,7 @@ MP_PROPERTY_GETSET(synthio_block_biquad_q_factor_obj, (mp_obj_t)&synthio_block_biquad_set_q_factor_obj); static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_kind), MP_ROM_PTR(&synthio_block_biquad_kind_obj) }, + { MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&synthio_block_biquad_mode_obj) }, { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&synthio_block_biquad_frequency_obj) }, { MP_ROM_QSTR(MP_QSTR_q_factor), MP_ROM_PTR(&synthio_block_biquad_q_factor_obj) }, }; diff --git a/shared-bindings/synthio/BlockBiquad.h b/shared-bindings/synthio/BlockBiquad.h index 133edb3be564..30a1ced54a2b 100644 --- a/shared-bindings/synthio/BlockBiquad.h +++ b/shared-bindings/synthio/BlockBiquad.h @@ -9,12 +9,12 @@ #include "py/obj.h" extern const mp_obj_type_t synthio_block_biquad_type_obj; -extern const mp_obj_type_t synthio_filter_type; +extern const mp_obj_type_t synthio_filter_mode_type; typedef struct synthio_block_biquad synthio_block_biquad_t; typedef enum { SYNTHIO_LOW_PASS, SYNTHIO_HIGH_PASS, SYNTHIO_BAND_PASS -} synthio_filter_e; +} synthio_filter_mode; mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self); @@ -23,6 +23,6 @@ void common_hal_synthio_block_biquad_set_q_factor(synthio_block_biquad_t *self, mp_obj_t common_hal_synthio_block_biquad_get_frequency(synthio_block_biquad_t *self); void common_hal_synthio_block_biquad_set_frequency(synthio_block_biquad_t *self, mp_obj_t frequency); -synthio_filter_e common_hal_synthio_block_biquad_get_kind(synthio_block_biquad_t *self); +synthio_filter_mode common_hal_synthio_block_biquad_get_mode(synthio_block_biquad_t *self); -mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t frequency, mp_obj_t Q); +mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_mode mode, mp_obj_t frequency, mp_obj_t Q); diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index fc490ff542f7..207d7afafa89 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -309,7 +309,7 @@ static const mp_rom_map_elem_t synthio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_synthio) }, { MP_ROM_QSTR(MP_QSTR_Biquad), MP_ROM_PTR(&synthio_biquad_type_obj) }, { MP_ROM_QSTR(MP_QSTR_BlockBiquad), MP_ROM_PTR(&synthio_block_biquad_type_obj) }, - { MP_ROM_QSTR(MP_QSTR_FilterType), MP_ROM_PTR(&synthio_filter_type) }, + { MP_ROM_QSTR(MP_QSTR_FilterMode), MP_ROM_PTR(&synthio_filter_mode_type) }, { MP_ROM_QSTR(MP_QSTR_Math), MP_ROM_PTR(&synthio_math_type) }, { MP_ROM_QSTR(MP_QSTR_MathOperation), MP_ROM_PTR(&synthio_math_operation_type) }, { MP_ROM_QSTR(MP_QSTR_MidiTrack), MP_ROM_PTR(&synthio_miditrack_type) }, diff --git a/shared-module/synthio/BlockBiquad.c b/shared-module/synthio/BlockBiquad.c index 6209be0bad5e..202ceb982c63 100644 --- a/shared-module/synthio/BlockBiquad.c +++ b/shared-module/synthio/BlockBiquad.c @@ -30,16 +30,16 @@ static void fast_sincos(mp_float_t theta, sincos_result_t *result) { result->s = evens - odds; } -mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_e kind, mp_obj_t f0, mp_obj_t Q) { +mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_mode mode, mp_obj_t f0, mp_obj_t Q) { synthio_block_biquad_t *self = mp_obj_malloc(synthio_block_biquad_t, &synthio_block_biquad_type_obj); - self->kind = kind; + self->mode = mode; synthio_block_assign_slot(f0, &self->f0, MP_QSTR_frequency); synthio_block_assign_slot(Q, &self->Q, MP_QSTR_q_factor); return MP_OBJ_FROM_PTR(self); } -synthio_filter_e common_hal_synthio_block_biquad_get_kind(synthio_block_biquad_t *self) { - return self->kind; +synthio_filter_mode common_hal_synthio_block_biquad_get_mode(synthio_block_biquad_t *self) { + return self->mode; } mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self) { @@ -79,7 +79,7 @@ void common_hal_synthio_block_biquad_tick(mp_obj_t self_in, biquad_filter_state a1 = -2 * sc.c; a2 = 1 - alpha; - switch (self->kind) { + switch (self->mode) { default: case SYNTHIO_LOW_PASS: b2 = b0 = (1 - sc.c) * .5; diff --git a/shared-module/synthio/BlockBiquad.h b/shared-module/synthio/BlockBiquad.h index 17fd5b7f816c..1eea1a7b53ba 100644 --- a/shared-module/synthio/BlockBiquad.h +++ b/shared-module/synthio/BlockBiquad.h @@ -13,7 +13,7 @@ typedef struct synthio_block_biquad { mp_obj_base_t base; - synthio_filter_e kind; + synthio_filter_mode mode; synthio_block_slot_t f0, Q; } synthio_block_biquad_t; diff --git a/tests/circuitpython-manual/synthio/note/blockfilter.py b/tests/circuitpython-manual/synthio/note/blockfilter.py index 70f8a5006384..7efbb626c671 100644 --- a/tests/circuitpython-manual/synthio/note/blockfilter.py +++ b/tests/circuitpython-manual/synthio/note/blockfilter.py @@ -36,9 +36,9 @@ def synthesize(synth): for biquad in ( None, - synthio.BlockBiquad(synthio.FilterType.LOW_PASS, freq_sweep), - synthio.BlockBiquad(synthio.FilterType.HIGH_PASS, freq_sweep), - synthio.BlockBiquad(synthio.FilterType.BAND_PASS, freq_sweep, Q=8), + synthio.BlockBiquad(synthio.FilterMode.LOW_PASS, freq_sweep), + synthio.BlockBiquad(synthio.FilterMode.HIGH_PASS, freq_sweep), + synthio.BlockBiquad(synthio.FilterMode.BAND_PASS, freq_sweep, Q=8), ): n = synthio.Note( frequency=synthio.midi_to_hz(72), From 21ebcad778088e1f66876d9cb0aee2fa62f09033 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 24 Oct 2024 21:02:40 -0500 Subject: [PATCH 164/252] Add notch filter to BlockBiquad --- shared-bindings/synthio/BlockBiquad.c | 2 ++ shared-bindings/synthio/BlockBiquad.h | 2 +- shared-module/synthio/BlockBiquad.c | 6 ++++++ tests/circuitpython-manual/synthio/note/blockfilter.py | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/shared-bindings/synthio/BlockBiquad.c b/shared-bindings/synthio/BlockBiquad.c index 0d38eb3026ae..510d52872499 100644 --- a/shared-bindings/synthio/BlockBiquad.c +++ b/shared-bindings/synthio/BlockBiquad.c @@ -24,11 +24,13 @@ MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, LOW_PASS, SYNTHIO_LOW_PASS); MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, HIGH_PASS, SYNTHIO_HIGH_PASS); MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, BAND_PASS, SYNTHIO_BAND_PASS); +MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, NOTCH, SYNTHIO_NOTCH); MAKE_ENUM_MAP(synthio_filter_mode) { MAKE_ENUM_MAP_ENTRY(mode, LOW_PASS), MAKE_ENUM_MAP_ENTRY(mode, HIGH_PASS), MAKE_ENUM_MAP_ENTRY(mode, BAND_PASS), + MAKE_ENUM_MAP_ENTRY(mode, NOTCH), }; static MP_DEFINE_CONST_DICT(synthio_filter_mode_locals_dict, synthio_filter_mode_locals_table); diff --git a/shared-bindings/synthio/BlockBiquad.h b/shared-bindings/synthio/BlockBiquad.h index 30a1ced54a2b..ca32ef6363b5 100644 --- a/shared-bindings/synthio/BlockBiquad.h +++ b/shared-bindings/synthio/BlockBiquad.h @@ -13,7 +13,7 @@ extern const mp_obj_type_t synthio_filter_mode_type; typedef struct synthio_block_biquad synthio_block_biquad_t; typedef enum { - SYNTHIO_LOW_PASS, SYNTHIO_HIGH_PASS, SYNTHIO_BAND_PASS + SYNTHIO_LOW_PASS, SYNTHIO_HIGH_PASS, SYNTHIO_BAND_PASS, SYNTHIO_NOTCH } synthio_filter_mode; diff --git a/shared-module/synthio/BlockBiquad.c b/shared-module/synthio/BlockBiquad.c index 202ceb982c63..3f9918467aa4 100644 --- a/shared-module/synthio/BlockBiquad.c +++ b/shared-module/synthio/BlockBiquad.c @@ -95,6 +95,12 @@ void common_hal_synthio_block_biquad_tick(mp_obj_t self_in, biquad_filter_state b0 = alpha; b1 = 0; b2 = -b0; + break; + + case SYNTHIO_NOTCH: + b0 = 1; + b1 = -2 * sc.c; + b2 = 1; } mp_float_t recip_a0 = 1 / a0; diff --git a/tests/circuitpython-manual/synthio/note/blockfilter.py b/tests/circuitpython-manual/synthio/note/blockfilter.py index 7efbb626c671..e1638a995924 100644 --- a/tests/circuitpython-manual/synthio/note/blockfilter.py +++ b/tests/circuitpython-manual/synthio/note/blockfilter.py @@ -39,6 +39,7 @@ def synthesize(synth): synthio.BlockBiquad(synthio.FilterMode.LOW_PASS, freq_sweep), synthio.BlockBiquad(synthio.FilterMode.HIGH_PASS, freq_sweep), synthio.BlockBiquad(synthio.FilterMode.BAND_PASS, freq_sweep, Q=8), + synthio.BlockBiquad(synthio.FilterMode.NOTCH, freq_sweep, Q=8), ): n = synthio.Note( frequency=synthio.midi_to_hz(72), From b9fa0c8b6d570ed8ef904da1c947786fb684ab5e Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 24 Oct 2024 23:58:14 -0400 Subject: [PATCH 165/252] Use volatile pointerwhen invalidating PSRAM cache --- ports/raspberrypi/supervisor/internal_flash.c | 4 +++- ports/raspberrypi/supervisor/port.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/supervisor/internal_flash.c b/ports/raspberrypi/supervisor/internal_flash.c index b667112b5880..1b328cbc5a7b 100644 --- a/ports/raspberrypi/supervisor/internal_flash.c +++ b/ports/raspberrypi/supervisor/internal_flash.c @@ -49,11 +49,13 @@ static uint32_t m1_timing; static void save_psram_settings(void) { #ifdef PICO_RP2350 // We're about to invalidate the XIP cache, clean it first to commit any dirty writes to PSRAM - uint8_t *maintenance_ptr = (uint8_t *)XIP_MAINTENANCE_BASE; + volatile uint8_t *maintenance_ptr = (uint8_t *)XIP_MAINTENANCE_BASE; for (int i = 1; i < 16 * 1024; i += 8) { // Background info: https://forums.raspberrypi.com/viewtopic.php?t=378249 maintenance_ptr[i] = 0; // Clean + __compiler_memory_barrier(); maintenance_ptr[i - 1] = 0; // Explicitly invalidate + __compiler_memory_barrier(); } m1_timing = qmi_hw->m[1].timing; diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index ffa25d12404e..13e5abb61216 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -244,7 +244,7 @@ void port_heap_init(void) { _heap = tlsf_create_with_pool(heap_bottom, size, 64 * 1024 * 1024); _ram_pool = tlsf_get_pool(_heap); if (_psram_size > 0) { - _psram_pool = tlsf_add_pool(_heap, (void *)0x11000004, _psram_size - 4); + _psram_pool = tlsf_add_pool(_heap, (void *)0x11000000, _psram_size); } } From 0a41264fcc99527b07d4a70b17e44b72b9cc96f1 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 25 Oct 2024 13:42:53 -0700 Subject: [PATCH 166/252] Add open-drain to digitalio + Resolve some issues with GPIO4 & setting pullup/pulldown --- ports/analog/Makefile | 1 + .../common-hal/digitalio/DigitalInOut.c | 140 ++++++++++++++---- .../common-hal/digitalio/DigitalInOut.h | 2 + 3 files changed, 112 insertions(+), 31 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 46dfc6a53b39..ebdb62bb2c13 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -209,6 +209,7 @@ CFLAGS += -Wno-error=unused-parameter \ -Wno-error=nested-externs \ -Wno-error=sign-compare \ -Wno-cast-align \ + -Wno-sign-compare \ ENTRY = Reset_Handler LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index 3861900d81cd..0f34b604fd0c 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -28,11 +28,13 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct( common_hal_mcu_pin_claim(pin); self->pin = pin; + self->open_drain = false; + self->vssel = MXC_GPIO_VSSEL_VDDIOH; mxc_gpio_cfg_t new_gpio_cfg = { .port = gpio_ports[self->pin->port], .mask = (self->pin->mask), - .vssel = self->pin->level, + .vssel = self->vssel, .func = MXC_GPIO_FUNC_IN, .drvstr = MXC_GPIO_DRVSTR_0, .pad = MXC_GPIO_PAD_NONE, @@ -55,6 +57,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + int err = E_NO_ERROR; if (self->pin->port == 4) { @@ -76,21 +79,18 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + self->open_drain = (drive_mode == DRIVE_MODE_OPEN_DRAIN); + + // Set GPIO(s) to output mode if (self->pin->port == 4) { - // Set GPIO(s) to output mode MXC_MCR->gpio4_ctrl |= GPIO4_OUTEN_MASK(mask); MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); } else { MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); } + common_hal_digitalio_digitalinout_set_value(self, value); - // todo (low): MSDK Hardware does not support open-drain configuration except - // todo (low): when directly managed by a peripheral such as I2C. - // todo (low): find a way to signal this to any upstream code - if (drive_mode != DRIVE_MODE_PUSH_PULL) { - return DIGITALINOUT_INVALID_DRIVE_MODE; - } return DIGITALINOUT_OK; } @@ -100,6 +100,11 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + // Open drain must be considered output for CircuitPython API to work properly + if (self->open_drain) { + return DIRECTION_OUTPUT; + } + if (self->pin->port < 4) { // Check that I/O mode is enabled and we don't have in AND out on at the same time MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask))); @@ -129,8 +134,30 @@ void common_hal_digitalio_digitalinout_set_value( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - if (dir == DIRECTION_OUTPUT) { - if (value == true) { + MXC_GPIO_SetVSSEL(port, self->vssel, mask); + + if (self->open_drain) { + // Open-drain can be done by setting to input mode, no pullup/pulldown + // when the value is high (no sink current into GPIO) + if (value) { + // set to input, no pull + common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); + } + else { + // can't use common_hal_switch_to_output b/c it calls this function + // set the GPIO to output, low + if (self->pin->port == 4) { + MXC_MCR->gpio4_ctrl |= GPIO4_OUTEN_MASK(mask); + MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); + } else { + MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); + } + MXC_GPIO_OutClr(port, mask); + } + } + + else if (dir == DIRECTION_OUTPUT) { + if (value) { MXC_GPIO_OutSet(port, mask); } else { MXC_GPIO_OutClr(port, mask); @@ -145,6 +172,10 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + if (self->open_drain) { + return MXC_GPIO_InGet(port, mask) && mask; + } + if (dir == DIRECTION_INPUT) { if (self->pin->port == 4) { return (bool)(MXC_MCR->gpio4_ctrl & GPIO4_DATAIN_MASK(mask)); @@ -155,21 +186,29 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s } } -/** FIXME: Implement open-drain by switching to input WITHOUT re-labeling the pin */ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) { - if (drive_mode == DRIVE_MODE_OPEN_DRAIN) { - common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); - } - // On MAX32, drive mode is not configurable - // and should always be push-pull unless managed by a peripheral like I2C + // Check what the current value is + bool value = common_hal_digitalio_digitalinout_get_value(self); + self->open_drain = (drive_mode == DRIVE_MODE_OPEN_DRAIN); + + // Re-set the value to account for different setting methods for drive types + // Switch to output will both set the output config + // AND set the value for the new drive type + common_hal_digitalio_digitalinout_switch_to_output(self, value, drive_mode); + return DIGITALINOUT_OK; } digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( digitalio_digitalinout_obj_t *self) { - return DRIVE_MODE_PUSH_PULL; + if (self->open_drain) { + return DRIVE_MODE_OPEN_DRAIN; + } + else { + return DRIVE_MODE_PUSH_PULL; + } } digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( @@ -178,11 +217,31 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - // padctrl registers only work in input mode + // GPIO4 handling if (self->pin->port == 4) { - MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); + switch(pull) { + case PULL_NONE: + // disable pullup/pulldown + MXC_MCR->gpio4_ctrl |= GPIO4_PULLDIS_MASK(mask); + break; + case PULL_UP: + // enable pullup/pulldown (clear the mask) + // then set output value to 1 + MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); + MXC_MCR->gpio4_ctrl |= GPIO4_DATAOUT_MASK(mask); + break; + case PULL_DOWN: + // enable pullup/pulldown (clear the mask) + // then clear output value to 0 + MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); + MXC_MCR->gpio4_ctrl &= ~(GPIO4_DATAOUT_MASK(mask)); + break; + default: + break; + } return DIGITALINOUT_OK; } else { + // padctrl registers only work in input mode if ((mask & port->en0) & (mask & ~(port->outen))) { // PULL_NONE, PULL_UP, or PULL_DOWN switch (pull) { @@ -193,10 +252,12 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( case PULL_UP: port->padctrl0 |= mask; port->padctrl1 &= ~(mask); + port->ps &= ~(mask); break; case PULL_DOWN: - port->padctrl0 &= ~(mask); + port->padctrl0 &= ~mask; port->padctrl1 |= mask; + port->ps &= ~mask; break; default: break; @@ -208,20 +269,37 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( } } -/** FIXME: Account for GPIO4 handling here */ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( digitalio_digitalinout_obj_t *self) { - bool pin_padctrl0 = (gpio_ports[self->pin->port]->padctrl0) & (self->pin->mask); - bool pin_padctrl1 = (gpio_ports[self->pin->port]->padctrl1) & (self->pin->mask); + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; - if ((pin_padctrl0) && !(pin_padctrl1)) { - return PULL_UP; - } else if (!(pin_padctrl0) && pin_padctrl1) { - return PULL_DOWN; - } else if (!(pin_padctrl0) && !(pin_padctrl1)) { - return PULL_NONE; - } else { - return PULL_NONE; + bool pin_padctrl0 = (port->padctrl0) & (mask); + bool pin_padctrl1 = (port->padctrl1) & (mask); + + if (self->pin->port == 4) { + if (MXC_MCR->gpio4_ctrl & GPIO4_PULLDIS_MASK(mask)) { + return PULL_NONE; + } + else { + if (MXC_MCR->gpio4_ctrl & GPIO4_DATAOUT_MASK(mask)) { + return PULL_UP; + } + else { + return PULL_DOWN; + } + } + } + else { + if ((pin_padctrl0) && !(pin_padctrl1)) { + return PULL_UP; + } else if (!(pin_padctrl0) && pin_padctrl1) { + return PULL_DOWN; + } else if (!(pin_padctrl0) && !(pin_padctrl1)) { + return PULL_NONE; + } else { + return PULL_NONE; + } } } diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.h b/ports/analog/common-hal/digitalio/DigitalInOut.h index f58b23832b19..d10345fa3fa8 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.h +++ b/ports/analog/common-hal/digitalio/DigitalInOut.h @@ -12,4 +12,6 @@ typedef struct { mp_obj_base_t base; const mcu_pin_obj_t *pin; + bool open_drain; + mxc_gpio_vssel_t vssel; } digitalio_digitalinout_obj_t; From eced88c0c42d45fe3f1e683ec6dd7a27b2a4ac7e Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 25 Oct 2024 13:47:15 -0700 Subject: [PATCH 167/252] Pre-commit formatting fix --- .../analog/common-hal/digitalio/DigitalInOut.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index 0f34b604fd0c..f3e3fe552dc0 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -142,8 +142,7 @@ void common_hal_digitalio_digitalinout_set_value( if (value) { // set to input, no pull common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); - } - else { + } else { // can't use common_hal_switch_to_output b/c it calls this function // set the GPIO to output, low if (self->pin->port == 4) { @@ -154,9 +153,7 @@ void common_hal_digitalio_digitalinout_set_value( } MXC_GPIO_OutClr(port, mask); } - } - - else if (dir == DIRECTION_OUTPUT) { + } else if (dir == DIRECTION_OUTPUT) { if (value) { MXC_GPIO_OutSet(port, mask); } else { @@ -219,7 +216,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( // GPIO4 handling if (self->pin->port == 4) { - switch(pull) { + switch (pull) { case PULL_NONE: // disable pullup/pulldown MXC_MCR->gpio4_ctrl |= GPIO4_PULLDIS_MASK(mask); @@ -281,17 +278,14 @@ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( if (self->pin->port == 4) { if (MXC_MCR->gpio4_ctrl & GPIO4_PULLDIS_MASK(mask)) { return PULL_NONE; - } - else { + } else { if (MXC_MCR->gpio4_ctrl & GPIO4_DATAOUT_MASK(mask)) { return PULL_UP; - } - else { + } else { return PULL_DOWN; } } - } - else { + } else { if ((pin_padctrl0) && !(pin_padctrl1)) { return PULL_UP; } else if (!(pin_padctrl0) && pin_padctrl1) { From 6d88785b18914ce76a3a59c2b6d500393174a467 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 25 Oct 2024 13:52:21 -0700 Subject: [PATCH 168/252] Pre-commit formatting fix --- ports/analog/common-hal/digitalio/DigitalInOut.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index f3e3fe552dc0..7d4048d77e70 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -202,8 +202,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( digitalio_digitalinout_obj_t *self) { if (self->open_drain) { return DRIVE_MODE_OPEN_DRAIN; - } - else { + } else { return DRIVE_MODE_PUSH_PULL; } } From 8fe0aed36b1661a74a5d284328ccf767ee0b3478 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 27 Oct 2024 13:28:20 +0100 Subject: [PATCH 169/252] Enabling gifio on Meowbits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on suggestion by deʃhipu to help katylase on #help-with-circuitpython --- ports/stm/boards/meowbit_v121/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm/boards/meowbit_v121/mpconfigboard.mk b/ports/stm/boards/meowbit_v121/mpconfigboard.mk index 1dfda9a1759a..6b46c6402360 100644 --- a/ports/stm/boards/meowbit_v121/mpconfigboard.mk +++ b/ports/stm/boards/meowbit_v121/mpconfigboard.mk @@ -26,7 +26,7 @@ CIRCUITPY_AESIO = 0 CIRCUITPY_BITMAPFILTER = 0 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BLEIO_HCI = 0 -CIRCUITPY_GIFIO = 0 +CIRCUITPY_GIFIO = 1 CIRCUITPY_ULAB = 0 CIRCUITPY_STAGE = 1 CIRCUITPY_ZLIB = 0 From c2115030a667d3baded726c686b1ad19d8913b8f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 27 Oct 2024 09:57:33 -0400 Subject: [PATCH 170/252] turn off epaperdisplay and sharpdisplay to make room for gifio --- ports/stm/boards/meowbit_v121/mpconfigboard.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ports/stm/boards/meowbit_v121/mpconfigboard.mk b/ports/stm/boards/meowbit_v121/mpconfigboard.mk index 6b46c6402360..435bbd7682f0 100644 --- a/ports/stm/boards/meowbit_v121/mpconfigboard.mk +++ b/ports/stm/boards/meowbit_v121/mpconfigboard.mk @@ -26,9 +26,11 @@ CIRCUITPY_AESIO = 0 CIRCUITPY_BITMAPFILTER = 0 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BLEIO_HCI = 0 -CIRCUITPY_GIFIO = 1 +CURCUITPY_EPAPERDISPLAY = 0 +CIRCUITPY_SHARPDISPLAY = 0 CIRCUITPY_ULAB = 0 -CIRCUITPY_STAGE = 1 CIRCUITPY_ZLIB = 0 +CIRCUITPY_STAGE = 1 + FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/meowbit From ef28529984da62d8c3548a37f8d45164ee8b547a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 27 Oct 2024 10:12:23 -0400 Subject: [PATCH 171/252] more meowbit disabling and fix typo --- ports/stm/boards/meowbit_v121/mpconfigboard.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/stm/boards/meowbit_v121/mpconfigboard.mk b/ports/stm/boards/meowbit_v121/mpconfigboard.mk index 435bbd7682f0..52c191b5b2ef 100644 --- a/ports/stm/boards/meowbit_v121/mpconfigboard.mk +++ b/ports/stm/boards/meowbit_v121/mpconfigboard.mk @@ -26,7 +26,8 @@ CIRCUITPY_AESIO = 0 CIRCUITPY_BITMAPFILTER = 0 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BLEIO_HCI = 0 -CURCUITPY_EPAPERDISPLAY = 0 +CIRCUITPY_EPAPERDISPLAY = 0 +CIRCUITPY_KEYPAD_DEMUX = 0 CIRCUITPY_SHARPDISPLAY = 0 CIRCUITPY_ULAB = 0 CIRCUITPY_ZLIB = 0 From 589c7f6a3497eb9e432c2b96c08d9e2b0bdf2d09 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 28 Oct 2024 08:04:01 -0500 Subject: [PATCH 172/252] unix: enable vectorio in coverage build --- ports/unix/displayio_min.c | 13 +++++++++++++ ports/unix/variants/coverage/mpconfigvariant.mk | 12 ++++++++++++ shared-bindings/vectorio/Circle.c | 4 ++-- shared-bindings/vectorio/Polygon.c | 2 +- shared-bindings/vectorio/Rectangle.c | 6 +++--- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/ports/unix/displayio_min.c b/ports/unix/displayio_min.c index 3d0d5efc3ce6..06b57d04df23 100644 --- a/ports/unix/displayio_min.c +++ b/ports/unix/displayio_min.c @@ -74,3 +74,16 @@ const mp_obj_module_t displayio_module = { }; MP_REGISTER_MODULE(MP_QSTR_displayio, displayio_module); + +displayio_buffer_transform_t null_transform = { + .x = 0, + .y = 0, + .dx = 1, + .dy = 1, + .scale = 1, + .width = 0, + .height = 0, + .mirror_x = false, + .mirror_y = false, + .transpose_xy = false +}; diff --git a/ports/unix/variants/coverage/mpconfigvariant.mk b/ports/unix/variants/coverage/mpconfigvariant.mk index 9721c2803e25..e250fbe9b2da 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.mk +++ b/ports/unix/variants/coverage/mpconfigvariant.mk @@ -59,6 +59,11 @@ SRC_BITMAP := \ shared-bindings/synthio/Synthesizer.c \ shared-bindings/traceback/__init__.c \ shared-bindings/util.c \ + shared-bindings/vectorio/Circle.c \ + shared-bindings/vectorio/__init__.c \ + shared-bindings/vectorio/Polygon.c \ + shared-bindings/vectorio/Rectangle.c \ + shared-bindings/vectorio/VectorShape.c \ shared-bindings/zlib/__init__.c \ shared-module/aesio/aes.c \ shared-module/aesio/__init__.c \ @@ -88,6 +93,12 @@ SRC_BITMAP := \ shared-module/synthio/Note.c \ shared-module/synthio/Biquad.c \ shared-module/synthio/Synthesizer.c \ + shared-bindings/vectorio/Circle.c \ + shared-module/vectorio/Circle.c \ + shared-module/vectorio/__init__.c \ + shared-module/vectorio/Polygon.c \ + shared-module/vectorio/Rectangle.c \ + shared-module/vectorio/VectorShape.c \ shared-module/traceback/__init__.c \ shared-module/zlib/__init__.c \ @@ -134,6 +145,7 @@ CFLAGS += \ -DCIRCUITPY_SYNTHIO=1 \ -DCIRCUITPY_SYNTHIO_MAX_CHANNELS=14 \ -DCIRCUITPY_TRACEBACK=1 \ + -DCIRCUITPY_VECTORIO=1 \ -DCIRCUITPY_ZLIB=1 # CIRCUITPY-CHANGE: test native base classes. diff --git a/shared-bindings/vectorio/Circle.c b/shared-bindings/vectorio/Circle.c index d2f31d6b86d8..2b7337439a6f 100644 --- a/shared-bindings/vectorio/Circle.c +++ b/shared-bindings/vectorio/Circle.c @@ -34,8 +34,8 @@ static mp_obj_t vectorio_circle_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pixel_shader, ARG_radius, ARG_x, ARG_y, ARG_color_index }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, - { MP_QSTR_radius, MP_ARG_REQUIRED | MP_ARG_INT }, + { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, { .u_obj = NULL } }, + { MP_QSTR_radius, MP_ARG_REQUIRED | MP_ARG_INT, { .u_obj = NULL } }, { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_color_index, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, diff --git a/shared-bindings/vectorio/Polygon.c b/shared-bindings/vectorio/Polygon.c index 05228465f6c1..cb76ccbb143a 100644 --- a/shared-bindings/vectorio/Polygon.c +++ b/shared-bindings/vectorio/Polygon.c @@ -42,7 +42,7 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pixel_shader, ARG_points_list, ARG_x, ARG_y, ARG_color_index }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, + { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, { .u_obj = NULL } }, { MP_QSTR_points, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, diff --git a/shared-bindings/vectorio/Rectangle.c b/shared-bindings/vectorio/Rectangle.c index 8949df7dd1e6..64210599753b 100644 --- a/shared-bindings/vectorio/Rectangle.c +++ b/shared-bindings/vectorio/Rectangle.c @@ -35,9 +35,9 @@ static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pixel_shader, ARG_width, ARG_height, ARG_x, ARG_y, ARG_color_index }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, - { MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT }, - { MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_INT }, + { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, {.u_obj = NULL } }, + { MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0 } }, + { MP_QSTR_height, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0 } }, { MP_QSTR_x, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_color_index, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, From 6badb92de8b8d5cef96ca8dee8aa0f7b3bdc1847 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 29 Oct 2024 12:52:27 -0500 Subject: [PATCH 173/252] Add support for list of Biquad objects within `audiofilters.Filter`. --- shared-bindings/audiofilters/Filter.c | 48 +++++++++++---------- shared-bindings/audiofilters/Filter.h | 6 +-- shared-module/audiofilters/Filter.c | 61 ++++++++++++++++++++------- shared-module/audiofilters/Filter.h | 7 ++- 4 files changed, 80 insertions(+), 42 deletions(-) diff --git a/shared-bindings/audiofilters/Filter.c b/shared-bindings/audiofilters/Filter.c index 457897909e0d..53c36b2d64d5 100644 --- a/shared-bindings/audiofilters/Filter.c +++ b/shared-bindings/audiofilters/Filter.c @@ -23,7 +23,7 @@ //| //| def __init__( //| self, -//| filter: Optional[synthio.Biquad] = None, +//| filters: Optional[List[synthio.Biquad]] = None, //| mix: synthio.BlockInput = 1.0, //| buffer_size: int = 512, //| sample_rate: int = 8000, @@ -38,7 +38,7 @@ //| The mix parameter allows you to change how much of the unchanged sample passes through to //| the output to how much of the effect audio you hear as the output. //| -//| :param Optional[synthio.Biquad] filter: The normalized biquad filter object used to process the signal. +//| :param Optional[List[synthio.Biquad]] filters: A list of normalized biquad filter objects used to process the signal. //| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). //| :param int buffer_size: The total size in bytes of each of the two playback buffers to use //| :param int sample_rate: The sample rate to be used @@ -56,9 +56,10 @@ //| //| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22) //| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100) -//| filter = audiofilters.Filter(filter=synth.low_pass_filter(frequency=2000, Q=1.25), buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0) -//| filter.play(synth) -//| audio.play(filter) +//| effect = audiofilters.Filter(buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0) +//| effect.filters.append(synth.low_pass_filter(frequency=2000, Q=1.25)) +//| effect.play(synth) +//| audio.play(effect) //| //| note = synthio.Note(261) //| while True: @@ -68,9 +69,9 @@ //| time.sleep(5)""" //| ... static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_filter, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; + enum { ARG_filters, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_filters, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 512} }, { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, @@ -90,7 +91,7 @@ static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n } audiofilters_filter_obj_t *self = mp_obj_malloc(audiofilters_filter_obj_t, &audiofilters_filter_type); - common_hal_audiofilters_filter_construct(self, args[ARG_filter].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + common_hal_audiofilters_filter_construct(self, args[ARG_filters].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); return MP_OBJ_FROM_PTR(self); } @@ -128,31 +129,34 @@ static mp_obj_t audiofilters_filter_obj___exit__(size_t n_args, const mp_obj_t * static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiofilters_filter___exit___obj, 4, 4, audiofilters_filter_obj___exit__); -//| filter: Optional[synthio.Biquad] -//| """The normalized biquad filter object used to process the signal.""" -static mp_obj_t audiofilters_filter_obj_get_filter(mp_obj_t self_in) { - return common_hal_audiofilters_filter_get_filter(self_in); +//| filters: List[synthio.Biquad] +//| """A list of normalized biquad filter objects used to process the signal.""" +//| +static mp_obj_t audiofilters_filter_obj_get_filters(mp_obj_t self_in) { + audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return common_hal_audiofilters_filter_get_filters(self); } -MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_filter_obj, audiofilters_filter_obj_get_filter); +MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_filters_obj, audiofilters_filter_obj_get_filters); -static mp_obj_t audiofilters_filter_obj_set_filter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_filter }; +static mp_obj_t audiofilters_filter_obj_set_filters(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_filters }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + { MP_QSTR_filters, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, }; audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - common_hal_audiofilters_filter_set_filter(self, args[ARG_filter].u_obj); + common_hal_audiofilters_filter_set_filters(self, args[ARG_filters].u_obj); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_set_filter_obj, 1, audiofilters_filter_obj_set_filter); +MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_set_filters_obj, 1, audiofilters_filter_obj_set_filters); -MP_PROPERTY_GETSET(audiofilters_filter_filter_obj, - (mp_obj_t)&audiofilters_filter_get_filter_obj, - (mp_obj_t)&audiofilters_filter_set_filter_obj); +MP_PROPERTY_GETSET(audiofilters_filter_filters_obj, + (mp_obj_t)&audiofilters_filter_get_filters_obj, + (mp_obj_t)&audiofilters_filter_set_filters_obj); //| mix: synthio.BlockInput @@ -241,7 +245,7 @@ static const mp_rom_map_elem_t audiofilters_filter_locals_dict_table[] = { // Properties { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiofilters_filter_playing_obj) }, - { MP_ROM_QSTR(MP_QSTR_filter), MP_ROM_PTR(&audiofilters_filter_filter_obj) }, + { MP_ROM_QSTR(MP_QSTR_filters), MP_ROM_PTR(&audiofilters_filter_filters_obj) }, { MP_ROM_QSTR(MP_QSTR_mix), MP_ROM_PTR(&audiofilters_filter_mix_obj) }, }; static MP_DEFINE_CONST_DICT(audiofilters_filter_locals_dict, audiofilters_filter_locals_dict_table); diff --git a/shared-bindings/audiofilters/Filter.h b/shared-bindings/audiofilters/Filter.h index 739b625ee6c5..3cbca2c9ee28 100644 --- a/shared-bindings/audiofilters/Filter.h +++ b/shared-bindings/audiofilters/Filter.h @@ -11,7 +11,7 @@ extern const mp_obj_type_t audiofilters_filter_type; void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, - mp_obj_t filter, mp_obj_t mix, + mp_obj_t filters, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate); @@ -22,8 +22,8 @@ uint32_t common_hal_audiofilters_filter_get_sample_rate(audiofilters_filter_obj_ uint8_t common_hal_audiofilters_filter_get_channel_count(audiofilters_filter_obj_t *self); uint8_t common_hal_audiofilters_filter_get_bits_per_sample(audiofilters_filter_obj_t *self); -mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self); -void common_hal_audiofilters_filter_set_filter(audiofilters_filter_obj_t *self, mp_obj_t arg); +mp_obj_t common_hal_audiofilters_filter_get_filters(audiofilters_filter_obj_t *self); +void common_hal_audiofilters_filter_set_filters(audiofilters_filter_obj_t *self, mp_obj_t arg); mp_obj_t common_hal_audiofilters_filter_get_mix(audiofilters_filter_obj_t *self); void common_hal_audiofilters_filter_set_mix(audiofilters_filter_obj_t *self, mp_obj_t arg); diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index 86edb6cb0418..ed53f7fce834 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -9,7 +9,7 @@ #include "py/runtime.h" void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, - mp_obj_t filter, mp_obj_t mix, + mp_obj_t filters, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { @@ -60,12 +60,12 @@ void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, // The below section sets up the effect's starting values. - if (filter == MP_OBJ_NULL) { - filter = mp_const_none; + if (filters == MP_OBJ_NULL) { + filters = mp_obj_new_list(0, NULL); } - synthio_biquad_filter_assign(&self->filter_state, filter); - self->filter_obj = filter; - + self->filters = filters; + reset_filter_states(self); + // If we did not receive a BlockInput we need to create a default float value if (mix == MP_OBJ_NULL) { mix = mp_obj_new_float(1.0); @@ -87,15 +87,37 @@ void common_hal_audiofilters_filter_deinit(audiofilters_filter_obj_t *self) { self->buffer[0] = NULL; self->buffer[1] = NULL; self->filter_buffer = NULL; + self->filter_states = NULL; +} + +void reset_filter_states(audiofilters_filter_obj_t *self) { + self->filter_states_len = self->filters->len; + self->filter_states = NULL; + + if (self->filter_states_len) { + self->filter_states = m_malloc(self->filter_states_len * sizeof(biquad_filter_state)); + if (self->filter_states == NULL) { + common_hal_audiofilters_filter_deinit(self); + m_malloc_fail(self->filter_states_len * sizeof(biquad_filter_state)); + } + + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(self->filters, &iter_buf); + mp_obj_t item; + uint8_t i = 0; + while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + synthio_biquad_filter_assign(&self->filter_states[i++], item); + } + } } -mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self) { - return self->filter_obj; +mp_obj_t common_hal_audiofilters_filter_get_filters(audiofilters_filter_obj_t *self) { + return self->filters; } -void common_hal_audiofilters_filter_set_filter(audiofilters_filter_obj_t *self, mp_obj_t arg) { - synthio_biquad_filter_assign(&self->filter_state, arg); - self->filter_obj = arg; +void common_hal_audiofilters_filter_set_filters(audiofilters_filter_obj_t *self, mp_obj_t arg) { + self->filters = arg; + reset_filter_states(self); } mp_obj_t common_hal_audiofilters_filter_get_mix(audiofilters_filter_obj_t *self) { @@ -126,7 +148,9 @@ void audiofilters_filter_reset_buffer(audiofilters_filter_obj_t *self, memset(self->buffer[1], 0, self->buffer_len); memset(self->filter_buffer, 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); - synthio_biquad_filter_reset(&self->filter_state); + for (uint8_t i = 0; i < self->filter_states_len; i++) { + synthio_biquad_filter_reset(&self->filter_states[i]); + } } bool common_hal_audiofilters_filter_get_playing(audiofilters_filter_obj_t *self) { @@ -209,6 +233,11 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o channel = 0; } + // Update filter_states if filters list has been appended or removed + if (self->filters->len != self->filter_states_len) { + reset_filter_states(self); + } + // get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required mp_float_t mix = MIN(1.0, MAX(synthio_block_slot_get(&self->mix), 0.0)); @@ -248,7 +277,7 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; // for 16-bit samples int8_t *sample_hsrc = (int8_t *)self->sample_remaining_buffer; // for 8-bit samples - if (mix <= 0.01 || self->filter_obj == mp_const_none) { // if mix is zero pure sample only or no biquad filter object is provided + if (mix <= 0.01 || !self->filter_states_len) { // if mix is zero pure sample only or no biquad filter objects are provided for (uint32_t i = 0; i < n; i++) { if (MP_LIKELY(self->bits_per_sample == 16)) { word_buffer[i] = sample_src[i]; @@ -275,8 +304,10 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o } } - // Process biquad filter - synthio_biquad_filter_samples(&self->filter_state, self->filter_buffer, n_samples); + // Process biquad filters + for (uint8_t j = 0; j < self->filter_states_len; j++) { + synthio_biquad_filter_samples(&self->filter_states[j], self->filter_buffer, n_samples); + } // Mix processed signal with original sample and transfer to output buffer for (uint32_t j = 0; j < n_samples; j++) { diff --git a/shared-module/audiofilters/Filter.h b/shared-module/audiofilters/Filter.h index b5d743a6c191..7d1ee4db1a39 100644 --- a/shared-module/audiofilters/Filter.h +++ b/shared-module/audiofilters/Filter.h @@ -15,10 +15,11 @@ extern const mp_obj_type_t audiofilters_filter_type; typedef struct { mp_obj_base_t base; - mp_obj_t filter_obj; + mp_obj_list_t *filters; synthio_block_slot_t mix; - biquad_filter_state filter_state; + uint8_t filter_states_len; + biquad_filter_state *filter_states; uint8_t bits_per_sample; bool samples_signed; @@ -40,6 +41,8 @@ typedef struct { mp_obj_t sample; } audiofilters_filter_obj_t; +void reset_filter_states(audiofilters_filter_obj_t *self); + void audiofilters_filter_reset_buffer(audiofilters_filter_obj_t *self, bool single_channel_output, uint8_t channel); From 169595eb4a70e911cd360aa23cd728afe6380ceb Mon Sep 17 00:00:00 2001 From: eightycc Date: Thu, 31 Oct 2024 08:45:54 -0700 Subject: [PATCH 174/252] Bump cyw43-driver module to v1.0.4 plus to match SDK 2.0.0. --- ports/raspberrypi/lib/cyw43-driver | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/lib/cyw43-driver b/ports/raspberrypi/lib/cyw43-driver index 9f6405f0b326..faf36381bad1 160000 --- a/ports/raspberrypi/lib/cyw43-driver +++ b/ports/raspberrypi/lib/cyw43-driver @@ -1 +1 @@ -Subproject commit 9f6405f0b3260968306d782e1c5ac275a46dc65d +Subproject commit faf36381bad1f668a30172b6336c9a970966ef4c From 0d91f1e08540be80ab4c5c2f35f62ce4c6a8475d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 1 Nov 2024 11:30:24 -0500 Subject: [PATCH 175/252] Add global GCC version check We can set some of them lower than 13 if necessary on a per-port basis. At least esp32 and arm ports all use 13 from what I could see. --- py/circuitpy_mpconfig.h | 16 ++++++++++++++++ py/circuitpy_mpconfig.mk | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index adb881ebac23..eacfbfbeb77c 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -599,3 +599,19 @@ void background_callback_run_all(void); // Enable compiler functionality. #define MICROPY_ENABLE_COMPILER (1) #define MICROPY_PY_BUILTINS_COMPILE (1) + +#ifndef CIRCUITPY_MIN_GCC_VERSION +#define CIRCUITPY_MIN_GCC_VERSION 13 +#endif + +#if defined(__GNUC__) +#if __GNUC__ < CIRCUITPY_MIN_GCC_VERSION +// (the 3 level scheme here is required to get expansion & stringization +// correct) +#define DO_PRAGMA(x) _Pragma(#x) +#define DO_ERROR_HELPER(x) DO_PRAGMA(GCC error #x) +#define DO_ERROR(x) DO_ERROR_HELPER(Minimum GCC version x \ + -- older versions are known to miscompile CircuitPython) +DO_ERROR(CIRCUITPY_MIN_GCC_VERSION); +#endif +#endif diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index e42555291192..1a831dbf314b 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -697,6 +697,10 @@ CFLAGS += -DCIRCUITPY_TUSB_ATTR_USBRAM=$(CIRCUITPY_TUSB_ATTR_USBRAM) CIRCUITPY_SWO_TRACE ?= 0 CFLAGS += -DCIRCUITPY_SWO_TRACE=$(CIRCUITPY_SWO_TRACE) +# Check for a minimum GCC version during build (set to 0 to disable) +CIRCUITPY_MIN_GCC_VERSION ?= 13 +CFLAGS += -DCIRCUITPY_MIN_GCC_VERSION=$(CIRCUITPY_MIN_GCC_VERSION) + # Define an equivalent for MICROPY_LONGINT_IMPL, to pass to $(MPY-TOOL) in py/mkrules.mk # $(MPY-TOOL) needs to know what kind of longint to use (if any) to freeze long integers. # This should correspond to the MICROPY_LONGINT_IMPL definition in mpconfigport.h. From 3a5c4e3a7473522b22a55b0c55b66e0ab40e0fcc Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 1 Nov 2024 14:22:20 -0500 Subject: [PATCH 176/252] these ports currently use older gcc versions --- ports/broadcom/Makefile | 2 ++ ports/litex/mpconfigport.mk | 1 + 2 files changed, 3 insertions(+) diff --git a/ports/broadcom/Makefile b/ports/broadcom/Makefile index 56c8c3237443..1c640fb2f7b9 100644 --- a/ports/broadcom/Makefile +++ b/ports/broadcom/Makefile @@ -10,10 +10,12 @@ ifeq ($(CHIP_VARIANT), "bcm2711") CFLAGS += -mcpu=cortex-a72 -DBCM_VERSION=2711 CROSS_COMPILE = aarch64-none-elf- SUFFIX = 8 +CIRCUITPY_MIN_GCC_VERSION ?= 10 else ifeq ($(CHIP_VARIANT), "bcm2837") CFLAGS += -mcpu=cortex-a53 -DBCM_VERSION=2837 CROSS_COMPILE = aarch64-none-elf- SUFFIX = 8 +CIRCUITPY_MIN_GCC_VERSION ?= 10 else ifeq ($(CHIP_VARIANT), "bcm2835") CFLAGS += -mcpu=arm1176jzf-s -DBCM_VERSION=2835 CROSS_COMPILE = arm-none-eabi- diff --git a/ports/litex/mpconfigport.mk b/ports/litex/mpconfigport.mk index d8dc4eef1edc..a93a3890bbc9 100644 --- a/ports/litex/mpconfigport.mk +++ b/ports/litex/mpconfigport.mk @@ -31,3 +31,4 @@ CIRCUITPY_USB_HID = 1 CIRCUITPY_USB_MIDI = 1 CIRCUITPY_BUILD_EXTENSIONS ?= dfu +CIRCUITPY_MIN_GCC_VERSION ?= 8 From a4399cf2d34bc7436e719b9c02f63bd6d7e8425f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 1 Nov 2024 15:04:11 -0500 Subject: [PATCH 177/252] Fix gcc version on broadcom again --- ports/broadcom/Makefile | 2 -- ports/broadcom/mpconfigport.mk | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/broadcom/Makefile b/ports/broadcom/Makefile index 1c640fb2f7b9..56c8c3237443 100644 --- a/ports/broadcom/Makefile +++ b/ports/broadcom/Makefile @@ -10,12 +10,10 @@ ifeq ($(CHIP_VARIANT), "bcm2711") CFLAGS += -mcpu=cortex-a72 -DBCM_VERSION=2711 CROSS_COMPILE = aarch64-none-elf- SUFFIX = 8 -CIRCUITPY_MIN_GCC_VERSION ?= 10 else ifeq ($(CHIP_VARIANT), "bcm2837") CFLAGS += -mcpu=cortex-a53 -DBCM_VERSION=2837 CROSS_COMPILE = aarch64-none-elf- SUFFIX = 8 -CIRCUITPY_MIN_GCC_VERSION ?= 10 else ifeq ($(CHIP_VARIANT), "bcm2835") CFLAGS += -mcpu=arm1176jzf-s -DBCM_VERSION=2835 CROSS_COMPILE = arm-none-eabi- diff --git a/ports/broadcom/mpconfigport.mk b/ports/broadcom/mpconfigport.mk index 543e17468361..b4b3e2ebf819 100644 --- a/ports/broadcom/mpconfigport.mk +++ b/ports/broadcom/mpconfigport.mk @@ -25,3 +25,9 @@ USB_NUM_ENDPOINT_PAIRS = 8 USB_HIGHSPEED = 1 CIRCUITPY_BUILD_EXTENSIONS ?= disk.img.zip,kernel8.img + +ifeq ($(CHIP_VARIANT), "bcm2711") +CIRCUITPY_MIN_GCC_VERSION ?= 10 +else ifeq ($(CHIP_VARIANT), "bcm2837") +CIRCUITPY_MIN_GCC_VERSION ?= 10 +endif From 3abd1223cb7c4c69b02c56cbea516180ba614abf Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 1 Nov 2024 18:31:41 -0400 Subject: [PATCH 178/252] RP2350: need cache flush in microcontroller.nvm --- ports/raspberrypi/common-hal/nvm/ByteArray.c | 7 ++++ ports/raspberrypi/supervisor/internal_flash.c | 33 +++++++++++-------- ports/raspberrypi/supervisor/internal_flash.h | 4 +++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ports/raspberrypi/common-hal/nvm/ByteArray.c b/ports/raspberrypi/common-hal/nvm/ByteArray.c index 541f1a34bd7c..2905a624c29b 100644 --- a/ports/raspberrypi/common-hal/nvm/ByteArray.c +++ b/ports/raspberrypi/common-hal/nvm/ByteArray.c @@ -12,6 +12,7 @@ #include "py/runtime.h" #include "src/rp2_common/hardware_flash/include/hardware/flash.h" #include "shared-bindings/microcontroller/__init__.h" +#include "supervisor/internal_flash.h" extern uint32_t __flash_binary_start; static const uint32_t flash_binary_start = (uint32_t)&__flash_binary_start; @@ -28,14 +29,18 @@ static void write_page(uint32_t page_addr, uint32_t offset, uint32_t len, uint8_ if (offset == 0 && len == FLASH_PAGE_SIZE) { // disable interrupts to prevent core hang on rp2040 common_hal_mcu_disable_interrupts(); + supervisor_flash_pre_write(); flash_range_program(RMV_OFFSET(page_addr), bytes, FLASH_PAGE_SIZE); + supervisor_flash_post_write(); common_hal_mcu_enable_interrupts(); } else { uint8_t buffer[FLASH_PAGE_SIZE]; memcpy(buffer, (uint8_t *)page_addr, FLASH_PAGE_SIZE); memcpy(buffer + offset, bytes, len); common_hal_mcu_disable_interrupts(); + supervisor_flash_pre_write(); flash_range_program(RMV_OFFSET(page_addr), buffer, FLASH_PAGE_SIZE); + supervisor_flash_post_write(); common_hal_mcu_enable_interrupts(); } @@ -57,8 +62,10 @@ static void erase_and_write_sector(uint32_t address, uint32_t len, uint8_t *byte memcpy(buffer + address, bytes, len); // disable interrupts to prevent core hang on rp2040 common_hal_mcu_disable_interrupts(); + supervisor_flash_pre_write(); flash_range_erase(RMV_OFFSET(CIRCUITPY_INTERNAL_NVM_START_ADDR), FLASH_SECTOR_SIZE); flash_range_program(RMV_OFFSET(CIRCUITPY_INTERNAL_NVM_START_ADDR), buffer, FLASH_SECTOR_SIZE); + supervisor_flash_post_write(); common_hal_mcu_enable_interrupts(); } diff --git a/ports/raspberrypi/supervisor/internal_flash.c b/ports/raspberrypi/supervisor/internal_flash.c index 1b328cbc5a7b..563795c516a9 100644 --- a/ports/raspberrypi/supervisor/internal_flash.c +++ b/ports/raspberrypi/supervisor/internal_flash.c @@ -46,16 +46,14 @@ static uint32_t m1_rfmt; static uint32_t m1_timing; #endif -static void save_psram_settings(void) { +static void __no_inline_not_in_flash_func(save_psram_settings)(void) { #ifdef PICO_RP2350 // We're about to invalidate the XIP cache, clean it first to commit any dirty writes to PSRAM - volatile uint8_t *maintenance_ptr = (uint8_t *)XIP_MAINTENANCE_BASE; - for (int i = 1; i < 16 * 1024; i += 8) { - // Background info: https://forums.raspberrypi.com/viewtopic.php?t=378249 - maintenance_ptr[i] = 0; // Clean - __compiler_memory_barrier(); - maintenance_ptr[i - 1] = 0; // Explicitly invalidate - __compiler_memory_barrier(); + // From https://forums.raspberrypi.com/viewtopic.php?t=378249#p2263677 + // Perform clean-by-set/way on all lines + for (uint32_t i = 0; i < 2048; ++i) { + // Use the upper 16k of the maintenance space (0x1bffc000 through 0x1bffffff): + *(volatile uint8_t *)(XIP_SRAM_BASE + (XIP_MAINTENANCE_BASE - XIP_BASE) + i * 8u + 0x1u) = 0; } m1_timing = qmi_hw->m[1].timing; @@ -63,13 +61,22 @@ static void save_psram_settings(void) { #endif } -static void restore_psram_settings(void) { +static void __no_inline_not_in_flash_func(restore_psram_settings)(void) { #ifdef PICO_RP2350 qmi_hw->m[1].timing = m1_timing; qmi_hw->m[1].rfmt = m1_rfmt; + __compiler_memory_barrier(); #endif } +void supervisor_flash_pre_write(void) { + save_psram_settings(); +} + +void supervisor_flash_post_write(void) { + restore_psram_settings(); +} + void supervisor_flash_init(void) { bi_decl_if_func_used(bi_block_device( BINARY_INFO_MAKE_TAG('C', 'P'), @@ -84,9 +91,9 @@ void supervisor_flash_init(void) { // Read the RDID register to get the flash capacity. uint8_t cmd[] = {0x9f, 0, 0, 0}; uint8_t data[4]; - save_psram_settings(); + supervisor_flash_pre_write(); flash_do_cmd(cmd, data, 4); - restore_psram_settings(); + supervisor_flash_post_write(); uint8_t power_of_two = FLASH_DEFAULT_POWER_OF_TWO; // Flash must be at least 2MB (1 << 21) because we use the first 1MB for the // CircuitPython core. We validate the range because Adesto Tech flash chips @@ -116,10 +123,10 @@ void port_internal_flash_flush(void) { #if CIRCUITPY_AUDIOCORE uint32_t channel_mask = audio_dma_pause_all(); #endif - save_psram_settings(); + supervisor_flash_pre_write(); flash_range_erase(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + _cache_lba, SECTOR_SIZE); flash_range_program(CIRCUITPY_CIRCUITPY_DRIVE_START_ADDR + _cache_lba, _cache, SECTOR_SIZE); - restore_psram_settings(); + supervisor_flash_post_write(); _cache_lba = NO_CACHE; #if CIRCUITPY_AUDIOCORE audio_dma_unpause_mask(channel_mask); diff --git a/ports/raspberrypi/supervisor/internal_flash.h b/ports/raspberrypi/supervisor/internal_flash.h index 01acbf02b4de..a7941b17c470 100644 --- a/ports/raspberrypi/supervisor/internal_flash.h +++ b/ports/raspberrypi/supervisor/internal_flash.h @@ -9,6 +9,10 @@ #include "mpconfigport.h" +// These must be called before and after doing a low-level flash write. +void supervisor_flash_pre_write(void); +void supervisor_flash_post_write(void); + // #define INTERNAL_FLASH_PART1_NUM_BLOCKS (CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) // #define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms From d6be48b41d39c59451a52c72d57bbe66bc451cf1 Mon Sep 17 00:00:00 2001 From: bablokb Date: Sat, 2 Nov 2024 10:35:41 +0000 Subject: [PATCH 179/252] use ADC_TEMPERATURE_CHANNEL_NUM instead of hard-coded channel '4' --- ports/raspberrypi/common-hal/microcontroller/Processor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index 678ceefbf92f..139edc999d66 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -39,7 +39,7 @@ float common_hal_mcu_processor_get_temperature(void) { adc_init(); adc_set_temp_sensor_enabled(true); - adc_select_input(4); + adc_select_input(ADC_TEMPERATURE_CHANNEL_NUM); uint16_t value = adc_read(); adc_set_temp_sensor_enabled(false); float voltage = value * 3.3 / (1 << 12); From 6d0a455e023da407d5d215d13e9cae87a22d581f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 3 Nov 2024 09:48:35 -0600 Subject: [PATCH 180/252] Fix various issues detected by zizmor --- .github/workflows/build-board-custom.yml | 23 ++++++++++++++++++----- .github/workflows/build-boards.yml | 1 + .github/workflows/build-mpy-cross.yml | 8 ++++++-- .github/workflows/build.yml | 20 ++++++++++++++------ .github/workflows/create-website-pr.yml | 1 + .github/workflows/pre-commit.yml | 1 + 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build-board-custom.yml b/.github/workflows/build-board-custom.yml index b91ccbd2d28f..39976cd7c1ec 100644 --- a/.github/workflows/build-board-custom.yml +++ b/.github/workflows/build-board-custom.yml @@ -42,21 +42,29 @@ jobs: run: | git clone --filter=tree:0 https://github.com/adafruit/circuitpython.git $GITHUB_WORKSPACE - name: Checkout head / tag + env: + TAG: ${{ inputs.version == 'latest' && 'HEAD' || inputs.version }} run: | - git checkout ${{ inputs.version == 'latest' && 'HEAD' || inputs.version }} + git checkout "$TAG" - name: fork compatibility if: github.repository_owner != 'adafruit' + env: + REPO: ${{ github.repository }} run: | - git remote add fork https://github.com/${{github.repository}}.git + git remote add fork "https://github.com/$REPO.git" git fetch fork --filter=tree:0 - name: branch compatibility if: inputs.branch != 'main' && inputs.version == 'latest' && github.repository_owner == 'adafruit' + env: + BRANCH: ${{ inputs.branch }} run: | - git checkout ${{inputs.branch}} + git checkout "$BRANCH" - name: branch compatibility (fork) if: inputs.branch != '' && inputs.version == 'latest' && github.repository_owner != 'adafruit' + env: + BRANCH: ${{ inputs.branch }} run: | - git checkout -b fork-branch fork/${{inputs.branch}} + git checkout -b fork-branch "fork/$BRANCH" - name: Set up identifier if: inputs.debug || inputs.flags != '' run: | @@ -101,7 +109,12 @@ jobs: riscv64-unknown-elf-gcc --version || true mkfs.fat --version || true - name: Build board - run: make -j4 ${{ inputs.flags }} BOARD=${{ inputs.board }} DEBUG=${{ inputs.debug && '1' || '0' }} TRANSLATION=${{ inputs.language }} + env: + TRANSLATION: ${{ inputs.language }} + BOARD: ${{ inputs.board }} + FLAGS: ${{ inputs.flags }} + DEBUG: ${{ inputs.debug && '1' || '0' }} + run: make -j4 $FLAGS BOARD="$BOARD" DEBUG=$DEBUG TRANSLATION="$TRANSLATION" working-directory: ports/${{ steps.set-up-port.outputs.port }} - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/build-boards.yml b/.github/workflows/build-boards.yml index be076e0789f8..7daa7ae7e322 100644 --- a/.github/workflows/build-boards.yml +++ b/.github/workflows/build-boards.yml @@ -31,6 +31,7 @@ jobs: submodules: false show-progress: false fetch-depth: 1 + persist-credentials: false - name: Set up python uses: actions/setup-python@v5 diff --git a/.github/workflows/build-mpy-cross.yml b/.github/workflows/build-mpy-cross.yml index 9d94fb638ef5..731cb8661f6d 100644 --- a/.github/workflows/build-mpy-cross.yml +++ b/.github/workflows/build-mpy-cross.yml @@ -33,6 +33,7 @@ jobs: submodules: false show-progress: false fetch-depth: 1 + persist-credentials: false - name: Set up python uses: actions/setup-python@v5 with: @@ -57,9 +58,12 @@ jobs: run: make -C mpy-cross -j4 -f Makefile.${{ matrix.mpy-cross }} - name: Set output + env: + EX=${{ env[format('EX_{0}', matrix.mpy-cross)] || matrix.mpy-cross }} + OS=${{ env[format('OS_{0}', matrix.mpy-cross)] }}" run: | - echo >> $GITHUB_ENV "EX=${{ env[format('EX_{0}', matrix.mpy-cross)] || matrix.mpy-cross }}" - echo >> $GITHUB_ENV "OS=${{ env[format('OS_{0}', matrix.mpy-cross)] }}" + echo >> $GITHUB_ENV "EX=$EX" + echo >> $GITHUB_ENV "OS=$OS" - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0f8b1b763817..7cc8d49a4efb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,6 +33,7 @@ jobs: submodules: false show-progress: false fetch-depth: 1 + persist-credentials: false - name: Set up python uses: actions/setup-python@v5 with: @@ -66,7 +67,9 @@ jobs: EXCLUDE_COMMIT: ${{ github.event.pull_request.head.sha }} - name: Set head sha (pull) if: github.event_name == 'pull_request' - run: echo "HEAD_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV + env: + HEAD_SHA:${{ github.event.pull_request.head.sha }} + run: echo "HEAD_SHA=$HEAD_SHA" >> $GITHUB_ENV - name: Set base sha (pull) if: github.event_name == 'pull_request' run: git cat-file -e $SHA && echo "BASE_SHA=$SHA" >> $GITHUB_ENV || true @@ -74,7 +77,9 @@ jobs: SHA: ${{ steps.get-last-commit-with-checks.outputs.commit_sha || github.event.pull_request.base.sha }} - name: Set head sha (push) if: github.event_name == 'push' - run: echo "HEAD_SHA=${{ github.event.after }}" >> $GITHUB_ENV + env: + SHA: ${{ github.event.after }} + run: echo "HEAD_SHA=$SHA" >> $GITHUB_ENV - name: Set base sha (push) if: github.event_name == 'push' run: git cat-file -e $SHA && echo "BASE_SHA=$SHA" >> $GITHUB_ENV || true @@ -114,6 +119,7 @@ jobs: submodules: false show-progress: false fetch-depth: 1 + persist-credentials: false - name: Set up python uses: actions/setup-python@v5 with: @@ -149,9 +155,9 @@ jobs: (github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'adafruit') || (github.event_name == 'release' && (github.event.action == 'published' || github.event.action == 'rerequested')) run: | - [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross-macos-universal s3://adafruit-circuit-python/bin/mpy-cross/macos/mpy-cross-macos-${{ env.CP_VERSION }}-universal --no-progress --region us-east-1 - [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/build-arm64/mpy-cross-arm64 s3://adafruit-circuit-python/bin/mpy-cross/macos/mpy-cross-macos-${{ env.CP_VERSION }}-arm64 --no-progress --region us-east-1 - [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/build/mpy-cross s3://adafruit-circuit-python/bin/mpy-cross/macos/mpy-cross-macos-${{ env.CP_VERSION }}-x64 --no-progress --region us-east-1 + [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross-macos-universal s3://adafruit-circuit-python/bin/mpy-cross/macos/mpy-cross-macos-"${CP_VERSION}"-universal --no-progress --region us-east-1 + [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/build-arm64/mpy-cross-arm64 s3://adafruit-circuit-python/bin/mpy-cross/macos/mpy-cross-macos-"${CP_VERSION}"-arm64 --no-progress --region us-east-1 + [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/build/mpy-cross s3://adafruit-circuit-python/bin/mpy-cross/macos/mpy-cross-macos-"${CP_VERSION}"-x64 --no-progress --region us-east-1 env: AWS_PAGER: '' AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} @@ -170,6 +176,7 @@ jobs: submodules: false show-progress: false fetch-depth: 1 + persist-credentials: false - name: Set up python uses: actions/setup-python@v5 with: @@ -188,7 +195,7 @@ jobs: name: stubs path: circuitpython-stubs/dist/* - name: Test Documentation Build (HTML) - run: sphinx-build -E -W -b html -D version=${{ env.CP_VERSION }} -D release=${{ env.CP_VERSION }} . _build/html + run: sphinx-build -E -W -b html -D version="$CP_VERSION" -D release="$CP_VERSION" . _build/html - uses: actions/upload-artifact@v4 with: name: docs-html @@ -271,6 +278,7 @@ jobs: submodules: false show-progress: false fetch-depth: 1 + persist-credentials: false - name: Set up submodules uses: ./.github/actions/deps/submodules - name: build mpy-cross diff --git a/.github/workflows/create-website-pr.yml b/.github/workflows/create-website-pr.yml index 8f4cce7691c1..32c1792fa6c7 100644 --- a/.github/workflows/create-website-pr.yml +++ b/.github/workflows/create-website-pr.yml @@ -22,6 +22,7 @@ jobs: submodules: false show-progress: false fetch-depth: 1 + persist-credentials: false - name: Set up python uses: actions/setup-python@v5 with: diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index b3517d748f5e..778270dc08c8 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -22,6 +22,7 @@ jobs: submodules: false show-progress: false fetch-depth: 1 + persist-credentials: false - name: Set up python uses: actions/setup-python@v5 with: From 4178456a505e3a47abd3ca2dc4badfbb4ed71181 Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Sun, 3 Nov 2024 11:29:01 -0500 Subject: [PATCH 181/252] Fix optimization settings for non-debug builds --- ports/analog/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index ebdb62bb2c13..a36619b5687c 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -163,10 +163,9 @@ DEBUG ?= 1 endif ifeq ($(DEBUG),1) -CFLAGS += -ggdb3 -COPT = -Og +COPT = -Og -ggdb3 -Os else -COPT += -O0 #opt completely off to start +COPT += -Os #opt completely off to start endif # TinyUSB CFLAGS From de20c412b2d4556f803ce28d0ff9060c4b30ab24 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sun, 3 Nov 2024 19:39:31 +0200 Subject: [PATCH 182/252] Reboot to normal mode upon fs wipe --- shared-module/storage/__init__.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 12486aff752f..e64184c000bb 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -264,6 +264,7 @@ void common_hal_storage_erase_filesystem(bool extended) { supervisor_flash_set_extended(extended); #endif (void)filesystem_init(false, true); // Force a re-format. Ignore failure. + common_hal_mcu_on_next_reset(RUNMODE_NORMAL); common_hal_mcu_reset(); // We won't actually get here, since we're resetting. } From 259cc6684820d5bac31c679063246c986ef1b6e5 Mon Sep 17 00:00:00 2001 From: Brandon Hurst Date: Sun, 3 Nov 2024 13:45:39 -0500 Subject: [PATCH 183/252] Enabled SysTick interrupt for time.sleep to work. Cleaned up optimization settings. --- ports/analog/Makefile | 16 ++++++++-------- ports/analog/supervisor/port.c | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index a36619b5687c..b2f392b17c59 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -141,7 +141,7 @@ SRC_S += supervisor/cpu.s \ $(STARTUPFILE) # Needed to compile some MAX32 headers -CFLAGS += -D$(MCU_VARIANT_UPPER) \ +CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET_REV=0x4131 \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ @@ -149,23 +149,23 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DCONFIG_TRUSTED_EXECUTION_SECURE=0 # todo: add these for linkerfiles later on so that it's easier to add new boards -# -DFLASH_ORIGIN=0x10000000 \ -# -DFLASH_SIZE=0x340000 \ -# -DSRAM_ORIGIN=0x20000000 \ -# -DSRAM_SIZE=0x100000 +# -DFLASH_ORIGIN \ +# -DFLASH_SIZE \ +# -DSRAM_ORIGIN \ +# -DSRAM_SIZE CPU_CORE=cortex-m4 CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -# NOTE: Start with DEBUG ONLY settings for now +# NOTE: Start with DEBUG=1 defaults for now ifeq ($(DEBUG),) DEBUG ?= 1 endif ifeq ($(DEBUG),1) -COPT = -Og -ggdb3 -Os +COPT = -ggdb3 -Og -Os else -COPT += -Os #opt completely off to start +COPT += -Os endif # TinyUSB CFLAGS diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index cdbf88d2528d..391ad655d2cd 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -65,11 +65,14 @@ static uint32_t tick_flag = 0; // defined by cmsis core files extern void NVIC_SystemReset(void) NORETURN; +// FIXME: Currently have an issue with time.sleep b/c MXC_Delay uses SysTick, +// and SysTick ISR isn't happening. Seems that MXC_Delay results in inf. loop safe_mode_t port_init(void) { int err = E_NO_ERROR; // 1ms tick timer SysTick_Config(SystemCoreClock / 1000); + NVIC_EnableIRQ(SysTick_IRQn); // FIXME: Test with NVIC Enable here before committing // Enable GPIO (enables clocks + common init for ports) for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { From 70a7180be33fe47b3a137cf66e8b659614050c91 Mon Sep 17 00:00:00 2001 From: Brandon Hurst Date: Sun, 3 Nov 2024 15:18:59 -0500 Subject: [PATCH 184/252] Remove FIXME comments from supervisor/port.c. Changes were tested. --- ports/analog/supervisor/port.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 391ad655d2cd..0aedd74f179c 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -65,14 +65,12 @@ static uint32_t tick_flag = 0; // defined by cmsis core files extern void NVIC_SystemReset(void) NORETURN; -// FIXME: Currently have an issue with time.sleep b/c MXC_Delay uses SysTick, -// and SysTick ISR isn't happening. Seems that MXC_Delay results in inf. loop safe_mode_t port_init(void) { int err = E_NO_ERROR; // 1ms tick timer SysTick_Config(SystemCoreClock / 1000); - NVIC_EnableIRQ(SysTick_IRQn); // FIXME: Test with NVIC Enable here before committing + NVIC_EnableIRQ(SysTick_IRQn); // Enable GPIO (enables clocks + common init for ports) for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { From 63c3e394d3efa37fa43723da1f7e922ca8080933 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 3 Nov 2024 18:30:19 -0600 Subject: [PATCH 185/252] Fix error with NULL sample handling in `audiofilters.Filter`. --- shared-module/audiofilters/Filter.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index 86edb6cb0418..47032fd46dfe 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -240,8 +240,21 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o } } - // If we have a sample, filter it - if (self->sample != NULL) { + if (self->sample == NULL) { + if (self->samples_signed) { + memset(word_buffer, 0, length * (self->bits_per_sample / 8)); + } else { + // For unsigned samples set to the middle which is "quiet" + if (MP_LIKELY(self->bits_per_sample == 16)) { + memset(word_buffer, 32768, length * (self->bits_per_sample / 8)); + } else { + memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); + } + } + + length = 0; + } else { + // we have a sample to play and filter // Determine how many bytes we can process to our buffer, the less of the sample we have left and our buffer remaining uint32_t n = MIN(self->sample_buffer_length, length); From aa7d619d55294a7fe0703820b5d56d278c2a0192 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 3 Nov 2024 19:57:02 -0600 Subject: [PATCH 186/252] Fix `ring_waveform_loop_start` typo in frequency calculation. --- shared-module/synthio/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index 630c3de86988..f2c05cd5f74a 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -196,7 +196,7 @@ static bool synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou ring_waveform = note->ring_waveform_buf.buf; ring_waveform_length = note->ring_waveform_buf.len; if (note->ring_waveform_loop_start > 0 && note->ring_waveform_loop_start < ring_waveform_length) { - ring_waveform_start = note->waveform_loop_start; + ring_waveform_start = note->ring_waveform_loop_start; } if (note->ring_waveform_loop_end > ring_waveform_start && note->ring_waveform_loop_end < ring_waveform_length) { ring_waveform_length = note->ring_waveform_loop_end; From ce12d90160f01c9be36ecd2facff40efd8404f96 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 3 Nov 2024 20:00:35 -0600 Subject: [PATCH 187/252] Fix default value of `synthio.Note.amplitude` in documentation. --- shared-bindings/synthio/Note.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index c886f106a4cf..f7f6f54986e7 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -40,7 +40,7 @@ static const mp_arg_t note_properties[] = { //| waveform_loop_start: int = 0, //| waveform_loop_end: int = waveform_max_length, //| envelope: Optional[Envelope] = None, -//| amplitude: BlockInput = 0.0, +//| amplitude: BlockInput = 1.0, //| bend: BlockInput = 0.0, //| filter: Optional[Biquad] = None, //| ring_frequency: float = 0.0, From e2a52afa9323853766cf556ef7ae0bc323e22054 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Sun, 3 Nov 2024 20:30:06 -0600 Subject: [PATCH 188/252] Add support for `synthio.BlockInput` on `synthio.Note.waveform_loop_start`, `synthio.Note.waveform_loop_end`, `synthio.Note.ring_waveform_loop_start`, and `synthio.Note.ring_waveform_loop_end`. --- shared-bindings/synthio/Note.c | 42 +++++++++++++++++--------------- shared-bindings/synthio/Note.h | 16 ++++++------ shared-module/synthio/Note.c | 36 ++++++++++++--------------- shared-module/synthio/Note.h | 4 +-- shared-module/synthio/__init__.c | 16 +++--------- 5 files changed, 52 insertions(+), 62 deletions(-) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index f7f6f54986e7..60ebbff3a2ae 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -20,15 +20,15 @@ static const mp_arg_t note_properties[] = { { MP_QSTR_amplitude, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(1) } }, { MP_QSTR_bend, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, - { MP_QSTR_waveform_loop_start, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, - { MP_QSTR_waveform_loop_end, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, + { MP_QSTR_waveform_loop_start, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, + { MP_QSTR_waveform_loop_end, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, { MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_ring_frequency, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_ring_bend, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_ring_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, - { MP_QSTR_ring_waveform_loop_start, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, - { MP_QSTR_ring_waveform_loop_end, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, + { MP_QSTR_ring_waveform_loop_start, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, + { MP_QSTR_ring_waveform_loop_end, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, }; //| class Note: //| def __init__( @@ -37,8 +37,8 @@ static const mp_arg_t note_properties[] = { //| frequency: float, //| panning: BlockInput = 0.0, //| waveform: Optional[ReadableBuffer] = None, -//| waveform_loop_start: int = 0, -//| waveform_loop_end: int = waveform_max_length, +//| waveform_loop_start: BlockInput = 0, +//| waveform_loop_end: BlockInput = waveform_max_length, //| envelope: Optional[Envelope] = None, //| amplitude: BlockInput = 1.0, //| bend: BlockInput = 0.0, @@ -46,8 +46,8 @@ static const mp_arg_t note_properties[] = { //| ring_frequency: float = 0.0, //| ring_bend: float = 0.0, //| ring_waveform: Optional[ReadableBuffer] = None, -//| ring_waveform_loop_start: int = 0, -//| ring_waveform_loop_end: int = waveform_max_length, +//| ring_waveform_loop_start: BlockInput = 0, +//| ring_waveform_loop_end: BlockInput = waveform_max_length, //| ) -> None: //| """Construct a Note object, with a frequency in Hz, and optional panning, waveform, envelope, tremolo (volume change) and bend (frequency change). //| @@ -198,7 +198,9 @@ MP_PROPERTY_GETSET(synthio_note_waveform_obj, (mp_obj_t)&synthio_note_get_waveform_obj, (mp_obj_t)&synthio_note_set_waveform_obj); -//| waveform_loop_start: int + + +//| waveform_loop_start: BlockInput //| """The sample index of where to begin looping waveform data. //| //| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`. @@ -206,13 +208,13 @@ MP_PROPERTY_GETSET(synthio_note_waveform_obj, //| Values greater than or equal to the actual waveform length are treated as 0.""" static mp_obj_t synthio_note_get_waveform_loop_start(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(common_hal_synthio_note_get_waveform_loop_start(self)); + return common_hal_synthio_note_get_waveform_loop_start(self); } MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_waveform_loop_start_obj, synthio_note_get_waveform_loop_start); static mp_obj_t synthio_note_set_waveform_loop_start(mp_obj_t self_in, mp_obj_t arg) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_note_set_waveform_loop_start(self, mp_obj_get_int(arg)); + common_hal_synthio_note_set_waveform_loop_start(self, arg); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_waveform_loop_start_obj, synthio_note_set_waveform_loop_start); @@ -220,7 +222,7 @@ MP_PROPERTY_GETSET(synthio_note_waveform_loop_start_obj, (mp_obj_t)&synthio_note_get_waveform_loop_start_obj, (mp_obj_t)&synthio_note_set_waveform_loop_start_obj); -//| waveform_loop_end: int +//| waveform_loop_end: BlockInput //| """The sample index of where to end looping waveform data. //| //| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`. @@ -231,13 +233,13 @@ MP_PROPERTY_GETSET(synthio_note_waveform_loop_start_obj, //| static mp_obj_t synthio_note_get_waveform_loop_end(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(common_hal_synthio_note_get_waveform_loop_end(self)); + return common_hal_synthio_note_get_waveform_loop_end(self); } MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_waveform_loop_end_obj, synthio_note_get_waveform_loop_end); static mp_obj_t synthio_note_set_waveform_loop_end(mp_obj_t self_in, mp_obj_t arg) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_note_set_waveform_loop_end(self, mp_obj_get_int(arg)); + common_hal_synthio_note_set_waveform_loop_end(self, arg); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_waveform_loop_end_obj, synthio_note_set_waveform_loop_end); @@ -331,7 +333,7 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj, (mp_obj_t)&synthio_note_get_ring_waveform_obj, (mp_obj_t)&synthio_note_set_ring_waveform_obj); -//| ring_waveform_loop_start: int +//| ring_waveform_loop_start: BlockInput //| """The sample index of where to begin looping waveform data. //| //| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`. @@ -339,13 +341,13 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj, //| Values greater than or equal to the actual waveform length are treated as 0.""" static mp_obj_t synthio_note_get_ring_waveform_loop_start(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(common_hal_synthio_note_get_ring_waveform_loop_start(self)); + return common_hal_synthio_note_get_ring_waveform_loop_start(self); } MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_ring_waveform_loop_start_obj, synthio_note_get_ring_waveform_loop_start); static mp_obj_t synthio_note_set_ring_waveform_loop_start(mp_obj_t self_in, mp_obj_t arg) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_note_set_ring_waveform_loop_start(self, mp_obj_get_int(arg)); + common_hal_synthio_note_set_ring_waveform_loop_start(self, arg); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_ring_waveform_loop_start_obj, synthio_note_set_ring_waveform_loop_start); @@ -353,7 +355,7 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_loop_start_obj, (mp_obj_t)&synthio_note_get_ring_waveform_loop_start_obj, (mp_obj_t)&synthio_note_set_ring_waveform_loop_start_obj); -//| ring_waveform_loop_end: int +//| ring_waveform_loop_end: BlockInput //| """The sample index of where to end looping waveform data. //| //| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`. @@ -364,13 +366,13 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_loop_start_obj, //| static mp_obj_t synthio_note_get_ring_waveform_loop_end(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(common_hal_synthio_note_get_ring_waveform_loop_end(self)); + return common_hal_synthio_note_get_ring_waveform_loop_end(self); } MP_DEFINE_CONST_FUN_OBJ_1(synthio_note_get_ring_waveform_loop_end_obj, synthio_note_get_ring_waveform_loop_end); static mp_obj_t synthio_note_set_ring_waveform_loop_end(mp_obj_t self_in, mp_obj_t arg) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_note_set_ring_waveform_loop_end(self, mp_obj_get_int(arg)); + common_hal_synthio_note_set_ring_waveform_loop_end(self, arg); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(synthio_note_set_ring_waveform_loop_end_obj, synthio_note_set_ring_waveform_loop_end); diff --git a/shared-bindings/synthio/Note.h b/shared-bindings/synthio/Note.h index 0ee450acfe46..707b9f2e1046 100644 --- a/shared-bindings/synthio/Note.h +++ b/shared-bindings/synthio/Note.h @@ -31,11 +31,11 @@ void common_hal_synthio_note_set_bend(synthio_note_obj_t *self, mp_obj_t value); mp_obj_t common_hal_synthio_note_get_waveform_obj(synthio_note_obj_t *self); void common_hal_synthio_note_set_waveform(synthio_note_obj_t *self, mp_obj_t value); -mp_int_t common_hal_synthio_note_get_waveform_loop_start(synthio_note_obj_t *self); -void common_hal_synthio_note_set_waveform_loop_start(synthio_note_obj_t *self, mp_int_t value_in); +mp_obj_t common_hal_synthio_note_get_waveform_loop_start(synthio_note_obj_t *self); +void common_hal_synthio_note_set_waveform_loop_start(synthio_note_obj_t *self, mp_obj_t value); -mp_int_t common_hal_synthio_note_get_waveform_loop_end(synthio_note_obj_t *self); -void common_hal_synthio_note_set_waveform_loop_end(synthio_note_obj_t *self, mp_int_t value_in); +mp_obj_t common_hal_synthio_note_get_waveform_loop_end(synthio_note_obj_t *self); +void common_hal_synthio_note_set_waveform_loop_end(synthio_note_obj_t *self, mp_obj_t value); mp_float_t common_hal_synthio_note_get_ring_frequency(synthio_note_obj_t *self); void common_hal_synthio_note_set_ring_frequency(synthio_note_obj_t *self, mp_float_t value); @@ -46,11 +46,11 @@ void common_hal_synthio_note_set_ring_bend(synthio_note_obj_t *self, mp_obj_t va mp_obj_t common_hal_synthio_note_get_ring_waveform_obj(synthio_note_obj_t *self); void common_hal_synthio_note_set_ring_waveform(synthio_note_obj_t *self, mp_obj_t value); -mp_int_t common_hal_synthio_note_get_ring_waveform_loop_start(synthio_note_obj_t *self); -void common_hal_synthio_note_set_ring_waveform_loop_start(synthio_note_obj_t *self, mp_int_t value_in); +mp_obj_t common_hal_synthio_note_get_ring_waveform_loop_start(synthio_note_obj_t *self); +void common_hal_synthio_note_set_ring_waveform_loop_start(synthio_note_obj_t *self, mp_obj_t value); -mp_int_t common_hal_synthio_note_get_ring_waveform_loop_end(synthio_note_obj_t *self); -void common_hal_synthio_note_set_ring_waveform_loop_end(synthio_note_obj_t *self, mp_int_t value_in); +mp_obj_t common_hal_synthio_note_get_ring_waveform_loop_end(synthio_note_obj_t *self); +void common_hal_synthio_note_set_ring_waveform_loop_end(synthio_note_obj_t *self, mp_obj_t value); mp_obj_t common_hal_synthio_note_get_envelope_obj(synthio_note_obj_t *self); void common_hal_synthio_note_set_envelope(synthio_note_obj_t *self, mp_obj_t value); diff --git a/shared-module/synthio/Note.c b/shared-module/synthio/Note.c index 49dfbb7f429d..0e612914ec70 100644 --- a/shared-module/synthio/Note.c +++ b/shared-module/synthio/Note.c @@ -100,22 +100,20 @@ void common_hal_synthio_note_set_waveform(synthio_note_obj_t *self, mp_obj_t wav self->waveform_obj = waveform_in; } -mp_int_t common_hal_synthio_note_get_waveform_loop_start(synthio_note_obj_t *self) { - return self->waveform_loop_start; +mp_obj_t common_hal_synthio_note_get_waveform_loop_start(synthio_note_obj_t *self) { + return self->waveform_loop_start.obj; } -void common_hal_synthio_note_set_waveform_loop_start(synthio_note_obj_t *self, mp_int_t value_in) { - mp_int_t val = mp_arg_validate_int_range(value_in, 0, SYNTHIO_WAVEFORM_SIZE - 1, MP_QSTR_waveform_loop_start); - self->waveform_loop_start = val; +void common_hal_synthio_note_set_waveform_loop_start(synthio_note_obj_t *self, mp_obj_t value_in) { + synthio_block_assign_slot(value_in, &self->waveform_loop_start, MP_QSTR_waveform_loop_start); } -mp_int_t common_hal_synthio_note_get_waveform_loop_end(synthio_note_obj_t *self) { - return self->waveform_loop_end; +mp_obj_t common_hal_synthio_note_get_waveform_loop_end(synthio_note_obj_t *self) { + return self->waveform_loop_end.obj; } -void common_hal_synthio_note_set_waveform_loop_end(synthio_note_obj_t *self, mp_int_t value_in) { - mp_int_t val = mp_arg_validate_int_range(value_in, 1, SYNTHIO_WAVEFORM_SIZE, MP_QSTR_waveform_loop_end); - self->waveform_loop_end = val; +void common_hal_synthio_note_set_waveform_loop_end(synthio_note_obj_t *self, mp_obj_t value_in) { + synthio_block_assign_slot(value_in, &self->waveform_loop_end, MP_QSTR_waveform_loop_end); } mp_obj_t common_hal_synthio_note_get_ring_waveform_obj(synthio_note_obj_t *self) { @@ -133,22 +131,20 @@ void common_hal_synthio_note_set_ring_waveform(synthio_note_obj_t *self, mp_obj_ self->ring_waveform_obj = ring_waveform_in; } -mp_int_t common_hal_synthio_note_get_ring_waveform_loop_start(synthio_note_obj_t *self) { - return self->ring_waveform_loop_start; +mp_obj_t common_hal_synthio_note_get_ring_waveform_loop_start(synthio_note_obj_t *self) { + return self->ring_waveform_loop_start.obj; } -void common_hal_synthio_note_set_ring_waveform_loop_start(synthio_note_obj_t *self, mp_int_t value_in) { - mp_int_t val = mp_arg_validate_int_range(value_in, 0, SYNTHIO_WAVEFORM_SIZE - 1, MP_QSTR_ring_waveform_loop_start); - self->ring_waveform_loop_start = val; +void common_hal_synthio_note_set_ring_waveform_loop_start(synthio_note_obj_t *self, mp_obj_t value_in) { + synthio_block_assign_slot(value_in, &self->ring_waveform_loop_start, MP_QSTR_ring_waveform_loop_start); } -mp_int_t common_hal_synthio_note_get_ring_waveform_loop_end(synthio_note_obj_t *self) { - return self->ring_waveform_loop_end; +mp_obj_t common_hal_synthio_note_get_ring_waveform_loop_end(synthio_note_obj_t *self) { + return self->ring_waveform_loop_end.obj; } -void common_hal_synthio_note_set_ring_waveform_loop_end(synthio_note_obj_t *self, mp_int_t value_in) { - mp_int_t val = mp_arg_validate_int_range(value_in, 1, SYNTHIO_WAVEFORM_SIZE, MP_QSTR_ring_waveform_loop_end); - self->ring_waveform_loop_end = val; +void common_hal_synthio_note_set_ring_waveform_loop_end(synthio_note_obj_t *self, mp_obj_t value_in) { + synthio_block_assign_slot(value_in, &self->ring_waveform_loop_end, MP_QSTR_ring_waveform_loop_end); } void synthio_note_recalculate(synthio_note_obj_t *self, int32_t sample_rate) { diff --git a/shared-module/synthio/Note.h b/shared-module/synthio/Note.h index dc4e5557fd3c..9d9deb42ac8f 100644 --- a/shared-module/synthio/Note.h +++ b/shared-module/synthio/Note.h @@ -28,9 +28,9 @@ typedef struct synthio_note_obj { int32_t ring_frequency_scaled, ring_frequency_bent; mp_buffer_info_t waveform_buf; - uint32_t waveform_loop_start, waveform_loop_end; + synthio_block_slot_t waveform_loop_start, waveform_loop_end; mp_buffer_info_t ring_waveform_buf; - uint32_t ring_waveform_loop_start, ring_waveform_loop_end; + synthio_block_slot_t ring_waveform_loop_start, ring_waveform_loop_end; synthio_envelope_definition_t envelope_def; } synthio_note_obj_t; diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index f2c05cd5f74a..8173da3f0ce3 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -184,23 +184,15 @@ static bool synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou if (note->waveform_buf.buf) { waveform = note->waveform_buf.buf; waveform_length = note->waveform_buf.len; - if (note->waveform_loop_start > 0 && note->waveform_loop_start < waveform_length) { - waveform_start = note->waveform_loop_start; - } - if (note->waveform_loop_end > waveform_start && note->waveform_loop_end < waveform_length) { - waveform_length = note->waveform_loop_end; - } + waveform_start = synthio_block_slot_get_limited(¬e->waveform_loop_start, 0, waveform_length - 1); + waveform_length = synthio_block_slot_get_limited(¬e->waveform_loop_end, waveform_start + 1, waveform_length); } dds_rate = synthio_frequency_convert_scaled_to_dds((uint64_t)frequency_scaled * (waveform_length - waveform_start), sample_rate); if (note->ring_frequency_scaled != 0 && note->ring_waveform_buf.buf) { ring_waveform = note->ring_waveform_buf.buf; ring_waveform_length = note->ring_waveform_buf.len; - if (note->ring_waveform_loop_start > 0 && note->ring_waveform_loop_start < ring_waveform_length) { - ring_waveform_start = note->ring_waveform_loop_start; - } - if (note->ring_waveform_loop_end > ring_waveform_start && note->ring_waveform_loop_end < ring_waveform_length) { - ring_waveform_length = note->ring_waveform_loop_end; - } + ring_waveform_start = synthio_block_slot_get_limited(¬e->ring_waveform_loop_start, 0, ring_waveform_length - 1); + ring_waveform_length = synthio_block_slot_get_limited(¬e->ring_waveform_loop_end, ring_waveform_start + 1, ring_waveform_length); ring_dds_rate = synthio_frequency_convert_scaled_to_dds((uint64_t)note->ring_frequency_bent * (ring_waveform_length - ring_waveform_start), sample_rate); uint32_t lim = ring_waveform_length << SYNTHIO_FREQUENCY_SHIFT; if (ring_dds_rate > lim / sizeof(int16_t)) { From e7382c2fc444f934b510d37033cdb3f01a74f507 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Mon, 4 Nov 2024 08:13:17 -0600 Subject: [PATCH 189/252] Make conversion of `mp_float_t` to `uint32_t` for waveform_loop values explicit. --- shared-module/synthio/__init__.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index 8173da3f0ce3..be7e036660a8 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -184,15 +184,15 @@ static bool synth_note_into_buffer(synthio_synth_t *synth, int chan, int32_t *ou if (note->waveform_buf.buf) { waveform = note->waveform_buf.buf; waveform_length = note->waveform_buf.len; - waveform_start = synthio_block_slot_get_limited(¬e->waveform_loop_start, 0, waveform_length - 1); - waveform_length = synthio_block_slot_get_limited(¬e->waveform_loop_end, waveform_start + 1, waveform_length); + waveform_start = (uint32_t)synthio_block_slot_get_limited(¬e->waveform_loop_start, 0, waveform_length - 1); + waveform_length = (uint32_t)synthio_block_slot_get_limited(¬e->waveform_loop_end, waveform_start + 1, waveform_length); } dds_rate = synthio_frequency_convert_scaled_to_dds((uint64_t)frequency_scaled * (waveform_length - waveform_start), sample_rate); if (note->ring_frequency_scaled != 0 && note->ring_waveform_buf.buf) { ring_waveform = note->ring_waveform_buf.buf; ring_waveform_length = note->ring_waveform_buf.len; - ring_waveform_start = synthio_block_slot_get_limited(¬e->ring_waveform_loop_start, 0, ring_waveform_length - 1); - ring_waveform_length = synthio_block_slot_get_limited(¬e->ring_waveform_loop_end, ring_waveform_start + 1, ring_waveform_length); + ring_waveform_start = (uint32_t)synthio_block_slot_get_limited(¬e->ring_waveform_loop_start, 0, ring_waveform_length - 1); + ring_waveform_length = (uint32_t)synthio_block_slot_get_limited(¬e->ring_waveform_loop_end, ring_waveform_start + 1, ring_waveform_length); ring_dds_rate = synthio_frequency_convert_scaled_to_dds((uint64_t)note->ring_frequency_bent * (ring_waveform_length - ring_waveform_start), sample_rate); uint32_t lim = ring_waveform_length << SYNTHIO_FREQUENCY_SHIFT; if (ring_dds_rate > lim / sizeof(int16_t)) { From 9113e171ba17f4766fad1ab9ac7db65f5eba13bb Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 4 Nov 2024 09:16:29 -0600 Subject: [PATCH 190/252] Throw TypeError when json-serializing invalid types This behavior is in line with standard Python Closes: #9768 --- py/obj.c | 7 +++++++ py/obj.h | 2 ++ py/objbool.c | 3 ++- py/objdict.c | 6 ++++-- py/objfloat.c | 3 ++- py/objint.c | 3 ++- py/objlist.c | 3 ++- py/objnone.c | 3 ++- py/objstr.c | 3 ++- py/objstrunicode.c | 3 ++- py/objtuple.c | 3 ++- tests/extmod/json_dumps_extra.py | 9 +++------ 12 files changed, 32 insertions(+), 16 deletions(-) diff --git a/py/obj.c b/py/obj.c index afbc62a65fce..a825efc3c5a8 100644 --- a/py/obj.c +++ b/py/obj.c @@ -144,6 +144,13 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t } #endif const mp_obj_type_t *type = mp_obj_get_type(o_in); + // CIRCUITPY-CHANGE: Diagnose json.dump on invalid types + #if MICROPY_PY_JSON + if (kind == PRINT_JSON && !(type->flags & MP_TYPE_FLAG_PRINT_JSON)) { + mp_raise_msg_varg(&mp_type_TypeError, + MP_ERROR_TEXT("can't convert %q to %q"), type->name, MP_QSTR_json); + } + #endif if (MP_OBJ_TYPE_HAS_SLOT(type, print)) { MP_OBJ_TYPE_GET_SLOT(type, print)((mp_print_t *)print, o_in, kind); } else { diff --git a/py/obj.h b/py/obj.h index 70fdeeebde4d..255a00b314f5 100644 --- a/py/obj.h +++ b/py/obj.h @@ -581,6 +581,8 @@ typedef mp_obj_t (*mp_fun_kw_t)(size_t n, const mp_obj_t *, mp_map_t *); #define MP_TYPE_FLAG_ITER_IS_CUSTOM (0x0100) #define MP_TYPE_FLAG_ITER_IS_STREAM (MP_TYPE_FLAG_ITER_IS_ITERNEXT | MP_TYPE_FLAG_ITER_IS_CUSTOM) #define MP_TYPE_FLAG_INSTANCE_TYPE (0x0200) +// CIRCUITPY-CHANGE: check for valid types in json dumps +#define MP_TYPE_FLAG_PRINT_JSON (0x0400) typedef enum { PRINT_STR = 0, diff --git a/py/objbool.c b/py/objbool.c index 5b3e3660e951..990f52bb26fe 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -84,11 +84,12 @@ static mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_ return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(value), rhs_in); } +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( // can match all numeric types mp_type_bool, MP_QSTR_bool, - MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, + MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_PRINT_JSON, make_new, bool_make_new, print, bool_print, unary_op, bool_unary_op, diff --git a/py/objdict.c b/py/objdict.c index 96a659d36e04..7094a1c1f99f 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -710,10 +710,11 @@ static const mp_rom_map_elem_t dict_locals_dict_table[] = { static MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table); +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( mp_type_dict, MP_QSTR_dict, - MP_TYPE_FLAG_ITER_IS_GETITER, + MP_TYPE_FLAG_ITER_IS_GETITER | MP_TYPE_FLAG_PRINT_JSON, make_new, mp_obj_dict_make_new, print, dict_print, unary_op, dict_unary_op, @@ -724,10 +725,11 @@ MP_DEFINE_CONST_OBJ_TYPE( ); #if MICROPY_PY_COLLECTIONS_ORDEREDDICT +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( mp_type_ordereddict, MP_QSTR_OrderedDict, - MP_TYPE_FLAG_ITER_IS_GETITER, + MP_TYPE_FLAG_ITER_IS_GETITER | MP_TYPE_FLAG_PRINT_JSON, make_new, mp_obj_dict_make_new, print, dict_print, unary_op, dict_unary_op, diff --git a/py/objfloat.c b/py/objfloat.c index b3a1f692594a..6f248cdadfc9 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -186,8 +186,9 @@ static mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs return mp_obj_float_binary_op(op, lhs_val, rhs_in); } +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( - mp_type_float, MP_QSTR_float, MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, + mp_type_float, MP_QSTR_float, MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_PRINT_JSON, make_new, float_make_new, print, float_print, unary_op, float_unary_op, diff --git a/py/objint.c b/py/objint.c index 197625ced815..7895f4f201ed 100644 --- a/py/objint.c +++ b/py/objint.c @@ -588,10 +588,11 @@ static const mp_rom_map_elem_t int_locals_dict_table[] = { static MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table); +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( mp_type_int, MP_QSTR_int, - MP_TYPE_FLAG_NONE, + MP_TYPE_FLAG_PRINT_JSON, make_new, mp_obj_int_make_new, print, mp_obj_int_print, unary_op, mp_obj_int_unary_op, diff --git a/py/objlist.c b/py/objlist.c index 475002239ca7..2c1545d87771 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -485,10 +485,11 @@ static const mp_rom_map_elem_t list_locals_dict_table[] = { static MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table); +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( mp_type_list, MP_QSTR_list, - MP_TYPE_FLAG_ITER_IS_GETITER, + MP_TYPE_FLAG_ITER_IS_GETITER | MP_TYPE_FLAG_PRINT_JSON, make_new, mp_obj_list_make_new, print, list_print, unary_op, list_unary_op, diff --git a/py/objnone.c b/py/objnone.c index a8ce8ebfedf8..1e2016abd9fb 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -43,10 +43,11 @@ static void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ } } +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( mp_type_NoneType, MP_QSTR_NoneType, - MP_TYPE_FLAG_NONE, + MP_TYPE_FLAG_PRINT_JSON, print, none_print ); diff --git a/py/objstr.c b/py/objstr.c index 0b2517197a0b..342affb514dd 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2203,10 +2203,11 @@ MP_DEFINE_CONST_DICT_WITH_SIZE(mp_obj_memoryview_locals_dict, #if !MICROPY_PY_BUILTINS_STR_UNICODE static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( mp_type_str, MP_QSTR_str, - MP_TYPE_FLAG_NONE, + MP_TYPE_FLAG_PRINT_JSON, make_new, mp_obj_str_make_new, print, str_print, binary_op, mp_obj_str_binary_op, diff --git a/py/objstrunicode.c b/py/objstrunicode.c index 203d3858e60d..a158b9123658 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -236,10 +236,11 @@ static mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( mp_type_str, MP_QSTR_str, - MP_TYPE_FLAG_ITER_IS_GETITER, + MP_TYPE_FLAG_ITER_IS_GETITER | MP_TYPE_FLAG_PRINT_JSON, make_new, mp_obj_str_make_new, print, uni_print, unary_op, uni_unary_op, diff --git a/py/objtuple.c b/py/objtuple.c index afa80799af58..ec1545abb84e 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -232,10 +232,11 @@ static const mp_rom_map_elem_t tuple_locals_dict_table[] = { static MP_DEFINE_CONST_DICT(tuple_locals_dict, tuple_locals_dict_table); +// CIRCUITPY-CHANGE: Diagnose json.dump on invalid types MP_DEFINE_CONST_OBJ_TYPE( mp_type_tuple, MP_QSTR_tuple, - MP_TYPE_FLAG_ITER_IS_GETITER, + MP_TYPE_FLAG_ITER_IS_GETITER | MP_TYPE_FLAG_PRINT_JSON, make_new, mp_obj_tuple_make_new, print, mp_obj_tuple_print, unary_op, mp_obj_tuple_unary_op, diff --git a/tests/extmod/json_dumps_extra.py b/tests/extmod/json_dumps_extra.py index 9074416a99d9..a410b0ee0ef6 100644 --- a/tests/extmod/json_dumps_extra.py +++ b/tests/extmod/json_dumps_extra.py @@ -1,9 +1,6 @@ # test uPy json behaviour that's not valid in CPy - -try: - import json -except ImportError: - print("SKIP") - raise SystemExit +# CIRCUITPY-CHANGE: This behavior matches CPython +print("SKIP") +raise SystemExit print(json.dumps(b"1234")) From e443f176f1e9c26b8b784fdd690fba234c4cad1b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 4 Nov 2024 09:54:57 -0600 Subject: [PATCH 191/252] fix yaml syntax error --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7cc8d49a4efb..7d37baebdc15 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -68,7 +68,7 @@ jobs: - name: Set head sha (pull) if: github.event_name == 'pull_request' env: - HEAD_SHA:${{ github.event.pull_request.head.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: echo "HEAD_SHA=$HEAD_SHA" >> $GITHUB_ENV - name: Set base sha (pull) if: github.event_name == 'pull_request' From 53bd93c8f6b106e3559d03f3374c2e8ee6ae4fd0 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 4 Nov 2024 09:56:36 -0600 Subject: [PATCH 192/252] Add basic block biquad test --- tests/circuitpython/synthio_block_biquad.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/circuitpython/synthio_block_biquad.py diff --git a/tests/circuitpython/synthio_block_biquad.py b/tests/circuitpython/synthio_block_biquad.py new file mode 100644 index 000000000000..69a783a3c825 --- /dev/null +++ b/tests/circuitpython/synthio_block_biquad.py @@ -0,0 +1,16 @@ +from synthnotehelper import * +from synthio import BlockBiquad, FilterType +import random + +random.seed(41) + +white_noise = array.array('h', [random.randint(-32000, 32000) for i in range(600)]) + +@synth_test_rms +def gen(synth): + l = LFO(sweep, offset=1440, scale=2880, rate=.025, once=True) + yield [l] + b = BlockBiquad(FilterType.LOW_PASS, l) + n = Note(100, filter=b, waveform=white_noise) + synth.press(n) + yield 20 From ce3e83d47448e22bd04da2224c079cd3d57814ac Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Mon, 4 Nov 2024 11:13:04 -0600 Subject: [PATCH 193/252] Update `ring_frequency` and `ring_bend` with `MP_ARG_KW_ONLY`. --- shared-bindings/synthio/Note.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index 60ebbff3a2ae..f46bef9f510a 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -24,8 +24,8 @@ static const mp_arg_t note_properties[] = { { MP_QSTR_waveform_loop_end, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, { MP_QSTR_envelope, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, - { MP_QSTR_ring_frequency, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, - { MP_QSTR_ring_bend, MP_ARG_OBJ, {.u_obj = MP_ROM_INT(0) } }, + { MP_QSTR_ring_frequency, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, + { MP_QSTR_ring_bend, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_ring_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_NONE } }, { MP_QSTR_ring_waveform_loop_start, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(0) } }, { MP_QSTR_ring_waveform_loop_end, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_ROM_INT(SYNTHIO_WAVEFORM_SIZE) } }, From dfe9836e352e745c561dfbafddf9dcad962fd63e Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Mon, 4 Nov 2024 11:25:51 -0600 Subject: [PATCH 194/252] Update loop docstrings to demonstrate `BlockInput` implementation. --- shared-bindings/synthio/Note.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/shared-bindings/synthio/Note.c b/shared-bindings/synthio/Note.c index f46bef9f510a..9e588edefd1a 100644 --- a/shared-bindings/synthio/Note.c +++ b/shared-bindings/synthio/Note.c @@ -203,9 +203,7 @@ MP_PROPERTY_GETSET(synthio_note_waveform_obj, //| waveform_loop_start: BlockInput //| """The sample index of where to begin looping waveform data. //| -//| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`. -//| -//| Values greater than or equal to the actual waveform length are treated as 0.""" +//| The value is limited to the range ``0`` to ``len(waveform)-1`` (inclusive).""" static mp_obj_t synthio_note_get_waveform_loop_start(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); return common_hal_synthio_note_get_waveform_loop_start(self); @@ -225,9 +223,7 @@ MP_PROPERTY_GETSET(synthio_note_waveform_loop_start_obj, //| waveform_loop_end: BlockInput //| """The sample index of where to end looping waveform data. //| -//| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`. -//| -//| If the value is greater than the actual waveform length, or less than or equal to the loop start, the loop will occur at the end of the waveform. +//| The value is limited to the range ``waveform_loop_start+1`` to ``len(waveform)`` (inclusive). //| //| Use the `synthio.waveform_max_length` constant to set the loop point at the end of the wave form, no matter its length.""" //| @@ -336,9 +332,7 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_obj, //| ring_waveform_loop_start: BlockInput //| """The sample index of where to begin looping waveform data. //| -//| Values outside the range ``0`` to ``waveform_max_length-1`` (inclusive) are rejected with a `ValueError`. -//| -//| Values greater than or equal to the actual waveform length are treated as 0.""" +//| The value is limited to the range ``0`` to ``len(ring_waveform)-1`` (inclusive).""" static mp_obj_t synthio_note_get_ring_waveform_loop_start(mp_obj_t self_in) { synthio_note_obj_t *self = MP_OBJ_TO_PTR(self_in); return common_hal_synthio_note_get_ring_waveform_loop_start(self); @@ -358,9 +352,7 @@ MP_PROPERTY_GETSET(synthio_note_ring_waveform_loop_start_obj, //| ring_waveform_loop_end: BlockInput //| """The sample index of where to end looping waveform data. //| -//| Values outside the range ``1`` to ``waveform_max_length`` (inclusive) are rejected with a `ValueError`. -//| -//| If the value is greater than the actual waveform length, or less than or equal to the loop start, the loop will occur at the end of the waveform. +//| The value is limited to the range ``ring_waveform_loop_start+1`` to ``len(ring_waveform)`` (inclusive). //| //| Use the `synthio.waveform_max_length` constant to set the loop point at the end of the wave form, no matter its length.""" //| From a3d7eb6b0434bb473f7a6b5bf115b2ae49924f80 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 4 Nov 2024 12:05:55 -0600 Subject: [PATCH 195/252] fix tests & add expected results --- tests/circuitpython/synthio_block_biquad.py | 4 +- .../circuitpython/synthio_block_biquad.py.exp | 640 ++++++++++++++++++ 2 files changed, 642 insertions(+), 2 deletions(-) create mode 100644 tests/circuitpython/synthio_block_biquad.py.exp diff --git a/tests/circuitpython/synthio_block_biquad.py b/tests/circuitpython/synthio_block_biquad.py index 69a783a3c825..f7ec7c38d5c6 100644 --- a/tests/circuitpython/synthio_block_biquad.py +++ b/tests/circuitpython/synthio_block_biquad.py @@ -1,5 +1,5 @@ from synthnotehelper import * -from synthio import BlockBiquad, FilterType +from synthio import BlockBiquad, FilterMode import random random.seed(41) @@ -10,7 +10,7 @@ def gen(synth): l = LFO(sweep, offset=1440, scale=2880, rate=.025, once=True) yield [l] - b = BlockBiquad(FilterType.LOW_PASS, l) + b = BlockBiquad(FilterMode.LOW_PASS, l) n = Note(100, filter=b, waveform=white_noise) synth.press(n) yield 20 diff --git a/tests/circuitpython/synthio_block_biquad.py.exp b/tests/circuitpython/synthio_block_biquad.py.exp new file mode 100644 index 000000000000..0a4c854ab27a --- /dev/null +++ b/tests/circuitpython/synthio_block_biquad.py.exp @@ -0,0 +1,640 @@ +0.0 0.5233163941292499 -1435.412246704102 +0.03125 0.5888741116989962 -1430.912384033203 +0.0625 0.5513501362374322 -1426.412521362305 +0.09375 0.5533979914194288 -1421.912658691406 +0.125 0.5398571609561279 -1417.412796020508 +0.15625 0.5468367798735001 -1412.912933349609 +0.1875 0.5634925509027698 -1408.413070678711 +0.21875 0.5645661363583713 -1403.913208007813 +0.25 0.5549288487251397 -1399.413345336914 +0.28125 0.5838228624458941 -1394.913482666016 +0.3125 0.5854923148763805 -1390.413619995117 +0.34375 0.5431788385492597 -1385.913757324219 +0.375 0.5970661628380437 -1381.41389465332 +0.40625 0.5555455655995383 -1376.914031982422 +0.4375 0.5928591556206007 -1372.414169311523 +0.46875 0.5813652534873269 -1367.914306640625 +0.5 0.545093375939561 -1363.414443969727 +0.53125 0.5440081666013258 -1358.914581298828 +0.5625 0.5613578721915968 -1354.41471862793 +0.59375 0.5373168087762234 -1349.914855957031 +0.625 0.5821319953822574 -1345.414993286133 +0.65625 0.5556490959021101 -1340.915130615234 +0.6875 0.5872875243764462 -1336.415267944336 +0.71875 0.5806883993533669 -1331.915405273438 +0.75 0.5852815758110332 -1327.415542602539 +0.78125 0.5703388819148339 -1322.915679931641 +0.8125 0.5759793425661491 -1318.415817260742 +0.84375 0.5508243231539421 -1313.915954589844 +0.875 0.560820014468103 -1309.416091918945 +0.90625 0.5421378527391773 -1304.916229248047 +0.9375 0.5420010042238626 -1300.416366577148 +0.96875 0.5491701137529543 -1295.91650390625 +1.0 0.5608312495809731 -1291.416641235352 +1.03125 0.5568380740898306 -1286.916778564453 +1.0625 0.5442811106044603 -1282.416915893555 +1.09375 0.5600122444984227 -1277.917053222656 +1.125 0.5758360307668417 -1273.417190551758 +1.15625 0.548131284515931 -1268.917327880859 +1.1875 0.5510493976289011 -1264.41746520996 +1.21875 0.5776113626962765 -1259.917602539063 +1.25 0.5470687072188508 -1255.417739868164 +1.28125 0.5650406419917773 -1250.917877197266 +1.3125 0.5860837091378376 -1246.418014526367 +1.34375 0.5720454282655103 -1241.918151855469 +1.375 0.5682908808089936 -1237.41828918457 +1.40625 0.5565669034789931 -1232.918426513672 +1.4375 0.5225427569415927 -1228.418563842773 +1.46875 0.528656799922158 -1223.918701171875 +1.5 0.5388063364749288 -1219.418838500977 +1.53125 0.5568995892348234 -1214.918975830078 +1.5625 0.5538175590768109 -1210.41911315918 +1.59375 0.5584539013258073 -1205.919250488281 +1.625 0.5497393833455019 -1201.419387817383 +1.65625 0.542731624632793 -1196.919525146485 +1.6875 0.5717515951534967 -1192.419662475586 +1.71875 0.5670740525571515 -1187.919799804688 +1.75 0.5661384126400268 -1183.41993713379 +1.78125 0.5499975057148479 -1178.920074462891 +1.8125 0.5319799725055219 -1174.420211791993 +1.84375 0.5530230503761957 -1169.920349121094 +1.875 0.5634698591133656 -1165.420486450196 +1.90625 0.5470904117219204 -1160.920623779297 +1.9375 0.5462323074916723 -1156.420761108398 +1.96875 0.5186497350082877 -1151.9208984375 +2.0 0.5524974140870907 -1147.421035766602 +2.03125 0.5684251638259989 -1142.921173095704 +2.0625 0.5373369141277137 -1138.421310424805 +2.09375 0.5623155902535638 -1133.921447753906 +2.125 0.5151661907370962 -1129.421585083008 +2.15625 0.5249581930617114 -1124.92172241211 +2.1875 0.5817756160077248 -1120.421859741211 +2.21875 0.5611413205776463 -1115.921997070313 +2.25 0.5991850139596161 -1111.422134399415 +2.28125 0.6042035347204486 -1106.922271728516 +2.3125 0.5513687575596959 -1102.422409057618 +2.34375 0.5568562879220313 -1097.922546386719 +2.375 0.5545761375854527 -1093.422683715821 +2.40625 0.5243707673660577 -1088.922821044922 +2.4375 0.5801785537954141 -1084.422958374024 +2.46875 0.562707323195996 -1079.923095703125 +2.5 0.595908131259724 -1075.423233032227 +2.53125 0.5725333638693439 -1070.923370361329 +2.5625 0.5434214559798377 -1066.42350769043 +2.59375 0.5462209512439381 -1061.923645019532 +2.625 0.56504689595266 -1057.423782348633 +2.65625 0.5583379851037877 -1052.923919677735 +2.6875 0.5504754345671578 -1048.424057006837 +2.71875 0.5540173423293693 -1043.924194335938 +2.75 0.5569208544474369 -1039.42433166504 +2.78125 0.5485128805906287 -1034.924468994141 +2.8125 0.5402199679595928 -1030.424606323243 +2.84375 0.5891253549156891 -1025.924743652345 +2.875 0.5413469679319655 -1021.424880981446 +2.90625 0.5621087907587169 -1016.925018310548 +2.9375 0.5809697135256842 -1012.425155639649 +2.96875 0.5412814012283086 -1007.925292968751 +3.0 0.5634686024733107 -1003.425430297852 +3.03125 0.5125218500024266 -998.9255676269536 +3.0625 0.5593353988827886 -994.4257049560556 +3.09375 0.573363079810572 -989.9258422851567 +3.125 0.5874805194410147 -985.4259796142587 +3.15625 0.5575262864848901 -980.9261169433603 +3.1875 0.5682703663517215 -976.4262542724618 +3.21875 0.5529682773272279 -971.9263916015634 +3.25 0.5788602199430506 -967.4265289306654 +3.28125 0.5699266266203952 -962.9266662597665 +3.3125 0.5508431951087346 -958.4268035888681 +3.34375 0.5545311015714406 -953.9269409179697 +3.375 0.5703749824534138 -949.4270782470712 +3.40625 0.5765930750929544 -944.9272155761732 +3.4375 0.5591865689411526 -940.4273529052743 +3.46875 0.5438688115680163 -935.9274902343764 +3.5 0.5770443322483677 -931.4276275634775 +3.53125 0.5599071331907393 -926.927764892579 +3.5625 0.5737737977946773 -922.4279022216811 +3.59375 0.5869385459050536 -917.9280395507822 +3.625 0.5639195135570374 -913.4281768798842 +3.65625 0.5529386113952421 -908.9283142089857 +3.6875 0.5890100436051251 -904.4284515380868 +3.71875 0.5523201537804379 -899.9285888671889 +3.75 0.5436066445351337 -895.4287261962904 +3.78125 0.5537370310128638 -890.928863525392 +3.8125 0.549814617558703 -886.4290008544936 +3.84375 0.6008523314436754 -881.9291381835951 +3.875 0.5325945534931562 -877.4292755126967 +3.90625 0.5611291614214771 -872.9294128417982 +3.9375 0.5587624222275791 -868.4295501708998 +3.96875 0.5381390146844121 -863.9296875000014 +4.0 0.5631265263936958 -859.4298248291029 +4.03125 0.5560699557405984 -854.9299621582045 +4.0625 0.5754277591982327 -850.4300994873065 +4.09375 0.5915981824253665 -845.9302368164076 +4.125 0.5357680930345895 -841.4303741455092 +4.15625 0.5879893618274627 -836.9305114746107 +4.1875 0.5464188455812566 -832.4306488037123 +4.21875 0.5706438108408328 -827.9307861328143 +4.25 0.5635922796535459 -823.4309234619159 +4.28125 0.5697220610856014 -818.931060791017 +4.3125 0.5517936403744668 -814.4311981201186 +4.34375 0.6004242476521108 -809.9313354492201 +4.375 0.5925180334425226 -805.4314727783221 +4.40625 0.5787811658254868 -800.9316101074237 +4.4375 0.5380560322154883 -796.4317474365248 +4.46875 0.5642541286963015 -791.9318847656264 +4.5 0.5584378411315557 -787.4320220947279 +4.53125 0.5642250866391942 -782.9321594238299 +4.5625 0.5742079044117807 -778.4322967529315 +4.59375 0.5738315641901234 -773.9324340820326 +4.625 0.5461171957884638 -769.4325714111342 +4.65625 0.5533378859109117 -764.9327087402362 +4.6875 0.581344255722229 -760.4328460693378 +4.71875 0.5428141298106971 -755.9329833984393 +4.75 0.5580035009121508 -751.4331207275409 +4.78125 0.5534871016385341 -746.933258056642 +4.8125 0.5578909520468173 -742.433395385744 +4.84375 0.5848112793586618 -737.9335327148456 +4.875 0.583573451167756 -733.4336700439471 +4.90625 0.5708054463460115 -728.9338073730487 +4.9375 0.5651886055827023 -724.4339447021498 +4.96875 0.5525625982940899 -719.9340820312518 +5.0 0.5752696487042543 -715.4342193603534 +5.03125 0.5647695964087438 -710.9343566894549 +5.0625 0.5513871041249724 -706.4344940185565 +5.09375 0.5596974518428355 -701.9346313476576 +5.125 0.5516503097910866 -697.4347686767592 +5.15625 0.5717992890171914 -692.9349060058612 +5.1875 0.5662466697073542 -688.4350433349628 +5.21875 0.5578416082514302 -683.9351806640639 +5.25 0.5583177099904105 -679.4353179931654 +5.28125 0.5624997177639164 -674.935455322267 +5.3125 0.5740358754080997 -670.4355926513686 +5.34375 0.5198447100680302 -665.9357299804701 +5.375 0.5812101373266519 -661.4358673095712 +5.40625 0.5690255464131015 -656.9360046386728 +5.4375 0.5698286073996001 -652.4361419677748 +5.46875 0.5212701389821012 -647.9362792968759 +5.5 0.6008879107808415 -643.4364166259775 +5.53125 0.5354583608110104 -638.9365539550786 +5.5625 0.5659721425363654 -634.4366912841806 +5.59375 0.5508335101466897 -629.9368286132817 +5.625 0.5748322041853707 -625.4369659423833 +5.65625 0.5112195310881697 -620.9371032714853 +5.6875 0.5503257418930935 -616.4372406005864 +5.71875 0.5483893261970563 -611.937377929688 +5.75 0.5586441290230967 -607.4375152587891 +5.78125 0.529618320202 -602.9376525878911 +5.8125 0.5583584354187394 -598.4377899169926 +5.84375 0.5119880230797152 -593.9379272460935 +5.875 0.5685560193282417 -589.4380645751953 +5.90625 0.5662137269319073 -584.9382019042969 +5.9375 0.548174405494183 -580.4383392333984 +5.96875 0.5723998468214697 -575.9384765625002 +6.0 0.5454906289769358 -571.4386138916011 +6.03125 0.5151144863097763 -566.9387512207027 +6.0625 0.5408932263910434 -562.4388885498047 +6.09375 0.5812600815615564 -557.939025878906 +6.125 0.5640642789476607 -553.4391632080074 +6.15625 0.5244641070494527 -548.9393005371087 +6.1875 0.5661904070460153 -544.4394378662105 +6.21875 0.5244075931431626 -539.9395751953118 +6.25 0.5525887404821925 -535.4397125244132 +6.28125 0.5020311692655093 -530.9398498535152 +6.3125 0.5036647252695824 -526.4399871826165 +6.34375 0.5441081599351917 -521.9401245117178 +6.375 0.5501128379371436 -517.4402618408189 +6.40625 0.5584356803834504 -512.940399169921 +6.4375 0.5053175171179443 -508.4405364990225 +6.46875 0.5041253886563949 -503.9406738281236 +6.5 0.5417281294449045 -499.4408111572252 +6.53125 0.5281308297848274 -494.9409484863268 +6.5625 0.55178896455521 -490.4410858154286 +6.59375 0.4901484208544025 -485.9412231445301 +6.625 0.564525485344044 -481.441360473631 +6.65625 0.4792626124438369 -476.9414978027328 +6.6875 0.5228646503684022 -472.4416351318346 +6.71875 0.4933138687761552 -467.9417724609359 +6.75 0.533761220406419 -463.4419097900372 +6.78125 0.5246718953730372 -458.9420471191386 +6.8125 0.5184862456752544 -454.4421844482406 +6.84375 0.534162821911546 -449.9423217773419 +6.875 0.5013670872181356 -445.442459106443 +6.90625 0.5388662152086168 -440.9425964355451 +6.9375 0.5218804778215822 -436.4427337646464 +6.96875 0.5736817891820368 -431.9428710937477 +7.0 0.5295169584694084 -427.4430084228491 +7.03125 0.549346460553386 -422.9431457519509 +7.0625 0.5278099495347873 -418.4432830810526 +7.09375 0.5092380846918898 -413.9434204101535 +7.125 0.4941508140939982 -409.4435577392551 +7.15625 0.5169463569183504 -404.9436950683569 +7.1875 0.4953175790791144 -400.4438323974584 +7.21875 0.516131378541008 -395.94396972656 +7.25 0.5261398073442543 -391.4441070556611 +7.28125 0.5008081946276275 -386.9442443847627 +7.3125 0.5237017380224776 -382.4443817138647 +7.34375 0.5269585850106822 -377.944519042966 +7.375 0.5403925301790693 -373.4446563720671 +7.40625 0.4912870467203073 -368.9447937011685 +7.4375 0.4860205498245958 -364.4449310302705 +7.46875 0.5076678968617992 -359.9450683593718 +7.5 0.5751840851181132 -355.4452056884732 +7.53125 0.5145785285700734 -350.9453430175749 +7.5625 0.5070222400192178 -346.4454803466763 +7.59375 0.5449130006453371 -341.9456176757776 +7.625 0.4998507782411507 -337.4457550048789 +7.65625 0.5012363391565783 -332.945892333981 +7.6875 0.5292675268030196 -328.4460296630825 +7.71875 0.5513583636674681 -323.9461669921836 +7.75 0.5030802143058754 -319.4463043212852 +7.78125 0.4905981840379553 -314.9464416503868 +7.8125 0.5274428911101353 -310.4465789794883 +7.84375 0.546627531334603 -305.9467163085901 +7.875 0.5151010996472523 -301.446853637691 +7.90625 0.4839249262021641 -296.9469909667926 +7.9375 0.5174238046942224 -292.4471282958946 +7.96875 0.5346946445719737 -287.9472656249959 +8.0 0.5313876108222209 -283.4474029540972 +8.03125 0.5095780489919427 -278.9475402831986 +8.0625 0.4911799576606958 -274.4476776123004 +8.09375 0.547494146625657 -269.9478149414017 +8.125 0.5038670653388587 -265.447952270503 +8.15625 0.5285942339808058 -260.9480895996051 +8.1875 0.5329857592119569 -256.4482269287064 +8.21875 0.5119534725212935 -251.9483642578077 +8.25 0.5033797213494831 -247.4485015869091 +8.28125 0.5177132418754256 -242.9486389160109 +8.3125 0.5538903262602162 -238.4487762451124 +8.34375 0.5368218985177576 -233.9489135742135 +8.375 0.5263842343389778 -229.4490509033151 +8.40625 0.5138763360031863 -224.9491882324169 +8.4375 0.5269683356839487 -220.4493255615184 +8.46875 0.5484451242131595 -215.94946289062 +8.5 0.5181561664959421 -211.4496002197211 +8.53125 0.538460254709516 -206.9497375488227 +8.5625 0.5396058249701871 -202.4498748779247 +8.59375 0.5183117701795767 -197.9500122070258 +8.625 0.5331941397833627 -193.4501495361271 +8.65625 0.5446388875727108 -188.9502868652285 +8.6875 0.5417772369865942 -184.4504241943305 +8.71875 0.5223062196070183 -179.9505615234318 +8.75 0.5290697979854333 -175.4506988525332 +8.78125 0.5297126110364021 -170.9508361816349 +8.8125 0.5450719527420691 -166.4509735107363 +8.84375 0.539206064335114 -161.9511108398376 +8.875 0.5272662938292431 -157.4512481689389 +8.90625 0.5374506762705708 -152.951385498041 +8.9375 0.5296481490281893 -148.4515228271425 +8.96875 0.5242848002098146 -143.9516601562434 +9.0 0.5342325745513286 -139.4517974853452 +9.03125 0.5304651103728572 -134.9519348144468 +9.0625 0.534625982617119 -130.4520721435483 +9.09375 0.5388630124495862 -125.9522094726499 +9.125 0.5419169053977618 -121.452346801751 +9.15625 0.5387306344924848 -116.9524841308526 +9.1875 0.5411771554428 -112.4526214599546 +9.21875 0.534663506650105 -107.9527587890559 +9.25 0.5432956058032731 -103.4528961181572 +9.28125 0.5452798871015233 -98.95303344725835 +9.3125 0.5400449469782619 -94.45317077636037 +9.34375 0.5440614233919323 -89.9533081054617 +9.375 0.5323203781216296 -85.45344543456304 +9.40625 0.5430447586723063 -80.95358276366505 +9.4375 0.5446712927539446 -76.45372009276616 +9.46875 0.5459524897592061 -71.9538574218675 +9.5 0.5460639734792513 -67.45399475096883 +9.53125 0.5494256027817332 -62.95413208007085 +9.5625 0.5457119306826957 -58.45426940917241 +9.59375 0.5515349992393668 -53.95440673827352 +9.625 0.5485894873057759 -49.45454406737508 +9.65625 0.5546036928766149 -44.95468139647664 +9.6875 0.5520760480678739 -40.45481872557843 +9.71875 0.5540796441777628 -35.95495605468 +9.75 0.5520483826700068 -31.45509338378088 +9.78125 0.5559964042093331 -26.95523071288267 +9.8125 0.5561241070465571 -22.45536804198446 +9.84375 0.553345490317982 -17.95550537108579 +9.875 0.5604416124584247 -13.45564270018713 +9.90625 0.5593413403554656 -8.955780029288462 +9.9375 0.5608126552225947 -4.455917358390479 +9.96875 0.5575838559074312 0.04394531250841283 +10.0 0.5654348388131066 4.54380798340685 +10.03125 0.5616753470922725 9.043670654305288 +10.0625 0.5639929263984667 13.54353332520373 +10.09375 0.5587586865317684 18.04339599610239 +10.125 0.5734582332480533 22.54325866700106 +10.15625 0.5732497606922596 27.04312133789927 +10.1875 0.5749851529847351 31.54298400879748 +10.21875 0.5802485173239508 36.04284667969637 +10.25 0.5738886067903813 40.54270935059503 +10.28125 0.5802850622636567 45.04257202149324 +10.3125 0.5777911320327425 49.54243469239145 +10.34375 0.5810982716930228 54.04229736329034 +10.375 0.5871746611246479 58.54216003418901 +10.40625 0.5782109696519912 63.04202270508745 +10.4375 0.5892671600317005 67.54188537598566 +10.46875 0.5866793190995349 72.04174804688409 +10.5 0.5845631933863139 76.54161071778299 +10.53125 0.5866080651713119 81.04147338868142 +10.5625 0.5816092770763072 85.54133605957986 +10.59375 0.5937762168930567 90.0411987304783 +10.625 0.5911745770284834 94.54106140137696 +10.65625 0.5877656317687221 99.04092407227517 +10.6875 0.5953735471025981 103.5407867431738 +10.71875 0.59160362529701 108.0406494140725 +10.75 0.5962187931680832 112.5405120849709 +10.78125 0.5883415636639483 117.0403747558692 +10.8125 0.5839910949801117 121.5402374267676 +10.84375 0.6010654911818396 126.0401000976665 +10.875 0.5970559532030666 130.5399627685651 +10.90625 0.5940572500168175 135.0398254394634 +10.9375 0.5732606837883286 139.5396881103616 +10.96875 0.5381164603175737 144.0395507812602 +11.0 0.5351711728901959 148.5394134521591 +11.03125 0.5183835078058662 153.0392761230576 +11.0625 0.5780151556478285 157.5391387939558 +11.09375 0.5247987291248501 162.0390014648542 +11.125 0.5425038966652155 166.5388641357529 +11.15625 0.5391587825768379 171.0387268066515 +11.1875 0.5758966434662992 175.5385894775497 +11.21875 0.5488268299762037 180.0384521484484 +11.25 0.5468267934304349 184.5383148193469 +11.28125 0.5296925278012772 189.0381774902453 +11.3125 0.5888686851451086 193.5380401611437 +11.34375 0.5352789347497206 198.0379028320426 +11.375 0.5533386912535877 202.5377655029411 +11.40625 0.5510777323399219 207.0376281738393 +11.4375 0.5869368732055307 211.5374908447377 +11.46875 0.5598609814741869 216.0373535156364 +11.5 0.5584633639894287 220.5372161865353 +11.53125 0.5412643632623084 225.0370788574335 +11.5625 0.6000724464415632 229.5369415283317 +11.59375 0.5465718645508223 234.0368041992303 +11.625 0.564507733573807 238.5366668701292 +11.65625 0.5632366936218962 243.0365295410274 +11.6875 0.598037908932081 247.5363922119257 +11.71875 0.5713189573698724 252.0362548828243 +11.75 0.5701763115892213 256.536117553723 +11.78125 0.5530012621580137 261.0359802246214 +11.8125 0.6114605286286333 265.5358428955199 +11.84375 0.5585243802662351 270.0357055664183 +11.875 0.5759449941332803 274.535568237317 +11.90625 0.5754924828837037 279.0354309082154 +11.9375 0.6092916917219224 283.5352935791138 +11.96875 0.5830561194579957 288.0351562500125 +12.0 0.5820349500078187 292.5350189209112 +12.03125 0.5649457377639776 297.0348815918094 +12.0625 0.6230816110324387 301.5347442627076 +12.09375 0.5709201383977375 306.0346069336065 +12.125 0.5876069042702596 310.5344696045051 +12.15625 0.5878231568638521 315.0343322754034 +12.1875 0.6208411580327887 319.5341949463016 +12.21875 0.5950273927755796 324.0340576172002 +12.25 0.5941588153659908 328.5339202880991 +12.28125 0.5770586958248074 333.0337829589976 +12.3125 0.634979908874035 337.5336456298958 +12.34375 0.5836739789055577 342.0335083007942 +12.375 0.5994445000638317 346.5333709716929 +12.40625 0.6003259429209249 351.0332336425915 +12.4375 0.6326380962952464 355.53309631349 +12.46875 0.6071836598135066 360.0329589843884 +12.5 0.6065060218610247 364.5328216552869 +12.53125 0.5893706914599263 369.0326843261853 +12.5625 0.6467316765872678 373.532546997084 +12.59375 0.5966873599268746 378.0324096679826 +12.625 0.6114690168226161 382.5322723388811 +12.65625 0.6130051754082282 387.0321350097793 +12.6875 0.6445522122006491 391.5319976806777 +12.71875 0.6195674199220667 396.0318603515766 +12.75 0.6190924514029002 400.5317230224753 +12.78125 0.601888235067373 405.0315856933735 +12.8125 0.6586365836569614 409.5314483642717 +12.84375 0.6098974600186474 414.0313110351703 +12.875 0.6236866064045412 418.5311737060692 +12.90625 0.6259159416467512 423.0310363769676 +12.9375 0.6566082212735398 427.5308990478658 +12.96875 0.6321466527481859 432.0307617187643 +13.0 0.6318346606972041 436.530624389663 +13.03125 0.614599313654773 441.0304870605615 +13.0625 0.6705283273461649 445.53034973146 +13.09375 0.6232986816970667 450.0302124023584 +13.125 0.6361400971100881 454.530075073257 +13.15625 0.6389446712306796 459.0299377441554 +13.1875 0.6686892707573188 463.5298004150538 +13.21875 0.6449864346003898 468.0296630859526 +13.25 0.6442914315668125 472.5295257568512 +13.28125 0.6272181360738232 477.0293884277494 +13.3125 0.6819845711375629 481.5292510986477 +13.34375 0.6368909041192503 486.0291137695466 +13.375 0.6488529681516589 490.5289764404453 +13.40625 0.6517436895129136 495.0288391113435 +13.4375 0.680690254581632 499.5287017822417 +13.46875 0.6580798929597741 504.0285644531403 +13.5 0.6568191976912985 508.5284271240392 +13.53125 0.6399436106511786 513.0282897949376 +13.5625 0.6933983577448943 517.5281524658358 +13.59375 0.6504292030516948 522.0280151367343 +13.625 0.6616640063279428 526.5278778076331 +13.65625 0.6645837368471335 531.0277404785315 +13.6875 0.6930362416315237 535.52760314943 +13.71875 0.6710562161167619 540.0274658203285 +13.75 0.6692539959116338 544.527328491227 +13.78125 0.6526921990411808 549.0271911621254 +13.8125 0.5145585911644841 553.527053833024 +13.84375 0.108799138638648 558.0269165039226 +13.875 0.08959367900381817 562.5267791748212 +13.90625 0.1070956643554223 567.0266418457194 +13.9375 0.1087724263648484 571.5265045166177 +13.96875 0.1106221411380315 576.0263671875166 +14.0 0.1134255133002185 580.5262298584153 +14.03125 0.1083000649330917 585.0260925293135 +14.0625 0.1144187792980931 589.5259552002117 +14.09375 0.1129808309621203 594.0258178711105 +14.125 0.09235243262500717 598.5256805420092 +14.15625 0.1099638007181997 603.0255432129077 +14.1875 0.1116974135793035 607.5254058838059 +14.21875 0.1145665008050144 612.0252685547043 +14.25 0.1164288467215701 616.5251312256031 +14.28125 0.1110493652205335 621.0249938965017 +14.3125 0.1168054416225558 625.5248565674 +14.34375 0.1168780477017844 630.0247192382985 +14.375 0.09512653014879378 634.5245819091971 +14.40625 0.1126620735370587 639.0244445800954 +14.4375 0.1146116668047789 643.524307250994 +14.46875 0.1183433183805806 648.0241699218926 +14.5 0.1192721157687402 652.5240325927912 +14.53125 0.1136771259979949 657.0238952636894 +14.5625 0.1191846903025063 661.5237579345878 +14.59375 0.1205410669858625 666.0236206054866 +14.625 0.09789373366721922 670.5234832763853 +14.65625 0.1152428871949321 675.0233459472836 +14.6875 0.1175161720598944 679.5232086181818 +14.71875 0.1219851247552673 684.0230712890805 +14.75 0.1219363210636846 688.5229339599792 +14.78125 0.1161924384899548 693.0227966308777 +14.8125 0.121613092822123 697.5226593017759 +14.84375 0.1239764518385377 702.0225219726744 +14.875 0.1006275983059951 706.5223846435731 +14.90625 0.1176704324771989 711.0222473144717 +14.9375 0.1204391753000987 715.52210998537 +14.96875 0.1255068643761589 720.0219726562685 +15.0 0.1244675562062874 724.5218353271671 +15.03125 0.1185906869307071 729.0216979980654 +15.0625 0.1240443938607149 733.521560668964 +15.09375 0.1272077423687175 738.0214233398626 +15.125 0.1033825383248399 742.5212860107612 +15.15625 0.1200114946440536 747.0211486816594 +15.1875 0.1233097800113023 751.5210113525578 +15.21875 0.1288641310828331 756.0208740234566 +15.25 0.1268875297914646 760.5207366943554 +15.28125 0.12087960596437 765.0205993652536 +15.3125 0.1264902986426788 769.5204620361518 +15.34375 0.1302217830538807 774.0203247070505 +15.375 0.1061117949192766 778.5201873779494 +15.40625 0.1222651837998628 783.0200500488477 +15.4375 0.1262036556506407 787.5199127197459 +15.46875 0.1321358868554278 792.0197753906444 +15.5 0.129238051588965 796.5196380615431 +15.53125 0.1230846180806053 801.0195007324417 +15.5625 0.1289600670941163 805.5193634033401 +15.59375 0.1330455097028878 810.0192260742385 +15.625 0.108769962921361 814.5190887451371 +15.65625 0.1244433321273532 819.0189514160355 +15.6875 0.1290258830403304 823.5188140869341 +15.71875 0.1352370036459023 828.0186767578327 +15.75 0.1314671437798762 832.5185394287313 +15.78125 0.1252368151393506 837.0184020996295 +15.8125 0.131441815952481 841.5182647705278 +15.84375 0.1357299574910208 846.0181274414267 +15.875 0.1113932434078271 850.5179901123254 +15.90625 0.1265361742193656 855.0178527832236 +15.9375 0.1318612186764555 859.5177154541218 +15.96875 0.1382446377482632 864.0175781250205 +16.0 0.1336759098607705 868.5174407959194 +16.03125 0.1273188319543719 873.0173034668177 +16.0625 0.1338980911212611 877.5171661377159 +16.09375 0.1382577621198477 882.0170288086144 +16.125 0.1139611850833507 886.5168914795131 +16.15625 0.1285969599331371 891.0167541504117 +16.1875 0.1346292697549597 895.5166168213101 +16.21875 0.1411076553823318 900.0164794922086 +16.25 0.1357901651555739 904.5163421631071 +16.28125 0.1293759308741255 909.0162048340055 +16.3125 0.1363674152928493 913.5160675049041 +16.34375 0.1406635128826926 918.0159301758027 +16.375 0.1164584394285753 922.5157928467013 +16.40625 0.1306157686432045 927.0156555175995 +16.4375 0.1373575035236127 931.5155181884979 +16.46875 0.1438759717421607 936.0153808593967 +16.5 0.1378728348873188 940.5152435302954 +16.53125 0.1313814762854565 945.0151062011936 +16.5625 0.1388294166832878 949.5149688720919 +16.59375 0.1429608054928704 954.0148315429906 +16.625 0.1188718755744542 958.5146942138894 +16.65625 0.1325990755893989 963.0145568847877 +16.6875 0.1400444821126768 967.5144195556859 +16.71875 0.146553881491509 972.0142822265846 +16.75 0.1399013059023452 976.5141448974832 +16.78125 0.1333688628257788 981.0140075683817 +16.8125 0.1412684645777973 985.5138702392801 +16.84375 0.1451646202140146 990.0137329101786 +16.875 0.1212109486603593 994.5135955810772 +16.90625 0.1345537723711169 999.0134582519755 +16.9375 0.1426904521953445 1003.513320922874 +16.96875 0.1491053051026527 1008.013183593773 +17.0 0.1418836982030045 1012.513046264671 +17.03125 0.1353621949607738 1017.012908935569 +17.0625 0.1436714338847207 1021.512771606468 +17.09375 0.1472982320063139 1026.012634277367 +17.125 0.1234753641227667 1030.512496948265 +17.15625 0.1365078164779559 1035.012359619164 +17.1875 0.1452920070879705 1039.512222290062 +17.21875 0.1515845901806397 1044.012084960961 +17.25 0.1438121245070723 1048.511947631859 +17.28125 0.1373257469191369 1053.011810302758 +17.3125 0.1460464635695965 1057.511672973656 +17.34375 0.1493487989834957 1062.011535644554 +17.375 0.1256713638206061 1066.511398315453 +17.40625 0.1384370178025034 1071.011260986352 +17.4375 0.1478343935958201 1075.51112365725 +17.46875 0.1539753906613792 1080.010986328149 +17.5 0.1457186058778294 1084.510848999047 +17.53125 0.1392901345579448 1089.010711669946 +17.5625 0.1483755109702189 1093.510574340844 +17.59375 0.1513463560457777 1098.010437011743 +17.625 0.1277705208353705 1102.510299682641 +17.65625 0.1403609732609399 1107.010162353539 +17.6875 0.1503210383547008 1111.510025024438 +17.71875 0.1562963809432098 1116.009887695337 +17.75 0.1475940413340046 1120.509750366235 +17.78125 0.1412528178631917 1125.009613037134 +17.8125 0.1506783240915595 1129.509475708032 +17.84375 0.1533055765365748 1134.009338378931 +17.875 0.1298077032152436 1138.509201049829 +17.90625 0.1422863915151054 1143.009063720728 +17.9375 0.1527476100657249 1147.508926391626 +17.96875 0.1585159083042 1152.008789062525 +18.0 0.1494341322857593 1156.508651733423 +18.03125 0.1432015539256189 1161.008514404322 +18.0625 0.1529348284731086 1165.50837707522 +18.09375 0.1552267558286024 1170.008239746119 +18.125 0.1317910699193585 1174.508102417017 +18.15625 0.1442192159649347 1179.007965087916 +18.1875 0.1551209608447591 1183.507827758814 +18.21875 0.1606807400708936 1188.007690429713 +18.25 0.1512314509665016 1192.507553100611 +18.28125 0.1451804195486575 1197.00741577151 +18.3125 0.1551359587623907 1201.507278442408 +18.34375 0.1571089814136766 1206.007141113307 +18.375 0.1337031293002361 1210.507003784206 +18.40625 0.1461368038403368 1215.006866455104 +18.4375 0.1574608183547282 1219.506729126002 +18.46875 0.1627737158145106 1224.006591796901 +18.5 0.1530236451343935 1228.506454467799 +18.53125 0.1471417794018446 1233.006317138698 +18.5625 0.1573060260229136 1237.506179809596 +18.59375 0.15896897913816 1242.006042480495 +18.625 0.1355600881678751 1246.505905151393 +18.65625 0.1480584372175698 1251.005767822292 +18.6875 0.1597602232805594 1255.50563049319 +18.71875 0.1647843002499096 1260.005493164089 +18.75 0.154795575289511 1264.505355834987 +18.78125 0.1491040672771789 1269.005218505886 +18.8125 0.1594358006329524 1273.505081176784 +18.84375 0.1608213788331513 1278.004943847683 +18.875 0.1373690815850701 1282.504806518581 +18.90625 0.1499994670079943 1287.00466918948 +18.9375 0.1620018993075552 1291.504531860378 +18.96875 0.1667401200106168 1296.004394531277 +19.0 0.1565241117081126 1300.504257202175 +19.03125 0.1510690468537137 1305.004119873074 +19.0625 0.1615109581846284 1309.503982543972 +19.09375 0.1626530516578939 1314.003845214871 +19.125 0.1391312982048554 1318.503707885769 +19.15625 0.151919662057496 1323.003570556668 +19.1875 0.1641978171209087 1327.503433227566 +19.21875 0.1686452485539238 1332.003295898465 +19.25 0.1582725315945457 1336.503158569363 +19.28125 0.1530360931041787 1341.003021240262 +19.3125 0.1635578813907874 1345.50288391116 +19.34375 0.1644948243532116 1350.002746582059 +19.375 0.1408611046153436 1354.502609252957 +19.40625 0.1538427847796541 1359.002471923856 +19.4375 0.1663685486438876 1363.502334594754 +19.46875 0.1704761147471038 1368.002197265653 +19.5 0.1599699794273519 1372.502059936551 +19.53125 0.1550181083978423 1377.00192260745 +19.5625 0.1655651615001207 1381.501785278348 +19.59375 0.1663309418141449 1386.001647949247 +19.625 0.1425702307382188 1390.501510620146 +19.65625 0.1557541316319879 1395.001373291044 +19.6875 0.1685153264700657 1399.501235961942 +19.71875 0.1722438810866091 1404.001098632841 +19.75 0.161674402461118 1408.50096130374 +19.78125 0.1569821598878027 1413.000823974638 +19.8125 0.1675501695895054 1417.500686645536 +19.84375 0.1681815453936252 1422.000549316435 +19.875 0.1442381996598139 1426.500411987333 +19.90625 0.1576679614425247 1431.000274658232 +19.9375 0.1706214070347111 1435.50013732913 +19.96875 0.1739651242968984 1440.000000000029 From 20dc44dc3ac7cd69ab88404111c2694e62950a74 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 4 Nov 2024 12:18:09 -0600 Subject: [PATCH 196/252] more yaml syntax fixes --- .github/workflows/build-mpy-cross.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-mpy-cross.yml b/.github/workflows/build-mpy-cross.yml index 731cb8661f6d..831ad3082275 100644 --- a/.github/workflows/build-mpy-cross.yml +++ b/.github/workflows/build-mpy-cross.yml @@ -59,8 +59,8 @@ jobs: - name: Set output env: - EX=${{ env[format('EX_{0}', matrix.mpy-cross)] || matrix.mpy-cross }} - OS=${{ env[format('OS_{0}', matrix.mpy-cross)] }}" + EX: ${{ env[format('EX_{0}', matrix.mpy-cross)] || matrix.mpy-cross }} + OS: ${{ env[format('OS_{0}', matrix.mpy-cross)] }}" run: | echo >> $GITHUB_ENV "EX=$EX" echo >> $GITHUB_ENV "OS=$OS" From fd24006901c06236f1e7771cc9e6aaf772a4bb18 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Mon, 4 Nov 2024 13:33:16 -0600 Subject: [PATCH 197/252] Updated expected results for synthesizer_note test. --- tests/circuitpython/synthesizer_note.py.exp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/circuitpython/synthesizer_note.py.exp b/tests/circuitpython/synthesizer_note.py.exp index 43d07e5e7da9..7417a4c8a19f 100644 --- a/tests/circuitpython/synthesizer_note.py.exp +++ b/tests/circuitpython/synthesizer_note.py.exp @@ -1,10 +1,10 @@ () [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] -(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0, waveform_loop_end=16384, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0, ring_waveform_loop_end=16384),) +(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0.0, waveform_loop_end=16384.0, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0.0, ring_waveform_loop_end=16384.0),) [-16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383] -(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0, waveform_loop_end=16384, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0, ring_waveform_loop_end=16384), Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0, waveform_loop_end=16384, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0, ring_waveform_loop_end=16384)) +(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0.0, waveform_loop_end=16384.0, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0.0, ring_waveform_loop_end=16384.0), Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0.0, waveform_loop_end=16384.0, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0.0, ring_waveform_loop_end=16384.0)) [-1, -1, -1, -1, -1, -1, -1, -1, 28045, -1, -1, -1, -1, -28046, -1, -1, -1, -1, 28045, -1, -1, -1, -1, -28046] -(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0, waveform_loop_end=16384, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0, ring_waveform_loop_end=16384),) +(Note(frequency=830.6076004423605, panning=0.0, amplitude=1.0, bend=0.0, waveform=None, waveform_loop_start=0.0, waveform_loop_end=16384.0, envelope=None, filter=None, ring_frequency=0.0, ring_bend=0.0, ring_waveform=None, ring_waveform_loop_start=0.0, ring_waveform_loop_end=16384.0),) [-1, -1, -1, 28045, -1, -1, -1, -1, -1, -1, -1, -1, 28045, -1, -1, -1, -1, -28046, -1, -1, -1, -1, 28045, -1] (-5242, 5241) (-10485, 10484) From e1059151403ce37eb50d789c9405326523518fe8 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 4 Nov 2024 18:29:46 -0600 Subject: [PATCH 198/252] mbedtls: avoid function that only exists on rp2040 rp2350 doesn't have the same RTC peripheral as the 2040 (let alone other family micros) this has the side effect of obeying a different timesource if one has been configured. --- lib/mbedtls_config/mbedtls_port.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/mbedtls_config/mbedtls_port.c b/lib/mbedtls_config/mbedtls_port.c index 73929c85e81e..b7e8ceae5de0 100644 --- a/lib/mbedtls_config/mbedtls_port.c +++ b/lib/mbedtls_config/mbedtls_port.c @@ -27,15 +27,13 @@ #if CIRCUITPY_SSL_MBEDTLS +#include "py/runtime.h" #include "mbedtls_config.h" #include "mbedtls/entropy_poll.h" -#include "hardware/rtc.h" #include "shared/timeutils/timeutils.h" #include "shared-bindings/os/__init__.h" - -#include "hardware/rtc.h" -#include "shared/timeutils/timeutils.h" +#include "shared-bindings/time/__init__.h" extern uint8_t rosc_random_u8(size_t cycles); @@ -46,9 +44,10 @@ int mbedtls_hardware_poll(void *data, unsigned char *output, size_t len, size_t } time_t rp2_rtctime_seconds(time_t *timer) { - datetime_t t; - rtc_get_datetime(&t); - return timeutils_seconds_since_epoch(t.year, t.month, t.day, t.hour, t.min, t.sec); + mp_obj_t datetime = mp_load_attr(MP_STATE_VM(rtc_time_source), MP_QSTR_datetime); + timeutils_struct_time_t tm; + struct_time_to_tm(datetime, &tm); + return timeutils_seconds_since_epoch(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); } #endif From 0aab00d7e571e3d2b882cf7da240d1bdcb4b4f1e Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 5 Nov 2024 08:41:23 -0600 Subject: [PATCH 199/252] Fix 16-bit unsigned integer silence within audio effects. --- shared-module/audiodelays/Echo.c | 5 ++++- shared-module/audiofilters/Filter.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index 3f45162cb5e9..a0c34c6540d8 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -342,7 +342,10 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * } else { // For unsigned samples set to the middle which is "quiet" if (MP_LIKELY(self->bits_per_sample == 16)) { - memset(word_buffer, 32768, length * (self->bits_per_sample / 8)); + uint16_t *uword_buffer = (uint16_t *)word_buffer; + while (length--) { + *uword_buffer++ = 32768; + } } else { memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); } diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index 47032fd46dfe..d7ee30e8ea66 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -246,7 +246,10 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o } else { // For unsigned samples set to the middle which is "quiet" if (MP_LIKELY(self->bits_per_sample == 16)) { - memset(word_buffer, 32768, length * (self->bits_per_sample / 8)); + uint16_t *uword_buffer = (uint16_t *)word_buffer; + while (length--) { + *uword_buffer++ = 32768; + } } else { memset(hword_buffer, 128, length * (self->bits_per_sample / 8)); } From 14b1383b6b03c672942f2a5d096b2ad878a2133e Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Tue, 5 Nov 2024 08:47:24 -0600 Subject: [PATCH 200/252] Remove trailing whitespace to fix pre-commit. --- shared-module/audiofilters/Filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index ed53f7fce834..e22133a25b61 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -65,7 +65,7 @@ void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, } self->filters = filters; reset_filter_states(self); - + // If we did not receive a BlockInput we need to create a default float value if (mix == MP_OBJ_NULL) { mix = mp_obj_new_float(1.0); From f8afdcb72924d0d3ca7e76669d2156d18e07bec1 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 5 Nov 2024 09:36:18 -0600 Subject: [PATCH 201/252] Add audiodelays & audioeffects to unix coverage port .. and add a very basic audioeffects test, showing that it plausibly is working I had to address several build errors that occurred in the Unix build, mostly related to conversion from FP types to integral types (replaced by explicit casts) and by accidental mixing of regular & f-suffixed floating constants (replaced with the MICROPY_FLOAT_CONST macro) Particularly this change could use consideration: ```diff - self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * sizeof(uint16_t)); // bytes + self->max_echo_buffer_len = (uint32_t)(self->sample_rate / 1000.0f * max_delay_ms) * (self->channel_count * sizeof(uint16_t)); // bytes ``` The buffer length is being calculated in floating point based on the millisecond delay & the sample rate. The result could then be a fractional number such as 529.2 for a 12ms delay at 44.1kHz. Multiplying a floating number by the size required for each echo buffer item (`(self->channel_count * sizeof(uint16_t))`) could yield a number of bytes that doesn't correspond to an integral number of buffer items. I grouped the float->int conversion so that it converts the number of echo buffer items to an integer and then multiplies by the size of the item. --- .../unix/variants/coverage/mpconfigvariant.mk | 11 + shared-module/audiodelays/Echo.c | 22 +- shared-module/audiofilters/Filter.c | 5 +- tests/circuitpython/audiofilter_filter.py | 16 + tests/circuitpython/audiofilter_filter.py.exp | 1536 +++++++++++++++++ tests/testlib/audiofilterhelper.py | 26 + 6 files changed, 1603 insertions(+), 13 deletions(-) create mode 100644 tests/circuitpython/audiofilter_filter.py create mode 100644 tests/circuitpython/audiofilter_filter.py.exp create mode 100644 tests/testlib/audiofilterhelper.py diff --git a/ports/unix/variants/coverage/mpconfigvariant.mk b/ports/unix/variants/coverage/mpconfigvariant.mk index e250fbe9b2da..80491823e492 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.mk +++ b/ports/unix/variants/coverage/mpconfigvariant.mk @@ -33,6 +33,10 @@ SRC_BITMAP := \ shared-bindings/audiocore/__init__.c \ shared-bindings/audiocore/RawSample.c \ shared-bindings/audiocore/WaveFile.c \ + shared-bindings/audiodelays/Echo.c \ + shared-bindings/audiodelays/__init__.c \ + shared-bindings/audiofilters/Filter.c \ + shared-bindings/audiofilters/__init__.c \ shared-bindings/audiomixer/__init__.c \ shared-bindings/audiomixer/Mixer.c \ shared-bindings/audiomixer/MixerVoice.c \ @@ -70,6 +74,10 @@ SRC_BITMAP := \ shared-module/audiocore/__init__.c \ shared-module/audiocore/RawSample.c \ shared-module/audiocore/WaveFile.c \ + shared-module/audiodelays/Echo.c \ + shared-module/audiodelays/__init__.c \ + shared-module/audiofilters/Filter.c \ + shared-module/audiofilters/__init__.c \ shared-module/audiomixer/__init__.c \ shared-module/audiomp3/MP3Decoder.c \ shared-module/audiomixer/Mixer.c \ @@ -127,6 +135,9 @@ $(BUILD)/lib/mp3/src/buffers.o: CFLAGS += -include "shared-module/audiomp3/__ini CFLAGS += \ -DCIRCUITPY_AESIO=1 \ -DCIRCUITPY_AUDIOCORE=1 \ + -DCIRCUITPY_AUDIOEFFECTS=1 \ + -DCIRCUITPY_AUDIODELAYS=1 \ + -DCIRCUITPY_AUDIOFILTERS=1 \ -DCIRCUITPY_AUDIOMIXER=1 \ -DCIRCUITPY_AUDIOMP3=1 \ -DCIRCUITPY_AUDIOMP3_USE_PORT_ALLOCATOR=0 \ diff --git a/shared-module/audiodelays/Echo.c b/shared-module/audiodelays/Echo.c index a0c34c6540d8..e4eeff48f4c3 100644 --- a/shared-module/audiodelays/Echo.c +++ b/shared-module/audiodelays/Echo.c @@ -77,7 +77,7 @@ void common_hal_audiodelays_echo_construct(audiodelays_echo_obj_t *self, uint32_ // Allocate the echo buffer for the max possible delay, echo is always 16-bit self->max_delay_ms = max_delay_ms; - self->max_echo_buffer_len = self->sample_rate / 1000.0f * max_delay_ms * (self->channel_count * sizeof(uint16_t)); // bytes + self->max_echo_buffer_len = (uint32_t)(self->sample_rate / 1000.0f * max_delay_ms) * (self->channel_count * sizeof(uint16_t)); // bytes self->echo_buffer = m_malloc(self->max_echo_buffer_len); if (self->echo_buffer == NULL) { common_hal_audiodelays_echo_deinit(self); @@ -129,11 +129,11 @@ void common_hal_audiodelays_echo_set_delay_ms(audiodelays_echo_obj_t *self, mp_o void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { if (self->freq_shift) { // Calculate the rate of iteration over the echo buffer with 8 sub-bits - self->echo_buffer_rate = MAX(self->max_delay_ms / f_delay_ms * 256.0f, 1.0); + self->echo_buffer_rate = (uint32_t)MAX(self->max_delay_ms / f_delay_ms * MICROPY_FLOAT_CONST(256.0), MICROPY_FLOAT_CONST(1.0)); self->echo_buffer_len = self->max_echo_buffer_len; } else { // Calculate the current echo buffer length in bytes - uint32_t new_echo_buffer_len = self->sample_rate / 1000.0f * f_delay_ms * (self->channel_count * sizeof(uint16_t)); + uint32_t new_echo_buffer_len = (uint32_t)(self->sample_rate / MICROPY_FLOAT_CONST(1000.0) * f_delay_ms) * (self->channel_count * sizeof(uint16_t)); // Check if our new echo is too long for our maximum buffer if (new_echo_buffer_len > self->max_echo_buffer_len) { @@ -153,7 +153,7 @@ void recalculate_delay(audiodelays_echo_obj_t *self, mp_float_t f_delay_ms) { memset(self->echo_buffer + self->echo_buffer_len, 0, self->max_echo_buffer_len - self->echo_buffer_len); } - self->current_delay_ms = f_delay_ms; + self->current_delay_ms = (uint32_t)f_delay_ms; } mp_obj_t common_hal_audiodelays_echo_get_decay(audiodelays_echo_obj_t *self) { @@ -360,17 +360,17 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * echo = echo_buffer[echo_buffer_pos >> 8]; next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate; - word = echo * decay; + word = (int16_t)(echo * decay); for (uint32_t j = echo_buffer_pos >> 8; j < next_buffer_pos >> 8; j++) { echo_buffer[j % echo_buf_len] = word; } } else { echo = echo_buffer[self->echo_buffer_read_pos++]; - word = echo * decay; + word = (int16_t)(echo * decay); echo_buffer[self->echo_buffer_write_pos++] = word; } - word = echo * mix; + word = (int16_t)(echo * mix); if (MP_LIKELY(self->bits_per_sample == 16)) { word_buffer[i] = word; @@ -433,10 +433,10 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * if (self->freq_shift) { echo = echo_buffer[echo_buffer_pos >> 8]; next_buffer_pos = echo_buffer_pos + self->echo_buffer_rate; - word = echo * decay + sample_word; + word = (int32_t)(echo * decay + sample_word); } else { echo = echo_buffer[self->echo_buffer_read_pos++]; - word = echo * decay + sample_word; + word = (int32_t)(echo * decay + sample_word); } if (MP_LIKELY(self->bits_per_sample == 16)) { @@ -467,12 +467,12 @@ audioio_get_buffer_result_t audiodelays_echo_get_buffer(audiodelays_echo_obj_t * word = echo + sample_word; if (MP_LIKELY(self->bits_per_sample == 16)) { - word_buffer[i] = (sample_word * (1.0 - mix)) + (word * mix); + word_buffer[i] = (int16_t)((sample_word * (1.0 - mix)) + (word * mix)); if (!self->samples_signed) { word_buffer[i] ^= 0x8000; } } else { - int8_t mixed = (sample_word * (1.0 - mix)) + (word * mix); + int8_t mixed = (int16_t)((sample_word * (1.0 - mix)) + (word * mix)); if (self->samples_signed) { hword_buffer[i] = mixed; } else { diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index d7ee30e8ea66..6b8fc85dd4e2 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -204,6 +204,7 @@ int16_t mix_down_sample(int32_t sample) { audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { + (void)channel; if (!single_channel_output) { channel = 0; @@ -297,7 +298,7 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o // Mix processed signal with original sample and transfer to output buffer for (uint32_t j = 0; j < n_samples; j++) { if (MP_LIKELY(self->bits_per_sample == 16)) { - word_buffer[i + j] = mix_down_sample((sample_src[i + j] * (1.0 - mix)) + (self->filter_buffer[j] * mix)); + word_buffer[i + j] = mix_down_sample((int32_t)((sample_src[i + j] * (MICROPY_FLOAT_CONST(1.0) - mix)) + (self->filter_buffer[j] * mix))); if (!self->samples_signed) { word_buffer[i + j] ^= 0x8000; } @@ -305,7 +306,7 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o if (self->samples_signed) { hword_buffer[i + j] = (int8_t)((sample_hsrc[i + j] * (1.0 - mix)) + (self->filter_buffer[j] * mix)); } else { - hword_buffer[i + j] = (uint8_t)(((int8_t)(((uint8_t)sample_hsrc[i + j]) ^ 0x80) * (1.0 - mix)) + (self->filter_buffer[j] * mix)) ^ 0x80; + hword_buffer[i + j] = (uint8_t)(((int8_t)(((uint8_t)sample_hsrc[i + j]) ^ 0x80) * (MICROPY_FLOAT_CONST(1.0) - mix)) + (self->filter_buffer[j] * mix)) ^ 0x80; } } } diff --git a/tests/circuitpython/audiofilter_filter.py b/tests/circuitpython/audiofilter_filter.py new file mode 100644 index 000000000000..3267ded43979 --- /dev/null +++ b/tests/circuitpython/audiofilter_filter.py @@ -0,0 +1,16 @@ +from audiofilters import Filter +from audiofilterhelper import synth_test, sine8k + +@synth_test +def basic_filter(): + effect = Filter( + bits_per_sample=16, + samples_signed=True, + ) + yield effect, [] + + effect.play(sine8k, loop=True) + yield 4 + + effect.stop() + yield 2 diff --git a/tests/circuitpython/audiofilter_filter.py.exp b/tests/circuitpython/audiofilter_filter.py.exp new file mode 100644 index 000000000000..734ac16b3a79 --- /dev/null +++ b/tests/circuitpython/audiofilter_filter.py.exp @@ -0,0 +1,1536 @@ +0 0.0 +1 0.010467529296875 +2 0.02093505859375 +3 0.031402587890625 +4 0.0418701171875 +5 0.05230712890625 +6 0.062774658203125 +7 0.073211669921875 +8 0.083648681640625 +9 0.094085693359375 +10 0.104522705078125 +11 0.11492919921875 +12 0.12530517578125 +13 0.13568115234375 +14 0.14605712890625 +15 0.156402587890625 +16 0.166748046875 +17 0.17706298828125 +18 0.187347412109375 +19 0.1976318359375 +20 0.2078857421875 +21 0.218109130859375 +22 0.22833251953125 +23 0.238525390625 +24 0.2486572265625 +25 0.2587890625 +26 0.268890380859375 +27 0.278961181640625 +28 0.28900146484375 +29 0.29901123046875 +30 0.308990478515625 +31 0.318939208984375 +32 0.328826904296875 +33 0.338714599609375 +34 0.348541259765625 +35 0.35833740234375 +36 0.36810302734375 +37 0.3778076171875 +38 0.387481689453125 +39 0.397125244140625 +40 0.406707763671875 +41 0.416259765625 +42 0.425750732421875 +43 0.435211181640625 +44 0.444610595703125 +45 0.453948974609375 +46 0.4632568359375 +47 0.4725341796875 +48 0.481719970703125 +49 0.490875244140625 +50 0.499969482421875 +51 0.509002685546875 +52 0.51800537109375 +53 0.52691650390625 +54 0.535797119140625 +55 0.54461669921875 +56 0.5533447265625 +57 0.562042236328125 +58 0.5706787109375 +59 0.579254150390625 +60 0.587738037109375 +61 0.59619140625 +62 0.60455322265625 +63 0.612884521484375 +64 0.621124267578125 +65 0.6292724609375 +66 0.63739013671875 +67 0.645416259765625 +68 0.65338134765625 +69 0.661285400390625 +70 0.669097900390625 +71 0.676849365234375 +72 0.68450927734375 +73 0.692108154296875 +74 0.699615478515625 +75 0.707061767578125 +76 0.714447021484375 +77 0.721710205078125 +78 0.72894287109375 +79 0.736053466796875 +80 0.74310302734375 +81 0.75006103515625 +82 0.7569580078125 +83 0.763763427734375 +84 0.770477294921875 +85 0.777099609375 +86 0.783660888671875 +87 0.790130615234375 +88 0.796478271484375 +89 0.802764892578125 +90 0.808990478515625 +91 0.815093994140625 +92 0.82110595703125 +93 0.8270263671875 +94 0.8328857421875 +95 0.838623046875 +96 0.84429931640625 +97 0.849853515625 +98 0.855316162109375 +99 0.860687255859375 +100 0.865997314453125 +101 0.871185302734375 +102 0.876251220703125 +103 0.881256103515625 +104 0.88616943359375 +105 0.890960693359375 +106 0.895660400390625 +107 0.9002685546875 +108 0.90478515625 +109 0.9091796875 +110 0.91351318359375 +111 0.917724609375 +112 0.92181396484375 +113 0.92584228515625 +114 0.929718017578125 +115 0.93353271484375 +116 0.937225341796875 +117 0.940826416015625 +118 0.9443359375 +119 0.947723388671875 +120 0.951019287109375 +121 0.954193115234375 +122 0.957275390625 +123 0.960235595703125 +124 0.963104248046875 +125 0.96588134765625 +126 0.968536376953125 +127 0.971099853515625 +128 0.973541259765625 +129 0.975860595703125 +130 0.97808837890625 +131 0.980224609375 +132 0.98223876953125 +133 0.984161376953125 +134 0.9859619140625 +135 0.987640380859375 +136 0.989227294921875 +137 0.990692138671875 +138 0.9920654296875 +139 0.993316650390625 +140 0.994476318359375 +141 0.995513916015625 +142 0.9964599609375 +143 0.997283935546875 +144 0.99798583984375 +145 0.99859619140625 +146 0.99908447265625 +147 0.99945068359375 +148 0.999725341796875 +149 0.999908447265625 +150 0.999969482421875 +151 0.999908447265625 +152 0.999725341796875 +153 0.99945068359375 +154 0.99908447265625 +155 0.99859619140625 +156 0.99798583984375 +157 0.997283935546875 +158 0.9964599609375 +159 0.995513916015625 +160 0.994476318359375 +161 0.993316650390625 +162 0.9920654296875 +163 0.990692138671875 +164 0.989227294921875 +165 0.987640380859375 +166 0.9859619140625 +167 0.984161376953125 +168 0.98223876953125 +169 0.980224609375 +170 0.97808837890625 +171 0.975860595703125 +172 0.973541259765625 +173 0.971099853515625 +174 0.968536376953125 +175 0.96588134765625 +176 0.963104248046875 +177 0.960235595703125 +178 0.957275390625 +179 0.954193115234375 +180 0.951019287109375 +181 0.947723388671875 +182 0.9443359375 +183 0.940826416015625 +184 0.937225341796875 +185 0.93353271484375 +186 0.929718017578125 +187 0.92584228515625 +188 0.92181396484375 +189 0.917724609375 +190 0.91351318359375 +191 0.9091796875 +192 0.90478515625 +193 0.9002685546875 +194 0.895660400390625 +195 0.890960693359375 +196 0.88616943359375 +197 0.881256103515625 +198 0.876251220703125 +199 0.871185302734375 +200 0.865997314453125 +201 0.860687255859375 +202 0.855316162109375 +203 0.849853515625 +204 0.84429931640625 +205 0.838623046875 +206 0.8328857421875 +207 0.8270263671875 +208 0.82110595703125 +209 0.815093994140625 +210 0.808990478515625 +211 0.802764892578125 +212 0.796478271484375 +213 0.790130615234375 +214 0.783660888671875 +215 0.777099609375 +216 0.770477294921875 +217 0.763763427734375 +218 0.7569580078125 +219 0.75006103515625 +220 0.74310302734375 +221 0.736053466796875 +222 0.72894287109375 +223 0.721710205078125 +224 0.714447021484375 +225 0.707061767578125 +226 0.699615478515625 +227 0.692108154296875 +228 0.68450927734375 +229 0.676849365234375 +230 0.669097900390625 +231 0.661285400390625 +232 0.65338134765625 +233 0.645416259765625 +234 0.63739013671875 +235 0.6292724609375 +236 0.621124267578125 +237 0.612884521484375 +238 0.60455322265625 +239 0.59619140625 +240 0.587738037109375 +241 0.579254150390625 +242 0.5706787109375 +243 0.562042236328125 +244 0.5533447265625 +245 0.54461669921875 +246 0.535797119140625 +247 0.52691650390625 +248 0.51800537109375 +249 0.509002685546875 +250 0.499969482421875 +251 0.490875244140625 +252 0.481719970703125 +253 0.4725341796875 +254 0.4632568359375 +255 0.453948974609375 +256 0.444610595703125 +257 0.435211181640625 +258 0.425750732421875 +259 0.416259765625 +260 0.406707763671875 +261 0.397125244140625 +262 0.387481689453125 +263 0.3778076171875 +264 0.36810302734375 +265 0.35833740234375 +266 0.348541259765625 +267 0.338714599609375 +268 0.328826904296875 +269 0.318939208984375 +270 0.308990478515625 +271 0.29901123046875 +272 0.28900146484375 +273 0.278961181640625 +274 0.268890380859375 +275 0.2587890625 +276 0.2486572265625 +277 0.238525390625 +278 0.22833251953125 +279 0.218109130859375 +280 0.2078857421875 +281 0.1976318359375 +282 0.187347412109375 +283 0.17706298828125 +284 0.166748046875 +285 0.156402587890625 +286 0.14605712890625 +287 0.13568115234375 +288 0.12530517578125 +289 0.11492919921875 +290 0.104522705078125 +291 0.094085693359375 +292 0.083648681640625 +293 0.073211669921875 +294 0.062774658203125 +295 0.05230712890625 +296 0.0418701171875 +297 0.031402587890625 +298 0.02093505859375 +299 0.010467529296875 +300 0.0 +301 -0.010467529296875 +302 -0.02093505859375 +303 -0.031402587890625 +304 -0.0418701171875 +305 -0.05230712890625 +306 -0.062774658203125 +307 -0.073211669921875 +308 -0.083648681640625 +309 -0.094085693359375 +310 -0.104522705078125 +311 -0.11492919921875 +312 -0.12530517578125 +313 -0.13568115234375 +314 -0.14605712890625 +315 -0.156402587890625 +316 -0.166748046875 +317 -0.17706298828125 +318 -0.187347412109375 +319 -0.1976318359375 +320 -0.2078857421875 +321 -0.218109130859375 +322 -0.22833251953125 +323 -0.238525390625 +324 -0.2486572265625 +325 -0.2587890625 +326 -0.268890380859375 +327 -0.278961181640625 +328 -0.28900146484375 +329 -0.29901123046875 +330 -0.308990478515625 +331 -0.318939208984375 +332 -0.328826904296875 +333 -0.338714599609375 +334 -0.348541259765625 +335 -0.35833740234375 +336 -0.36810302734375 +337 -0.3778076171875 +338 -0.387481689453125 +339 -0.397125244140625 +340 -0.406707763671875 +341 -0.416259765625 +342 -0.425750732421875 +343 -0.435211181640625 +344 -0.444610595703125 +345 -0.453948974609375 +346 -0.4632568359375 +347 -0.4725341796875 +348 -0.481719970703125 +349 -0.490875244140625 +350 -0.499969482421875 +351 -0.509002685546875 +352 -0.51800537109375 +353 -0.52691650390625 +354 -0.535797119140625 +355 -0.54461669921875 +356 -0.5533447265625 +357 -0.562042236328125 +358 -0.5706787109375 +359 -0.579254150390625 +360 -0.587738037109375 +361 -0.59619140625 +362 -0.60455322265625 +363 -0.612884521484375 +364 -0.621124267578125 +365 -0.6292724609375 +366 -0.63739013671875 +367 -0.645416259765625 +368 -0.65338134765625 +369 -0.661285400390625 +370 -0.669097900390625 +371 -0.676849365234375 +372 -0.68450927734375 +373 -0.692108154296875 +374 -0.699615478515625 +375 -0.707061767578125 +376 -0.714447021484375 +377 -0.721710205078125 +378 -0.72894287109375 +379 -0.736053466796875 +380 -0.74310302734375 +381 -0.75006103515625 +382 -0.7569580078125 +383 -0.763763427734375 +384 -0.770477294921875 +385 -0.777099609375 +386 -0.783660888671875 +387 -0.790130615234375 +388 -0.796478271484375 +389 -0.802764892578125 +390 -0.808990478515625 +391 -0.815093994140625 +392 -0.82110595703125 +393 -0.8270263671875 +394 -0.8328857421875 +395 -0.838623046875 +396 -0.84429931640625 +397 -0.849853515625 +398 -0.855316162109375 +399 -0.860687255859375 +400 -0.865997314453125 +401 -0.871185302734375 +402 -0.876251220703125 +403 -0.881256103515625 +404 -0.88616943359375 +405 -0.890960693359375 +406 -0.895660400390625 +407 -0.9002685546875 +408 -0.90478515625 +409 -0.9091796875 +410 -0.91351318359375 +411 -0.917724609375 +412 -0.92181396484375 +413 -0.92584228515625 +414 -0.929718017578125 +415 -0.93353271484375 +416 -0.937225341796875 +417 -0.940826416015625 +418 -0.9443359375 +419 -0.947723388671875 +420 -0.951019287109375 +421 -0.954193115234375 +422 -0.957275390625 +423 -0.960235595703125 +424 -0.963104248046875 +425 -0.96588134765625 +426 -0.968536376953125 +427 -0.971099853515625 +428 -0.973541259765625 +429 -0.975860595703125 +430 -0.97808837890625 +431 -0.980224609375 +432 -0.98223876953125 +433 -0.984161376953125 +434 -0.9859619140625 +435 -0.987640380859375 +436 -0.989227294921875 +437 -0.990692138671875 +438 -0.9920654296875 +439 -0.993316650390625 +440 -0.994476318359375 +441 -0.995513916015625 +442 -0.9964599609375 +443 -0.997283935546875 +444 -0.99798583984375 +445 -0.99859619140625 +446 -0.99908447265625 +447 -0.99945068359375 +448 -0.999725341796875 +449 -0.999908447265625 +450 -0.999969482421875 +451 -0.999908447265625 +452 -0.999725341796875 +453 -0.99945068359375 +454 -0.99908447265625 +455 -0.99859619140625 +456 -0.99798583984375 +457 -0.997283935546875 +458 -0.9964599609375 +459 -0.995513916015625 +460 -0.994476318359375 +461 -0.993316650390625 +462 -0.9920654296875 +463 -0.990692138671875 +464 -0.989227294921875 +465 -0.987640380859375 +466 -0.9859619140625 +467 -0.984161376953125 +468 -0.98223876953125 +469 -0.980224609375 +470 -0.97808837890625 +471 -0.975860595703125 +472 -0.973541259765625 +473 -0.971099853515625 +474 -0.968536376953125 +475 -0.96588134765625 +476 -0.963104248046875 +477 -0.960235595703125 +478 -0.957275390625 +479 -0.954193115234375 +480 -0.951019287109375 +481 -0.947723388671875 +482 -0.9443359375 +483 -0.940826416015625 +484 -0.937225341796875 +485 -0.93353271484375 +486 -0.929718017578125 +487 -0.92584228515625 +488 -0.92181396484375 +489 -0.917724609375 +490 -0.91351318359375 +491 -0.9091796875 +492 -0.90478515625 +493 -0.9002685546875 +494 -0.895660400390625 +495 -0.890960693359375 +496 -0.88616943359375 +497 -0.881256103515625 +498 -0.876251220703125 +499 -0.871185302734375 +500 -0.865997314453125 +501 -0.860687255859375 +502 -0.855316162109375 +503 -0.849853515625 +504 -0.84429931640625 +505 -0.838623046875 +506 -0.8328857421875 +507 -0.8270263671875 +508 -0.82110595703125 +509 -0.815093994140625 +510 -0.808990478515625 +511 -0.802764892578125 +512 -0.796478271484375 +513 -0.790130615234375 +514 -0.783660888671875 +515 -0.777099609375 +516 -0.770477294921875 +517 -0.763763427734375 +518 -0.7569580078125 +519 -0.75006103515625 +520 -0.74310302734375 +521 -0.736053466796875 +522 -0.72894287109375 +523 -0.721710205078125 +524 -0.714447021484375 +525 -0.707061767578125 +526 -0.699615478515625 +527 -0.692108154296875 +528 -0.68450927734375 +529 -0.676849365234375 +530 -0.669097900390625 +531 -0.661285400390625 +532 -0.65338134765625 +533 -0.645416259765625 +534 -0.63739013671875 +535 -0.6292724609375 +536 -0.621124267578125 +537 -0.612884521484375 +538 -0.60455322265625 +539 -0.59619140625 +540 -0.587738037109375 +541 -0.579254150390625 +542 -0.5706787109375 +543 -0.562042236328125 +544 -0.5533447265625 +545 -0.54461669921875 +546 -0.535797119140625 +547 -0.52691650390625 +548 -0.51800537109375 +549 -0.509002685546875 +550 -0.499969482421875 +551 -0.490875244140625 +552 -0.481719970703125 +553 -0.4725341796875 +554 -0.4632568359375 +555 -0.453948974609375 +556 -0.444610595703125 +557 -0.435211181640625 +558 -0.425750732421875 +559 -0.416259765625 +560 -0.406707763671875 +561 -0.397125244140625 +562 -0.387481689453125 +563 -0.3778076171875 +564 -0.36810302734375 +565 -0.35833740234375 +566 -0.348541259765625 +567 -0.338714599609375 +568 -0.328826904296875 +569 -0.318939208984375 +570 -0.308990478515625 +571 -0.29901123046875 +572 -0.28900146484375 +573 -0.278961181640625 +574 -0.268890380859375 +575 -0.2587890625 +576 -0.2486572265625 +577 -0.238525390625 +578 -0.22833251953125 +579 -0.218109130859375 +580 -0.2078857421875 +581 -0.1976318359375 +582 -0.187347412109375 +583 -0.17706298828125 +584 -0.166748046875 +585 -0.156402587890625 +586 -0.14605712890625 +587 -0.13568115234375 +588 -0.12530517578125 +589 -0.11492919921875 +590 -0.104522705078125 +591 -0.094085693359375 +592 -0.083648681640625 +593 -0.073211669921875 +594 -0.062774658203125 +595 -0.05230712890625 +596 -0.0418701171875 +597 -0.031402587890625 +598 -0.02093505859375 +599 -0.010467529296875 +600 0.0 +601 0.010467529296875 +602 0.02093505859375 +603 0.031402587890625 +604 0.0418701171875 +605 0.05230712890625 +606 0.062774658203125 +607 0.073211669921875 +608 0.083648681640625 +609 0.094085693359375 +610 0.104522705078125 +611 0.11492919921875 +612 0.12530517578125 +613 0.13568115234375 +614 0.14605712890625 +615 0.156402587890625 +616 0.166748046875 +617 0.17706298828125 +618 0.187347412109375 +619 0.1976318359375 +620 0.2078857421875 +621 0.218109130859375 +622 0.22833251953125 +623 0.238525390625 +624 0.2486572265625 +625 0.2587890625 +626 0.268890380859375 +627 0.278961181640625 +628 0.28900146484375 +629 0.29901123046875 +630 0.308990478515625 +631 0.318939208984375 +632 0.328826904296875 +633 0.338714599609375 +634 0.348541259765625 +635 0.35833740234375 +636 0.36810302734375 +637 0.3778076171875 +638 0.387481689453125 +639 0.397125244140625 +640 0.406707763671875 +641 0.416259765625 +642 0.425750732421875 +643 0.435211181640625 +644 0.444610595703125 +645 0.453948974609375 +646 0.4632568359375 +647 0.4725341796875 +648 0.481719970703125 +649 0.490875244140625 +650 0.499969482421875 +651 0.509002685546875 +652 0.51800537109375 +653 0.52691650390625 +654 0.535797119140625 +655 0.54461669921875 +656 0.5533447265625 +657 0.562042236328125 +658 0.5706787109375 +659 0.579254150390625 +660 0.587738037109375 +661 0.59619140625 +662 0.60455322265625 +663 0.612884521484375 +664 0.621124267578125 +665 0.6292724609375 +666 0.63739013671875 +667 0.645416259765625 +668 0.65338134765625 +669 0.661285400390625 +670 0.669097900390625 +671 0.676849365234375 +672 0.68450927734375 +673 0.692108154296875 +674 0.699615478515625 +675 0.707061767578125 +676 0.714447021484375 +677 0.721710205078125 +678 0.72894287109375 +679 0.736053466796875 +680 0.74310302734375 +681 0.75006103515625 +682 0.7569580078125 +683 0.763763427734375 +684 0.770477294921875 +685 0.777099609375 +686 0.783660888671875 +687 0.790130615234375 +688 0.796478271484375 +689 0.802764892578125 +690 0.808990478515625 +691 0.815093994140625 +692 0.82110595703125 +693 0.8270263671875 +694 0.8328857421875 +695 0.838623046875 +696 0.84429931640625 +697 0.849853515625 +698 0.855316162109375 +699 0.860687255859375 +700 0.865997314453125 +701 0.871185302734375 +702 0.876251220703125 +703 0.881256103515625 +704 0.88616943359375 +705 0.890960693359375 +706 0.895660400390625 +707 0.9002685546875 +708 0.90478515625 +709 0.9091796875 +710 0.91351318359375 +711 0.917724609375 +712 0.92181396484375 +713 0.92584228515625 +714 0.929718017578125 +715 0.93353271484375 +716 0.937225341796875 +717 0.940826416015625 +718 0.9443359375 +719 0.947723388671875 +720 0.951019287109375 +721 0.954193115234375 +722 0.957275390625 +723 0.960235595703125 +724 0.963104248046875 +725 0.96588134765625 +726 0.968536376953125 +727 0.971099853515625 +728 0.973541259765625 +729 0.975860595703125 +730 0.97808837890625 +731 0.980224609375 +732 0.98223876953125 +733 0.984161376953125 +734 0.9859619140625 +735 0.987640380859375 +736 0.989227294921875 +737 0.990692138671875 +738 0.9920654296875 +739 0.993316650390625 +740 0.994476318359375 +741 0.995513916015625 +742 0.9964599609375 +743 0.997283935546875 +744 0.99798583984375 +745 0.99859619140625 +746 0.99908447265625 +747 0.99945068359375 +748 0.999725341796875 +749 0.999908447265625 +750 0.999969482421875 +751 0.999908447265625 +752 0.999725341796875 +753 0.99945068359375 +754 0.99908447265625 +755 0.99859619140625 +756 0.99798583984375 +757 0.997283935546875 +758 0.9964599609375 +759 0.995513916015625 +760 0.994476318359375 +761 0.993316650390625 +762 0.9920654296875 +763 0.990692138671875 +764 0.989227294921875 +765 0.987640380859375 +766 0.9859619140625 +767 0.984161376953125 +768 0.98223876953125 +769 0.980224609375 +770 0.97808837890625 +771 0.975860595703125 +772 0.973541259765625 +773 0.971099853515625 +774 0.968536376953125 +775 0.96588134765625 +776 0.963104248046875 +777 0.960235595703125 +778 0.957275390625 +779 0.954193115234375 +780 0.951019287109375 +781 0.947723388671875 +782 0.9443359375 +783 0.940826416015625 +784 0.937225341796875 +785 0.93353271484375 +786 0.929718017578125 +787 0.92584228515625 +788 0.92181396484375 +789 0.917724609375 +790 0.91351318359375 +791 0.9091796875 +792 0.90478515625 +793 0.9002685546875 +794 0.895660400390625 +795 0.890960693359375 +796 0.88616943359375 +797 0.881256103515625 +798 0.876251220703125 +799 0.871185302734375 +800 0.865997314453125 +801 0.860687255859375 +802 0.855316162109375 +803 0.849853515625 +804 0.84429931640625 +805 0.838623046875 +806 0.8328857421875 +807 0.8270263671875 +808 0.82110595703125 +809 0.815093994140625 +810 0.808990478515625 +811 0.802764892578125 +812 0.796478271484375 +813 0.790130615234375 +814 0.783660888671875 +815 0.777099609375 +816 0.770477294921875 +817 0.763763427734375 +818 0.7569580078125 +819 0.75006103515625 +820 0.74310302734375 +821 0.736053466796875 +822 0.72894287109375 +823 0.721710205078125 +824 0.714447021484375 +825 0.707061767578125 +826 0.699615478515625 +827 0.692108154296875 +828 0.68450927734375 +829 0.676849365234375 +830 0.669097900390625 +831 0.661285400390625 +832 0.65338134765625 +833 0.645416259765625 +834 0.63739013671875 +835 0.6292724609375 +836 0.621124267578125 +837 0.612884521484375 +838 0.60455322265625 +839 0.59619140625 +840 0.587738037109375 +841 0.579254150390625 +842 0.5706787109375 +843 0.562042236328125 +844 0.5533447265625 +845 0.54461669921875 +846 0.535797119140625 +847 0.52691650390625 +848 0.51800537109375 +849 0.509002685546875 +850 0.499969482421875 +851 0.490875244140625 +852 0.481719970703125 +853 0.4725341796875 +854 0.4632568359375 +855 0.453948974609375 +856 0.444610595703125 +857 0.435211181640625 +858 0.425750732421875 +859 0.416259765625 +860 0.406707763671875 +861 0.397125244140625 +862 0.387481689453125 +863 0.3778076171875 +864 0.36810302734375 +865 0.35833740234375 +866 0.348541259765625 +867 0.338714599609375 +868 0.328826904296875 +869 0.318939208984375 +870 0.308990478515625 +871 0.29901123046875 +872 0.28900146484375 +873 0.278961181640625 +874 0.268890380859375 +875 0.2587890625 +876 0.2486572265625 +877 0.238525390625 +878 0.22833251953125 +879 0.218109130859375 +880 0.2078857421875 +881 0.1976318359375 +882 0.187347412109375 +883 0.17706298828125 +884 0.166748046875 +885 0.156402587890625 +886 0.14605712890625 +887 0.13568115234375 +888 0.12530517578125 +889 0.11492919921875 +890 0.104522705078125 +891 0.094085693359375 +892 0.083648681640625 +893 0.073211669921875 +894 0.062774658203125 +895 0.05230712890625 +896 0.0418701171875 +897 0.031402587890625 +898 0.02093505859375 +899 0.010467529296875 +900 0.0 +901 -0.010467529296875 +902 -0.02093505859375 +903 -0.031402587890625 +904 -0.0418701171875 +905 -0.05230712890625 +906 -0.062774658203125 +907 -0.073211669921875 +908 -0.083648681640625 +909 -0.094085693359375 +910 -0.104522705078125 +911 -0.11492919921875 +912 -0.12530517578125 +913 -0.13568115234375 +914 -0.14605712890625 +915 -0.156402587890625 +916 -0.166748046875 +917 -0.17706298828125 +918 -0.187347412109375 +919 -0.1976318359375 +920 -0.2078857421875 +921 -0.218109130859375 +922 -0.22833251953125 +923 -0.238525390625 +924 -0.2486572265625 +925 -0.2587890625 +926 -0.268890380859375 +927 -0.278961181640625 +928 -0.28900146484375 +929 -0.29901123046875 +930 -0.308990478515625 +931 -0.318939208984375 +932 -0.328826904296875 +933 -0.338714599609375 +934 -0.348541259765625 +935 -0.35833740234375 +936 -0.36810302734375 +937 -0.3778076171875 +938 -0.387481689453125 +939 -0.397125244140625 +940 -0.406707763671875 +941 -0.416259765625 +942 -0.425750732421875 +943 -0.435211181640625 +944 -0.444610595703125 +945 -0.453948974609375 +946 -0.4632568359375 +947 -0.4725341796875 +948 -0.481719970703125 +949 -0.490875244140625 +950 -0.499969482421875 +951 -0.509002685546875 +952 -0.51800537109375 +953 -0.52691650390625 +954 -0.535797119140625 +955 -0.54461669921875 +956 -0.5533447265625 +957 -0.562042236328125 +958 -0.5706787109375 +959 -0.579254150390625 +960 -0.587738037109375 +961 -0.59619140625 +962 -0.60455322265625 +963 -0.612884521484375 +964 -0.621124267578125 +965 -0.6292724609375 +966 -0.63739013671875 +967 -0.645416259765625 +968 -0.65338134765625 +969 -0.661285400390625 +970 -0.669097900390625 +971 -0.676849365234375 +972 -0.68450927734375 +973 -0.692108154296875 +974 -0.699615478515625 +975 -0.707061767578125 +976 -0.714447021484375 +977 -0.721710205078125 +978 -0.72894287109375 +979 -0.736053466796875 +980 -0.74310302734375 +981 -0.75006103515625 +982 -0.7569580078125 +983 -0.763763427734375 +984 -0.770477294921875 +985 -0.777099609375 +986 -0.783660888671875 +987 -0.790130615234375 +988 -0.796478271484375 +989 -0.802764892578125 +990 -0.808990478515625 +991 -0.815093994140625 +992 -0.82110595703125 +993 -0.8270263671875 +994 -0.8328857421875 +995 -0.838623046875 +996 -0.84429931640625 +997 -0.849853515625 +998 -0.855316162109375 +999 -0.860687255859375 +1000 -0.865997314453125 +1001 -0.871185302734375 +1002 -0.876251220703125 +1003 -0.881256103515625 +1004 -0.88616943359375 +1005 -0.890960693359375 +1006 -0.895660400390625 +1007 -0.9002685546875 +1008 -0.90478515625 +1009 -0.9091796875 +1010 -0.91351318359375 +1011 -0.917724609375 +1012 -0.92181396484375 +1013 -0.92584228515625 +1014 -0.929718017578125 +1015 -0.93353271484375 +1016 -0.937225341796875 +1017 -0.940826416015625 +1018 -0.9443359375 +1019 -0.947723388671875 +1020 -0.951019287109375 +1021 -0.954193115234375 +1022 -0.957275390625 +1023 -0.960235595703125 +1024 0.0 +1025 0.0 +1026 0.0 +1027 0.0 +1028 0.0 +1029 0.0 +1030 0.0 +1031 0.0 +1032 0.0 +1033 0.0 +1034 0.0 +1035 0.0 +1036 0.0 +1037 0.0 +1038 0.0 +1039 0.0 +1040 0.0 +1041 0.0 +1042 0.0 +1043 0.0 +1044 0.0 +1045 0.0 +1046 0.0 +1047 0.0 +1048 0.0 +1049 0.0 +1050 0.0 +1051 0.0 +1052 0.0 +1053 0.0 +1054 0.0 +1055 0.0 +1056 0.0 +1057 0.0 +1058 0.0 +1059 0.0 +1060 0.0 +1061 0.0 +1062 0.0 +1063 0.0 +1064 0.0 +1065 0.0 +1066 0.0 +1067 0.0 +1068 0.0 +1069 0.0 +1070 0.0 +1071 0.0 +1072 0.0 +1073 0.0 +1074 0.0 +1075 0.0 +1076 0.0 +1077 0.0 +1078 0.0 +1079 0.0 +1080 0.0 +1081 0.0 +1082 0.0 +1083 0.0 +1084 0.0 +1085 0.0 +1086 0.0 +1087 0.0 +1088 0.0 +1089 0.0 +1090 0.0 +1091 0.0 +1092 0.0 +1093 0.0 +1094 0.0 +1095 0.0 +1096 0.0 +1097 0.0 +1098 0.0 +1099 0.0 +1100 0.0 +1101 0.0 +1102 0.0 +1103 0.0 +1104 0.0 +1105 0.0 +1106 0.0 +1107 0.0 +1108 0.0 +1109 0.0 +1110 0.0 +1111 0.0 +1112 0.0 +1113 0.0 +1114 0.0 +1115 0.0 +1116 0.0 +1117 0.0 +1118 0.0 +1119 0.0 +1120 0.0 +1121 0.0 +1122 0.0 +1123 0.0 +1124 0.0 +1125 0.0 +1126 0.0 +1127 0.0 +1128 0.0 +1129 0.0 +1130 0.0 +1131 0.0 +1132 0.0 +1133 0.0 +1134 0.0 +1135 0.0 +1136 0.0 +1137 0.0 +1138 0.0 +1139 0.0 +1140 0.0 +1141 0.0 +1142 0.0 +1143 0.0 +1144 0.0 +1145 0.0 +1146 0.0 +1147 0.0 +1148 0.0 +1149 0.0 +1150 0.0 +1151 0.0 +1152 0.0 +1153 0.0 +1154 0.0 +1155 0.0 +1156 0.0 +1157 0.0 +1158 0.0 +1159 0.0 +1160 0.0 +1161 0.0 +1162 0.0 +1163 0.0 +1164 0.0 +1165 0.0 +1166 0.0 +1167 0.0 +1168 0.0 +1169 0.0 +1170 0.0 +1171 0.0 +1172 0.0 +1173 0.0 +1174 0.0 +1175 0.0 +1176 0.0 +1177 0.0 +1178 0.0 +1179 0.0 +1180 0.0 +1181 0.0 +1182 0.0 +1183 0.0 +1184 0.0 +1185 0.0 +1186 0.0 +1187 0.0 +1188 0.0 +1189 0.0 +1190 0.0 +1191 0.0 +1192 0.0 +1193 0.0 +1194 0.0 +1195 0.0 +1196 0.0 +1197 0.0 +1198 0.0 +1199 0.0 +1200 0.0 +1201 0.0 +1202 0.0 +1203 0.0 +1204 0.0 +1205 0.0 +1206 0.0 +1207 0.0 +1208 0.0 +1209 0.0 +1210 0.0 +1211 0.0 +1212 0.0 +1213 0.0 +1214 0.0 +1215 0.0 +1216 0.0 +1217 0.0 +1218 0.0 +1219 0.0 +1220 0.0 +1221 0.0 +1222 0.0 +1223 0.0 +1224 0.0 +1225 0.0 +1226 0.0 +1227 0.0 +1228 0.0 +1229 0.0 +1230 0.0 +1231 0.0 +1232 0.0 +1233 0.0 +1234 0.0 +1235 0.0 +1236 0.0 +1237 0.0 +1238 0.0 +1239 0.0 +1240 0.0 +1241 0.0 +1242 0.0 +1243 0.0 +1244 0.0 +1245 0.0 +1246 0.0 +1247 0.0 +1248 0.0 +1249 0.0 +1250 0.0 +1251 0.0 +1252 0.0 +1253 0.0 +1254 0.0 +1255 0.0 +1256 0.0 +1257 0.0 +1258 0.0 +1259 0.0 +1260 0.0 +1261 0.0 +1262 0.0 +1263 0.0 +1264 0.0 +1265 0.0 +1266 0.0 +1267 0.0 +1268 0.0 +1269 0.0 +1270 0.0 +1271 0.0 +1272 0.0 +1273 0.0 +1274 0.0 +1275 0.0 +1276 0.0 +1277 0.0 +1278 0.0 +1279 0.0 +1280 0.0 +1281 0.0 +1282 0.0 +1283 0.0 +1284 0.0 +1285 0.0 +1286 0.0 +1287 0.0 +1288 0.0 +1289 0.0 +1290 0.0 +1291 0.0 +1292 0.0 +1293 0.0 +1294 0.0 +1295 0.0 +1296 0.0 +1297 0.0 +1298 0.0 +1299 0.0 +1300 0.0 +1301 0.0 +1302 0.0 +1303 0.0 +1304 0.0 +1305 0.0 +1306 0.0 +1307 0.0 +1308 0.0 +1309 0.0 +1310 0.0 +1311 0.0 +1312 0.0 +1313 0.0 +1314 0.0 +1315 0.0 +1316 0.0 +1317 0.0 +1318 0.0 +1319 0.0 +1320 0.0 +1321 0.0 +1322 0.0 +1323 0.0 +1324 0.0 +1325 0.0 +1326 0.0 +1327 0.0 +1328 0.0 +1329 0.0 +1330 0.0 +1331 0.0 +1332 0.0 +1333 0.0 +1334 0.0 +1335 0.0 +1336 0.0 +1337 0.0 +1338 0.0 +1339 0.0 +1340 0.0 +1341 0.0 +1342 0.0 +1343 0.0 +1344 0.0 +1345 0.0 +1346 0.0 +1347 0.0 +1348 0.0 +1349 0.0 +1350 0.0 +1351 0.0 +1352 0.0 +1353 0.0 +1354 0.0 +1355 0.0 +1356 0.0 +1357 0.0 +1358 0.0 +1359 0.0 +1360 0.0 +1361 0.0 +1362 0.0 +1363 0.0 +1364 0.0 +1365 0.0 +1366 0.0 +1367 0.0 +1368 0.0 +1369 0.0 +1370 0.0 +1371 0.0 +1372 0.0 +1373 0.0 +1374 0.0 +1375 0.0 +1376 0.0 +1377 0.0 +1378 0.0 +1379 0.0 +1380 0.0 +1381 0.0 +1382 0.0 +1383 0.0 +1384 0.0 +1385 0.0 +1386 0.0 +1387 0.0 +1388 0.0 +1389 0.0 +1390 0.0 +1391 0.0 +1392 0.0 +1393 0.0 +1394 0.0 +1395 0.0 +1396 0.0 +1397 0.0 +1398 0.0 +1399 0.0 +1400 0.0 +1401 0.0 +1402 0.0 +1403 0.0 +1404 0.0 +1405 0.0 +1406 0.0 +1407 0.0 +1408 0.0 +1409 0.0 +1410 0.0 +1411 0.0 +1412 0.0 +1413 0.0 +1414 0.0 +1415 0.0 +1416 0.0 +1417 0.0 +1418 0.0 +1419 0.0 +1420 0.0 +1421 0.0 +1422 0.0 +1423 0.0 +1424 0.0 +1425 0.0 +1426 0.0 +1427 0.0 +1428 0.0 +1429 0.0 +1430 0.0 +1431 0.0 +1432 0.0 +1433 0.0 +1434 0.0 +1435 0.0 +1436 0.0 +1437 0.0 +1438 0.0 +1439 0.0 +1440 0.0 +1441 0.0 +1442 0.0 +1443 0.0 +1444 0.0 +1445 0.0 +1446 0.0 +1447 0.0 +1448 0.0 +1449 0.0 +1450 0.0 +1451 0.0 +1452 0.0 +1453 0.0 +1454 0.0 +1455 0.0 +1456 0.0 +1457 0.0 +1458 0.0 +1459 0.0 +1460 0.0 +1461 0.0 +1462 0.0 +1463 0.0 +1464 0.0 +1465 0.0 +1466 0.0 +1467 0.0 +1468 0.0 +1469 0.0 +1470 0.0 +1471 0.0 +1472 0.0 +1473 0.0 +1474 0.0 +1475 0.0 +1476 0.0 +1477 0.0 +1478 0.0 +1479 0.0 +1480 0.0 +1481 0.0 +1482 0.0 +1483 0.0 +1484 0.0 +1485 0.0 +1486 0.0 +1487 0.0 +1488 0.0 +1489 0.0 +1490 0.0 +1491 0.0 +1492 0.0 +1493 0.0 +1494 0.0 +1495 0.0 +1496 0.0 +1497 0.0 +1498 0.0 +1499 0.0 +1500 0.0 +1501 0.0 +1502 0.0 +1503 0.0 +1504 0.0 +1505 0.0 +1506 0.0 +1507 0.0 +1508 0.0 +1509 0.0 +1510 0.0 +1511 0.0 +1512 0.0 +1513 0.0 +1514 0.0 +1515 0.0 +1516 0.0 +1517 0.0 +1518 0.0 +1519 0.0 +1520 0.0 +1521 0.0 +1522 0.0 +1523 0.0 +1524 0.0 +1525 0.0 +1526 0.0 +1527 0.0 +1528 0.0 +1529 0.0 +1530 0.0 +1531 0.0 +1532 0.0 +1533 0.0 +1534 0.0 +1535 0.0 diff --git a/tests/testlib/audiofilterhelper.py b/tests/testlib/audiofilterhelper.py new file mode 100644 index 000000000000..15862dc398c7 --- /dev/null +++ b/tests/testlib/audiofilterhelper.py @@ -0,0 +1,26 @@ +import array +from ulab import numpy as np +from math import sin, pi, ceil +from audiocore import get_buffer, RawSample +from synthio import Note, LFO, MathOperation, Synthesizer + +sinedata = array.array("h", [int(32767 * sin(i * 2 * pi / 600)) for i in range(600)]) +sine8k = RawSample(sinedata, sample_rate=8000) + +def synth_test(_gen=None, dtype=np.int16, divisor = 32768, channel_count=1): + def func(gen): + g = gen() + synth, blocks = next(g) + t = 0 + for nframes in g: + for i in range(nframes): + samples = np.frombuffer(get_buffer(synth)[1], dtype=dtype) / divisor + block_values = [b.value for b in blocks] + for k in range(0, len(samples), channel_count): + print(t, *(list(samples[k : k + channel_count]) + block_values)) + t += 1 + + if _gen is None: + return func + else: + func(_gen) From 27d5fa008ebd817aef20b8d7d8dfb13cb82b228f Mon Sep 17 00:00:00 2001 From: Iqbal Rifai Date: Tue, 5 Nov 2024 13:30:34 +0000 Subject: [PATCH 202/252] Translated using Weblate (Indonesian) Currently translated at 37.3% (372 of 997 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/id/ --- locale/ID.po | 173 +++++++++++++++++++++++++++------------------------ 1 file changed, 92 insertions(+), 81 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 4bc03c8ccd76..973aa69ffb74 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -6,15 +6,15 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-11-16 15:03+0000\n" -"Last-Translator: Scott Shawcroft \n" +"PO-Revision-Date: 2024-11-06 14:00+0000\n" +"Last-Translator: Iqbal Rifai \n" "Language-Team: LANGUAGE \n" "Language: ID\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 5.2\n" +"X-Generator: Weblate 5.8.2\n" #: main.c msgid "" @@ -1714,15 +1714,15 @@ msgstr "Jumlah pin terlalu besar" #: ports/stm/common-hal/alarm/pin/PinAlarm.c #: ports/stm/common-hal/pulseio/PulseIn.c msgid "Pin interrupt already in use" -msgstr "" +msgstr "Pin interupsi sudah digunakan" #: shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c msgid "Pin is input only" -msgstr "" +msgstr "Pin hanya input" #: ports/raspberrypi/common-hal/countio/Counter.c msgid "Pin must be on PWM Channel B" -msgstr "" +msgstr "Pin harus berada di Saluran PWM B" #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format @@ -1741,11 +1741,11 @@ msgstr "Pin harus berurutan" #: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c msgid "Pins must be sequential GPIO pins" -msgstr "" +msgstr "Pin harus merupakan pin GPIO yang berurutan" #: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c msgid "Pins must share PWM slice" -msgstr "" +msgstr "Pin harus berbagi potongan PWM" #: shared-module/usb/core/Device.c msgid "Pipe error" @@ -1757,11 +1757,11 @@ msgstr "Tambahkan module apapun pada filesystem\n" #: shared-module/vectorio/Polygon.c msgid "Polygon needs at least 3 points" -msgstr "" +msgstr "Poligon membutuhkan setidaknya 3 poin" #: supervisor/shared/safe_mode.c msgid "Power dipped. Make sure you are providing enough power." -msgstr "" +msgstr "Daya menurun. Pastikan Anda menyediakan daya yang cukup." #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" @@ -1779,19 +1779,19 @@ msgstr "" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "Program does IN without loading ISR" -msgstr "" +msgstr "Program melakukan IN tanpa memuat ISR" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "Program does OUT without loading OSR" -msgstr "" +msgstr "Program melakukan OUT tanpa memuat OSR" #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "Program size invalid" -msgstr "" +msgstr "Ukuran program tidak valid" #: ports/espressif/common-hal/espulp/ULP.c msgid "Program too long" -msgstr "" +msgstr "Program terlalu lama" #: shared-bindings/digitalio/DigitalInOut.c msgid "Pull not used when direction is output." @@ -1799,11 +1799,11 @@ msgstr "Pull tidak digunakan saat arah output." #: ports/raspberrypi/common-hal/countio/Counter.c msgid "RISE_AND_FALL not available on this chip" -msgstr "" +msgstr "RISE_AND_FALL tidak tersedia pada chip ini" #: shared-module/displayio/OnDiskBitmap.c msgid "RLE-compressed BMP not supported" -msgstr "" +msgstr "BMP-terkompresi RLE tidak didukung" #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" @@ -1844,11 +1844,11 @@ msgstr "sistem file (filesystem) bersifat Read-only" #: ports/espressif/common-hal/espidf/__init__.c msgid "Received response was invalid" -msgstr "" +msgstr "Respon yang diterima tidak valid" #: supervisor/shared/bluetooth/bluetooth.c msgid "Reconnecting" -msgstr "" +msgstr "Menghubungkan kembali" #: shared-bindings/epaperdisplay/EPaperDisplay.c msgid "Refresh too soon" @@ -1856,7 +1856,7 @@ msgstr "Segarkan terlalu cepat" #: shared-bindings/canio/RemoteTransmissionRequest.c msgid "RemoteTransmissionRequests limited to 8 bytes" -msgstr "" +msgstr "RemoteTransmissionRequests dibatasi hingga 8 byte" #: shared-bindings/aesio/aes.c msgid "Requested AES mode is unsupported" @@ -1864,7 +1864,7 @@ msgstr "Mode AES yang diminta tidak didukung" #: ports/espressif/common-hal/espidf/__init__.c msgid "Requested resource not found" -msgstr "" +msgstr "Sumber yang diminta tidak ditemukan" #: ports/atmel-samd/common-hal/audioio/AudioOut.c msgid "Right channel unsupported" @@ -1872,7 +1872,7 @@ msgstr "Channel Kanan tidak didukung" #: shared-module/jpegio/JpegDecoder.c msgid "Right format but not supported" -msgstr "" +msgstr "Format benar tapi tidak didukung" #: main.c msgid "Running in safe mode! Not running saved code.\n" @@ -1882,7 +1882,7 @@ msgstr "" #: shared-module/sdcardio/SDCard.c msgid "SD card CSD format not supported" -msgstr "" +msgstr "Kartu SD Format CSD tidak didukung" #: ports/cxd56/common-hal/sdioio/SDCard.c msgid "SDCard init" @@ -1901,7 +1901,7 @@ msgstr "" #: ports/espressif/common-hal/busio/SPI.c msgid "SPI configuration failed" -msgstr "" +msgstr "Konfigurasi SPI gagal" #: ports/stm/common-hal/busio/SPI.c msgid "SPI init error" @@ -1909,7 +1909,7 @@ msgstr "" #: ports/raspberrypi/common-hal/busio/SPI.c msgid "SPI peripheral in use" -msgstr "" +msgstr "Periferal SPI sedang digunakan" #: ports/stm/common-hal/busio/SPI.c msgid "SPI re-init" @@ -1917,12 +1917,12 @@ msgstr "" #: shared-bindings/is31fl3741/FrameBuffer.c msgid "Scale dimensions must divide by 3" -msgstr "" +msgstr "Skala dimensi harus dibagi 3" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nordic/common-hal/_bleio/Adapter.c msgid "Scan already in progress. Stop with stop_scan." -msgstr "" +msgstr "Pemindaian sedang berjalan. Hentikan dengan stop_scan." #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -1931,11 +1931,11 @@ msgstr "Serializer sedang digunakan" #: shared-bindings/ssl/SSLContext.c msgid "Server side context cannot have hostname" -msgstr "" +msgstr "Context server tidak mendukung hostname" #: ports/cxd56/common-hal/camera/Camera.c msgid "Size not supported" -msgstr "" +msgstr "Ukuran tidak didukung" #: shared-bindings/alarm/SleepMemory.c shared-bindings/memorymap/AddressRange.c #: shared-bindings/nvm/ByteArray.c @@ -1952,7 +1952,7 @@ msgstr "Potongan tidak didukung" #: ports/espressif/common-hal/socketpool/SocketPool.c #: ports/raspberrypi/common-hal/socketpool/SocketPool.c msgid "SocketPool can only be used with wifi.radio" -msgstr "" +msgstr "SocketPool hanya dapat digunakan dengan wifi.radio" #: shared-bindings/aesio/aes.c msgid "Source and destination buffers must be the same length" @@ -1960,19 +1960,19 @@ msgstr "Buffer sumber dan tujuan harus memiliki panjang yang sama" #: shared-bindings/paralleldisplaybus/ParallelBus.c msgid "Specify exactly one of data0 or data_pins" -msgstr "" +msgstr "Pilih hanya satu antara data0 atau data_pins" #: supervisor/shared/safe_mode.c msgid "Stack overflow. Increase stack size." -msgstr "" +msgstr "Stack overflow. Tambahkan ukuran stack." #: shared-bindings/alarm/time/TimeAlarm.c msgid "Supply one of monotonic_time or epoch_time" -msgstr "" +msgstr "Berikan salah satu dari monotonic_time atau epoch_time" #: shared-bindings/gnss/GNSS.c msgid "System entry must be gnss.SatelliteSystem" -msgstr "" +msgstr "Entri sistem harus berupa gnss.SatelliteSystem" #: ports/stm/common-hal/microcontroller/Processor.c msgid "Temperature read timed out" @@ -1980,33 +1980,36 @@ msgstr "Waktu baca suhu habis" #: supervisor/shared/safe_mode.c msgid "The `microcontroller` module was used to boot into safe mode." -msgstr "" +msgstr "Modul `microcontroller` digunakan untuk boot ke mode aman." #: py/obj.c msgid "The above exception was the direct cause of the following exception:" msgstr "" +"Pengecualian di atas adalah penyebab langsung dari pengecualian berikut:" #: shared-bindings/rgbmatrix/RGBMatrix.c msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" -msgstr "" +msgstr "Panjang rgb_pins harus 6, 12, 18, 24, atau 30" #: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" -msgstr "" +msgstr "Sampel punya %q yang tidak cocok" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." -msgstr "" +msgstr "Kesalahan fatal pada firmware pihak ketiga." #: shared-module/imagecapture/ParallelImageCapture.c msgid "This microcontroller does not support continuous capture." -msgstr "" +msgstr "Mikrokontroler ini tidak mendukung penangkapan berkelanjutan." #: shared-module/paralleldisplaybus/ParallelBus.c msgid "" "This microcontroller only supports data0=, not data_pins=, because it " "requires contiguous pins." msgstr "" +"Mikrokontroler ini hanya mendukung data0=, bukan data_pins=, karena " +"membutuhkan pin yang berurutan." #: shared-bindings/displayio/TileGrid.c msgid "Tile height must exactly divide bitmap height" @@ -2022,17 +2025,18 @@ msgstr "Lebar ubin harus persis membagi lebar bitmap" #: shared-bindings/alarm/time/TimeAlarm.c msgid "Time is in the past." -msgstr "" +msgstr "Waktu sudah berlalu." #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nordic/common-hal/_bleio/Adapter.c #, c-format msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" +"Waktu tunggu terlalu lama: Panjang maksimum waktu tunggu adalah %d detik" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c msgid "Too many channels in sample" -msgstr "" +msgstr "Sampel memiliki terlalu banyak saluran" #: ports/raspberrypi/common-hal/audiobusio/I2SOut.c msgid "Too many channels in sample." @@ -2040,11 +2044,13 @@ msgstr "Terlalu banyak channel dalam sampel" #: ports/espressif/common-hal/_bleio/Characteristic.c msgid "Too many descriptors" -msgstr "" +msgstr "Terlalu banyak deskriptor" #: shared-module/displayio/__init__.c msgid "Too many display busses; forgot displayio.release_displays() ?" msgstr "" +"Terlalu banyak jalur tampilan; mungkin kamu lupa untuk panggil displayio." +"release_displays()?" #: shared-module/displayio/__init__.c msgid "Too many displays" @@ -2053,12 +2059,12 @@ msgstr "Terlalu banyak tampilan" #: ports/espressif/common-hal/_bleio/PacketBuffer.c #: ports/nordic/common-hal/_bleio/PacketBuffer.c msgid "Total data to write is larger than %q" -msgstr "" +msgstr "Total data yang akan ditulis lebih besar dari %q" #: ports/raspberrypi/common-hal/alarm/touch/TouchAlarm.c #: ports/stm/common-hal/alarm/touch/TouchAlarm.c msgid "Touch alarms not available" -msgstr "" +msgstr "Alarm sentuh tidak tersedia" #: py/obj.c msgid "Traceback (most recent call last):\n" @@ -2075,7 +2081,7 @@ msgstr "" #: ports/raspberrypi/common-hal/busio/UART.c msgid "UART peripheral in use" -msgstr "" +msgstr "Periferal UART sedang digunakan" #: ports/stm/common-hal/busio/UART.c msgid "UART re-init" @@ -2095,11 +2101,11 @@ msgstr "" #: supervisor/shared/safe_mode.c msgid "USB devices need more endpoints than are available." -msgstr "" +msgstr "Perangkat USB butuh lebih banyak endpoint daripada yang tersedia." #: supervisor/shared/safe_mode.c msgid "USB devices specify too many interface names." -msgstr "" +msgstr "Perangkat USB menggunakan terlalu banyak nama antarmuka." #: shared-module/usb_hid/Device.c msgid "USB error" @@ -2119,7 +2125,7 @@ msgstr "Nilai UUID bukan str, int atau byte buffer" #: ports/raspberrypi/common-hal/memorymap/AddressRange.c msgid "Unable to access unaligned IO register" -msgstr "" +msgstr "Tidak dapat mengakses register IO yang tidak teratur" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -2130,11 +2136,11 @@ msgstr "Tidak dapat mengalokasikan buffer untuk signed conversion" #: supervisor/shared/safe_mode.c msgid "Unable to allocate to the heap." -msgstr "" +msgstr "Tidak dapat mengalokasikan ke heap." #: ports/espressif/common-hal/busio/I2C.c msgid "Unable to create lock" -msgstr "" +msgstr "Tidak dapat membuat kunci" #: shared-module/i2cdisplaybus/I2CDisplayBus.c #: shared-module/is31fl3741/IS31FL3741.c @@ -2153,7 +2159,7 @@ msgstr "Tidak dapat membaca data palet warna" #: ports/espressif/common-hal/mdns/Server.c #: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" -msgstr "" +msgstr "Tidak dapat memulai kueri mDNS" #: shared-bindings/nvm/ByteArray.c msgid "Unable to write to nvm." @@ -2161,11 +2167,11 @@ msgstr "Tidak dapat menulis ke nvm." #: ports/raspberrypi/common-hal/memorymap/AddressRange.c msgid "Unable to write to read-only memory" -msgstr "" +msgstr "Tidak dapat menulis ke memori hanya-baca" #: shared-bindings/alarm/SleepMemory.c msgid "Unable to write to sleep_memory." -msgstr "" +msgstr "Tidak dapat menulis ke sleep_memory." #: ports/nordic/common-hal/_bleio/UUID.c msgid "Unexpected nrfx uuid type" @@ -2174,23 +2180,23 @@ msgstr "Tipe urf nrfx tak sesuai" #: ports/espressif/common-hal/_bleio/__init__.c #, c-format msgid "Unknown BLE error at %s:%d: %d" -msgstr "" +msgstr "Kesalahan BLE tidak diketahui di %s:%d: %d" #: ports/espressif/common-hal/_bleio/__init__.c #, c-format msgid "Unknown BLE error: %d" -msgstr "" +msgstr "Kesalahan BLE tidak diketahui: %d" #: ports/espressif/common-hal/max3421e/Max3421E.c #: ports/raspberrypi/common-hal/wifi/__init__.c #, c-format msgid "Unknown error code %d" -msgstr "" +msgstr "Kode kesalahan tidak diketahui %d" #: shared-bindings/wifi/Radio.c #, c-format msgid "Unknown failure %d" -msgstr "" +msgstr "Kegagalan tidak diketahui %d" #: ports/nordic/common-hal/_bleio/__init__.c #, c-format @@ -2210,17 +2216,17 @@ msgstr "Kesalahan keamanan tidak dikenal: 0x%04x" #: ports/espressif/common-hal/_bleio/__init__.c #, c-format msgid "Unknown system firmware error at %s:%d: %d" -msgstr "" +msgstr "Kesalahan firmware sistem tidak dikenal di %s:%d: %d" #: ports/nordic/common-hal/_bleio/__init__.c #, c-format msgid "Unknown system firmware error: %04x" -msgstr "" +msgstr "Kesalahan firmware sistem tidak diketahui: %04x" #: ports/espressif/common-hal/_bleio/__init__.c #, c-format msgid "Unknown system firmware error: %d" -msgstr "" +msgstr "Kesalahan firmware sistem tidak diketahui: %d" #: shared-bindings/adafruit_pixelbuf/PixelBuf.c #: shared-module/_pixelmap/PixelMap.c @@ -2250,16 +2256,16 @@ msgstr "Format tidak didukung" #: shared-bindings/hashlib/__init__.c msgid "Unsupported hash algorithm" -msgstr "" +msgstr "Algoritma hash tidak didukung" #: ports/espressif/common-hal/socketpool/Socket.c msgid "Unsupported socket type" -msgstr "" +msgstr "Jenis soket tidak didukung" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/espressif/common-hal/dualbank/__init__.c msgid "Update failed" -msgstr "" +msgstr "Pembaruan gagal" #: ports/espressif/common-hal/_bleio/Characteristic.c #: ports/nordic/common-hal/_bleio/Characteristic.c @@ -2275,7 +2281,7 @@ msgstr "Panjang nilai > max_length" #: ports/espressif/common-hal/espidf/__init__.c msgid "Version was invalid" -msgstr "" +msgstr "Versi tidak valid" #: ports/stm/common-hal/microcontroller/Processor.c msgid "Voltage read timed out" @@ -2287,7 +2293,7 @@ msgstr "PERINGATAN: Nama file kode anda mempunyai dua ekstensi\n" #: ports/nordic/common-hal/watchdog/WatchDogTimer.c msgid "WatchDogTimer cannot be deinitialized once mode is set to RESET" -msgstr "" +msgstr "WatchDogTimer tidak dapat dideinisialisasi setelah mode diatur ke RESET" #: py/builtinhelp.c #, c-format @@ -2298,6 +2304,11 @@ msgid "" "\n" "To list built-in modules type `help(\"modules\")`.\n" msgstr "" +"Selamat datang di Adafruit CircuitPython %s!\n" +"\n" +"Kunjungi circuitpython.org untuk informasi lebih lanjut.\n" +"\n" +"Untuk membuat daftar modul bawaan, ketik `help(\"modules\")`.\n" #: supervisor/shared/web_workflow/web_workflow.c msgid "Wi-Fi: " @@ -2305,7 +2316,7 @@ msgstr "" #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "Wifi is not enabled" -msgstr "" +msgstr "Wifi tidak diaktifkan" #: main.c msgid "Woken up by alarm.\n" @@ -2321,63 +2332,63 @@ msgstr "Menulis tidak didukung pada Karakteristik" #: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h #: ports/atmel-samd/boards/meowmeow/mpconfigboard.h msgid "You pressed both buttons at start up." -msgstr "" +msgstr "Anda menekan kedua tombol saat memulai." #: ports/espressif/boards/m5stack_core_basic/mpconfigboard.h #: ports/espressif/boards/m5stack_core_fire/mpconfigboard.h #: ports/espressif/boards/m5stack_stick_c/mpconfigboard.h #: ports/espressif/boards/m5stack_stick_c_plus/mpconfigboard.h msgid "You pressed button A at start up." -msgstr "" +msgstr "Anda menekan tombol A saat memulai." #: ports/espressif/boards/m5stack_m5paper/mpconfigboard.h msgid "You pressed button DOWN at start up." -msgstr "" +msgstr "Anda menekan tombol DOWN saat memulai." #: supervisor/shared/safe_mode.c msgid "You pressed the BOOT button at start up" -msgstr "" +msgstr "Anda menekan tombol BOOT saat memulai" #: ports/espressif/boards/adafruit_feather_esp32c6_4mbflash_nopsram/mpconfigboard.h #: ports/espressif/boards/adafruit_itsybitsy_esp32/mpconfigboard.h msgid "You pressed the BOOT button at start up." -msgstr "" +msgstr "Anda menekan tombol BOOT saat memulai" #: ports/espressif/boards/adafruit_huzzah32_breakout/mpconfigboard.h msgid "You pressed the GPIO0 button at start up." -msgstr "" +msgstr "Anda menekan tombol GPIO0 saat memulai." #: ports/espressif/boards/espressif_esp32_lyrat/mpconfigboard.h msgid "You pressed the Rec button at start up." -msgstr "" +msgstr "Anda menekan tombol Rec saat memulai." #: ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h msgid "You pressed the SW38 button at start up." -msgstr "" +msgstr "Anda menekan tombol SW38 saat memulai." #: ports/espressif/boards/hardkernel_odroid_go/mpconfigboard.h #: ports/espressif/boards/vidi_x/mpconfigboard.h msgid "You pressed the VOLUME button at start up." -msgstr "" +msgstr "Anda menekan tombol VOLUME saat memulai." #: ports/espressif/boards/m5stack_atom_echo/mpconfigboard.h #: ports/espressif/boards/m5stack_atom_lite/mpconfigboard.h #: ports/espressif/boards/m5stack_atom_matrix/mpconfigboard.h #: ports/espressif/boards/m5stack_atom_u/mpconfigboard.h msgid "You pressed the central button at start up." -msgstr "" +msgstr "Anda menekan tombol tengah saat memulai." #: ports/nordic/boards/aramcon2_badge/mpconfigboard.h msgid "You pressed the left button at start up." -msgstr "" +msgstr "Anda menekan tombol kiri saat memulai." #: supervisor/shared/safe_mode.c msgid "You pressed the reset button during boot." -msgstr "" +msgstr "Anda menekan tombol reset saat memulai." #: supervisor/shared/micropython.c msgid "[truncated due to length]" -msgstr "" +msgstr "[terpotong karena kepanjangan]" #: py/objtype.c msgid "__init__() should return None" @@ -2402,11 +2413,11 @@ msgstr "alamatnya kosong" #: py/compile.c msgid "annotation must be an identifier" -msgstr "" +msgstr "anotasi harus merupakan pengidentifikasi" #: extmod/ulab/code/numpy/create.c msgid "arange: cannot compute length" -msgstr "" +msgstr "arange: tidak dapat menghitung panjang" #: py/modbuiltins.c msgid "arg is an empty sequence" @@ -2414,7 +2425,7 @@ msgstr "arg berisi urutan kosong" #: py/objobject.c msgid "arg must be user-type" -msgstr "" +msgstr "arg harus bertipe user-type" #: extmod/ulab/code/numpy/numerical.c msgid "argsort argument must be an ndarray" From d3f56cf0e4a47c010e2ec6a67b6aeb54de5c9a91 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 7 Nov 2024 10:50:32 -0600 Subject: [PATCH 203/252] make the default variant 'coverage' This means that the variant no longer needs to be explicitly named and you can just run `make test`. --- ports/unix/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 526955b1ea5c..cd0403a8f5df 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -4,8 +4,9 @@ ifdef VARIANT_DIR # the path as the variant name. VARIANT ?= $(notdir $(VARIANT_DIR:/=)) else -# If not given on the command line, then default to standard. -VARIANT ?= standard +# CIRCUITPY-CHANGE: default variant is coverage +# If not given on the command line, then default to coverage. +VARIANT ?= coverage VARIANT_DIR ?= variants/$(VARIANT) endif From 941e1228f2cfe1602a1d98034ad2413a127dbb46 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Thu, 7 Nov 2024 13:03:59 -0600 Subject: [PATCH 204/252] Rename `filters` back to `filter` and support individual Biquad object and tuple of Biquad objects. --- locale/circuitpython.pot | 11 +++- shared-bindings/audiofilters/Filter.c | 40 ++++++------- shared-bindings/audiofilters/Filter.h | 6 +- shared-module/audiofilters/Filter.c | 83 +++++++++++++++++---------- shared-module/audiofilters/Filter.h | 5 +- 5 files changed, 88 insertions(+), 57 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index a6acb8a644fb..b604ed388375 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -187,6 +187,10 @@ msgstr "" msgid "%q must be >= %d" msgstr "" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "" @@ -1274,6 +1278,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "" @@ -1970,7 +1975,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2504,7 +2510,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/shared-bindings/audiofilters/Filter.c b/shared-bindings/audiofilters/Filter.c index 53c36b2d64d5..e8e6fbfa5e7f 100644 --- a/shared-bindings/audiofilters/Filter.c +++ b/shared-bindings/audiofilters/Filter.c @@ -23,7 +23,7 @@ //| //| def __init__( //| self, -//| filters: Optional[List[synthio.Biquad]] = None, +//| filter: Optional[synthio.Biquad | Tuple[synthio.Biquad]] = None, //| mix: synthio.BlockInput = 1.0, //| buffer_size: int = 512, //| sample_rate: int = 8000, @@ -38,7 +38,7 @@ //| The mix parameter allows you to change how much of the unchanged sample passes through to //| the output to how much of the effect audio you hear as the output. //| -//| :param Optional[List[synthio.Biquad]] filters: A list of normalized biquad filter objects used to process the signal. +//| :param Optional[synthio.Biquad|Tuple[synthio.Biquad]] filter: A normalized biquad filter object or tuple of normalized biquad filter objects. The sample is processed sequentially by each filter to produce the output samples. //| :param synthio.BlockInput mix: The mix as a ratio of the sample (0.0) to the effect (1.0). //| :param int buffer_size: The total size in bytes of each of the two playback buffers to use //| :param int sample_rate: The sample rate to be used @@ -57,7 +57,7 @@ //| audio = audiobusio.I2SOut(bit_clock=board.GP20, word_select=board.GP21, data=board.GP22) //| synth = synthio.Synthesizer(channel_count=1, sample_rate=44100) //| effect = audiofilters.Filter(buffer_size=1024, channel_count=1, sample_rate=44100, mix=1.0) -//| effect.filters.append(synth.low_pass_filter(frequency=2000, Q=1.25)) +//| effect.filter = synth.low_pass_filter(frequency=2000, Q=1.25) //| effect.play(synth) //| audio.play(effect) //| @@ -69,9 +69,9 @@ //| time.sleep(5)""" //| ... static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_filters, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; + enum { ARG_filter, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_filters, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_mix, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_buffer_size, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 512} }, { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, @@ -91,7 +91,7 @@ static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n } audiofilters_filter_obj_t *self = mp_obj_malloc(audiofilters_filter_obj_t, &audiofilters_filter_type); - common_hal_audiofilters_filter_construct(self, args[ARG_filters].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); + common_hal_audiofilters_filter_construct(self, args[ARG_filter].u_obj, args[ARG_mix].u_obj, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); return MP_OBJ_FROM_PTR(self); } @@ -129,34 +129,34 @@ static mp_obj_t audiofilters_filter_obj___exit__(size_t n_args, const mp_obj_t * static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiofilters_filter___exit___obj, 4, 4, audiofilters_filter_obj___exit__); -//| filters: List[synthio.Biquad] -//| """A list of normalized biquad filter objects used to process the signal.""" +//| filter: synthio.Biquad | Tuple[synthio.Biquad] | None +//| """A normalized biquad filter object or tuple of normalized biquad filter objects. The sample is processed sequentially by each filter to produce the output samples.""" //| -static mp_obj_t audiofilters_filter_obj_get_filters(mp_obj_t self_in) { +static mp_obj_t audiofilters_filter_obj_get_filter(mp_obj_t self_in) { audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - return common_hal_audiofilters_filter_get_filters(self); + return common_hal_audiofilters_filter_get_filter(self); } -MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_filters_obj, audiofilters_filter_obj_get_filters); +MP_DEFINE_CONST_FUN_OBJ_1(audiofilters_filter_get_filter_obj, audiofilters_filter_obj_get_filter); -static mp_obj_t audiofilters_filter_obj_set_filters(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_filters }; +static mp_obj_t audiofilters_filter_obj_set_filter(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_filter }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_filters, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, + { MP_QSTR_filter, MP_ARG_OBJ | MP_ARG_REQUIRED, {} }, }; audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - common_hal_audiofilters_filter_set_filters(self, args[ARG_filters].u_obj); + common_hal_audiofilters_filter_set_filter(self, args[ARG_filter].u_obj); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_set_filters_obj, 1, audiofilters_filter_obj_set_filters); +MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_set_filter_obj, 1, audiofilters_filter_obj_set_filter); -MP_PROPERTY_GETSET(audiofilters_filter_filters_obj, - (mp_obj_t)&audiofilters_filter_get_filters_obj, - (mp_obj_t)&audiofilters_filter_set_filters_obj); +MP_PROPERTY_GETSET(audiofilters_filter_filter_obj, + (mp_obj_t)&audiofilters_filter_get_filter_obj, + (mp_obj_t)&audiofilters_filter_set_filter_obj); //| mix: synthio.BlockInput @@ -245,7 +245,7 @@ static const mp_rom_map_elem_t audiofilters_filter_locals_dict_table[] = { // Properties { MP_ROM_QSTR(MP_QSTR_playing), MP_ROM_PTR(&audiofilters_filter_playing_obj) }, - { MP_ROM_QSTR(MP_QSTR_filters), MP_ROM_PTR(&audiofilters_filter_filters_obj) }, + { MP_ROM_QSTR(MP_QSTR_filter), MP_ROM_PTR(&audiofilters_filter_filter_obj) }, { MP_ROM_QSTR(MP_QSTR_mix), MP_ROM_PTR(&audiofilters_filter_mix_obj) }, }; static MP_DEFINE_CONST_DICT(audiofilters_filter_locals_dict, audiofilters_filter_locals_dict_table); diff --git a/shared-bindings/audiofilters/Filter.h b/shared-bindings/audiofilters/Filter.h index 3cbca2c9ee28..739b625ee6c5 100644 --- a/shared-bindings/audiofilters/Filter.h +++ b/shared-bindings/audiofilters/Filter.h @@ -11,7 +11,7 @@ extern const mp_obj_type_t audiofilters_filter_type; void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, - mp_obj_t filters, mp_obj_t mix, + mp_obj_t filter, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate); @@ -22,8 +22,8 @@ uint32_t common_hal_audiofilters_filter_get_sample_rate(audiofilters_filter_obj_ uint8_t common_hal_audiofilters_filter_get_channel_count(audiofilters_filter_obj_t *self); uint8_t common_hal_audiofilters_filter_get_bits_per_sample(audiofilters_filter_obj_t *self); -mp_obj_t common_hal_audiofilters_filter_get_filters(audiofilters_filter_obj_t *self); -void common_hal_audiofilters_filter_set_filters(audiofilters_filter_obj_t *self, mp_obj_t arg); +mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self); +void common_hal_audiofilters_filter_set_filter(audiofilters_filter_obj_t *self, mp_obj_t arg); mp_obj_t common_hal_audiofilters_filter_get_mix(audiofilters_filter_obj_t *self); void common_hal_audiofilters_filter_set_mix(audiofilters_filter_obj_t *self, mp_obj_t arg); diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index e22133a25b61..dd2ccb8ff881 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -9,7 +9,7 @@ #include "py/runtime.h" void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, - mp_obj_t filters, mp_obj_t mix, + mp_obj_t filter, mp_obj_t mix, uint32_t buffer_size, uint8_t bits_per_sample, bool samples_signed, uint8_t channel_count, uint32_t sample_rate) { @@ -60,11 +60,10 @@ void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, // The below section sets up the effect's starting values. - if (filters == MP_OBJ_NULL) { - filters = mp_obj_new_list(0, NULL); + if (filter == MP_OBJ_NULL) { + filter = mp_const_none; } - self->filters = filters; - reset_filter_states(self); + common_hal_audiofilters_filter_set_filter(self, filter); // If we did not receive a BlockInput we need to create a default float value if (mix == MP_OBJ_NULL) { @@ -91,32 +90,59 @@ void common_hal_audiofilters_filter_deinit(audiofilters_filter_obj_t *self) { } void reset_filter_states(audiofilters_filter_obj_t *self) { - self->filter_states_len = self->filters->len; + self->filter_states_len = 0; self->filter_states = NULL; - if (self->filter_states_len) { - self->filter_states = m_malloc(self->filter_states_len * sizeof(biquad_filter_state)); - if (self->filter_states == NULL) { - common_hal_audiofilters_filter_deinit(self); - m_malloc_fail(self->filter_states_len * sizeof(biquad_filter_state)); - } + mp_obj_t *items; + if (mp_obj_is_type(self->filter, (const mp_obj_type_t *)&synthio_biquad_type_obj)) { + self->filter_states_len = 1; + items = self->filter; + } else if (mp_obj_is_tuple_compatible(self->filter)) { + mp_obj_tuple_get(self->filter, &self->filter_states_len, &items); + } + + if (!self->filter_states_len) { + return; + } + + self->filter_states = m_malloc(self->filter_states_len * sizeof(biquad_filter_state)); + if (self->filter_states == NULL) { + common_hal_audiofilters_filter_deinit(self); + m_malloc_fail(self->filter_states_len * sizeof(biquad_filter_state)); + } - mp_obj_iter_buf_t iter_buf; - mp_obj_t iterable = mp_getiter(self->filters, &iter_buf); - mp_obj_t item; - uint8_t i = 0; - while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { - synthio_biquad_filter_assign(&self->filter_states[i++], item); + if (mp_obj_is_type(items, (const mp_obj_type_t *)&synthio_biquad_type_obj)) { + synthio_biquad_filter_assign(&self->filter_states[0], items); + } else { + for (size_t i = 0; i < self->filter_states_len; i++) { + synthio_biquad_filter_assign(&self->filter_states[i], items[i]); } } } -mp_obj_t common_hal_audiofilters_filter_get_filters(audiofilters_filter_obj_t *self) { - return self->filters; +mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *self) { + if (mp_obj_is_type(self->filter, (const mp_obj_type_t *)&synthio_biquad_type_obj) || mp_obj_is_tuple_compatible(self->filter)) { + return self->filter; + } else { + return mp_const_none; + } } -void common_hal_audiofilters_filter_set_filters(audiofilters_filter_obj_t *self, mp_obj_t arg) { - self->filters = arg; +void common_hal_audiofilters_filter_set_filter(audiofilters_filter_obj_t *self, mp_obj_t arg) { + if (arg == mp_const_none || mp_obj_is_type(arg, (const mp_obj_type_t *)&synthio_biquad_type_obj)) { + self->filter = arg; + } else if (mp_obj_is_tuple_compatible(arg)) { + mp_obj_tuple_t *tuple_obj = (mp_obj_tuple_t *)MP_OBJ_TO_PTR(arg); + self->filter = mp_obj_new_tuple(tuple_obj->len, tuple_obj->items); + } else if (mp_obj_is_type(arg, &mp_type_list)) { + size_t list_len; + mp_obj_t *list_items; + mp_obj_list_get(arg, &list_len, &list_items); + self->filter = mp_obj_new_tuple(list_len, list_items); + } else { + mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be a %q object, %q, or %q"), MP_QSTR_filter, MP_QSTR_Biquad, MP_QSTR_tuple, MP_QSTR_None); + } + reset_filter_states(self); } @@ -148,8 +174,10 @@ void audiofilters_filter_reset_buffer(audiofilters_filter_obj_t *self, memset(self->buffer[1], 0, self->buffer_len); memset(self->filter_buffer, 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); - for (uint8_t i = 0; i < self->filter_states_len; i++) { - synthio_biquad_filter_reset(&self->filter_states[i]); + if (self->filter_states) { + for (uint8_t i = 0; i < self->filter_states_len; i++) { + synthio_biquad_filter_reset(&self->filter_states[i]); + } } } @@ -233,11 +261,6 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o channel = 0; } - // Update filter_states if filters list has been appended or removed - if (self->filters->len != self->filter_states_len) { - reset_filter_states(self); - } - // get the effect values we need from the BlockInput. These may change at run time so you need to do bounds checking if required mp_float_t mix = MIN(1.0, MAX(synthio_block_slot_get(&self->mix), 0.0)); @@ -277,7 +300,7 @@ audioio_get_buffer_result_t audiofilters_filter_get_buffer(audiofilters_filter_o int16_t *sample_src = (int16_t *)self->sample_remaining_buffer; // for 16-bit samples int8_t *sample_hsrc = (int8_t *)self->sample_remaining_buffer; // for 8-bit samples - if (mix <= 0.01 || !self->filter_states_len) { // if mix is zero pure sample only or no biquad filter objects are provided + if (mix <= 0.01 || !self->filter_states) { // if mix is zero pure sample only or no biquad filter objects are provided for (uint32_t i = 0; i < n; i++) { if (MP_LIKELY(self->bits_per_sample == 16)) { word_buffer[i] = sample_src[i]; diff --git a/shared-module/audiofilters/Filter.h b/shared-module/audiofilters/Filter.h index 7d1ee4db1a39..e2ac4e5b7276 100644 --- a/shared-module/audiofilters/Filter.h +++ b/shared-module/audiofilters/Filter.h @@ -7,6 +7,7 @@ #include "py/obj.h" +#include "shared-bindings/synthio/Biquad.h" #include "shared-module/audiocore/__init__.h" #include "shared-module/synthio/block.h" #include "shared-module/synthio/Biquad.h" @@ -15,10 +16,10 @@ extern const mp_obj_type_t audiofilters_filter_type; typedef struct { mp_obj_base_t base; - mp_obj_list_t *filters; + mp_obj_t *filter; synthio_block_slot_t mix; - uint8_t filter_states_len; + size_t filter_states_len; biquad_filter_state *filter_states; uint8_t bits_per_sample; From 5f8ec0afc6f9d1e461abb01da3341050e339e122 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Thu, 7 Nov 2024 13:58:01 -0600 Subject: [PATCH 205/252] Validate type of filter tuple items. --- shared-module/audiofilters/Filter.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index dd2ccb8ff881..82a9c9f81edd 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -131,14 +131,18 @@ mp_obj_t common_hal_audiofilters_filter_get_filter(audiofilters_filter_obj_t *se void common_hal_audiofilters_filter_set_filter(audiofilters_filter_obj_t *self, mp_obj_t arg) { if (arg == mp_const_none || mp_obj_is_type(arg, (const mp_obj_type_t *)&synthio_biquad_type_obj)) { self->filter = arg; - } else if (mp_obj_is_tuple_compatible(arg)) { - mp_obj_tuple_t *tuple_obj = (mp_obj_tuple_t *)MP_OBJ_TO_PTR(arg); - self->filter = mp_obj_new_tuple(tuple_obj->len, tuple_obj->items); - } else if (mp_obj_is_type(arg, &mp_type_list)) { - size_t list_len; - mp_obj_t *list_items; - mp_obj_list_get(arg, &list_len, &list_items); - self->filter = mp_obj_new_tuple(list_len, list_items); + } else if (mp_obj_is_tuple_compatible(arg) || mp_obj_is_type(arg, &mp_type_list)) { + size_t tuple_len; + mp_obj_t *tuple_items = NULL; + + mp_obj_get_array(arg, &tuple_len, &tuple_items); + + mp_obj_t *biquad_objects[tuple_len]; + for (size_t i = 0; i < tuple_len; i++) { + biquad_objects[i] = mp_arg_validate_type_in(tuple_items[i], (const mp_obj_type_t *)&synthio_biquad_type_obj, MP_QSTR_filter); + } + + self->filter = mp_obj_new_tuple(tuple_len, (const mp_obj_t *)biquad_objects); } else { mp_raise_ValueError_varg(MP_ERROR_TEXT("%q must be a %q object, %q, or %q"), MP_QSTR_filter, MP_QSTR_Biquad, MP_QSTR_tuple, MP_QSTR_None); } From 6ff3860ec8da590cf6ce90d45f69cf7f72ac76db Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 7 Nov 2024 13:55:27 -0600 Subject: [PATCH 206/252] Synthesizer: Match documentation to implementation. The docstrings incorrectly gave the name of the argument; the code only accepts the argument name "Q": ``` { MP_QSTR_Q, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL } }, ``` --- shared-bindings/synthio/Synthesizer.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/shared-bindings/synthio/Synthesizer.c b/shared-bindings/synthio/Synthesizer.c index 87ea44de6948..94595013b494 100644 --- a/shared-bindings/synthio/Synthesizer.c +++ b/shared-bindings/synthio/Synthesizer.c @@ -287,13 +287,13 @@ MP_PROPERTY_GETTER(synthio_synthesizer_blocks_obj, //| """Maximum polyphony of the synthesizer (read-only class property)""" //| -//| def low_pass_filter(cls, frequency: float, q_factor: float = 0.7071067811865475) -> Biquad: +//| def low_pass_filter(cls, frequency: float, Q: float = 0.7071067811865475) -> Biquad: //| """Construct a low-pass filter with the given parameters. //| //| ``frequency``, called f0 in the cookbook, is the corner frequency in Hz //| of the filter. //| -//| ``q_factor``, called ``Q`` in the cookbook. Controls how peaked the response will be at the cutoff frequency. A large value makes the response more peaked. +//| ``Q`` controls how peaked the response will be at the cutoff frequency. A large value makes the response more peaked. //| """ enum passfilter_arg_e { ARG_f0, ARG_Q }; @@ -328,15 +328,13 @@ static mp_obj_t synthio_synthesizer_lpf(size_t n_pos, const mp_obj_t *pos_args, MP_DEFINE_CONST_FUN_OBJ_KW(synthio_synthesizer_lpf_fun_obj, 1, synthio_synthesizer_lpf); -//| def high_pass_filter( -//| cls, frequency: float, q_factor: float = 0.7071067811865475 -//| ) -> Biquad: +//| def high_pass_filter(cls, frequency: float, Q: float = 0.7071067811865475) -> Biquad: //| """Construct a high-pass filter with the given parameters. //| //| ``frequency``, called f0 in the cookbook, is the corner frequency in Hz //| of the filter. //| -//| ``q_factor``, called ``Q`` in the cookbook. Controls how peaked the response will be at the cutoff frequency. A large value makes the response more peaked. +//| ``Q`` controls how peaked the response will be at the cutoff frequency. A large value makes the response more peaked. //| """ static mp_obj_t synthio_synthesizer_hpf(size_t n_pos, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -358,15 +356,13 @@ static mp_obj_t synthio_synthesizer_hpf(size_t n_pos, const mp_obj_t *pos_args, } -//| def band_pass_filter( -//| cls, frequency: float, q_factor: float = 0.7071067811865475 -//| ) -> Biquad: +//| def band_pass_filter(cls, frequency: float, Q: float = 0.7071067811865475) -> Biquad: //| """Construct a band-pass filter with the given parameters. //| //| ``frequency``, called f0 in the cookbook, is the center frequency in Hz //| of the filter. //| -//| ``q_factor``, called ``Q`` in the cookbook. Controls how peaked the response will be at the cutoff frequency. A large value makes the response more peaked. +//| ``Q`` Controls how peaked the response will be at the cutoff frequency. A large value makes the response more peaked. //| //| The coefficients are scaled such that the filter has a 0dB peak gain. //| """ From c06e6ee03e8638c7c731ea8793390a9a1ed93921 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 7 Nov 2024 13:51:26 -0600 Subject: [PATCH 207/252] BlockBiquad: Use `Q` as argument name Synthesizer.lpf takes `Q` as the argument name, use the same convention here. --- .../raspberry_pi_pico2/mpconfigboard.mk | 1 + shared-bindings/synthio/BlockBiquad.c | 28 +++++++++---------- shared-bindings/synthio/BlockBiquad.h | 4 +-- shared-module/synthio/BlockBiquad.c | 8 +++--- tests/circuitpython/synthio_block_biquad.py | 2 +- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk index 43328dd47094..30eed9142c5d 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk @@ -10,3 +10,4 @@ CHIP_FAMILY = rp2 EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" CIRCUITPY__EVE = 1 +CIRCUITPY_SSL = 1 diff --git a/shared-bindings/synthio/BlockBiquad.c b/shared-bindings/synthio/BlockBiquad.c index 510d52872499..dc67a4065c1f 100644 --- a/shared-bindings/synthio/BlockBiquad.c +++ b/shared-bindings/synthio/BlockBiquad.c @@ -48,11 +48,11 @@ static synthio_filter_mode validate_synthio_filter_mode(mp_obj_t obj, qstr arg_n //| self, //| mode: FilterMode, //| frequency: BlockInput, -//| q_factor: BlockInput = 0.7071067811865475, +//| Q: BlockInput = 0.7071067811865475, //| ) -> None: //| """Construct a biquad filter object with dynamic center frequency & q factor //| -//| Since ``frequency`` and ``q_factor`` are `BlockInput` objects, they can +//| Since ``frequency`` and ``Q`` are `BlockInput` objects, they can //| be varied dynamically. Internally, this is evaluated as "direct form 1" //| biquad filter. //| @@ -115,29 +115,29 @@ MP_PROPERTY_GETSET(synthio_block_biquad_frequency_obj, //| -//| q_factor: BlockInput -//| """The sharpness (q_factor) of the filter""" +//| Q: BlockInput +//| """The sharpness (Q) of the filter""" //| -static mp_obj_t synthio_block_biquad_get_q_factor(mp_obj_t self_in) { +static mp_obj_t synthio_block_biquad_get_Q(mp_obj_t self_in) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); - return common_hal_synthio_block_biquad_get_q_factor(self); + return common_hal_synthio_block_biquad_get_Q(self); } -MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_q_factor_obj, synthio_block_biquad_get_q_factor); +MP_DEFINE_CONST_FUN_OBJ_1(synthio_block_biquad_get_Q_obj, synthio_block_biquad_get_Q); -static mp_obj_t synthio_block_biquad_set_q_factor(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t synthio_block_biquad_set_Q(mp_obj_t self_in, mp_obj_t arg) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_synthio_block_biquad_set_q_factor(self, arg); + common_hal_synthio_block_biquad_set_Q(self, arg); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_q_factor_obj, synthio_block_biquad_set_q_factor); -MP_PROPERTY_GETSET(synthio_block_biquad_q_factor_obj, - (mp_obj_t)&synthio_block_biquad_get_q_factor_obj, - (mp_obj_t)&synthio_block_biquad_set_q_factor_obj); +MP_DEFINE_CONST_FUN_OBJ_2(synthio_block_biquad_set_Q_obj, synthio_block_biquad_set_Q); +MP_PROPERTY_GETSET(synthio_block_biquad_Q_obj, + (mp_obj_t)&synthio_block_biquad_get_Q_obj, + (mp_obj_t)&synthio_block_biquad_set_Q_obj); static const mp_rom_map_elem_t synthio_block_biquad_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_mode), MP_ROM_PTR(&synthio_block_biquad_mode_obj) }, { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&synthio_block_biquad_frequency_obj) }, - { MP_ROM_QSTR(MP_QSTR_q_factor), MP_ROM_PTR(&synthio_block_biquad_q_factor_obj) }, + { MP_ROM_QSTR(MP_QSTR_Q), MP_ROM_PTR(&synthio_block_biquad_Q_obj) }, }; static MP_DEFINE_CONST_DICT(synthio_block_biquad_locals_dict, synthio_block_biquad_locals_dict_table); diff --git a/shared-bindings/synthio/BlockBiquad.h b/shared-bindings/synthio/BlockBiquad.h index ca32ef6363b5..a61b60263230 100644 --- a/shared-bindings/synthio/BlockBiquad.h +++ b/shared-bindings/synthio/BlockBiquad.h @@ -17,8 +17,8 @@ typedef enum { } synthio_filter_mode; -mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self); -void common_hal_synthio_block_biquad_set_q_factor(synthio_block_biquad_t *self, mp_obj_t Q); +mp_obj_t common_hal_synthio_block_biquad_get_Q(synthio_block_biquad_t *self); +void common_hal_synthio_block_biquad_set_Q(synthio_block_biquad_t *self, mp_obj_t Q); mp_obj_t common_hal_synthio_block_biquad_get_frequency(synthio_block_biquad_t *self); void common_hal_synthio_block_biquad_set_frequency(synthio_block_biquad_t *self, mp_obj_t frequency); diff --git a/shared-module/synthio/BlockBiquad.c b/shared-module/synthio/BlockBiquad.c index 3f9918467aa4..5a7194e42f9e 100644 --- a/shared-module/synthio/BlockBiquad.c +++ b/shared-module/synthio/BlockBiquad.c @@ -34,7 +34,7 @@ mp_obj_t common_hal_synthio_block_biquad_new(synthio_filter_mode mode, mp_obj_t synthio_block_biquad_t *self = mp_obj_malloc(synthio_block_biquad_t, &synthio_block_biquad_type_obj); self->mode = mode; synthio_block_assign_slot(f0, &self->f0, MP_QSTR_frequency); - synthio_block_assign_slot(Q, &self->Q, MP_QSTR_q_factor); + synthio_block_assign_slot(Q, &self->Q, MP_QSTR_Q); return MP_OBJ_FROM_PTR(self); } @@ -42,12 +42,12 @@ synthio_filter_mode common_hal_synthio_block_biquad_get_mode(synthio_block_biqua return self->mode; } -mp_obj_t common_hal_synthio_block_biquad_get_q_factor(synthio_block_biquad_t *self) { +mp_obj_t common_hal_synthio_block_biquad_get_Q(synthio_block_biquad_t *self) { return self->Q.obj; } -void common_hal_synthio_block_biquad_set_q_factor(synthio_block_biquad_t *self, mp_obj_t q_factor) { - synthio_block_assign_slot(q_factor, &self->Q, MP_QSTR_q_factor); +void common_hal_synthio_block_biquad_set_Q(synthio_block_biquad_t *self, mp_obj_t Q) { + synthio_block_assign_slot(Q, &self->Q, MP_QSTR_Q); } mp_obj_t common_hal_synthio_block_biquad_get_frequency(synthio_block_biquad_t *self) { diff --git a/tests/circuitpython/synthio_block_biquad.py b/tests/circuitpython/synthio_block_biquad.py index f7ec7c38d5c6..db7cddd987dc 100644 --- a/tests/circuitpython/synthio_block_biquad.py +++ b/tests/circuitpython/synthio_block_biquad.py @@ -10,7 +10,7 @@ def gen(synth): l = LFO(sweep, offset=1440, scale=2880, rate=.025, once=True) yield [l] - b = BlockBiquad(FilterMode.LOW_PASS, l) + b = BlockBiquad(FilterMode.LOW_PASS, l, Q=.5**.5) n = Note(100, filter=b, waveform=white_noise) synth.press(n) yield 20 From c377123d0b771a398f4966179b502e7c774fafb8 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 7 Nov 2024 14:14:13 -0600 Subject: [PATCH 208/252] BlockBiquad: Only recalculate when needed. --- shared-module/synthio/BlockBiquad.c | 17 +++++++++++++++++ shared-module/synthio/BlockBiquad.h | 1 + 2 files changed, 18 insertions(+) diff --git a/shared-module/synthio/BlockBiquad.c b/shared-module/synthio/BlockBiquad.c index 5a7194e42f9e..361a5a0ce011 100644 --- a/shared-module/synthio/BlockBiquad.c +++ b/shared-module/synthio/BlockBiquad.c @@ -62,12 +62,29 @@ static int32_t biquad_scale_arg_float(mp_float_t arg) { return (int32_t)MICROPY_FLOAT_C_FUN(round)(MICROPY_FLOAT_C_FUN(ldexp)(arg, BIQUAD_SHIFT)); } +static int float_equal_or_update( + mp_float_t *cached, + mp_float_t new) { + // uses memcmp to avoid error about equality float comparison + if (memcmp(cached, &new, sizeof(mp_float_t))) { + *cached = new; + return false; + } + return true; +} + void common_hal_synthio_block_biquad_tick(mp_obj_t self_in, biquad_filter_state *filter_state) { synthio_block_biquad_t *self = MP_OBJ_TO_PTR(self_in); mp_float_t W0 = synthio_block_slot_get(&self->f0) * synthio_global_W_scale; mp_float_t Q = synthio_block_slot_get(&self->Q); + // n.b., assumes that the `mode` field is read-only + // n.b., use of `&` is deliberate, avoids short-circuiting behavior + if (float_equal_or_update(&self->cached_W0, W0) & float_equal_or_update(&self->cached_Q, Q)) { + return; + } + sincos_result_t sc; fast_sincos(W0, &sc); diff --git a/shared-module/synthio/BlockBiquad.h b/shared-module/synthio/BlockBiquad.h index 1eea1a7b53ba..f94c158a6513 100644 --- a/shared-module/synthio/BlockBiquad.h +++ b/shared-module/synthio/BlockBiquad.h @@ -15,6 +15,7 @@ typedef struct synthio_block_biquad { mp_obj_base_t base; synthio_filter_mode mode; synthio_block_slot_t f0, Q; + mp_float_t cached_W0, cached_Q; } synthio_block_biquad_t; void common_hal_synthio_block_biquad_tick(mp_obj_t self_in, biquad_filter_state *filter_state); From c96d1428e1cef185675370d761ef6fccdb0edae8 Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Thu, 7 Nov 2024 19:06:25 -0600 Subject: [PATCH 209/252] Remove unnecessary `m_malloc_fail` and deinit from memory allocation routines. --- shared-module/audiofilters/Filter.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/shared-module/audiofilters/Filter.c b/shared-module/audiofilters/Filter.c index 82a9c9f81edd..ea0a2058f2e8 100644 --- a/shared-module/audiofilters/Filter.c +++ b/shared-module/audiofilters/Filter.c @@ -28,27 +28,15 @@ void common_hal_audiofilters_filter_construct(audiofilters_filter_obj_t *self, self->buffer_len = buffer_size; // in bytes self->buffer[0] = m_malloc(self->buffer_len); - if (self->buffer[0] == NULL) { - common_hal_audiofilters_filter_deinit(self); - m_malloc_fail(self->buffer_len); - } memset(self->buffer[0], 0, self->buffer_len); self->buffer[1] = m_malloc(self->buffer_len); - if (self->buffer[1] == NULL) { - common_hal_audiofilters_filter_deinit(self); - m_malloc_fail(self->buffer_len); - } memset(self->buffer[1], 0, self->buffer_len); self->last_buf_idx = 1; // Which buffer to use first, toggle between 0 and 1 // This buffer will be used to process samples through the biquad filter self->filter_buffer = m_malloc(SYNTHIO_MAX_DUR * sizeof(int32_t)); - if (self->filter_buffer == NULL) { - common_hal_audiofilters_filter_deinit(self); - m_malloc_fail(SYNTHIO_MAX_DUR * sizeof(int32_t)); - } memset(self->filter_buffer, 0, SYNTHIO_MAX_DUR * sizeof(int32_t)); // Initialize other values most effects will need. @@ -106,10 +94,6 @@ void reset_filter_states(audiofilters_filter_obj_t *self) { } self->filter_states = m_malloc(self->filter_states_len * sizeof(biquad_filter_state)); - if (self->filter_states == NULL) { - common_hal_audiofilters_filter_deinit(self); - m_malloc_fail(self->filter_states_len * sizeof(biquad_filter_state)); - } if (mp_obj_is_type(items, (const mp_obj_type_t *)&synthio_biquad_type_obj)) { synthio_biquad_filter_assign(&self->filter_states[0], items); From 6259419f8980a1253946f378c009c755b4173964 Mon Sep 17 00:00:00 2001 From: eightycc Date: Fri, 8 Nov 2024 07:08:10 -0800 Subject: [PATCH 210/252] Fix raspberrypi bootloop when using serial REPL by removing extra call to serial_early_init. --- ports/raspberrypi/supervisor/port.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index 13e5abb61216..b9697a0f83fd 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -326,8 +326,6 @@ safe_mode_t port_init(void) { // Reset everything into a known state before board_init. reset_port(); - serial_early_init(); - #ifdef CIRCUITPY_PSRAM_CHIP_SELECT setup_psram(); #endif From 9a204b2f50daf94f0ae67dad65e76cf90e2832ed Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Sun, 10 Nov 2024 16:13:40 +0100 Subject: [PATCH 211/252] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ --- locale/ID.po | 14 +++++++++++--- locale/cs.po | 11 +++++++++-- locale/de_DE.po | 11 +++++++++-- locale/el.po | 11 +++++++++-- locale/en_GB.po | 11 +++++++++-- locale/es.po | 11 +++++++++-- locale/fil.po | 11 +++++++++-- locale/fr.po | 11 +++++++++-- locale/hi.po | 11 +++++++++-- locale/it_IT.po | 11 +++++++++-- locale/ja.po | 11 +++++++++-- locale/ko.po | 11 +++++++++-- locale/nl.po | 11 +++++++++-- locale/pl.po | 11 +++++++++-- locale/pt_BR.po | 11 +++++++++-- locale/ru.po | 11 +++++++++-- locale/sv.po | 11 +++++++++-- locale/tr.po | 11 +++++++++-- locale/zh_Latn_pinyin.po | 11 +++++++++-- 19 files changed, 173 insertions(+), 39 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 973aa69ffb74..3fa09972192f 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -190,6 +190,10 @@ msgstr "" msgid "%q must be >= %d" msgstr "%q harus >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "" @@ -1282,6 +1286,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "" @@ -1991,7 +1996,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Panjang rgb_pins harus 6, 12, 18, 24, atau 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "Sampel punya %q yang tidak cocok" @@ -2293,7 +2299,8 @@ msgstr "PERINGATAN: Nama file kode anda mempunyai dua ekstensi\n" #: ports/nordic/common-hal/watchdog/WatchDogTimer.c msgid "WatchDogTimer cannot be deinitialized once mode is set to RESET" -msgstr "WatchDogTimer tidak dapat dideinisialisasi setelah mode diatur ke RESET" +msgstr "" +"WatchDogTimer tidak dapat dideinisialisasi setelah mode diatur ke RESET" #: py/builtinhelp.c #, c-format @@ -2537,7 +2544,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/cs.po b/locale/cs.po index 5957c68696cf..eaeca9dc132c 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -198,6 +198,10 @@ msgstr "%q musí být <= %u" msgid "%q must be >= %d" msgstr "%q musí být >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q musí být bytearray nebo pole typu 'H' nebo 'B'" @@ -1294,6 +1298,7 @@ msgid "Invalid socket for TLS" msgstr "Chybný soket pro TLS" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Chybný stav" @@ -1995,7 +2000,8 @@ msgstr "Výše uvedená výjimka byla přímá příčina následující výjimk msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Počet prvků rgb_pin musí být 6, 12, 18, 24, nebo 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2535,7 +2541,8 @@ msgstr "velikosti bitmapy musí odpovídat" msgid "bits must be 32 or less" msgstr "počet bitů nesmí přesáhnout 32" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index b6c187d18de9..8151d5b6dc93 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -200,6 +200,10 @@ msgstr "%q muss <= %u sein" msgid "%q must be >= %d" msgstr "%q muss >= %d sein" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q muss ein Bytearray oder ein Array vom Typ 'H' oder 'B' sein" @@ -1305,6 +1309,7 @@ msgid "Invalid socket for TLS" msgstr "Ungültiges Socket für TLS" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Ungültiger Zustand" @@ -2018,7 +2023,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Die Länge von rgb_pins muss 6, 12, 18, 24 oder 30 betragen" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2567,7 +2573,8 @@ msgstr "Bitmap-Größen müssen übereinstimmen" msgid "bits must be 32 or less" msgstr "bits müssen 32 oder kleiner sein" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "Es müssen 8 oder 16 bits_per_sample sein" diff --git a/locale/el.po b/locale/el.po index e9fdb50bbee7..f6ae72829c19 100644 --- a/locale/el.po +++ b/locale/el.po @@ -202,6 +202,10 @@ msgstr "%q πρέπει να είναι <= %u" msgid "%q must be >= %d" msgstr "%q πρέπει να είναι >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q πρέπει να είναι bytearray ή array τύπου 'H' ή 'B'" @@ -1300,6 +1304,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "" @@ -1998,7 +2003,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2532,7 +2538,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index e348de3da894..377e3145bdae 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -200,6 +200,10 @@ msgstr "%q must be <= %u" msgid "%q must be >= %d" msgstr "%q must be >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q must be a bytearray or array of type 'H' or 'B'" @@ -1293,6 +1297,7 @@ msgid "Invalid socket for TLS" msgstr "Invalid socket for TLS" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Invalid state" @@ -1996,7 +2001,8 @@ msgstr "The above exception was the direct cause of the following exception:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "The length of rgb_pins must be 6, 12, 18, 24, or 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "The sample's %q does not match" @@ -2539,7 +2545,8 @@ msgstr "bitmap sizes must match" msgid "bits must be 32 or less" msgstr "bits must be 32 or less" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample must be 8 or 16" diff --git a/locale/es.po b/locale/es.po index 02c5786788a2..48ae7c18a6bc 100644 --- a/locale/es.po +++ b/locale/es.po @@ -202,6 +202,10 @@ msgstr "%q debe ser <= %u" msgid "%q must be >= %d" msgstr "%q debe ser >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q debe ser un bytearray o array de tipo 'H' o 'B'" @@ -1313,6 +1317,7 @@ msgid "Invalid socket for TLS" msgstr "Socket invalido para TLS" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Estado invalido" @@ -2025,7 +2030,8 @@ msgstr "La excepción fue la causa directa de la excepción siguiente:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "La longitud de rgb_pins debe ser 6, 12, 18, 24, o 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2572,7 +2578,8 @@ msgstr "los tamaños de los bitmap deben coincidir" msgid "bits must be 32 or less" msgstr "los bits deben ser 32 o menos" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample debe ser 8 ó 16" diff --git a/locale/fil.po b/locale/fil.po index 93735ffea9f6..c51dff69371d 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -190,6 +190,10 @@ msgstr "" msgid "%q must be >= %d" msgstr "" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "" @@ -1286,6 +1290,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "" @@ -1987,7 +1992,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2523,7 +2529,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample ay dapat 8 o 16" diff --git a/locale/fr.po b/locale/fr.po index 0358ad0d6738..7691f499b04a 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -203,6 +203,10 @@ msgstr "%q doit être <=%u" msgid "%q must be >= %d" msgstr "%q doit être >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q doit être un bytearray ou un array de type 'H' ou 'B'" @@ -1322,6 +1326,7 @@ msgid "Invalid socket for TLS" msgstr "Socket non valide pour TLS" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "État invalide" @@ -2040,7 +2045,8 @@ msgstr "L'exception précédente est la cause directe de l'exception suivante:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "La taille de rgb_pins doit être 6, 12, 18, 24 ou 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2589,7 +2595,8 @@ msgstr "les tailles des images doivent correspondre" msgid "bits must be 32 or less" msgstr "les bits doivent être 32 ou moins" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "'bits_per_sample' doivent être 8 ou 16" diff --git a/locale/hi.po b/locale/hi.po index d57d4aea6859..936772024175 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -189,6 +189,10 @@ msgstr "" msgid "%q must be >= %d" msgstr "" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "" @@ -1276,6 +1280,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "" @@ -1972,7 +1977,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2506,7 +2512,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index c4f721660914..ab8248aa41fd 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -191,6 +191,10 @@ msgstr "" msgid "%q must be >= %d" msgstr "" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "" @@ -1284,6 +1288,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "" @@ -1985,7 +1990,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2521,7 +2527,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c #, fuzzy msgid "bits_per_sample must be 8 or 16" msgstr "i bit devono essere 7, 8 o 9" diff --git a/locale/ja.po b/locale/ja.po index 523eda2bb8ed..4fa58168d867 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -200,6 +200,10 @@ msgstr "%q は <= %u である必要があります" msgid "%q must be >= %d" msgstr "%q は >= %d である必要があります" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q は bytearray か、 'H' または 'B' 型の array である必要があります" @@ -1293,6 +1297,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "" @@ -1994,7 +1999,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2529,7 +2535,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sampleは8または16でなければなりません" diff --git a/locale/ko.po b/locale/ko.po index 1151b188bd2e..386b603ef4ff 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -204,6 +204,10 @@ msgstr "%q 는 <= %u 여야 합니다" msgid "%q must be >= %d" msgstr "%q 는 >= %d 여야 합니다" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q는 'H' 또는 'B' 타입의 바이트 배열 또는 배열이어야 합니다" @@ -1328,6 +1332,7 @@ msgid "Invalid socket for TLS" msgstr "TLS에 대한 잘못된 소켓" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "잘못된 상태" @@ -2049,7 +2054,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2584,7 +2590,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample은 8 또는 16이어야합니다." diff --git a/locale/nl.po b/locale/nl.po index d9e4dde06071..7661b154e777 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -187,6 +187,10 @@ msgstr "" msgid "%q must be >= %d" msgstr "" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "" @@ -1279,6 +1283,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "" @@ -1986,7 +1991,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "De lengte van rgb_pins moet 6, 12, 18, 24 of 30 zijn" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2524,7 +2530,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample moet 8 of 16 zijn" diff --git a/locale/pl.po b/locale/pl.po index aaac9890fcd2..e30f7dabc24f 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -195,6 +195,10 @@ msgstr "" msgid "%q must be >= %d" msgstr "" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "" @@ -1298,6 +1302,7 @@ msgid "Invalid socket for TLS" msgstr "" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Nieprawidłowy stan" @@ -2000,7 +2005,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2536,7 +2542,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample musi być 8 lub 16" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 1decf5e551b6..79a78c01784a 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -200,6 +200,10 @@ msgstr "%q deve ser <= %u" msgid "%q must be >= %d" msgstr "o %q deve ser >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q deve ser um bytearray ou uma matriz do tipo 'H' ou 'B'" @@ -1309,6 +1313,7 @@ msgid "Invalid socket for TLS" msgstr "Soquete inválido para o TLS" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Estado inválido" @@ -2024,7 +2029,8 @@ msgstr "A exceção acima foi a causa direta da seguinte exceção:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "O comprimento dos rgb_pins devem ser 6, 12, 18, 24, ou 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "Não há correspondência nas amostras %q" @@ -2575,7 +2581,8 @@ msgstr "os tamanhos do bitmap devem coincidir" msgid "bits must be 32 or less" msgstr "bits deve ser 32 ou menos" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample deve ser 8 ou 16" diff --git a/locale/ru.po b/locale/ru.po index f59a8ec6b51d..499e9a6acfe7 100644 --- a/locale/ru.po +++ b/locale/ru.po @@ -202,6 +202,10 @@ msgstr "%q должно быть <= %u" msgid "%q must be >= %d" msgstr "%q должно быть >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q должен быть массивом байтов или массивом типа «H» или «B»" @@ -1315,6 +1319,7 @@ msgid "Invalid socket for TLS" msgstr "Неверный сокет для TLS" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Неверное состояние" @@ -2028,7 +2033,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Длина rgb_pins должна быть 6, 12, 18, 24 или 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2578,7 +2584,8 @@ msgstr "Размеры растровых изображений должны с msgid "bits must be 32 or less" msgstr "биты должны быть 32 или менее" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample должно быть 8 или 16" diff --git a/locale/sv.po b/locale/sv.po index 3b16112fa4d1..f3607c744220 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -199,6 +199,10 @@ msgstr "%q måste vara <= %u" msgid "%q must be >= %d" msgstr "%q måste vara >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q måste vara en bytearray eller array av typen 'H' eller 'B'" @@ -1301,6 +1305,7 @@ msgid "Invalid socket for TLS" msgstr "Ogiltig socket för TLS" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Ogiltigt tillstånd" @@ -2007,7 +2012,8 @@ msgstr "Ovanstående undantag var den direkta orsaken till följande undantag:" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Längden på rgb_pins vara 6, 12, 18, 24 eller 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2550,7 +2556,8 @@ msgstr "bitmappsstorlekar måste matcha" msgid "bits must be 32 or less" msgstr "bits måste vara 32 eller färre" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "bits_per_sample måste vara 8 eller 16" diff --git a/locale/tr.po b/locale/tr.po index 35c45dac64e8..8690e202a0f7 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -200,6 +200,10 @@ msgstr "" msgid "%q must be >= %d" msgstr "%q >= %d olmalıdır" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q 'H' ya da 'B' tipi bir bytearray ya da array olmalıdır" @@ -1295,6 +1299,7 @@ msgid "Invalid socket for TLS" msgstr "TLS için geçersiz soket" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "Geçersiz durum" @@ -1994,7 +1999,8 @@ msgstr "" msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2528,7 +2534,8 @@ msgstr "" msgid "bits must be 32 or less" msgstr "" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index ad0928eb52e2..974bae0135c8 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -201,6 +201,10 @@ msgstr "%q bì xū <= %u" msgid "%q must be >= %d" msgstr "%q bìxū >= %d" +#: shared-module/audiofilters/Filter.c +msgid "%q must be a %q object, %q, or %q" +msgstr "" + #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" msgstr "%q bì xū shì zì jié shù zǔ huò lèi xíng wéi 'H' huò 'B' de shù zǔ" @@ -1307,6 +1311,7 @@ msgid "Invalid socket for TLS" msgstr "TLS de chā zuò wú xiào" #: ports/espressif/common-hal/espidf/__init__.c +#: ports/nordic/common-hal/_bleio/__init__.c msgid "Invalid state" msgstr "wú xiào zhuàng tài" @@ -2013,7 +2018,8 @@ msgstr "shàng shù yì cháng shì yǐ xià yì cháng de zhí jiē yuán yīn: msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" msgstr "Rgb_pins de chángdù bìxū wèi 6,12,18,24 huò 30" -#: shared-module/audiodelays/Echo.c shared-module/audiomixer/MixerVoice.c +#: shared-module/audiodelays/Echo.c shared-module/audiofilters/Filter.c +#: shared-module/audiomixer/MixerVoice.c msgid "The sample's %q does not match" msgstr "" @@ -2556,7 +2562,8 @@ msgstr "wèi tú dà xiǎo bì xū pǐ pèi" msgid "bits must be 32 or less" msgstr "wèi bì xū shì 32 huò gèng shǎo" -#: shared-bindings/audiodelays/Echo.c shared-bindings/audiomixer/Mixer.c +#: shared-bindings/audiodelays/Echo.c shared-bindings/audiofilters/Filter.c +#: shared-bindings/audiomixer/Mixer.c msgid "bits_per_sample must be 8 or 16" msgstr "měi jiàn yàngběn bìxū wèi 8 huò 16" From 2442d8c74f39c6815b7e247f97be19ba3a409663 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 10 Nov 2024 10:57:02 -0600 Subject: [PATCH 212/252] setting should not have been enabled --- ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk index 30eed9142c5d..43328dd47094 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico2/mpconfigboard.mk @@ -10,4 +10,3 @@ CHIP_FAMILY = rp2 EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" CIRCUITPY__EVE = 1 -CIRCUITPY_SSL = 1 From 411ba7af3d3f152062eda93335d535a479ff47d7 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 10 Nov 2024 14:36:07 -0600 Subject: [PATCH 213/252] add notch filter to docs --- shared-bindings/synthio/BlockBiquad.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared-bindings/synthio/BlockBiquad.c b/shared-bindings/synthio/BlockBiquad.c index dc67a4065c1f..055bd3bd2667 100644 --- a/shared-bindings/synthio/BlockBiquad.c +++ b/shared-bindings/synthio/BlockBiquad.c @@ -19,6 +19,8 @@ //| """A high-pass filter""" //| BAND_PASS: FilterMode //| """A band-pass filter""" +//| NOTCH: FilterMode +//| """A notch filter""" //| MAKE_ENUM_VALUE(synthio_filter_mode_type, mode, LOW_PASS, SYNTHIO_LOW_PASS); From eee92af5e9811c097b1016cd56e245a2570071d3 Mon Sep 17 00:00:00 2001 From: Iqbal Rifai Date: Mon, 11 Nov 2024 06:42:51 +0000 Subject: [PATCH 214/252] Translated using Weblate (Indonesian) Currently translated at 43.7% (437 of 998 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/id/ --- locale/ID.po | 135 +++++++++++++++++++++++++++------------------------ 1 file changed, 72 insertions(+), 63 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 3fa09972192f..f2a3150c414e 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -6,8 +6,8 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-11-06 14:00+0000\n" -"Last-Translator: Iqbal Rifai \n" +"PO-Revision-Date: 2024-11-11 07:05+0000\n" +"Last-Translator: Iqbal Rifai \n" "Language-Team: LANGUAGE \n" "Language: ID\n" "MIME-Version: 1.0\n" @@ -29,6 +29,8 @@ msgid "" "\n" "Code stopped by auto-reload. Reloading soon.\n" msgstr "" +"\n" +"Kode dihentikan karena pemuatan ulang otomatis. Akan segera dimuat ulang.\n" #: supervisor/shared/safe_mode.c msgid "" @@ -36,18 +38,25 @@ msgid "" "Please file an issue with your program at github.com/adafruit/circuitpython/" "issues." msgstr "" +"\n" +"Silakan laporkan masalah dengan program Anda di github.com/adafruit/" +"sirkuitpython/issues." #: supervisor/shared/safe_mode.c msgid "" "\n" "Press reset to exit safe mode.\n" msgstr "" +"\n" +"Tekan reset untuk keluar dari mode aman.\n" #: supervisor/shared/safe_mode.c msgid "" "\n" "You are in safe mode because:\n" msgstr "" +"\n" +"Anda berada dalam mode aman karena:\n" #: py/obj.c msgid " File \"%q\"" @@ -87,15 +96,15 @@ msgstr "%q dan %q berisi pin duplikat" #: ports/atmel-samd/common-hal/audioio/AudioOut.c msgid "%q and %q must be different" -msgstr "" +msgstr "%q dan %q harus berbeda" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c msgid "%q and %q must share a clock unit" -msgstr "" +msgstr "%q dan %q harus berbagi unit jam" #: ports/nordic/common-hal/watchdog/WatchDogTimer.c msgid "%q cannot be changed once mode is set to %q" -msgstr "" +msgstr "%q tidak dapat diubah setelah mode diatur ke %q" #: shared-bindings/microcontroller/Pin.c msgid "%q contains duplicate pins" @@ -107,7 +116,7 @@ msgstr "%q gagal: %d" #: py/argcheck.c msgid "%q in %q must be of type %q, not %q" -msgstr "" +msgstr "%q dalam %q harus bertipe %q, bukan %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c @@ -131,19 +140,19 @@ msgstr "indeks %q harus bilangan bulat, bukan %s" #: shared-module/bitbangio/SPI.c msgid "%q init failed" -msgstr "" +msgstr "%q inisiasi gagal" #: ports/espressif/bindings/espnow/Peer.c shared-bindings/dualbank/__init__.c msgid "%q is %q" -msgstr "" +msgstr "%q adalah %q" #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "%q is read-only for this board" -msgstr "" +msgstr "%q hanya dapat dibaca untuk papan ini" #: py/argcheck.c shared-bindings/usb_hid/Device.c msgid "%q length must be %d" -msgstr "" +msgstr "%q panjangnya harus %d" #: py/argcheck.c msgid "%q length must be %d-%d" @@ -151,19 +160,19 @@ msgstr "%q panjang harus %d-%d" #: py/argcheck.c msgid "%q length must be <= %d" -msgstr "" +msgstr "%q panjangnya harus <= %d" #: py/argcheck.c msgid "%q length must be >= %d" -msgstr "" +msgstr "%q panjangnya harus >= %d" #: py/modsys.c py/objmodule.c py/runtime.c msgid "%q moved from %q to %q" -msgstr "" +msgstr "%q dipindahkan dari %q ke %q" #: py/argcheck.c msgid "%q must be %d" -msgstr "" +msgstr "%q harusnya %d" #: py/argcheck.c shared-bindings/busdisplay/BusDisplay.c #: shared-bindings/displayio/Bitmap.c @@ -175,7 +184,7 @@ msgstr "%q harus %d-%d" #: shared-bindings/busdisplay/BusDisplay.c msgid "%q must be 1 when %q is True" -msgstr "" +msgstr "%q harus 1 ketika %q bernilai Benar" #: py/argcheck.c shared-bindings/gifio/GifWriter.c #: shared-module/gifio/OnDiskGif.c @@ -184,7 +193,7 @@ msgstr "%q harus <= %d" #: ports/espressif/common-hal/watchdog/WatchDogTimer.c msgid "%q must be <= %u" -msgstr "" +msgstr "%q harus <= %u" #: py/argcheck.c msgid "%q must be >= %d" @@ -192,47 +201,47 @@ msgstr "%q harus >= %d" #: shared-module/audiofilters/Filter.c msgid "%q must be a %q object, %q, or %q" -msgstr "" +msgstr "%q harus berupa objek %q, %q, atau %q" #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" -msgstr "" +msgstr "%q harus berupa bytearray atau array bertipe 'H' atau 'B'" #: shared-bindings/audiocore/RawSample.c msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'" -msgstr "" +msgstr "%q harus berupa bytearray atau array bertipe 'h', 'H', 'b', atau 'B'" #: shared-bindings/warnings/__init__.c msgid "%q must be a subclass of %q" -msgstr "" +msgstr "%q harus menjadi subkelas dari %q" #: ports/espressif/common-hal/analogbufio/BufferedIn.c msgid "%q must be array of type 'H'" -msgstr "" +msgstr "%q harus berupa array bertipe 'H'" #: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" -msgstr "" +msgstr "%q harus berupa array bertipe 'h'" #: shared-bindings/audiobusio/PDMIn.c msgid "%q must be multiple of 8." -msgstr "" +msgstr "%q harus kelipatan 8." #: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c #: shared-bindings/bitmapfilter/__init__.c shared-bindings/canio/CAN.c #: shared-bindings/digitalio/Pull.c shared-bindings/supervisor/__init__.c #: shared-module/synthio/Synthesizer.c msgid "%q must be of type %q or %q, not %q" -msgstr "" +msgstr "%q harus bertipe %q atau %q, bukan %q" #: shared-bindings/jpegio/JpegDecoder.c msgid "%q must be of type %q, %q, or %q, not %q" -msgstr "" +msgstr "%q harus bertipe %q, %q, atau %q, bukan %q" #: py/argcheck.c py/runtime.c shared-bindings/bitmapfilter/__init__.c #: shared-module/synthio/__init__.c msgid "%q must be of type %q, not %q" -msgstr "" +msgstr "%q harus bertipe %q, %q, atau %q, bukan %q" #: ports/atmel-samd/common-hal/busio/UART.c msgid "%q must be power of 2" @@ -240,7 +249,7 @@ msgstr "%q harus pangkat 2" #: shared-bindings/wifi/Monitor.c msgid "%q out of bounds" -msgstr "" +msgstr "%q di luar batas" #: ports/atmel-samd/common-hal/pulseio/PulseIn.c #: ports/cxd56/common-hal/pulseio/PulseIn.c @@ -253,15 +262,15 @@ msgstr "%q di luar jangkauan" #: py/objmodule.c py/runtime.c msgid "%q renamed %q" -msgstr "" +msgstr "%q berganti nama menjadi %q" #: py/objrange.c py/objslice.c shared-bindings/random/__init__.c msgid "%q step cannot be zero" -msgstr "" +msgstr "%q step tidak boleh nol" #: shared-module/bitbangio/I2C.c msgid "%q too long" -msgstr "" +msgstr "%q terlalu panjang" #: py/bc.c py/objnamedtuple.c msgid "%q() takes %d positional arguments but %d were given" @@ -269,7 +278,7 @@ msgstr "%q() mengambil posisi argumen %d tapi %d yang diberikan" #: shared-module/jpegio/JpegDecoder.c msgid "%q() without %q()" -msgstr "" +msgstr "%q() tanpa %q()" #: shared-bindings/usb_hid/Device.c msgid "%q, %q, and %q must all be the same length" @@ -282,19 +291,19 @@ msgstr "" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "%q[%u] shifts in more bits than pin count" -msgstr "" +msgstr "%q[%u] berpindah lebih banyak bit daripada jumlah pin" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "%q[%u] shifts out more bits than pin count" -msgstr "" +msgstr "%q[%u] menggeser lebih banyak bit daripada jumlah pin" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "%q[%u] uses extra pin" -msgstr "" +msgstr "%q[%u] menggunakan pin tambahan" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "%q[%u] waits on input outside of count" -msgstr "" +msgstr "%q[%u] menunggu input di luar hitungan" #: ports/espressif/common-hal/espidf/__init__.c #, c-format @@ -369,17 +378,17 @@ msgstr "'%s' integer %d tidak berada dalam jangkauan %d..%d" #: py/emitinlinethumb.c #, c-format msgid "'%s' integer 0x%x doesn't fit in mask 0x%x" -msgstr "" +msgstr "'%s' Integer 0x%x tidak cocok dengan mask 0x%x" #: py/obj.c #, c-format msgid "'%s' object doesn't support item assignment" -msgstr "" +msgstr "Objek '%s' tidak mendukung penetapan item" #: py/obj.c #, c-format msgid "'%s' object doesn't support item deletion" -msgstr "" +msgstr "Objek '%s' tidak mendukung penghapusan item" #: py/runtime.c msgid "'%s' object has no attribute '%q'" @@ -388,7 +397,7 @@ msgstr "Objek '%s' tidak memiliki atribut '%q'" #: py/obj.c #, c-format msgid "'%s' object isn't subscriptable" -msgstr "" +msgstr "Objek '%s' tidak dapat dijadikan subskrip" #: py/objstr.c msgid "'=' alignment not allowed in string format specifier" @@ -408,7 +417,7 @@ msgstr "'await' diluar fungsi" #: py/compile.c msgid "'break'/'continue' outside loop" -msgstr "" +msgstr "'break'/'continue' di luar loop" #: py/compile.c msgid "'data' requires at least 2 arguments" @@ -424,7 +433,7 @@ msgstr "'label' membutuhkan 1 argumen" #: py/emitnative.c msgid "'not' not implemented" -msgstr "" +msgstr "'not' tidak diimplementasikan" #: py/compile.c msgid "'return' outside function" @@ -440,7 +449,7 @@ msgstr "'yield' diluar fungsi" #: py/compile.c msgid "* arg after **" -msgstr "" +msgstr "* arg setelah **" #: py/compile.c msgid "*x must be assignment target" @@ -454,7 +463,7 @@ msgstr ", dalam %q\n" #: shared-bindings/epaperdisplay/EPaperDisplay.c #: shared-bindings/framebufferio/FramebufferDisplay.c msgid ".show(x) removed. Use .root_group = x" -msgstr "" +msgstr ".show(x) dihapus. Gunakan .root_group = x" #: py/objcomplex.c msgid "0.0 to a complex power" @@ -466,7 +475,7 @@ msgstr "pow() 3-arg tidak didukung" #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "AP could not be started" -msgstr "" +msgstr "AP tidak dapat dimulai" #: shared-bindings/_bleio/Address.c shared-bindings/ipaddress/IPv4Address.c #, c-format @@ -477,15 +486,15 @@ msgstr "Alamat harus sepanjang %d byte" #: ports/nordic/common-hal/memorymap/AddressRange.c #: ports/raspberrypi/common-hal/memorymap/AddressRange.c msgid "Address range not allowed" -msgstr "" +msgstr "Rentang alamat tidak diizinkan" #: shared-bindings/memorymap/AddressRange.c msgid "Address range wraps around" -msgstr "" +msgstr "Rentang alamat melingkar" #: ports/espressif/common-hal/canio/CAN.c msgid "All CAN peripherals are in use" -msgstr "" +msgstr "Semua peripheral CAN sedang digunakan" #: ports/espressif/common-hal/busio/I2C.c #: ports/espressif/common-hal/i2ctarget/I2CTarget.c @@ -511,11 +520,11 @@ msgstr "Semua perangkat UART sedang digunakan" #: ports/nordic/common-hal/pulseio/PulseIn.c #: ports/nordic/common-hal/rotaryio/IncrementalEncoder.c msgid "All channels in use" -msgstr "" +msgstr "Semua saluran sedang digunakan" #: ports/raspberrypi/common-hal/usb_host/Port.c msgid "All dma channels in use" -msgstr "" +msgstr "Semua saluran dma sedang digunakan" #: ports/atmel-samd/common-hal/audioio/AudioOut.c msgid "All event channels in use" @@ -526,7 +535,7 @@ msgstr "Semua channel event sedang digunakan" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: ports/raspberrypi/common-hal/usb_host/Port.c msgid "All state machines in use" -msgstr "" +msgstr "Semua mesin status yang digunakan" #: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" @@ -560,28 +569,28 @@ msgstr "" #: ports/espressif/common-hal/_bleio/__init__.c msgid "Already in progress" -msgstr "" +msgstr "Sudah dalam proses" #: ports/espressif/bindings/espnow/ESPNow.c #: ports/espressif/common-hal/espulp/ULP.c #: shared-module/memorymonitor/AllocationAlarm.c #: shared-module/memorymonitor/AllocationSize.c msgid "Already running" -msgstr "" +msgstr "Sudah berjalan" #: ports/espressif/common-hal/wifi/Radio.c #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "Already scanning for wifi networks" -msgstr "" +msgstr "Sudah memindai jaringan wifi" #: shared-module/os/getenv.c #, c-format msgid "An error occurred while retrieving '%s':\n" -msgstr "" +msgstr "Terjadi kesalahan saat mengambil '%s':\n" #: ports/stm/common-hal/audiopwmio/PWMAudioOut.c msgid "Another PWMAudioOut is already active" -msgstr "" +msgstr "PWMAudioOut lainnya sudah aktif" #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/cxd56/common-hal/pulseio/PulseOut.c @@ -600,19 +609,19 @@ msgstr "Nilai array harus berupa byte tunggal." #: shared-module/memorymonitor/AllocationAlarm.c #, c-format msgid "Attempt to allocate %d blocks" -msgstr "" +msgstr "Mencoba mengalokasikan %d blok" #: ports/raspberrypi/audio_dma.c msgid "Audio conversion not implemented" -msgstr "" +msgstr "Konversi audio belum diimplementasikan" #: shared-bindings/wifi/Radio.c msgid "AuthMode.OPEN is not used with password" -msgstr "" +msgstr "AuthMode.OPEN tidak digunakan dengan kata sandi" #: shared-bindings/wifi/Radio.c supervisor/shared/web_workflow/web_workflow.c msgid "Authentication failure" -msgstr "" +msgstr "Kegagalan otentikasi" #: main.c msgid "Auto-reload is off.\n" @@ -628,7 +637,7 @@ msgstr "" #: ports/espressif/common-hal/canio/CAN.c msgid "Baudrate not supported by peripheral" -msgstr "" +msgstr "Baudrate tidak didukung oleh periferal" #: shared-module/busdisplay/BusDisplay.c #: shared-module/framebufferio/FramebufferDisplay.c @@ -637,15 +646,15 @@ msgstr "Di bawah frame rate minimum" #: ports/raspberrypi/common-hal/audiobusio/I2SOut.c msgid "Bit clock and word select must be sequential GPIO pins" -msgstr "" +msgstr "Jam bit dan pemilihan kata harus berupa pin GPIO berurutan" #: shared-bindings/bitmaptools/__init__.c msgid "Bitmap size and bits per value must match" -msgstr "" +msgstr "Ukuran bitmap dan bit per nilai harus cocok" #: supervisor/shared/safe_mode.c msgid "Boot device must be first (interface #0)." -msgstr "" +msgstr "Perangkat boot harus menjadi yang pertama (interface #0)." #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" From d39e9edd501f729a674beff919d466212e018bca Mon Sep 17 00:00:00 2001 From: Wellington Terumi Uemura Date: Sun, 10 Nov 2024 20:13:31 +0000 Subject: [PATCH 215/252] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (998 of 998 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/pt_BR/ --- locale/pt_BR.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 79a78c01784a..58269ff86d65 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2024-10-23 01:15+0000\n" +"PO-Revision-Date: 2024-11-11 07:05+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -14,7 +14,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 5.8.2-dev\n" +"X-Generator: Weblate 5.8.2\n" #: main.c msgid "" @@ -202,7 +202,7 @@ msgstr "o %q deve ser >= %d" #: shared-module/audiofilters/Filter.c msgid "%q must be a %q object, %q, or %q" -msgstr "" +msgstr "%q deve ser um objeto %q, %q ou %q" #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" From f10ef530c6b74d8cb197cb2ea3ca8f80b82c16e9 Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Wed, 14 Aug 2024 14:29:27 -0700 Subject: [PATCH 216/252] Initial commit for ADI MAX32690 support. Still many modules to implement/unstub, but builds clean. --- .gitmodules | 3 + ports/analog/Makefile | 261 +++++++++++ ports/analog/README.md | 52 +++ ports/analog/background.c | 28 ++ ports/analog/background.h | 10 + ports/analog/boards/APARD/README.md | 14 + ports/analog/boards/APARD/board.c | 9 + ports/analog/boards/APARD/mpconfigboard.h | 31 ++ ports/analog/boards/APARD/mpconfigboard.mk | 18 + ports/analog/boards/APARD/pins.c | 125 ++++++ ports/analog/common-hal/board/__init__.c | 5 + ports/analog/common-hal/microcontroller/Pin.c | 34 ++ ports/analog/common-hal/microcontroller/Pin.h | 14 + .../common-hal/microcontroller/Processor.c | 36 ++ .../common-hal/microcontroller/Processor.h | 16 + .../common-hal/microcontroller/__init__.c | 410 ++++++++++++++++++ ports/analog/common-hal/os/__init__.c | 50 +++ ports/analog/linking/max32690_cktpy.ld | 160 +++++++ ports/analog/mpconfigport.h | 36 ++ ports/analog/mpconfigport.mk | 85 ++++ ports/analog/mphalport.c | 15 + ports/analog/mphalport.h | 22 + ports/analog/msdk | 1 + ports/analog/peripherals/max32690/pins.c | 119 +++++ ports/analog/peripherals/max32690/pins.h | 114 +++++ ports/analog/peripherals/pins.h | 34 ++ ports/analog/qstrdefsport.h | 10 + ports/analog/supervisor/cpu.s | 27 ++ ports/analog/supervisor/internal_flash.c | 289 ++++++++++++ ports/analog/supervisor/internal_flash.h | 16 + ports/analog/supervisor/port.c | 167 +++++++ ports/analog/supervisor/serial.c | 61 +++ tools/ci_fetch_deps.py | 6 + 33 files changed, 2278 insertions(+) create mode 100644 ports/analog/Makefile create mode 100644 ports/analog/README.md create mode 100644 ports/analog/background.c create mode 100644 ports/analog/background.h create mode 100644 ports/analog/boards/APARD/README.md create mode 100644 ports/analog/boards/APARD/board.c create mode 100644 ports/analog/boards/APARD/mpconfigboard.h create mode 100644 ports/analog/boards/APARD/mpconfigboard.mk create mode 100644 ports/analog/boards/APARD/pins.c create mode 100644 ports/analog/common-hal/board/__init__.c create mode 100644 ports/analog/common-hal/microcontroller/Pin.c create mode 100644 ports/analog/common-hal/microcontroller/Pin.h create mode 100644 ports/analog/common-hal/microcontroller/Processor.c create mode 100644 ports/analog/common-hal/microcontroller/Processor.h create mode 100644 ports/analog/common-hal/microcontroller/__init__.c create mode 100644 ports/analog/common-hal/os/__init__.c create mode 100644 ports/analog/linking/max32690_cktpy.ld create mode 100644 ports/analog/mpconfigport.h create mode 100644 ports/analog/mpconfigport.mk create mode 100644 ports/analog/mphalport.c create mode 100644 ports/analog/mphalport.h create mode 160000 ports/analog/msdk create mode 100644 ports/analog/peripherals/max32690/pins.c create mode 100644 ports/analog/peripherals/max32690/pins.h create mode 100644 ports/analog/peripherals/pins.h create mode 100644 ports/analog/qstrdefsport.h create mode 100644 ports/analog/supervisor/cpu.s create mode 100644 ports/analog/supervisor/internal_flash.c create mode 100644 ports/analog/supervisor/internal_flash.h create mode 100644 ports/analog/supervisor/port.c create mode 100644 ports/analog/supervisor/serial.c diff --git a/.gitmodules b/.gitmodules index c01f23dbe6e1..2185e9207941 100644 --- a/.gitmodules +++ b/.gitmodules @@ -407,3 +407,6 @@ [submodule "frozen/Adafruit_CircuitPython_Wiznet5k"] path = frozen/Adafruit_CircuitPython_Wiznet5k url = https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k +[submodule "ports/analog/msdk"] + path = ports/analog/msdk + url = https://github.com/analogdevicesinc/msdk.git diff --git a/ports/analog/Makefile b/ports/analog/Makefile new file mode 100644 index 000000000000..b348a57d237f --- /dev/null +++ b/ports/analog/Makefile @@ -0,0 +1,261 @@ +# This file is part of the CircuitPython project: https://circuitpython.org +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# Includes mpconfigboard.mk & mpconfigport.mk, +# along with numerous other shared environment makefiles. +include ../../py/circuitpy_mkenv.mk + +CROSS_COMPILE = arm-none-eabi- + +# MCU_SERIES e.g. "max32" +# MCU_VARIANT e.g. "max32690" +# defined in mpconfigboard.mk +MCU_SERIES_LOWER := $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]') +MCU_SERIES_UPPER := $(shell echo $(MCU_SERIES) | tr '[:lower:]' '[:upper:]') +MCU_VARIANT_LOWER := $(shell echo $(MCU_VARIANT) | tr '[:upper:]' '[:lower:]') +MCU_VARIANT_UPPER := $(shell echo $(MCU_VARIANT) | tr '[:lower:]' '[:upper:]') + +# ******************************************************************************* +#### MSDK INCLUDES #### +# Necessary for msdk makefiles +TARGET := $(MCU_VARIANT_UPPER) +TARGET_UC := $(MCU_VARIANT_UPPER) +TARGET_LC := $(MCU_VARIANT_LOWER) + +MSDK_ROOT = ./msdk +MSDK_LIBS = $(MSDK_ROOT)/Libraries +CMSIS_ROOT = $(MSDK_LIBS)/CMSIS +ADI_PERIPH = $(MSDK_ROOT)/Libraries/PeriphDrivers +ADI_MISC_DRIVERS_DIR ?= $(MSDK_LIBS)/MiscDrivers +ADI_BOARD_DIR = $(MSDK_LIBS)/Boards/$(MCU_VARIANT_UPPER)/$(BOARD) + +# For debugging the build +ifneq ($(BUILD_VERBOSE),"") +$(info MSDK_ROOT is $(MSDK_ROOT)) +$(info MSDK_LIBS is $(MSDK_LIBS)) +$(info CMSIS_ROOT is $(CMSIS_ROOT)) +$(info ADI_PERIPH is $(ADI_PERIPH)) +$(info ADI_MISC_DRIVERS_DIR is $(ADI_MISC_DRIVERS_DIR)) +$(info ADI_BOARD_DIR is $(ADI_BOARD_DIR)) +$(info MAXIM_PATH is $(MAXIM_PATH)) +endif + +# ----------------- +# Sources & Include +# ----------------- +# Define max32 die type for PeriphDriver Includes +# default to me18 for max32690 +# more info: +# https://analogdevicesinc.github.io/msdk//USERGUIDE/#die-types-to-part-numbers +ifeq ($(MCU_VARIANT_LOWER), "max32690") +DIE_TYPE=me18 +else +DIE_TYPE=me18 +endif + +PERIPH_SRC = $(ADI_PERIPH)/Source + +INC += -I. +INC += -I../.. +INC += -I$(BUILD) +INC += -I$(BUILD)/genhdr +INC += -I./../../lib/cmsis/inc +INC += -I./boards/ +INC += -I./boards/$(BOARD) +INC += -I./peripherals/ +INC += -I../../lib/mp-readline + +INC += \ + -I$(TOP)/$(BOARD_PATH) \ + -I$(TOP)/lib/cmsis/inc \ + -I$(CMSIS_ROOT)/Include \ + -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Include \ + -I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \ + -I$(PERIPH_SRC)/SYS \ + -I$(PERIPH_SRC)/GPIO \ + -I$(PERIPH_SRC)/CTB \ + -I$(PERIPH_SRC)/ICC \ + -I$(PERIPH_SRC)/FLC \ + -I$(PERIPH_SRC)/UART \ + +INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC + +SRC_MAX32 += \ + $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/heap.c \ + $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/system_$(MCU_VARIANT_LOWER).c \ + $(PERIPH_SRC)/SYS/mxc_assert.c \ + $(PERIPH_SRC)/SYS/mxc_delay.c \ + $(PERIPH_SRC)/SYS/mxc_lock.c \ + $(PERIPH_SRC)/SYS/nvic_table.c \ + $(PERIPH_SRC)/SYS/pins_$(DIE_TYPE).c \ + $(PERIPH_SRC)/SYS/sys_$(DIE_TYPE).c \ + $(PERIPH_SRC)/CTB/ctb_$(DIE_TYPE).c \ + $(PERIPH_SRC)/CTB/ctb_reva.c \ + $(PERIPH_SRC)/CTB/ctb_common.c \ + $(PERIPH_SRC)/FLC/flc_common.c \ + $(PERIPH_SRC)/FLC/flc_$(DIE_TYPE).c \ + $(PERIPH_SRC)/FLC/flc_reva.c \ + $(PERIPH_SRC)/GPIO/gpio_common.c \ + $(PERIPH_SRC)/GPIO/gpio_$(DIE_TYPE).c \ + $(PERIPH_SRC)/GPIO/gpio_reva.c \ + $(PERIPH_SRC)/ICC/icc_$(DIE_TYPE).c \ + $(PERIPH_SRC)/ICC/icc_reva.c \ + $(PERIPH_SRC)/UART/uart_common.c \ + $(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \ + $(PERIPH_SRC)/UART/uart_revb.c \ + +SRC_C += $(SRC_MAX32) \ + boards/$(BOARD)/board.c \ + boards/$(BOARD)/pins.c \ + peripherals/$(MCU_VARIANT_LOWER)/pins.c \ + +# ******************************************************************************* +### Compiler & Linker Flags ### +COMPILER ?= GCC + +ifeq ($(COMPILER), GCC) + +STARTUPFILE = $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC/startup_$(MCU_VARIANT_LOWER).s +# STARTUPFILE = $(ADI_BOARD_DIR)/Source/startup_$(MCU_VARIANT_LOWER).s + +# CircuitPython custom linkerfile (necessary for build steps & filesystems) +LINKERFILE = linking/$(MCU_VARIANT_LOWER)_cktpy.ld +LDFLAGS += -nostartfiles -specs=nosys.specs -specs=nano.specs +endif + +SRC_S += supervisor/cpu.s \ + $(STARTUPFILE) + +# Needed to compile some MAX32 headers +CFLAGS += -D$(MCU_VARIANT_UPPER) \ + -DTARGET_REV=0x4131 \ + -DTARGET=$(MCU_VARIANT_UPPER) \ + -DIAR_PRAGMAS=0 \ + # -DFLASH_ORIGIN=0x10000000 \ + # -DFLASH_SIZE=0x340000 \ + # -DSRAM_ORIGIN=0x20000000 \ + # -DSRAM_SIZE=0x100000 \ + +CPU_CORE=cortex-m4 +CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=hard -mfpu=fpv4-sp-d16 + +# NOTE: Start with DEBUG ONLY settings for now +ifeq ($(DEBUG),) +DEBUG ?= 1 +endif + +ifeq ($(DEBUG),1) +CFLAGS += -ggdb3 +COPT = -Og +else +COPT += -O2 +endif + + +# TinyUSB CFLAGS +CFLAGS += \ + -DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \ + -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \ + +# TODO: Add for TinyUSB once our PR goes through for MAX32 devices +# Add TinyUSB +# INC += -I../../lib/tinyusb/src +# INC += -I../../supervisor/shared/usb +# SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c + +SRC_C += \ + boards/$(BOARD)/board.c \ + background.c \ + mphalport.c \ + +CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostartfiles $(BASE_CFLAGS) $(COPT) + +# Suppress some warnings for MSDK +CFLAGS += -Wno-error=unused-parameter \ + -Wno-error=old-style-declaration \ + -Wno-error=sign-compare \ + -Wno-error=strict-prototypes \ + -Wno-error=cast-qual \ + -Wno-unused-variable \ + -Wno-lto-type-mismatch \ + -Wno-cast-align \ + -Wno-nested-externs \ + -Wno-sign-compare + +LDFLAGS += $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections +LIBS := -lgcc -lc + +# If not using CKTPY mathlib, use toolchain mathlib +ifndef INTERNAL_LIBM +LIBS += -lm +endif + +# ******************************************************************************* +### PORT-DEFINED BUILD RULES ### +# This section attempts to build the Python core, the supervisor, and any +# port-provided source code. +# +# QSTR sources are provided for the initial build step, which generates +# Python constants to represent C data which gets passed into the GC. + +SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ + $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ + $(addprefix common-hal/, $(SRC_COMMON_HAL)) + +SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) + +# There are duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED, +# because a few modules have files both in common-hal/ and shared-module/. +# Doing a $(sort ...) removes duplicates as part of sorting. +SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)) + +# OBJ includes +OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o)) +ifeq ($(INTERNAL_LIBM),1) +OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o)) +endif +OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) + +# List of sources for qstr extraction +SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_CIRCUITPY_COMMON) \ + $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED) $(SRC_MOD) +# Sources that only hold QSTRs after pre-processing. +SRC_QSTR_PREPROCESSOR += + +# Default build target +all: $(BUILD)/firmware.elf + +clean-max32: + rm -rf build-* + +# Optional flash option when running within an installed MSDK to use OpenOCD +# Mainline OpenOCD does not yet have the MAX32's flash algorithm integrated. +# If the MSDK is installed, flash-msdk can be run to utilize the the modified +# openocd with the algorithms +MAXIM_PATH := $(subst \,/,$(MAXIM_PATH)) +flash-msdk: + $(MAXIM_PATH)/Tools/OpenOCD/openocd -s $(MAXIM_PATH)/Tools/OpenOCD/scripts \ + -f interface/cmsis-dap.cfg -f target/$(MCU_VARIANT_LOWER).cfg \ + -c "program $(BUILD)/$(PROJECT).elf verify; init; reset; exit" + +# flash target using JLink +JLINK_DEVICE = $(MCU_VARIANT_LOWER) +flash: flash-jlink + +$(BUILD)/firmware.elf: $(OBJ) $(LINKERFILE) + $(STEPECHO) "LINK $@" + $(Q)echo $(OBJ) > $(BUILD)/firmware.objs + $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--print-memory-usage -Wl,--start-group $(LIBS) -Wl,--end-group + $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINKERFILE) $(BUILD) + +# ******************************************************************************* +### CKTPY BUILD RULES ### +include $(TOP)/py/mkrules.mk diff --git a/ports/analog/README.md b/ports/analog/README.md new file mode 100644 index 000000000000..0e5d3f7d2951 --- /dev/null +++ b/ports/analog/README.md @@ -0,0 +1,52 @@ +# Analog Devices "MAX32" MCUs + +This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. These devices are mostly ARM Cortex-M4-based and focus on delivering performance at low-power levels. Currently this port only supports MAX32690. + +### Structure of this port + +- **`boards/:`** Board-specific definitions including pins, board initialization, etc. +- **`common-hal/:`** Port-specific implementations of CircuitPython common-hal APIs. When a new module is enabled, this is often where the implementation is found. Expected functions for modules in `common-hal` are usually found in `shared-bindings/` or `shared-module/` in the CircuitPy root directory. +- **`linking/:`** Linkerfiles customized for CircuitPython. These are distinct from the linkerfiles used in MSDK as they adopt the structure required by CircuitPython. They may also omit unused features and memory sections, e.g. Mailboxes, RISC-V Flash, & Hyperbus RAM for MAX32690. +- **`msdk:/`** SDK for MAX32 devices. More info on our GitHub: [Analog Devices MSDK GitHub](https://github.com/analogdevicesinc/msdk) +- **`peripherals:/`** Helper files for peripherals such as clocks, gpio, etc. These files tend to be specific to vendor SDKs and provide some useful functions for the common-hal interfaces. +- **`supervisor/:`** Implementation files for the CircuitPython supervisor. This includes port setup, usb, and a filesystem on a storage medium such as SD Card/eMMC, QSPI Flash, or internal flash memory. Currently the internal flash is used. + +- `. :` Build system and high-level interface to the CircuitPython core for the ADI port. + +### Building for MAX32 devices + +Ensure CircuitPython dependencies are up-to-date by following the CircuitPython introduction on Adafruit's Website: [Building CircuitPython - Introduction](https://learn.adafruit.com/building-circuitpython/introduction). In particular, it is necessary to fetch all submodules (including the ARM Toolchain inside MSDK) and build the `mpy-cross` compiler. + +Ensure the MSDK's ARM toolchain is contained on your PATH. This can be done in MinGW or WSL by exporting a prefix to the PATH variable: + + $ export MSDK_GNU_PATH=/ports/analog/msdk/Tools/GNUTools/10.3/bin + $ export PATH=$MSDK_GNU_PATH:$PATH + +This needs to be done each time you open a command environment to build CircuitPython. + +Once you have built `mpy-cross` and set up your build system for CircuitPython, you can build for MAX32 devices using the following commands: + + $ cd ports/analog + $ make BOARD= + +Be aware the build may take a long time without parallelizing via the `-jN` flag, where N is the # of cores on your machine. + +### Flashing the board + +Universal instructions on flashing MAX32 devices this project can be found in the **[MSDK User Guide](https://analogdevicesinc.github.io/msdk/USERGUIDE/)**. + +In addition, a user may flash the device by calling `make` with the `flash-msdk` target from within the `ports/analog` directory, as below: + + $ make BOARD= flash-msdk + +This requires the following: +- A MAX32625PICO is connected to the PC via USB +- The PICO board shows up as a "DAPLINK" drive which implements the CMSIS-DAP interface. +- The PICO board is connected to the target board via a 10-pin SWD ribbon cable. + - If SWD connectors are not keyed, the P1 indicator (red line) on the SWD ribbon cable should match the P1 indicator on the board silkscreen near the 10-pin SWD connector. + +[**Section in Progress.**] + +### Using the REPL + +[**Section in Progress. Review & Testing are needed.**] diff --git a/ports/analog/background.c b/ports/analog/background.c new file mode 100644 index 000000000000..ccf71bf77bf5 --- /dev/null +++ b/ports/analog/background.c @@ -0,0 +1,28 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "py/runtime.h" +#include "supervisor/filesystem.h" +#include "supervisor/usb.h" +#include "supervisor/shared/stack.h" + +//TODO: IMPLEMENT + +void port_background_task(void) { + return; +} + +void port_background_tick(void) { + return; +} + +void port_start_background_tick(void) { + return; +} + +void port_finish_background_tick(void) { + return; +} diff --git a/ports/analog/background.h b/ports/analog/background.h new file mode 100644 index 000000000000..8fbe98bd9d8e --- /dev/null +++ b/ports/analog/background.h @@ -0,0 +1,10 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#ifndef MICROPY_INCLUDED_BACKGROUND_H +#define MICROPY_INCLUDED_BACKGROUND_H + +#endif // MICROPY_INCLUDED_BACKGROUND_H diff --git a/ports/analog/boards/APARD/README.md b/ports/analog/boards/APARD/README.md new file mode 100644 index 000000000000..8768ed93d56d --- /dev/null +++ b/ports/analog/boards/APARD/README.md @@ -0,0 +1,14 @@ +# AD-APARD32690-SL + +This board features the MAX32690, a dual-core ARM Cortex-M4/RISC-V MCU with 3MiB Flash, 1MiB SRAM. The board also has support for 10BASE-T1L Ethernet, Wifi, Bluetooth, USB, and Security via MAXQ1065. However, most of these features are not yet available for this CircuitPython port (USB will be added soon; others are currently unplanned). + +### Onboard connectors & peripherals + +This board comes in a form-factor similar to an Arduino Mega, enabling Arduino-style shield boards to be plugged in and evaluated with the MAX32690. This vastly opens up the options for easily plugging peripherals into the board, especially when combined with the two Pmod:tm: connectors, P8 (SPI) and P13 (I2C). + +### Product Resources + +For more info about AD-APARD32690-SL, visit our product webpages for datasheets, User Guides, Software, and Design Documents: + +[AD-APARD32690-SL Product Webpage](https://www.analog.com/en/resources/evaluation-hardware-and-software/evaluation-boards-kits/ad-apard32690-sl.html) +[AD-APARD32690-SL User Guide](https://wiki.analog.com/resources/eval/user-guides/ad-apard32690-sl) diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c new file mode 100644 index 000000000000..b44a1ae51e04 --- /dev/null +++ b/ports/analog/boards/APARD/board.c @@ -0,0 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/APARD/mpconfigboard.h new file mode 100644 index 000000000000..b22c7ab9ecc6 --- /dev/null +++ b/ports/analog/boards/APARD/mpconfigboard.h @@ -0,0 +1,31 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2016 Glenn Ruben Bakke +// SPDX-FileCopyrightText: Copyright (c) 2018 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define MICROPY_HW_BOARD_NAME "APARD32690" +#define MICROPY_HW_MCU_NAME "max32690" + +#define FLASH_SIZE (0x300000) // 3MiB +#define FLASH_PAGE_SIZE (0x4000) // 16384 byte pages (16 KiB) + +#define BOARD_HAS_CRYSTAL 1 + +// todo: figure out a way to smartly set this up based on storage considerations +#if INTERNAL_FLASH_FILESYSTEM +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x10032000) // for MAX32690 +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64 * 1024) // 64K +#else +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) +#endif diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk new file mode 100644 index 000000000000..7e5465e69422 --- /dev/null +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -0,0 +1,18 @@ +# This file is part of the CircuitPython project: https://circuitpython.org +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +INTERNAL_FLASH_FILESYSTEM = 1 +# FLASH: 0x10000000 to 0x10340000 +# SRAM: 0x20000000 to 0x20100000 + +USB_PRODUCT = "MAX32690 APARD" +USB_MANUFACTURER = "Analog Devices, Inc." +# CFLAGS+=-DEXT_FLASH_MX25 + +MCU_SERIES=max32 +MCU_VARIANT=max32690 + +CFLAGS += -DHAS_TRNG=1 diff --git a/ports/analog/boards/APARD/pins.c b/ports/analog/boards/APARD/pins.c new file mode 100644 index 000000000000..ddd2afdafe58 --- /dev/null +++ b/ports/analog/boards/APARD/pins.c @@ -0,0 +1,125 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + //P0 + { MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_P0_16) }, + { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_P0_17) }, + { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_P0_18) }, + { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_P0_19) }, + { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_P0_20) }, + { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_P0_21) }, + { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_P0_22) }, + { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_P0_23) }, + { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_P0_24) }, + { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_P0_25) }, + { MP_ROM_QSTR(MP_QSTR_PA26), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_P0_27) }, + { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_PA29), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_P0_31) }, + //P1 + { MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_P1_11) }, + { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_P1_12) }, + { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_P1_13) }, + { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_P1_14) }, + { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_P1_16) }, + { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_P1_17) }, + { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_P1_18) }, + { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_P1_19) }, + { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_P1_20) }, + { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_P1_21) }, + { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_P1_22) }, + { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_P1_23) }, + { MP_ROM_QSTR(MP_QSTR_PB24), MP_ROM_PTR(&pin_P1_24) }, + { MP_ROM_QSTR(MP_QSTR_PB25), MP_ROM_PTR(&pin_P1_25) }, + { MP_ROM_QSTR(MP_QSTR_PB26), MP_ROM_PTR(&pin_P1_26) }, + { MP_ROM_QSTR(MP_QSTR_PB27), MP_ROM_PTR(&pin_P1_27) }, + { MP_ROM_QSTR(MP_QSTR_PB28), MP_ROM_PTR(&pin_P1_28) }, + { MP_ROM_QSTR(MP_QSTR_PB29), MP_ROM_PTR(&pin_P1_29) }, + { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_P1_30) }, + { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_P1_31) }, + //P2 + { MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_PC09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_P2_10) }, + { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_P2_11) }, + { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_P2_12) }, + { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_P2_13) }, + { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_P2_14) }, + { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_P2_15) }, + { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_P2_16) }, + { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_P2_17) }, + { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_P2_18) }, + { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_P2_19) }, + { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_P2_20) }, + { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_P2_21) }, + { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_P2_22) }, + { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_P2_23) }, + { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_P2_24) }, + { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_P2_25) }, + { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_P2_26) }, + { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_P2_27) }, + { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_P2_28) }, + { MP_ROM_QSTR(MP_QSTR_PC29), MP_ROM_PTR(&pin_P2_29) }, + { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_P2_30) }, + { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_P2_31) }, + //P3 + { MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_P3_09) }, + //P4 + { MP_ROM_QSTR(MP_QSTR_PE00), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_PE01), MP_ROM_PTR(&pin_P4_01) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/analog/common-hal/board/__init__.c b/ports/analog/common-hal/board/__init__.c new file mode 100644 index 000000000000..bcae8371c18c --- /dev/null +++ b/ports/analog/common-hal/board/__init__.c @@ -0,0 +1,5 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2018 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c new file mode 100644 index 000000000000..bc1ef9d70efc --- /dev/null +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -0,0 +1,34 @@ + +#include + +#include "shared-bindings/microcontroller/Pin.h" +// #include "shared-bindings/digitalio/DigitalInOut.h" + + +// #include "gpio.h" + + +//FIXME: Implement +void reset_all_pins(void) { + return; +} + +// FIXME: Implement +void reset_pin_number(uint8_t pin) { + return; +} + +// FIXME: Implement +void claim_pin(const mcu_pin_obj_t *pin) { + return; +} + +// FIXME: Implement +bool pin_number_is_free(uint8_t pin_number) { + return true; +} + +// FIXME: Implement +void never_reset_pin_number(uint8_t pin_number) { + return; +} diff --git a/ports/analog/common-hal/microcontroller/Pin.h b/ports/analog/common-hal/microcontroller/Pin.h new file mode 100644 index 000000000000..6089a94e0c11 --- /dev/null +++ b/ports/analog/common-hal/microcontroller/Pin.h @@ -0,0 +1,14 @@ + +#pragma once + +#include "py/mphal.h" + +#include "peripherals/pins.h" + +void reset_all_pins(void); +// reset_pin_number takes the pin number instead of the pointer so that objects don't +// need to store a full pointer. +void reset_pin_number(uint8_t pin); +void claim_pin(const mcu_pin_obj_t *pin); +bool pin_number_is_free(uint8_t pin_number); +void never_reset_pin_number(uint8_t pin_number); diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c new file mode 100644 index 000000000000..1bdcceeeb74c --- /dev/null +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -0,0 +1,36 @@ + + +#include +#include "py/runtime.h" + +#if CIRCUITPY_ALARM +#include "common-hal/alarm/__init__.h" +#endif + +#include "common-hal/microcontroller/Processor.h" +#include "shared-bindings/microcontroller/ResetReason.h" + +#include "system_max32690.h" + +// +float common_hal_mcu_processor_get_temperature(void) { + return NAN; +} + +// TODO: Determine if there's a means of getting core voltage +float common_hal_mcu_processor_get_voltage(void) { + return NAN; +} + +uint32_t common_hal_mcu_processor_get_frequency(void) { + return SystemCoreClock; +} + +void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { + return; +} + +// TODO: May need to add reset reason in alarm / deepsleep cases +mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { + return RESET_REASON_UNKNOWN; +} diff --git a/ports/analog/common-hal/microcontroller/Processor.h b/ports/analog/common-hal/microcontroller/Processor.h new file mode 100644 index 000000000000..aab7727550a9 --- /dev/null +++ b/ports/analog/common-hal/microcontroller/Processor.h @@ -0,0 +1,16 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 12 + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + // Stores no state currently. +} mcu_processor_obj_t; diff --git a/ports/analog/common-hal/microcontroller/__init__.c b/ports/analog/common-hal/microcontroller/__init__.c new file mode 100644 index 000000000000..f15ef9bcecc3 --- /dev/null +++ b/ports/analog/common-hal/microcontroller/__init__.c @@ -0,0 +1,410 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "py/mphal.h" +#include "py/obj.h" +#include "py/runtime.h" + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/microcontroller/Processor.h" + +// #include "shared-bindings/nvm/ByteArray.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/microcontroller/Processor.h" +#include "supervisor/port.h" +#include "supervisor/filesystem.h" +#include "supervisor/shared/safe_mode.h" + + +#include "max32690.h" +/** NOTE: It is not advised to directly include the below! + * These are includes taken care of by the core cmsis file. + * e.g. "max32690.h". Since CMSIS is compiled as lib, these are + * included there as for example. +*/ +// #include "core_cmFunc.h" // For enable/disable interrupts +// #include "core_cm4.h" // For NVIC_SystemReset +// #include "core_cmInstr.h" // For __DMB Data Memory Barrier + +void common_hal_mcu_delay_us(uint32_t delay) { + // uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq() / 1000000UL; + // delay *= ticks_per_us; + // SysTick->VAL = 0UL; + // SysTick->LOAD = delay; + // SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; + // while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) { + // } + // SysTick->CTRL = 0UL; +} + +volatile uint32_t nesting_count = 0; + +void common_hal_mcu_disable_interrupts(void) { + __disable_irq(); + __DMB(); + nesting_count++; +} + +void common_hal_mcu_enable_interrupts(void) { + if (nesting_count == 0) { + // This is very very bad because it means there was mismatched disable/enables. + reset_into_safe_mode(SAFE_MODE_INTERRUPT_ERROR); + } + nesting_count--; + if (nesting_count > 0) { + return; + } + __DMB(); + __enable_irq(); +} + +static bool next_reset_to_bootloader = false; + +void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { + if (runmode == RUNMODE_SAFE_MODE) { + safe_mode_on_next_reset(SAFE_MODE_PROGRAMMATIC); + } + if (runmode == RUNMODE_BOOTLOADER) { + next_reset_to_bootloader = true; + } +} + +void common_hal_mcu_reset(void) { + + if (next_reset_to_bootloader) { + reset_to_bootloader(); + } else { + NVIC_SystemReset(); + } +} + +// The singleton microcontroller.Processor object, bound to microcontroller.cpu +// It currently only has properties, and no state. +const mcu_processor_obj_t common_hal_mcu_processor_obj = { + .base = { + .type = &mcu_processor_type, + }, +}; + +// This maps MCU pin names to pin objects. +static const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { + #if defined(PIN_PA01) && !defined(IGNORE_PIN_PA01) + { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) }, + #endif + #if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02) + { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) }, + #endif + #if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03) + { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) }, + #endif + #if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04) + { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) }, + #endif + #if defined(PIN_PA05) && !defined(IGNORE_PIN_PA05) + { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) }, + #endif + #if defined(PIN_PA06) && !defined(IGNORE_PIN_PA06) + { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) }, + #endif + #if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07) + { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) }, + #endif + #if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) + { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) }, + #endif + #if defined(PIN_PA09) && !defined(IGNORE_PIN_PA09) + { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) }, + #endif + #if defined(PIN_PA10) && !defined(IGNORE_PIN_PA10) + { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) }, + #endif + #if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11) + { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) }, + #endif + #if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12) + { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) }, + #endif + #if defined(PIN_PA13) && !defined(IGNORE_PIN_PA13) + { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) }, + #endif + #if defined(PIN_PA14) && !defined(IGNORE_PIN_PA14) + { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) }, + #endif + #if defined(PIN_PA15) && !defined(IGNORE_PIN_PA15) + { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) }, + #endif + #if defined(PIN_PA16) && !defined(IGNORE_PIN_PA16) + { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_PA16) }, + #endif + #if defined(PIN_PA17) && !defined(IGNORE_PIN_PA17) + { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_PA17) }, + #endif + #if defined(PIN_PA18) && !defined(IGNORE_PIN_PA18) + { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_PA18) }, + #endif + #if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19) + { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) }, + #endif + #if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20) + { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) }, + #endif + #if defined(PIN_PA21) && !defined(IGNORE_PIN_PA21) + { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_PA21) }, + #endif + #if defined(PIN_PA22) && !defined(IGNORE_PIN_PA22) + { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_PA22) }, + #endif + #if defined(PIN_PA23) && !defined(IGNORE_PIN_PA23) + { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_PA23) }, + #endif + #if defined(PIN_PA24) && !defined(IGNORE_PIN_PA24) + { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_PA24) }, + #endif + #if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25) + { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) }, + #endif + #if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27) + { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) }, + #endif + #if defined(PIN_PA28) && !defined(IGNORE_PIN_PA28) + { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_PA28) }, + #endif + #if defined(PIN_PA30) && !defined(IGNORE_PIN_PA30) + { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_PA30) }, + #endif + #if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31) + { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) }, + #endif + + #if defined(PIN_PB01) && !defined(IGNORE_PIN_PB01) + { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) }, + #endif + #if defined(PIN_PB02) && !defined(IGNORE_PIN_PB02) + { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) }, + #endif + #if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03) + { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }, + #endif + #if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04) + { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) }, + #endif + #if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05) + { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) }, + #endif + #if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06) + { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) }, + #endif + #if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07) + { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) }, + #endif + #if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08) + { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) }, + #endif + #if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09) + { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) }, + #endif + #if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10) + { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) }, + #endif + #if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11) + { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) }, + #endif + #if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12) + { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) }, + #endif + #if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13) + { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) }, + #endif + #if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14) + { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) }, + #endif + #if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15) + { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) }, + #endif + #if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16) + { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) }, + #endif + #if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17) + { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) }, + #endif + #if defined(PIN_PB18) && !defined(IGNORE_PIN_PB18) + { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_PB18) }, + #endif + #if defined(PIN_PB19) && !defined(IGNORE_PIN_PB19) + { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_PB19) }, + #endif + #if defined(PIN_PB20) && !defined(IGNORE_PIN_PB20) + { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_PB20) }, + #endif + #if defined(PIN_PB21) && !defined(IGNORE_PIN_PB21) + { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_PB21) }, + #endif + #if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22) + { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) }, + #endif + #if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23) + { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) }, + #endif + #if defined(PIN_PB24) && !defined(IGNORE_PIN_PB24) + { MP_ROM_QSTR(MP_QSTR_PB24), MP_ROM_PTR(&pin_PB24) }, + #endif + #if defined(PIN_PB25) && !defined(IGNORE_PIN_PB25) + { MP_ROM_QSTR(MP_QSTR_PB25), MP_ROM_PTR(&pin_PB25) }, + #endif + #if defined(PIN_PB26) && !defined(IGNORE_PIN_PB26) + { MP_ROM_QSTR(MP_QSTR_PB26), MP_ROM_PTR(&pin_PB26) }, + #endif + #if defined(PIN_PB27) && !defined(IGNORE_PIN_PB27) + { MP_ROM_QSTR(MP_QSTR_PB27), MP_ROM_PTR(&pin_PB27) }, + #endif + #if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28) + { MP_ROM_QSTR(MP_QSTR_PB28), MP_ROM_PTR(&pin_PB28) }, + #endif + #if defined(PIN_PB29) && !defined(IGNORE_PIN_PB29) + { MP_ROM_QSTR(MP_QSTR_PB29), MP_ROM_PTR(&pin_PB29) }, + #endif + #if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30) + { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) }, + #endif + #if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31) + { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) }, + #endif + + #if defined(PIN_PC01) && !defined(IGNORE_PIN_PC01) + { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) }, + #endif + #if defined(PIN_PC02) && !defined(IGNORE_PIN_PC02) + { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) }, + #endif + #if defined(PIN_PC03) && !defined(IGNORE_PIN_PC03) + { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) }, + #endif + #if defined(PIN_PC04) && !defined(IGNORE_PIN_PC04) + { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_PC04) }, + #endif + #if defined(PIN_PC05) && !defined(IGNORE_PIN_PC05) + { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) }, + #endif + #if defined(PIN_PC06) && !defined(IGNORE_PIN_PC06) + { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, + #endif + #if defined(PIN_PC07) && !defined(IGNORE_PIN_PC07) + { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, + #endif + #if defined(PIN_PC10) && !defined(IGNORE_PIN_PC10) + { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) }, + #endif + #if defined(PIN_PC11) && !defined(IGNORE_PIN_PC11) + { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) }, + #endif + #if defined(PIN_PC12) && !defined(IGNORE_PIN_PC12) + { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) }, + #endif + #if defined(PIN_PC13) && !defined(IGNORE_PIN_PC13) + { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, + #endif + #if defined(PIN_PC14) && !defined(IGNORE_PIN_PC14) + { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_PC14) }, + #endif + #if defined(PIN_PC15) && !defined(IGNORE_PIN_PC15) + { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_PC15) }, + #endif + #if defined(PIN_PC16) && !defined(IGNORE_PIN_PC16) + { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_PC16) }, + #endif + #if defined(PIN_PC17) && !defined(IGNORE_PIN_PC17) + { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_PC17) }, + #endif + #if defined(PIN_PC18) && !defined(IGNORE_PIN_PC18) + { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_PC18) }, + #endif + #if defined(PIN_PC19) && !defined(IGNORE_PIN_PC19) + { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_PC19) }, + #endif + #if defined(PIN_PC20) && !defined(IGNORE_PIN_PC20) + { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_PC20) }, + #endif + #if defined(PIN_PC21) && !defined(IGNORE_PIN_PC21) + { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_PC21) }, + #endif + #if defined(PIN_PC22) && !defined(IGNORE_PIN_PC22) + { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_PC22) }, + #endif + #if defined(PIN_PC23) && !defined(IGNORE_PIN_PC23) + { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_PC23) }, + #endif + #if defined(PIN_PC24) && !defined(IGNORE_PIN_PC24) + { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_PC24) }, + #endif + #if defined(PIN_PC25) && !defined(IGNORE_PIN_PC25) + { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_PC25) }, + #endif + #if defined(PIN_PC26) && !defined(IGNORE_PIN_PC26) + { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_PC26) }, + #endif + #if defined(PIN_PC27) && !defined(IGNORE_PIN_PC27) + { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_PC27) }, + #endif + #if defined(PIN_PC28) && !defined(IGNORE_PIN_PC28) + { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_PC28) }, + #endif + #if defined(PIN_PC30) && !defined(IGNORE_PIN_PC30) + { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_PC30) }, + #endif + #if defined(PIN_PC31) && !defined(IGNORE_PIN_PC31) + { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_PC31) }, + #endif + + #if defined(PIN_PD01) && !defined(IGNORE_PIN_PD01) + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) }, + #endif + #if defined(PIN_PD02) && !defined(IGNORE_PIN_PD02) + { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_PD02) }, + #endif + #if defined(PIN_PD03) && !defined(IGNORE_PIN_PD03) + { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_PD03) }, + #endif + #if defined(PIN_PD04) && !defined(IGNORE_PIN_PD04) + { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_PD04) }, + #endif + #if defined(PIN_PD05) && !defined(IGNORE_PIN_PD05) + { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_PD05) }, + #endif + #if defined(PIN_PD06) && !defined(IGNORE_PIN_PD06) + { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_PD06) }, + #endif + #if defined(PIN_PD07) && !defined(IGNORE_PIN_PD07) + { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_PD07) }, + #endif + #if defined(PIN_PD08) && !defined(IGNORE_PIN_PD08) + { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) }, + #endif + #if defined(PIN_PD09) && !defined(IGNORE_PIN_PD09) + { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) }, + #endif + + #if defined(PIN_PE01) && !defined(IGNORE_PIN_PE01) + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD02) }, + #endif + #if defined(PIN_PE02) && !defined(IGNORE_PIN_PD02) + { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD02) }, + #endif + +}; +MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table); + +// #if CIRCUITPY_INTERNAL_NVM_SIZE > 0 +// // The singleton nvm.ByteArray object. +// const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { +// .base = { +// .type = &nvm_bytearray_type, +// }, +// .len = NVM_BYTEARRAY_BUFFER_SIZE, +// .start_address = (uint8_t *)(CIRCUITPY_INTERNAL_NVM_START_ADDR) +// }; +// #endif diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c new file mode 100644 index 000000000000..97ce98cb9e1e --- /dev/null +++ b/ports/analog/common-hal/os/__init__.c @@ -0,0 +1,50 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "genhdr/mpversion.h" +#include "py/mpconfig.h" +#include "py/objstr.h" +#include "py/objtuple.h" + +#include "py/mperrno.h" +#include "py/runtime.h" + +// #include "peripherals/periph.h" + +static const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, "max32"); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, "max32"); + +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +static MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj + ); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + +bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { + #if (HAS_TRNG) + //todo: implement + #else + #endif + return false; +} diff --git a/ports/analog/linking/max32690_cktpy.ld b/ports/analog/linking/max32690_cktpy.ld new file mode 100644 index 000000000000..3ecc0b991f2f --- /dev/null +++ b/ports/analog/linking/max32690_cktpy.ld @@ -0,0 +1,160 @@ +MEMORY { + ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K + FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M + FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 200K + FLASH_FS (rw) : ORIGIN = 0x10032000, LENGTH = 64K + FLASH_FIRMWARE (rx) : ORIGIN = 0x10042000, LENGTH = 0x002BE000 + RAM (rwx): ORIGIN = 0x20000000, LENGTH = 1M +} +/* FLASH FIRMWARE: 0x10300000 (end) - 0x10042000 = 0x002BE000 */ + +ENTRY(Reset_Handler) + +SECTIONS { + .rom : + { + KEEP(*(.rom_vector)) + *(.rom_handlers*) + } > ROM + + /* Place ISR vector in a separate flash section */ + .isr_vector : + { + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + EXCLUDE_FILE (*riscv.o) *(.text*) /* program code, exclude RISCV code */ + } >FLASH_ISR + + .text : + { + . = ALIGN(4); + _text = .; + *(.rodata*) /* read-only data: "const" */ + + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + /* C++ Exception handling */ + KEEP(*(.eh_frame*)) + . = ALIGN(4); + _etext = .; + } > FLASH_FIRMWARE + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH_FIRMWARE + + /* Binary import */ + .bin_storage : + { + FILL(0xFF) + _bin_start_ = .; + KEEP(*(.bin_storage_img)) + _bin_end_ = .; + . = ALIGN(4); + } > FLASH_FIRMWARE + + /* it's used for C++ exception handling */ + /* we need to keep this to avoid overlapping */ + .ARM.exidx : + { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > FLASH_FIRMWARE + + .data : + { + . = ALIGN(4); + _data = .; + _sdata = .; + + *(vtable) + *(.data*) /*read-write initialized data: initialized global variable*/ + + /* These array sections are used by __libc_init_array to call static C++ constructors */ + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP(*(SORT(.fini_array.*))) + KEEP(*(.fini_array)) + PROVIDE_HIDDEN (__fini_array_end = .); + + /* Run the flash programming functions from SRAM */ + *(.flashprog) + + . = ALIGN(4); + _edata = .; + } > RAM AT>FLASH_FIRMWARE + __load_data = LOADADDR(.data); + + .bss : + { + . = ALIGN(4); + _sbss = .; /* Provide _sbss for Cktpy */ + _bss = .; + + *(.bss*) /*read-write zero initialized data: uninitialized global variable*/ + *(COMMON) + + . = ALIGN(4); + _ebss = .; + _ezero = .; /* Provide _ezero /_ebss for CktPython (same as ebss) */ + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + __estack = __StackLimit; /* Provide _estack for CktPython */ + + .heap (COPY): + { + . = ALIGN(4); + PROVIDE ( end = . ); + PROVIDE ( _end = . ); + *(.heap*) + __HeapLimit = ABSOLUTE(__StackLimit); + } > RAM + + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack") +} diff --git a/ports/analog/mpconfigport.h b/ports/analog/mpconfigport.h new file mode 100644 index 000000000000..bb9f8b6ac368 --- /dev/null +++ b/ports/analog/mpconfigport.h @@ -0,0 +1,36 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2015 Glenn Ruben Bakke +// SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include + +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + + +// 24kiB stack +#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 +// uint8_t _ld_default_stack_size; +// #define CIRCUITPY_DEFAULT_STACK_SIZE ((uint32_t)&_ld_default_stack_size) + +// Also includes mpconfigboard.h +#include "py/circuitpy_mpconfig.h" + +// Board flags: +#ifndef BOARD_OVERWRITE_SWD +#define BOARD_OVERWRITE_SWD (0) +#endif +#ifndef BOARD_VTOR_DEFER +#define BOARD_VTOR_DEFER (0) +#endif +#ifndef BOARD_NO_VBUS_SENSE +#define BOARD_NO_VBUS_SENSE (0) +#endif +#ifndef BOARD_NO_USB_OTG_ID_SENSE +#define BOARD_NO_USB_OTG_ID_SENSE (0) +#endif diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk new file mode 100644 index 000000000000..3c68a62884fd --- /dev/null +++ b/ports/analog/mpconfigport.mk @@ -0,0 +1,85 @@ +# This file is part of the CircuitPython project: https://circuitpython.org +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +CHIP_FAMILY ?= max32 + +# Necessary to build CircuitPython +USB_NUM_ENDPOINT_PAIRS ?= 0 +LONGINT_IMPL ?= MPZ +INTERNAL_LIBM ?= 1 + +#################################################################################### +# Suggested config for first-time porting +#################################################################################### +# These modules are implemented in ports//common-hal: + +# Typically the first module to create +CIRCUITPY_MICROCONTROLLER = 1 +# Typically the second module to create +CIRCUITPY_DIGITALIO = 0 +# Other modules: +CIRCUITPY_ANALOGIO = 0 +CIRCUITPY_BUSIO = 0 +CIRCUITPY_COUNTIO = 0 +CIRCUITPY_NEOPIXEL_WRITE = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_OS = 1 +CIRCUITPY_NVM = 0 +CIRCUITPY_AUDIOBUSIO = 0 +CIRCUITPY_AUDIOIO = 0 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_RTC = 0 +CIRCUITPY_SDCARDIO = 0 +CIRCUITPY_FRAMEBUFFERIO = 0 +CIRCUITPY_FREQUENCYIO = 0 +CIRCUITPY_I2CTARGET = 0 +# Requires SPI, PulseIO (stub ok): +CIRCUITPY_DISPLAYIO = 0 + +# These modules are implemented in shared-module/ - they can be included in +# any port once their prerequisites in common-hal are complete. +# Requires DigitalIO: +CIRCUITPY_BITBANGIO = 0 +# Requires neopixel_write or SPI (dotstar) +CIRCUITPY_PIXELBUF = 0 +# Requires OS +CIRCUITPY_RANDOM = 0 +# Requires OS, filesystem +CIRCUITPY_STORAGE = 0 +# Requires Microcontroller +CIRCUITPY_TOUCHIO = 0 +# Requires UART! +CIRCUITPY_CONSOLE_UART = 0 +# Requires USB +CIRCUITPY_USB_DEVICE = 0 +CIRCUITPY_USB_CDC = 0 +CIRCUITPY_USB_HID = 0 +CIRCUITPY_USB_MIDI = 0 +# Does nothing without I2C +CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 +# No requirements, but takes extra flash +CIRCUITPY_ULAB = 0 +#################################################################################### +# Required for clean building (additional CircuittPython Defaults) +#################################################################################### +# Enabled by default +CIRCUITPY_PWMIO = 0 +# Depends on BUSIO +# CIRCUITPY_BLEIO = 0 +CIRCUITPY_BLEIO_HCI = 0 +CIRCUITPY_KEYPAD = 0 +CIRCUITPY_BUSDEVICE = 0 + +# TinyUSB will be added later. +CIRCUITPY_TINYUSB = 0 +CIRCUITPY_PYUSB = 0 + +INTERNAL_FLASH_FILESYSTEM = 1 +SPI_FLASH_FILESYSTEM = 0 +QSPI_FLASH_FILESYSTEM = 0 + +# TODO: Review flash filesystem funcs before flashing +DISABLE_FILESYSTEM = 0 diff --git a/ports/analog/mphalport.c b/ports/analog/mphalport.c new file mode 100644 index 000000000000..1bbcf605b007 --- /dev/null +++ b/ports/analog/mphalport.c @@ -0,0 +1,15 @@ + +#include "mphalport.h" +#include "cmsis_gcc.h" + + +// TODO: Define tick & other port functions + + +void mp_hal_disable_all_interrupts(void) { + __disable_irq(); +} + +void mp_hal_enable_all_interrupts(void) { + __enable_irq(); +} diff --git a/ports/analog/mphalport.h b/ports/analog/mphalport.h new file mode 100644 index 000000000000..8dba63d82ff0 --- /dev/null +++ b/ports/analog/mphalport.h @@ -0,0 +1,22 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "py/obj.h" +#include "lib/oofatfs/ff.h" +#include "supervisor/shared/tick.h" + +// TODO: Define tick & other port functions +// Global millisecond tick count (driven by SysTick interrupt). +static inline mp_uint_t mp_hal_ticks_ms(void) { + return supervisor_ticks_ms32(); +} + +void mp_hal_set_interrupt_char(int c); + +void mp_hal_disable_all_interrupts(void); +void mp_hal_enable_all_interrupts(void); diff --git a/ports/analog/msdk b/ports/analog/msdk new file mode 160000 index 000000000000..608acf33e95a --- /dev/null +++ b/ports/analog/msdk @@ -0,0 +1 @@ +Subproject commit 608acf33e95a994d548b8223955952c4749acaac diff --git a/ports/analog/peripherals/max32690/pins.c b/ports/analog/peripherals/max32690/pins.c new file mode 100644 index 000000000000..4f26d9d1f6d6 --- /dev/null +++ b/ports/analog/peripherals/max32690/pins.c @@ -0,0 +1,119 @@ +#include "py/obj.h" +#include "py/mphal.h" +#include "peripherals/pins.h" + +#include "gpio.h" +#include "gpio_regs.h" + +const mcu_pin_obj_t pin_P0_00 = PIN(MXC_GPIO_PORT_0, 0); +const mcu_pin_obj_t pin_P0_01 = PIN(MXC_GPIO_PORT_0, 1); +const mcu_pin_obj_t pin_P0_02 = PIN(MXC_GPIO_PORT_0, 2); +const mcu_pin_obj_t pin_P0_03 = PIN(MXC_GPIO_PORT_0, 3); +const mcu_pin_obj_t pin_P0_04 = PIN(MXC_GPIO_PORT_0, 4); +const mcu_pin_obj_t pin_P0_05 = PIN(MXC_GPIO_PORT_0, 5); +const mcu_pin_obj_t pin_P0_06 = PIN(MXC_GPIO_PORT_0, 6); +const mcu_pin_obj_t pin_P0_07 = PIN(MXC_GPIO_PORT_0, 7); +const mcu_pin_obj_t pin_P0_08 = PIN(MXC_GPIO_PORT_0, 8); +const mcu_pin_obj_t pin_P0_09 = PIN(MXC_GPIO_PORT_0, 9); +const mcu_pin_obj_t pin_P0_10 = PIN(MXC_GPIO_PORT_0, 10); +const mcu_pin_obj_t pin_P0_11 = PIN(MXC_GPIO_PORT_0, 11); +const mcu_pin_obj_t pin_P0_12 = PIN(MXC_GPIO_PORT_0, 12); +const mcu_pin_obj_t pin_P0_13 = PIN(MXC_GPIO_PORT_0, 13); +const mcu_pin_obj_t pin_P0_14 = PIN(MXC_GPIO_PORT_0, 14); +const mcu_pin_obj_t pin_P0_15 = PIN(MXC_GPIO_PORT_0, 15); +const mcu_pin_obj_t pin_P0_16 = PIN(MXC_GPIO_PORT_0, 16); +const mcu_pin_obj_t pin_P0_17 = PIN(MXC_GPIO_PORT_0, 17); +const mcu_pin_obj_t pin_P0_18 = PIN(MXC_GPIO_PORT_0, 18); +const mcu_pin_obj_t pin_P0_19 = PIN(MXC_GPIO_PORT_0, 19); +const mcu_pin_obj_t pin_P0_20 = PIN(MXC_GPIO_PORT_0, 20); +const mcu_pin_obj_t pin_P0_21 = PIN(MXC_GPIO_PORT_0, 21); +const mcu_pin_obj_t pin_P0_22 = PIN(MXC_GPIO_PORT_0, 22); +const mcu_pin_obj_t pin_P0_23 = PIN(MXC_GPIO_PORT_0, 23); +const mcu_pin_obj_t pin_P0_24 = PIN(MXC_GPIO_PORT_0, 24); +const mcu_pin_obj_t pin_P0_25 = PIN(MXC_GPIO_PORT_0, 25); +const mcu_pin_obj_t pin_P0_26 = PIN(MXC_GPIO_PORT_0, 26); +const mcu_pin_obj_t pin_P0_27 = PIN(MXC_GPIO_PORT_0, 27); +const mcu_pin_obj_t pin_P0_28 = PIN(MXC_GPIO_PORT_0, 28); +const mcu_pin_obj_t pin_P0_29 = PIN(MXC_GPIO_PORT_0, 29); +const mcu_pin_obj_t pin_P0_30 = PIN(MXC_GPIO_PORT_0, 30); +const mcu_pin_obj_t pin_P0_31 = PIN(MXC_GPIO_PORT_0, 31); + +const mcu_pin_obj_t pin_P1_00 = PIN(MXC_GPIO_PORT_1, 0); +const mcu_pin_obj_t pin_P1_01 = PIN(MXC_GPIO_PORT_1, 1); +const mcu_pin_obj_t pin_P1_02 = PIN(MXC_GPIO_PORT_1, 2); +const mcu_pin_obj_t pin_P1_03 = PIN(MXC_GPIO_PORT_1, 3); +const mcu_pin_obj_t pin_P1_04 = PIN(MXC_GPIO_PORT_1, 4); +const mcu_pin_obj_t pin_P1_05 = PIN(MXC_GPIO_PORT_1, 5); +const mcu_pin_obj_t pin_P1_06 = PIN(MXC_GPIO_PORT_1, 6); +const mcu_pin_obj_t pin_P1_07 = PIN(MXC_GPIO_PORT_1, 7); +const mcu_pin_obj_t pin_P1_08 = PIN(MXC_GPIO_PORT_1, 8); +const mcu_pin_obj_t pin_P1_09 = PIN(MXC_GPIO_PORT_1, 9); +const mcu_pin_obj_t pin_P1_10 = PIN(MXC_GPIO_PORT_1, 10); +const mcu_pin_obj_t pin_P1_11 = PIN(MXC_GPIO_PORT_1, 11); +const mcu_pin_obj_t pin_P1_12 = PIN(MXC_GPIO_PORT_1, 12); +const mcu_pin_obj_t pin_P1_13 = PIN(MXC_GPIO_PORT_1, 13); +const mcu_pin_obj_t pin_P1_14 = PIN(MXC_GPIO_PORT_1, 14); +const mcu_pin_obj_t pin_P1_15 = PIN(MXC_GPIO_PORT_1, 15); +const mcu_pin_obj_t pin_P1_16 = PIN(MXC_GPIO_PORT_1, 16); +const mcu_pin_obj_t pin_P1_17 = PIN(MXC_GPIO_PORT_1, 17); +const mcu_pin_obj_t pin_P1_18 = PIN(MXC_GPIO_PORT_1, 18); +const mcu_pin_obj_t pin_P1_19 = PIN(MXC_GPIO_PORT_1, 19); +const mcu_pin_obj_t pin_P1_20 = PIN(MXC_GPIO_PORT_1, 20); +const mcu_pin_obj_t pin_P1_21 = PIN(MXC_GPIO_PORT_1, 21); +const mcu_pin_obj_t pin_P1_22 = PIN(MXC_GPIO_PORT_1, 22); +const mcu_pin_obj_t pin_P1_23 = PIN(MXC_GPIO_PORT_1, 23); +const mcu_pin_obj_t pin_P1_24 = PIN(MXC_GPIO_PORT_1, 24); +const mcu_pin_obj_t pin_P1_25 = PIN(MXC_GPIO_PORT_1, 25); +const mcu_pin_obj_t pin_P1_26 = PIN(MXC_GPIO_PORT_1, 26); +const mcu_pin_obj_t pin_P1_27 = PIN(MXC_GPIO_PORT_1, 27); +const mcu_pin_obj_t pin_P1_28 = PIN(MXC_GPIO_PORT_1, 28); +const mcu_pin_obj_t pin_P1_29 = PIN(MXC_GPIO_PORT_1, 29); +const mcu_pin_obj_t pin_P1_30 = PIN(MXC_GPIO_PORT_1, 30); +const mcu_pin_obj_t pin_P1_31 = PIN(MXC_GPIO_PORT_1, 31); + +const mcu_pin_obj_t pin_P2_00 = PIN(MXC_GPIO_PORT_2, 0); +const mcu_pin_obj_t pin_P2_01 = PIN(MXC_GPIO_PORT_2, 1); +const mcu_pin_obj_t pin_P2_02 = PIN(MXC_GPIO_PORT_2, 2); +const mcu_pin_obj_t pin_P2_03 = PIN(MXC_GPIO_PORT_2, 3); +const mcu_pin_obj_t pin_P2_04 = PIN(MXC_GPIO_PORT_2, 4); +const mcu_pin_obj_t pin_P2_05 = PIN(MXC_GPIO_PORT_2, 5); +const mcu_pin_obj_t pin_P2_06 = PIN(MXC_GPIO_PORT_2, 6); +const mcu_pin_obj_t pin_P2_07 = PIN(MXC_GPIO_PORT_2, 7); +const mcu_pin_obj_t pin_P2_08 = PIN(MXC_GPIO_PORT_2, 8); +const mcu_pin_obj_t pin_P2_09 = PIN(MXC_GPIO_PORT_2, 9); +const mcu_pin_obj_t pin_P2_10 = PIN(MXC_GPIO_PORT_2, 10); +const mcu_pin_obj_t pin_P2_11 = PIN(MXC_GPIO_PORT_2, 11); +const mcu_pin_obj_t pin_P2_12 = PIN(MXC_GPIO_PORT_2, 12); +const mcu_pin_obj_t pin_P2_13 = PIN(MXC_GPIO_PORT_2, 13); +const mcu_pin_obj_t pin_P2_14 = PIN(MXC_GPIO_PORT_2, 14); +const mcu_pin_obj_t pin_P2_15 = PIN(MXC_GPIO_PORT_2, 15); +const mcu_pin_obj_t pin_P2_16 = PIN(MXC_GPIO_PORT_2, 16); +const mcu_pin_obj_t pin_P2_17 = PIN(MXC_GPIO_PORT_2, 17); +const mcu_pin_obj_t pin_P2_18 = PIN(MXC_GPIO_PORT_2, 18); +const mcu_pin_obj_t pin_P2_19 = PIN(MXC_GPIO_PORT_2, 19); +const mcu_pin_obj_t pin_P2_20 = PIN(MXC_GPIO_PORT_2, 20); +const mcu_pin_obj_t pin_P2_21 = PIN(MXC_GPIO_PORT_2, 21); +const mcu_pin_obj_t pin_P2_22 = PIN(MXC_GPIO_PORT_2, 22); +const mcu_pin_obj_t pin_P2_23 = PIN(MXC_GPIO_PORT_2, 23); +const mcu_pin_obj_t pin_P2_24 = PIN(MXC_GPIO_PORT_2, 24); +const mcu_pin_obj_t pin_P2_25 = PIN(MXC_GPIO_PORT_2, 25); +const mcu_pin_obj_t pin_P2_26 = PIN(MXC_GPIO_PORT_2, 26); +const mcu_pin_obj_t pin_P2_27 = PIN(MXC_GPIO_PORT_2, 27); +const mcu_pin_obj_t pin_P2_28 = PIN(MXC_GPIO_PORT_2, 28); +const mcu_pin_obj_t pin_P2_29 = PIN(MXC_GPIO_PORT_2, 29); +const mcu_pin_obj_t pin_P2_30 = PIN(MXC_GPIO_PORT_2, 30); +const mcu_pin_obj_t pin_P2_31 = PIN(MXC_GPIO_PORT_2, 31); + +const mcu_pin_obj_t pin_P3_00 = PIN(MXC_GPIO_PORT_3, 0); +const mcu_pin_obj_t pin_P3_01 = PIN(MXC_GPIO_PORT_3, 1); +const mcu_pin_obj_t pin_P3_02 = PIN(MXC_GPIO_PORT_3, 2); +const mcu_pin_obj_t pin_P3_03 = PIN(MXC_GPIO_PORT_3, 3); +const mcu_pin_obj_t pin_P3_04 = PIN(MXC_GPIO_PORT_3, 4); +const mcu_pin_obj_t pin_P3_05 = PIN(MXC_GPIO_PORT_3, 5); +const mcu_pin_obj_t pin_P3_06 = PIN(MXC_GPIO_PORT_3, 6); +const mcu_pin_obj_t pin_P3_07 = PIN(MXC_GPIO_PORT_3, 7); +const mcu_pin_obj_t pin_P3_08 = PIN(MXC_GPIO_PORT_3, 8); +const mcu_pin_obj_t pin_P3_09 = PIN(MXC_GPIO_PORT_3, 9); + +const mcu_pin_obj_t pin_P4_00 = PIN(MXC_GPIO_PORT_4, 0); +const mcu_pin_obj_t pin_P4_01 = PIN(MXC_GPIO_PORT_4, 1); diff --git a/ports/analog/peripherals/max32690/pins.h b/ports/analog/peripherals/max32690/pins.h new file mode 100644 index 000000000000..9b5cc303ee5c --- /dev/null +++ b/ports/analog/peripherals/max32690/pins.h @@ -0,0 +1,114 @@ +#pragma once + +extern const mcu_pin_obj_t pin_P0_00; +extern const mcu_pin_obj_t pin_P0_01; +extern const mcu_pin_obj_t pin_P0_02; +extern const mcu_pin_obj_t pin_P0_03; +extern const mcu_pin_obj_t pin_P0_04; +extern const mcu_pin_obj_t pin_P0_05; +extern const mcu_pin_obj_t pin_P0_06; +extern const mcu_pin_obj_t pin_P0_07; +extern const mcu_pin_obj_t pin_P0_08; +extern const mcu_pin_obj_t pin_P0_09; +extern const mcu_pin_obj_t pin_P0_10; +extern const mcu_pin_obj_t pin_P0_11; +extern const mcu_pin_obj_t pin_P0_12; +extern const mcu_pin_obj_t pin_P0_13; +extern const mcu_pin_obj_t pin_P0_14; +extern const mcu_pin_obj_t pin_P0_15; +extern const mcu_pin_obj_t pin_P0_16; +extern const mcu_pin_obj_t pin_P0_17; +extern const mcu_pin_obj_t pin_P0_18; +extern const mcu_pin_obj_t pin_P0_19; +extern const mcu_pin_obj_t pin_P0_20; +extern const mcu_pin_obj_t pin_P0_21; +extern const mcu_pin_obj_t pin_P0_22; +extern const mcu_pin_obj_t pin_P0_23; +extern const mcu_pin_obj_t pin_P0_24; +extern const mcu_pin_obj_t pin_P0_25; +extern const mcu_pin_obj_t pin_P0_26; +extern const mcu_pin_obj_t pin_P0_27; +extern const mcu_pin_obj_t pin_P0_28; +extern const mcu_pin_obj_t pin_P0_29; +extern const mcu_pin_obj_t pin_P0_30; +extern const mcu_pin_obj_t pin_P0_31; + +extern const mcu_pin_obj_t pin_P1_00; +extern const mcu_pin_obj_t pin_P1_01; +extern const mcu_pin_obj_t pin_P1_02; +extern const mcu_pin_obj_t pin_P1_03; +extern const mcu_pin_obj_t pin_P1_04; +extern const mcu_pin_obj_t pin_P1_05; +extern const mcu_pin_obj_t pin_P1_06; +extern const mcu_pin_obj_t pin_P1_07; +extern const mcu_pin_obj_t pin_P1_08; +extern const mcu_pin_obj_t pin_P1_09; +extern const mcu_pin_obj_t pin_P1_10; +extern const mcu_pin_obj_t pin_P1_11; +extern const mcu_pin_obj_t pin_P1_12; +extern const mcu_pin_obj_t pin_P1_13; +extern const mcu_pin_obj_t pin_P1_14; +extern const mcu_pin_obj_t pin_P1_15; +extern const mcu_pin_obj_t pin_P1_16; +extern const mcu_pin_obj_t pin_P1_17; +extern const mcu_pin_obj_t pin_P1_18; +extern const mcu_pin_obj_t pin_P1_19; +extern const mcu_pin_obj_t pin_P1_20; +extern const mcu_pin_obj_t pin_P1_21; +extern const mcu_pin_obj_t pin_P1_22; +extern const mcu_pin_obj_t pin_P1_23; +extern const mcu_pin_obj_t pin_P1_24; +extern const mcu_pin_obj_t pin_P1_25; +extern const mcu_pin_obj_t pin_P1_26; +extern const mcu_pin_obj_t pin_P1_27; +extern const mcu_pin_obj_t pin_P1_28; +extern const mcu_pin_obj_t pin_P1_29; +extern const mcu_pin_obj_t pin_P1_30; +extern const mcu_pin_obj_t pin_P1_31; + +extern const mcu_pin_obj_t pin_P2_00; +extern const mcu_pin_obj_t pin_P2_01; +extern const mcu_pin_obj_t pin_P2_02; +extern const mcu_pin_obj_t pin_P2_03; +extern const mcu_pin_obj_t pin_P2_04; +extern const mcu_pin_obj_t pin_P2_05; +extern const mcu_pin_obj_t pin_P2_06; +extern const mcu_pin_obj_t pin_P2_07; +extern const mcu_pin_obj_t pin_P2_08; +extern const mcu_pin_obj_t pin_P2_09; +extern const mcu_pin_obj_t pin_P2_10; +extern const mcu_pin_obj_t pin_P2_11; +extern const mcu_pin_obj_t pin_P2_12; +extern const mcu_pin_obj_t pin_P2_13; +extern const mcu_pin_obj_t pin_P2_14; +extern const mcu_pin_obj_t pin_P2_15; +extern const mcu_pin_obj_t pin_P2_16; +extern const mcu_pin_obj_t pin_P2_17; +extern const mcu_pin_obj_t pin_P2_18; +extern const mcu_pin_obj_t pin_P2_19; +extern const mcu_pin_obj_t pin_P2_20; +extern const mcu_pin_obj_t pin_P2_21; +extern const mcu_pin_obj_t pin_P2_22; +extern const mcu_pin_obj_t pin_P2_23; +extern const mcu_pin_obj_t pin_P2_24; +extern const mcu_pin_obj_t pin_P2_25; +extern const mcu_pin_obj_t pin_P2_26; +extern const mcu_pin_obj_t pin_P2_27; +extern const mcu_pin_obj_t pin_P2_28; +extern const mcu_pin_obj_t pin_P2_29; +extern const mcu_pin_obj_t pin_P2_30; +extern const mcu_pin_obj_t pin_P2_31; + +extern const mcu_pin_obj_t pin_P3_00; +extern const mcu_pin_obj_t pin_P3_01; +extern const mcu_pin_obj_t pin_P3_02; +extern const mcu_pin_obj_t pin_P3_03; +extern const mcu_pin_obj_t pin_P3_04; +extern const mcu_pin_obj_t pin_P3_05; +extern const mcu_pin_obj_t pin_P3_06; +extern const mcu_pin_obj_t pin_P3_07; +extern const mcu_pin_obj_t pin_P3_08; +extern const mcu_pin_obj_t pin_P3_09; + +extern const mcu_pin_obj_t pin_P4_00; // BTLDR Stimulus +extern const mcu_pin_obj_t pin_P4_01; diff --git a/ports/analog/peripherals/pins.h b/ports/analog/peripherals/pins.h new file mode 100644 index 000000000000..ae471dc29e18 --- /dev/null +++ b/ports/analog/peripherals/pins.h @@ -0,0 +1,34 @@ + + +#pragma once + +// STD includes +#include +#include + +// CktPy includes +#include "py/obj.h" + +// HAL includes +// #include "gpio.h" + +typedef struct { + mp_obj_base_t base; + const uint8_t port; + const uint8_t pad; + // const uint8_t level : 4; // FIXME: Find how to include the VDDIO/VDDIOH level +} mcu_pin_obj_t; + +extern const mp_obj_type_t mcu_pin_type; + +#define NO_PIN (0xFF) // for non-connected pins + +#define PIN(pin_port, pin_pad) \ + { \ + { &mcu_pin_type }, \ + .port = pin_port, \ + .pad = pin_pad, \ + } + +// TODO: Create macros for detecting MCU VARIANT +#include "max32690/pins.h" diff --git a/ports/analog/qstrdefsport.h b/ports/analog/qstrdefsport.h new file mode 100644 index 000000000000..2d2c26092348 --- /dev/null +++ b/ports/analog/qstrdefsport.h @@ -0,0 +1,10 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Adafruit Industries LLC +// +// SPDX-License-Identifier: MIT + +// Do not use #pragma once in this file; it will cause a warning during qstr generation. + +// qstrs specific to this port +// *FORMAT-OFF* diff --git a/ports/analog/supervisor/cpu.s b/ports/analog/supervisor/cpu.s new file mode 100644 index 000000000000..9e6807a5e2e9 --- /dev/null +++ b/ports/analog/supervisor/cpu.s @@ -0,0 +1,27 @@ +.syntax unified +.cpu cortex-m4 +.thumb +.text +.align 2 + +@ uint cpu_get_regs_and_sp(r0=uint regs[10]) +.global cpu_get_regs_and_sp +.thumb +.thumb_func +.type cpu_get_regs_and_sp, %function +cpu_get_regs_and_sp: +@ store registers into given array +str r4, [r0], #4 +str r5, [r0], #4 +str r6, [r0], #4 +str r7, [r0], #4 +str r8, [r0], #4 +str r9, [r0], #4 +str r10, [r0], #4 +str r11, [r0], #4 +str r12, [r0], #4 +str r13, [r0], #4 + +@ return the sp +mov r0, sp +bx lr diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c new file mode 100644 index 000000000000..a8c10076d3bf --- /dev/null +++ b/ports/analog/supervisor/internal_flash.c @@ -0,0 +1,289 @@ + +#include "supervisor/internal_flash.h" + +#include +#include + +#include "extmod/vfs.h" +#include "extmod/vfs_fat.h" + +#include "py/obj.h" +#include "py/mphal.h" +#include "py/runtime.h" + +#include "supervisor/filesystem.h" +#include "supervisor/flash.h" +#include "supervisor/shared/safe_mode.h" + +#if CIRCUITPY_USB_DEVICE +#include "supervisor/usb.h" +#endif + +// MAX32 HAL Includes +#include "flc.h" +#include "flc_reva.h" +#include "icc.h" // includes icc_.c for MSDK die type +#include "mxc_device.h" + +/** TODO: + * - Verify all necessary Filesystem MACROs are defined in mpconfigport.h + * + * NOTE: + * ANY function which modifies flash contents must execute from a crit section. + * This is because FLC functions are loc'd in RAM, and any ISR executing + * from Flash will trigger a HardFault. + * + * An alternative would be to initialize with NVIC_SetRAM(), + * which makes ISRs execute from RAM. + * + * NOTE: + * Additionally, any code that modifies flash contents must disable the + * cache. Turn off ICC0 any time flash is to be modified. Remember to re-enable if using. + * + * For Maxim devices which include an additional RISC-V processor, this shall be ignored. + * Therefore only ICC0 need be used for the purpose of these functions. + */ + +#define NO_CACHE 0xffffffff +#define MAX_CACHE 0x4000 + +typedef struct { + uint32_t base_addr; + uint32_t sector_size; + uint32_t num_sectors; +} flash_layout_t; + +#ifdef MAX32690 +static const flash_layout_t flash_layout[] = { + { 0x1000000, 0x4000, 192}, + { 0x1030000, 0x2000, 32 }, +}; +static uint8_t _flash_cache[0x4000] __attribute__((aligned(4))); +#endif + +// Address of the flash sector currently being cached +static uint32_t _cache_addr_in_flash = NO_CACHE; + +static inline int32_t block2addr(uint32_t block) { + if (block > 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { + return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; + } + else return -1; +} + +int flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { + // This function should return -1 in the event of errors. + if (addr >= flash_layout[0].base_addr) { + uint32_t sector_index = 0; + if (MP_ARRAY_SIZE(flash_layout) == 1) { + sector_index = (addr - flash_layout[0].base_addr) / flash_layout[0].sector_size; + if (sector_index >= flash_layout[0].num_sectors) { + return -1; + } + if (start_addr) { + *start_addr = flash_layout[0].base_addr + (sector_index * flash_layout[0].sector_size); + } + if (size) { + *size = flash_layout[0].sector_size; + } + return sector_index; + } + + for (uint8_t i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) { + for (uint8_t j = 0; j < flash_layout[i].num_sectors; ++j) { + uint32_t sector_start_next = flash_layout[i].base_addr + + (j + 1) * flash_layout[i].sector_size; + if (addr < sector_start_next) { + if (start_addr) { + *start_addr = flash_layout[i].base_addr + + j * flash_layout[i].sector_size; + } + if (size) { + *size = flash_layout[i].sector_size; + } + return sector_index; + } + ++sector_index; + } + } + } + return -1; +} + +void supervisor_flash_init(void) { + // No initialization needed. + // Pay attention to the note at the top of this file! +} + +uint32_t supervisor_flash_get_block_size(void) { + return FILESYSTEM_BLOCK_SIZE; +} + +uint32_t supervisor_flash_get_block_count(void) { + return INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS; +} + +// Flush the flash page that is currently cached +void port_internal_flash_flush(void) { + // Flash has not been cached + if (_cache_addr_in_flash == NO_CACHE) { + return; + } + uint32_t sector_start, sector_size = 0xffffffff; + + // Clear & enable flash interrupt flags + MXC_FLC_EnableInt(MXC_F_FLC_INTR_DONEIE | MXC_F_FLC_INTR_AFIE); + + // Figure out the sector of flash we're targeting + if (flash_get_sector_info(_cache_addr_in_flash, §or_start, §or_size) == -1) { + // If not in valid sector, just release the cache and return + supervisor_flash_release_cache(); + return; + } + + // if invalid sector or sector size > the size of our cache, reset with flash fail + if (sector_size > sizeof(_flash_cache) || sector_start == 0xffffffff) { + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + // skip if the data in cache is the same as what's already there + if (memcmp(_flash_cache, (void *)_cache_addr_in_flash, FLASH_PAGE_SIZE) != 0) { + uint32_t error; + + // buffer for the page of flash + uint32_t page_buffer[FLASH_PAGE_SIZE >> 2] = { + 0xFFFFFFFF + }; // bytes per page / 4 bytes = # of uint32_t + + // Unlock Flash + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_UNLOCKED; + + /*** ERASE FLASH PAGE ***/ + MXC_CRITICAL( + // buffer the page + MXC_FLC_Read(sector_start, page_buffer, sector_size); + // Erase page & error check + error = MXC_FLC_PageErase(sector_start); + ); + if (error != E_NO_ERROR) { + // lock flash & reset + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + /*** RE-WRITE FLASH PAGE w/ CACHE DATA ***/ + MXC_CRITICAL( + // ret = program the flash page with cache data (for loop) + for (uint32_t i = 0; i < (sector_size >> 2); i++) { + error = MXC_FLC_Write32(_cache_addr_in_flash + 4 * i, _flash_cache[i]); + } + ); + if (error != E_NO_ERROR) { + // lock flash & reset + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + // Lock flash & exit + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + } + +} + +mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { + // Find the address of the block we want to read + int src_addr = block2addr(block); + if (src_addr == -1) { + // bad block num + return false; + } + + uint32_t sector_size, sector_start; + if (flash_get_sector_info(src_addr, §or_start, §or_size) == -1) { + // bad sector idx + return false; + } + + // Find how many blocks left in sector + uint32_t blocks_in_sector = (sector_size - (src_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; + + // If the whole read is inside the cache, then read cache + if (num_blocks <= blocks_in_sector && _cache_addr_in_flash == sector_start) { + memcpy(dest, (_flash_cache + (src_addr - sector_start)), FILESYSTEM_BLOCK_SIZE * num_blocks); + } else { + supervisor_flash_flush(); + /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking + * than memcpy does. Will use it for now. + */ + MXC_FLC_Read((int)dest, (int *)src_addr, FILESYSTEM_BLOCK_SIZE * num_blocks); + } + return 0; // success +} + +mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { + uint32_t count=0; + uint32_t sector_size=0; + uint32_t sector_start=0; + + while (num_blocks > 0) { + const int32_t dest_addr = block2addr(block_num); + // bad block number passed in + if (dest_addr == -1) { + return false; + } + + // Implementation is from STM port + // NOTE: May replace later, but this port had a method + // that seemed to make sense across multiple devices. + if (flash_get_sector_info(dest_addr, §or_start, §or_size) == -1) { + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + // fail if sector size is greater than cache size + if (sector_size > sizeof(_flash_cache)) { + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + // Find the number of blocks left within this sector + // BLOCK_NUM = (SECTOR SIZE - BLOCK OFFSET within sector)) / BLOCK_SIZE + count = (sector_size - (dest_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; + count = MIN(num_blocks, count); + + // if we're not at the start of a sector, copy the whole sector to cache + if (_cache_addr_in_flash != sector_start) { + // Flush cache first + supervisor_flash_flush(); + + _cache_addr_in_flash = sector_start; + + // Copy the whole sector into cache + memcpy(_flash_cache, (void *)sector_start, sector_size); + } + + // Overwrite the cache with source data passed in + memcpy(_flash_cache + (dest_addr - sector_start), src, count * FILESYSTEM_BLOCK_SIZE); + + block_num += count; + src += count * FILESYSTEM_BLOCK_SIZE; + num_blocks -= count; + } + return 0; // success +} + +void supervisor_flash_release_cache(void) { + // Flush the cache for ARM M4 + MXC_ICC_Flush(MXC_ICC0); + MXC_ICC_Flush(MXC_ICC1); + + // Clear the line fill buffer by reading 2 pages from flash + volatile uint32_t *line_addr; + volatile uint32_t line; + line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE); + line = *line_addr; + line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE + MXC_FLASH_PAGE_SIZE); + line = *line_addr; + (void)line; // Silence build warnings that this variable is not used. + + // Invalidate the current cache + _cache_addr_in_flash = NO_CACHE; +} diff --git a/ports/analog/supervisor/internal_flash.h b/ports/analog/supervisor/internal_flash.h new file mode 100644 index 000000000000..e59fd2af2408 --- /dev/null +++ b/ports/analog/supervisor/internal_flash.h @@ -0,0 +1,16 @@ + +#pragma once + +#include +#include + +#include "py/mpconfig.h" + +/** Sections defined in linker files under "linking" */ +#ifdef MAX32690 +#define MAX32_FLASH_SIZE 0x300000 // 3 MB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64K +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10032000 // Load into the last MB of code/data storage??? +#endif + +#define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c new file mode 100644 index 000000000000..cf63b3a261f4 --- /dev/null +++ b/ports/analog/supervisor/port.c @@ -0,0 +1,167 @@ +/****************************************************************************** + * + * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. All Rights Reserved. + * (now owned by Analog Devices, Inc.), + * Copyright (C) 2023 Analog Devices, Inc. All Rights Reserved. This software + * is proprietary to Analog Devices, Inc. and its licensors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/** + * @file port.c + * @author Brandon Hurst @ Analog Devices, Inc. + * @brief Functions required for a basic CircuitPython port + * @date 2024-07-30 + * + * @copyright Copyright (c) 2024 + */ + +#include +#include "supervisor/board.h" +#include "supervisor/port.h" + +#include +// #include "gpio.h" +#include "mxc_assert.h" +#include "mxc_delay.h" +#include "mxc_device.h" +#include "mxc_pins.h" +#include "mxc_sys.h" +#include "uart.h" + +/** Linker variables defined.... + * _estack: end of the stack + * _ebss: end of BSS section + * _ezero: same as ebss (acc. to main.c) + */ +extern uint32_t _ezero; +extern uint32_t _estack; +extern uint32_t _ebss; // Stored at the end of the bss section (which includes the heap). +extern uint32_t _ld_heap_start, _ld_heap_end, _ld_stack_top, _ld_stack_bottom; + +// defined by cmsis core files +void NVIC_SystemReset(void) NORETURN; + +safe_mode_t port_init(void) { + return SAFE_MODE_NONE; +} + +void HAL_Delay(uint32_t delay_ms) { +} + +uint32_t HAL_GetTick(void) { + return 1000; +} + +void SysTick_Handler(void) { +} + +void reset_to_bootloader(void) { + NVIC_SystemReset(); +} + + +void reset_cpu(void) { + NVIC_SystemReset(); +} + +void reset_port(void) { + // MXC_GPIO_Reset(MXC_GPIO0); + // MXC_GPIO_Reset(MXC_GPIO1); +} + +uint32_t *port_heap_get_bottom(void) { + return (uint32_t *)0xAAAAAAAA; +} + +uint32_t *port_heap_get_top(void) { + return (uint32_t *)0xAAAAAAAF; +} + +uint32_t *port_stack_get_limit(void) { + #pragma GCC diagnostic push + + #pragma GCC diagnostic ignored "-Warray-bounds" + // return port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t); + return port_stack_get_top() - (0 + 0) / sizeof(uint32_t); + #pragma GCC diagnostic pop +} + +uint32_t *port_stack_get_top(void) { + return (uint32_t *)0xB000000; +} + + +// Place the word to save just after our BSS section that gets blanked. +void port_set_saved_word(uint32_t value) { + _ebss = value; +} + +uint32_t port_get_saved_word(void) { + return _ebss; +} + +// __attribute__((used)) void MemManage_Handler(void) { +// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +// while (true) { +// asm ("nop;"); +// } +// } + +// __attribute__((used)) void BusFault_Handler(void) { +// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +// while (true) { +// asm ("nop;"); +// } +// } + +// __attribute__((used)) void UsageFault_Handler(void) { +// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +// while (true) { +// asm ("nop;"); +// } +// } + +// __attribute__((used)) void HardFault_Handler(void) { +// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +// while (true) { +// asm ("nop;"); +// } +// } + +uint64_t port_get_raw_ticks(uint8_t *subticks) { + return 1000; +} + +// Enable 1/1024 second tick. +void port_enable_tick(void) { +} + +// Disable 1/1024 second tick. +void port_disable_tick(void) { +} + +void port_interrupt_after_ticks(uint32_t ticks) { + // todo: implement isr after rtc ticks +} + +void port_idle_until_interrupt(void) { + __WFI(); +} + +// Required by __libc_init_array in startup code if we are compiling using +// -nostdlib/-nostartfiles. +void _init(void) { +} diff --git a/ports/analog/supervisor/serial.c b/ports/analog/supervisor/serial.c new file mode 100644 index 000000000000..7f485a35204c --- /dev/null +++ b/ports/analog/supervisor/serial.c @@ -0,0 +1,61 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "py/mphal.h" +#include +#include "supervisor/shared/serial.h" + +#define MAX32_SERIAL 0 + +#if MAX32_SERIAL +// TODO: Switch this to using DEBUG_UART. +#endif + +void port_serial_init(void) { + #if MAX32_SERIAL + // huart2.Instance = USART2; + // huart2.Init.BaudRate = 115200; + // huart2.Init.WordLength = UART_WORDLENGTH_8B; + // huart2.Init.StopBits = UART_STOPBITS_1; + // huart2.Init.Parity = UART_PARITY_NONE; + // huart2.Init.Mode = UART_MODE_TX_RX; + // huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; + // huart2.Init.OverSampling = UART_OVERSAMPLING_16; + // if (HAL_UART_Init(&huart2) == HAL_OK) { + // stm32f4_peripherals_status_led(1, 1); + // } + #endif +} + +bool port_serial_connected(void) { + return true; +} + +char port_serial_read(void) { + #if MAX32_SERIAL + // uint8_t data; + // HAL_UART_Receive(&huart2, &data, 1, 500); + // return data; + #else + return -1; + #endif +} + +// There is no easy way to find the number of pending characters, so just say there's 1. +uint32_t port_serial_bytes_available(void) { + #if MAX32_SERIAL + // return __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) ? 1 : 0; + #else + return 0; + #endif +} + +void port_serial_write_substring(const char *text, uint32_t len) { + #if MAX32_SERIAL + // HAL_UART_Transmit(&huart2, (uint8_t *)text, len, 5000); + #endif +} diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index cbae4b3ff5e0..778a90c31b63 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -46,6 +46,12 @@ def matching_submodules(s): # Submodules needed by port builds outside of their ports directory. # Should we try and detect these? PORT_DEPS = { + "analog": [ + "extmod/ulab/", + "/lib/tlsf/", + "lib/tinyusb/", + "lib/protomatter", + ], "atmel-samd": [ "extmod/ulab/", "lib/adafruit_floppy/", From 287c3324740fa2d99ed128a99c0fdca853dda765 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Thu, 15 Aug 2024 23:10:01 -0700 Subject: [PATCH 217/252] - Added 1/1024 s tick based on 4096 Hz RTC. - Added simple status LED for initial testing - Generally cleaned up & implemented supervisor/port.c - Added some additional commenting from supervisor headers - Fixed a linkerscript issue copying .text into FLASH_ISR --- ports/analog/Makefile | 7 +- ports/analog/background.c | 37 ++- ports/analog/boards/APARD/board.c | 20 +- ports/analog/linking/max32690_cktpy.ld | 19 +- ports/analog/mpconfigport.mk | 18 +- ports/analog/mphalport.c | 9 +- ports/analog/supervisor/internal_flash.h | 2 +- ports/analog/supervisor/max32_port.h | 31 +++ ports/analog/supervisor/port.c | 314 +++++++++++++++++------ 9 files changed, 351 insertions(+), 106 deletions(-) create mode 100644 ports/analog/supervisor/max32_port.h diff --git a/ports/analog/Makefile b/ports/analog/Makefile index b348a57d237f..b7ed00f0b691 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -75,10 +75,11 @@ INC += \ -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Include \ -I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \ -I$(PERIPH_SRC)/SYS \ - -I$(PERIPH_SRC)/GPIO \ -I$(PERIPH_SRC)/CTB \ - -I$(PERIPH_SRC)/ICC \ -I$(PERIPH_SRC)/FLC \ + -I$(PERIPH_SRC)/GPIO \ + -I$(PERIPH_SRC)/ICC \ + -I$(PERIPH_SRC)/RTC \ -I$(PERIPH_SRC)/UART \ INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC @@ -103,6 +104,8 @@ SRC_MAX32 += \ $(PERIPH_SRC)/GPIO/gpio_reva.c \ $(PERIPH_SRC)/ICC/icc_$(DIE_TYPE).c \ $(PERIPH_SRC)/ICC/icc_reva.c \ + $(PERIPH_SRC)/RTC/rtc_$(DIE_TYPE).c \ + $(PERIPH_SRC)/RTC/rtc_reva.c \ $(PERIPH_SRC)/UART/uart_common.c \ $(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \ $(PERIPH_SRC)/UART/uart_revb.c \ diff --git a/ports/analog/background.c b/ports/analog/background.c index ccf71bf77bf5..f08eb00a7123 100644 --- a/ports/analog/background.c +++ b/ports/analog/background.c @@ -9,20 +9,41 @@ #include "supervisor/usb.h" #include "supervisor/shared/stack.h" -//TODO: IMPLEMENT +#include "supervisor/max32_port.h" -void port_background_task(void) { - return; -} +/** NOTE: ALL "ticks" refer to a 1/1024 s period */ +static int status_led_ticks=0; + +extern mxc_gpio_cfg_t led_pin[]; +extern const unsigned int num_leds; +extern mxc_gpio_cfg_t pb_pin[]; +extern const unsigned int num_pbs; + +// This function is where port-specific background +// tasks should be performed +// Execute port specific actions during background tick. Only if ticks are enabled. void port_background_tick(void) { - return; + status_led_ticks++; + + // Set an LED approx. 1/s + if (status_led_ticks > 1024) + { + MXC_GPIO_OutToggle(led_pin[0].port, led_pin[0].mask); + status_led_ticks = 0; + } } -void port_start_background_tick(void) { - return; +// Execute port specific actions during background tasks. This is before the +// background callback system and happens *very* often. Use +// port_background_tick() when possible. +void port_background_task(void) { } +// Take port specific actions at the beginning and end of background ticks. +// This is used e.g., to set a monitoring pin for debug purposes. "Actual +// work" should be done in port_background_tick() instead. +void port_start_background_tick(void) { +} void port_finish_background_tick(void) { - return; } diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c index b44a1ae51e04..cd69f369579a 100644 --- a/ports/analog/boards/APARD/board.c +++ b/ports/analog/boards/APARD/board.c @@ -6,4 +6,22 @@ #include "supervisor/board.h" -// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. +// DEFAULT: Using the weak-defined supervisor/shared/board.c functions + +/***** OPTIONAL BOARD-SPECIFIC FUNTIONS from supervisor/board.h *****/ +// Returns true if the user initiates safe mode in a board specific way. +// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific +// way. +// bool board_requests_safe_mode(void); + +// Initializes board related state once on start up. +// void board_init(void); + +// Reset the state of off MCU components such as neopixels. +// void reset_board(void); + +// Deinit the board. This should put the board in deep sleep durable, low power +// state. It should not prevent the user access method from working (such as +// disabling USB, BLE or flash) because CircuitPython may continue to run. +// void board_deinit(void); +/*******************************************************************/ diff --git a/ports/analog/linking/max32690_cktpy.ld b/ports/analog/linking/max32690_cktpy.ld index 3ecc0b991f2f..423bfc321168 100644 --- a/ports/analog/linking/max32690_cktpy.ld +++ b/ports/analog/linking/max32690_cktpy.ld @@ -1,9 +1,9 @@ MEMORY { ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M - FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 200K - FLASH_FS (rw) : ORIGIN = 0x10032000, LENGTH = 64K - FLASH_FIRMWARE (rx) : ORIGIN = 0x10042000, LENGTH = 0x002BE000 + FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 16K + FLASH_FS (rw) : ORIGIN = 0x10004000, LENGTH = 64K + FLASH_FIRMWARE (rx) : ORIGIN = 0x10014000, LENGTH = 0x10030000 - 80K RAM (rwx): ORIGIN = 0x20000000, LENGTH = 1M } /* FLASH FIRMWARE: 0x10300000 (end) - 0x10042000 = 0x002BE000 */ @@ -21,14 +21,18 @@ SECTIONS { .isr_vector : { . = ALIGN(4); - KEEP(*(.isr_vector)) /* Startup code */ - EXCLUDE_FILE (*riscv.o) *(.text*) /* program code, exclude RISCV code */ + /* Startup code */ + KEEP(*(.isr_vector*)) } >FLASH_ISR .text : { . = ALIGN(4); _text = .; + + /* program code, exclude RISCV code */ + EXCLUDE_FILE (*riscv.o) *(.text*) + *(.rodata*) /* read-only data: "const" */ KEEP(*(.init)) @@ -142,17 +146,20 @@ SECTIONS { * size of stack_dummy section */ __StackTop = ORIGIN(RAM) + LENGTH(RAM); __StackLimit = __StackTop - SIZEOF(.stack_dummy); - __estack = __StackLimit; /* Provide _estack for CktPython */ + _estack = __StackLimit; /* Provide _estack for CktPython */ .heap (COPY): { . = ALIGN(4); + __heap = .; PROVIDE ( end = . ); PROVIDE ( _end = . ); *(.heap*) __HeapLimit = ABSOLUTE(__StackLimit); } > RAM + __eheap = __HeapLimit; + PROVIDE(__stack = __StackTop); /* Check if data + heap + stack exceeds RAM limit */ diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 3c68a62884fd..c4a6234f664e 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -11,6 +11,13 @@ USB_NUM_ENDPOINT_PAIRS ?= 0 LONGINT_IMPL ?= MPZ INTERNAL_LIBM ?= 1 +INTERNAL_FLASH_FILESYSTEM = 1 +SPI_FLASH_FILESYSTEM = 0 +QSPI_FLASH_FILESYSTEM = 0 + +# TODO: Review flash filesystem funcs before flashing +DISABLE_FILESYSTEM = 0 + #################################################################################### # Suggested config for first-time porting #################################################################################### @@ -31,6 +38,7 @@ CIRCUITPY_NVM = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOIO = 0 CIRCUITPY_ROTARYIO = 0 +#todo: implement time/date based on RTC sec/subsec CIRCUITPY_RTC = 0 CIRCUITPY_SDCARDIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 @@ -60,8 +68,9 @@ CIRCUITPY_USB_HID = 0 CIRCUITPY_USB_MIDI = 0 # Does nothing without I2C CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 + # No requirements, but takes extra flash -CIRCUITPY_ULAB = 0 +CIRCUITPY_ULAB = 1 #################################################################################### # Required for clean building (additional CircuittPython Defaults) #################################################################################### @@ -76,10 +85,3 @@ CIRCUITPY_BUSDEVICE = 0 # TinyUSB will be added later. CIRCUITPY_TINYUSB = 0 CIRCUITPY_PYUSB = 0 - -INTERNAL_FLASH_FILESYSTEM = 1 -SPI_FLASH_FILESYSTEM = 0 -QSPI_FLASH_FILESYSTEM = 0 - -# TODO: Review flash filesystem funcs before flashing -DISABLE_FILESYSTEM = 0 diff --git a/ports/analog/mphalport.c b/ports/analog/mphalport.c index 1bbcf605b007..d4e63ec67393 100644 --- a/ports/analog/mphalport.c +++ b/ports/analog/mphalport.c @@ -1,10 +1,15 @@ #include "mphalport.h" -#include "cmsis_gcc.h" +#include "py/mphal.h" +// includes __enable/__disable interrupts +#include "mxc_sys.h" -// TODO: Define tick & other port functions +#include "shared-bindings/microcontroller/__init__.h" +void mp_hal_delay_us(mp_uint_t delay) { + common_hal_mcu_delay_us(delay); +} void mp_hal_disable_all_interrupts(void) { __disable_irq(); diff --git a/ports/analog/supervisor/internal_flash.h b/ports/analog/supervisor/internal_flash.h index e59fd2af2408..ef944fbffed5 100644 --- a/ports/analog/supervisor/internal_flash.h +++ b/ports/analog/supervisor/internal_flash.h @@ -10,7 +10,7 @@ #ifdef MAX32690 #define MAX32_FLASH_SIZE 0x300000 // 3 MB #define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64K -#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10032000 // Load into the last MB of code/data storage??? +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10040000 // Load into the last MB of code/data storage??? #endif #define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) diff --git a/ports/analog/supervisor/max32_port.h b/ports/analog/supervisor/max32_port.h new file mode 100644 index 000000000000..25641a5dddbc --- /dev/null +++ b/ports/analog/supervisor/max32_port.h @@ -0,0 +1,31 @@ + +#ifndef MAX32_PORT_H +#define MAX32_PORT_H + +#include + +#include "mxc_sys.h" +#include "mxc_pins.h" +#include "gpio.h" +#include "mxc_assert.h" + +/** Linker variables defined.... + * _estack: end of the stack + * _ebss: end of BSS section + * _ezero: same as ebss (acc. to main.c) + */ +extern uint32_t _ezero; +extern uint32_t _estack; +extern uint32_t _ebss; // Stored at the end of the bss section (which includes the heap). +extern uint32_t __stack, __heap; + +extern uint32_t SystemCoreClock; + +// Tick timer should be 1/1024 s. RTC Oscillator is usually 32.768 kHz ERTCO. +#define TICKS_PER_SEC 1024 + +#ifdef MAX32690 +#define SUBSEC_PER_TICK 8 // 12-bit ssec register, ticks @ 4096 Hz +#endif + +#endif //MAX32_PORT_H diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index cf63b3a261f4..fd6bc1806aeb 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -29,139 +29,297 @@ */ #include +#include +#include "supervisor/background_callback.h" #include "supervisor/board.h" #include "supervisor/port.h" -#include -// #include "gpio.h" -#include "mxc_assert.h" +#include "common-hal/microcontroller/Pin.h" +#include "shared-bindings/microcontroller/__init__.h" + +//todo: pack the below definitions into their own module +//todo: under peripherals/gpio, peripherals/clocks, etc. + +// Sys includes +#include "max32_port.h" + +// Timers #include "mxc_delay.h" -#include "mxc_device.h" -#include "mxc_pins.h" -#include "mxc_sys.h" -#include "uart.h" - -/** Linker variables defined.... - * _estack: end of the stack - * _ebss: end of BSS section - * _ezero: same as ebss (acc. to main.c) - */ -extern uint32_t _ezero; -extern uint32_t _estack; -extern uint32_t _ebss; // Stored at the end of the bss section (which includes the heap). -extern uint32_t _ld_heap_start, _ld_heap_end, _ld_stack_top, _ld_stack_bottom; +#include "rtc.h" + +//todo: define an LED HAL +// #include "peripherals/led.h" + +#ifdef MAX32690 +// Board-level setup for MAX32690 +// clang-format off +const mxc_gpio_cfg_t pb_pin[] = { + { MXC_GPIO1, MXC_GPIO_PIN_27, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, +}; +const unsigned int num_pbs = (sizeof(pb_pin) / sizeof(mxc_gpio_cfg_t)); + +const mxc_gpio_cfg_t led_pin[] = { + { MXC_GPIO2, MXC_GPIO_PIN_1, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO0, MXC_GPIO_PIN_11, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO0, MXC_GPIO_PIN_12, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, +}; +const unsigned int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); +// clang-format on +#endif + +// For caching rtc data for ticks +static uint32_t subsec, sec = 0; // defined by cmsis core files -void NVIC_SystemReset(void) NORETURN; +extern void NVIC_SystemReset(void) NORETURN; safe_mode_t port_init(void) { - return SAFE_MODE_NONE; -} + int err = E_NO_ERROR; -void HAL_Delay(uint32_t delay_ms) { -} + // Enable GPIO (enables clocks + common init for ports) + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + err = MXC_GPIO_Init(0x1 << i); + if (err) { + return SAFE_MODE_PROGRAMMATIC; + } + } -uint32_t HAL_GetTick(void) { - return 1000; -} + // Init Board LEDs + /* setup GPIO for the LED */ + for (int i = 0; i < num_leds; i++) { + // Set the output value + MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); -void SysTick_Handler(void) { -} + if (MXC_GPIO_Config(&led_pin[i]) != E_NO_ERROR) { + return SAFE_MODE_PROGRAMMATIC; + } + } -void reset_to_bootloader(void) { - NVIC_SystemReset(); -} + // Turn on one LED to indicate Sign of Life + MXC_GPIO_OutSet(led_pin[0].port, led_pin[0].mask); + + // Init RTC w/ 0sec, 0subsec + // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s + err = MXC_RTC_Init(0, 0); + if (err) { + return SAFE_MODE_SDK_FATAL_ERROR; + } + NVIC_EnableIRQ(RTC_IRQn); + + // todo: init periph clocks / console here when ready + MXC_RTC_Start(); + return SAFE_MODE_NONE; +} +// Reset the MCU completely void reset_cpu(void) { + // includes MCU reset request + awaits on memory bus NVIC_SystemReset(); } +// Reset MCU state void reset_port(void) { - // MXC_GPIO_Reset(MXC_GPIO0); - // MXC_GPIO_Reset(MXC_GPIO1); -} + int err; + // Reset GPIO Ports + // Enable GPIO (enables clocks + common init for ports) + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + err = MXC_GPIO_Reset(0x1 << i); + if (err) { + // todo: indicate some gpio error + continue; + } + } -uint32_t *port_heap_get_bottom(void) { - return (uint32_t *)0xAAAAAAAA; + // TODO: Reset peripheral clocks + + // Reset 1/1024 tick timer + MXC_RTC_Stop(); + MXC_RTC_ClearFlags(0xFFFFFFFF); + MXC_RTC_Init(0,0); } -uint32_t *port_heap_get_top(void) { - return (uint32_t *)0xAAAAAAAF; +// Reset to the bootloader +// note: not implemented since max32 requires external stim ignals to +// activate bootloaders +// todo: check if there's a method to jump to it +void reset_to_bootloader(void) { + NVIC_SystemReset(); + while (true) { + asm ("nop;"); + } } +/** Acquire values of stack & heap starts & limits + * Return variables defined by linkerscript. + */ uint32_t *port_stack_get_limit(void) { + // ignore array bounds GCC warnings for stack here #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Warray-bounds" - // return port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t); - return port_stack_get_top() - (0 + 0) / sizeof(uint32_t); + + // NOTE: Only return how much stack we have alloted for CircuitPython + return (uint32_t *)(port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t)); + // return _estack; + + // end GCC diagnostic disable #pragma GCC diagnostic pop } - uint32_t *port_stack_get_top(void) { - return (uint32_t *)0xB000000; + return (uint32_t *)__stack; +} +uint32_t *port_heap_get_bottom(void) { + return (uint32_t *)__heap; +} +uint32_t *port_heap_get_top(void) { + return port_stack_get_limit(); } - -// Place the word to save just after our BSS section that gets blanked. +/** Save & retrieve a word from memory over a reset cycle. + * Used for safe mode + */ void port_set_saved_word(uint32_t value) { _ebss = value; } - uint32_t port_get_saved_word(void) { return _ebss; } -// __attribute__((used)) void MemManage_Handler(void) { -// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); -// while (true) { -// asm ("nop;"); -// } -// } - -// __attribute__((used)) void BusFault_Handler(void) { -// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); -// while (true) { -// asm ("nop;"); -// } -// } - -// __attribute__((used)) void UsageFault_Handler(void) { -// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); -// while (true) { -// asm ("nop;"); -// } -// } - -// __attribute__((used)) void HardFault_Handler(void) { -// reset_into_safe_mode(SAFE_MODE_HARD_FAULT); -// while (true) { -// asm ("nop;"); -// } -// } - +// Raw monotonic tick count since startup. +// NOTE (rollover): +// seconds reg is 32 bits, can hold up to 2^32-1 +// theref. rolls over after ~136 years uint64_t port_get_raw_ticks(uint8_t *subticks) { - return 1000; + // Ensure we can read from ssec register as soon as we can + // MXC function does cross-tick / busy checking of RTC controller + __disable_irq(); + MXC_RTC_GetTime(&sec, &subsec); + __enable_irq(); + + // Return ticks given total subseconds + // ticks = TICKS/s * s + subsec/ subs/tick + uint64_t raw_ticks = ((uint64_t)TICKS_PER_SEC) * sec + (subsec / SUBSEC_PER_TICK); + + if (subticks) { + // subticks may only be filled to a resn of 1/4096 in some cases + // e.g. multiply by 32 / 8 = 4 to get true 1/32768 subticks + *subticks = (32 / (SUBSEC_PER_TICK)) * (subsec - (subsec / SUBSEC_PER_TICK)); + } + + return raw_ticks; } // Enable 1/1024 second tick. void port_enable_tick(void) { + MXC_RTC_Start(); } // Disable 1/1024 second tick. void port_disable_tick(void) { + MXC_RTC_Stop(); } +// Wake the CPU after a given # of ticks or sooner void port_interrupt_after_ticks(uint32_t ticks) { - // todo: implement isr after rtc ticks + // Stop RTC & store current time & ticks + port_disable_tick(); + port_get_raw_ticks(NULL); + + uint32_t target_sec = (ticks / TICKS_PER_SEC); + uint32_t target_ssec = (ticks - (target_sec * TICKS_PER_SEC)) * SUBSEC_PER_TICK; + + // Set up alarm configuration + // if alarm is greater than 1 s, + // use the ToD alarm --> resol. to closest second + // else + // use Ssec alarm --> resn. to 1/1024 s. (down to a full tick) + if (target_sec > 0) { + if (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | + MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { + // todo: signal some RTC error! + } + + if (MXC_RTC_SetTimeofdayAlarm(target_sec) != E_NO_ERROR) { + // todo: signal some RTC error! + } + if (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { + // todo: signal some RTC error! + } + } + else { + if (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | + MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { + // todo: signal some RTC error! + } + + if (MXC_RTC_SetSubsecondAlarm(target_ssec) != E_NO_ERROR) { + // todo: signal some RTC error! + } + + if (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) { + // todo: signal some RTC error! + } + } + port_enable_tick(); +} + +void RTC_IRQHandler(void) { + // Read flags to clear + int flags = MXC_RTC_GetFlags(); + + if (flags & MXC_F_RTC_CTRL_TOD_ALARM) { + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); + while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {} + } + + if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) { + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); + while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {} + } } void port_idle_until_interrupt(void) { - __WFI(); + // Check if alarm triggers before we even got here + if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { + return; + } + + common_hal_mcu_disable_interrupts(); + if (!background_callback_pending()) { + __WFI(); + } + common_hal_mcu_enable_interrupts(); +} + +__attribute__((used)) void MemManage_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} + +__attribute__((used)) void BusFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} + +__attribute__((used)) void UsageFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} + +__attribute__((used)) void HardFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } } -// Required by __libc_init_array in startup code if we are compiling using -// -nostdlib/-nostartfiles. +// Required by libc _init_array loops in startup code +// if we are compiling using "-nostdlib/-nostartfiles" void _init(void) { } From 50bac077f2ff763a404dc2e8781a96fc51ff8656 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 20 Aug 2024 13:23:36 -0700 Subject: [PATCH 218/252] - (build): Added tinyUSB src/inc, DMA & RTC from MSDK. - (build): added hex & bin targets for executable. - (build): temporarily modified .ld due to issue exiting MAX32 ROM code - (flash): added flash target for jlink & msdk, along with helper files under tools/ - Reorganized mpconfigport.mk for clarity - Moved flash driver & LED/PB definitions to board files (mpconfigboard._) --- ports/analog/Makefile | 58 ++++++++++++------ ports/analog/README.md | 4 +- ports/analog/background.c | 16 ++--- ports/analog/boards/APARD/mpconfigboard.h | 10 +++- ports/analog/linking/max32690_cktpy.ld | 55 ++++++++++------- ports/analog/mpconfigport.h | 5 +- ports/analog/mpconfigport.mk | 72 ++++++++++++----------- ports/analog/mphalport.h | 3 +- ports/analog/supervisor/internal_flash.c | 49 ++++++++++----- ports/analog/supervisor/internal_flash.h | 7 --- ports/analog/tools/connect-gdb.txt | 16 +++++ ports/analog/tools/flash-halt-openocd.bat | 5 ++ ports/analog/tools/flash_max32.jlink | 6 ++ 13 files changed, 191 insertions(+), 115 deletions(-) create mode 100644 ports/analog/tools/connect-gdb.txt create mode 100644 ports/analog/tools/flash-halt-openocd.bat create mode 100644 ports/analog/tools/flash_max32.jlink diff --git a/ports/analog/Makefile b/ports/analog/Makefile index b7ed00f0b691..151299a8792a 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -76,9 +76,11 @@ INC += \ -I$(ADI_PERIPH)/Include/$(MCU_VARIANT_UPPER) \ -I$(PERIPH_SRC)/SYS \ -I$(PERIPH_SRC)/CTB \ + -I$(PERIPH_SRC)/DMA \ -I$(PERIPH_SRC)/FLC \ -I$(PERIPH_SRC)/GPIO \ -I$(PERIPH_SRC)/ICC \ + -I$(PERIPH_SRC)/TMR \ -I$(PERIPH_SRC)/RTC \ -I$(PERIPH_SRC)/UART \ @@ -96,6 +98,9 @@ SRC_MAX32 += \ $(PERIPH_SRC)/CTB/ctb_$(DIE_TYPE).c \ $(PERIPH_SRC)/CTB/ctb_reva.c \ $(PERIPH_SRC)/CTB/ctb_common.c \ + $(PERIPH_SRC)/DMA/dma_reva.c \ + $(PERIPH_SRC)/DMA/dma_revb.c \ + $(PERIPH_SRC)/DMA/dma_$(DIE_TYPE).c \ $(PERIPH_SRC)/FLC/flc_common.c \ $(PERIPH_SRC)/FLC/flc_$(DIE_TYPE).c \ $(PERIPH_SRC)/FLC/flc_reva.c \ @@ -106,6 +111,9 @@ SRC_MAX32 += \ $(PERIPH_SRC)/ICC/icc_reva.c \ $(PERIPH_SRC)/RTC/rtc_$(DIE_TYPE).c \ $(PERIPH_SRC)/RTC/rtc_reva.c \ + $(PERIPH_SRC)/TMR/tmr_common.c \ + $(PERIPH_SRC)/TMR/tmr_revb.c \ + $(PERIPH_SRC)/TMR/tmr_$(DIE_TYPE).c \ $(PERIPH_SRC)/UART/uart_common.c \ $(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \ $(PERIPH_SRC)/UART/uart_revb.c \ @@ -126,7 +134,7 @@ STARTUPFILE = $(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC/startup # CircuitPython custom linkerfile (necessary for build steps & filesystems) LINKERFILE = linking/$(MCU_VARIANT_LOWER)_cktpy.ld -LDFLAGS += -nostartfiles -specs=nosys.specs -specs=nano.specs +LDFLAGS += -nostartfiles -specs=nano.specs endif SRC_S += supervisor/cpu.s \ @@ -137,13 +145,14 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET_REV=0x4131 \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ + -DRISCV_LOAD=0 \ # -DFLASH_ORIGIN=0x10000000 \ # -DFLASH_SIZE=0x340000 \ # -DSRAM_ORIGIN=0x20000000 \ # -DSRAM_SIZE=0x100000 \ CPU_CORE=cortex-m4 -CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=hard -mfpu=fpv4-sp-d16 +CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=softfp -mfpu=fpv4-sp-d16 # NOTE: Start with DEBUG ONLY settings for now ifeq ($(DEBUG),) @@ -154,7 +163,7 @@ ifeq ($(DEBUG),1) CFLAGS += -ggdb3 COPT = -Og else -COPT += -O2 +COPT += -O0 #opt completely off to start endif @@ -165,9 +174,9 @@ CFLAGS += \ # TODO: Add for TinyUSB once our PR goes through for MAX32 devices # Add TinyUSB -# INC += -I../../lib/tinyusb/src -# INC += -I../../supervisor/shared/usb -# SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c +INC += -I../../lib/tinyusb/src +INC += -I../../supervisor/shared/usb +SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c SRC_C += \ boards/$(BOARD)/board.c \ @@ -182,13 +191,14 @@ CFLAGS += -Wno-error=unused-parameter \ -Wno-error=sign-compare \ -Wno-error=strict-prototypes \ -Wno-error=cast-qual \ - -Wno-unused-variable \ - -Wno-lto-type-mismatch \ - -Wno-cast-align \ - -Wno-nested-externs \ - -Wno-sign-compare + -Wno-error=unused-variable \ + -Wno-error=lto-type-mismatch \ + -Wno-error=cast-align \ + -Wno-error=nested-externs \ + -Wno-error=sign-compare \ -LDFLAGS += $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections +ENTRY = Reset_Handler +LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections LIBS := -lgcc -lc # If not using CKTPY mathlib, use toolchain mathlib @@ -234,7 +244,7 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_CIRCUITPY_COMMON) \ SRC_QSTR_PREPROCESSOR += # Default build target -all: $(BUILD)/firmware.elf +all: $(BUILD)/firmware.elf $(BUILD)/firmware.hex $(BUILD)/firmware.bin clean-max32: rm -rf build-* @@ -247,18 +257,32 @@ MAXIM_PATH := $(subst \,/,$(MAXIM_PATH)) flash-msdk: $(MAXIM_PATH)/Tools/OpenOCD/openocd -s $(MAXIM_PATH)/Tools/OpenOCD/scripts \ -f interface/cmsis-dap.cfg -f target/$(MCU_VARIANT_LOWER).cfg \ - -c "program $(BUILD)/$(PROJECT).elf verify; init; reset; exit" + -c "program $(BUILD)/firmware.elf verify; init; reset; exit" # flash target using JLink JLINK_DEVICE = $(MCU_VARIANT_LOWER) -flash: flash-jlink -$(BUILD)/firmware.elf: $(OBJ) $(LINKERFILE) +JLINKEXE ?= JLink.exe +JLINKEXE += -if SWD -device ${JLINK_DEVICE} -speed 10000 +COMMAND_FILE := tools/flash_max32.jlink + +flash-jlink: $(BUILD)/firmware.bin + @$(JLINKEXE) -device $(MCU_VARIANT_UPPER) -NoGui 1 -CommandFile ${COMMAND_FILE} + +$(BUILD)/firmware.elf: $(OBJ) $(STEPECHO) "LINK $@" - $(Q)echo $(OBJ) > $(BUILD)/firmware.objs + $(Q)echo $^ > $(BUILD)/firmware.objs $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--print-memory-usage -Wl,--start-group $(LIBS) -Wl,--end-group $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINKERFILE) $(BUILD) +$(BUILD)/firmware.hex: $(BUILD)/firmware.elf + $(STEPECHO) "Create $@" + $(Q)$(OBJCOPY) -O ihex $^ $@ + +$(BUILD)/firmware.bin: $(BUILD)/firmware.elf + $(STEPECHO) "Create $@" + $(Q)$(OBJCOPY) -O binary $^ $@ + # ******************************************************************************* ### CKTPY BUILD RULES ### include $(TOP)/py/mkrules.mk diff --git a/ports/analog/README.md b/ports/analog/README.md index 0e5d3f7d2951..603a22f9fd4b 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -45,8 +45,6 @@ This requires the following: - The PICO board is connected to the target board via a 10-pin SWD ribbon cable. - If SWD connectors are not keyed, the P1 indicator (red line) on the SWD ribbon cable should match the P1 indicator on the board silkscreen near the 10-pin SWD connector. -[**Section in Progress.**] - ### Using the REPL -[**Section in Progress. Review & Testing are needed.**] +[**Section in Progress. USB support needs implementation & test.**] diff --git a/ports/analog/background.c b/ports/analog/background.c index f08eb00a7123..8dad8c4e351d 100644 --- a/ports/analog/background.c +++ b/ports/analog/background.c @@ -9,17 +9,17 @@ #include "supervisor/usb.h" #include "supervisor/shared/stack.h" -#include "supervisor/max32_port.h" +#include "max32_port.h" + +// From boards/$(BOARD)/board.c +extern const mxc_gpio_cfg_t pb_pin[]; +extern const int num_pbs; +extern const mxc_gpio_cfg_t led_pin[]; +extern const int num_leds; /** NOTE: ALL "ticks" refer to a 1/1024 s period */ static int status_led_ticks=0; -extern mxc_gpio_cfg_t led_pin[]; -extern const unsigned int num_leds; - -extern mxc_gpio_cfg_t pb_pin[]; -extern const unsigned int num_pbs; - // This function is where port-specific background // tasks should be performed // Execute port specific actions during background tick. Only if ticks are enabled. @@ -29,7 +29,7 @@ void port_background_tick(void) { // Set an LED approx. 1/s if (status_led_ticks > 1024) { - MXC_GPIO_OutToggle(led_pin[0].port, led_pin[0].mask); + MXC_GPIO_OutToggle(led_pin[2].port, led_pin[2].mask); status_led_ticks = 0; } } diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/APARD/mpconfigboard.h index b22c7ab9ecc6..87baa0120994 100644 --- a/ports/analog/boards/APARD/mpconfigboard.h +++ b/ports/analog/boards/APARD/mpconfigboard.h @@ -22,10 +22,16 @@ #define BOARD_HAS_CRYSTAL 1 -// todo: figure out a way to smartly set this up based on storage considerations +#define NUM_GPIO_PORTS 4 + #if INTERNAL_FLASH_FILESYSTEM -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x10032000) // for MAX32690 +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102FC000) // for MAX32690 #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64 * 1024) // 64K + +#define MAX32_FLASH_SIZE 0x300000 // 3 MiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64KiB +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102FC000 // Load into the last MiB of code/data storage + #else #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) #endif diff --git a/ports/analog/linking/max32690_cktpy.ld b/ports/analog/linking/max32690_cktpy.ld index 423bfc321168..e80a14d53c90 100644 --- a/ports/analog/linking/max32690_cktpy.ld +++ b/ports/analog/linking/max32690_cktpy.ld @@ -1,38 +1,51 @@ MEMORY { ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M - FLASH_ISR (rx) : ORIGIN = 0x10000000, LENGTH = 16K - FLASH_FS (rw) : ORIGIN = 0x10004000, LENGTH = 64K - FLASH_FIRMWARE (rx) : ORIGIN = 0x10014000, LENGTH = 0x10030000 - 80K - RAM (rwx): ORIGIN = 0x20000000, LENGTH = 1M + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 2992K + FLASH_ISR (rx) : ORIGIN = 0x102EC000, LENGTH = 16K + FLASH_FS (rx) : ORIGIN = 0x102FC000, LENGTH = 64K + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 1M } -/* FLASH FIRMWARE: 0x10300000 (end) - 0x10042000 = 0x002BE000 */ - -ENTRY(Reset_Handler) +/* Minimum flash page is 16K */ +/* FLASH FIRMWARE: 3072K [3MB] - 16K - 64K = 2992K */ SECTIONS { .rom : { - KEEP(*(.rom_vector)) - *(.rom_handlers*) + KEEP(*(.rom_vector*)) + KEEP(*(.rom_handlers*)) } > ROM + + /** FIXME: can't place this in its own section for some reason + * system doesn't exit ROM code unless *(.isr_vector) + * is placed in the beginning of .text, + * even if .text is moved upward and *(.isr_vector) is + * placed at 0x10000000. + **/ + /* Place ISR vector in a separate flash section */ - .isr_vector : - { - . = ALIGN(4); - /* Startup code */ - KEEP(*(.isr_vector*)) - } >FLASH_ISR + /* .isr_vector : */ + /* { */ + /* ISR Vector beginning of .text */ + /* KEEP(*(.isr_vector)) */ + /* KEEP(*(.isr_vector*)) */ + /* } > FLASH_ISR */ .text : { . = ALIGN(4); _text = .; - /* program code, exclude RISCV code */ - EXCLUDE_FILE (*riscv.o) *(.text*) + /* ISR Vector beginning of .text */ + /** fixme: may want to move this to FLASH_ISR long-term */ + KEEP(*(.isr_vector)) + KEEP(*(.isr_vector*)) + + . = ALIGN(4); + /* program code; exclude RISCV code */ + EXCLUDE_FILE (*riscv.o) *(.text*) *(.rodata*) /* read-only data: "const" */ KEEP(*(.init)) @@ -146,21 +159,21 @@ SECTIONS { * size of stack_dummy section */ __StackTop = ORIGIN(RAM) + LENGTH(RAM); __StackLimit = __StackTop - SIZEOF(.stack_dummy); + + _stack = __StackTop; _estack = __StackLimit; /* Provide _estack for CktPython */ .heap (COPY): { . = ALIGN(4); - __heap = .; + _heap = .; PROVIDE ( end = . ); PROVIDE ( _end = . ); *(.heap*) __HeapLimit = ABSOLUTE(__StackLimit); } > RAM - __eheap = __HeapLimit; - - PROVIDE(__stack = __StackTop); + _eheap = __HeapLimit; /* Check if data + heap + stack exceeds RAM limit */ ASSERT(__StackLimit >= _ebss, "region RAM overflowed with stack") diff --git a/ports/analog/mpconfigport.h b/ports/analog/mpconfigport.h index bb9f8b6ac368..cadfbddbc55b 100644 --- a/ports/analog/mpconfigport.h +++ b/ports/analog/mpconfigport.h @@ -12,11 +12,8 @@ #define MICROPY_PY_FUNCTION_ATTRS (1) #define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) - -// 24kiB stack +// 24KiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 -// uint8_t _ld_default_stack_size; -// #define CIRCUITPY_DEFAULT_STACK_SIZE ((uint32_t)&_ld_default_stack_size) // Also includes mpconfigboard.h #include "py/circuitpy_mpconfig.h" diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index c4a6234f664e..b67622935183 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -15,7 +15,7 @@ INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 -# TODO: Review flash filesystem funcs before flashing +# TODO: TEST filesystem & general bringup! DISABLE_FILESYSTEM = 0 #################################################################################### @@ -24,60 +24,62 @@ DISABLE_FILESYSTEM = 0 # These modules are implemented in ports//common-hal: # Typically the first module to create -CIRCUITPY_MICROCONTROLLER = 1 +CIRCUITPY_MICROCONTROLLER ?= 1 # Typically the second module to create -CIRCUITPY_DIGITALIO = 0 -# Other modules: -CIRCUITPY_ANALOGIO = 0 -CIRCUITPY_BUSIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_NEOPIXEL_WRITE = 0 -CIRCUITPY_PULSEIO = 0 -CIRCUITPY_OS = 1 -CIRCUITPY_NVM = 0 -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_AUDIOIO = 0 -CIRCUITPY_ROTARYIO = 0 -#todo: implement time/date based on RTC sec/subsec -CIRCUITPY_RTC = 0 -CIRCUITPY_SDCARDIO = 0 -CIRCUITPY_FRAMEBUFFERIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CTARGET = 0 +CIRCUITPY_DIGITALIO ?= 0 + +# Plan to implement +CIRCUITPY_BUSIO ?= 0 +CIRCUITPY_OS ?= 1 +CIRCUITPY_RTC ?= 0 + +# Other modules (may or may not implement): +CIRCUITPY_ANALOGIO ?= 0 +CIRCUITPY_AUDIOBUSIO ?= 0 +CIRCUITPY_AUDIOIO ?= 0 +CIRCUITPY_COUNTIO ?= 0 +CIRCUITPY_NEOPIXEL_WRITE ?= 0 +CIRCUITPY_FREQUENCYIO ?= 0 +CIRCUITPY_I2CTARGET ?= 0 +CIRCUITPY_PULSEIO ?= 0 +CIRCUITPY_PWMIO ?= 0 +CIRCUITPY_NVM ?= 0 +CIRCUITPY_ROTARYIO ?= 0 +CIRCUITPY_SDCARDIO ?= 0 +CIRCUITPY_FRAMEBUFFERIO ?= 0 # Requires SPI, PulseIO (stub ok): -CIRCUITPY_DISPLAYIO = 0 +CIRCUITPY_DISPLAYIO ?= 0 # These modules are implemented in shared-module/ - they can be included in # any port once their prerequisites in common-hal are complete. # Requires DigitalIO: -CIRCUITPY_BITBANGIO = 0 +CIRCUITPY_BITBANGIO ?= 0 # Requires neopixel_write or SPI (dotstar) -CIRCUITPY_PIXELBUF = 0 +CIRCUITPY_PIXELBUF ?= 0 # Requires OS -CIRCUITPY_RANDOM = 0 +CIRCUITPY_RANDOM ?= 0 # Requires OS, filesystem -CIRCUITPY_STORAGE = 0 +CIRCUITPY_STORAGE ?= 0 # Requires Microcontroller -CIRCUITPY_TOUCHIO = 0 -# Requires UART! -CIRCUITPY_CONSOLE_UART = 0 +CIRCUITPY_TOUCHIO ?= 0 +# Requires UART +CIRCUITPY_CONSOLE_UART ?= 0 # Requires USB -CIRCUITPY_USB_DEVICE = 0 -CIRCUITPY_USB_CDC = 0 -CIRCUITPY_USB_HID = 0 -CIRCUITPY_USB_MIDI = 0 +CIRCUITPY_USB_DEVICE ?= 0 +CIRCUITPY_USB_CDC ?= 0 +CIRCUITPY_USB_HID ?= 0 +CIRCUITPY_USB_MIDI ?= 0 # Does nothing without I2C CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 # No requirements, but takes extra flash CIRCUITPY_ULAB = 1 + #################################################################################### # Required for clean building (additional CircuittPython Defaults) #################################################################################### -# Enabled by default -CIRCUITPY_PWMIO = 0 + # Depends on BUSIO -# CIRCUITPY_BLEIO = 0 CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_BUSDEVICE = 0 diff --git a/ports/analog/mphalport.h b/ports/analog/mphalport.h index 8dba63d82ff0..5efd78736e78 100644 --- a/ports/analog/mphalport.h +++ b/ports/analog/mphalport.h @@ -10,8 +10,7 @@ #include "lib/oofatfs/ff.h" #include "supervisor/shared/tick.h" -// TODO: Define tick & other port functions -// Global millisecond tick count (driven by SysTick interrupt). +// Global millisecond tick count static inline mp_uint_t mp_hal_ticks_ms(void) { return supervisor_ticks_ms32(); } diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c index a8c10076d3bf..97fe21d4a52c 100644 --- a/ports/analog/supervisor/internal_flash.c +++ b/ports/analog/supervisor/internal_flash.c @@ -26,11 +26,11 @@ #include "mxc_device.h" /** TODO: - * - Verify all necessary Filesystem MACROs are defined in mpconfigport.h + * Test! * * NOTE: * ANY function which modifies flash contents must execute from a crit section. - * This is because FLC functions are loc'd in RAM, and any ISR executing + * This is because FLC functions are loc'd in RAM, and an ISR executing * from Flash will trigger a HardFault. * * An alternative would be to initialize with NVIC_SetRAM(), @@ -54,10 +54,14 @@ typedef struct { } flash_layout_t; #ifdef MAX32690 +// struct layout is the actual layout of flash +// FS Code will use INTERNAL_FLASH_FILESYSTEM_START_ADDR +// and won't conflict with ISR vector in first 16 KiB of flash static const flash_layout_t flash_layout[] = { - { 0x1000000, 0x4000, 192}, - { 0x1030000, 0x2000, 32 }, + { 0x10000000, 0x4000, 192}, + // { 0x10300000, 0x2000, 32 }, // RISC-V flash }; +// Cache a full 16K sector static uint8_t _flash_cache[0x4000] __attribute__((aligned(4))); #endif @@ -65,12 +69,13 @@ static uint8_t _flash_cache[0x4000] __attribute__((aligned(4))); static uint32_t _cache_addr_in_flash = NO_CACHE; static inline int32_t block2addr(uint32_t block) { - if (block > 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { + if (block >= 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; } else return -1; } +// Get index, start addr, & size of the flash sector where addr lies int flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { // This function should return -1 in the event of errors. if (addr >= flash_layout[0].base_addr) { @@ -78,17 +83,24 @@ int flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { if (MP_ARRAY_SIZE(flash_layout) == 1) { sector_index = (addr - flash_layout[0].base_addr) / flash_layout[0].sector_size; if (sector_index >= flash_layout[0].num_sectors) { - return -1; + return -1; // addr is not in flash } if (start_addr) { *start_addr = flash_layout[0].base_addr + (sector_index * flash_layout[0].sector_size); } + else { + return -1; // start_addr is NULL + } if (size) { *size = flash_layout[0].sector_size; } + else { + return -1; //size is NULL + } return sector_index; } + // algorithm for multiple flash sections for (uint8_t i = 0; i < MP_ARRAY_SIZE(flash_layout); ++i) { for (uint8_t j = 0; j < flash_layout[i].num_sectors; ++j) { uint32_t sector_start_next = flash_layout[i].base_addr @@ -123,7 +135,7 @@ uint32_t supervisor_flash_get_block_count(void) { return INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS; } -// Flush the flash page that is currently cached +// Write back to Flash the page that is currently cached void port_internal_flash_flush(void) { // Flash has not been cached if (_cache_addr_in_flash == NO_CACHE) { @@ -186,10 +198,11 @@ void port_internal_flash_flush(void) { // Lock flash & exit MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; - } - + } // finished flushing cache + // todo: verify no other flash operation (e.g. flushing HW cache) is needed to complete this } +// Read flash blocks, using cache if it contains the right data mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { // Find the address of the block we want to read int src_addr = block2addr(block); @@ -208,9 +221,10 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n uint32_t blocks_in_sector = (sector_size - (src_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; // If the whole read is inside the cache, then read cache - if (num_blocks <= blocks_in_sector && _cache_addr_in_flash == sector_start) { + if ( (num_blocks <= blocks_in_sector) && (_cache_addr_in_flash == sector_start) ) { memcpy(dest, (_flash_cache + (src_addr - sector_start)), FILESYSTEM_BLOCK_SIZE * num_blocks); } else { + // flush the cache & read the flash data directly supervisor_flash_flush(); /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking * than memcpy does. Will use it for now. @@ -220,6 +234,9 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n return 0; // success } +// Write to flash blocks, using cache if it is targeting the right page (and large enough) +// todo: most of this fn is taken from the ST driver. +// todo: look at other ports and see if I can adapt it at all mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { uint32_t count=0; uint32_t sector_size=0; @@ -251,7 +268,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, // if we're not at the start of a sector, copy the whole sector to cache if (_cache_addr_in_flash != sector_start) { - // Flush cache first + // Flush cache first before we overwrite it supervisor_flash_flush(); _cache_addr_in_flash = sector_start; @@ -270,10 +287,13 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, return 0; // success } +// Empty the fs cache void supervisor_flash_release_cache(void) { - // Flush the cache for ARM M4 + // Invalidate the current FS cache + _cache_addr_in_flash = NO_CACHE; + + // Flush the hardware cache for ARM M4 MXC_ICC_Flush(MXC_ICC0); - MXC_ICC_Flush(MXC_ICC1); // Clear the line fill buffer by reading 2 pages from flash volatile uint32_t *line_addr; @@ -283,7 +303,4 @@ void supervisor_flash_release_cache(void) { line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE + MXC_FLASH_PAGE_SIZE); line = *line_addr; (void)line; // Silence build warnings that this variable is not used. - - // Invalidate the current cache - _cache_addr_in_flash = NO_CACHE; } diff --git a/ports/analog/supervisor/internal_flash.h b/ports/analog/supervisor/internal_flash.h index ef944fbffed5..1b4091e9a4fd 100644 --- a/ports/analog/supervisor/internal_flash.h +++ b/ports/analog/supervisor/internal_flash.h @@ -6,11 +6,4 @@ #include "py/mpconfig.h" -/** Sections defined in linker files under "linking" */ -#ifdef MAX32690 -#define MAX32_FLASH_SIZE 0x300000 // 3 MB -#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64K -#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x10040000 // Load into the last MB of code/data storage??? -#endif - #define INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS (INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE) diff --git a/ports/analog/tools/connect-gdb.txt b/ports/analog/tools/connect-gdb.txt new file mode 100644 index 000000000000..ced4bdf6af3a --- /dev/null +++ b/ports/analog/tools/connect-gdb.txt @@ -0,0 +1,16 @@ +For connecting GDB... + +// Set symbol & exec to .elf +arm-none-eabi-gdb --se=build-APARD/firmware.elf + +// connect to remote on local machine TCP port :3333 +target extended-remote localhost:3333 + +// reset halt the MCU +monitor reset halt + +// set a breakpoint on main & hit it +b main +continue + +// now...time to mess around! diff --git a/ports/analog/tools/flash-halt-openocd.bat b/ports/analog/tools/flash-halt-openocd.bat new file mode 100644 index 000000000000..ae30cdff0b97 --- /dev/null +++ b/ports/analog/tools/flash-halt-openocd.bat @@ -0,0 +1,5 @@ +:: Flash the target MCU via OpenOCD, +:: then reset halt to prepare for gdb connection +:: waits for gdb connection on localhost port 3333; see connect-gdb.txt for more info +:: leave this process open if you're connecting gdb +openocd -s $MAXIM_PATH/Tools/OpenOCD/scripts -f interface/cmsis-dap.cfg -f target/max32690.cfg -c "program build-APARD/firmware.elf verify; init; reset halt" diff --git a/ports/analog/tools/flash_max32.jlink b/ports/analog/tools/flash_max32.jlink new file mode 100644 index 000000000000..4c9cbacb96fe --- /dev/null +++ b/ports/analog/tools/flash_max32.jlink @@ -0,0 +1,6 @@ +si 1 +erase +loadbin build-APARD/firmware.bin 0x10000000 +r +g +exit From 63ef3ab096d20ac63d8e5b74a2089ef621517b6c Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 20 Aug 2024 13:32:18 -0700 Subject: [PATCH 219/252] - Fixed stack & heap variables from linkerscript causing HardFaults. Placed in supervisor/port.c - Moved LEDs & PBs from supervisor/port.c to boards/$(BOARD)/board.c for APARD - Reviewed Processor.c in common-hal/microcontroller - Prepared stubs for common-hal/microcontroller/Pin.c --- ports/analog/boards/APARD/board.c | 37 +++++++++++- ports/analog/boards/APARD/mpconfigboard.mk | 7 ++- ports/analog/common-hal/microcontroller/Pin.c | 51 ++++++++++++---- .../common-hal/microcontroller/Processor.c | 14 +++-- .../common-hal/microcontroller/__init__.c | 23 ++++---- ports/analog/{supervisor => }/max32_port.h | 12 +++- ports/analog/supervisor/port.c | 58 ++++++------------- 7 files changed, 129 insertions(+), 73 deletions(-) rename ports/analog/{supervisor => }/max32_port.h (85%) diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c index cd69f369579a..a075ec67d501 100644 --- a/ports/analog/boards/APARD/board.c +++ b/ports/analog/boards/APARD/board.c @@ -5,6 +5,24 @@ // SPDX-License-Identifier: MIT #include "supervisor/board.h" +#include "supervisor/port.h" +#include "mpconfigboard.h" +#include "max32_port.h" + +// Board-level setup for MAX32690 +// clang-format off +const mxc_gpio_cfg_t pb_pin[] = { + { MXC_GPIO1, MXC_GPIO_PIN_27, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, +}; +const int num_pbs = (sizeof(pb_pin) / sizeof(mxc_gpio_cfg_t)); + +const mxc_gpio_cfg_t led_pin[] = { + { MXC_GPIO2, MXC_GPIO_PIN_1, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO0, MXC_GPIO_PIN_11, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO0, MXC_GPIO_PIN_12, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, +}; +const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); +// clang-format on // DEFAULT: Using the weak-defined supervisor/shared/board.c functions @@ -15,7 +33,23 @@ // bool board_requests_safe_mode(void); // Initializes board related state once on start up. -// void board_init(void); +void board_init(void) { + // Enable GPIO (enables clocks + common init for ports) + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + MXC_GPIO_Init(0x1 << i); + } + + // Init Board LEDs + /* setup GPIO for the LED */ + for (int i = 0; i < num_leds; i++) { + // Set the output value + MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); + MXC_GPIO_Config(&led_pin[i]); + } + + // Turn on one LED to indicate Sign of Life + MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); +} // Reset the state of off MCU components such as neopixels. // void reset_board(void); @@ -24,4 +58,5 @@ // state. It should not prevent the user access method from working (such as // disabling USB, BLE or flash) because CircuitPython may continue to run. // void board_deinit(void); + /*******************************************************************/ diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index 7e5465e69422..874c3c14e394 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -5,13 +5,18 @@ # SPDX-License-Identifier: MIT INTERNAL_FLASH_FILESYSTEM = 1 -# FLASH: 0x10000000 to 0x10340000 +# FLASH: 0x10000000 to 0x10300000 (ARM) # SRAM: 0x20000000 to 0x20100000 USB_PRODUCT = "MAX32690 APARD" USB_MANUFACTURER = "Analog Devices, Inc." + +# NOTE: Not implementing external flash for now # CFLAGS+=-DEXT_FLASH_MX25 +# define 13 bytes UID for memory safety (buffer gets passed as a raw ptr) +COMMON_HAL_MCU_PROCESSOR_UID_LENGTH = 13 + MCU_SERIES=max32 MCU_VARIANT=max32690 diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index bc1ef9d70efc..6826b18e036f 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -2,33 +2,62 @@ #include #include "shared-bindings/microcontroller/Pin.h" -// #include "shared-bindings/digitalio/DigitalInOut.h" +#include "mpconfigboard.h" +#include "pins.h" +#include "mxc_sys.h" +#include "max32690.h" +#include "gpio.h" -// #include "gpio.h" - - -//FIXME: Implement void reset_all_pins(void) { - return; + // todo: this is not a good method for this long-term + // Pins should be individually reset to account for never_reset pins like SWD + for (int i = 0; i < NUM_GPIO_PORTS; i++) { + MXC_GPIO_Reset(i); + } } -// FIXME: Implement +// todo: Implement void reset_pin_number(uint8_t pin) { - return; } -// FIXME: Implement +// todo: Implement void claim_pin(const mcu_pin_obj_t *pin) { return; } -// FIXME: Implement +// todo: Implement bool pin_number_is_free(uint8_t pin_number) { return true; } -// FIXME: Implement + +// todo: Implement void never_reset_pin_number(uint8_t pin_number) { return; } + +//todo: implement +uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { + return 0; +} + +// todo: implement +bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { + return true; +} + +void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { +} + +void common_hal_reset_pin(const mcu_pin_obj_t *pin) { +} + +void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { +} + +void common_hal_mcu_pin_claim_number(uint8_t pin_no) { +} + +void common_hal_mcu_pin_reset_number(uint8_t pin_no) { +} diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c index 1bdcceeeb74c..339770f9fd24 100644 --- a/ports/analog/common-hal/microcontroller/Processor.c +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -10,14 +10,15 @@ #include "common-hal/microcontroller/Processor.h" #include "shared-bindings/microcontroller/ResetReason.h" -#include "system_max32690.h" +#include "max32_port.h" -// +// No means of getting core temperature for currently supported devices float common_hal_mcu_processor_get_temperature(void) { return NAN; } -// TODO: Determine if there's a means of getting core voltage +// MAX32690 can measure VCORE +// TODO: (low prior.) Implement ADC API under "peripherals" and use API to measure VCORE float common_hal_mcu_processor_get_voltage(void) { return NAN; } @@ -26,11 +27,16 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { return SystemCoreClock; } +// NOTE: COMMON_HAL_MCU_PROCESSOR_UID_LENGTH is defined in mpconfigboard.h +// Use this per device to make sure raw_id is an appropriate minimum number of bytes void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { + MXC_SYS_GetUSN(raw_id, NULL); // NULL checksum will not be verified by AES return; } -// TODO: May need to add reset reason in alarm / deepsleep cases mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { + #if CIRCUITPY_ALARM + // TODO: (low prior.) add reset reason in alarm / deepsleep cases (should require alarm peripheral API in "peripherals") + #endif return RESET_REASON_UNKNOWN; } diff --git a/ports/analog/common-hal/microcontroller/__init__.c b/ports/analog/common-hal/microcontroller/__init__.c index f15ef9bcecc3..aff2dc2fd497 100644 --- a/ports/analog/common-hal/microcontroller/__init__.c +++ b/ports/analog/common-hal/microcontroller/__init__.c @@ -22,24 +22,20 @@ #include "max32690.h" +#include "mxc_delay.h" + /** NOTE: It is not advised to directly include the below! * These are includes taken care of by the core cmsis file. * e.g. "max32690.h". Since CMSIS is compiled as lib, these are * included there as for example. */ -// #include "core_cmFunc.h" // For enable/disable interrupts -// #include "core_cm4.h" // For NVIC_SystemReset -// #include "core_cmInstr.h" // For __DMB Data Memory Barrier +// #include // For enable/disable interrupts +// #include // For NVIC_SystemReset +// #include // For __DMB Data Memory Barrier (flush DBUS activity) void common_hal_mcu_delay_us(uint32_t delay) { - // uint32_t ticks_per_us = HAL_RCC_GetSysClockFreq() / 1000000UL; - // delay *= ticks_per_us; - // SysTick->VAL = 0UL; - // SysTick->LOAD = delay; - // SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; - // while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0) { - // } - // SysTick->CTRL = 0UL; + + MXC_Delay(MXC_DELAY_USEC(delay)); } volatile uint32_t nesting_count = 0; @@ -59,7 +55,7 @@ void common_hal_mcu_enable_interrupts(void) { if (nesting_count > 0) { return; } - __DMB(); + __DMB(); // flush internal DBUS before proceeding __enable_irq(); } @@ -75,7 +71,6 @@ void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { } void common_hal_mcu_reset(void) { - if (next_reset_to_bootloader) { reset_to_bootloader(); } else { @@ -398,6 +393,8 @@ static const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { }; MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table); + +/** NOTE: Not implemented yet */ // #if CIRCUITPY_INTERNAL_NVM_SIZE > 0 // // The singleton nvm.ByteArray object. // const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { diff --git a/ports/analog/supervisor/max32_port.h b/ports/analog/max32_port.h similarity index 85% rename from ports/analog/supervisor/max32_port.h rename to ports/analog/max32_port.h index 25641a5dddbc..ec6d29ad80f8 100644 --- a/ports/analog/supervisor/max32_port.h +++ b/ports/analog/max32_port.h @@ -4,10 +4,18 @@ #include -#include "mxc_sys.h" +#include "mxc_assert.h" +#include "mxc_delay.h" +#include "mxc_device.h" #include "mxc_pins.h" +#include "mxc_sys.h" + #include "gpio.h" -#include "mxc_assert.h" + +#ifdef MQAX32690 +#include "system_max32690.h" +#include "max32690.h" +#endif /** Linker variables defined.... * _estack: end of the stack diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index fd6bc1806aeb..21f4b6504cca 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -47,26 +47,19 @@ #include "mxc_delay.h" #include "rtc.h" +// Externs defined by linker .ld file +extern uint32_t _stack, _heap, _estack, _eheap; +extern uint32_t _ebss; + +// From boards/$(BOARD)/board.c +extern const mxc_gpio_cfg_t pb_pin[]; +extern const int num_pbs; +extern const mxc_gpio_cfg_t led_pin[]; +extern const int num_leds; + //todo: define an LED HAL // #include "peripherals/led.h" -#ifdef MAX32690 -// Board-level setup for MAX32690 -// clang-format off -const mxc_gpio_cfg_t pb_pin[] = { - { MXC_GPIO1, MXC_GPIO_PIN_27, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, -}; -const unsigned int num_pbs = (sizeof(pb_pin) / sizeof(mxc_gpio_cfg_t)); - -const mxc_gpio_cfg_t led_pin[] = { - { MXC_GPIO2, MXC_GPIO_PIN_1, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, - { MXC_GPIO0, MXC_GPIO_PIN_11, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, - { MXC_GPIO0, MXC_GPIO_PIN_12, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, -}; -const unsigned int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); -// clang-format on -#endif - // For caching rtc data for ticks static uint32_t subsec, sec = 0; @@ -96,7 +89,7 @@ safe_mode_t port_init(void) { } // Turn on one LED to indicate Sign of Life - MXC_GPIO_OutSet(led_pin[0].port, led_pin[0].mask); + MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); // Init RTC w/ 0sec, 0subsec // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s @@ -120,23 +113,9 @@ void reset_cpu(void) { // Reset MCU state void reset_port(void) { - int err; - // Reset GPIO Ports - // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ - err = MXC_GPIO_Reset(0x1 << i); - if (err) { - // todo: indicate some gpio error - continue; - } - } - - // TODO: Reset peripheral clocks + reset_all_pins(); - // Reset 1/1024 tick timer - MXC_RTC_Stop(); - MXC_RTC_ClearFlags(0xFFFFFFFF); - MXC_RTC_Init(0,0); + // todo: may need rtc-related resets here later } // Reset to the bootloader @@ -154,22 +133,19 @@ void reset_to_bootloader(void) { * Return variables defined by linkerscript. */ uint32_t *port_stack_get_limit(void) { - // ignore array bounds GCC warnings for stack here + // ignore array bounds GCC warnings #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" // NOTE: Only return how much stack we have alloted for CircuitPython - return (uint32_t *)(port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t)); - // return _estack; - - // end GCC diagnostic disable + return port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t); #pragma GCC diagnostic pop } uint32_t *port_stack_get_top(void) { - return (uint32_t *)__stack; + return &_stack; } uint32_t *port_heap_get_bottom(void) { - return (uint32_t *)__heap; + return &_heap; } uint32_t *port_heap_get_top(void) { return port_stack_get_limit(); From 48051ae734390c526a5d02bab1d38a10525d94c4 Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Fri, 23 Aug 2024 14:39:44 -0700 Subject: [PATCH 220/252] -Added USB via tinyUSB. Still need to test/debug before REPL is ready. - Enabled USB-based modules & dependencies in mpconfigport.mk --- ports/analog/Makefile | 19 +++- ports/analog/README.md | 3 +- ports/analog/boards/APARD/board.c | 13 +++ ports/analog/boards/APARD/mpconfigboard.mk | 9 +- ports/analog/common-hal/microcontroller/Pin.c | 96 ++++++++++++++----- ports/analog/common-hal/microcontroller/Pin.h | 5 +- ports/analog/mpconfigport.mk | 24 ++--- ports/analog/supervisor/usb.c | 40 ++++++++ 8 files changed, 160 insertions(+), 49 deletions(-) create mode 100644 ports/analog/supervisor/usb.c diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 151299a8792a..7a684711546d 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -166,17 +166,30 @@ else COPT += -O0 #opt completely off to start endif - # TinyUSB CFLAGS +ifeq ($(CIRCUITPY_TINYUSB),1) CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \ -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \ + -DCFG_TUSB_OS=OPT_OS_NONE \ + -DCFG_TUD_TASK_QUEUE_SZ=32 -# TODO: Add for TinyUSB once our PR goes through for MAX32 devices -# Add TinyUSB +# Add TinyUSB sources INC += -I../../lib/tinyusb/src INC += -I../../supervisor/shared/usb SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c +endif + +ifeq ($(CIRCUITPY_USB_DEVICE),1) +CFLAGS += \ + -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ + -DCFG_TUD_CDC_TX_BUFSIZE=1024 \ + -DCFG_TUD_MSC_BUFSIZE=4096 \ + -DCFG_TUD_MIDI_RX_BUFSIZE=128 \ + -DCFG_TUD_MIDI_TX_BUFSIZE=128 \ + -DCFG_TUD_VENDOR_RX_BUFSIZE=128 \ + -DCFG_TUD_VENDOR_TX_BUFSIZE=128 +endif SRC_C += \ boards/$(BOARD)/board.c \ diff --git a/ports/analog/README.md b/ports/analog/README.md index 603a22f9fd4b..1650fad1cac5 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -9,7 +9,8 @@ This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. Thes - **`linking/:`** Linkerfiles customized for CircuitPython. These are distinct from the linkerfiles used in MSDK as they adopt the structure required by CircuitPython. They may also omit unused features and memory sections, e.g. Mailboxes, RISC-V Flash, & Hyperbus RAM for MAX32690. - **`msdk:/`** SDK for MAX32 devices. More info on our GitHub: [Analog Devices MSDK GitHub](https://github.com/analogdevicesinc/msdk) - **`peripherals:/`** Helper files for peripherals such as clocks, gpio, etc. These files tend to be specific to vendor SDKs and provide some useful functions for the common-hal interfaces. -- **`supervisor/:`** Implementation files for the CircuitPython supervisor. This includes port setup, usb, and a filesystem on a storage medium such as SD Card/eMMC, QSPI Flash, or internal flash memory. Currently the internal flash is used. +- **`supervisor/:`** Implementation files for the CircuitPython supervisor. This includes port setup, usb, and a filesystem on a storage medium such as SD Card/eMMC, QSPI Flash, or internal flash memory. Currently the internal flash is used. This folder is the most important part of a port's core functionality for CircuitPython. +- **`supervisor/port.c:`** Port-specific startup code including clock initialization, console startup, etc. - `. :` Build system and high-level interface to the CircuitPython core for the ADI port. diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c index a075ec67d501..972bdcee6f8c 100644 --- a/ports/analog/boards/APARD/board.c +++ b/ports/analog/boards/APARD/board.c @@ -32,8 +32,21 @@ const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); // way. // bool board_requests_safe_mode(void); +volatile uint32_t system_ticks = 0; + +void SysTick_Handler(void) { + system_ticks++; +} + +uint32_t board_millis(void) { + return system_ticks; +} + // Initializes board related state once on start up. void board_init(void) { + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000);\ + // Enable GPIO (enables clocks + common init for ports) for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ MXC_GPIO_Init(0x1 << i); diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index 874c3c14e394..16c8ac72581d 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -8,8 +8,13 @@ INTERNAL_FLASH_FILESYSTEM = 1 # FLASH: 0x10000000 to 0x10300000 (ARM) # SRAM: 0x20000000 to 0x20100000 -USB_PRODUCT = "MAX32690 APARD" -USB_MANUFACTURER = "Analog Devices, Inc." +USB_MANUFACTURER="Analog Devices, Inc." +USB_PRODUCT="MAX32690 APARD" + +# Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim +USB_VID=0x0456 +# USB_VID=0x0B6A +USB_PID=0x003C # NOTE: Not implementing external flash for now # CFLAGS+=-DEXT_FLASH_MX25 diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 6826b18e036f..e11c9413c907 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -8,56 +8,104 @@ #include "mxc_sys.h" #include "max32690.h" #include "gpio.h" +#include "gpio_regs.h" + +// Structs to represent GPIO ports & valid pins/pads +#ifdef MAX32690 +// todo: special constraints are applied to GPIO4 for MAX32690. Tend to these later (low prior) +static mxc_gpio_regs_t* ports[NUM_GPIO_PORTS] = { MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3}; +#endif + +static uint32_t claimed_pins[NUM_GPIO_PORTS]; +static uint32_t never_reset_pins[NUM_GPIO_PORTS]; + +#define INVALID_PIN 0xFF // id for invalid pin void reset_all_pins(void) { - // todo: this is not a good method for this long-term - // Pins should be individually reset to account for never_reset pins like SWD + // reset all pins except for never_reset_pins for (int i = 0; i < NUM_GPIO_PORTS; i++) { - MXC_GPIO_Reset(i); + for (int j = 0; j < 32; j++) { + if (!(never_reset_pins[i] & (1 << j))) { + reset_pin_number(i, j); + } + } + // set claimed pins to never_reset pins + claimed_pins[i] = never_reset_pins[i]; } } -// todo: Implement -void reset_pin_number(uint8_t pin) { -} +void reset_pin_number(uint8_t pin_port, uint8_t pin_pad) { + if (pin_port == INVALID_PIN || pin_port > NUM_GPIO_PORTS) { + return; + } -// todo: Implement -void claim_pin(const mcu_pin_obj_t *pin) { - return; -} + uint32_t mask = 1 << (pin_pad); -// todo: Implement -bool pin_number_is_free(uint8_t pin_number) { - return true; -} + /** START: RESET LOGIC for GPIOs */ + // Switch to I/O mode first + ports[pin_port]->en0_set = mask; + + // set GPIO configuration enable bits to I/O + ports[pin_port]->en0_clr = mask; + ports[pin_port]->en1_clr = mask; + ports[pin_port]->en2_clr = mask; + + // enable input mode GPIOn_INEN.pin = 1 + ports[pin_port]->inen |= mask; + + // High Impedance mode enable (GPIOn_PADCTRL1 = 0, _PADCTRL0 = 0), pu/pd disable + ports[pin_port]->padctrl0 &= ~mask; + ports[pin_port]->padctrl1 &= ~mask; + // Output mode disable GPIOn_OUTEN = 0 + ports[pin_port]->outen |= mask; -// todo: Implement -void never_reset_pin_number(uint8_t pin_number) { - return; + // Interrupt disable GPIOn_INTEN = 0 + ports[pin_port]->inten &= ~mask; + /** END: RESET LOGIC for GPIOs */ } -//todo: implement uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { - return 0; + if (pin == NULL) { + return INVALID_PIN; + } + + // most max32 gpio ports have 32 pins + // todo: create a struct to encode # of pins for each port, since some GPIO ports differ + return pin->port * 32 + pin->pad; } -// todo: implement bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { - return true; + if (pin == NULL) { + return true; + } + return !(claimed_pins[pin->port] & (pin->pad)); } void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { + if ((pin != NULL) && (pin->pad != INVALID_PIN)) { + never_reset_pins[pin->port] |= (1 << pin->pad); + + // any never reset pin must also be claimed + claimed_pins[pin->port] |= (1 << pin->pad); + } } void common_hal_reset_pin(const mcu_pin_obj_t *pin) { -} + if (pin == NULL) { + return; + } -void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { + reset_pin_number(pin->port, pin->pad); } -void common_hal_mcu_pin_claim_number(uint8_t pin_no) { +void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { + if (pin == NULL) { + return; + } + claimed_pins[pin->port] |= (1 << pin->pad); } void common_hal_mcu_pin_reset_number(uint8_t pin_no) { + reset_pin_number(pin_no / 32, pin_no & 32); } diff --git a/ports/analog/common-hal/microcontroller/Pin.h b/ports/analog/common-hal/microcontroller/Pin.h index 6089a94e0c11..55d4081f3a6b 100644 --- a/ports/analog/common-hal/microcontroller/Pin.h +++ b/ports/analog/common-hal/microcontroller/Pin.h @@ -8,7 +8,4 @@ void reset_all_pins(void); // reset_pin_number takes the pin number instead of the pointer so that objects don't // need to store a full pointer. -void reset_pin_number(uint8_t pin); -void claim_pin(const mcu_pin_obj_t *pin); -bool pin_number_is_free(uint8_t pin_number); -void never_reset_pin_number(uint8_t pin_number); +void reset_pin_number(uint8_t pin_port, uint8_t pin_pad); diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index b67622935183..689ae445b7fe 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -15,22 +15,27 @@ INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 -# TODO: TEST filesystem & general bringup! +# TODO: Test/Debug fs & general bringup DISABLE_FILESYSTEM = 0 +# TODO: Test/Debug TinyUSB! +# Builds clean; need to test +CIRCUITPY_TINYUSB = 1 +CIRCUITPY_USB_DEVICE ?= 1 +CIRCUITPY_USB_CDC ?= 1 +CIRCUITPY_USB_HID ?= 0 +CIRCUITPY_USB_MIDI ?= 0 + #################################################################################### # Suggested config for first-time porting #################################################################################### # These modules are implemented in ports//common-hal: -# Typically the first module to create -CIRCUITPY_MICROCONTROLLER ?= 1 # Typically the second module to create CIRCUITPY_DIGITALIO ?= 0 # Plan to implement CIRCUITPY_BUSIO ?= 0 -CIRCUITPY_OS ?= 1 CIRCUITPY_RTC ?= 0 # Other modules (may or may not implement): @@ -58,17 +63,10 @@ CIRCUITPY_BITBANGIO ?= 0 CIRCUITPY_PIXELBUF ?= 0 # Requires OS CIRCUITPY_RANDOM ?= 0 -# Requires OS, filesystem -CIRCUITPY_STORAGE ?= 0 # Requires Microcontroller CIRCUITPY_TOUCHIO ?= 0 # Requires UART CIRCUITPY_CONSOLE_UART ?= 0 -# Requires USB -CIRCUITPY_USB_DEVICE ?= 0 -CIRCUITPY_USB_CDC ?= 0 -CIRCUITPY_USB_HID ?= 0 -CIRCUITPY_USB_MIDI ?= 0 # Does nothing without I2C CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 @@ -83,7 +81,3 @@ CIRCUITPY_ULAB = 1 CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_BUSDEVICE = 0 - -# TinyUSB will be added later. -CIRCUITPY_TINYUSB = 0 -CIRCUITPY_PYUSB = 0 diff --git a/ports/analog/supervisor/usb.c b/ports/analog/supervisor/usb.c new file mode 100644 index 000000000000..2fd1545bdb1b --- /dev/null +++ b/ports/analog/supervisor/usb.c @@ -0,0 +1,40 @@ + +#include "supervisor/usb.h" +#include "common-hal/microcontroller/Pin.h" + +#include "py/mpconfig.h" + +#include "lib/tinyusb/src/device/usbd.h" + +// max32 includes +#include "mxc_sys.h" +#include "gcr_regs.h" +#include "mcr_regs.h" + +void init_usb_hardware(void) { + // USB GPIOs are non-configurable on MAX32 devices + // No need to add them to the never_reset list for mcu/Pin API. + + // 1 ms SysTick initialized in board.c + // todo: consider moving SysTick initialization here? + + // Enable requisite clocks & power for USB + MXC_SYS_ClockSourceEnable(MXC_SYS_CLOCK_IPO); + MXC_MCR->ldoctrl |= MXC_F_MCR_LDOCTRL_0P9EN; + MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_USB); + MXC_SYS_Reset_Periph(MXC_SYS_RESET0_USB); + + // Supervisor calls TinyUSB's dcd_init, + // which initializes the USB PHY. + // Dep. on CIRCUITPY_TINYUSB and CIRCUITPY_USB_DEVICE + + // Interrupt enables are left to TUSB depending on the device class + // todo: confirm with testing! +} + +void USB_IRQHandler(void) +{ + // Schedules USB background callback + // appropriate to a given device class via TinyUSB lib + usb_irq_handler(0); +} From a29336b0fcba4b4e67bea846ccaf164eba9d1fc5 Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Mon, 26 Aug 2024 15:09:37 -0700 Subject: [PATCH 221/252] Fixed USB endpoint speed issue w/ configuration setting --- ports/analog/Makefile | 40 +++++++++++++--------- ports/analog/boards/APARD/mpconfigboard.mk | 12 ++++--- ports/analog/mpconfigport.mk | 1 - 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 7a684711546d..20ea99f5de62 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -82,7 +82,7 @@ INC += \ -I$(PERIPH_SRC)/ICC \ -I$(PERIPH_SRC)/TMR \ -I$(PERIPH_SRC)/RTC \ - -I$(PERIPH_SRC)/UART \ + -I$(PERIPH_SRC)/UART INC += -I$(CMSIS_ROOT)/Device/Maxim/$(MCU_VARIANT_UPPER)/Source/GCC @@ -116,12 +116,12 @@ SRC_MAX32 += \ $(PERIPH_SRC)/TMR/tmr_$(DIE_TYPE).c \ $(PERIPH_SRC)/UART/uart_common.c \ $(PERIPH_SRC)/UART/uart_$(DIE_TYPE).c \ - $(PERIPH_SRC)/UART/uart_revb.c \ + $(PERIPH_SRC)/UART/uart_revb.c SRC_C += $(SRC_MAX32) \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ - peripherals/$(MCU_VARIANT_LOWER)/pins.c \ + peripherals/$(MCU_VARIANT_LOWER)/pins.c # ******************************************************************************* ### Compiler & Linker Flags ### @@ -145,11 +145,11 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET_REV=0x4131 \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ - -DRISCV_LOAD=0 \ - # -DFLASH_ORIGIN=0x10000000 \ - # -DFLASH_SIZE=0x340000 \ - # -DSRAM_ORIGIN=0x20000000 \ - # -DSRAM_SIZE=0x100000 \ + -DRISCV_LOAD=0 +# -DFLASH_ORIGIN=0x10000000 \ +# -DFLASH_SIZE=0x340000 \ +# -DSRAM_ORIGIN=0x20000000 \ +# -DSRAM_SIZE=0x100000 CPU_CORE=cortex-m4 CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=softfp -mfpu=fpv4-sp-d16 @@ -171,8 +171,9 @@ ifeq ($(CIRCUITPY_TINYUSB),1) CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \ -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \ - -DCFG_TUSB_OS=OPT_OS_NONE \ - -DCFG_TUD_TASK_QUEUE_SZ=32 + -DCFG_TUSB_OS=OPT_OS_NONE + +# -DCFG_TUD_TASK_QUEUE_SZ=32 # Add TinyUSB sources INC += -I../../lib/tinyusb/src @@ -182,15 +183,20 @@ endif ifeq ($(CIRCUITPY_USB_DEVICE),1) CFLAGS += \ - -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ -DCFG_TUD_CDC_TX_BUFSIZE=1024 \ - -DCFG_TUD_MSC_BUFSIZE=4096 \ - -DCFG_TUD_MIDI_RX_BUFSIZE=128 \ - -DCFG_TUD_MIDI_TX_BUFSIZE=128 \ - -DCFG_TUD_VENDOR_RX_BUFSIZE=128 \ - -DCFG_TUD_VENDOR_TX_BUFSIZE=128 + -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ + -DCFG_TUD_MSC_BUFSIZE=4096 endif +ifdef CIRCUITPY_USB_VENDOR +CFLASGS += \ + -DCFG_TUD_VENDOR_RX_BUFSIZE=1024 \ + -DCFG_TUD_VENDOR_TX_BUFSIZE=1024 +endif + +# -DCFG_TUD_MIDI_RX_BUFSIZE=128 +# -DCFG_TUD_MIDI_TX_BUFSIZE=128 + SRC_C += \ boards/$(BOARD)/board.c \ background.c \ @@ -208,7 +214,7 @@ CFLAGS += -Wno-error=unused-parameter \ -Wno-error=lto-type-mismatch \ -Wno-error=cast-align \ -Wno-error=nested-externs \ - -Wno-error=sign-compare \ + -Wno-error=sign-compare ENTRY = Reset_Handler LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index 16c8ac72581d..749c30465679 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -4,23 +4,25 @@ # # SPDX-License-Identifier: MIT -INTERNAL_FLASH_FILESYSTEM = 1 +INTERNAL_FLASH_FILESYSTEM=1 # FLASH: 0x10000000 to 0x10300000 (ARM) # SRAM: 0x20000000 to 0x20100000 -USB_MANUFACTURER="Analog Devices, Inc." -USB_PRODUCT="MAX32690 APARD" - # Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim USB_VID=0x0456 # USB_VID=0x0B6A USB_PID=0x003C +USB_MANUFACTURER="Analog Devices, Inc." +USB_PRODUCT="MAX32690 APARD" +# Num endpt pairs for a given device +USB_NUM_ENDPOINT_PAIRS=12 +USB_HIGHSPEED=1 # NOTE: Not implementing external flash for now # CFLAGS+=-DEXT_FLASH_MX25 # define 13 bytes UID for memory safety (buffer gets passed as a raw ptr) -COMMON_HAL_MCU_PROCESSOR_UID_LENGTH = 13 +COMMON_HAL_MCU_PROCESSOR_UID_LENGTH=13 MCU_SERIES=max32 MCU_VARIANT=max32690 diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 689ae445b7fe..0fb490cc150b 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -7,7 +7,6 @@ CHIP_FAMILY ?= max32 # Necessary to build CircuitPython -USB_NUM_ENDPOINT_PAIRS ?= 0 LONGINT_IMPL ?= MPZ INTERNAL_LIBM ?= 1 From 8da1f121703596ba73821327e32959b3d357ab09 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Mon, 2 Sep 2024 13:22:06 -0700 Subject: [PATCH 222/252] Fixed some RTC alarm setup issues; tick interrupts now function as expected. --- ports/analog/boards/APARD/mpconfigboard.mk | 17 ++- ports/analog/max32_port.h | 5 +- ports/analog/mpconfigport.mk | 4 +- ports/analog/supervisor/port.c | 132 +++++++++++---------- ports/analog/tools/connect-gdb.txt | 16 --- ports/analog/tools/flash-halt-openocd.bat | 5 - 6 files changed, 83 insertions(+), 96 deletions(-) delete mode 100644 ports/analog/tools/connect-gdb.txt delete mode 100644 ports/analog/tools/flash-halt-openocd.bat diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index 749c30465679..e49d695761c3 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -4,27 +4,26 @@ # # SPDX-License-Identifier: MIT +MCU_SERIES=max32 +MCU_VARIANT=max32690 + INTERNAL_FLASH_FILESYSTEM=1 # FLASH: 0x10000000 to 0x10300000 (ARM) # SRAM: 0x20000000 to 0x20100000 +#### USB CONFIGURATION # Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim USB_VID=0x0456 # USB_VID=0x0B6A USB_PID=0x003C USB_MANUFACTURER="Analog Devices, Inc." USB_PRODUCT="MAX32690 APARD" -# Num endpt pairs for a given device USB_NUM_ENDPOINT_PAIRS=12 USB_HIGHSPEED=1 +### + +# define UID len for memory safety (buffer gets passed as a raw ptr) +COMMON_HAL_MCU_PROCESSOR_UID_LENGTH=30 # NOTE: Not implementing external flash for now # CFLAGS+=-DEXT_FLASH_MX25 - -# define 13 bytes UID for memory safety (buffer gets passed as a raw ptr) -COMMON_HAL_MCU_PROCESSOR_UID_LENGTH=13 - -MCU_SERIES=max32 -MCU_VARIANT=max32690 - -CFLAGS += -DHAS_TRNG=1 diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index ec6d29ad80f8..214e975b719b 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -12,7 +12,7 @@ #include "gpio.h" -#ifdef MQAX32690 +#ifdef MAX32690 #include "system_max32690.h" #include "max32690.h" #endif @@ -33,7 +33,8 @@ extern uint32_t SystemCoreClock; #define TICKS_PER_SEC 1024 #ifdef MAX32690 -#define SUBSEC_PER_TICK 8 // 12-bit ssec register, ticks @ 4096 Hz +// 12-bit ssec register, ticks @ 4096 Hz +#define SUBSEC_PER_TICK 4 #endif #endif //MAX32_PORT_H diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 0fb490cc150b..f9b50477bc23 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -10,6 +10,9 @@ CHIP_FAMILY ?= max32 LONGINT_IMPL ?= MPZ INTERNAL_LIBM ?= 1 +# Req'd for OS; all max32 have TRNG +CFLAGS += -DHAS_TRNG=1 + INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 @@ -18,7 +21,6 @@ QSPI_FLASH_FILESYSTEM = 0 DISABLE_FILESYSTEM = 0 # TODO: Test/Debug TinyUSB! -# Builds clean; need to test CIRCUITPY_TINYUSB = 1 CIRCUITPY_USB_DEVICE ?= 1 CIRCUITPY_USB_CDC ?= 1 diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 21f4b6504cca..31a46b8de8b8 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -47,6 +47,11 @@ #include "mxc_delay.h" #include "rtc.h" +// msec to RTC subsec ticks (4 kHz) +#define MSEC_TO_SS_ALARM(x) \ + (0 - ((x * 4096) / \ + 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */ + // Externs defined by linker .ld file extern uint32_t _stack, _heap, _estack, _eheap; extern uint32_t _ebss; @@ -60,8 +65,9 @@ extern const int num_leds; //todo: define an LED HAL // #include "peripherals/led.h" -// For caching rtc data for ticks +// For saving rtc data for ticks static uint32_t subsec, sec = 0; +static uint32_t tick_flag = 0; // defined by cmsis core files extern void NVIC_SystemReset(void) NORETURN; @@ -91,20 +97,43 @@ safe_mode_t port_init(void) { // Turn on one LED to indicate Sign of Life MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); + // Enable clock to RTC peripheral + MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_ERTCO_EN; + while(!(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_ERTCO_RDY)); + + NVIC_EnableIRQ(RTC_IRQn); + NVIC_EnableIRQ(USB_IRQn); + // Init RTC w/ 0sec, 0subsec // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s - err = MXC_RTC_Init(0, 0); - if (err) { - return SAFE_MODE_SDK_FATAL_ERROR; - } - NVIC_EnableIRQ(RTC_IRQn); + while( MXC_RTC_Init(0,0) != E_SUCCESS ) {}; - // todo: init periph clocks / console here when ready + // enable 1 sec RTC SSEC alarm + MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); + MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(1000)); + MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); + + // Enable RTC + while ( MXC_RTC_Start() != E_SUCCESS ) {}; - MXC_RTC_Start(); return SAFE_MODE_NONE; } +void RTC_IRQHandler(void) { + // Read flags to clear + int flags = MXC_RTC_GetFlags(); + + if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) { + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); + } + + if (flags & MXC_F_RTC_CTRL_TOD_ALARM) { + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); + } + + tick_flag = 1; +} + // Reset the MCU completely void reset_cpu(void) { // includes MCU reset request + awaits on memory bus @@ -114,18 +143,15 @@ void reset_cpu(void) { // Reset MCU state void reset_port(void) { reset_all_pins(); - - // todo: may need rtc-related resets here later } // Reset to the bootloader // note: not implemented since max32 requires external stim ignals to // activate bootloaders -// todo: check if there's a method to jump to it void reset_to_bootloader(void) { NVIC_SystemReset(); while (true) { - asm ("nop;"); + __NOP(); } } @@ -169,7 +195,14 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { // Ensure we can read from ssec register as soon as we can // MXC function does cross-tick / busy checking of RTC controller __disable_irq(); - MXC_RTC_GetTime(&sec, &subsec); + if (MXC_RTC->ctrl & MXC_F_RTC_CTRL_EN) { + // NOTE: RTC_GetTime always returns BUSY if RTC is not running + while( (MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR ); + } + else { + sec = MXC_RTC->sec; + subsec = MXC_RTC->ssec; + } __enable_irq(); // Return ticks given total subseconds @@ -197,71 +230,44 @@ void port_disable_tick(void) { // Wake the CPU after a given # of ticks or sooner void port_interrupt_after_ticks(uint32_t ticks) { + uint32_t ticks_msec = 0; // Stop RTC & store current time & ticks port_disable_tick(); port_get_raw_ticks(NULL); - uint32_t target_sec = (ticks / TICKS_PER_SEC); - uint32_t target_ssec = (ticks - (target_sec * TICKS_PER_SEC)) * SUBSEC_PER_TICK; - - // Set up alarm configuration - // if alarm is greater than 1 s, - // use the ToD alarm --> resol. to closest second - // else - // use Ssec alarm --> resn. to 1/1024 s. (down to a full tick) - if (target_sec > 0) { - if (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | - MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { - // todo: signal some RTC error! - } + ticks_msec = 1000 * ticks / TICKS_PER_SEC; - if (MXC_RTC_SetTimeofdayAlarm(target_sec) != E_NO_ERROR) { - // todo: signal some RTC error! - } - if (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { - // todo: signal some RTC error! - } - } - else { - if (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | - MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { - // todo: signal some RTC error! - } + while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | + MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {}; - if (MXC_RTC_SetSubsecondAlarm(target_ssec) != E_NO_ERROR) { - // todo: signal some RTC error! - } - - if (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) { - // todo: signal some RTC error! - } - } - port_enable_tick(); -} + // Clear the flag to be set by the RTC Handler + tick_flag = 0; -void RTC_IRQHandler(void) { - // Read flags to clear - int flags = MXC_RTC_GetFlags(); + // Subsec alarm is the starting/reload value of the SSEC counter. + // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0 + while ( MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec) ) == E_BUSY) {} + while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {} - if (flags & MXC_F_RTC_CTRL_TOD_ALARM) { - MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); - while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {} - } + NVIC_EnableIRQ(RTC_IRQn); - if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) { - MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); - while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {} - } + port_enable_tick(); } void port_idle_until_interrupt(void) { - // Check if alarm triggers before we even got here - if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { - return; - } + #if CIRCUITPY_RTC + // Check if alarm triggers before we even got here + if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { + return; + } + #endif + // Interrupts should be disabled to ensure the ISR queue is flushed + // WFI still returns as long as the interrupt flag toggles; + // only when we re-enable interrupts will the ISR function trigger common_hal_mcu_disable_interrupts(); if (!background_callback_pending()) { + __DSB(); + /** DEBUG: may comment out WFI for debugging port functions */ __WFI(); } common_hal_mcu_enable_interrupts(); diff --git a/ports/analog/tools/connect-gdb.txt b/ports/analog/tools/connect-gdb.txt deleted file mode 100644 index ced4bdf6af3a..000000000000 --- a/ports/analog/tools/connect-gdb.txt +++ /dev/null @@ -1,16 +0,0 @@ -For connecting GDB... - -// Set symbol & exec to .elf -arm-none-eabi-gdb --se=build-APARD/firmware.elf - -// connect to remote on local machine TCP port :3333 -target extended-remote localhost:3333 - -// reset halt the MCU -monitor reset halt - -// set a breakpoint on main & hit it -b main -continue - -// now...time to mess around! diff --git a/ports/analog/tools/flash-halt-openocd.bat b/ports/analog/tools/flash-halt-openocd.bat deleted file mode 100644 index ae30cdff0b97..000000000000 --- a/ports/analog/tools/flash-halt-openocd.bat +++ /dev/null @@ -1,5 +0,0 @@ -:: Flash the target MCU via OpenOCD, -:: then reset halt to prepare for gdb connection -:: waits for gdb connection on localhost port 3333; see connect-gdb.txt for more info -:: leave this process open if you're connecting gdb -openocd -s $MAXIM_PATH/Tools/OpenOCD/scripts -f interface/cmsis-dap.cfg -f target/max32690.cfg -c "program build-APARD/firmware.elf verify; init; reset halt" From 2f58ca3e953540ed4fa203f54af0bf9e92d4a4b6 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 3 Sep 2024 09:33:41 -0700 Subject: [PATCH 223/252] Reorganized some build files & commented out WFI to debug USB. USB enumerates but has some issues starting interfaces for CDC/MSC/HID. --- ports/analog/Makefile | 30 +++++++++--------------------- ports/analog/mpconfigport.mk | 13 +++++++------ ports/analog/supervisor/port.c | 4 ++-- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 20ea99f5de62..7c3e1cb80117 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -167,36 +167,24 @@ COPT += -O0 #opt completely off to start endif # TinyUSB CFLAGS -ifeq ($(CIRCUITPY_TINYUSB),1) CFLAGS += \ -DCFG_TUSB_MCU=OPT_MCU_$(MCU_VARIANT_UPPER) \ -DBOARD_TUD_MAX_SPEED=OPT_MODE_HIGH_SPEED \ - -DCFG_TUSB_OS=OPT_OS_NONE - -# -DCFG_TUD_TASK_QUEUE_SZ=32 - -# Add TinyUSB sources -INC += -I../../lib/tinyusb/src -INC += -I../../supervisor/shared/usb -SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c -endif - -ifeq ($(CIRCUITPY_USB_DEVICE),1) -CFLAGS += \ + -DCFG_TUSB_OS=OPT_OS_NONE \ -DCFG_TUD_CDC_TX_BUFSIZE=1024 \ -DCFG_TUD_CDC_RX_BUFSIZE=1024 \ - -DCFG_TUD_MSC_BUFSIZE=4096 -endif - -ifdef CIRCUITPY_USB_VENDOR -CFLASGS += \ + -DCFG_TUD_MSC_BUFSIZE=4096 \ + -DCFG_TUD_MIDI_RX_BUFSIZE=128 \ + -DCFG_TUD_MIDI_TX_BUFSIZE=128 \ -DCFG_TUD_VENDOR_RX_BUFSIZE=1024 \ -DCFG_TUD_VENDOR_TX_BUFSIZE=1024 -endif -# -DCFG_TUD_MIDI_RX_BUFSIZE=128 -# -DCFG_TUD_MIDI_TX_BUFSIZE=128 +# Add TinyUSB sources +INC += -I../../lib/tinyusb/src +INC += -I../../supervisor/shared/usb +SRC_C += lib/tinyusb/src/portable/mentor/musb/dcd_musb.c +# Add port sources incl. any board functions SRC_C += \ boards/$(BOARD)/board.c \ background.c \ diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index f9b50477bc23..32881729c7a9 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -17,15 +17,16 @@ INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 -# TODO: Test/Debug fs & general bringup +# TODO: Test/Debug fs once USB-MSC is ready DISABLE_FILESYSTEM = 0 # TODO: Test/Debug TinyUSB! -CIRCUITPY_TINYUSB = 1 -CIRCUITPY_USB_DEVICE ?= 1 -CIRCUITPY_USB_CDC ?= 1 -CIRCUITPY_USB_HID ?= 0 -CIRCUITPY_USB_MIDI ?= 0 +# CIRCUITPY_TINYUSB = 1 +# CIRCUITPY_USB_DEVICE ?= 1 +# CIRCUITPY_USB_CDC ?= 1 +# CIRCUITPY_USB_VENDOR ?=1 +# CIRCUITPY_USB_HID ?= 0 +# CIRCUITPY_USB_MIDI ?= 0 #################################################################################### # Suggested config for first-time porting diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 31a46b8de8b8..730d85124259 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -163,7 +163,7 @@ uint32_t *port_stack_get_limit(void) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" - // NOTE: Only return how much stack we have alloted for CircuitPython + // NOTE: Only return how much stack we have allotted for CircuitPython return port_stack_get_top() - (CIRCUITPY_DEFAULT_STACK_SIZE + CIRCUITPY_EXCEPTION_STACK_SIZE) / sizeof(uint32_t); #pragma GCC diagnostic pop } @@ -268,7 +268,7 @@ void port_idle_until_interrupt(void) { if (!background_callback_pending()) { __DSB(); /** DEBUG: may comment out WFI for debugging port functions */ - __WFI(); + // __WFI(); } common_hal_mcu_enable_interrupts(); } From b19f8a2b478a37d3cb294ea26d151ef2c02dae72 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 3 Sep 2024 13:02:24 -0700 Subject: [PATCH 224/252] - Fixed USB endpoint descriptor problems. All USB classes should now be usable. - Had to adjust some shared modules to account for MAX32 devices not supporting IN/OUT endpoints on the same EP # --- ports/analog/boards/APARD/mpconfigboard.mk | 4 +++- ports/analog/mpconfigport.mk | 10 +--------- shared-module/storage/__init__.c | 5 +++++ shared-module/usb_cdc/__init__.c | 5 +++++ shared-module/usb_hid/__init__.c | 6 ++++++ shared-module/usb_midi/__init__.c | 6 ++++++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index e49d695761c3..cbd2e97d9058 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -18,8 +18,10 @@ USB_VID=0x0456 USB_PID=0x003C USB_MANUFACTURER="Analog Devices, Inc." USB_PRODUCT="MAX32690 APARD" -USB_NUM_ENDPOINT_PAIRS=12 USB_HIGHSPEED=1 + +# NOTE: MAX32 devices do not support IN/OUT pairs on the same EP +USB_NUM_ENDPOINT_PAIRS=12 ### # define UID len for memory safety (buffer gets passed as a raw ptr) diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 32881729c7a9..fe250e282751 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -17,17 +17,9 @@ INTERNAL_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 0 QSPI_FLASH_FILESYSTEM = 0 -# TODO: Test/Debug fs once USB-MSC is ready +# TODO: Test/Debug FS DISABLE_FILESYSTEM = 0 -# TODO: Test/Debug TinyUSB! -# CIRCUITPY_TINYUSB = 1 -# CIRCUITPY_USB_DEVICE ?= 1 -# CIRCUITPY_USB_CDC ?= 1 -# CIRCUITPY_USB_VENDOR ?=1 -# CIRCUITPY_USB_HID ?= 0 -# CIRCUITPY_USB_MIDI ?= 0 - #################################################################################### # Suggested config for first-time porting #################################################################################### diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index e64184c000bb..dd20d2a70fff 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -92,6 +92,11 @@ size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t * descriptor_buf[MSC_IN_ENDPOINT_INDEX] = 0x80 | (USB_MSC_EP_NUM_IN ? USB_MSC_EP_NUM_IN : descriptor_counts->current_endpoint); descriptor_counts->num_in_endpoints++; + // Some TinyUSB devices have issues with bi-directional endpoints + #ifdef TUD_ENDPOINT_ONE_DIRECTION_ONLY + descriptor_counts->current_endpoint++; + #endif + descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = USB_MSC_EP_NUM_OUT ? USB_MSC_EP_NUM_OUT : descriptor_counts->current_endpoint; descriptor_counts->num_out_endpoints++; diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 502d8fa620e0..0248c0f180fd 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -192,6 +192,11 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *desc ? (USB_CDC_EP_NUM_DATA_IN ? USB_CDC_EP_NUM_DATA_IN : descriptor_counts->current_endpoint) : (USB_CDC2_EP_NUM_DATA_IN ? USB_CDC2_EP_NUM_DATA_IN : descriptor_counts->current_endpoint)); descriptor_counts->num_in_endpoints++; + // Some TinyUSB devices have issues with bi-directional endpoints + #ifdef TUD_ENDPOINT_ONE_DIRECTION_ONLY + descriptor_counts->current_endpoint++; + #endif + descriptor_buf[CDC_DATA_OUT_ENDPOINT_INDEX] = console ? (USB_CDC_EP_NUM_DATA_OUT ? USB_CDC_EP_NUM_DATA_OUT : descriptor_counts->current_endpoint) diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index b007bc3ac2d4..4d0d5fc2e3d5 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -172,6 +172,12 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *desc descriptor_buf[HID_IN_ENDPOINT_INDEX] = 0x80 | (USB_HID_EP_NUM_IN ? USB_HID_EP_NUM_IN : descriptor_counts->current_endpoint); descriptor_counts->num_in_endpoints++; + + // Some TinyUSB devices have issues with bi-directional endpoints + #ifdef TUD_ENDPOINT_ONE_DIRECTION_ONLY + descriptor_counts->current_endpoint++; + #endif + descriptor_buf[HID_OUT_ENDPOINT_INDEX] = USB_HID_EP_NUM_OUT ? USB_HID_EP_NUM_OUT : descriptor_counts->current_endpoint; descriptor_counts->num_out_endpoints++; diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index e0853e4e2a7a..3808801ff7e1 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -176,6 +176,12 @@ size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *des descriptor_buf[MIDI_STREAMING_IN_ENDPOINT_INDEX] = 0x80 | (USB_MIDI_EP_NUM_IN ? USB_MIDI_EP_NUM_IN : descriptor_counts->current_endpoint); descriptor_counts->num_in_endpoints++; + + // Some TinyUSB devices have issues with bi-directional endpoints + #ifdef TUD_ENDPOINT_ONE_DIRECTION_ONLY + descriptor_counts->current_endpoint++; + #endif + descriptor_buf[MIDI_STREAMING_OUT_ENDPOINT_INDEX] = USB_MIDI_EP_NUM_OUT ? USB_MIDI_EP_NUM_OUT : descriptor_counts->current_endpoint; descriptor_counts->num_out_endpoints++; From 66916551620811037eb9f5578c903a4eccadba94 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Thu, 5 Sep 2024 17:48:38 -0600 Subject: [PATCH 225/252] - Fixed USB issues. REPL & CIRCUITPY: drive now function correctly! - Fixed bugs with Internal Flash filesystem. Files now write & read back correctly. - Added copyright headers for all files. --- ports/analog/Makefile | 1 + ports/analog/README.md | 12 +- ports/analog/background.c | 1 + ports/analog/background.h | 1 + ports/analog/boards/APARD/README.md | 22 ++ ports/analog/boards/APARD/board.c | 4 +- ports/analog/boards/APARD/mpconfigboard.h | 23 +- ports/analog/boards/APARD/mpconfigboard.mk | 1 + ports/analog/boards/APARD/pins.c | 1 + ports/analog/common-hal/microcontroller/Pin.c | 5 + ports/analog/common-hal/microcontroller/Pin.h | 5 + .../common-hal/microcontroller/Processor.c | 6 +- .../common-hal/microcontroller/__init__.c | 1 + ports/analog/linking/max32690_cktpy.ld | 10 +- ports/analog/max32_port.h | 5 + ports/analog/mpconfigport.mk | 6 +- ports/analog/mphalport.c | 5 + ports/analog/mphalport.h | 2 +- ports/analog/peripherals/led.h | 5 + ports/analog/peripherals/max32690/pins.c | 6 + ports/analog/peripherals/max32690/pins.h | 6 + ports/analog/peripherals/pins.h | 6 +- ports/analog/supervisor/cpu.s | 7 + ports/analog/supervisor/internal_flash.c | 215 +++++++----------- ports/analog/supervisor/internal_flash.h | 6 + ports/analog/supervisor/serial.c | 51 +++-- ports/analog/supervisor/usb.c | 10 +- 27 files changed, 243 insertions(+), 180 deletions(-) create mode 100644 ports/analog/peripherals/led.h diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 7c3e1cb80117..072d9f866219 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -1,6 +1,7 @@ # This file is part of the CircuitPython project: https://circuitpython.org # # SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. # # SPDX-License-Identifier: MIT diff --git a/ports/analog/README.md b/ports/analog/README.md index 1650fad1cac5..e2bd38b66472 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -38,7 +38,9 @@ Universal instructions on flashing MAX32 devices this project can be found in th In addition, a user may flash the device by calling `make` with the `flash-msdk` target from within the `ports/analog` directory, as below: - $ make BOARD= flash-msdk +``` +$ make BOARD= flash-msdk +``` This requires the following: - A MAX32625PICO is connected to the PC via USB @@ -48,4 +50,10 @@ This requires the following: ### Using the REPL -[**Section in Progress. USB support needs implementation & test.**] +Once the device is plugged in, it will enumerate via USB as both a USB Serial Device (CDC) and a Mass Storage Device (MSC). You can connect to the Python REPL with your favorite Serial Monitor program e.g. TeraTerm, VS Code, Putty, etc. Use any buadrate with 8-bit, No Parity, 1 Stop Bit (8N1) settings. From this point forward, you can run Python code on the MCU! If you want help with learning CircuitPython-specific code or learning Python in general, a good place to start is Adafruit's ["Welcome to CircuitPython"](https://learn.adafruit.com/welcome-to-circuitpython/) guide. + +### Editing code.py + +Python code may be executed from `code.py` the `CIRCUITPY:` drive. When editing this file, please be aware that some text editors will work better than others. A list of suggested text editors can be found at Adafruit's guide here: https://learn.adafruit.com/welcome-to-circuitpython/recommended-editors + +Once you save `code.py`, it gets written back to the device you are running Circuitpython on, and will automatically run and output it's result to the REPL. You can also automatically reload and run code.py any time from the REPL by pressing CTRL+D. diff --git a/ports/analog/background.c b/ports/analog/background.c index 8dad8c4e351d..ad3063b7feb9 100644 --- a/ports/analog/background.c +++ b/ports/analog/background.c @@ -1,6 +1,7 @@ // This file is part of the CircuitPython project: https://circuitpython.org // // SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. // // SPDX-License-Identifier: MIT diff --git a/ports/analog/background.h b/ports/analog/background.h index 8fbe98bd9d8e..d32f2b0dc2c3 100644 --- a/ports/analog/background.h +++ b/ports/analog/background.h @@ -1,6 +1,7 @@ // This file is part of the CircuitPython project: https://circuitpython.org // // SPDX-FileCopyrightText: Copyright (c) 2019 Dan Halbert for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. // // SPDX-License-Identifier: MIT diff --git a/ports/analog/boards/APARD/README.md b/ports/analog/boards/APARD/README.md index 8768ed93d56d..04f28ca4502b 100644 --- a/ports/analog/boards/APARD/README.md +++ b/ports/analog/boards/APARD/README.md @@ -12,3 +12,25 @@ For more info about AD-APARD32690-SL, visit our product webpages for datasheets, [AD-APARD32690-SL Product Webpage](https://www.analog.com/en/resources/evaluation-hardware-and-software/evaluation-boards-kits/ad-apard32690-sl.html) [AD-APARD32690-SL User Guide](https://wiki.analog.com/resources/eval/user-guides/ad-apard32690-sl) + +#### Building for this board + +To build for this board, ensure you are in the `ports/analog` directory and run the following command. Note that passing in the `-jN` flag, where N is the # of cores on your machine, can speed up compile times. + +``` +make BOARD=APARD +``` + +#### Flashing this board + +To flash the board, run the following command if using the MAX32625PICO: + +``` +make BOARD=APARD flash-msdk +``` + +If using Segger JLink, please run the following command instead: + +``` +make BOARD=APARD flash-jlink +``` diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/APARD/board.c index 972bdcee6f8c..c24ff5a08e83 100644 --- a/ports/analog/boards/APARD/board.c +++ b/ports/analog/boards/APARD/board.c @@ -1,6 +1,6 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc // // SPDX-License-Identifier: MIT @@ -26,7 +26,7 @@ const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); // DEFAULT: Using the weak-defined supervisor/shared/board.c functions -/***** OPTIONAL BOARD-SPECIFIC FUNTIONS from supervisor/board.h *****/ +/***** OPTIONAL BOARD-SPECIFIC FUNCTIONS from supervisor/board.h *****/ // Returns true if the user initiates safe mode in a board specific way. // Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific // way. diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/APARD/mpconfigboard.h index 87baa0120994..972ca72abeba 100644 --- a/ports/analog/boards/APARD/mpconfigboard.h +++ b/ports/analog/boards/APARD/mpconfigboard.h @@ -1,6 +1,7 @@ // This file is part of the CircuitPython project: https://circuitpython.org // // SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices Inc. // // SPDX-License-Identifier: MIT @@ -20,18 +21,18 @@ #define FLASH_SIZE (0x300000) // 3MiB #define FLASH_PAGE_SIZE (0x4000) // 16384 byte pages (16 KiB) -#define BOARD_HAS_CRYSTAL 1 +#define BOARD_HAS_CRYSTAL 1 +#define NUM_GPIO_PORTS 4 +#define CONSOLE_UART MXC_UART0 -#define NUM_GPIO_PORTS 4 - -#if INTERNAL_FLASH_FILESYSTEM -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102FC000) // for MAX32690 -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (64 * 1024) // 64K +// #if INTERNAL_FLASH_FILESYSTEM +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102E0000) // for MAX32690 +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (128 * 1024) // 64K #define MAX32_FLASH_SIZE 0x300000 // 3 MiB -#define INTERNAL_FLASH_FILESYSTEM_SIZE 0x10000 // 64KiB -#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102FC000 // Load into the last MiB of code/data storage +#define INTERNAL_FLASH_FILESYSTEM_SIZE CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102E0000 // Load into the last MiB of code/data storage -#else -#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) -#endif +// #else +// #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) +// #endif diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/APARD/mpconfigboard.mk index cbd2e97d9058..7cc54ccfc6dd 100644 --- a/ports/analog/boards/APARD/mpconfigboard.mk +++ b/ports/analog/boards/APARD/mpconfigboard.mk @@ -1,6 +1,7 @@ # This file is part of the CircuitPython project: https://circuitpython.org # # SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc # # SPDX-License-Identifier: MIT diff --git a/ports/analog/boards/APARD/pins.c b/ports/analog/boards/APARD/pins.c index ddd2afdafe58..89bc41832751 100644 --- a/ports/analog/boards/APARD/pins.c +++ b/ports/analog/boards/APARD/pins.c @@ -1,6 +1,7 @@ // This file is part of the CircuitPython project: https://circuitpython.org // // SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. // // SPDX-License-Identifier: MIT diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index e11c9413c907..65949045cdcc 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -1,3 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #include diff --git a/ports/analog/common-hal/microcontroller/Pin.h b/ports/analog/common-hal/microcontroller/Pin.h index 55d4081f3a6b..169586e7e903 100644 --- a/ports/analog/common-hal/microcontroller/Pin.h +++ b/ports/analog/common-hal/microcontroller/Pin.h @@ -1,3 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #pragma once diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c index 339770f9fd24..e28388e58596 100644 --- a/ports/analog/common-hal/microcontroller/Processor.c +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -1,4 +1,8 @@ - +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #include #include "py/runtime.h" diff --git a/ports/analog/common-hal/microcontroller/__init__.c b/ports/analog/common-hal/microcontroller/__init__.c index aff2dc2fd497..bbdb686195ca 100644 --- a/ports/analog/common-hal/microcontroller/__init__.c +++ b/ports/analog/common-hal/microcontroller/__init__.c @@ -2,6 +2,7 @@ // // SPDX-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries // SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc // // SPDX-License-Identifier: MIT diff --git a/ports/analog/linking/max32690_cktpy.ld b/ports/analog/linking/max32690_cktpy.ld index e80a14d53c90..9b32121a135a 100644 --- a/ports/analog/linking/max32690_cktpy.ld +++ b/ports/analog/linking/max32690_cktpy.ld @@ -1,9 +1,15 @@ +/** This file is part of the CircuitPython project: https://circuitpython.org +* +* SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices Inc. +* +* SPDX-License-Identifier: MIT +*/ + MEMORY { ROM (rx) : ORIGIN = 0x00000000, LENGTH = 128K FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 3M FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 2992K - FLASH_ISR (rx) : ORIGIN = 0x102EC000, LENGTH = 16K - FLASH_FS (rx) : ORIGIN = 0x102FC000, LENGTH = 64K + FLASH_FS (rx) : ORIGIN = 0x102E0000, LENGTH = 128K RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 1M } /* Minimum flash page is 16K */ diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index 214e975b719b..0ded32e5b820 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -1,3 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT #ifndef MAX32_PORT_H #define MAX32_PORT_H diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index fe250e282751..60b18a5249a2 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -1,6 +1,7 @@ # This file is part of the CircuitPython project: https://circuitpython.org # # SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. # # SPDX-License-Identifier: MIT @@ -14,11 +15,6 @@ INTERNAL_LIBM ?= 1 CFLAGS += -DHAS_TRNG=1 INTERNAL_FLASH_FILESYSTEM = 1 -SPI_FLASH_FILESYSTEM = 0 -QSPI_FLASH_FILESYSTEM = 0 - -# TODO: Test/Debug FS -DISABLE_FILESYSTEM = 0 #################################################################################### # Suggested config for first-time porting diff --git a/ports/analog/mphalport.c b/ports/analog/mphalport.c index d4e63ec67393..8f305d6325e5 100644 --- a/ports/analog/mphalport.c +++ b/ports/analog/mphalport.c @@ -1,3 +1,8 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #include "mphalport.h" #include "py/mphal.h" diff --git a/ports/analog/mphalport.h b/ports/analog/mphalport.h index 5efd78736e78..3cd3e00c6e18 100644 --- a/ports/analog/mphalport.h +++ b/ports/analog/mphalport.h @@ -1,6 +1,6 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc // // SPDX-License-Identifier: MIT diff --git a/ports/analog/peripherals/led.h b/ports/analog/peripherals/led.h new file mode 100644 index 000000000000..ff05be051bb2 --- /dev/null +++ b/ports/analog/peripherals/led.h @@ -0,0 +1,5 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT diff --git a/ports/analog/peripherals/max32690/pins.c b/ports/analog/peripherals/max32690/pins.c index 4f26d9d1f6d6..b6c4e993553b 100644 --- a/ports/analog/peripherals/max32690/pins.c +++ b/ports/analog/peripherals/max32690/pins.c @@ -1,3 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT + #include "py/obj.h" #include "py/mphal.h" #include "peripherals/pins.h" diff --git a/ports/analog/peripherals/max32690/pins.h b/ports/analog/peripherals/max32690/pins.h index 9b5cc303ee5c..44022decdf71 100644 --- a/ports/analog/peripherals/max32690/pins.h +++ b/ports/analog/peripherals/max32690/pins.h @@ -1,3 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT + #pragma once extern const mcu_pin_obj_t pin_P0_00; diff --git a/ports/analog/peripherals/pins.h b/ports/analog/peripherals/pins.h index ae471dc29e18..313addc1f205 100644 --- a/ports/analog/peripherals/pins.h +++ b/ports/analog/peripherals/pins.h @@ -1,4 +1,8 @@ - +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT #pragma once diff --git a/ports/analog/supervisor/cpu.s b/ports/analog/supervisor/cpu.s index 9e6807a5e2e9..7cb8291045f1 100644 --- a/ports/analog/supervisor/cpu.s +++ b/ports/analog/supervisor/cpu.s @@ -1,3 +1,10 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT + .syntax unified .cpu cortex-m4 .thumb diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c index 97fe21d4a52c..2b9b51967734 100644 --- a/ports/analog/supervisor/internal_flash.c +++ b/ports/analog/supervisor/internal_flash.c @@ -1,8 +1,16 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George +// SPDX-FileCopyrightText: Copyright (c) 2020 Lucian Copeland for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT #include "supervisor/internal_flash.h" #include #include +#include #include "extmod/vfs.h" #include "extmod/vfs_fat.h" @@ -14,20 +22,19 @@ #include "supervisor/filesystem.h" #include "supervisor/flash.h" #include "supervisor/shared/safe_mode.h" - #if CIRCUITPY_USB_DEVICE #include "supervisor/usb.h" #endif +#include "mpconfigboard.h" + // MAX32 HAL Includes #include "flc.h" #include "flc_reva.h" #include "icc.h" // includes icc_.c for MSDK die type #include "mxc_device.h" -/** TODO: - * Test! - * +/** * NOTE: * ANY function which modifies flash contents must execute from a crit section. * This is because FLC functions are loc'd in RAM, and an ISR executing @@ -44,13 +51,10 @@ * Therefore only ICC0 need be used for the purpose of these functions. */ -#define NO_CACHE 0xffffffff -#define MAX_CACHE 0x4000 - typedef struct { - uint32_t base_addr; - uint32_t sector_size; - uint32_t num_sectors; + const uint32_t base_addr; + const uint32_t sector_size; + const uint32_t num_sectors; } flash_layout_t; #ifdef MAX32690 @@ -58,15 +62,15 @@ typedef struct { // FS Code will use INTERNAL_FLASH_FILESYSTEM_START_ADDR // and won't conflict with ISR vector in first 16 KiB of flash static const flash_layout_t flash_layout[] = { - { 0x10000000, 0x4000, 192}, + { 0x10000000, FLASH_PAGE_SIZE, 192}, // { 0x10300000, 0x2000, 32 }, // RISC-V flash }; -// Cache a full 16K sector -static uint8_t _flash_cache[0x4000] __attribute__((aligned(4))); -#endif +// must be able to hold a full page (for re-writing upon erase) +static uint32_t page_buffer[FLASH_PAGE_SIZE / 4] = {0x0}; -// Address of the flash sector currently being cached -static uint32_t _cache_addr_in_flash = NO_CACHE; +#else +#error "Invalid BOARD. Please set BOARD equal to any board under 'boards/'." +#endif static inline int32_t block2addr(uint32_t block) { if (block >= 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { @@ -135,150 +139,100 @@ uint32_t supervisor_flash_get_block_count(void) { return INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS; } -// Write back to Flash the page that is currently cached void port_internal_flash_flush(void) { - // Flash has not been cached - if (_cache_addr_in_flash == NO_CACHE) { - return; - } - uint32_t sector_start, sector_size = 0xffffffff; - - // Clear & enable flash interrupt flags - MXC_FLC_EnableInt(MXC_F_FLC_INTR_DONEIE | MXC_F_FLC_INTR_AFIE); - - // Figure out the sector of flash we're targeting - if (flash_get_sector_info(_cache_addr_in_flash, §or_start, §or_size) == -1) { - // If not in valid sector, just release the cache and return - supervisor_flash_release_cache(); - return; - } - - // if invalid sector or sector size > the size of our cache, reset with flash fail - if (sector_size > sizeof(_flash_cache) || sector_start == 0xffffffff) { - reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); - } - - // skip if the data in cache is the same as what's already there - if (memcmp(_flash_cache, (void *)_cache_addr_in_flash, FLASH_PAGE_SIZE) != 0) { - uint32_t error; - - // buffer for the page of flash - uint32_t page_buffer[FLASH_PAGE_SIZE >> 2] = { - 0xFFFFFFFF - }; // bytes per page / 4 bytes = # of uint32_t - - // Unlock Flash - MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_UNLOCKED; - - /*** ERASE FLASH PAGE ***/ - MXC_CRITICAL( - // buffer the page - MXC_FLC_Read(sector_start, page_buffer, sector_size); - // Erase page & error check - error = MXC_FLC_PageErase(sector_start); - ); - if (error != E_NO_ERROR) { - // lock flash & reset - MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; - reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); - } - /*** RE-WRITE FLASH PAGE w/ CACHE DATA ***/ - MXC_CRITICAL( - // ret = program the flash page with cache data (for loop) - for (uint32_t i = 0; i < (sector_size >> 2); i++) { - error = MXC_FLC_Write32(_cache_addr_in_flash + 4 * i, _flash_cache[i]); - } - ); - if (error != E_NO_ERROR) { - // lock flash & reset - MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; - reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); - } + // Flush all instruction cache + // ME18 has bug where top-level sysctrl flush bit only works one. + // Have to use low-level flush bits for each ICC instance. + MXC_ICC_Flush(MXC_ICC0); + MXC_ICC_Flush(MXC_ICC1); - // Lock flash & exit - MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; - } // finished flushing cache - // todo: verify no other flash operation (e.g. flushing HW cache) is needed to complete this + // Clear the line fill buffer by reading 2 pages from flash + volatile uint32_t *line_addr; + volatile uint32_t line; + line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE); + line = *line_addr; + line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE + MXC_FLASH_PAGE_SIZE); + line = *line_addr; + (void)line; // Silence build warnings that this variable is not used. } // Read flash blocks, using cache if it contains the right data +// return 0 on success, non-zero on error mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { // Find the address of the block we want to read int src_addr = block2addr(block); if (src_addr == -1) { // bad block num - return false; + return 1; } uint32_t sector_size, sector_start; if (flash_get_sector_info(src_addr, §or_start, §or_size) == -1) { // bad sector idx - return false; + return 2; } - // Find how many blocks left in sector - uint32_t blocks_in_sector = (sector_size - (src_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; - - // If the whole read is inside the cache, then read cache - if ( (num_blocks <= blocks_in_sector) && (_cache_addr_in_flash == sector_start) ) { - memcpy(dest, (_flash_cache + (src_addr - sector_start)), FILESYSTEM_BLOCK_SIZE * num_blocks); - } else { - // flush the cache & read the flash data directly - supervisor_flash_flush(); - /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking - * than memcpy does. Will use it for now. - */ - MXC_FLC_Read((int)dest, (int *)src_addr, FILESYSTEM_BLOCK_SIZE * num_blocks); - } + /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking + * than memcpy does. Will use it for now. + */ + MXC_FLC_Read( src_addr, dest, FILESYSTEM_BLOCK_SIZE * num_blocks ); + return 0; // success } -// Write to flash blocks, using cache if it is targeting the right page (and large enough) -// todo: most of this fn is taken from the ST driver. -// todo: look at other ports and see if I can adapt it at all +// Write to flash blocks +// return 0 on success, non-zero on error mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { - uint32_t count=0; - uint32_t sector_size=0; - uint32_t sector_start=0; + uint32_t error, blocks_left, count, page_start, page_size = 0; while (num_blocks > 0) { - const int32_t dest_addr = block2addr(block_num); + uint32_t dest_addr = block2addr(block_num); // bad block number passed in if (dest_addr == -1) { - return false; - } - - // Implementation is from STM port - // NOTE: May replace later, but this port had a method - // that seemed to make sense across multiple devices. - if (flash_get_sector_info(dest_addr, §or_start, §or_size) == -1) { - reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + return 1; } - // fail if sector size is greater than cache size - if (sector_size > sizeof(_flash_cache)) { + if (flash_get_sector_info(dest_addr, &page_start, &page_size) == -1) { reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); } // Find the number of blocks left within this sector - // BLOCK_NUM = (SECTOR SIZE - BLOCK OFFSET within sector)) / BLOCK_SIZE - count = (sector_size - (dest_addr - sector_start)) / FILESYSTEM_BLOCK_SIZE; - count = MIN(num_blocks, count); + // BLOCKS_LEFT = (SECTOR_SIZE - BLOCK_OFFSET within sector)) / BLOCK_SIZE + blocks_left = (page_size - (dest_addr - page_start)) / FILESYSTEM_BLOCK_SIZE; + count = MIN(num_blocks, blocks_left); - // if we're not at the start of a sector, copy the whole sector to cache - if (_cache_addr_in_flash != sector_start) { - // Flush cache first before we overwrite it - supervisor_flash_flush(); + MXC_ICC_Disable(MXC_ICC0); - _cache_addr_in_flash = sector_start; + // Buffer the page of flash to erase + MXC_FLC_Read(page_start , page_buffer, page_size); - // Copy the whole sector into cache - memcpy(_flash_cache, (void *)sector_start, sector_size); + // Erase flash page + MXC_CRITICAL( + error = MXC_FLC_PageErase(dest_addr); + ); + if (error != E_NO_ERROR) { + // lock flash & reset + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); } - // Overwrite the cache with source data passed in - memcpy(_flash_cache + (dest_addr - sector_start), src, count * FILESYSTEM_BLOCK_SIZE); + // Copy new src data into the page buffer + // fill the new data in at the offset dest_addr - page_start + // account for uint32_t page_buffer vs uint8_t src + memcpy( (page_buffer + (dest_addr - page_start) / 4), src, count * FILESYSTEM_BLOCK_SIZE); + + // Write new page buffer back into flash + MXC_CRITICAL( + error = MXC_FLC_Write(page_start, page_size, page_buffer); + ); + if (error != E_NO_ERROR) { + // lock flash & reset + MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + + MXC_ICC_Enable(MXC_ICC0); block_num += count; src += count * FILESYSTEM_BLOCK_SIZE; @@ -289,18 +243,5 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, // Empty the fs cache void supervisor_flash_release_cache(void) { - // Invalidate the current FS cache - _cache_addr_in_flash = NO_CACHE; - - // Flush the hardware cache for ARM M4 - MXC_ICC_Flush(MXC_ICC0); - - // Clear the line fill buffer by reading 2 pages from flash - volatile uint32_t *line_addr; - volatile uint32_t line; - line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE); - line = *line_addr; - line_addr = (uint32_t *)(MXC_FLASH_MEM_BASE + MXC_FLASH_PAGE_SIZE); - line = *line_addr; - (void)line; // Silence build warnings that this variable is not used. + supervisor_flash_flush(); } diff --git a/ports/analog/supervisor/internal_flash.h b/ports/analog/supervisor/internal_flash.h index 1b4091e9a4fd..cc25f80be770 100644 --- a/ports/analog/supervisor/internal_flash.h +++ b/ports/analog/supervisor/internal_flash.h @@ -1,3 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT #pragma once diff --git a/ports/analog/supervisor/serial.c b/ports/analog/supervisor/serial.c index 7f485a35204c..871e6cd0fe72 100644 --- a/ports/analog/supervisor/serial.c +++ b/ports/analog/supervisor/serial.c @@ -2,6 +2,7 @@ // // SPDX-FileCopyrightText: Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries // SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) Brandon Hurst, Analog Devices, Inc. // // SPDX-License-Identifier: MIT @@ -9,25 +10,24 @@ #include #include "supervisor/shared/serial.h" +#include "uart.h" +#include "uart_regs.h" + +#ifndef MAX32_SERIAL #define MAX32_SERIAL 0 +#endif #if MAX32_SERIAL -// TODO: Switch this to using DEBUG_UART. +#ifdef MAX32690 +#define CONSOLE_UART MXC_UART0 +#endif #endif void port_serial_init(void) { #if MAX32_SERIAL - // huart2.Instance = USART2; - // huart2.Init.BaudRate = 115200; - // huart2.Init.WordLength = UART_WORDLENGTH_8B; - // huart2.Init.StopBits = UART_STOPBITS_1; - // huart2.Init.Parity = UART_PARITY_NONE; - // huart2.Init.Mode = UART_MODE_TX_RX; - // huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - // huart2.Init.OverSampling = UART_OVERSAMPLING_16; - // if (HAL_UART_Init(&huart2) == HAL_OK) { - // stm32f4_peripherals_status_led(1, 1); - // } + MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_IBRO_EN; + while( !(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_IBRO_RDY) ); + MXC_UART_Init(CONSOLE_UART, 115200, MXC_UART_IBRO_CLK); #endif } @@ -40,15 +40,27 @@ char port_serial_read(void) { // uint8_t data; // HAL_UART_Receive(&huart2, &data, 1, 500); // return data; + uint8_t rData; + + mxc_uart_req_t uart_req = { + .uart = CONSOLE_UART, + .rxCnt = 0, + .txCnt = 0, + .txData = NULL, + .rxData = &rData, + .txLen = 0, + .rxLen = 1 + }; + MXC_UART_Transaction(&uart_req); + return rData; #else return -1; #endif } -// There is no easy way to find the number of pending characters, so just say there's 1. uint32_t port_serial_bytes_available(void) { #if MAX32_SERIAL - // return __HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) ? 1 : 0; + return MXC_UART_GetRXFIFOAvailable(CONSOLE_UART); #else return 0; #endif @@ -56,6 +68,15 @@ uint32_t port_serial_bytes_available(void) { void port_serial_write_substring(const char *text, uint32_t len) { #if MAX32_SERIAL - // HAL_UART_Transmit(&huart2, (uint8_t *)text, len, 5000); + mxc_uart_req_t uart_req = { + .uart = CONSOLE_UART, + .rxCnt = 0, + .txCnt = 0, + .txData = (const unsigned char *)text, + .rxData = NULL, + .txLen = len, + .rxLen = 0 + }; + MXC_UART_Transaction(&uart_req); #endif } diff --git a/ports/analog/supervisor/usb.c b/ports/analog/supervisor/usb.c index 2fd1545bdb1b..f156669ad386 100644 --- a/ports/analog/supervisor/usb.c +++ b/ports/analog/supervisor/usb.c @@ -1,3 +1,9 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2018 hathach for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT #include "supervisor/usb.h" #include "common-hal/microcontroller/Pin.h" @@ -16,7 +22,6 @@ void init_usb_hardware(void) { // No need to add them to the never_reset list for mcu/Pin API. // 1 ms SysTick initialized in board.c - // todo: consider moving SysTick initialization here? // Enable requisite clocks & power for USB MXC_SYS_ClockSourceEnable(MXC_SYS_CLOCK_IPO); @@ -26,10 +31,9 @@ void init_usb_hardware(void) { // Supervisor calls TinyUSB's dcd_init, // which initializes the USB PHY. - // Dep. on CIRCUITPY_TINYUSB and CIRCUITPY_USB_DEVICE + // Depending on CIRCUITPY_TINYUSB and CIRCUITPY_USB_DEVICE // Interrupt enables are left to TUSB depending on the device class - // todo: confirm with testing! } void USB_IRQHandler(void) From 298bce304af3e8a3f2e8cf80be549b8102fae82c Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Sun, 22 Sep 2024 09:48:11 -0600 Subject: [PATCH 226/252] Added digitalio module. --- ports/analog/boards/APARD/mpconfigboard.h | 2 +- ports/analog/boards/APARD/pins.c | 216 +++++----- .../common-hal/digitalio/DigitalInOut.c | 201 +++++++++ .../common-hal/digitalio/DigitalInOut.h | 15 + ports/analog/common-hal/digitalio/__init__.c | 7 + ports/analog/common-hal/microcontroller/Pin.c | 45 +- .../common-hal/microcontroller/__init__.c | 404 +++++++++--------- ports/analog/mpconfigport.mk | 2 +- ports/analog/peripherals/max32690/pins.c | 220 +++++----- ports/analog/peripherals/pins.h | 22 +- 10 files changed, 678 insertions(+), 456 deletions(-) create mode 100644 ports/analog/common-hal/digitalio/DigitalInOut.c create mode 100644 ports/analog/common-hal/digitalio/DigitalInOut.h create mode 100644 ports/analog/common-hal/digitalio/__init__.c diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/APARD/mpconfigboard.h index 972ca72abeba..0e09a4ede674 100644 --- a/ports/analog/boards/APARD/mpconfigboard.h +++ b/ports/analog/boards/APARD/mpconfigboard.h @@ -22,7 +22,7 @@ #define FLASH_PAGE_SIZE (0x4000) // 16384 byte pages (16 KiB) #define BOARD_HAS_CRYSTAL 1 -#define NUM_GPIO_PORTS 4 +#define NUM_GPIO_PORTS 5 #define CONSOLE_UART MXC_UART0 // #if INTERNAL_FLASH_FILESYSTEM diff --git a/ports/analog/boards/APARD/pins.c b/ports/analog/boards/APARD/pins.c index 89bc41832751..5b736385dc58 100644 --- a/ports/analog/boards/APARD/pins.c +++ b/ports/analog/boards/APARD/pins.c @@ -10,117 +10,117 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS //P0 - { MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_P0_00) }, - { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_P0_01) }, - { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_P0_02) }, - { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_P0_03) }, - { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_P0_04) }, - { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_P0_05) }, - { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_P0_06) }, - { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_P0_07) }, - { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_P0_08) }, - { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_P0_09) }, - { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_P0_10) }, - { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_P0_11) }, - { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_P0_12) }, - { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_P0_13) }, - { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_P0_14) }, - { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_P0_15) }, - { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_P0_16) }, - { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_P0_17) }, - { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_P0_18) }, - { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_P0_19) }, - { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_P0_20) }, - { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_P0_21) }, - { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_P0_22) }, - { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_P0_23) }, - { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_P0_24) }, - { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_P0_25) }, - { MP_ROM_QSTR(MP_QSTR_PA26), MP_ROM_PTR(&pin_P0_26) }, - { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_P0_27) }, - { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_P0_28) }, - { MP_ROM_QSTR(MP_QSTR_PA29), MP_ROM_PTR(&pin_P0_29) }, - { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_P0_30) }, - { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_P0_31) }, + { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) }, + { MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) }, + { MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) }, + { MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) }, + { MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) }, + { MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) }, + { MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) }, + { MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) }, + { MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) }, + { MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) }, + { MP_ROM_QSTR(MP_QSTR_P0_26), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) }, + { MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, //P1 - { MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_P1_00) }, - { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_P1_01) }, - { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_P1_02) }, - { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_P1_03) }, - { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_P1_04) }, - { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_P1_05) }, - { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_P1_06) }, - { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_P1_07) }, - { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_P1_08) }, - { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_P1_09) }, - { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_P1_10) }, - { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_P1_11) }, - { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_P1_12) }, - { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_P1_13) }, - { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_P1_14) }, - { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_P1_15) }, - { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_P1_16) }, - { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_P1_17) }, - { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_P1_18) }, - { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_P1_19) }, - { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_P1_20) }, - { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_P1_21) }, - { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_P1_22) }, - { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_P1_23) }, - { MP_ROM_QSTR(MP_QSTR_PB24), MP_ROM_PTR(&pin_P1_24) }, - { MP_ROM_QSTR(MP_QSTR_PB25), MP_ROM_PTR(&pin_P1_25) }, - { MP_ROM_QSTR(MP_QSTR_PB26), MP_ROM_PTR(&pin_P1_26) }, - { MP_ROM_QSTR(MP_QSTR_PB27), MP_ROM_PTR(&pin_P1_27) }, - { MP_ROM_QSTR(MP_QSTR_PB28), MP_ROM_PTR(&pin_P1_28) }, - { MP_ROM_QSTR(MP_QSTR_PB29), MP_ROM_PTR(&pin_P1_29) }, - { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_P1_30) }, - { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_P1_31) }, + { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, + { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, + { MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) }, + { MP_ROM_QSTR(MP_QSTR_P1_14), MP_ROM_PTR(&pin_P1_14) }, + { MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_P1_16), MP_ROM_PTR(&pin_P1_16) }, + { MP_ROM_QSTR(MP_QSTR_P1_17), MP_ROM_PTR(&pin_P1_17) }, + { MP_ROM_QSTR(MP_QSTR_P1_18), MP_ROM_PTR(&pin_P1_18) }, + { MP_ROM_QSTR(MP_QSTR_P1_19), MP_ROM_PTR(&pin_P1_19) }, + { MP_ROM_QSTR(MP_QSTR_P1_20), MP_ROM_PTR(&pin_P1_20) }, + { MP_ROM_QSTR(MP_QSTR_P1_21), MP_ROM_PTR(&pin_P1_21) }, + { MP_ROM_QSTR(MP_QSTR_P1_22), MP_ROM_PTR(&pin_P1_22) }, + { MP_ROM_QSTR(MP_QSTR_P1_23), MP_ROM_PTR(&pin_P1_23) }, + { MP_ROM_QSTR(MP_QSTR_P1_24), MP_ROM_PTR(&pin_P1_24) }, + { MP_ROM_QSTR(MP_QSTR_P1_25), MP_ROM_PTR(&pin_P1_25) }, + { MP_ROM_QSTR(MP_QSTR_P1_26), MP_ROM_PTR(&pin_P1_26) }, + { MP_ROM_QSTR(MP_QSTR_P1_27), MP_ROM_PTR(&pin_P1_27) }, + { MP_ROM_QSTR(MP_QSTR_P1_28), MP_ROM_PTR(&pin_P1_28) }, + { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, + { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, + { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, //P2 - { MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_P2_00) }, - { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_P2_01) }, - { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_P2_02) }, - { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_P2_03) }, - { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_P2_04) }, - { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_P2_05) }, - { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_P2_06) }, - { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_P2_07) }, - { MP_ROM_QSTR(MP_QSTR_PC08), MP_ROM_PTR(&pin_P2_08) }, - { MP_ROM_QSTR(MP_QSTR_PC09), MP_ROM_PTR(&pin_P2_09) }, - { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_P2_10) }, - { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_P2_11) }, - { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_P2_12) }, - { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_P2_13) }, - { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_P2_14) }, - { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_P2_15) }, - { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_P2_16) }, - { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_P2_17) }, - { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_P2_18) }, - { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_P2_19) }, - { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_P2_20) }, - { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_P2_21) }, - { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_P2_22) }, - { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_P2_23) }, - { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_P2_24) }, - { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_P2_25) }, - { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_P2_26) }, - { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_P2_27) }, - { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_P2_28) }, - { MP_ROM_QSTR(MP_QSTR_PC29), MP_ROM_PTR(&pin_P2_29) }, - { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_P2_30) }, - { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_P2_31) }, + { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_P2_08), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_P2_09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, + { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, + { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, + { MP_ROM_QSTR(MP_QSTR_P2_13), MP_ROM_PTR(&pin_P2_13) }, + { MP_ROM_QSTR(MP_QSTR_P2_14), MP_ROM_PTR(&pin_P2_14) }, + { MP_ROM_QSTR(MP_QSTR_P2_15), MP_ROM_PTR(&pin_P2_15) }, + { MP_ROM_QSTR(MP_QSTR_P2_16), MP_ROM_PTR(&pin_P2_16) }, + { MP_ROM_QSTR(MP_QSTR_P2_17), MP_ROM_PTR(&pin_P2_17) }, + { MP_ROM_QSTR(MP_QSTR_P2_18), MP_ROM_PTR(&pin_P2_18) }, + { MP_ROM_QSTR(MP_QSTR_P2_19), MP_ROM_PTR(&pin_P2_19) }, + { MP_ROM_QSTR(MP_QSTR_P2_20), MP_ROM_PTR(&pin_P2_20) }, + { MP_ROM_QSTR(MP_QSTR_P2_21), MP_ROM_PTR(&pin_P2_21) }, + { MP_ROM_QSTR(MP_QSTR_P2_22), MP_ROM_PTR(&pin_P2_22) }, + { MP_ROM_QSTR(MP_QSTR_P2_23), MP_ROM_PTR(&pin_P2_23) }, + { MP_ROM_QSTR(MP_QSTR_P2_24), MP_ROM_PTR(&pin_P2_24) }, + { MP_ROM_QSTR(MP_QSTR_P2_25), MP_ROM_PTR(&pin_P2_25) }, + { MP_ROM_QSTR(MP_QSTR_P2_26), MP_ROM_PTR(&pin_P2_26) }, + { MP_ROM_QSTR(MP_QSTR_P2_27), MP_ROM_PTR(&pin_P2_27) }, + { MP_ROM_QSTR(MP_QSTR_P2_28), MP_ROM_PTR(&pin_P2_28) }, + { MP_ROM_QSTR(MP_QSTR_P2_29), MP_ROM_PTR(&pin_P2_29) }, + { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, + { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, //P3 - { MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_P3_00) }, - { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_P3_01) }, - { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_P3_02) }, - { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_P3_03) }, - { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_P3_04) }, - { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_P3_05) }, - { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_P3_06) }, - { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_P3_07) }, - { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_P3_08) }, - { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_P3_09) }, + { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, //P4 - { MP_ROM_QSTR(MP_QSTR_PE00), MP_ROM_PTR(&pin_P4_00) }, - { MP_ROM_QSTR(MP_QSTR_PE01), MP_ROM_PTR(&pin_P4_01) }, + { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c new file mode 100644 index 000000000000..59a242239e0d --- /dev/null +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -0,0 +1,201 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/Pin.h" + +#include "gpio_reva.h" + +extern mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS]; + +void common_hal_digitalio_digitalinout_never_reset( + digitalio_digitalinout_obj_t *self) { + common_hal_never_reset_pin(self->pin); +} + +bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) { + return self->pin == NULL; +} + +digitalinout_result_t common_hal_digitalio_digitalinout_construct( + digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) { + + common_hal_mcu_pin_claim(pin); + self->pin = pin; + + mxc_gpio_cfg_t new_gpio_cfg = { + .port = gpio_ports[self->pin->port], + .mask = (self->pin->mask), + .vssel = self->pin->level, + .func = MXC_GPIO_FUNC_IN, + .drvstr = MXC_GPIO_DRVSTR_0, + .pad = MXC_GPIO_PAD_NONE, + }; + MXC_GPIO_Config(&new_gpio_cfg); + + return DIGITALINOUT_OK; +} + +void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) { + if (common_hal_digitalio_digitalinout_deinited(self)) { + return; + } + + reset_pin_number(self->pin->port, self->pin->mask); + self->pin = NULL; +} + +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) +{ + mxc_gpio_regs_t* port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); + return common_hal_digitalio_digitalinout_set_pull(self, pull); +} + +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( + digitalio_digitalinout_obj_t *self, bool value, + digitalio_drive_mode_t drive_mode) +{ + mxc_gpio_regs_t* port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); + common_hal_digitalio_digitalinout_set_value(self, value); + + // todo (low): MSDK Hardware does not support open-drain configuration except + // todo (low): when directly managed by a peripheral such as I2C. + // todo (low): find a way to signal this perhaps to any upstream code + if (drive_mode != DRIVE_MODE_PUSH_PULL) { + return DIGITALINOUT_OK; + } + return DIGITALINOUT_OK; +} + +digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( + digitalio_digitalinout_obj_t *self) { + + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + // Check that I/O mode is enabled and we don't have in AND out on at the same time + MP_STATIC_ASSERT(!( (port->en0 & mask) && (port->inen & mask) && (port->outen & mask) )); + + if ( (port->en0 & mask) && (port->outen & mask) ) + { + return DIRECTION_OUTPUT; + } + else if ( (port->en0 & mask) && (port->inen & mask) ) + { + return DIRECTION_INPUT; + } + + // do not try to drive a pin which has an odd configuration here + else return DIRECTION_INPUT; +} + +void common_hal_digitalio_digitalinout_set_value( + digitalio_digitalinout_obj_t *self, bool value) +{ + digitalio_direction_t dir = + common_hal_digitalio_digitalinout_get_direction(self); + + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + if (dir == DIRECTION_OUTPUT) { + if (value == true) { + MXC_GPIO_OutSet(port, mask); + } + else { + MXC_GPIO_OutClr(port, mask); + } + } +} + +bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self) +{ + digitalio_direction_t dir = + common_hal_digitalio_digitalinout_get_direction(self); + + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + if (dir == DIRECTION_INPUT) { + return (MXC_GPIO_InGet(port, mask)); + } + else { + return ( (port->out & mask) == true); + } +} + +digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( + digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) { + + // On MAX32, drive mode is not configurable + // and should always be push-pull unless managed by a peripheral like I2C + return DIGITALINOUT_OK; +} + +digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( + digitalio_digitalinout_obj_t *self) { + return DRIVE_MODE_PUSH_PULL; +} + +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; + + if ( (port->en0 & mask) && (port->inen & mask) ) { + // PULL_NONE, PULL_UP, or PULL_DOWN + switch (pull) { + case PULL_NONE: + port->padctrl0 &= ~(mask); + port->padctrl1 &= ~(mask); + break; + case PULL_UP: + port->padctrl0 |= mask; + port->padctrl1 &= ~(mask); + break; + case PULL_DOWN: + port->padctrl0 &= ~(mask); + port->padctrl1 |= mask; + break; + default: + break; + } + return DIGITALINOUT_OK; + } + else { + return DIGITALINOUT_PIN_BUSY; + } +} + +digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( + digitalio_digitalinout_obj_t *self) { + + bool pin_padctrl0 = (gpio_ports[self->pin->port]->padctrl0) & ( self->pin->mask); + bool pin_padctrl1 = (gpio_ports[self->pin->port]->padctrl1) & ( self->pin->mask); + + if ( (pin_padctrl0) && !(pin_padctrl1) ) { + return PULL_UP; + } + else if ( !(pin_padctrl0) && pin_padctrl1 ) { + return PULL_DOWN; + } + else if ( !(pin_padctrl0) && !(pin_padctrl1) ) { + return PULL_NONE; + } + + // Shouldn't happen, (value 0b11 is reserved) + else { + return PULL_NONE; + } +} diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.h b/ports/analog/common-hal/digitalio/DigitalInOut.h new file mode 100644 index 000000000000..f58b23832b19 --- /dev/null +++ b/ports/analog/common-hal/digitalio/DigitalInOut.h @@ -0,0 +1,15 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#include "common-hal/microcontroller/Pin.h" + +typedef struct { + mp_obj_base_t base; + const mcu_pin_obj_t *pin; +} digitalio_digitalinout_obj_t; diff --git a/ports/analog/common-hal/digitalio/__init__.c b/ports/analog/common-hal/digitalio/__init__.c new file mode 100644 index 000000000000..fa222ed01f03 --- /dev/null +++ b/ports/analog/common-hal/digitalio/__init__.c @@ -0,0 +1,7 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Adafruit Industries LLC +// +// SPDX-License-Identifier: MIT + +// No digitalio module functions. diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 65949045cdcc..7259c0effe8a 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -11,17 +11,20 @@ #include "pins.h" #include "mxc_sys.h" -#include "max32690.h" #include "gpio.h" #include "gpio_regs.h" -// Structs to represent GPIO ports & valid pins/pads +#include "common-hal/microcontroller/Pin.h" + +static uint32_t claimed_pins[NUM_GPIO_PORTS]; + +// todo (low): try moving this to an extern in the board support #ifdef MAX32690 -// todo: special constraints are applied to GPIO4 for MAX32690. Tend to these later (low prior) -static mxc_gpio_regs_t* ports[NUM_GPIO_PORTS] = { MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3}; +#include "max32690.h" +mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = + {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; #endif -static uint32_t claimed_pins[NUM_GPIO_PORTS]; static uint32_t never_reset_pins[NUM_GPIO_PORTS]; #define INVALID_PIN 0xFF // id for invalid pin @@ -48,25 +51,25 @@ void reset_pin_number(uint8_t pin_port, uint8_t pin_pad) { /** START: RESET LOGIC for GPIOs */ // Switch to I/O mode first - ports[pin_port]->en0_set = mask; + gpio_ports[pin_port]->en0_set = mask; // set GPIO configuration enable bits to I/O - ports[pin_port]->en0_clr = mask; - ports[pin_port]->en1_clr = mask; - ports[pin_port]->en2_clr = mask; + gpio_ports[pin_port]->en0_clr = mask; + gpio_ports[pin_port]->en1_clr = mask; + gpio_ports[pin_port]->en2_clr = mask; // enable input mode GPIOn_INEN.pin = 1 - ports[pin_port]->inen |= mask; + gpio_ports[pin_port]->inen |= mask; // High Impedance mode enable (GPIOn_PADCTRL1 = 0, _PADCTRL0 = 0), pu/pd disable - ports[pin_port]->padctrl0 &= ~mask; - ports[pin_port]->padctrl1 &= ~mask; + gpio_ports[pin_port]->padctrl0 &= ~mask; + gpio_ports[pin_port]->padctrl1 &= ~mask; // Output mode disable GPIOn_OUTEN = 0 - ports[pin_port]->outen |= mask; + gpio_ports[pin_port]->outen |= mask; // Interrupt disable GPIOn_INTEN = 0 - ports[pin_port]->inten &= ~mask; + gpio_ports[pin_port]->inten &= ~mask; /** END: RESET LOGIC for GPIOs */ } @@ -77,22 +80,22 @@ uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { // most max32 gpio ports have 32 pins // todo: create a struct to encode # of pins for each port, since some GPIO ports differ - return pin->port * 32 + pin->pad; + return pin->port * 32 + pin->mask; } bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { if (pin == NULL) { return true; } - return !(claimed_pins[pin->port] & (pin->pad)); + return !(claimed_pins[pin->port] & (pin->mask)); } void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { - if ((pin != NULL) && (pin->pad != INVALID_PIN)) { - never_reset_pins[pin->port] |= (1 << pin->pad); + if ((pin != NULL) && (pin->mask != INVALID_PIN)) { + never_reset_pins[pin->port] |= (1 << pin->mask); // any never reset pin must also be claimed - claimed_pins[pin->port] |= (1 << pin->pad); + claimed_pins[pin->port] |= (1 << pin->mask); } } @@ -101,14 +104,14 @@ void common_hal_reset_pin(const mcu_pin_obj_t *pin) { return; } - reset_pin_number(pin->port, pin->pad); + reset_pin_number(pin->port, pin->mask); } void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { if (pin == NULL) { return; } - claimed_pins[pin->port] |= (1 << pin->pad); + claimed_pins[pin->port] |= (1 << pin->mask); } void common_hal_mcu_pin_reset_number(uint8_t pin_no) { diff --git a/ports/analog/common-hal/microcontroller/__init__.c b/ports/analog/common-hal/microcontroller/__init__.c index bbdb686195ca..207ddbe52f37 100644 --- a/ports/analog/common-hal/microcontroller/__init__.c +++ b/ports/analog/common-hal/microcontroller/__init__.c @@ -1,10 +1,10 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries -// SPDX-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries -// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// SP3_X-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries +// SP3_X-FileCopyrightText: Copyright (c) 2019 Lucian Copeland for Adafruit Industries +// SP3_X-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc // -// SPDX-License-Identifier: MIT +// SP3_X-License-Identifier: MIT #include "py/mphal.h" #include "py/obj.h" @@ -89,306 +89,306 @@ const mcu_processor_obj_t common_hal_mcu_processor_obj = { // This maps MCU pin names to pin objects. static const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { - #if defined(PIN_PA01) && !defined(IGNORE_PIN_PA01) - { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) }, + #if defined(PIN_P0_01) && !defined(IGNORE_PIN_P0_01) + { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, #endif - #if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02) - { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) }, + #if defined(PIN_P0_02) && !defined(IGNORE_PIN_P0_02) + { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, #endif - #if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03) - { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) }, + #if defined(PIN_P0_03) && !defined(IGNORE_PIN_P0_03) + { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, #endif - #if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04) - { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) }, + #if defined(PIN_P0_04) && !defined(IGNORE_PIN_P0_04) + { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, #endif - #if defined(PIN_PA05) && !defined(IGNORE_PIN_PA05) - { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) }, + #if defined(PIN_P0_05) && !defined(IGNORE_PIN_P0_05) + { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, #endif - #if defined(PIN_PA06) && !defined(IGNORE_PIN_PA06) - { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) }, + #if defined(PIN_P0_06) && !defined(IGNORE_PIN_P0_06) + { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, #endif - #if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07) - { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) }, + #if defined(PIN_P0_07) && !defined(IGNORE_PIN_P0_07) + { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, #endif - #if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) - { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) }, + #if defined(PIN_P0_08) && !defined(IGNORE_PIN_P0_08) + { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, #endif - #if defined(PIN_PA09) && !defined(IGNORE_PIN_PA09) - { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) }, + #if defined(PIN_P0_09) && !defined(IGNORE_PIN_P0_09) + { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, #endif - #if defined(PIN_PA10) && !defined(IGNORE_PIN_PA10) - { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) }, + #if defined(PIN_P0_10) && !defined(IGNORE_PIN_P0_10) + { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, #endif - #if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11) - { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) }, + #if defined(PIN_P0_11) && !defined(IGNORE_PIN_P0_11) + { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, #endif - #if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12) - { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) }, + #if defined(PIN_P0_12) && !defined(IGNORE_PIN_P0_12) + { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, #endif - #if defined(PIN_PA13) && !defined(IGNORE_PIN_PA13) - { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) }, + #if defined(PIN_P0_13) && !defined(IGNORE_PIN_P0_13) + { MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) }, #endif - #if defined(PIN_PA14) && !defined(IGNORE_PIN_PA14) - { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) }, + #if defined(PIN_P0_14) && !defined(IGNORE_PIN_P0_14) + { MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) }, #endif - #if defined(PIN_PA15) && !defined(IGNORE_PIN_PA15) - { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) }, + #if defined(PIN_P0_15) && !defined(IGNORE_PIN_P0_15) + { MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) }, #endif - #if defined(PIN_PA16) && !defined(IGNORE_PIN_PA16) - { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_PA16) }, + #if defined(PIN_P0_16) && !defined(IGNORE_PIN_P0_16) + { MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) }, #endif - #if defined(PIN_PA17) && !defined(IGNORE_PIN_PA17) - { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_PA17) }, + #if defined(PIN_P0_17) && !defined(IGNORE_PIN_P0_17) + { MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) }, #endif - #if defined(PIN_PA18) && !defined(IGNORE_PIN_PA18) - { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_PA18) }, + #if defined(PIN_P0_18) && !defined(IGNORE_PIN_P0_18) + { MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) }, #endif - #if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19) - { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) }, + #if defined(PIN_P0_19) && !defined(IGNORE_PIN_P0_19) + { MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) }, #endif - #if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20) - { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) }, + #if defined(PIN_P0_20) && !defined(IGNORE_PIN_P0_20) + { MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) }, #endif - #if defined(PIN_PA21) && !defined(IGNORE_PIN_PA21) - { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_PA21) }, + #if defined(PIN_P0_21) && !defined(IGNORE_PIN_P0_21) + { MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) }, #endif - #if defined(PIN_PA22) && !defined(IGNORE_PIN_PA22) - { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_PA22) }, + #if defined(PIN_P0_22) && !defined(IGNORE_PIN_P0_22) + { MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) }, #endif - #if defined(PIN_PA23) && !defined(IGNORE_PIN_PA23) - { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_PA23) }, + #if defined(PIN_P0_23) && !defined(IGNORE_PIN_P0_23) + { MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) }, #endif - #if defined(PIN_PA24) && !defined(IGNORE_PIN_PA24) - { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_PA24) }, + #if defined(PIN_P0_24) && !defined(IGNORE_PIN_P0_24) + { MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) }, #endif - #if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25) - { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) }, + #if defined(PIN_P0_25) && !defined(IGNORE_PIN_P0_25) + { MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) }, #endif - #if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27) - { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) }, + #if defined(PIN_P0_27) && !defined(IGNORE_PIN_P0_27) + { MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) }, #endif - #if defined(PIN_PA28) && !defined(IGNORE_PIN_PA28) - { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_PA28) }, + #if defined(PIN_P0_28) && !defined(IGNORE_PIN_P0_28) + { MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) }, #endif - #if defined(PIN_PA30) && !defined(IGNORE_PIN_PA30) - { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_PA30) }, + #if defined(PIN_P0_30) && !defined(IGNORE_PIN_P0_30) + { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, #endif - #if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31) - { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) }, + #if defined(PIN_P0_31) && !defined(IGNORE_PIN_P0_31) + { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, #endif - #if defined(PIN_PB01) && !defined(IGNORE_PIN_PB01) - { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) }, + #if defined(PIN_P1_01) && !defined(IGNORE_PIN_P1_01) + { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, #endif - #if defined(PIN_PB02) && !defined(IGNORE_PIN_PB02) - { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) }, + #if defined(PIN_P1_02) && !defined(IGNORE_PIN_P1_02) + { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, #endif - #if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03) - { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }, + #if defined(PIN_P1_03) && !defined(IGNORE_PIN_P1_03) + { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, #endif - #if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04) - { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) }, + #if defined(PIN_P1_04) && !defined(IGNORE_PIN_P1_04) + { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, #endif - #if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05) - { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) }, + #if defined(PIN_P1_05) && !defined(IGNORE_PIN_P1_05) + { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, #endif - #if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06) - { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) }, + #if defined(PIN_P1_06) && !defined(IGNORE_PIN_P1_06) + { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, #endif - #if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07) - { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) }, + #if defined(PIN_P1_07) && !defined(IGNORE_PIN_P1_07) + { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, #endif - #if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08) - { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) }, + #if defined(PIN_P1_08) && !defined(IGNORE_PIN_P1_08) + { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, #endif - #if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09) - { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) }, + #if defined(PIN_P1_09) && !defined(IGNORE_PIN_P1_09) + { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, #endif - #if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10) - { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) }, + #if defined(PIN_P1_10) && !defined(IGNORE_PIN_P1_10) + { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, #endif - #if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11) - { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) }, + #if defined(PIN_P1_11) && !defined(IGNORE_PIN_P1_11) + { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, #endif - #if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12) - { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) }, + #if defined(PIN_P1_12) && !defined(IGNORE_PIN_P1_12) + { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, #endif - #if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13) - { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) }, + #if defined(PIN_P1_13) && !defined(IGNORE_PIN_P1_13) + { MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) }, #endif - #if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14) - { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) }, + #if defined(PIN_P1_14) && !defined(IGNORE_PIN_P1_14) + { MP_ROM_QSTR(MP_QSTR_P1_14), MP_ROM_PTR(&pin_P1_14) }, #endif - #if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15) - { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) }, + #if defined(PIN_P1_15) && !defined(IGNORE_PIN_P1_15) + { MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) }, #endif - #if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16) - { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) }, + #if defined(PIN_P1_16) && !defined(IGNORE_PIN_P1_16) + { MP_ROM_QSTR(MP_QSTR_P1_16), MP_ROM_PTR(&pin_P1_16) }, #endif - #if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17) - { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) }, + #if defined(PIN_P1_17) && !defined(IGNORE_PIN_P1_17) + { MP_ROM_QSTR(MP_QSTR_P1_17), MP_ROM_PTR(&pin_P1_17) }, #endif - #if defined(PIN_PB18) && !defined(IGNORE_PIN_PB18) - { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_PB18) }, + #if defined(PIN_P1_18) && !defined(IGNORE_PIN_P1_18) + { MP_ROM_QSTR(MP_QSTR_P1_18), MP_ROM_PTR(&pin_P1_18) }, #endif - #if defined(PIN_PB19) && !defined(IGNORE_PIN_PB19) - { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_PB19) }, + #if defined(PIN_P1_19) && !defined(IGNORE_PIN_P1_19) + { MP_ROM_QSTR(MP_QSTR_P1_19), MP_ROM_PTR(&pin_P1_19) }, #endif - #if defined(PIN_PB20) && !defined(IGNORE_PIN_PB20) - { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_PB20) }, + #if defined(PIN_P1_20) && !defined(IGNORE_PIN_P1_20) + { MP_ROM_QSTR(MP_QSTR_P1_20), MP_ROM_PTR(&pin_P1_20) }, #endif - #if defined(PIN_PB21) && !defined(IGNORE_PIN_PB21) - { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_PB21) }, + #if defined(PIN_P1_21) && !defined(IGNORE_PIN_P1_21) + { MP_ROM_QSTR(MP_QSTR_P1_21), MP_ROM_PTR(&pin_P1_21) }, #endif - #if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22) - { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) }, + #if defined(PIN_P1_22) && !defined(IGNORE_PIN_P1_22) + { MP_ROM_QSTR(MP_QSTR_P1_22), MP_ROM_PTR(&pin_P1_22) }, #endif - #if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23) - { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) }, + #if defined(PIN_P1_23) && !defined(IGNORE_PIN_P1_23) + { MP_ROM_QSTR(MP_QSTR_P1_23), MP_ROM_PTR(&pin_P1_23) }, #endif - #if defined(PIN_PB24) && !defined(IGNORE_PIN_PB24) - { MP_ROM_QSTR(MP_QSTR_PB24), MP_ROM_PTR(&pin_PB24) }, + #if defined(PIN_P1_24) && !defined(IGNORE_PIN_P1_24) + { MP_ROM_QSTR(MP_QSTR_P1_24), MP_ROM_PTR(&pin_P1_24) }, #endif - #if defined(PIN_PB25) && !defined(IGNORE_PIN_PB25) - { MP_ROM_QSTR(MP_QSTR_PB25), MP_ROM_PTR(&pin_PB25) }, + #if defined(PIN_P1_25) && !defined(IGNORE_PIN_P1_25) + { MP_ROM_QSTR(MP_QSTR_P1_25), MP_ROM_PTR(&pin_P1_25) }, #endif - #if defined(PIN_PB26) && !defined(IGNORE_PIN_PB26) - { MP_ROM_QSTR(MP_QSTR_PB26), MP_ROM_PTR(&pin_PB26) }, + #if defined(PIN_P1_26) && !defined(IGNORE_PIN_P1_26) + { MP_ROM_QSTR(MP_QSTR_P1_26), MP_ROM_PTR(&pin_P1_26) }, #endif - #if defined(PIN_PB27) && !defined(IGNORE_PIN_PB27) - { MP_ROM_QSTR(MP_QSTR_PB27), MP_ROM_PTR(&pin_PB27) }, + #if defined(PIN_P1_27) && !defined(IGNORE_PIN_P1_27) + { MP_ROM_QSTR(MP_QSTR_P1_27), MP_ROM_PTR(&pin_P1_27) }, #endif - #if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28) - { MP_ROM_QSTR(MP_QSTR_PB28), MP_ROM_PTR(&pin_PB28) }, + #if defined(PIN_P1_28) && !defined(IGNORE_PIN_P1_28) + { MP_ROM_QSTR(MP_QSTR_P1_28), MP_ROM_PTR(&pin_P1_28) }, #endif - #if defined(PIN_PB29) && !defined(IGNORE_PIN_PB29) - { MP_ROM_QSTR(MP_QSTR_PB29), MP_ROM_PTR(&pin_PB29) }, + #if defined(PIN_P1_29) && !defined(IGNORE_PIN_P1_29) + { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, #endif - #if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30) - { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) }, + #if defined(PIN_P1_30) && !defined(IGNORE_PIN_P1_30) + { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, #endif - #if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31) - { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) }, + #if defined(PIN_P1_31) && !defined(IGNORE_PIN_P1_31) + { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, #endif - #if defined(PIN_PC01) && !defined(IGNORE_PIN_PC01) - { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) }, + #if defined(PIN_P2_01) && !defined(IGNORE_PIN_P2_01) + { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, #endif - #if defined(PIN_PC02) && !defined(IGNORE_PIN_PC02) - { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) }, + #if defined(PIN_P2_02) && !defined(IGNORE_PIN_P2_02) + { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, #endif - #if defined(PIN_PC03) && !defined(IGNORE_PIN_PC03) - { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) }, + #if defined(PIN_P2_03) && !defined(IGNORE_PIN_P2_03) + { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, #endif - #if defined(PIN_PC04) && !defined(IGNORE_PIN_PC04) - { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_PC04) }, + #if defined(PIN_P2_04) && !defined(IGNORE_PIN_P2_04) + { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, #endif - #if defined(PIN_PC05) && !defined(IGNORE_PIN_PC05) - { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) }, + #if defined(PIN_P2_05) && !defined(IGNORE_PIN_P2_05) + { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, #endif - #if defined(PIN_PC06) && !defined(IGNORE_PIN_PC06) - { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, + #if defined(PIN_P2_06) && !defined(IGNORE_PIN_P2_06) + { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, #endif - #if defined(PIN_PC07) && !defined(IGNORE_PIN_PC07) - { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, + #if defined(PIN_P2_07) && !defined(IGNORE_PIN_P2_07) + { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, #endif - #if defined(PIN_PC10) && !defined(IGNORE_PIN_PC10) - { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) }, + #if defined(PIN_P2_10) && !defined(IGNORE_PIN_P2_10) + { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, #endif - #if defined(PIN_PC11) && !defined(IGNORE_PIN_PC11) - { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) }, + #if defined(PIN_P2_11) && !defined(IGNORE_PIN_P2_11) + { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, #endif - #if defined(PIN_PC12) && !defined(IGNORE_PIN_PC12) - { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) }, + #if defined(PIN_P2_12) && !defined(IGNORE_PIN_P2_12) + { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, #endif - #if defined(PIN_PC13) && !defined(IGNORE_PIN_PC13) - { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, + #if defined(PIN_P2_13) && !defined(IGNORE_PIN_P2_13) + { MP_ROM_QSTR(MP_QSTR_P2_13), MP_ROM_PTR(&pin_P2_13) }, #endif - #if defined(PIN_PC14) && !defined(IGNORE_PIN_PC14) - { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_PC14) }, + #if defined(PIN_P2_14) && !defined(IGNORE_PIN_P2_14) + { MP_ROM_QSTR(MP_QSTR_P2_14), MP_ROM_PTR(&pin_P2_14) }, #endif - #if defined(PIN_PC15) && !defined(IGNORE_PIN_PC15) - { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_PC15) }, + #if defined(PIN_P2_15) && !defined(IGNORE_PIN_P2_15) + { MP_ROM_QSTR(MP_QSTR_P2_15), MP_ROM_PTR(&pin_P2_15) }, #endif - #if defined(PIN_PC16) && !defined(IGNORE_PIN_PC16) - { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_PC16) }, + #if defined(PIN_P2_16) && !defined(IGNORE_PIN_P2_16) + { MP_ROM_QSTR(MP_QSTR_P2_16), MP_ROM_PTR(&pin_P2_16) }, #endif - #if defined(PIN_PC17) && !defined(IGNORE_PIN_PC17) - { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_PC17) }, + #if defined(PIN_P2_17) && !defined(IGNORE_PIN_P2_17) + { MP_ROM_QSTR(MP_QSTR_P2_17), MP_ROM_PTR(&pin_P2_17) }, #endif - #if defined(PIN_PC18) && !defined(IGNORE_PIN_PC18) - { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_PC18) }, + #if defined(PIN_P2_18) && !defined(IGNORE_PIN_P2_18) + { MP_ROM_QSTR(MP_QSTR_P2_18), MP_ROM_PTR(&pin_P2_18) }, #endif - #if defined(PIN_PC19) && !defined(IGNORE_PIN_PC19) - { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_PC19) }, + #if defined(PIN_P2_19) && !defined(IGNORE_PIN_P2_19) + { MP_ROM_QSTR(MP_QSTR_P2_19), MP_ROM_PTR(&pin_P2_19) }, #endif - #if defined(PIN_PC20) && !defined(IGNORE_PIN_PC20) - { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_PC20) }, + #if defined(PIN_P2_20) && !defined(IGNORE_PIN_P2_20) + { MP_ROM_QSTR(MP_QSTR_P2_20), MP_ROM_PTR(&pin_P2_20) }, #endif - #if defined(PIN_PC21) && !defined(IGNORE_PIN_PC21) - { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_PC21) }, + #if defined(PIN_P2_21) && !defined(IGNORE_PIN_P2_21) + { MP_ROM_QSTR(MP_QSTR_P2_21), MP_ROM_PTR(&pin_P2_21) }, #endif - #if defined(PIN_PC22) && !defined(IGNORE_PIN_PC22) - { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_PC22) }, + #if defined(PIN_P2_22) && !defined(IGNORE_PIN_P2_22) + { MP_ROM_QSTR(MP_QSTR_P2_22), MP_ROM_PTR(&pin_P2_22) }, #endif - #if defined(PIN_PC23) && !defined(IGNORE_PIN_PC23) - { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_PC23) }, + #if defined(PIN_P2_23) && !defined(IGNORE_PIN_P2_23) + { MP_ROM_QSTR(MP_QSTR_P2_23), MP_ROM_PTR(&pin_P2_23) }, #endif - #if defined(PIN_PC24) && !defined(IGNORE_PIN_PC24) - { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_PC24) }, + #if defined(PIN_P2_24) && !defined(IGNORE_PIN_P2_24) + { MP_ROM_QSTR(MP_QSTR_P2_24), MP_ROM_PTR(&pin_P2_24) }, #endif - #if defined(PIN_PC25) && !defined(IGNORE_PIN_PC25) - { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_PC25) }, + #if defined(PIN_P2_25) && !defined(IGNORE_PIN_P2_25) + { MP_ROM_QSTR(MP_QSTR_P2_25), MP_ROM_PTR(&pin_P2_25) }, #endif - #if defined(PIN_PC26) && !defined(IGNORE_PIN_PC26) - { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_PC26) }, + #if defined(PIN_P2_26) && !defined(IGNORE_PIN_P2_26) + { MP_ROM_QSTR(MP_QSTR_P2_26), MP_ROM_PTR(&pin_P2_26) }, #endif - #if defined(PIN_PC27) && !defined(IGNORE_PIN_PC27) - { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_PC27) }, + #if defined(PIN_P2_27) && !defined(IGNORE_PIN_P2_27) + { MP_ROM_QSTR(MP_QSTR_P2_27), MP_ROM_PTR(&pin_P2_27) }, #endif - #if defined(PIN_PC28) && !defined(IGNORE_PIN_PC28) - { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_PC28) }, + #if defined(PIN_P2_28) && !defined(IGNORE_PIN_P2_28) + { MP_ROM_QSTR(MP_QSTR_P2_28), MP_ROM_PTR(&pin_P2_28) }, #endif - #if defined(PIN_PC30) && !defined(IGNORE_PIN_PC30) - { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_PC30) }, + #if defined(PIN_P2_30) && !defined(IGNORE_PIN_P2_30) + { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, #endif - #if defined(PIN_PC31) && !defined(IGNORE_PIN_PC31) - { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_PC31) }, + #if defined(PIN_P2_31) && !defined(IGNORE_PIN_P2_31) + { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, #endif - #if defined(PIN_PD01) && !defined(IGNORE_PIN_PD01) - { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) }, + #if defined(PIN_P3_01) && !defined(IGNORE_PIN_P3_01) + { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, #endif - #if defined(PIN_PD02) && !defined(IGNORE_PIN_PD02) - { MP_ROM_QSTR(MP_QSTR_PD02), MP_ROM_PTR(&pin_PD02) }, + #if defined(PIN_P3_02) && !defined(IGNORE_PIN_P3_02) + { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, #endif - #if defined(PIN_PD03) && !defined(IGNORE_PIN_PD03) - { MP_ROM_QSTR(MP_QSTR_PD03), MP_ROM_PTR(&pin_PD03) }, + #if defined(PIN_P3_03) && !defined(IGNORE_PIN_P3_03) + { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, #endif - #if defined(PIN_PD04) && !defined(IGNORE_PIN_PD04) - { MP_ROM_QSTR(MP_QSTR_PD04), MP_ROM_PTR(&pin_PD04) }, + #if defined(PIN_P3_04) && !defined(IGNORE_PIN_P3_04) + { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, #endif - #if defined(PIN_PD05) && !defined(IGNORE_PIN_PD05) - { MP_ROM_QSTR(MP_QSTR_PD05), MP_ROM_PTR(&pin_PD05) }, + #if defined(PIN_P3_05) && !defined(IGNORE_PIN_P3_05) + { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, #endif - #if defined(PIN_PD06) && !defined(IGNORE_PIN_PD06) - { MP_ROM_QSTR(MP_QSTR_PD06), MP_ROM_PTR(&pin_PD06) }, + #if defined(PIN_P3_06) && !defined(IGNORE_PIN_P3_06) + { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, #endif - #if defined(PIN_PD07) && !defined(IGNORE_PIN_PD07) - { MP_ROM_QSTR(MP_QSTR_PD07), MP_ROM_PTR(&pin_PD07) }, + #if defined(PIN_P3_07) && !defined(IGNORE_PIN_P3_07) + { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, #endif - #if defined(PIN_PD08) && !defined(IGNORE_PIN_PD08) - { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) }, + #if defined(PIN_P3_08) && !defined(IGNORE_PIN_P3_08) + { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, #endif - #if defined(PIN_PD09) && !defined(IGNORE_PIN_PD09) - { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) }, + #if defined(PIN_P3_09) && !defined(IGNORE_PIN_P3_09) + { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, #endif - #if defined(PIN_PE01) && !defined(IGNORE_PIN_PE01) - { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD02) }, + #if defined(PIN_P4_01) && !defined(IGNORE_PIN_P4_01) + { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_02) }, #endif - #if defined(PIN_PE02) && !defined(IGNORE_PIN_PD02) - { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD02) }, + #if defined(PIN_P4_02) && !defined(IGNORE_PIN_P4_02) + { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_02) }, #endif }; diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 60b18a5249a2..f2cc8bd7aea0 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -22,7 +22,7 @@ INTERNAL_FLASH_FILESYSTEM = 1 # These modules are implemented in ports//common-hal: # Typically the second module to create -CIRCUITPY_DIGITALIO ?= 0 +CIRCUITPY_DIGITALIO ?= 1 # Plan to implement CIRCUITPY_BUSIO ?= 0 diff --git a/ports/analog/peripherals/max32690/pins.c b/ports/analog/peripherals/max32690/pins.c index b6c4e993553b..7550dc549efa 100644 --- a/ports/analog/peripherals/max32690/pins.c +++ b/ports/analog/peripherals/max32690/pins.c @@ -7,119 +7,117 @@ #include "py/obj.h" #include "py/mphal.h" #include "peripherals/pins.h" +#include "max32690.h" -#include "gpio.h" -#include "gpio_regs.h" +const mcu_pin_obj_t pin_P0_00 = PIN(0, 0); +const mcu_pin_obj_t pin_P0_01 = PIN(0, 1); +const mcu_pin_obj_t pin_P0_02 = PIN(0, 2); +const mcu_pin_obj_t pin_P0_03 = PIN(0, 3); +const mcu_pin_obj_t pin_P0_04 = PIN(0, 4); +const mcu_pin_obj_t pin_P0_05 = PIN(0, 5); +const mcu_pin_obj_t pin_P0_06 = PIN(0, 6); +const mcu_pin_obj_t pin_P0_07 = PIN(0, 7); +const mcu_pin_obj_t pin_P0_08 = PIN(0, 8); +const mcu_pin_obj_t pin_P0_09 = PIN(0, 9); +const mcu_pin_obj_t pin_P0_10 = PIN(0, 10); +const mcu_pin_obj_t pin_P0_11 = PIN(0, 11); +const mcu_pin_obj_t pin_P0_12 = PIN(0, 12); +const mcu_pin_obj_t pin_P0_13 = PIN(0, 13); +const mcu_pin_obj_t pin_P0_14 = PIN(0, 14); +const mcu_pin_obj_t pin_P0_15 = PIN(0, 15); +const mcu_pin_obj_t pin_P0_16 = PIN(0, 16); +const mcu_pin_obj_t pin_P0_17 = PIN(0, 17); +const mcu_pin_obj_t pin_P0_18 = PIN(0, 18); +const mcu_pin_obj_t pin_P0_19 = PIN(0, 19); +const mcu_pin_obj_t pin_P0_20 = PIN(0, 20); +const mcu_pin_obj_t pin_P0_21 = PIN(0, 21); +const mcu_pin_obj_t pin_P0_22 = PIN(0, 22); +const mcu_pin_obj_t pin_P0_23 = PIN(0, 23); +const mcu_pin_obj_t pin_P0_24 = PIN(0, 24); +const mcu_pin_obj_t pin_P0_25 = PIN(0, 25); +const mcu_pin_obj_t pin_P0_26 = PIN(0, 26); +const mcu_pin_obj_t pin_P0_27 = PIN(0, 27); +const mcu_pin_obj_t pin_P0_28 = PIN(0, 28); +const mcu_pin_obj_t pin_P0_29 = PIN(0, 29); +const mcu_pin_obj_t pin_P0_30 = PIN(0, 30); +const mcu_pin_obj_t pin_P0_31 = PIN(0, 31); -const mcu_pin_obj_t pin_P0_00 = PIN(MXC_GPIO_PORT_0, 0); -const mcu_pin_obj_t pin_P0_01 = PIN(MXC_GPIO_PORT_0, 1); -const mcu_pin_obj_t pin_P0_02 = PIN(MXC_GPIO_PORT_0, 2); -const mcu_pin_obj_t pin_P0_03 = PIN(MXC_GPIO_PORT_0, 3); -const mcu_pin_obj_t pin_P0_04 = PIN(MXC_GPIO_PORT_0, 4); -const mcu_pin_obj_t pin_P0_05 = PIN(MXC_GPIO_PORT_0, 5); -const mcu_pin_obj_t pin_P0_06 = PIN(MXC_GPIO_PORT_0, 6); -const mcu_pin_obj_t pin_P0_07 = PIN(MXC_GPIO_PORT_0, 7); -const mcu_pin_obj_t pin_P0_08 = PIN(MXC_GPIO_PORT_0, 8); -const mcu_pin_obj_t pin_P0_09 = PIN(MXC_GPIO_PORT_0, 9); -const mcu_pin_obj_t pin_P0_10 = PIN(MXC_GPIO_PORT_0, 10); -const mcu_pin_obj_t pin_P0_11 = PIN(MXC_GPIO_PORT_0, 11); -const mcu_pin_obj_t pin_P0_12 = PIN(MXC_GPIO_PORT_0, 12); -const mcu_pin_obj_t pin_P0_13 = PIN(MXC_GPIO_PORT_0, 13); -const mcu_pin_obj_t pin_P0_14 = PIN(MXC_GPIO_PORT_0, 14); -const mcu_pin_obj_t pin_P0_15 = PIN(MXC_GPIO_PORT_0, 15); -const mcu_pin_obj_t pin_P0_16 = PIN(MXC_GPIO_PORT_0, 16); -const mcu_pin_obj_t pin_P0_17 = PIN(MXC_GPIO_PORT_0, 17); -const mcu_pin_obj_t pin_P0_18 = PIN(MXC_GPIO_PORT_0, 18); -const mcu_pin_obj_t pin_P0_19 = PIN(MXC_GPIO_PORT_0, 19); -const mcu_pin_obj_t pin_P0_20 = PIN(MXC_GPIO_PORT_0, 20); -const mcu_pin_obj_t pin_P0_21 = PIN(MXC_GPIO_PORT_0, 21); -const mcu_pin_obj_t pin_P0_22 = PIN(MXC_GPIO_PORT_0, 22); -const mcu_pin_obj_t pin_P0_23 = PIN(MXC_GPIO_PORT_0, 23); -const mcu_pin_obj_t pin_P0_24 = PIN(MXC_GPIO_PORT_0, 24); -const mcu_pin_obj_t pin_P0_25 = PIN(MXC_GPIO_PORT_0, 25); -const mcu_pin_obj_t pin_P0_26 = PIN(MXC_GPIO_PORT_0, 26); -const mcu_pin_obj_t pin_P0_27 = PIN(MXC_GPIO_PORT_0, 27); -const mcu_pin_obj_t pin_P0_28 = PIN(MXC_GPIO_PORT_0, 28); -const mcu_pin_obj_t pin_P0_29 = PIN(MXC_GPIO_PORT_0, 29); -const mcu_pin_obj_t pin_P0_30 = PIN(MXC_GPIO_PORT_0, 30); -const mcu_pin_obj_t pin_P0_31 = PIN(MXC_GPIO_PORT_0, 31); +const mcu_pin_obj_t pin_P1_00 = PIN(1, 0); +const mcu_pin_obj_t pin_P1_01 = PIN(1, 1); +const mcu_pin_obj_t pin_P1_02 = PIN(1, 2); +const mcu_pin_obj_t pin_P1_03 = PIN(1, 3); +const mcu_pin_obj_t pin_P1_04 = PIN(1, 4); +const mcu_pin_obj_t pin_P1_05 = PIN(1, 5); +const mcu_pin_obj_t pin_P1_06 = PIN(1, 6); +const mcu_pin_obj_t pin_P1_07 = PIN(1, 7); +const mcu_pin_obj_t pin_P1_08 = PIN(1, 8); +const mcu_pin_obj_t pin_P1_09 = PIN(1, 9); +const mcu_pin_obj_t pin_P1_10 = PIN(1, 10); +const mcu_pin_obj_t pin_P1_11 = PIN(1, 11); +const mcu_pin_obj_t pin_P1_12 = PIN(1, 12); +const mcu_pin_obj_t pin_P1_13 = PIN(1, 13); +const mcu_pin_obj_t pin_P1_14 = PIN(1, 14); +const mcu_pin_obj_t pin_P1_15 = PIN(1, 15); +const mcu_pin_obj_t pin_P1_16 = PIN(1, 16); +const mcu_pin_obj_t pin_P1_17 = PIN(1, 17); +const mcu_pin_obj_t pin_P1_18 = PIN(1, 18); +const mcu_pin_obj_t pin_P1_19 = PIN(1, 19); +const mcu_pin_obj_t pin_P1_20 = PIN(1, 20); +const mcu_pin_obj_t pin_P1_21 = PIN(1, 21); +const mcu_pin_obj_t pin_P1_22 = PIN(1, 22); +const mcu_pin_obj_t pin_P1_23 = PIN(1, 23); +const mcu_pin_obj_t pin_P1_24 = PIN(1, 24); +const mcu_pin_obj_t pin_P1_25 = PIN(1, 25); +const mcu_pin_obj_t pin_P1_26 = PIN(1, 26); +const mcu_pin_obj_t pin_P1_27 = PIN(1, 27); +const mcu_pin_obj_t pin_P1_28 = PIN(1, 28); +const mcu_pin_obj_t pin_P1_29 = PIN(1, 29); +const mcu_pin_obj_t pin_P1_30 = PIN(1, 30); +const mcu_pin_obj_t pin_P1_31 = PIN(1, 31); -const mcu_pin_obj_t pin_P1_00 = PIN(MXC_GPIO_PORT_1, 0); -const mcu_pin_obj_t pin_P1_01 = PIN(MXC_GPIO_PORT_1, 1); -const mcu_pin_obj_t pin_P1_02 = PIN(MXC_GPIO_PORT_1, 2); -const mcu_pin_obj_t pin_P1_03 = PIN(MXC_GPIO_PORT_1, 3); -const mcu_pin_obj_t pin_P1_04 = PIN(MXC_GPIO_PORT_1, 4); -const mcu_pin_obj_t pin_P1_05 = PIN(MXC_GPIO_PORT_1, 5); -const mcu_pin_obj_t pin_P1_06 = PIN(MXC_GPIO_PORT_1, 6); -const mcu_pin_obj_t pin_P1_07 = PIN(MXC_GPIO_PORT_1, 7); -const mcu_pin_obj_t pin_P1_08 = PIN(MXC_GPIO_PORT_1, 8); -const mcu_pin_obj_t pin_P1_09 = PIN(MXC_GPIO_PORT_1, 9); -const mcu_pin_obj_t pin_P1_10 = PIN(MXC_GPIO_PORT_1, 10); -const mcu_pin_obj_t pin_P1_11 = PIN(MXC_GPIO_PORT_1, 11); -const mcu_pin_obj_t pin_P1_12 = PIN(MXC_GPIO_PORT_1, 12); -const mcu_pin_obj_t pin_P1_13 = PIN(MXC_GPIO_PORT_1, 13); -const mcu_pin_obj_t pin_P1_14 = PIN(MXC_GPIO_PORT_1, 14); -const mcu_pin_obj_t pin_P1_15 = PIN(MXC_GPIO_PORT_1, 15); -const mcu_pin_obj_t pin_P1_16 = PIN(MXC_GPIO_PORT_1, 16); -const mcu_pin_obj_t pin_P1_17 = PIN(MXC_GPIO_PORT_1, 17); -const mcu_pin_obj_t pin_P1_18 = PIN(MXC_GPIO_PORT_1, 18); -const mcu_pin_obj_t pin_P1_19 = PIN(MXC_GPIO_PORT_1, 19); -const mcu_pin_obj_t pin_P1_20 = PIN(MXC_GPIO_PORT_1, 20); -const mcu_pin_obj_t pin_P1_21 = PIN(MXC_GPIO_PORT_1, 21); -const mcu_pin_obj_t pin_P1_22 = PIN(MXC_GPIO_PORT_1, 22); -const mcu_pin_obj_t pin_P1_23 = PIN(MXC_GPIO_PORT_1, 23); -const mcu_pin_obj_t pin_P1_24 = PIN(MXC_GPIO_PORT_1, 24); -const mcu_pin_obj_t pin_P1_25 = PIN(MXC_GPIO_PORT_1, 25); -const mcu_pin_obj_t pin_P1_26 = PIN(MXC_GPIO_PORT_1, 26); -const mcu_pin_obj_t pin_P1_27 = PIN(MXC_GPIO_PORT_1, 27); -const mcu_pin_obj_t pin_P1_28 = PIN(MXC_GPIO_PORT_1, 28); -const mcu_pin_obj_t pin_P1_29 = PIN(MXC_GPIO_PORT_1, 29); -const mcu_pin_obj_t pin_P1_30 = PIN(MXC_GPIO_PORT_1, 30); -const mcu_pin_obj_t pin_P1_31 = PIN(MXC_GPIO_PORT_1, 31); +const mcu_pin_obj_t pin_P2_00 = PIN(2, 0); +const mcu_pin_obj_t pin_P2_01 = PIN(2, 1); +const mcu_pin_obj_t pin_P2_02 = PIN(2, 2); +const mcu_pin_obj_t pin_P2_03 = PIN(2, 3); +const mcu_pin_obj_t pin_P2_04 = PIN(2, 4); +const mcu_pin_obj_t pin_P2_05 = PIN(2, 5); +const mcu_pin_obj_t pin_P2_06 = PIN(2, 6); +const mcu_pin_obj_t pin_P2_07 = PIN(2, 7); +const mcu_pin_obj_t pin_P2_08 = PIN(2, 8); +const mcu_pin_obj_t pin_P2_09 = PIN(2, 9); +const mcu_pin_obj_t pin_P2_10 = PIN(2, 10); +const mcu_pin_obj_t pin_P2_11 = PIN(2, 11); +const mcu_pin_obj_t pin_P2_12 = PIN(2, 12); +const mcu_pin_obj_t pin_P2_13 = PIN(2, 13); +const mcu_pin_obj_t pin_P2_14 = PIN(2, 14); +const mcu_pin_obj_t pin_P2_15 = PIN(2, 15); +const mcu_pin_obj_t pin_P2_16 = PIN(2, 16); +const mcu_pin_obj_t pin_P2_17 = PIN(2, 17); +const mcu_pin_obj_t pin_P2_18 = PIN(2, 18); +const mcu_pin_obj_t pin_P2_19 = PIN(2, 19); +const mcu_pin_obj_t pin_P2_20 = PIN(2, 20); +const mcu_pin_obj_t pin_P2_21 = PIN(2, 21); +const mcu_pin_obj_t pin_P2_22 = PIN(2, 22); +const mcu_pin_obj_t pin_P2_23 = PIN(2, 23); +const mcu_pin_obj_t pin_P2_24 = PIN(2, 24); +const mcu_pin_obj_t pin_P2_25 = PIN(2, 25); +const mcu_pin_obj_t pin_P2_26 = PIN(2, 26); +const mcu_pin_obj_t pin_P2_27 = PIN(2, 27); +const mcu_pin_obj_t pin_P2_28 = PIN(2, 28); +const mcu_pin_obj_t pin_P2_29 = PIN(2, 29); +const mcu_pin_obj_t pin_P2_30 = PIN(2, 30); +const mcu_pin_obj_t pin_P2_31 = PIN(2, 31); -const mcu_pin_obj_t pin_P2_00 = PIN(MXC_GPIO_PORT_2, 0); -const mcu_pin_obj_t pin_P2_01 = PIN(MXC_GPIO_PORT_2, 1); -const mcu_pin_obj_t pin_P2_02 = PIN(MXC_GPIO_PORT_2, 2); -const mcu_pin_obj_t pin_P2_03 = PIN(MXC_GPIO_PORT_2, 3); -const mcu_pin_obj_t pin_P2_04 = PIN(MXC_GPIO_PORT_2, 4); -const mcu_pin_obj_t pin_P2_05 = PIN(MXC_GPIO_PORT_2, 5); -const mcu_pin_obj_t pin_P2_06 = PIN(MXC_GPIO_PORT_2, 6); -const mcu_pin_obj_t pin_P2_07 = PIN(MXC_GPIO_PORT_2, 7); -const mcu_pin_obj_t pin_P2_08 = PIN(MXC_GPIO_PORT_2, 8); -const mcu_pin_obj_t pin_P2_09 = PIN(MXC_GPIO_PORT_2, 9); -const mcu_pin_obj_t pin_P2_10 = PIN(MXC_GPIO_PORT_2, 10); -const mcu_pin_obj_t pin_P2_11 = PIN(MXC_GPIO_PORT_2, 11); -const mcu_pin_obj_t pin_P2_12 = PIN(MXC_GPIO_PORT_2, 12); -const mcu_pin_obj_t pin_P2_13 = PIN(MXC_GPIO_PORT_2, 13); -const mcu_pin_obj_t pin_P2_14 = PIN(MXC_GPIO_PORT_2, 14); -const mcu_pin_obj_t pin_P2_15 = PIN(MXC_GPIO_PORT_2, 15); -const mcu_pin_obj_t pin_P2_16 = PIN(MXC_GPIO_PORT_2, 16); -const mcu_pin_obj_t pin_P2_17 = PIN(MXC_GPIO_PORT_2, 17); -const mcu_pin_obj_t pin_P2_18 = PIN(MXC_GPIO_PORT_2, 18); -const mcu_pin_obj_t pin_P2_19 = PIN(MXC_GPIO_PORT_2, 19); -const mcu_pin_obj_t pin_P2_20 = PIN(MXC_GPIO_PORT_2, 20); -const mcu_pin_obj_t pin_P2_21 = PIN(MXC_GPIO_PORT_2, 21); -const mcu_pin_obj_t pin_P2_22 = PIN(MXC_GPIO_PORT_2, 22); -const mcu_pin_obj_t pin_P2_23 = PIN(MXC_GPIO_PORT_2, 23); -const mcu_pin_obj_t pin_P2_24 = PIN(MXC_GPIO_PORT_2, 24); -const mcu_pin_obj_t pin_P2_25 = PIN(MXC_GPIO_PORT_2, 25); -const mcu_pin_obj_t pin_P2_26 = PIN(MXC_GPIO_PORT_2, 26); -const mcu_pin_obj_t pin_P2_27 = PIN(MXC_GPIO_PORT_2, 27); -const mcu_pin_obj_t pin_P2_28 = PIN(MXC_GPIO_PORT_2, 28); -const mcu_pin_obj_t pin_P2_29 = PIN(MXC_GPIO_PORT_2, 29); -const mcu_pin_obj_t pin_P2_30 = PIN(MXC_GPIO_PORT_2, 30); -const mcu_pin_obj_t pin_P2_31 = PIN(MXC_GPIO_PORT_2, 31); +const mcu_pin_obj_t pin_P3_00 = PIN(3, 0); +const mcu_pin_obj_t pin_P3_01 = PIN(3, 1); +const mcu_pin_obj_t pin_P3_02 = PIN(3, 2); +const mcu_pin_obj_t pin_P3_03 = PIN(3, 3); +const mcu_pin_obj_t pin_P3_04 = PIN(3, 4); +const mcu_pin_obj_t pin_P3_05 = PIN(3, 5); +const mcu_pin_obj_t pin_P3_06 = PIN(3, 6); +const mcu_pin_obj_t pin_P3_07 = PIN(3, 7); +const mcu_pin_obj_t pin_P3_08 = PIN(3, 8); +const mcu_pin_obj_t pin_P3_09 = PIN(3, 9); -const mcu_pin_obj_t pin_P3_00 = PIN(MXC_GPIO_PORT_3, 0); -const mcu_pin_obj_t pin_P3_01 = PIN(MXC_GPIO_PORT_3, 1); -const mcu_pin_obj_t pin_P3_02 = PIN(MXC_GPIO_PORT_3, 2); -const mcu_pin_obj_t pin_P3_03 = PIN(MXC_GPIO_PORT_3, 3); -const mcu_pin_obj_t pin_P3_04 = PIN(MXC_GPIO_PORT_3, 4); -const mcu_pin_obj_t pin_P3_05 = PIN(MXC_GPIO_PORT_3, 5); -const mcu_pin_obj_t pin_P3_06 = PIN(MXC_GPIO_PORT_3, 6); -const mcu_pin_obj_t pin_P3_07 = PIN(MXC_GPIO_PORT_3, 7); -const mcu_pin_obj_t pin_P3_08 = PIN(MXC_GPIO_PORT_3, 8); -const mcu_pin_obj_t pin_P3_09 = PIN(MXC_GPIO_PORT_3, 9); - -const mcu_pin_obj_t pin_P4_00 = PIN(MXC_GPIO_PORT_4, 0); -const mcu_pin_obj_t pin_P4_01 = PIN(MXC_GPIO_PORT_4, 1); +const mcu_pin_obj_t pin_P4_00 = PIN(4, 0); +const mcu_pin_obj_t pin_P4_01 = PIN(4, 1); diff --git a/ports/analog/peripherals/pins.h b/ports/analog/peripherals/pins.h index 313addc1f205..efee60a2962a 100644 --- a/ports/analog/peripherals/pins.h +++ b/ports/analog/peripherals/pins.h @@ -14,25 +14,23 @@ #include "py/obj.h" // HAL includes -// #include "gpio.h" +#include "gpio.h" +#include "gpio_regs.h" typedef struct { mp_obj_base_t base; - const uint8_t port; - const uint8_t pad; - // const uint8_t level : 4; // FIXME: Find how to include the VDDIO/VDDIOH level + uint8_t port; + uint32_t mask; // the pad # target e.g. P0.01 is Port=0, Mask=1 + mxc_gpio_vssel_t level; } mcu_pin_obj_t; extern const mp_obj_type_t mcu_pin_type; -#define NO_PIN (0xFF) // for non-connected pins +#define PIN(pin_port, pin_mask) { {&mcu_pin_type}, .port = pin_port, .mask = 1UL< Date: Mon, 23 Sep 2024 07:13:10 -0600 Subject: [PATCH 227/252] Added max32690 EVKIT board & changed APARD board to apard32690 --- .../boards/{APARD => apard32690}/README.md | 0 .../boards/{APARD => apard32690}/board.c | 0 .../{APARD => apard32690}/mpconfigboard.h | 0 .../{APARD => apard32690}/mpconfigboard.mk | 0 .../boards/{APARD => apard32690}/pins.c | 0 ports/analog/boards/max32690evkit/board.c | 74 ++++++++++ .../boards/max32690evkit/mpconfigboard.h | 38 ++++++ .../boards/max32690evkit/mpconfigboard.mk | 32 +++++ ports/analog/boards/max32690evkit/pins.c | 126 ++++++++++++++++++ 9 files changed, 270 insertions(+) rename ports/analog/boards/{APARD => apard32690}/README.md (100%) rename ports/analog/boards/{APARD => apard32690}/board.c (100%) rename ports/analog/boards/{APARD => apard32690}/mpconfigboard.h (100%) rename ports/analog/boards/{APARD => apard32690}/mpconfigboard.mk (100%) rename ports/analog/boards/{APARD => apard32690}/pins.c (100%) create mode 100644 ports/analog/boards/max32690evkit/board.c create mode 100644 ports/analog/boards/max32690evkit/mpconfigboard.h create mode 100644 ports/analog/boards/max32690evkit/mpconfigboard.mk create mode 100644 ports/analog/boards/max32690evkit/pins.c diff --git a/ports/analog/boards/APARD/README.md b/ports/analog/boards/apard32690/README.md similarity index 100% rename from ports/analog/boards/APARD/README.md rename to ports/analog/boards/apard32690/README.md diff --git a/ports/analog/boards/APARD/board.c b/ports/analog/boards/apard32690/board.c similarity index 100% rename from ports/analog/boards/APARD/board.c rename to ports/analog/boards/apard32690/board.c diff --git a/ports/analog/boards/APARD/mpconfigboard.h b/ports/analog/boards/apard32690/mpconfigboard.h similarity index 100% rename from ports/analog/boards/APARD/mpconfigboard.h rename to ports/analog/boards/apard32690/mpconfigboard.h diff --git a/ports/analog/boards/APARD/mpconfigboard.mk b/ports/analog/boards/apard32690/mpconfigboard.mk similarity index 100% rename from ports/analog/boards/APARD/mpconfigboard.mk rename to ports/analog/boards/apard32690/mpconfigboard.mk diff --git a/ports/analog/boards/APARD/pins.c b/ports/analog/boards/apard32690/pins.c similarity index 100% rename from ports/analog/boards/APARD/pins.c rename to ports/analog/boards/apard32690/pins.c diff --git a/ports/analog/boards/max32690evkit/board.c b/ports/analog/boards/max32690evkit/board.c new file mode 100644 index 000000000000..9a0c8278641f --- /dev/null +++ b/ports/analog/boards/max32690evkit/board.c @@ -0,0 +1,74 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" +#include "supervisor/port.h" +#include "mpconfigboard.h" +#include "max32_port.h" + +// Board-level setup for MAX32690 +// clang-format off +const mxc_gpio_cfg_t pb_pin[] = { + { MXC_GPIO4, MXC_GPIO_PIN_0, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, +}; +const int num_pbs = (sizeof(pb_pin) / sizeof(mxc_gpio_cfg_t)); + +const mxc_gpio_cfg_t led_pin[] = { + { MXC_GPIO0, MXC_GPIO_PIN_14, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, + { MXC_GPIO2, MXC_GPIO_PIN_12, MXC_GPIO_FUNC_OUT, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIO, MXC_GPIO_DRVSTR_0 }, +}; +const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); +// clang-format on + +// DEFAULT: Using the weak-defined supervisor/shared/board.c functions + +/***** OPTIONAL BOARD-SPECIFIC FUNCTIONS from supervisor/board.h *****/ +// Returns true if the user initiates safe mode in a board specific way. +// Also add BOARD_USER_SAFE_MODE in mpconfigboard.h to explain the board specific +// way. +// bool board_requests_safe_mode(void); + +volatile uint32_t system_ticks = 0; + +void SysTick_Handler(void) { + system_ticks++; +} + +uint32_t board_millis(void) { + return system_ticks; +} + +// Initializes board related state once on start up. +void board_init(void) { + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000);\ + + // Enable GPIO (enables clocks + common init for ports) + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + MXC_GPIO_Init(0x1 << i); + } + + // Init Board LEDs + /* setup GPIO for the LED */ + for (int i = 0; i < num_leds; i++) { + // Set the output value + MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); + MXC_GPIO_Config(&led_pin[i]); + } + + // Turn on one LED to indicate Sign of Life + MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); +} + +// Reset the state of off MCU components such as neopixels. +// void reset_board(void); + +// Deinit the board. This should put the board in deep sleep durable, low power +// state. It should not prevent the user access method from working (such as +// disabling USB, BLE or flash) because CircuitPython may continue to run. +// void board_deinit(void); + +/*******************************************************************/ diff --git a/ports/analog/boards/max32690evkit/mpconfigboard.h b/ports/analog/boards/max32690evkit/mpconfigboard.h new file mode 100644 index 000000000000..7ab6acf658d1 --- /dev/null +++ b/ports/analog/boards/max32690evkit/mpconfigboard.h @@ -0,0 +1,38 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices Inc. +// +// SPDX-License-Identifier: MIT + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2016 Glenn Ruben Bakke +// SPDX-FileCopyrightText: Copyright (c) 2018 Dan Halbert for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +#define MICROPY_HW_BOARD_NAME "MAX32690 EvKit" +#define MICROPY_HW_MCU_NAME "max32690" + +#define FLASH_SIZE (0x300000) // 3MiB +#define FLASH_PAGE_SIZE (0x4000) // 16384 byte pages (16 KiB) + +#define BOARD_HAS_CRYSTAL 1 +#define NUM_GPIO_PORTS 5 +#define CONSOLE_UART MXC_UART2 + +// #if INTERNAL_FLASH_FILESYSTEM +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x102E0000) // for MAX32690 +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (128 * 1024) // 64K + +#define MAX32_FLASH_SIZE 0x300000 // 3 MiB +#define INTERNAL_FLASH_FILESYSTEM_SIZE CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE +#define INTERNAL_FLASH_FILESYSTEM_START_ADDR 0x102E0000 // Load into the last MiB of code/data storage + +// #else +// #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) +// #endif diff --git a/ports/analog/boards/max32690evkit/mpconfigboard.mk b/ports/analog/boards/max32690evkit/mpconfigboard.mk new file mode 100644 index 000000000000..4e6e766df5d2 --- /dev/null +++ b/ports/analog/boards/max32690evkit/mpconfigboard.mk @@ -0,0 +1,32 @@ +# This file is part of the CircuitPython project: https://circuitpython.org +# +# SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc +# +# SPDX-License-Identifier: MIT + +MCU_SERIES=max32 +MCU_VARIANT=max32690 + +INTERNAL_FLASH_FILESYSTEM=1 +# FLASH: 0x10000000 to 0x10300000 (ARM) +# SRAM: 0x20000000 to 0x20100000 + +#### USB CONFIGURATION +# Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim +USB_VID=0x0456 +# USB_VID=0x0B6A +USB_PID=0x003C +USB_MANUFACTURER="Analog Devices, Inc." +USB_PRODUCT="MAX32690 EvKit" +USB_HIGHSPEED=1 + +# NOTE: MAX32 devices do not support IN/OUT pairs on the same EP +USB_NUM_ENDPOINT_PAIRS=12 +### + +# define UID len for memory safety (buffer gets passed as a raw ptr) +COMMON_HAL_MCU_PROCESSOR_UID_LENGTH=30 + +# NOTE: Not implementing external flash for now +# CFLAGS+=-DEXT_FLASH_MX25 diff --git a/ports/analog/boards/max32690evkit/pins.c b/ports/analog/boards/max32690evkit/pins.c new file mode 100644 index 000000000000..5b736385dc58 --- /dev/null +++ b/ports/analog/boards/max32690evkit/pins.c @@ -0,0 +1,126 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + //P0 + { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, + { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_P0_13), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_P0_14), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_P0_15), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_P0_16), MP_ROM_PTR(&pin_P0_16) }, + { MP_ROM_QSTR(MP_QSTR_P0_17), MP_ROM_PTR(&pin_P0_17) }, + { MP_ROM_QSTR(MP_QSTR_P0_18), MP_ROM_PTR(&pin_P0_18) }, + { MP_ROM_QSTR(MP_QSTR_P0_19), MP_ROM_PTR(&pin_P0_19) }, + { MP_ROM_QSTR(MP_QSTR_P0_20), MP_ROM_PTR(&pin_P0_20) }, + { MP_ROM_QSTR(MP_QSTR_P0_21), MP_ROM_PTR(&pin_P0_21) }, + { MP_ROM_QSTR(MP_QSTR_P0_22), MP_ROM_PTR(&pin_P0_22) }, + { MP_ROM_QSTR(MP_QSTR_P0_23), MP_ROM_PTR(&pin_P0_23) }, + { MP_ROM_QSTR(MP_QSTR_P0_24), MP_ROM_PTR(&pin_P0_24) }, + { MP_ROM_QSTR(MP_QSTR_P0_25), MP_ROM_PTR(&pin_P0_25) }, + { MP_ROM_QSTR(MP_QSTR_P0_26), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_P0_27), MP_ROM_PTR(&pin_P0_27) }, + { MP_ROM_QSTR(MP_QSTR_P0_28), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, + { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, + //P1 + { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, + { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, + { MP_ROM_QSTR(MP_QSTR_P1_13), MP_ROM_PTR(&pin_P1_13) }, + { MP_ROM_QSTR(MP_QSTR_P1_14), MP_ROM_PTR(&pin_P1_14) }, + { MP_ROM_QSTR(MP_QSTR_P1_15), MP_ROM_PTR(&pin_P1_15) }, + { MP_ROM_QSTR(MP_QSTR_P1_16), MP_ROM_PTR(&pin_P1_16) }, + { MP_ROM_QSTR(MP_QSTR_P1_17), MP_ROM_PTR(&pin_P1_17) }, + { MP_ROM_QSTR(MP_QSTR_P1_18), MP_ROM_PTR(&pin_P1_18) }, + { MP_ROM_QSTR(MP_QSTR_P1_19), MP_ROM_PTR(&pin_P1_19) }, + { MP_ROM_QSTR(MP_QSTR_P1_20), MP_ROM_PTR(&pin_P1_20) }, + { MP_ROM_QSTR(MP_QSTR_P1_21), MP_ROM_PTR(&pin_P1_21) }, + { MP_ROM_QSTR(MP_QSTR_P1_22), MP_ROM_PTR(&pin_P1_22) }, + { MP_ROM_QSTR(MP_QSTR_P1_23), MP_ROM_PTR(&pin_P1_23) }, + { MP_ROM_QSTR(MP_QSTR_P1_24), MP_ROM_PTR(&pin_P1_24) }, + { MP_ROM_QSTR(MP_QSTR_P1_25), MP_ROM_PTR(&pin_P1_25) }, + { MP_ROM_QSTR(MP_QSTR_P1_26), MP_ROM_PTR(&pin_P1_26) }, + { MP_ROM_QSTR(MP_QSTR_P1_27), MP_ROM_PTR(&pin_P1_27) }, + { MP_ROM_QSTR(MP_QSTR_P1_28), MP_ROM_PTR(&pin_P1_28) }, + { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, + { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, + { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, + //P2 + { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_P2_08), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_P2_09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, + { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, + { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, + { MP_ROM_QSTR(MP_QSTR_P2_13), MP_ROM_PTR(&pin_P2_13) }, + { MP_ROM_QSTR(MP_QSTR_P2_14), MP_ROM_PTR(&pin_P2_14) }, + { MP_ROM_QSTR(MP_QSTR_P2_15), MP_ROM_PTR(&pin_P2_15) }, + { MP_ROM_QSTR(MP_QSTR_P2_16), MP_ROM_PTR(&pin_P2_16) }, + { MP_ROM_QSTR(MP_QSTR_P2_17), MP_ROM_PTR(&pin_P2_17) }, + { MP_ROM_QSTR(MP_QSTR_P2_18), MP_ROM_PTR(&pin_P2_18) }, + { MP_ROM_QSTR(MP_QSTR_P2_19), MP_ROM_PTR(&pin_P2_19) }, + { MP_ROM_QSTR(MP_QSTR_P2_20), MP_ROM_PTR(&pin_P2_20) }, + { MP_ROM_QSTR(MP_QSTR_P2_21), MP_ROM_PTR(&pin_P2_21) }, + { MP_ROM_QSTR(MP_QSTR_P2_22), MP_ROM_PTR(&pin_P2_22) }, + { MP_ROM_QSTR(MP_QSTR_P2_23), MP_ROM_PTR(&pin_P2_23) }, + { MP_ROM_QSTR(MP_QSTR_P2_24), MP_ROM_PTR(&pin_P2_24) }, + { MP_ROM_QSTR(MP_QSTR_P2_25), MP_ROM_PTR(&pin_P2_25) }, + { MP_ROM_QSTR(MP_QSTR_P2_26), MP_ROM_PTR(&pin_P2_26) }, + { MP_ROM_QSTR(MP_QSTR_P2_27), MP_ROM_PTR(&pin_P2_27) }, + { MP_ROM_QSTR(MP_QSTR_P2_28), MP_ROM_PTR(&pin_P2_28) }, + { MP_ROM_QSTR(MP_QSTR_P2_29), MP_ROM_PTR(&pin_P2_29) }, + { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, + { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, + //P3 + { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, + //P4 + { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From a491986a40c19411deb2559495dc1cfc0d24d295 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Mon, 23 Sep 2024 09:30:16 -0600 Subject: [PATCH 228/252] Reordered mpconfigport.mk; replaced MXC_SYS includes with max32_port.h in microcontroller/Pin.c --- ports/analog/Makefile | 9 +++++++-- .../common-hal/digitalio/DigitalInOut.c | 5 +++-- ports/analog/common-hal/microcontroller/Pin.c | 6 ++---- ports/analog/mpconfigport.mk | 20 ++++++++----------- ports/analog/peripherals/led.h | 5 ----- ports/analog/supervisor/internal_flash.c | 2 +- ports/analog/supervisor/port.c | 6 ------ 7 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 ports/analog/peripherals/led.h diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 072d9f866219..766f0f78b930 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -147,6 +147,8 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ -DRISCV_LOAD=0 + +# todo: add these for linkerfiles later on so that it's easier to add new boards # -DFLASH_ORIGIN=0x10000000 \ # -DFLASH_SIZE=0x340000 \ # -DSRAM_ORIGIN=0x20000000 \ @@ -193,7 +195,9 @@ SRC_C += \ CFLAGS += $(INC) -Werror -Wall -std=gnu11 -nostartfiles $(BASE_CFLAGS) $(COPT) -# Suppress some warnings for MSDK +# Suppress some errors for MSDK +# cast-align warning will be suppressed; +# it gets generated by CircuitPy's TLSF memory allocator lib CFLAGS += -Wno-error=unused-parameter \ -Wno-error=old-style-declaration \ -Wno-error=sign-compare \ @@ -203,7 +207,8 @@ CFLAGS += -Wno-error=unused-parameter \ -Wno-error=lto-type-mismatch \ -Wno-error=cast-align \ -Wno-error=nested-externs \ - -Wno-error=sign-compare + -Wno-error=sign-compare \ + -Wno-cast-align \ ENTRY = Reset_Handler LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index 59a242239e0d..d23c90fdbc36 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -4,6 +4,7 @@ // // SPDX-License-Identifier: MIT +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE 1 #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/microcontroller/Pin.h" @@ -70,9 +71,9 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( // todo (low): MSDK Hardware does not support open-drain configuration except // todo (low): when directly managed by a peripheral such as I2C. - // todo (low): find a way to signal this perhaps to any upstream code + // todo (low): find a way to signal this to any upstream code if (drive_mode != DRIVE_MODE_PUSH_PULL) { - return DIGITALINOUT_OK; + return DIGITALINOUT_INVALID_DRIVE_MODE; } return DIGITALINOUT_OK; } diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 7259c0effe8a..22e3ce3899d9 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -10,9 +10,7 @@ #include "mpconfigboard.h" #include "pins.h" -#include "mxc_sys.h" -#include "gpio.h" -#include "gpio_regs.h" +#include "max32_port.h" #include "common-hal/microcontroller/Pin.h" @@ -79,7 +77,7 @@ uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { } // most max32 gpio ports have 32 pins - // todo: create a struct to encode # of pins for each port, since some GPIO ports differ + // todo (low prior.): encode # of pins for each port, since some GPIO ports differ return pin->port * 32 + pin->mask; } diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index f2cc8bd7aea0..348d61dc2892 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -21,9 +21,6 @@ INTERNAL_FLASH_FILESYSTEM = 1 #################################################################################### # These modules are implemented in ports//common-hal: -# Typically the second module to create -CIRCUITPY_DIGITALIO ?= 1 - # Plan to implement CIRCUITPY_BUSIO ?= 0 CIRCUITPY_RTC ?= 0 @@ -47,21 +44,20 @@ CIRCUITPY_DISPLAYIO ?= 0 # These modules are implemented in shared-module/ - they can be included in # any port once their prerequisites in common-hal are complete. +# No requirements, but takes extra flash +CIRCUITPY_ULAB = 1 # Requires DigitalIO: -CIRCUITPY_BITBANGIO ?= 0 -# Requires neopixel_write or SPI (dotstar) -CIRCUITPY_PIXELBUF ?= 0 +CIRCUITPY_BITBANGIO ?= 1 +# Requires Microcontroller +CIRCUITPY_TOUCHIO ?= 1 # Requires OS CIRCUITPY_RANDOM ?= 0 -# Requires Microcontroller -CIRCUITPY_TOUCHIO ?= 0 -# Requires UART +# Requires busio.UART CIRCUITPY_CONSOLE_UART ?= 0 # Does nothing without I2C CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 - -# No requirements, but takes extra flash -CIRCUITPY_ULAB = 1 +# Requires neopixel_write or SPI (dotstar) +CIRCUITPY_PIXELBUF ?= 0 #################################################################################### # Required for clean building (additional CircuittPython Defaults) diff --git a/ports/analog/peripherals/led.h b/ports/analog/peripherals/led.h deleted file mode 100644 index ff05be051bb2..000000000000 --- a/ports/analog/peripherals/led.h +++ /dev/null @@ -1,5 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2024 Brandon Hurst, Analog Devices, Inc. -// -// SPDX-License-Identifier: MIT diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c index 2b9b51967734..57dd7d8b45d4 100644 --- a/ports/analog/supervisor/internal_flash.c +++ b/ports/analog/supervisor/internal_flash.c @@ -187,7 +187,7 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t error, blocks_left, count, page_start, page_size = 0; while (num_blocks > 0) { - uint32_t dest_addr = block2addr(block_num); + int dest_addr = block2addr(block_num); // bad block number passed in if (dest_addr == -1) { return 1; diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 730d85124259..af929e074e8f 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -37,9 +37,6 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" -//todo: pack the below definitions into their own module -//todo: under peripherals/gpio, peripherals/clocks, etc. - // Sys includes #include "max32_port.h" @@ -62,9 +59,6 @@ extern const int num_pbs; extern const mxc_gpio_cfg_t led_pin[]; extern const int num_leds; -//todo: define an LED HAL -// #include "peripherals/led.h" - // For saving rtc data for ticks static uint32_t subsec, sec = 0; static uint32_t tick_flag = 0; From 66d2c95dd3936a0cc73922c805a74b6fbc37e7b7 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 08:22:33 -0700 Subject: [PATCH 229/252] Moved GPIO ports to board.c to make it easy to add boards in the future. Added priority to remaining TODOs (low) --- ports/analog/boards/apard32690/board.c | 3 +++ ports/analog/boards/max32690evkit/board.c | 3 +++ ports/analog/common-hal/microcontroller/Pin.c | 8 ++------ ports/analog/common-hal/os/__init__.c | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ports/analog/boards/apard32690/board.c b/ports/analog/boards/apard32690/board.c index c24ff5a08e83..c8751aa37e79 100644 --- a/ports/analog/boards/apard32690/board.c +++ b/ports/analog/boards/apard32690/board.c @@ -10,6 +10,9 @@ #include "max32_port.h" // Board-level setup for MAX32690 +mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = + {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; + // clang-format off const mxc_gpio_cfg_t pb_pin[] = { { MXC_GPIO1, MXC_GPIO_PIN_27, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, diff --git a/ports/analog/boards/max32690evkit/board.c b/ports/analog/boards/max32690evkit/board.c index 9a0c8278641f..924eaeafef0e 100644 --- a/ports/analog/boards/max32690evkit/board.c +++ b/ports/analog/boards/max32690evkit/board.c @@ -10,6 +10,9 @@ #include "max32_port.h" // Board-level setup for MAX32690 +mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = + {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; + // clang-format off const mxc_gpio_cfg_t pb_pin[] = { { MXC_GPIO4, MXC_GPIO_PIN_0, MXC_GPIO_FUNC_IN, MXC_GPIO_PAD_NONE, MXC_GPIO_VSSEL_VDDIOH, MXC_GPIO_DRVSTR_0}, diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 22e3ce3899d9..29befaf5e5c0 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -16,12 +16,8 @@ static uint32_t claimed_pins[NUM_GPIO_PORTS]; -// todo (low): try moving this to an extern in the board support -#ifdef MAX32690 -#include "max32690.h" -mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = - {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; -#endif +// defined in board.c +extern mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS]; static uint32_t never_reset_pins[NUM_GPIO_PORTS]; diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c index 97ce98cb9e1e..04e561e61909 100644 --- a/ports/analog/common-hal/os/__init__.c +++ b/ports/analog/common-hal/os/__init__.c @@ -43,7 +43,7 @@ mp_obj_t common_hal_os_uname(void) { bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { #if (HAS_TRNG) - //todo: implement + //todo (low prior): implement #else #endif return false; From f90f390aaae4d0fb5c07d7ae2cd5a26b4aee8743 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 08:51:06 -0700 Subject: [PATCH 230/252] Updated USB PID for max32690evkit --- ports/analog/boards/max32690evkit/mpconfigboard.mk | 2 +- tests/pyboard.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/analog/boards/max32690evkit/mpconfigboard.mk b/ports/analog/boards/max32690evkit/mpconfigboard.mk index 4e6e766df5d2..61413216d817 100644 --- a/ports/analog/boards/max32690evkit/mpconfigboard.mk +++ b/ports/analog/boards/max32690evkit/mpconfigboard.mk @@ -16,7 +16,7 @@ INTERNAL_FLASH_FILESYSTEM=1 # Use 0x0456 for Analog Devices, Inc.; 0B6A for Maxim USB_VID=0x0456 # USB_VID=0x0B6A -USB_PID=0x003C +USB_PID=0x003D USB_MANUFACTURER="Analog Devices, Inc." USB_PRODUCT="MAX32690 EvKit" USB_HIGHSPEED=1 diff --git a/tests/pyboard.py b/tests/pyboard.py index 616773a313a1..582a1f894f8b 120000 --- a/tests/pyboard.py +++ b/tests/pyboard.py @@ -1 +1 @@ -../tools/cpboard.py \ No newline at end of file +../tools/cpboard.py From 9a9660334692529f796619e1a6769ed4c6d58121 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 09:06:33 -0700 Subject: [PATCH 231/252] Formatting fixes missed by local pre-commit runner --- ports/analog/background.c | 5 +- ports/analog/boards/apard32690/board.c | 12 ++-- ports/analog/boards/apard32690/pins.c | 10 +-- ports/analog/boards/max32690evkit/board.c | 8 +-- .../common-hal/digitalio/DigitalInOut.c | 62 ++++++++----------- ports/analog/common-hal/microcontroller/Pin.c | 6 +- .../common-hal/microcontroller/Processor.c | 2 +- ports/analog/common-hal/os/__init__.c | 4 +- ports/analog/supervisor/serial.c | 6 +- ports/analog/supervisor/usb.c | 3 +- 10 files changed, 53 insertions(+), 65 deletions(-) diff --git a/ports/analog/background.c b/ports/analog/background.c index ad3063b7feb9..ffad007ffa51 100644 --- a/ports/analog/background.c +++ b/ports/analog/background.c @@ -19,7 +19,7 @@ extern const mxc_gpio_cfg_t led_pin[]; extern const int num_leds; /** NOTE: ALL "ticks" refer to a 1/1024 s period */ -static int status_led_ticks=0; +static int status_led_ticks = 0; // This function is where port-specific background // tasks should be performed @@ -28,8 +28,7 @@ void port_background_tick(void) { status_led_ticks++; // Set an LED approx. 1/s - if (status_led_ticks > 1024) - { + if (status_led_ticks > 1024) { MXC_GPIO_OutToggle(led_pin[2].port, led_pin[2].mask); status_led_ticks = 0; } diff --git a/ports/analog/boards/apard32690/board.c b/ports/analog/boards/apard32690/board.c index c8751aa37e79..3cc10de29f1e 100644 --- a/ports/analog/boards/apard32690/board.c +++ b/ports/analog/boards/apard32690/board.c @@ -10,8 +10,8 @@ #include "max32_port.h" // Board-level setup for MAX32690 -mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = - {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; +mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS] = +{MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; // clang-format off const mxc_gpio_cfg_t pb_pin[] = { @@ -38,20 +38,20 @@ const int num_leds = (sizeof(led_pin) / sizeof(mxc_gpio_cfg_t)); volatile uint32_t system_ticks = 0; void SysTick_Handler(void) { - system_ticks++; + system_ticks++; } uint32_t board_millis(void) { - return system_ticks; + return system_ticks; } // Initializes board related state once on start up. void board_init(void) { // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000);\ + SysTick_Config(SystemCoreClock / 1000); \ // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { MXC_GPIO_Init(0x1 << i); } diff --git a/ports/analog/boards/apard32690/pins.c b/ports/analog/boards/apard32690/pins.c index 5b736385dc58..0486687d3347 100644 --- a/ports/analog/boards/apard32690/pins.c +++ b/ports/analog/boards/apard32690/pins.c @@ -9,7 +9,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - //P0 + // P0 { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, @@ -42,7 +42,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) }, { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, - //P1 + // P1 { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, @@ -75,7 +75,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, - //P2 + // P2 { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, @@ -108,7 +108,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P2_29), MP_ROM_PTR(&pin_P2_29) }, { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, - //P3 + // P3 { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, @@ -119,7 +119,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, - //P4 + // P4 { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, }; diff --git a/ports/analog/boards/max32690evkit/board.c b/ports/analog/boards/max32690evkit/board.c index 924eaeafef0e..76da5c0adccb 100644 --- a/ports/analog/boards/max32690evkit/board.c +++ b/ports/analog/boards/max32690evkit/board.c @@ -10,8 +10,8 @@ #include "max32_port.h" // Board-level setup for MAX32690 -mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS] = - {MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; +mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS] = +{MXC_GPIO0, MXC_GPIO1, MXC_GPIO2, MXC_GPIO3, MXC_GPIO4}; // clang-format off const mxc_gpio_cfg_t pb_pin[] = { @@ -47,10 +47,10 @@ uint32_t board_millis(void) { // Initializes board related state once on start up. void board_init(void) { // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000);\ + SysTick_Config(SystemCoreClock / 1000); \ // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { MXC_GPIO_Init(0x1 << i); } diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index d23c90fdbc36..166021b44128 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -10,7 +10,7 @@ #include "gpio_reva.h" -extern mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS]; +extern mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS]; void common_hal_digitalio_digitalinout_never_reset( digitalio_digitalinout_obj_t *self) { @@ -50,9 +50,8 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( - digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) -{ - mxc_gpio_regs_t* port = gpio_ports[self->pin->port]; + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); @@ -61,9 +60,8 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( digitalio_digitalinout_obj_t *self, bool value, - digitalio_drive_mode_t drive_mode) -{ - mxc_gpio_regs_t* port = gpio_ports[self->pin->port]; + digitalio_drive_mode_t drive_mode) { + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); @@ -85,24 +83,21 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( uint32_t mask = self->pin->mask; // Check that I/O mode is enabled and we don't have in AND out on at the same time - MP_STATIC_ASSERT(!( (port->en0 & mask) && (port->inen & mask) && (port->outen & mask) )); + MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask))); - if ( (port->en0 & mask) && (port->outen & mask) ) - { + if ((port->en0 & mask) && (port->outen & mask)) { return DIRECTION_OUTPUT; - } - else if ( (port->en0 & mask) && (port->inen & mask) ) - { + } else if ((port->en0 & mask) && (port->inen & mask)) { return DIRECTION_INPUT; } - // do not try to drive a pin which has an odd configuration here - else return DIRECTION_INPUT; + else { + return DIRECTION_INPUT; + } } void common_hal_digitalio_digitalinout_set_value( - digitalio_digitalinout_obj_t *self, bool value) -{ + digitalio_digitalinout_obj_t *self, bool value) { digitalio_direction_t dir = common_hal_digitalio_digitalinout_get_direction(self); @@ -112,15 +107,13 @@ void common_hal_digitalio_digitalinout_set_value( if (dir == DIRECTION_OUTPUT) { if (value == true) { MXC_GPIO_OutSet(port, mask); - } - else { + } else { MXC_GPIO_OutClr(port, mask); } } } -bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self) -{ +bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self) { digitalio_direction_t dir = common_hal_digitalio_digitalinout_get_direction(self); @@ -128,10 +121,9 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s uint32_t mask = self->pin->mask; if (dir == DIRECTION_INPUT) { - return (MXC_GPIO_InGet(port, mask)); - } - else { - return ( (port->out & mask) == true); + return MXC_GPIO_InGet(port, mask); + } else { + return (port->out & mask) == true; } } @@ -154,7 +146,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - if ( (port->en0 & mask) && (port->inen & mask) ) { + if ((port->en0 & mask) && (port->inen & mask)) { // PULL_NONE, PULL_UP, or PULL_DOWN switch (pull) { case PULL_NONE: @@ -162,7 +154,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( port->padctrl1 &= ~(mask); break; case PULL_UP: - port->padctrl0 |= mask; + port->padctrl0 |= mask; port->padctrl1 &= ~(mask); break; case PULL_DOWN: @@ -173,8 +165,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( break; } return DIGITALINOUT_OK; - } - else { + } else { return DIGITALINOUT_PIN_BUSY; } } @@ -182,19 +173,16 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( digitalio_digitalinout_obj_t *self) { - bool pin_padctrl0 = (gpio_ports[self->pin->port]->padctrl0) & ( self->pin->mask); - bool pin_padctrl1 = (gpio_ports[self->pin->port]->padctrl1) & ( self->pin->mask); + bool pin_padctrl0 = (gpio_ports[self->pin->port]->padctrl0) & (self->pin->mask); + bool pin_padctrl1 = (gpio_ports[self->pin->port]->padctrl1) & (self->pin->mask); - if ( (pin_padctrl0) && !(pin_padctrl1) ) { + if ((pin_padctrl0) && !(pin_padctrl1)) { return PULL_UP; - } - else if ( !(pin_padctrl0) && pin_padctrl1 ) { + } else if (!(pin_padctrl0) && pin_padctrl1) { return PULL_DOWN; - } - else if ( !(pin_padctrl0) && !(pin_padctrl1) ) { + } else if (!(pin_padctrl0) && !(pin_padctrl1)) { return PULL_NONE; } - // Shouldn't happen, (value 0b11 is reserved) else { return PULL_NONE; diff --git a/ports/analog/common-hal/microcontroller/Pin.c b/ports/analog/common-hal/microcontroller/Pin.c index 29befaf5e5c0..4545aa039c2f 100644 --- a/ports/analog/common-hal/microcontroller/Pin.c +++ b/ports/analog/common-hal/microcontroller/Pin.c @@ -17,7 +17,7 @@ static uint32_t claimed_pins[NUM_GPIO_PORTS]; // defined in board.c -extern mxc_gpio_regs_t* gpio_ports[NUM_GPIO_PORTS]; +extern mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS]; static uint32_t never_reset_pins[NUM_GPIO_PORTS]; @@ -31,8 +31,8 @@ void reset_all_pins(void) { reset_pin_number(i, j); } } - // set claimed pins to never_reset pins - claimed_pins[i] = never_reset_pins[i]; + // set claimed pins to never_reset pins + claimed_pins[i] = never_reset_pins[i]; } } diff --git a/ports/analog/common-hal/microcontroller/Processor.c b/ports/analog/common-hal/microcontroller/Processor.c index e28388e58596..87d8047ff2cb 100644 --- a/ports/analog/common-hal/microcontroller/Processor.c +++ b/ports/analog/common-hal/microcontroller/Processor.c @@ -40,7 +40,7 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { #if CIRCUITPY_ALARM - // TODO: (low prior.) add reset reason in alarm / deepsleep cases (should require alarm peripheral API in "peripherals") + // TODO: (low prior.) add reset reason in alarm / deepsleep cases (should require alarm peripheral API in "peripherals") #endif return RESET_REASON_UNKNOWN; } diff --git a/ports/analog/common-hal/os/__init__.c b/ports/analog/common-hal/os/__init__.c index 04e561e61909..1f89300c4c18 100644 --- a/ports/analog/common-hal/os/__init__.c +++ b/ports/analog/common-hal/os/__init__.c @@ -43,8 +43,8 @@ mp_obj_t common_hal_os_uname(void) { bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { #if (HAS_TRNG) - //todo (low prior): implement + // todo (low prior): implement #else #endif - return false; + return false; } diff --git a/ports/analog/supervisor/serial.c b/ports/analog/supervisor/serial.c index 871e6cd0fe72..536355e38f60 100644 --- a/ports/analog/supervisor/serial.c +++ b/ports/analog/supervisor/serial.c @@ -26,7 +26,9 @@ void port_serial_init(void) { #if MAX32_SERIAL MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_IBRO_EN; - while( !(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_IBRO_RDY) ); + while (!(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_IBRO_RDY)) { + ; + } MXC_UART_Init(CONSOLE_UART, 115200, MXC_UART_IBRO_CLK); #endif } @@ -76,7 +78,7 @@ void port_serial_write_substring(const char *text, uint32_t len) { .rxData = NULL, .txLen = len, .rxLen = 0 - }; + }; MXC_UART_Transaction(&uart_req); #endif } diff --git a/ports/analog/supervisor/usb.c b/ports/analog/supervisor/usb.c index f156669ad386..1624359ab51f 100644 --- a/ports/analog/supervisor/usb.c +++ b/ports/analog/supervisor/usb.c @@ -36,8 +36,7 @@ void init_usb_hardware(void) { // Interrupt enables are left to TUSB depending on the device class } -void USB_IRQHandler(void) -{ +void USB_IRQHandler(void) { // Schedules USB background callback // appropriate to a given device class via TinyUSB lib usb_irq_handler(0); From c11fac858f09cbc1768a09423fb517e17875bb9b Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 09:15:49 -0700 Subject: [PATCH 232/252] Add "analog" to shared_bindings_matrix.py --- docs/shared_bindings_matrix.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index f4b430111eb7..66b6881e4f74 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -31,6 +31,7 @@ from concurrent.futures import ThreadPoolExecutor SUPPORTED_PORTS = [ + "analog", "atmel-samd", "broadcom", "cxd56", From a911626a413fe26032797e3e800c8f763d02fde4 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 09:33:29 -0700 Subject: [PATCH 233/252] More pre-commit fixes. --- ports/analog/peripherals/pins.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/analog/peripherals/pins.h b/ports/analog/peripherals/pins.h index efee60a2962a..3bd7d02bf46d 100644 --- a/ports/analog/peripherals/pins.h +++ b/ports/analog/peripherals/pins.h @@ -26,7 +26,7 @@ typedef struct { extern const mp_obj_type_t mcu_pin_type; -#define PIN(pin_port, pin_mask) { {&mcu_pin_type}, .port = pin_port, .mask = 1UL< Date: Fri, 27 Sep 2024 09:46:38 -0700 Subject: [PATCH 234/252] Manual pre-commit fix for all requisite files. --- ports/analog/boards/max32690evkit/pins.c | 10 +++--- ports/analog/max32_port.h | 2 +- ports/analog/supervisor/internal_flash.c | 21 ++++++------ ports/analog/supervisor/port.c | 43 +++++++++++++++--------- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/ports/analog/boards/max32690evkit/pins.c b/ports/analog/boards/max32690evkit/pins.c index 5b736385dc58..0486687d3347 100644 --- a/ports/analog/boards/max32690evkit/pins.c +++ b/ports/analog/boards/max32690evkit/pins.c @@ -9,7 +9,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - //P0 + // P0 { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, @@ -42,7 +42,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_29), MP_ROM_PTR(&pin_P0_29) }, { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, - //P1 + // P1 { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, @@ -75,7 +75,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P1_29), MP_ROM_PTR(&pin_P1_29) }, { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, - //P2 + // P2 { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, @@ -108,7 +108,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P2_29), MP_ROM_PTR(&pin_P2_29) }, { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, - //P3 + // P3 { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, @@ -119,7 +119,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, - //P4 + // P4 { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, }; diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index 0ded32e5b820..fe6d5e157fea 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -42,4 +42,4 @@ extern uint32_t SystemCoreClock; #define SUBSEC_PER_TICK 4 #endif -#endif //MAX32_PORT_H +#endif // MAX32_PORT_H diff --git a/ports/analog/supervisor/internal_flash.c b/ports/analog/supervisor/internal_flash.c index 57dd7d8b45d4..8518b235566c 100644 --- a/ports/analog/supervisor/internal_flash.c +++ b/ports/analog/supervisor/internal_flash.c @@ -75,8 +75,9 @@ static uint32_t page_buffer[FLASH_PAGE_SIZE / 4] = {0x0}; static inline int32_t block2addr(uint32_t block) { if (block >= 0 && block < INTERNAL_FLASH_FILESYSTEM_NUM_BLOCKS) { return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; + } else { + return -1; } - else return -1; } // Get index, start addr, & size of the flash sector where addr lies @@ -91,15 +92,13 @@ int flash_get_sector_info(uint32_t addr, uint32_t *start_addr, uint32_t *size) { } if (start_addr) { *start_addr = flash_layout[0].base_addr + (sector_index * flash_layout[0].sector_size); - } - else { + } else { return -1; // start_addr is NULL } if (size) { *size = flash_layout[0].sector_size; - } - else { - return -1; //size is NULL + } else { + return -1; // size is NULL } return sector_index; } @@ -176,7 +175,7 @@ mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t n /** NOTE: The MXC_FLC_Read function executes from SRAM and does some more error checking * than memcpy does. Will use it for now. */ - MXC_FLC_Read( src_addr, dest, FILESYSTEM_BLOCK_SIZE * num_blocks ); + MXC_FLC_Read(src_addr, dest, FILESYSTEM_BLOCK_SIZE * num_blocks); return 0; // success } @@ -205,12 +204,12 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, MXC_ICC_Disable(MXC_ICC0); // Buffer the page of flash to erase - MXC_FLC_Read(page_start , page_buffer, page_size); + MXC_FLC_Read(page_start, page_buffer, page_size); // Erase flash page MXC_CRITICAL( error = MXC_FLC_PageErase(dest_addr); - ); + ); if (error != E_NO_ERROR) { // lock flash & reset MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; @@ -220,12 +219,12 @@ mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t block_num, // Copy new src data into the page buffer // fill the new data in at the offset dest_addr - page_start // account for uint32_t page_buffer vs uint8_t src - memcpy( (page_buffer + (dest_addr - page_start) / 4), src, count * FILESYSTEM_BLOCK_SIZE); + memcpy((page_buffer + (dest_addr - page_start) / 4), src, count * FILESYSTEM_BLOCK_SIZE); // Write new page buffer back into flash MXC_CRITICAL( error = MXC_FLC_Write(page_start, page_size, page_buffer); - ); + ); if (error != E_NO_ERROR) { // lock flash & reset MXC_FLC0->ctrl = (MXC_FLC0->ctrl & ~MXC_F_FLC_REVA_CTRL_UNLOCK) | MXC_S_FLC_REVA_CTRL_UNLOCK_LOCKED; diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index af929e074e8f..065ac3b3c437 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -46,8 +46,8 @@ // msec to RTC subsec ticks (4 kHz) #define MSEC_TO_SS_ALARM(x) \ - (0 - ((x * 4096) / \ - 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */ + (0 - ((x * 4096) / \ + 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */ // Externs defined by linker .ld file extern uint32_t _stack, _heap, _estack, _eheap; @@ -70,7 +70,7 @@ safe_mode_t port_init(void) { int err = E_NO_ERROR; // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++){ + for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { err = MXC_GPIO_Init(0x1 << i); if (err) { return SAFE_MODE_PROGRAMMATIC; @@ -93,14 +93,18 @@ safe_mode_t port_init(void) { // Enable clock to RTC peripheral MXC_GCR->clkctrl |= MXC_F_GCR_CLKCTRL_ERTCO_EN; - while(!(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_ERTCO_RDY)); + while (!(MXC_GCR->clkctrl & MXC_F_GCR_CLKCTRL_ERTCO_RDY)) { + ; + } NVIC_EnableIRQ(RTC_IRQn); NVIC_EnableIRQ(USB_IRQn); // Init RTC w/ 0sec, 0subsec // Driven by 32.768 kHz ERTCO, with ssec= 1/4096 s - while( MXC_RTC_Init(0,0) != E_SUCCESS ) {}; + while (MXC_RTC_Init(0, 0) != E_SUCCESS) { + } + ; // enable 1 sec RTC SSEC alarm MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); @@ -108,7 +112,9 @@ safe_mode_t port_init(void) { MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); // Enable RTC - while ( MXC_RTC_Start() != E_SUCCESS ) {}; + while (MXC_RTC_Start() != E_SUCCESS) { + } + ; return SAFE_MODE_NONE; } @@ -191,9 +197,10 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { __disable_irq(); if (MXC_RTC->ctrl & MXC_F_RTC_CTRL_EN) { // NOTE: RTC_GetTime always returns BUSY if RTC is not running - while( (MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR ); - } - else { + while ((MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR) { + ; + } + } else { sec = MXC_RTC->sec; subsec = MXC_RTC->ssec; } @@ -232,15 +239,19 @@ void port_interrupt_after_ticks(uint32_t ticks) { ticks_msec = 1000 * ticks / TICKS_PER_SEC; while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | - MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) {}; + MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { + } + ; // Clear the flag to be set by the RTC Handler tick_flag = 0; // Subsec alarm is the starting/reload value of the SSEC counter. // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0 - while ( MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec) ) == E_BUSY) {} - while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) {} + while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) == E_BUSY) { + } + while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) { + } NVIC_EnableIRQ(RTC_IRQn); @@ -249,10 +260,10 @@ void port_interrupt_after_ticks(uint32_t ticks) { void port_idle_until_interrupt(void) { #if CIRCUITPY_RTC - // Check if alarm triggers before we even got here - if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { - return; - } + // Check if alarm triggers before we even got here + if (MXC_RTC_GetFlags() == (MXC_F_RTC_CTRL_TOD_ALARM | MXC_F_RTC_CTRL_SSEC_ALARM)) { + return; + } #endif // Interrupts should be disabled to ensure the ISR queue is flushed From ba08379e875adebbeef05e6704e5b40df041e477 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Fri, 27 Sep 2024 09:57:01 -0700 Subject: [PATCH 235/252] Manual pre-commit fix for last delinquent file --- ports/analog/supervisor/port.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 065ac3b3c437..1c068cb22c1d 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -45,9 +45,8 @@ #include "rtc.h" // msec to RTC subsec ticks (4 kHz) -#define MSEC_TO_SS_ALARM(x) \ - (0 - ((x * 4096) / \ - 1000)) /* Converts a time in milleseconds to the equivalent RSSA register value. */ +/* Converts a time in milleseconds to equivalent RSSA register value */ +#define MSEC_TO_SS_ALARM(x) (0 - ((x * 4096) / 1000)) // Externs defined by linker .ld file extern uint32_t _stack, _heap, _estack, _eheap; From 79a9ad7a63f54a003d1da5af78f8fc34c512ea07 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 1 Oct 2024 08:44:14 -0700 Subject: [PATCH 236/252] - Move SysTick init from board_init to port_init. - Fix RTC issue with interrupt_after_ticks. - Move LED inidcator to STATUS_LED code. --- ports/analog/Makefile | 2 +- ports/analog/boards/apard32690/README.md | 2 +- ports/analog/boards/apard32690/board.c | 18 ------- .../analog/boards/apard32690/mpconfigboard.h | 2 + ports/analog/boards/max32690evkit/board.c | 18 ------- .../boards/max32690evkit/mpconfigboard.h | 3 ++ ports/analog/supervisor/port.c | 52 ++++++++++--------- 7 files changed, 34 insertions(+), 63 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 766f0f78b930..79eb7a49052d 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -259,7 +259,7 @@ SRC_QSTR_PREPROCESSOR += # Default build target all: $(BUILD)/firmware.elf $(BUILD)/firmware.hex $(BUILD)/firmware.bin -clean-max32: +clean-all: rm -rf build-* # Optional flash option when running within an installed MSDK to use OpenOCD diff --git a/ports/analog/boards/apard32690/README.md b/ports/analog/boards/apard32690/README.md index 04f28ca4502b..3e8464854cb3 100644 --- a/ports/analog/boards/apard32690/README.md +++ b/ports/analog/boards/apard32690/README.md @@ -18,7 +18,7 @@ For more info about AD-APARD32690-SL, visit our product webpages for datasheets, To build for this board, ensure you are in the `ports/analog` directory and run the following command. Note that passing in the `-jN` flag, where N is the # of cores on your machine, can speed up compile times. ``` -make BOARD=APARD +make BOARD=apard32690 ``` #### Flashing this board diff --git a/ports/analog/boards/apard32690/board.c b/ports/analog/boards/apard32690/board.c index 3cc10de29f1e..cfef4bfcf61a 100644 --- a/ports/analog/boards/apard32690/board.c +++ b/ports/analog/boards/apard32690/board.c @@ -47,24 +47,6 @@ uint32_t board_millis(void) { // Initializes board related state once on start up. void board_init(void) { - // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000); \ - - // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { - MXC_GPIO_Init(0x1 << i); - } - - // Init Board LEDs - /* setup GPIO for the LED */ - for (int i = 0; i < num_leds; i++) { - // Set the output value - MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); - MXC_GPIO_Config(&led_pin[i]); - } - - // Turn on one LED to indicate Sign of Life - MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); } // Reset the state of off MCU components such as neopixels. diff --git a/ports/analog/boards/apard32690/mpconfigboard.h b/ports/analog/boards/apard32690/mpconfigboard.h index 0e09a4ede674..19b75a79d810 100644 --- a/ports/analog/boards/apard32690/mpconfigboard.h +++ b/ports/analog/boards/apard32690/mpconfigboard.h @@ -36,3 +36,5 @@ // #else // #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) // #endif + + #define MICROPY_HW_LED_STATUS (&pin_P2_01) diff --git a/ports/analog/boards/max32690evkit/board.c b/ports/analog/boards/max32690evkit/board.c index 76da5c0adccb..ebb8b2da35fc 100644 --- a/ports/analog/boards/max32690evkit/board.c +++ b/ports/analog/boards/max32690evkit/board.c @@ -46,24 +46,6 @@ uint32_t board_millis(void) { // Initializes board related state once on start up. void board_init(void) { - // 1ms tick timer - SysTick_Config(SystemCoreClock / 1000); \ - - // Enable GPIO (enables clocks + common init for ports) - for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { - MXC_GPIO_Init(0x1 << i); - } - - // Init Board LEDs - /* setup GPIO for the LED */ - for (int i = 0; i < num_leds; i++) { - // Set the output value - MXC_GPIO_OutClr(led_pin[i].port, led_pin[i].mask); - MXC_GPIO_Config(&led_pin[i]); - } - - // Turn on one LED to indicate Sign of Life - MXC_GPIO_OutSet(led_pin[2].port, led_pin[2].mask); } // Reset the state of off MCU components such as neopixels. diff --git a/ports/analog/boards/max32690evkit/mpconfigboard.h b/ports/analog/boards/max32690evkit/mpconfigboard.h index 7ab6acf658d1..e4395e8a0ae7 100644 --- a/ports/analog/boards/max32690evkit/mpconfigboard.h +++ b/ports/analog/boards/max32690evkit/mpconfigboard.h @@ -36,3 +36,6 @@ // #else // #define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) // #endif + +#define MICROPY_HW_LED_STATUS (&pin_P2_12) +#define MICROPY_HW_LED_STATUS_INVERTED 1 diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 1c068cb22c1d..6ef3b350744e 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -68,6 +68,9 @@ extern void NVIC_SystemReset(void) NORETURN; safe_mode_t port_init(void) { int err = E_NO_ERROR; + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000); + // Enable GPIO (enables clocks + common init for ports) for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { err = MXC_GPIO_Init(0x1 << i); @@ -122,12 +125,18 @@ void RTC_IRQHandler(void) { // Read flags to clear int flags = MXC_RTC_GetFlags(); - if (flags & MXC_F_RTC_CTRL_SSEC_ALARM) { - MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); - } - - if (flags & MXC_F_RTC_CTRL_TOD_ALARM) { - MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); + switch (flags) { + case MXC_F_RTC_CTRL_SSEC_ALARM: + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_SSEC_ALARM); + break; + case MXC_F_RTC_CTRL_TOD_ALARM: + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_TOD_ALARM); + break; + case MXC_F_RTC_CTRL_RDY: + MXC_RTC_ClearFlags(MXC_F_RTC_CTRL_RDY); + break; + default: + break; } tick_flag = 1; @@ -145,7 +154,7 @@ void reset_port(void) { } // Reset to the bootloader -// note: not implemented since max32 requires external stim ignals to +// note: not implemented since max32 requires external signals to // activate bootloaders void reset_to_bootloader(void) { NVIC_SystemReset(); @@ -193,7 +202,6 @@ uint32_t port_get_saved_word(void) { uint64_t port_get_raw_ticks(uint8_t *subticks) { // Ensure we can read from ssec register as soon as we can // MXC function does cross-tick / busy checking of RTC controller - __disable_irq(); if (MXC_RTC->ctrl & MXC_F_RTC_CTRL_EN) { // NOTE: RTC_GetTime always returns BUSY if RTC is not running while ((MXC_RTC_GetTime(&sec, &subsec)) != E_NO_ERROR) { @@ -203,7 +211,6 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { sec = MXC_RTC->sec; subsec = MXC_RTC->ssec; } - __enable_irq(); // Return ticks given total subseconds // ticks = TICKS/s * s + subsec/ subs/tick @@ -220,41 +227,36 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { // Enable 1/1024 second tick. void port_enable_tick(void) { - MXC_RTC_Start(); + while ( MXC_RTC_Start() == E_BUSY ); } // Disable 1/1024 second tick. void port_disable_tick(void) { - MXC_RTC_Stop(); + while( MXC_RTC_Stop() == E_BUSY ); } // Wake the CPU after a given # of ticks or sooner void port_interrupt_after_ticks(uint32_t ticks) { uint32_t ticks_msec = 0; - // Stop RTC & store current time & ticks - port_disable_tick(); - port_get_raw_ticks(NULL); - ticks_msec = 1000 * ticks / TICKS_PER_SEC; + ticks_msec = (ticks / TICKS_PER_SEC) * 1000; - while (MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | - MXC_F_RTC_CTRL_TOD_ALARM_IE) == E_BUSY) { - } - ; + // Disable RTC interrupts + MXC_RTC_DisableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE | + MXC_F_RTC_CTRL_TOD_ALARM_IE | MXC_F_RTC_CTRL_RDY_IE); + + // Stop RTC & store current time & ticks + port_get_raw_ticks(NULL); // Clear the flag to be set by the RTC Handler tick_flag = 0; // Subsec alarm is the starting/reload value of the SSEC counter. // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0 - while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) == E_BUSY) { - } - while (MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE) == E_BUSY) { - } + while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) != E_SUCCESS) {} - NVIC_EnableIRQ(RTC_IRQn); + MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); - port_enable_tick(); } void port_idle_until_interrupt(void) { From 6c99e4e80b061ccbf335206de9333545b6eb626f Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 1 Oct 2024 17:00:33 -0700 Subject: [PATCH 237/252] - Changed board.c to match silkscreen. - Added digitalio handling for GPIO Port 4 (different on MAX32690). - Added MCR defs to max32_port.h. --- ports/analog/boards/apard32690/pins.c | 91 ++++++++------- ports/analog/boards/max32690evkit/pins.c | 89 +++++++------- .../common-hal/digitalio/DigitalInOut.c | 110 +++++++++++++----- ports/analog/max32_port.h | 29 +++++ 4 files changed, 203 insertions(+), 116 deletions(-) diff --git a/ports/analog/boards/apard32690/pins.c b/ports/analog/boards/apard32690/pins.c index 0486687d3347..f4970aff7aeb 100644 --- a/ports/analog/boards/apard32690/pins.c +++ b/ports/analog/boards/apard32690/pins.c @@ -10,16 +10,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS // P0 - { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, - { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, - { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, - { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, - { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, - { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, - { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, - { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, - { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, - { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P0_0), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_P0_1), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_P0_2), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P0_3), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P0_4), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P0_5), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P0_6), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P0_7), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P0_8), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P0_9), MP_ROM_PTR(&pin_P0_09) }, { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, @@ -43,16 +43,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, // P1 - { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, - { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, - { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, - { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, - { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, - { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, - { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, - { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, - { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, - { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_P1_0), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_P1_1), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_P1_2), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_P1_3), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_P1_4), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_P1_5), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_P1_6), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_P1_7), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_P1_8), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_P1_9), MP_ROM_PTR(&pin_P1_09) }, { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, @@ -76,16 +76,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, // P2 - { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, - { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, - { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, - { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, - { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, - { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, - { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, - { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, - { MP_ROM_QSTR(MP_QSTR_P2_08), MP_ROM_PTR(&pin_P2_08) }, - { MP_ROM_QSTR(MP_QSTR_P2_09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_P2_0), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_P2_1), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_P2_2), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_P2_3), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_P2_4), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_P2_5), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_P2_6), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_P2_7), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_P2_8), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_P2_9), MP_ROM_PTR(&pin_P2_09) }, { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, @@ -109,18 +109,25 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, // P3 - { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, - { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, - { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, - { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, - { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, - { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, - { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, - { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, - { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, - { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, + { MP_ROM_QSTR(MP_QSTR_P3_0), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_P3_1), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_P3_2), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_P3_3), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_P3_4), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_P3_5), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_P3_6), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_P3_7), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_P3_8), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_P3_9), MP_ROM_PTR(&pin_P3_09) }, // P4 - { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, - { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, + { MP_ROM_QSTR(MP_QSTR_P4_0), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_P4_1), MP_ROM_PTR(&pin_P4_01) }, + + // Silkscreen aliases + { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P0_11) }, + { MP_ROM_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_S2), MP_ROM_PTR(&pin_P1_27) }, + }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/analog/boards/max32690evkit/pins.c b/ports/analog/boards/max32690evkit/pins.c index 0486687d3347..3270e4d62b2a 100644 --- a/ports/analog/boards/max32690evkit/pins.c +++ b/ports/analog/boards/max32690evkit/pins.c @@ -10,16 +10,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS // P0 - { MP_ROM_QSTR(MP_QSTR_P0_00), MP_ROM_PTR(&pin_P0_00) }, - { MP_ROM_QSTR(MP_QSTR_P0_01), MP_ROM_PTR(&pin_P0_01) }, - { MP_ROM_QSTR(MP_QSTR_P0_02), MP_ROM_PTR(&pin_P0_02) }, - { MP_ROM_QSTR(MP_QSTR_P0_03), MP_ROM_PTR(&pin_P0_03) }, - { MP_ROM_QSTR(MP_QSTR_P0_04), MP_ROM_PTR(&pin_P0_04) }, - { MP_ROM_QSTR(MP_QSTR_P0_05), MP_ROM_PTR(&pin_P0_05) }, - { MP_ROM_QSTR(MP_QSTR_P0_06), MP_ROM_PTR(&pin_P0_06) }, - { MP_ROM_QSTR(MP_QSTR_P0_07), MP_ROM_PTR(&pin_P0_07) }, - { MP_ROM_QSTR(MP_QSTR_P0_08), MP_ROM_PTR(&pin_P0_08) }, - { MP_ROM_QSTR(MP_QSTR_P0_09), MP_ROM_PTR(&pin_P0_09) }, + { MP_ROM_QSTR(MP_QSTR_P0_0), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_P0_1), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_P0_2), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_P0_3), MP_ROM_PTR(&pin_P0_03) }, + { MP_ROM_QSTR(MP_QSTR_P0_4), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_P0_5), MP_ROM_PTR(&pin_P0_05) }, + { MP_ROM_QSTR(MP_QSTR_P0_6), MP_ROM_PTR(&pin_P0_06) }, + { MP_ROM_QSTR(MP_QSTR_P0_7), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_P0_8), MP_ROM_PTR(&pin_P0_08) }, + { MP_ROM_QSTR(MP_QSTR_P0_9), MP_ROM_PTR(&pin_P0_09) }, { MP_ROM_QSTR(MP_QSTR_P0_10), MP_ROM_PTR(&pin_P0_10) }, { MP_ROM_QSTR(MP_QSTR_P0_11), MP_ROM_PTR(&pin_P0_11) }, { MP_ROM_QSTR(MP_QSTR_P0_12), MP_ROM_PTR(&pin_P0_12) }, @@ -43,16 +43,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P0_30), MP_ROM_PTR(&pin_P0_30) }, { MP_ROM_QSTR(MP_QSTR_P0_31), MP_ROM_PTR(&pin_P0_31) }, // P1 - { MP_ROM_QSTR(MP_QSTR_P1_00), MP_ROM_PTR(&pin_P1_00) }, - { MP_ROM_QSTR(MP_QSTR_P1_01), MP_ROM_PTR(&pin_P1_01) }, - { MP_ROM_QSTR(MP_QSTR_P1_02), MP_ROM_PTR(&pin_P1_02) }, - { MP_ROM_QSTR(MP_QSTR_P1_03), MP_ROM_PTR(&pin_P1_03) }, - { MP_ROM_QSTR(MP_QSTR_P1_04), MP_ROM_PTR(&pin_P1_04) }, - { MP_ROM_QSTR(MP_QSTR_P1_05), MP_ROM_PTR(&pin_P1_05) }, - { MP_ROM_QSTR(MP_QSTR_P1_06), MP_ROM_PTR(&pin_P1_06) }, - { MP_ROM_QSTR(MP_QSTR_P1_07), MP_ROM_PTR(&pin_P1_07) }, - { MP_ROM_QSTR(MP_QSTR_P1_08), MP_ROM_PTR(&pin_P1_08) }, - { MP_ROM_QSTR(MP_QSTR_P1_09), MP_ROM_PTR(&pin_P1_09) }, + { MP_ROM_QSTR(MP_QSTR_P1_0), MP_ROM_PTR(&pin_P1_00) }, + { MP_ROM_QSTR(MP_QSTR_P1_1), MP_ROM_PTR(&pin_P1_01) }, + { MP_ROM_QSTR(MP_QSTR_P1_2), MP_ROM_PTR(&pin_P1_02) }, + { MP_ROM_QSTR(MP_QSTR_P1_3), MP_ROM_PTR(&pin_P1_03) }, + { MP_ROM_QSTR(MP_QSTR_P1_4), MP_ROM_PTR(&pin_P1_04) }, + { MP_ROM_QSTR(MP_QSTR_P1_5), MP_ROM_PTR(&pin_P1_05) }, + { MP_ROM_QSTR(MP_QSTR_P1_6), MP_ROM_PTR(&pin_P1_06) }, + { MP_ROM_QSTR(MP_QSTR_P1_7), MP_ROM_PTR(&pin_P1_07) }, + { MP_ROM_QSTR(MP_QSTR_P1_8), MP_ROM_PTR(&pin_P1_08) }, + { MP_ROM_QSTR(MP_QSTR_P1_9), MP_ROM_PTR(&pin_P1_09) }, { MP_ROM_QSTR(MP_QSTR_P1_10), MP_ROM_PTR(&pin_P1_10) }, { MP_ROM_QSTR(MP_QSTR_P1_11), MP_ROM_PTR(&pin_P1_11) }, { MP_ROM_QSTR(MP_QSTR_P1_12), MP_ROM_PTR(&pin_P1_12) }, @@ -76,16 +76,16 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P1_30), MP_ROM_PTR(&pin_P1_30) }, { MP_ROM_QSTR(MP_QSTR_P1_31), MP_ROM_PTR(&pin_P1_31) }, // P2 - { MP_ROM_QSTR(MP_QSTR_P2_00), MP_ROM_PTR(&pin_P2_00) }, - { MP_ROM_QSTR(MP_QSTR_P2_01), MP_ROM_PTR(&pin_P2_01) }, - { MP_ROM_QSTR(MP_QSTR_P2_02), MP_ROM_PTR(&pin_P2_02) }, - { MP_ROM_QSTR(MP_QSTR_P2_03), MP_ROM_PTR(&pin_P2_03) }, - { MP_ROM_QSTR(MP_QSTR_P2_04), MP_ROM_PTR(&pin_P2_04) }, - { MP_ROM_QSTR(MP_QSTR_P2_05), MP_ROM_PTR(&pin_P2_05) }, - { MP_ROM_QSTR(MP_QSTR_P2_06), MP_ROM_PTR(&pin_P2_06) }, - { MP_ROM_QSTR(MP_QSTR_P2_07), MP_ROM_PTR(&pin_P2_07) }, - { MP_ROM_QSTR(MP_QSTR_P2_08), MP_ROM_PTR(&pin_P2_08) }, - { MP_ROM_QSTR(MP_QSTR_P2_09), MP_ROM_PTR(&pin_P2_09) }, + { MP_ROM_QSTR(MP_QSTR_P2_0), MP_ROM_PTR(&pin_P2_00) }, + { MP_ROM_QSTR(MP_QSTR_P2_1), MP_ROM_PTR(&pin_P2_01) }, + { MP_ROM_QSTR(MP_QSTR_P2_2), MP_ROM_PTR(&pin_P2_02) }, + { MP_ROM_QSTR(MP_QSTR_P2_3), MP_ROM_PTR(&pin_P2_03) }, + { MP_ROM_QSTR(MP_QSTR_P2_4), MP_ROM_PTR(&pin_P2_04) }, + { MP_ROM_QSTR(MP_QSTR_P2_5), MP_ROM_PTR(&pin_P2_05) }, + { MP_ROM_QSTR(MP_QSTR_P2_6), MP_ROM_PTR(&pin_P2_06) }, + { MP_ROM_QSTR(MP_QSTR_P2_7), MP_ROM_PTR(&pin_P2_07) }, + { MP_ROM_QSTR(MP_QSTR_P2_8), MP_ROM_PTR(&pin_P2_08) }, + { MP_ROM_QSTR(MP_QSTR_P2_9), MP_ROM_PTR(&pin_P2_09) }, { MP_ROM_QSTR(MP_QSTR_P2_10), MP_ROM_PTR(&pin_P2_10) }, { MP_ROM_QSTR(MP_QSTR_P2_11), MP_ROM_PTR(&pin_P2_11) }, { MP_ROM_QSTR(MP_QSTR_P2_12), MP_ROM_PTR(&pin_P2_12) }, @@ -109,18 +109,23 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_P2_30), MP_ROM_PTR(&pin_P2_30) }, { MP_ROM_QSTR(MP_QSTR_P2_31), MP_ROM_PTR(&pin_P2_31) }, // P3 - { MP_ROM_QSTR(MP_QSTR_P3_00), MP_ROM_PTR(&pin_P3_00) }, - { MP_ROM_QSTR(MP_QSTR_P3_01), MP_ROM_PTR(&pin_P3_01) }, - { MP_ROM_QSTR(MP_QSTR_P3_02), MP_ROM_PTR(&pin_P3_02) }, - { MP_ROM_QSTR(MP_QSTR_P3_03), MP_ROM_PTR(&pin_P3_03) }, - { MP_ROM_QSTR(MP_QSTR_P3_04), MP_ROM_PTR(&pin_P3_04) }, - { MP_ROM_QSTR(MP_QSTR_P3_05), MP_ROM_PTR(&pin_P3_05) }, - { MP_ROM_QSTR(MP_QSTR_P3_06), MP_ROM_PTR(&pin_P3_06) }, - { MP_ROM_QSTR(MP_QSTR_P3_07), MP_ROM_PTR(&pin_P3_07) }, - { MP_ROM_QSTR(MP_QSTR_P3_08), MP_ROM_PTR(&pin_P3_08) }, - { MP_ROM_QSTR(MP_QSTR_P3_09), MP_ROM_PTR(&pin_P3_09) }, + { MP_ROM_QSTR(MP_QSTR_P3_0), MP_ROM_PTR(&pin_P3_00) }, + { MP_ROM_QSTR(MP_QSTR_P3_1), MP_ROM_PTR(&pin_P3_01) }, + { MP_ROM_QSTR(MP_QSTR_P3_2), MP_ROM_PTR(&pin_P3_02) }, + { MP_ROM_QSTR(MP_QSTR_P3_3), MP_ROM_PTR(&pin_P3_03) }, + { MP_ROM_QSTR(MP_QSTR_P3_4), MP_ROM_PTR(&pin_P3_04) }, + { MP_ROM_QSTR(MP_QSTR_P3_5), MP_ROM_PTR(&pin_P3_05) }, + { MP_ROM_QSTR(MP_QSTR_P3_6), MP_ROM_PTR(&pin_P3_06) }, + { MP_ROM_QSTR(MP_QSTR_P3_7), MP_ROM_PTR(&pin_P3_07) }, + { MP_ROM_QSTR(MP_QSTR_P3_8), MP_ROM_PTR(&pin_P3_08) }, + { MP_ROM_QSTR(MP_QSTR_P3_9), MP_ROM_PTR(&pin_P3_09) }, // P4 - { MP_ROM_QSTR(MP_QSTR_P4_00), MP_ROM_PTR(&pin_P4_00) }, - { MP_ROM_QSTR(MP_QSTR_P4_01), MP_ROM_PTR(&pin_P4_01) }, + { MP_ROM_QSTR(MP_QSTR_P4_0), MP_ROM_PTR(&pin_P4_00) }, + { MP_ROM_QSTR(MP_QSTR_P4_1), MP_ROM_PTR(&pin_P4_01) }, + + // Board silkscreen Aliases + { MP_ROM_QSTR(MP_QSTR_LED0), MP_ROM_PTR(&pin_P0_14) }, + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_P2_12) }, + { MP_ROM_QSTR(MP_QSTR_PB0), MP_ROM_PTR(&pin_P4_00) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index 166021b44128..c5d8bbd508db 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -8,7 +8,9 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/microcontroller/Pin.h" +#include "max32_port.h" #include "gpio_reva.h" +#include "mxc_errors.h" extern mxc_gpio_regs_t *gpio_ports[NUM_GPIO_PORTS]; @@ -53,8 +55,19 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + int err=E_NO_ERROR; - MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); + if (self->pin->port == 4) { + // Set GPIO(s) to input mode + MXC_MCR->gpio4_ctrl &= ~GPIO4_OUTEN_MASK(mask); + MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); + } + else { + err = MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); + } + if (err != E_NO_ERROR) { + return DIGITALINOUT_PIN_BUSY; + } return common_hal_digitalio_digitalinout_set_pull(self, pull); } @@ -64,7 +77,14 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); + if (self->pin->port == 4) { + // Set GPIO(s) to output mode + MXC_MCR->gpio4_ctrl |= GPIO4_OUTEN_MASK(mask); + MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); + } + else { + MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); + } common_hal_digitalio_digitalinout_set_value(self, value); // todo (low): MSDK Hardware does not support open-drain configuration except @@ -82,17 +102,27 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - // Check that I/O mode is enabled and we don't have in AND out on at the same time - MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask))); + if (self->pin->port < 4) { + // Check that I/O mode is enabled and we don't have in AND out on at the same time + MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask))); - if ((port->en0 & mask) && (port->outen & mask)) { - return DIRECTION_OUTPUT; - } else if ((port->en0 & mask) && (port->inen & mask)) { - return DIRECTION_INPUT; + if ((port->en0 & mask) && (port->outen & mask)) { + return DIRECTION_OUTPUT; + } else if ((port->en0 & mask) && (port->inen & mask)) { + return DIRECTION_INPUT; + } + // do not try to drive a pin which has an odd configuration here + else { + return DIRECTION_INPUT; + } } - // do not try to drive a pin which has an odd configuration here else { - return DIRECTION_INPUT; + if (MXC_MCR->gpio4_ctrl & GPIO4_OUTEN_MASK(mask)) { + return DIRECTION_OUTPUT; + } + else { + return DIRECTION_INPUT; + } } } @@ -121,15 +151,22 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s uint32_t mask = self->pin->mask; if (dir == DIRECTION_INPUT) { - return MXC_GPIO_InGet(port, mask); + if (self->pin->port == 4) { + return (bool)(MXC_MCR->gpio4_ctrl & GPIO4_DATAIN_MASK(mask)); + } + return (MXC_GPIO_InGet(port, mask) && mask); } else { - return (port->out & mask) == true; + return (MXC_GPIO_OutGet(port, mask) && mask); } } +/** FIXME: Implement open-drain by switching to input WITHOUT re-labeling the pin */ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) { + if (drive_mode == DRIVE_MODE_OPEN_DRAIN) { + common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); + } // On MAX32, drive mode is not configurable // and should always be push-pull unless managed by a peripheral like I2C return DIGITALINOUT_OK; @@ -146,30 +183,39 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - if ((port->en0 & mask) && (port->inen & mask)) { - // PULL_NONE, PULL_UP, or PULL_DOWN - switch (pull) { - case PULL_NONE: - port->padctrl0 &= ~(mask); - port->padctrl1 &= ~(mask); - break; - case PULL_UP: - port->padctrl0 |= mask; - port->padctrl1 &= ~(mask); - break; - case PULL_DOWN: - port->padctrl0 &= ~(mask); - port->padctrl1 |= mask; - break; - default: - break; - } + // padctrl registers only work in input mode + if (self->pin->port == 4) { + MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); return DIGITALINOUT_OK; - } else { - return DIGITALINOUT_PIN_BUSY; + } + else { + if ((mask & port->en0) & (mask & ~(port->outen))) { + // PULL_NONE, PULL_UP, or PULL_DOWN + switch (pull) { + case PULL_NONE: + port->padctrl0 &= ~(mask); + port->padctrl1 &= ~(mask); + break; + case PULL_UP: + port->padctrl0 |= mask; + port->padctrl1 &= ~(mask); + break; + case PULL_DOWN: + port->padctrl0 &= ~(mask); + port->padctrl1 |= mask; + break; + default: + break; + } + return DIGITALINOUT_OK; + } + else { + return DIGITALINOUT_PIN_BUSY; + } } } +/** FIXME: Account for GPIO4 handling here */ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( digitalio_digitalinout_obj_t *self) { diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index fe6d5e157fea..8781bd56238b 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -14,12 +14,41 @@ #include "mxc_device.h" #include "mxc_pins.h" #include "mxc_sys.h" +#include "mcr_regs.h" #include "gpio.h" #ifdef MAX32690 #include "system_max32690.h" #include "max32690.h" + +/** START: GPIO4 Handling specific to MAX32690 */ +#define GPIO4_PIN_MASK 0x00000003 +#define GPIO4_RESET_MASK 0xFFFFFF77 +#define GPIO4_OUTEN_MASK(mask) \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1))) +#define GPIO4_PULLDIS_MASK(mask) \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1))) +#define GPIO4_DATAOUT_MASK(mask) \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) +#define GPIO4_DATAOUT_GET_MASK(mask) \ + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \ + (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \ + mask) +#define GPIO4_DATAIN_MASK(mask) \ + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ + ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ + (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \ + mask) +#define GPIO4_AFEN_MASK(mask) \ + (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ + ((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1))) +/** END: GPIO4 Handling specific to MAX32690 */ + #endif /** Linker variables defined.... From fbffbfd96871204a48c680a343dfb39015743456 Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Tue, 1 Oct 2024 17:29:45 -0700 Subject: [PATCH 238/252] pre-commit formatting fixes --- .../common-hal/digitalio/DigitalInOut.c | 33 +++++++------------ ports/analog/max32_port.h | 32 +++++++++--------- ports/analog/supervisor/port.c | 11 +++++-- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index c5d8bbd508db..3861900d81cd 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -55,14 +55,13 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - int err=E_NO_ERROR; + int err = E_NO_ERROR; if (self->pin->port == 4) { // Set GPIO(s) to input mode MXC_MCR->gpio4_ctrl &= ~GPIO4_OUTEN_MASK(mask); MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); - } - else { + } else { err = MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_IN, mask); } if (err != E_NO_ERROR) { @@ -81,8 +80,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( // Set GPIO(s) to output mode MXC_MCR->gpio4_ctrl |= GPIO4_OUTEN_MASK(mask); MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); - } - else { + } else { MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); } common_hal_digitalio_digitalinout_set_value(self, value); @@ -110,17 +108,14 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( return DIRECTION_OUTPUT; } else if ((port->en0 & mask) && (port->inen & mask)) { return DIRECTION_INPUT; - } - // do not try to drive a pin which has an odd configuration here - else { + // do not try to drive a pin which has an odd configuration here + } else { return DIRECTION_INPUT; } - } - else { + } else { if (MXC_MCR->gpio4_ctrl & GPIO4_OUTEN_MASK(mask)) { return DIRECTION_OUTPUT; - } - else { + } else { return DIRECTION_INPUT; } } @@ -154,9 +149,9 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s if (self->pin->port == 4) { return (bool)(MXC_MCR->gpio4_ctrl & GPIO4_DATAIN_MASK(mask)); } - return (MXC_GPIO_InGet(port, mask) && mask); + return MXC_GPIO_InGet(port, mask) && mask; } else { - return (MXC_GPIO_OutGet(port, mask) && mask); + return MXC_GPIO_OutGet(port, mask) && mask; } } @@ -187,8 +182,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( if (self->pin->port == 4) { MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); return DIGITALINOUT_OK; - } - else { + } else { if ((mask & port->en0) & (mask & ~(port->outen))) { // PULL_NONE, PULL_UP, or PULL_DOWN switch (pull) { @@ -208,8 +202,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( break; } return DIGITALINOUT_OK; - } - else { + } else { return DIGITALINOUT_PIN_BUSY; } } @@ -228,9 +221,7 @@ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( return PULL_DOWN; } else if (!(pin_padctrl0) && !(pin_padctrl1)) { return PULL_NONE; - } - // Shouldn't happen, (value 0b11 is reserved) - else { + } else { return PULL_NONE; } } diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index 8781bd56238b..64c6915aa68d 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -26,27 +26,27 @@ #define GPIO4_PIN_MASK 0x00000003 #define GPIO4_RESET_MASK 0xFFFFFF77 #define GPIO4_OUTEN_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ - ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1))) + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1))) #define GPIO4_PULLDIS_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ - ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1))) + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1))) #define GPIO4_DATAOUT_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ - ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) #define GPIO4_DATAOUT_GET_MASK(mask) \ - ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ - ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \ - (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \ - mask) + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \ + (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1)))& \ + mask) #define GPIO4_DATAIN_MASK(mask) \ - ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ - ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ - (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \ - mask) + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ + ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ + (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1)))& \ + mask) #define GPIO4_AFEN_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ - ((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1))) + (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ + ((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1))) /** END: GPIO4 Handling specific to MAX32690 */ #endif diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 6ef3b350744e..cdbf88d2528d 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -227,12 +227,16 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { // Enable 1/1024 second tick. void port_enable_tick(void) { - while ( MXC_RTC_Start() == E_BUSY ); + while (MXC_RTC_Start() == E_BUSY) { + ; + } } // Disable 1/1024 second tick. void port_disable_tick(void) { - while( MXC_RTC_Stop() == E_BUSY ); + while (MXC_RTC_Stop() == E_BUSY) { + ; + } } // Wake the CPU after a given # of ticks or sooner @@ -253,7 +257,8 @@ void port_interrupt_after_ticks(uint32_t ticks) { // Subsec alarm is the starting/reload value of the SSEC counter. // ISR triggered when SSEC rolls over from 0xFFFF_FFFF to 0x0 - while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) != E_SUCCESS) {} + while (MXC_RTC_SetSubsecondAlarm(MSEC_TO_SS_ALARM(ticks_msec)) != E_SUCCESS) { + } MXC_RTC_EnableInt(MXC_F_RTC_CTRL_SSEC_ALARM_IE); From af96599bd9181ca258a31507e2d70e2e345a05ae Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 1 Oct 2024 18:01:45 -0700 Subject: [PATCH 239/252] more pre-commit fixes --- ports/analog/max32_port.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index 64c6915aa68d..c464dabb2844 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -26,26 +26,26 @@ #define GPIO4_PIN_MASK 0x00000003 #define GPIO4_RESET_MASK 0xFFFFFF77 #define GPIO4_OUTEN_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_OE_POS) | \ ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_OE_POS - 1))) #define GPIO4_PULLDIS_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_PE_POS) | \ ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_PE_POS - 1))) #define GPIO4_DATAOUT_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + (((mask & (1 << 0)) << MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ ((mask & (1 << 1)) << (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) #define GPIO4_DATAOUT_GET_MASK(mask) \ - ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_DO) >> MXC_F_MCR_GPIO4_CTRL_P40_DO_POS) | \ ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_DO) >> \ - (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1)))& \ + (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \ mask) #define GPIO4_DATAIN_MASK(mask) \ ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ - (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1)))& \ + (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \ mask) #define GPIO4_AFEN_MASK(mask) \ - (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ + (((mask & (1 << 0)) << MXC_F_MCR_OUTEN_PDOWN_OUT_EN_POS) | \ ((mask & (1 << 1)) >> (MXC_F_MCR_OUTEN_SQWOUT_EN_POS + 1))) /** END: GPIO4 Handling specific to MAX32690 */ From 41ee08637eaed03e57598786ee34adbc29f99e18 Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Tue, 1 Oct 2024 18:04:19 -0700 Subject: [PATCH 240/252] final pre-commit fix --- ports/analog/max32_port.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/analog/max32_port.h b/ports/analog/max32_port.h index c464dabb2844..5d92fcfe6d3e 100644 --- a/ports/analog/max32_port.h +++ b/ports/analog/max32_port.h @@ -40,7 +40,7 @@ (MXC_F_MCR_GPIO4_CTRL_P41_DO_POS - 1))) & \ mask) #define GPIO4_DATAIN_MASK(mask) \ - ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ + ((((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P40_IN) >> MXC_F_MCR_GPIO4_CTRL_P40_IN_POS) | \ ((MXC_MCR->gpio4_ctrl & MXC_F_MCR_GPIO4_CTRL_P41_IN) >> \ (MXC_F_MCR_GPIO4_CTRL_P41_IN_POS - 1))) & \ mask) From 509239a02fa4e912feb68d44af4857755047d46a Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Wed, 2 Oct 2024 09:16:25 -0700 Subject: [PATCH 241/252] Fix CI run issues with docs & tlsf submodule --- ports/analog/README.md | 10 +++++----- ports/analog/boards/apard32690/README.md | 8 ++++---- tools/ci_fetch_deps.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ports/analog/README.md b/ports/analog/README.md index e2bd38b66472..39d8db098dd0 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -2,7 +2,7 @@ This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. These devices are mostly ARM Cortex-M4-based and focus on delivering performance at low-power levels. Currently this port only supports MAX32690. -### Structure of this port +## Structure of this port - **`boards/:`** Board-specific definitions including pins, board initialization, etc. - **`common-hal/:`** Port-specific implementations of CircuitPython common-hal APIs. When a new module is enabled, this is often where the implementation is found. Expected functions for modules in `common-hal` are usually found in `shared-bindings/` or `shared-module/` in the CircuitPy root directory. @@ -14,7 +14,7 @@ This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. Thes - `. :` Build system and high-level interface to the CircuitPython core for the ADI port. -### Building for MAX32 devices +## Building for MAX32 devices Ensure CircuitPython dependencies are up-to-date by following the CircuitPython introduction on Adafruit's Website: [Building CircuitPython - Introduction](https://learn.adafruit.com/building-circuitpython/introduction). In particular, it is necessary to fetch all submodules (including the ARM Toolchain inside MSDK) and build the `mpy-cross` compiler. @@ -32,7 +32,7 @@ Once you have built `mpy-cross` and set up your build system for CircuitPython, Be aware the build may take a long time without parallelizing via the `-jN` flag, where N is the # of cores on your machine. -### Flashing the board +## Flashing the board Universal instructions on flashing MAX32 devices this project can be found in the **[MSDK User Guide](https://analogdevicesinc.github.io/msdk/USERGUIDE/)**. @@ -48,11 +48,11 @@ This requires the following: - The PICO board is connected to the target board via a 10-pin SWD ribbon cable. - If SWD connectors are not keyed, the P1 indicator (red line) on the SWD ribbon cable should match the P1 indicator on the board silkscreen near the 10-pin SWD connector. -### Using the REPL +## Using the REPL Once the device is plugged in, it will enumerate via USB as both a USB Serial Device (CDC) and a Mass Storage Device (MSC). You can connect to the Python REPL with your favorite Serial Monitor program e.g. TeraTerm, VS Code, Putty, etc. Use any buadrate with 8-bit, No Parity, 1 Stop Bit (8N1) settings. From this point forward, you can run Python code on the MCU! If you want help with learning CircuitPython-specific code or learning Python in general, a good place to start is Adafruit's ["Welcome to CircuitPython"](https://learn.adafruit.com/welcome-to-circuitpython/) guide. -### Editing code.py +## Editing code.py Python code may be executed from `code.py` the `CIRCUITPY:` drive. When editing this file, please be aware that some text editors will work better than others. A list of suggested text editors can be found at Adafruit's guide here: https://learn.adafruit.com/welcome-to-circuitpython/recommended-editors diff --git a/ports/analog/boards/apard32690/README.md b/ports/analog/boards/apard32690/README.md index 3e8464854cb3..960a26a007f2 100644 --- a/ports/analog/boards/apard32690/README.md +++ b/ports/analog/boards/apard32690/README.md @@ -2,18 +2,18 @@ This board features the MAX32690, a dual-core ARM Cortex-M4/RISC-V MCU with 3MiB Flash, 1MiB SRAM. The board also has support for 10BASE-T1L Ethernet, Wifi, Bluetooth, USB, and Security via MAXQ1065. However, most of these features are not yet available for this CircuitPython port (USB will be added soon; others are currently unplanned). -### Onboard connectors & peripherals +## Onboard connectors & peripherals This board comes in a form-factor similar to an Arduino Mega, enabling Arduino-style shield boards to be plugged in and evaluated with the MAX32690. This vastly opens up the options for easily plugging peripherals into the board, especially when combined with the two Pmod:tm: connectors, P8 (SPI) and P13 (I2C). -### Product Resources +## Product Resources For more info about AD-APARD32690-SL, visit our product webpages for datasheets, User Guides, Software, and Design Documents: [AD-APARD32690-SL Product Webpage](https://www.analog.com/en/resources/evaluation-hardware-and-software/evaluation-boards-kits/ad-apard32690-sl.html) [AD-APARD32690-SL User Guide](https://wiki.analog.com/resources/eval/user-guides/ad-apard32690-sl) -#### Building for this board +### Building for this board To build for this board, ensure you are in the `ports/analog` directory and run the following command. Note that passing in the `-jN` flag, where N is the # of cores on your machine, can speed up compile times. @@ -21,7 +21,7 @@ To build for this board, ensure you are in the `ports/analog` directory and run make BOARD=apard32690 ``` -#### Flashing this board +### Flashing this board To flash the board, run the following command if using the MAX32625PICO: diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index 778a90c31b63..a06631bb307e 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -48,7 +48,7 @@ def matching_submodules(s): PORT_DEPS = { "analog": [ "extmod/ulab/", - "/lib/tlsf/", + "lib/tlsf/", "lib/tinyusb/", "lib/protomatter", ], From 77a4f75a09fb7b7c20a7317b7df3a9dbe920186f Mon Sep 17 00:00:00 2001 From: "Hurst, Brandon" Date: Wed, 2 Oct 2024 10:18:13 -0700 Subject: [PATCH 242/252] - Add elf target for CI build. - Add ports/analog/README to toctree for Sphinx docs. --- docs/supported_ports.rst | 1 + ports/analog/mpconfigport.mk | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/supported_ports.rst b/docs/supported_ports.rst index 69eaa5ef1489..41f872864791 100644 --- a/docs/supported_ports.rst +++ b/docs/supported_ports.rst @@ -12,6 +12,7 @@ Additional testing is limited. .. toctree:: :maxdepth: 2 + ../ports/analog/README ../ports/atmel-samd/README ../ports/broadcom/README ../ports/cxd56/README diff --git a/ports/analog/mpconfigport.mk b/ports/analog/mpconfigport.mk index 348d61dc2892..1b9655c7f33c 100644 --- a/ports/analog/mpconfigport.mk +++ b/ports/analog/mpconfigport.mk @@ -60,10 +60,13 @@ CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 CIRCUITPY_PIXELBUF ?= 0 #################################################################################### -# Required for clean building (additional CircuittPython Defaults) +# Required for clean building (additional CircuitPython Defaults) #################################################################################### # Depends on BUSIO CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_BUSDEVICE = 0 + +# For CircuitPython CI +CIRCUITPY_BUILD_EXTENSIONS ?= elf From dfca771f9a11f93a3fb05e2332903ccc30203ce4 Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 24 Oct 2024 12:00:18 -0700 Subject: [PATCH 243/252] Update msdk submodule to clear nvic/dma warnings --- ports/analog/msdk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/analog/msdk b/ports/analog/msdk index 608acf33e95a..db69388844d2 160000 --- a/ports/analog/msdk +++ b/ports/analog/msdk @@ -1 +1 @@ -Subproject commit 608acf33e95a994d548b8223955952c4749acaac +Subproject commit db69388844d29e727cd245b90b54279341f77401 From d406a7485cc94fc1e3293e3cc127e5961740ca1e Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 24 Oct 2024 12:23:26 -0700 Subject: [PATCH 244/252] Remove dma_revb.c from Makefile --- ports/analog/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 79eb7a49052d..9499c8eacd36 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -100,7 +100,6 @@ SRC_MAX32 += \ $(PERIPH_SRC)/CTB/ctb_reva.c \ $(PERIPH_SRC)/CTB/ctb_common.c \ $(PERIPH_SRC)/DMA/dma_reva.c \ - $(PERIPH_SRC)/DMA/dma_revb.c \ $(PERIPH_SRC)/DMA/dma_$(DIE_TYPE).c \ $(PERIPH_SRC)/FLC/flc_common.c \ $(PERIPH_SRC)/FLC/flc_$(DIE_TYPE).c \ From 83ffc64558394d5714fbb33a1ff6d939ef3a6f1c Mon Sep 17 00:00:00 2001 From: Brandon Date: Thu, 24 Oct 2024 12:40:44 -0700 Subject: [PATCH 245/252] Add CONFIG_TRUSTED_EXECUTION_SECURE macro to Makefile --- ports/analog/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 9499c8eacd36..46dfc6a53b39 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -145,7 +145,8 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET_REV=0x4131 \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ - -DRISCV_LOAD=0 + -DRISCV_LOAD=0 \ + -DCONFIG_TRUSTED_EXECUTION_SECURE=0 # todo: add these for linkerfiles later on so that it's easier to add new boards # -DFLASH_ORIGIN=0x10000000 \ From b50c31bd77736b911e9e1bd7ecb7e923bd2e9247 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 25 Oct 2024 13:42:53 -0700 Subject: [PATCH 246/252] Add open-drain to digitalio + Resolve some issues with GPIO4 & setting pullup/pulldown --- ports/analog/Makefile | 1 + .../common-hal/digitalio/DigitalInOut.c | 140 ++++++++++++++---- .../common-hal/digitalio/DigitalInOut.h | 2 + 3 files changed, 112 insertions(+), 31 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index 46dfc6a53b39..ebdb62bb2c13 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -209,6 +209,7 @@ CFLAGS += -Wno-error=unused-parameter \ -Wno-error=nested-externs \ -Wno-error=sign-compare \ -Wno-cast-align \ + -Wno-sign-compare \ ENTRY = Reset_Handler LDFLAGS += $(CFLAGS) --entry $(ENTRY) -Wl,-nostdlib -Wl,-T,$(LINKERFILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index 3861900d81cd..0f34b604fd0c 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -28,11 +28,13 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct( common_hal_mcu_pin_claim(pin); self->pin = pin; + self->open_drain = false; + self->vssel = MXC_GPIO_VSSEL_VDDIOH; mxc_gpio_cfg_t new_gpio_cfg = { .port = gpio_ports[self->pin->port], .mask = (self->pin->mask), - .vssel = self->pin->level, + .vssel = self->vssel, .func = MXC_GPIO_FUNC_IN, .drvstr = MXC_GPIO_DRVSTR_0, .pad = MXC_GPIO_PAD_NONE, @@ -55,6 +57,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + int err = E_NO_ERROR; if (self->pin->port == 4) { @@ -76,21 +79,18 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + self->open_drain = (drive_mode == DRIVE_MODE_OPEN_DRAIN); + + // Set GPIO(s) to output mode if (self->pin->port == 4) { - // Set GPIO(s) to output mode MXC_MCR->gpio4_ctrl |= GPIO4_OUTEN_MASK(mask); MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); } else { MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); } + common_hal_digitalio_digitalinout_set_value(self, value); - // todo (low): MSDK Hardware does not support open-drain configuration except - // todo (low): when directly managed by a peripheral such as I2C. - // todo (low): find a way to signal this to any upstream code - if (drive_mode != DRIVE_MODE_PUSH_PULL) { - return DIGITALINOUT_INVALID_DRIVE_MODE; - } return DIGITALINOUT_OK; } @@ -100,6 +100,11 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + // Open drain must be considered output for CircuitPython API to work properly + if (self->open_drain) { + return DIRECTION_OUTPUT; + } + if (self->pin->port < 4) { // Check that I/O mode is enabled and we don't have in AND out on at the same time MP_STATIC_ASSERT(!((port->en0 & mask) && (port->inen & mask) && (port->outen & mask))); @@ -129,8 +134,30 @@ void common_hal_digitalio_digitalinout_set_value( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - if (dir == DIRECTION_OUTPUT) { - if (value == true) { + MXC_GPIO_SetVSSEL(port, self->vssel, mask); + + if (self->open_drain) { + // Open-drain can be done by setting to input mode, no pullup/pulldown + // when the value is high (no sink current into GPIO) + if (value) { + // set to input, no pull + common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); + } + else { + // can't use common_hal_switch_to_output b/c it calls this function + // set the GPIO to output, low + if (self->pin->port == 4) { + MXC_MCR->gpio4_ctrl |= GPIO4_OUTEN_MASK(mask); + MXC_MCR->outen &= ~GPIO4_AFEN_MASK(mask); + } else { + MXC_GPIO_RevA_SetAF((mxc_gpio_reva_regs_t *)port, MXC_GPIO_FUNC_OUT, mask); + } + MXC_GPIO_OutClr(port, mask); + } + } + + else if (dir == DIRECTION_OUTPUT) { + if (value) { MXC_GPIO_OutSet(port, mask); } else { MXC_GPIO_OutClr(port, mask); @@ -145,6 +172,10 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; + if (self->open_drain) { + return MXC_GPIO_InGet(port, mask) && mask; + } + if (dir == DIRECTION_INPUT) { if (self->pin->port == 4) { return (bool)(MXC_MCR->gpio4_ctrl & GPIO4_DATAIN_MASK(mask)); @@ -155,21 +186,29 @@ bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *s } } -/** FIXME: Implement open-drain by switching to input WITHOUT re-labeling the pin */ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) { - if (drive_mode == DRIVE_MODE_OPEN_DRAIN) { - common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); - } - // On MAX32, drive mode is not configurable - // and should always be push-pull unless managed by a peripheral like I2C + // Check what the current value is + bool value = common_hal_digitalio_digitalinout_get_value(self); + self->open_drain = (drive_mode == DRIVE_MODE_OPEN_DRAIN); + + // Re-set the value to account for different setting methods for drive types + // Switch to output will both set the output config + // AND set the value for the new drive type + common_hal_digitalio_digitalinout_switch_to_output(self, value, drive_mode); + return DIGITALINOUT_OK; } digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( digitalio_digitalinout_obj_t *self) { - return DRIVE_MODE_PUSH_PULL; + if (self->open_drain) { + return DRIVE_MODE_OPEN_DRAIN; + } + else { + return DRIVE_MODE_PUSH_PULL; + } } digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( @@ -178,11 +217,31 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; uint32_t mask = self->pin->mask; - // padctrl registers only work in input mode + // GPIO4 handling if (self->pin->port == 4) { - MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); + switch(pull) { + case PULL_NONE: + // disable pullup/pulldown + MXC_MCR->gpio4_ctrl |= GPIO4_PULLDIS_MASK(mask); + break; + case PULL_UP: + // enable pullup/pulldown (clear the mask) + // then set output value to 1 + MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); + MXC_MCR->gpio4_ctrl |= GPIO4_DATAOUT_MASK(mask); + break; + case PULL_DOWN: + // enable pullup/pulldown (clear the mask) + // then clear output value to 0 + MXC_MCR->gpio4_ctrl &= ~(GPIO4_PULLDIS_MASK(mask)); + MXC_MCR->gpio4_ctrl &= ~(GPIO4_DATAOUT_MASK(mask)); + break; + default: + break; + } return DIGITALINOUT_OK; } else { + // padctrl registers only work in input mode if ((mask & port->en0) & (mask & ~(port->outen))) { // PULL_NONE, PULL_UP, or PULL_DOWN switch (pull) { @@ -193,10 +252,12 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( case PULL_UP: port->padctrl0 |= mask; port->padctrl1 &= ~(mask); + port->ps &= ~(mask); break; case PULL_DOWN: - port->padctrl0 &= ~(mask); + port->padctrl0 &= ~mask; port->padctrl1 |= mask; + port->ps &= ~mask; break; default: break; @@ -208,20 +269,37 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( } } -/** FIXME: Account for GPIO4 handling here */ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( digitalio_digitalinout_obj_t *self) { - bool pin_padctrl0 = (gpio_ports[self->pin->port]->padctrl0) & (self->pin->mask); - bool pin_padctrl1 = (gpio_ports[self->pin->port]->padctrl1) & (self->pin->mask); + mxc_gpio_regs_t *port = gpio_ports[self->pin->port]; + uint32_t mask = self->pin->mask; - if ((pin_padctrl0) && !(pin_padctrl1)) { - return PULL_UP; - } else if (!(pin_padctrl0) && pin_padctrl1) { - return PULL_DOWN; - } else if (!(pin_padctrl0) && !(pin_padctrl1)) { - return PULL_NONE; - } else { - return PULL_NONE; + bool pin_padctrl0 = (port->padctrl0) & (mask); + bool pin_padctrl1 = (port->padctrl1) & (mask); + + if (self->pin->port == 4) { + if (MXC_MCR->gpio4_ctrl & GPIO4_PULLDIS_MASK(mask)) { + return PULL_NONE; + } + else { + if (MXC_MCR->gpio4_ctrl & GPIO4_DATAOUT_MASK(mask)) { + return PULL_UP; + } + else { + return PULL_DOWN; + } + } + } + else { + if ((pin_padctrl0) && !(pin_padctrl1)) { + return PULL_UP; + } else if (!(pin_padctrl0) && pin_padctrl1) { + return PULL_DOWN; + } else if (!(pin_padctrl0) && !(pin_padctrl1)) { + return PULL_NONE; + } else { + return PULL_NONE; + } } } diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.h b/ports/analog/common-hal/digitalio/DigitalInOut.h index f58b23832b19..d10345fa3fa8 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.h +++ b/ports/analog/common-hal/digitalio/DigitalInOut.h @@ -12,4 +12,6 @@ typedef struct { mp_obj_base_t base; const mcu_pin_obj_t *pin; + bool open_drain; + mxc_gpio_vssel_t vssel; } digitalio_digitalinout_obj_t; From b84170d980574941d685434a93b207ff73684a38 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 25 Oct 2024 13:47:15 -0700 Subject: [PATCH 247/252] Pre-commit formatting fix --- .../analog/common-hal/digitalio/DigitalInOut.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index 0f34b604fd0c..f3e3fe552dc0 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -142,8 +142,7 @@ void common_hal_digitalio_digitalinout_set_value( if (value) { // set to input, no pull common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); - } - else { + } else { // can't use common_hal_switch_to_output b/c it calls this function // set the GPIO to output, low if (self->pin->port == 4) { @@ -154,9 +153,7 @@ void common_hal_digitalio_digitalinout_set_value( } MXC_GPIO_OutClr(port, mask); } - } - - else if (dir == DIRECTION_OUTPUT) { + } else if (dir == DIRECTION_OUTPUT) { if (value) { MXC_GPIO_OutSet(port, mask); } else { @@ -219,7 +216,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( // GPIO4 handling if (self->pin->port == 4) { - switch(pull) { + switch (pull) { case PULL_NONE: // disable pullup/pulldown MXC_MCR->gpio4_ctrl |= GPIO4_PULLDIS_MASK(mask); @@ -281,17 +278,14 @@ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( if (self->pin->port == 4) { if (MXC_MCR->gpio4_ctrl & GPIO4_PULLDIS_MASK(mask)) { return PULL_NONE; - } - else { + } else { if (MXC_MCR->gpio4_ctrl & GPIO4_DATAOUT_MASK(mask)) { return PULL_UP; - } - else { + } else { return PULL_DOWN; } } - } - else { + } else { if ((pin_padctrl0) && !(pin_padctrl1)) { return PULL_UP; } else if (!(pin_padctrl0) && pin_padctrl1) { From fd152664c96d845fc2fcf32256857cf704ce4a00 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 25 Oct 2024 13:52:21 -0700 Subject: [PATCH 248/252] Pre-commit formatting fix --- ports/analog/common-hal/digitalio/DigitalInOut.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/analog/common-hal/digitalio/DigitalInOut.c b/ports/analog/common-hal/digitalio/DigitalInOut.c index f3e3fe552dc0..7d4048d77e70 100644 --- a/ports/analog/common-hal/digitalio/DigitalInOut.c +++ b/ports/analog/common-hal/digitalio/DigitalInOut.c @@ -202,8 +202,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( digitalio_digitalinout_obj_t *self) { if (self->open_drain) { return DRIVE_MODE_OPEN_DRAIN; - } - else { + } else { return DRIVE_MODE_PUSH_PULL; } } From b0bd66204883f714aec494dd373468a4cd3d193a Mon Sep 17 00:00:00 2001 From: "U-ANALOG\\BHurst" Date: Sun, 3 Nov 2024 11:29:01 -0500 Subject: [PATCH 249/252] Fix optimization settings for non-debug builds --- ports/analog/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index ebdb62bb2c13..a36619b5687c 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -163,10 +163,9 @@ DEBUG ?= 1 endif ifeq ($(DEBUG),1) -CFLAGS += -ggdb3 -COPT = -Og +COPT = -Og -ggdb3 -Os else -COPT += -O0 #opt completely off to start +COPT += -Os #opt completely off to start endif # TinyUSB CFLAGS From ff2bdc5254c2f295de21e98c465a764a0b4ee8cc Mon Sep 17 00:00:00 2001 From: Brandon Hurst Date: Sun, 3 Nov 2024 13:45:39 -0500 Subject: [PATCH 250/252] Enabled SysTick interrupt for time.sleep to work. Cleaned up optimization settings. --- ports/analog/Makefile | 16 ++++++++-------- ports/analog/supervisor/port.c | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index a36619b5687c..b2f392b17c59 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -141,7 +141,7 @@ SRC_S += supervisor/cpu.s \ $(STARTUPFILE) # Needed to compile some MAX32 headers -CFLAGS += -D$(MCU_VARIANT_UPPER) \ +CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DTARGET_REV=0x4131 \ -DTARGET=$(MCU_VARIANT_UPPER) \ -DIAR_PRAGMAS=0 \ @@ -149,23 +149,23 @@ CFLAGS += -D$(MCU_VARIANT_UPPER) \ -DCONFIG_TRUSTED_EXECUTION_SECURE=0 # todo: add these for linkerfiles later on so that it's easier to add new boards -# -DFLASH_ORIGIN=0x10000000 \ -# -DFLASH_SIZE=0x340000 \ -# -DSRAM_ORIGIN=0x20000000 \ -# -DSRAM_SIZE=0x100000 +# -DFLASH_ORIGIN \ +# -DFLASH_SIZE \ +# -DSRAM_ORIGIN \ +# -DSRAM_SIZE CPU_CORE=cortex-m4 CFLAGS += -mthumb -mcpu=$(CPU_CORE) -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -# NOTE: Start with DEBUG ONLY settings for now +# NOTE: Start with DEBUG=1 defaults for now ifeq ($(DEBUG),) DEBUG ?= 1 endif ifeq ($(DEBUG),1) -COPT = -Og -ggdb3 -Os +COPT = -ggdb3 -Og -Os else -COPT += -Os #opt completely off to start +COPT += -Os endif # TinyUSB CFLAGS diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index cdbf88d2528d..391ad655d2cd 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -65,11 +65,14 @@ static uint32_t tick_flag = 0; // defined by cmsis core files extern void NVIC_SystemReset(void) NORETURN; +// FIXME: Currently have an issue with time.sleep b/c MXC_Delay uses SysTick, +// and SysTick ISR isn't happening. Seems that MXC_Delay results in inf. loop safe_mode_t port_init(void) { int err = E_NO_ERROR; // 1ms tick timer SysTick_Config(SystemCoreClock / 1000); + NVIC_EnableIRQ(SysTick_IRQn); // FIXME: Test with NVIC Enable here before committing // Enable GPIO (enables clocks + common init for ports) for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { From 689cf8b66aabf26435551ed0cfcbf3fb81e85480 Mon Sep 17 00:00:00 2001 From: Brandon Hurst Date: Sun, 3 Nov 2024 15:18:59 -0500 Subject: [PATCH 251/252] Remove FIXME comments from supervisor/port.c. Changes were tested. --- ports/analog/supervisor/port.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ports/analog/supervisor/port.c b/ports/analog/supervisor/port.c index 391ad655d2cd..0aedd74f179c 100644 --- a/ports/analog/supervisor/port.c +++ b/ports/analog/supervisor/port.c @@ -65,14 +65,12 @@ static uint32_t tick_flag = 0; // defined by cmsis core files extern void NVIC_SystemReset(void) NORETURN; -// FIXME: Currently have an issue with time.sleep b/c MXC_Delay uses SysTick, -// and SysTick ISR isn't happening. Seems that MXC_Delay results in inf. loop safe_mode_t port_init(void) { int err = E_NO_ERROR; // 1ms tick timer SysTick_Config(SystemCoreClock / 1000); - NVIC_EnableIRQ(SysTick_IRQn); // FIXME: Test with NVIC Enable here before committing + NVIC_EnableIRQ(SysTick_IRQn); // Enable GPIO (enables clocks + common init for ports) for (int i = 0; i < MXC_CFG_GPIO_INSTANCES; i++) { From 2bb66a439f56a6426ef74596f86dba16dcc9ac28 Mon Sep 17 00:00:00 2001 From: Brandon Hurst Date: Tue, 12 Nov 2024 08:54:29 -0800 Subject: [PATCH 252/252] - Add instructions for ARM Cross Toolchain to README. - Add OpenOCD overriding to Makefile flash-msdk task --- ports/analog/Makefile | 4 +++- ports/analog/README.md | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ports/analog/Makefile b/ports/analog/Makefile index b2f392b17c59..5d923cbaf6b6 100644 --- a/ports/analog/Makefile +++ b/ports/analog/Makefile @@ -267,8 +267,10 @@ clean-all: # If the MSDK is installed, flash-msdk can be run to utilize the the modified # openocd with the algorithms MAXIM_PATH := $(subst \,/,$(MAXIM_PATH)) +OPENOCD ?= $(MAXIM_PATH)/Tools/OpenOCD/openocd +OPENOCD_SCRIPTS ?= $(MAXIM_PATH)/Tools/OpenOCD/scripts flash-msdk: - $(MAXIM_PATH)/Tools/OpenOCD/openocd -s $(MAXIM_PATH)/Tools/OpenOCD/scripts \ + $(OPENOCD) -s $(OPENOCD_SCRIPTS) \ -f interface/cmsis-dap.cfg -f target/$(MCU_VARIANT_LOWER).cfg \ -c "program $(BUILD)/firmware.elf verify; init; reset; exit" diff --git a/ports/analog/README.md b/ports/analog/README.md index 39d8db098dd0..fa5ab1f4a778 100644 --- a/ports/analog/README.md +++ b/ports/analog/README.md @@ -16,14 +16,14 @@ This port brings CircuitPython to ADI's "MAX32" series of microcontrollers. Thes ## Building for MAX32 devices -Ensure CircuitPython dependencies are up-to-date by following the CircuitPython introduction on Adafruit's Website: [Building CircuitPython - Introduction](https://learn.adafruit.com/building-circuitpython/introduction). In particular, it is necessary to fetch all submodules (including the ARM Toolchain inside MSDK) and build the `mpy-cross` compiler. +Ensure CircuitPython dependencies are up-to-date by following the CircuitPython introduction on Adafruit's Website: [Building CircuitPython - Introduction](https://learn.adafruit.com/building-circuitpython/introduction). You will require the [ARM GNU Toolchain](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads), with ARM GCC >=13.x. It is also necessary to fetch all submodules and build the `mpy-cross` compiler, per the "Building CircuitPython" guide. -Ensure the MSDK's ARM toolchain is contained on your PATH. This can be done in MinGW or WSL by exporting a prefix to the PATH variable: +Ensure the ARM toolchain is contained on your PATH. This can be done in MinGW or WSL by exporting a prefix to the PATH variable. The author's path is included below as an example: - $ export MSDK_GNU_PATH=/ports/analog/msdk/Tools/GNUTools/10.3/bin - $ export PATH=$MSDK_GNU_PATH:$PATH + $ export ARM_GNU_PATH=C:/x-tools/arm-win/arm-none-eabi-w64-i686-13.3rel1/bin + $ export PATH=$ARM_GNU_PATH:$PATH -This needs to be done each time you open a command environment to build CircuitPython. +This needs to be done each time you open a command environment to build CircuitPython. It can be useful to set up a simple shell script for this. Once you have built `mpy-cross` and set up your build system for CircuitPython, you can build for MAX32 devices using the following commands: