summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules2
-rw-r--r--docs/design_guide.rst4
m---------extmod/ulab0
-rw-r--r--locale/ID.po30
-rw-r--r--locale/circuitpython.pot30
-rw-r--r--locale/de_DE.po30
-rw-r--r--locale/en_US.po30
-rw-r--r--locale/en_x_pirate.po30
-rw-r--r--locale/es.po30
-rw-r--r--locale/fil.po30
-rw-r--r--locale/fr.po30
-rw-r--r--locale/it_IT.po30
-rw-r--r--locale/ko.po30
-rw-r--r--locale/pl.po30
-rw-r--r--locale/pt_BR.po30
-rw-r--r--locale/zh_Latn_pinyin.po30
-rw-r--r--ports/atmel-samd/boards/hallowing_m4_express/board.c2
-rw-r--r--ports/atmel-samd/boards/monster_m4sk/board.c2
-rw-r--r--ports/atmel-samd/boards/openbook_m4/board.c2
-rw-r--r--ports/atmel-samd/boards/pewpew_m4/board.c2
-rw-r--r--ports/atmel-samd/boards/pybadge/board.c2
-rw-r--r--ports/atmel-samd/boards/pybadge_airlift/board.c2
-rw-r--r--ports/atmel-samd/boards/pygamer/board.c2
-rw-r--r--ports/atmel-samd/boards/pygamer_advance/board.c2
-rw-r--r--ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk2
-rw-r--r--ports/atmel-samd/common-hal/analogio/AnalogIn.c4
-rw-r--r--ports/atmel-samd/common-hal/audiobusio/I2SOut.c12
-rw-r--r--ports/atmel-samd/common-hal/audiobusio/PDMIn.c9
-rw-r--r--ports/atmel-samd/common-hal/audioio/AudioOut.c9
-rw-r--r--ports/atmel-samd/common-hal/busio/SPI.c4
-rw-r--r--ports/atmel-samd/common-hal/busio/UART.c8
-rw-r--r--ports/atmel-samd/common-hal/digitalio/DigitalInOut.c4
-rw-r--r--ports/atmel-samd/common-hal/pulseio/PWMOut.c4
-rw-r--r--ports/atmel-samd/mpconfigport.mk2
-rw-r--r--ports/cxd56/Makefile4
-rw-r--r--ports/cxd56/common-hal/analogio/AnalogIn.c4
-rw-r--r--ports/cxd56/common-hal/busio/UART.c4
-rw-r--r--ports/cxd56/common-hal/digitalio/DigitalInOut.c4
-rw-r--r--ports/cxd56/common-hal/pulseio/PWMOut.c8
-rw-r--r--ports/cxd56/common-hal/pulseio/PulseIn.c25
-rw-r--r--ports/cxd56/mpconfigport.mk2
-rw-r--r--ports/mimxrt10xx/common-hal/analogio/AnalogIn.c4
-rw-r--r--ports/mimxrt10xx/common-hal/busio/UART.c18
-rw-r--r--ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c4
-rw-r--r--ports/nrf/boards/clue_nrf52840_express/board.c2
-rw-r--r--ports/nrf/boards/ohs2020_badge/board.c2
-rw-r--r--ports/nrf/common-hal/analogio/AnalogIn.c4
-rw-r--r--ports/nrf/common-hal/audiobusio/PDMIn.c3
-rw-r--r--ports/nrf/common-hal/audiopwmio/PWMAudioOut.c3
-rw-r--r--ports/nrf/common-hal/busio/SPI.c4
-rw-r--r--ports/nrf/common-hal/busio/UART.c14
-rw-r--r--ports/nrf/common-hal/digitalio/DigitalInOut.c4
-rw-r--r--ports/stm32f4/common-hal/analogio/AnalogIn.c14
-rw-r--r--ports/stm32f4/common-hal/analogio/AnalogOut.c4
-rw-r--r--ports/stm32f4/common-hal/busio/I2C.c18
-rw-r--r--ports/stm32f4/common-hal/busio/SPI.c44
-rw-r--r--ports/stm32f4/common-hal/busio/UART.c16
-rw-r--r--ports/stm32f4/common-hal/digitalio/DigitalInOut.c12
-rw-r--r--ports/stm32f4/common-hal/pulseio/PWMOut.c16
-rw-r--r--ports/stm32f4/mpconfigport.mk2
-rw-r--r--py/builtinimport.c30
-rw-r--r--py/circuitpy_mpconfig.h3
-rw-r--r--py/circuitpy_mpconfig.mk5
-rwxr-xr-xpy/gc_long_lived.c2
-rw-r--r--py/lexer.c166
-rw-r--r--py/lexer.h16
-rwxr-xr-xpy/mpconfig.h5
-rw-r--r--py/objmodule.c7
-rw-r--r--py/parse.c61
-rw-r--r--shared-bindings/analogio/AnalogIn.c9
-rw-r--r--shared-bindings/analogio/AnalogOut.c6
-rw-r--r--shared-bindings/audiobusio/I2SOut.c14
-rw-r--r--shared-bindings/audiobusio/PDMIn.c11
-rw-r--r--shared-bindings/audioio/AudioOut.c12
-rw-r--r--shared-bindings/audiopwmio/PWMAudioOut.c12
-rw-r--r--shared-bindings/bitbangio/I2C.c7
-rw-r--r--shared-bindings/bitbangio/OneWire.c5
-rw-r--r--shared-bindings/bitbangio/SPI.c10
-rw-r--r--shared-bindings/busio/I2C.c10
-rw-r--r--shared-bindings/busio/OneWire.c4
-rw-r--r--shared-bindings/busio/SPI.c16
-rw-r--r--shared-bindings/busio/UART.c20
-rw-r--r--shared-bindings/digitalio/DigitalInOut.c6
-rw-r--r--shared-bindings/displayio/Display.c8
-rw-r--r--shared-bindings/displayio/EPaperDisplay.c8
-rw-r--r--shared-bindings/displayio/FourWire.c13
-rw-r--r--shared-bindings/displayio/I2CDisplay.c7
-rw-r--r--shared-bindings/displayio/ParallelBus.c20
-rw-r--r--shared-bindings/frequencyio/FrequencyIn.c4
-rw-r--r--shared-bindings/i2cslave/I2CSlave.c8
-rw-r--r--shared-bindings/microcontroller/Pin.c29
-rw-r--r--shared-bindings/microcontroller/Pin.h6
-rw-r--r--shared-bindings/ps2io/Ps2.c9
-rw-r--r--shared-bindings/pulseio/PWMOut.c5
-rw-r--r--shared-bindings/pulseio/PulseIn.c4
-rw-r--r--shared-bindings/rotaryio/IncrementalEncoder.c9
-rw-r--r--shared-bindings/touchio/TouchIn.c5
-rw-r--r--shared-bindings/wiznet/wiznet5k.c6
-rw-r--r--shared-module/bitbangio/SPI.c6
-rw-r--r--shared-module/board/__init__.c6
-rw-r--r--shared-module/wiznet/wiznet5k.c4
-rw-r--r--shared-module/wiznet/wiznet5k.h2
-rw-r--r--tests/basics/string_pep498_fstring.py113
-rw-r--r--tests/basics/string_pep498_fstring.py.exp0
-rw-r--r--tests/cmdline/cmd_parsetree.py.exp4
105 files changed, 1040 insertions, 382 deletions
diff --git a/.gitmodules b/.gitmodules
index 9130593f2..c25239882 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -116,7 +116,7 @@
url = https://github.com/adafruit/Adafruit_CircuitPython_Register.git
[submodule "extmod/ulab"]
path = extmod/ulab
- url = https://github.com/adafruit/circuitpython-ulab
+ url = https://github.com/v923z/micropython-ulab/
[submodule "frozen/Adafruit_CircuitPython_ESP32SPI"]
path = frozen/Adafruit_CircuitPython_ESP32SPI
url = https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI
diff --git a/docs/design_guide.rst b/docs/design_guide.rst
index 5d965f907..6f87ecf79 100644
--- a/docs/design_guide.rst
+++ b/docs/design_guide.rst
@@ -476,6 +476,8 @@ properties.
+-----------------------+-----------------------+-------------------------------------------------------------------------+
| ``distance`` | float | centimeters |
+-----------------------+-----------------------+-------------------------------------------------------------------------+
+| ``proximity`` | int | non-unit-specifc proximity values (monotonic but not actual distance) |
++-----------------------+-----------------------+-------------------------------------------------------------------------+
| ``light`` | float | non-unit-specific light levels (should be monotonic but is not lux) |
+-----------------------+-----------------------+-------------------------------------------------------------------------+
| ``lux`` | float | SI lux |
@@ -504,6 +506,8 @@ properties.
+-----------------------+-----------------------+-------------------------------------------------------------------------+
| ``weight`` | float | grams (g) |
+-----------------------+-----------------------+-------------------------------------------------------------------------+
+| ``sound_level`` | float | non-unit-specific sound level (monotonic but not actual decibels) |
++-----------------------+-----------------------+-------------------------------------------------------------------------+
Adding native modules
--------------------------------------------------------------------------------
diff --git a/extmod/ulab b/extmod/ulab
-Subproject 42d831e1e65b1c75ed90de11b87a1c4a0ebe615
+Subproject 66b89de8c714790de8647dc55f5943000204417
diff --git a/locale/ID.po b/locale/ID.po
index 4325ac322..dff59c1ce 100644
--- a/locale/ID.po
+++ b/locale/ID.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -2080,6 +2080,26 @@ msgstr "argumen keyword ekstra telah diberikan"
msgid "extra positional arguments given"
msgstr "argumen posisi ekstra telah diberikan"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2393,6 +2413,10 @@ msgstr ""
msgid "long int not supported in this build"
msgstr ""
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr ""
@@ -2721,6 +2745,10 @@ msgstr ""
msgid "queue overflow"
msgstr "antrian meluap (overflow)"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot
index 5494ed932..e9afe41c2 100644
--- a/locale/circuitpython.pot
+++ b/locale/circuitpython.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -2056,6 +2056,26 @@ msgstr ""
msgid "extra positional arguments given"
msgstr ""
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2369,6 +2389,10 @@ msgstr ""
msgid "long int not supported in this build"
msgstr ""
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr ""
@@ -2696,6 +2720,10 @@ msgstr ""
msgid "queue overflow"
msgstr ""
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/de_DE.po b/locale/de_DE.po
index 9f0ff3a43..b1ddf050e 100644
--- a/locale/de_DE.po
+++ b/locale/de_DE.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: Pascal Deneaux\n"
"Language-Team: Sebastian Plamauer, Pascal Deneaux\n"
@@ -2085,6 +2085,26 @@ msgstr "Es wurden zusätzliche Keyword-Argumente angegeben"
msgid "extra positional arguments given"
msgstr "Es wurden zusätzliche Argumente ohne Keyword angegeben"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2405,6 +2425,10 @@ msgstr ""
msgid "long int not supported in this build"
msgstr "long int wird in diesem Build nicht unterstützt"
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr "map buffer zu klein"
@@ -2734,6 +2758,10 @@ msgstr ""
msgid "queue overflow"
msgstr "Warteschlangenüberlauf"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/en_US.po b/locale/en_US.po
index 3ab55e3e3..b41734976 100644
--- a/locale/en_US.po
+++ b/locale/en_US.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -2056,6 +2056,26 @@ msgstr ""
msgid "extra positional arguments given"
msgstr ""
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2369,6 +2389,10 @@ msgstr ""
msgid "long int not supported in this build"
msgstr ""
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr ""
@@ -2696,6 +2720,10 @@ msgstr ""
msgid "queue overflow"
msgstr ""
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po
index 6e31f7638..b079dcd09 100644
--- a/locale/en_x_pirate.po
+++ b/locale/en_x_pirate.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
"Last-Translator: \n"
"Language-Team: @sommersoft, @MrCertainly\n"
@@ -2060,6 +2060,26 @@ msgstr ""
msgid "extra positional arguments given"
msgstr ""
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2373,6 +2393,10 @@ msgstr ""
msgid "long int not supported in this build"
msgstr ""
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr ""
@@ -2700,6 +2724,10 @@ msgstr ""
msgid "queue overflow"
msgstr ""
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/es.po b/locale/es.po
index 406d91234..772c38f69 100644
--- a/locale/es.po
+++ b/locale/es.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2018-08-24 22:56-0500\n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -2087,6 +2087,26 @@ msgstr "argumento(s) por palabra clave adicionales fueron dados"
msgid "extra positional arguments given"
msgstr "argumento posicional adicional dado"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2403,6 +2423,10 @@ msgstr "variable local referenciada antes de la asignación"
msgid "long int not supported in this build"
msgstr "long int no soportado en esta compilación"
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr "map buffer muy pequeño"
@@ -2734,6 +2758,10 @@ msgstr "pow() con 3 argumentos requiere enteros"
msgid "queue overflow"
msgstr "desbordamiento de cola(queue)"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/fil.po b/locale/fil.po
index 2c79dfe5c..450ed5f0e 100644
--- a/locale/fil.po
+++ b/locale/fil.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2018-12-20 22:15-0800\n"
"Last-Translator: Timothy <me@timothygarcia.ca>\n"
"Language-Team: fil\n"
@@ -2101,6 +2101,26 @@ msgstr "dagdag na keyword argument na ibinigay"
msgid "extra positional arguments given"
msgstr "dagdag na positional argument na ibinigay"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2419,6 +2439,10 @@ msgstr "local variable na reference bago na i-assign"
msgid "long int not supported in this build"
msgstr "long int hindi sinusuportahan sa build na ito"
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr "masyadong maliit ang buffer map"
@@ -2748,6 +2772,10 @@ msgstr "pow() na may 3 argumento kailangan ng integers"
msgid "queue overflow"
msgstr "puno na ang pila (overflow)"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/fr.po b/locale/fr.po
index 220b66de8..708176c6b 100644
--- a/locale/fr.po
+++ b/locale/fr.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2019-04-14 20:05+0100\n"
"Last-Translator: Pierrick Couturier <arofarn@arofarn.info>\n"
"Language-Team: fr\n"
@@ -2126,6 +2126,26 @@ msgstr "argument(s) nommé(s) supplémentaire(s) donné(s)"
msgid "extra positional arguments given"
msgstr "argument(s) positionnel(s) supplémentaire(s) donné(s)"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2443,6 +2463,10 @@ msgstr "variable locale référencée avant d'être assignée"
msgid "long int not supported in this build"
msgstr "entiers longs non supportés dans cette build"
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr "tampon trop petit"
@@ -2780,6 +2804,10 @@ msgstr "pow() avec 3 arguments nécessite des entiers"
msgid "queue overflow"
msgstr "dépassement de file"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/it_IT.po b/locale/it_IT.po
index 19162faf5..f4eeea46f 100644
--- a/locale/it_IT.po
+++ b/locale/it_IT.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2018-10-02 16:27+0200\n"
"Last-Translator: Enrico Paganin <enrico.paganin@mail.com>\n"
"Language-Team: \n"
@@ -2102,6 +2102,26 @@ msgstr "argomento nominato aggiuntivo fornito"
msgid "extra positional arguments given"
msgstr "argomenti posizonali extra dati"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2421,6 +2441,10 @@ msgstr "variabile locale richiamata prima di un assegnamento"
msgid "long int not supported in this build"
msgstr "long int non supportata in questa build"
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr "map buffer troppo piccolo"
@@ -2755,6 +2779,10 @@ msgstr "pow() con 3 argomenti richiede interi"
msgid "queue overflow"
msgstr "overflow della coda"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/ko.po b/locale/ko.po
index 067d3491f..96bb26d09 100644
--- a/locale/ko.po
+++ b/locale/ko.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2019-05-06 14:22-0700\n"
"Last-Translator: \n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -2061,6 +2061,26 @@ msgstr ""
msgid "extra positional arguments given"
msgstr ""
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2374,6 +2394,10 @@ msgstr ""
msgid "long int not supported in this build"
msgstr ""
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr ""
@@ -2701,6 +2725,10 @@ msgstr ""
msgid "queue overflow"
msgstr ""
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/pl.po b/locale/pl.po
index a1d47caa6..581dac8d0 100644
--- a/locale/pl.po
+++ b/locale/pl.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2019-03-19 18:37-0700\n"
"Last-Translator: Radomir Dopieralski <circuitpython@sheep.art.pl>\n"
"Language-Team: pl\n"
@@ -2065,6 +2065,26 @@ msgstr "nadmiarowe argumenty nazwane"
msgid "extra positional arguments given"
msgstr "nadmiarowe argumenty pozycyjne"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2378,6 +2398,10 @@ msgstr "zmienna lokalna użyta przed przypisaniem"
msgid "long int not supported in this build"
msgstr "long int jest nieobsługiwany"
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr "bufor mapy zbyt mały"
@@ -2706,6 +2730,10 @@ msgstr "trzyargumentowe pow() wymaga liczb całkowitych"
msgid "queue overflow"
msgstr "przepełnienie kolejki"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/pt_BR.po b/locale/pt_BR.po
index f37d75050..3dce592e3 100644
--- a/locale/pt_BR.po
+++ b/locale/pt_BR.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2018-10-02 21:14-0000\n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -2078,6 +2078,26 @@ msgstr "argumentos extras de palavras-chave passados"
msgid "extra positional arguments given"
msgstr "argumentos extra posicionais passados"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2391,6 +2411,10 @@ msgstr ""
msgid "long int not supported in this build"
msgstr ""
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr ""
@@ -2718,6 +2742,10 @@ msgstr ""
msgid "queue overflow"
msgstr "estouro de fila"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po
index 465920d5d..cc23d7fc8 100644
--- a/locale/zh_Latn_pinyin.po
+++ b/locale/zh_Latn_pinyin.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: circuitpython-cn\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2020-03-03 20:13-0600\n"
+"POT-Creation-Date: 2020-03-09 08:19-0500\n"
"PO-Revision-Date: 2019-04-13 10:10-0700\n"
"Last-Translator: hexthat\n"
"Language-Team: Chinese Hanyu Pinyin\n"
@@ -2093,6 +2093,26 @@ msgstr "éwài de guānjiàn cí cānshù"
msgid "extra positional arguments given"
msgstr "gěi chūle éwài de wèizhì cānshù"
+#: py/parse.c
+msgid "f-string expression part cannot include a '#'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string expression part cannot include a backslash"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: empty expression not allowed"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: expecting '}'"
+msgstr ""
+
+#: py/parse.c
+msgid "f-string: single '}' is not allowed"
+msgstr ""
+
#: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c
#: shared-bindings/displayio/OnDiskBitmap.c
msgid "file must be a file opened in byte mode"
@@ -2407,6 +2427,10 @@ msgstr "fùzhí qián yǐnyòng de júbù biànliàng"
msgid "long int not supported in this build"
msgstr "cǐ bǎnběn bù zhīchí zhǎng zhěngshù"
+#: py/parse.c
+msgid "malformed f-string"
+msgstr ""
+
#: shared-bindings/_stage/Layer.c
msgid "map buffer too small"
msgstr "dìtú huǎnchōng qū tài xiǎo"
@@ -2735,6 +2759,10 @@ msgstr "pow() yǒu 3 cānshù xūyào zhěngshù"
msgid "queue overflow"
msgstr "duìliè yìchū"
+#: py/parse.c
+msgid "raw f-strings are not implemented"
+msgstr ""
+
#: extmod/ulab/code/fft.c
msgid "real and imaginary parts must be of equal length"
msgstr ""
diff --git a/ports/atmel-samd/boards/hallowing_m4_express/board.c b/ports/atmel-samd/boards/hallowing_m4_express/board.c
index 5d1ef6d9b..6bb2a591f 100644
--- a/ports/atmel-samd/boards/hallowing_m4_express/board.c
+++ b/ports/atmel-samd/boards/hallowing_m4_express/board.c
@@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/atmel-samd/boards/monster_m4sk/board.c b/ports/atmel-samd/boards/monster_m4sk/board.c
index 40141ca15..2377f4a9d 100644
--- a/ports/atmel-samd/boards/monster_m4sk/board.c
+++ b/ports/atmel-samd/boards/monster_m4sk/board.c
@@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c
index 85a588879..2d9b31647 100644
--- a/ports/atmel-samd/boards/openbook_m4/board.c
+++ b/ports/atmel-samd/boards/openbook_m4/board.c
@@ -55,7 +55,7 @@ uint8_t stop_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c
index 1872d1876..5f5a01e48 100644
--- a/ports/atmel-samd/boards/pewpew_m4/board.c
+++ b/ports/atmel-samd/boards/pewpew_m4/board.c
@@ -97,7 +97,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c
index 28e1aec13..bead06f3c 100644
--- a/ports/atmel-samd/boards/pybadge/board.c
+++ b/ports/atmel-samd/boards/pybadge/board.c
@@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/atmel-samd/boards/pybadge_airlift/board.c b/ports/atmel-samd/boards/pybadge_airlift/board.c
index fbb4441f0..061f3d777 100644
--- a/ports/atmel-samd/boards/pybadge_airlift/board.c
+++ b/ports/atmel-samd/boards/pybadge_airlift/board.c
@@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c
index c052614db..70d4a05dc 100644
--- a/ports/atmel-samd/boards/pygamer/board.c
+++ b/ports/atmel-samd/boards/pygamer/board.c
@@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/atmel-samd/boards/pygamer_advance/board.c b/ports/atmel-samd/boards/pygamer_advance/board.c
index a138c7e50..ff2da34a2 100644
--- a/ports/atmel-samd/boards/pygamer_advance/board.c
+++ b/ports/atmel-samd/boards/pygamer_advance/board.c
@@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk
index a0449d7bb..b1f916ec2 100644
--- a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk
@@ -6,6 +6,7 @@ USB_PID = 0x8062
USB_PRODUCT = "Sol"
USB_MANUFACTURER = "Winterbloom"
USB_INTERFACE_NAME = "Sol"
+USB_DEVICES = "CDC,MSC,AUDIO"
CHIP_VARIANT = SAMD51J20A
CHIP_FAMILY = samd51
@@ -25,6 +26,7 @@ CIRCUITPY_I2CSLAVE = 0
CIRCUITPY_NETWORK = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_PS2IO = 0
+CIRCUITPY_USB_HID = 0
# Enable micropython.native
CIRCUITPY_ENABLE_MPY_NATIVE = 1
diff --git a/ports/atmel-samd/common-hal/analogio/AnalogIn.c b/ports/atmel-samd/common-hal/analogio/AnalogIn.c
index fc11d5d19..2bd218cdd 100644
--- a/ports/atmel-samd/common-hal/analogio/AnalogIn.c
+++ b/ports/atmel-samd/common-hal/analogio/AnalogIn.c
@@ -73,7 +73,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
}
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
@@ -81,7 +81,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
return;
}
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
void analogin_reset() {
diff --git a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c
index 05a6aaf7b..8f827e7fb 100644
--- a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c
+++ b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c
@@ -89,6 +89,7 @@ void i2sout_reset(void) {
#endif
}
+// Caller validates that pins are free.
void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
const mcu_pin_obj_t* bit_clock, const mcu_pin_obj_t* word_select,
const mcu_pin_obj_t* data, bool left_justified) {
@@ -182,9 +183,6 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
#ifdef SAMD21
#define GPIO_I2S_FUNCTION GPIO_PIN_FUNCTION_G
#endif
- assert_pin_free(bit_clock);
- assert_pin_free(word_select);
- assert_pin_free(data);
self->bit_clock = bit_clock;
self->word_select = word_select;
@@ -204,7 +202,7 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
}
bool common_hal_audiobusio_i2sout_deinited(audiobusio_i2sout_obj_t* self) {
- return self->bit_clock == mp_const_none;
+ return self->bit_clock == NULL;
}
void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) {
@@ -213,11 +211,11 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) {
}
reset_pin_number(self->bit_clock->number);
- self->bit_clock = mp_const_none;
+ self->bit_clock = NULL;
reset_pin_number(self->word_select->number);
- self->word_select = mp_const_none;
+ self->word_select = NULL;
reset_pin_number(self->data->number);
- self->data = mp_const_none;
+ self->data = NULL;
}
void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
index 3a51cce8f..76e66ab45 100644
--- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
+++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
@@ -74,6 +74,7 @@ void pdmin_reset(void) {
I2S->CTRLA.reg = I2S_CTRLA_SWRST;
}
+// Caller validates that pins are free.
void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
const mcu_pin_obj_t* clock_pin,
const mcu_pin_obj_t* data_pin,
@@ -157,8 +158,6 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
#ifdef SAMD21
#define GPIO_I2S_FUNCTION GPIO_PIN_FUNCTION_G
#endif
- assert_pin_free(clock_pin);
- assert_pin_free(data_pin);
uint32_t clock_divisor = (uint32_t) roundf( 48000000.0f / sample_rate / oversample);
float mic_clock_freq = 48000000.0f / clock_divisor;
@@ -219,7 +218,7 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
}
bool common_hal_audiobusio_pdmin_deinited(audiobusio_pdmin_obj_t* self) {
- return self->clock_pin == mp_const_none;
+ return self->clock_pin == NULL;
}
void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) {
@@ -237,8 +236,8 @@ void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) {
reset_pin_number(self->clock_pin->number);
reset_pin_number(self->data_pin->number);
- self->clock_pin = mp_const_none;
- self->data_pin = mp_const_none;
+ self->clock_pin = NULL;
+ self->data_pin = NULL;
}
uint8_t common_hal_audiobusio_pdmin_get_bit_depth(audiobusio_pdmin_obj_t* self) {
diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c
index b75c2b335..75621b361 100644
--- a/ports/atmel-samd/common-hal/audioio/AudioOut.c
+++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c
@@ -115,6 +115,7 @@ void audioout_reset(void) {
// TODO(tannewt): Turn off the DAC clocks to save power.
}
+// Caller validates that pins are free.
void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
const mcu_pin_obj_t* left_channel, const mcu_pin_obj_t* right_channel, uint16_t quiescent_value) {
#ifdef SAMD51
@@ -135,7 +136,6 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
if (left_channel != &pin_PA02) {
mp_raise_ValueError(translate("Invalid pin"));
}
- assert_pin_free(left_channel);
claim_pin(left_channel);
#endif
#ifdef SAMD51
@@ -143,7 +143,6 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
if (left_channel != &pin_PA02 && left_channel != &pin_PA05) {
mp_raise_ValueError(translate("Invalid pin for left channel"));
}
- assert_pin_free(left_channel);
if (right_channel != NULL && right_channel != &pin_PA02 && right_channel != &pin_PA05) {
mp_raise_ValueError(translate("Invalid pin for right channel"));
}
@@ -304,7 +303,7 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
}
bool common_hal_audioio_audioout_deinited(audioio_audioout_obj_t* self) {
- return self->left_channel == mp_const_none;
+ return self->left_channel == NULL;
}
void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) {
@@ -332,10 +331,10 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) {
tc_set_enable(tc_insts[self->tc_index], false);
reset_pin_number(self->left_channel->number);
- self->left_channel = mp_const_none;
+ self->left_channel = NULL;
#ifdef SAMD51
reset_pin_number(self->right_channel->number);
- self->right_channel = mp_const_none;
+ self->right_channel = NULL;
#endif
}
diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c
index 7a1426bed..1dc389027 100644
--- a/ports/atmel-samd/common-hal/busio/SPI.c
+++ b/ports/atmel-samd/common-hal/busio/SPI.c
@@ -89,8 +89,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
Sercom* sercom = NULL;
uint8_t sercom_index;
uint32_t clock_pinmux = 0;
- bool mosi_none = mosi == mp_const_none || mosi == NULL;
- bool miso_none = miso == mp_const_none || miso == NULL;
+ bool mosi_none = mosi == NULL;
+ bool miso_none = miso == NULL;
uint32_t mosi_pinmux = 0;
uint32_t miso_pinmux = 0;
uint8_t clock_pad = 0;
diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c
index fb9968605..1f6b75f97 100644
--- a/ports/atmel-samd/common-hal/busio/UART.c
+++ b/ports/atmel-samd/common-hal/busio/UART.c
@@ -65,7 +65,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
uint32_t tx_pinmux = 0;
uint8_t tx_pad = 255; // Unset pad
- if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) {
+ if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
}
@@ -73,8 +73,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
mp_raise_NotImplementedError(translate("bytes > 8 bits not supported"));
}
- bool have_tx = tx != mp_const_none;
- bool have_rx = rx != mp_const_none;
+ bool have_tx = tx != NULL;
+ bool have_rx = rx != NULL;
if (!have_tx && !have_rx) {
mp_raise_ValueError(translate("tx and rx cannot both be None"));
}
@@ -109,7 +109,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
#endif
tx_pinmux = PINMUX(tx->number, (i == 0) ? MUX_C : MUX_D);
tx_pad = tx->sercom[i].pad;
- if (rx == mp_const_none) {
+ if (rx == NULL) {
sercom = potential_sercom;
break;
}
diff --git a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c
index e167cbb69..68d3da806 100644
--- a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c
+++ b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c
@@ -55,7 +55,7 @@ void common_hal_digitalio_digitalinout_never_reset(
}
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t* self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) {
@@ -63,7 +63,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self
return;
}
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pulseio/PWMOut.c
index 0adb23fc5..fef581584 100644
--- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c
+++ b/ports/atmel-samd/common-hal/pulseio/PWMOut.c
@@ -292,7 +292,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
}
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
@@ -319,7 +319,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
}
}
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) {
diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk
index 7565e41a4..6b6b335d3 100644
--- a/ports/atmel-samd/mpconfigport.mk
+++ b/ports/atmel-samd/mpconfigport.mk
@@ -40,6 +40,8 @@ endif
# SAMD21 needs separate endpoint pairs for MSC BULK IN and BULK OUT, otherwise it's erratic.
USB_MSC_EP_NUM_OUT = 1
+MICROPY_PY_ULAB = 0
+
endif # samd21
# Put samd51-only choices here.
diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile
index a0782c4e9..e2fce976d 100644
--- a/ports/cxd56/Makefile
+++ b/ports/cxd56/Makefile
@@ -176,6 +176,10 @@ OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_EXPANDED:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED_MODULE_EXPANDED:.c=.o))
+ifeq ($(INTERNAL_LIBM),1)
+OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
+endif
+OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o))
# List of sources for qstr extraction
SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)
diff --git a/ports/cxd56/common-hal/analogio/AnalogIn.c b/ports/cxd56/common-hal/analogio/AnalogIn.c
index e2ca5e4a4..cdf37c06a 100644
--- a/ports/cxd56/common-hal/analogio/AnalogIn.c
+++ b/ports/cxd56/common-hal/analogio/AnalogIn.c
@@ -83,7 +83,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const
// start ADC
ioctl(analogin_dev[self->number].fd, ANIOC_CXD56_START, 0);
-
+
self->pin = pin;
}
@@ -97,7 +97,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
close(analogin_dev[self->number].fd);
analogin_dev[self->number].fd = -1;
- self->pin = mp_const_none;
+ self->pin = NULL;
}
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
diff --git a/ports/cxd56/common-hal/busio/UART.c b/ports/cxd56/common-hal/busio/UART.c
index 3ed980952..3bca240e0 100644
--- a/ports/cxd56/common-hal/busio/UART.c
+++ b/ports/cxd56/common-hal/busio/UART.c
@@ -60,10 +60,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
mp_float_t timeout, uint16_t receiver_buffer_size) {
struct termios tio;
- if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) {
+ if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
}
-
+
if (bits != 8) {
mp_raise_ValueError(translate("Could not initialize UART"));
}
diff --git a/ports/cxd56/common-hal/digitalio/DigitalInOut.c b/ports/cxd56/common-hal/digitalio/DigitalInOut.c
index 7b1f6cc03..c9af12e44 100644
--- a/ports/cxd56/common-hal/digitalio/DigitalInOut.c
+++ b/ports/cxd56/common-hal/digitalio/DigitalInOut.c
@@ -56,11 +56,11 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
board_gpio_config(self->pin->number, 0, false, true, PIN_FLOAT);
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) {
diff --git a/ports/cxd56/common-hal/pulseio/PWMOut.c b/ports/cxd56/common-hal/pulseio/PWMOut.c
index a0b4e79c6..7e0be566b 100644
--- a/ports/cxd56/common-hal/pulseio/PWMOut.c
+++ b/ports/cxd56/common-hal/pulseio/PWMOut.c
@@ -50,7 +50,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self,
const mcu_pin_obj_t *pin, uint16_t duty, uint32_t frequency,
bool variable_frequency) {
self->number = -1;
-
+
for (int i = 0; i < MP_ARRAY_SIZE(pwmout_dev); i++) {
if (pin->number == pwmout_dev[i].pin->number) {
self->number = i;
@@ -95,7 +95,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) {
pwmout_dev[self->number].fd = -1;
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t *self) {
@@ -131,11 +131,11 @@ bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t *self
void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) {
never_reset_pin_number(self->pin->number);
- pwmout_dev[self->number].reset = false;
+ pwmout_dev[self->number].reset = false;
}
void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
- pwmout_dev[self->number].reset = true;
+ pwmout_dev[self->number].reset = true;
}
void pwmout_reset(void) {
diff --git a/ports/cxd56/common-hal/pulseio/PulseIn.c b/ports/cxd56/common-hal/pulseio/PulseIn.c
index dd2773d1d..65ca1d97e 100644
--- a/ports/cxd56/common-hal/pulseio/PulseIn.c
+++ b/ports/cxd56/common-hal/pulseio/PulseIn.c
@@ -106,7 +106,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
board_gpio_int(self->pin->number, true);
}
-
+
void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
if (common_hal_pulseio_pulsein_deinited(self)) {
return;
@@ -116,18 +116,18 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
board_gpio_intconfig(self->pin->number, 0, false, NULL);
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
-
+
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
-
+
void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) {
board_gpio_int(self->pin->number, false);
self->paused = true;
}
-
+
void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, uint16_t trigger_duration) {
// Make sure we're paused.
common_hal_pulseio_pulsein_pause(self);
@@ -147,14 +147,14 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, uint16_t tri
pulsein_set_config(self, true);
board_gpio_int(self->pin->number, true);
}
-
+
void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t *self) {
common_hal_mcu_disable_interrupts();
self->start = 0;
self->len = 0;
common_hal_mcu_enable_interrupts();
}
-
+
uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
if (self->len == 0) {
mp_raise_IndexError(translate("pop from an empty PulseIn"));
@@ -167,19 +167,19 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {
return value;
}
-
+
uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t *self) {
return self->maxlen;
}
-
+
bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t *self) {
return self->paused;
}
-
+
uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t *self) {
return self->len;
}
-
+
uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_t index) {
common_hal_mcu_disable_interrupts();
if (index < 0) {
@@ -193,4 +193,3 @@ uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, int16_
common_hal_mcu_enable_interrupts();
return value;
}
- \ No newline at end of file
diff --git a/ports/cxd56/mpconfigport.mk b/ports/cxd56/mpconfigport.mk
index a418ae8e9..ad3d0e72d 100644
--- a/ports/cxd56/mpconfigport.mk
+++ b/ports/cxd56/mpconfigport.mk
@@ -18,3 +18,5 @@ CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FREQUENCYIO = 0
+
+INTERNAL_LIBM = 1
diff --git a/ports/mimxrt10xx/common-hal/analogio/AnalogIn.c b/ports/mimxrt10xx/common-hal/analogio/AnalogIn.c
index d714001f3..2cc2681b4 100644
--- a/ports/mimxrt10xx/common-hal/analogio/AnalogIn.c
+++ b/ports/mimxrt10xx/common-hal/analogio/AnalogIn.c
@@ -58,7 +58,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
}
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
@@ -66,7 +66,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
return;
}
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
diff --git a/ports/mimxrt10xx/common-hal/busio/UART.c b/ports/mimxrt10xx/common-hal/busio/UART.c
index 4fd7afecb..b34b948b2 100644
--- a/ports/mimxrt10xx/common-hal/busio/UART.c
+++ b/ports/mimxrt10xx/common-hal/busio/UART.c
@@ -80,8 +80,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
// TODO: Allow none rx or tx
- bool have_tx = tx != mp_const_none;
- bool have_rx = rx != mp_const_none;
+ bool have_tx = tx != NULL;
+ bool have_rx = rx != NULL;
if (!have_tx && !have_rx) {
mp_raise_ValueError(translate("tx and rx cannot both be None"));
}
@@ -116,8 +116,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
// Filter for sane settings for RS485
- if (rs485_dir != mp_const_none) {
- if ((rts != mp_const_none) || (cts != mp_const_none)) {
+ if (rs485_dir != NULL) {
+ if ((rts != NULL) || (cts != NULL)) {
mp_raise_ValueError(translate("Cannot specify RTS or CTS in RS485 mode"));
}
// For IMXRT the RTS pin is used for RS485 direction
@@ -133,7 +133,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
const uint32_t rts_count = sizeof(mcu_uart_rts_list) / sizeof(mcu_periph_obj_t);
const uint32_t cts_count = sizeof(mcu_uart_cts_list) / sizeof(mcu_periph_obj_t);
- if (rts != mp_const_none) {
+ if (rts != NULL) {
for (uint32_t i=0; i < rts_count; ++i) {
if (mcu_uart_rts_list[i].bank_idx == self->rx_pin->bank_idx) {
if (mcu_uart_rts_list[i].pin == rts) {
@@ -146,7 +146,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
mp_raise_ValueError(translate("Selected RTS pin not valid"));
}
- if (cts != mp_const_none) {
+ if (cts != NULL) {
for (uint32_t i=0; i < cts_count; ++i) {
if (mcu_uart_cts_list[i].bank_idx == self->rx_pin->bank_idx) {
if (mcu_uart_cts_list[i].pin == cts) {
@@ -158,7 +158,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
if (self->cts_pin == NULL)
mp_raise_ValueError(translate("Selected CTS pin not valid"));
}
-
+
self->uart = mcu_uart_banks[self->tx_pin->bank_idx - 1];
config_periph_pin(self->rx_pin);
@@ -166,7 +166,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
if (self->rts_pin)
config_periph_pin(self->rts_pin);
if (self->cts_pin)
- config_periph_pin(self->cts_pin);
+ config_periph_pin(self->cts_pin);
lpuart_config_t config = { 0 };
LPUART_GetDefaultConfig(&config);
@@ -187,7 +187,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
// Before we init, setup RS485 direction pin
// ..unfortunately this isn't done by the driver library
uint32_t modir = (self->uart->MODIR) & ~(LPUART_MODIR_TXRTSPOL_MASK | LPUART_MODIR_TXRTSE_MASK);
- if (rs485_dir != mp_const_none) {
+ if (rs485_dir != NULL) {
modir |= LPUART_MODIR_TXRTSE_MASK;
if (rs485_invert)
modir |= LPUART_MODIR_TXRTSPOL_MASK;
diff --git a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c
index d69a18d96..603515764 100644
--- a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c
+++ b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c
@@ -78,7 +78,7 @@ void common_hal_digitalio_digitalinout_never_reset(
}
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t* self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) {
@@ -86,7 +86,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self
return;
}
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
diff --git a/ports/nrf/boards/clue_nrf52840_express/board.c b/ports/nrf/boards/clue_nrf52840_express/board.c
index 5f5337a3d..e342c6d93 100644
--- a/ports/nrf/boards/clue_nrf52840_express/board.c
+++ b/ports/nrf/boards/clue_nrf52840_express/board.c
@@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/nrf/boards/ohs2020_badge/board.c b/ports/nrf/boards/ohs2020_badge/board.c
index 7e3e05814..9e881d763 100644
--- a/ports/nrf/boards/ohs2020_badge/board.c
+++ b/ports/nrf/boards/ohs2020_badge/board.c
@@ -49,7 +49,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
- common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, mp_const_none);
+ common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
diff --git a/ports/nrf/common-hal/analogio/AnalogIn.c b/ports/nrf/common-hal/analogio/AnalogIn.c
index 3bc097019..dbcc5281c 100644
--- a/ports/nrf/common-hal/analogio/AnalogIn.c
+++ b/ports/nrf/common-hal/analogio/AnalogIn.c
@@ -55,7 +55,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, const
}
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
@@ -65,7 +65,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
nrf_gpio_cfg_default(self->pin->number);
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
diff --git a/ports/nrf/common-hal/audiobusio/PDMIn.c b/ports/nrf/common-hal/audiobusio/PDMIn.c
index a7f9c9d74..ddd34174b 100644
--- a/ports/nrf/common-hal/audiobusio/PDMIn.c
+++ b/ports/nrf/common-hal/audiobusio/PDMIn.c
@@ -34,6 +34,7 @@ NRF_PDM_Type *nrf_pdm = NRF_PDM;
static uint32_t dummy_buffer[4];
+// Caller validates that pins are free.
void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
const mcu_pin_obj_t* clock_pin,
const mcu_pin_obj_t* data_pin,
@@ -41,8 +42,6 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
uint8_t bit_depth,
bool mono,
uint8_t oversample) {
- assert_pin_free(clock_pin);
- assert_pin_free(data_pin);
claim_pin(clock_pin);
claim_pin(data_pin);
diff --git a/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c b/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
index cdb57bbe1..7b99901d5 100644
--- a/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
+++ b/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c
@@ -155,10 +155,9 @@ void audiopwmout_background() {
}
}
+// Caller validates that pins are free.
void common_hal_audiopwmio_pwmaudioout_construct(audiopwmio_pwmaudioout_obj_t* self,
const mcu_pin_obj_t* left_channel, const mcu_pin_obj_t* right_channel, uint16_t quiescent_value) {
- assert_pin_free(left_channel);
- assert_pin_free(right_channel);
self->pwm = pwmout_allocate(256, PWM_PRESCALER_PRESCALER_DIV_1, true, NULL, NULL);
if (!self->pwm) {
mp_raise_RuntimeError(translate("All timers in use"));
diff --git a/ports/nrf/common-hal/busio/SPI.c b/ports/nrf/common-hal/busio/SPI.c
index b4ebddde1..3f205e778 100644
--- a/ports/nrf/common-hal/busio/SPI.c
+++ b/ports/nrf/common-hal/busio/SPI.c
@@ -155,7 +155,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
self->clock_pin_number = clock->number;
claim_pin(clock);
- if (mosi != mp_const_none) {
+ if (mosi != NULL) {
config.mosi_pin = mosi->number;
self->MOSI_pin_number = mosi->number;
claim_pin(mosi);
@@ -163,7 +163,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *
self->MOSI_pin_number = NO_PIN;
}
- if (miso != mp_const_none) {
+ if (miso != NULL) {
config.miso_pin = miso->number;
self->MISO_pin_number = mosi->number;
claim_pin(miso);
diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c
index 933faf17b..14fa36374 100644
--- a/ports/nrf/common-hal/busio/UART.c
+++ b/ports/nrf/common-hal/busio/UART.c
@@ -135,10 +135,10 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
uint32_t baudrate, uint8_t bits, uart_parity_t parity, uint8_t stop,
mp_float_t timeout, uint16_t receiver_buffer_size) {
- if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert)) {
+ if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert)) {
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
}
-
+
// Find a free UART peripheral.
self->uarte = NULL;
for (size_t i = 0 ; i < MP_ARRAY_SIZE(nrfx_uartes); i++) {
@@ -152,7 +152,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
mp_raise_ValueError(translate("All UART peripherals are in use"));
}
- if ( (tx == mp_const_none) && (rx == mp_const_none) ) {
+ if ( (tx == NULL) && (rx == NULL) ) {
mp_raise_ValueError(translate("tx and rx cannot both be None"));
}
@@ -165,8 +165,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
nrfx_uarte_config_t config = {
- .pseltxd = (tx == mp_const_none) ? NRF_UARTE_PSEL_DISCONNECTED : tx->number,
- .pselrxd = (rx == mp_const_none) ? NRF_UARTE_PSEL_DISCONNECTED : rx->number,
+ .pseltxd = (tx == NULL) ? NRF_UARTE_PSEL_DISCONNECTED : tx->number,
+ .pselrxd = (rx == NULL) ? NRF_UARTE_PSEL_DISCONNECTED : rx->number,
.pselcts = NRF_UARTE_PSEL_DISCONNECTED,
.pselrts = NRF_UARTE_PSEL_DISCONNECTED,
.p_context = self,
@@ -181,7 +181,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
_VERIFY_ERR(nrfx_uarte_init(self->uarte, &config, uart_callback_irq));
// Init buffer for rx
- if ( rx != mp_const_none ) {
+ if ( rx != NULL ) {
// 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
@@ -200,7 +200,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
claim_pin(rx);
}
- if ( tx != mp_const_none ) {
+ if ( tx != NULL ) {
self->tx_pin_number = tx->number;
claim_pin(tx);
} else {
diff --git a/ports/nrf/common-hal/digitalio/DigitalInOut.c b/ports/nrf/common-hal/digitalio/DigitalInOut.c
index 0836962c6..c5a7a7dfb 100644
--- a/ports/nrf/common-hal/digitalio/DigitalInOut.c
+++ b/ports/nrf/common-hal/digitalio/DigitalInOut.c
@@ -46,7 +46,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
}
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) {
@@ -56,7 +56,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
nrf_gpio_cfg_default(self->pin->number);
reset_pin_number(self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
diff --git a/ports/stm32f4/common-hal/analogio/AnalogIn.c b/ports/stm32f4/common-hal/analogio/AnalogIn.c
index 3ee3c4dbb..1d1b308b6 100644
--- a/ports/stm32f4/common-hal/analogio/AnalogIn.c
+++ b/ports/stm32f4/common-hal/analogio/AnalogIn.c
@@ -45,11 +45,11 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
}
// TODO: add ADC traits to structure?
- // Note that ADC2 is always bundled pin-to-pin with ADC1 if it exists, and used only
- // for dual conversion. For this basic application it is never used.
+ // Note that ADC2 is always bundled pin-to-pin with ADC1 if it exists, and used only
+ // for dual conversion. For this basic application it is never used.
LL_GPIO_SetPinMode(pin_port(pin->port), (uint32_t)pin_mask(pin->number), LL_GPIO_MODE_ANALOG);
if (pin->adc_unit & 0x01) {
- LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
+ LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC1);
} else if (pin->adc_unit == 0x04) {
#ifdef LL_APB2_GRP1_PERIPH_ADC3
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_ADC3);
@@ -62,7 +62,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t* self,
}
bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
@@ -70,7 +70,7 @@ void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) {
return;
}
reset_pin_number(self->pin->port,self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
@@ -116,10 +116,10 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
HAL_ADC_Start(&AdcHandle);
- HAL_ADC_PollForConversion(&AdcHandle,1);
+ HAL_ADC_PollForConversion(&AdcHandle,1);
uint16_t value = (uint16_t)HAL_ADC_GetValue(&AdcHandle);
HAL_ADC_Stop(&AdcHandle);
-
+
// // Shift the value to be 16 bit.
return value << 4;
}
diff --git a/ports/stm32f4/common-hal/analogio/AnalogOut.c b/ports/stm32f4/common-hal/analogio/AnalogOut.c
index 79ced0492..2ea969f50 100644
--- a/ports/stm32f4/common-hal/analogio/AnalogOut.c
+++ b/ports/stm32f4/common-hal/analogio/AnalogOut.c
@@ -39,7 +39,7 @@
#include "stm32f4xx_hal.h"
-//DAC is shared between both channels.
+//DAC is shared between both channels.
#if HAS_DAC
DAC_HandleTypeDef handle;
#endif
@@ -97,7 +97,7 @@ bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
#if HAS_DAC
reset_pin_number(self->pin->port,self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
dac_on[self->dac_index] = false;
//turn off the DAC if both channels are off
diff --git a/ports/stm32f4/common-hal/busio/I2C.c b/ports/stm32f4/common-hal/busio/I2C.c
index 1437e5e78..8e98b966d 100644
--- a/ports/stm32f4/common-hal/busio/I2C.c
+++ b/ports/stm32f4/common-hal/busio/I2C.c
@@ -100,14 +100,14 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = self->sda->altfn_index;
+ GPIO_InitStruct.Alternate = self->sda->altfn_index;
HAL_GPIO_Init(pin_port(sda->port), &GPIO_InitStruct);
GPIO_InitStruct.Pin = pin_mask(scl->number);
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
- GPIO_InitStruct.Alternate = self->scl->altfn_index;
+ GPIO_InitStruct.Alternate = self->scl->altfn_index;
HAL_GPIO_Init(pin_port(scl->port), &GPIO_InitStruct);
//Note: due to I2C soft reboot issue, do not relocate clock init.
@@ -144,7 +144,7 @@ void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) {
}
bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) {
- return self->sda->pin == mp_const_none;
+ return self->sda == NULL;
}
void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
@@ -158,8 +158,8 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
reset_pin_number(self->sda->pin->port,self->sda->pin->number);
reset_pin_number(self->scl->pin->port,self->scl->pin->number);
- self->sda = mp_const_none;
- self->scl = mp_const_none;
+ self->sda = NULL;
+ self->scl = NULL;
}
bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
@@ -169,7 +169,7 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) {
bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) {
bool grabbed_lock = false;
- //Critical section code that may be required at some point.
+ //Critical section code that may be required at some point.
// uint32_t store_primask = __get_PRIMASK();
// __disable_irq();
// __DMB();
@@ -195,19 +195,19 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) {
uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr,
const uint8_t *data, size_t len, bool transmit_stop_bit) {
- HAL_StatusTypeDef result = HAL_I2C_Master_Transmit(&(self->handle), (uint16_t)(addr << 1),
+ HAL_StatusTypeDef result = HAL_I2C_Master_Transmit(&(self->handle), (uint16_t)(addr << 1),
(uint8_t *)data, (uint16_t)len, 500);
return result == HAL_OK ? 0 : MP_EIO;
}
uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr,
uint8_t *data, size_t len) {
- return HAL_I2C_Master_Receive(&(self->handle), (uint16_t)(addr<<1), data, (uint16_t)len, 500)
+ return HAL_I2C_Master_Receive(&(self->handle), (uint16_t)(addr<<1), data, (uint16_t)len, 500)
== HAL_OK ? 0 : MP_EIO;
}
STATIC void i2c_clock_enable(uint8_t mask) {
- //Note: hard reset required due to soft reboot issue.
+ //Note: hard reset required due to soft reboot issue.
#ifdef I2C1
if (mask & (1 << 0)) {
__HAL_RCC_I2C1_CLK_ENABLE();
diff --git a/ports/stm32f4/common-hal/busio/SPI.c b/ports/stm32f4/common-hal/busio/SPI.c
index e00b5e9f0..7e25e0a57 100644
--- a/ports/stm32f4/common-hal/busio/SPI.c
+++ b/ports/stm32f4/common-hal/busio/SPI.c
@@ -49,7 +49,7 @@ STATIC void spi_clock_enable(uint8_t mask);
STATIC void spi_clock_disable(uint8_t mask);
STATIC uint32_t get_busclock(SPI_TypeDef * instance) {
- //SPI2 and 3 are on PCLK1, if they exist.
+ //SPI2 and 3 are on PCLK1, if they exist.
#ifdef SPI2
if (instance == SPI2) return HAL_RCC_GetPCLK1Freq();
#endif
@@ -113,7 +113,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
for (uint i = 0; i < sck_len; i++) {
if (mcu_spi_sck_list[i].pin == sck) {
//if both MOSI and MISO exist, loop search normally
- if ((mosi != mp_const_none) && (miso != mp_const_none)) {
+ if ((mosi != NULL) && (miso != NULL)) {
//MOSI
for (uint j = 0; j < mosi_len; j++) {
if (mcu_spi_mosi_list[j].pin == mosi) {
@@ -133,11 +133,11 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
self->miso = &mcu_spi_miso_list[k];
break;
}
- }
+ }
}
}
// if just MISO, reduce search
- } else if (miso != mp_const_none) {
+ } else if (miso != NULL) {
for (uint j = 0; j < miso_len; j++) {
if ((mcu_spi_miso_list[j].pin == miso) //only SCK and MISO need the same index
&& (mcu_spi_sck_list[i].spi_index == mcu_spi_miso_list[j].spi_index)) {
@@ -152,9 +152,9 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
self->miso = &mcu_spi_miso_list[j];
break;
}
- }
+ }
// if just MOSI, reduce search
- } else if (mosi != mp_const_none) {
+ } else if (mosi != NULL) {
for (uint j = 0; j < mosi_len; j++) {
if ((mcu_spi_mosi_list[j].pin == mosi) //only SCK and MOSI need the same index
&& (mcu_spi_sck_list[i].spi_index == mcu_spi_mosi_list[j].spi_index)) {
@@ -169,7 +169,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
self->miso = NULL;
break;
}
- }
+ }
} else {
//throw an error immediately
mp_raise_ValueError(translate("Must provide MISO or MOSI pin"));
@@ -179,8 +179,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
//handle typedef selection, errors
if ( (self->sck != NULL && self->mosi != NULL && self->miso != NULL) ||
- (self->sck != NULL && self->mosi != NULL && miso == mp_const_none) ||
- (self->sck != NULL && self->miso != NULL && mosi == mp_const_none)) {
+ (self->sck != NULL && self->mosi != NULL && miso == NULL) ||
+ (self->sck != NULL && self->miso != NULL && mosi == NULL)) {
SPIx = mcu_spi_banks[self->sck->spi_index - 1];
} else {
if (spi_taken) {
@@ -196,7 +196,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = self->sck->altfn_index;
+ GPIO_InitStruct.Alternate = self->sck->altfn_index;
HAL_GPIO_Init(pin_port(sck->port), &GPIO_InitStruct);
if (self->mosi != NULL) {
@@ -204,7 +204,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = self->mosi->altfn_index;
+ GPIO_InitStruct.Alternate = self->mosi->altfn_index;
HAL_GPIO_Init(pin_port(mosi->port), &GPIO_InitStruct);
}
@@ -213,14 +213,14 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- GPIO_InitStruct.Alternate = self->miso->altfn_index;
+ GPIO_InitStruct.Alternate = self->miso->altfn_index;
HAL_GPIO_Init(pin_port(miso->port), &GPIO_InitStruct);
}
spi_clock_enable(1 << (self->sck->spi_index - 1));
reserved_spi[self->sck->spi_index - 1] = true;
-
- self->handle.Instance = SPIx;
+
+ self->handle.Instance = SPIx;
self->handle.Init.Mode = SPI_MODE_MASTER;
// Direction change only required for RX-only, see RefMan RM0090:884
self->handle.Init.Direction = (self->mosi == NULL) ? SPI_CR1_RXONLY : SPI_DIRECTION_2LINES;
@@ -269,7 +269,7 @@ void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) {
}
bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) {
- return self->sck->pin == mp_const_none;
+ return self->sck->pin == NULL;
}
void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
@@ -287,15 +287,15 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
if (self->miso != NULL) {
reset_pin_number(self->miso->pin->port,self->miso->pin->number);
}
- self->sck = mp_const_none;
- self->mosi = mp_const_none;
- self->miso = mp_const_none;
+ self->sck = NULL;
+ self->mosi = NULL;
+ self->miso = NULL;
}
bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
//This resets the SPI, so check before updating it redundantly
- if (baudrate == self->baudrate && polarity== self->polarity
+ if (baudrate == self->baudrate && polarity== self->polarity
&& phase == self->phase && bits == self->bits) {
return true;
}
@@ -307,7 +307,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
self->handle.Init.CLKPolarity = (polarity) ? SPI_POLARITY_HIGH : SPI_POLARITY_LOW;
self->handle.Init.CLKPhase = (phase) ? SPI_PHASE_2EDGE : SPI_PHASE_1EDGE;
- self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(baudrate, &self->prescaler,
+ self->handle.Init.BaudRatePrescaler = stm32_baud_to_spi_div(baudrate, &self->prescaler,
get_busclock(self->handle.Instance));
if (HAL_SPI_Init(&self->handle) != HAL_OK)
@@ -325,7 +325,7 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self,
bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
bool grabbed_lock = false;
- //Critical section code that may be required at some point.
+ //Critical section code that may be required at some point.
// uint32_t store_primask = __get_PRIMASK();
// __disable_irq();
// __DMB();
@@ -367,7 +367,7 @@ bool common_hal_busio_spi_read(busio_spi_obj_t *self,
return result == HAL_OK;
}
-bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
+bool common_hal_busio_spi_transfer(busio_spi_obj_t *self,
uint8_t *data_out, uint8_t *data_in, size_t len) {
if (self->miso == NULL || self->mosi == NULL) {
mp_raise_ValueError(translate("Missing MISO or MOSI Pin"));
diff --git a/ports/stm32f4/common-hal/busio/UART.c b/ports/stm32f4/common-hal/busio/UART.c
index 3c1909259..0b434fd02 100644
--- a/ports/stm32f4/common-hal/busio/UART.c
+++ b/ports/stm32f4/common-hal/busio/UART.c
@@ -86,12 +86,12 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
bool uart_taken = false;
uint8_t uart_index = 0; //origin 0 corrected
- if ((rts != mp_const_none) || (cts != mp_const_none) || (rs485_dir != mp_const_none) || (rs485_invert == true)) {
+ if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) || (rs485_invert == true)) {
mp_raise_ValueError(translate("RTS/CTS/RS485 Not yet supported on this device"));
}
-
+
//Can have both pins, or either
- if ((tx != mp_const_none) && (rx != mp_const_none)) {
+ if ((tx != NULL) && (rx != NULL)) {
//normal find loop if both pins exist
for (uint i = 0; i < tx_len; i++) {
if (mcu_uart_tx_list[i].pin == tx) {
@@ -115,7 +115,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
uart_index = self->tx->uart_index - 1;
USARTx = assign_uart_or_throw(self, (self->tx != NULL && self->rx != NULL),
uart_index, uart_taken);
- } else if (tx == mp_const_none) {
+ } else if (tx == NULL) {
//If there is no tx, run only rx
for (uint i = 0; i < rx_len; i++) {
if (mcu_uart_rx_list[i].pin == rx) {
@@ -132,7 +132,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
uart_index = self->rx->uart_index - 1;
USARTx = assign_uart_or_throw(self, (self->rx != NULL),
uart_index, uart_taken);
- } else if (rx == mp_const_none) {
+ } else if (rx == NULL) {
//If there is no rx, run only tx
for (uint i = 0; i < tx_len; i++) {
if (mcu_uart_tx_list[i].pin == tx) {
@@ -236,7 +236,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
}
bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) {
- return self->tx->pin == mp_const_none;
+ return self->tx->pin == NULL;
}
void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
@@ -244,8 +244,8 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) {
reset_pin_number(self->tx->pin->port,self->tx->pin->number);
reset_pin_number(self->rx->pin->port,self->rx->pin->number);
- self->tx = mp_const_none;
- self->rx = mp_const_none;
+ self->tx = NULL;
+ self->rx = NULL;
gc_free(self->rbuf.buf);
self->rbuf.size = 0;
self->rbuf.iput = self->rbuf.iget = 0;
diff --git a/ports/stm32f4/common-hal/digitalio/DigitalInOut.c b/ports/stm32f4/common-hal/digitalio/DigitalInOut.c
index 36c1075e2..be2db4dac 100644
--- a/ports/stm32f4/common-hal/digitalio/DigitalInOut.c
+++ b/ports/stm32f4/common-hal/digitalio/DigitalInOut.c
@@ -54,7 +54,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
}
bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) {
- return self->pin == mp_const_none;
+ return self->pin == NULL;
}
void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) {
@@ -63,7 +63,7 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self
}
reset_pin_number(self->pin->port, self->pin->number);
- self->pin = mp_const_none;
+ self->pin = NULL;
}
void common_hal_digitalio_digitalinout_switch_to_input(
@@ -90,7 +90,7 @@ void common_hal_digitalio_digitalinout_switch_to_output(
digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
digitalio_digitalinout_obj_t *self) {
- return (LL_GPIO_GetPinMode(pin_port(self->pin->port), pin_mask(self->pin->number))
+ return (LL_GPIO_GetPinMode(pin_port(self->pin->port), pin_mask(self->pin->number))
== LL_GPIO_MODE_INPUT) ? DIRECTION_INPUT : DIRECTION_OUTPUT;
}
@@ -111,7 +111,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_drive_mode_t drive_mode) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = pin_mask(self->pin->number);
- GPIO_InitStruct.Mode = (drive_mode == DRIVE_MODE_OPEN_DRAIN ?
+ GPIO_InitStruct.Mode = (drive_mode == DRIVE_MODE_OPEN_DRAIN ?
GPIO_MODE_OUTPUT_OD : GPIO_MODE_OUTPUT_PP);
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
@@ -121,7 +121,7 @@ void common_hal_digitalio_digitalinout_set_drive_mode(
digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode(
digitalio_digitalinout_obj_t *self) {
- return LL_GPIO_GetPinOutputType(pin_port(self->pin->port), pin_mask(self->pin->number))
+ return LL_GPIO_GetPinOutputType(pin_port(self->pin->port), pin_mask(self->pin->number))
== LL_GPIO_OUTPUT_OPENDRAIN ? DRIVE_MODE_OPEN_DRAIN : DRIVE_MODE_PUSH_PULL;
}
@@ -145,7 +145,7 @@ void common_hal_digitalio_digitalinout_set_pull(
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
digitalio_digitalinout_obj_t *self) {
-
+
switch (LL_GPIO_GetPinPull(pin_port(self->pin->port), pin_mask(self->pin->number))) {
case LL_GPIO_PULL_UP:
diff --git a/ports/stm32f4/common-hal/pulseio/PWMOut.c b/ports/stm32f4/common-hal/pulseio/PWMOut.c
index 4bb3afae4..d62ee2a38 100644
--- a/ports/stm32f4/common-hal/pulseio/PWMOut.c
+++ b/ports/stm32f4/common-hal/pulseio/PWMOut.c
@@ -72,7 +72,7 @@ STATIC uint32_t timer_get_internal_duty(uint16_t duty, uint32_t period) {
return (duty*period) / ((1 << 16) - 1);
}
-STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,
+STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,
uint32_t frequency, uint32_t source_freq) {
//Find the largest possible period supported by this frequency
for (int i = 0; i < (1 << 16); i++) {
@@ -139,7 +139,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
first_time_setup = false; //skip setting up the timer
}
//No problems taken, so set it up
- self->tim = l_tim;
+ self->tim = l_tim;
break;
}
}
@@ -182,7 +182,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
uint32_t prescaler = 0; //prescaler is 15 bit
uint32_t period = 0; //period is 16 bit
- timer_get_optimal_divisors(&period, &prescaler, frequency,
+ timer_get_optimal_divisors(&period, &prescaler, frequency,
timer_get_source_freq(self->tim->tim_index));
//Timer init
@@ -240,7 +240,7 @@ void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) {
}
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) {
- return self->tim == mp_const_none;
+ return self->tim == NULL;
}
void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
@@ -255,7 +255,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
HAL_TIM_PWM_Stop(&self->handle, self->channel);
}
reset_pin_number(self->tim->pin->port,self->tim->pin->number);
- self->tim = mp_const_none;
+ self->tim = NULL;
//if reserved timer has no active channels, we can disable it
if (!reserved_tim[self->tim->tim_index - 1]) {
@@ -276,13 +276,13 @@ uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) {
void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_t frequency) {
//don't halt setup for the same frequency
- if (frequency == self->frequency) {
+ if (frequency == self->frequency) {
return;
}
uint32_t prescaler = 0;
uint32_t period = 0;
- timer_get_optimal_divisors(&period, &prescaler, frequency,
+ timer_get_optimal_divisors(&period, &prescaler, frequency,
timer_get_source_freq(self->tim->tim_index));
//shut down
@@ -290,7 +290,7 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_
//Only change altered values
self->handle.Init.Period = period - 1;
- self->handle.Init.Prescaler = prescaler - 1;
+ self->handle.Init.Prescaler = prescaler - 1;
//restart everything, adjusting for new speed
if (HAL_TIM_PWM_Init(&self->handle) != HAL_OK) {
diff --git a/ports/stm32f4/mpconfigport.mk b/ports/stm32f4/mpconfigport.mk
index f214282cb..493f32c63 100644
--- a/ports/stm32f4/mpconfigport.mk
+++ b/ports/stm32f4/mpconfigport.mk
@@ -71,5 +71,7 @@ endif
CFLAGS += -DMICROPY_CPYTHON_COMPAT=1
+MICROPY_PY_ULAB = 1
+
#ifeq ($(MCU_SUB_VARIANT), stm32f412zx)
#endif
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 6ed0a7594..2be779c6c 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -400,21 +400,31 @@ mp_obj_t mp_builtin___import__(size_t n_args, const mp_obj_t *args) {
DEBUG_printf("Current path: %.*s\n", vstr_len(&path), vstr_str(&path));
if (stat == MP_IMPORT_STAT_NO_EXIST) {
- #if MICROPY_MODULE_WEAK_LINKS
- // check if there is a weak link to this module
- if (i == mod_len) {
- mp_map_elem_t *el = mp_map_lookup((mp_map_t*)&mp_builtin_module_weak_links_map, MP_OBJ_NEW_QSTR(mod_name), MP_MAP_LOOKUP);
+ // This is just the module name after the previous .
+ qstr current_module_name = qstr_from_strn(mod_str + last, i - last);
+ mp_map_elem_t *el = NULL;
+ if (outer_module_obj == MP_OBJ_NULL) {
+ el = mp_map_lookup((mp_map_t*)&mp_builtin_module_map,
+ MP_OBJ_NEW_QSTR(current_module_name),
+ MP_MAP_LOOKUP);
+ #if MICROPY_MODULE_WEAK_LINKS
+ // check if there is a weak link to this module
if (el == NULL) {
- goto no_exist;
+ el = mp_map_lookup((mp_map_t*)&mp_builtin_module_weak_links_map,
+ MP_OBJ_NEW_QSTR(current_module_name),
+ MP_MAP_LOOKUP);
}
- // found weak linked module
+ #endif
+ } else {
+ el = mp_map_lookup(&((mp_obj_module_t*) outer_module_obj)->globals->map,
+ MP_OBJ_NEW_QSTR(current_module_name),
+ MP_MAP_LOOKUP);
+ }
+
+ if (el != NULL && MP_OBJ_IS_TYPE(el->value, &mp_type_module)) {
module_obj = el->value;
mp_module_call_init(mod_name, module_obj);
} else {
- no_exist:
- #else
- {
- #endif
// couldn't find the file, so fail
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
mp_raise_ImportError(translate("module not found"));
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index 61dd901ed..acff27bcf 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -187,6 +187,9 @@ typedef long mp_off_t;
#if !defined(MICROPY_CPYTHON_COMPAT)
#define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD)
#endif
+#if !defined(MICROPY_COMP_FSTRING_LITERAL)
+#define MICROPY_COMP_FSTRING_LITERAL (MICROPY_CPYTHON_COMPAT)
+#endif
#define MICROPY_MODULE_WEAK_LINKS (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_ALL_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD)
#define MICROPY_PY_BUILTINS_COMPLEX (CIRCUITPY_FULL_BUILD)
diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk
index d6e033daf..21b1abd9b 100644
--- a/py/circuitpy_mpconfig.mk
+++ b/py/circuitpy_mpconfig.mk
@@ -339,6 +339,11 @@ CIRCUITPY_SERIAL_UART = 0
endif
CFLAGS += -DCIRCUITPY_SERIAL_UART=$(CIRCUITPY_SERIAL_UART)
+# ulab numerics library
+ifndef MICROPY_PY_ULAB
+MICROPY_PY_ULAB = $(CIRCUITPY_FULL_BUILD)
+endif
+
# Enabled micropython.native decorator (experimental)
ifndef CIRCUITPY_ENABLE_MPY_NATIVE
CIRCUITPY_ENABLE_MPY_NATIVE = 0
diff --git a/py/gc_long_lived.c b/py/gc_long_lived.c
index 01c22a7af..0e94390e9 100755
--- a/py/gc_long_lived.c
+++ b/py/gc_long_lived.c
@@ -89,7 +89,7 @@ mp_obj_dict_t *make_dict_long_lived(mp_obj_dict_t *dict, uint8_t max_depth) {
#ifndef MICROPY_ENABLE_GC
return dict;
#endif
- if (dict == NULL || max_depth == 0 || dict == &MP_STATE_VM(dict_main)) {
+ if (dict == NULL || max_depth == 0 || dict == &MP_STATE_VM(dict_main) || dict->map.is_fixed) {
return dict;
}
// Don't recurse unnecessarily. Return immediately if we've already seen this dict.
diff --git a/py/lexer.c b/py/lexer.c
index 755fa625b..00cd59bca 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -64,6 +64,12 @@ STATIC bool is_char_or3(mp_lexer_t *lex, byte c1, byte c2, byte c3) {
return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3;
}
+#if MICROPY_COMP_FSTRING_LITERAL
+STATIC bool is_char_or4(mp_lexer_t *lex, byte c1, byte c2, byte c3, byte c4) {
+ return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3 || lex->chr0 == c4;
+}
+#endif
+
STATIC bool is_char_following(mp_lexer_t *lex, byte c) {
return lex->chr1 == c;
}
@@ -107,7 +113,13 @@ STATIC bool is_following_odigit(mp_lexer_t *lex) {
STATIC bool is_string_or_bytes(mp_lexer_t *lex) {
return is_char_or(lex, '\'', '\"')
+#if MICROPY_COMP_FSTRING_LITERAL
+ || (is_char_or4(lex, 'r', 'u', 'b', 'f') && is_char_following_or(lex, '\'', '\"'))
+ || ((is_char_and(lex, 'r', 'f') || is_char_and(lex, 'f', 'r'))
+ && is_char_following_following_or(lex, '\'', '\"'))
+#else
|| (is_char_or3(lex, 'r', 'u', 'b') && is_char_following_or(lex, '\'', '\"'))
+#endif
|| ((is_char_and(lex, 'r', 'b') || is_char_and(lex, 'b', 'r'))
&& is_char_following_following_or(lex, '\'', '\"'));
}
@@ -121,6 +133,31 @@ STATIC bool is_tail_of_identifier(mp_lexer_t *lex) {
return is_head_of_identifier(lex) || is_digit(lex);
}
+#if MICROPY_COMP_FSTRING_LITERAL
+STATIC void swap_char_banks(mp_lexer_t *lex) {
+ if (lex->vstr_postfix_processing) {
+ lex->chr3 = lex->chr0;
+ lex->chr4 = lex->chr1;
+ lex->chr5 = lex->chr2;
+ lex->chr0 = lex->vstr_postfix.buf[0];
+ lex->chr1 = lex->vstr_postfix.buf[1];
+ lex->chr2 = lex->vstr_postfix.buf[2];
+
+ lex->vstr_postfix_idx = 3;
+ } else {
+ // blindly reset to the "backup" bank when done postfix processing
+ // this restores control to the mp_reader
+ lex->chr0 = lex->chr3;
+ lex->chr1 = lex->chr4;
+ lex->chr2 = lex->chr5;
+ // willfully ignoring setting chr3-5 here - WARNING consider those garbage data now
+
+ vstr_reset(&lex->vstr_postfix);
+ lex->vstr_postfix_idx = 0;
+ }
+}
+#endif
+
STATIC void next_char(mp_lexer_t *lex) {
if (lex->chr0 == '\n') {
// a new line
@@ -136,7 +173,19 @@ STATIC void next_char(mp_lexer_t *lex) {
lex->chr0 = lex->chr1;
lex->chr1 = lex->chr2;
- lex->chr2 = lex->reader.readbyte(lex->reader.data);
+
+#if MICROPY_COMP_FSTRING_LITERAL
+ if (lex->vstr_postfix_processing) {
+ if (lex->vstr_postfix_idx == lex->vstr_postfix.len) {
+ lex->chr2 = '\0';
+ } else {
+ lex->chr2 = lex->vstr_postfix.buf[lex->vstr_postfix_idx++];
+ }
+ } else
+#endif
+ {
+ lex->chr2 = lex->reader.readbyte(lex->reader.data);
+ }
if (lex->chr1 == '\r') {
// CR is a new line, converted to LF
@@ -151,6 +200,13 @@ STATIC void next_char(mp_lexer_t *lex) {
if (lex->chr2 == MP_LEXER_EOF && lex->chr1 != MP_LEXER_EOF && lex->chr1 != '\n') {
lex->chr2 = '\n';
}
+
+#if MICROPY_COMP_FSTRING_LITERAL
+ if (lex->vstr_postfix_processing && lex->chr0 == '\0') {
+ lex->vstr_postfix_processing = false;
+ swap_char_banks(lex);
+ }
+#endif
}
STATIC void indent_push(mp_lexer_t *lex, size_t indent) {
@@ -270,7 +326,7 @@ STATIC bool get_hex(mp_lexer_t *lex, size_t num_digits, mp_uint_t *result) {
return true;
}
-STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
+STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw, bool is_fstring) {
// get first quoting character
char quote_char = '\'';
if (is_char(lex, '\"')) {
@@ -291,15 +347,71 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
}
size_t n_closing = 0;
+#if MICROPY_COMP_FSTRING_LITERAL
+ bool in_expression = false;
+ bool expression_eat = true;
+#endif
+
while (!is_end(lex) && (num_quotes > 1 || !is_char(lex, '\n')) && n_closing < num_quotes) {
if (is_char(lex, quote_char)) {
n_closing += 1;
vstr_add_char(&lex->vstr, CUR_CHAR(lex));
} else {
n_closing = 0;
+#if MICROPY_COMP_FSTRING_LITERAL
+ if (is_fstring && is_char(lex, '{')) {
+ vstr_add_char(&lex->vstr, CUR_CHAR(lex));
+ in_expression = !in_expression;
+ expression_eat = in_expression;
+
+ if (lex->vstr_postfix.len == 0) {
+ vstr_add_str(&lex->vstr_postfix, ".format(");
+ }
+
+ next_char(lex);
+ continue;
+ }
+
+ if (is_fstring && is_char(lex, '}')) {
+ vstr_add_char(&lex->vstr, CUR_CHAR(lex));
+
+ if (in_expression) {
+ in_expression = false;
+ vstr_add_char(&lex->vstr_postfix, ',');
+ }
+
+ next_char(lex);
+ continue;
+ }
+
+ if (in_expression) {
+ // throw errors for illegal chars inside f-string expressions
+ if (is_char(lex, '#')) {
+ lex->tok_kind = MP_TOKEN_FSTRING_COMMENT;
+ return;
+ } else if (is_char(lex, '\\')) {
+ lex->tok_kind = MP_TOKEN_FSTRING_BACKSLASH;
+ return;
+ } else if (is_char(lex, ':')) {
+ expression_eat = false;
+ }
+
+ unichar c = CUR_CHAR(lex);
+ if (expression_eat) {
+ vstr_add_char(&lex->vstr_postfix, c);
+ } else {
+ vstr_add_char(&lex->vstr, c);
+ }
+
+ next_char(lex);
+ continue;
+ }
+#endif
+
if (is_char(lex, '\\')) {
next_char(lex);
unichar c = CUR_CHAR(lex);
+
if (is_raw) {
// raw strings allow escaping of quotes, but the backslash is also emitted
vstr_add_char(&lex->vstr, '\\');
@@ -430,6 +542,15 @@ STATIC bool skip_whitespace(mp_lexer_t *lex, bool stop_at_newline) {
}
void mp_lexer_to_next(mp_lexer_t *lex) {
+#if MICROPY_COMP_FSTRING_LITERAL
+ if (lex->vstr_postfix.len && !lex->vstr_postfix_processing) {
+ // end format call injection
+ vstr_add_char(&lex->vstr_postfix, ')');
+ lex->vstr_postfix_processing = true;
+ swap_char_banks(lex);
+ }
+#endif
+
// start new token text
vstr_reset(&lex->vstr);
@@ -481,10 +602,19 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
// MP_TOKEN_END is used to indicate that this is the first string token
lex->tok_kind = MP_TOKEN_END;
+#if MICROPY_COMP_FSTRING_LITERAL
+ bool saw_normal = false, saw_fstring = false;
+#endif
+
// Loop to accumulate string/bytes literals
do {
// parse type codes
bool is_raw = false;
+#if MICROPY_COMP_FSTRING_LITERAL
+ bool is_fstring = false;
+#else
+ const bool is_fstring = false;
+#endif
mp_token_kind_t kind = MP_TOKEN_STRING;
int n_char = 0;
if (is_char(lex, 'u')) {
@@ -503,7 +633,33 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
kind = MP_TOKEN_BYTES;
n_char = 2;
}
+#if MICROPY_COMP_FSTRING_LITERAL
+ if (is_char_following(lex, 'f')) {
+ lex->tok_kind = MP_TOKEN_FSTRING_RAW;
+ break;
+ }
+ } else if (is_char(lex, 'f')) {
+ if (is_char_following(lex, 'r')) {
+ lex->tok_kind = MP_TOKEN_FSTRING_RAW;
+ break;
+ }
+ n_char = 1;
+ is_fstring = true;
+#endif
+ }
+
+#if MICROPY_COMP_FSTRING_LITERAL
+ if (is_fstring) {
+ saw_fstring = true;
+ } else {
+ saw_normal = true;
+ }
+
+ if (saw_fstring && saw_normal) {
+ // Can't concatenate f-string with normal string
+ break;
}
+#endif
// Set or check token kind
if (lex->tok_kind == MP_TOKEN_END) {
@@ -522,13 +678,12 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
}
// Parse the literal
- parse_string_literal(lex, is_raw);
+ parse_string_literal(lex, is_raw, is_fstring);
// Skip whitespace so we can check if there's another string following
skip_whitespace(lex, true);
} while (is_string_or_bytes(lex));
-
} else if (is_head_of_identifier(lex)) {
lex->tok_kind = MP_TOKEN_NAME;
@@ -682,6 +837,9 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
lex->num_indent_level = 1;
lex->indent_level = m_new(uint16_t, lex->alloc_indent_level);
vstr_init(&lex->vstr, 32);
+#if MICROPY_COMP_FSTRING_LITERAL
+ vstr_init(&lex->vstr_postfix, 0);
+#endif
// store sentinel for first indentation level
lex->indent_level[0] = 0;
diff --git a/py/lexer.h b/py/lexer.h
index a29709107..a3eaa2a7e 100644
--- a/py/lexer.h
+++ b/py/lexer.h
@@ -44,6 +44,14 @@ typedef enum _mp_token_kind_t {
MP_TOKEN_INVALID,
MP_TOKEN_DEDENT_MISMATCH,
MP_TOKEN_LONELY_STRING_OPEN,
+#if MICROPY_COMP_FSTRING_LITERAL
+ MP_TOKEN_FSTRING_BACKSLASH,
+ MP_TOKEN_FSTRING_COMMENT,
+ MP_TOKEN_FSTRING_UNCLOSED,
+ MP_TOKEN_FSTRING_UNOPENED,
+ MP_TOKEN_FSTRING_EMPTY_EXP,
+ MP_TOKEN_FSTRING_RAW,
+#endif
MP_TOKEN_NEWLINE,
MP_TOKEN_INDENT,
@@ -150,6 +158,9 @@ typedef struct _mp_lexer_t {
mp_reader_t reader; // stream source
unichar chr0, chr1, chr2; // current cached characters from source
+#if MICROPY_COMP_FSTRING_LITERAL
+ unichar chr3, chr4, chr5; // current cached characters from alt source
+#endif
size_t line; // current source line
size_t column; // current source column
@@ -165,6 +176,11 @@ typedef struct _mp_lexer_t {
size_t tok_column; // token source column
mp_token_kind_t tok_kind; // token kind
vstr_t vstr; // token data
+#if MICROPY_COMP_FSTRING_LITERAL
+ vstr_t vstr_postfix; // postfix to apply to string
+ bool vstr_postfix_processing;
+ uint16_t vstr_postfix_idx;
+#endif
} mp_lexer_t;
mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader);
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 8f78ade5c..01572f546 100755
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -377,6 +377,11 @@
#define MICROPY_COMP_RETURN_IF_EXPR (0)
#endif
+// Whether to include parsing of f-string literals
+#ifndef MICROPY_COMP_FSTRING_LITERAL
+#define MICROPY_COMP_FSTRING_LITERAL (1)
+#endif
+
/*****************************************************************************/
/* Internal debugging stuff */
diff --git a/py/objmodule.c b/py/objmodule.c
index c7b080300..7405a6919 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -69,6 +69,13 @@ STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
// delete/store attribute
mp_obj_dict_t *dict = self->globals;
if (dict->map.is_fixed) {
+ mp_map_elem_t *elem = mp_map_lookup(&dict->map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
+ // Return success if the given value is already in the dictionary. This is the case for
+ // native packages with native submodules.
+ if (elem != NULL && elem->value == dest[1]) {
+ dest[0] = MP_OBJ_NULL; // indicate success
+ return;
+ } else
#if MICROPY_CAN_OVERRIDE_BUILTINS
if (dict == &mp_module_builtins_globals) {
if (MP_STATE_VM(mp_module_builtins_override_dict) == NULL) {
diff --git a/py/parse.c b/py/parse.c
index 864528470..b8cfda2cb 100644
--- a/py/parse.c
+++ b/py/parse.c
@@ -924,6 +924,7 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
backtrack = false;
}
for (; i < n; ++i) {
+ //printf("--> inside for @L924\n");
uint16_t kind = rule_arg[i] & RULE_ARG_KIND_MASK;
if (kind == RULE_ARG_TOK) {
if (lex->tok_kind == (rule_arg[i] & RULE_ARG_ARG_MASK)) {
@@ -1168,15 +1169,57 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
) {
syntax_error:;
mp_obj_t exc;
- if (lex->tok_kind == MP_TOKEN_INDENT) {
- exc = mp_obj_new_exception_msg(&mp_type_IndentationError,
- translate("unexpected indent"));
- } else if (lex->tok_kind == MP_TOKEN_DEDENT_MISMATCH) {
- exc = mp_obj_new_exception_msg(&mp_type_IndentationError,
- translate("unindent does not match any outer indentation level"));
- } else {
- exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
- translate("invalid syntax"));
+ switch(lex->tok_kind) {
+ case MP_TOKEN_INDENT:
+ exc = mp_obj_new_exception_msg(&mp_type_IndentationError,
+ translate("unexpected indent"));
+ break;
+ case MP_TOKEN_DEDENT_MISMATCH:
+ exc = mp_obj_new_exception_msg(&mp_type_IndentationError,
+ translate("unindent does not match any outer indentation level"));
+ break;
+#if MICROPY_COMP_FSTRING_LITERAL
+#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
+ case MP_TOKEN_FSTRING_BACKSLASH:
+ exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
+ translate("f-string expression part cannot include a backslash"));
+ break;
+ case MP_TOKEN_FSTRING_COMMENT:
+ exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
+ translate("f-string expression part cannot include a '#'"));
+ break;
+ case MP_TOKEN_FSTRING_UNCLOSED:
+ exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
+ translate("f-string: expecting '}'"));
+ break;
+ case MP_TOKEN_FSTRING_UNOPENED:
+ exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
+ translate("f-string: single '}' is not allowed"));
+ break;
+ case MP_TOKEN_FSTRING_EMPTY_EXP:
+ exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
+ translate("f-string: empty expression not allowed"));
+ break;
+ case MP_TOKEN_FSTRING_RAW:
+ exc = mp_obj_new_exception_msg(&mp_type_NotImplementedError,
+ translate("raw f-strings are not implemented"));
+ break;
+#else
+ case MP_TOKEN_FSTRING_BACKSLASH:
+ case MP_TOKEN_FSTRING_COMMENT:
+ case MP_TOKEN_FSTRING_UNCLOSED:
+ case MP_TOKEN_FSTRING_UNOPENED:
+ case MP_TOKEN_FSTRING_EMPTY_EXP:
+ case MP_TOKEN_FSTRING_RAW:
+ exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
+ translate("malformed f-string"));
+ break;
+#endif
+#endif
+ default:
+ exc = mp_obj_new_exception_msg(&mp_type_SyntaxError,
+ translate("invalid syntax"));
+ break;
}
// add traceback to give info about file name and location
// we don't have a 'block' name, so just pass the NULL qstr to indicate this
diff --git a/shared-bindings/analogio/AnalogIn.c b/shared-bindings/analogio/AnalogIn.c
index 9a9b525d8..b4eeb2af1 100644
--- a/shared-bindings/analogio/AnalogIn.c
+++ b/shared-bindings/analogio/AnalogIn.c
@@ -63,16 +63,13 @@ STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
mp_arg_check_num(n_args, kw_args, 1, 1, false);
// 1st argument is the pin
- mp_obj_t pin_obj = args[0];
- assert_pin(pin_obj, false);
+ const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]);
analogio_analogin_obj_t *self = m_new_obj(analogio_analogin_obj_t);
self->base.type = &analogio_analogin_type;
- const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
- assert_pin_free(pin);
common_hal_analogio_analogin_construct(self, pin);
- return (mp_obj_t) self;
+ return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit()
@@ -141,7 +138,7 @@ STATIC mp_obj_t analogio_analogin_obj_get_reference_voltage(mp_obj_t self_in) {
float reference_voltage = common_hal_analogio_analogin_get_reference_voltage(self);
if (reference_voltage <= 0.0f) {
- return mp_const_none;
+ return mp_const_none;
} else {
return mp_obj_new_float(reference_voltage);
}
diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c
index 0816da465..89cf147b2 100644
--- a/shared-bindings/analogio/AnalogOut.c
+++ b/shared-bindings/analogio/AnalogOut.c
@@ -62,15 +62,13 @@ STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t
// check arguments
mp_arg_check_num(n_args, kw_args, 1, 1, false);
- assert_pin(args[0], false);
- const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(args[0]);
+ const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]);
analogio_analogout_obj_t *self = m_new_obj(analogio_analogout_obj_t);
self->base.type = &analogio_analogout_type;
- assert_pin_free(pin);
common_hal_analogio_analogout_construct(self, pin);
- return self;
+ return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit()
diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c
index 8f7382fde..cd662acb5 100644
--- a/shared-bindings/audiobusio/I2SOut.c
+++ b/shared-bindings/audiobusio/I2SOut.c
@@ -105,17 +105,9 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
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_obj_t bit_clock_obj = args[ARG_bit_clock].u_obj;
- assert_pin(bit_clock_obj, false);
- const mcu_pin_obj_t *bit_clock = MP_OBJ_TO_PTR(bit_clock_obj);
-
- mp_obj_t word_select_obj = args[ARG_word_select].u_obj;
- assert_pin(word_select_obj, false);
- const mcu_pin_obj_t *word_select = MP_OBJ_TO_PTR(word_select_obj);
-
- mp_obj_t data_obj = args[ARG_data].u_obj;
- assert_pin(data_obj, false);
- const mcu_pin_obj_t *data = MP_OBJ_TO_PTR(data_obj);
+ const mcu_pin_obj_t *bit_clock = validate_obj_is_free_pin(args[ARG_bit_clock].u_obj);
+ const mcu_pin_obj_t *word_select = validate_obj_is_free_pin(args[ARG_word_select].u_obj);
+ const mcu_pin_obj_t *data = validate_obj_is_free_pin(args[ARG_data].u_obj);
audiobusio_i2sout_obj_t *self = m_new_obj_with_finaliser(audiobusio_i2sout_obj_t);
self->base.type = &audiobusio_i2sout_type;
diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c
index 0c92c2478..fce6cf7a2 100644
--- a/shared-bindings/audiobusio/PDMIn.c
+++ b/shared-bindings/audiobusio/PDMIn.c
@@ -104,15 +104,8 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
- mp_obj_t clock_pin_obj = args[ARG_clock_pin].u_obj;
- assert_pin(clock_pin_obj, false);
- const mcu_pin_obj_t *clock_pin = MP_OBJ_TO_PTR(clock_pin_obj);
- assert_pin_free(clock_pin);
-
- mp_obj_t data_pin_obj = args[ARG_data_pin].u_obj;
- assert_pin(data_pin_obj, false);
- const mcu_pin_obj_t *data_pin = MP_OBJ_TO_PTR(data_pin_obj);
- assert_pin_free(data_pin);
+ const mcu_pin_obj_t *clock_pin = validate_obj_is_free_pin(args[ARG_clock_pin].u_obj);
+ const mcu_pin_obj_t *data_pin = validate_obj_is_free_pin(args[ARG_data_pin].u_obj);
// create PDMIn object from the given pin
audiobusio_pdmin_obj_t *self = m_new_obj(audiobusio_pdmin_obj_t);
diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c
index eb4ef1fc6..ea1efcdff 100644
--- a/shared-bindings/audioio/AudioOut.c
+++ b/shared-bindings/audioio/AudioOut.c
@@ -104,16 +104,8 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
- mp_obj_t left_channel_obj = args[ARG_left_channel].u_obj;
- assert_pin(left_channel_obj, false);
- const mcu_pin_obj_t *left_channel_pin = MP_OBJ_TO_PTR(left_channel_obj);
-
- mp_obj_t right_channel_obj = args[ARG_right_channel].u_obj;
- const mcu_pin_obj_t *right_channel_pin = NULL;
- if (right_channel_obj != mp_const_none) {
- assert_pin(right_channel_obj, false);
- right_channel_pin = MP_OBJ_TO_PTR(right_channel_obj);
- }
+ const mcu_pin_obj_t *left_channel_pin = validate_obj_is_free_pin(args[ARG_left_channel].u_obj);
+ const mcu_pin_obj_t *right_channel_pin = validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj);
// create AudioOut object from the given pin
audioio_audioout_obj_t *self = m_new_obj(audioio_audioout_obj_t);
diff --git a/shared-bindings/audiopwmio/PWMAudioOut.c b/shared-bindings/audiopwmio/PWMAudioOut.c
index 60bf08500..9fa2b1578 100644
--- a/shared-bindings/audiopwmio/PWMAudioOut.c
+++ b/shared-bindings/audiopwmio/PWMAudioOut.c
@@ -107,16 +107,8 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_
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_obj_t left_channel_obj = args[ARG_left_channel].u_obj;
- assert_pin(left_channel_obj, false);
- const mcu_pin_obj_t *left_channel_pin = MP_OBJ_TO_PTR(left_channel_obj);
-
- mp_obj_t right_channel_obj = args[ARG_right_channel].u_obj;
- const mcu_pin_obj_t *right_channel_pin = NULL;
- if (right_channel_obj != mp_const_none) {
- assert_pin(right_channel_obj, false);
- right_channel_pin = MP_OBJ_TO_PTR(right_channel_obj);
- }
+ const mcu_pin_obj_t *left_channel_pin = validate_obj_is_free_pin(args[ARG_left_channel].u_obj);
+ const mcu_pin_obj_t *right_channel_pin = validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj);
// create AudioOut object from the given pin
audiopwmio_pwmaudioout_obj_t *self = m_new_obj(audiopwmio_pwmaudioout_obj_t);
diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c
index 01a128393..3c4f13777 100644
--- a/shared-bindings/bitbangio/I2C.c
+++ b/shared-bindings/bitbangio/I2C.c
@@ -63,10 +63,9 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
};
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);
- assert_pin(args[ARG_scl].u_obj, false);
- assert_pin(args[ARG_sda].u_obj, false);
- const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj);
- const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
+
+ const mcu_pin_obj_t* scl = validate_obj_is_free_pin(args[ARG_scl].u_obj);
+ const mcu_pin_obj_t* sda = validate_obj_is_free_pin(args[ARG_sda].u_obj);
bitbangio_i2c_obj_t *self = m_new_obj(bitbangio_i2c_obj_t);
self->base.type = &bitbangio_i2c_type;
diff --git a/shared-bindings/bitbangio/OneWire.c b/shared-bindings/bitbangio/OneWire.c
index 73bedcd8d..95bbd0679 100644
--- a/shared-bindings/bitbangio/OneWire.c
+++ b/shared-bindings/bitbangio/OneWire.c
@@ -69,9 +69,8 @@ STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_a
};
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);
- assert_pin(args[ARG_pin].u_obj, false);
- const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj);
- assert_pin_free(pin);
+
+ const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
bitbangio_onewire_obj_t *self = m_new_obj(bitbangio_onewire_obj_t);
self->base.type = &bitbangio_onewire_type;
diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c
index 9a51bde66..b1a94c184 100644
--- a/shared-bindings/bitbangio/SPI.c
+++ b/shared-bindings/bitbangio/SPI.c
@@ -71,12 +71,10 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args,
};
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);
- assert_pin(args[ARG_clock].u_obj, false);
- assert_pin(args[ARG_MOSI].u_obj, true);
- assert_pin(args[ARG_MISO].u_obj, true);
- const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(args[ARG_clock].u_obj);
- const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(args[ARG_MOSI].u_obj);
- const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(args[ARG_MISO].u_obj);
+
+ const mcu_pin_obj_t* clock = validate_obj_is_free_pin(args[ARG_clock].u_obj);
+ const mcu_pin_obj_t* mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj);
+ const mcu_pin_obj_t* miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj);
bitbangio_spi_obj_t *self = m_new_obj(bitbangio_spi_obj_t);
self->base.type = &bitbangio_spi_type;
diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c
index 50a95beb2..c89215acd 100644
--- a/shared-bindings/busio/I2C.c
+++ b/shared-bindings/busio/I2C.c
@@ -76,12 +76,10 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, con
};
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);
- assert_pin(args[ARG_scl].u_obj, false);
- assert_pin(args[ARG_sda].u_obj, false);
- const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj);
- assert_pin_free(scl);
- const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
- assert_pin_free(sda);
+
+ const mcu_pin_obj_t* scl = validate_obj_is_free_pin(args[ARG_scl].u_obj);
+ const mcu_pin_obj_t* sda = validate_obj_is_free_pin(args[ARG_sda].u_obj);
+
common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int);
return (mp_obj_t)self;
}
diff --git a/shared-bindings/busio/OneWire.c b/shared-bindings/busio/OneWire.c
index aca2a3ef2..022d6afcf 100644
--- a/shared-bindings/busio/OneWire.c
+++ b/shared-bindings/busio/OneWire.c
@@ -69,9 +69,7 @@ STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args,
};
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);
- assert_pin(args[ARG_pin].u_obj, false);
- const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj);
- assert_pin_free(pin);
+ const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
busio_onewire_obj_t *self = m_new_obj(busio_onewire_obj_t);
self->base.type = &busio_onewire_type;
diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c
index 828ffb8d0..043c1089d 100644
--- a/shared-bindings/busio/SPI.c
+++ b/shared-bindings/busio/SPI.c
@@ -89,17 +89,13 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con
};
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);
- assert_pin(args[ARG_clock].u_obj, false);
- assert_pin(args[ARG_MOSI].u_obj, true);
- assert_pin(args[ARG_MISO].u_obj, true);
- const mcu_pin_obj_t* clock = MP_OBJ_TO_PTR(args[ARG_clock].u_obj);
- assert_pin_free(clock);
- const mcu_pin_obj_t* mosi = MP_OBJ_TO_PTR(args[ARG_MOSI].u_obj);
- assert_pin_free(mosi);
- const mcu_pin_obj_t* miso = MP_OBJ_TO_PTR(args[ARG_MISO].u_obj);
- assert_pin_free(miso);
+
+ const mcu_pin_obj_t* clock = validate_obj_is_free_pin(args[ARG_clock].u_obj);
+ const mcu_pin_obj_t* mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj);
+ const mcu_pin_obj_t* miso = validate_obj_is_free_pin_or_none(args[ARG_MISO].u_obj);
+
common_hal_busio_spi_construct(self, clock, mosi, miso);
- return (mp_obj_t)self;
+ return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit()
diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c
index 02c5afb16..f231924d5 100644
--- a/shared-bindings/busio/UART.c
+++ b/shared-bindings/busio/UART.c
@@ -105,13 +105,12 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
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);
- assert_pin(args[ARG_rx].u_obj, true);
- const mcu_pin_obj_t* rx = MP_OBJ_TO_PTR(args[ARG_rx].u_obj);
- assert_pin_free(rx);
+ const mcu_pin_obj_t* rx = validate_obj_is_free_pin_or_none(args[ARG_rx].u_obj);
+ const mcu_pin_obj_t* tx = validate_obj_is_free_pin_or_none(args[ARG_tx].u_obj);
- assert_pin(args[ARG_tx].u_obj, true);
- const mcu_pin_obj_t* tx = MP_OBJ_TO_PTR(args[ARG_tx].u_obj);
- assert_pin_free(tx);
+ if ( (tx == NULL) && (rx == NULL) ) {
+ mp_raise_ValueError(translate("tx and rx cannot both be None"));
+ }
uint8_t bits = args[ARG_bits].u_int;
if (bits < 7 || bits > 9) {
@@ -133,12 +132,11 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj);
validate_timeout(timeout);
- const mcu_pin_obj_t* rts = MP_OBJ_TO_PTR(args[ARG_rts].u_obj);
-
- const mcu_pin_obj_t* cts = MP_OBJ_TO_PTR(args[ARG_cts].u_obj);
+ const mcu_pin_obj_t* rts = validate_obj_is_free_pin_or_none(args[ARG_rts].u_obj);
+ const mcu_pin_obj_t* cts = validate_obj_is_free_pin_or_none(args[ARG_cts].u_obj);
+ const mcu_pin_obj_t* rs485_dir = validate_obj_is_free_pin_or_none(args[ARG_rs485_dir].u_obj);
- const mcu_pin_obj_t* rs485_dir = args[ARG_rs485_dir].u_obj;
- bool rs485_invert = args[ARG_rs485_invert].u_bool;
+ const bool rs485_invert = args[ARG_rs485_invert].u_bool;
common_hal_busio_uart_construct(self, tx, rx, rts, cts, rs485_dir, rs485_invert,
args[ARG_baudrate].u_int, bits, parity, stop, timeout,
diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c
index 16472c12c..39da00cf7 100644
--- a/shared-bindings/digitalio/DigitalInOut.c
+++ b/shared-bindings/digitalio/DigitalInOut.c
@@ -68,12 +68,10 @@ STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type,
digitalio_digitalinout_obj_t *self = m_new_obj(digitalio_digitalinout_obj_t);
self->base.type = &digitalio_digitalinout_type;
- assert_pin(args[0], false);
- mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(args[0]);
- assert_pin_free(pin);
+ mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]);
common_hal_digitalio_digitalinout_construct(self, pin);
- return (mp_obj_t)self;
+ return MP_OBJ_FROM_PTR(self);
}
//| .. method:: deinit()
diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c
index 5759e8ad2..991c828be 100644
--- a/shared-bindings/displayio/Display.c
+++ b/shared-bindings/displayio/Display.c
@@ -141,13 +141,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_init_sequence].u_obj, &bufinfo, MP_BUFFER_READ);
- mp_obj_t backlight_pin_obj = args[ARG_backlight_pin].u_obj;
- assert_pin(backlight_pin_obj, true);
- const mcu_pin_obj_t* backlight_pin = NULL;
- if (backlight_pin_obj != NULL && backlight_pin_obj != mp_const_none) {
- backlight_pin = MP_OBJ_TO_PTR(backlight_pin_obj);
- assert_pin_free(backlight_pin);
- }
+ const mcu_pin_obj_t* backlight_pin = validate_obj_is_free_pin_or_none(args[ARG_backlight_pin].u_obj);
mp_float_t brightness = mp_obj_get_float(args[ARG_brightness].u_obj);
diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c
index 81e06f82f..25a4a41e9 100644
--- a/shared-bindings/displayio/EPaperDisplay.c
+++ b/shared-bindings/displayio/EPaperDisplay.c
@@ -129,13 +129,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size
mp_get_buffer_raise(args[ARG_stop_sequence].u_obj, &stop_bufinfo, MP_BUFFER_READ);
- mp_obj_t busy_pin_obj = args[ARG_busy_pin].u_obj;
- assert_pin(busy_pin_obj, true);
- const mcu_pin_obj_t* busy_pin = NULL;
- if (busy_pin_obj != NULL && busy_pin_obj != mp_const_none) {
- busy_pin = MP_OBJ_TO_PTR(busy_pin_obj);
- assert_pin_free(busy_pin);
- }
+ const mcu_pin_obj_t* busy_pin = validate_obj_is_free_pin_or_none(args[ARG_busy_pin].u_obj);
mp_int_t rotation = args[ARG_rotation].u_int;
if (rotation % 90 != 0) {
diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c
index 51203d460..2cbceec48 100644
--- a/shared-bindings/displayio/FourWire.c
+++ b/shared-bindings/displayio/FourWire.c
@@ -73,16 +73,9 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
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_obj_t command = args[ARG_command].u_obj;
- mp_obj_t chip_select = args[ARG_chip_select].u_obj;
- assert_pin_free(command);
- assert_pin_free(chip_select);
- mp_obj_t reset = args[ARG_reset].u_obj;
- if (reset != mp_const_none) {
- assert_pin_free(reset);
- } else {
- reset = NULL;
- }
+ mcu_pin_obj_t *command = validate_obj_is_free_pin(args[ARG_command].u_obj);
+ mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj);
+ mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj);
displayio_fourwire_obj_t* self = NULL;
mp_obj_t spi = args[ARG_spi_bus].u_obj;
diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c
index 9b863f656..2e312aa14 100644
--- a/shared-bindings/displayio/I2CDisplay.c
+++ b/shared-bindings/displayio/I2CDisplay.c
@@ -69,12 +69,7 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t
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_obj_t reset = args[ARG_reset].u_obj;
- if (reset != mp_const_none) {
- assert_pin_free(reset);
- } else {
- reset = NULL;
- }
+ mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj);
displayio_i2cdisplay_obj_t* self = NULL;
mp_obj_t i2c = args[ARG_i2c_bus].u_obj;
diff --git a/shared-bindings/displayio/ParallelBus.c b/shared-bindings/displayio/ParallelBus.c
index f7195b9cc..b3a876f90 100644
--- a/shared-bindings/displayio/ParallelBus.c
+++ b/shared-bindings/displayio/ParallelBus.c
@@ -71,23 +71,17 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_write, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
{ MP_QSTR_read, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
- { MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
+ { MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
};
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_obj_t data0 = args[ARG_data0].u_obj;
- mp_obj_t command = args[ARG_command].u_obj;
- mp_obj_t chip_select = args[ARG_chip_select].u_obj;
- mp_obj_t write = args[ARG_write].u_obj;
- mp_obj_t read = args[ARG_read].u_obj;
- mp_obj_t reset = args[ARG_reset].u_obj;
- assert_pin_free(data0);
- assert_pin_free(command);
- assert_pin_free(chip_select);
- assert_pin_free(write);
- assert_pin_free(read);
- assert_pin_free(reset);
+ mcu_pin_obj_t *data0 = validate_obj_is_free_pin(args[ARG_data0].u_obj);
+ mcu_pin_obj_t *command = validate_obj_is_free_pin(args[ARG_command].u_obj);
+ mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj);
+ mcu_pin_obj_t *write = validate_obj_is_free_pin(args[ARG_write].u_obj);
+ mcu_pin_obj_t *read = validate_obj_is_free_pin(args[ARG_read].u_obj);
+ mcu_pin_obj_t *reset = validate_obj_is_free_pin(args[ARG_reset].u_obj);
displayio_parallelbus_obj_t* self = NULL;
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c
index e2b924c07..6743f8706 100644
--- a/shared-bindings/frequencyio/FrequencyIn.c
+++ b/shared-bindings/frequencyio/FrequencyIn.c
@@ -87,9 +87,7 @@ STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size
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);
- assert_pin(args[ARG_pin].u_obj, false);
- mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj);
- assert_pin_free(pin);
+ mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
const uint16_t capture_period = args[ARG_capture_period].u_int;
diff --git a/shared-bindings/i2cslave/I2CSlave.c b/shared-bindings/i2cslave/I2CSlave.c
index c98ea52e0..e28eb3f25 100644
--- a/shared-bindings/i2cslave/I2CSlave.c
+++ b/shared-bindings/i2cslave/I2CSlave.c
@@ -77,12 +77,8 @@ STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_
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);
- assert_pin(args[ARG_scl].u_obj, false);
- assert_pin(args[ARG_sda].u_obj, false);
- const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj);
- assert_pin_free(scl);
- const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
- assert_pin_free(sda);
+ const mcu_pin_obj_t* scl = validate_obj_is_free_pin(args[ARG_scl].u_obj);
+ const mcu_pin_obj_t* sda = validate_obj_is_free_pin(args[ARG_sda].u_obj);
mp_obj_iter_buf_t iter_buf;
mp_obj_t iterable = mp_getiter(args[ARG_addresses].u_obj, &iter_buf);
diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c
index 3635f0afb..67aecaf66 100644
--- a/shared-bindings/microcontroller/Pin.c
+++ b/shared-bindings/microcontroller/Pin.c
@@ -84,10 +84,35 @@ const mp_obj_type_t mcu_pin_type = {
.print = mcu_pin_print
};
-void assert_pin(mp_obj_t obj, bool none_ok) {
- if ((obj != mp_const_none || !none_ok) && !MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) {
+mcu_pin_obj_t *validate_obj_is_pin(mp_obj_t obj) {
+ if (!MP_OBJ_IS_TYPE(obj, &mcu_pin_type)) {
mp_raise_TypeError_varg(translate("Expected a %q"), mcu_pin_type.name);
}
+ return MP_OBJ_TO_PTR(obj);
+}
+
+// Validate that the obj is a pin or None. Return an mcu_pin_obj_t* or NULL, correspondingly.
+mcu_pin_obj_t *validate_obj_is_pin_or_none(mp_obj_t obj) {
+ if (obj == mp_const_none) {
+ return NULL;
+ }
+ return validate_obj_is_pin(obj);
+}
+
+mcu_pin_obj_t *validate_obj_is_free_pin(mp_obj_t obj) {
+ mcu_pin_obj_t *pin = validate_obj_is_pin(obj);
+ assert_pin_free(pin);
+ return pin;
+}
+
+// Validate that the obj is a free pin or None. Return an mcu_pin_obj_t* or NULL, correspondingly.
+mcu_pin_obj_t *validate_obj_is_free_pin_or_none(mp_obj_t obj) {
+ if (obj == mp_const_none) {
+ return NULL;
+ }
+ mcu_pin_obj_t *pin = validate_obj_is_pin(obj);
+ assert_pin_free(pin);
+ return pin;
}
void assert_pin_free(const mcu_pin_obj_t* pin) {
diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h
index 2d15dd5c5..4f29322a0 100644
--- a/shared-bindings/microcontroller/Pin.h
+++ b/shared-bindings/microcontroller/Pin.h
@@ -33,7 +33,11 @@
// Type object used in Python. Should be shared between ports.
extern const mp_obj_type_t mcu_pin_type;
-void assert_pin(mp_obj_t obj, bool none_ok);
+mcu_pin_obj_t *validate_obj_is_pin(mp_obj_t obj);
+mcu_pin_obj_t *validate_obj_is_pin_or_none(mp_obj_t obj);
+mcu_pin_obj_t *validate_obj_is_free_pin(mp_obj_t obj);
+mcu_pin_obj_t *validate_obj_is_free_pin_or_none(mp_obj_t obj);
+
void assert_pin_free(const mcu_pin_obj_t* pin);
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin);
diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c
index fb5c24b85..89ed0a76c 100644
--- a/shared-bindings/ps2io/Ps2.c
+++ b/shared-bindings/ps2io/Ps2.c
@@ -77,12 +77,9 @@ STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, con
};
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);
- assert_pin(args[ARG_clkpin].u_obj, false);
- assert_pin(args[ARG_datapin].u_obj, false);
- const mcu_pin_obj_t* clkpin = MP_OBJ_TO_PTR(args[ARG_clkpin].u_obj);
- assert_pin_free(clkpin);
- const mcu_pin_obj_t* datapin = MP_OBJ_TO_PTR(args[ARG_datapin].u_obj);
- assert_pin_free(datapin);
+
+ const mcu_pin_obj_t* clkpin = validate_obj_is_free_pin(args[ARG_clkpin].u_obj);
+ const mcu_pin_obj_t* datapin = validate_obj_is_free_pin(args[ARG_datapin].u_obj);
ps2io_ps2_obj_t *self = m_new_obj(ps2io_ps2_obj_t);
self->base.type = &ps2io_ps2_type;
diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pulseio/PWMOut.c
index 53b88c61a..2491a5c3f 100644
--- a/shared-bindings/pulseio/PWMOut.c
+++ b/shared-bindings/pulseio/PWMOut.c
@@ -96,10 +96,7 @@ STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args
mp_arg_val_t parsed_args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, parsed_args);
- mp_obj_t pin_obj = parsed_args[ARG_pin].u_obj;
- assert_pin(pin_obj, false);
- const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
- assert_pin_free(pin);
+ const mcu_pin_obj_t *pin = validate_obj_is_free_pin(parsed_args[ARG_pin].u_obj);
uint16_t duty_cycle = parsed_args[ARG_duty_cycle].u_int;
uint32_t frequency = parsed_args[ARG_frequency].u_int;
diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c
index 8b69109f0..6c01a4c17 100644
--- a/shared-bindings/pulseio/PulseIn.c
+++ b/shared-bindings/pulseio/PulseIn.c
@@ -90,9 +90,7 @@ STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_arg
};
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);
- assert_pin(args[ARG_pin].u_obj, false);
- const mcu_pin_obj_t* pin = MP_OBJ_TO_PTR(args[ARG_pin].u_obj);
- assert_pin_free(pin);
+ const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
pulseio_pulsein_obj_t *self = m_new_obj(pulseio_pulsein_obj_t);
self->base.type = &pulseio_pulsein_type;
diff --git a/shared-bindings/rotaryio/IncrementalEncoder.c b/shared-bindings/rotaryio/IncrementalEncoder.c
index f2f157847..058241d24 100644
--- a/shared-bindings/rotaryio/IncrementalEncoder.c
+++ b/shared-bindings/rotaryio/IncrementalEncoder.c
@@ -73,13 +73,8 @@ STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type,
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);
- assert_pin(args[ARG_pin_a].u_obj, false);
- const mcu_pin_obj_t* pin_a = MP_OBJ_TO_PTR(args[ARG_pin_a].u_obj);
- assert_pin_free(pin_a);
-
- assert_pin(args[ARG_pin_b].u_obj, false);
- const mcu_pin_obj_t* pin_b = MP_OBJ_TO_PTR(args[ARG_pin_b].u_obj);
- assert_pin_free(pin_b);
+ const mcu_pin_obj_t* pin_a = validate_obj_is_free_pin(args[ARG_pin_a].u_obj);
+ const mcu_pin_obj_t* pin_b = validate_obj_is_free_pin(args[ARG_pin_b].u_obj);
rotaryio_incrementalencoder_obj_t *self = m_new_obj(rotaryio_incrementalencoder_obj_t);
self->base.type = &rotaryio_incrementalencoder_type;
diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c
index 33d369c74..db53ec1bc 100644
--- a/shared-bindings/touchio/TouchIn.c
+++ b/shared-bindings/touchio/TouchIn.c
@@ -66,10 +66,7 @@ STATIC mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type,
mp_arg_check_num(n_args, kw_args, 1, 1, false);
// 1st argument is the pin
- mp_obj_t pin_obj = args[0];
- assert_pin(pin_obj, false);
- const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
- assert_pin_free(pin);
+ const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]);
touchio_touchin_obj_t *self = m_new_obj(touchio_touchin_obj_t);
self->base.type = &touchio_touchin_type;
diff --git a/shared-bindings/wiznet/wiznet5k.c b/shared-bindings/wiznet/wiznet5k.c
index ac89cc691..786978bfe 100644
--- a/shared-bindings/wiznet/wiznet5k.c
+++ b/shared-bindings/wiznet/wiznet5k.c
@@ -78,10 +78,10 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, cons
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);
// TODO check type of ARG_spi?
- assert_pin(args[ARG_cs].u_obj, false);
- assert_pin(args[ARG_rst].u_obj, true); // may be NULL
+ const mcu_pin_obj_t *cs = validate_obj_is_free_pin(args[ARG_cs].u_obj);
+ const mcu_pin_obj_t *rst = validate_obj_is_free_pin_or_none(args[ARG_rst].u_obj);
- mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, args[ARG_cs].u_obj, args[ARG_rst].u_obj);
+ mp_obj_t ret = wiznet5k_create(args[ARG_spi].u_obj, cs, rst);
if (args[ARG_dhcp].u_bool) wiznet5k_start_dhcp();
return ret;
}
diff --git a/shared-module/bitbangio/SPI.c b/shared-module/bitbangio/SPI.c
index d02adf34f..e0ff1184f 100644
--- a/shared-module/bitbangio/SPI.c
+++ b/shared-module/bitbangio/SPI.c
@@ -45,7 +45,7 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
}
common_hal_digitalio_digitalinout_switch_to_output(&self->clock, self->polarity == 1, DRIVE_MODE_PUSH_PULL);
- if (mosi != mp_const_none) {
+ if (mosi != NULL) {
result = common_hal_digitalio_digitalinout_construct(&self->mosi, mosi);
if (result != DIGITALINOUT_OK) {
common_hal_digitalio_digitalinout_deinit(&self->clock);
@@ -55,12 +55,12 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
common_hal_digitalio_digitalinout_switch_to_output(&self->mosi, false, DRIVE_MODE_PUSH_PULL);
}
- if (miso != mp_const_none) {
+ if (miso != NULL) {
// Starts out as input by default, no need to change.
result = common_hal_digitalio_digitalinout_construct(&self->miso, miso);
if (result != DIGITALINOUT_OK) {
common_hal_digitalio_digitalinout_deinit(&self->clock);
- if (mosi != mp_const_none) {
+ if (mosi != NULL) {
common_hal_digitalio_digitalinout_deinit(&self->mosi);
}
mp_raise_ValueError(translate("MISO pin init failed."));
diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c
index bbf177384..789318a05 100644
--- a/shared-module/board/__init__.c
+++ b/shared-module/board/__init__.c
@@ -103,12 +103,12 @@ mp_obj_t common_hal_board_create_uart(void) {
#ifdef DEFAULT_UART_BUS_RTS
const mcu_pin_obj_t* rts = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RTS);
#else
- const mcu_pin_obj_t* rts = mp_const_none;
+ const mcu_pin_obj_t* rts = NULL;
#endif
#ifdef DEFAULT_UART_BUS_CTS
const mcu_pin_obj_t* cts = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_CTS);
#else
- const mcu_pin_obj_t* cts = mp_const_none;
+ const mcu_pin_obj_t* cts = NULL;
#endif
#ifdef DEFAULT_UART_IS_RS485
const mcu_pin_obj_t* rs485_dir = MP_OBJ_TO_PTR(DEFAULT_UART_BUS_RS485DIR);
@@ -118,7 +118,7 @@ mp_obj_t common_hal_board_create_uart(void) {
const bool rs485_invert = false;
#endif
#else
- const mcu_pin_obj_t* rs485_dir = mp_const_none;
+ const mcu_pin_obj_t* rs485_dir = NULL;
const bool rs485_invert = false;
#endif
diff --git a/shared-module/wiznet/wiznet5k.c b/shared-module/wiznet/wiznet5k.c
index 3c5c5f0c8..a603a5593 100644
--- a/shared-module/wiznet/wiznet5k.c
+++ b/shared-module/wiznet/wiznet5k.c
@@ -379,12 +379,12 @@ void wiznet5k_socket_deinit(mod_network_socket_obj_t *socket) {
}
/// Create and return a WIZNET5K object.
-mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in) {
+mp_obj_t wiznet5k_create(busio_spi_obj_t *spi_in, const mcu_pin_obj_t *cs_in, const mcu_pin_obj_t *rst_in) {
// init the wiznet5k object
wiznet5k_obj.base.type = (mp_obj_type_t*)&mod_network_nic_type_wiznet5k;
wiznet5k_obj.cris_state = 0;
- wiznet5k_obj.spi = MP_OBJ_TO_PTR(spi_in);
+ wiznet5k_obj.spi = spi_in;
wiznet5k_obj.socket_used = 0;
wiznet5k_obj.dhcp_socket = -1;
diff --git a/shared-module/wiznet/wiznet5k.h b/shared-module/wiznet/wiznet5k.h
index 0154831c7..19823ae55 100644
--- a/shared-module/wiznet/wiznet5k.h
+++ b/shared-module/wiznet/wiznet5k.h
@@ -59,7 +59,7 @@ int wiznet5k_socket_ioctl(mod_network_socket_obj_t *socket, mp_uint_t request, m
void wiznet5k_socket_timer_tick(mod_network_socket_obj_t *socket);
void wiznet5k_socket_deinit(mod_network_socket_obj_t *socket);
mp_obj_t wiznet5k_socket_disconnect(mp_obj_t self_in);
-mp_obj_t wiznet5k_create(mp_obj_t spi_in, mp_obj_t cs_in, mp_obj_t rst_in);
+mp_obj_t wiznet5k_create(busio_spi_obj_t *spi_in, const mcu_pin_obj_t *cs_in, const mcu_pin_obj_t *rst_in);
int wiznet5k_start_dhcp(void);
int wiznet5k_stop_dhcp(void);
diff --git a/tests/basics/string_pep498_fstring.py b/tests/basics/string_pep498_fstring.py
new file mode 100644
index 000000000..c645a730c
--- /dev/null
+++ b/tests/basics/string_pep498_fstring.py
@@ -0,0 +1,113 @@
+# Tests against https://www.python.org/dev/peps/pep-0498/
+
+assert f'no interpolation' == 'no interpolation'
+assert f"no interpolation" == 'no interpolation'
+
+# Quoth the PEP:
+# Backslashes may not appear anywhere within expressions. Comments, using the
+# '#' character, are not allowed inside an expression
+#
+# CPython (3.7.4 on Linux) raises a SyntaxError here:
+# >>> f'{#}'
+# File "<stdin>", line 1
+# SyntaxError: f-string expression part cannot include '#'
+# >>> f'{\}'
+# File "<stdin>", line 1
+# SyntaxError: f-string expression part cannot include a backslash
+# >>> f'{\\}'
+# File "<stdin>", line 1
+# SyntaxError: f-string expression part cannot include a backslash
+# >>> f'{\#}'
+# File "<stdin>", line 1
+# SyntaxError: f-string expression part cannot include a backslash
+
+# Backslashes and comments allowed outside expression
+assert f"\\" == "\\"
+assert f'#' == '#'
+
+## But not inside
+try:
+ eval("f'{\}'")
+except SyntaxError:
+ pass
+else:
+ raise AssertionError('f-string with backslash in expression did not raise SyntaxError')
+
+try:
+ eval("f'{#}'")
+except SyntaxError:
+ pass
+else:
+ raise AssertionError('f-string with \'#\' in expression did not raise SyntaxError')
+
+# Quoth the PEP:
+# While scanning the string for expressions, any doubled braces '{{' or '}}'
+# inside literal portions of an f-string are replaced by the corresponding
+# single brace. Doubled literal opening braces do not signify the start of an
+# expression. A single closing curly brace '}' in the literal portion of a
+# string is an error: literal closing curly braces must be doubled '}}' in
+# order to represent a single closing brace.
+#
+# CPython (3.7.4 on Linux) raises a SyntaxError for the last case:
+# >>> f'{{}'
+# File "<stdin>", line 1
+# SyntaxError: f-string: single '}' is not allowed
+
+assert f'{{}}' == '{}'
+
+try:
+ eval("f'{{}'")
+except ValueError:
+ pass
+else:
+ raise RuntimeError('Expected ValueError for invalid f-string literal bracing')
+
+x = 1
+assert f'{x}' == '1'
+
+# Quoth the PEP:
+# The expressions that are extracted from the string are evaluated in the
+# context where the f-string appeared. This means the expression has full
+# access to local and global variables. Any valid Python expression can be
+# used, including function and method calls. Because the f-strings are
+# evaluated where the string appears in the source code, there is no additional
+# expressiveness available with f-strings. There are also no additional
+# security concerns: you could have also just written the same expression, not
+# inside of an f-string:
+
+def foo():
+ return 20
+
+assert f'result={foo()}' == 'result=20'
+assert f'result={foo()}' == 'result={}'.format(foo())
+assert f'result={foo()}' == 'result={result}'.format(result=foo())
+
+
+# Quoth the PEP:
+# Adjacent f-strings and regular strings are concatenated. Regular strings are
+# concatenated at compile time, and f-strings are concatenated at run time. For
+# example, the expression:
+#
+# >>> x = 10
+# >>> y = 'hi'
+# >>> 'a' 'b' f'{x}' '{c}' f'str<{y:^4}>' 'd' 'e'
+#
+# yields the value: 'ab10{c}str< hi >de'
+#
+# Because strings are concatenated at lexer time rather than parser time in
+# MicroPython for mostly RAM efficiency reasons (see
+# https://github.com/micropython/micropython/commit/534b7c368dc2af7720f3aaed0c936ef46d773957),
+# and because f-strings here are implemented as a syntax translation
+# (f'{something}' => '{}'.format(something)), this particular functionality is unimplemented,
+# and in the above example, the '{c}' portion will trigger a KeyError on String.format()
+
+x = 10
+y = 'hi'
+assert (f'h' f'i') == 'hi'
+#assert (f'h' 'i') == 'hi'
+#assert ('h' f'i') == 'hi'
+assert f'{x:^4}' == ' 10 '
+#assert ('a' 'b' f'{x}' f'str<{y:^4}>' 'd' 'e') == 'ab10str< hi >de'
+
+# Other tests
+assert f'{{{4*10}}}' == '{40}'
diff --git a/tests/basics/string_pep498_fstring.py.exp b/tests/basics/string_pep498_fstring.py.exp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/basics/string_pep498_fstring.py.exp
diff --git a/tests/cmdline/cmd_parsetree.py.exp b/tests/cmdline/cmd_parsetree.py.exp
index 12a1bfbe9..c06ce4e31 100644
--- a/tests/cmdline/cmd_parsetree.py.exp
+++ b/tests/cmdline/cmd_parsetree.py.exp
@@ -1,6 +1,6 @@
----------------
[ 4] rule(1) (n=9)
- tok(4)
+ tok(10)
[ 4] rule(22) (n=4)
id(i)
[ 4] rule(44) (n=1)
@@ -9,7 +9,7 @@
NULL
[ 6] rule(5) (n=2)
id(a)
- tok(14)
+ tok(20)
[ 7] rule(5) (n=2)
id(b)
str(str)