diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 52f1bdb5ad..01db150b3f 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -95,6 +95,7 @@ msgstr "" msgid "%q failure: %d" msgstr "" +#: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c msgid "%q in use" msgstr "" @@ -916,6 +917,10 @@ msgstr "" msgid "Expected a %q" msgstr "" +#: ports/raspberrypi/bindings/cyw43/__init__.c +msgid "Expected a %q or %q" +msgstr "" + #: shared-bindings/alarm/__init__.c msgid "Expected an %q" msgstr "" @@ -1177,7 +1182,7 @@ msgstr "" msgid "Internal watchdog timer expired." msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c msgid "Invalid %q" msgstr "" diff --git a/main.c b/main.c index 04e8777b9a..d8542bcb57 100644 --- a/main.c +++ b/main.c @@ -784,6 +784,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { mp_printf(&mp_plat_print, "%02X", raw_id[i]); } mp_printf(&mp_plat_print, "\n"); + port_boot_info(); #endif bool found_boot = maybe_run_list(boot_py_filenames); diff --git a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c index 8358ac4d87..dc770a2de3 100644 --- a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c +++ b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c @@ -66,11 +66,12 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self self->pin = NULL; } -void common_hal_digitalio_digitalinout_switch_to_input( +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { self->output = false; // This also sets direction to input. common_hal_digitalio_digitalinout_set_pull(self, pull); + return DIGITALINOUT_OK; } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( @@ -151,7 +152,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( } } -void common_hal_digitalio_digitalinout_set_pull( +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { enum gpio_pull_mode asf_pull = GPIO_PULL_OFF; switch (pull) { @@ -168,6 +169,7 @@ void common_hal_digitalio_digitalinout_set_pull( // Must set pull after setting direction. gpio_set_pin_direction(self->pin->number, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(self->pin->number, asf_pull); + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( diff --git a/ports/broadcom/common-hal/digitalio/DigitalInOut.c b/ports/broadcom/common-hal/digitalio/DigitalInOut.c index d8ac3472de..0dd74a8412 100644 --- a/ports/broadcom/common-hal/digitalio/DigitalInOut.c +++ b/ports/broadcom/common-hal/digitalio/DigitalInOut.c @@ -63,11 +63,12 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self self->pin = NULL; } -void common_hal_digitalio_digitalinout_switch_to_input( +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { self->output = false; // This also sets direction to input. common_hal_digitalio_digitalinout_set_pull(self, pull); + return DIGITALINOUT_OK; } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( @@ -134,7 +135,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( } } -void common_hal_digitalio_digitalinout_set_pull( +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { const uint8_t pin = self->pin->number; BP_PULL_Enum bp_pull = BP_PULL_NONE; @@ -144,6 +145,7 @@ void common_hal_digitalio_digitalinout_set_pull( bp_pull = BP_PULL_DOWN; } gpio_set_pull(pin, bp_pull); + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( diff --git a/ports/cxd56/common-hal/digitalio/DigitalInOut.c b/ports/cxd56/common-hal/digitalio/DigitalInOut.c index cfb39301df..c1f247d0a9 100644 --- a/ports/cxd56/common-hal/digitalio/DigitalInOut.c +++ b/ports/cxd56/common-hal/digitalio/DigitalInOut.c @@ -64,11 +64,12 @@ bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *se return self->pin == NULL; } -void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { self->input = true; self->pull = pull; board_gpio_write(self->pin->number, -1); board_gpio_config(self->pin->number, 0, true, true, pull); + return DIGITALINOUT_OK; } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode) { @@ -124,10 +125,11 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitali return self->open_drain ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL; } -void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { self->pull = pull; board_gpio_write(self->pin->number, -1); board_gpio_config(self->pin->number, 0, true, true, pull); + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t *self) { diff --git a/ports/espressif/common-hal/digitalio/DigitalInOut.c b/ports/espressif/common-hal/digitalio/DigitalInOut.c index 63c8ec1a41..61671dadb9 100644 --- a/ports/espressif/common-hal/digitalio/DigitalInOut.c +++ b/ports/espressif/common-hal/digitalio/DigitalInOut.c @@ -82,10 +82,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self self->pin = NULL; } -void common_hal_digitalio_digitalinout_switch_to_input( +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { common_hal_digitalio_digitalinout_set_pull(self, pull); gpio_set_direction(self->pin->number, GPIO_MODE_INPUT); + return DIGITALINOUT_OK; } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( @@ -140,7 +141,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( return DRIVE_MODE_PUSH_PULL; } -void common_hal_digitalio_digitalinout_set_pull( +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { gpio_num_t number = self->pin->number; gpio_pullup_dis(number); @@ -150,6 +151,7 @@ void common_hal_digitalio_digitalinout_set_pull( } else if (pull == PULL_DOWN) { gpio_pulldown_en(number); } + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( diff --git a/ports/litex/common-hal/digitalio/DigitalInOut.c b/ports/litex/common-hal/digitalio/DigitalInOut.c index a48d698fcb..7545722967 100644 --- a/ports/litex/common-hal/digitalio/DigitalInOut.c +++ b/ports/litex/common-hal/digitalio/DigitalInOut.c @@ -58,10 +58,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self self->pin = NULL; } -void common_hal_digitalio_digitalinout_switch_to_input( +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { (void)pull; touch_oe_write(touch_oe_read() & ~(1 << self->pin->number)); + return DIGITALINOUT_OK; } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( @@ -111,10 +112,11 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( } } -void common_hal_digitalio_digitalinout_set_pull( +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { (void)self; (void)pull; + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( diff --git a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c index dde7b3badd..7639204bc6 100644 --- a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c +++ b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c @@ -88,12 +88,13 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self self->pin = NULL; } -void common_hal_digitalio_digitalinout_switch_to_input( +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { self->output = false; // This also sets direction to input. common_hal_digitalio_digitalinout_set_pull(self, pull); + return DIGITALINOUT_OK; } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( @@ -150,7 +151,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( } } -void common_hal_digitalio_digitalinout_set_pull( +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { self->pull = pull; @@ -158,6 +159,7 @@ void common_hal_digitalio_digitalinout_set_pull( const gpio_pin_config_t config = { kGPIO_DigitalInput, 0, kGPIO_NoIntmode }; GPIO_PinInit(self->pin->gpio, self->pin->number, &config); + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( diff --git a/ports/nrf/common-hal/digitalio/DigitalInOut.c b/ports/nrf/common-hal/digitalio/DigitalInOut.c index 95e488f3b7..a6440228f1 100644 --- a/ports/nrf/common-hal/digitalio/DigitalInOut.c +++ b/ports/nrf/common-hal/digitalio/DigitalInOut.c @@ -59,10 +59,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self self->pin = NULL; } -void common_hal_digitalio_digitalinout_switch_to_input( +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { nrf_gpio_cfg_input(self->pin->number, NRF_GPIO_PIN_NOPULL); common_hal_digitalio_digitalinout_set_pull(self, pull); + return DIGITALINOUT_OK; } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( @@ -120,7 +121,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( } } -void common_hal_digitalio_digitalinout_set_pull( +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { nrf_gpio_pin_pull_t hal_pull = NRF_GPIO_PIN_NOPULL; @@ -137,6 +138,7 @@ void common_hal_digitalio_digitalinout_set_pull( } nrf_gpio_cfg_input(self->pin->number, hal_pull); + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index 09824f7c43..313005932c 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -57,6 +57,71 @@ CROSS_COMPILE = arm-none-eabi- HAL_DIR=hal/$(MCU_SERIES) +ifeq ($(CIRCUITPY_CYW43),1) +INC_CYW43 := \ + -isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \ + -isystem sdk/lib/cyw43-driver/src \ + -isystem sdk/lib/cyw43-driver/firmware \ + +CFLAGS_CYW43 := -DCYW43_LWIP=0 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25 +SRC_SDK_CYW43 := \ + lib/cyw43-driver/src/cyw43_ctrl.c \ + lib/cyw43-driver/src/cyw43_ll.c \ + lib/cyw43-driver/src/cyw43_lwip.c \ + lib/cyw43-driver/src/cyw43_stats.c \ + src/common/pico_sync/sem.c \ + src/rp2_common/pico_cyw43_arch/cyw43_arch.c \ + src/rp2_common/pico_cyw43_arch/cyw43_arch_threadsafe_background.c \ + src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.c \ + +SRC_CYW43 := $(wildcard bindings/cyw43/*.c) + +PIOASM = $(BUILD)/sdk/pioasm/pioasm +.PHONY: PioasmBuild +PioasmBuild: $(PIOASM) +$(PIOASM): + $(Q)cmake -S sdk -B $(BUILD)/sdk + $(Q)make -C $(BUILD)/sdk PioasmBuild + +$(BUILD)/cyw43_bus_pio_spi.pio.h: sdk/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.pio $(PIOASM) + $(Q)$(PIOASM) -o c-sdk $< $@ +$(BUILD)/sdk/src/rp2_common/cyw43_driver/cyw43_bus_pio_spi.o: $(BUILD)/cyw43_bus_pio_spi.pio.h + +CYW43_FIRMWARE_BIN = 43439A0-7.95.49.00.combined + +$(BUILD)/cyw43_resource.o: sdk/lib/cyw43-driver/firmware/$(CYW43_FIRMWARE_BIN) + $(Q)$(OBJCOPY) -I binary -O elf32-littlearm -B arm \ + --readonly-text \ + --rename-section .data=.big_const,contents,alloc,load,readonly,data \ + --redefine-sym _binary_sdk_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_start=fw_43439A0_7_95_49_00_start \ + --redefine-sym _binary_sdk_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_size=fw_43439A0_7_95_49_00_size \ + --redefine-sym _binary_sdk_lib_cyw43_driver_firmware_43439A0_7_95_49_00_combined_end=fw_43439A0_7_95_49_00_end \ + $< $@ +OBJ_CYW43 := $(BUILD)/cyw43_resource.o +# need to do the equivalent of this in cmake +### # cyw43_resource.o contains the WiFi and BT firmware as a binary blob +### add_custom_command( +### OUTPUT ${CYW43_FIRMWARE_OBJ} +### DEPENDS ${PICO_CYW43_DRIVER_PATH}/firmware/${CYW43_FIRMWARE_BIN} +### WORKING_DIRECTORY ${PICO_CYW43_DRIVER_PATH}/firmware +### COMMAND ${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm +### --readonly-text +### --rename-section .data=${RESOURCE_SECNAME},${RESOURCE_SECFLAGS} +### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_start=${CYW43_FIRMWARE_PRETTY}_start +### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_end=${CYW43_FIRMWARE_PRETTY}_end +### --redefine-sym _binary_${CYW43_FIRMWARE_BIN_}_size=${CYW43_FIRMWARE_PRETTY}_size +### ${CYW43_FIRMWARE_BIN} ${CYW43_FIRMWARE_OBJ} +### ) +### +else +$(error y u no y fi) +INC_CYW43 := +CFLAGS_CYW43 := +SRC_SDK_CYW43 := +SRC_CYW43 := +OBJ_CYW43 := +endif + INC += \ -I. \ -I../.. \ @@ -102,6 +167,7 @@ INC += \ -isystem sdk/src/rp2_common/pico_runtime/printf/include/ \ -isystem sdk/src/rp2_common/pico_bootrom/include/ \ -isystem sdk/src/rp2_common/pico_unique_id/include/ \ + $(INC_CYW43) \ -Isdk_config \ -I../../lib/tinyusb/src \ -I../../supervisor/shared/usb \ @@ -116,6 +182,9 @@ CFLAGS += -DTUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX=1 -DCFG_TUSB_MCU=OPT_MCU_R # option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk CFLAGS += $(OPTIMIZATION_FLAGS) +# flags specific to wifi / cyw43 + +CFLAGS += $(CFLAGS_CYW43) #Debugging/Optimization ifeq ($(DEBUG), 1) CFLAGS += -ggdb3 -O3 @@ -133,7 +202,7 @@ endif # Remove -Wno-stringop-overflow after we can test with CI's GCC 10. Mac's looks weird. DISABLE_WARNINGS = -Wno-stringop-overflow -Wno-unused-function -Wno-unused-variable -Wno-strict-overflow -Wno-cast-align -Wno-strict-prototypes -Wno-nested-externs -Wno-double-promotion -Wno-sign-compare -CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes +CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes -Wno-error=unused-result CFLAGS += \ -march=armv6-m \ @@ -186,6 +255,7 @@ SRC_SDK := \ src/rp2_common/pico_runtime/runtime.c \ src/rp2_common/pico_stdio/stdio.c \ src/rp2_common/pico_unique_id/unique_id.c \ + $(SRC_SDK_CYW43) \ SRC_SDK := $(addprefix sdk/, $(SRC_SDK)) $(patsubst %.c,$(BUILD)/%.o,$(SRC_SDK)): CFLAGS += -Wno-missing-prototypes -Wno-undef @@ -205,6 +275,7 @@ SRC_C += \ lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c \ lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c \ mphalport.c \ + $(SRC_CYW43) \ SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ @@ -244,6 +315,7 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_S_UPPER:.S=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) OBJ += $(BUILD)/boot2_padded_checksummed.o +OBJ += $(OBJ_CYW43) $(BUILD)/boot2_padded_checksummed.o: $(BUILD)/boot2_padded_checksummed.S $(STEPECHO) "CC $<" diff --git a/ports/raspberrypi/bindings/cyw43/__init__.c b/ports/raspberrypi/bindings/cyw43/__init__.c new file mode 100644 index 0000000000..2d5479a5d2 --- /dev/null +++ b/ports/raspberrypi/bindings/cyw43/__init__.c @@ -0,0 +1,70 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Jeff Epler for Adafruit Industries + * Copyright (c) 2016 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/runtime.h" + +#include "shared-bindings/board/__init__.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "bindings/cyw43/__init__.h" + +const mp_obj_type_t cyw43_pin_type = { + { &mp_type_type }, + .flags = MP_TYPE_FLAG_EXTENDED, + .name = MP_QSTR_CywPin, + .print = shared_bindings_microcontroller_pin_print, + MP_TYPE_EXTENDED_FIELDS( + .unary_op = mp_generic_unary_op, + ) +}; + +const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj) { + if (!mp_obj_is_type(obj, &mcu_pin_type) && !mp_obj_is_type(obj, &cyw43_pin_type)) { + mp_raise_TypeError_varg(translate("Expected a %q or %q"), mcu_pin_type.name, cyw43_pin_type.name); + } + return MP_OBJ_TO_PTR(obj); +} + +const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj) { + const mcu_pin_obj_t *pin = validate_obj_is_pin_including_cyw43(obj); + assert_pin_free(pin); + return pin; +} + +STATIC const mp_rom_map_elem_t cyw43_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cyw43) }, + { MP_ROM_QSTR(MP_QSTR_CywPin), MP_ROM_QSTR(MP_QSTR_CywPin) }, +}; + +STATIC MP_DEFINE_CONST_DICT(cyw43_module_globals, cyw43_module_globals_table); + +const mp_obj_module_t cyw43_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&cyw43_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_cyw43, cyw43_module, CIRCUITPY_CYW43); diff --git a/ports/raspberrypi/bindings/cyw43/__init__.h b/ports/raspberrypi/bindings/cyw43/__init__.h new file mode 100644 index 0000000000..5dcdfba52b --- /dev/null +++ b/ports/raspberrypi/bindings/cyw43/__init__.h @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Jeff Epler for Adafruit Industries + * Copyright (c) 2016 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +#include "py/obj.h" + +extern const mp_obj_type_t cyw43_pin_type; +const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj); +const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj); diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/board.c b/ports/raspberrypi/boards/raspberry_pi_pico_w/board.c new file mode 100644 index 0000000000..de6e424ed9 --- /dev/null +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} + +void board_deinit(void) { +} diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld new file mode 100644 index 0000000000..7d0a44ce51 --- /dev/null +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld @@ -0,0 +1,293 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +MEMORY +{ + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1788k + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k + SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k + SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k +} + +ENTRY(_entry_point) + +SECTIONS +{ + /* Second stage bootloader is prepended to the image. It must be 256 bytes big + and checksummed. It is usually built by the boot_stage2 target + in the Pico SDK + */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH_FIRMWARE + + .boot2 : { + __boot2_start__ = .; + KEEP (*(.boot2)) + __boot2_end__ = .; + } > FLASH_FIRMWARE + + ASSERT(__boot2_end__ - __boot2_start__ == 256, + "ERROR: Pico second stage bootloader must be 256 bytes in size") + + /* The second stage will always enter the image at the start of .text. + The debugger will use the ELF entry point, which is the _entry_point + symbol if present, otherwise defaults to start of .text. + This can be used to transfer control back to the bootrom on debugger + launches only, to perform proper flash setup. + */ + + .text : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.reset)) + /* TODO revisit this now memset/memcpy/float in ROM */ + /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from + * FLASH ... we will include any thing excluded here in .data below by default */ + *(.init) + + __property_getter_start = .; + *(.property_getter) + __property_getter_end = .; + __property_getset_start = .; + *(.property_getset) + __property_getset_end = .; + + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + . = ALIGN(4); + } > FLASH_FIRMWARE + + .rodata : { + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH_FIRMWARE + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH_FIRMWARE + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH_FIRMWARE + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH_FIRMWARE + __binary_info_end = .; + . = ALIGN(4); + + /* End of .text-like segments */ + __etext = .; + + .ram_vector_table (COPY): { + *(.ram_vector_table) + } > RAM + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ + *(.text*) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + 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 = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + } > RAM AT> FLASH_FIRMWARE + + .itcm : + { + . = ALIGN(4); + *(.itcm.*) + + . = ALIGN(4); + } > RAM AT> FLASH_FIRMWARE + _ld_itcm_destination = ADDR(.itcm); + _ld_itcm_flash_copy = LOADADDR(.itcm); + _ld_itcm_size = SIZEOF(.itcm); + + .dtcm_data : + { + . = ALIGN(4); + + *(.dtcm_data.*) + + . = ALIGN(4); + } > RAM AT> FLASH_FIRMWARE + _ld_dtcm_data_destination = ADDR(.dtcm_data); + _ld_dtcm_data_flash_copy = LOADADDR(.dtcm_data); + _ld_dtcm_data_size = SIZEOF(.dtcm_data); + + .dtcm_bss : + { + . = ALIGN(4); + + *(.dtcm_bss.*) + + . = ALIGN(4); + } > RAM AT> RAM + _ld_dtcm_bss_start = ADDR(.dtcm_bss); + _ld_dtcm_bss_size = SIZEOF(.dtcm_bss); + + .uninitialized_data (COPY): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT > FLASH_FIRMWARE + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT > FLASH_FIRMWARE + __scratch_y_source__ = LOADADDR(.scratch_y); + + .bss : { + . = ALIGN(4); + __bss_start__ = .; + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + end = __end__; + *(.heap*) + __HeapLimit = .; + } > 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 + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (COPY): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (COPY): + { + *(.stack*) + } > SCRATCH_Y + + .flash_end : { + __flash_binary_end = .; + } > FLASH_FIRMWARE + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") + /* todo assert on extra code */ +} diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.h b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.h new file mode 100644 index 0000000000..58a291b18b --- /dev/null +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.h @@ -0,0 +1,5 @@ +#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico W" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (1) +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (1) diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk new file mode 100644 index 0000000000..0b3ce5ef00 --- /dev/null +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk @@ -0,0 +1,20 @@ +USB_VID = 0x239A +USB_PID = 0x8120 +USB_PRODUCT = "Pico W" +USB_MANUFACTURER = "Raspberry Pi" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" + +CIRCUITPY__EVE = 1 + +CIRCUITPY_CYW43 = 1 +CIRCUITPY_SSL = 0 +CIRCUITPY_HASHLIB = 0 +CIRCUITPY_WEB_WORKFLOW = 0 +CIRCUITPY_MDNS = 0 +CIRCUITPY_SOCKETPOOL = 0 + +CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/pico-sdk-configboard.h b/ports/raspberrypi/boards/raspberry_pi_pico_w/pico-sdk-configboard.h new file mode 100644 index 0000000000..36da55d457 --- /dev/null +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/pico-sdk-configboard.h @@ -0,0 +1 @@ +// Put board-specific pico-sdk definitions here. This file must exist. diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/pins.c b/ports/raspberrypi/boards/raspberry_pi_pico_w/pins.c new file mode 100644 index 0000000000..fb3570cc8a --- /dev/null +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/pins.c @@ -0,0 +1,54 @@ +#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_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_GP23), MP_ROM_PTR(&pin_GPIO23) }, + + { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_CYW0) }, + { MP_ROM_QSTR(MP_QSTR_CYW0), MP_ROM_PTR(&pin_CYW0) }, + + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c b/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c index ef431d8506..1702254f9f 100644 --- a/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c +++ b/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c @@ -31,11 +31,18 @@ #include "py/mphal.h" #include "common-hal/microcontroller/Pin.h" +#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/digitalio/DigitalInOut.h" #include "supervisor/shared/translate/translate.h" #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#if CIRCUITPY_CYW43 +#include "pico/cyw43_arch.h" +#include "bindings/cyw43/__init__.h" +#define IS_CYW(self) ((self)->pin->base.type == &cyw43_pin_type) +#endif + digitalinout_result_t common_hal_digitalio_digitalinout_construct( digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) { claim_pin(pin); @@ -61,20 +68,31 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self if (common_hal_digitalio_digitalinout_deinited(self)) { return; } - reset_pin_number(self->pin->number); + common_hal_reset_pin(self->pin); self->pin = NULL; } -void common_hal_digitalio_digitalinout_switch_to_input( +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { - self->output = false; // This also sets direction to input. - common_hal_digitalio_digitalinout_set_pull(self, pull); + 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) { + + #if CIRCUITPY_CYW43 + if (IS_CYW(self)) { + if (drive_mode != DRIVE_MODE_PUSH_PULL) { + return DIGITALINOUT_INVALID_DRIVE_MODE; + } + cyw43_arch_gpio_put(self->pin->number, value); + self->output = true; + self->open_drain = false; + return DIGITALINOUT_OK; + } + #endif const uint8_t pin = self->pin->number; gpio_disable_pulls(pin); @@ -99,6 +117,12 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( void common_hal_digitalio_digitalinout_set_value( digitalio_digitalinout_obj_t *self, bool value) { const uint8_t pin = self->pin->number; + #if CIRCUITPY_CYW43 + if (IS_CYW(self)) { + cyw43_arch_gpio_put(pin, value); + return; + } + #endif if (self->open_drain && value) { // If true and open-drain, set the direction -before- setting // the pin value, to to avoid a high glitch on the pin before @@ -122,6 +146,13 @@ bool common_hal_digitalio_digitalinout_get_value( digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode) { + #if CIRCUITPY_CYW43 + if (IS_CYW(self)) { + if (drive_mode != DRIVE_MODE_PUSH_PULL) { + return DIGITALINOUT_INVALID_DRIVE_MODE; + } + } + #endif const uint8_t pin = self->pin->number; bool value = common_hal_digitalio_digitalinout_get_value(self); self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN; @@ -142,11 +173,23 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( } } -void common_hal_digitalio_digitalinout_set_pull( +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + #if CIRCUITPY_CYW43 + if (IS_CYW(self)) { + if (pull != PULL_NONE) { + return DIGITALINOUT_INVALID_PULL; + } + cyw43_arch_gpio_get(self->pin->number); + self->output = false; + return DIGITALINOUT_OK; + } + #endif const uint8_t pin = self->pin->number; gpio_set_pulls(pin, pull == PULL_UP, pull == PULL_DOWN); gpio_set_dir(pin, GPIO_IN); + self->output = false; + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( @@ -170,6 +213,11 @@ bool common_hal_digitalio_has_reg_op(digitalinout_reg_op_t op) { } volatile uint32_t *common_hal_digitalio_digitalinout_get_reg(digitalio_digitalinout_obj_t *self, digitalinout_reg_op_t op, uint32_t *mask) { + #if CIRCUITPY_CYW43 + if (IS_CYW(self)) { + return NULL; + } + #endif const uint8_t pin = self->pin->number; *mask = 1u << pin; diff --git a/ports/raspberrypi/common-hal/microcontroller/Pin.c b/ports/raspberrypi/common-hal/microcontroller/Pin.c index d40c1f43b5..59adb5395f 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Pin.c +++ b/ports/raspberrypi/common-hal/microcontroller/Pin.c @@ -28,11 +28,19 @@ #include "common-hal/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" +#include "bindings/cyw43/__init__.h" #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#if CIRCUITPY_CYW43 +#include "pico/cyw43_arch.h" +#endif + STATIC uint32_t never_reset_pins; +bool cyw_ever_init; +static uint32_t cyw_pin_claimed; + void reset_all_pins(void) { for (size_t i = 0; i < TOTAL_GPIO_COUNT; i++) { if ((never_reset_pins & (1 << i)) != 0) { @@ -40,6 +48,14 @@ void reset_all_pins(void) { } reset_pin_number(i); } + #if CIRCUITPY_CYW43 + if (cyw_ever_init) { + for (size_t i = 0; i < 1; i++) { + cyw43_arch_gpio_put(i, 0); + } + } + cyw_pin_claimed = 0; + #endif } void never_reset_pin_number(uint8_t pin_number) { @@ -66,15 +82,30 @@ void reset_pin_number(uint8_t pin_number) { hw_set_bits(&padsbank0_hw->io[pin_number], PADS_BANK0_GPIO0_OD_BITS); } +void reset_pin_number_cyw(uint8_t pin_no) { + cyw_pin_claimed &= ~(1 << pin_no); +} + void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { never_reset_pin_number(pin->number); } void common_hal_reset_pin(const mcu_pin_obj_t *pin) { + #if CIRCUITPY_CYW43 + if (pin->base.type == &cyw43_pin_type) { + reset_pin_number_cyw(pin->number); + return; + } + #endif reset_pin_number(pin->number); } void claim_pin(const mcu_pin_obj_t *pin) { + #if CIRCUITPY_CYW43 + if (pin->base.type == &cyw43_pin_type) { + cyw_pin_claimed |= (1 << pin->number); + } + #endif // Nothing to do because all changes will set the GPIO settings. } @@ -89,6 +120,11 @@ bool pin_number_is_free(uint8_t pin_number) { } bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { + #if CIRCUITPY_CYW43 + if (pin->base.type == &cyw43_pin_type) { + return !(cyw_pin_claimed & (1 << pin->number)); + } + #endif return pin_number_is_free(pin->number); } diff --git a/ports/raspberrypi/common-hal/microcontroller/Pin.h b/ports/raspberrypi/common-hal/microcontroller/Pin.h index 3e2287dc5d..5042dd7d66 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Pin.h +++ b/ports/raspberrypi/common-hal/microcontroller/Pin.h @@ -34,10 +34,13 @@ #include "peripherals/pins.h" +extern bool cyw_ever_init; + 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_number); +void reset_pin_number_cyw(uint8_t pin_number); void never_reset_pin_number(uint8_t pin_number); void claim_pin(const mcu_pin_obj_t *pin); bool pin_number_is_free(uint8_t pin_number); diff --git a/ports/raspberrypi/common-hal/microcontroller/__init__.c b/ports/raspberrypi/common-hal/microcontroller/__init__.c index 3b656edc07..5e79fbd0ce 100644 --- a/ports/raspberrypi/common-hal/microcontroller/__init__.c +++ b/ports/raspberrypi/common-hal/microcontroller/__init__.c @@ -175,10 +175,15 @@ const mp_rom_map_elem_t mcu_pin_global_dict_table[TOTAL_GPIO_COUNT] = { { MP_ROM_QSTR(MP_QSTR_GPIO22), MP_ROM_PTR(&pin_GPIO22) }, { MP_ROM_QSTR(MP_QSTR_GPIO23), MP_ROM_PTR(&pin_GPIO23) }, { MP_ROM_QSTR(MP_QSTR_GPIO24), MP_ROM_PTR(&pin_GPIO24) }, + #if !defined(IGNORE_GPIO25) { MP_ROM_QSTR(MP_QSTR_GPIO25), MP_ROM_PTR(&pin_GPIO25) }, + #endif { MP_ROM_QSTR(MP_QSTR_GPIO26), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_GPIO27), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_GPIO28), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_GPIO29), MP_ROM_PTR(&pin_GPIO29) }, + #if CIRCUITPY_CYW43 + { MP_ROM_QSTR(MP_QSTR_CYW0), MP_ROM_PTR(&pin_CYW0) }, + #endif }; MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table); diff --git a/ports/raspberrypi/peripherals/pins.c b/ports/raspberrypi/peripherals/pins.c index 1b5fe91cac..e6a197f3be 100644 --- a/ports/raspberrypi/peripherals/pins.c +++ b/ports/raspberrypi/peripherals/pins.c @@ -27,6 +27,7 @@ #include "pins.h" #include "shared-bindings/microcontroller/Pin.h" +#include "bindings/cyw43/__init__.h" // This macro is used to simplify pin definition in boards//pins.c #define PIN(p_number) \ @@ -34,6 +35,11 @@ { &mcu_pin_type }, \ .number = p_number \ } +#define CYW_PIN(p_number) \ + const mcu_pin_obj_t pin_CYW##p_number = { \ + { &cyw43_pin_type }, \ + .number = p_number \ + } PIN(0); PIN(1); @@ -60,8 +66,13 @@ PIN(21); PIN(22); PIN(23); PIN(24); +#if !defined(IGNORE_GPIO25) PIN(25); +#endif PIN(26); PIN(27); PIN(28); PIN(29); +#if CIRCUITPY_CYW43 +CYW_PIN(0); +#endif diff --git a/ports/raspberrypi/peripherals/pins.h b/ports/raspberrypi/peripherals/pins.h index 99ab9cfe48..0a01b3959e 100644 --- a/ports/raspberrypi/peripherals/pins.h +++ b/ports/raspberrypi/peripherals/pins.h @@ -62,10 +62,16 @@ extern const mcu_pin_obj_t pin_GPIO21; extern const mcu_pin_obj_t pin_GPIO22; extern const mcu_pin_obj_t pin_GPIO23; extern const mcu_pin_obj_t pin_GPIO24; +#if !defined(IGNORE_GPIO25) extern const mcu_pin_obj_t pin_GPIO25; +#endif extern const mcu_pin_obj_t pin_GPIO26; extern const mcu_pin_obj_t pin_GPIO27; extern const mcu_pin_obj_t pin_GPIO28; extern const mcu_pin_obj_t pin_GPIO29; +#if CIRCUITPY_CYW43 +extern const mcu_pin_obj_t pin_CYW0; +#endif + #endif // MICROPY_INCLUDED_RASPBERRYPI_PERIPHERALS_PINS_H diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index 5041250c0a..2e1fed7a25 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -53,12 +53,17 @@ #include "src/rp2_common/hardware_uart/include/hardware/uart.h" #include "src/rp2_common/hardware_sync/include/hardware/sync.h" #include "src/rp2_common/hardware_timer/include/hardware/timer.h" +#if CIRCUITPY_CYW43 +#include "pico/cyw43_arch.h" +#endif #include "src/common/pico_time/include/pico/time.h" #include "src/common/pico_binary_info/include/pico/binary_info.h" #include "pico/bootrom.h" #include "hardware/watchdog.h" +#include "supervisor/serial.h" + extern volatile bool mp_msc_enabled; STATIC void _tick_callback(uint alarm_num); @@ -122,6 +127,24 @@ safe_mode_t port_init(void) { // Check brownout. + #if CIRCUITPY_CYW43 + never_reset_pin_number(23); + never_reset_pin_number(24); + never_reset_pin_number(25); + never_reset_pin_number(29); + if (cyw43_arch_init()) { + serial_write("WiFi init failed\n"); + return -1; + } else { + cyw_ever_init = true; + for (int i = 3; i--;) { + cyw43_arch_gpio_put(0, 1); + sleep_ms(100); + cyw43_arch_gpio_put(0, 0); + sleep_ms(100); + } + } + #endif if (board_requests_safe_mode()) { return USER_SAFE_MODE; } @@ -261,3 +284,19 @@ __attribute__((used)) void HardFault_Handler(void) { asm ("nop;"); } } + +void port_yield() { + #if CIRCUITPY_CYW43 + cyw43_arch_poll(); + #endif +} + +void port_boot_info(void) { + #if CIRCUITPY_CYW43 + mp_printf(&mp_plat_print, "MAC"); + for (int i = 0; i < 6; i++) { + mp_printf(&mp_plat_print, ":%02X", cyw43_state.mac[i]); + } + mp_printf(&mp_plat_print, "\n"); + #endif +} diff --git a/ports/stm/common-hal/digitalio/DigitalInOut.c b/ports/stm/common-hal/digitalio/DigitalInOut.c index 3a0e27943b..58f81b43b6 100644 --- a/ports/stm/common-hal/digitalio/DigitalInOut.c +++ b/ports/stm/common-hal/digitalio/DigitalInOut.c @@ -77,7 +77,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self self->pin = NULL; } -void common_hal_digitalio_digitalinout_switch_to_input( +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { GPIO_InitTypeDef GPIO_InitStruct = {0}; @@ -88,6 +88,7 @@ void common_hal_digitalio_digitalinout_switch_to_input( HAL_GPIO_Init(pin_port(self->pin->port), &GPIO_InitStruct); common_hal_digitalio_digitalinout_set_pull(self, pull); + return DIGITALINOUT_OK; } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( @@ -138,7 +139,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( == LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL; } -void common_hal_digitalio_digitalinout_set_pull( +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { switch (pull) { @@ -154,6 +155,7 @@ void common_hal_digitalio_digitalinout_set_pull( default: break; } + return DIGITALINOUT_OK; } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 80377f1a65..b5c8047f99 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -170,6 +170,9 @@ endif ifeq ($(CIRCUITPY_COUNTIO),1) SRC_PATTERNS += countio/% endif +ifeq ($(CIRCUITPY_CYW43),1) +SRC_PATTERNS += cyw43/% +endif ifeq ($(CIRCUITPY_DIGITALIO),1) SRC_PATTERNS += digitalio/% endif diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index acdf08e6a4..7c497c6106 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -588,6 +588,15 @@ void supervisor_run_background_tasks_if_tick(void); #define MICROPY_WRAP_MP_EXECUTE_BYTECODE PLACE_IN_ITCM #endif +#ifndef CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (0) +#endif + +#ifndef CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (0) +#endif + + #define MICROPY_PY_OPTIMIZE_PROPERTY_FLASH_SIZE (CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE) #endif // __INCLUDED_MPCONFIG_CIRCUITPY_H diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 0f4269c522..6bff102dd4 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -159,6 +159,9 @@ CFLAGS += -DCIRCUITPY_CAMERA=$(CIRCUITPY_CAMERA) CIRCUITPY_CANIO ?= 0 CFLAGS += -DCIRCUITPY_CANIO=$(CIRCUITPY_CANIO) +CIRCUITPY_CYW43 ?= 0 +CFLAGS += -DCIRCUITPY_CYW43=$(CIRCUITPY_CYW43) + CIRCUITPY_DIGITALIO ?= 1 CFLAGS += -DCIRCUITPY_DIGITALIO=$(CIRCUITPY_DIGITALIO) diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index ae72b5cb55..c4a1f853b5 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -43,6 +43,29 @@ #include "shared-bindings/util.h" #include "supervisor/shared/translate/translate.h" +#if CIRCUITPY_CYW43 +#include "bindings/cyw43/__init__.h" +#endif + +STATIC void check_result(digitalinout_result_t result) { + switch (result) { + case DIGITALINOUT_OK: + return; + case DIGITALINOUT_PIN_BUSY: + mp_raise_ValueError_varg(translate("%q in use"), MP_QSTR_Pin); + case DIGITALINOUT_INPUT_ONLY: + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_direction); + #if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL + case DIGITALINOUT_INVALID_PULL: + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_pull); + #endif + #if CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE + case DIGITALINOUT_INVALID_DRIVE_MODE: + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_drive_mode); + #endif + } +} + //| class DigitalInOut: //| """Digital input and output //| @@ -65,7 +88,11 @@ STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type, digitalio_digitalinout_obj_t *self = m_new_obj(digitalio_digitalinout_obj_t); self->base.type = &digitalio_digitalinout_type; + #if CIRCUITPY_CYW43 + const mcu_pin_obj_t *pin = validate_obj_is_free_pin_including_cyw43(args[0]); + #else const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); + #endif common_hal_digitalio_digitalinout_construct(self, pin); return MP_OBJ_FROM_PTR(self); @@ -166,7 +193,7 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_input(size_t n_args, const mp_o 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_digitalio_digitalinout_switch_to_input(self, validate_pull(args[ARG_pull].u_rom_obj, MP_QSTR_pull)); + check_result(common_hal_digitalio_digitalinout_switch_to_input(self, validate_pull(args[ARG_pull].u_rom_obj, MP_QSTR_pull))); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_input_obj, 1, digitalio_digitalinout_switch_to_input); @@ -200,7 +227,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_direction(mp_obj_t self_in, mp_ob digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); if (value == MP_ROM_PTR(&digitalio_direction_input_obj)) { - common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE); + check_result(common_hal_digitalio_digitalinout_switch_to_input(self, PULL_NONE)); } else if (value == MP_ROM_PTR(&digitalio_direction_output_obj)) { digitalinout_result_t result = common_hal_digitalio_digitalinout_switch_to_output(self, false, DRIVE_MODE_PUSH_PULL); if (result == DIGITALINOUT_INPUT_ONLY) { @@ -276,7 +303,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_drive_mode(mp_obj_t self_in, mp_o if (drive_mode == MP_ROM_PTR(&digitalio_drive_mode_open_drain_obj)) { c_drive_mode = DRIVE_MODE_OPEN_DRAIN; } - common_hal_digitalio_digitalinout_set_drive_mode(self, c_drive_mode); + check_result(common_hal_digitalio_digitalinout_set_drive_mode(self, c_drive_mode)); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(digitalio_digitalinout_set_drive_mode_obj, digitalio_digitalinout_obj_set_drive_mode); @@ -319,7 +346,7 @@ STATIC mp_obj_t digitalio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t p return mp_const_none; } - common_hal_digitalio_digitalinout_set_pull(self, validate_pull(pull_obj, MP_QSTR_pull)); + check_result(common_hal_digitalio_digitalinout_set_pull(self, validate_pull(pull_obj, MP_QSTR_pull))); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(digitalio_digitalinout_set_pull_obj, digitalio_digitalinout_obj_set_pull); diff --git a/shared-bindings/digitalio/DigitalInOut.h b/shared-bindings/digitalio/DigitalInOut.h index b6edbc63aa..9a751e93bb 100644 --- a/shared-bindings/digitalio/DigitalInOut.h +++ b/shared-bindings/digitalio/DigitalInOut.h @@ -38,7 +38,13 @@ extern const mp_obj_type_t digitalio_digitalinout_type; typedef enum { DIGITALINOUT_OK, DIGITALINOUT_PIN_BUSY, - DIGITALINOUT_INPUT_ONLY + DIGITALINOUT_INPUT_ONLY, + #if CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL + DIGITALINOUT_INVALID_PULL, + #endif + #if CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE + DIGITALINOUT_INVALID_DRIVE_MODE, + #endif } digitalinout_result_t; typedef enum { @@ -52,14 +58,14 @@ typedef enum { digitalinout_result_t common_hal_digitalio_digitalinout_construct(digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin); void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self); bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self); -void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull); +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull); digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(digitalio_digitalinout_obj_t *self, bool value, digitalio_drive_mode_t drive_mode); digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(digitalio_digitalinout_obj_t *self); void common_hal_digitalio_digitalinout_set_value(digitalio_digitalinout_obj_t *self, bool value); bool common_hal_digitalio_digitalinout_get_value(digitalio_digitalinout_obj_t *self); digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(digitalio_digitalinout_obj_t *self, digitalio_drive_mode_t drive_mode); digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(digitalio_digitalinout_obj_t *self); -void common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull); +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull); digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(digitalio_digitalinout_obj_t *self); void common_hal_digitalio_digitalinout_never_reset(digitalio_digitalinout_obj_t *self); digitalio_digitalinout_obj_t *assert_digitalinout(mp_obj_t obj); diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index 840f468e2a..1bf41e1e61 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -70,7 +70,7 @@ static void get_pin_name(const mcu_pin_obj_t *self, qstr *package, qstr *module, } } -STATIC void mcu_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +void shared_bindings_microcontroller_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mcu_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); qstr package = MP_QSTR_Pin; qstr module; @@ -88,7 +88,7 @@ const mp_obj_type_t mcu_pin_type = { { &mp_type_type }, .flags = MP_TYPE_FLAG_EXTENDED, .name = MP_QSTR_Pin, - .print = mcu_pin_print, + .print = shared_bindings_microcontroller_pin_print, MP_TYPE_EXTENDED_FIELDS( .unary_op = mp_generic_unary_op, ) diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h index 12ff422a4a..b41b3c308a 100644 --- a/shared-bindings/microcontroller/Pin.h +++ b/shared-bindings/microcontroller/Pin.h @@ -55,6 +55,8 @@ 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); +void shared_bindings_microcontroller_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); + #define COMMON_HAL_MCU_NO_PIN ((uint8_t)0xff) #endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H diff --git a/supervisor/port.h b/supervisor/port.h index 554baca2a4..2fb24385c1 100644 --- a/supervisor/port.h +++ b/supervisor/port.h @@ -120,4 +120,8 @@ void port_yield(void); // A default weak implementation is provided that does nothing. void port_post_boot_py(bool heap_valid); +// Some ports want to add information to boot_out.txt. +// A default weak implementation is provided that does nothing. +void port_boot_info(void); + #endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H diff --git a/supervisor/shared/port.c b/supervisor/shared/port.c index e78e6a931a..4070cf254e 100644 --- a/supervisor/shared/port.c +++ b/supervisor/shared/port.c @@ -34,3 +34,6 @@ MP_WEAK void port_wake_main_task_from_isr(void) { MP_WEAK void port_yield(void) { } + +MP_WEAK void port_boot_info(void) { +}