Merge branch 'main' into wio_add_pin_assign

This commit is contained in:
Dan Halbert 2021-05-03 09:33:18 -04:00 committed by GitHub
commit 9ca0e689a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
153 changed files with 4519 additions and 2451 deletions

View File

@ -209,6 +209,7 @@ jobs:
- "clue_nrf52840_express"
- "cp32-m4"
- "cp_sapling_m0"
- "cp_sapling_m0_revb"
- "cp_sapling_m0_spiflash"
- "datalore_ip_m4"
- "datum_distance"

View File

@ -238,11 +238,34 @@ Module description
After the license comment::
"""
`<module name>` - <Short description>
`<module name>`
=================================================
<Longer description.>
<Longer description>
* Author(s):
Implementation Notes
--------------------
**Hardware:**
* Adafruit `Device Description
<hyperlink>`_ (Product ID: <Product Number>)
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads
* Adafruit's Bus Device library:
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
* Adafruit's Register library:
https://github.com/adafruit/Adafruit_CircuitPython_Register
"""
Class description
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -269,6 +292,58 @@ Renders as:
:param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to.
:param int address: The I2C address of the device. Defaults to :const:`0x40`
Documenting Parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Although there are different ways to document class and functions definitions in Python,
the following is the prevalent method of documenting parameters
for CircuitPython libraries. When documenting class parameters you should use the
following structure:
.. code-block:: sh
:param param_type param_name: Parameter_description
param_type
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The type of the parameter. This could be among other `int`, `float`, `str` `bool`, etc.
To document an object in the CircuitPython domain, you need to include a ``~`` before the
definition as shown in the following example:
.. code-block:: sh
:param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to.
To include references to CircuitPython modules, cookiecutter creates an entry in the
intersphinx_mapping section in the ``conf.py`` file located within the ``docs`` directory.
To add different types outside CircuitPython you need to include them in the intersphinx_mapping::
intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),
"BusDevice":("https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", None,),
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
}
The intersphinx_mapping above includes references to Python, BusDevice and CircuitPython
Documentation
param_name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter name used in the class or method definition
Parameter_description
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Parameter description. When the parameter defaults to a particular value, it is good
practice to include the default::
:param int pitch: Pitch value for the servo. Defaults to :const:`4500`
Attributes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -383,6 +458,14 @@ Renders as:
:param float degrees: Degrees to turn right
Documentation References to other Libraries
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When you need to make references to documentation in other libraries you should refer the class using single
backticks ``:class:`~adafruit_motor.servo.Servo```. You must also add the reference in the ``conf.py`` file in the
``intersphinx_mapping section`` by adding a new entry::
"adafruit_motor": ("https://circuitpython.readthedocs.io/projects/motor/en/latest/", None,),
Use BusDevice
--------------------------------------------------------------------------------

View File

@ -6,7 +6,7 @@ msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
"PO-Revision-Date: 2021-04-07 12:23+0000\n"
"PO-Revision-Date: 2021-04-28 16:11+0000\n"
"Last-Translator: Reza Almanda <rezaalmanda27@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: ID\n"
@ -14,7 +14,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 4.6-dev\n"
"X-Generator: Weblate 4.7-dev\n"
#: main.c
msgid ""
@ -698,6 +698,7 @@ msgstr ""
"digunakan"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1307,7 +1308,8 @@ msgstr "Fase tidak valid"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Pin tidak valid"
@ -1662,11 +1664,11 @@ msgstr "Hanya 8 atau 16 bit mono dengan "
#: ports/esp32s2/common-hal/wifi/__init__.c
msgid "Only IPv4 addresses supported"
msgstr ""
msgstr "Hanya alamat IPv4 yang didukung"
#: ports/esp32s2/common-hal/socketpool/SocketPool.c
msgid "Only IPv4 sockets supported"
msgstr ""
msgstr "Hanysa socket IPv4 yang didukung"
#: shared-module/displayio/OnDiskBitmap.c
#, c-format
@ -1690,6 +1692,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""
@ -1707,15 +1710,15 @@ msgstr ""
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Operation timed out"
msgstr ""
msgstr "Waktu habis"
#: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c
msgid "Out of memory"
msgstr ""
msgstr "Kehabisan memori"
#: ports/esp32s2/common-hal/socketpool/SocketPool.c
msgid "Out of sockets"
msgstr ""
msgstr "Kehabisan socket"
#: ports/raspberrypi/bindings/rp2pio/StateMachine.c
msgid "Out-buffer elements must be <= 4 bytes long"
@ -1761,7 +1764,7 @@ msgstr "ParallelBus belum didukung"
#: ports/esp32s2/common-hal/audiobusio/__init__.c
msgid "Peripheral in use"
msgstr ""
msgstr "Periferal sedang digunakan"
#: py/moduerrno.c
msgid "Permission denied"
@ -1773,7 +1776,7 @@ msgstr ""
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
msgid "Pin count too large"
msgstr ""
msgstr "Jumlah pin terlalu besar"
#: ports/atmel-samd/common-hal/analogio/AnalogIn.c
#: ports/cxd56/common-hal/analogio/AnalogIn.c
@ -1815,7 +1818,7 @@ msgstr ""
#: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c
msgid "Pins must be sequential"
msgstr ""
msgstr "Pin harus berurutan"
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
msgid "Pins must share PWM slice"
@ -4239,11 +4242,11 @@ msgstr ""
#: ports/esp32s2/common-hal/wifi/Radio.c
msgid "wifi is not enabled"
msgstr ""
msgstr "wifi tidak diaktifkan"
#: shared-bindings/_bleio/Adapter.c
msgid "window must be <= interval"
msgstr ""
msgstr "jendela harus <= interval"
#: extmod/ulab/code/numpy/numerical/numerical.c
msgid "wrong axis index"

View File

@ -681,6 +681,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr ""
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1285,7 +1286,8 @@ msgstr ""
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr ""
@ -1663,6 +1665,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -684,6 +684,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr ""
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1288,7 +1289,8 @@ msgstr ""
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr ""
@ -1666,6 +1668,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -694,6 +694,7 @@ msgstr ""
"Die Frequenz eines bereits verwendeten Timers kann nicht variiert werden"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr "Kann nicht auf Flanke wecken, nur auf Level."
@ -1308,7 +1309,8 @@ msgstr "Ungültige Phase"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Ungültiger Pin"
@ -1693,6 +1695,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -681,6 +681,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr ""
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1285,7 +1286,8 @@ msgstr ""
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr ""
@ -1663,6 +1665,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -692,6 +692,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "Cannot vary frequency on a timer that is already in use"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr "Cannot wake on pin edge. Only level."
@ -1302,7 +1303,8 @@ msgstr "Invalid phase"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Invalid pin"
@ -1684,6 +1686,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr "Only one TouchAlarm can be set in deep sleep."
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr "Only one alarm.time alarm can be set."

View File

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
"PO-Revision-Date: 2021-04-25 18:43+0000\n"
"PO-Revision-Date: 2021-04-28 16:11+0000\n"
"Last-Translator: Alvaro Figueroa <alvaro@greencore.co.cr>\n"
"Language-Team: \n"
"Language: es\n"
@ -701,6 +701,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "No puede variar la frecuencia en un temporizador que ya está en uso"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr "No puede despertar en pin edge, solo en nivel."
@ -1319,7 +1320,8 @@ msgstr "Fase inválida"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Pin inválido"
@ -1707,6 +1709,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr "Solamente una TouchAlarm puede ser configurada durante deep sleep."
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr "Solamente una alarm.time puede ser configurada."
@ -3164,11 +3167,11 @@ msgstr "identificador redefinido como nonlocal"
#: py/persistentcode.c
msgid "incompatible .mpy file"
msgstr ""
msgstr "archivo .mpy incompatible"
#: py/persistentcode.c
msgid "incompatible native .mpy architecture"
msgstr ""
msgstr "arquitectura nativa de .mpy incompatible"
#: py/objstr.c
msgid "incomplete format"
@ -3291,7 +3294,7 @@ msgstr "el intervalo debe ser der rango %s-%s"
#: py/compile.c
msgid "invalid architecture"
msgstr ""
msgstr "arquitectura inválida"
#: lib/netutils/netutils.c
msgid "invalid arguments"

View File

@ -688,6 +688,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr ""
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1300,7 +1301,8 @@ msgstr "Mali ang phase"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Mali ang pin"
@ -1681,6 +1683,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
"PO-Revision-Date: 2021-04-24 14:29+0000\n"
"PO-Revision-Date: 2021-04-28 16:11+0000\n"
"Last-Translator: Hugo Dahl <hugo@code-jedi.com>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
@ -707,6 +707,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "Impossible de faire varier la fréquence sur un minuteur déjà utilisée"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr "Ne peut reveillé sur le board de broche. Seuleument à niveau."
@ -1331,7 +1332,8 @@ msgstr "Phase invalide"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Broche invalide"
@ -1717,6 +1719,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr "Seulement une TouchAlarm peu être réglée en someil profond."
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr "Seulement une alarme alarm.time peut être réglée."
@ -3187,11 +3190,11 @@ msgstr "identifiant redéfini comme nonlocal"
#: py/persistentcode.c
msgid "incompatible .mpy file"
msgstr ""
msgstr "Fichier .mpy incompatible"
#: py/persistentcode.c
msgid "incompatible native .mpy architecture"
msgstr ""
msgstr "architecture native .mpy incompatible"
#: py/objstr.c
msgid "incomplete format"
@ -3315,7 +3318,7 @@ msgstr "interval doit être dans la portée %s-%s"
#: py/compile.c
msgid "invalid architecture"
msgstr ""
msgstr "architecture invalide"
#: lib/netutils/netutils.c
msgid "invalid arguments"

View File

@ -681,6 +681,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr ""
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1285,7 +1286,8 @@ msgstr ""
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr ""
@ -1663,6 +1665,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -698,6 +698,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr ""
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1311,7 +1312,8 @@ msgstr "Fase non valida"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Pin non valido"
@ -1695,6 +1697,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -690,6 +690,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "使用中のタイマー上では周波数を変えられません"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1298,7 +1299,8 @@ msgstr "不正なphase"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "不正なピン"
@ -1678,6 +1680,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -684,6 +684,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr ""
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1288,7 +1289,8 @@ msgstr "단계가 잘못되었습니다"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "핀이 잘못되었습니다"
@ -1666,6 +1668,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -688,6 +688,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "Kan de frequentie van een timer die al in gebruik is niet variëren"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1299,7 +1300,8 @@ msgstr "Ongeldige fase"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Ongeldige pin"
@ -1683,6 +1685,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr "Slechts één alarm.time alarm kan worden ingesteld."

View File

@ -688,6 +688,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "Nie można zmieniać częstotliwości timera, który jest już używany"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr ""
@ -1298,7 +1299,8 @@ msgstr "Zła faza"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Zła nóżka"
@ -1676,6 +1678,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr ""
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr ""

View File

@ -6,7 +6,7 @@ msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
"PO-Revision-Date: 2021-04-25 18:43+0000\n"
"PO-Revision-Date: 2021-04-28 16:11+0000\n"
"Last-Translator: Wellington Terumi Uemura <wellingtonuemura@gmail.com>\n"
"Language-Team: \n"
"Language: pt_BR\n"
@ -705,6 +705,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "Não é possível variar a frequência em um timer que já esteja em uso"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr "Não é possível acordar (wake) no pino edge. Nível apenas."
@ -1322,7 +1323,8 @@ msgstr "Fase Inválida"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Pino inválido"
@ -1707,6 +1709,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr "Apenas um TouchAlarm pode ser colocado em deep sleep."
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr "Apenas um alarme alarm.time pode ser definido."
@ -3173,11 +3176,11 @@ msgstr "o identificador foi redefinido como não-local"
#: py/persistentcode.c
msgid "incompatible .mpy file"
msgstr ""
msgstr "arquivo .mpy incompatível"
#: py/persistentcode.c
msgid "incompatible native .mpy architecture"
msgstr ""
msgstr "arquivo .mpy com arquitetura nativa incompatível"
#: py/objstr.c
msgid "incomplete format"
@ -3301,7 +3304,7 @@ msgstr "o intervalo deve estar entre %s-%s"
#: py/compile.c
msgid "invalid architecture"
msgstr ""
msgstr "arquitetura inválida"
#: lib/netutils/netutils.c
msgid "invalid arguments"

View File

@ -6,7 +6,7 @@ msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
"PO-Revision-Date: 2021-04-24 14:29+0000\n"
"PO-Revision-Date: 2021-04-28 16:11+0000\n"
"Last-Translator: Jonny Bergdahl <jonny@bergdahl.it>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: sv\n"
@ -694,6 +694,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "Det går inte att ändra frekvensen på en timer som redan används"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr "Kan inte vakna på nivåskift, enbart nivå."
@ -1306,7 +1307,8 @@ msgstr "Ogiltig fas"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Ogiltig pinne"
@ -1690,6 +1692,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr "Endast ett TouchAlarm kan ställas in för djupsömn."
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr "Endast ett alarm.time kan ställas in."
@ -3139,11 +3142,11 @@ msgstr "identifieraren omdefinierad som icke-lokal"
#: py/persistentcode.c
msgid "incompatible .mpy file"
msgstr ""
msgstr "inkompatibel .mpy-fil"
#: py/persistentcode.c
msgid "incompatible native .mpy architecture"
msgstr ""
msgstr "inkompatibel nativ .mpy-arkitektur"
#: py/objstr.c
msgid "incomplete format"
@ -3266,7 +3269,7 @@ msgstr "interval måste vara i intervallet %s-%s"
#: py/compile.c
msgid "invalid architecture"
msgstr ""
msgstr "ogiltig arkitektur"
#: lib/netutils/netutils.c
msgid "invalid arguments"

View File

@ -695,6 +695,7 @@ msgid "Cannot vary frequency on a timer that is already in use"
msgstr "Wúfǎ gēnggǎi yǐ zài shǐyòng de jìshí qì shàng de pínlǜ"
#: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c
msgid "Cannot wake on pin edge. Only level."
msgstr "wú fǎ zài yǐn jiǎo biān yuán huàn xǐng. jǐn jí bié."
@ -1308,7 +1309,8 @@ msgstr "Jiēduàn wúxiào"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
#: ports/atmel-samd/common-hal/touchio/TouchIn.c
#: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c
#: ports/esp32s2/common-hal/touchio/TouchIn.c
#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c
#: shared-module/rgbmatrix/RGBMatrix.c
msgid "Invalid pin"
msgstr "Wúxiào de yǐn jiǎo"
@ -1692,6 +1694,7 @@ msgid "Only one TouchAlarm can be set in deep sleep."
msgstr "zhǐ yǒu yí gè chù mō bì kě yǐ shè zhì zài shēn dù shuì mián."
#: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c
#: ports/nrf/common-hal/alarm/time/TimeAlarm.c
msgid "Only one alarm.time alarm can be set."
msgstr "zhǐ néng shè zhì yí gè bào jǐng."

1
main.c
View File

@ -427,6 +427,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
// it may also return due to another interrupt, that's why we check
// for deep sleep alarms above. If it wasn't a deep sleep alarm,
// then we'll idle here again.
#if CIRCUITPY_ALARM
common_hal_alarm_pretending_deep_sleep();
#else

View File

@ -0,0 +1,40 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "supervisor/board.h"
#include "common-hal/microcontroller/Pin.h"
#include "supervisor/shared/board.h"
#include "hal/include/hal_gpio.h"
void board_init(void) {
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}

View File

@ -0,0 +1,55 @@
#define MICROPY_HW_BOARD_NAME "CP Sapling M0"
#define MICROPY_HW_MCU_NAME "samd21e18"
#define MICROPY_HW_NEOPIXEL (&pin_PA15)
#define MICROPY_PORT_A (0)
#define MICROPY_PORT_B (0)
#define MICROPY_PORT_C (0)
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA05 1
#define IGNORE_PIN_PA06 1
#define IGNORE_PIN_PA12 1
#define IGNORE_PIN_PA13 1
#define IGNORE_PIN_PA20 1
#define IGNORE_PIN_PA21 1
#define IGNORE_PIN_PA23
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1
#define IGNORE_PIN_PB01 1
#define IGNORE_PIN_PB02 1
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PB04 1
#define IGNORE_PIN_PB05 1
#define IGNORE_PIN_PB06 1
#define IGNORE_PIN_PB07 1
#define IGNORE_PIN_PB08 1
#define IGNORE_PIN_PB09 1
#define IGNORE_PIN_PB10 1
#define IGNORE_PIN_PB11 1
#define IGNORE_PIN_PB12 1
#define IGNORE_PIN_PB13 1
#define IGNORE_PIN_PB14 1
#define IGNORE_PIN_PB15 1
#define IGNORE_PIN_PB16 1
#define IGNORE_PIN_PB17 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PB30 1
#define IGNORE_PIN_PB31 1
#define IGNORE_PIN_PB00 1
#define DEFAULT_I2C_BUS_SCL (&pin_PA09)
#define DEFAULT_I2C_BUS_SDA (&pin_PA08)
#define DEFAULT_SPI_BUS_SS (&pin_PA22)
#define DEFAULT_SPI_BUS_SCK (&pin_PA19)
#define DEFAULT_SPI_BUS_MOSI (&pin_PA18)
#define DEFAULT_SPI_BUS_MISO (&pin_PA17)
#define DEFAULT_UART_BUS_RX (&pin_PA00)
#define DEFAULT_UART_BUX_TX (&pin_PA01)

View File

@ -0,0 +1,14 @@
USB_VID = 0x1209
USB_PID = 0x4DDF
USB_PRODUCT = "CP Sapling Rev B"
USB_MANUFACTURER = "Oak Development Technologies"
CHIP_VARIANT = SAMD21E18A
CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
SUPEROPT_GC = 0
SUPEROPT_VM = 0

View File

@ -0,0 +1,54 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_A8), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA00) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_A9), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA01) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_A11), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_A12), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_A13), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_A14), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_A15), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA15) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_uart), MP_ROM_PTR(&board_uart_obj) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -27,6 +27,17 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
// Other some pins that do not appear in the pinout & are not used internally
// this list is not (yet) exhaustive
#define IGNORE_PIN_PA03 1
#define IGNORE_PIN_PB01 1
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PB04 1
#define IGNORE_PIN_PB05 1
#define IGNORE_PIN_PB06 1
#define IGNORE_PIN_PB07 1
#define IGNORE_PIN_PB12 1
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1

View File

@ -23,6 +23,21 @@
#define DEFAULT_UART_BUS_RX (&pin_PB08) /* ANALOG 1 */
#define DEFAULT_UART_BUS_TX (&pin_PB09) /* ANALOG 2 */
// Other some pins that do not appear in the pinout & are not used internally
// this list is not (yet) exhaustive
#define IGNORE_PIN_PA01 1
#define IGNORE_PIN_PA03 1
#define IGNORE_PIN_PB04 1
#define IGNORE_PIN_PB05 1
#define IGNORE_PIN_PB00 1
#define IGNORE_PIN_PB01 1
#define IGNORE_PIN_PB02 1
#define IGNORE_PIN_PB04 1
#define IGNORE_PIN_PB05 1
#define IGNORE_PIN_PB06 1
#define IGNORE_PIN_PB07 1
#define IGNORE_PIN_PB12 1
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1

View File

@ -102,10 +102,12 @@ void audioout_reset(void) {
return;
#endif
#ifdef SAMD21
while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {}
while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {
}
#endif
#ifdef SAM_D5X_E5X
while (DAC->SYNCBUSY.reg & DAC_SYNCBUSY_SWRST) {}
while (DAC->SYNCBUSY.reg & DAC_SYNCBUSY_SWRST) {
}
#endif
if (DAC->CTRLA.bit.ENABLE) {
ramp_value(0x8000, 0);
@ -174,7 +176,8 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
_gclk_enable_channel(DAC_GCLK_ID, CONF_GCLK_DAC_SRC);
DAC->CTRLA.bit.SWRST = 1;
while (DAC->CTRLA.bit.SWRST == 1) {}
while (DAC->CTRLA.bit.SWRST == 1) {
}
// Make sure there are no outstanding access errors. (Reading DATA can cause this.)
#ifdef SAM_D5X_E5X
PAC->INTFLAGD.reg = PAC_INTFLAGD_DAC;
@ -216,12 +219,16 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
// Re-enable the DAC
DAC->CTRLA.bit.ENABLE = 1;
#ifdef SAMD21
while (DAC->STATUS.bit.SYNCBUSY == 1) {}
while (DAC->STATUS.bit.SYNCBUSY == 1) {
}
#endif
#ifdef SAM_D5X_E5X
while (DAC->SYNCBUSY.bit.ENABLE == 1) {}
while (channel0_enabled && DAC->STATUS.bit.READY0 == 0) {}
while (channel1_enabled && DAC->STATUS.bit.READY1 == 0) {}
while (DAC->SYNCBUSY.bit.ENABLE == 1) {
}
while (channel0_enabled && DAC->STATUS.bit.READY0 == 0) {
}
while (channel1_enabled && DAC->STATUS.bit.READY1 == 0) {
}
#endif
// Use a timer to coordinate when DAC conversions occur.
@ -320,10 +327,12 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) {
DAC->CTRLA.bit.ENABLE = 0;
#ifdef SAMD21
while (DAC->STATUS.bit.SYNCBUSY == 1) {}
while (DAC->STATUS.bit.SYNCBUSY == 1) {
}
#endif
#ifdef SAM_D5X_E5X
while (DAC->SYNCBUSY.bit.ENABLE == 1) {}
while (DAC->SYNCBUSY.bit.ENABLE == 1) {
}
#endif
disable_event_channel(self->tc_to_dac_event_channel);
@ -428,7 +437,8 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t* self,
Tc *timer = tc_insts[self->tc_index];
set_timer_frequency(timer, audiosample_sample_rate(sample));
timer->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_RETRIGGER;
while (timer->COUNT16.STATUS.bit.STOP == 1) {}
while (timer->COUNT16.STATUS.bit.STOP == 1) {
}
self->playing = true;
}

View File

@ -47,8 +47,7 @@ STATIC canio_can_obj_t *can_objs[MP_ARRAY_SIZE(can_insts)];
// This must be placed in the first 64kB of RAM
STATIC COMPILER_SECTION(".canram") canio_can_state_t can_state[MP_ARRAY_SIZE(can_insts)];
void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mcu_pin_obj_t *rx, int baudrate, bool loopback, bool silent)
{
void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mcu_pin_obj_t *rx, int baudrate, bool loopback, bool silent) {
mcu_pin_function_t *tx_function = mcu_find_pin_function(can_tx, tx, -1, MP_QSTR_tx);
int instance = tx_function->instance;
@ -255,23 +254,19 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mc
can_objs[instance] = self;
}
bool common_hal_canio_can_loopback_get(canio_can_obj_t *self)
{
bool common_hal_canio_can_loopback_get(canio_can_obj_t *self) {
return self->loopback;
}
int common_hal_canio_can_baudrate_get(canio_can_obj_t *self)
{
int common_hal_canio_can_baudrate_get(canio_can_obj_t *self) {
return self->baudrate;
}
int common_hal_canio_can_transmit_error_count_get(canio_can_obj_t *self)
{
int common_hal_canio_can_transmit_error_count_get(canio_can_obj_t *self) {
return self->hw->ECR.bit.TEC;
}
int common_hal_canio_can_receive_error_count_get(canio_can_obj_t *self)
{
int common_hal_canio_can_receive_error_count_get(canio_can_obj_t *self) {
return self->hw->ECR.bit.REC;
}
@ -313,11 +308,11 @@ static void maybe_auto_restart(canio_can_obj_t *self) {
}
}
void common_hal_canio_can_send(canio_can_obj_t *self, mp_obj_t message_in)
{
void common_hal_canio_can_send(canio_can_obj_t *self, mp_obj_t message_in) {
maybe_auto_restart(self);
canio_message_obj_t *message = message_in;;
canio_message_obj_t *message = message_in;
;
// We have just one dedicated TX buffer, use it!
canio_can_tx_buffer_t *ent = &self->state->tx_buffer[0];
@ -365,8 +360,7 @@ void common_hal_canio_can_check_for_deinit(canio_can_obj_t *self) {
}
}
void common_hal_canio_can_deinit(canio_can_obj_t *self)
{
void common_hal_canio_can_deinit(canio_can_obj_t *self) {
if (self->hw) {
hri_can_set_CCCR_INIT_bit(self->hw);
self->hw = 0;

View File

@ -179,7 +179,8 @@ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
} else {
if (hri_port_get_PINCFG_PULLEN_bit(PORT, GPIO_PORT(pin), GPIO_PIN(pin)) == 0) {
return PULL_NONE;
} if (hri_port_get_OUT_reg(PORT, GPIO_PORT(pin), 1U << GPIO_PIN(pin)) > 0) {
}
if (hri_port_get_OUT_reg(PORT, GPIO_PORT(pin), 1U << GPIO_PIN(pin)) > 0) {
return PULL_UP;
} else {
return PULL_DOWN;

View File

@ -63,7 +63,8 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe
#endif
sercom->I2CS.CTRLA.bit.SWRST = 1;
while (sercom->I2CS.CTRLA.bit.SWRST || sercom->I2CS.SYNCBUSY.bit.SWRST) {}
while (sercom->I2CS.CTRLA.bit.SWRST || sercom->I2CS.SYNCBUSY.bit.SWRST) {
}
sercom->I2CS.CTRLB.bit.AACKEN = 0; // Automatic acknowledge is disabled.
@ -134,8 +135,7 @@ static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self,
return -err;
}
int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart)
{
int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) {
int err = i2c_peripheral_check_error(self, false);
if (err) {
return err;

View File

@ -54,14 +54,12 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
const mcu_pin_obj_t *data_clock,
const mcu_pin_obj_t *vertical_sync,
const mcu_pin_obj_t *horizontal_reference,
int data_count)
{
int data_count) {
if (data0->number != PIN_PCC_D0) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_data0);
}
// The peripheral supports 8, 10, 12, or 14 data bits, but the code only supports 8 at present
if (data_count != 8)
{
if (data_count != 8) {
mp_raise_ValueError_varg(translate("Invalid data_count %d"), data_count);
}
if (vertical_sync && vertical_sync->number != PIN_PCC_DEN1) {
@ -121,8 +119,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
}
}
void common_hal_imagecapture_parallelimagecapture_deinit(imagecapture_parallelimagecapture_obj_t *self)
{
void common_hal_imagecapture_parallelimagecapture_deinit(imagecapture_parallelimagecapture_obj_t *self) {
if (common_hal_imagecapture_parallelimagecapture_deinited(self)) {
return;
}
@ -135,8 +132,7 @@ void common_hal_imagecapture_parallelimagecapture_deinit(imagecapture_parallelim
self->data_count = 0;
}
bool common_hal_imagecapture_parallelimagecapture_deinited(imagecapture_parallelimagecapture_obj_t *self)
{
bool common_hal_imagecapture_parallelimagecapture_deinited(imagecapture_parallelimagecapture_obj_t *self) {
return self->data_count == 0;
}
@ -154,8 +150,7 @@ static void setup_dma(DmacDescriptor* descriptor, size_t count, uint32_t *buffer
#include <string.h>
void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_parallelimagecapture_obj_t *self, void *buffer, size_t bufsize)
{
void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_parallelimagecapture_obj_t *self, void *buffer, size_t bufsize) {
uint8_t dma_channel = dma_allocate_channel();
@ -171,8 +166,7 @@ void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_paralleli
const volatile uint32_t *vsync_reg = &PORT->Group[(self->vertical_sync / 32)].IN.reg;
uint32_t vsync_bit = 1 << (self->vertical_sync % 32);
while (*vsync_reg & vsync_bit)
{
while (*vsync_reg & vsync_bit) {
// Wait for VSYNC low (frame end)
RUN_BACKGROUND_TASKS;

View File

@ -83,11 +83,11 @@
STATIC float convert_dec_to_frac(uint8_t val) {
float float_val = (float)val;
if (val < 10) {
return (float_val/10.0);
return float_val / 10.0;
} else if (val < 100) {
return (float_val/100.0);
return float_val / 100.0;
} else {
return (float_val/1000.0);
return float_val / 1000.0;
}
}

View File

@ -108,7 +108,8 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
// Wait to make sure we don't append onto the last transmission. This should only be a tick or
// two.
while (port_get_raw_ticks(NULL) < next_start_raw_ticks) {}
while (port_get_raw_ticks(NULL) < next_start_raw_ticks) {
}
// Turn off interrupts of any kind during timing-sensitive code.
mp_hal_disable_all_interrupts();

View File

@ -307,8 +307,7 @@ bool common_hal_ps2io_ps2_get_paused(ps2io_ps2_obj_t* self) {
return (EIC->INTENSET.reg & (mask << EIC_INTENSET_EXTINT_Pos)) == 0;
}
int16_t common_hal_ps2io_ps2_popleft(ps2io_ps2_obj_t* self)
{
int16_t common_hal_ps2io_ps2_popleft(ps2io_ps2_obj_t *self) {
common_hal_mcu_disable_interrupts();
if (self->bufcount <= 0) {
common_hal_mcu_enable_interrupts();
@ -321,8 +320,7 @@ int16_t common_hal_ps2io_ps2_popleft(ps2io_ps2_obj_t* self)
return b;
}
uint16_t common_hal_ps2io_ps2_clear_errors(ps2io_ps2_obj_t* self)
{
uint16_t common_hal_ps2io_ps2_clear_errors(ps2io_ps2_obj_t *self) {
common_hal_mcu_disable_interrupts();
uint16_t errors = self->last_errors;
self->last_errors = 0;
@ -333,8 +331,7 @@ uint16_t common_hal_ps2io_ps2_clear_errors(ps2io_ps2_obj_t* self)
// Based upon TMK implementation of PS/2 protocol
// https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/protocol/ps2_interrupt.c
int16_t common_hal_ps2io_ps2_sendcmd(ps2io_ps2_obj_t* self, uint8_t b)
{
int16_t common_hal_ps2io_ps2_sendcmd(ps2io_ps2_obj_t *self, uint8_t b) {
disable_interrupt(self);
inhibit(self);
delay_us(100);

View File

@ -54,10 +54,14 @@ volatile static uint32_t overflow_count = 0;
volatile static uint32_t start_overflow = 0;
void pulsein_timer_interrupt_handler(uint8_t index) {
if (index != pulsein_tc_index) return;
if (index != pulsein_tc_index) {
return;
}
overflow_count++;
Tc *tc = tc_insts[index];
if (!tc->COUNT16.INTFLAG.bit.OVF) return;
if (!tc->COUNT16.INTFLAG.bit.OVF) {
return;
}
// Clear the interrupt bit.
tc->COUNT16.INTFLAG.reg = TC_INTFLAG_OVF;
@ -87,7 +91,8 @@ void pulsein_interrupt_handler(uint8_t channel) {
#ifdef SAM_D5X_E5X
tc->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_READSYNC;
while (tc->COUNT16.SYNCBUSY.bit.COUNT == 1 ||
tc->COUNT16.CTRLBSET.bit.CMD == TC_CTRLBSET_CMD_READSYNC_Val) {}
tc->COUNT16.CTRLBSET.bit.CMD == TC_CTRLBSET_CMD_READSYNC_Val) {
}
#endif
uint32_t current_count = tc->COUNT16.COUNT.reg;

View File

@ -79,9 +79,13 @@ void pulse_finish(void) {
}
void pulseout_interrupt_handler(uint8_t index) {
if (index != pulseout_tc_index) return;
if (index != pulseout_tc_index) {
return;
}
Tc *tc = tc_insts[index];
if (!tc->COUNT16.INTFLAG.bit.MC0) return;
if (!tc->COUNT16.INTFLAG.bit.MC0) {
return;
}
pulse_finish();

View File

@ -347,7 +347,8 @@ extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uin
#endif
#ifdef SAM_D5X_E5X
Tc *tc = tc_insts[t->index];
while (tc->COUNT16.SYNCBUSY.bit.CC1 != 0) {}
while (tc->COUNT16.SYNCBUSY.bit.CC1 != 0) {
}
tc->COUNT16.CCBUF[1].reg = adjusted_duty;
#endif
} else {
@ -359,7 +360,8 @@ extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uin
// CC register on an UPDATE (when period is finished).
// Do clock domain syncing as necessary.
while (tcc->SYNCBUSY.reg != 0) {}
while (tcc->SYNCBUSY.reg != 0) {
}
// Lock out double-buffering while updating the CCB value.
tcc->CTRLBSET.bit.LUPD = 1;
@ -385,7 +387,8 @@ uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) {
uint8_t channel = tcc_channel(t);
uint32_t cv = 0;
while (tcc->SYNCBUSY.bit.CTRLB) {}
while (tcc->SYNCBUSY.bit.CTRLB) {
}
#ifdef SAMD21
// If CCBV (CCB valid) is set, the CCB value hasn't yet been copied
@ -446,7 +449,8 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self,
tc->COUNT16.CC[0].reg = new_top;
#endif
#ifdef SAM_D5X_E5X
while (tc->COUNT16.SYNCBUSY.reg != 0) {}
while (tc->COUNT16.SYNCBUSY.reg != 0) {
}
tc->COUNT16.CCBUF[0].reg = new_top;
#endif
} else {
@ -457,7 +461,8 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self,
tcc->CTRLA.bit.PRESCALER = new_divisor;
tcc_set_enable(tcc, true);
}
while (tcc->SYNCBUSY.reg != 0) {}
while (tcc->SYNCBUSY.reg != 0) {
}
tcc_periods[t->index] = new_top;
#ifdef SAMD21
tcc->PERB.bit.PERB = new_top;

0
ports/atmel-samd/common-hal/supervisor/Runtime.c Executable file → Normal file
View File

View File

@ -114,10 +114,12 @@ void touchin_reset() {
Ptc *ptc = ((Ptc *)PTC);
if (ptc->CTRLA.bit.ENABLE == 1) {
ptc->CTRLA.bit.ENABLE = 0;
while (ptc->CTRLA.bit.ENABLE == 1) {}
while (ptc->CTRLA.bit.ENABLE == 1) {
}
ptc->CTRLA.bit.SWRESET = 1;
while (ptc->CTRLA.bit.SWRESET == 1) {}
while (ptc->CTRLA.bit.SWRESET == 1) {
}
}
}

View File

@ -228,8 +228,7 @@ static bool sd_mmc_mci_install_mmc(void);
*
* \return true if success, otherwise false
*/
static bool mmc_mci_op_cond(void)
{
static bool mmc_mci_op_cond(void) {
uint32_t retry, resp;
/*
@ -268,8 +267,7 @@ static bool mmc_mci_op_cond(void)
*
* \return true if success, otherwise false
*/
static bool sd_mci_op_cond(uint8_t v2)
{
static bool sd_mci_op_cond(uint8_t v2) {
uint32_t arg, retry, resp;
/*
@ -321,8 +319,7 @@ static bool sd_mci_op_cond(uint8_t v2)
*
* \return true if success, otherwise false
*/
static bool sdio_op_cond(void)
{
static bool sdio_op_cond(void) {
uint32_t resp;
/* CMD5 - SDIO send operation condition (OCR) command. */
@ -373,8 +370,7 @@ static bool sdio_op_cond(void)
*
* \return true if success, otherwise false
*/
static bool sdio_get_max_speed(void)
{
static bool sdio_get_max_speed(void) {
uint32_t addr_new, addr_old;
uint8_t buf[6];
uint32_t unit;
@ -451,8 +447,7 @@ static bool sdio_get_max_speed(void)
*
* \return true if success, otherwise false
*/
static bool sdio_cmd52_set_bus_width(void)
{
static bool sdio_cmd52_set_bus_width(void) {
/**
* A SD memory card always supports bus 4bit
* A SD COMBO card always supports bus 4bit
@ -486,8 +481,7 @@ static bool sdio_cmd52_set_bus_width(void)
*
* \return true if success, otherwise false
*/
static bool sdio_cmd52_set_high_speed(void)
{
static bool sdio_cmd52_set_high_speed(void) {
uint8_t u8_value;
/* Check CIA.HS */
@ -509,20 +503,16 @@ static bool sdio_cmd52_set_high_speed(void)
}
#else
static bool sdio_op_cond(void)
{
static bool sdio_op_cond(void) {
return true; /* No error but card type not updated */
}
static bool sdio_get_max_speed(void)
{
static bool sdio_get_max_speed(void) {
return false;
}
static bool sdio_cmd52_set_bus_width(void)
{
static bool sdio_cmd52_set_bus_width(void) {
return false;
}
static bool sdio_cmd52_set_high_speed(void)
{
static bool sdio_cmd52_set_high_speed(void) {
return false;
}
#endif
@ -536,8 +526,7 @@ static bool sdio_cmd52_set_high_speed(void)
*
* \return true if success, otherwise false
*/
static bool sd_cm6_set_high_speed(void)
{
static bool sd_cm6_set_high_speed(void) {
uint8_t switch_status[SD_SW_STATUS_BSIZE] = {0};
if (!driver_adtc_start(sd_mmc_hal,
@ -587,8 +576,7 @@ static bool sd_cm6_set_high_speed(void)
*
* \return true if success, otherwise false
*/
static bool mmc_cmd6_set_bus_width(uint8_t bus_width)
{
static bool mmc_cmd6_set_bus_width(uint8_t bus_width) {
uint32_t arg;
switch (bus_width) {
@ -622,8 +610,7 @@ static bool mmc_cmd6_set_bus_width(uint8_t bus_width)
*
* \return true if success, otherwise false
*/
static bool mmc_cmd6_set_high_speed(void)
{
static bool mmc_cmd6_set_high_speed(void) {
if (!driver_send_cmd(sd_mmc_hal,
MMC_CMD6_SWITCH,
MMC_CMD6_ACCESS_WRITE_BYTE | MMC_CMD6_INDEX_HS_TIMING | MMC_CMD6_VALUE_HS_TIMING_ENABLE)) {
@ -652,8 +639,7 @@ static bool mmc_cmd6_set_high_speed(void)
* \return true if success, otherwise false
* with a update of \ref sd_mmc_err.
*/
static bool sd_cmd8(uint8_t *v2)
{
static bool sd_cmd8(uint8_t *v2) {
uint32_t resp;
*v2 = 0;
@ -683,8 +669,7 @@ static bool sd_cmd8(uint8_t *v2)
*
* \return true if success, otherwise false
*/
static bool mmc_cmd8(uint8_t *b_authorize_high_speed)
{
static bool mmc_cmd8(uint8_t *b_authorize_high_speed) {
uint16_t i;
uint32_t ext_csd;
uint32_t sec_count;
@ -730,8 +715,7 @@ static bool mmc_cmd8(uint8_t *b_authorize_high_speed)
*
* \return true if success, otherwise false
*/
static bool sd_mmc_cmd9_mci(void)
{
static bool sd_mmc_cmd9_mci(void) {
if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD9_SEND_CSD, (uint32_t)sd_mmc_card->rca << 16)) {
return false;
}
@ -743,8 +727,7 @@ static bool sd_mmc_cmd9_mci(void)
/**
* \brief Decodes MMC CSD register
*/
static void mmc_decode_csd(void)
{
static void mmc_decode_csd(void) {
uint32_t unit;
uint32_t mul;
uint32_t tran_speed;
@ -803,8 +786,7 @@ static void mmc_decode_csd(void)
/**
* \brief Decodes SD CSD register
*/
static void sd_decode_csd(void)
{
static void sd_decode_csd(void) {
uint32_t unit;
uint32_t mul;
uint32_t tran_speed;
@ -843,8 +825,7 @@ static void sd_decode_csd(void)
*
* \return true if success, otherwise false
*/
static bool sd_mmc_cmd13(void)
{
static bool sd_mmc_cmd13(void) {
uint32_t nec_timeout;
/* Wait for data ready status.
@ -881,8 +862,7 @@ static bool sd_mmc_cmd13(void)
*
* \return true if success, otherwise false
*/
static bool sdio_cmd52(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t rd_after_wr, uint8_t *io_data)
{
static bool sdio_cmd52(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t rd_after_wr, uint8_t *io_data) {
ASSERT(io_data != NULL);
if (!driver_send_cmd(sd_mmc_hal,
SDIO_CMD52_IO_RW_DIRECT,
@ -912,8 +892,7 @@ static bool sdio_cmd52(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint
* \return true if success, otherwise false
*/
static bool sdio_cmd53(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t inc_addr, uint32_t size,
bool access_block)
{
bool access_block) {
ASSERT(size != 0);
ASSERT(size <= 512);
@ -934,8 +913,7 @@ static bool sdio_cmd53(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint
*
* \return true if success, otherwise false
*/
static bool sd_acmd6(void)
{
static bool sd_acmd6(void) {
/* CMD55 - Indicate to the card that the next command is an
* application specific command rather than a standard command.*/
if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD55_APP_CMD, (uint32_t)sd_mmc_card->rca << 16)) {
@ -960,8 +938,7 @@ static bool sd_acmd6(void)
*
* \return true if success, otherwise false
*/
static bool sd_acmd51(void)
{
static bool sd_acmd51(void) {
uint8_t scr[SD_SCR_REG_BSIZE];
/* CMD55 - Indicate to the card that the next command is an
@ -1015,8 +992,7 @@ static bool sd_acmd51(void)
* \retval SD_MMC_INIT_ONGOING Card initialization requested
* \retval SD_MMC_OK Card present
*/
static sd_mmc_err_t sd_mmc_select_slot(uint8_t slot)
{
static sd_mmc_err_t sd_mmc_select_slot(uint8_t slot) {
if (slot >= CONF_SD_MMC_MEM_CNT) {
return SD_MMC_ERR_SLOT;
}
@ -1077,8 +1053,7 @@ static sd_mmc_err_t sd_mmc_select_slot(uint8_t slot)
/**
* \brief Configures the driver with the selected card configuration
*/
static void sd_mmc_configure_slot(void)
{
static void sd_mmc_configure_slot(void) {
driver_select_device(
sd_mmc_hal, sd_mmc_slot_sel, sd_mmc_card->clock, sd_mmc_card->bus_width, sd_mmc_card->high_speed);
}
@ -1086,8 +1061,7 @@ static void sd_mmc_configure_slot(void)
/**
* \brief Deselect the current card slot
*/
static void sd_mmc_deselect_slot(void)
{
static void sd_mmc_deselect_slot(void) {
if (sd_mmc_slot_sel < CONF_SD_MMC_MEM_CNT) {
driver_deselect_device(sd_mmc_hal, sd_mmc_slot_sel);
}
@ -1103,8 +1077,7 @@ static void sd_mmc_deselect_slot(void)
*
* \return true if success, otherwise false
*/
static bool sd_mmc_mci_card_init(void)
{
static bool sd_mmc_mci_card_init(void) {
uint8_t v2 = 0;
#if (CONF_SDIO_SUPPORT == 1)
uint8_t data = 0x08;
@ -1236,8 +1209,7 @@ static bool sd_mmc_mci_card_init(void)
*
* \return true if success, otherwise false
*/
static bool sd_mmc_mci_install_mmc(void)
{
static bool sd_mmc_mci_install_mmc(void) {
uint8_t b_authorize_high_speed;
/* CMD0 - Reset all cards to idle state. */
@ -1312,8 +1284,7 @@ static bool sd_mmc_mci_install_mmc(void)
/*--------------------- PUBLIC FUNCTIONS ----------------------------*/
void sd_mmc_init(void *hal, sd_mmc_detect_t *card_detects, sd_mmc_detect_t *wp_detects)
{
void sd_mmc_init(void *hal, sd_mmc_detect_t *card_detects, sd_mmc_detect_t *wp_detects) {
/* GPIO will be used to detect card and write protect.
* The related clocks and pinmux must be configurated in good
* condition. */
@ -1327,13 +1298,11 @@ void sd_mmc_init(void *hal, sd_mmc_detect_t *card_detects, sd_mmc_detect_t *wp_d
_wp = wp_detects;
}
uint8_t sd_mmc_nb_slot(void)
{
uint8_t sd_mmc_nb_slot(void) {
return CONF_SD_MMC_MEM_CNT;
}
sd_mmc_err_t sd_mmc_check(uint8_t slot)
{
sd_mmc_err_t sd_mmc_check(uint8_t slot) {
sd_mmc_err_t sd_mmc_err;
sd_mmc_err = sd_mmc_select_slot(slot);
@ -1355,8 +1324,7 @@ sd_mmc_err_t sd_mmc_check(uint8_t slot)
return SD_MMC_ERR_UNUSABLE;
}
card_type_t sd_mmc_get_type(uint8_t slot)
{
card_type_t sd_mmc_get_type(uint8_t slot) {
if (SD_MMC_OK != sd_mmc_select_slot(slot)) {
return CARD_TYPE_UNKNOWN;
}
@ -1364,8 +1332,7 @@ card_type_t sd_mmc_get_type(uint8_t slot)
return sd_mmc_card->type;
}
card_version_t sd_mmc_get_version(uint8_t slot)
{
card_version_t sd_mmc_get_version(uint8_t slot) {
if (SD_MMC_OK != sd_mmc_select_slot(slot)) {
return CARD_VER_UNKNOWN;
}
@ -1373,8 +1340,7 @@ card_version_t sd_mmc_get_version(uint8_t slot)
return sd_mmc_card->version;
}
uint32_t sd_mmc_get_capacity(uint8_t slot)
{
uint32_t sd_mmc_get_capacity(uint8_t slot) {
if (SD_MMC_OK != sd_mmc_select_slot(slot)) {
return 0;
}
@ -1382,8 +1348,7 @@ uint32_t sd_mmc_get_capacity(uint8_t slot)
return sd_mmc_card->capacity;
}
bool sd_mmc_is_write_protected(uint8_t slot)
{
bool sd_mmc_is_write_protected(uint8_t slot) {
/* No detection, always writable */
if (!_wp || _wp[slot].pin == -1) {
return false;
@ -1395,8 +1360,7 @@ bool sd_mmc_is_write_protected(uint8_t slot)
return false;
}
sd_mmc_err_t sd_mmc_init_read_blocks(uint8_t slot, uint32_t start, uint16_t nb_block)
{
sd_mmc_err_t sd_mmc_init_read_blocks(uint8_t slot, uint32_t start, uint16_t nb_block) {
sd_mmc_err_t sd_mmc_err;
uint32_t cmd, arg, resp;
@ -1442,8 +1406,7 @@ sd_mmc_err_t sd_mmc_init_read_blocks(uint8_t slot, uint32_t start, uint16_t nb_b
return SD_MMC_OK;
}
sd_mmc_err_t sd_mmc_start_read_blocks(void *dest, uint16_t nb_block)
{
sd_mmc_err_t sd_mmc_start_read_blocks(void *dest, uint16_t nb_block) {
ASSERT(sd_mmc_nb_block_remaining >= nb_block);
if (!driver_start_read_blocks(sd_mmc_hal, dest, nb_block)) {
@ -1454,8 +1417,7 @@ sd_mmc_err_t sd_mmc_start_read_blocks(void *dest, uint16_t nb_block)
return SD_MMC_OK;
}
sd_mmc_err_t sd_mmc_wait_end_of_read_blocks(bool abort)
{
sd_mmc_err_t sd_mmc_wait_end_of_read_blocks(bool abort) {
if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) {
return SD_MMC_ERR_COMM;
}
@ -1481,8 +1443,7 @@ sd_mmc_err_t sd_mmc_wait_end_of_read_blocks(bool abort)
return SD_MMC_OK;
}
sd_mmc_err_t sd_mmc_init_write_blocks(uint8_t slot, uint32_t start, uint16_t nb_block)
{
sd_mmc_err_t sd_mmc_init_write_blocks(uint8_t slot, uint32_t start, uint16_t nb_block) {
sd_mmc_err_t sd_mmc_err;
uint32_t cmd, arg, resp;
@ -1525,8 +1486,7 @@ sd_mmc_err_t sd_mmc_init_write_blocks(uint8_t slot, uint32_t start, uint16_t nb_
return SD_MMC_OK;
}
sd_mmc_err_t sd_mmc_start_write_blocks(const void *src, uint16_t nb_block)
{
sd_mmc_err_t sd_mmc_start_write_blocks(const void *src, uint16_t nb_block) {
ASSERT(sd_mmc_nb_block_remaining >= nb_block);
if (!driver_start_write_blocks(sd_mmc_hal, src, nb_block)) {
sd_mmc_nb_block_remaining = 0;
@ -1536,8 +1496,7 @@ sd_mmc_err_t sd_mmc_start_write_blocks(const void *src, uint16_t nb_block)
return SD_MMC_OK;
}
sd_mmc_err_t sd_mmc_wait_end_of_write_blocks(bool abort)
{
sd_mmc_err_t sd_mmc_wait_end_of_write_blocks(bool abort) {
if (!driver_wait_end_of_write_blocks(sd_mmc_hal)) {
return SD_MMC_ERR_COMM;
}
@ -1566,8 +1525,7 @@ sd_mmc_err_t sd_mmc_wait_end_of_write_blocks(bool abort)
}
#if (CONF_SDIO_SUPPORT == 1)
sd_mmc_err_t sdio_read_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t *dest)
{
sd_mmc_err_t sdio_read_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t *dest) {
sd_mmc_err_t sd_mmc_err;
if (dest == NULL) {
@ -1587,8 +1545,7 @@ sd_mmc_err_t sdio_read_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uin
return SD_MMC_OK;
}
sd_mmc_err_t sdio_write_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t data)
{
sd_mmc_err_t sdio_write_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t data) {
sd_mmc_err_t sd_mmc_err;
sd_mmc_err = sd_mmc_select_slot(slot);
@ -1606,8 +1563,7 @@ sd_mmc_err_t sdio_write_direct(uint8_t slot, uint8_t func_num, uint32_t addr, ui
}
sd_mmc_err_t sdio_read_extended(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *dest,
uint16_t size)
{
uint16_t size) {
sd_mmc_err_t sd_mmc_err;
if ((size == 0) || (size > 512)) {
@ -1637,8 +1593,7 @@ sd_mmc_err_t sdio_read_extended(uint8_t slot, uint8_t func_num, uint32_t addr, u
}
sd_mmc_err_t sdio_write_extended(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *src,
uint16_t size)
{
uint16_t size) {
sd_mmc_err_t sd_mmc_err;
if ((size == 0) || (size > 512)) {

View File

@ -716,8 +716,7 @@ typedef uint32_t sdmmc_cmd_def_t;
* \brief Macro function to extract a bits field from a large SD MMC register
* Used by : CSD, SCR, Switch status
*/
static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint16_t pos, uint8_t size)
{
static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint16_t pos, uint8_t size) {
uint32_t value;
value = reg[((reg_size - pos + 7) / 8) - 1] >> (pos % 8);
if (((pos % 8) + size) > 8) {

View File

@ -97,9 +97,13 @@
volatile bool hold_interrupt = false;
#ifdef SAMD21
static void rtc_set_continuous(bool continuous) {
while (RTC->MODE0.STATUS.bit.SYNCBUSY);
while (RTC->MODE0.STATUS.bit.SYNCBUSY) {
;
}
RTC->MODE0.READREQ.reg = (continuous ? RTC_READREQ_RCONT : 0) | 0x0010;
while (RTC->MODE0.STATUS.bit.SYNCBUSY);
while (RTC->MODE0.STATUS.bit.SYNCBUSY) {
;
}
}
void rtc_start_pulse(void) {
@ -164,7 +168,8 @@ static void rtc_init(void) {
#ifdef SAMD21
_gclk_enable_channel(RTC_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK2_Val);
RTC->MODE0.CTRL.bit.SWRST = true;
while (RTC->MODE0.CTRL.bit.SWRST != 0) {}
while (RTC->MODE0.CTRL.bit.SWRST != 0) {
}
RTC->MODE0.CTRL.reg = RTC_MODE0_CTRL_ENABLE |
RTC_MODE0_CTRL_MODE_COUNT32 |
@ -173,7 +178,8 @@ static void rtc_init(void) {
#ifdef SAM_D5X_E5X
hri_mclk_set_APBAMASK_RTC_bit(MCLK);
RTC->MODE0.CTRLA.bit.SWRST = true;
while (RTC->MODE0.SYNCBUSY.bit.SWRST != 0) {}
while (RTC->MODE0.SYNCBUSY.bit.SWRST != 0) {
}
RTC->MODE0.CTRLA.reg = RTC_MODE0_CTRLA_ENABLE |
RTC_MODE0_CTRLA_MODE_COUNT32 |
@ -436,12 +442,14 @@ static volatile bool _ticks_enabled = false;
static uint32_t _get_count(uint64_t *overflow_count) {
#ifdef SAM_D5X_E5X
while ((RTC->MODE0.SYNCBUSY.reg & (RTC_MODE0_SYNCBUSY_COUNTSYNC | RTC_MODE0_SYNCBUSY_COUNT)) != 0) {}
while ((RTC->MODE0.SYNCBUSY.reg & (RTC_MODE0_SYNCBUSY_COUNTSYNC | RTC_MODE0_SYNCBUSY_COUNT)) != 0) {
}
#endif
#ifdef SAMD21
// Request a read so we don't stall the bus later. See section 14.3.1.5 Read Request
RTC->MODE0.READREQ.reg = RTC_READREQ_RREQ | 0x0010;
while (RTC->MODE0.STATUS.bit.SYNCBUSY != 0) {}
while (RTC->MODE0.STATUS.bit.SYNCBUSY != 0) {
}
#endif
// Disable interrupts so we can grab the count and the overflow.
common_hal_mcu_disable_interrupts();
@ -567,8 +575,7 @@ void port_idle_until_interrupt(void) {
/**
* \brief Default interrupt handler for unused IRQs.
*/
__attribute__((used)) void HardFault_Handler(void)
{
__attribute__((used)) void HardFault_Handler(void) {
#ifdef ENABLE_MICRO_TRACE_BUFFER
// Turn off the micro trace buffer so we don't fill it up in the infinite
// loop below.

View File

@ -49,7 +49,9 @@ bool spi_flash_command(uint8_t command) {
QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
while( !QSPI->INTFLAG.bit.INSTREND );
while (!QSPI->INTFLAG.bit.INSTREND) {
;
}
QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;
@ -76,7 +78,9 @@ bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length)
QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
while( !QSPI->INTFLAG.bit.INSTREND );
while (!QSPI->INTFLAG.bit.INSTREND) {
;
}
QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;
@ -107,7 +111,9 @@ bool spi_flash_write_command(uint8_t command, uint8_t* data, uint32_t length) {
QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
while( !QSPI->INTFLAG.bit.INSTREND );
while (!QSPI->INTFLAG.bit.INSTREND) {
;
}
QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;
@ -128,7 +134,9 @@ bool spi_flash_sector_command(uint8_t command, uint32_t address) {
QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
while( !QSPI->INTFLAG.bit.INSTREND );
while (!QSPI->INTFLAG.bit.INSTREND) {
;
}
QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;
@ -154,7 +162,9 @@ bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t length) {
QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
while( !QSPI->INTFLAG.bit.INSTREND );
while (!QSPI->INTFLAG.bit.INSTREND) {
;
}
QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;
@ -201,7 +211,9 @@ bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t length) {
QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER;
while( !QSPI->INTFLAG.bit.INSTREND );
while (!QSPI->INTFLAG.bit.INSTREND) {
;
}
QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND;

View File

@ -39,7 +39,3 @@
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO34)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO33)
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO36)
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35)
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO37)

View File

@ -18,6 +18,9 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_EPD_RESET), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_EPD_DC), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_EPD_CS), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_EPD_MOSI), MP_ROM_PTR(&pin_GPIO35) },
{ MP_ROM_QSTR(MP_QSTR_EPD_SCK), MP_ROM_PTR(&pin_GPIO36) },
{ MP_ROM_QSTR(MP_QSTR_EPD_MISO), MP_ROM_PTR(&pin_GPIO37) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) },
@ -40,18 +43,12 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO33) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO34) },
{ MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO35) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO37) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)},

View File

@ -24,11 +24,11 @@
* THE SOFTWARE.
*/
#include "shared-bindings/wifi/Network.h"
#include <string.h>
#include "py/obj.h"
#include "py/enum.h"
#include "shared-bindings/wifi/Network.h"
#include "shared-bindings/wifi/AuthMode.h"
mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self) {
const char *cstr = (const char *)self->record.ssid;
@ -56,35 +56,42 @@ mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) {
}
mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) {
const char *authmode = "";
uint8_t authmode_mask = 0;
switch (self->record.authmode) {
case WIFI_AUTH_OPEN:
authmode = "OPEN";
authmode_mask = (1 << AUTHMODE_OPEN);
break;
case WIFI_AUTH_WEP:
authmode = "WEP";
authmode_mask = (1 << AUTHMODE_WEP);
break;
case WIFI_AUTH_WPA_PSK:
authmode = "WPA_PSK";
authmode_mask = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_PSK);
break;
case WIFI_AUTH_WPA2_PSK:
authmode = "WPA2_PSK";
authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK);
break;
case WIFI_AUTH_WPA_WPA2_PSK:
authmode = "WPA_WPA2_PSK";
authmode_mask = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK);
break;
case WIFI_AUTH_WPA2_ENTERPRISE:
authmode = "WPA2_ENTERPRISE";
authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_ENTERPRISE);
break;
case WIFI_AUTH_WPA3_PSK:
authmode = "WPA3_PSK";
authmode_mask = (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK);
break;
case WIFI_AUTH_WPA2_WPA3_PSK:
authmode = "WPA2_WPA3_PSK";
authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK);
break;
default:
authmode = "UNKNOWN";
break;
}
return mp_obj_new_str(authmode, strlen(authmode));
mp_obj_t authmode_list = mp_obj_new_list(0, NULL);
if (authmode_mask != 0) {
for (uint8_t i = 0; i < 8; i++) {
if ((authmode_mask >> i) & 1) {
mp_obj_list_append(authmode_list, cp_enum_find(&wifi_authmode_type, i));
}
}
}
return authmode_list;
}

View File

@ -94,6 +94,11 @@ else
CFLAGS += -flto -flto-partition=none
endif
ifeq ($(NRF_DEBUG_PRINT), 1)
CFLAGS += -DNRF_DEBUG_PRINT=1
SRC_SUPERVISOR += supervisor/debug_uart.c
endif
# option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk
CFLAGS += $(OPTIMIZATION_FLAGS)

View File

@ -7,6 +7,7 @@ MCU_CHIP = nrf52833
INTERNAL_FLASH_FILESYSTEM = 1
CIRCUITPY_ALARM = 0
CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_BITBANGIO = 0
CIRCUITPY_BITMAPTOOLS = 0

View File

@ -10,6 +10,7 @@ MCU_CHIP = nrf52833
INTERNAL_FLASH_FILESYSTEM = 1
CIRCUITPY_ALARM = 0
CIRCUITPY_AESIO = 1
CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_BITMAPTOOLS = 0
@ -24,6 +25,8 @@ CIRCUITPY_MSGPACK = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0
CIRCUITPY_PIXELBUF = 0
CIRCUITPY_PULSEIO = 0
CIRCUITPY_PWMIO = 1
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 1

View File

@ -0,0 +1,118 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <string.h>
#include "py/runtime.h"
#include "common-hal/alarm/__init__.h"
#include "common-hal/alarm/SleepMemory.h"
#include "nrf_power.h"
#ifdef NRF_DEBUG_PRINT
extern void dbg_dump_RAMreg(void);
#include "supervisor/serial.h" // dbg_printf()
#endif
__attribute__((section(".uninitialized"))) static uint8_t _sleepmem[SLEEP_MEMORY_LENGTH];
__attribute__((section(".uninitialized"))) uint8_t sleepmem_wakeup_event;
__attribute__((section(".uninitialized"))) uint8_t sleepmem_wakeup_pin;
__attribute__((section(".uninitialized"))) static uint32_t _sleepmem_magicnum;
#define SLEEP_MEMORY_DATA_GUARD 0xad0000af
#define SLEEP_MEMORY_DATA_GUARD_MASK 0xff0000ff
static int is_sleep_memory_valid(void) {
if ((_sleepmem_magicnum & SLEEP_MEMORY_DATA_GUARD_MASK)
== SLEEP_MEMORY_DATA_GUARD) {
return 1;
}
return 0;
}
void set_memory_retention(void) {
// set RAM[n].POWER register for RAM retention
// nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5]
// nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1]
for (int block = 0; block <= 7; ++block) {
nrf_power_rampower_mask_on(NRF_POWER, block,
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK);
};
#ifdef NRF52840
nrf_power_rampower_mask_on(NRF_POWER, 8,
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK |
NRF_POWER_RAMPOWER_S2RETENTION_MASK |
NRF_POWER_RAMPOWER_S3RETENTION_MASK |
NRF_POWER_RAMPOWER_S4RETENTION_MASK |
NRF_POWER_RAMPOWER_S5RETENTION_MASK);
#endif
#ifdef NRF52833
nrf_power_rampower_mask_on(NRF_POWER, 8,
NRF_POWER_RAMPOWER_S0RETENTION_MASK |
NRF_POWER_RAMPOWER_S1RETENTION_MASK);
#endif
}
static void initialize_sleep_memory(void) {
memset((uint8_t *)_sleepmem, 0, SLEEP_MEMORY_LENGTH);
sleepmem_wakeup_event = 0;
sleepmem_wakeup_pin = 0;
set_memory_retention();
#ifdef NRF_DEBUG_PRINT
// dbg_dump_RAMreg();
#endif
_sleepmem_magicnum = SLEEP_MEMORY_DATA_GUARD;
}
void alarm_sleep_memory_reset(void) {
if (!is_sleep_memory_valid()) {
initialize_sleep_memory();
#ifdef NRF_DEBUG_PRINT
dbg_printf("sleep memory initialized\r\n");
#endif
}
}
uint32_t common_hal_alarm_sleep_memory_get_length(alarm_sleep_memory_obj_t *self) {
return sizeof(_sleepmem);
}
bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t *values, uint32_t len) {
if (start_index + len > sizeof(_sleepmem)) {
return false;
}
memcpy((uint8_t *)(_sleepmem + start_index), values, len);
return true;
}
void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t *values, uint32_t len) {
if (start_index + len > sizeof(_sleepmem)) {
return;
}
memcpy(values, (uint8_t *)(_sleepmem + start_index), len);
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H
#define MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H
#include "py/obj.h"
#define SLEEP_MEMORY_LENGTH (256)
typedef struct {
mp_obj_base_t base;
} alarm_sleep_memory_obj_t;
extern void set_memory_retention(void);
extern void alarm_sleep_memory_reset(void);
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H

View File

@ -0,0 +1,347 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/gc.h"
#include "py/obj.h"
#include "py/objtuple.h"
#include "py/runtime.h"
#include <stdio.h>
#include <string.h>
#include "shared-bindings/alarm/__init__.h"
#include "shared-bindings/alarm/SleepMemory.h"
#include "shared-bindings/alarm/pin/PinAlarm.h"
#include "shared-bindings/alarm/time/TimeAlarm.h"
#include "shared-bindings/alarm/touch/TouchAlarm.h"
#include "shared-bindings/time/__init__.h"
#include "supervisor/port.h"
#include "supervisor/serial.h" // serial_connected()
#ifdef NRF_DEBUG_PRINT
#include "supervisor/serial.h" // dbg_printf()
extern int dbg_check_RTCprescaler(void);
#endif
#include "supervisor/qspi_flash.h"
#include "nrf.h"
#include "nrf_power.h"
#include "nrfx.h"
#include "nrfx_gpiote.h"
// Singleton instance of SleepMemory.
const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
.base = {
.type = &alarm_sleep_memory_type,
},
};
void alarm_reset(void) {
alarm_sleep_memory_reset();
alarm_pin_pinalarm_reset();
alarm_time_timealarm_reset();
alarm_touch_touchalarm_reset();
}
extern uint32_t reset_reason_saved;
STATIC nrf_sleep_source_t _get_wakeup_cause(void) {
if (alarm_pin_pinalarm_woke_us_up()) {
return NRF_SLEEP_WAKEUP_GPIO;
}
if (alarm_time_timealarm_woke_us_up()) {
return NRF_SLEEP_WAKEUP_TIMER;
}
if (alarm_touch_touchalarm_woke_us_up()) {
return NRF_SLEEP_WAKEUP_TOUCHPAD;
}
if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) {
return NRF_SLEEP_WAKEUP_RESETPIN;
} else if (reset_reason_saved & NRF_POWER_RESETREAS_OFF_MASK) {
return NRF_SLEEP_WAKEUP_GPIO;
} else if (reset_reason_saved & NRF_POWER_RESETREAS_VBUS_MASK) {
return NRF_SLEEP_WAKEUP_VBUS;
}
return NRF_SLEEP_WAKEUP_UNDEFINED;
}
#ifdef NRF_DEBUG_PRINT
static const char *cause_str[] = {
"UNDEFINED",
"GPIO",
"TIMER",
"TOUCHPAD",
"VBUS",
"RESETPIN",
};
void print_wakeup_cause(nrf_sleep_source_t cause) {
if (cause >= 0 && cause < NRF_SLEEP_WAKEUP_ZZZ) {
dbg_printf("wakeup cause = NRF_SLEEP_WAKEUP_%s\r\n",
cause_str[(int)cause]);
}
}
#endif
bool common_hal_alarm_woken_from_sleep(void) {
nrf_sleep_source_t cause = _get_wakeup_cause();
#ifdef NRF_DEBUG_PRINT
if (cause != NRF_SLEEP_WAKEUP_UNDEFINED) {
// print_wakeup_cause(cause);
}
#endif
return cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER
|| cause == NRF_SLEEP_WAKEUP_TOUCHPAD;
}
STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) {
nrf_sleep_source_t cause = _get_wakeup_cause();
switch (cause) {
case NRF_SLEEP_WAKEUP_TIMER: {
return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms);
}
case NRF_SLEEP_WAKEUP_TOUCHPAD: {
return alarm_touch_touchalarm_get_wakeup_alarm(n_alarms, alarms);
}
case NRF_SLEEP_WAKEUP_GPIO: {
return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms);
}
default:
break;
}
return mp_const_none;
}
mp_obj_t common_hal_alarm_get_wake_alarm(void) {
mp_obj_t obj = _get_wake_alarm(0, NULL);
return obj;
}
// Set up light sleep or deep sleep alarms.
STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) {
alarm_pin_pinalarm_set_alarms(deep_sleep, n_alarms, alarms);
alarm_time_timealarm_set_alarms(deep_sleep, n_alarms, alarms);
alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms);
}
// TODO: this handles all possible types of wakeup, which is redundant with main.
// revise to extract all parts essential to enabling sleep wakeup, but leave the
// alarm/non-alarm sorting to the existing main loop.
void system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) {
bool have_timeout = false;
uint64_t start_tick = 0, end_tick = 0;
int64_t tickdiff;
#if defined(MICROPY_QSPI_CS)
qspi_flash_enter_sleep();
#endif
if (timediff_ms != -1) {
have_timeout = true;
#if 0
int64_t now = common_hal_time_monotonic_ms();
dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms);
#endif
if (timediff_ms < 0) {
timediff_ms = 0;
}
if (prescaler == 0) {
// 1 tick = 1/1024 sec = 1000/1024 ms
// -> 1 ms = 1024/1000 ticks
tickdiff = (mp_uint_t)(timediff_ms * 1024 / 1000); // ms -> ticks
} else {
// 1 tick = prescaler/1024 sec = prescaler*1000/1024 ms
// -> 1ms = 1024/(1000*prescaler) ticks
tickdiff = (mp_uint_t)(timediff_ms * 1024 / (1000 * prescaler));
}
start_tick = port_get_raw_ticks(NULL);
end_tick = start_tick + tickdiff;
}
#if 0
dbg_printf("start_tick=%ld end_tick=%ld have_timeout=%c\r\n", (long)start_tick, (long)end_tick, have_timeout ? 'T' : 'F');
#endif
int64_t remaining;
sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE;
sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF;
#ifdef NRF_DEBUG_PRINT
int ct = 40;
char reason = '?';
#define WAKEUP_REASON(x) reason = (x)
#else
#define WAKEUP_REASON(x)
#endif
while (1) {
if (mp_hal_is_interrupted()) {
WAKEUP_REASON('I');
break;
}
if (serial_connected() && serial_bytes_available()) {
WAKEUP_REASON('S');
break;
}
RUN_BACKGROUND_TASKS;
if (common_hal_alarm_woken_from_sleep()) {
WAKEUP_REASON('W');
break;
}
if (have_timeout) {
remaining = end_tick - port_get_raw_ticks(NULL);
// We break a bit early so we don't risk setting the alarm before the time when we call
// sleep.
if (remaining < 1) {
WAKEUP_REASON('t');
break;
}
port_interrupt_after_ticks(remaining);
}
// Idle until an interrupt happens.
port_idle_until_interrupt();
#ifdef NRF_DEBUG_PRINT
if (ct > 0) {
dbg_printf("_");
--ct;
}
#endif
if (have_timeout) {
remaining = end_tick - port_get_raw_ticks(NULL);
if (remaining <= 0) {
sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER;
WAKEUP_REASON('T');
break;
}
}
}
#ifdef NRF_DEBUG_PRINT
dbg_printf("%c\r\n", reason);
#endif
#if defined(MICROPY_QSPI_CS)
qspi_flash_exit_sleep();
#endif
#ifdef NRF_DEBUG_PRINT
tickdiff = port_get_raw_ticks(NULL) - start_tick;
double sec;
if (prescaler == 0) {
sec = (double)tickdiff / 1024;
} else {
sec = (double)(tickdiff * prescaler) / 1024;
}
dbg_printf("lapse %6.1f sec\r\n", sec);
#endif
}
mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms) {
mp_obj_t wake_alarm;
alarm_time_timealarm_clear_wakeup_time();
_setup_sleep_alarms(false, n_alarms, alarms);
#ifdef NRF_DEBUG_PRINT
dbg_printf("\r\nlight sleep...");
#endif
int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms();
system_on_idle_until_alarm(timediff_ms, 0);
if (mp_hal_is_interrupted()) {
wake_alarm = mp_const_none;
} else {
wake_alarm = _get_wake_alarm(n_alarms, alarms);
}
alarm_reset();
return wake_alarm;
}
void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms) {
alarm_time_timealarm_clear_wakeup_time();
_setup_sleep_alarms(true, n_alarms, alarms);
}
#define PRESCALER_VALUE_IN_DEEP_SLEEP (1024)
void NORETURN common_hal_alarm_enter_deep_sleep(void) {
alarm_pin_pinalarm_prepare_for_deep_sleep();
alarm_time_timealarm_prepare_for_deep_sleep();
#ifdef NRF_DEBUG_PRINT
dbg_printf("\r\ndeep sleep...");
#endif
int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms();
tick_set_prescaler(PRESCALER_VALUE_IN_DEEP_SLEEP - 1);
#ifdef NRF_DEBUG_PRINT
dbg_check_RTCprescaler(); // XXX
#endif
system_on_idle_until_alarm(timediff_ms, PRESCALER_VALUE_IN_DEEP_SLEEP);
#ifdef NRF_DEBUG_PRINT
dbg_printf("RESET...\r\n\r\n");
#endif
reset_cpu();
// should not reach here..
while (1) {
;
}
}
// old version deep sleep code that was used in common_hal_alarm_enter_deep_sleep()
// for anyone who might want true System OFF sleep ..
#if 0
void OLD_go_system_off(void) {
sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE;
sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF;
uint8_t sd_enabled;
sd_softdevice_is_enabled(&sd_enabled);
set_memory_retention();
dbg_printf("OLD go system off.. %d\r\n", sd_enabled);
if (sd_enabled) {
sd_power_system_off();
} else {
NRF_POWER->SYSTEMOFF = 1;
}
}
#endif
void common_hal_alarm_pretending_deep_sleep(void) {
alarm_pin_pinalarm_prepare_for_deep_sleep();
alarm_time_timealarm_prepare_for_deep_sleep();
#ifdef NRF_DEBUG_PRINT
dbg_printf("\r\npretending to deep sleep...");
#endif
int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms();
system_on_idle_until_alarm(timediff_ms, 0);
alarm_reset();
}
void common_hal_alarm_gc_collect(void) {
gc_collect_ptr(shared_alarm_get_wake_alarm());
}

View File

@ -0,0 +1,56 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Dan Halbert for Adafruit Industries.
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H
#define MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H
#include "common-hal/alarm/SleepMemory.h"
typedef enum {
NRF_SLEEP_WAKEUP_UNDEFINED,
NRF_SLEEP_WAKEUP_GPIO,
NRF_SLEEP_WAKEUP_TIMER,
NRF_SLEEP_WAKEUP_TOUCHPAD,
NRF_SLEEP_WAKEUP_VBUS,
NRF_SLEEP_WAKEUP_RESETPIN,
NRF_SLEEP_WAKEUP_ZZZ
} nrf_sleep_source_t;
extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
enum {
SLEEPMEM_WAKEUP_BY_NONE = 0,
SLEEPMEM_WAKEUP_BY_PIN = 1,
SLEEPMEM_WAKEUP_BY_TIMER = 2,
};
#define WAKEUP_PIN_UNDEF 0xFF
extern uint8_t sleepmem_wakeup_event;
extern uint8_t sleepmem_wakeup_pin;
extern void alarm_reset(void);
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H

View File

@ -0,0 +1,238 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/runtime.h"
#include <stdio.h>
#include <assert.h>
#include "shared-bindings/alarm/pin/PinAlarm.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "common-hal/alarm/__init__.h"
#include "nrfx.h"
#include "nrf_gpio.h"
#include "nrfx_gpiote.h"
#include "nrf_soc.h"
#include <string.h>
#include "supervisor/serial.h" // dbg_print
#define WPIN_UNUSED 0xFF
volatile char _pinhandler_gpiote_count;
static bool pins_configured = false;
extern uint32_t reset_reason_saved;
extern void dbg_dump_GPIOregs(void);
void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull) {
if (edge) {
mp_raise_ValueError(translate("Cannot wake on pin edge. Only level."));
}
if (pin->number >= NUMBER_OF_PINS) {
mp_raise_ValueError(translate("Invalid pin"));
}
self->pin = pin;
self->value = value;
self->pull = pull;
}
mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self) {
return self->pin;
}
bool common_hal_alarm_pin_pinalarm_get_value(alarm_pin_pinalarm_obj_t *self) {
return self->value;
}
bool common_hal_alarm_pin_pinalarm_get_edge(alarm_pin_pinalarm_obj_t *self) {
return false;
}
bool common_hal_alarm_pin_pinalarm_get_pull(alarm_pin_pinalarm_obj_t *self) {
return self->pull;
}
static void pinalarm_gpiote_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
++_pinhandler_gpiote_count;
sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_PIN;
sleepmem_wakeup_pin = pin & 0xFF;
}
bool alarm_pin_pinalarm_woke_us_up(void) {
return sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_PIN &&
sleepmem_wakeup_pin != WAKEUP_PIN_UNDEF;
}
mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) {
// First, check to see if we match any given alarms.
for (size_t i = 0; i < n_alarms; i++) {
if (!mp_obj_is_type(alarms[i], &alarm_pin_pinalarm_type)) {
continue;
}
alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]);
if (alarm->pin->number == sleepmem_wakeup_pin) {
return alarms[i];
}
}
alarm_pin_pinalarm_obj_t *alarm = m_new_obj(alarm_pin_pinalarm_obj_t);
alarm->base.type = &alarm_pin_pinalarm_type;
alarm->pin = NULL;
// Map the pin number back to a pin object.
for (size_t i = 0; i < mcu_pin_globals.map.used; i++) {
const mcu_pin_obj_t *pin_obj = MP_OBJ_TO_PTR(mcu_pin_globals.map.table[i].value);
if ((size_t)pin_obj->number == sleepmem_wakeup_pin) {
alarm->pin = mcu_pin_globals.map.table[i].value;
break;
}
}
return alarm;
}
// These must be static because we need to configure pulls later, right before
// deep sleep.
static uint64_t high_alarms = 0;
static uint64_t low_alarms = 0;
static uint64_t pull_pins = 0;
void alarm_pin_pinalarm_reset(void) {
for (size_t i = 0; i < 64; i++) {
uint64_t mask = 1ull << i;
bool high = (high_alarms & mask) != 0;
bool low = (low_alarms & mask) != 0;
if (!(high || low)) {
continue;
}
reset_pin_number(i);
nrfx_gpiote_in_event_disable((nrfx_gpiote_pin_t)i);
nrfx_gpiote_in_uninit((nrfx_gpiote_pin_t)i);
}
high_alarms = 0;
low_alarms = 0;
pull_pins = 0;
}
static void configure_pins_for_sleep(void) {
nrfx_err_t err;
if (nrfx_gpiote_is_init()) {
nrfx_gpiote_uninit();
}
err = nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY);
assert(err == NRFX_SUCCESS);
(void)err; // to suppress unused warning
_pinhandler_gpiote_count = 0;
nrfx_gpiote_in_config_t cfg = {
.sense = NRF_GPIOTE_POLARITY_TOGGLE,
.pull = NRF_GPIO_PIN_PULLUP,
.is_watcher = false,
.hi_accuracy = true,
.skip_gpio_setup = false
};
for (size_t i = 0; i < 64; ++i) {
uint64_t mask = 1ull << i;
if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) {
continue;
}
if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) {
cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI;
cfg.pull = ((pull_pins & mask) != 0) ?
NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL;
} else
if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) {
cfg.sense = NRF_GPIOTE_POLARITY_HITOLO;
cfg.pull = ((pull_pins & mask) != 0) ?
NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL;
} else {
cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE;
cfg.pull = NRF_GPIO_PIN_NOPULL;
}
err = nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg,
pinalarm_gpiote_handler);
assert(err == NRFX_SUCCESS);
nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true);
if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) {
nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH);
}
if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) {
nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW);
}
}
}
void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) {
// Bitmask of wake up settings.
size_t high_count = 0;
size_t low_count = 0;
int pin_number = -1;
for (size_t i = 0; i < n_alarms; i++) {
if (!mp_obj_is_type(alarms[i], &alarm_pin_pinalarm_type)) {
continue;
}
alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]);
pin_number = alarm->pin->number;
// dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull);
if (alarm->value) {
high_alarms |= 1ull << pin_number;
high_count++;
} else {
low_alarms |= 1ull << pin_number;
low_count++;
}
if (alarm->pull) {
pull_pins |= 1ull << pin_number;
}
}
if (pin_number != -1) {
if (!deep_sleep) {
configure_pins_for_sleep();
} else {
// we don't setup gpio HW here but do them in
// alarm_pin_pinalarm_prepare_for_deep_sleep() below
reset_reason_saved = 0;
pins_configured = false;
}
} else {
// dbg_printf("alarm_pin_pinalarm_set_alarms() no valid pins\r\n");
}
}
void alarm_pin_pinalarm_prepare_for_deep_sleep(void) {
if (!pins_configured) {
configure_pins_for_sleep();
pins_configured = true;
#ifdef NRF_DEBUG_PRINT
// dbg_dump_GPIOregs();
#endif
}
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/obj.h"
#include "py/objtuple.h"
typedef struct {
mp_obj_base_t base;
mcu_pin_obj_t *pin;
bool value;
bool pull;
} alarm_pin_pinalarm_obj_t;
void alarm_pin_pinalarm_reset(void);
void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
void alarm_pin_pinalarm_prepare_for_deep_sleep(void);
mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms);
bool alarm_pin_pinalarm_woke_us_up(void);

View File

@ -0,0 +1,102 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 Dan Halbert for Adafruit Industries
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/runtime.h"
#include <stdio.h>
#include "common-hal/alarm/__init__.h"
#include "shared-bindings/alarm/time/TimeAlarm.h"
#include "shared-bindings/time/__init__.h"
void common_hal_alarm_time_timealarm_construct(alarm_time_timealarm_obj_t *self, mp_float_t monotonic_time) {
self->monotonic_time = monotonic_time;
}
mp_float_t common_hal_alarm_time_timealarm_get_monotonic_time(alarm_time_timealarm_obj_t *self) {
return self->monotonic_time;
}
mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) {
// First, check to see if we match
for (size_t i = 0; i < n_alarms; i++) {
if (mp_obj_is_type(alarms[i], &alarm_time_timealarm_type)) {
return alarms[i];
}
}
alarm_time_timealarm_obj_t *timer = m_new_obj(alarm_time_timealarm_obj_t);
timer->base.type = &alarm_time_timealarm_type;
// TODO: Set monotonic_time based on the RTC state.
timer->monotonic_time = 0.0f;
return timer;
}
bool alarm_time_timealarm_woke_us_up(void) {
return sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_TIMER;
}
int64_t wakeup_time_saved = 0;
int64_t alarm_time_timealarm_get_wakeup_timediff_ms(void) {
if (wakeup_time_saved == 0) {
return -1;
}
return wakeup_time_saved - common_hal_time_monotonic_ms();
}
void alarm_time_timealarm_clear_wakeup_time(void) {
wakeup_time_saved = 0;
}
void alarm_time_timealarm_reset(void) {
port_disable_interrupt_after_ticks_ch(1);
wakeup_time_saved = 0;
}
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) {
bool timealarm_set = false;
alarm_time_timealarm_obj_t *timealarm = MP_OBJ_NULL;
wakeup_time_saved = 0;
for (size_t i = 0; i < n_alarms; i++) {
if (!mp_obj_is_type(alarms[i], &alarm_time_timealarm_type)) {
continue;
}
if (timealarm_set) {
mp_raise_ValueError(translate("Only one alarm.time alarm can be set."));
}
timealarm = MP_OBJ_TO_PTR(alarms[i]);
timealarm_set = true;
}
if (!timealarm_set) {
return;
}
wakeup_time_saved = (int64_t)(timealarm->monotonic_time * 1000.0f);
}
void alarm_time_timealarm_prepare_for_deep_sleep(void) {
}

View File

@ -0,0 +1,50 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/obj.h"
typedef struct {
mp_obj_base_t base;
mp_float_t monotonic_time; // values compatible with time.monotonic_time()
} alarm_time_timealarm_obj_t;
extern volatile int rtc_woke_up_counter;
extern void port_disable_interrupt_after_ticks_ch(uint32_t channel);
extern void port_interrupt_after_ticks_ch(uint32_t channel, uint32_t ticks);
// Find the alarm object that caused us to wake up or create an equivalent one.
mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms);
// Check for the wake up alarm from pretend deep sleep.
bool alarm_time_timealarm_woke_us_up(void);
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
void alarm_time_timealarm_reset(void);
extern void alarm_time_timealarm_prepare_for_deep_sleep(void);
extern int64_t alarm_time_timealarm_get_wakeup_timediff_ms(void);
extern void alarm_time_timealarm_clear_wakeup_time(void);
extern void dbg_dump_RTCreg(void);
extern void tick_set_prescaler(uint32_t prescaler_val);

View File

@ -0,0 +1,53 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 microDev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/runtime.h"
#include "shared-bindings/alarm/touch/TouchAlarm.h"
#include "shared-bindings/microcontroller/__init__.h"
// static volatile bool woke_up = false;
void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) {
mp_raise_NotImplementedError(NULL);
(void)pin;
}
mp_obj_t alarm_touch_touchalarm_get_wakeup_alarm(const size_t n_alarms, const mp_obj_t *alarms) {
return mp_const_none;
}
void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms) {
}
void alarm_touch_touchalarm_prepare_for_deep_sleep(void) {
}
bool alarm_touch_touchalarm_woke_us_up(void) {
return false;
}
void alarm_touch_touchalarm_reset(void) {
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 microDev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
#define MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
#include "py/obj.h"
#include "common-hal/microcontroller/Pin.h"
typedef struct {
mp_obj_base_t base;
const mcu_pin_obj_t *pin;
} alarm_touch_touchalarm_obj_t;
// Find the alarm object that caused us to wake up or create an equivalent one.
mp_obj_t alarm_touch_touchalarm_get_wakeup_alarm(const size_t n_alarms, const mp_obj_t *alarms);
// Check for the wake up alarm from pretend deep sleep.
void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms);
void alarm_touch_touchalarm_prepare_for_deep_sleep(void);
bool alarm_touch_touchalarm_woke_us_up(void);
void alarm_touch_touchalarm_reset(void);
#endif // MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H

View File

@ -127,5 +127,20 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) {
}
mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) {
return RESET_REASON_UNKNOWN;
mcu_reset_reason_t r = RESET_REASON_UNKNOWN;
if (reset_reason_saved == 0) {
r = RESET_REASON_POWER_ON;
} else if (reset_reason_saved & POWER_RESETREAS_RESETPIN_Msk) {
r = RESET_REASON_RESET_PIN;
} else if (reset_reason_saved & POWER_RESETREAS_DOG_Msk) {
r = RESET_REASON_WATCHDOG;
} else if (reset_reason_saved & POWER_RESETREAS_SREQ_Msk) {
r = RESET_REASON_SOFTWARE;
} else if ((reset_reason_saved & POWER_RESETREAS_OFF_Msk) ||
(reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) ||
(reset_reason_saved & POWER_RESETREAS_NFC_Msk) ||
(reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) {
r = RESET_REASON_DEEP_SLEEP_ALARM;
}
return r;
}

View File

@ -36,4 +36,6 @@ typedef struct {
// Stores no state currently.
} mcu_processor_obj_t;
extern uint32_t reset_reason_saved;
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H

View File

@ -46,6 +46,9 @@ CIRCUITPY_FRAMEBUFFERIO ?= 1
CIRCUITPY_COUNTIO ?= 1
CIRCUITPY_WATCHDOG ?= 1
# Sleep and Wakeup
CIRCUITPY_ALARM ?= 1
# nRF52840-specific
ifeq ($(MCU_CHIP),nrf52840)

View File

@ -116,7 +116,7 @@
// GPIO interrupt
#define NRFX_GPIOTE_ENABLED 1
#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1
#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 2
#define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 7
// NVM controller

View File

@ -0,0 +1,241 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 Jun2Sak
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#ifdef NRF_DEBUG_PRINT
#define DEBUG_UART_TXPIN 26
#define DEBUG_UART_RXPIN 15
#include "nrfx.h"
#include "nrf_uart.h"
#include "nrf_gpio.h"
#include "nrf_rtc.h"
#include "nrfx_uarte.h"
#include "nrfx_rtc.h"
#include "supervisor/serial.h" // dbg_printf()
#include "shared-bindings/microcontroller/Processor.h"
#include "common-hal/alarm/__init__.h"
extern const nrfx_rtc_t rtc_instance; // port.c
extern uint32_t reset_reason_saved;
const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1);
static int _dbg_uart_initialized = 0;
#define DBG_PBUF_LEN 80
static char _dbg_pbuf[DBG_PBUF_LEN + 1];
void _debug_uart_uninit(void) {
nrf_gpio_cfg(DEBUG_UART_TXPIN,
NRF_GPIO_PIN_DIR_INPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_NOPULL,
NRF_GPIO_PIN_S0S1,
NRF_GPIO_PIN_NOSENSE);
nrfx_uarte_uninit(&_dbg_uart_inst);
}
void _debug_uart_init(void) {
// if (_dbg_uart_initialized) return;
nrfx_uarte_config_t config = {
.pseltxd = DEBUG_UART_TXPIN,
.pselrxd = DEBUG_UART_RXPIN,
.pselcts = NRF_UARTE_PSEL_DISCONNECTED,
.pselrts = NRF_UARTE_PSEL_DISCONNECTED,
.p_context = NULL,
.baudrate = NRF_UART_BAUDRATE_115200,
.interrupt_priority = 7,
.hal_cfg = {
.hwfc = NRF_UARTE_HWFC_DISABLED,
.parity = NRF_UARTE_PARITY_EXCLUDED
}
};
nrfx_uarte_init(&_dbg_uart_inst, &config, NULL);
// drive config
nrf_gpio_cfg(config.pseltxd,
NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_DISCONNECT,
NRF_GPIO_PIN_PULLUP, // orig=NOPULL
NRF_GPIO_PIN_H0H1, // orig=S0S1
NRF_GPIO_PIN_NOSENSE);
_dbg_uart_initialized = 1;
return;
}
void _debug_print_substr(const char *text, uint32_t length) {
char *data = (char *)text;
int siz;
while (length != 0) {
if (length <= DBG_PBUF_LEN) {
siz = length;
} else {
siz = DBG_PBUF_LEN;
}
memcpy(_dbg_pbuf, data, siz);
_dbg_pbuf[siz] = 0;
nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const *)_dbg_pbuf, siz);
data += siz;
length -= siz;
}
}
void _debug_uart_deinit(void) {
nrfx_uarte_uninit(&_dbg_uart_inst);
}
int dbg_printf(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int ret = vprintf(fmt, ap);
va_end(ap);
return ret;
}
void dbg_dump_RTCreg(void) {
dbg_printf("\r\nRTC2\r\n");
NRF_RTC_Type *r = rtc_instance.p_reg;
dbg_printf("PRESCALER=%08X, ", (int)r->PRESCALER);
dbg_printf("COUNTER=%08X ", (int)r->COUNTER);
dbg_printf("INTENSET=%08X ", (int)r->INTENSET);
dbg_printf("EVTENSET=%08X\r\n", (int)r->EVTENSET);
dbg_printf("EVENTS_COMPARE[0..3]=%X,%X,%X,%X ", (int)r->EVENTS_COMPARE[0], (int)r->EVENTS_COMPARE[1], (int)r->EVENTS_COMPARE[2], (int)r->EVENTS_COMPARE[3]);
dbg_printf("CC[0..3]=%08X,%08X,%08X,%08X\r\n", (int)r->CC[0], (int)r->CC[1], (int)r->CC[2], (int)r->CC[3]);
}
int dbg_check_RTCprescaler(void) {
NRF_RTC_Type *r = rtc_instance.p_reg;
if ((int)r->PRESCALER == 0) {
dbg_printf("****** PRESCALER == 0\r\n");
return -1;
}
return 0;
}
void dbg_dump_RAMreg(void) {
int i;
for (i = 0; i <= 8; ++i) {
dbg_printf(" RAM%d:%08X", i, (int)(NRF_POWER->RAM[i].POWER));
if (i == 4) {
dbg_printf("\r\n");
}
}
dbg_printf("\r\n");
}
void dbg_dump_GPIOregs(void) {
int i, port, col;
NRF_GPIO_Type *gpio[] = { NRF_P0, NRF_P1 };
const char cnf_pull_chr[] = "-D*U"; // pull down, pull up
const char cnf_sense_chr[] = "-?HL"; // sense high, sense low
for (port = 0, col = 0; port <= 1; ++port) {
for (i = 0; i < 32; ++i) {
uint32_t cnf = gpio[port]->PIN_CNF[i];
if (cnf != 0x0002) { // changed from default value
dbg_printf("[%d_%02d]:%c%c%c%d%c ", port, i,
(cnf & 1) ? 'O' : 'I', // output, input
(cnf & 2) ? 'd' : 'c', // disconnected, connected
cnf_pull_chr[(cnf >> 2) & 3],
(int)((cnf >> 8) & 7), // drive config 0-7
cnf_sense_chr[(cnf >> 16) & 3]);
if (++col >= 6) {
dbg_printf("\r\n");
col = 0;
}
}
}
}
if (col > 0) {
dbg_printf("\r\n");
}
dbg_printf("GPIOTE\r\n");
NRF_GPIOTE_Type const *reg = NRF_GPIOTE;
const char config_mode_chr[] = "-E-T"; // event, task
const char config_pol_chr[] = "-HLT"; // low-to-Hi, hi-to-Low, Toggle
const char config_outinit_chr[] = "01"; // initial value is 0 or 1
for (i = 0, col = 0; i < 8; ++i) {
uint32_t conf = reg->CONFIG[i];
if (conf != 0) { // changed from default value
dbg_printf("CONFIG[%d]:%d_%02d,%c%c%c ", i,
(int)((conf >> 13) & 1), (int)((conf >> 8) & 0x1F),
config_mode_chr[conf & 3],
config_pol_chr[(conf >> 16) & 3],
(conf & 3) == 3 ?
config_outinit_chr[(conf >> 20) & 1] : '-');
if (++col >= 4) {
dbg_printf("\r\n");
col = 0;
}
}
}
if (col > 0) {
dbg_printf("\r\n");
}
for (i = 0; i < 8; ++i) {
dbg_printf("EVENTS_IN[%d]:%X ", i, (int)(reg->EVENTS_IN[i]));
if ((i & 3) == 3) {
dbg_printf("\r\n");
}
}
dbg_printf("EVENTS_PORT:%X INTENSET:%08X\r\n",
(int)(reg->EVENTS_PORT), (int)(reg->INTENSET));
}
void dbg_dumpQSPIreg(void) {
uint32_t r;
dbg_printf("QSPI\r\n");
r = NRF_QSPI->IFCONFIG0;
dbg_printf("IFCONFIG0 READ=%ld write=%ld ADDR=%ld DPM=%ld PPSIZE=%ld\r\n",
r & 7, (r >> 3) & 7, (r >> 6) & 1, (r >> 7) & 1, (r >> 12) & 1);
r = NRF_QSPI->IFCONFIG1;
dbg_printf("IFCONFIG1 SCKDELAY=%ld SPIMODE=%ld SCKFREQ=%ld\r\n",
r & 0xFF, (r >> 25) & 1, (r >> 28) & 0xF);
r = NRF_QSPI->STATUS;
dbg_printf("STATUS DPM=%ld READY=%ld SREG=0x%02lX\r\n",
(r >> 2) & 1, (r >> 3) & 1, (r >> 24) & 0xFF);
r = NRF_QSPI->DPMDUR;
dbg_printf("DPMDUR ENTER=%ld EXIT=%ld\r\n", r & 0xFFFF, (r >> 16) & 0xFFFF);
}
void dbg_dump_reset_reason(void) {
int reset_reason = (int)common_hal_mcu_processor_get_reset_reason();
const char *rr_str[] = {
"POWER_ON", "BROWNOUT", "SOFTWARE", "DEEPSLEEPALARM",
"RESET_PIN", "WATCHDOG", "UNKNOWN"
};
dbg_printf("reset_reason=%s\r\n", rr_str[reset_reason]);
}
#else /*!NRF_DEBUG_PRINT*/
int dbg_printf(const char *fmt, ...) {
return 0;
}
#endif /*!NRF_DEBUG_PRINT*/

View File

@ -4,6 +4,7 @@
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2021 Junji Sakai
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -51,6 +52,7 @@
#include "common-hal/rtc/RTC.h"
#include "common-hal/neopixel_write/__init__.h"
#include "common-hal/watchdog/WatchDogTimer.h"
#include "common-hal/alarm/__init__.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/rtc/__init__.h"
@ -73,9 +75,14 @@ static void power_warning_handler(void) {
reset_into_safe_mode(BROWNOUT);
}
#ifdef NRF_DEBUG_PRINT
extern void _debug_uart_init(void);
#endif
uint32_t reset_reason_saved = 0;
const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(2);
const nrfx_rtc_config_t rtc_config = {
nrfx_rtc_config_t rtc_config = {
.prescaler = RTC_FREQ_TO_PRESCALER(0x8000),
.reliable = 0,
.tick_latency = 0,
@ -100,6 +107,12 @@ void rtc_handler(nrfx_rtc_int_type_t int_type) {
supervisor_tick();
} else if (int_type == NRFX_RTC_INT_COMPARE0) {
nrfx_rtc_cc_set(&rtc_instance, 0, 0, false);
} else if (int_type == NRFX_RTC_INT_COMPARE1) {
// used in light sleep
#if CIRCUITPY_ALARM
sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER;
#endif
nrfx_rtc_cc_set(&rtc_instance, 1, 0, false);
}
}
@ -124,6 +137,22 @@ void tick_init(void) {
}
}
void tick_uninit(void) {
nrfx_rtc_counter_clear(&rtc_instance);
nrfx_rtc_disable(&rtc_instance);
nrfx_rtc_uninit(&rtc_instance);
}
void tick_set_prescaler(uint32_t prescaler_val) {
tick_uninit();
// update of prescaler value sometimes fails if we skip this delay..
NRFX_DELAY_US(1000);
uint16_t prescaler_saved = rtc_config.prescaler;
rtc_config.prescaler = prescaler_val;
tick_init();
rtc_config.prescaler = prescaler_saved;
}
safe_mode_t port_init(void) {
nrf_peripherals_clocks_init();
@ -153,11 +182,21 @@ safe_mode_t port_init(void) {
analogin_init();
#endif
reset_reason_saved = NRF_POWER->RESETREAS;
// clear all RESET reason bits
NRF_POWER->RESETREAS = reset_reason_saved;
// clear wakeup event/pin when reset by reset-pin
if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) {
#if CIRCUITPY_ALARM
sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE;
#endif
}
// If the board was reset by the WatchDogTimer, we may
// need to boot into safe mode. Reset the RESETREAS bit
// for the WatchDogTimer so we don't encounter this the
// next time we reboot.
if (NRF_POWER->RESETREAS & POWER_RESETREAS_DOG_Msk) {
if (reset_reason_saved & POWER_RESETREAS_DOG_Msk) {
NRF_POWER->RESETREAS = POWER_RESETREAS_DOG_Msk;
uint32_t usb_reg = NRF_POWER->USBREGSTATUS;
@ -219,6 +258,10 @@ void reset_port(void) {
#endif
reset_all_pins();
#ifdef NRF_DEBUG_PRINT
_debug_uart_init();
#endif
}
void reset_to_bootloader(void) {
@ -295,7 +338,7 @@ void port_disable_tick(void) {
nrfx_rtc_tick_disable(&rtc_instance);
}
void port_interrupt_after_ticks(uint32_t ticks) {
void port_interrupt_after_ticks_ch(uint32_t channel, uint32_t ticks) {
uint32_t current_ticks = nrfx_rtc_counter_get(&rtc_instance);
uint32_t diff = 3;
if (ticks > diff) {
@ -304,7 +347,15 @@ void port_interrupt_after_ticks(uint32_t ticks) {
if (diff > 0xffffff) {
diff = 0xffffff;
}
nrfx_rtc_cc_set(&rtc_instance, 0, current_ticks + diff, true);
nrfx_rtc_cc_set(&rtc_instance, channel, current_ticks + diff, true);
}
void port_disable_interrupt_after_ticks_ch(uint32_t channel) {
nrfx_rtc_cc_disable(&rtc_instance, channel);
}
void port_interrupt_after_ticks(uint32_t ticks) {
port_interrupt_after_ticks_ch(0, ticks);
}
void port_idle_until_interrupt(void) {
@ -355,3 +406,9 @@ void HardFault_Handler(void) {
asm ("nop;");
}
}
#if CIRCUITPY_ALARM
// in case boards/xxx/board.c does not provide board_deinit()
MP_WEAK void board_deinit(void) {
}
#endif

View File

@ -37,6 +37,31 @@
#include "supervisor/shared/external_flash/common_commands.h"
#include "supervisor/shared/external_flash/qspi_flash.h"
#ifdef NRF_DEBUG_PRINT
#include "supervisor/serial.h" // dbg_printf()
#endif
#ifdef QSPI_FLASH_POWERDOWN
// Parameters for external QSPI Flash power-down
// for W25Q128FV,
// tDP (nCS high to Power-down mode) = 3us
// tRES (nCS high to Standby mode) = 3us
// sck_delay = max(tDP, tRES) / 62.5ns = 48 -> 50 (w/ margin)
#define DUR_DPM_ENTER 1 // tDP in (256*62.5ns) units
#define DUR_DPM_EXIT 1 // tRES in (256*62.5ns) units
#define SCK_DELAY 50 // max(tDP, tRES) in (62.5ns) units
// wait necessary just after DPM enter/exit (cut and try)
#define WAIT_AFTER_DPM_ENTER 10 // usec
#define WAIT_AFTER_DPM_EXIT 50 // usec
static int sck_delay_saved = 0;
#endif
#ifdef NRF_DEBUG_PRINT
extern void dbg_dumpQSPIreg(void);
#else
#define dbg_dumpQSPIreg(...)
#endif
// When USB is disconnected, disable QSPI in sleep mode to save energy
void qspi_disable(void) {
@ -188,7 +213,11 @@ void spi_flash_init(void) {
.readoc = NRF_QSPI_READOC_FASTREAD,
.writeoc = NRF_QSPI_WRITEOC_PP,
.addrmode = NRF_QSPI_ADDRMODE_24BIT,
#ifdef QSPI_FLASH_POWERDOWN
.dpmconfig = true
#else
.dpmconfig = false
#endif
},
.phy_if = {
.sck_freq = NRF_QSPI_FREQ_32MDIV16, // Start at a slow 2MHz and speed up once we know what we're talking to.
@ -213,6 +242,13 @@ void spi_flash_init(void) {
// No callback for blocking API
nrfx_qspi_init(&qspi_cfg, NULL, NULL);
#ifdef QSPI_FLASH_POWERDOWN
// If pin-reset while flash is in power-down mode,
// the flash cannot accept any commands. Send CMD_WAKE to release it.
spi_flash_write_command(CMD_WAKE, NULL, 0);
NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT);
#endif
}
void spi_flash_init_device(const external_flash_device *device) {
@ -236,3 +272,61 @@ void spi_flash_init_device(const external_flash_device *device) {
NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_SCKFREQ_Msk;
NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKFREQ_Pos;
}
void qspi_flash_enter_sleep(void) {
#ifdef QSPI_FLASH_POWERDOWN
uint32_t r;
NRF_QSPI->DPMDUR =
((DUR_DPM_ENTER & 0xFFFF) << 16) | (DUR_DPM_EXIT & 0xFFFF);
// set sck_delay tempolarily
r = NRF_QSPI->IFCONFIG1;
sck_delay_saved = (r & QSPI_IFCONFIG1_SCKDELAY_Msk)
>> QSPI_IFCONFIG1_SCKDELAY_Pos;
NRF_QSPI->IFCONFIG1
= (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk)
| (SCK_DELAY << QSPI_IFCONFIG1_SCKDELAY_Pos);
// enabling IFCONFIG0.DPMENABLE here won't work.
// -> do it in spi_flash_init()
// NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_DPMENABLE_Msk;
// dbg_dumpQSPIreg();
// enter deep power-down mode (DPM)
NRF_QSPI->IFCONFIG1 |= QSPI_IFCONFIG1_DPMEN_Msk;
NRFX_DELAY_US(WAIT_AFTER_DPM_ENTER);
if (!(NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk)) {
#ifdef NRF_DEBUG_PRINT
dbg_printf("qspi flash: DPM failed\r\n");
#endif
}
#endif
qspi_disable();
// dbg_dumpQSPIreg();
}
void qspi_flash_exit_sleep(void) {
qspi_enable();
#ifdef QSPI_FLASH_POWERDOWN
if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) {
// exit deep power-down mode
NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_DPMEN_Msk;
NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT);
if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) {
#ifdef NRF_DEBUG_PRINT
dbg_printf("qspi flash: exiting DPM failed\r\n");
#endif
}
// restore sck_delay
if (sck_delay_saved == 0) {
sck_delay_saved = 10; // default
}
NRF_QSPI->IFCONFIG1
= (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk)
| (sck_delay_saved << QSPI_IFCONFIG1_SCKDELAY_Pos);
}
// dbg_dumpQSPIreg();
#endif
}

View File

@ -0,0 +1,2 @@
extern void qspi_flash_enter_sleep(void);
extern void qspi_flash_exit_sleep(void);

View File

@ -23,18 +23,19 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO5) },
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },

View File

@ -1,14 +1,14 @@
#define MICROPY_HW_BOARD_NAME "SparkFun Thing Plus - RP2040"
#define MICROPY_HW_MCU_NAME "rp2040"
#define MICROPY_HW_NEOPIXEL (&pin_GPIO8)
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO7)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO6)
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO14)
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO15)
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO12)
#define DEFAULT_UART_BUS_RX (&pin_GPIO1)
#define DEFAULT_UART_BUS_TX (&pin_GPIO0)
#define DEFAULT_UART_BUS_RX (&pin_GPIO1)
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO2)
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO3)
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO4)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO6)
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO7)
#define MICROPY_HW_NEOPIXEL (&pin_GPIO8)

View File

@ -1,35 +1,61 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) },
{ MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_GPIO24) },
{ MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_GPIO25) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO2) },
// Left side breakouts, top-to-bottom, as labeled
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) },
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO7) }, // GPIO7 & GPIO23 are shorted together
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO7) },
{ MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) },
// Right side breakouts, top-to-bottom, as labeled
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO8) },
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) },
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO3) },
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) },
{ MP_ROM_QSTR(MP_QSTR_D29), MP_ROM_PTR(&pin_GPIO29) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) },
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO28) },
{ MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO28) },
// SD Card
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO14)},
{ MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO15)},
{ MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO12)},
{ MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO9)},
// Others
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, // on-board LED (separate/additional from neopixel)
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },

View File

@ -73,8 +73,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
const mcu_pin_obj_t *data_clock,
const mcu_pin_obj_t *vertical_sync,
const mcu_pin_obj_t *horizontal_reference,
int data_count)
{
int data_count) {
uint16_t imagecapture_code[] = IMAGECAPTURE_CODE(data_count, data_clock->number, vertical_sync->number, horizontal_reference->number);
@ -103,21 +102,18 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
rp2pio_statemachine_set_wrap(&self->state_machine, 2, 5);
}
void common_hal_imagecapture_parallelimagecapture_deinit(imagecapture_parallelimagecapture_obj_t *self)
{
void common_hal_imagecapture_parallelimagecapture_deinit(imagecapture_parallelimagecapture_obj_t *self) {
if (common_hal_imagecapture_parallelimagecapture_deinited(self)) {
return;
}
return common_hal_rp2pio_statemachine_deinit(&self->state_machine);
}
bool common_hal_imagecapture_parallelimagecapture_deinited(imagecapture_parallelimagecapture_obj_t *self)
{
bool common_hal_imagecapture_parallelimagecapture_deinited(imagecapture_parallelimagecapture_obj_t *self) {
return common_hal_rp2pio_statemachine_deinited(&self->state_machine);
}
void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_parallelimagecapture_obj_t *self, void *buffer, size_t bufsize)
{
void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_parallelimagecapture_obj_t *self, void *buffer, size_t bufsize) {
PIO pio = self->state_machine.pio;
uint sm = self->state_machine.state_machine;
uint8_t offset = rp2pio_statemachine_program_offset(&self->state_machine);

View File

@ -142,9 +142,16 @@ void common_hal_pulseio_pulsein_interrupt() {
// ignore pulses that are too short
if (result <= MAX_PULSE && result > MIN_PULSE) {
self->buffer[buf_index] = (uint16_t)result;
buf_index++;
if (self->len < self->maxlen) {
self->len++;
}
if (buf_index < self->maxlen) {
buf_index++;
} else {
self->start = 0;
buf_index = 0;
}
}
}
}

View File

@ -163,10 +163,8 @@ STATIC void move_to_beginning(uint16_t *buffer, uint16_t *buffer_length, uint16_
STATIC void pwmaudioout_event_handler(void) {
// Detect TIM Update event
if (__HAL_TIM_GET_FLAG(&tim_handle, TIM_FLAG_UPDATE) != RESET)
{
if (__HAL_TIM_GET_IT_SOURCE(&tim_handle, TIM_IT_UPDATE) != RESET)
{
if (__HAL_TIM_GET_FLAG(&tim_handle, TIM_FLAG_UPDATE) != RESET) {
if (__HAL_TIM_GET_IT_SOURCE(&tim_handle, TIM_IT_UPDATE) != RESET) {
__HAL_TIM_CLEAR_IT(&tim_handle, TIM_IT_UPDATE);
if (!active_audio || active_audio->paused) {
__HAL_TIM_DISABLE_IT(&tim_handle, TIM_IT_UPDATE);

View File

@ -1 +1 @@
print('frzmpy1')
print("frzmpy1")

View File

@ -1,3 +1,3 @@
# test frozen package with __init__.py
print('frzmpy_pkg1.__init__')
print("frzmpy_pkg1.__init__")
x = 1

View File

@ -1,4 +1,6 @@
# test frozen package without __init__.py
print('frzmpy_pkg2.mod')
print("frzmpy_pkg2.mod")
class Foo:
x = 1

View File

@ -1 +1 @@
print('frzstr1')
print("frzstr1")

View File

@ -1,3 +1,3 @@
# test frozen package with __init__.py
print('frzstr_pkg1.__init__')
print("frzstr_pkg1.__init__")
x = 1

View File

@ -1,4 +1,6 @@
# test frozen package without __init__.py
print('frzstr_pkg2.mod')
print("frzstr_pkg2.mod")
class Foo:
x = 1

View File

@ -451,6 +451,7 @@ $(filter $(SRC_PATTERNS), \
msgpack/__init__.c \
msgpack/ExtType.c \
supervisor/RunReason.c \
wifi/AuthMode.c \
)
SRC_BINDINGS_ENUMS += \

View File

@ -61,7 +61,7 @@ def generate_module_table_header(modules):
# Print header file for all external modules.
mod_defs = []
print("// Automatically generated by makemoduledefs.py.\n")
print("#include \"py/mpconfig.h\"")
print('#include "py/mpconfig.h"')
for module_name, obj_module, enabled_define in modules:
mod_def = "MODULE_DEF_{}".format(module_name.upper())
mod_defs.append(mod_def)

View File

@ -631,6 +631,7 @@ def parse_input_headers(infiles):
return qcfgs, qstrs, i18ns
def escape_bytes(qstr):
if all(32 <= ord(c) <= 126 and c != "\\" and c != '"' for c in qstr):
# qstr is all printable ASCII so render it as-is (for easier debugging)
@ -640,6 +641,7 @@ def escape_bytes(qstr):
qbytes = bytes_cons(qstr, "utf8")
return "".join(("\\x%02x" % b) for b in qbytes)
def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr):
qbytes = bytes_cons(qstr, "utf8")
qlen = len(qbytes)
@ -715,7 +717,6 @@ def print_qstr_enums(qstrs):
print("QENUM(MP_QSTR_%s)" % (ident,))
if __name__ == "__main__":
import argparse

View File

@ -65,7 +65,6 @@ def get_version_info_from_git():
return git_tag, git_hash, ver
def get_version_info_from_docs_conf():
with open(os.path.join(os.path.dirname(sys.argv[0]), "..", "conf.py")) as f:
for line in f:

View File

@ -854,7 +854,8 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
}
mp_obj_class_lookup(&lookup, self->base.type);
if (member[0] == MP_OBJ_SENTINEL) {
mp_obj_t ret = mp_obj_subscr(self->subobj[0], index, value);
mp_obj_type_t *subobj_type = mp_obj_get_type(self->subobj[0]);
mp_obj_t ret = subobj_type->subscr(self_in, index, value);
// May have called port specific C code. Make sure it didn't mess up the heap.
assert_heap_ok();
return ret;

12
py/vm.c
View File

@ -127,11 +127,21 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t * code_st
#endif
#if MICROPY_OPT_COMPUTED_GOTO
#include "py/vmentrytable.h"
#if MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE
#define ONE_TRUE_DISPATCH() one_true_dispatch : do { \
TRACE(ip); \
MARK_EXC_IP_GLOBAL(); \
goto *(void *)((char *) && entry_MP_BC_LOAD_CONST_FALSE + entry_table[*ip++]); \
} while (0)
#define DISPATCH() do { goto one_true_dispatch; } while (0)
#else
#define ONE_TRUE_DISPATCH() DISPATCH()
#define DISPATCH() do { \
TRACE(ip); \
MARK_EXC_IP_GLOBAL(); \
goto *entry_table[*ip++]; \
} while (0)
#endif
#define DISPATCH_WITH_PEND_EXC_CHECK() goto pending_exception_check
#define ENTRY(op) entry_##op
#define ENTRY_DEFAULT entry_default
@ -197,7 +207,7 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t * code_st
for (;;) {
dispatch_loop:
#if MICROPY_OPT_COMPUTED_GOTO
DISPATCH();
ONE_TRUE_DISPATCH();
#else
TRACE(ip);
MARK_EXC_IP_GLOBAL();

View File

@ -244,6 +244,7 @@ const mp_obj_module_t alarm_module = {
};
extern void port_idle_until_interrupt(void);
MP_WEAK void common_hal_alarm_pretending_deep_sleep(void) {
port_idle_until_interrupt();
}

View File

@ -49,7 +49,7 @@
//| but the `displayio.Bitmap.dirty` method must be used to inform
//| displayio when a bitmap was modified through the buffer interface.
//|
//| `bitmaptools.arrayblit` can also be useful to omve data efficiently
//| `bitmaptools.arrayblit` can also be useful to move data efficiently
//| into a Bitmap.
//| """
//|

View File

@ -0,0 +1,76 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 microDev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "py/enum.h"
#include "shared-bindings/wifi/AuthMode.h"
MAKE_ENUM_VALUE(wifi_authmode_type, authmode, OPEN, AUTHMODE_OPEN);
MAKE_ENUM_VALUE(wifi_authmode_type, authmode, WEP, AUTHMODE_WEP);
MAKE_ENUM_VALUE(wifi_authmode_type, authmode, WPA, AUTHMODE_WPA);
MAKE_ENUM_VALUE(wifi_authmode_type, authmode, WPA2, AUTHMODE_WPA2);
MAKE_ENUM_VALUE(wifi_authmode_type, authmode, WPA3, AUTHMODE_WPA3);
MAKE_ENUM_VALUE(wifi_authmode_type, authmode, PSK, AUTHMODE_PSK);
MAKE_ENUM_VALUE(wifi_authmode_type, authmode, ENTERPRISE, AUTHMODE_ENTERPRISE);
//| class AuthMode:
//| """The authentication protocols used by WiFi."""
//|
//| OPEN: object
//| """Open network. No authentication required."""
//|
//| WEP: object
//| """Wired Equivalent Privacy."""
//|
//| WPA: object
//| """Wireless Protected Access."""
//|
//| WPA2: object
//| """Wireless Protected Access 2."""
//|
//| WPA3: object
//| """Wireless Protected Access 3."""
//|
//| PSK: object
//| """Pre-shared Key. (password)"""
//|
//| ENTERPRISE: object
//| """Each user has a unique credential."""
//|
MAKE_ENUM_MAP(wifi_authmode) {
MAKE_ENUM_MAP_ENTRY(authmode, OPEN),
MAKE_ENUM_MAP_ENTRY(authmode, WEP),
MAKE_ENUM_MAP_ENTRY(authmode, WPA),
MAKE_ENUM_MAP_ENTRY(authmode, WPA2),
MAKE_ENUM_MAP_ENTRY(authmode, WPA3),
MAKE_ENUM_MAP_ENTRY(authmode, PSK),
MAKE_ENUM_MAP_ENTRY(authmode, ENTERPRISE),
};
STATIC MP_DEFINE_CONST_DICT(wifi_authmode_locals_dict, wifi_authmode_locals_table);
MAKE_PRINTER(wifi, wifi_authmode);
MAKE_ENUM_TYPE(wifi, AuthMode, wifi_authmode);

View File

@ -0,0 +1,42 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2021 microDev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H
typedef enum {
AUTHMODE_OPEN,
AUTHMODE_WEP,
AUTHMODE_WPA,
AUTHMODE_WPA2,
AUTHMODE_WPA3,
AUTHMODE_PSK,
AUTHMODE_ENTERPRISE
} wifi_authmode_t;
extern const mp_obj_type_t wifi_authmode_type;
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H

View File

@ -29,6 +29,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "py/mpconfig.h"
@ -47,4 +48,7 @@ char serial_read(void);
bool serial_bytes_available(void);
bool serial_connected(void);
// XXX used in nrf52-sleep debug
int dbg_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H

View File

@ -37,6 +37,12 @@
#include "tusb.h"
#ifdef NRF_DEBUG_PRINT
// XXX these functions are in nrf/supervisor/debug_uart.c
extern void _debug_uart_init(void);
extern void _debug_print_substr(const char *text, uint32_t length);
#endif
/*
* Note: DEBUG_UART currently only works on STM32,
* enabling on another platform will cause a crash.
@ -64,10 +70,17 @@ void serial_early_init(void) {
buf_array, true);
common_hal_busio_uart_never_reset(&debug_uart);
#endif
#ifdef NRF_DEBUG_PRINT
_debug_uart_init();
#endif
}
void serial_init(void) {
usb_init();
#ifdef NRF_DEBUG_PRINT
_debug_uart_init();
#endif
}
bool serial_connected(void) {
@ -146,8 +159,14 @@ void serial_write_substring(const char *text, uint32_t length) {
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
int uart_errcode;
common_hal_busio_uart_write(&debug_uart, (const uint8_t *)text, length, &uart_errcode);
#endif
#ifdef NRF_DEBUG_PRINT
_debug_print_substr(text, length);
#endif
}
void serial_write(const char *text) {

View File

@ -27,4 +27,3 @@
#pragma once
extern bool supervisor_workflow_connecting(void);
extern bool supervisor_workflow_active(void);

View File

@ -53,3 +53,7 @@ void serial_write(const char *text) {
void supervisor_workflow_reset(void) {
}
bool supervisor_workflow_active(void) {
return false;
}

View File

@ -29,4 +29,4 @@
void supervisor_workflow_reset(void);
// True when the user could be actively iterating on their code.
bool workflow_active(void);
bool supervisor_workflow_active(void);

View File

@ -65,7 +65,8 @@ extension_by_board = {
"meowbit_v121": UF2,
}
language_allow_list = set([
language_allow_list = set(
[
"ID",
"de_DE",
"en_GB",
@ -81,7 +82,8 @@ language_allow_list = set([
"pt_BR",
"sv",
"zh_Latn_pinyin",
])
]
)
def get_languages(list_all=False):

View File

@ -90,9 +90,11 @@ for board in build_boards:
for alias in board_info["aliases"] + [board]:
bin_directory = "../bin/{alias}/{language}".format(alias=alias, language=language)
os.makedirs(bin_directory, exist_ok=True)
final_filename = "adafruit-circuitpython-{alias}-{language}-{version}.{extension}".format(
final_filename = (
"adafruit-circuitpython-{alias}-{language}-{version}.{extension}".format(
alias=alias, language=language, version=version, extension=extension
)
)
final_filename = os.path.join(bin_directory, final_filename)
try:
shutil.copyfile(temp_filename, final_filename)

View File

@ -32,6 +32,7 @@ import itertools
import os
import pathlib
import re
import sys
import subprocess
# Relative to top-level repo dir.
@ -68,6 +69,45 @@ EXCLUSIONS = [
"tests/basics/*.py",
]
# None of the standard Python path matching routines implement the matching
# we want, which is most like git's "pathspec" version of globs.
# In particular, we want "**/" to match all directories.
# This routine is sufficient to work with the patterns we have, but
# subtle cases like character classes that contain meta-characters
# are not covered
def git_glob_to_regex(pat):
def transform(m):
m = m.group(0)
if m == "*":
return "[^/]*"
if m == "**/":
return "(.*/)?"
if m == "?":
return "[^/]"
if m == ".":
return r"\."
return m
result = [transform(part) for part in re.finditer(r"(\*\*/|[*?.]|[^*?.]+)", pat)]
return "(^" + "".join(result) + "$)"
# Create a single, complicated regular expression that matches exactly the
# files we want, accounting for the PATHS as well as the EXCLUSIONS.
path_re = (
""
# First a negative lookahead assertion that it doesn't match
# any of the EXCLUSIONS
+ "(?!"
+ "|".join(git_glob_to_regex(pat) for pat in EXCLUSIONS)
+ ")"
# Then a positive match for any of the PATHS
+ "(?:"
+ "|".join(git_glob_to_regex(pat) for pat in PATHS)
+ ")"
)
path_rx = re.compile(path_re)
# Path to repo top-level dir.
TOP = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
@ -76,15 +116,15 @@ UNCRUSTIFY_CFG = os.path.join(TOP, "tools/uncrustify.cfg")
C_EXTS = (".c", ".h")
PY_EXTS = (".py",)
# Transform a filename argument relative to the current directory into one
# relative to the TOP directory, which is what we need when checking against
# path_rx.
def relative_filename(arg):
return str(pathlib.Path(arg).resolve().relative_to(TOP))
def list_files(args, paths, exclusions=None, prefix=""):
files = set()
args = [os.path.join(prefix, arg) for arg in args]
for pattern in paths:
files.update(arg for arg in args if pathlib.Path(arg).match(pattern))
for pattern in exclusions or []:
files.difference_update(fnmatch.filter(files, os.path.join(prefix, pattern)))
return sorted(files)
def list_files(args):
return sorted(arg for arg in args if path_rx.match(relative_filename(arg)))
def fixup_c(filename):
@ -135,19 +175,25 @@ def fixup_c(filename):
def main():
cmd_parser = argparse.ArgumentParser(description="Auto-format C and Python files -- to be used via pre-commit only.")
cmd_parser = argparse.ArgumentParser(
description="Auto-format C and Python files -- to be used via pre-commit only."
)
cmd_parser.add_argument("-c", action="store_true", help="Format C code only")
cmd_parser.add_argument("-p", action="store_true", help="Format Python code only")
cmd_parser.add_argument("-v", action="store_true", help="Enable verbose output")
cmd_parser.add_argument("--dry-run", action="store_true", help="Print, don't act")
cmd_parser.add_argument("files", nargs="+", help="Run on specific globs")
args = cmd_parser.parse_args()
if args.dry_run:
print(" ".join(sys.argv))
# Setting only one of -c or -p disables the other. If both or neither are set, then do both.
format_c = args.c or not args.p
format_py = args.p or not args.c
# Expand the arguments passed on the command line, subject to the PATHS and EXCLUSIONS
files = list_files(args.files, PATHS, EXCLUSIONS, TOP)
files = list_files(args.files)
# Extract files matching a specific language.
def lang_files(exts):
@ -161,6 +207,9 @@ def main():
file_args = list(itertools.islice(files, N))
if not file_args:
break
if args.dry_run:
print(" ".join(cmd + file_args))
else:
subprocess.call(cmd + file_args)
# Format C files with uncrustify.

View File

@ -619,7 +619,6 @@ configuration = standard.ConfigurationDescriptor(
# bit 7 is always 1 and 0-4 are always 0
# Turn off remote wakeup until we handle it in CircuitPython.
bmAttributes=0x80,
)
descriptor_list.insert(0, configuration)

View File

@ -805,7 +805,6 @@ def read_raw_code(f, qstr_win):
)
def read_mpy(filename):
with open(filename, "rb") as f:
header = bytes_cons(f.read(4))
@ -823,7 +822,6 @@ def read_mpy(filename):
return read_raw_code(f, qstr_win)
def dump_mpy(raw_codes):
for rc in raw_codes:
rc.dump()
@ -896,10 +894,10 @@ def freeze_mpy(base_qstrs, raw_codes):
qstr_size = {"metadata": 0, "data": 0}
for _, _, qstr in new:
qbytes = qstrutil.bytes_cons(qstr, "utf8")
print(" {%d, %d}," % (
qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH),
len(qbytes)
))
print(
" {%d, %d},"
% (qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH), len(qbytes))
)
qstr_size["metadata"] += (
config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH
)
@ -919,7 +917,7 @@ def freeze_mpy(base_qstrs, raw_codes):
print(" (qstr_attr_t *)mp_qstr_frozen_const_attr,")
print(" {")
for _, _, qstr in new:
print(" \"%s\"," % qstrutil.escape_bytes(qstr))
print(' "%s",' % qstrutil.escape_bytes(qstr))
print(" },")
print("};")