diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0b23f4538e..5cbf8abc15 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -154,8 +154,24 @@ jobs: with: name: mpy-cross-macos-catalina path: mpy-cross/mpy-cross + - name: Select SDK for M1 build + run: sudo xcode-select -switch /Applications/Xcode_12.3.app + - name: Build mpy-cross (arm64) + run: make -C mpy-cross -j2 -f Makefile.m1 V=2 + - uses: actions/upload-artifact@v2 + with: + name: mpy-cross-macos-bigsur-arm64 + path: mpy-cross/mpy-cross-arm64 + - name: Make universal binary + run: lipo -create -output mpy-cross-macos-universal mpy-cross/mpy-cross mpy-cross/mpy-cross-arm64 + - uses: actions/upload-artifact@v2 + with: + name: mpy-cross-macos-universal + path: mpy-cross-macos-universal - name: Upload mpy-cross build to S3 run: | + [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross-macos-universal s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross-macos-universal-${{ env.CP_VERSION }} --no-progress --region us-east-1 + [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross-arm64 s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross-macos-bigsur-${{ env.CP_VERSION }}-arm64 --no-progress --region us-east-1 [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross-macos-catalina-${{ env.CP_VERSION }} --no-progress --region us-east-1 env: AWS_PAGER: '' @@ -212,6 +228,7 @@ jobs: - "cp_sapling_m0" - "cp_sapling_m0_revb" - "cp_sapling_m0_spiflash" + - "cytron_maker_pi_rp2040" - "datalore_ip_m4" - "datum_distance" - "datum_imu" @@ -291,6 +308,7 @@ jobs: - "pewpew_m4" - "picoplanet" - "pimoroni_keybow2040" + - "pimoroni_pga2040" - "pimoroni_picolipo_16mb" - "pimoroni_picolipo_4mb" - "pimoroni_picosystem" @@ -330,6 +348,7 @@ jobs: - "sparkfun_redboard_turbo" - "sparkfun_samd21_dev" - "sparkfun_samd21_mini" + - "sparkfun_samd51_micromod" - "sparkfun_samd51_thing_plus" - "sparkfun_thing_plus_rp2040" - "spresense" @@ -472,7 +491,8 @@ jobs: - "franzininho_wifi_wrover" - "lilygo_ttgo_t8_s2_st7789" - "microdev_micro_s2" - - "muselab_nanoesp32_s2" + - "muselab_nanoesp32_s2_wroom" + - "muselab_nanoesp32_s2_wrover" - "targett_module_clip_wroom" - "targett_module_clip_wrover" - "unexpectedmaker_feathers2" diff --git a/.github/workflows/ports_windows.yml b/.github/workflows/ports_windows.yml new file mode 100644 index 0000000000..2347902f7b --- /dev/null +++ b/.github/workflows/ports_windows.yml @@ -0,0 +1,106 @@ +name: windows port + +on: + push: + pull_request: + paths: + - '.github/workflows/*.yml' + - 'tools/**' + - 'py/**' + - 'extmod/**' + - 'lib/**' + - 'ports/unix/**' + - 'ports/windows/**' + +jobs: + build: + runs-on: windows-2019 + defaults: + run: + # We define a custom shell script here, although `msys2.cmd` does neither exist nor is it available in the PATH yet + shell: msys2 {0} + steps: + + # We want to change the configuration of the git command that actions/checkout will be using (since it is not possible to set autocrlf through the action yet, see actions/checkout#226). + - run: git config --global core.autocrlf input + shell: bash + + - name: Check python coding (cmd) + run: | + python -c "import sys, locale; print(sys.getdefaultencoding(), locale.getpreferredencoding(False))" + shell: cmd + + # We use a JS Action, which calls the system terminal or other custom terminals directly, if required + - uses: msys2/setup-msys2@v2 + with: + update: true + install: base-devel git wget unzip gcc python-pip + + # The goal of this was to test how things worked when the default file + # encoding (locale.getpreferedencoding()) was not UTF-8. However, msys2 + # python does use utf-8 as the preferred file encoding, and using + # actions/setup-python python3.8 gave a broken build, so we're not really + # testing what we wanted to test. + # + # however, commandline length limits are being tested so that does some + # good. + - name: Check python coding (msys2) + run: | + locale -v + which python; python --version + python -c "import sys, locale; print(sys.getdefaultencoding(), locale.getpreferredencoding(False))" + which python3; python3 --version + python3 -c "import sys, locale; print(sys.getdefaultencoding(), locale.getpreferredencoding(False))" + + - name: Install dependencies + run: | + wget --no-verbose -O gcc-arm.zip https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-win32.zip + unzip -q -d /tmp gcc-arm.zip + tar -C /tmp/gcc-arm-none-* -cf - . | tar -C /usr/local -xf - + pip install wheel + # requirements_dev.txt doesn't install on windows. (with msys2 python) + # instead, pick a subset for what we want to do + pip install cascadetoml jinja2 typer + # check that installed packages work....? + which python; python --version; python -c "import cascadetoml" + which python3; python3 --version; python3 -c "import cascadetoml" + + - uses: actions/checkout@v2 + with: + submodules: true + fetch-depth: 0 + + - run: git fetch --recurse-submodules=no https://github.com/adafruit/circuitpython refs/tags/*:refs/tags/* + - name: CircuitPython version + run: | + git describe --dirty --tags + echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags) + + - name: build mpy-cross + run: make -j2 -C mpy-cross + + - name: build rp2040 + run: make -j2 -C ports/raspberrypi BOARD=adafruit_feather_rp2040 TRANSLATION=de_DE + + - name: build samd21 + run: make -j2 -C ports/atmel-samd BOARD=feather_m0_express TRANSLATION=zh_Latn_pinyin + + - name: build samd51 + run: make -j2 -C ports/atmel-samd BOARD=feather_m4_express TRANSLATION=es + + - name: build nrf + run: make -j2 -C ports/nrf BOARD=feather_nrf52840_express TRANSLATION=fr + + - name: build stm + run: make -j2 -C ports/stm BOARD=feather_stm32f405_express TRANSLATION=pt_BR + +# I gave up trying to do esp32 builds on windows when I saw +# ERROR: Platform MINGW64_NT-10.0-17763-x86_64 appears to be unsupported +# https://github.com/espressif/esp-idf/issues/7062 +# +# - name: prepare esp +# run: ports/esp32s2/esp-idf/install.bat +# shell: cmd +# +# - name: build esp +# run: . ports/esp32s2/esp-idf/export.sh && make -j2 -C ports/esp32s2 BOARD=adafruit_metro_esp32s2 diff --git a/.gitmodules b/.gitmodules index 24ba2e2f6f..55fce0eebb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -184,3 +184,6 @@ [submodule "frozen/Adafruit_CircuitPython_MIDI"] path = frozen/Adafruit_CircuitPython_MIDI url = https://github.com/adafruit/Adafruit_CircuitPython_MIDI +[submodule "frozen/Adafruit_CircuitPython_SimpleIO"] + path = frozen/Adafruit_CircuitPython_SimpleIO + url = https://github.com/adafruit/adafruit_circuitpython_simpleio diff --git a/frozen/Adafruit_CircuitPython_DotStar b/frozen/Adafruit_CircuitPython_DotStar index 8ece81d95a..f376fcca8c 160000 --- a/frozen/Adafruit_CircuitPython_DotStar +++ b/frozen/Adafruit_CircuitPython_DotStar @@ -1 +1 @@ -Subproject commit 8ece81d95a62c2aa84a7f4d5ebaef362bbbabc45 +Subproject commit f376fcca8c829b1e68236edbef6b71cb57f7e42f diff --git a/frozen/Adafruit_CircuitPython_ESP32SPI b/frozen/Adafruit_CircuitPython_ESP32SPI index d3e7a587a2..61e38631b5 160000 --- a/frozen/Adafruit_CircuitPython_ESP32SPI +++ b/frozen/Adafruit_CircuitPython_ESP32SPI @@ -1 +1 @@ -Subproject commit d3e7a587a2f974251f44254fae88c14a52229979 +Subproject commit 61e38631b557a51376edbd02501ca51311631597 diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index de68b7d457..78b0fbbb00 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit de68b7d4575151c1648c734559e59c2932965939 +Subproject commit 78b0fbbb00c0431042b460fe20a76bbc440c4793 diff --git a/frozen/Adafruit_CircuitPython_NeoPixel b/frozen/Adafruit_CircuitPython_NeoPixel index bdef506ca4..a8e9975b3f 160000 --- a/frozen/Adafruit_CircuitPython_NeoPixel +++ b/frozen/Adafruit_CircuitPython_NeoPixel @@ -1 +1 @@ -Subproject commit bdef506ca48a50607ad6a3e5a9c7cc2c9ace0e42 +Subproject commit a8e9975b3f06d454f8951254d96f99755b11d962 diff --git a/frozen/Adafruit_CircuitPython_ProgressBar b/frozen/Adafruit_CircuitPython_ProgressBar index 7b617d33ee..7193260344 160000 --- a/frozen/Adafruit_CircuitPython_ProgressBar +++ b/frozen/Adafruit_CircuitPython_ProgressBar @@ -1 +1 @@ -Subproject commit 7b617d33ee5746140aa38edec001f4f5c31167ce +Subproject commit 7193260344306337050a165bdee4f9d0de7bb8e9 diff --git a/frozen/Adafruit_CircuitPython_SimpleIO b/frozen/Adafruit_CircuitPython_SimpleIO new file mode 160000 index 0000000000..9b53bebc52 --- /dev/null +++ b/frozen/Adafruit_CircuitPython_SimpleIO @@ -0,0 +1 @@ +Subproject commit 9b53bebc520d70f89d44fc989fc493d5036df925 diff --git a/frozen/Adafruit_CircuitPython_seesaw b/frozen/Adafruit_CircuitPython_seesaw index 6467edbed5..3c47a7323f 160000 --- a/frozen/Adafruit_CircuitPython_seesaw +++ b/frozen/Adafruit_CircuitPython_seesaw @@ -1 +1 @@ -Subproject commit 6467edbed535484ebdd7492d885adf3433fb8280 +Subproject commit 3c47a7323f81e961b06853814964d04db5b3817b diff --git a/lib/protomatter b/lib/protomatter index 98017c5734..7fe6406aff 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit 98017c57349e259fab70c6a7830436b19a55f6f4 +Subproject commit 7fe6406affb1376193102cf76ded06e61316d7e6 diff --git a/locale/ID.po b/locale/ID.po index f0e702b7f0..f8ea996124 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -94,6 +94,10 @@ msgstr "indeks %q harus bilangan bulat, bukan %s" msgid "%q list must be a list" msgstr "daftar %q harus berupa daftar" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -111,7 +115,7 @@ msgid "%q must be >= 1" msgstr "%q harus >= 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index a710b1effb..0031641588 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -87,6 +87,10 @@ msgstr "" msgid "%q list must be a list" msgstr "" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -104,7 +108,7 @@ msgid "%q must be >= 1" msgstr "" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/cs.po b/locale/cs.po index aebc210b81..902d0e9254 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -90,6 +90,10 @@ msgstr "Indexy %q musí být celá čísla, nikoli %s" msgid "%q list must be a list" msgstr "Seznam %q musí být seznam" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -107,7 +111,7 @@ msgid "%q must be >= 1" msgstr "%q musí být > = 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/de_DE.po b/locale/de_DE.po index 12a9112722..ea3fed6ea8 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -95,6 +95,10 @@ msgstr "%q Indizes müssen Integer sein, nicht %s" msgid "%q list must be a list" msgstr "%q Liste muss eine Liste sein" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -112,7 +116,7 @@ msgid "%q must be >= 1" msgstr "%q muss >= 1 sein" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/el.po b/locale/el.po index 3430bb0078..5203a4d6a9 100644 --- a/locale/el.po +++ b/locale/el.po @@ -87,6 +87,10 @@ msgstr "" msgid "%q list must be a list" msgstr "" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -104,7 +108,7 @@ msgid "%q must be >= 1" msgstr "" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/en_GB.po b/locale/en_GB.po index 0b9eb660c3..8eff40108e 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -96,6 +96,10 @@ msgstr "" msgid "%q list must be a list" msgstr "%q list must be a list" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -113,7 +117,7 @@ msgid "%q must be >= 1" msgstr "%q must be >= 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/es.po b/locale/es.po index fb4c3f5e96..973a94b284 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,8 +8,8 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-05-24 21:25+0000\n" -"Last-Translator: Jose David M \n" +"PO-Revision-Date: 2021-05-30 13:32+0000\n" +"Last-Translator: Alvaro Figueroa \n" "Language-Team: \n" "Language: es\n" "MIME-Version: 1.0\n" @@ -98,6 +98,10 @@ msgstr "%q indices deben ser enteros, no %s" msgid "%q list must be a list" msgstr "%q lista debe ser una lista" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "%q debe ser de 0-255" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "%q debe estar entre 1-255" @@ -115,8 +119,8 @@ msgid "%q must be >= 1" msgstr "%q debe ser >= 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" -msgstr "%q debe ser None o 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" +msgstr "%q debe ser None o entre 1 y len(report_descriptor)-1" #: shared-module/vectorio/Polygon.c msgid "%q must be a tuple of length 2" @@ -4448,6 +4452,9 @@ msgstr "zi debe ser de tipo flotante" msgid "zi must be of shape (n_section, 2)" msgstr "zi debe ser una forma (n_section,2)" +#~ msgid "%q must be None or 1-255" +#~ msgstr "%q debe ser None o 1-255" + #~ msgid "Only raw int or string supported for ip" #~ msgstr "Para ip solo puede con un entero o una cadena" diff --git a/locale/fil.po b/locale/fil.po index ca689b783e..748886d42b 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -86,6 +86,10 @@ msgstr "%q indeks ay dapat integers, hindi %s" msgid "%q list must be a list" msgstr "" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -104,7 +108,7 @@ msgid "%q must be >= 1" msgstr "aarehas na haba dapat ang buffer slices" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/fr.po b/locale/fr.po index a55d920693..902821ca1d 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -98,6 +98,10 @@ msgstr "les indices %q doivent être des entiers, pas %s" msgid "%q list must be a list" msgstr "La liste %q doit être une liste" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "%q doit être compris entre 1 et 255" @@ -115,8 +119,8 @@ msgid "%q must be >= 1" msgstr "%q doit être >= 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" -msgstr "%q doit être None ou compris entre 1 et 255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" +msgstr "" #: shared-module/vectorio/Polygon.c msgid "%q must be a tuple of length 2" @@ -4459,6 +4463,9 @@ msgstr "zi doit être de type float" msgid "zi must be of shape (n_section, 2)" msgstr "zi doit être de forme (n_section, 2)" +#~ msgid "%q must be None or 1-255" +#~ msgstr "%q doit être None ou compris entre 1 et 255" + #~ msgid "Only raw int supported for ip" #~ msgstr "IP n'accepte que les chiffres entiers bruts" diff --git a/locale/hi.po b/locale/hi.po index ecb7d2d8cc..604cb4ca56 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -87,6 +87,10 @@ msgstr "" msgid "%q list must be a list" msgstr "" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -104,7 +108,7 @@ msgid "%q must be >= 1" msgstr "" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/it_IT.po b/locale/it_IT.po index 4b58d8d02e..416ad5e94a 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -96,6 +96,10 @@ msgstr "gli indici %q devono essere interi, non %s" msgid "%q list must be a list" msgstr "lista %q deve essere una lista" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -114,7 +118,7 @@ msgid "%q must be >= 1" msgstr "slice del buffer devono essere della stessa lunghezza" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/ja.po b/locale/ja.po index aa9b79ea5b..fd825e7bd1 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -92,6 +92,10 @@ msgstr "" msgid "%q list must be a list" msgstr "%q リストはリストでなければなりません" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -109,7 +113,7 @@ msgid "%q must be >= 1" msgstr "%qは1以上でなければなりません" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/ko.po b/locale/ko.po index 82d4928e9f..064e69704f 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -88,6 +88,10 @@ msgstr "%q 인덱스는 %s 가 아닌 정수 여야합니다" msgid "%q list must be a list" msgstr "" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -105,7 +109,7 @@ msgid "%q must be >= 1" msgstr "%q 는 >=1이어야합니다" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/nl.po b/locale/nl.po index 8ba8094d45..0a9f7f331a 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -90,6 +90,10 @@ msgstr "%q indexen moeten integers zijn, niet %s" msgid "%q list must be a list" msgstr "%q lijst moet een lijst zijn" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -107,7 +111,7 @@ msgid "%q must be >= 1" msgstr "%q moet >= 1 zijn" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/pl.po b/locale/pl.po index 5497efcba3..7e89641e28 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -92,6 +92,10 @@ msgstr "%q indeks musi być liczbą całkowitą, a nie %s" msgid "%q list must be a list" msgstr "" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "" @@ -109,7 +113,7 @@ msgid "%q must be >= 1" msgstr "%q musi być >= 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" msgstr "" #: shared-module/vectorio/Polygon.c diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 14baa40edf..6c6c8064c6 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-05-25 17:41+0000\n" +"PO-Revision-Date: 2021-05-30 13:32+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -96,6 +96,10 @@ msgstr "Os índices %q devem ser inteiros, e não %s" msgid "%q list must be a list" msgstr "A lista %q deve ser uma lista" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "%q deve ser entre 0-255" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "%q deve ser 1-255" @@ -113,8 +117,8 @@ msgid "%q must be >= 1" msgstr "%q deve ser >= 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" -msgstr "%q deve ser Nenhum ou 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" +msgstr "%q deve ser None ou entre 1 e len(report_descriptor)-1" #: shared-module/vectorio/Polygon.c msgid "%q must be a tuple of length 2" @@ -4458,6 +4462,9 @@ msgstr "zi deve ser de um tipo float" msgid "zi must be of shape (n_section, 2)" msgstr "zi deve estar na forma (n_section, 2)" +#~ msgid "%q must be None or 1-255" +#~ msgstr "%q deve ser Nenhum ou 1-255" + #~ msgid "Only raw int or string supported for ip" #~ msgstr "Apenas int ou string bruto é compatível para o ip" diff --git a/locale/sv.po b/locale/sv.po index f38f7240af..21fb6da6c4 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-05-24 21:25+0000\n" +"PO-Revision-Date: 2021-05-30 13:32+0000\n" "Last-Translator: Jonny Bergdahl \n" "Language-Team: LANGUAGE \n" "Language: sv\n" @@ -95,6 +95,10 @@ msgstr "Indexet %q måste vara ett heltal, inte %s" msgid "%q list must be a list" msgstr "%q-listan måste vara en lista" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "%q måste vara 0-255" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "%q måste vara 1-255" @@ -112,8 +116,8 @@ msgid "%q must be >= 1" msgstr "%q måste vara >= 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" -msgstr "%q måste vara None eller 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" +msgstr "%q måste vara None eller mellan 1 och len(report_descriptor)-1" #: shared-module/vectorio/Polygon.c msgid "%q must be a tuple of length 2" @@ -4417,6 +4421,9 @@ msgstr "zi måste vara av typ float" msgid "zi must be of shape (n_section, 2)" msgstr "zi måste vara i formen (n_section, 2)" +#~ msgid "%q must be None or 1-255" +#~ msgstr "%q måste vara None eller 1-255" + #~ msgid "Only raw int or string supported for ip" #~ msgstr "Enbart int eller string stöds för ip" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 0f54ddec98..9a59f6236f 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-05-25 17:41+0000\n" +"PO-Revision-Date: 2021-06-01 13:10+0000\n" "Last-Translator: hexthat \n" "Language-Team: Chinese Hanyu Pinyin\n" "Language: zh_Latn_pinyin\n" @@ -97,6 +97,10 @@ msgstr "%q suǒyǐn bìxū shì zhěngshù, ér bùshì %s" msgid "%q list must be a list" msgstr "%q lièbiǎo bìxū shì lièbiǎo" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 0-255" +msgstr "%q bì xū wéi 0-255" + #: shared-bindings/usb_hid/Device.c msgid "%q must be 1-255" msgstr "%q bì xū wéi 1-255" @@ -114,8 +118,8 @@ msgid "%q must be >= 1" msgstr "%q bìxū dàyú huò děngyú 1" #: shared-bindings/usb_hid/Device.c -msgid "%q must be None or 1-255" -msgstr "%q bì xū wéi wú huò 1-255" +msgid "%q must be None or between 1 and len(report_descriptor)-1" +msgstr "%q bì xū wéi wú huò zài 1 hé len(report_descriptor)-1 zhī jiān" #: shared-module/vectorio/Polygon.c msgid "%q must be a tuple of length 2" @@ -4414,6 +4418,9 @@ msgstr "zi bìxū wèi fú diǎn xíng" msgid "zi must be of shape (n_section, 2)" msgstr "zi bìxū jùyǒu xíngzhuàng (n_section,2)" +#~ msgid "%q must be None or 1-255" +#~ msgstr "%q bì xū wéi wú huò 1-255" + #~ msgid "Only raw int supported for ip" #~ msgstr "Ip jǐn zhīchí raw int" diff --git a/mpy-cross/Makefile.m1 b/mpy-cross/Makefile.m1 new file mode 100644 index 0000000000..34e9841540 --- /dev/null +++ b/mpy-cross/Makefile.m1 @@ -0,0 +1,10 @@ +# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) +# +# SPDX-License-Identifier: MIT + +PROG=mpy-cross-arm64 +BUILD=build-arm64 + +include mpy-cross.mk +# Because mpy-cross.mk unconditionally overwrites CC for Darwin, we must set it BELOW the inclusion +CC := $(shell xcrun --sdk macosx11.1 --find clang) -isysroot $(shell xcrun --sdk macosx11.1 --show-sdk-path) -target arm64-apple-macos11 diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 574d115260..8df7de590d 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -398,7 +398,8 @@ all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2 $(BUILD)/firmware.elf: $(OBJ) $(GENERATED_LD_FILE) $(STEPECHO) "LINK $@" - $(Q)$(CC) -o $@ $(LDFLAGS) $(OBJ) -Wl,--start-group $(LIBS) -Wl,--end-group + $(Q)echo $(OBJ) > $(BUILD)/firmware.objs + $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE) $(BUILD)/firmware.bin: $(BUILD)/firmware.elf diff --git a/ports/atmel-samd/boards/metro_m4_express/pins.c b/ports/atmel-samd/boards/metro_m4_express/pins.c index 4eb26dd21b..8b04072917 100644 --- a/ports/atmel-samd/boards/metro_m4_express/pins.c +++ b/ports/atmel-samd/boards/metro_m4_express/pins.c @@ -26,6 +26,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA19) }, { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA17) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_LED),MP_ROM_PTR(&pin_PA16) }, { MP_OBJ_NEW_QSTR(MP_QSTR_D13),MP_ROM_PTR(&pin_PA16) }, { MP_OBJ_NEW_QSTR(MP_QSTR_SDA),MP_ROM_PTR(&pin_PB02) }, diff --git a/ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c b/ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c new file mode 100644 index 0000000000..5fca974e9e --- /dev/null +++ b/ports/atmel-samd/boards/sparkfun_samd51_micromod/board.c @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.h b/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.h new file mode 100644 index 0000000000..dc9809d564 --- /dev/null +++ b/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.h @@ -0,0 +1,33 @@ +#define MICROPY_HW_BOARD_NAME "SparkFun MicroMod SAMD51" +#define MICROPY_HW_MCU_NAME "samd51j20" + +#define CIRCUITPY_MCU_FAMILY samd51 + +// On-board flash +#define SPI_FLASH_MOSI_PIN &pin_PA09 +#define SPI_FLASH_MISO_PIN &pin_PA10 +#define SPI_FLASH_SCK_PIN &pin_PA08 +#define SPI_FLASH_CS_PIN &pin_PA11 + +// These are pins not to reset. +// SPI Data pins +#define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) +#define MICROPY_PORT_D (0) + +#define BOARD_HAS_CRYSTAL 1 + +#define DEFAULT_I2C_BUS_SCL (&pin_PA16) +#define DEFAULT_I2C_BUS_SDA (&pin_PA17) + +#define DEFAULT_SPI_BUS_SCK (&pin_PA05) +#define DEFAULT_SPI_BUS_MOSI (&pin_PA04) +#define DEFAULT_SPI_BUS_MISO (&pin_PB06) + +#define DEFAULT_UART_BUS_RX (&pin_PB30) +#define DEFAULT_UART_BUS_TX (&pin_PB31) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.mk new file mode 100644 index 0000000000..63d52382a2 --- /dev/null +++ b/ports/atmel-samd/boards/sparkfun_samd51_micromod/mpconfigboard.mk @@ -0,0 +1,14 @@ +LD_FILE = boards/samd51x20-bootloader-external-flash.ld +USB_VID = 0x1b4f +USB_PID = 0x0020 # Used by uf2 bootloader +USB_PRODUCT = "SparkFun MicroMod SAMD51" +USB_MANUFACTURER = "SparkFun Electronics" + +CHIP_VARIANT = SAMD51J20A +CHIP_FAMILY = samd51 + +SPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICES = W25Q128JVxM +LONGINT_IMPL = MPZ + +CIRCUITPY_PS2IO = 1 diff --git a/ports/atmel-samd/boards/sparkfun_samd51_micromod/pins.c b/ports/atmel-samd/boards/sparkfun_samd51_micromod/pins.c new file mode 100644 index 0000000000..49411217d7 --- /dev/null +++ b/ports/atmel-samd/boards/sparkfun_samd51_micromod/pins.c @@ -0,0 +1,97 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + // D (digital only) pins (D0,D1) + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PB04) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PB05) }, + + // A (ADC) pins (A0-A4) + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB00) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB01) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PB02) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PB03) }, + + // DAC + { MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&pin_PA02) }, + + // G (General/BUS) pins (G0-G9) + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_G0), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_G1), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PB08) }, + { MP_ROM_QSTR(MP_QSTR_G2), MP_ROM_PTR(&pin_PB08) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PB09) }, + { MP_ROM_QSTR(MP_QSTR_G3), MP_ROM_PTR(&pin_PB09) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_G4), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_G5), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PB12) }, + { MP_ROM_QSTR(MP_QSTR_G6), MP_ROM_PTR(&pin_PB12) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PB13) }, + { MP_ROM_QSTR(MP_QSTR_G7), MP_ROM_PTR(&pin_PB13) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_G8), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_G9), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_D32), MP_ROM_PTR(&pin_PB31) }, + { MP_ROM_QSTR(MP_QSTR_D33), MP_ROM_PTR(&pin_PB30) }, + { MP_ROM_QSTR(MP_QSTR_D38), MP_ROM_PTR(&pin_PB14) }, + { MP_ROM_QSTR(MP_QSTR_G10), MP_ROM_PTR(&pin_PB14) }, + { MP_ROM_QSTR(MP_QSTR_D39), MP_ROM_PTR(&pin_PB15) }, + { MP_ROM_QSTR(MP_QSTR_G11), MP_ROM_PTR(&pin_PB15) }, + + // PWM pins (PWM0, PWM1) + { MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_PB01) }, + { MP_ROM_QSTR(MP_QSTR_PWM1), MP_ROM_PTR(&pin_PB02) }, + + // AUD (audio) + { MP_ROM_QSTR(MP_QSTR_AUD_MCLK), MP_ROM_PTR(&pin_PB17) }, + { MP_ROM_QSTR(MP_QSTR_AUD_OUT), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_AUD_IN), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_AUD_LRCLK), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_AUD_BCLK), MP_ROM_PTR(&pin_PB16) }, + + // I2C + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_SDA1), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_SCL1), MP_ROM_PTR(&pin_PA16) }, + + { MP_ROM_QSTR(MP_QSTR_I2C_INT), MP_ROM_PTR(&pin_PA18) }, + + // I2C2 + { MP_ROM_QSTR(MP_QSTR_SDA2), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_SCL2), MP_ROM_PTR(&pin_PA12) }, + + // SPI + { MP_ROM_QSTR(MP_QSTR_CIPO), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_COPI), MP_ROM_PTR(&pin_PA04) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA04) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_PA07) }, + + // Status LED + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA23) }, + + // UART + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB30) }, + { MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_PB30) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB31) }, + { MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_PB31) }, + + // UART2 + { MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_PA13) }, + { MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_PA12) }, + + + // Board objects + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c index cd8263bc56..5aa13d076d 100644 --- a/ports/atmel-samd/common-hal/busio/UART.c +++ b/ports/atmel-samd/common-hal/busio/UART.c @@ -45,6 +45,8 @@ #include "samd/sercom.h" +#include "common-hal/busio/SPI.h" // for never_reset_sercom + #define UART_DEBUG(...) (void)0 // #define UART_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__) @@ -152,16 +154,21 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, if (rx && receiver_buffer_size > 0) { self->buffer_length = receiver_buffer_size; - // Initially allocate the UART's buffer in the long-lived part of the - // heap. UARTs are generally long-lived objects, but the "make long- - // lived" machinery is incapable of moving internal pointers like - // self->buffer, so do it manually. (However, as long as internal - // pointers like this are NOT moved, allocating the buffer - // in the long-lived pool is not strictly necessary) - self->buffer = (uint8_t *)gc_alloc(self->buffer_length * sizeof(uint8_t), false, true); - if (self->buffer == NULL) { - common_hal_busio_uart_deinit(self); - mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), self->buffer_length * sizeof(uint8_t)); + if (NULL != receiver_buffer) { + self->buffer = receiver_buffer; + } else { + // Initially allocate the UART's buffer in the long-lived part of the + // heap. UARTs are generally long-lived objects, but the "make long- + // lived" machinery is incapable of moving internal pointers like + // self->buffer, so do it manually. (However, as long as internal + // pointers like this are NOT moved, allocating the buffer + // in the long-lived pool is not strictly necessary) + + self->buffer = (uint8_t *)gc_alloc(self->buffer_length * sizeof(uint8_t), false, true); + if (self->buffer == NULL) { + common_hal_busio_uart_deinit(self); + mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), self->buffer_length * sizeof(uint8_t)); + } } } else { self->buffer_length = 0; @@ -246,6 +253,21 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, usart_async_enable(usart_desc_p); } +void common_hal_busio_uart_never_reset(busio_uart_obj_t *self) { + for (size_t i = 0; i < MP_ARRAY_SIZE(sercom_insts); i++) { + const Sercom *sercom = sercom_insts[i]; + Sercom *hw = (Sercom *)(self->usart_desc.device.hw); + + // Reserve pins for active UART only + if (sercom == hw) { + never_reset_sercom(hw); + never_reset_pin_number(self->rx_pin); + never_reset_pin_number(self->tx_pin); + } + } + return; +} + bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { return self->rx_pin == NO_PIN && self->tx_pin == NO_PIN; } diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile index 85d8e04332..201989e0c9 100644 --- a/ports/esp32s2/Makefile +++ b/ports/esp32s2/Makefile @@ -222,6 +222,8 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) $(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os $(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os +$(BUILD)/lib/protomatter/src/core.o: CFLAGS += -DESP32 + # List of sources for qstr extraction SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) # Sources that only hold QSTRs after pre-processing. diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2/board.c b/ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/board.c similarity index 100% rename from ports/esp32s2/boards/muselab_nanoesp32_s2/board.c rename to ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/board.c diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.h b/ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h similarity index 96% rename from ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.h rename to ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h index 1612153976..41ce41c238 100644 --- a/ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.h +++ b/ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.h @@ -26,7 +26,7 @@ // Micropython setup -#define MICROPY_HW_BOARD_NAME "nanoESP32-S2" +#define MICROPY_HW_BOARD_NAME "nanoESP32-S2 w/Wroom" #define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_NEOPIXEL (&pin_GPIO18) diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.mk b/ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.mk similarity index 90% rename from ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.mk rename to ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.mk index 449676d380..736bbb5adc 100644 --- a/ports/esp32s2/boards/muselab_nanoesp32_s2/mpconfigboard.mk +++ b/ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/mpconfigboard.mk @@ -1,6 +1,6 @@ USB_VID = 0x239A USB_PID = 0x80DE -USB_PRODUCT = "nanoESP32-S2" +USB_PRODUCT = "nanoESP32-S2 w/Wroom" USB_MANUFACTURER = "Muselab" INTERNAL_FLASH_FILESYSTEM = 1 diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2/pins.c b/ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/pins.c similarity index 100% rename from ports/esp32s2/boards/muselab_nanoesp32_s2/pins.c rename to ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/pins.c diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2/sdkconfig b/ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/sdkconfig similarity index 100% rename from ports/esp32s2/boards/muselab_nanoesp32_s2/sdkconfig rename to ports/esp32s2/boards/muselab_nanoesp32_s2_wroom/sdkconfig diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/board.c b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/board.c new file mode 100644 index 0000000000..e40b6335bc --- /dev/null +++ b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/board.c @@ -0,0 +1,52 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * 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. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // USB + common_hal_never_reset_pin(&pin_GPIO19); + common_hal_never_reset_pin(&pin_GPIO20); + + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif /* DEBUG */ +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} + +void board_deinit(void) { +} diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/mpconfigboard.h b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/mpconfigboard.h new file mode 100644 index 0000000000..c5c05676f1 --- /dev/null +++ b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/mpconfigboard.h @@ -0,0 +1,38 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 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. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "nanoESP32-S2 w/Wrover" +#define MICROPY_HW_MCU_NAME "ESP32S2" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO18) + +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) + +#define BOARD_USER_SAFE_MODE_ACTION translate("pressing boot button at start up.\n") + +#define AUTORESET_DELAY_MS 500 diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/mpconfigboard.mk b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/mpconfigboard.mk new file mode 100644 index 0000000000..9904a06e4b --- /dev/null +++ b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/mpconfigboard.mk @@ -0,0 +1,17 @@ +USB_VID = 0x303A +USB_PID = 0x80B2 +USB_PRODUCT = "nanoESP32-S2 w/Wrover" +USB_MANUFACTURER = "Muselab" + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = MPZ + +# The default queue depth of 16 overflows on release builds, +# so increase it to 32. +CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32 + +CIRCUITPY_ESP_FLASH_MODE=dio +CIRCUITPY_ESP_FLASH_FREQ=40m +CIRCUITPY_ESP_FLASH_SIZE=4MB + +CIRCUITPY_MODULE=wrover diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/pins.c b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/pins.c new file mode 100644 index 0000000000..0562d9331f --- /dev/null +++ b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/pins.c @@ -0,0 +1,48 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + + + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO18) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/sdkconfig b/ports/esp32s2/boards/muselab_nanoesp32_s2_wrover/sdkconfig new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/esp32s2/common-hal/microcontroller/Pin.c b/ports/esp32s2/common-hal/microcontroller/Pin.c index 402de227d2..d912402fb9 100644 --- a/ports/esp32s2/common-hal/microcontroller/Pin.c +++ b/ports/esp32s2/common-hal/microcontroller/Pin.c @@ -51,7 +51,7 @@ STATIC void floating_gpio_reset(gpio_num_t pin_number) { } void never_reset_pin_number(gpio_num_t pin_number) { - if (pin_number == -1) { + if (pin_number == NO_PIN) { return; } never_reset_pins[pin_number / 32] |= 1 << pin_number % 32; @@ -63,7 +63,7 @@ void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { // Mark pin as free and return it to a quiescent state. void reset_pin_number(gpio_num_t pin_number) { - if (pin_number == -1) { + if (pin_number == NO_PIN) { return; } never_reset_pins[pin_number / 32] &= ~(1 << pin_number % 32); @@ -72,6 +72,10 @@ void reset_pin_number(gpio_num_t pin_number) { floating_gpio_reset(pin_number); } +void common_hal_mcu_pin_reset_number(uint8_t i) { + reset_pin_number((gpio_num_t)i); +} + void common_hal_reset_pin(const mcu_pin_obj_t *pin) { if (pin == NULL) { return; @@ -109,3 +113,7 @@ bool pin_number_is_free(gpio_num_t pin_number) { bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { return pin_number_is_free(pin->number); } + +uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { + return pin ? pin->number : NO_PIN; +} diff --git a/ports/esp32s2/common-hal/rgbmatrix/RGBMatrix.c b/ports/esp32s2/common-hal/rgbmatrix/RGBMatrix.c new file mode 100644 index 0000000000..d42829985f --- /dev/null +++ b/ports/esp32s2/common-hal/rgbmatrix/RGBMatrix.c @@ -0,0 +1,75 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Jeff Epler 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 + +#include "common-hal/rgbmatrix/RGBMatrix.h" + +#include "peripherals/timer.h" + +void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) { + const timer_config_t config = { + .alarm_en = false, + .counter_en = false, + .intr_type = TIMER_INTR_LEVEL, + .counter_dir = TIMER_COUNT_UP, + .auto_reload = true, + .divider = 2 // 40MHz + }; + + timer_index_t *timer = malloc(sizeof(timer_index_t)); + bool res = peripherals_timer_init(&config, timer); + if (!res) { + return NULL; + } + peripherals_timer_never_reset(timer); + return timer; +} + +extern bool _PM_esp32timerCallback(void *arg); + +void common_hal_rgbmatrix_timer_enable(void *ptr) { +} + +void common_hal_rgbmatrix_timer_disable(void *ptr) { + timer_index_t *timer = (timer_index_t *)ptr; + if (timer->idx == TIMER_MAX) { + return; + } + timer_pause(timer->group, timer->idx); + timer_disable_intr(timer->group, timer->idx); + timer_isr_callback_remove(timer->group, timer->idx); +} + +void common_hal_rgbmatrix_timer_free(void *ptr) { + timer_index_t *timer = (timer_index_t *)ptr; + if (timer->idx == TIMER_MAX) { + return; + } + common_hal_rgbmatrix_timer_disable(ptr); + peripherals_timer_deinit(timer); + timer->idx = TIMER_MAX; +} diff --git a/ports/esp32s2/common-hal/rgbmatrix/RGBMatrix.h b/ports/esp32s2/common-hal/rgbmatrix/RGBMatrix.h new file mode 100644 index 0000000000..d14cd9b083 --- /dev/null +++ b/ports/esp32s2/common-hal/rgbmatrix/RGBMatrix.h @@ -0,0 +1,37 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Jeff Epler 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. + */ + +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_RGBMATRIX_RGBMATRIX_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_RGBMATRIX_RGBMATRIX_H + +#include "shared-module/rgbmatrix/RGBMatrix.h" + +void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self); +void common_hal_rgbmatrix_timer_enable(void *); +void common_hal_rgbmatrix_timer_disable(void *); +void common_hal_rgbmatrix_timer_free(void *); + +#endif diff --git a/ports/esp32s2/common-hal/rgbmatrix/__init__.c b/ports/esp32s2/common-hal/rgbmatrix/__init__.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/esp32s2/common-hal/rgbmatrix/__init__.h b/ports/esp32s2/common-hal/rgbmatrix/__init__.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk index a8dded05de..1f5021bc15 100644 --- a/ports/esp32s2/mpconfigport.mk +++ b/ports/esp32s2/mpconfigport.mk @@ -21,8 +21,10 @@ CIRCUITPY_AUDIOIO = 0 CIRCUITPY_CANIO = 1 CIRCUITPY_COUNTIO = 1 CIRCUITPY_DUALBANK = 1 +CIRCUITPY_FRAMEBUFFERIO = 1 CIRCUITPY_FREQUENCYIO = 1 CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_RGBMATRIX = 1 CIRCUITPY_ROTARYIO = 1 CIRCUITPY_NVM = 1 CIRCUITPY_PS2IO ?= 1 diff --git a/ports/esp32s2/peripherals/pins.h b/ports/esp32s2/peripherals/pins.h index c92f4b4cce..0ffa482166 100644 --- a/ports/esp32s2/peripherals/pins.h +++ b/ports/esp32s2/peripherals/pins.h @@ -91,4 +91,6 @@ extern const mcu_pin_obj_t pin_GPIO44; extern const mcu_pin_obj_t pin_GPIO45; extern const mcu_pin_obj_t pin_GPIO46; +#define NO_PIN (GPIO_NUM_NC) + #endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PINS_H diff --git a/ports/esp32s2/peripherals/timer.c b/ports/esp32s2/peripherals/timer.c index 674d7fc5b2..8e516756b6 100644 --- a/ports/esp32s2/peripherals/timer.c +++ b/ports/esp32s2/peripherals/timer.c @@ -26,6 +26,7 @@ #include "peripherals/timer.h" +#define TIMER_NEVER_RESET 2 #define TIMER_FREE 1 #define TIMER_BUSY 0 @@ -45,7 +46,7 @@ void peripherals_timer_reset(void) { } } -void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer) { +bool peripherals_timer_init(const timer_config_t *config, timer_index_t *timer) { bool break_loop = false; // get free timer @@ -60,7 +61,7 @@ void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer) } else if (i == 1 && j == 1) { timer->idx = TIMER_MAX; timer->group = TIMER_GROUP_MAX; - return; + return false; } } if (break_loop) { @@ -68,11 +69,30 @@ void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer) } } + timer->hw = (timer->group == 0) ? &TIMERG0 : &TIMERG1; + // initialize timer module timer_init(timer->group, timer->idx, config); timer_set_counter_value(timer->group, timer->idx, 0); + + return true; } void peripherals_timer_deinit(timer_index_t *timer) { + if (timer->group == TIMER_GROUP_MAX || timer->idx == TIMER_MAX) { + return; + } timer_deinit(timer->group, timer->idx); + int i = timer->group; + int j = timer->idx; + timer->group = TIMER_GROUP_MAX; + timer->idx = TIMER_MAX; + timer_state[i][j] = TIMER_FREE; +} + +void peripherals_timer_never_reset(timer_index_t *timer) { + timer_deinit(timer->group, timer->idx); + int i = timer->group; + int j = timer->idx; + timer_state[i][j] = TIMER_NEVER_RESET; } diff --git a/ports/esp32s2/peripherals/timer.h b/ports/esp32s2/peripherals/timer.h index 54150069c4..6869bd4352 100644 --- a/ports/esp32s2/peripherals/timer.h +++ b/ports/esp32s2/peripherals/timer.h @@ -30,12 +30,14 @@ #include "driver/timer.h" typedef struct { + timg_dev_t *hw; timer_idx_t idx; timer_group_t group; } timer_index_t; -extern void peripherals_timer_init(const timer_config_t *config, timer_index_t *timer); +extern bool peripherals_timer_init(const timer_config_t *config, timer_index_t *timer); extern void peripherals_timer_deinit(timer_index_t *timer); extern void peripherals_timer_reset(void); +extern void peripherals_timer_never_reset(timer_index_t *timer); #endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_TIMER_HANDLER_H diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 091bd7599b..290d99386a 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -252,7 +252,8 @@ all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2 $(BUILD)/firmware.elf: $(OBJ) $(GENERATED_LD_FILE) $(STEPECHO) "LINK $@" - $(Q)$(CC) -o $@ $(LDFLAGS) $(OBJ) -Wl,--start-group $(LIBS) -Wl,--end-group + $(Q)echo $(OBJ) > $(BUILD)/firmware.objs + $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE) $(BUILD)/firmware.bin: $(BUILD)/firmware.elf diff --git a/ports/raspberrypi/audio_dma.c b/ports/raspberrypi/audio_dma.c index 28a80a770c..7044c44edf 100644 --- a/ports/raspberrypi/audio_dma.c +++ b/ports/raspberrypi/audio_dma.c @@ -352,6 +352,8 @@ bool audio_dma_get_paused(audio_dma_t *dma) { void audio_dma_init(audio_dma_t *dma) { dma->first_buffer = NULL; dma->second_buffer = NULL; + dma->channel[0] = NUM_DMA_CHANNELS; + dma->channel[1] = NUM_DMA_CHANNELS; } void audio_dma_deinit(audio_dma_t *dma) { @@ -368,7 +370,6 @@ bool audio_dma_get_playing(audio_dma_t *dma) { } if (!dma_channel_is_busy(dma->channel[0]) && !dma_channel_is_busy(dma->channel[1])) { - audio_dma_stop(dma); return false; } diff --git a/ports/raspberrypi/boards/cytron_maker_pi_rp2040/board.c b/ports/raspberrypi/boards/cytron_maker_pi_rp2040/board.c new file mode 100644 index 0000000000..e68ca62414 --- /dev/null +++ b/ports/raspberrypi/boards/cytron_maker_pi_rp2040/board.c @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Wai Weng for Cytron Technologies + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/raspberrypi/boards/cytron_maker_pi_rp2040/mpconfigboard.h b/ports/raspberrypi/boards/cytron_maker_pi_rp2040/mpconfigboard.h new file mode 100644 index 0000000000..9c035c7d13 --- /dev/null +++ b/ports/raspberrypi/boards/cytron_maker_pi_rp2040/mpconfigboard.h @@ -0,0 +1,2 @@ +#define MICROPY_HW_BOARD_NAME "Cytron Maker Pi RP2040" +#define MICROPY_HW_MCU_NAME "rp2040" diff --git a/ports/raspberrypi/boards/cytron_maker_pi_rp2040/mpconfigboard.mk b/ports/raspberrypi/boards/cytron_maker_pi_rp2040/mpconfigboard.mk new file mode 100644 index 0000000000..049c230f94 --- /dev/null +++ b/ports/raspberrypi/boards/cytron_maker_pi_rp2040/mpconfigboard.mk @@ -0,0 +1,16 @@ +USB_VID = 0x2E8A +USB_PID = 0x1000 +USB_PRODUCT = "Maker Pi RP2040" +USB_MANUFACTURER = "Cytron" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" + +CIRCUITPY__EVE = 1 + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Motor +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SimpleIO diff --git a/ports/raspberrypi/boards/cytron_maker_pi_rp2040/pins.c b/ports/raspberrypi/boards/cytron_maker_pi_rp2040/pins.c new file mode 100644 index 0000000000..5229642670 --- /dev/null +++ b/ports/raspberrypi/boards/cytron_maker_pi_rp2040/pins.c @@ -0,0 +1,59 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_M1A), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + + { MP_ROM_QSTR(MP_QSTR_M1B), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_M2A), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + + { MP_ROM_QSTR(MP_QSTR_M2B), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + + { MP_ROM_QSTR(MP_QSTR_RGB), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_BUZZER), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_VBATT), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/raspberrypi/boards/pimoroni_pga2040/board.c b/ports/raspberrypi/boards/pimoroni_pga2040/board.c new file mode 100644 index 0000000000..67486d4c23 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pga2040/board.c @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/raspberrypi/boards/pimoroni_pga2040/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_pga2040/mpconfigboard.h new file mode 100644 index 0000000000..a5a0414146 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pga2040/mpconfigboard.h @@ -0,0 +1,2 @@ +#define MICROPY_HW_BOARD_NAME "Pimoroni PGA2040" +#define MICROPY_HW_MCU_NAME "rp2040" diff --git a/ports/raspberrypi/boards/pimoroni_pga2040/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pga2040/mpconfigboard.mk new file mode 100644 index 0000000000..1b870037d4 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pga2040/mpconfigboard.mk @@ -0,0 +1,11 @@ +USB_VID = 0x2E8A +USB_PID = 0x1008 +USB_PRODUCT = "PGA2040" +USB_MANUFACTURER = "Pimoroni" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q64JVxQ" + +CIRCUITPY__EVE = 1 diff --git a/ports/raspberrypi/boards/pimoroni_pga2040/pins.c b/ports/raspberrypi/boards/pimoroni_pga2040/pins.c new file mode 100644 index 0000000000..1ddc885082 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pga2040/pins.c @@ -0,0 +1,47 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_GP23), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) }, + + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_GP29_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_GP29), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c index 4fef53ff0a..e191606577 100644 --- a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c @@ -102,6 +102,7 @@ void common_hal_audiopwmio_pwmaudioout_construct(audiopwmio_pwmaudioout_obj_t *s } audio_dma_init(&self->dma); + self->pacing_timer = NUM_DMA_TIMERS; self->quiescent_value = quiescent_value; } @@ -126,6 +127,7 @@ void common_hal_audiopwmio_pwmaudioout_deinit(audiopwmio_pwmaudioout_obj_t *self } void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, mp_obj_t sample, bool loop) { + if (common_hal_audiopwmio_pwmaudioout_get_playing(self)) { common_hal_audiopwmio_pwmaudioout_stop(self); } @@ -135,8 +137,8 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, for (size_t i = 0; i < NUM_DMA_TIMERS; i++) { if (dma_hw->timer[i] == 0) { pacing_timer = i; + break; } - break; } if (pacing_timer == NUM_DMA_TIMERS) { mp_raise_RuntimeError(translate("No DMA pacing timer found")); diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 78f05d5d63..520526c661 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -117,9 +117,13 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) { } void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) { + pio_sm_restart(self->state_machine.pio, self->state_machine.state_machine); pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); + last_level = self->idle_state; + level_count = 0; + result = 0; + buf_index = 0; } - void common_hal_pulseio_pulsein_interrupt() { pulseio_pulsein_obj_t *self = save_self; @@ -134,13 +138,13 @@ void common_hal_pulseio_pulsein_interrupt() { } else { result = level_count; last_level = level; - level_count = 1; - // Pulses that are londger than MAX_PULSE will return MAX_PULSE + level_count = 0; + // Pulses that are longer than MAX_PULSE will return MAX_PULSE if (result > MAX_PULSE) { result = MAX_PULSE; } - // ignore pulses that are too short - if (result <= MAX_PULSE && result > MIN_PULSE) { + // return pulses that are not too short + if (result > MIN_PULSE) { self->buffer[buf_index] = (uint16_t)result; if (self->len < self->maxlen) { self->len++; @@ -165,12 +169,6 @@ void common_hal_pulseio_pulsein_interrupt() { } void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, uint16_t trigger_duration) { - // exec a wait for the selected pin to change state - if (self->idle_state == true) { - pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x2020); - } else { - pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); - } // Send the trigger pulse. if (trigger_duration > 0) { gpio_set_function(self->pin,GPIO_FUNC_SIO); @@ -178,11 +176,17 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, gpio_put(self->pin, !self->idle_state); common_hal_mcu_delay_us((uint32_t)trigger_duration); gpio_set_function(self->pin,GPIO_FUNC_PIO0); - common_hal_mcu_delay_us(225); + common_hal_mcu_delay_us(125); } // Reconfigure the pin for PIO gpio_set_function(self->pin, GPIO_FUNC_PIO0); + // exec a wait for the selected pin to change state + if (self->idle_state == true) { + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x2020); + } else { + pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0); + } pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true); } diff --git a/ports/raspberrypi/sdk b/ports/raspberrypi/sdk index 7a6660134a..49c0c1613d 160000 --- a/ports/raspberrypi/sdk +++ b/ports/raspberrypi/sdk @@ -1 +1 @@ -Subproject commit 7a6660134ac6242e3223fe1c78b248caf6b2cbf4 +Subproject commit 49c0c1613dca37eea85f168290e858cca4411d81 diff --git a/ports/stm/Makefile b/ports/stm/Makefile index 41f2e50e3d..1de7ed5c82 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -280,7 +280,8 @@ all: $(BUILD)/firmware.bin $(BUILD)/firmware.uf2 $(BUILD)/firmware.elf: $(OBJ) $(STEPECHO) "LINK $@" - $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group + $(Q)echo $^ > $(BUILD)/firmware.objs + $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE) $(BUILD)/firmware.bin: $(BUILD)/firmware.elf diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 0e52063ac7..a4374500ef 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -228,7 +228,7 @@ include $(TOP)/py/mkrules.mk test: $(PROG) $(TOP)/tests/run-tests.py $(eval DIRNAME=ports/$(notdir $(CURDIR))) - cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests.py --auto-jobs + cd $(TOP)/tests && MICROPY_MICROPYTHON=../$(DIRNAME)/$(PROG) ./run-tests.py test_full: $(PROG) $(TOP)/tests/run-tests.py $(eval DIRNAME=ports/$(notdir $(CURDIR))) diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index c71cad6aeb..009b428645 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -96,6 +96,7 @@ #define MICROPY_PY_BUILTINS_SET (1) #define MICROPY_PY_BUILTINS_SLICE (1) #define MICROPY_PY_BUILTINS_SLICE_ATTRS (1) +#define MICROPY_PY_BUILTINS_SLICE_INDICES (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_CMATH (0) diff --git a/py/mpz.h b/py/mpz.h index b273cdcc62..ba2db4c308 100644 --- a/py/mpz.h +++ b/py/mpz.h @@ -142,6 +142,9 @@ static inline size_t mpz_max_num_bits(const mpz_t *z) { return z->len * MPZ_DIG_SIZE; } static inline size_t mpz_num_bits(const mpz_t *z) { + if (mpz_is_zero(z)) { + return 0; + } size_t last_bits = (8 * (sizeof(long) - sizeof(mpz_dig_t))) - __builtin_clzl(z->dig[z->len - 1]); return z->len * MPZ_DIG_SIZE + last_bits; } diff --git a/py/nlraarch64.c b/py/nlraarch64.c index 66faf93fa5..37a860540e 100644 --- a/py/nlraarch64.c +++ b/py/nlraarch64.c @@ -34,8 +34,13 @@ // Implemented purely as inline assembly; inside a function, we have to deal with undoing the prologue, restoring // SP and LR. This way, we don't. __asm( + #if defined(__APPLE__) && defined(__MACH__) + "_nlr_push: \n" + ".global _nlr_push \n" + #else "nlr_push: \n" ".global nlr_push \n" + #endif "mov x9, sp \n" "stp lr, x9, [x0, #16]\n" // 16 == offsetof(nlr_buf_t, regs) "stp x19, x20, [x0, #32]\n" @@ -44,7 +49,11 @@ __asm( "stp x25, x26, [x0, #80]\n" "stp x27, x28, [x0, #96]\n" "str x29, [x0, #112]\n" + #if defined(__APPLE__) && defined(__MACH__) + "b _nlr_push_tail \n" // do the rest in C + #else "b nlr_push_tail \n" // do the rest in C + #endif ); NORETURN void nlr_jump(void *val) { diff --git a/setup.py b/setup.py index d2989d068d..8c1f27e405 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,11 @@ # SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) # # SPDX-License-Identifier: MIT - +import os +import site from datetime import datetime +from typing import List + from setuptools import setup from pathlib import Path import subprocess @@ -25,6 +28,13 @@ if len(pieces) > 2: pieces.pop() version = "-".join(pieces) +def build_data_files_list() -> List[tuple]: + result = [] + for package in os.listdir("circuitpython-stubs"): + result.append((site.getsitepackages()[0] + "/" + package + "/", + ["circuitpython-stubs/{}/__init__.pyi".format(package)])) + return result + setup( name="circuitpython-stubs", description="PEP 561 type stubs for CircuitPython", @@ -34,7 +44,6 @@ setup( author_email="circuitpython@adafruit.com", version=version, license="MIT", - package_data={"circuitpython-stubs": stubs}, - packages=["circuitpython-stubs"], + data_files=build_data_files_list(), setup_requires=["setuptools>=38.6.0"], ) diff --git a/shared-bindings/displayio/OnDiskBitmap.c b/shared-bindings/displayio/OnDiskBitmap.c index 580665eab9..b6341b1929 100644 --- a/shared-bindings/displayio/OnDiskBitmap.c +++ b/shared-bindings/displayio/OnDiskBitmap.c @@ -55,7 +55,7 @@ //| //| with open("/sample.bmp", "rb") as f: //| odb = displayio.OnDiskBitmap(f) -//| face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter()) +//| face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader) //| splash.append(face) //| # Wait for the image to load. //| board.DISPLAY.refresh(target_frames_per_second=60) @@ -127,8 +127,29 @@ const mp_obj_property_t displayio_ondiskbitmap_height_obj = { }; +//| pixel_shader: Union[ColorConverter, Palette] +//| """The image's pixel_shader. The type depends on the underlying +//| bitmap's structure. The pixel shadder can be modified (e.g., to set the +//| transparent pixel or, for paletted images, to update the palette""" +//| +STATIC mp_obj_t displayio_ondiskbitmap_obj_get_pixel_shader(mp_obj_t self_in) { + displayio_ondiskbitmap_t *self = MP_OBJ_TO_PTR(self_in); + return common_hal_displayio_ondiskbitmap_get_pixel_shader(self); +} + +MP_DEFINE_CONST_FUN_OBJ_1(displayio_ondiskbitmap_get_pixel_shader_obj, displayio_ondiskbitmap_obj_get_pixel_shader); + +const mp_obj_property_t displayio_ondiskbitmap_pixel_shader_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&displayio_ondiskbitmap_get_pixel_shader_obj, + (mp_obj_t)MP_ROM_NONE, + (mp_obj_t)MP_ROM_NONE}, +}; + + STATIC const mp_rom_map_elem_t displayio_ondiskbitmap_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_ondiskbitmap_height_obj) }, + { MP_ROM_QSTR(MP_QSTR_pixel_shader), MP_ROM_PTR(&displayio_ondiskbitmap_pixel_shader_obj) }, { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_ondiskbitmap_width_obj) }, }; STATIC MP_DEFINE_CONST_DICT(displayio_ondiskbitmap_locals_dict, displayio_ondiskbitmap_locals_dict_table); diff --git a/shared-bindings/displayio/OnDiskBitmap.h b/shared-bindings/displayio/OnDiskBitmap.h index aff3a19db2..6d534ec50e 100644 --- a/shared-bindings/displayio/OnDiskBitmap.h +++ b/shared-bindings/displayio/OnDiskBitmap.h @@ -38,6 +38,6 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *b int16_t x, int16_t y); uint16_t common_hal_displayio_ondiskbitmap_get_height(displayio_ondiskbitmap_t *self); - +mp_obj_t common_hal_displayio_ondiskbitmap_get_pixel_shader(displayio_ondiskbitmap_t *self); uint16_t common_hal_displayio_ondiskbitmap_get_width(displayio_ondiskbitmap_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO_ONDISKBITMAP_H diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index b7ebdd850a..262346bad2 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -33,7 +33,9 @@ #include "shared-bindings/supervisor/RunReason.h" #include "shared-bindings/supervisor/Runtime.h" +#if (CIRCUITPY_USB) #include "tusb.h" +#endif STATIC supervisor_run_reason_t _run_reason; diff --git a/shared-bindings/usb_cdc/__init__.c b/shared-bindings/usb_cdc/__init__.c index f16373fa73..18e8356e34 100644 --- a/shared-bindings/usb_cdc/__init__.c +++ b/shared-bindings/usb_cdc/__init__.c @@ -52,9 +52,9 @@ //| """The `console` `Serial` object is used for the REPL, and for `sys.stdin` and `sys.stdout`. //| `console` is ``None`` if disabled. //| -//| However, note that`sys.stdin` and `sys.stdout` are text-based streams, +//| However, note that `sys.stdin` and `sys.stdout` are text-based streams, //| and the `console` object is a binary stream. -//| You do not normally need to write to `console` unless you wnat to write binary data. +//| You do not normally need to write to `console` unless you want to write binary data. //| """ //| //| data: Optional[Serial] diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 38556e5c13..64803f8e13 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -69,16 +69,16 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args { MP_QSTR_usage_page, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_usage, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_in_report_length, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, - { MP_QSTR_out_report_length, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_int = 0 } }, + { MP_QSTR_out_report_length, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0 } }, { MP_QSTR_report_id_index, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[ARG_report_descriptor].u_obj, &bufinfo, MP_BUFFER_READ); - mp_obj_t descriptor = mp_obj_new_bytearray(bufinfo.len, bufinfo.buf); + mp_buffer_info_t descriptor_bufinfo; + mp_get_buffer_raise(args[ARG_report_descriptor].u_obj, &descriptor_bufinfo, MP_BUFFER_READ); + mp_obj_t descriptor = mp_obj_new_bytearray(descriptor_bufinfo.len, descriptor_bufinfo.buf); const mp_int_t usage_page_arg = args[ARG_usage_page].u_int; if (usage_page_arg <= 0 || usage_page_arg > 255) { @@ -99,8 +99,8 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args const uint8_t in_report_length = in_report_length_arg; const mp_int_t out_report_length_arg = args[ARG_out_report_length].u_int; - if (out_report_length_arg <= 0 || out_report_length_arg > 255) { - mp_raise_ValueError_varg(translate("%q must be 1-255"), MP_QSTR_out_report_length); + if (out_report_length_arg < 0 || out_report_length_arg > 255) { + mp_raise_ValueError_varg(translate("%q must be 0-255"), MP_QSTR_out_report_length); } const uint8_t out_report_length = out_report_length_arg; @@ -108,8 +108,9 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args uint8_t report_id_index = 0; if (report_id_index_arg != mp_const_none) { const mp_int_t report_id_index_int = mp_obj_int_get_checked(report_id_index_arg); - if (report_id_index_int <= 0 || report_id_index_int > 255) { - mp_raise_ValueError_varg(translate("%q must be None or 1-255"), MP_QSTR_report_id_index); + if (report_id_index_int <= 0 || (uint32_t)report_id_index_int >= descriptor_bufinfo.len) { + mp_raise_ValueError_varg(translate("%q must be None or between 1 and len(report_descriptor)-1"), + MP_QSTR_report_id_index); } report_id_index = report_id_index_int; } diff --git a/shared-module/displayio/ColorConverter.h b/shared-module/displayio/ColorConverter.h index 55f86982dc..d8805ed720 100644 --- a/shared-module/displayio/ColorConverter.h +++ b/shared-module/displayio/ColorConverter.h @@ -33,7 +33,7 @@ #include "py/obj.h" #include "shared-module/displayio/Palette.h" -typedef struct { +typedef struct displayio_colorconverter { mp_obj_base_t base; bool dither; uint8_t input_colorspace; diff --git a/shared-module/displayio/OnDiskBitmap.c b/shared-module/displayio/OnDiskBitmap.c index 5c7e00a583..1bc5f93eb6 100644 --- a/shared-module/displayio/OnDiskBitmap.c +++ b/shared-module/displayio/OnDiskBitmap.c @@ -25,6 +25,10 @@ */ #include "shared-bindings/displayio/OnDiskBitmap.h" +#include "shared-bindings/displayio/ColorConverter.h" +#include "shared-bindings/displayio/Palette.h" +#include "shared-module/displayio/ColorConverter.h" +#include "shared-module/displayio/Palette.h" #include @@ -63,6 +67,11 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, self->width = read_word(bmp_header, 9); self->height = read_word(bmp_header, 11); + displayio_colorconverter_t *colorconverter = m_new_obj(displayio_colorconverter_t); + colorconverter->base.type = &displayio_colorconverter_type; + common_hal_displayio_colorconverter_construct(colorconverter, false, DISPLAYIO_COLORSPACE_RGB888); + self->colorconverter = colorconverter; + if (bits_per_pixel == 16) { if (((header_size >= 56)) || (self->bitfield_compressed)) { self->r_bitmask = read_word(bmp_header, 27); @@ -74,25 +83,41 @@ void common_hal_displayio_ondiskbitmap_construct(displayio_ondiskbitmap_t *self, self->g_bitmask = 0x3e0; self->b_bitmask = 0x1f; } - } else if (indexed && self->bits_per_pixel != 1) { + } else if (indexed) { if (number_of_colors == 0) { number_of_colors = 1 << bits_per_pixel; } - uint16_t palette_size = number_of_colors * sizeof(uint32_t); - uint16_t palette_offset = 0xe + header_size; - self->palette_data = m_malloc(palette_size, false); + displayio_palette_t *palette = m_new_obj(displayio_palette_t); + palette->base.type = &displayio_palette_type; + common_hal_displayio_palette_construct(palette, number_of_colors); - f_rewind(&self->file->fp); - f_lseek(&self->file->fp, palette_offset); + if (number_of_colors > 1) { + uint16_t palette_size = number_of_colors * sizeof(uint32_t); + uint16_t palette_offset = 0xe + header_size; - UINT palette_bytes_read; - if (f_read(&self->file->fp, self->palette_data, palette_size, &palette_bytes_read) != FR_OK) { - mp_raise_OSError(MP_EIO); - } - if (palette_bytes_read != palette_size) { - mp_raise_ValueError(translate("Unable to read color palette data")); + uint32_t *palette_data = m_malloc(palette_size, false); + + f_rewind(&self->file->fp); + f_lseek(&self->file->fp, palette_offset); + + UINT palette_bytes_read; + if (f_read(&self->file->fp, palette_data, palette_size, &palette_bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (palette_bytes_read != palette_size) { + mp_raise_ValueError(translate("Unable to read color palette data")); + } + for (uint16_t i = 0; i < palette_size; i++) { + common_hal_displayio_palette_set_color(palette, i, palette_data[i]); + } + m_free(palette_data); + } else { + common_hal_displayio_palette_set_color(palette, 0, 0x0); + common_hal_displayio_palette_set_color(palette, 1, 0xffffff); } + self->palette = palette; + } else if (!(header_size == 12 || header_size == 40 || header_size == 108 || header_size == 124)) { mp_raise_ValueError_varg(translate("Only Windows format, uncompressed BMP supported: given header size is %d"), header_size); } @@ -148,15 +173,7 @@ uint32_t common_hal_displayio_ondiskbitmap_get_pixel(displayio_ondiskbitmap_t *s uint8_t offset = (x % pixels_per_byte) * self->bits_per_pixel; uint8_t mask = (1 << self->bits_per_pixel) - 1; - uint8_t index = (pixel_data >> ((8 - self->bits_per_pixel) - offset)) & mask; - if (self->bits_per_pixel == 1) { - if (index == 1) { - return 0xFFFFFF; - } else { - return 0x000000; - } - } - return self->palette_data[index]; + return (pixel_data >> ((8 - self->bits_per_pixel) - offset)) & mask; } else if (bytes_per_pixel == 2) { if (self->g_bitmask == 0x07e0) { // 565 red = ((pixel_data & self->r_bitmask) >> 11); @@ -185,3 +202,7 @@ uint16_t common_hal_displayio_ondiskbitmap_get_height(displayio_ondiskbitmap_t * uint16_t common_hal_displayio_ondiskbitmap_get_width(displayio_ondiskbitmap_t *self) { return self->width; } + +mp_obj_t common_hal_displayio_ondiskbitmap_get_pixel_shader(displayio_ondiskbitmap_t *self) { + return MP_OBJ_FROM_PTR(self->pixel_shader_base); +} diff --git a/shared-module/displayio/OnDiskBitmap.h b/shared-module/displayio/OnDiskBitmap.h index 610b114910..806b13f7f9 100644 --- a/shared-module/displayio/OnDiskBitmap.h +++ b/shared-module/displayio/OnDiskBitmap.h @@ -43,10 +43,14 @@ typedef struct { uint32_t r_bitmask; uint32_t g_bitmask; uint32_t b_bitmask; - bool bitfield_compressed; pyb_file_obj_t *file; + union { + mp_obj_base_t *pixel_shader_base; + struct displayio_palette *palette; + struct displayio_colorconverter *colorconverter; + }; + bool bitfield_compressed; uint8_t bits_per_pixel; - uint32_t *palette_data; } displayio_ondiskbitmap_t; #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_ONDISKBITMAP_H diff --git a/shared-module/displayio/Palette.h b/shared-module/displayio/Palette.h index 82504b7ed1..49f03b56c7 100644 --- a/shared-module/displayio/Palette.h +++ b/shared-module/displayio/Palette.h @@ -69,7 +69,7 @@ typedef struct { bool opaque; } displayio_output_pixel_t; -typedef struct { +typedef struct displayio_palette { mp_obj_base_t base; _displayio_color_t *colors; uint32_t color_count; diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 7d9dc26dd3..23338275e8 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -185,6 +185,8 @@ void reset_displays(void) { rgbmatrix_rgbmatrix_obj_t *pm = &displays[i].rgbmatrix; if (!any_display_uses_this_framebuffer(&pm->base)) { common_hal_rgbmatrix_rgbmatrix_deinit(pm); + } else { + common_hal_rgbmatrix_rgbmatrix_set_paused(pm, true); } #endif #if CIRCUITPY_SHARPDISPLAY diff --git a/shared-module/rgbmatrix/RGBMatrix.c b/shared-module/rgbmatrix/RGBMatrix.c index a0dc783b55..0bfed0aa6c 100644 --- a/shared-module/rgbmatrix/RGBMatrix.c +++ b/shared-module/rgbmatrix/RGBMatrix.c @@ -104,15 +104,11 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t *self, if (stat == PROTOMATTER_OK) { _PM_protoPtr = &self->protomatter; - common_hal_mcu_disable_interrupts(); common_hal_rgbmatrix_timer_enable(self->timer); stat = _PM_begin(&self->protomatter); if (stat == PROTOMATTER_OK) { _PM_convert_565(&self->protomatter, self->bufinfo.buf, self->width); - } - common_hal_mcu_enable_interrupts(); - if (stat == PROTOMATTER_OK) { _PM_swapbuffer_maybe(&self->protomatter); } } diff --git a/shared-module/terminalio/Terminal.c b/shared-module/terminalio/Terminal.c index 8ef2acd1ca..8e4979ecad 100644 --- a/shared-module/terminalio/Terminal.c +++ b/shared-module/terminalio/Terminal.c @@ -106,7 +106,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con } } if (c == ';') { - int16_t m = 0; + uint16_t m = 0; for (++j; j < 9; j++) { if ('0' <= i[j] && i[j] <= '9') { m = m * 10 + (i[j] - '0'); @@ -116,6 +116,12 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con } } if (c == 'H') { + if (n > 0) { + n--; + } + if (m > 0) { + m--; + } if (n >= self->tilegrid->height_in_tiles) { n = self->tilegrid->height_in_tiles - 1; } diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 769a2ce87f..5881ec4c32 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -147,26 +147,26 @@ static const char data_cdc_comm_interface_name[] = USB_INTERFACE_NAME " CDC2 con static const char console_cdc_data_interface_name[] = USB_INTERFACE_NAME " CDC data"; static const char data_cdc_data_interface_name[] = USB_INTERFACE_NAME " CDC2 data"; +// .idx is set later. + static usb_cdc_serial_obj_t usb_cdc_console_obj = { .base.type = &usb_cdc_serial_type, .timeout = -1.0f, .write_timeout = -1.0f, - .idx = 0, }; static usb_cdc_serial_obj_t usb_cdc_data_obj = { .base.type = &usb_cdc_serial_type, .timeout = -1.0f, .write_timeout = -1.0f, - .idx = 1, }; static bool usb_cdc_console_is_enabled; static bool usb_cdc_data_is_enabled; void usb_cdc_set_defaults(void) { - usb_cdc_console_is_enabled = CIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT; - usb_cdc_data_is_enabled = CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT; + common_hal_usb_cdc_enable(CIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT, + CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT); } bool usb_cdc_console_enabled(void) { @@ -241,11 +241,21 @@ bool common_hal_usb_cdc_enable(bool console, bool data) { // Right now these objects contain no heap objects, but if that changes, // they will need to be protected against gc. + // Assign only as many idx values as necessary. They must start at 0. + uint8_t idx = 0; usb_cdc_console_is_enabled = console; usb_cdc_set_console(console ? MP_OBJ_FROM_PTR(&usb_cdc_console_obj) : mp_const_none); + if (console) { + usb_cdc_console_obj.idx = idx; + idx++; + } usb_cdc_data_is_enabled = data; usb_cdc_set_data(data ? MP_OBJ_FROM_PTR(&usb_cdc_data_obj) : mp_const_none); + if (data) { + usb_cdc_data_obj.idx = idx; + } + return true; } diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index f7e0aafaaf..f3a0d5a976 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -67,7 +67,7 @@ void serial_early_init(void) { const mcu_pin_obj_t *tx = MP_OBJ_TO_PTR(DEBUG_UART_TX); common_hal_busio_uart_construct(&debug_uart, tx, rx, NULL, NULL, NULL, - false, 115200, 8, UART_PARITY_NONE, 1, 1.0f, 64, + false, 115200, 8, BUSIO_UART_PARITY_NONE, 1, 1.0f, 64, buf_array, true); common_hal_busio_uart_never_reset(&debug_uart); #endif diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 061e74e73d..0e1c3472eb 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -77,10 +77,15 @@ void usb_init(void) { post_usb_init(); - #if MICROPY_KBD_EXCEPTION + #if MICROPY_KBD_EXCEPTION && CIRCUITPY_USB_CDC // Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() usb_callback will be invoked when Ctrl+C is received // This usb_callback always got invoked regardless of mp_interrupt_char value since we only set it once here - tud_cdc_set_wanted_char(CHAR_CTRL_C); + + // Don't watch for ctrl-C if there is no REPL. + if (usb_cdc_console_enabled()) { + // Console will always be itf 0. + tud_cdc_set_wanted_char(CHAR_CTRL_C); + } #endif } @@ -103,7 +108,7 @@ void usb_set_defaults(void) { #endif }; -// Some dynamic USB data must be saved after boot.py. How much is needed +// Some dynamic USB data must be saved after boot.py. How much is needed? size_t usb_boot_py_data_size(void) { size_t size = 0; @@ -151,7 +156,13 @@ void usb_background(void) { #if CFG_TUSB_OS == OPT_OS_NONE tud_task(); #endif - tud_cdc_write_flush(); + // No need to flush if there's no REPL. + #if CIRCUITPY_USB_CDC + if (usb_cdc_console_enabled()) { + // Console will always be itf 0. + tud_cdc_write_flush(); + } + #endif } } @@ -205,6 +216,7 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { // DTR = false is counted as disconnected if (!dtr) { cdc_line_coding_t coding; + // Use whichever CDC is itf 0. tud_cdc_get_line_coding(&coding); if (coding.bit_rate == 1200) { @@ -274,13 +286,13 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ * @param itf Interface index (for multiple cdc interfaces) * @param wanted_char The wanted char (set previously) */ -void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) { - (void)itf; // not used +// Only called when console is enabled. +void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) { // Workaround for using lib/utils/interrupt_char.c // Compare mp_interrupt_char with wanted_char and ignore if not matched if (mp_interrupt_char == wanted_char) { - tud_cdc_read_flush(); // flush read fifo + tud_cdc_n_read_flush(itf); // flush read fifo mp_keyboard_interrupt(); } } diff --git a/tests/run-tests.py b/tests/run-tests.py index 77994f4cd8..f33822cb9b 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -7,10 +7,11 @@ import platform import argparse import inspect import re -import threading +from glob import glob import multiprocessing from multiprocessing.pool import ThreadPool -from glob import glob +import threading +import tempfile # See stackoverflow.com/questions/2632199: __file__ nor sys.argv[0] # are guaranteed to always work, this one should though. @@ -169,26 +170,27 @@ def run_micropython(pyb, args, test_file, is_special=False): # if running via .mpy, first compile the .py file if args.via_mpy: + mpy_modname = tempfile.mktemp(dir="") + mpy_filename = mpy_modname + ".mpy" subprocess.check_output( [MPYCROSS] + args.mpy_cross_flags.split() - + ["-o", "mpytest.mpy", "-X", "emit=" + args.emit, test_file] + + ["-o", mpy_filename, "-X", "emit=" + args.emit, test_file] ) - cmdlist.extend(["-m", "mpytest"]) + cmdlist.extend(["-m", mpy_modname]) else: cmdlist.append(test_file) # run the actual test - e = {"LANG": "en_US.UTF-8", "MICROPYPATH": os.environ["MICROPYPATH"]} try: - output_mupy = subprocess.check_output(cmdlist, env=e, stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as error: + output_mupy = subprocess.check_output(cmdlist, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as er: had_crash = True - output_mupy = error.output + b"CRASH" + output_mupy = er.output + b"CRASH" # clean up if we had an intermediate .mpy file if args.via_mpy: - rm_f("mpytest.mpy") + rm_f(mpy_filename) else: # run on pyboard @@ -200,7 +202,7 @@ def run_micropython(pyb, args, test_file, is_special=False): if not is_special and e.args[0] == "exception": output_mupy = e.args[1] + e.args[2] + b"CRASH" else: - output_mupy = b"CRASH" + output_mupy = bytes(e.args[0], "ascii") + b"\nCRASH" # canonical form for all ports/platforms is to use \n for end-of-line output_mupy = output_mupy.replace(b"\r\n", b"\n") @@ -241,10 +243,9 @@ def run_micropython(pyb, args, test_file, is_special=False): else: # a regex if lines_exp[i][1].match(lines_mupy[i_mupy]): - # print("match", lines_exp[i][0], lines_mupy[i_mupy]) lines_mupy[i_mupy] = lines_exp[i][0] else: - # print("don't match: %r %s" % (lines_exp[i][0], lines_mupy[i_mupy])) # DEBUG + # print("don't match: %r %s" % (lines_exp[i][1], lines_mupy[i_mupy])) # DEBUG pass i_mupy += 1 if i_mupy >= len(lines_mupy): @@ -266,6 +267,9 @@ class ThreadSafeCounter: self._value = start self._lock = threading.Lock() + def increment(self): + self.add(1) + def add(self, to_add): with self._lock: self._value += to_add @@ -306,11 +310,11 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if not (args.list_tests or args.write_exp): # Even if we run completely different tests in a different directory, # we need to access feature_checks from the same directory as the - # run-tests script itself so use base_path. + # run-tests.py script itself so use base_path. # Check if micropython.native is supported, and skip such tests if it's not output = run_feature_check(pyb, args, base_path, "native_check.py") - if output.endswith(b"CRASH"): + if output != b"native\n": skip_native = True # Check if arbitrary-precision integers are supported, and skip such tests if it's not @@ -325,7 +329,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): # Check if set type (and set literals) is supported, and skip such tests if it's not output = run_feature_check(pyb, args, base_path, "set_check.py") - if output.endswith(b"CRASH"): + if output != b"{1}\n": skip_set_type = True # Check if slice is supported, and skip such tests if it's not @@ -335,12 +339,12 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): # Check if async/await keywords are supported, and skip such tests if it's not output = run_feature_check(pyb, args, base_path, "async_check.py") - if output.endswith(b"CRASH"): + if output != b"async\n": skip_async = True # Check if const keyword (MicroPython extension) is supported, and skip such tests if it's not output = run_feature_check(pyb, args, base_path, "const.py") - if output.endswith(b"CRASH"): + if output != b"1\n": skip_const = True # Check if __rOP__ special methods are supported, and skip such tests if it's not @@ -365,10 +369,10 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): upy_byteorder = run_feature_check(pyb, args, base_path, "byteorder.py") upy_float_precision = run_feature_check(pyb, args, base_path, "float.py") - if upy_float_precision.endswith(b"CRASH"): - upy_float_precision = 0 - else: + try: upy_float_precision = int(upy_float_precision) + except ValueError: + upy_float_precision = 0 has_complex = run_feature_check(pyb, args, base_path, "complex.py") == b"complex\n" has_coverage = run_feature_check(pyb, args, base_path, "coverage.py") == b"coverage\n" cpy_byteorder = subprocess.check_output( @@ -545,7 +549,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): is_bytearray = test_name.startswith("bytearray") or test_name.endswith("_bytearray") is_set_type = test_name.startswith("set_") or test_name.startswith("frozenset") is_slice = test_name.find("slice") != -1 or test_name in misc_slice_tests - is_async = test_name.startswith("async_") + is_async = test_name.startswith(("async_", "uasyncio_")) is_const = test_name.startswith("const") is_io_module = test_name.startswith("io_") @@ -610,8 +614,8 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): filename_mupy = os.path.join(result_dir, test_basename + ".out") if output_expected == output_mupy: - # print("pass ", test_file) - passed_count.add(1) + print("pass ", test_file) + passed_count.increment() rm_f(filename_expected) rm_f(filename_mupy) else: @@ -619,17 +623,13 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): f.write(output_expected) with open(filename_mupy, "wb") as f: f.write(output_mupy) - print("### Expected") - print(output_expected) - print("### Actual") - print(output_mupy) print("FAIL ", test_file) - failed_tests.append(test_file) + failed_tests.append(test_name) - test_count.add(1) + test_count.increment() - if args.list_tests: - return True + if pyb or args.list_tests: + num_threads = 1 if num_threads > 1: pool = ThreadPool(num_threads) @@ -638,6 +638,9 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): for test in tests: run_one_test(test) + if args.list_tests: + return True + print( "{} tests performed ({} individual testcases)".format( test_count.value, testcase_count.value @@ -645,18 +648,12 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): ) print("{} tests passed".format(passed_count.value)) - if len(skipped_tests.value) > 0: - print( - "{} tests skipped: {}".format( - len(skipped_tests.value), " ".join(sorted(skipped_tests.value)) - ) - ) - if len(failed_tests.value) > 0: - print( - "{} tests failed: {}".format( - len(failed_tests.value), " ".join(sorted(failed_tests.value)) - ) - ) + skipped_tests = sorted(skipped_tests.value) + if len(skipped_tests) > 0: + print("{} tests skipped: {}".format(len(skipped_tests), " ".join(skipped_tests))) + failed_tests = sorted(failed_tests.value) + if len(failed_tests) > 0: + print("{} tests failed: {}".format(len(failed_tests), " ".join(failed_tests))) return False # all tests succeeded @@ -758,18 +755,11 @@ the last matching regex is used: cmd_parser.add_argument( "-j", "--jobs", - default=1, + default=multiprocessing.cpu_count(), metavar="N", type=int, help="Number of tests to run simultaneously", ) - cmd_parser.add_argument( - "--auto-jobs", - action="store_const", - dest="jobs", - const=multiprocessing.cpu_count(), - help="Set the -j values to the CPU (thread) count", - ) cmd_parser.add_argument("files", nargs="*", help="input test files") cmd_parser.add_argument( "--print-failures", @@ -869,9 +859,7 @@ the last matching regex is used: if not args.keep_path: # clear search path to make sure tests use only builtin modules and those in extmod - os.environ["MICROPYPATH"] = ( - os.pathsep + base_path("../extmod") + os.pathsep + base_path(".") - ) + os.environ["MICROPYPATH"] = os.pathsep + base_path("../extmod") try: os.makedirs(args.result_dir, exist_ok=True)