From a2514ca3049cb90a38fcacd8a7d089923b969e64 Mon Sep 17 00:00:00 2001 From: Phillip Burgess Date: Wed, 8 Mar 2023 11:37:51 -0800 Subject: [PATCH 01/23] Add board adafruit_feather_rp2040_dvi Based on Feather RP2040 SCORPIO, but new USB PID (from MBAdafruitBoards/Production) and pin name changes for GP16-23 (CKN/CKP etc., from board schematic). --- .../adafruit_feather_rp2040_dvi/board.c | 29 +++++++++++ .../mpconfigboard.h | 14 ++++++ .../mpconfigboard.mk | 9 ++++ .../pico-sdk-configboard.h | 4 ++ .../boards/adafruit_feather_rp2040_dvi/pins.c | 48 +++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c new file mode 100644 index 0000000000..331653173e --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c @@ -0,0 +1,29 @@ +/* + * 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" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.h new file mode 100644 index 0000000000..06cfaf37f6 --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.h @@ -0,0 +1,14 @@ +#define MICROPY_HW_BOARD_NAME "Adafruit Feather RP2040 DVI" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO16) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO3) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO2) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO14) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO15) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO8) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO1) +#define DEFAULT_UART_BUS_TX (&pin_GPIO0) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.mk b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.mk new file mode 100644 index 0000000000..a60ff7b9a7 --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.mk @@ -0,0 +1,9 @@ +USB_VID = 0x239A +USB_PID = 0x8128 +USB_PRODUCT = "Feather RP2040 DVI" +USB_MANUFACTURER = "Adafruit" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ" diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pico-sdk-configboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pico-sdk-configboard.h new file mode 100644 index 0000000000..a41131dd22 --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pico-sdk-configboard.h @@ -0,0 +1,4 @@ +// 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/adafruit_feather_rp2040_dvi/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c new file mode 100644 index 0000000000..b352cd96e2 --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c @@ -0,0 +1,48 @@ +#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_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + { 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_D24), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO3) }, + { 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_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_LED), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_CKN), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_CKP), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_D0N), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_D0P), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_D1N), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_D1P), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_D2N), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_D2P), MP_ROM_PTR(&pin_GPIO23) }, + + { 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_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From de3c5ad2f4c71170bb7f5e1e94c4159ef9f07cf2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 11:00:55 -0500 Subject: [PATCH 02/23] add blank lines around aliased pins --- ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c index b352cd96e2..f8618cd6d1 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c @@ -12,10 +12,13 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO14) }, { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO15) }, { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO0) }, { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO7) }, @@ -27,6 +30,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { 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_LED), MP_ROM_PTR(&pin_GPIO13) }, From 2ebc0ea51ca22a0e32d1d2d2ead7000bca971bfa Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 11:30:38 -0500 Subject: [PATCH 03/23] GitHub online editor introduced spaces on blank lines :( --- ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c index f8618cd6d1..e014ace05a 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c @@ -15,10 +15,10 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, - + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO0) }, { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, - + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO7) }, From ec2101f4aa5a94d3592a9fedd1672ec896d28463 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 13:18:54 -0500 Subject: [PATCH 04/23] update tinyusb to latest --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index 73896a3b71..990fb6ae5c 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 73896a3b71c525a3ee4cefa7e35ce3b3a93786ef +Subproject commit 990fb6ae5c4d9d4b77c5a9ecb3a2abe899dd2712 From 0f31ba676b187d2d641eabb8cce4a298cea3ae8e Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 17:40:53 -0500 Subject: [PATCH 05/23] update errata fixes for RP2040 --- ports/raspberrypi/sdk_config/pico/config_autogen.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/raspberrypi/sdk_config/pico/config_autogen.h b/ports/raspberrypi/sdk_config/pico/config_autogen.h index a29ccb458a..ee99b1c609 100644 --- a/ports/raspberrypi/sdk_config/pico/config_autogen.h +++ b/ports/raspberrypi/sdk_config/pico/config_autogen.h @@ -18,6 +18,8 @@ #define PICO_NO_HARDWARE (0) #define PICO_ON_DEVICE (1) #define PICO_PRINTF_ALWAYS_INCLUDED (1) +#define PICO_RP2040_USB_DEVICE_ENUMERATION_FIX (1) +#define PICO_RP2040_USB_DEVICE_UFRAME_FIX (1) #define PICO_STDIO_IGNORE_NESTED_STDOUT (0) #define PICO_USE_CRT_PRINTF (0) #define PICO_USE_OPTIMISTIC_SBRK (0) From 7f10f36dfbe4b5f48371e40e66157236b696f102 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Mar 2023 23:18:58 -0500 Subject: [PATCH 06/23] usbh_control.c no longer exists --- supervisor/supervisor.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 801025f41a..c461c5353f 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -163,7 +163,6 @@ ifeq ($(CIRCUITPY_USB),1) SRC_SUPERVISOR += \ lib/tinyusb/src/host/hub.c \ lib/tinyusb/src/host/usbh.c \ - lib/tinyusb/src/host/usbh_control.c \ endif endif From 5cb21539f295d3537a80bbf4c33266a9feab6642 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 10 Mar 2023 13:12:37 -0500 Subject: [PATCH 07/23] use revised USB host API on mimxrt10xx --- shared-module/usb/core/Device.c | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/shared-module/usb/core/Device.c b/shared-module/usb/core/Device.c index 81431d5d7a..706c94eec3 100644 --- a/shared-module/usb/core/Device.c +++ b/shared-module/usb/core/Device.c @@ -61,12 +61,9 @@ uint16_t common_hal_usb_core_device_get_idProduct(usb_core_device_obj_t *self) { } STATIC xfer_result_t _get_string_result; -STATIC bool _transfer_done_cb(uint8_t daddr, tusb_control_request_t const *request, xfer_result_t result) { - // Store the result so we stop waiting for the transfer. We don't need the other data for now. - (void)daddr; - (void)request; - _get_string_result = result; - return true; +STATIC void _transfer_done_cb(tuh_xfer_t *xfer) { + // Store the result so we stop waiting for the transfer. + _get_string_result = xfer->result; } STATIC void _wait_for_callback(void) { @@ -89,7 +86,7 @@ STATIC mp_obj_t _get_string(const uint16_t *temp_buf) { mp_obj_t common_hal_usb_core_device_get_serial_number(usb_core_device_obj_t *self) { _get_string_result = 0xff; uint16_t temp_buf[127]; - if (!tuh_descriptor_string_serial_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) { + if (!tuh_descriptor_get_serial_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) { return mp_const_none; } _wait_for_callback(); @@ -99,7 +96,7 @@ mp_obj_t common_hal_usb_core_device_get_serial_number(usb_core_device_obj_t *sel mp_obj_t common_hal_usb_core_device_get_product(usb_core_device_obj_t *self) { _get_string_result = 0xff; uint16_t temp_buf[127]; - if (!tuh_descriptor_string_product_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) { + if (!tuh_descriptor_get_product_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) { return mp_const_none; } _wait_for_callback(); @@ -109,7 +106,7 @@ mp_obj_t common_hal_usb_core_device_get_product(usb_core_device_obj_t *self) { mp_obj_t common_hal_usb_core_device_get_manufacturer(usb_core_device_obj_t *self) { _get_string_result = 0xff; uint16_t temp_buf[127]; - if (!tuh_descriptor_string_manufacturer_get(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb)) { + if (!tuh_descriptor_get_manufacturer_string(self->device_number, 0, temp_buf, MP_ARRAY_SIZE(temp_buf), _transfer_done_cb, 0)) { return mp_const_none; } _wait_for_callback(); @@ -125,11 +122,8 @@ mp_obj_t common_hal_usb_core_device_read(usb_core_device_obj_t *self, mp_int_t e } xfer_result_t control_result; -STATIC bool _control_complete_cb(uint8_t dev_addr, tusb_control_request_t const *request, xfer_result_t result) { - (void)dev_addr; - (void)request; - control_result = result; - return true; +STATIC void _control_complete_cb(tuh_xfer_t *xfer) { + control_result = xfer->result; } mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, @@ -145,11 +139,17 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self, .wIndex = wIndex, .wLength = len }; + tuh_xfer_t xfer = { + .daddr = self->device_number, + .ep_addr = 0, + .setup = &request, + .buffer = buffer, + .complete_cb = _control_complete_cb, + }; + control_result = XFER_RESULT_STALLED; - bool result = tuh_control_xfer(self->device_number, - &request, - buffer, - _control_complete_cb); + + bool result = tuh_control_xfer(&xfer); if (!result) { mp_raise_usb_core_USBError(NULL); } From a6400fb08ae896f5c71989ac47bf5ea803faeb70 Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Sat, 11 Mar 2023 00:14:36 +0530 Subject: [PATCH 08/23] use intersection of changes per commit and merge ref --- .github/workflows/build.yml | 5 ---- tools/ci_set_matrix.py | 46 ++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4383153fd1..150c2364ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,16 +80,11 @@ jobs: run: git cat-file -e $SHA && echo "BASE_SHA=$SHA" >> $GITHUB_ENV || true env: SHA: ${{ github.event.before }} - - name: Get changes - id: get-changes - if: env.BASE_SHA && env.HEAD_SHA - run: echo $(git diff $BASE_SHA...$HEAD_SHA --name-only) | echo "changed_files=[\"$(sed "s/ /\", \"/g")\"]" >> $GITHUB_OUTPUT - name: Set matrix id: set-matrix run: python3 -u ci_set_matrix.py working-directory: tools env: - CHANGED_FILES: ${{ steps.get-changes.outputs.changed_files }} LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.check_runs }} tests: diff --git a/tools/ci_set_matrix.py b/tools/ci_set_matrix.py index b5618aec2f..3cd0dbf56f 100755 --- a/tools/ci_set_matrix.py +++ b/tools/ci_set_matrix.py @@ -68,25 +68,43 @@ PATTERN_WINDOWS = [ "tools/", ] + +def git_diff(pattern: str): + return ( + subprocess.run( + f"git diff {pattern} --name-only", + capture_output=True, + shell=True, + ) + .stdout.decode("utf-8") + .split("\n")[:-1] + ) + + if len(sys.argv) > 1: print("Using files list on commandline") changed_files = sys.argv[1:] - last_failed_jobs = {} +elif os.environ.get("BASE_SHA") and os.environ.get("HEAD_SHA"): + print("Using files list by computing diff") + changed_files = git_diff("$BASE_SHA...$HEAD_SHA") + if os.environ.get("GITHUB_EVENT_NAME") == "pull_request": + changed_files = list(set(changed_files).intersection(git_diff("$HEAD_SHA~...$HEAD_SHA"))) else: - c = os.environ["CHANGED_FILES"] - if c == "": - print("CHANGED_FILES is in environment, but value is empty") - changed_files = [] - else: - print("Using files list in CHANGED_FILES") - changed_files = json.loads(c.replace("\\", "")) + print("Using files list in CHANGED_FILES") + changed_files = json.loads(os.environ.get("CHANGED_FILES") or "[]") - j = os.environ["LAST_FAILED_JOBS"] - if j == "": - print("LAST_FAILED_JOBS is in environment, but value is empty") - last_failed_jobs = {} - else: - last_failed_jobs = json.loads(j) +print("Using jobs list in LAST_FAILED_JOBS") +last_failed_jobs = json.loads(os.environ.get("LAST_FAILED_JOBS") or "{}") + + +def print_enclosed(title, content): + print("::group::" + title) + print(content) + print("::endgroup::") + + +print_enclosed("LOG: changed_files", changed_files) +print_enclosed("LOG: last_failed_jobs", last_failed_jobs) def set_output(name: str, value): From a651696c5c5bfdb945c06645963f3b56ad0cc9eb Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 10 Mar 2023 23:07:29 -0500 Subject: [PATCH 09/23] pick up latest tinyusb changes --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index 990fb6ae5c..be21413361 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 990fb6ae5c4d9d4b77c5a9ecb3a2abe899dd2712 +Subproject commit be214133615684327b114a5f167cd052841c3acf From 29cee603d32b8f7854626b8aaa90b54d5c420828 Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Sat, 11 Mar 2023 11:56:04 +0530 Subject: [PATCH 10/23] update `.readthedocs.yml` and add it to docs pattern --- .readthedocs.yml | 2 +- tools/ci_set_matrix.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 29a915766f..8f1b89cb67 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -14,7 +14,7 @@ build: python: "3" jobs: post_install: - - python tools/ci_fetch_deps.py build-doc + - python tools/ci_fetch_deps.py docs formats: - pdf diff --git a/tools/ci_set_matrix.py b/tools/ci_set_matrix.py index 3cd0dbf56f..5d7e3a477b 100755 --- a/tools/ci_set_matrix.py +++ b/tools/ci_set_matrix.py @@ -52,7 +52,7 @@ IGNORE_DIRS = ["tests", "docs", ".devcontainer"] PATTERN_DOCS = ( r"^(?:\.github|docs|extmod\/ulab)|" - r"^(?:(?:ports\/\w+\/bindings|shared-bindings)\S+\.c|tools\/extract_pyi\.py|conf\.py|requirements-doc\.txt)$|" + r"^(?:(?:ports\/\w+\/bindings|shared-bindings)\S+\.c|tools\/extract_pyi\.py|\.readthedocs\.yml|conf\.py|requirements-doc\.txt)$|" r"(?:-stubs|\.(?:md|MD|rst|RST))$" ) From ec74be7cb42071c5d9e0cc0bdaf4ed260afc91ae Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Sat, 11 Mar 2023 14:00:29 +0530 Subject: [PATCH 11/23] use set for `changed_files` and minor updates --- tools/ci_set_matrix.py | 49 +++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/tools/ci_set_matrix.py b/tools/ci_set_matrix.py index 5d7e3a477b..c38ef29ecc 100755 --- a/tools/ci_set_matrix.py +++ b/tools/ci_set_matrix.py @@ -42,13 +42,15 @@ from shared_bindings_matrix import ( all_ports_all_boards, ) -IGNORE = [ - "tools/ci_set_matrix.py", +# Files that never influence board builds +IGNORE_BOARD = { + ".devcontainer", + "docs", + "tests", + "tools/ci_changes_per_commit.py", "tools/ci_check_duplicate_usb_vid_pid.py", -] - -# Files in these directories never influence board builds -IGNORE_DIRS = ["tests", "docs", ".devcontainer"] + "tools/ci_set_matrix.py", +} PATTERN_DOCS = ( r"^(?:\.github|docs|extmod\/ulab)|" @@ -56,21 +58,20 @@ PATTERN_DOCS = ( r"(?:-stubs|\.(?:md|MD|rst|RST))$" ) -PATTERN_WINDOWS = [ +PATTERN_WINDOWS = { ".github/", "extmod/", "lib/", "mpy-cross/", "ports/unix/", - "ports/windows/", "py/", - "requirements", "tools/", -] + "requirements-dev.txt", +} def git_diff(pattern: str): - return ( + return set( subprocess.run( f"git diff {pattern} --name-only", capture_output=True, @@ -83,15 +84,15 @@ def git_diff(pattern: str): if len(sys.argv) > 1: print("Using files list on commandline") - changed_files = sys.argv[1:] + changed_files = set(sys.argv[1:]) elif os.environ.get("BASE_SHA") and os.environ.get("HEAD_SHA"): print("Using files list by computing diff") changed_files = git_diff("$BASE_SHA...$HEAD_SHA") if os.environ.get("GITHUB_EVENT_NAME") == "pull_request": - changed_files = list(set(changed_files).intersection(git_diff("$HEAD_SHA~...$HEAD_SHA"))) + changed_files.intersection_update(git_diff("$HEAD_SHA~...$HEAD_SHA")) else: print("Using files list in CHANGED_FILES") - changed_files = json.loads(os.environ.get("CHANGED_FILES") or "[]") + changed_files = set(json.loads(os.environ.get("CHANGED_FILES") or "[]")) print("Using jobs list in LAST_FAILED_JOBS") last_failed_jobs = json.loads(os.environ.get("LAST_FAILED_JOBS") or "{}") @@ -103,8 +104,8 @@ def print_enclosed(title, content): print("::endgroup::") -print_enclosed("LOG: changed_files", changed_files) -print_enclosed("LOG: last_failed_jobs", last_failed_jobs) +print_enclosed("Log: changed_files", changed_files) +print_enclosed("Log: last_failed_jobs", last_failed_jobs) def set_output(name: str, value): @@ -173,11 +174,7 @@ def set_boards(build_all: bool): boards_to_build.update(port_to_boards[port]) continue - # Check the ignore list to see if the file isn't used on board builds. - if p in IGNORE: - continue - - if any([p.startswith(d) for d in IGNORE_DIRS]): + if any([p.startswith(d) for d in IGNORE_BOARD]): continue # As a (nearly) last resort, for some certain files, we compute the settings from the @@ -287,7 +284,9 @@ def set_windows(build_windows: bool): else: for file in changed_files: for pattern in PATTERN_WINDOWS: - if file.startswith(pattern): + if file.startswith(pattern) and not any( + [file.startswith(d) for d in IGNORE_BOARD] + ): build_windows = True break else: @@ -302,11 +301,7 @@ def set_windows(build_windows: bool): def main(): # Build all if no changed files build_all = not changed_files - print( - "Building all docs/boards" - if build_all - else "Adding docs/boards to build based on changed files" - ) + print("Running: " + ("all" if build_all else "conditionally")) # Set jobs set_docs(build_all) From 3a4bffdd6505dac0a7fda88070b6484f67fb1708 Mon Sep 17 00:00:00 2001 From: MicroDev <70126934+MicroDev1@users.noreply.github.com> Date: Sun, 12 Mar 2023 09:42:16 +0530 Subject: [PATCH 12/23] use correct commits for diff --- .github/workflows/build.yml | 6 ++---- tools/ci_set_matrix.py | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 150c2364ae..e322004515 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,11 +67,9 @@ jobs: run: echo "HEAD_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV - name: Set base sha (pull) if: github.event_name == 'pull_request' - run: | - git fetch --no-tags --no-recurse-submodules --depth=$((DEPTH + 1)) origin $HEAD_SHA - echo "BASE_SHA=$(git rev-list $HEAD_SHA --skip=$DEPTH --max-count=1)" >> $GITHUB_ENV + run: git cat-file -e $SHA && echo "BASE_SHA=$SHA" >> $GITHUB_ENV || true env: - DEPTH: ${{ steps.get-last-commit-with-checks.outputs.commit_depth || github.event.pull_request.commits }} + 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 diff --git a/tools/ci_set_matrix.py b/tools/ci_set_matrix.py index c38ef29ecc..fa53c81829 100755 --- a/tools/ci_set_matrix.py +++ b/tools/ci_set_matrix.py @@ -89,7 +89,7 @@ elif os.environ.get("BASE_SHA") and os.environ.get("HEAD_SHA"): print("Using files list by computing diff") changed_files = git_diff("$BASE_SHA...$HEAD_SHA") if os.environ.get("GITHUB_EVENT_NAME") == "pull_request": - changed_files.intersection_update(git_diff("$HEAD_SHA~...$HEAD_SHA")) + changed_files.intersection_update(git_diff("$GITHUB_SHA~...$GITHUB_SHA")) else: print("Using files list in CHANGED_FILES") changed_files = set(json.loads(os.environ.get("CHANGED_FILES") or "[]")) From daa927a114148904f82604f4fb47aca84cb00df2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 12 Mar 2023 14:02:38 -0400 Subject: [PATCH 13/23] switch STM to dwc2 USB --- ports/stm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/stm/Makefile b/ports/stm/Makefile index 325b13b1bc..d6afeb5f29 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -215,7 +215,7 @@ ifneq ($(CIRCUITPY_AUDIOBUSIO_PDMIN),0) endif ifneq ($(CIRCUITPY_USB),0) -SRC_C += lib/tinyusb/src/portable/st/synopsys/dcd_synopsys.c +SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c endif SRC_S = \ From 49e9ea2e9aa77060275b764d064d025a29b43712 Mon Sep 17 00:00:00 2001 From: Matthias Kreier <43933271+kreier@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:17:55 +0700 Subject: [PATCH 14/23] add missing pins 4, 36 and 39 - and 4 aliases The original list left D4 (GPIO4), VN (GPIO39) and VP (GPIO36) out. Added aliases for 1, 3, 16 and 17 with their GPIO names, even though they won't be used as such since they are UART0 and UART2 --- ports/espressif/boards/doit_esp32_devkit_v1/pins.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ports/espressif/boards/doit_esp32_devkit_v1/pins.c b/ports/espressif/boards/doit_esp32_devkit_v1/pins.c index 78c37897ac..673728e9f3 100644 --- a/ports/espressif/boards/doit_esp32_devkit_v1/pins.c +++ b/ports/espressif/boards/doit_esp32_devkit_v1/pins.c @@ -3,9 +3,10 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - // External pins are in silkscreen order, from top to bottom, left side, then right side + // External pins are in silkscreen order, from top to bottom, left side {MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15)}, {MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2)}, + {MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4)}, {MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_GPIO16)}, {MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_GPIO17)}, {MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5)}, @@ -16,6 +17,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_TX0), MP_ROM_PTR(&pin_GPIO3)}, {MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22)}, {MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO23)}, + // External pins are in silkscreen order, from top to bottom, right side {MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13)}, {MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12)}, {MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14)}, @@ -26,6 +28,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_D32), MP_ROM_PTR(&pin_GPIO32)}, {MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_GPIO35)}, {MP_ROM_QSTR(MP_QSTR_D34), MP_ROM_PTR(&pin_GPIO34)}, + {MP_ROM_QSTR(MP_QSTR_VN), MP_ROM_PTR(&pin_GPIO39)}, + {MP_ROM_QSTR(MP_QSTR_VP), MP_ROM_PTR(&pin_GPIO36)}, {MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO2)}, @@ -38,6 +42,11 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO17)}, {MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO16)}, + + {MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1)}, + {MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3)}, + {MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16)}, + {MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17)}, {MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj)}, {MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj)}, From f5b8b8d6f22eed5e36499060d085eb88812a35ca Mon Sep 17 00:00:00 2001 From: Matthias Kreier <43933271+kreier@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:30:52 +0700 Subject: [PATCH 15/23] tailing whitespace removed (pre-commit run failed) --- ports/espressif/boards/doit_esp32_devkit_v1/pins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/doit_esp32_devkit_v1/pins.c b/ports/espressif/boards/doit_esp32_devkit_v1/pins.c index 673728e9f3..8381fa0644 100644 --- a/ports/espressif/boards/doit_esp32_devkit_v1/pins.c +++ b/ports/espressif/boards/doit_esp32_devkit_v1/pins.c @@ -42,7 +42,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO17)}, {MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO16)}, - + {MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1)}, {MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3)}, {MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16)}, From b432cf62019d40b103e1cba6fbfecb5813cd61a7 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 13 Mar 2023 21:49:01 +0700 Subject: [PATCH 16/23] fix rp2040 with new shared irq usb handler --- ports/raspberrypi/supervisor/usb.c | 11 ++--------- supervisor/shared/usb/usb.c | 12 ++++++++---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ports/raspberrypi/supervisor/usb.c b/ports/raspberrypi/supervisor/usb.c index d0e9b2e466..fb4f72134d 100644 --- a/ports/raspberrypi/supervisor/usb.c +++ b/ports/raspberrypi/supervisor/usb.c @@ -39,15 +39,8 @@ STATIC void _usb_irq_wrapper(void) { } void post_usb_init(void) { - irq_set_enabled(USBCTRL_IRQ, false); - - irq_handler_t usb_handler = irq_get_exclusive_handler(USBCTRL_IRQ); - if (usb_handler) { - irq_remove_handler(USBCTRL_IRQ, usb_handler); - } - irq_set_exclusive_handler(USBCTRL_IRQ, _usb_irq_wrapper); - - irq_set_enabled(USBCTRL_IRQ, true); + irq_add_shared_handler(USBCTRL_IRQ, _usb_irq_wrapper, + PICO_SHARED_IRQ_HANDLER_LOWEST_ORDER_PRIORITY); // There is a small window where the USB interrupt may be handled by the // pico-sdk instead of CircuitPython. If that is the case, then we'll have diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index fa85cddb83..5ac8454312 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -225,13 +225,17 @@ void usb_background_schedule(void) { } void usb_irq_handler(int instance) { + #if CFG_TUSB_MCU != OPT_MCU_RP2040 + // For rp2040, IRQ handler is already installed and invoked automatically if (instance == CIRCUITPY_USB_DEVICE_INSTANCE) { tud_int_handler(instance); - } else if (instance == CIRCUITPY_USB_HOST_INSTANCE) { - #if CIRCUITPY_USB_HOST - tuh_int_handler(instance); - #endif } + #if CIRCUITPY_USB_HOST + else if (instance == CIRCUITPY_USB_HOST_INSTANCE) { + tuh_int_handler(instance); + } + #endif + #endif usb_background_schedule(); } From d85970b7a2cfb0aeb4d89575d839c91ce3e6d1ad Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 13 Mar 2023 17:53:32 -0400 Subject: [PATCH 17/23] update TinyUSB again for latest changes --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index be21413361..7cf67b2845 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit be214133615684327b114a5f167cd052841c3acf +Subproject commit 7cf67b28456f6cb8738956bd6af1fd2b8300de4f From 2497b3ea7a67c7371a857deae32ca4a5ed572dff Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 13 Mar 2023 22:11:02 -0400 Subject: [PATCH 18/23] update tinyusb --- lib/tinyusb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tinyusb b/lib/tinyusb index 7cf67b2845..ea8ecea59a 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 7cf67b28456f6cb8738956bd6af1fd2b8300de4f +Subproject commit ea8ecea59aa60a1028cce16b0f15bb33918b11af From d4840cbf1022f447d2fa76eac4f40c4257425e9a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 14 Mar 2023 13:13:58 -0400 Subject: [PATCH 19/23] translate() messages must be one string --- ports/espressif/common-hal/espcamera/Camera.c | 3 +-- shared-bindings/pwmio/PWMOut.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ports/espressif/common-hal/espcamera/Camera.c b/ports/espressif/common-hal/espcamera/Camera.c index e3e5ef49f9..574b4e846b 100644 --- a/ports/espressif/common-hal/espcamera/Camera.c +++ b/ports/espressif/common-hal/espcamera/Camera.c @@ -79,8 +79,7 @@ void common_hal_espcamera_camera_construct( if (common_hal_espidf_get_reserved_psram() == 0) { mp_raise_msg(&mp_type_MemoryError, translate( - "espcamera.Camera requires reserved PSRAM to be configured. " - "See the documentation for instructions.")); + "espcamera.Camera requires reserved PSRAM to be configured. See the documentation for instructions.")); } for (int i = 0; i < 8; i++) { claim_pin_number(data_pins[i]); diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c index 24c0097c0c..784f87a025 100644 --- a/shared-bindings/pwmio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -271,8 +271,7 @@ STATIC mp_obj_t pwmio_pwmout_obj_set_frequency(mp_obj_t self_in, mp_obj_t freque check_for_deinit(self); if (!common_hal_pwmio_pwmout_get_variable_frequency(self)) { mp_raise_AttributeError(translate( - "PWM frequency not writable when variable_frequency is False on " - "construction.")); + "PWM frequency not writable when variable_frequency is False on construction.")); } mp_int_t freq = mp_obj_get_int(frequency); if (freq == 0) { From 5ec586019ba5e293451534e5368769136493f2e9 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 14 Mar 2023 13:27:57 -0400 Subject: [PATCH 20/23] fix TimeAlarm signature --- shared-bindings/alarm/time/TimeAlarm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/alarm/time/TimeAlarm.c b/shared-bindings/alarm/time/TimeAlarm.c index abbb050c64..86c96de1d4 100644 --- a/shared-bindings/alarm/time/TimeAlarm.c +++ b/shared-bindings/alarm/time/TimeAlarm.c @@ -45,7 +45,7 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) { //| """Trigger an alarm when the specified time is reached.""" //| //| def __init__( -//| self, monotonic_time: Optional[float] = None, epoch_time: Optional[int] = None +//| self, *, monotonic_time: Optional[float] = None, epoch_time: Optional[int] = None //| ) -> None: //| """Create an alarm that will be triggered when `time.monotonic()` would equal //| ``monotonic_time``, or when `time.time()` would equal ``epoch_time``. From 6a9d69d743ba9ffc9fb96de1fceb79a0b9cac0e8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 14 Mar 2023 16:03:42 -0400 Subject: [PATCH 21/23] add port-specific modules to support matrix --- docs/shared_bindings_matrix.py | 201 ++++++++++++++++++++------------- 1 file changed, 123 insertions(+), 78 deletions(-) diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index 761e3e29f2..9705e33585 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -31,7 +31,17 @@ import functools from concurrent.futures import ThreadPoolExecutor -SUPPORTED_PORTS = ['atmel-samd', 'broadcom', 'cxd56', 'espressif', 'litex', 'mimxrt10xx', 'nrf', 'raspberrypi', 'stm'] +SUPPORTED_PORTS = [ + "atmel-samd", + "broadcom", + "cxd56", + "espressif", + "litex", + "mimxrt10xx", + "nrf", + "raspberrypi", + "stm", +] ALIASES_BY_BOARD = { "circuitplayground_express": [ @@ -44,16 +54,11 @@ ALIASES_BY_BOARD = { } ALIASES_BRAND_NAMES = { - "circuitplayground_express_4h": - "Adafruit Circuit Playground Express 4-H", - "circuitplayground_express_digikey_pycon2019": - "Circuit Playground Express Digi-Key PyCon 2019", - "edgebadge": - "Adafruit EdgeBadge", - "pyportal_pynt": - "Adafruit PyPortal Pynt", - "gemma_m0_pycon2018": - "Adafruit Gemma M0 PyCon 2018", + "circuitplayground_express_4h": "Adafruit Circuit Playground Express 4-H", + "circuitplayground_express_digikey_pycon2019": "Circuit Playground Express Digi-Key PyCon 2019", + "edgebadge": "Adafruit EdgeBadge", + "pyportal_pynt": "Adafruit PyPortal Pynt", + "gemma_m0_pycon2018": "Adafruit Gemma M0 PyCon 2018", } ADDITIONAL_MODULES = { @@ -72,7 +77,19 @@ ADDITIONAL_MODULES = { "usb": "CIRCUITPY_USB_HOST", } -MODULES_NOT_IN_SHARED_BINDINGS = ["_asyncio", "array", "binascii", "builtins", "collections", "errno", "json", "re", "select", "sys", "ulab"] +MODULES_NOT_IN_BINDINGS = [ + "_asyncio", + "array", + "binascii", + "builtins", + "collections", + "errno", + "json", + "re", + "select", + "sys", + "ulab", +] FROZEN_EXCLUDES = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"] """Files and dirs at the root of a frozen directory that should be ignored. @@ -83,16 +100,23 @@ repository_urls = {} root_dir = pathlib.Path(__file__).resolve().parent.parent + def get_circuitpython_root_dir(): - """ The path to the root './circuitpython' directory. - """ + """The path to the root './circuitpython' directory.""" return root_dir -def get_shared_bindings(): - """ Get a list of modules in shared-bindings based on folder names. - """ - shared_bindings_dir = get_circuitpython_root_dir() / "shared-bindings" - return [item.name for item in shared_bindings_dir.iterdir()] + MODULES_NOT_IN_SHARED_BINDINGS + +def get_bindings(): + """Get a list of modules in shared-bindings and ports/*/bindings based on folder names.""" + shared_bindings_modules = [ + module.name + for module in (get_circuitpython_root_dir() / "shared-bindings").iterdir() + if module.is_dir() + ] + bindings_modules = [] + for d in get_circuitpython_root_dir().glob("ports/*/bindings"): + bindings_modules.extend(module.name for module in d.iterdir() if d.is_dir()) + return shared_bindings_modules + bindings_modules + MODULES_NOT_IN_BINDINGS def get_board_mapping(): @@ -124,8 +148,7 @@ def get_board_mapping(): def read_mpconfig(): - """ Open 'circuitpy_mpconfig.mk' and return the contents. - """ + """Open 'circuitpy_mpconfig.mk' and return the contents.""" configs = [] cpy_mpcfg = get_circuitpython_root_dir() / "py" / "circuitpy_mpconfig.mk" with open(cpy_mpcfg) as mpconfig: @@ -135,14 +158,14 @@ def read_mpconfig(): def build_module_map(): - """ Establish the base of the JSON file, based on the contents from - `configs`. Base will contain module names, if they're part of - the `FULL_BUILD`, or their default value (0, 1, or a list of - modules that determine default [see audiocore, audiomixer, etc.]). + """Establish the base of the JSON file, based on the contents from + `configs`. Base will contain module names, if they're part of + the `FULL_BUILD`, or their default value (0, 1, or a list of + modules that determine default [see audiocore, audiomixer, etc.]). """ base = dict() - modules = get_shared_bindings() + modules = get_bindings() configs = read_mpconfig() full_build = False for module in modules: @@ -150,7 +173,7 @@ def build_module_map(): if module in ADDITIONAL_MODULES: search_identifier = ADDITIONAL_MODULES[module] else: - search_identifier = 'CIRCUITPY_'+module.lstrip("_").upper() + search_identifier = "CIRCUITPY_" + module.lstrip("_").upper() re_pattern = f"{re.escape(search_identifier)}\s*\??=\s*(.+)" find_config = re.findall(re_pattern, configs) if not find_config: @@ -173,21 +196,22 @@ def build_module_map(): return base -def get_settings_from_makefile(port_dir, board_name): - """ Invoke make in a mode which prints the database, then parse it for - settings. - This means that the effect of all Makefile directives is taken - into account, without having to re-encode the logic that sets them - in this script, something that has proved error-prone +def get_settings_from_makefile(port_dir, board_name): + """Invoke make in a mode which prints the database, then parse it for + settings. + + This means that the effect of all Makefile directives is taken + into account, without having to re-encode the logic that sets them + in this script, something that has proved error-prone """ contents = subprocess.run( - ["make", "-C", port_dir, f"BOARD={board_name}", "-qp", "print-CC"], - encoding="utf-8", - errors="replace", - stdout=subprocess.PIPE, - stderr=subprocess.PIPE - ) + ["make", "-C", port_dir, f"BOARD={board_name}", "-qp", "print-CC"], + encoding="utf-8", + errors="replace", + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) # Make signals errors with exit status 2; 0 and 1 are "non-error" statuses if contents.returncode not in (0, 1): error_msg = ( @@ -197,22 +221,23 @@ def get_settings_from_makefile(port_dir, board_name): raise RuntimeError(error_msg) settings = {} - for line in contents.stdout.split('\n'): + for line in contents.stdout.split("\n"): # Handle both = and := definitions. - m = re.match(r'^([A-Z][A-Z0-9_]*) :?= (.*)$', line) + m = re.match(r"^([A-Z][A-Z0-9_]*) :?= (.*)$", line) if m: settings[m.group(1)] = m.group(2) return settings + def get_repository_url(directory): if directory in repository_urls: return repository_urls[directory] readme = None for readme_path in ( - os.path.join(directory, "README.rst"), - os.path.join(os.path.dirname(directory), "README.rst") - ): + os.path.join(directory, "README.rst"), + os.path.join(os.path.dirname(directory), "README.rst"), + ): if os.path.exists(readme_path): readme = readme_path break @@ -220,7 +245,10 @@ def get_repository_url(directory): if readme: with open(readme, "r") as fp: for line in fp.readlines(): - if m := re.match("\s+:target:\s+(http\S+(docs.circuitpython|readthedocs)\S+)\s*", line): + if m := re.match( + "\s+:target:\s+(http\S+(docs.circuitpython|readthedocs)\S+)\s*", + line, + ): path = m.group(1) break if m := re.search("<(http[^>]+)>", line): @@ -233,12 +261,13 @@ def get_repository_url(directory): errors="replace", stdout=subprocess.PIPE, stderr=subprocess.PIPE, - cwd=directory + cwd=directory, ) path = contents.stdout.strip() repository_urls[directory] = path return path + def frozen_modules_from_dirs(frozen_mpy_dirs, withurl): """ Go through the list of frozen directories and extract the python modules. @@ -261,34 +290,36 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl): else: frozen_modules.append(sub.name[:-3]) continue - if next(sub.glob("**/*.py"), None): # tests if not empty + if next(sub.glob("**/*.py"), None): # tests if not empty if withurl: frozen_modules.append((sub.name, url_repository)) else: frozen_modules.append(sub.name) return frozen_modules -def lookup_setting(settings, key, default=''): + +def lookup_setting(settings, key, default=""): while True: value = settings.get(key, default) - if not value.startswith('$'): + if not value.startswith("$"): break key = value[2:-1] return value + @functools.cache def all_ports_all_boards(ports=SUPPORTED_PORTS): for port in ports: - port_dir = get_circuitpython_root_dir() / "ports" / port for entry in (port_dir / "boards").iterdir(): if not entry.is_dir(): continue yield (port, entry) + def support_matrix_by_board(use_branded_name=True, withurl=True): - """ Compiles a list of the available core modules available for each - board. + """Compiles a list of the available core modules available for each + board. """ base = build_module_map() @@ -300,8 +331,9 @@ def support_matrix_by_board(use_branded_name=True, withurl=True): if use_branded_name: with open(entry / "mpconfigboard.h") as get_name: board_contents = get_name.read() - board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", - board_contents) + board_name_re = re.search( + r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", board_contents + ) if board_name_re: board_name = board_name_re.group(1).strip('"') else: @@ -309,56 +341,69 @@ def support_matrix_by_board(use_branded_name=True, withurl=True): board_modules = [] for module in base: - key = base[module]['key'] - if int(lookup_setting(settings, key, '0')): - board_modules.append(base[module]['name']) + key = base[module]["key"] + if int(lookup_setting(settings, key, "0")): + board_modules.append(base[module]["name"]) board_modules.sort() if "CIRCUITPY_BUILD_EXTENSIONS" in settings: board_extensions = [ - extension.strip() for extension in - settings["CIRCUITPY_BUILD_EXTENSIONS"].split(",") + extension.strip() + for extension in settings["CIRCUITPY_BUILD_EXTENSIONS"].split(",") ] else: raise OSError(f"Board extensions undefined: {board_name}.") frozen_modules = [] if "FROZEN_MPY_DIRS" in settings: - frozen_modules = frozen_modules_from_dirs(settings["FROZEN_MPY_DIRS"], withurl) + frozen_modules = frozen_modules_from_dirs( + settings["FROZEN_MPY_DIRS"], withurl + ) if frozen_modules: frozen_modules.sort() # generate alias boards too - board_matrix = [( - board_name, { - "modules": board_modules, - "frozen_libraries": frozen_modules, - "extensions": board_extensions, - } - )] + board_matrix = [ + ( + board_name, + { + "modules": board_modules, + "frozen_libraries": frozen_modules, + "extensions": board_extensions, + }, + ) + ] if entry.name in ALIASES_BY_BOARD: for alias in ALIASES_BY_BOARD[entry.name]: if use_branded_name: if alias in ALIASES_BRAND_NAMES: alias = ALIASES_BRAND_NAMES[alias] else: - alias = alias.replace("_"," ").title() - board_matrix.append(( - alias, { - "modules": board_modules, - "frozen_libraries": frozen_modules, - "extensions": board_extensions, - }, - )) + alias = alias.replace("_", " ").title() + board_matrix.append( + ( + alias, + { + "modules": board_modules, + "frozen_libraries": frozen_modules, + "extensions": board_extensions, + }, + ) + ) - return board_matrix # this is now a list of (board,modules) + return board_matrix # this is now a list of (board,modules) executor = ThreadPoolExecutor(max_workers=os.cpu_count()) mapped_exec = executor.map(support_matrix, all_ports_all_boards()) # flatmap with comprehensions - boards = dict(sorted([board for matrix in mapped_exec for board in matrix], key=lambda x: x[0])) + boards = dict( + sorted( + [board for matrix in mapped_exec for board in matrix], key=lambda x: x[0] + ) + ) return boards -if __name__ == '__main__': + +if __name__ == "__main__": print(json.dumps(support_matrix_by_board(), indent=2)) From 069a058a83ebb9fbf35bbe3c76691564a830f3ad Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 14 Mar 2023 22:37:56 -0400 Subject: [PATCH 22/23] update build_board_info.py per Neradoc --- tools/build_board_info.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/build_board_info.py b/tools/build_board_info.py index 5209337b95..01d935ac46 100755 --- a/tools/build_board_info.py +++ b/tools/build_board_info.py @@ -6,6 +6,7 @@ import json import os +import requests import subprocess import sys import sh @@ -96,7 +97,19 @@ def get_current_info(): response = response.json() git_info = commit_sha, response["sha"] - current_list = json.loads(base64.b64decode(response["content"]).decode("utf-8")) + + if response["content"] != "": + # if the file is there + current_list = json.loads(base64.b64decode(response["content"]).decode("utf-8")) + else: + # if too big, the file is not included + download_url = response["download_url"] + response = requests.get(download_url) + if not response.ok: + print(response.text) + raise RuntimeError("cannot get previous files.json") + current_list = response.json() + current_info = {} for info in current_list: current_info[info["id"]] = info From 6062e75b0885743fb9f03c4781b8667fde82a2a9 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Sat, 19 Nov 2022 12:11:13 -0800 Subject: [PATCH 23/23] add Blok --- .../boards/boardsource_blok/board.c | 45 +++++++++++++++++ .../boards/boardsource_blok/mpconfigboard.h | 4 ++ .../boards/boardsource_blok/mpconfigboard.mk | 14 ++++++ .../boardsource_blok/pico-sdk-configboard.h | 4 ++ .../boards/boardsource_blok/pins.c | 50 +++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 ports/raspberrypi/boards/boardsource_blok/board.c create mode 100644 ports/raspberrypi/boards/boardsource_blok/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/boardsource_blok/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/boardsource_blok/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/boardsource_blok/pins.c diff --git a/ports/raspberrypi/boards/boardsource_blok/board.c b/ports/raspberrypi/boards/boardsource_blok/board.c new file mode 100644 index 0000000000..55540c965a --- /dev/null +++ b/ports/raspberrypi/boards/boardsource_blok/board.c @@ -0,0 +1,45 @@ +/* + * 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" +#include "shared-bindings/microcontroller/Pin.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" +#include "supervisor/shared/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + // turn off any left over LED + // board_reset_user_neopixels(&pin_GPIO29, 62); +} + +void board_deinit(void) { +} diff --git a/ports/raspberrypi/boards/boardsource_blok/mpconfigboard.h b/ports/raspberrypi/boards/boardsource_blok/mpconfigboard.h new file mode 100644 index 0000000000..0ac77bf54e --- /dev/null +++ b/ports/raspberrypi/boards/boardsource_blok/mpconfigboard.h @@ -0,0 +1,4 @@ +#define MICROPY_HW_BOARD_NAME "BLOK" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO29) diff --git a/ports/raspberrypi/boards/boardsource_blok/mpconfigboard.mk b/ports/raspberrypi/boards/boardsource_blok/mpconfigboard.mk new file mode 100644 index 0000000000..aba2838864 --- /dev/null +++ b/ports/raspberrypi/boards/boardsource_blok/mpconfigboard.mk @@ -0,0 +1,14 @@ +USB_VID = 0x2E8A +USB_PID = 0x104A +USB_PRODUCT = "BLOK" +USB_MANUFACTURER = "Boardsource" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel + + +# CIRCUITPY__EVE = 1 diff --git a/ports/raspberrypi/boards/boardsource_blok/pico-sdk-configboard.h b/ports/raspberrypi/boards/boardsource_blok/pico-sdk-configboard.h new file mode 100644 index 0000000000..a41131dd22 --- /dev/null +++ b/ports/raspberrypi/boards/boardsource_blok/pico-sdk-configboard.h @@ -0,0 +1,4 @@ +// 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/boardsource_blok/pins.c b/ports/raspberrypi/boards/boardsource_blok/pins.c new file mode 100644 index 0000000000..e3b0ba0169 --- /dev/null +++ b/ports/raspberrypi/boards/boardsource_blok/pins.c @@ -0,0 +1,50 @@ +#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_TX), MP_ROM_PTR(&pin_GPIO0)}, + {MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1)}, + {MP_ROM_QSTR(MP_QSTR_GP02), MP_ROM_PTR(&pin_GPIO2)}, + {MP_ROM_QSTR(MP_QSTR_GP03), MP_ROM_PTR(&pin_GPIO3)}, + {MP_ROM_QSTR(MP_QSTR_GP04), MP_ROM_PTR(&pin_GPIO4)}, + {MP_ROM_QSTR(MP_QSTR_GP05), MP_ROM_PTR(&pin_GPIO5)}, + {MP_ROM_QSTR(MP_QSTR_GP06), MP_ROM_PTR(&pin_GPIO6)}, + {MP_ROM_QSTR(MP_QSTR_GP07), MP_ROM_PTR(&pin_GPIO7)}, + {MP_ROM_QSTR(MP_QSTR_GP08), MP_ROM_PTR(&pin_GPIO8)}, + {MP_ROM_QSTR(MP_QSTR_GP09), 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_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_GP23), MP_ROM_PTR(&pin_GPIO23)}, + {MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24)}, + + {MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24)}, + {MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25)}, + {MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO25)}, + {MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26)}, + {MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27)}, + {MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28)}, + {MP_ROM_QSTR(MP_QSTR_GP29), MP_ROM_PTR(&pin_GPIO29)}, + {MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO16)}, + {MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO17)}, + + {MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO26)}, + {MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO28)}, + {MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO27)}, + + {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_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);