diff --git a/.devcontainer/Readme.md b/.devcontainer/Readme.md new file mode 100644 index 0000000000..00acbb5786 --- /dev/null +++ b/.devcontainer/Readme.md @@ -0,0 +1,31 @@ +Build CircuitPython in a Github-Devcontainer +============================================ + +To build CircuitPython within a Github-Devcontainer, you need to perform +the following steps. + + 1. checkout the code to a devcontainer + + - click on the green "<> Code"-button + - select the Codespaces-tab + - choose "+ new with options..." from the "..."-menu + - in the following screen select the branch and then + - select ".devcontainer/cortex-m/devcontainer.json" instead + of "Default Codespaces configuration" + - update region as necessary + - finally, click on the green "Create codespace" button + + 2. Your codespace is created. Cloning the images is quite fast, but + preparing it for CircuitPython-development takes about 10 minutes. + Note that this is a one-time task. + + 3. During creation, you can run the command + `tail -f /workspaces/.codespaces/.persistedshare/creation.log` + to see what is going on. + + 4. To actually build CircuitPython, run + + cd ports/raspberrypi + make -j $(nproc) BOARD=whatever TRANSLATION=xx_XX + + This takes about 2m40s. diff --git a/.devcontainer/cortex-m/devcontainer.json b/.devcontainer/cortex-m/devcontainer.json new file mode 100644 index 0000000000..796f83a4eb --- /dev/null +++ b/.devcontainer/cortex-m/devcontainer.json @@ -0,0 +1,23 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/universal +{ + "name": "CircuitPython Cortex-M Build-Environment (base: Default Linux Universal)", + "image": "mcr.microsoft.com/devcontainers/universal:2-linux", + "postCreateCommand": ".devcontainer/cortex-mq/on-create.sh", + "remoteEnv": { "PATH": "/workspaces/gcc-arm-none-eabi/bin:${containerEnv:PATH}" } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.devcontainer/cortex-m/on-create.sh b/.devcontainer/cortex-m/on-create.sh new file mode 100755 index 0000000000..8c4bd0cfed --- /dev/null +++ b/.devcontainer/cortex-m/on-create.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# on-create.sh: postCreateCommand-hook for devcontainer.json (Cortex-M build) +# +# Author: Bernhard Bablok +# +# ----------------------------------------------------------------------------- + +echo -e "[on-create.sh] downloading and installing gcc-arm-non-eabi toolchain" +cd /workspaces +wget -qO gcc-arm-none-eabi.tar.bz2 https://adafru.it/Pid +tar -xjf gcc-arm-none-eabi.tar.bz2 +ln -s gcc-arm-none-eabi-10-2020-q4-major gcc-arm-none-eabi +rm -f /workspaces/gcc-arm-none-eabi.tar.bz2 +export PATH=/workspaces/gcc-arm-none-eabi/bin:$PATH + +# add repository and install tools +echo -e "[on-create.sh] adding pybricks/ppa" +sudo add-apt-repository -y ppa:pybricks/ppa +echo -e "[on-create.sh] installing uncrustify and mtools" +sudo apt-get -y install uncrustify mtools + +# dosfstools >= 4.2 needed, standard repo only has 4.1 +echo -e "[on-create.sh] downloading and installing dosfstools" +wget https://github.com/dosfstools/dosfstools/releases/download/v4.2/dosfstools-4.2.tar.gz +tar -xzf dosfstools-4.2.tar.gz +cd dosfstools-4.2/ +./configure +make -j $(nproc) +sudo make install +cd /workspaces +rm -fr /workspaces/dosfstools-4.2 /workspaces/dosfstools-4.2.tar.gz + +# prepare source-code tree +cd /workspaces/circuitpython/ +echo -e "[on-create.sh] fetching submodules" +make fetch-submodules +echo -e "[on-create.sh] fetching tags" +git fetch --tags --recurse-submodules=no --shallow-since="2021-07-01" https://github.com/adafruit/circuitpython HEAD + +# additional python requirements +echo -e "[on-create.sh] pip-installing requirements" +pip install --upgrade -r requirements-dev.txt +pip install --upgrade -r requirements-doc.txt + +# add pre-commit +echo -e "[on-create.sh] installing pre-commit" +pre-commit install + +# create cross-compiler +echo -e "[on-create.sh] building mpy-cross" +make -j $(nproc) -C mpy-cross # time: about 36 sec + +# that's it! +echo -e "[on-create.sh] setup complete" + +#commands to actually build CP: +#cd ports/raspberrypi +#time make -j $(nproc) BOARD=pimoroni_tufty2040 TRANSLATION=de_DE diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0dc47946b5..8863664232 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -125,20 +125,30 @@ jobs: [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static-raspbian s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-raspbian-${{ env.CP_VERSION }} --no-progress --region us-east-1 [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-amd64-linux-${{ env.CP_VERSION }} --no-progress --region us-east-1 [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static.exe s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-x64-windows-${{ env.CP_VERSION }}.exe --no-progress --region us-east-1 - - name: "Get changes" + - name: Get last commit with checks + id: get-last-commit-with-checks if: github.event_name == 'pull_request' - uses: dorny/paths-filter@v2 - id: filter + working-directory: tools + env: + REPO: ${{ github.repository }} + PULL: ${{ github.event.number }} + GITHUB_TOKEN: ${{ github.token }} + EXCLUDE_COMMIT: ${{ github.event.after }} + run: python3 -u ci_changes_per_commit.py + - name: Get changes + id: get-changes + if: github.event_name == 'pull_request' + uses: tj-actions/changed-files@v34 with: - list-files: json - filters: | - changed: - - '**' - - name: "Set matrix" + json: true + sha: ${{ steps.get-last-commit-with-checks.outputs.commit && github.event.after }} + base_sha: ${{ steps.get-last-commit-with-checks.outputs.commit }} + - name: Set matrix id: set-matrix working-directory: tools env: - CHANGED_FILES: ${{ steps.filter.outputs.changed_files }} + CHANGED_FILES: ${{ steps.get-changes.outputs.all_changed_and_modified_files }} + LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.checkruns }} run: python3 -u ci_set_matrix.py diff --git a/.gitmodules b/.gitmodules index f13eb79e45..ae413799c7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -312,10 +312,12 @@ url = https://github.com/adafruit/esp32-camera/ [submodule "ports/raspberrypi/lib/cyw43-driver"] path = ports/raspberrypi/lib/cyw43-driver - url = https://github.com/georgerobotics/cyw43-driver.git + url = https://github.com/adafruit/cyw43-driver.git + branch = circuitpython8 [submodule "ports/raspberrypi/lib/lwip"] path = ports/raspberrypi/lib/lwip - url = https://github.com/lwip-tcpip/lwip.git + url = https://github.com/adafruit/lwip.git + branch = circuitpython8 [submodule "lib/mbedtls"] path = lib/mbedtls url = https://github.com/ARMmbed/mbedtls.git diff --git a/conf.py b/conf.py index 90f58979d9..7b3b4ca585 100644 --- a/conf.py +++ b/conf.py @@ -171,6 +171,7 @@ exclude_patterns = ["**/build*", ".env", ".venv", ".direnv", + ".devcontainer/Readme.md", "data", "docs/autoapi", "docs/README.md", diff --git a/locale/ID.po b/locale/ID.po index fe346373ef..5ac957eb07 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -112,7 +112,7 @@ msgstr "%q gagal: %d" msgid "%q in use" msgstr "%q sedang digunakan" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q indeks di luar batas" @@ -177,7 +177,7 @@ msgstr "%q harus berupa string" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q harus bertipe %q" @@ -1683,6 +1683,10 @@ msgstr "" msgid "Operation timed out" msgstr "Waktu habis" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "Kehabisan memori" @@ -2221,6 +2225,7 @@ msgid "Unable to read color palette data" msgstr "Tidak dapat membaca data palet warna" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3184,7 +3189,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "index keluar dari jangkauan" @@ -3436,10 +3441,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 2af9257feb..093886478b 100755 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -175,7 +175,7 @@ msgstr "" msgid "%q must be of type %q" msgstr "" -#: shared-bindings/digitalio/Pull.c +#: py/objexcept.c shared-bindings/digitalio/Pull.c msgid "%q must be of type %q or None" msgstr "" @@ -894,6 +894,10 @@ msgstr "" msgid "Drive mode not used when direction is input." msgstr "" +#: py/obj.c +msgid "During handling of the above exception, another exception occurred:" +msgstr "" + #: shared-bindings/aesio/aes.c msgid "ECB only operates on 16 bytes at a time" msgstr "" @@ -1663,6 +1667,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2011,6 +2019,10 @@ msgid "" "exit safe mode." msgstr "" +#: py/obj.c +msgid "The above exception was the direct cause of the following exception:" +msgstr "" + #: ports/espressif/boards/m5stack_atom_lite/mpconfigboard.h msgid "The central button was pressed at start up.\n" msgstr "" @@ -2196,6 +2208,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3352,10 +3365,6 @@ msgstr "" msgid "invalid syntax for number" msgstr "" -#: py/objexcept.c -msgid "invalid traceback" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "" @@ -3421,10 +3430,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/cs.po b/locale/cs.po index 3ea4c2dcf3..55a1787aa7 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -113,7 +113,7 @@ msgstr "%q: selhání %d" msgid "%q in use" msgstr "%q se právě používá" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "Index %q je mimo rozsah" @@ -178,7 +178,7 @@ msgstr "%q musí být string" msgid "%q must be an int" msgstr "%q musí být int" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q musí být typu %q" @@ -1679,6 +1679,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2210,6 +2214,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3171,7 +3176,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "" @@ -3423,10 +3428,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index d9c21c5742..127a1c4ac7 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -114,7 +114,7 @@ msgstr "%q Fehler: %d" msgid "%q in use" msgstr "%q in Benutzung" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "Der Index %q befindet sich außerhalb des Bereiches" @@ -180,7 +180,7 @@ msgstr "%q muss ein String sein" msgid "%q must be an int" msgstr "%q muss vom Typ Integer sein" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q muss vom Type %q sein" @@ -1700,6 +1700,10 @@ msgstr "Vorgang oder Funktion wird nicht unterstützt" msgid "Operation timed out" msgstr "Zeit für Vorgang abgelaufen" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "Kein Speicher mehr verfügbar" @@ -2249,6 +2253,7 @@ msgid "Unable to read color palette data" msgstr "Konnte Farbpalettendaten nicht lesen" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "mDNS-Abfrage kann nicht gestartet werden" @@ -3242,7 +3247,7 @@ msgid "index is out of bounds" msgstr "Index ist außerhalb der Grenzen" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "index außerhalb der Reichweite" @@ -3500,10 +3505,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "Loopback + Silent Mode wird vom Peripheriegerät nicht unterstützt" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "mDNS bereits initialisiert" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "mDNS funktioniert nur mit integriertem WiFi" diff --git a/locale/el.po b/locale/el.po index d47a0c5399..4a6b5c4250 100644 --- a/locale/el.po +++ b/locale/el.po @@ -118,7 +118,7 @@ msgstr "%q αποτυχία: %d" msgid "%q in use" msgstr "%q είναι σε χρήση" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q δείκτης εκτός εμβέλειας" @@ -183,7 +183,7 @@ msgstr "%q πρέπει να είναι string" msgid "%q must be an int" msgstr "%q πρέπει να είναι int" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q πρέπει να είναι τύπου %q" @@ -1688,6 +1688,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2219,6 +2223,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3180,7 +3185,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "" @@ -3432,10 +3437,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index e6fabd93d9..15d3644f52 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -116,7 +116,7 @@ msgstr "%q failure: %d" msgid "%q in use" msgstr "%q in use" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q index out of range" @@ -181,7 +181,7 @@ msgstr "%q must be a string" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1683,6 +1683,10 @@ msgstr "Operation or feature not supported" msgid "Operation timed out" msgstr "Operation timed out" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "Out of memory" @@ -2223,6 +2227,7 @@ msgid "Unable to read color palette data" msgstr "Unable to read colour palette data" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3190,7 +3195,7 @@ msgid "index is out of bounds" msgstr "index is out of bounds" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "index out of range" @@ -3442,10 +3447,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "loopback + silent mode not supported by peripheral" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/es.po b/locale/es.po index 13cb9a3821..bb1c36b9bf 100644 --- a/locale/es.po +++ b/locale/es.po @@ -118,7 +118,7 @@ msgstr "%q fallo: %d" msgid "%q in use" msgstr "%q está siendo utilizado" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q indice fuera de rango" @@ -183,7 +183,7 @@ msgstr "%q debe ser una cadena" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1707,6 +1707,10 @@ msgstr "Operación no característica no soportada" msgid "Operation timed out" msgstr "Tiempo de espera agotado" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "Memoria agotada" @@ -2255,6 +2259,7 @@ msgid "Unable to read color palette data" msgstr "No se pudo leer los datos de la paleta de colores" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3230,7 +3235,7 @@ msgid "index is out of bounds" msgstr "el índice está fuera de límites" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "index fuera de rango" @@ -3485,10 +3490,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "Loopback + modo silencioso no están soportados por periférico" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/fil.po b/locale/fil.po index f1e363b149..2cf6e49da4 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -107,7 +107,7 @@ msgstr "" msgid "%q in use" msgstr "%q ay ginagamit" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q indeks wala sa sakop" @@ -172,7 +172,7 @@ msgstr "" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1678,6 +1678,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2209,6 +2213,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3184,7 +3189,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "index wala sa sakop" @@ -3440,10 +3445,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/fr.po b/locale/fr.po index 2a4d6b230f..9f6bfba96b 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -118,7 +118,7 @@ msgstr "Échec de %q : %d" msgid "%q in use" msgstr "%q en cours d'utilisation" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "index %q hors de portée" @@ -183,7 +183,7 @@ msgstr "%q doit être une chaîne de caractères" msgid "%q must be an int" msgstr "%q doit être un entier" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q doit être du type %q" @@ -1727,6 +1727,10 @@ msgstr "Opération ou fonction non supportée" msgid "Operation timed out" msgstr "Timeout de l'opération" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "Mémoire insuffisante" @@ -2280,6 +2284,7 @@ msgid "Unable to read color palette data" msgstr "Impossible de lire les données de la palette de couleurs" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "Impossible de lancer la requête mDNS" @@ -3270,7 +3275,7 @@ msgid "index is out of bounds" msgstr "l'index est hors limites" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "index est hors bornes" @@ -3529,10 +3534,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "loopback + silent mode non pris en charge par le périphérique" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "mDNS a déjà été initialisé" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "mDNS ne fonctionne que avec le WiFi intégré" diff --git a/locale/hi.po b/locale/hi.po index 3c3496600b..ec884b211e 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -106,7 +106,7 @@ msgstr "" msgid "%q in use" msgstr "" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "" @@ -171,7 +171,7 @@ msgstr "" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1663,6 +1663,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2192,6 +2196,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3153,7 +3158,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "" @@ -3405,10 +3410,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index e1ba5c3827..60698f4d36 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -113,7 +113,7 @@ msgstr "%q fallito: %d" msgid "%q in use" msgstr "%q in uso" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "indice %q fuori intervallo" @@ -178,7 +178,7 @@ msgstr "" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1685,6 +1685,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2219,6 +2223,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3192,7 +3197,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "indice fuori intervallo" @@ -3449,10 +3454,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/ja.po b/locale/ja.po index f0755961cf..cc48e83b25 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -111,7 +111,7 @@ msgstr "%q 失敗: %d" msgid "%q in use" msgstr "%qは使用中" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q インデックスは範囲外" @@ -176,7 +176,7 @@ msgstr "" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1676,6 +1676,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2206,6 +2210,7 @@ msgid "Unable to read color palette data" msgstr "カラーパレットデータを読み込めません" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3171,7 +3176,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "インデクスが範囲外" @@ -3424,10 +3429,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/ko.po b/locale/ko.po index 4ec7ff804f..e1609990db 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -107,7 +107,7 @@ msgstr "" msgid "%q in use" msgstr "%q 사용 중입니다" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q 인덱스 범위를 벗어났습니다" @@ -172,7 +172,7 @@ msgstr "" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1666,6 +1666,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2196,6 +2200,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3157,7 +3162,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "" @@ -3409,10 +3414,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/nl.po b/locale/nl.po index fc1e1f77b8..e002370151 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -109,7 +109,7 @@ msgstr "%q fout: %d" msgid "%q in use" msgstr "%q in gebruik" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q index buiten bereik" @@ -174,7 +174,7 @@ msgstr "" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1680,6 +1680,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2216,6 +2220,7 @@ msgid "Unable to read color palette data" msgstr "Niet in staat kleurenpalet data te lezen" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3187,7 +3192,7 @@ msgid "index is out of bounds" msgstr "index is buiten bereik" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "index is buiten bereik" @@ -3442,10 +3447,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "loopback + silent mode wordt niet ondersteund door randapparaat" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/pl.po b/locale/pl.po index 22eacea387..d025272b69 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -111,7 +111,7 @@ msgstr "%q niepowodzenie: %d" msgid "%q in use" msgstr "%q w użyciu" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q poza zakresem" @@ -176,7 +176,7 @@ msgstr "" msgid "%q must be an int" msgstr "" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "" @@ -1674,6 +1674,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "Brak pamięci" @@ -2203,6 +2207,7 @@ msgid "Unable to read color palette data" msgstr "Nie można odczytać danych palety" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3165,7 +3170,7 @@ msgid "index is out of bounds" msgstr "indeks jest poza zakresem" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "indeks poza zakresem" @@ -3417,10 +3422,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index c3f7475167..e8a71e3d5b 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -115,7 +115,7 @@ msgstr "%q falha: %d" msgid "%q in use" msgstr "%q em uso" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "O índice %q está fora do intervalo" @@ -180,7 +180,7 @@ msgstr "%q deve ser uma string" msgid "%q must be an int" msgstr "%q deve ser um inteiro" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q deve ser do tipo %q" @@ -1709,6 +1709,10 @@ msgstr "A operação ou o recurso não é suportado" msgid "Operation timed out" msgstr "A operação expirou" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "Sem memória" @@ -2262,6 +2266,7 @@ msgid "Unable to read color palette data" msgstr "Não foi possível ler os dados da paleta de cores" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "Não é possível iniciar a consulta mDNS" @@ -3247,7 +3252,7 @@ msgid "index is out of bounds" msgstr "o índice está fora dos limites" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "Índice fora do intervalo" @@ -3503,10 +3508,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "o loopback + o modo silencioso não é suportado pelo periférico" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "O mDNS já foi inicializado" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "O mDNS só funciona com WiFi integrado" diff --git a/locale/ru.po b/locale/ru.po index a575f05a40..2bfe2cdece 100644 --- a/locale/ru.po +++ b/locale/ru.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2022-04-06 13:37+0000\n" -"Last-Translator: Jeff Epler \n" +"PO-Revision-Date: 2022-11-29 01:02+0000\n" +"Last-Translator: Clay \n" "Language-Team: none\n" "Language: ru\n" "MIME-Version: 1.0\n" @@ -16,7 +16,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" -"X-Generator: Weblate 4.12-dev\n" +"X-Generator: Weblate 4.15-dev\n" #: main.c msgid "" @@ -31,6 +31,8 @@ msgid "" "\n" "Code stopped by auto-reload. Reloading soon.\n" msgstr "" +"\n" +"Программа остановлена автоматической перезагрузкой. Скоро перезагрузка.\n" #: supervisor/shared/safe_mode.c msgid "" @@ -71,13 +73,14 @@ msgstr "%%c требует int или char" #: main.c #, c-format msgid "%02X" -msgstr "" +msgstr "%02X" #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format msgid "" "%d address pins, %d rgb pins and %d tiles indicate a height of %d, not %d" -msgstr "%d адресные пины, %d rgb пины и %d плитки указывают высоту %d а не %d" +msgstr "" +"%d адресных пинов, %d rgb пинов и %d тайлов указывают высоту %d а не %d" #: ports/atmel-samd/common-hal/alarm/__init__.c #: ports/cxd56/common-hal/analogio/AnalogOut.c ports/cxd56/common-hal/rtc/RTC.c @@ -90,7 +93,7 @@ msgstr "%d адресные пины, %d rgb пины и %d плитки ука #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/rtc/RTC.c msgid "%q" -msgstr "" +msgstr "%q" #: shared-bindings/microcontroller/Pin.c msgid "%q and %q contain duplicate pins" @@ -98,7 +101,7 @@ msgstr "%q и %q содержат пины-дупликаты" #: ports/atmel-samd/common-hal/audioio/AudioOut.c msgid "%q and %q must be different" -msgstr "" +msgstr "%q и %q должны быть разными" #: shared-bindings/microcontroller/Pin.c msgid "%q contains duplicate pins" @@ -114,21 +117,21 @@ msgstr "%q сбой: %d" msgid "%q in use" msgstr "%q используется" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "Индекс %q вне диапазона" #: shared-module/bitbangio/SPI.c msgid "%q init failed" -msgstr "" +msgstr "Инициализация %q не удалась" #: shared-bindings/dualbank/__init__.c msgid "%q is %q" -msgstr "" +msgstr "%q является %q" #: py/argcheck.c msgid "%q length must be %d" -msgstr "" +msgstr "Длинна %q должна быть %d" #: py/argcheck.c msgid "%q length must be %d-%d" @@ -136,11 +139,11 @@ msgstr "Длинна %q должна быть %d-%d" #: py/argcheck.c msgid "%q length must be <= %d" -msgstr "" +msgstr "Длинна %q должна быть <= %d" #: py/argcheck.c msgid "%q length must be >= %d" -msgstr "" +msgstr "Длинна %q должна быть >= %d" #: shared-bindings/busio/I2C.c msgid "%q length must be >= 1" @@ -148,44 +151,44 @@ msgstr "Длинна %q должна быть >= 1" #: py/argcheck.c msgid "%q must be %d" -msgstr "" +msgstr "%q должно быть %d" #: py/argcheck.c msgid "%q must be %d-%d" -msgstr "%q должен быть %d-%d" +msgstr "%q должно быть %d-%d" #: shared-bindings/displayio/Display.c msgid "%q must be 1 when %q is True" -msgstr "" +msgstr "%q должно быть 1 когда %q is True" #: py/argcheck.c shared-bindings/gifio/GifWriter.c msgid "%q must be <= %d" -msgstr "%q должен быть <= %d" +msgstr "%q должно быть <= %d" #: py/argcheck.c msgid "%q must be >= %d" -msgstr "%q должен быть >= %d" +msgstr "%q должно быть >= %d" #: shared-bindings/analogbufio/BufferedIn.c #: shared-bindings/audiocore/RawSample.c msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'" -msgstr "" +msgstr "%q должно быть bytearray или array типа 'h', 'H', 'b', или 'B'" #: py/argcheck.c msgid "%q must be a string" -msgstr "%q должен быть строкой" +msgstr "%q должно быть строкой" #: py/argcheck.c msgid "%q must be an int" -msgstr "" +msgstr "%q должно быть int" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" -msgstr "%q должен быть типа %q" +msgstr "%q должно быть типа %q" #: shared-bindings/digitalio/Pull.c msgid "%q must be of type %q or None" -msgstr "" +msgstr "%q должно быть типа %q или None" #: ports/atmel-samd/common-hal/busio/UART.c msgid "%q must be power of 2" @@ -223,7 +226,7 @@ msgstr "%q, %q, и %q должны быть одной длинны" #: py/objint.c shared-bindings/storage/__init__.c msgid "%q=%q" -msgstr "" +msgstr "%q=%q" #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c #, c-format @@ -357,7 +360,7 @@ msgstr "'data' требует как минимум 2 аргумента" #: py/compile.c msgid "'data' requires integer arguments" -msgstr "'data' требует целочисленных аргументов" +msgstr "'data' требует целочисленные аргументы" #: py/compile.c msgid "'label' requires 1 argument" @@ -598,7 +601,7 @@ msgstr "Для управления потоком требуется как RX, #: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h #: ports/atmel-samd/boards/meowmeow/mpconfigboard.h msgid "Both buttons were pressed at start up.\n" -msgstr "" +msgstr "Обе кнопки были нажаты при загрузке.\n" #: ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c msgid "Both pins must support hardware interrupts" @@ -668,7 +671,7 @@ msgstr "Пин шины %d уже используется" #: ports/espressif/boards/m5stack_core_basic/mpconfigboard.h #: ports/espressif/boards/m5stack_core_fire/mpconfigboard.h msgid "Button A was pressed at start up.\n" -msgstr "" +msgstr "Кнопка A была нажата при загрузке\n" #: shared-bindings/_bleio/UUID.c msgid "Byte buffer must be 16 bytes." @@ -680,7 +683,7 @@ msgstr "Блоки CBC должны быть кратны 16 байтам" #: supervisor/shared/safe_mode.c msgid "CIRCUITPY drive could not be found or created." -msgstr "" +msgstr "Не удалось найти или создать диск CIRCUITPY." #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "CRC or checksum was invalid" @@ -692,7 +695,7 @@ msgstr "Вызовите super().__init__() перед обращением к #: ports/cxd56/common-hal/camera/Camera.c msgid "Camera init" -msgstr "" +msgstr "Иницализация камеры" #: ports/espressif/common-hal/alarm/pin/PinAlarm.c msgid "Can only alarm on RTC IO from deep sleep." @@ -764,7 +767,7 @@ msgstr "Невозможно перемонтировать '/' пока он в #: ports/cxd56/common-hal/microcontroller/__init__.c #: ports/mimxrt10xx/common-hal/microcontroller/__init__.c msgid "Cannot reset into bootloader because no bootloader is present" -msgstr "" +msgstr "Не удалось перезагрузится в загрузчик так как загрузчик отсутствует" #: ports/espressif/common-hal/socketpool/Socket.c msgid "Cannot set socket options" @@ -785,15 +788,18 @@ msgstr "Срез субкласса невозможен" #: shared-module/bitbangio/SPI.c msgid "Cannot transfer without MOSI and MISO pins" -msgstr "" +msgstr "Невозможно передать данные без пинов MOSI и MISO" #: shared-bindings/pwmio/PWMOut.c msgid "Cannot vary frequency on a timer that is already in use" msgstr "Невозможно изменить частоту на таймере, который уже используется" #: ports/nrf/common-hal/alarm/pin/PinAlarm.c +#, fuzzy msgid "Cannot wake on pin edge, only level" msgstr "" +"Невозможно проснуться по изменению логического уровня (CHANGE), только по " +"уровню (LEVEL)" #: ports/espressif/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." @@ -913,7 +919,7 @@ msgstr "Поворот дисплея должен осуществляться #: main.c msgid "Done" -msgstr "" +msgstr "Выполнено" #: shared-bindings/digitalio/DigitalInOut.c msgid "Drive mode not used when direction is input." @@ -958,11 +964,12 @@ msgstr "Ожидалось(ся) %q" #: ports/raspberrypi/bindings/cyw43/__init__.c msgid "Expected a %q or %q" -msgstr "" +msgstr "Ожидалось %q или %q" #: shared-bindings/alarm/__init__.c +#, fuzzy msgid "Expected an %q" -msgstr "" +msgstr "Ожидалось %q" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nrf/common-hal/_bleio/Adapter.c @@ -992,7 +999,7 @@ msgstr "Не удалось получить mutex, ошибка 0x%04x" #: shared-module/rgbmatrix/RGBMatrix.c msgid "Failed to allocate %q buffer" -msgstr "" +msgstr "Не удалось выделить буфер %q" #: ports/espressif/common-hal/wifi/__init__.c msgid "Failed to allocate Wifi memory" @@ -1043,17 +1050,19 @@ msgid "Filters too complex" msgstr "Фильтры слишком сложные" #: ports/espressif/common-hal/dualbank/__init__.c +#, fuzzy msgid "Firmware is duplicate" -msgstr "" +msgstr "Прошивка является дубликатом" #: ports/espressif/common-hal/dualbank/__init__.c +#, fuzzy msgid "Firmware is invalid" -msgstr "" +msgstr "Прошивка является неправильной" #: ports/espressif/common-hal/coproc/Coproc.c #: ports/espressif/common-hal/dualbank/__init__.c msgid "Firmware is too big" -msgstr "" +msgstr "Прошивка слишком большая" #: shared-bindings/bitmaptools/__init__.c msgid "For L8 colorspace, input bitmap must have 8 bits per pixel" @@ -1073,6 +1082,8 @@ msgstr "Формат не поддерживается" msgid "" "Frequency must be 24, 150, 396, 450, 528, 600, 720, 816, 912, 960 or 1008 Mhz" msgstr "" +"Частота должна быть 24, 150, 396, 450, 528, 600, 720, 816, 912, 960 или 1008 " +"МГц" #: shared-bindings/pwmio/PWMOut.c msgid "Frequency must match existing PWMOut using this timer" @@ -1087,7 +1098,7 @@ msgstr "Функция требует блокировки" #: ports/cxd56/common-hal/gnss/GNSS.c msgid "GNSS init" -msgstr "" +msgstr "Инициализация GNSS" #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Generic Failure" @@ -1104,7 +1115,7 @@ msgstr "Группа уже используется" #: ports/mimxrt10xx/common-hal/busio/SPI.c ports/nrf/common-hal/busio/SPI.c #: ports/raspberrypi/common-hal/busio/SPI.c msgid "Half duplex SPI is not implemented" -msgstr "" +msgstr "Полудуплексный SPI не реализован" #: ports/mimxrt10xx/common-hal/busio/SPI.c ports/stm/common-hal/busio/I2C.c #: ports/stm/common-hal/busio/SPI.c ports/stm/common-hal/canio/CAN.c @@ -1122,7 +1133,7 @@ msgstr "Операция ввода-вывода на закрытом файл #: ports/stm/common-hal/busio/I2C.c msgid "I2C init error" -msgstr "" +msgstr "Ошибка инициализации I2C" #: ports/raspberrypi/common-hal/busio/I2C.c #: ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c @@ -1238,8 +1249,9 @@ msgid "Internal error #%d" msgstr "Внутренняя ошибка #%d" #: supervisor/shared/safe_mode.c +#, fuzzy msgid "Internal watchdog timer expired." -msgstr "" +msgstr "Внутренний сторожевой таймер истек." #: py/argcheck.c shared-bindings/digitalio/DigitalInOut.c msgid "Invalid %q" @@ -1322,12 +1334,14 @@ msgid "LHS of keyword arg must be an id" msgstr "LHS ключевого слова arg должен быть идентификатором(id)" #: shared-module/displayio/Group.c +#, fuzzy msgid "Layer already in a group" -msgstr "" +msgstr "Слой уже в группе (Group)" #: shared-module/displayio/Group.c +#, fuzzy msgid "Layer must be a Group or TileGrid subclass" -msgstr "" +msgstr "Слой должен быть группой (Group) или субклассом TileGrid." #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "MAC address was invalid" @@ -1349,7 +1363,7 @@ msgstr "Задержка включения микрофона должна бы #: ports/raspberrypi/bindings/rp2pio/StateMachine.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "Mismatched data size" -msgstr "" +msgstr "Размер данных различается" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "Mismatched swap flag" @@ -1361,7 +1375,7 @@ msgstr "Отсутствует пин MISO или MOSI" #: ports/stm/common-hal/busio/SPI.c msgid "Missing MISO or MOSI pin" -msgstr "" +msgstr "Отсутствует пин MISO или MOSI" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #, c-format @@ -1426,7 +1440,7 @@ msgstr "Имя слишком длинное" #: shared-bindings/displayio/TileGrid.c msgid "New bitmap must be same size as old bitmap" -msgstr "" +msgstr "Новый bitmap должен быть того же размера что и старый" #: ports/espressif/common-hal/_bleio/__init__.c msgid "Nimble out of memory" @@ -1454,13 +1468,13 @@ msgid "No DMA pacing timer found" msgstr "" #: shared-module/adafruit_bus_device/i2c_device/I2CDevice.c -#, c-format +#, fuzzy, c-format msgid "No I2C device at address: 0x%x" -msgstr "" +msgstr "Не найдено устройство I2C по адресу: %x" #: supervisor/shared/web_workflow/web_workflow.c msgid "No IP" -msgstr "" +msgstr "Нет IP" #: ports/espressif/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/SPI.c @@ -1469,7 +1483,7 @@ msgstr "Нет пина MISO" #: ports/stm/common-hal/busio/SPI.c shared-module/bitbangio/SPI.c msgid "No MISO pin" -msgstr "" +msgstr "Нет пина MISO" #: ports/espressif/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/SPI.c @@ -1478,7 +1492,7 @@ msgstr "Нет пина MOSI" #: ports/stm/common-hal/busio/SPI.c shared-module/bitbangio/SPI.c msgid "No MOSI pin" -msgstr "" +msgstr "Нет пина MOSI" #: ports/atmel-samd/common-hal/busio/UART.c #: ports/espressif/common-hal/busio/UART.c @@ -1564,8 +1578,9 @@ msgid "No space left on device" msgstr "На устройстве не осталось свободного места" #: py/moduerrno.c +#, fuzzy msgid "No such device" -msgstr "" +msgstr "Нет такого устройства" #: py/moduerrno.c msgid "No such file/directory" @@ -1576,8 +1591,9 @@ msgid "No timer available" msgstr "Нет доступного таймера" #: supervisor/shared/safe_mode.c +#, fuzzy msgid "Nordic system firmware failure assertion." -msgstr "" +msgstr "Сбой системной прошивки Nordic (assertion)." #: ports/nrf/common-hal/_bleio/__init__.c msgid "Nordic system firmware out of memory" @@ -1595,12 +1611,14 @@ msgstr "Не подключено" #: shared-bindings/audiobusio/I2SOut.c shared-bindings/audioio/AudioOut.c #: shared-bindings/audiopwmio/PWMAudioOut.c +#, fuzzy msgid "Not playing" -msgstr "Не играет" +msgstr "Не воспроизводится (Not playing)" #: shared-bindings/_bleio/__init__.c +#, fuzzy msgid "Not settable" -msgstr "Не устанавливается" +msgstr "Невозможно установить" #: ports/espressif/common-hal/paralleldisplay/ParallelBus.c #, c-format @@ -1620,11 +1638,12 @@ msgstr "" #: supervisor/shared/bluetooth/bluetooth.c msgid "Off" -msgstr "" +msgstr "Выключено" #: supervisor/shared/bluetooth/bluetooth.c +#, fuzzy msgid "Ok" -msgstr "" +msgstr "Ok" #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c #: ports/raspberrypi/common-hal/audiobusio/PDMIn.c @@ -1705,6 +1724,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2241,6 +2264,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3202,7 +3226,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "" @@ -3454,10 +3478,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/sv.po b/locale/sv.po index 1980477f4f..20e22166cd 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -114,7 +114,7 @@ msgstr "%q-fel: %d" msgid "%q in use" msgstr "%q används redan" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "Index %q ligger utanför intervallet" @@ -181,7 +181,7 @@ msgstr "%q måste vara en sträng" msgid "%q must be an int" msgstr "%q måste vara en int" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q måste vara av typen %q" @@ -1691,6 +1691,10 @@ msgstr "Operation eller funktion stöds inte" msgid "Operation timed out" msgstr "Åtgärden orsakade timeout" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "Slut på minne" @@ -2237,6 +2241,7 @@ msgid "Unable to read color palette data" msgstr "Det går inte att läsa färgpalettdata" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "Det gick inte att starta mDNS-frågan" @@ -3215,7 +3220,7 @@ msgid "index is out of bounds" msgstr "index är utanför gränserna" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "index utanför intervallet" @@ -3470,10 +3475,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "loopback + tyst läge stöds inte av kringutrustning" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "mDNS har redan initierats" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "mDNS fungerar bara med inbyggt WiFi" diff --git a/locale/tr.po b/locale/tr.po index 1d8eacdae0..09705c507e 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -118,7 +118,7 @@ msgstr "%q hata: %d" msgid "%q in use" msgstr "%q kullanımda" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q indeksi aralık dışında" @@ -183,7 +183,7 @@ msgstr "%q bir string olmalıdır" msgid "%q must be an int" msgstr "%q bir tam sayı olmalıdır" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q, %q türünde olmalıdır" @@ -1680,6 +1680,10 @@ msgstr "" msgid "Operation timed out" msgstr "" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "" @@ -2212,6 +2216,7 @@ msgid "Unable to read color palette data" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "" @@ -3173,7 +3178,7 @@ msgid "index is out of bounds" msgstr "" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "" @@ -3425,10 +3430,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 9178bd4caa..ac9d28d5fc 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,8 +7,8 @@ msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2022-11-15 04:35+0000\n" -"Last-Translator: River Wang \n" +"PO-Revision-Date: 2022-11-19 18:48+0000\n" +"Last-Translator: hexthat \n" "Language-Team: Chinese Hanyu Pinyin\n" "Language: zh_Latn_pinyin\n" "MIME-Version: 1.0\n" @@ -72,7 +72,7 @@ msgstr "%%c xūyào zhěngshù huòzhě zìfú" #: main.c #, c-format msgid "%02X" -msgstr "" +msgstr "%02X" #: shared-bindings/rgbmatrix/RGBMatrix.c #, c-format @@ -117,7 +117,7 @@ msgstr "%q Shībài: %d" msgid "%q in use" msgstr "%q zhèngzài bèi shǐyòng" -#: py/obj.c py/objstr.c py/objstrunicode.c +#: py/objstr.c py/objstrunicode.c msgid "%q index out of range" msgstr "%q suǒyǐn chāochū fànwéi" @@ -183,7 +183,7 @@ msgstr "%q bìxū shì yí gè zì fú chuàn" msgid "%q must be an int" msgstr "%q bìxū shì zhěng xíng" -#: py/argcheck.c +#: py/argcheck.c py/obj.c msgid "%q must be of type %q" msgstr "%q bì xū shì %q lèi xíng" @@ -741,9 +741,8 @@ msgid "Cannot get temperature" msgstr "Wúfǎ huòqǔ wēndù" #: shared-bindings/_bleio/Adapter.c -#, fuzzy msgid "Cannot have scan responses for extended, connectable advertisements." -msgstr "Nín wúfǎ sǎomiáo kuòzhǎn de, kě liánjiē de guǎnggào." +msgstr "Quē fá duì tuī guǎng, kě lián jiē guǎng gào de dá fù." #: ports/espressif/common-hal/alarm/pin/PinAlarm.c msgid "Cannot pull on input-only pin." @@ -794,7 +793,7 @@ msgstr "wúfǎ shǐyòng biānyuán huànxǐng, zhǐnéng shǐyòng diànpíng" #: ports/espressif/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." -msgstr "wúfǎ shǐyòng biānyuán huànxǐng. zhǐnéng shǐyòng diànpíng" +msgstr "wúfǎ shǐyòng biānyuán huànxǐng. zhǐnéng shǐyòng diànpíng." #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "CharacteristicBuffer writing not provided" @@ -864,9 +863,8 @@ msgstr "DAC zhèngzài bèi shǐyòng" #: ports/atmel-samd/common-hal/paralleldisplay/ParallelBus.c #: ports/nrf/common-hal/paralleldisplay/ParallelBus.c -#, fuzzy msgid "Data 0 pin must be byte aligned" -msgstr "Shùjù 0 de yǐn jiǎo bìxū shì zì jié duìqí" +msgstr "shù jù 0 yǐn jiǎo bì xū shì zì jié duì qí de" #: shared-module/audiocore/WaveFile.c msgid "Data chunk must follow fmt chunk" @@ -874,9 +872,8 @@ msgstr "Shùjù kuài bìxū zūnxún fmt qū kuài" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nrf/common-hal/_bleio/Adapter.c -#, fuzzy msgid "Data not supported with directed advertising" -msgstr "bù zhī chí dìng xiàng guǎng gào de shù jù" +msgstr "wèi xiàng guǎng gào tí gòng zhī zhù de shù jù" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nrf/common-hal/_bleio/Adapter.c @@ -1701,6 +1698,10 @@ msgstr "bù zhī chí cāo zuò huò gōng néng" msgid "Operation timed out" msgstr "cāo zuò yǐ fēn shí" +#: ports/raspberrypi/common-hal/mdns/Server.c +msgid "Out of MDNS service slots" +msgstr "" + #: ports/espressif/common-hal/espidf/__init__.c ports/espressif/esp_error.c msgid "Out of memory" msgstr "nèi cún bù zú" @@ -2186,7 +2187,7 @@ msgstr "UART xiě rù" #: main.c msgid "UID:" -msgstr "" +msgstr "UID:" #: shared-module/usb_hid/Device.c msgid "USB busy" @@ -2246,6 +2247,7 @@ msgid "Unable to read color palette data" msgstr "Wúfǎ dúqǔ tiáosèbǎn shùjù" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" msgstr "wú fǎ qǐ dòng mDNS chá xún" @@ -3225,7 +3227,7 @@ msgid "index is out of bounds" msgstr "suǒyǐn chāochū fànwéi" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c -#: ports/espressif/common-hal/pulseio/PulseIn.c py/obj.c +#: ports/espressif/common-hal/pulseio/PulseIn.c #: shared-bindings/bitmaptools/__init__.c msgid "index out of range" msgstr "suǒyǐn chāochū fànwéi" @@ -3478,10 +3480,12 @@ msgid "loopback + silent mode not supported by peripheral" msgstr "Wài shè bù zhī chí huán huí + jìng yīn mó shì" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" msgstr "mDNS yǐ chū shǐ huà" #: ports/espressif/common-hal/mdns/Server.c +#: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" msgstr "mDNS jǐn shì yòng yú nèi zhì wú xiàn wǎng luò" diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 4405766d00..68beeaf129 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -22,36 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -ifeq ($(BOARD),) - $(error You must provide a BOARD parameter) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- @@ -108,7 +79,7 @@ endif ifeq ($(CHIP_FAMILY), same54) PERIPHERALS_CHIP_FAMILY=sam_d5x_e5x -OPTIMIZATION_FLAGS ?= -O2 +OPTIMIZATION_FLAGS ?= -Os # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 endif @@ -322,7 +293,6 @@ SRC_C += \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ eic_handler.c \ - fatfs_port.c \ lib/tinyusb/src/portable/microchip/samd/dcd_samd.c \ mphalport.c \ reset.c \ diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index a565a77042..7007672b3f 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -405,7 +405,13 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self, if (self->right_channel == &pin_PA02) { right_channel_reg = (uint32_t)&DAC->DATABUF[0].reg; } - if (right_channel_reg == left_channel_reg + 2 && audiosample_bits_per_sample(sample) == 16) { + + size_t num_channels = audiosample_channel_count(sample); + + if (num_channels == 2 && + // Are DAC channels sequential? + left_channel_reg + 2 == right_channel_reg && + audiosample_bits_per_sample(sample) == 16) { result = audio_dma_setup_playback(&self->left_dma, sample, loop, false, 0, false /* output unsigned */, left_channel_reg, @@ -415,7 +421,11 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self, false /* output unsigned */, left_channel_reg, left_channel_trigger); - if (right_channel_reg != 0 && result == AUDIO_DMA_OK) { + // Don't play back on right channel unless stereo. + // TODO possibility: Set up non-incrementing DMA on one channel so they use the same samples? + // Right now, playing back mono on both channels causes sample to play twice as fast. + if (num_channels == 2 && + right_channel_reg != 0 && result == AUDIO_DMA_OK) { result = audio_dma_setup_playback(&self->right_dma, sample, loop, true, 1, false /* output unsigned */, right_channel_reg, diff --git a/ports/atmel-samd/common-hal/sdioio/SDCard.c b/ports/atmel-samd/common-hal/sdioio/SDCard.c index 7ce8a1e1b1..e641db75ac 100644 --- a/ports/atmel-samd/common-hal/sdioio/SDCard.c +++ b/ports/atmel-samd/common-hal/sdioio/SDCard.c @@ -114,8 +114,6 @@ CLK PA21 PCC_D? (D32) BROWN gpio_set_pin_pull_mode(functions[i]->pin, (i == 1 || i == 5) ? GPIO_PULL_OFF : GPIO_PULL_UP); gpio_set_pin_function(functions[i]->pin, GPIO_PIN_FUNCTION_SDIO); - - common_hal_never_reset_pin(functions[i]->obj); } self->num_data = num_data; @@ -145,6 +143,12 @@ CLK PA21 PCC_D? (D32) BROWN } if (result != SD_MMC_OK) { + for (size_t i = 0; i < MP_ARRAY_SIZE(functions); i++) { + if (!functions[i]->obj) { + break; + } + reset_pin_number(functions[i]->obj->number); + } mp_raise_OSError_msg_varg(translate("%q failure: %d"), MP_QSTR_sd_mmc_check, (int)result); } // sd_mmc_get_capacity() is in KiB, but our "capacity" is in 512-byte blocks diff --git a/ports/atmel-samd/fatfs_port.c b/ports/atmel-samd/fatfs_port.c deleted file mode 100644 index 58a0ef0d72..0000000000 --- a/ports/atmel-samd/fatfs_port.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George - * - * 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/mphal.h" -#include "py/runtime.h" -#include "lib/oofatfs/ff.h" /* FatFs lower layer API */ -#include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "shared/timeutils/timeutils.h" - -#if CIRCUITPY_RTC -#include "shared-bindings/rtc/RTC.h" -#endif - -DWORD get_fattime(void) { - #if CIRCUITPY_RTC - timeutils_struct_time_t tm; - common_hal_rtc_get_time(&tm); - return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) | - (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); - #else - return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2); - #endif - - -} diff --git a/ports/broadcom/Makefile b/ports/broadcom/Makefile index 757e7f3450..b6dd62dedf 100644 --- a/ports/broadcom/Makefile +++ b/ports/broadcom/Makefile @@ -1,35 +1,28 @@ -# Select the board to build for. -BOARD?=raspberrypi_pi4b +# This file is part of the MicroPython project, http://micropython.org/ +# +# The MIT License (MIT) +# +# SPDX-FileCopyrightText: Copyright (c) 2020 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. -ifeq ($(BOARD),) - $(error You must provide a BOARD parameter) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD "$(BOARD)" specified) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk ifeq ($(CHIP_VARIANT), "bcm2711") CFLAGS += -mcpu=cortex-a72 -DBCM_VERSION=2711 @@ -65,7 +58,6 @@ SRC_C += bindings/videocore/__init__.c \ boards/$(BOARD)/pins.c \ background.c \ common-hal/videocore/Framebuffer.c \ - fatfs_port.c \ mphalport.c \ lib/sdmmc/sdmmc_cmd.c \ lib/sdmmc/sdmmc_common.c \ diff --git a/ports/broadcom/fatfs_port.c b/ports/broadcom/fatfs_port.c deleted file mode 100644 index 58a0ef0d72..0000000000 --- a/ports/broadcom/fatfs_port.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George - * - * 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/mphal.h" -#include "py/runtime.h" -#include "lib/oofatfs/ff.h" /* FatFs lower layer API */ -#include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "shared/timeutils/timeutils.h" - -#if CIRCUITPY_RTC -#include "shared-bindings/rtc/RTC.h" -#endif - -DWORD get_fattime(void) { - #if CIRCUITPY_RTC - timeutils_struct_time_t tm; - common_hal_rtc_get_time(&tm); - return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) | - (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); - #else - return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2); - #endif - - -} diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index 073d2d59ce..5d06143f73 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -22,39 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -ifeq ($(BOARD),) - $(error You must provide a BOARD parameter) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk - -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk - -# Port-specific -include mpconfigport.mk - -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- @@ -172,7 +140,6 @@ SRC_S = supervisor/cpu.s SRC_C += \ background.c \ - fatfs_port.c \ mphalport.c \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ diff --git a/ports/cxd56/fatfs_port.c b/ports/cxd56/fatfs_port.c deleted file mode 100644 index e672b095b7..0000000000 --- a/ports/cxd56/fatfs_port.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright 2019 Sony Semiconductor Solutions Corporation - * - * 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/mphal.h" -#include "py/runtime.h" -#include "lib/oofatfs/ff.h" /* FatFs lower layer API */ -#include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "shared/timeutils/timeutils.h" - -#if CIRCUITPY_RTC -#include "shared-bindings/rtc/RTC.h" -#endif - -DWORD get_fattime(void) { - #if CIRCUITPY_RTC - timeutils_struct_time_t tm; - common_hal_rtc_get_time(&tm); - return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) | - (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); - #else - return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2); - #endif -} diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 30c35f9caf..4e72e5c45a 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -22,42 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -ifeq ($(BOARD),) - $(error You must provide a BOARD parameter) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - -# If the flash PORT is not given, use the default /dev/tty.SLAB_USBtoUART. -PORT ?= /dev/tty.SLAB_USBtoUART - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk - -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk - -# Port-specific -include mpconfigport.mk - -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk ifeq ($(IDF_TARGET),esp32c3) IDF_TARGET_ARCH = riscv @@ -250,7 +215,6 @@ endif SRC_C += \ background.c \ - fatfs_port.c \ mphalport.c \ bindings/espidf/__init__.c \ boards/$(BOARD)/board.c \ @@ -458,7 +422,7 @@ esp-idf-stamp: $(BUILD)/esp-idf/config/sdkconfig.h $(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp $(STEPECHO) "LINK $@" - $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) $(BUILD)/esp-idf/esp-idf/newlib/libnewlib.a -Wl,--end-group -u newlib_include_pthread_impl -Wl,--start-group $(LIBS) -Wl,--end-group $(BUILD)/esp-idf/esp-idf/pthread/libpthread.a -u __cxx_fatal_exception + $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(ESP_IDF_COMPONENTS_EXPANDED) $(BINARY_BLOBS) $(MBEDTLS_COMPONENTS_LINK_EXPANDED) $(BUILD)/esp-idf/esp-idf/newlib/libnewlib.a -Wl,--end-group -u newlib_include_pthread_impl -u ld_include_highint_hdl -Wl,--start-group $(LIBS) -Wl,--end-group $(BUILD)/esp-idf/esp-idf/pthread/libpthread.a -u __cxx_fatal_exception $(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf | tools/build_memory_info.py $(STEPECHO) "Create $@" diff --git a/ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig b/ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig index 5111900c7e..b47420753c 100644 --- a/ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig +++ b/ports/espressif/boards/adafruit_qtpy_esp32c3/sdkconfig @@ -1,70 +1,5 @@ -# Automatically generated file. DO NOT EDIT. -# Espressif IoT Development Framework (ESP-IDF) Project Configuration -# -# Bootloader config -# -CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y -# CONFIG_BOOTLOADER_LOG_LEVEL_INFO is not set -CONFIG_BOOTLOADER_LOG_LEVEL=0 -# end of Bootloader config - -# -# Serial flasher config -# -# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set -# end of Serial flasher config - -# -# Partition Table -# -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="esp-idf-config/partitions-4MB-no-uf2.csv" -CONFIG_PARTITION_TABLE_FILENAME="esp-idf-config/partitions-4MB-no-uf2.csv" -# end of Partition Table - -# -# Compiler options -# -# CONFIG_COMPILER_SAVE_RESTORE_LIBCALLS is not set -# end of Compiler options - -# -# Component config -# -# - -# -# PHY -# -CONFIG_ESP_PHY_ENABLE_USB=y -# end of PHY - -# -# ESP System Settings -# -# CONFIG_ESP_SYSTEM_USE_EH_FRAME is not set -CONFIG_ESP_CONSOLE_SECONDARY_NONE=y -# CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is not set -# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set -# end of ESP System Settings - # # LWIP # CONFIG_LWIP_LOCAL_HOSTNAME="Adafruit-QTPy-ESP32C3" # end of LWIP - -# -# SPI Flash driver -# -# CONFIG_SPI_FLASH_AUTO_SUSPEND is not set -# end of SPI Flash driver - -# end of Component config - -# -# Deprecated options for backward compatibility -# -# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set -CONFIG_LOG_BOOTLOADER_LEVEL=0 -# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set -# end of Deprecated options for backward compatibility diff --git a/ports/espressif/boards/ai_thinker_esp32-c3s-2m/mpconfigboard.h b/ports/espressif/boards/ai_thinker_esp32-c3s-2m/mpconfigboard.h index a42f8b0436..a9f0075a41 100644 --- a/ports/espressif/boards/ai_thinker_esp32-c3s-2m/mpconfigboard.h +++ b/ports/espressif/boards/ai_thinker_esp32-c3s-2m/mpconfigboard.h @@ -30,7 +30,9 @@ #define MICROPY_HW_MCU_NAME "ESP32-C3" // Status LED -#define MICROPY_HW_LED_STATUS (&pin_GPIO19) +#define CIRCUITPY_RGB_STATUS_R (&pin_GPIO3) +#define CIRCUITPY_RGB_STATUS_G (&pin_GPIO4) +#define CIRCUITPY_RGB_STATUS_B (&pin_GPIO5) // Default bus pins #define DEFAULT_UART_BUS_RX (&pin_GPIO20) diff --git a/ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h b/ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h index 20fb1ff022..f3f89d500b 100644 --- a/ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h +++ b/ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h @@ -30,7 +30,9 @@ #define MICROPY_HW_MCU_NAME "ESP32-C3FN4" // Status LED -#define MICROPY_HW_LED_STATUS (&pin_GPIO19) +#define CIRCUITPY_RGB_STATUS_R (&pin_GPIO3) +#define CIRCUITPY_RGB_STATUS_G (&pin_GPIO4) +#define CIRCUITPY_RGB_STATUS_B (&pin_GPIO5) // Default bus pins #define DEFAULT_UART_BUS_RX (&pin_GPIO20) diff --git a/ports/espressif/boards/beetle-esp32-c3/sdkconfig b/ports/espressif/boards/beetle-esp32-c3/sdkconfig index 331a5d14dc..68be40df7a 100644 --- a/ports/espressif/boards/beetle-esp32-c3/sdkconfig +++ b/ports/espressif/boards/beetle-esp32-c3/sdkconfig @@ -1,13 +1,5 @@ -# -# PHY -# -CONFIG_ESP_PHY_ENABLE_USB=y -# end of PHY - # # LWIP # CONFIG_LWIP_LOCAL_HOSTNAME="beetle-esp32-c3 # end of LWIP - - diff --git a/ports/espressif/boards/lolin_c3_mini/sdkconfig b/ports/espressif/boards/lolin_c3_mini/sdkconfig index c548ee3c69..833f8368fa 100644 --- a/ports/espressif/boards/lolin_c3_mini/sdkconfig +++ b/ports/espressif/boards/lolin_c3_mini/sdkconfig @@ -1,13 +1,5 @@ -# -# PHY -# -CONFIG_ESP_PHY_ENABLE_USB=y -# end of PHY - # # LWIP # CONFIG_LWIP_LOCAL_HOSTNAME="lolin-c3-mini" # end of LWIP - - diff --git a/ports/espressif/boards/microdev_micro_c3/sdkconfig b/ports/espressif/boards/microdev_micro_c3/sdkconfig index 6674dbfb90..f6f038a77c 100644 --- a/ports/espressif/boards/microdev_micro_c3/sdkconfig +++ b/ports/espressif/boards/microdev_micro_c3/sdkconfig @@ -1,70 +1,5 @@ -# Automatically generated file. DO NOT EDIT. -# Espressif IoT Development Framework (ESP-IDF) Project Configuration -# -# Bootloader config -# -CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y -# CONFIG_BOOTLOADER_LOG_LEVEL_INFO is not set -CONFIG_BOOTLOADER_LOG_LEVEL=0 -# end of Bootloader config - -# -# Serial flasher config -# -# CONFIG_ESPTOOLPY_FLASHFREQ_26M is not set -# end of Serial flasher config - -# -# Partition Table -# -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="esp-idf-config/partitions-4MB-no-uf2.csv" -CONFIG_PARTITION_TABLE_FILENAME="esp-idf-config/partitions-4MB-no-uf2.csv" -# end of Partition Table - -# -# Compiler options -# -# CONFIG_COMPILER_SAVE_RESTORE_LIBCALLS is not set -# end of Compiler options - -# -# Component config -# -# - -# -# PHY -# -CONFIG_ESP_PHY_ENABLE_USB=y -# end of PHY - -# -# ESP System Settings -# -# CONFIG_ESP_SYSTEM_USE_EH_FRAME is not set -CONFIG_ESP_CONSOLE_SECONDARY_NONE=y -# CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is not set -# CONFIG_ESP_DEBUG_STUBS_ENABLE is not set -# end of ESP System Settings - # # LWIP # CONFIG_LWIP_LOCAL_HOSTNAME="MicroDev-microC3" # end of LWIP - -# -# SPI Flash driver -# -# CONFIG_SPI_FLASH_AUTO_SUSPEND is not set -# end of SPI Flash driver - -# end of Component config - -# -# Deprecated options for backward compatibility -# -# CONFIG_LOG_BOOTLOADER_LEVEL_INFO is not set -CONFIG_LOG_BOOTLOADER_LEVEL=0 -# CONFIG_COMPILER_OPTIMIZATION_LEVEL_DEBUG is not set -# end of Deprecated options for backward compatibility diff --git a/ports/espressif/common-hal/busio/UART.c b/ports/espressif/common-hal/busio/UART.c index cdaf25250f..f025c15b3e 100644 --- a/ports/espressif/common-hal/busio/UART.c +++ b/ports/espressif/common-hal/busio/UART.c @@ -49,8 +49,9 @@ static void uart_event_task(void *param) { while (true) { if (xQueueReceive(self->event_queue, &event, portMAX_DELAY)) { switch (event.type) { + case UART_BREAK: case UART_PATTERN_DET: - // When the console uart receives CTRL+C, wake the main task and schedule a keyboard interrupt + // When the console uart receives CTRL+C or BREAK, wake the main task and schedule a keyboard interrupt if (self->is_console) { port_wake_main_task(); if (mp_interrupt_char == CHAR_CTRL_C) { diff --git a/ports/espressif/common-hal/pwmio/PWMOut.c b/ports/espressif/common-hal/pwmio/PWMOut.c index d83ce6590a..68518fbd25 100644 --- a/ports/espressif/common-hal/pwmio/PWMOut.c +++ b/ports/espressif/common-hal/pwmio/PWMOut.c @@ -166,7 +166,20 @@ void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) { void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) { never_reset_tim[self->tim_handle.timer_num] = false; - never_reset_chan[self->chan_handle.channel] = false; + // Search if any other channel is using the timer and is never reset. + // Otherwise, we clear never_reset for the timer as well. + bool other_never_reset = false; + for (size_t i = 0; i < LEDC_CHANNEL_MAX; i++) { + if (i != self->chan_handle.channel && + reserved_channels[i] == self->tim_handle.timer_num && + never_reset_chan[i]) { + other_never_reset = true; + break; + } + } + if (!other_never_reset) { + never_reset_chan[self->chan_handle.channel] = false; + } } bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t *self) { @@ -182,11 +195,13 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) { ledc_stop(LEDC_LOW_SPEED_MODE, self->chan_handle.channel, 0); } reserved_channels[self->chan_handle.channel] = INDEX_EMPTY; + never_reset_chan[self->chan_handle.channel] = false; // Search if any other channel is using the timer bool taken = false; for (size_t i = 0; i < LEDC_CHANNEL_MAX; i++) { if (reserved_channels[i] == self->tim_handle.timer_num) { taken = true; + break; } } // Variable frequency means there's only one channel on the timer @@ -195,6 +210,7 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) { reserved_timer_freq[self->tim_handle.timer_num] = 0; // if timer isn't varfreq this will be off aleady varfreq_timers[self->tim_handle.timer_num] = false; + never_reset_tim[self->tim_handle.timer_num] = false; } common_hal_reset_pin(self->pin); self->deinited = true; diff --git a/ports/espressif/common-hal/socketpool/Socket.c b/ports/espressif/common-hal/socketpool/Socket.c index ce177f3821..5f34d674b2 100644 --- a/ports/espressif/common-hal/socketpool/Socket.c +++ b/ports/espressif/common-hal/socketpool/Socket.c @@ -240,7 +240,7 @@ socketpool_socket_obj_t *common_hal_socketpool_socket(socketpool_socketpool_obj_ return sock; } -int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_t *port) { +int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_t *port, socketpool_socket_obj_t *accepted) { struct sockaddr_in accept_addr; socklen_t socklen = sizeof(accept_addr); int newsoc = -1; @@ -274,12 +274,25 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_ lwip_close(newsoc); return -MP_EBADF; } + + + if (accepted != NULL) { + // Close the active socket because we have another we accepted. + if (!common_hal_socketpool_socket_get_closed(accepted)) { + common_hal_socketpool_socket_close(accepted); + } + // Create the socket + accepted->num = newsoc; + accepted->pool = self->pool; + accepted->connected = true; + } + return newsoc; } socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_t *port) { - int newsoc = socketpool_socket_accept(self, ip, port); + int newsoc = socketpool_socket_accept(self, ip, port, NULL); if (newsoc > 0) { mark_user_socket(newsoc); @@ -554,6 +567,15 @@ void common_hal_socketpool_socket_settimeout(socketpool_socket_obj_t *self, uint self->timeout_ms = timeout_ms; } + +int common_hal_socketpool_socket_setsockopt(socketpool_socket_obj_t *self, int level, int optname, const void *value, size_t optlen) { + int err = lwip_setsockopt(self->num, level, optname, value, optlen); + if (err != 0) { + return -errno; + } + return 0; +} + bool common_hal_socketpool_readable(socketpool_socket_obj_t *self) { struct timeval immediate = {0, 0}; @@ -577,3 +599,18 @@ bool common_hal_socketpool_writable(socketpool_socket_obj_t *self) { // including returning true in the error case return num_triggered != 0; } + +void socketpool_socket_move(socketpool_socket_obj_t *self, socketpool_socket_obj_t *sock) { + *sock = *self; + self->connected = false; + self->num = -1; +} + +void socketpool_socket_reset(socketpool_socket_obj_t *self) { + if (self->base.type == &socketpool_socket_type) { + return; + } + self->base.type = &socketpool_socket_type; + self->connected = false; + self->num = -1; +} diff --git a/ports/espressif/common-hal/socketpool/SocketPool.c b/ports/espressif/common-hal/socketpool/SocketPool.c index 1d1aafa638..780e90c42c 100644 --- a/ports/espressif/common-hal/socketpool/SocketPool.c +++ b/ports/espressif/common-hal/socketpool/SocketPool.c @@ -45,6 +45,16 @@ void common_hal_socketpool_socketpool_construct(socketpool_socketpool_obj_t *sel mp_obj_t common_hal_socketpool_socketpool_gethostbyname(socketpool_socketpool_obj_t *self, const char *host) { + // As of 2022, the version of lwip in esp-idf does not handle the + // trailing-dot syntax of domain names, so emulate it. + // Remove this once https://github.com/espressif/esp-idf/issues/10013 has + // been implemented + size_t strlen_host = strlen(host); + if (strlen_host && host[strlen_host - 1] == '.') { + mp_obj_t nodot = mp_obj_new_str(host, strlen_host - 1); + host = mp_obj_str_get_str(nodot); + } + const struct addrinfo hints = { .ai_family = AF_INET, .ai_socktype = SOCK_STREAM, diff --git a/ports/espressif/common-hal/wifi/Network.c b/ports/espressif/common-hal/wifi/Network.c index 34cb15d603..5c9852a1f7 100644 --- a/ports/espressif/common-hal/wifi/Network.c +++ b/ports/espressif/common-hal/wifi/Network.c @@ -55,31 +55,31 @@ mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) { } mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) { - uint8_t authmode_mask = 0; + uint32_t authmode_mask = 0; switch (self->record.authmode) { case WIFI_AUTH_OPEN: - authmode_mask = (1 << AUTHMODE_OPEN); + authmode_mask = AUTHMODE_OPEN; break; case WIFI_AUTH_WEP: - authmode_mask = (1 << AUTHMODE_WEP); + authmode_mask = AUTHMODE_WEP; break; case WIFI_AUTH_WPA_PSK: - authmode_mask = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_PSK); + authmode_mask = AUTHMODE_WPA | AUTHMODE_PSK; break; case WIFI_AUTH_WPA2_PSK: - authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK); + authmode_mask = AUTHMODE_WPA2 | AUTHMODE_PSK; break; case WIFI_AUTH_WPA_WPA2_PSK: - authmode_mask = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK); + authmode_mask = AUTHMODE_WPA | AUTHMODE_WPA2 | AUTHMODE_PSK; break; case WIFI_AUTH_WPA2_ENTERPRISE: - authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_ENTERPRISE); + authmode_mask = AUTHMODE_WPA2 | AUTHMODE_ENTERPRISE; break; case WIFI_AUTH_WPA3_PSK: - authmode_mask = (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK); + authmode_mask = AUTHMODE_WPA3 | AUTHMODE_PSK; break; case WIFI_AUTH_WPA2_WPA3_PSK: - authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK); + authmode_mask = AUTHMODE_WPA2 | AUTHMODE_WPA3 | AUTHMODE_PSK; break; default: break; diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 27e2c8c610..acd6ae53bc 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -205,20 +205,21 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { set_mode_station(self, false); } -void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections) { +void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint32_t authmodes, uint8_t max_connections) { set_mode_ap(self, true); - switch (authmode) { - case (1 << AUTHMODE_OPEN): + uint8_t authmode = 0; + switch (authmodes) { + case AUTHMODE_OPEN: authmode = WIFI_AUTH_OPEN; break; - case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_PSK)): + case AUTHMODE_WPA | AUTHMODE_PSK: authmode = WIFI_AUTH_WPA_PSK; break; - case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)): + case AUTHMODE_WPA2 | AUTHMODE_PSK: authmode = WIFI_AUTH_WPA2_PSK; break; - case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)): + case AUTHMODE_WPA | AUTHMODE_WPA2 | AUTHMODE_PSK: authmode = WIFI_AUTH_WPA_WPA2_PSK; break; default: diff --git a/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults b/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults index 5b5df1837c..5fdb766add 100644 --- a/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults +++ b/ports/espressif/esp-idf-config/sdkconfig-esp32c3.defaults @@ -80,6 +80,12 @@ CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y # end of Hardware Settings +# +# PHY +# +CONFIG_ESP_PHY_ENABLE_USB=y +# end of PHY + # # ESP System Settings # @@ -97,8 +103,12 @@ CONFIG_ESP_SYSTEM_MEMPROT_MEM_ALIGN_SIZE=512 CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y # CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set CONFIG_ESP_MAIN_TASK_AFFINITY=0x0 + +CONFIG_ESP_CONSOLE_SECONDARY_NONE=y +# CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is not set # end of ESP System Settings + # # Wi-Fi # diff --git a/ports/espressif/fatfs_port.c b/ports/espressif/fatfs_port.c deleted file mode 100644 index 38c2d923b8..0000000000 --- a/ports/espressif/fatfs_port.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George - * - * 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 "lib/oofatfs/ff.h" -#include "shared/timeutils/timeutils.h" -#include "shared-bindings/rtc/RTC.h" -#include "shared-bindings/time/__init__.h" -#include "supervisor/fatfs_port.h" - -DWORD _time_override = 0; -DWORD get_fattime(void) { - if (_time_override > 0) { - return _time_override; - } - #if CIRCUITPY_RTC - timeutils_struct_time_t tm; - common_hal_rtc_get_time(&tm); - return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) | - (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); - #else - return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2); - #endif -} - -void override_fattime(DWORD time) { - _time_override = time; -} diff --git a/ports/litex/Makefile b/ports/litex/Makefile index 6b1e33c8d1..efe99dc5b4 100644 --- a/ports/litex/Makefile +++ b/ports/litex/Makefile @@ -22,37 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -ifeq ($(BOARD),) - $(error You must provide a BOARD parameter) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk - -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = riscv64-unknown-elf- @@ -117,7 +87,6 @@ CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_VALENTYUSB_EPTRI -DCFG_TUD_CDC_RX_BUFSIZE=1024 SRC_C += \ background.c \ - fatfs_port.c \ mphalport.c \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile index 4b05c91714..080a65e8fe 100644 --- a/ports/mimxrt10xx/Makefile +++ b/ports/mimxrt10xx/Makefile @@ -23,36 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -ifeq ($(BOARD),) - $(error You must provide a BOARD parameter) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- @@ -150,7 +121,6 @@ SRC_C += \ boards/$(BOARD)/board.c \ boards/$(BOARD)/flash_config.c \ boards/$(BOARD)/pins.c \ - fatfs_port.c \ lib/tinyusb/src/portable/chipidea/ci_hs/dcd_ci_hs.c \ mphalport.c \ peripherals/mimxrt10xx/$(CHIP_FAMILY)/clocks.c \ diff --git a/ports/mimxrt10xx/fatfs_port.c b/ports/mimxrt10xx/fatfs_port.c deleted file mode 100644 index 58a0ef0d72..0000000000 --- a/ports/mimxrt10xx/fatfs_port.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George - * - * 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/mphal.h" -#include "py/runtime.h" -#include "lib/oofatfs/ff.h" /* FatFs lower layer API */ -#include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "shared/timeutils/timeutils.h" - -#if CIRCUITPY_RTC -#include "shared-bindings/rtc/RTC.h" -#endif - -DWORD get_fattime(void) { - #if CIRCUITPY_RTC - timeutils_struct_time_t tm; - common_hal_rtc_get_time(&tm); - return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) | - (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); - #else - return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2); - #endif - - -} diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index bbe102ffc8..d1b71799bf 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -22,42 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -ifeq ($(BOARD),) - $(info You must provide a BOARD parameter with 'BOARD=') - $(info Possible values are:) - $(info $(sort $(subst /.,,$(subst boards/,,$(wildcard boards/*/.))))) - $(error BOARD not defined) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - -CLI_SD := $(SD) -SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]') - -# Build directory with SD if it's different from the default. -BUILD ?= $(if $(CLI_SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD)) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk ifneq ($(SD), ) include bluetooth/bluetooth_common.mk @@ -165,7 +130,6 @@ endif SRC_C += \ background.c \ - fatfs_port.c \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \ diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index 85a5ce0e6f..d72d59bcf6 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -22,36 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -ifeq ($(BOARD),) - $(error You must provide a BOARD parameter) -else - ifeq ($(wildcard boards/$(BOARD)/.),) - $(error Invalid BOARD specified) - endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- @@ -78,6 +49,7 @@ SRC_LWIP := \ shared/netutils/netutils.c \ shared/netutils/trace.c \ shared/netutils/dhcpserver.c \ + $(wildcard lib/lwip/src/apps/mdns/*.c) \ $(wildcard lib/lwip/src/core/*.c) \ $(wildcard lib/lwip/src/core/ipv4/*.c) \ lib/lwip/src/netif/ethernet.c \ @@ -213,13 +185,15 @@ CFLAGS += \ -msoft-float \ -mfloat-abi=soft -PICO_LDFLAGS = --specs=nosys.specs -Wl,--wrap=__aeabi_ldiv0 -Wl,--wrap=__aeabi_idiv0 -Wl,--wrap=__aeabi_lmul -Wl,--wrap=__clzsi2 -Wl,--wrap=__clzdi2 -Wl,--wrap=__ctzsi2 -Wl,--wrap=__ctzdi2 -Wl,--wrap=__popcountsi2 -Wl,--wrap=__popcountdi2 -Wl,--wrap=__clz -Wl,--wrap=__clzl -Wl,--wrap=__clzll -Wl,--wrap=__aeabi_idiv -Wl,--wrap=__aeabi_idivmod -Wl,--wrap=__aeabi_ldivmod -Wl,--wrap=__aeabi_uidiv -Wl,--wrap=__aeabi_uidivmod -Wl,--wrap=__aeabi_uldivmod -Wl,--wrap=__aeabi_dadd -Wl,--wrap=__aeabi_ddiv -Wl,--wrap=__aeabi_dmul -Wl,--wrap=__aeabi_drsub -Wl,--wrap=__aeabi_dsub -Wl,--wrap=__aeabi_cdcmpeq -Wl,--wrap=__aeabi_cdrcmple -Wl,--wrap=__aeabi_cdcmple -Wl,--wrap=__aeabi_dcmpeq -Wl,--wrap=__aeabi_dcmplt -Wl,--wrap=__aeabi_dcmple -Wl,--wrap=__aeabi_dcmpge -Wl,--wrap=__aeabi_dcmpgt -Wl,--wrap=__aeabi_dcmpun -Wl,--wrap=__aeabi_i2d -Wl,--wrap=__aeabi_l2d -Wl,--wrap=__aeabi_ui2d -Wl,--wrap=__aeabi_ul2d -Wl,--wrap=__aeabi_d2iz -Wl,--wrap=__aeabi_d2lz -Wl,--wrap=__aeabi_d2uiz -Wl,--wrap=__aeabi_d2ulz -Wl,--wrap=__aeabi_d2f -Wl,--wrap=sqrt -Wl,--wrap=cos -Wl,--wrap=sin -Wl,--wrap=tan -Wl,--wrap=atan2 -Wl,--wrap=exp -Wl,--wrap=log -Wl,--wrap=ldexp -Wl,--wrap=copysign -Wl,--wrap=trunc -Wl,--wrap=floor -Wl,--wrap=ceil -Wl,--wrap=round -Wl,--wrap=sincos -Wl,--wrap=asin -Wl,--wrap=acos -Wl,--wrap=atan -Wl,--wrap=sinh -Wl,--wrap=cosh -Wl,--wrap=tanh -Wl,--wrap=asinh -Wl,--wrap=acosh -Wl,--wrap=atanh -Wl,--wrap=exp2 -Wl,--wrap=log2 -Wl,--wrap=exp10 -Wl,--wrap=log10 -Wl,--wrap=pow -Wl,--wrap=powint -Wl,--wrap=hypot -Wl,--wrap=cbrt -Wl,--wrap=fmod -Wl,--wrap=drem -Wl,--wrap=remainder -Wl,--wrap=remquo -Wl,--wrap=expm1 -Wl,--wrap=log1p -Wl,--wrap=fma -Wl,--wrap=__aeabi_fadd -Wl,--wrap=__aeabi_fdiv -Wl,--wrap=__aeabi_fmul -Wl,--wrap=__aeabi_frsub -Wl,--wrap=__aeabi_fsub -Wl,--wrap=__aeabi_cfcmpeq -Wl,--wrap=__aeabi_cfrcmple -Wl,--wrap=__aeabi_cfcmple -Wl,--wrap=__aeabi_fcmpeq -Wl,--wrap=__aeabi_fcmplt -Wl,--wrap=__aeabi_fcmple -Wl,--wrap=__aeabi_fcmpge -Wl,--wrap=__aeabi_fcmpgt -Wl,--wrap=__aeabi_fcmpun -Wl,--wrap=__aeabi_i2f -Wl,--wrap=__aeabi_l2f -Wl,--wrap=__aeabi_ui2f -Wl,--wrap=__aeabi_ul2f -Wl,--wrap=__aeabi_f2iz -Wl,--wrap=__aeabi_f2lz -Wl,--wrap=__aeabi_f2uiz -Wl,--wrap=__aeabi_f2ulz -Wl,--wrap=__aeabi_f2d -Wl,--wrap=sqrtf -Wl,--wrap=cosf -Wl,--wrap=sinf -Wl,--wrap=tanf -Wl,--wrap=atan2f -Wl,--wrap=expf -Wl,--wrap=logf -Wl,--wrap=ldexpf -Wl,--wrap=copysignf -Wl,--wrap=truncf -Wl,--wrap=floorf -Wl,--wrap=ceilf -Wl,--wrap=roundf -Wl,--wrap=sincosf -Wl,--wrap=asinf -Wl,--wrap=acosf -Wl,--wrap=atanf -Wl,--wrap=sinhf -Wl,--wrap=coshf -Wl,--wrap=tanhf -Wl,--wrap=asinhf -Wl,--wrap=acoshf -Wl,--wrap=atanhf -Wl,--wrap=exp2f -Wl,--wrap=log2f -Wl,--wrap=exp10f -Wl,--wrap=log10f -Wl,--wrap=powf -Wl,--wrap=powintf -Wl,--wrap=hypotf -Wl,--wrap=cbrtf -Wl,--wrap=fmodf -Wl,--wrap=dremf -Wl,--wrap=remainderf -Wl,--wrap=remquof -Wl,--wrap=expm1f -Wl,--wrap=log1pf -Wl,--wrap=fmaf -Wl,--wrap=memcpy -Wl,--wrap=memset -Wl,--wrap=__aeabi_memcpy -Wl,--wrap=__aeabi_memset -Wl,--wrap=__aeabi_memcpy4 -Wl,--wrap=__aeabi_memset4 -Wl,--wrap=__aeabi_memcpy8 -Wl,--wrap=__aeabi_memset8 +PICO_LDFLAGS = --specs=nosys.specs --specs=nano.specs -Wl,--wrap=__aeabi_ldiv0 -Wl,--wrap=__aeabi_idiv0 -Wl,--wrap=__aeabi_lmul -Wl,--wrap=__clzsi2 -Wl,--wrap=__clzdi2 -Wl,--wrap=__ctzsi2 -Wl,--wrap=__ctzdi2 -Wl,--wrap=__popcountsi2 -Wl,--wrap=__popcountdi2 -Wl,--wrap=__clz -Wl,--wrap=__clzl -Wl,--wrap=__clzll -Wl,--wrap=__aeabi_idiv -Wl,--wrap=__aeabi_idivmod -Wl,--wrap=__aeabi_ldivmod -Wl,--wrap=__aeabi_uidiv -Wl,--wrap=__aeabi_uidivmod -Wl,--wrap=__aeabi_uldivmod -Wl,--wrap=__aeabi_dadd -Wl,--wrap=__aeabi_ddiv -Wl,--wrap=__aeabi_dmul -Wl,--wrap=__aeabi_drsub -Wl,--wrap=__aeabi_dsub -Wl,--wrap=__aeabi_cdcmpeq -Wl,--wrap=__aeabi_cdrcmple -Wl,--wrap=__aeabi_cdcmple -Wl,--wrap=__aeabi_dcmpeq -Wl,--wrap=__aeabi_dcmplt -Wl,--wrap=__aeabi_dcmple -Wl,--wrap=__aeabi_dcmpge -Wl,--wrap=__aeabi_dcmpgt -Wl,--wrap=__aeabi_dcmpun -Wl,--wrap=__aeabi_i2d -Wl,--wrap=__aeabi_l2d -Wl,--wrap=__aeabi_ui2d -Wl,--wrap=__aeabi_ul2d -Wl,--wrap=__aeabi_d2iz -Wl,--wrap=__aeabi_d2lz -Wl,--wrap=__aeabi_d2uiz -Wl,--wrap=__aeabi_d2ulz -Wl,--wrap=__aeabi_d2f -Wl,--wrap=sqrt -Wl,--wrap=cos -Wl,--wrap=sin -Wl,--wrap=tan -Wl,--wrap=atan2 -Wl,--wrap=exp -Wl,--wrap=log -Wl,--wrap=ldexp -Wl,--wrap=copysign -Wl,--wrap=trunc -Wl,--wrap=floor -Wl,--wrap=ceil -Wl,--wrap=round -Wl,--wrap=sincos -Wl,--wrap=asin -Wl,--wrap=acos -Wl,--wrap=atan -Wl,--wrap=sinh -Wl,--wrap=cosh -Wl,--wrap=tanh -Wl,--wrap=asinh -Wl,--wrap=acosh -Wl,--wrap=atanh -Wl,--wrap=exp2 -Wl,--wrap=log2 -Wl,--wrap=exp10 -Wl,--wrap=log10 -Wl,--wrap=pow -Wl,--wrap=powint -Wl,--wrap=hypot -Wl,--wrap=cbrt -Wl,--wrap=fmod -Wl,--wrap=drem -Wl,--wrap=remainder -Wl,--wrap=remquo -Wl,--wrap=expm1 -Wl,--wrap=log1p -Wl,--wrap=fma -Wl,--wrap=__aeabi_fadd -Wl,--wrap=__aeabi_fdiv -Wl,--wrap=__aeabi_fmul -Wl,--wrap=__aeabi_frsub -Wl,--wrap=__aeabi_fsub -Wl,--wrap=__aeabi_cfcmpeq -Wl,--wrap=__aeabi_cfrcmple -Wl,--wrap=__aeabi_cfcmple -Wl,--wrap=__aeabi_fcmpeq -Wl,--wrap=__aeabi_fcmplt -Wl,--wrap=__aeabi_fcmple -Wl,--wrap=__aeabi_fcmpge -Wl,--wrap=__aeabi_fcmpgt -Wl,--wrap=__aeabi_fcmpun -Wl,--wrap=__aeabi_i2f -Wl,--wrap=__aeabi_l2f -Wl,--wrap=__aeabi_ui2f -Wl,--wrap=__aeabi_ul2f -Wl,--wrap=__aeabi_f2iz -Wl,--wrap=__aeabi_f2lz -Wl,--wrap=__aeabi_f2uiz -Wl,--wrap=__aeabi_f2ulz -Wl,--wrap=__aeabi_f2d -Wl,--wrap=sqrtf -Wl,--wrap=cosf -Wl,--wrap=sinf -Wl,--wrap=tanf -Wl,--wrap=atan2f -Wl,--wrap=expf -Wl,--wrap=logf -Wl,--wrap=ldexpf -Wl,--wrap=copysignf -Wl,--wrap=truncf -Wl,--wrap=floorf -Wl,--wrap=ceilf -Wl,--wrap=roundf -Wl,--wrap=sincosf -Wl,--wrap=asinf -Wl,--wrap=acosf -Wl,--wrap=atanf -Wl,--wrap=sinhf -Wl,--wrap=coshf -Wl,--wrap=tanhf -Wl,--wrap=asinhf -Wl,--wrap=acoshf -Wl,--wrap=atanhf -Wl,--wrap=exp2f -Wl,--wrap=log2f -Wl,--wrap=exp10f -Wl,--wrap=log10f -Wl,--wrap=powf -Wl,--wrap=powintf -Wl,--wrap=hypotf -Wl,--wrap=cbrtf -Wl,--wrap=fmodf -Wl,--wrap=dremf -Wl,--wrap=remainderf -Wl,--wrap=remquof -Wl,--wrap=expm1f -Wl,--wrap=log1pf -Wl,--wrap=fmaf -Wl,--wrap=memcpy -Wl,--wrap=memset -Wl,--wrap=__aeabi_memcpy -Wl,--wrap=__aeabi_memset -Wl,--wrap=__aeabi_memcpy4 -Wl,--wrap=__aeabi_memset4 -Wl,--wrap=__aeabi_memcpy8 -Wl,--wrap=__aeabi_memset8 # Use toolchain libm if we're not using our own. ifndef INTERNAL_LIBM LIBS += -lm endif +LIBS += -lc + SRC_SDK := \ src/common/pico_sync/critical_section.c \ src/common/pico_sync/lock_core.c \ @@ -272,7 +246,6 @@ SRC_C += \ background.c \ peripherals/pins.c \ lib/crypto-algorithms/sha256.c \ - fatfs_port.c \ lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c \ lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c \ mphalport.c \ @@ -443,7 +416,7 @@ $(BUILD)/firmware.elf: $(OBJ) $(LINK_LD) $(STEPECHO) "LINK $@" $(Q)echo $(OBJ) > $(BUILD)/firmware.objs $(Q)echo $(PICO_LDFLAGS) > $(BUILD)/firmware.ldflags - $(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags -Wl,-T,$(LINK_LD) -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs + $(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags -Wl,-T,$(LINK_LD) -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs -Wl,-lc $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINK_LD) $(BUILD)/firmware.bin: $(BUILD)/firmware.elf diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk index 9773755649..a050391505 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk @@ -14,8 +14,8 @@ CIRCUITPY_CYW43 = 1 CIRCUITPY_SSL = 1 CIRCUITPY_SSL_MBEDTLS = 1 CIRCUITPY_HASHLIB = 1 -CIRCUITPY_WEB_WORKFLOW = 0 -CIRCUITPY_MDNS = 0 +CIRCUITPY_WEB_WORKFLOW = 1 +CIRCUITPY_MDNS = 1 CIRCUITPY_SOCKETPOOL = 1 CIRCUITPY_WIFI = 1 diff --git a/ports/raspberrypi/common-hal/busio/SPI.c b/ports/raspberrypi/common-hal/busio/SPI.c index a7b97823f9..67323790bf 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.c +++ b/ports/raspberrypi/common-hal/busio/SPI.c @@ -151,6 +151,15 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, spi_set_format(self->peripheral, bits, polarity, phase, SPI_MSB_FIRST); + // Workaround to start with clock line high if polarity=1. The hw SPI peripheral does not do this + // automatically. See https://github.com/raspberrypi/pico-sdk/issues/868 and + // https://forums.raspberrypi.com/viewtopic.php?t=336142 + // TODO: scheduled to be be fixed in pico-sdk 1.5.0. + if (polarity) { + hw_clear_bits(&spi_get_hw(self->peripheral)->cr1, SPI_SSPCR1_SSE_BITS); // disable the SPI + hw_set_bits(&spi_get_hw(self->peripheral)->cr1, SPI_SSPCR1_SSE_BITS); // re-enable the SPI + } + self->polarity = polarity; self->phase = phase; self->bits = bits; diff --git a/ports/raspberrypi/common-hal/mdns/RemoteService.c b/ports/raspberrypi/common-hal/mdns/RemoteService.c new file mode 100644 index 0000000000..071a9c1648 --- /dev/null +++ b/ports/raspberrypi/common-hal/mdns/RemoteService.c @@ -0,0 +1,64 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 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 "shared-bindings/mdns/RemoteService.h" + +#include "shared-bindings/ipaddress/IPv4Address.h" + +const char *common_hal_mdns_remoteservice_get_service_type(mdns_remoteservice_obj_t *self) { + return self->service_name; +} + +const char *common_hal_mdns_remoteservice_get_protocol(mdns_remoteservice_obj_t *self) { + return self->protocol; +} + +const char *common_hal_mdns_remoteservice_get_instance_name(mdns_remoteservice_obj_t *self) { + return self->instance_name; +} + +const char *common_hal_mdns_remoteservice_get_hostname(mdns_remoteservice_obj_t *self) { + return self->hostname; +} + +mp_int_t common_hal_mdns_remoteservice_get_port(mdns_remoteservice_obj_t *self) { + return self->port; +} + +uint32_t mdns_remoteservice_get_ipv4_address(mdns_remoteservice_obj_t *self) { + return self->ipv4_address; +} + +mp_obj_t common_hal_mdns_remoteservice_get_ipv4_address(mdns_remoteservice_obj_t *self) { + uint32_t addr = mdns_remoteservice_get_ipv4_address(self); + if (addr == 0) { + return mp_const_none; + } + return common_hal_ipaddress_new_ipv4address(addr); +} + +void common_hal_mdns_remoteservice_deinit(mdns_remoteservice_obj_t *self) { +} diff --git a/ports/litex/fatfs_port.c b/ports/raspberrypi/common-hal/mdns/RemoteService.h similarity index 68% rename from ports/litex/fatfs_port.c rename to ports/raspberrypi/common-hal/mdns/RemoteService.h index 631f7f0982..06814f0fbb 100644 --- a/ports/litex/fatfs_port.c +++ b/ports/raspberrypi/common-hal/mdns/RemoteService.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2022 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 @@ -24,10 +24,17 @@ * THE SOFTWARE. */ -#include "py/runtime.h" -#include "lib/oofatfs/ff.h" +#pragma once -DWORD get_fattime(void) { - // TODO: Implement this function. For now, fake it. - return ((2016 - 1980) << 25) | ((12) << 21) | ((4) << 16) | ((00) << 11) | ((18) << 5) | (23 / 2); -} +#include "lwip/apps/mdns.h" + +typedef struct { + mp_obj_base_t base; + uint32_t ipv4_address; + uint16_t port; + char protocol[5]; // RFC 6763 Section 7.2 - 4 bytes + 1 for NUL + char service_name[17]; // RFC 6763 Section 7.2 - 16 bytes + 1 for NUL + char instance_name[64]; // RFC 6763 Section 7.2 - 63 bytes + 1 for NUL + char hostname[64]; // RFC 6762 Appendix A - 63 bytes for label + 1 for NUL + mp_obj_t next; +} mdns_remoteservice_obj_t; diff --git a/ports/raspberrypi/common-hal/mdns/Server.c b/ports/raspberrypi/common-hal/mdns/Server.c new file mode 100644 index 0000000000..72aedf3889 --- /dev/null +++ b/ports/raspberrypi/common-hal/mdns/Server.c @@ -0,0 +1,307 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2022 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 "shared-bindings/mdns/Server.h" + +#include "py/gc.h" +#include "py/runtime.h" +#include "shared/runtime/interrupt_char.h" +#include "shared-bindings/mdns/RemoteService.h" +#include "shared-bindings/wifi/__init__.h" +#include "supervisor/shared/tick.h" + +#include "lwip/apps/mdns.h" +#include "lwip/prot/dns.h" + +STATIC bool inited = false; + +#define NETIF_STA (&cyw43_state.netif[CYW43_ITF_STA]) +#define NETIF_AP (&cyw43_state.netif[CYW43_ITF_AP]) + +void mdns_server_construct(mdns_server_obj_t *self, bool workflow) { + if (inited) { + return; + } + + mdns_resp_init(); + inited = true; + + uint8_t mac[6]; + wifi_radio_get_mac_address(&common_hal_wifi_radio_obj, mac); + snprintf(self->default_hostname, sizeof(self->default_hostname), "cpy-%02x%02x%02x", mac[3], mac[4], mac[5]); + common_hal_mdns_server_set_hostname(self, self->default_hostname); + + if (workflow) { + // Add a second host entry to respond to "circuitpython.local" queries as well. + + #if MDNS_MAX_SECONDARY_HOSTNAMES > 0 + mdns_resp_add_secondary_hostname(NETIF_STA, "circuitpython"); + #endif + } +} + +void common_hal_mdns_server_construct(mdns_server_obj_t *self, mp_obj_t network_interface) { + if (network_interface != MP_OBJ_FROM_PTR(&common_hal_wifi_radio_obj)) { + mp_raise_ValueError(translate("mDNS only works with built-in WiFi")); + return; + } + if (inited) { + mp_raise_RuntimeError(translate("mDNS already initialized")); + } + mdns_server_construct(self, false); +} + +void common_hal_mdns_server_deinit(mdns_server_obj_t *self) { + inited = false; + mdns_resp_remove_netif(NETIF_STA); +} + +bool common_hal_mdns_server_deinited(mdns_server_obj_t *self) { + return !mdns_resp_netif_active(NETIF_STA); +} + +const char *common_hal_mdns_server_get_hostname(mdns_server_obj_t *self) { + return self->hostname; +} + +void common_hal_mdns_server_set_hostname(mdns_server_obj_t *self, const char *hostname) { + if (mdns_resp_netif_active(NETIF_STA)) { + mdns_resp_rename_netif(NETIF_STA, hostname); + } else { + mdns_resp_add_netif(NETIF_STA, hostname); + } + + self->hostname = hostname; +} + +const char *common_hal_mdns_server_get_instance_name(mdns_server_obj_t *self) { + return self->instance_name; +} + +void common_hal_mdns_server_set_instance_name(mdns_server_obj_t *self, const char *instance_name) { + self->instance_name = instance_name; +} + +typedef struct { + uint8_t request_id; + size_t i; + mdns_remoteservice_obj_t *out; + size_t out_len; +} nonalloc_search_state_t; + +STATIC void copy_data_into_remote_service(struct mdns_answer *answer, const char *varpart, int varlen, mdns_remoteservice_obj_t *out) { + if (varlen > 0) { + if (answer->info.type == DNS_RRTYPE_A) { + char *hostname = out->hostname; + size_t len = MIN(63, answer->info.domain.name[0]); + memcpy(hostname, answer->info.domain.name + 1, len); + hostname[len] = '\0'; + out->ipv4_address = varpart[0] | varpart[1] << 8 | varpart[2] << 16 | varpart[3] << 24; + } + if (answer->info.type == DNS_RRTYPE_SRV) { + // This isn't a null terminated string. Its length encoded. + uint8_t *domain = answer->info.domain.name; + char *instance_name = out->instance_name; + size_t offset = 0; + uint8_t iname_len = domain[offset++]; + size_t len = MIN(63, iname_len); + memcpy(instance_name, domain + offset, len); + offset += iname_len; + instance_name[len] = '\0'; + + uint8_t sn_len = domain[offset++]; + char *service_name = out->service_name; + len = MIN(16, sn_len); + memcpy(service_name, domain + offset, len); + offset += sn_len; + service_name[len] = '\0'; + + uint8_t proto_len = domain[offset++]; + char *protocol = out->protocol; + len = MIN(4, proto_len); + memcpy(protocol, domain + offset, len); + offset += proto_len; + protocol[len] = '\0'; + + out->port = varpart[4] << 8 | varpart[5]; + } + } +} + +STATIC void search_result_cb(struct mdns_answer *answer, const char *varpart, int varlen, int flags, void *arg) { + nonalloc_search_state_t *state = arg; + state->out[state->i].base.type = &mdns_remoteservice_type; + + copy_data_into_remote_service(answer, varpart, varlen, &state->out[state->i]); + + if ((flags & MDNS_SEARCH_RESULT_LAST) != 0) { + state->i += 1; + } + + if (state->i == state->out_len) { + mdns_search_stop(state->request_id); + state->request_id = MDNS_MAX_REQUESTS; + } +} + +size_t mdns_server_find(mdns_server_obj_t *self, const char *service_type, const char *protocol, + mp_float_t timeout, mdns_remoteservice_obj_t *out, size_t out_len) { + + enum mdns_sd_proto proto = DNSSD_PROTO_UDP; + if (strcmp(protocol, "_tcp") == 0) { + proto = DNSSD_PROTO_TCP; + } + + nonalloc_search_state_t state; + state.i = 0; + state.out = out; + state.out_len = out_len; + + err_t err = mdns_search_service(NULL, service_type, proto, + NETIF_STA, &search_result_cb, &state, + &state.request_id); + if (err != ERR_OK) { + return 0; + } + + uint64_t start_ticks = supervisor_ticks_ms64(); + uint64_t timeout_ms = timeout * 1000; + + while (state.request_id < MDNS_MAX_REQUESTS && + !mp_hal_is_interrupted() && + supervisor_ticks_ms64() - start_ticks < timeout_ms) { + RUN_BACKGROUND_TASKS; + } + if (state.request_id < MDNS_MAX_REQUESTS) { + mdns_search_stop(state.request_id); + state.request_id = MDNS_MAX_REQUESTS; + } + + return state.i; +} + +typedef struct { + uint8_t request_id; + mdns_remoteservice_obj_t *head; + size_t count; +} alloc_search_state_t; + +STATIC void alloc_search_result_cb(struct mdns_answer *answer, const char *varpart, int varlen, int flags, void *arg) { + alloc_search_state_t *state = arg; + + if ((flags & MDNS_SEARCH_RESULT_FIRST) != 0) { + // first + mdns_remoteservice_obj_t *service = gc_alloc(sizeof(mdns_remoteservice_obj_t), 0, false); + mp_printf(&mp_plat_print, "found service %p\n", service); + if (service == NULL) { + // alloc fails + mdns_search_stop(state->request_id); + state->request_id = MDNS_MAX_REQUESTS; + if (state->count == 0) { + m_malloc_fail(sizeof(mdns_remoteservice_obj_t)); + } + return; + } + service->base.type = &mdns_remoteservice_type; + state->count++; + service->next = state->head; + state->head = service; + } + + copy_data_into_remote_service(answer, varpart, varlen, state->head); +} + +mp_obj_t common_hal_mdns_server_find(mdns_server_obj_t *self, const char *service_type, const char *protocol, mp_float_t timeout) { + enum mdns_sd_proto proto = DNSSD_PROTO_UDP; + if (strcmp(protocol, "_tcp") == 0) { + proto = DNSSD_PROTO_TCP; + } + + alloc_search_state_t state; + state.count = 0; + state.head = NULL; + + err_t err = mdns_search_service(NULL, service_type, proto, + NETIF_STA, &alloc_search_result_cb, &state, + &state.request_id); + if (err != ERR_OK) { + mp_raise_RuntimeError(translate("Unable to start mDNS query")); + } + + uint64_t start_ticks = supervisor_ticks_ms64(); + uint64_t timeout_ms = timeout * 1000; + + while (state.request_id < MDNS_MAX_REQUESTS && + !mp_hal_is_interrupted() && + supervisor_ticks_ms64() - start_ticks < timeout_ms) { + RUN_BACKGROUND_TASKS; + } + if (state.request_id < MDNS_MAX_REQUESTS) { + mdns_search_stop(state.request_id); + state.request_id = MDNS_MAX_REQUESTS; + } + + mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(state.count, NULL)); + mdns_remoteservice_obj_t *next = state.head; + uint8_t added = 0; + while (next != NULL) { + mdns_remoteservice_obj_t *cur = next; + tuple->items[added] = MP_OBJ_FROM_PTR(cur); + next = cur->next; + // Set next back to NULL so that each service object is independently + // tracked for GC. + cur->next = NULL; + added++; + } + + return MP_OBJ_FROM_PTR(tuple); +} + +void common_hal_mdns_server_advertise_service(mdns_server_obj_t *self, const char *service_type, const char *protocol, mp_int_t port) { + enum mdns_sd_proto proto = DNSSD_PROTO_UDP; + if (strcmp(protocol, "_tcp") == 0) { + proto = DNSSD_PROTO_TCP; + } + // Remove the existing service if it was already added. + int8_t existing_slot = MDNS_MAX_SERVICES; + for (int i = 0; i < MDNS_MAX_SERVICES; i++) { + if (self->service_type[i] != NULL && + (service_type == self->service_type[i] || + strcmp(service_type, self->service_type[i]) == 0)) { + existing_slot = i; + break; + } + } + if (existing_slot < MDNS_MAX_SERVICES) { + mdns_resp_del_service(NETIF_STA, existing_slot); + } + int8_t slot = mdns_resp_add_service(NETIF_STA, self->instance_name, service_type, proto, port, NULL, NULL); + if (slot < 0) { + mp_raise_RuntimeError(translate("Out of MDNS service slots")); + return; + } + self->service_type[slot] = service_type; +} diff --git a/ports/stm/fatfs_port.c b/ports/raspberrypi/common-hal/mdns/Server.h similarity index 76% rename from ports/stm/fatfs_port.c rename to ports/raspberrypi/common-hal/mdns/Server.h index 631f7f0982..8f28d74d3c 100644 --- a/ports/stm/fatfs_port.c +++ b/ports/raspberrypi/common-hal/mdns/Server.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2022 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 @@ -24,10 +24,17 @@ * THE SOFTWARE. */ -#include "py/runtime.h" -#include "lib/oofatfs/ff.h" +#pragma once -DWORD get_fattime(void) { - // TODO: Implement this function. For now, fake it. - return ((2016 - 1980) << 25) | ((12) << 21) | ((4) << 16) | ((00) << 11) | ((18) << 5) | (23 / 2); -} +#include "py/obj.h" + +#include "lwip/apps/mdns_opts.h" + +typedef struct { + mp_obj_base_t base; + const char *hostname; + const char *instance_name; + // "cpy-" "XXXXXX" "\0" + char default_hostname[4 + 6 + 1]; + const char *service_type[MDNS_MAX_SERVICES]; +} mdns_server_obj_t; diff --git a/ports/raspberrypi/common-hal/mdns/__init__.c b/ports/raspberrypi/common-hal/mdns/__init__.c new file mode 100644 index 0000000000..57740777c8 --- /dev/null +++ b/ports/raspberrypi/common-hal/mdns/__init__.c @@ -0,0 +1 @@ +// No mdns module functions. diff --git a/ports/raspberrypi/common-hal/socketpool/Socket.c b/ports/raspberrypi/common-hal/socketpool/Socket.c index 440fe56d42..be3f2cd087 100644 --- a/ports/raspberrypi/common-hal/socketpool/Socket.c +++ b/ports/raspberrypi/common-hal/socketpool/Socket.c @@ -166,6 +166,7 @@ static inline void exec_user_callback(socketpool_socket_obj_t *socket) { mp_sched_schedule(socket->callback, MP_OBJ_FROM_PTR(socket)); } #endif + supervisor_workflow_request_background(); } #if MICROPY_PY_LWIP_SOCK_RAW @@ -745,57 +746,47 @@ socketpool_socket_obj_t *common_hal_socketpool_socket(socketpool_socketpool_obj_ return socket; } -int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_t *port) { - return -MP_EBADF; -} - -socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_obj_t *socket, - uint8_t *ip, uint32_t *port) { - if (socket->type != MOD_NETWORK_SOCK_STREAM) { - mp_raise_OSError(MP_EOPNOTSUPP); +int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_t *port, socketpool_socket_obj_t *accepted) { + if (self->type != MOD_NETWORK_SOCK_STREAM) { + return -MP_EOPNOTSUPP; } - // Create new socket object, do it here because we must not raise an out-of-memory - // exception when the LWIP concurrency lock is held - socketpool_socket_obj_t *socket2 = m_new_ll_obj_with_finaliser(socketpool_socket_obj_t); - socket2->base.type = &socketpool_socket_type; + if (common_hal_socketpool_socket_get_closed(self)) { + return -MP_EBADF; + } MICROPY_PY_LWIP_ENTER - if (socket->pcb.tcp == NULL) { + if (self->pcb.tcp == NULL) { MICROPY_PY_LWIP_EXIT - m_del_obj(socketpool_socket_obj_t, socket2); - mp_raise_OSError(MP_EBADF); + return -MP_EBADF; } // I need to do this because "tcp_accepted", later, is a macro. - struct tcp_pcb *listener = socket->pcb.tcp; + struct tcp_pcb *listener = self->pcb.tcp; if (listener->state != LISTEN) { MICROPY_PY_LWIP_EXIT - m_del_obj(socketpool_socket_obj_t, socket2); - mp_raise_OSError(MP_EINVAL); + return -MP_EINVAL; } // accept incoming connection - struct tcp_pcb *volatile *incoming_connection = &lwip_socket_incoming_array(socket)[socket->incoming.connection.iget]; + struct tcp_pcb *volatile *incoming_connection = &lwip_socket_incoming_array(self)[self->incoming.connection.iget]; if (*incoming_connection == NULL) { - if (socket->timeout == 0) { + if (self->timeout == 0) { MICROPY_PY_LWIP_EXIT - m_del_obj(socketpool_socket_obj_t, socket2); - mp_raise_OSError(MP_EAGAIN); - } else if (socket->timeout != (unsigned)-1) { - mp_uint_t retries = socket->timeout / 100; - while (*incoming_connection == NULL) { + return -MP_EAGAIN; + } else if (self->timeout != (unsigned)-1) { + mp_uint_t retries = self->timeout / 100; + while (*incoming_connection == NULL && !mp_hal_is_interrupted()) { MICROPY_PY_LWIP_EXIT if (retries-- == 0) { - m_del_obj(socketpool_socket_obj_t, socket2); - mp_raise_OSError(MP_ETIMEDOUT); + return -MP_ETIMEDOUT; } mp_hal_delay_ms(100); MICROPY_PY_LWIP_REENTER } } else { - while (*incoming_connection == NULL) { + while (*incoming_connection == NULL && !mp_hal_is_interrupted()) { MICROPY_PY_LWIP_EXIT poll_sockets(); MICROPY_PY_LWIP_REENTER @@ -803,43 +794,75 @@ socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_o } } + if (*incoming_connection == NULL) { + // We were interrupted. + return 0; + } + + // Close the accepted socket because we have another we accepted. + if (!common_hal_socketpool_socket_get_closed(accepted)) { + common_hal_socketpool_socket_close(accepted); + } + // We get a new pcb handle... - socket2->pcb.tcp = *incoming_connection; - if (++socket->incoming.connection.iget >= socket->incoming.connection.alloc) { - socket->incoming.connection.iget = 0; + accepted->pcb.tcp = *incoming_connection; + if (++self->incoming.connection.iget >= self->incoming.connection.alloc) { + self->incoming.connection.iget = 0; } *incoming_connection = NULL; // ...and set up the new socket for it. - socket2->domain = MOD_NETWORK_AF_INET; - socket2->type = MOD_NETWORK_SOCK_STREAM; - socket2->incoming.pbuf = NULL; - socket2->timeout = socket->timeout; - socket2->state = STATE_CONNECTED; - socket2->recv_offset = 0; - socket2->callback = MP_OBJ_NULL; - tcp_arg(socket2->pcb.tcp, (void *)socket2); - tcp_err(socket2->pcb.tcp, _lwip_tcp_error); - tcp_recv(socket2->pcb.tcp, _lwip_tcp_recv); + accepted->domain = MOD_NETWORK_AF_INET; + accepted->type = MOD_NETWORK_SOCK_STREAM; + accepted->incoming.pbuf = NULL; + accepted->timeout = self->timeout; + accepted->state = STATE_CONNECTED; + accepted->recv_offset = 0; + accepted->callback = MP_OBJ_NULL; + tcp_arg(accepted->pcb.tcp, (void *)accepted); + tcp_err(accepted->pcb.tcp, _lwip_tcp_error); + tcp_recv(accepted->pcb.tcp, _lwip_tcp_recv); tcp_accepted(listener); MICROPY_PY_LWIP_EXIT + // output values + memcpy(ip, &(accepted->pcb.tcp->remote_ip), NETUTILS_IPV4ADDR_BUFSIZE); + *port = (mp_uint_t)accepted->pcb.tcp->remote_port; + + return 1; +} + +socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_obj_t *socket, + uint8_t *ip, uint32_t *port) { + // Create new socket object, do it here because we must not raise an out-of-memory + // exception when the LWIP concurrency lock is held + socketpool_socket_obj_t *accepted = m_new_ll_obj_with_finaliser(socketpool_socket_obj_t); + socketpool_socket_reset(accepted); + + int ret = socketpool_socket_accept(socket, ip, port, accepted); + + if (ret <= 0) { + m_del_obj(socketpool_socket_obj_t, accepted); + if (ret == 0) { + // Interrupted. + return mp_const_none; + } + mp_raise_OSError(-ret); + } + DEBUG_printf("registering socket in socketpool_socket_accept()\n"); - if (!register_open_socket(socket2)) { + if (!register_open_socket(accepted)) { DEBUG_printf("collecting garbage to open socket\n"); gc_collect(); - if (!register_open_socket(socket2)) { + if (!register_open_socket(accepted)) { mp_raise_RuntimeError(translate("Out of sockets")); } } - mark_user_socket(socket2); + mark_user_socket(accepted); - // output values - memcpy(ip, &(socket2->pcb.tcp->remote_ip), NETUTILS_IPV4ADDR_BUFSIZE); - *port = (mp_uint_t)socket2->pcb.tcp->remote_port; - return MP_OBJ_FROM_PTR(socket2); + return MP_OBJ_FROM_PTR(accepted); } bool common_hal_socketpool_socket_bind(socketpool_socket_obj_t *socket, @@ -847,21 +870,26 @@ bool common_hal_socketpool_socket_bind(socketpool_socket_obj_t *socket, // get address ip_addr_t bind_addr; - int error = socketpool_resolve_host(socket->pool, host, &bind_addr); - if (error != 0) { - mp_raise_OSError(EHOSTUNREACH); - } + const ip_addr_t *bind_addr_ptr = &bind_addr; + if (hostlen > 0) { + int error = socketpool_resolve_host(socket->pool, host, &bind_addr); + if (error != 0) { + mp_raise_OSError(EHOSTUNREACH); + } + } else { + bind_addr_ptr = IP_ANY_TYPE; + } ip_set_option(socket->pcb.ip, SOF_REUSEADDR); err_t err = ERR_ARG; switch (socket->type) { case MOD_NETWORK_SOCK_STREAM: { - err = tcp_bind(socket->pcb.tcp, &bind_addr, port); + err = tcp_bind(socket->pcb.tcp, bind_addr_ptr, port); break; } case MOD_NETWORK_SOCK_DGRAM: { - err = udp_bind(socket->pcb.udp, &bind_addr, port); + err = udp_bind(socket->pcb.udp, bind_addr_ptr, port); break; } } @@ -1164,6 +1192,20 @@ void common_hal_socketpool_socket_settimeout(socketpool_socket_obj_t *self, uint self->timeout = timeout_ms; } +int common_hal_socketpool_socket_setsockopt(socketpool_socket_obj_t *self, int level, int optname, const void *value, size_t optlen) { + if (level == SOCKETPOOL_IPPROTO_TCP && optname == SOCKETPOOL_TCP_NODELAY) { + int one = 1; + bool enable = optlen == sizeof(&one) && memcmp(value, &one, optlen); + if (enable) { + tcp_set_flags(self->pcb.tcp, TF_NODELAY); + } else { + tcp_clear_flags(self->pcb.tcp, TF_NODELAY); + } + return 0; + } + return -MP_EOPNOTSUPP; +} + bool common_hal_socketpool_readable(socketpool_socket_obj_t *self) { MICROPY_PY_LWIP_ENTER; @@ -1206,3 +1248,32 @@ bool common_hal_socketpool_writable(socketpool_socket_obj_t *self) { return result; } + +void socketpool_socket_move(socketpool_socket_obj_t *self, socketpool_socket_obj_t *sock) { + *sock = *self; + self->state = _ERR_BADF; + + // Reregister the callbacks with the new socket copy. + MICROPY_PY_LWIP_ENTER; + + tcp_arg(self->pcb.tcp, NULL); + tcp_err(self->pcb.tcp, NULL); + tcp_recv(self->pcb.tcp, NULL); + + self->pcb.tcp = NULL; + + tcp_arg(sock->pcb.tcp, (void *)sock); + tcp_err(sock->pcb.tcp, _lwip_tcp_error); + tcp_recv(sock->pcb.tcp, _lwip_tcp_recv); + + MICROPY_PY_LWIP_EXIT; +} + +void socketpool_socket_reset(socketpool_socket_obj_t *self) { + if (self->base.type == &socketpool_socket_type) { + return; + } + self->base.type = &socketpool_socket_type; + self->pcb.tcp = NULL; + self->state = _ERR_BADF; +} diff --git a/ports/raspberrypi/common-hal/wifi/Network.c b/ports/raspberrypi/common-hal/wifi/Network.c index 8db42e962c..e9b64ffd2c 100644 --- a/ports/raspberrypi/common-hal/wifi/Network.c +++ b/ports/raspberrypi/common-hal/wifi/Network.c @@ -55,18 +55,18 @@ mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) { mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) { uint8_t authmode_mask = 0; if (self->record.auth_mode == 0) { - authmode_mask = (1 << AUTHMODE_OPEN); + authmode_mask = AUTHMODE_OPEN; } if (self->record.auth_mode & 1) { - authmode_mask |= (1 << AUTHMODE_PSK); + authmode_mask |= AUTHMODE_PSK; } ; if (self->record.auth_mode & 2) { - authmode_mask |= (1 << AUTHMODE_WPA); + authmode_mask |= AUTHMODE_WPA; } ; if (self->record.auth_mode & 4) { - authmode_mask |= (1 << AUTHMODE_WPA2); + authmode_mask |= AUTHMODE_WPA2; } ; mp_obj_t authmode_list = mp_obj_new_list(0, NULL); diff --git a/ports/raspberrypi/common-hal/wifi/Radio.c b/ports/raspberrypi/common-hal/wifi/Radio.c index 55b9fc7b95..fcedcb2ce2 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.c +++ b/ports/raspberrypi/common-hal/wifi/Radio.c @@ -42,10 +42,6 @@ #include "shared-bindings/time/__init__.h" #include "shared-module/ipaddress/__init__.h" -#if CIRCUITPY_MDNS -#include "components/mdns/include/mdns.h" -#endif - #include "lwip/sys.h" #include "lwip/dns.h" #include "lwip/icmp.h" @@ -73,13 +69,12 @@ NORETURN static void ro_attribute(int attr) { } bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) { - return true; + return self->enabled; } void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) { - if (!enabled) { - ro_attribute(MP_QSTR_enabled); - } + self->enabled = enabled; + // TODO: Actually enable and disable the WiFi module at this point. } mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self) { @@ -96,6 +91,10 @@ void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *host netif_set_hostname(NETIF_AP, self->hostname); } +void wifi_radio_get_mac_address(wifi_radio_obj_t *self, uint8_t *mac) { + memcpy(mac, cyw43_state.mac, MAC_ADDRESS_LENGTH); +} + mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) { return mp_obj_new_bytes(cyw43_state.mac, MAC_ADDRESS_LENGTH); } @@ -282,6 +281,13 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self) { return common_hal_ipaddress_new_ipv4address(NETIF_AP->netmask.addr); } +uint32_t wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) { + if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_STA) != CYW43_LINK_UP) { + return 0; + } + return NETIF_STA->ip_addr.addr; +} + mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) { if (cyw43_tcpip_link_status(&cyw43_state, CYW43_ITF_STA) != CYW43_LINK_UP) { return mp_const_none; diff --git a/ports/raspberrypi/common-hal/wifi/Radio.h b/ports/raspberrypi/common-hal/wifi/Radio.h index 0dc18c8957..b2e9df9e3a 100644 --- a/ports/raspberrypi/common-hal/wifi/Radio.h +++ b/ports/raspberrypi/common-hal/wifi/Radio.h @@ -35,6 +35,7 @@ typedef struct { mp_obj_base_t base; char hostname[254]; // hostname max is 253 chars, + 1 for trailing NUL wifi_scannednetworks_obj_t *current_scan; + bool enabled; } wifi_radio_obj_t; extern void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self); diff --git a/ports/raspberrypi/fatfs_port.c b/ports/raspberrypi/fatfs_port.c deleted file mode 100644 index 58a0ef0d72..0000000000 --- a/ports/raspberrypi/fatfs_port.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George - * - * 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/mphal.h" -#include "py/runtime.h" -#include "lib/oofatfs/ff.h" /* FatFs lower layer API */ -#include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "shared/timeutils/timeutils.h" - -#if CIRCUITPY_RTC -#include "shared-bindings/rtc/RTC.h" -#endif - -DWORD get_fattime(void) { - #if CIRCUITPY_RTC - timeutils_struct_time_t tm; - common_hal_rtc_get_time(&tm); - return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) | - (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1); - #else - return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2); - #endif - - -} diff --git a/ports/raspberrypi/lib/cyw43-driver b/ports/raspberrypi/lib/cyw43-driver index 195dfcc10b..746e063603 160000 --- a/ports/raspberrypi/lib/cyw43-driver +++ b/ports/raspberrypi/lib/cyw43-driver @@ -1 +1 @@ -Subproject commit 195dfcc10bb6f379e3dea45147590db2203d3c7b +Subproject commit 746e0636033d0550b7652688124a77a6a1639cf9 diff --git a/ports/raspberrypi/lib/lwip b/ports/raspberrypi/lib/lwip index 239918ccc1..d26459c32c 160000 --- a/ports/raspberrypi/lib/lwip +++ b/ports/raspberrypi/lib/lwip @@ -1 +1 @@ -Subproject commit 239918ccc173cb2c2a62f41a40fd893f57faf1d6 +Subproject commit d26459c32c83aa14a6d4e30237d91cee36e0adbd diff --git a/ports/raspberrypi/lwip_inc/lwipopts.h b/ports/raspberrypi/lwip_inc/lwipopts.h index 0d4ecd3707..6d116e89b6 100644 --- a/ports/raspberrypi/lwip_inc/lwipopts.h +++ b/ports/raspberrypi/lwip_inc/lwipopts.h @@ -54,6 +54,14 @@ #define LWIP_DHCP_DOES_ACD_CHECK 0 #define SO_REUSE 1 +#if CIRCUITPY_MDNS +#define LWIP_IGMP 1 +#define LWIP_MDNS_RESPONDER 1 +#define LWIP_NUM_NETIF_CLIENT_DATA 1 +#define LWIP_NETIF_EXT_STATUS_CALLBACK 1 +#define MDNS_MAX_SECONDARY_HOSTNAMES 1 +#endif + #ifndef NDEBUG #define LWIP_DEBUG 1 #define LWIP_STATS 1 @@ -88,6 +96,7 @@ #define PPP_DEBUG LWIP_DBG_OFF #define SLIP_DEBUG LWIP_DBG_OFF #define DHCP_DEBUG LWIP_DBG_OFF +#define MDNS_DEBUG LWIP_DBG_OFF #define LWIP_TIMEVAL_PRIVATE 0 diff --git a/ports/stm/Makefile b/ports/stm/Makefile index cd37a9bda0..094bee7aef 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -23,37 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Select the board to build for. -ifeq ($(BOARD),) -$(error You must provide a BOARD parameter) -else -ifeq ($(wildcard boards/$(BOARD)/.),) -$(error Invalid BOARD specified) -endif -endif - -# If the build directory is not given, make it reflect the board name. -BUILD ?= build-$(BOARD) - -include ../../py/mkenv.mk -# Board-specific -include boards/$(BOARD)/mpconfigboard.mk -# Port-specific -include mpconfigport.mk - -# CircuitPython-specific -include $(TOP)/py/circuitpy_mpconfig.mk - -# qstr definitions (must come before including py.mk) -QSTR_DEFS = qstrdefsport.h - -# include py core make definitions -include $(TOP)/py/py.mk - -include $(TOP)/supervisor/supervisor.mk - -# Include make rules and variables common across CircuitPython builds. -include $(TOP)/py/circuitpy_defns.mk +include ../../py/circuitpy_mkenv.mk CROSS_COMPILE = arm-none-eabi- @@ -221,7 +191,6 @@ SRC_STM32 += boards/system_stm32$(MCU_SERIES_LOWER)xx.c SRC_C += \ background.c \ - fatfs_port.c \ mphalport.c \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ diff --git a/ports/unix/variants/coverage/mpconfigvariant.h b/ports/unix/variants/coverage/mpconfigvariant.h index f6ebc2087b..ba9e941c28 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.h +++ b/ports/unix/variants/coverage/mpconfigvariant.h @@ -65,6 +65,7 @@ #define MICROPY_PY_UCRYPTOLIB (1) #define MICROPY_PY_UCRYPTOLIB_CTR (1) #define MICROPY_PY_MICROPYTHON_HEAP_LOCKED (1) +#define MICROPY_CPYTHON_EXCEPTION_CHAIN (1) // use vfs's functions for import stat and builtin open #define mp_import_stat mp_vfs_import_stat diff --git a/py/circuitpy_mkenv.mk b/py/circuitpy_mkenv.mk new file mode 100644 index 0000000000..d776cc2fef --- /dev/null +++ b/py/circuitpy_mkenv.mk @@ -0,0 +1,70 @@ +# This file is part of the MicroPython project, http://micropython.org/ +# +# The MIT License (MIT) +# +# SPDX-FileCopyrightText: Copyright (c) 2022 MicroDev +# +# 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. + +# Common Makefile items that can be shared across CircuitPython ports. + +# Select the board to build for. +define show_board_error +$(info Valid boards:) +$(shell printf '%s\n' $(patsubst boards/%/mpconfigboard.mk,%,$(wildcard boards/*/mpconfigboard.mk)) | column -xc $$(tput cols || echo 80) 1>&2) +$(error Rerun with $(MAKE) BOARD=) +endef + +ifeq ($(BOARD),) + $(info No BOARD specified) + $(call show_board_error) +else + ifeq ($(wildcard boards/$(BOARD)/.),) + $(info Invalid BOARD specified) + $(call show_board_error) + endif +endif + +# If the flash PORT is not given, use the default /dev/tty.SLAB_USBtoUART. +PORT ?= /dev/tty.SLAB_USBtoUART + +# If the build directory is not given, make it reflect the board name. +BUILD ?= build-$(BOARD) + +include ../../py/mkenv.mk + +# Board-specific +include boards/$(BOARD)/mpconfigboard.mk + +# Port-specific +include mpconfigport.mk + +# CircuitPython-specific +include $(TOP)/py/circuitpy_mpconfig.mk + +# qstr definitions (must come before including py.mk) +QSTR_DEFS = qstrdefsport.h + +# include py core make definitions +include $(TOP)/py/py.mk + +include $(TOP)/supervisor/supervisor.mk + +# Include make rules and variables common across CircuitPython builds. +include $(TOP)/py/circuitpy_defns.mk diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 6ae8275058..d6d8419c8f 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -224,6 +224,9 @@ typedef long mp_off_t; #ifndef MICROPY_CPYTHON_COMPAT #define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD) #endif +#ifndef MICROPY_CPYTHON_EXCEPTION_CHAIN +#define MICROPY_CPYTHON_EXCEPTION_CHAIN (CIRCUITPY_FULL_BUILD) +#endif #define MICROPY_PY_BUILTINS_POW3 (CIRCUITPY_BUILTINS_POW3) #define MICROPY_PY_FSTRINGS (1) #define MICROPY_MODULE_WEAK_LINKS (0) diff --git a/py/mpconfig.h b/py/mpconfig.h index 386a9765eb..9d68f4ce9d 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -773,6 +773,16 @@ typedef long long mp_longint_impl_t; #define MICROPY_WARNINGS (0) #endif +// Whether to support chained exceptions +#ifndef MICROPY_CPYTHON_EXCEPTION_CHAIN +#define MICROPY_CPYTHON_EXCEPTION_CHAIN (0) +#endif + +// Whether the statically allocated GeneratorExit exception may be const +#ifndef MICROPY_CONST_GENERATOREXIT_OBJ +#define MICROPY_CONST_GENERATOREXIT_OBJ (!MICROPY_CPYTHON_EXCEPTION_CHAIN) +#endif + // Whether to support warning categories #ifndef MICROPY_WARNINGS_CATEGORY #define MICROPY_WARNINGS_CATEGORY (0) diff --git a/py/obj.c b/py/obj.c index af2f4c1b68..72a0647176 100644 --- a/py/obj.c +++ b/py/obj.c @@ -142,9 +142,33 @@ void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_print_helper(MP_PYTHON_PRINTER, o_in, kind); } +static void mp_obj_print_inner_exception(const mp_print_t *print, mp_obj_t self_in, mp_int_t limit) { + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + mp_obj_exception_t *self = mp_obj_exception_get_native(self_in); + const compressed_string_t *msg = MP_ERROR_TEXT("During handling of the above exception, another exception occurred:"); + mp_obj_exception_t *inner = NULL; + if (self->cause) { + msg = MP_ERROR_TEXT("The above exception was the direct cause of the following exception:"); + inner = self->cause; + } else if (!self->suppress_context) { + inner = self->context; + } + if (inner && !inner->marked) { + inner->marked = true; + mp_obj_print_exception_with_limit(print, MP_OBJ_FROM_PTR(inner), limit); + inner->marked = false; + mp_printf(print, "\n"); + mp_cprintf(print, msg); + mp_printf(print, "\n\n"); + } + #endif +} + // helper function to print an exception with traceback void mp_obj_print_exception_with_limit(const mp_print_t *print, mp_obj_t exc, mp_int_t limit) { if (mp_obj_is_exception_instance(exc) && stack_ok()) { + mp_obj_print_inner_exception(print, exc, limit); + size_t n, *values; mp_obj_exception_get_traceback(exc, &n, &values); if (n > 0) { diff --git a/py/obj.h b/py/obj.h index 7fa21f5e38..b7e76a1106 100644 --- a/py/obj.h +++ b/py/obj.h @@ -791,7 +791,9 @@ extern const struct _mp_obj_dict_t mp_const_empty_dict_obj; extern const struct _mp_obj_traceback_t mp_const_empty_traceback_obj; extern const struct _mp_obj_singleton_t mp_const_ellipsis_obj; extern const struct _mp_obj_singleton_t mp_const_notimplemented_obj; -extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj; +#if MICROPY_CONST_GENERATOREXIT_OBJ +extern const struct _mp_obj_exception_t mp_static_GeneratorExit_obj; +#endif // Fixed empty map. Useful when calling keyword-receiving functions // without any keywords from C, etc. diff --git a/py/objexcept.c b/py/objexcept.c index 32dacbb17a..80da487076 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -218,19 +218,45 @@ void mp_obj_exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_exception_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] != MP_OBJ_NULL) { // store/delete attribute - if (self == &mp_const_GeneratorExit_obj) { + #if MICROPY_CONST_GENERATOREXIT_OBJ + if (self == &mp_static_GeneratorExit_obj) { mp_raise_AttributeError(MP_ERROR_TEXT("can't set attribute")); } + #endif if (attr == MP_QSTR___traceback__) { if (dest[1] == mp_const_none) { self->traceback = (mp_obj_traceback_t *)&mp_const_empty_traceback_obj; } else { if (!mp_obj_is_type(dest[1], &mp_type_traceback)) { - mp_raise_TypeError(MP_ERROR_TEXT("invalid traceback")); + mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q or None"), MP_QSTR___context__, MP_QSTR_traceback); } self->traceback = MP_OBJ_TO_PTR(dest[1]); } dest[0] = MP_OBJ_NULL; // indicate success + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + } else if (attr == MP_QSTR___cause__) { + if (dest[1] == mp_const_none) { + self->cause = NULL; + } else if (!mp_obj_is_type(dest[1], &mp_type_BaseException)) { + self->cause = dest[1]; + } else { + mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q or None"), attr, MP_QSTR_BaseException); + } + self->suppress_context = true; + dest[0] = MP_OBJ_NULL; // indicate success + } else if (attr == MP_QSTR___context__) { + if (dest[1] == mp_const_none) { + self->context = NULL; + } else if (!mp_obj_is_type(dest[1], &mp_type_BaseException)) { + self->context = dest[1]; + } else { + mp_raise_TypeError_varg(MP_ERROR_TEXT("%q must be of type %q or None"), attr, MP_QSTR_BaseException); + } + dest[0] = MP_OBJ_NULL; // indicate success + } else if (attr == MP_QSTR___suppress_context__) { + self->suppress_context = mp_obj_is_true(dest[1]); + dest[0] = MP_OBJ_NULL; // indicate success + #endif } return; } @@ -240,6 +266,14 @@ void mp_obj_exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { dest[0] = mp_obj_exception_get_value(self_in); } else if (attr == MP_QSTR___traceback__) { dest[0] = (self->traceback) ? MP_OBJ_FROM_PTR(self->traceback) : mp_const_none; + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + } else if (attr == MP_QSTR___cause__) { + dest[0] = (self->cause) ? MP_OBJ_FROM_PTR(self->cause) : mp_const_none; + } else if (attr == MP_QSTR___context__) { + dest[0] = (self->context) ? MP_OBJ_FROM_PTR(self->context) : mp_const_none; + } else if (attr == MP_QSTR___suppress_context__) { + dest[0] = mp_obj_new_bool(self->suppress_context); + #endif #if MICROPY_CPYTHON_COMPAT } else if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(self->base.type), MP_OBJ_FROM_PTR(&mp_type_OSError))) { if (attr == MP_QSTR_errno) { diff --git a/py/objexcept.h b/py/objexcept.h index f28f50f5dc..77b338e951 100644 --- a/py/objexcept.h +++ b/py/objexcept.h @@ -34,6 +34,11 @@ typedef struct _mp_obj_exception_t { mp_obj_base_t base; mp_obj_tuple_t *args; mp_obj_traceback_t *traceback; + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + struct _mp_obj_exception_t *cause, *context; + bool suppress_context; + bool marked; + #endif } mp_obj_exception_t; void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind); diff --git a/py/objgenerator.c b/py/objgenerator.c index c9af11fbb5..2256911e23 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -38,7 +38,12 @@ #include "supervisor/shared/translate/translate.h" // Instance of GeneratorExit exception - needed by generator.close() -const mp_obj_exception_t mp_const_GeneratorExit_obj = {{&mp_type_GeneratorExit}, (mp_obj_tuple_t *)&mp_const_empty_tuple_obj, (mp_obj_traceback_t *)&mp_const_empty_traceback_obj}; +#if MICROPY_CONST_GENERATOREXIT_OBJ +const +#else +static +#endif +mp_obj_exception_t mp_static_GeneratorExit_obj = {{&mp_type_GeneratorExit}, (mp_obj_tuple_t *)&mp_const_empty_tuple_obj, (mp_obj_traceback_t *)&mp_const_empty_traceback_obj}; /******************************************************************************/ /* generator wrapper */ @@ -362,9 +367,19 @@ STATIC mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gen_instance_throw_obj, 2, 4, gen_instance_throw); +static mp_obj_t generatorexit(void) { + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + MP_STATIC_ASSERT(!MICROPY_CONST_GENERATOREXIT_OBJ); + mp_static_GeneratorExit_obj.context = NULL; + mp_static_GeneratorExit_obj.cause = NULL; + mp_static_GeneratorExit_obj.suppress_context = false; + #endif + return MP_OBJ_FROM_PTR(&mp_static_GeneratorExit_obj); +} + STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) { mp_obj_t ret; - switch (mp_obj_gen_resume(self_in, mp_const_none, MP_OBJ_FROM_PTR(&mp_const_GeneratorExit_obj), &ret)) { + switch (mp_obj_gen_resume(self_in, mp_const_none, generatorexit(), &ret)) { case MP_VM_RETURN_YIELD: mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("generator ignored GeneratorExit")); diff --git a/py/vm.c b/py/vm.c index 12a0f2d445..9e9dbcaa8d 100644 --- a/py/vm.c +++ b/py/vm.c @@ -183,6 +183,15 @@ #define TRACE_TICK(current_ip, current_sp, is_exception) #endif // MICROPY_PY_SYS_SETTRACE +STATIC mp_obj_t get_active_exception(mp_exc_stack_t *exc_sp, mp_exc_stack_t *exc_stack) { + for (mp_exc_stack_t *e = exc_sp; e >= exc_stack; --e) { + if (e->prev_exc != NULL) { + return MP_OBJ_FROM_PTR(e->prev_exc); + } + } + return MP_OBJ_NULL; +} + // fastn has items in reverse order (fastn[0] is local[0], fastn[-1] is local[1], etc) // sp points to bottom of stack which grows up // returns: @@ -1129,13 +1138,7 @@ unwind_return: ENTRY(MP_BC_RAISE_LAST): { MARK_EXC_IP_SELECTIVE(); // search for the inner-most previous exception, to reraise it - mp_obj_t obj = MP_OBJ_NULL; - for (mp_exc_stack_t *e = exc_sp; e >= exc_stack; --e) { - if (e->prev_exc != NULL) { - obj = MP_OBJ_FROM_PTR(e->prev_exc); - break; - } - } + mp_obj_t obj = get_active_exception(exc_sp, exc_stack); if (obj == MP_OBJ_NULL) { obj = mp_obj_new_exception_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("no active exception to reraise")); } @@ -1145,14 +1148,30 @@ unwind_return: ENTRY(MP_BC_RAISE_OBJ): { MARK_EXC_IP_SELECTIVE(); mp_obj_t obj = mp_make_raise_obj(TOP()); + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + mp_obj_t active_exception = get_active_exception(exc_sp, exc_stack); + if (active_exception != MP_OBJ_NULL) { + mp_store_attr(obj, MP_QSTR___context__, active_exception); + } + #endif RAISE(obj); } ENTRY(MP_BC_RAISE_FROM): { MARK_EXC_IP_SELECTIVE(); - mp_warning(NULL, "exception chaining not supported"); - sp--; // ignore (pop) "from" argument + mp_obj_t cause = POP(); mp_obj_t obj = mp_make_raise_obj(TOP()); + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + // search for the inner-most previous exception, to chain it + mp_obj_t active_exception = get_active_exception(exc_sp, exc_stack); + if (active_exception != MP_OBJ_NULL) { + mp_store_attr(obj, MP_QSTR___context__, active_exception); + } + mp_store_attr(obj, MP_QSTR___cause__, cause); + #else + (void)cause; + mp_warning(NULL, "exception chaining not supported"); + #endif RAISE(obj); } @@ -1391,7 +1410,10 @@ unwind_loop: // - constant GeneratorExit object, because it's const // - exceptions re-raised by END_FINALLY // - exceptions re-raised explicitly by "raise" - if (nlr.ret_val != &mp_const_GeneratorExit_obj + if ( true + #if MICROPY_CONST_GENERATOREXIT_OBJ + && nlr.ret_val != &mp_static_GeneratorExit_obj + #endif && *code_state->ip != MP_BC_END_FINALLY && *code_state->ip != MP_BC_RAISE_LAST) { const byte *ip = code_state->fun_bc->bytecode; @@ -1434,10 +1456,19 @@ unwind_loop: // catch exception and pass to byte code code_state->ip = exc_sp->handler; mp_obj_t *sp = MP_TAGPTR_PTR(exc_sp->val_sp); + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + mp_obj_t active_exception = get_active_exception(exc_sp, exc_stack); + #endif // save this exception in the stack so it can be used in a reraise, if needed exc_sp->prev_exc = nlr.ret_val; + mp_obj_t obj = MP_OBJ_FROM_PTR(nlr.ret_val); + #if MICROPY_CPYTHON_EXCEPTION_CHAIN + if (active_exception != MP_OBJ_NULL) { + mp_store_attr(obj, MP_QSTR___context__, active_exception); + } + #endif // push exception object so it can be handled by bytecode - PUSH(MP_OBJ_FROM_PTR(nlr.ret_val)); + PUSH(obj); code_state->sp = sp; #if MICROPY_STACKLESS diff --git a/shared-bindings/adafruit_pixelbuf/PixelBuf.h b/shared-bindings/adafruit_pixelbuf/PixelBuf.h index 7ae3d6acf8..e73d3e02d6 100644 --- a/shared-bindings/adafruit_pixelbuf/PixelBuf.h +++ b/shared-bindings/adafruit_pixelbuf/PixelBuf.h @@ -31,6 +31,13 @@ extern const mp_obj_type_t pixelbuf_pixelbuf_type; +typedef union { + struct { + uint8_t r, g, b, w; + }; + uint32_t rgbw; +} color_u; + void common_hal_adafruit_pixelbuf_pixelbuf_construct(pixelbuf_pixelbuf_obj_t *self, size_t n, pixelbuf_byteorder_details_t *byteorder, mp_float_t brightness, bool auto_write, uint8_t *header, size_t header_len, uint8_t *trailer, size_t trailer_len); diff --git a/shared-bindings/i2ctarget/I2CTarget.c b/shared-bindings/i2ctarget/I2CTarget.c index 4dc5b775f4..17da952118 100644 --- a/shared-bindings/i2ctarget/I2CTarget.c +++ b/shared-bindings/i2ctarget/I2CTarget.c @@ -159,7 +159,7 @@ STATIC mp_obj_t i2ctarget_i2c_target_request(size_t n_args, const mp_obj_t *pos_ bool forever = false; uint64_t timeout_end = 0; - if (timeout_ms <= 0) { + if (timeout_ms == 0) { forever = true; } else if (timeout_ms > 0) { timeout_end = common_hal_time_monotonic_ms() + timeout_ms; diff --git a/shared-bindings/socketpool/Socket.c b/shared-bindings/socketpool/Socket.c index 7a60463c4b..fbf78a4cdc 100644 --- a/shared-bindings/socketpool/Socket.c +++ b/shared-bindings/socketpool/Socket.c @@ -344,38 +344,36 @@ STATIC mp_obj_t socketpool_socket_setblocking(mp_obj_t self_in, mp_obj_t blockin } STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_setblocking_obj, socketpool_socket_setblocking); -// //| def setsockopt(self, level: int, optname: int, value: int) -> None: -// //| """Sets socket options""" -// //| ... -// //| -// STATIC mp_obj_t socketpool_socket_setsockopt(size_t n_args, const mp_obj_t *args) { -// // mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); +//| def setsockopt(self, level: int, optname: int, value: int) -> None: +//| """Sets socket options""" +//| ... +STATIC mp_obj_t socketpool_socket_setsockopt(size_t n_args, const mp_obj_t *args) { + socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(args[0]); + mp_int_t level = mp_obj_get_int(args[1]); + mp_int_t opt = mp_obj_get_int(args[2]); -// // mp_int_t level = mp_obj_get_int(args[1]); -// // mp_int_t opt = mp_obj_get_int(args[2]); + const void *optval; + mp_uint_t optlen; + mp_int_t val; + if (mp_obj_is_integer(args[3])) { + val = mp_obj_get_int_truncated(args[3]); + optval = &val; + optlen = sizeof(val); + } else { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); + optval = bufinfo.buf; + optlen = bufinfo.len; + } -// // const void *optval; -// // mp_uint_t optlen; -// // mp_int_t val; -// // if (mp_obj_is_integer(args[3])) { -// // val = mp_obj_get_int_truncated(args[3]); -// // optval = &val; -// // optlen = sizeof(val); -// // } else { -// // mp_buffer_info_t bufinfo; -// // mp_get_buffer_raise(args[3], &bufinfo, MP_BUFFER_READ); -// // optval = bufinfo.buf; -// // optlen = bufinfo.len; -// // } + int _errno = common_hal_socketpool_socket_setsockopt(self, level, opt, optval, optlen); + if (_errno < 0) { + mp_raise_OSError(-_errno); + } -// // int _errno; -// // if (self->nic_type->setsockopt(self, level, opt, optval, optlen, &_errno) != 0) { -// // mp_raise_OSError(_errno); -// // } - -// return mp_const_none; -// } -// STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socketpool_socket_setsockopt_obj, 4, 4, socketpool_socket_setsockopt); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socketpool_socket_setsockopt_obj, 4, 4, socketpool_socket_setsockopt); //| def settimeout(self, value: int) -> None: @@ -417,7 +415,7 @@ STATIC const mp_rom_map_elem_t socketpool_socket_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_sendall), MP_ROM_PTR(&socketpool_socket_sendall_obj) }, { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socketpool_socket_sendto_obj) }, { MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socketpool_socket_setblocking_obj) }, - // { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socketpool_socket_setsockopt_obj) }, + { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socketpool_socket_setsockopt_obj) }, { MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&socketpool_socket_settimeout_obj) }, }; diff --git a/shared-bindings/socketpool/Socket.h b/shared-bindings/socketpool/Socket.h index cf5a97a428..690c9f8363 100644 --- a/shared-bindings/socketpool/Socket.h +++ b/shared-bindings/socketpool/Socket.h @@ -46,13 +46,22 @@ mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t *self, const mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t *self, const char *host, size_t hostlen, uint32_t port, const uint8_t *buf, uint32_t len); void common_hal_socketpool_socket_settimeout(socketpool_socket_obj_t *self, uint32_t timeout_ms); +int common_hal_socketpool_socket_setsockopt(socketpool_socket_obj_t *self, int level, int optname, const void *value, size_t optlen); bool common_hal_socketpool_readable(socketpool_socket_obj_t *self); bool common_hal_socketpool_writable(socketpool_socket_obj_t *self); // Non-allocating versions for internal use. -int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_t *port); +int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_t *port, socketpool_socket_obj_t *accepted); void socketpool_socket_close(socketpool_socket_obj_t *self); int socketpool_socket_send(socketpool_socket_obj_t *self, const uint8_t *buf, uint32_t len); int socketpool_socket_recv_into(socketpool_socket_obj_t *self, const uint8_t *buf, uint32_t len); + +// Moves self to sock without closing the real socket. self will think its closed afterwards. +void socketpool_socket_move(socketpool_socket_obj_t *self, socketpool_socket_obj_t *sock); + +// Resets the socket object state so it appears closed and disconnected. This only works on +// uninitialized memory. +void socketpool_socket_reset(socketpool_socket_obj_t *self); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_SOCKETPOOL_SOCKET_H diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index e500784f1f..4881a0597b 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -36,6 +36,8 @@ #include "shared-bindings/socketpool/Socket.h" #include "shared-bindings/socketpool/SocketPool.h" +#define SOCKETPOOL_EAI_NONAME (-2) + //| class SocketPool: //| """A pool of socket resources available for the given radio. Only one //| SocketPool can be created for each radio. @@ -52,7 +54,6 @@ //| returned by :py:attr:`wifi.radio` //| """ //| ... - STATIC mp_obj_t socketpool_socketpool_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); @@ -65,12 +66,23 @@ STATIC mp_obj_t socketpool_socketpool_make_new(const mp_obj_type_t *type, size_t return MP_OBJ_FROM_PTR(s); } +//| class gaierror(OSError): +//| """Errors raised by getaddrinfo""" +//| +MP_DEFINE_EXCEPTION(gaierror, OSError) + +//| //| AF_INET: int //| AF_INET6: int +//| //| SOCK_STREAM: int //| SOCK_DGRAM: int //| SOCK_RAW: int +//| EAI_NONAME: int //| +//| TCP_NODELAY: int +//| +//| IPPROTO_TCP: int //| def socket(self, family: int = AF_INET, type: int = SOCK_STREAM) -> socketpool.Socket: //| """Create a new socket //| @@ -143,7 +155,11 @@ STATIC mp_obj_t socketpool_socketpool_getaddrinfo(size_t n_args, const mp_obj_t } if (ip_str == mp_const_none) { - mp_raise_OSError(-2); // socket.EAI_NONAME from CPython + mp_obj_t exc_args[2] = { + MP_OBJ_NEW_SMALL_INT(SOCKETPOOL_EAI_NONAME), + MP_OBJ_NEW_QSTR(MP_QSTR_Name_space_or_space_service_space_not_space_known), + }; + nlr_raise(mp_obj_new_exception_args(&mp_type_gaierror, 2, exc_args)); } mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(5, NULL)); @@ -162,6 +178,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(socketpool_socketpool_getaddrinfo_obj, 1, sock STATIC const mp_rom_map_elem_t socketpool_socketpool_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_socket), MP_ROM_PTR(&socketpool_socketpool_socket_obj) }, { MP_ROM_QSTR(MP_QSTR_getaddrinfo), MP_ROM_PTR(&socketpool_socketpool_getaddrinfo_obj) }, + { MP_ROM_QSTR(MP_QSTR_gaierror), MP_ROM_PTR(&mp_type_gaierror) }, // class constants { MP_ROM_QSTR(MP_QSTR_AF_INET), MP_ROM_INT(SOCKETPOOL_AF_INET) }, @@ -170,6 +187,12 @@ STATIC const mp_rom_map_elem_t socketpool_socketpool_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SOCK_STREAM), MP_ROM_INT(SOCKETPOOL_SOCK_STREAM) }, { MP_ROM_QSTR(MP_QSTR_SOCK_DGRAM), MP_ROM_INT(SOCKETPOOL_SOCK_DGRAM) }, { MP_ROM_QSTR(MP_QSTR_SOCK_RAW), MP_ROM_INT(SOCKETPOOL_SOCK_RAW) }, + + { MP_ROM_QSTR(MP_QSTR_TCP_NODELAY), MP_ROM_INT(SOCKETPOOL_TCP_NODELAY) }, + + { MP_ROM_QSTR(MP_QSTR_IPPROTO_TCP), MP_ROM_INT(SOCKETPOOL_IPPROTO_TCP) }, + + { MP_ROM_QSTR(MP_QSTR_EAI_NONAME), MP_ROM_INT(SOCKETPOOL_EAI_NONAME) }, }; STATIC MP_DEFINE_CONST_DICT(socketpool_socketpool_locals_dict, socketpool_socketpool_locals_dict_table); diff --git a/shared-bindings/socketpool/SocketPool.h b/shared-bindings/socketpool/SocketPool.h index 92382078e1..5a2d9f4337 100644 --- a/shared-bindings/socketpool/SocketPool.h +++ b/shared-bindings/socketpool/SocketPool.h @@ -34,16 +34,24 @@ extern const mp_obj_type_t socketpool_socketpool_type; typedef enum { - SOCKETPOOL_SOCK_STREAM, - SOCKETPOOL_SOCK_DGRAM, - SOCKETPOOL_SOCK_RAW + SOCKETPOOL_SOCK_STREAM = 1, + SOCKETPOOL_SOCK_DGRAM = 2, + SOCKETPOOL_SOCK_RAW = 3 } socketpool_socketpool_sock_t; typedef enum { - SOCKETPOOL_AF_INET, - SOCKETPOOL_AF_INET6 + SOCKETPOOL_AF_INET = 2, + SOCKETPOOL_AF_INET6 = 10 } socketpool_socketpool_addressfamily_t; +typedef enum { + SOCKETPOOL_IPPROTO_TCP = 6, +} socketpool_socketpool_ipproto_t; + +typedef enum { + SOCKETPOOL_TCP_NODELAY = 1, +} socketpool_socketpool_tcpopt_t; + void common_hal_socketpool_socketpool_construct(socketpool_socketpool_obj_t *self, mp_obj_t radio); socketpool_socket_obj_t *common_hal_socketpool_socket(socketpool_socketpool_obj_t *self, diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index b61d05d636..37f35e2e18 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -197,7 +197,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(supervisor_set_next_code_file_obj, 0, supervisor_set_ //| //| def ticks_add(ticks, delta): //| "Add a delta to a base number of ticks, performing wraparound at 2**29ms." -//| return (a + b) % _TICKS_PERIOD +//| return (ticks + delta) % _TICKS_PERIOD //| //| def ticks_diff(ticks1, ticks2): //| "Compute the signed difference between two ticks values, assuming that they are within 2**28 ticks" diff --git a/shared-bindings/vectorio/Circle.c b/shared-bindings/vectorio/Circle.c index 91b0d3ae34..87cd46ad9a 100644 --- a/shared-bindings/vectorio/Circle.c +++ b/shared-bindings/vectorio/Circle.c @@ -109,6 +109,9 @@ MP_PROPERTY_GETSET(vectorio_circle_color_index_obj, //| y: int //| """Y position of the center point of the circle in the parent.""" //| +//| hidden: bool +//| """Hide the circle or not.""" +//| //| location: Tuple[int, int] //| """(X,Y) position of the center point of the circle in the parent.""" //| @@ -123,6 +126,7 @@ STATIC const mp_rom_map_elem_t vectorio_circle_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_radius), MP_ROM_PTR(&vectorio_circle_radius_obj) }, { MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) }, { MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) }, + { MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&vectorio_vector_shape_hidden_obj) }, { MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_circle_color_index_obj) }, { MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) }, { MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) }, diff --git a/shared-bindings/vectorio/Polygon.c b/shared-bindings/vectorio/Polygon.c index f4f07c66a0..6ad102e6e6 100644 --- a/shared-bindings/vectorio/Polygon.c +++ b/shared-bindings/vectorio/Polygon.c @@ -118,6 +118,9 @@ MP_PROPERTY_GETSET(vectorio_polygon_color_index_obj, //| y: int //| """Y position of the 0,0 origin in the points list.""" //| +//| hidden: bool +//| """Hide the polygon or not.""" +//| //| location: Tuple[int, int] //| """(X,Y) position of the 0,0 origin in the points list.""" //| @@ -132,6 +135,7 @@ STATIC const mp_rom_map_elem_t vectorio_polygon_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_points), MP_ROM_PTR(&vectorio_polygon_points_obj) }, { MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) }, { MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) }, + { MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&vectorio_vector_shape_hidden_obj) }, { MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_polygon_color_index_obj) }, { MP_ROM_QSTR(MP_QSTR_location), MP_ROM_PTR(&vectorio_vector_shape_location_obj) }, { MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&vectorio_vector_shape_pixel_shader_obj) }, diff --git a/shared-bindings/vectorio/Rectangle.c b/shared-bindings/vectorio/Rectangle.c index 5c163a7693..a4f3e12e69 100644 --- a/shared-bindings/vectorio/Rectangle.c +++ b/shared-bindings/vectorio/Rectangle.c @@ -139,6 +139,9 @@ const mp_obj_property_t vectorio_rectangle_color_index_obj = { //| y: int //| """Y position of the top left corner of the rectangle in the parent.""" //| +//| hidden: bool +//| """Hide the rectangle or not.""" +//| //| location: Tuple[int, int] //| """(X,Y) position of the top left corner of the rectangle in the parent.""" //| @@ -152,6 +155,7 @@ STATIC const mp_rom_map_elem_t vectorio_rectangle_locals_dict_table[] = { // Properties { MP_ROM_QSTR(MP_QSTR_x), MP_ROM_PTR(&vectorio_vector_shape_x_obj) }, { MP_ROM_QSTR(MP_QSTR_y), MP_ROM_PTR(&vectorio_vector_shape_y_obj) }, + { MP_ROM_QSTR(MP_QSTR_hidden), MP_ROM_PTR(&vectorio_vector_shape_hidden_obj) }, { MP_ROM_QSTR(MP_QSTR_color_index), MP_ROM_PTR(&vectorio_rectangle_color_index_obj) }, { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&vectorio_rectangle_width_obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&vectorio_rectangle_height_obj) }, diff --git a/shared-bindings/vectorio/VectorShape.c b/shared-bindings/vectorio/VectorShape.c index ba55cfb851..e5c806b943 100644 --- a/shared-bindings/vectorio/VectorShape.c +++ b/shared-bindings/vectorio/VectorShape.c @@ -181,6 +181,33 @@ MP_PROPERTY_GETSET(vectorio_vector_shape_location_obj, (mp_obj_t)&vectorio_vector_shape_set_location_obj); +// Stub checker does not approve of these shared properties. +// hidden: bool +// """Hide the shape or not.""" +// +STATIC mp_obj_t vectorio_vector_shape_obj_get_hidden(mp_obj_t wrapper_shape) { + // Relies on the fact that only vector_shape impl gets matched with a VectorShape. + const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, wrapper_shape); + vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(draw_protocol->draw_get_protocol_self(wrapper_shape)); + return mp_obj_new_bool(common_hal_vectorio_vector_shape_get_hidden(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(vectorio_vector_shape_get_hidden_obj, vectorio_vector_shape_obj_get_hidden); + +STATIC mp_obj_t vectorio_vector_shape_obj_set_hidden(mp_obj_t wrapper_shape, mp_obj_t hidden_obj) { + // Relies on the fact that only vector_shape impl gets matched with a VectorShape. + const vectorio_draw_protocol_t *draw_protocol = mp_proto_get(MP_QSTR_protocol_draw, wrapper_shape); + vectorio_vector_shape_t *self = MP_OBJ_TO_PTR(draw_protocol->draw_get_protocol_self(wrapper_shape)); + + common_hal_vectorio_vector_shape_set_hidden(self, mp_obj_is_true(hidden_obj)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(vectorio_vector_shape_set_hidden_obj, vectorio_vector_shape_obj_set_hidden); + +MP_PROPERTY_GETSET(vectorio_vector_shape_hidden_obj, + (mp_obj_t)&vectorio_vector_shape_get_hidden_obj, + (mp_obj_t)&vectorio_vector_shape_set_hidden_obj); + + // pixel_shader: Union[ColorConverter, Palette] // """The pixel shader of the shape.""" // diff --git a/shared-bindings/vectorio/VectorShape.h b/shared-bindings/vectorio/VectorShape.h index 13f62922f3..c94476c25a 100644 --- a/shared-bindings/vectorio/VectorShape.h +++ b/shared-bindings/vectorio/VectorShape.h @@ -31,6 +31,9 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self mp_int_t common_hal_vectorio_vector_shape_get_y(vectorio_vector_shape_t *self); void common_hal_vectorio_vector_shape_set_y(vectorio_vector_shape_t *self, mp_int_t y); +mp_int_t common_hal_vectorio_vector_shape_get_hidden(vectorio_vector_shape_t *self); +void common_hal_vectorio_vector_shape_set_hidden(vectorio_vector_shape_t *self, bool hidden); + mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self); void common_hal_vectorio_vector_shape_set_pixel_shader(vectorio_vector_shape_t *self, mp_obj_t pixel_shader); @@ -40,6 +43,7 @@ void vectorio_vector_shape_update_transform(vectorio_vector_shape_t *self, displ extern vectorio_draw_protocol_impl_t vectorio_vector_shape_draw_protocol_impl; extern const mp_obj_property_getset_t vectorio_vector_shape_x_obj; extern const mp_obj_property_getset_t vectorio_vector_shape_y_obj; +extern const mp_obj_property_getset_t vectorio_vector_shape_hidden_obj; extern const mp_obj_property_getset_t vectorio_vector_shape_location_obj; extern const mp_obj_property_getset_t vectorio_vector_shape_pixel_shader_obj; extern const mp_obj_fun_builtin_fixed_t vectorio_vector_shape_contains_obj; diff --git a/shared-bindings/wifi/AuthMode.h b/shared-bindings/wifi/AuthMode.h index a1016d6c8a..c514fb2a32 100644 --- a/shared-bindings/wifi/AuthMode.h +++ b/shared-bindings/wifi/AuthMode.h @@ -30,13 +30,13 @@ #include "py/enum.h" typedef enum { - AUTHMODE_OPEN, - AUTHMODE_WEP, - AUTHMODE_WPA, - AUTHMODE_WPA2, - AUTHMODE_WPA3, - AUTHMODE_PSK, - AUTHMODE_ENTERPRISE + AUTHMODE_OPEN = 1 << 0, + AUTHMODE_WEP = 1 << 1, + AUTHMODE_WPA = 1 << 2, + AUTHMODE_WPA2 = 1 << 3, + AUTHMODE_WPA3 = 1 << 4, + AUTHMODE_PSK = 1 << 5, + AUTHMODE_ENTERPRISE = 1 << 6, } wifi_authmode_t; extern const mp_obj_type_t wifi_authmode_type; diff --git a/shared-bindings/wifi/Monitor.c b/shared-bindings/wifi/Monitor.c index bd688d357d..d087ec587b 100644 --- a/shared-bindings/wifi/Monitor.c +++ b/shared-bindings/wifi/Monitor.c @@ -36,15 +36,14 @@ //| """For monitoring WiFi packets.""" //| -//| def __init__(self, channel: Optional[int] = 1, queue: Optional[int] = 128) -> None: -//| """Initialize `wifi.Monitor` singleton. +//| def __init__(self, channel: Optional[int] = 1, queue: Optional[int] = 128) -> None: +//| """Initialize `wifi.Monitor` singleton. //| -//| :param int channel: The WiFi channel to scan. -//| :param int queue: The queue size for buffering the packet. -//| -//| """ -//| ... +//| :param int channel: The WiFi channel to scan. +//| :param int queue: The queue size for buffering the packet. //| +//| """ +//| ... STATIC mp_obj_t wifi_monitor_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_channel, ARG_queue }; static const mp_arg_t allowed_args[] = { @@ -69,8 +68,8 @@ STATIC mp_obj_t wifi_monitor_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(self); } -//| channel: int -//| """The WiFi channel to scan.""" +//| channel: int +//| """The WiFi channel to scan.""" STATIC mp_obj_t wifi_monitor_obj_get_channel(mp_obj_t self_in) { return common_hal_wifi_monitor_get_channel(self_in); } @@ -90,8 +89,8 @@ MP_PROPERTY_GETSET(wifi_monitor_channel_obj, (mp_obj_t)&wifi_monitor_get_channel_obj, (mp_obj_t)&wifi_monitor_set_channel_obj); -//| queue: int -//| """The queue size for buffering the packet.""" +//| queue: int +//| """The queue size for buffering the packet.""" STATIC mp_obj_t wifi_monitor_obj_get_queue(mp_obj_t self_in) { return common_hal_wifi_monitor_get_queue(self_in); } @@ -100,29 +99,26 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_get_queue_obj, wifi_monitor_obj_get_queue MP_PROPERTY_GETTER(wifi_monitor_queue_obj, (mp_obj_t)&wifi_monitor_get_queue_obj); -//| def deinit(self) -> None: -//| """De-initialize `wifi.Monitor` singleton.""" -//| ... -//| +//| def deinit(self) -> None: +//| """De-initialize `wifi.Monitor` singleton.""" +//| ... STATIC mp_obj_t wifi_monitor_obj_deinit(mp_obj_t self_in) { common_hal_wifi_monitor_deinit(self_in); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_deinit_obj, wifi_monitor_obj_deinit); -//| def lost(self) -> int: -//| """Returns the packet loss count. The counter resets after each poll.""" -//| ... -//| +//| def lost(self) -> int: +//| """Returns the packet loss count. The counter resets after each poll.""" +//| ... STATIC mp_obj_t wifi_monitor_obj_get_lost(mp_obj_t self_in) { return common_hal_wifi_monitor_get_lost(self_in); } MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_lost_obj, wifi_monitor_obj_get_lost); -//| def queued(self) -> int: -//| """Returns the packet queued count.""" -//| ... -//| +//| def queued(self) -> int: +//| """Returns the packet queued count.""" +//| ... STATIC mp_obj_t wifi_monitor_obj_get_queued(mp_obj_t self_in) { if (common_hal_wifi_monitor_deinited()) { return mp_obj_new_int_from_uint(0); @@ -131,9 +127,9 @@ STATIC mp_obj_t wifi_monitor_obj_get_queued(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(wifi_monitor_queued_obj, wifi_monitor_obj_get_queued); -//| def packet(self) -> dict: -//| """Returns the monitor packet.""" -//| ... +//| def packet(self) -> dict: +//| """Returns the monitor packet.""" +//| ... //| STATIC mp_obj_t wifi_monitor_obj_get_packet(mp_obj_t self_in) { if (common_hal_wifi_monitor_deinited()) { diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 57e953ec68..c12e19e726 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -140,11 +140,11 @@ MP_PROPERTY_GETSET(wifi_radio_hostname_obj, //| mac_address: ReadableBuffer //| """MAC address for the station. When the address is altered after interface is connected //| the changes would only be reflected once the interface reconnects.""" -STATIC mp_obj_t wifi_radio_get_mac_address(mp_obj_t self_in) { +STATIC mp_obj_t _wifi_radio_get_mac_address(mp_obj_t self_in) { wifi_radio_obj_t *self = MP_OBJ_TO_PTR(self_in); return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address(self)); } -MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_obj, wifi_radio_get_mac_address); +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_obj, _wifi_radio_get_mac_address); STATIC mp_obj_t wifi_radio_set_mac_address(mp_obj_t self_in, mp_obj_t mac_address_in) { mp_buffer_info_t mac_address; @@ -282,10 +282,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| def start_ap( //| self, //| ssid: Union[str | ReadableBuffer], -//| password: Union[str | ReadableBuffer] = "", +//| password: Union[str | ReadableBuffer] = b"", //| *, -//| channel: Optional[int] = 1, -//| authmode: Optional[AuthMode], +//| channel: int = 1, +//| authmode: Optional[AuthMode] = None, //| max_connections: Optional[int] = 4 //| ) -> None: //| """Starts an Access Point with the specified ssid and password. @@ -293,10 +293,11 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| If ``channel`` is given, the access point will use that channel unless //| a station is already operating on a different channel. //| -//| If ``authmode`` is given, the access point will use that Authentication -//| mode. If a password is given, ``authmode`` must not be ``OPEN``. -//| If ``authmode`` isn't given, ``OPEN`` will be used when password isn't provided, -//| otherwise ``WPA_WPA2_PSK``. +//| If ``authmode`` is not None, the access point will use that Authentication +//| mode. If a non-empty password is given, ``authmode`` must not be ``OPEN``. +//| If ``authmode`` is not given or is None, +//| ``OPEN`` will be used when the password is the empty string, +//| otherwise ``authmode`` will be ``WPA_WPA2_PSK``. //| //| If ``max_connections`` is given, the access point will allow up to //| that number of stations to connect.""" @@ -305,9 +306,9 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ enum { ARG_ssid, ARG_password, ARG_channel, ARG_authmode, ARG_max_connections }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} }, { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, - { MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } }, { MP_QSTR_max_connections, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 4} }, }; @@ -315,12 +316,13 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ 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); - uint8_t authmode = 0; - if (args[ARG_authmode].u_obj != MP_OBJ_NULL) { + // 0 indicates mode wasn't given. + uint32_t authmodes = 0; + if (args[ARG_authmode].u_obj != mp_const_none) { mp_obj_iter_buf_t iter_buf; mp_obj_t item, iterable = mp_getiter(args[ARG_authmode].u_obj, &iter_buf); while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { - authmode |= (1 << (wifi_authmode_t)cp_enum_value(&wifi_authmode_type, item)); + authmodes |= cp_enum_value(&wifi_authmode_type, item); } } @@ -329,20 +331,24 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ mp_arg_validate_length_range(ssid.len, 1, 32, MP_QSTR_ssid); mp_buffer_info_t password; - password.len = 0; - if (args[ARG_password].u_obj != MP_OBJ_NULL) { - if (authmode == 1) { - mp_raise_ValueError(translate("AuthMode.OPEN is not used with password")); - } else if (authmode == 0) { - authmode = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK); + mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ); + if (authmodes == 0) { + if (password.len == 0) { + authmodes = AUTHMODE_OPEN; + } else { + authmodes = AUTHMODE_WPA | AUTHMODE_WPA2 | AUTHMODE_PSK; } - mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ); - mp_arg_validate_length_range(password.len, 8, 63, MP_QSTR_password); - } else { - authmode = 1; } - common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmode, args[ARG_max_connections].u_int); + if (authmodes == AUTHMODE_OPEN && password.len > 0) { + mp_raise_ValueError(translate("AuthMode.OPEN is not used with password")); + } + + if (authmodes != AUTHMODE_OPEN) { + mp_arg_validate_length_range(password.len, 8, 63, MP_QSTR_password); + } + + common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmodes, args[ARG_max_connections].u_int); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap); @@ -359,10 +365,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_ap_obj, wifi_radio_stop_ap); //| def connect( //| self, //| ssid: Union[str | ReadableBuffer], -//| password: Union[str | ReadableBuffer] = "", +//| password: Union[str | ReadableBuffer] = b"", //| *, -//| channel: Optional[int] = 0, -//| bssid: Optional[Union[str | ReadableBuffer]] = "", +//| channel: int = 0, +//| bssid: Optional[Union[str | ReadableBuffer]] = None, //| timeout: Optional[float] = None //| ) -> None: //| """Connects to the given ssid and waits for an ip address. Reconnections are handled @@ -371,20 +377,20 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_ap_obj, wifi_radio_stop_ap); //| By default, this will scan all channels and connect to the access point (AP) with the //| given ``ssid`` and greatest signal strength (rssi). //| -//| If ``channel`` is given, the scan will begin with the given channel and connect to +//| If ``channel`` is non-zero, the scan will begin with the given channel and connect to //| the first AP with the given ``ssid``. This can speed up the connection time //| significantly because a full scan doesn't occur. //| -//| If ``bssid`` is given, the scan will start at the first channel or the one given and +//| If ``bssid`` is given and not None, the scan will start at the first channel or the one given and //| connect to the AP with the given ``bssid`` and ``ssid``.""" //| ... STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_ssid, ARG_password, ARG_channel, ARG_bssid, ARG_timeout }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = mp_const_empty_bytes} }, { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_bssid, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; @@ -404,9 +410,11 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m mp_buffer_info_t password; password.len = 0; - if (args[ARG_password].u_obj != MP_OBJ_NULL) { + if (args[ARG_password].u_obj != mp_const_none) { mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ); - mp_arg_validate_length_range(password.len, 8, 63, MP_QSTR_password); + if (password.len != 0) { + mp_arg_validate_length_range(password.len, 8, 63, MP_QSTR_password); + } } #define MAC_ADDRESS_LENGTH 6 @@ -414,7 +422,7 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m mp_buffer_info_t bssid; bssid.len = 0; // Should probably make sure bssid is just bytes and not something else too - if (args[ARG_bssid].u_obj != MP_OBJ_NULL) { + if (args[ARG_bssid].u_obj != mp_const_none) { mp_get_buffer_raise(args[ARG_bssid].u_obj, &bssid, MP_BUFFER_READ); if (bssid.len != MAC_ADDRESS_LENGTH) { mp_raise_ValueError(translate("Invalid BSSID")); diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 370bdbd917..dbaeb9cce8 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -77,6 +77,8 @@ extern void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabl extern mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname); + +extern void wifi_radio_get_mac_address(wifi_radio_obj_t *self, uint8_t *mac); extern mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_set_mac_address(wifi_radio_obj_t *self, const uint8_t *mac); extern mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self); @@ -91,7 +93,7 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self); -extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections); +extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint32_t authmodes, uint8_t max_connections); extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_start_dhcp_client(wifi_radio_obj_t *self); diff --git a/shared-module/adafruit_pixelbuf/PixelBuf.c b/shared-module/adafruit_pixelbuf/PixelBuf.c index cab97feace..5017ba2f2c 100644 --- a/shared-module/adafruit_pixelbuf/PixelBuf.c +++ b/shared-module/adafruit_pixelbuf/PixelBuf.c @@ -143,8 +143,10 @@ void common_hal_adafruit_pixelbuf_pixelbuf_set_brightness(mp_obj_t self_in, mp_f STATIC uint8_t _pixelbuf_get_as_uint8(mp_obj_t obj) { if (mp_obj_is_small_int(obj)) { return MP_OBJ_SMALL_INT_VALUE(obj); + #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE } else if (mp_obj_is_int(obj)) { return mp_obj_get_int_truncated(obj); + #endif } else if (mp_obj_is_float(obj)) { return (uint8_t)mp_obj_get_float(obj); } @@ -152,50 +154,56 @@ STATIC uint8_t _pixelbuf_get_as_uint8(mp_obj_t obj) { translate("can't convert %q to %q"), mp_obj_get_type_qstr(obj), MP_QSTR_int); } -STATIC void _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t *self, mp_obj_t color, uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *w) { +STATIC color_u _pixelbuf_parse_color(pixelbuf_pixelbuf_obj_t *self, mp_obj_t color) { + color_u result; pixelbuf_byteorder_details_t *byteorder = &self->byteorder; // w is shared between white in NeoPixels and brightness in dotstars (so that DotStars can have // per-pixel brightness). Set the defaults here in case it isn't set below. if (byteorder->is_dotstar) { - *w = 255; + result.w = 255; } else { - *w = 0; + result.w = 0; } if (mp_obj_is_int(color) || mp_obj_is_float(color)) { mp_int_t value = mp_obj_is_int(color) ? mp_obj_get_int_truncated(color) : (mp_int_t)mp_obj_get_float(color); - *r = value >> 16 & 0xff; - *g = (value >> 8) & 0xff; - *b = value & 0xff; + result.r = value >> 16 & 0xff; + result.g = (value >> 8) & 0xff; + result.b = value & 0xff; } else { mp_obj_t *items; size_t len; mp_obj_get_array(color, &len, &items); mp_arg_validate_length_range(len, 3, 4, MP_QSTR_color); - *r = _pixelbuf_get_as_uint8(items[PIXEL_R]); - *g = _pixelbuf_get_as_uint8(items[PIXEL_G]); - *b = _pixelbuf_get_as_uint8(items[PIXEL_B]); + result.r = _pixelbuf_get_as_uint8(items[PIXEL_R]); + result.g = _pixelbuf_get_as_uint8(items[PIXEL_G]); + result.b = _pixelbuf_get_as_uint8(items[PIXEL_B]); if (len > 3) { if (mp_obj_is_float(items[PIXEL_W])) { - *w = 255 * mp_obj_get_float(items[PIXEL_W]); + result.w = 255 * mp_obj_get_float(items[PIXEL_W]); } else { - *w = mp_obj_get_int_truncated(items[PIXEL_W]); + result.w = mp_obj_get_int_truncated(items[PIXEL_W]); } - return; + return result; } } // Int colors can't set white directly so convert to white when all components are equal. // Also handles RGBW values assigned an RGB tuple. - if (!byteorder->is_dotstar && byteorder->bpp == 4 && byteorder->has_white && *r == *g && *r == *b) { - *w = *r; - *r = 0; - *g = 0; - *b = 0; + if (!byteorder->is_dotstar && byteorder->bpp == 4 && byteorder->has_white && result.r == result.g && result.r == result.b) { + result.w = result.r; + result.r = 0; + result.g = 0; + result.b = 0; } + return result; } -STATIC void _pixelbuf_set_pixel_color(pixelbuf_pixelbuf_obj_t *self, size_t index, uint8_t r, uint8_t g, uint8_t b, uint8_t w) { +STATIC void _pixelbuf_set_pixel_color(pixelbuf_pixelbuf_obj_t *self, size_t index, color_u rgbw) { + uint8_t r = rgbw.r; + uint8_t g = rgbw.g; + uint8_t b = rgbw.b; + uint8_t w = rgbw.w; // DotStars don't have white, instead they have 5 bit brightness so pack it into w. Shift right // by three to leave the top five bits. if (self->bytes_per_pixel == 4 && self->byteorder.is_dotstar) { @@ -234,12 +242,8 @@ STATIC void _pixelbuf_set_pixel_color(pixelbuf_pixelbuf_obj_t *self, size_t inde } STATIC void _pixelbuf_set_pixel(pixelbuf_pixelbuf_obj_t *self, size_t index, mp_obj_t value) { - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t w; - _pixelbuf_parse_color(self, value, &r, &g, &b, &w); - _pixelbuf_set_pixel_color(self, index, r, g, b, w); + color_u rgbw = _pixelbuf_parse_color(self, value); + _pixelbuf_set_pixel_color(self, index, rgbw); } void common_hal_adafruit_pixelbuf_pixelbuf_set_pixels(mp_obj_t self_in, size_t start, mp_int_t step, size_t slice_len, mp_obj_t *values, @@ -318,14 +322,10 @@ void common_hal_adafruit_pixelbuf_pixelbuf_show(mp_obj_t self_in) { void common_hal_adafruit_pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t fill_color) { pixelbuf_pixelbuf_obj_t *self = native_pixelbuf(self_in); - uint8_t r; - uint8_t g; - uint8_t b; - uint8_t w; - _pixelbuf_parse_color(self, fill_color, &r, &g, &b, &w); + color_u rgbw = _pixelbuf_parse_color(self, fill_color); for (size_t i = 0; i < self->pixel_count; i++) { - _pixelbuf_set_pixel_color(self, i, r, g, b, w); + _pixelbuf_set_pixel_color(self, i, rgbw); } if (self->auto_write) { common_hal_adafruit_pixelbuf_pixelbuf_show(self_in); diff --git a/shared-module/vectorio/VectorShape.c b/shared-module/vectorio/VectorShape.c index d9c13f54cc..20e1405d9a 100644 --- a/shared-module/vectorio/VectorShape.c +++ b/shared-module/vectorio/VectorShape.c @@ -293,6 +293,16 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self } } +mp_int_t common_hal_vectorio_vector_shape_get_hidden(vectorio_vector_shape_t *self) { + VECTORIO_SHAPE_DEBUG("%p get_hidden\n", self); + return self->hidden; +} + +void common_hal_vectorio_vector_shape_set_hidden(vectorio_vector_shape_t *self, bool hidden) { + VECTORIO_SHAPE_DEBUG("%p set_hidden %d\n", self, x); + self->hidden = hidden; + common_hal_vectorio_vector_shape_set_dirty(self); +} mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader(vectorio_vector_shape_t *self) { VECTORIO_SHAPE_DEBUG("%p get_pixel_shader\n", self); @@ -315,6 +325,11 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ uint64_t start = common_hal_time_monotonic_ns(); uint64_t pixel_time = 0; #endif + + if (self->hidden) { + return false; + } + VECTORIO_SHAPE_DEBUG("%p fill_area: fill: {(%5d,%5d), (%5d,%5d)}", self, area->x1, area->y1, area->x2, area->y2 diff --git a/shared-module/vectorio/VectorShape.h b/shared-module/vectorio/VectorShape.h index fdbae964a8..6ce09f9308 100644 --- a/shared-module/vectorio/VectorShape.h +++ b/shared-module/vectorio/VectorShape.h @@ -37,6 +37,7 @@ typedef struct { displayio_area_t ephemeral_dirty_area; displayio_area_t current_area; bool current_area_dirty; + bool hidden; } vectorio_vector_shape_t; displayio_area_t *vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail); diff --git a/supervisor/fatfs_port.h b/supervisor/fatfs.h similarity index 89% rename from supervisor/fatfs_port.h rename to supervisor/fatfs.h index e76ced524d..59226aae1c 100644 --- a/supervisor/fatfs_port.h +++ b/supervisor/fatfs.h @@ -24,11 +24,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SUPERVISOR_FATFS_PORT_H -#define MICROPY_INCLUDED_SUPERVISOR_FATFS_PORT_H +#ifndef MICROPY_INCLUDED_SUPERVISOR_FATFS_H +#define MICROPY_INCLUDED_SUPERVISOR_FATFS_H #include "lib/oofatfs/ff.h" void override_fattime(DWORD time); -#endif // MICROPY_INCLUDED_SUPERVISOR_FATFS_PORT_H +#endif // MICROPY_INCLUDED_SUPERVISOR_FATFS_H diff --git a/supervisor/shared/bluetooth/file_transfer.c b/supervisor/shared/bluetooth/file_transfer.c index 159c639e4d..ae24c29899 100644 --- a/supervisor/shared/bluetooth/file_transfer.c +++ b/supervisor/shared/bluetooth/file_transfer.c @@ -42,7 +42,7 @@ #include "common-hal/_bleio/__init__.h" -#include "supervisor/fatfs_port.h" +#include "supervisor/fatfs.h" #include "supervisor/filesystem.h" #include "supervisor/shared/reload.h" #include "supervisor/shared/bluetooth/file_transfer.h" diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 8ed2f5c17e..0a066e8016 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -74,11 +74,8 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { scale = 1; } - width_in_tiles = width_px / (scroll_area->tile_width * scale); - if (width_in_tiles < 1) { - width_in_tiles = 1; - } - uint16_t height_in_tiles = height_px / (scroll_area->tile_height * scale); + width_in_tiles = MAX(1, width_px / (scroll_area->tile_width * scale)); + uint16_t height_in_tiles = MAX(2, height_px / (scroll_area->tile_height * scale)); uint16_t total_tiles = width_in_tiles * height_in_tiles; @@ -117,7 +114,6 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { status_bar->top_left_y = 0; status_bar->width_in_tiles = width_in_tiles; status_bar->height_in_tiles = 1; - assert(width_in_tiles > 0); status_bar->pixel_width = width_in_tiles * status_bar->tile_width; status_bar->pixel_height = status_bar->tile_height; status_bar->tiles = tiles; @@ -127,8 +123,6 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { scroll_area->top_left_y = 0; scroll_area->width_in_tiles = width_in_tiles; scroll_area->height_in_tiles = height_in_tiles - 1; - assert(width_in_tiles > 0); - assert(height_in_tiles > 1); scroll_area->pixel_width = width_in_tiles * scroll_area->tile_width; scroll_area->pixel_height = (height_in_tiles - 1) * scroll_area->tile_height; #if CIRCUITPY_REPL_LOGO diff --git a/ports/nrf/fatfs_port.c b/supervisor/shared/fatfs.c similarity index 94% rename from ports/nrf/fatfs_port.c rename to supervisor/shared/fatfs.c index 38c2d923b8..76db02d6bf 100644 --- a/ports/nrf/fatfs_port.c +++ b/supervisor/shared/fatfs.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George + * Copyright (c) 2022 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 @@ -24,12 +24,13 @@ * THE SOFTWARE. */ +#include "supervisor/fatfs.h" + #include "py/runtime.h" #include "lib/oofatfs/ff.h" #include "shared/timeutils/timeutils.h" #include "shared-bindings/rtc/RTC.h" #include "shared-bindings/time/__init__.h" -#include "supervisor/fatfs_port.h" DWORD _time_override = 0; DWORD get_fattime(void) { diff --git a/supervisor/shared/status_leds.c b/supervisor/shared/status_leds.c index 315e64a9a0..7e6c7983b1 100644 --- a/supervisor/shared/status_leds.c +++ b/supervisor/shared/status_leds.c @@ -179,27 +179,15 @@ void status_led_init() { #elif CIRCUITPY_PWM_RGB_LED if (common_hal_mcu_pin_is_free(CIRCUITPY_RGB_STATUS_R)) { - pwmout_result_t red_result = common_hal_pwmio_pwmout_construct(&rgb_status_r, CIRCUITPY_RGB_STATUS_R, 0, 50000, false); - - if (PWMOUT_OK == red_result) { - common_hal_pwmio_pwmout_never_reset(&rgb_status_r); - } + common_hal_pwmio_pwmout_construct(&rgb_status_r, CIRCUITPY_RGB_STATUS_R, 0, 50000, false); } if (common_hal_mcu_pin_is_free(CIRCUITPY_RGB_STATUS_G)) { - pwmout_result_t green_result = common_hal_pwmio_pwmout_construct(&rgb_status_g, CIRCUITPY_RGB_STATUS_G, 0, 50000, false); - - if (PWMOUT_OK == green_result) { - common_hal_pwmio_pwmout_never_reset(&rgb_status_g); - } + common_hal_pwmio_pwmout_construct(&rgb_status_g, CIRCUITPY_RGB_STATUS_G, 0, 50000, false); } if (common_hal_mcu_pin_is_free(CIRCUITPY_RGB_STATUS_B)) { - pwmout_result_t blue_result = common_hal_pwmio_pwmout_construct(&rgb_status_b, CIRCUITPY_RGB_STATUS_B, 0, 50000, false); - - if (PWMOUT_OK == blue_result) { - common_hal_pwmio_pwmout_never_reset(&rgb_status_b); - } + common_hal_pwmio_pwmout_construct(&rgb_status_b, CIRCUITPY_RGB_STATUS_B, 0, 50000, false); } #elif defined(MICROPY_HW_LED_STATUS) diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index a51c6c2659..fa85cddb83 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -341,7 +341,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ #endif // CIRCUITPY_USB_VENDOR -#if MICROPY_KBD_EXCEPTION +#if MICROPY_KBD_EXCEPTION && CIRCUITPY_USB_CDC /** * Callback invoked when received an "wanted" char. @@ -359,4 +359,10 @@ void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) { } } +void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms) { + if (usb_cdc_console_enabled() && mp_interrupt_char != -1 && itf == 0 && duration_ms > 0) { + mp_sched_keyboard_interrupt(); + } +} + #endif diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index 3f0b9ad8f7..3527090f1e 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -24,18 +24,20 @@ * THE SOFTWARE. */ +#include #include #include "extmod/vfs.h" #include "extmod/vfs_fat.h" #include "genhdr/mpversion.h" +#include "py/mperrno.h" #include "py/mpstate.h" #include "py/stackctrl.h" #include "shared-bindings/wifi/Radio.h" #include "shared-module/storage/__init__.h" #include "shared/timeutils/timeutils.h" -#include "supervisor/fatfs_port.h" +#include "supervisor/fatfs.h" #include "supervisor/filesystem.h" #include "supervisor/port.h" #include "supervisor/shared/reload.h" @@ -47,8 +49,12 @@ #include "shared-bindings/hashlib/__init__.h" #include "shared-bindings/hashlib/Hash.h" + +#if CIRCUITPY_MDNS #include "shared-bindings/mdns/RemoteService.h" #include "shared-bindings/mdns/Server.h" +#endif + #include "shared-bindings/microcontroller/Processor.h" #include "shared-bindings/socketpool/__init__.h" #include "shared-bindings/socketpool/Socket.h" @@ -62,11 +68,6 @@ #include "shared-module/dotenv/__init__.h" #endif -// TODO: Remove ESP specific stuff. For now, it is useful as we refine the server. -#include "esp_log.h" - -static const char *TAG = "CP webserver"; - enum request_state { STATE_METHOD, STATE_PATH, @@ -95,6 +96,7 @@ typedef struct { bool expect; bool json; bool websocket; + bool new_socket; uint32_t websocket_version; // RFC6455 for websockets says this header should be 24 base64 characters long. char websocket_key[24 + 1]; @@ -109,7 +111,10 @@ static uint32_t _last_ip = 0; static wifi_radio_error_t _last_wifi_status = WIFI_RADIO_ERROR_NONE; #endif +#if CIRCUITPY_MDNS static mdns_server_obj_t mdns; +#endif + static uint32_t web_api_port = 80; static socketpool_socketpool_obj_t pool; @@ -271,7 +276,7 @@ void supervisor_start_web_workflow(void) { // attempting to connect to the given network. _wifi_status = common_hal_wifi_radio_connect( &common_hal_wifi_radio_obj, (uint8_t *)ssid, ssid_len, (uint8_t *)password, password_len, - 0, 0.1, NULL, 0); + 0, 8, NULL, 0); if (_wifi_status != WIFI_RADIO_ERROR_NONE) { common_hal_wifi_radio_set_enabled(&common_hal_wifi_radio_obj, false); @@ -289,21 +294,20 @@ void supervisor_start_web_workflow(void) { new_port = strtoul(port_encoded, NULL, 10); } - bool first_start = mdns.base.type != &mdns_server_type; + bool first_start = pool.base.type != &socketpool_socketpool_type; bool port_changed = new_port != web_api_port; if (first_start) { - ESP_LOGI(TAG, "Starting web workflow"); + #if CIRCUITPY_MDNS mdns_server_construct(&mdns, true); mdns.base.type = &mdns_server_type; common_hal_mdns_server_set_instance_name(&mdns, MICROPY_HW_BOARD_NAME); + #endif pool.base.type = &socketpool_socketpool_type; common_hal_socketpool_socketpool_construct(&pool, &common_hal_wifi_radio_obj); - listening.base.type = &socketpool_socket_type; - active.base.type = &socketpool_socket_type; - active.num = -1; - active.connected = false; + socketpool_socket_reset(&listening); + socketpool_socket_reset(&active); websocket_init(); } @@ -312,7 +316,9 @@ void supervisor_start_web_workflow(void) { } if (first_start || port_changed) { web_api_port = new_port; + #if CIRCUITPY_MDNS common_hal_mdns_server_advertise_service(&mdns, "_circuitpython", "_tcp", web_api_port); + #endif socketpool_socket(&pool, SOCKETPOOL_AF_INET, SOCKETPOOL_SOCK_STREAM, &listening); common_hal_socketpool_socket_settimeout(&listening, 0); // Bind to any ip. @@ -326,17 +332,13 @@ void supervisor_start_web_workflow(void) { _api_password[api_password_len + 1] = '\0'; _base64_in_place(_api_password, api_password_len + 1, sizeof(_api_password)); } - - // TODO: - // GET /edit/ - // - Super basic editor #endif } void web_workflow_send_raw(socketpool_socket_obj_t *socket, const uint8_t *buf, int len) { int total_sent = 0; - int sent = -EAGAIN; - while ((sent == -EAGAIN || (sent > 0 && total_sent < len)) && + int sent = -MP_EAGAIN; + while ((sent == -MP_EAGAIN || (sent > 0 && total_sent < len)) && common_hal_socketpool_socket_get_connected(socket)) { sent = socketpool_socket_send(socket, buf + total_sent, len - total_sent); if (sent > 0) { @@ -347,9 +349,6 @@ void web_workflow_send_raw(socketpool_socket_obj_t *socket, const uint8_t *buf, } } } - if (total_sent < len) { - ESP_LOGE(TAG, "short send %d %d", sent, len); - } } STATIC void _print_raw(void *env, const char *str, size_t len) { @@ -429,20 +428,21 @@ static bool _endswith(const char *str, const char *suffix) { } const char *ok_hosts[] = { - "code.circuitpython.org", "127.0.0.1", "localhost", }; static bool _origin_ok(const char *origin) { const char *http = "http://"; - const char *local = ".local"; // note: redirected requests send an Origin of "null" and will be caught by this if (strncmp(origin, http, strlen(http)) != 0) { return false; } // These are prefix checks up to : so that any port works. + // TODO: Support DHCP hostname in addition to MDNS. + #if CIRCUITPY_MDNS + const char *local = ".local"; const char *hostname = common_hal_mdns_server_get_hostname(&mdns); const char *end = origin + strlen(http) + strlen(hostname) + strlen(local); if (strncmp(origin + strlen(http), hostname, strlen(hostname)) == 0 && @@ -450,6 +450,9 @@ static bool _origin_ok(const char *origin) { (end[0] == '\0' || end[0] == ':')) { return true; } + #else + const char *end; + #endif _update_encoded_ip(); end = origin + strlen(http) + strlen(_our_ip_encoded); @@ -604,9 +607,10 @@ static void _reply_server_error(socketpool_socket_obj_t *socket, _request *reque _send_str(socket, "\r\n"); } +#if CIRCUITPY_MDNS static void _reply_redirect(socketpool_socket_obj_t *socket, _request *request, const char *path) { int nodelay = 1; - lwip_setsockopt(socket->num, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay)); + common_hal_socketpool_socket_setsockopt(socket, SOCKETPOOL_IPPROTO_TCP, SOCKETPOOL_TCP_NODELAY, &nodelay, sizeof(nodelay)); const char *hostname = common_hal_mdns_server_get_hostname(&mdns); _send_strs(socket, "HTTP/1.1 307 Temporary Redirect\r\n", @@ -628,6 +632,7 @@ static void _reply_redirect(socketpool_socket_obj_t *socket, _request *request, _cors_header(socket, request); _send_str(socket, "\r\n"); } +#endif static void _reply_directory_json(socketpool_socket_obj_t *socket, _request *request, FF_DIR *dir, const char *request_path, const char *path) { socketpool_socket_send(socket, (const uint8_t *)OK_JSON, strlen(OK_JSON)); @@ -710,10 +715,9 @@ static void _reply_with_file(socketpool_socket_obj_t *socket, _request *request, while (send_offset < quantity_read) { int sent = socketpool_socket_send(socket, data_buffer + send_offset, quantity_read - send_offset); if (sent < 0) { - if (sent == -EAGAIN) { + if (sent == -MP_EAGAIN) { sent = 0; } else { - ESP_LOGE(TAG, "file send error %d", sent); break; } } @@ -726,15 +730,20 @@ static void _reply_with_file(socketpool_socket_obj_t *socket, _request *request, } static void _reply_with_devices_json(socketpool_socket_obj_t *socket, _request *request) { + #if CIRCUITPY_MDNS mdns_remoteservice_obj_t found_devices[32]; size_t total_results = mdns_server_find(&mdns, "_circuitpython", "_tcp", 1, found_devices, MP_ARRAY_SIZE(found_devices)); size_t count = MIN(total_results, MP_ARRAY_SIZE(found_devices)); + #else + size_t total_results = 0; + #endif socketpool_socket_send(socket, (const uint8_t *)OK_JSON, strlen(OK_JSON)); _cors_header(socket, request); _send_str(socket, "\r\n"); mp_print_t _socket_print = {socket, _print_chunk}; mp_printf(&_socket_print, "{\"total\": %d, \"devices\": [", total_results); + #if CIRCUITPY_MDNS for (size_t i = 0; i < count; i++) { if (i > 0) { _send_chunk(socket, ","); @@ -751,6 +760,7 @@ static void _reply_with_devices_json(socketpool_socket_obj_t *socket, _request * "\"ip\": \"%d.%d.%d.%d\"}", hostname, instance_name, port, octets[0], octets[1], octets[2], octets[3]); common_hal_mdns_remoteservice_deinit(&found_devices[i]); } + #endif _send_chunk(socket, "]}"); // Empty chunk signals the end of the response. _send_chunk(socket, ""); @@ -762,7 +772,11 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request * _send_str(socket, "\r\n"); mp_print_t _socket_print = {socket, _print_chunk}; + #if CIRCUITPY_MDNS const char *hostname = common_hal_mdns_server_get_hostname(&mdns); + #else + const char *hostname = ""; + #endif _update_encoded_ip(); // Note: this leverages the fact that C concats consecutive string literals together. mp_printf(&_socket_print, @@ -848,7 +862,6 @@ static void _write_file_and_reply(socketpool_socket_obj_t *socket, _request *req return; } if (result != FR_OK) { - ESP_LOGE(TAG, "file write error %d %s", result, path); override_fattime(0); #if CIRCUITPY_USB_MSC usb_msc_unlock(); @@ -888,19 +901,13 @@ static void _write_file_and_reply(socketpool_socket_obj_t *socket, _request *req size_t read_len = MIN(sizeof(bytes), request->content_length - total_read); int len = socketpool_socket_recv_into(socket, bytes, read_len); if (len < 0) { - if (len == -EAGAIN) { + if (len == -MP_EAGAIN) { continue; - } else { - ESP_LOGE(TAG, "other error %d", len); } error = true; break; } - UINT actual; - f_write(&active_file, bytes, len, &actual); - if (actual != (UINT)len) { - ESP_LOGE(TAG, "didn't write whole file"); - } + f_write(&active_file, bytes, len, NULL); total_read += len; } @@ -934,7 +941,7 @@ STATIC_FILE(blinka_16x16_ico); static void _reply_static(socketpool_socket_obj_t *socket, _request *request, const uint8_t *response, size_t response_len, const char *content_type) { uint32_t total_length = response_len; char encoded_len[10]; - snprintf(encoded_len, sizeof(encoded_len), "%d", total_length); + snprintf(encoded_len, sizeof(encoded_len), "%" PRIu32, total_length); _send_strs(socket, "HTTP/1.1 200 OK\r\n", @@ -1004,9 +1011,10 @@ static void _decode_percents(char *str) { static bool _reply(socketpool_socket_obj_t *socket, _request *request) { if (request->redirect) { + #if CIRCUITPY_MDNS _reply_redirect(socket, request, request->path); + #endif } else if (strlen(request->origin) > 0 && !_origin_ok(request->origin)) { - ESP_LOGE(TAG, "bad origin %s", request->origin); _reply_forbidden(socket, request); } else if (strncmp(request->path, "/fs/", 4) == 0) { if (strcasecmp(request->method, "OPTIONS") == 0) { @@ -1061,7 +1069,6 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { if (result == FR_NO_PATH || result == FR_NO_FILE) { _reply_missing(socket, request); } else if (result != FR_OK) { - ESP_LOGE(TAG, "rm error %d %s", result, path); _reply_server_error(socket, request); } else { _reply_no_content(socket, request); @@ -1089,7 +1096,6 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { } else if (result == FR_NO_PATH || result == FR_NO_FILE) { // Missing higher directories or target file. _reply_missing(socket, request); } else if (result != FR_OK) { - ESP_LOGE(TAG, "move error %d %s", result, path); _reply_server_error(socket, request); } else { _reply_created(socket, request); @@ -1137,7 +1143,6 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { } else if (result == FR_NO_PATH) { _reply_missing(socket, request); } else if (result != FR_OK) { - ESP_LOGE(TAG, "mkdir error %d %s", result, path); _reply_server_error(socket, request); } else { _reply_created(socket, request); @@ -1237,6 +1242,7 @@ static void _reset_request(_request *request) { request->redirect = false; request->done = false; request->in_progress = false; + request->new_socket = false; request->authenticated = false; request->expect = false; request->json = false; @@ -1257,6 +1263,7 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request) if (!request->in_progress) { autoreload_suspend(AUTORELOAD_SUSPEND_WEB); request->in_progress = true; + request->new_socket = false; } switch (request->state) { case STATE_METHOD: { @@ -1276,7 +1283,6 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request) if (c == ' ') { request->path[request->offset] = '\0'; request->offset = 0; - ESP_LOGI(TAG, "Request %s %s", request->method, request->path); request->state = STATE_VERSION; } else if (request->offset > sizeof(request->path) - 1) { // Skip methods that are too long. @@ -1352,7 +1358,6 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request) } else if (strcasecmp(request->header_key, "X-Destination") == 0) { strcpy(request->destination, request->header_value); } - ESP_LOGI(TAG, "Header %s %s", request->header_key, request->header_value); } else if (request->offset > sizeof(request->header_value) - 1) { // Skip methods that are too long. } else { @@ -1369,8 +1374,9 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request) } if (error) { const char *error_response = "HTTP/1.1 501 Not Implemented\r\n\r\n"; + int nodelay = 1; - lwip_setsockopt(socket->num, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay)); + common_hal_socketpool_socket_setsockopt(socket, SOCKETPOOL_IPPROTO_TCP, SOCKETPOOL_TCP_NODELAY, &nodelay, sizeof(nodelay)); socketpool_socket_send(socket, (const uint8_t *)error_response, strlen(error_response)); } if (!request->done) { @@ -1386,45 +1392,44 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request) void supervisor_web_workflow_background(void) { - // Otherwise, see if we have another socket to accept. - if ((!common_hal_socketpool_socket_get_connected(&active) || !active_request.in_progress) && - !common_hal_socketpool_socket_get_closed(&listening) && - listening.num > 0) { - uint32_t ip; - uint32_t port; - int newsoc = socketpool_socket_accept(&listening, (uint8_t *)&ip, &port); - if (newsoc == -EBADF) { - common_hal_socketpool_socket_close(&listening); - return; + // Track if we have more to do. For example, we should start processing a + // request immediately after we accept the socket. + bool more_to_do = true; + while (more_to_do) { + more_to_do = false; + // If we have a request in progress, continue working on it. Do this first + // so that we can accept another socket after finishing this request. + if (common_hal_socketpool_socket_get_connected(&active)) { + _process_request(&active, &active_request); + } else { + // Close the active socket if it is no longer connected. + common_hal_socketpool_socket_close(&active); } - if (newsoc > 0) { - // Close the active socket because we have another we accepted. - if (!common_hal_socketpool_socket_get_closed(&active)) { - common_hal_socketpool_socket_close(&active); + + // Otherwise, see if we have another socket to accept. + if ((!common_hal_socketpool_socket_get_connected(&active) || + (!active_request.in_progress && !active_request.new_socket)) && + !common_hal_socketpool_socket_get_closed(&listening)) { + uint32_t ip; + uint32_t port; + int newsoc = socketpool_socket_accept(&listening, (uint8_t *)&ip, &port, &active); + if (newsoc == -EBADF) { + common_hal_socketpool_socket_close(&listening); + return; } - // TODO: Don't do this because it uses the private struct layout. - // Create the socket - active.num = newsoc; - active.pool = &pool; - active.connected = true; + if (newsoc > 0) { + common_hal_socketpool_socket_settimeout(&active, 0); - common_hal_socketpool_socket_settimeout(&active, 0); - - _reset_request(&active_request); - - lwip_fcntl(newsoc, F_SETFL, O_NONBLOCK); + _reset_request(&active_request); + // Mark new sockets, otherwise we may accept another before the first + // could start its request. + active_request.new_socket = true; + more_to_do = true; + } } - } - // If we have a request in progress, continue working on it. - if (common_hal_socketpool_socket_get_connected(&active)) { - _process_request(&active, &active_request); - } else { - // Close the active socket if it is no longer connected. - common_hal_socketpool_socket_close(&active); + websocket_background(); } - - websocket_background(); } void supervisor_stop_web_workflow(void) { diff --git a/supervisor/shared/web_workflow/websocket.c b/supervisor/shared/web_workflow/websocket.c index 3901c4eefe..9d1cf9919f 100644 --- a/supervisor/shared/web_workflow/websocket.c +++ b/supervisor/shared/web_workflow/websocket.c @@ -29,15 +29,13 @@ #include "py/ringbuf.h" #include "py/runtime.h" #include "shared/runtime/interrupt_char.h" +#include "shared-bindings/socketpool/SocketPool.h" #include "supervisor/shared/web_workflow/web_workflow.h" #if CIRCUITPY_STATUS_BAR #include "supervisor/shared/status_bar.h" #endif -// TODO: Remove ESP specific stuff. For now, it is useful as we refine the server. -#include "esp_log.h" - typedef struct { socketpool_socket_obj_t socket; uint8_t opcode; @@ -57,24 +55,18 @@ STATIC uint8_t _buf[16]; static _websocket cp_serial; -static const char *TAG = "CP websocket"; - void websocket_init(void) { - cp_serial.socket.num = -1; - cp_serial.socket.connected = false; + socketpool_socket_reset(&cp_serial.socket); ringbuf_init(&_incoming_ringbuf, _buf, sizeof(_buf) - 1); } void websocket_handoff(socketpool_socket_obj_t *socket) { - cp_serial.socket = *socket; + socketpool_socket_move(socket, &cp_serial.socket); cp_serial.closed = false; cp_serial.opcode = 0; cp_serial.frame_index = 0; cp_serial.frame_len = 2; - // Mark the original socket object as closed without telling the lower level. - socket->connected = false; - socket->num = -1; #if CIRCUITPY_STATUS_BAR // Send the title bar for the new client. @@ -89,9 +81,6 @@ bool websocket_connected(void) { static bool _read_byte(uint8_t *c) { int len = socketpool_socket_recv_into(&cp_serial.socket, c, 1); if (len != 1) { - if (len != -EAGAIN) { - ESP_LOGE(TAG, "recv error %d", len); - } return false; } return true; @@ -147,13 +136,10 @@ static void _read_next_frame_header(void) { // Set the TCP socket to send immediately so that we send the payload back before // closing the connection. int nodelay = 1; - lwip_setsockopt(cp_serial.socket.num, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay)); + common_hal_socketpool_socket_setsockopt(&cp_serial.socket, SOCKETPOOL_IPPROTO_TCP, SOCKETPOOL_TCP_NODELAY, &nodelay, sizeof(nodelay)); } uint8_t frame_header[2]; frame_header[0] = 1 << 7 | opcode; - if (cp_serial.payload_remaining > 125) { - ESP_LOGE(TAG, "CLOSE or PING has long payload"); - } frame_header[1] = cp_serial.payload_remaining; web_workflow_send_raw(&cp_serial.socket, (const uint8_t *)frame_header, 2); } diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index a8deb9606d..801025f41a 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -4,6 +4,7 @@ SRC_SUPERVISOR = \ supervisor/shared/background_callback.c \ supervisor/shared/board.c \ supervisor/shared/cpu.c \ + supervisor/shared/fatfs.c \ supervisor/shared/flash.c \ supervisor/shared/lock.c \ supervisor/shared/memory.c \ diff --git a/tests/basics/exception_chain.py b/tests/basics/exception_chain.py index c3a7d6b113..b84ff19dd6 100644 --- a/tests/basics/exception_chain.py +++ b/tests/basics/exception_chain.py @@ -1,6 +1,54 @@ -# Exception chaining is not supported, but check that basic -# exception works as expected. try: - raise Exception from None -except Exception: - print("Caught Exception") + Exception().__cause__ +except AttributeError: + print("SKIP") + raise SystemExit + +def print_exc_info(e): + print("exception", type(e), e.args) + print("context", type(e.__context__), e.__suppress_context__) + print("cause", type(e.__cause__)) + +try: + try: + 1/0 + except Exception as inner: + raise RuntimeError() from inner +except Exception as e: + print_exc_info(e) +print() + +try: + try: + 1/0 + except Exception as inner: + raise RuntimeError() from OSError() +except Exception as e: + print_exc_info(e) +print() + + +try: + try: + 1/0 + except Exception as inner: + raise RuntimeError() +except Exception as e: + print_exc_info(e) +print() + +try: + try: + 1/0 + except Exception as inner: + raise RuntimeError() from None +except Exception as e: + print_exc_info(e) + +try: + try: + raise RuntimeError() + except Exception as inner: + 1/0 +except Exception as e: + print_exc_info(e) diff --git a/tests/basics/exception_chain.py.exp b/tests/basics/exception_chain.py.exp deleted file mode 100644 index 13635b3cde..0000000000 --- a/tests/basics/exception_chain.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -Warning: exception chaining not supported -Caught Exception diff --git a/tests/circuitpython/traceback_test_chained.py b/tests/circuitpython/traceback_test_chained.py new file mode 100644 index 0000000000..83d0c03466 --- /dev/null +++ b/tests/circuitpython/traceback_test_chained.py @@ -0,0 +1,63 @@ +try: + Exception().__cause__ +except AttributeError: + print("SKIP") + raise SystemExit + +try: + import traceback +except: + print("SKIP") + raise SystemExit + + +def print_exc_info(e): + print("-" * 72) + traceback.print_exception(None, e, e.__traceback__) + print("-" * 72) + print() + + +try: + try: + 1 / 0 + except Exception as inner: + raise RuntimeError() from inner +except Exception as e: + print_exc_info(e) +print() + +try: + try: + 1 / 0 + except Exception as inner: + raise RuntimeError() from OSError() +except Exception as e: + print_exc_info(e) +print() + + +try: + try: + 1 / 0 + except Exception as inner: + raise RuntimeError() +except Exception as e: + print_exc_info(e) +print() + +try: + try: + 1 / 0 + except Exception as inner: + raise RuntimeError() from None +except Exception as e: + print_exc_info(e) + +try: + try: + raise RuntimeError() + except Exception as inner: + 1 / 0 +except Exception as e: + print_exc_info(e) diff --git a/tests/circuitpython/traceback_test_chained.py.exp b/tests/circuitpython/traceback_test_chained.py.exp new file mode 100644 index 0000000000..c874ff707f --- /dev/null +++ b/tests/circuitpython/traceback_test_chained.py.exp @@ -0,0 +1,55 @@ +------------------------------------------------------------------------ +Traceback (most recent call last): + File "circuitpython/traceback_test_chained.py", line 23, in +ZeroDivisionError: division by zero + +The above exception was the direct cause of the following exception: + +Traceback (most recent call last): + File "circuitpython/traceback_test_chained.py", line 25, in +RuntimeError: +------------------------------------------------------------------------ + + +------------------------------------------------------------------------ +OSError: + +The above exception was the direct cause of the following exception: + +Traceback (most recent call last): + File "circuitpython/traceback_test_chained.py", line 34, in +RuntimeError: +------------------------------------------------------------------------ + + +------------------------------------------------------------------------ +Traceback (most recent call last): + File "circuitpython/traceback_test_chained.py", line 42, in +ZeroDivisionError: division by zero + +During handling of the above exception, another exception occurred: + +Traceback (most recent call last): + File "circuitpython/traceback_test_chained.py", line 44, in +RuntimeError: +------------------------------------------------------------------------ + + +------------------------------------------------------------------------ +Traceback (most recent call last): + File "circuitpython/traceback_test_chained.py", line 53, in +RuntimeError: +------------------------------------------------------------------------ + +------------------------------------------------------------------------ +Traceback (most recent call last): + File "circuitpython/traceback_test_chained.py", line 59, in +RuntimeError: + +During handling of the above exception, another exception occurred: + +Traceback (most recent call last): + File "circuitpython/traceback_test_chained.py", line 61, in +ZeroDivisionError: division by zero +------------------------------------------------------------------------ + diff --git a/tests/run-tests.py b/tests/run-tests.py index ed0cf18e45..7a7b3adbcb 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -522,8 +522,12 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add("basics/scope_implicit.py") # requires checking for unbound local skip_tests.add("basics/try_finally_return2.py") # requires raise_varargs skip_tests.add("basics/unboundlocal.py") # requires checking for unbound local - skip_tests.add( - "circuitpython/traceback_test.py" + skip_tests.update( + ( + "basics/chained_exception.py", + "circuitpython/traceback_test.py", + "circuitpython/traceback_test_chained.py", + ) ) # because native doesn't have proper traceback info skip_tests.add("extmod/uasyncio_event.py") # unknown issue skip_tests.add("extmod/uasyncio_lock.py") # requires async with diff --git a/tools/ci_changes_per_commit.py b/tools/ci_changes_per_commit.py new file mode 100644 index 0000000000..e38c98f40e --- /dev/null +++ b/tools/ci_changes_per_commit.py @@ -0,0 +1,233 @@ +#! /usr/bin/env python3 + +# SPDX-FileCopyrightText: 2021 microDev +# +# SPDX-License-Identifier: MIT + +# GraphQL Query + +QUERY_COMMITS = """ +query ($owner: String!, $name: String!, $pullNumber: Int!, $commitsPerPage: Int!, $beforeCommit: String) { + repository(owner: $owner, name: $name) { + pullRequest(number: $pullNumber) { + commits(last: $commitsPerPage, before: $beforeCommit) { + totalCount + pageInfo { + startCursor + hasPreviousPage + } + nodes { + commit { + checkSuites(first: 3) { + nodes { + conclusion + workflowRun { + workflow { + name + } + } + id + } + totalCount + } + oid + } + } + } + } + } +} +""" + +QUERY_CHECKRUNS = """ +query ($checkSuiteID: ID!, + $afterFailedRun: String, $afterIncompleteRun: String, + $includeFailedRuns: Boolean!, $includeIncompleteRuns: Boolean!) { + node(id: $checkSuiteID) { + ... on CheckSuite { + failedRuns: checkRuns( + first: 100 + after: $afterFailedRun + filterBy: {checkType: LATEST, conclusions: [ACTION_REQUIRED, TIMED_OUT, CANCELLED, FAILURE, NEUTRAL, STARTUP_FAILURE]} + ) @include(if: $includeFailedRuns) { + nodes { + name + } + pageInfo { + endCursor + hasNextPage + } + } + incompleteRuns: checkRuns( + first: 100 + after: $afterIncompleteRun + filterBy: {checkType: LATEST, statuses: [QUEUED, IN_PROGRESS, WAITING, PENDING, REQUESTED]} + ) @include(if: $includeIncompleteRuns) { + nodes { + name + } + pageInfo { + endCursor + hasNextPage + } + } + } + } +} +""" + + +import os +import re +import json +import requests + + +query_variables_commits = { + "owner": "", + "name": "", + "pullNumber": int(os.environ["PULL"]), + "commitsPerPage": 20, + "beforeCommit": None, +} + + +query_variables_checkruns = { + "checkSuiteID": "", + "afterFailedRun": None, + "afterIncompleteRun": None, + "includeFailedRuns": True, + "includeIncompleteRuns": True, +} + + +headers = {"Authorization": f"Bearer {os.environ['GITHUB_TOKEN']}"} + + +class Query: + def __init__(self, query, variables={}, headers={}): + self.query = query + self.variables = variables + self.headers = headers + + def paginate(self, page_info, name): + has_page = ( + page_info["hasNextPage"] if name.startswith("after") else page_info["hasPreviousPage"] + ) + if has_page: + self.variables[name] = ( + page_info["endCursor"] if name.startswith("after") else page_info["startCursor"] + ) + return has_page + + def fetch(self): + request = requests.post( + "https://api.github.com/graphql", + json={"query": self.query, "variables": self.variables}, + headers=self.headers, + ) + if request.status_code == 200: + return request.json() + else: + print(request.json()) + raise Exception("Query Failed: {}".format(request.status_code)) + + +def set_output(name, value): + if "GITHUB_OUTPUT" in os.environ: + with open(os.environ["GITHUB_OUTPUT"], "at") as f: + print(f"{name}={value}", file=f) + else: + print(f"Would set GitHub actions output {name} to '{value}'") + + +def get_commit_and_checksuite(query_commits): + commits = query_commits.fetch()["data"]["repository"]["pullRequest"]["commits"] + + if commits["totalCount"] > 0: + for commit in reversed(commits["nodes"]): + commit = commit["commit"] + commit_sha = commit["oid"] + if commit_sha == os.environ["EXCLUDE_COMMIT"]: + continue + checksuites = commit["checkSuites"] + if checksuites["totalCount"] > 0: + for checksuite in checksuites["nodes"]: + if checksuite["workflowRun"]["workflow"]["name"] == "Build CI": + return [ + commit_sha, + checksuite["id"] if checksuite["conclusion"] != "SUCCESS" else None, + ] + else: + if query_commits.paginate(commits["pageInfo"], "beforeCommit"): + return get_commit_and_checksuite(query_commits) + + return [None, None] + + +def append_runs_to_list(runs, bad_runs_by_matrix): + regex_matrix = re.compile("^build-[^ ]+") + regex_board = re.compile("\([^ ]+\)$") + for run in runs["nodes"]: + name = run["name"] + res_matrix = regex_matrix.search(name) + if res_matrix: + matrix = res_matrix.group() + if matrix not in bad_runs_by_matrix: + bad_runs_by_matrix[matrix] = [] + res_board = regex_board.search(name) + if res_board: + bad_runs_by_matrix[matrix].append(res_board.group()[1:-1]) + + +def get_bad_checkruns(query_checkruns): + more_pages = True + bad_runs_by_matrix = {} + while more_pages: + checkruns = query_checkruns.fetch()["data"]["node"] + run_types = ["failed", "incomplete"] + more_pages = False + + for run_type in run_types: + run_type_camel = run_type.capitalize() + "Run" + run_type = run_type + "Runs" + + append_runs_to_list(checkruns[run_type], bad_runs_by_matrix) + + if query_checkruns.paginate(checkruns[run_type]["pageInfo"], "after" + run_type_camel): + query_checkruns.variables["include" + run_type_camel] = True + more_pages = True + + return bad_runs_by_matrix + + +def main(): + query_commits = Query(QUERY_COMMITS, query_variables_commits, headers) + query_commits.variables["owner"], query_commits.variables["name"] = os.environ["REPO"].split( + "/" + ) + + commit, checksuite = get_commit_and_checksuite(query_commits) + + if checksuite is None: + if commit is None: + print("No checkSuites found -> Abort") + else: + set_output("commit", commit) + quit() + + query_checkruns = Query(QUERY_CHECKRUNS, query_variables_checkruns, headers) + query_checkruns.variables["checkSuiteID"] = checksuite + + checkruns = get_bad_checkruns(query_checkruns) + + if len(checkruns) == 0: + print("No checkRuns found -> Abort") + quit() + + set_output("commit", commit) + set_output("checkruns", json.dumps(checkruns)) + + +if __name__ == "__main__": + main() diff --git a/tools/ci_set_matrix.py b/tools/ci_set_matrix.py index f22840fad7..aeb24b9931 100755 --- a/tools/ci_set_matrix.py +++ b/tools/ci_set_matrix.py @@ -25,7 +25,6 @@ import re import os import sys import json -import yaml import pathlib from concurrent.futures import ThreadPoolExecutor @@ -62,6 +61,7 @@ IGNORE = [ if len(sys.argv) > 1: print("Using files list on commandline") changed_files = sys.argv[1:] + last_failed_jobs = {} else: c = os.environ["CHANGED_FILES"] if c == "": @@ -69,7 +69,14 @@ else: changed_files = [] else: print("Using files list in CHANGED_FILES") - changed_files = json.loads(os.environ["CHANGED_FILES"]) + changed_files = json.loads(c.replace("\\", "")) + + 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) def set_output(name, value): @@ -208,10 +215,21 @@ def set_boards_to_build(build_all): # Set the step outputs for each architecture for arch in arch_to_boards: + # Append previous failed jobs + if f"build-{arch}" in last_failed_jobs: + failed_boards = last_failed_jobs[f"build-{arch}"] + for board in failed_boards: + if not board in arch_to_boards[arch]: + print(" ", board) + arch_to_boards[arch].append(board) + # Set Output set_output(f"boards-{arch}", json.dumps(sorted(arch_to_boards[arch]))) def set_docs_to_build(build_all): + if "build-doc" in last_failed_jobs: + build_all = True + doc_match = build_all if not build_all: doc_pattern = re.compile( @@ -224,7 +242,7 @@ def set_docs_to_build(build_all): # Set the step outputs print("Building docs:", doc_match) - set_output(f"build-doc", doc_match) + set_output("build-doc", doc_match) def check_changed_files():