Merge branch 'adafruit:main' into rp2040-shim

This commit is contained in:
Patrick Van Oosterwijck 2022-06-22 11:40:02 -05:00 committed by GitHub
commit 0b80c62400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
584 changed files with 13475 additions and 13122 deletions

View File

@ -382,7 +382,8 @@ jobs:
if: ${{ needs.test.outputs.boards-espressif != '[]' }} if: ${{ needs.test.outputs.boards-espressif != '[]' }}
steps: steps:
- name: Set up Python 3 - name: Set up Python 3
uses: actions/setup-python@v2 id: py3
uses: actions/setup-python@v4
with: with:
python-version: "3.x" python-version: "3.x"
- uses: actions/checkout@v2.2.0 - uses: actions/checkout@v2.2.0
@ -400,7 +401,7 @@ jobs:
id: idf-cache id: idf-cache
with: with:
path: ${{ github.workspace }}/.idf_tools path: ${{ github.workspace }}/.idf_tools
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/espressif/esp-idf/HEAD') }}-20220404 key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/espressif/esp-idf/HEAD') }}-${{ steps.py3.outputs.python-path }}-20220404
- name: Clone IDF submodules - name: Clone IDF submodules
run: | run: |
(cd $IDF_PATH && git submodule update --init) (cd $IDF_PATH && git submodule update --init)

6
.gitmodules vendored
View File

@ -286,3 +286,9 @@
[submodule "frozen/Adafruit_CircuitPython_FakeRequests"] [submodule "frozen/Adafruit_CircuitPython_FakeRequests"]
path = frozen/Adafruit_CircuitPython_FakeRequests path = frozen/Adafruit_CircuitPython_FakeRequests
url = https://github.com/adafruit/Adafruit_CircuitPython_FakeRequests.git url = https://github.com/adafruit/Adafruit_CircuitPython_FakeRequests.git
[submodule "frozen/pew-pewpew-lcd"]
path = frozen/pew-pewpew-lcd
url = https://github.com/pypewpew/pew-pewpew-lcd.git
[submodule "frozen/mixgo_cp_lib"]
path = frozen/mixgo_cp_lib
url = https://github.com/dahanzimin/circuitpython_lib.git

View File

@ -9,16 +9,15 @@
version: 2 version: 2
build: build:
os: ubuntu-20.04 os: ubuntu-20.04
tools: tools:
python: "3" python: "3"
jobs:
submodules: post_install:
include: - python tools/ci_fetch_deps.py docs HEAD
- extmod/ulab
formats: formats:
- pdf - pdf
python: python:
install: install:

View File

@ -61,6 +61,7 @@ TRANSLATE_SOURCES_EXC = -path "ports/*/build-*" \
help: help:
@echo "Please use \`make <target>' where <target> is one of" @echo "Please use \`make <target>' where <target> is one of"
@echo " fetch-submodules to fetch dependencies from submodules, run this right after you clone the repo"
@echo " html to make standalone HTML files" @echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories" @echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file" @echo " singlehtml to make a single large HTML file"

View File

@ -120,7 +120,7 @@ Behavior
make each file independent from each other. make each file independent from each other.
- ``boot.py`` runs only once on start up before - ``boot.py`` runs only once on start up before
USB is initialized. This lays the ground work for configuring USB at workflows are initialized. This lays the ground work for configuring USB at
startup rather than it being fixed. Since serial is not available, startup rather than it being fixed. Since serial is not available,
output is written to ``boot_out.txt``. output is written to ``boot_out.txt``.
- ``code.py`` (or ``main.py``) is run after every reload until it - ``code.py`` (or ``main.py``) is run after every reload until it
@ -135,7 +135,10 @@ Behavior
possible to fix code that causes nasty crashes by making it available through mass storage after possible to fix code that causes nasty crashes by making it available through mass storage after
the crash. A reset (the button) is needed after it's fixed to get back into normal mode. the crash. A reset (the button) is needed after it's fixed to get back into normal mode.
- RGB status LED indicating CircuitPython state. - RGB status LED indicating CircuitPython state.
- Re-runs ``code.py`` or other main file after file system writes over USB mass storage. (Disable with - One green flash - code completed without error.
- Two red flashes - code ended due to an exception.
- Three yellow flashes - safe mode. May be due to CircuitPython internal error.
- Re-runs ``code.py`` or other main file after file system writes by a workflow. (Disable with
``supervisor.disable_autoreload()``) ``supervisor.disable_autoreload()``)
- Autoreload is disabled while the REPL is active. - Autoreload is disabled while the REPL is active.
- Main is one of these: ``code.txt``, ``code.py``, ``main.py``, - Main is one of these: ``code.txt``, ``code.py``, ``main.py``,

27
conf.py
View File

@ -33,6 +33,25 @@ from sphinx import addnodes
tools_describe = str(pathlib.Path(__file__).parent / "tools/describe") tools_describe = str(pathlib.Path(__file__).parent / "tools/describe")
# Monkeypatch autoapi
def _format_args(args_info, include_annotations=True, ignore_self=None):
result = []
for i, (prefix, name, annotation, default) in enumerate(args_info):
if i == 0 and ignore_self is not None and name == ignore_self:
continue
formatted = "{}{}{}{}".format(
prefix or "",
name or "",
": {}".format(annotation) if annotation and include_annotations else "",
(" = {}" if annotation else "={}").format(default) if default else "",
)
result.append(formatted)
return ", ".join(result)
import autoapi.mappers.python.objects as objects
objects._format_args = _format_args
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here. # documentation root, use os.path.abspath to make it absolute, like shown here.
@ -53,9 +72,13 @@ subprocess.check_output(["make", "stubs"])
modules_support_matrix = shared_bindings_matrix.support_matrix_by_board() modules_support_matrix = shared_bindings_matrix.support_matrix_by_board()
modules_support_matrix_reverse = defaultdict(list) modules_support_matrix_reverse = defaultdict(list)
for board, modules in modules_support_matrix.items(): for board, modules in modules_support_matrix.items():
for module in modules: for module in modules[0]:
modules_support_matrix_reverse[module].append(board) modules_support_matrix_reverse[module].append(board)
modules_support_matrix_reverse = dict((module, sorted(boards)) for module, boards in modules_support_matrix_reverse.items())
modules_support_matrix_reverse = dict(
(module, sorted(boards))
for module, boards in modules_support_matrix_reverse.items()
)
html_context = { html_context = {
'support_matrix': modules_support_matrix, 'support_matrix': modules_support_matrix,

View File

@ -57,9 +57,9 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
self->value = mp_obj_new_bytes(initial_value_bufinfo->buf, initial_value_bufinfo->len); self->value = mp_obj_new_bytes(initial_value_bufinfo->buf, initial_value_bufinfo->len);
const mp_int_t max_length_max = 512; const mp_int_t max_length_max = 512;
if (max_length < 0 || max_length > max_length_max) {
mp_raise_ValueError(translate("max_length must be <= 512")); mp_arg_validate_int_range(max_length, 0, max_length_max, MP_QSTR_max_length);
}
self->max_length = max_length; self->max_length = max_length;
self->fixed_length = fixed_length; self->fixed_length = fixed_length;

View File

@ -57,6 +57,11 @@ bool vm_used_ble;
// } // }
// } // }
void bleio_user_reset() {
// HCI doesn't support the BLE workflow so just do a full reset.
bleio_reset();
}
// Turn off BLE on a reset or reload. // Turn off BLE on a reset or reload.
void bleio_reset() { void bleio_reset() {
// Create a UUID object for all CCCD's. // Create a UUID object for all CCCD's.

View File

@ -44,6 +44,7 @@
#include "shared-bindings/_bleio/Service.h" #include "shared-bindings/_bleio/Service.h"
#include "shared-bindings/_bleio/UUID.h" #include "shared-bindings/_bleio/UUID.h"
#include "supervisor/shared/tick.h" #include "supervisor/shared/tick.h"
#include "supervisor/shared/translate/translate.h"
STATIC uint16_t max_mtu = BT_ATT_DEFAULT_LE_MTU; // 23 STATIC uint16_t max_mtu = BT_ATT_DEFAULT_LE_MTU; // 23
STATIC unsigned long timeout = 5000; STATIC unsigned long timeout = 5000;

40
docs/environment.rst Normal file
View File

@ -0,0 +1,40 @@
Environment Variables
=====================
CircuitPython 8.0.0 introduces support for environment variables. Environment
variables are commonly used to store "secrets" such as Wi-Fi passwords and API
keys. This method *does not* make them secure. It only separates them from the
code.
CircuitPython supports these by mimicking the `dotenv <https://github.com/theskumar/python-dotenv>`_
CPython library. Other languages such as Javascript, PHP and Ruby also have
dotenv libraries.
These libraries store environment variables in a ``.env`` file. Here is a simple
example:
.. code-block:: bash
KEY1='value1'
# Comment
KEY2='value2
is multiple lines'
CircuitPython uses the ``.env`` at the drive root (no folder) as the environment.
User code can access the values from the file using `os.getenv()`. It is
recommended to save any values used repeatedly in a variable because `os.getenv()`
will parse the ``/.env`` on every access.
CircuitPython behavior
----------------------
CircuitPython will also read the environment to configure its behavior. Other
keys are ignored by CircuitPython. Here are the keys it uses:
CIRCUITPY_WIFI_PASSWORD
~~~~~~~~~~~~~~~~~~~~~~~
Wi-Fi password used to auto connect to CIRCUITPY_WIFI_SSID
CIRCUITPY_WIFI_SSID
~~~~~~~~~~~~~~~~~~~
Wi-Fi SSID to auto-connect to even if user code is not running.

View File

@ -22,6 +22,7 @@ Full Table of Contents
supported_ports.rst supported_ports.rst
troubleshooting.rst troubleshooting.rst
drivers.rst drivers.rst
environment.rst
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1

View File

@ -4,11 +4,18 @@
All builtin functions and exceptions are described here. They are also All builtin functions and exceptions are described here. They are also
available via ``builtins`` module. available via ``builtins`` module.
For more information about built-ins, see the following CPython documentation:
* `Builtin CPython Functions <https://docs.python.org/3/library/functions.html>`_
* `Builtin CPython Exceptions <https://docs.python.org/3/library/exceptions.html>`_
* `Builtin CPython Constants <https://docs.python.org/3/library/constants.html>`_
.. note:: Not all of these functions, types, exceptions, and constants are turned
on in all CircuitPython ports, for space reasons.
Functions and types Functions and types
------------------- -------------------
Not all of these functions and types are turned on in all CircuitPython ports, for space reasons.
.. function:: abs() .. function:: abs()
.. function:: all() .. function:: all()
@ -160,46 +167,77 @@ Not all of these functions and types are turned on in all CircuitPython ports, f
Exceptions Exceptions
---------- ----------
.. exception:: ArithmeticError
.. exception:: AssertionError .. exception:: AssertionError
.. exception:: AttributeError .. exception:: AttributeError
.. exception:: BaseException
.. exception:: BrokenPipeError
.. exception:: ConnectionError
.. exception:: EOFError
.. exception:: Exception .. exception:: Exception
.. exception:: ImportError .. exception:: ImportError
.. exception:: IndentationError
.. exception:: IndexError .. exception:: IndexError
.. exception:: KeyboardInterrupt .. exception:: KeyboardInterrupt
.. exception:: KeyError .. exception:: KeyError
.. exception:: LookupError
.. exception:: MemoryError .. exception:: MemoryError
.. exception:: MpyError
Not a part of the CPython standard library
.. exception:: NameError .. exception:: NameError
.. exception:: NotImplementedError .. exception:: NotImplementedError
.. exception:: OSError .. exception:: OSError
.. exception:: OverflowError
.. exception:: RuntimeError .. exception:: RuntimeError
.. exception:: ReloadException .. exception:: ReloadException
`ReloadException` is used internally to deal with soft restarts. `ReloadException` is used internally to deal with soft restarts.
Not a part of the CPython standard library
.. exception:: StopAsyncIteration
.. exception:: StopIteration .. exception:: StopIteration
.. exception:: SyntaxError .. exception:: SyntaxError
.. exception:: SystemExit .. exception:: SystemExit
|see_cpython| :py:class:`cpython:SystemExit`. .. exception:: TimeoutError
.. exception:: TypeError .. exception:: TypeError
|see_cpython| :py:class:`cpython:TypeError`. .. exception:: UnicodeError
.. exception:: ValueError .. exception:: ValueError
.. exception:: ZeroDivisionError .. exception:: ZeroDivisionError
Constants
---------
.. data:: Ellipsis
.. data:: NotImplemented

View File

@ -79,8 +79,6 @@ as a natural "TODO" list. An example minimal build list is shown below:
# any port once their prerequisites in common-hal are complete. # any port once their prerequisites in common-hal are complete.
# Requires DigitalIO: # Requires DigitalIO:
CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITBANGIO = 0
# Requires DigitalIO
CIRCUITPY_GAMEPADSHIFT = 0
# Requires neopixel_write or SPI (dotstar) # Requires neopixel_write or SPI (dotstar)
CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PIXELBUF = 0
# Requires OS # Requires OS

View File

@ -45,12 +45,10 @@ shared-bindings/audiomp3/__init__.rst shared-bindings/audiomp3/
shared-bindings/audiopwmio/PWMAudioOut.rst shared-bindings/audiopwmio/#audiopwmio.PWMAudioOut shared-bindings/audiopwmio/PWMAudioOut.rst shared-bindings/audiopwmio/#audiopwmio.PWMAudioOut
shared-bindings/audiopwmio/__init__.rst shared-bindings/audiopwmio/ shared-bindings/audiopwmio/__init__.rst shared-bindings/audiopwmio/
shared-bindings/bitbangio/I2C.rst shared-bindings/bitbangio/#bitbangio.I2C shared-bindings/bitbangio/I2C.rst shared-bindings/bitbangio/#bitbangio.I2C
shared-bindings/bitbangio/OneWire.rst shared-bindings/bitbangio/#bitbangio.OneWire
shared-bindings/bitbangio/SPI.rst shared-bindings/bitbangio/#bitbangio.SPI shared-bindings/bitbangio/SPI.rst shared-bindings/bitbangio/#bitbangio.SPI
shared-bindings/bitbangio/__init__.rst shared-bindings/bitbangio/ shared-bindings/bitbangio/__init__.rst shared-bindings/bitbangio/
shared-bindings/board/__init__.rst shared-bindings/board/ shared-bindings/board/__init__.rst shared-bindings/board/
shared-bindings/busio/I2C.rst shared-bindings/busio/#busio.I2C shared-bindings/busio/I2C.rst shared-bindings/busio/#busio.I2C
shared-bindings/busio/OneWire.rst shared-bindings/busio/#busio.OneWire
shared-bindings/busio/Parity.rst shared-bindings/busio/#busio.Parity shared-bindings/busio/Parity.rst shared-bindings/busio/#busio.Parity
shared-bindings/busio/SPI.rst shared-bindings/busio/#busio.SPI shared-bindings/busio/SPI.rst shared-bindings/busio/#busio.SPI
shared-bindings/busio/UART.rst shared-bindings/busio/#busio.UART shared-bindings/busio/UART.rst shared-bindings/busio/#busio.UART
@ -82,10 +80,6 @@ shared-bindings/framebufferio/FramebufferDisplay.rst shared-bindings/framebuffer
shared-bindings/framebufferio/__init__.rst shared-bindings/framebufferio/ shared-bindings/framebufferio/__init__.rst shared-bindings/framebufferio/
shared-bindings/frequencyio/FrequencyIn.rst shared-bindings/frequencyio/#frequencyio.FrequencyIn shared-bindings/frequencyio/FrequencyIn.rst shared-bindings/frequencyio/#frequencyio.FrequencyIn
shared-bindings/frequencyio/__init__.rst shared-bindings/frequencyio/ shared-bindings/frequencyio/__init__.rst shared-bindings/frequencyio/
shared-bindings/gamepad/GamePad.rst shared-bindings/gamepad/#gamepad.GamePad
shared-bindings/gamepad/__init__.rst shared-bindings/gamepad/
shared-bindings/gamepadshift/GamePadShift.rst shared-bindings/gamepadshift/#gamepadshift.GamePadShift
shared-bindings/gamepadshift/__init__.rst shared-bindings/gamepadshift/
shared-bindings/gnss/__init__.rst shared-bindings/gnss/ shared-bindings/gnss/__init__.rst shared-bindings/gnss/
shared-bindings/i2cperipheral/__init__.rst shared-bindings/i2cperipheral/ shared-bindings/i2cperipheral/__init__.rst shared-bindings/i2cperipheral/
shared-bindings/i2csecondary/__init__.rst shared-bindings/i2csecondary/ shared-bindings/i2csecondary/__init__.rst shared-bindings/i2csecondary/
@ -101,6 +95,7 @@ shared-bindings/neopixel_write/__init__.rst shared-bindings/neopixel_write/
shared-bindings/network/__init__.rst shared-bindings/network/ shared-bindings/network/__init__.rst shared-bindings/network/
shared-bindings/nvm/ByteArray.rst shared-bindings/nvm/#nvm.ByteArray shared-bindings/nvm/ByteArray.rst shared-bindings/nvm/#nvm.ByteArray
shared-bindings/nvm/__init__.rst shared-bindings/nvm/ shared-bindings/nvm/__init__.rst shared-bindings/nvm/
shared-bindings/onewireio/OneWire.rst shared-bindings/onewireio/#onewireio.OneWire
shared-bindings/os/__init__.rst shared-bindings/os/ shared-bindings/os/__init__.rst shared-bindings/os/
shared-bindings/protomatter/__init__.rst shared-bindings/protomatter/ shared-bindings/protomatter/__init__.rst shared-bindings/protomatter/
shared-bindings/ps2io/Ps2.rst shared-bindings/ps2io/#ps2io.Ps2 shared-bindings/ps2io/Ps2.rst shared-bindings/ps2io/#ps2io.Ps2

View File

@ -62,9 +62,17 @@ additional_modules = {
"fontio": "CIRCUITPY_DISPLAYIO", "fontio": "CIRCUITPY_DISPLAYIO",
"terminalio": "CIRCUITPY_DISPLAYIO", "terminalio": "CIRCUITPY_DISPLAYIO",
"adafruit_bus_device": "CIRCUITPY_BUSDEVICE", "adafruit_bus_device": "CIRCUITPY_BUSDEVICE",
"adafruit_pixelbuf": "CIRCUITPY_PIXELBUF" "adafruit_pixelbuf": "CIRCUITPY_PIXELBUF",
"usb": "CIRCUITPY_USB_HOST",
} }
frozen_excludes = ["examples", "docs", "tests", "utils", "conf.py", "setup.py"]
"""Files and dirs at the root of a frozen directory that should be ignored.
This is the same list as in the preprocess_frozen_modules script."""
repository_urls = {}
"""Cache of repository URLs for frozen modules."""
def get_circuitpython_root_dir(): def get_circuitpython_root_dir():
""" The path to the root './circuitpython' directory """ The path to the root './circuitpython' directory
""" """
@ -162,6 +170,63 @@ def get_settings_from_makefile(port_dir, board_name):
return settings return settings
def get_repository_url(directory):
if directory in repository_urls:
return repository_urls[directory]
readme = None
for readme_path in (
os.path.join(directory, "README.rst"),
os.path.join(os.path.dirname(directory), "README.rst")
):
if os.path.exists(readme_path):
readme = readme_path
break
path = None
if readme:
with open(readme, "r") as fp:
for line in fp.readlines():
if m := re.match("\s+:target:\s+(http\S+(docs.circuitpython|readthedocs)\S+)\s*", line):
path = m.group(1)
break
if m := re.search("<(http[^>]+)>", line):
path = m.group(1)
break
if path is None:
contents = subprocess.run(
["git", "remote", "get-url", "origin"],
encoding="utf-8",
errors="replace",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=directory
)
path = contents.stdout.strip()
repository_urls[directory] = path
return path
def frozen_modules_from_dirs(frozen_mpy_dirs):
"""
Go through the list of frozen directories and extract the python modules.
Paths are of the type:
$(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground
$(TOP)/frozen/circuitpython-stage/meowbit
Python modules are at the root of the path, and are python files or directories
containing python files. Except the ones in the frozen_excludes list.
"""
frozen_modules = []
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
source_dir = get_circuitpython_root_dir() / frozen_path[7:]
url_repository = get_repository_url(source_dir)
for sub in source_dir.glob("*"):
if sub.name in frozen_excludes:
continue
if sub.name.endswith(".py"):
frozen_modules.append((sub.name[:-3], url_repository))
continue
if next(sub.glob("**/*.py"), None): # tests if not empty
frozen_modules.append((sub.name, url_repository))
return frozen_modules
def lookup_setting(settings, key, default=''): def lookup_setting(settings, key, default=''):
while True: while True:
value = settings.get(key, default) value = settings.get(key, default)
@ -207,8 +272,14 @@ def support_matrix_by_board(use_branded_name=True):
board_modules.append(base[module]['name']) board_modules.append(base[module]['name'])
board_modules.sort() board_modules.sort()
frozen_modules = []
if "FROZEN_MPY_DIRS" in settings:
frozen_modules = frozen_modules_from_dirs(settings["FROZEN_MPY_DIRS"])
if frozen_modules:
frozen_modules.sort()
# generate alias boards too # generate alias boards too
board_matrix = [(board_name, board_modules)] board_matrix = [(board_name, (board_modules, frozen_modules))]
if entry.name in aliases_by_board: if entry.name in aliases_by_board:
for alias in aliases_by_board[entry.name]: for alias in aliases_by_board[entry.name]:
if use_branded_name: if use_branded_name:
@ -216,7 +287,7 @@ def support_matrix_by_board(use_branded_name=True):
alias = aliases_brand_names[alias] alias = aliases_brand_names[alias]
else: else:
alias = alias.replace("_"," ").title() alias = alias.replace("_"," ").title()
board_matrix.append( (alias, board_modules) ) board_matrix.append( (alias, (board_modules, frozen_modules)) )
return board_matrix # this is now a list of (board,modules) return board_matrix # this is now a list of (board,modules)
@ -225,7 +296,6 @@ def support_matrix_by_board(use_branded_name=True):
# flatmap with comprehensions # flatmap with comprehensions
boards = dict(sorted([board for matrix in mapped_exec for board in matrix])) boards = dict(sorted([board for matrix in mapped_exec for board in matrix]))
# print(json.dumps(boards, indent=2))
return boards return boards
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -7,8 +7,21 @@
right: 10px; right: 10px;
top: 4px; top: 4px;
} }
.support-matrix-table .this_module code,
.support-matrix-table .this_module span { .support-matrix-table .reference.external {
box-sizing: border-box;
font-weight: 700;
color: #404040;
font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", Courier, monospace;
padding: 2px 5px;
background: white;
border: 1px solid #e1e4e5;
font-size: 75%;
}
.support-matrix-table .this_module,
.support-matrix-table .this_module.reference.external,
.support-matrix-table .this_module * {
background: black; background: black;
color: white; color: white;
} }

View File

@ -44,14 +44,14 @@ $(() => {
var nvisible = 0; var nvisible = 0;
$(".support-matrix-table tbody tr").each( (index,item) => { $(".support-matrix-table tbody tr").each( (index,item) => {
var name = $(item).find("td:first-child p").html(); var name = $(item).find("td:first-child p").html();
var modules = $(item).find("a.reference.internal"); var modules = $(item).find("code, a.reference.external");
var matching_all = true; var matching_all = true;
// //
list_search.forEach((sstring) => { list_search.forEach((sstring) => {
var matching = (sstring[0] == "-"); var matching = (sstring[0] == "-");
for(var modi = 0; modi < modules.length; ++modi) { for(var modi = 0; modi < modules.length; ++modi) {
module = modules[modi]; module = modules[modi];
var mod_name = module.firstChild.firstChild.textContent; var mod_name = module.firstChild.textContent;
if(sstring[0] == "-") { if(sstring[0] == "-") {
if(mod_name.match(sstring.substr(1))) { if(mod_name.match(sstring.substr(1))) {
matching = false; matching = false;

View File

@ -33,6 +33,8 @@
#include "shared-bindings/supervisor/__init__.h" #include "shared-bindings/supervisor/__init__.h"
#endif #endif
#include "supervisor/shared/translate/translate.h"
#if MICROPY_PY_UASYNCIO #if MICROPY_PY_UASYNCIO
// Used when task cannot be guaranteed to be non-NULL. // Used when task cannot be guaranteed to be non-NULL.

View File

@ -11,6 +11,8 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/binary.h" #include "py/binary.h"
#include "supervisor/shared/translate/translate.h"
static void check_not_unicode(const mp_obj_t arg) { static void check_not_unicode(const mp_obj_t arg) {
#if MICROPY_CPYTHON_COMPAT #if MICROPY_CPYTHON_COMPAT
if (mp_obj_is_str(arg)) { if (mp_obj_is_str(arg)) {

View File

@ -11,7 +11,7 @@
#include "py/objtuple.h" #include "py/objtuple.h"
#include "py/binary.h" #include "py/binary.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#if MICROPY_PY_UCTYPES #if MICROPY_PY_UCTYPES

View File

@ -8,7 +8,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#if MICROPY_PY_UHASHLIB #if MICROPY_PY_UHASHLIB

View File

@ -6,7 +6,7 @@
#include "py/objlist.h" #include "py/objlist.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#if MICROPY_PY_UHEAPQ #if MICROPY_PY_UHEAPQ

View File

@ -13,7 +13,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/stream.h" #include "py/stream.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#if MICROPY_PY_UJSON #if MICROPY_PY_UJSON

View File

@ -10,7 +10,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/smallint.h" #include "py/smallint.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#if MICROPY_PY_UTIMEQ #if MICROPY_PY_UTIMEQ

View File

@ -10,7 +10,7 @@
#include "py/stream.h" #include "py/stream.h"
#include "py/mperrno.h" #include "py/mperrno.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#if MICROPY_PY_UZLIB #if MICROPY_PY_UZLIB

View File

@ -20,7 +20,7 @@
#include "extmod/vfs_fat.h" #include "extmod/vfs_fat.h"
#include "shared/timeutils/timeutils.h" #include "shared/timeutils/timeutils.h"
#include "supervisor/filesystem.h" #include "supervisor/filesystem.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#if FF_MAX_SS == FF_MIN_SS #if FF_MAX_SS == FF_MIN_SS
#define SECSIZE(fs) (FF_MIN_SS) #define SECSIZE(fs) (FF_MIN_SS)
@ -30,6 +30,11 @@
#define mp_obj_fat_vfs_t fs_user_mount_t #define mp_obj_fat_vfs_t fs_user_mount_t
// Factoring this common call saves about 90 bytes.
STATIC NORETURN void mp_raise_OSError_fresult(FRESULT res) {
mp_raise_OSError(fresult_to_errno_table[res]);
}
STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) {
fs_user_mount_t *vfs = vfs_in; fs_user_mount_t *vfs = vfs_in;
FILINFO fno; FILINFO fno;
@ -64,7 +69,7 @@ STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_
// don't error out if no filesystem, to let mkfs()/mount() create one if wanted // don't error out if no filesystem, to let mkfs()/mount() create one if wanted
vfs->blockdev.flags |= MP_BLOCKDEV_FLAG_NO_FILESYSTEM; vfs->blockdev.flags |= MP_BLOCKDEV_FLAG_NO_FILESYSTEM;
} else if (res != FR_OK) { } else if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return MP_OBJ_FROM_PTR(vfs); return MP_OBJ_FROM_PTR(vfs);
@ -97,7 +102,7 @@ STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) {
res = f_mkfs(&vfs->fatfs, FM_FAT32, 0, working_buf, sizeof(working_buf)); res = f_mkfs(&vfs->fatfs, FM_FAT32, 0, working_buf, sizeof(working_buf));
} }
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_const_none; return mp_const_none;
@ -172,7 +177,7 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) {
iter->is_str = is_str_type; iter->is_str = is_str_type;
FRESULT res = f_opendir(&self->fatfs, &iter->dir, path); FRESULT res = f_opendir(&self->fatfs, &iter->dir, path);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return MP_OBJ_FROM_PTR(iter); return MP_OBJ_FROM_PTR(iter);
@ -188,7 +193,7 @@ STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_in
FRESULT res = f_stat(&self->fatfs, path, &fno); FRESULT res = f_stat(&self->fatfs, path, &fno);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
// check if path is a file or directory // check if path is a file or directory
@ -196,7 +201,7 @@ STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_in
res = f_unlink(&self->fatfs, path); res = f_unlink(&self->fatfs, path);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_const_none; return mp_const_none;
} else { } else {
@ -226,7 +231,7 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
FILINFO fno; FILINFO fno;
FRESULT res = f_stat(&self->fatfs, old_path, &fno); FRESULT res = f_stat(&self->fatfs, old_path, &fno);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
if ((fno.fattrib & AM_DIR) != 0 && if ((fno.fattrib & AM_DIR) != 0 &&
strlen(new_path) > strlen(old_path) && strlen(new_path) > strlen(old_path) &&
@ -245,7 +250,7 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
if (res == FR_OK) { if (res == FR_OK) {
return mp_const_none; return mp_const_none;
} else { } else {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
} }
@ -259,7 +264,7 @@ STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) {
if (res == FR_OK) { if (res == FR_OK) {
return mp_const_none; return mp_const_none;
} else { } else {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir); STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir);
@ -273,7 +278,7 @@ STATIC mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) {
FRESULT res = f_chdir(&self->fatfs, path); FRESULT res = f_chdir(&self->fatfs, path);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_const_none; return mp_const_none;
@ -286,7 +291,7 @@ STATIC mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) {
char buf[MICROPY_ALLOC_PATH_MAX + 1]; char buf[MICROPY_ALLOC_PATH_MAX + 1];
FRESULT res = f_getcwd(&self->fatfs, buf, sizeof(buf)); FRESULT res = f_getcwd(&self->fatfs, buf, sizeof(buf));
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_obj_new_str(buf, strlen(buf)); return mp_obj_new_str(buf, strlen(buf));
} }
@ -307,7 +312,7 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) {
} else { } else {
FRESULT res = f_stat(&self->fatfs, path, &fno); FRESULT res = f_stat(&self->fatfs, path, &fno);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
} }
@ -357,7 +362,7 @@ STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) {
FATFS *fatfs = &self->fatfs; FATFS *fatfs = &self->fatfs;
FRESULT res = f_getfree(fatfs, &nclst); FRESULT res = f_getfree(fatfs, &nclst);
if (FR_OK != res) { if (FR_OK != res) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL)); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(10, NULL));
@ -395,7 +400,7 @@ STATIC mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs
res = f_mkfs(&self->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf)); res = f_mkfs(&self->fatfs, FM_FAT | FM_SFD, 0, working_buf, sizeof(working_buf));
} }
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
self->blockdev.flags &= ~MP_BLOCKDEV_FLAG_NO_FILESYSTEM; self->blockdev.flags &= ~MP_BLOCKDEV_FLAG_NO_FILESYSTEM;
@ -416,7 +421,7 @@ STATIC mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) {
char working_buf[12]; char working_buf[12];
FRESULT res = f_getlabel(&self->fatfs, working_buf, NULL); FRESULT res = f_getlabel(&self->fatfs, working_buf, NULL);
if (res != FR_OK) { if (res != FR_OK) {
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_obj_new_str(working_buf, strlen(working_buf)); return mp_obj_new_str(working_buf, strlen(working_buf));
} }
@ -431,7 +436,7 @@ STATIC mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) {
if (res == FR_WRITE_PROTECTED) { if (res == FR_WRITE_PROTECTED) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Read-only filesystem")); mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("Read-only filesystem"));
} }
mp_raise_OSError(fresult_to_errno_table[res]); mp_raise_OSError_fresult(res);
} }
return mp_const_none; return mp_const_none;
} }

View File

@ -182,7 +182,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
} }
if (rwxa_count != 1 || plus_count > 1 || bt_count > 1 || bad_mode) { if (rwxa_count != 1 || plus_count > 1 || bt_count > 1 || bad_mode) {
mp_raise_ValueError(translate("Invalid mode")); mp_arg_error_invalid(MP_QSTR_mode);
} }
assert(vfs != NULL); assert(vfs != NULL);

View File

@ -8,7 +8,7 @@
#include "py/runtime.h" #include "py/runtime.h"
#include "py/stream.h" #include "py/stream.h"
#include "extmod/vfs_posix.h" #include "extmod/vfs_posix.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#if (defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX) || (defined(MICROPY_VFS_POSIX_FILE) && MICROPY_VFS_POSIX_FILE) #if (defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX) || (defined(MICROPY_VFS_POSIX_FILE) && MICROPY_VFS_POSIX_FILE)

@ -1 +1 @@
Subproject commit f82d3ef195256aa71d274a34ea25f760d7e651d1 Subproject commit 54b2fa03d8af80562b77460841e63d47f12eee43

@ -1 +1 @@
Subproject commit 2dfd61a0d5ffc8048e72d24e5ecdac9a74bb2bc3 Subproject commit 3d1aab0daf63c3b4476f73cba39cf5da49e1e4aa

@ -1 +1 @@
Subproject commit 742ac7c8fb52bb85d9fd367b60a7f80475d7ed14 Subproject commit 2d8310f19d1bdce817df13e807b409b5b057fc21

@ -1 +1 @@
Subproject commit 5fdd62ab69fda70407644acc6f9b45681da9ef68 Subproject commit 850c3dc512f7feae1eaad20bdc1c5e4c63c92f08

1
frozen/mixgo_cp_lib Submodule

@ -0,0 +1 @@
Subproject commit 8b6cd888b264abaf8f9b1904b09b01313b273bb2

1
frozen/pew-pewpew-lcd Submodule

@ -0,0 +1 @@
Subproject commit 837f3e5f16accae5b3677954921b5ddd517f0799

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

54
main.c
View File

@ -58,7 +58,7 @@
#include "supervisor/shared/status_leds.h" #include "supervisor/shared/status_leds.h"
#include "supervisor/shared/tick.h" #include "supervisor/shared/tick.h"
#include "supervisor/shared/traceback.h" #include "supervisor/shared/traceback.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#include "supervisor/shared/workflow.h" #include "supervisor/shared/workflow.h"
#include "supervisor/usb.h" #include "supervisor/usb.h"
#include "supervisor/workflow.h" #include "supervisor/workflow.h"
@ -101,6 +101,10 @@
#include "shared-module/memorymonitor/__init__.h" #include "shared-module/memorymonitor/__init__.h"
#endif #endif
#if CIRCUITPY_SOCKETPOOL
#include "shared-bindings/socketpool/__init__.h"
#endif
#if CIRCUITPY_USB_HID #if CIRCUITPY_USB_HID
#include "shared-module/usb_hid/__init__.h" #include "shared-module/usb_hid/__init__.h"
#endif #endif
@ -277,10 +281,10 @@ STATIC void cleanup_after_vm(supervisor_allocation *heap, mp_obj_t exception) {
memorymonitor_reset(); memorymonitor_reset();
#endif #endif
filesystem_flush(); // Disable user related BLE state that uses the micropython heap.
stop_mp(); #if CIRCUITPY_BLEIO
free_memory(heap); bleio_user_reset();
supervisor_move_memory(); #endif
#if CIRCUITPY_CANIO #if CIRCUITPY_CANIO
common_hal_canio_reset(); common_hal_canio_reset();
@ -290,6 +294,16 @@ STATIC void cleanup_after_vm(supervisor_allocation *heap, mp_obj_t exception) {
keypad_reset(); keypad_reset();
#endif #endif
// Close user-initiated sockets.
#if CIRCUITPY_SOCKETPOOL
socketpool_user_reset();
#endif
// Turn off user initiated WiFi connections.
#if CIRCUITPY_WIFI
wifi_user_reset();
#endif
// reset_board_buses() first because it may release pins from the never_reset state, so that // reset_board_buses() first because it may release pins from the never_reset state, so that
// reset_port() can reset them. // reset_port() can reset them.
#if CIRCUITPY_BOARD #if CIRCUITPY_BOARD
@ -297,6 +311,15 @@ STATIC void cleanup_after_vm(supervisor_allocation *heap, mp_obj_t exception) {
#endif #endif
reset_port(); reset_port();
reset_board(); reset_board();
// Free the heap last because other modules may reference heap memory and need to shut down.
filesystem_flush();
stop_mp();
free_memory(heap);
supervisor_move_memory();
// Let the workflows know we've reset in case they want to restart.
supervisor_workflow_reset();
} }
STATIC void print_code_py_status_message(safe_mode_t safe_mode) { STATIC void print_code_py_status_message(safe_mode_t safe_mode) {
@ -645,6 +668,12 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
// Done waiting, start the board back up. // Done waiting, start the board back up.
// We delay resetting BLE until after the wait in case we're transferring
// more files over.
#if CIRCUITPY_BLEIO
bleio_reset();
#endif
// free code allocation if unused // free code allocation if unused
if ((next_code_options & next_code_stickiness_situation) == 0) { if ((next_code_options & next_code_stickiness_situation) == 0) {
free_memory(next_code_allocation); free_memory(next_code_allocation);
@ -877,20 +906,7 @@ int __attribute__((used)) main(void) {
run_boot_py(safe_mode); run_boot_py(safe_mode);
// Start USB after giving boot.py a chance to tweak behavior. supervisor_workflow_start();
#if CIRCUITPY_USB
// Setup USB connection after heap is available.
// It needs the heap to build descriptors.
usb_init();
#endif
// Set up any other serial connection.
serial_init();
#if CIRCUITPY_BLEIO
supervisor_bluetooth_enable_workflow();
supervisor_start_bluetooth();
#endif
// Boot script is finished, so now go into REPL or run code.py. // Boot script is finished, so now go into REPL or run code.py.
int exit_code = PYEXEC_FORCED_EXIT; int exit_code = PYEXEC_FORCED_EXIT;

View File

@ -67,7 +67,7 @@ SRC_C += \
shared/runtime/gchelper_generic.c \ shared/runtime/gchelper_generic.c \
supervisor/stub/safe_mode.c \ supervisor/stub/safe_mode.c \
supervisor/stub/stack.c \ supervisor/stub/stack.c \
supervisor/shared/translate.c supervisor/shared/translate/translate.c
# Add fmode when compiling with mingw gcc # Add fmode when compiling with mingw gcc
COMPILER_TARGET := $(shell $(CC) -dumpmachine) COMPILER_TARGET := $(shell $(CC) -dumpmachine)
@ -78,6 +78,6 @@ endif
OBJ = $(PY_CORE_O) OBJ = $(PY_CORE_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h $(BUILD)/supervisor/shared/translate/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/compression.generated.h
include $(TOP)/py/mkrules.mk include $(TOP)/py/mkrules.mk

View File

@ -123,8 +123,6 @@ $(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY))
#Debugging/Optimization #Debugging/Optimization
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
CFLAGS += -ggdb3 -Og -Os CFLAGS += -ggdb3 -Og -Os
# You may want to disable -flto if it interferes with debugging.
CFLAGS += -flto -flto-partition=none
# You may want to enable these flags to make setting breakpoints easier. # You may want to enable these flags to make setting breakpoints easier.
# CFLAGS += -fno-inline -fno-ipa-sra # CFLAGS += -fno-inline -fno-ipa-sra
ifeq ($(CHIP_FAMILY), samd21) ifeq ($(CHIP_FAMILY), samd21)
@ -147,8 +145,6 @@ else
CFLAGS += -finline-limit=$(CFLAGS_INLINE_LIMIT) CFLAGS += -finline-limit=$(CFLAGS_INLINE_LIMIT)
endif endif
CFLAGS += -flto -flto-partition=none
ifeq ($(CIRCUITPY_FULL_BUILD),0) ifeq ($(CIRCUITPY_FULL_BUILD),0)
CFLAGS += --param inline-unit-growth=15 --param max-inline-insns-auto=20 CFLAGS += --param inline-unit-growth=15 --param max-inline-insns-auto=20
endif endif
@ -204,7 +200,6 @@ endif
CFLAGS += -Wno-stringop-overread -Wno-stringop-overflow CFLAGS += -Wno-stringop-overread -Wno-stringop-overflow
LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
LDFLAGS += -flto=$(shell $(NPROC))
LIBS := -lgcc -lc LIBS := -lgcc -lc
# Use toolchain libm if we're not using our own. # Use toolchain libm if we're not using our own.
@ -275,6 +270,9 @@ SRC_ASF += \
hpl/oscctrl/hpl_oscctrl.c \ hpl/oscctrl/hpl_oscctrl.c \
hpl/trng/hpl_trng.c \ hpl/trng/hpl_trng.c \
# Ignore these errors
$(BUILD)/asf4/same54/hpl/sercom/hpl_sercom.o: CFLAGS += -Wno-maybe-uninitialized
else ifeq ($(CHIP_FAMILY), same51) else ifeq ($(CHIP_FAMILY), same51)
SRC_ASF += \ SRC_ASF += \
hal/src/hal_rand_sync.c \ hal/src/hal_rand_sync.c \

View File

@ -9,6 +9,3 @@ CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1 INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0 CIRCUITPY_FULL_BUILD = 0
# This board has many pins, and we have to remove something else to make room.
CIRCUITPY_RAINBOWIO = 0

View File

@ -11,4 +11,3 @@ LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0 CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_ONEWIREIO = 0
CIRCUITPY_RAINBOWIO = 0

View File

@ -19,7 +19,7 @@ CIRCUITPY_COUNTIO = 1
CIRCUITPY_BUSDEVICE = 1 CIRCUITPY_BUSDEVICE = 1
# Include these Python libraries in firmware. # Include these Python libraries in firmware.
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground/frozen_cpx
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel

View File

@ -18,7 +18,7 @@ CIRCUITPY_KEYPAD = 0
CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_ONEWIREIO = 0
# Include these Python libraries in firmware. # Include these Python libraries in firmware.
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground/frozen_cpx
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Crickit FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Crickit
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Motor FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Motor

View File

@ -12,6 +12,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
# Turn off features and optimizations for displayio build to make room for additional frozen libs. # Turn off features and optimizations for displayio build to make room for additional frozen libs.
LONGINT_IMPL = NONE LONGINT_IMPL = NONE
CIRCUITPY_KEYPAD = 0 CIRCUITPY_KEYPAD = 0
CIRCUITPY_ONEWIREIO = 0
CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PIXELBUF = 0
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0 CIRCUITPY_RTC = 0
@ -23,7 +24,7 @@ CIRCUITPY_BITMAPTOOLS = 0
CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PARALLELDISPLAY = 0
# Include these Python libraries in firmware. # Include these Python libraries in firmware.
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground/frozen_cpx
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Thermistor FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Thermistor

View File

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

View File

@ -0,0 +1,27 @@
#define MICROPY_HW_BOARD_NAME "Cytron Maker Zero SAMD21"
#define MICROPY_HW_MCU_NAME "samd21g18"
#define MICROPY_HW_LED_TX &pin_PA27
#define MICROPY_HW_LED_RX &pin_PB03
#define DEFAULT_I2C_BUS_SCL (&pin_PA23)
#define DEFAULT_I2C_BUS_SDA (&pin_PA22)
#define DEFAULT_SPI_BUS_SCK (&pin_PB11)
#define DEFAULT_SPI_BUS_MOSI (&pin_PB10)
#define DEFAULT_SPI_BUS_MISO (&pin_PA12)
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1
// SWD-only
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1

View File

@ -0,0 +1,11 @@
USB_VID = 0x04D8
USB_PID = 0xE799
USB_PRODUCT = "Maker Zero SAMD21"
USB_MANUFACTURER = "Cytron"
CHIP_VARIANT = SAMD21G18A
CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0

View File

@ -0,0 +1,49 @@
#include "shared-bindings/board/__init__.h"
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB08) },
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB09) },
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PB02) },
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA11) },
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA11) },
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA10) },
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA10) },
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA14) },
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA15) },
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA20) },
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA21) },
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA16) },
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR_D38), MP_ROM_PTR(&pin_PA13) },
{ MP_ROM_QSTR(MP_QSTR_ATN), MP_ROM_PTR(&pin_PA13) },
{ MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_PA23) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA23) },
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB11) },
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB10) },
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA12) },
{ 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_module_globals_table);

View File

@ -12,3 +12,5 @@ LONGINT_IMPL = MPZ
CIRCUITPY__EVE = 1 CIRCUITPY__EVE = 1
CIRCUITPY_CANIO = 1 CIRCUITPY_CANIO = 1
CIRCUITPY_LTO_PARTITION = one

View File

@ -111,7 +111,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // not SH1107 false, // not SH1107
50000); // backlight pwm frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -91,7 +91,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // not SH1107 false, // not SH1107
50000); // backlight pwm frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -7,5 +7,5 @@ CHIP_VARIANT = SAMD51J19A
CHIP_FAMILY = samd51 CHIP_FAMILY = samd51
QSPI_FLASH_FILESYSTEM = 1 QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = GD25Q64C EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ

View File

@ -27,6 +27,8 @@ CIRCUITPY_PS2IO = 0
CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_ROTARYIO = 0 CIRCUITPY_ROTARYIO = 0
CIRCUITPY_TOUCHIO = 0 CIRCUITPY_TOUCHIO = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_ULAB = 0 CIRCUITPY_ULAB = 0

View File

@ -10,6 +10,8 @@ QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C" EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ
CIRCUITPY_LTO_PARTITION = one
CIRCUITPY_AESIO = 0 CIRCUITPY_AESIO = 0
CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_ONEWIREIO = 0
CIRCUITPY_PARALLELDISPLAY = 0 CIRCUITPY_PARALLELDISPLAY = 0

View File

@ -9,5 +9,3 @@ CHIP_FAMILY = samd21
SPI_FLASH_FILESYSTEM = 1 SPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ
CIRCUITPY_ONEWIREIO = 0

View File

@ -92,7 +92,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // SH1107_addressing false, // SH1107_addressing
50000); // backlight pwm frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -7,5 +7,5 @@ CHIP_VARIANT = SAMD51J19A
CHIP_FAMILY = samd51 CHIP_FAMILY = samd51
QSPI_FLASH_FILESYSTEM = 1 QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = GD25Q64C EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ

View File

@ -10,4 +10,4 @@ QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = GD25Q16C EXTERNAL_FLASH_DEVICES = GD25Q16C
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ
CIRCUITPY_GAMEPADSHIFT = 1 CIRCUITPY_KEYPAD = 1

View File

@ -0,0 +1,105 @@
/*
* 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 "shared-bindings/board/__init__.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/busio/SPI.h"
displayio_fourwire_obj_t board_display_obj;
#define DELAY 0x80
uint8_t display_init_sequence[] = {
0xe2, 0, // reset
0x2f, 0, // power on
0x80, 0, // contrast 0
0xa4, 0, // display normal
0xaf, 0, // display on
0x40, 0, // start line 0
};
void board_init(void) {
busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, false);
common_hal_busio_spi_never_reset(spi);
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
bus->base.type = &displayio_fourwire_type;
common_hal_displayio_fourwire_construct(bus,
spi,
NULL, // Command or data
&pin_PA19, // Chip select
&pin_PA18, // Reset
40000000LL, // Baudrate
0, // Polarity
0); // Phase
displayio_display_obj_t *display = &displays[0].display;
display->base.type = &displayio_display_type;
common_hal_displayio_display_construct(display,
bus,
96, // Width
68, // Height
0, // column start
0, // row start
180, // rotation
1, // Color depth
true, // grayscale
false, // pixels in byte share row. Only used with depth < 8
1, // bytes per cell. Only valid for depths < 8
false, // reverse_pixels_in_byte. Only valid for depths < 8
false, // reverse_pixels_in_word
0, // Set column command
0, // Set row command
0, // Write memory command
display_init_sequence,
sizeof(display_init_sequence),
NULL, // &pin_PA17, // brightness pin
NO_BRIGHTNESS_COMMAND,
0.0f, // brightness
false, // auto_brightness
false, // single_byte_bounds
true, // data as commands
true, // auto_refresh
2, // native_frames_per_second
true, // backlight_on_high
true, // SH1107_addressing
50000); // backlight pwm frequency
}
bool board_requests_safe_mode(void) {
return false;
}
void reset_board(void) {
}
void board_deinit(void) {
}

View File

@ -0,0 +1,16 @@
#define MICROPY_HW_BOARD_NAME "PewPew LCD"
#define MICROPY_HW_MCU_NAME "samd21e18"
#define MICROPY_PORT_A (0)
#define MICROPY_PORT_B (0)
#define MICROPY_PORT_C (0)
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (48 * 1024)
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
#define SAMD21_BOD33_LEVEL (6)
#define CIRCUITPY_REPL_LOGO (0)

View File

@ -0,0 +1,57 @@
USB_VID = 0x1209
USB_PID = 0xD1B5
USB_PRODUCT = "PewPew LCD"
USB_MANUFACTURER = "Radomir Dopieralski"
CHIP_VARIANT = SAMD21E18A
CHIP_FAMILY = samd21
INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
CIRCUITPY_DISPLAYIO = 1
CIRCUITPY_TOUCHIO = 1
CIRCUITPY_PWMIO = 1
CIRCUITPY_MATH = 0
CIRCUITPY_ANALOGIO = 0
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOBUSIO_I2SOUT = 0
CIRCUITPY_AUDIOCORE = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_AUDIOMIXER = 0
CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_AUDIOPWMIO = 0
CIRCUITPY_BITBANG_APA102 = 0
CIRCUITPY_BITBANGIO = 0
CIRCUITPY_BITBANGIO = 0
CIRCUITPY_BITMAPTOOLS = 0
CIRCUITPY_BITMAPTOOLS = 0
CIRCUITPY_BLEIO = 0
CIRCUITPY_BUSDEVICE = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
CIRCUITPY_NVM = 0
CIRCUITPY_PIXELBUF = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_PULSEIO = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0
CIRCUITPY_SAMD = 0
CIRCUITPY_ULAB = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_USB_VENDOR = 0
CIRCUITPY_VECTORIO = 0
CIRCUITPY_RAINBOWIO = 0
CIRCUITPY_DISPLAY_FONT = $(TOP)/ports/atmel-samd/boards/ugame10/brutalist-6.bdf
OPTIMIZATION_FLAGS = -Os
FROZEN_MPY_DIRS += $(TOP)/frozen/pew-pewpew-lcd

View File

@ -0,0 +1,28 @@
#include "shared-bindings/board/__init__.h"
#include "shared-module/displayio/__init__.h"
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR__SCK), MP_ROM_PTR(&pin_PA23) },
{ MP_ROM_QSTR(MP_QSTR__MOSI), MP_ROM_PTR(&pin_PA22) },
{ MP_ROM_QSTR(MP_QSTR__CS), MP_ROM_PTR(&pin_PA19) },
{ MP_ROM_QSTR(MP_QSTR__RST), MP_ROM_PTR(&pin_PA18) },
{ MP_ROM_QSTR(MP_QSTR__BL), MP_ROM_PTR(&pin_PA17) },
{ MP_ROM_QSTR(MP_QSTR__UP), MP_ROM_PTR(&pin_PA03) },
{ MP_ROM_QSTR(MP_QSTR__DOWN), MP_ROM_PTR(&pin_PA05) },
{ MP_ROM_QSTR(MP_QSTR__LEFT), MP_ROM_PTR(&pin_PA04) },
{ MP_ROM_QSTR(MP_QSTR__RIGHT), MP_ROM_PTR(&pin_PA02) },
{ MP_ROM_QSTR(MP_QSTR__O), MP_ROM_PTR(&pin_PA06) },
{ MP_ROM_QSTR(MP_QSTR__X), MP_ROM_PTR(&pin_PA07) },
{ MP_ROM_QSTR(MP_QSTR_P1), MP_ROM_PTR(&pin_PA30) },
{ MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_PA31) },
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_PA08) },
{ MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_PA09) },
{ MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_PA10) },
{ MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_PA11) },
{ MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_PA14) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

View File

@ -144,7 +144,8 @@ void board_init(void) {
false, // auto_refresh false, // auto_refresh
20, // native_frames_per_second 20, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // SH1107_addressing false, // SH1107_addressing
50000); // backlight pwm frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -114,7 +114,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // SH1107_addressing false, // SH1107_addressing
50000); // backlight pwm frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -12,8 +12,8 @@ LONGINT_IMPL = MPZ
CIRCUITPY_AESIO = 0 CIRCUITPY_AESIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_GAMEPADSHIFT = 1
CIRCUITPY_GIFIO = 0 CIRCUITPY_GIFIO = 0
CIRCUITPY_KEYPAD = 1
CIRCUITPY_STAGE = 1 CIRCUITPY_STAGE = 1
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pybadge FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pybadge

View File

@ -114,7 +114,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // SH1107_addressing false, // SH1107_addressing
50000); // backlight pwm frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -7,13 +7,13 @@ CHIP_VARIANT = SAMD51J19A
CHIP_FAMILY = samd51 CHIP_FAMILY = samd51
QSPI_FLASH_FILESYSTEM = 1 QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICES = GD25Q64C EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ"
LONGINT_IMPL = MPZ LONGINT_IMPL = MPZ
CIRCUITPY_AESIO = 0 CIRCUITPY_AESIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_GAMEPADSHIFT = 1
CIRCUITPY_GIFIO = 0 CIRCUITPY_GIFIO = 0
CIRCUITPY_KEYPAD = 1
CIRCUITPY_STAGE = 1 CIRCUITPY_STAGE = 1
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pygamer FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pygamer

View File

@ -101,7 +101,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // SH1107_addressing false, // SH1107_addressing
50000); // backlight pwm frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -118,7 +118,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // SH1107_addressing false, // SH1107_addressing
500); // backlight_pwm_frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -109,7 +109,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // SH1107_addressing false, // SH1107_addressing
50000); // backlight pwm frequency
// Enabling the Power of the 40-pin at the back // Enabling the Power of the 40-pin at the back
CTR_5V.base.type = &digitalio_digitalinout_type; CTR_5V.base.type = &digitalio_digitalinout_type;

View File

@ -12,5 +12,4 @@ CIRCUITPY_FULL_BUILD = 0
# There are many pin definitions on this board; it doesn't quite fit on very large translations. # There are many pin definitions on this board; it doesn't quite fit on very large translations.
CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_ONEWIREIO = 0
CIRCUITPY_RAINBOWIO = 0
CIRCUITPY_USB_MIDI = 0 CIRCUITPY_USB_MIDI = 0

View File

@ -111,7 +111,8 @@ void board_init(void) {
true, // auto_refresh true, // auto_refresh
60, // native_frames_per_second 60, // native_frames_per_second
true, // backlight_on_high true, // backlight_on_high
false); // SH1107_addressing false, // SH1107_addressing
50000); // backlight pwm frequency
} }
bool board_requests_safe_mode(void) { bool board_requests_safe_mode(void) {

View File

@ -35,7 +35,7 @@
#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
#include "samd/timers.h" #include "samd/timers.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#include "timer_handler.h" #include "timer_handler.h"

View File

@ -234,7 +234,7 @@ static void pinalarm_set_alarms_light(size_t n_alarms, const mp_obj_t *alarms) {
// raise ValueError here // raise ValueError here
MP_FALLTHROUGH MP_FALLTHROUGH
case PINALARM_ERR_NOEXTINT: case PINALARM_ERR_NOEXTINT:
mp_raise_RuntimeError(translate("No hardware support on pin")); raise_ValueError_invalid_pin();
case PINALARM_ERR_NOCHANNEL: case PINALARM_ERR_NOCHANNEL:
mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use")); mp_raise_RuntimeError(translate("A hardware interrupt channel is already in use"));
default: default:
@ -261,7 +261,7 @@ static void pinalarm_set_alarms_deep(size_t n_alarms, const mp_obj_t *alarms) {
} }
} }
if (t->n < 0) { if (t->n < 0) {
mp_raise_ValueError(translate("Pin cannot wake from Deep Sleep")); raise_ValueError_invalid_pin();
} }
// It is strange, but to my experiment, interrupt during sleep // It is strange, but to my experiment, interrupt during sleep

View File

@ -100,7 +100,7 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_
continue; continue;
} }
if (timealarm_set) { if (timealarm_set) {
mp_raise_ValueError(translate("Only one alarm.time alarm can be set.")); mp_raise_ValueError(translate("Only one alarm.time alarm can be set"));
} }
timealarm = MP_OBJ_TO_PTR(alarms[i]); timealarm = MP_OBJ_TO_PTR(alarms[i]);
timealarm_set = true; timealarm_set = true;

View File

@ -36,7 +36,8 @@
#include "samd/adc.h" #include "samd/adc.h"
#include "shared-bindings/analogio/AnalogIn.h" #include "shared-bindings/analogio/AnalogIn.h"
#include "supervisor/shared/translate.h" #include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate/translate.h"
#include "atmel_start_pins.h" #include "atmel_start_pins.h"
#include "hal/include/hal_adc_sync.h" #include "hal/include/hal_adc_sync.h"
@ -60,7 +61,7 @@ void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self,
} }
if (adc_channel == 0xff) { if (adc_channel == 0xff) {
// No ADC function on that pin // No ADC function on that pin
mp_raise_ValueError(translate("Pin does not have ADC capabilities")); raise_ValueError_invalid_pin();
} }
claim_pin(pin); claim_pin(pin);
@ -122,8 +123,8 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) {
adc_sync_read_channel(&adc, self->channel, ((uint8_t *)&value), 2); adc_sync_read_channel(&adc, self->channel, ((uint8_t *)&value), 2);
adc_sync_deinit(&adc); adc_sync_deinit(&adc);
// Shift the value to be 16 bit. // Stretch 12-bit ADC reading to 16-bit range
return value << 4; return (value << 4) | (value >> 8);
} }
float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) { float common_hal_analogio_analogin_get_reference_voltage(analogio_analogin_obj_t *self) {

View File

@ -33,7 +33,7 @@
#include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/analogio/AnalogOut.h"
#include "shared-bindings/audioio/AudioOut.h" #include "shared-bindings/audioio/AudioOut.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#include "atmel_start_pins.h" #include "atmel_start_pins.h"
#include "hal/include/hal_dac_sync.h" #include "hal/include/hal_dac_sync.h"
@ -70,7 +70,7 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self,
#endif #endif
default: default:
mp_raise_ValueError(translate("AnalogOut not supported on given pin")); raise_ValueError_invalid_pin();
return; return;
} }

View File

@ -40,7 +40,7 @@
#include "shared-bindings/audiobusio/I2SOut.h" #include "shared-bindings/audiobusio/I2SOut.h"
#include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/audiocore/RawSample.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#include "atmel_start_pins.h" #include "atmel_start_pins.h"
#include "hal/include/hal_gpio.h" #include "hal/include/hal_gpio.h"
@ -151,16 +151,16 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
} }
#endif #endif
if (bc_clock_unit == 0xff) { if (bc_clock_unit == 0xff) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_bit_clock); raise_ValueError_invalid_pin_name(MP_QSTR_clock);
} }
if (ws_clock_unit == 0xff) { if (ws_clock_unit == 0xff) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_word_select); raise_ValueError_invalid_pin_name(MP_QSTR_word_select);
} }
if (bc_clock_unit != ws_clock_unit) { if (bc_clock_unit != ws_clock_unit) {
mp_raise_ValueError(translate("Bit clock and word select must share a clock unit")); mp_raise_ValueError(translate("Bit clock and word select must share a clock unit"));
} }
if (serializer == 0xff) { if (serializer == 0xff) {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_data); raise_ValueError_invalid_pin_name(MP_QSTR_data);
} }
self->clock_unit = ws_clock_unit; self->clock_unit = ws_clock_unit;
self->serializer = serializer; self->serializer = serializer;
@ -255,7 +255,7 @@ void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t *self,
} }
uint8_t channel_count = audiosample_channel_count(sample); uint8_t channel_count = audiosample_channel_count(sample);
if (channel_count > 2) { if (channel_count > 2) {
mp_raise_ValueError(translate("Too many channels in sample.")); mp_raise_ValueError(translate("Too many channels in sample"));
} }
#ifdef SAMD21 #ifdef SAMD21
uint32_t serctrl = (self->clock_unit << I2S_SERCTRL_CLKSEL_Pos) | SERCTRL(SERMODE_TX) | I2S_SERCTRL_TXSAME_SAME | I2S_SERCTRL_EXTEND_MSBIT | I2S_SERCTRL_TXDEFAULT_ONE | I2S_SERCTRL_SLOTADJ_LEFT; uint32_t serctrl = (self->clock_unit << I2S_SERCTRL_CLKSEL_Pos) | SERCTRL(SERMODE_TX) | I2S_SERCTRL_TXSAME_SAME | I2S_SERCTRL_EXTEND_MSBIT | I2S_SERCTRL_TXDEFAULT_ONE | I2S_SERCTRL_SLOTADJ_LEFT;

View File

@ -37,7 +37,7 @@
#include "shared-bindings/audiobusio/PDMIn.h" #include "shared-bindings/audiobusio/PDMIn.h"
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#include "atmel_start_pins.h" #include "atmel_start_pins.h"
#include "hal/include/hal_gpio.h" #include "hal/include/hal_gpio.h"
@ -58,11 +58,11 @@
#define MIN_MIC_CLOCK 1000000 #define MIN_MIC_CLOCK 1000000
#ifdef SAMD21 #ifdef SAMD21
#define SERCTRL(name) I2S_SERCTRL_ ## name #define SERCTRL(name) I2S_SERCTRL_##name
#endif #endif
#ifdef SAM_D5X_E5X #ifdef SAM_D5X_E5X
#define SERCTRL(name) I2S_RXCTRL_ ## name #define SERCTRL(name) I2S_RXCTRL_##name
#endif #endif
// Set by interrupt handler when DMA block has finished transferring. // Set by interrupt handler when DMA block has finished transferring.
@ -80,48 +80,50 @@ void pdmin_reset(void) {
pdmin_dma_block_done = false; pdmin_dma_block_done = false;
pdmin_event_channel = EVSYS_SYNCH_NUM; pdmin_event_channel = EVSYS_SYNCH_NUM;
while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {} while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {
}
I2S->INTENCLR.reg = I2S_INTENCLR_MASK; I2S->INTENCLR.reg = I2S_INTENCLR_MASK;
I2S->INTFLAG.reg = I2S_INTFLAG_MASK; I2S->INTFLAG.reg = I2S_INTFLAG_MASK;
I2S->CTRLA.reg &= ~I2S_SYNCBUSY_ENABLE; I2S->CTRLA.reg &= ~I2S_SYNCBUSY_ENABLE;
while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {} while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {
}
I2S->CTRLA.reg = I2S_CTRLA_SWRST; I2S->CTRLA.reg = I2S_CTRLA_SWRST;
} }
// Caller validates that pins are free. // Caller validates that pins are free.
void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self, void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self,
const mcu_pin_obj_t* clock_pin, const mcu_pin_obj_t *clock_pin,
const mcu_pin_obj_t* data_pin, const mcu_pin_obj_t *data_pin,
uint32_t sample_rate, uint32_t sample_rate,
uint8_t bit_depth, uint8_t bit_depth,
bool mono, bool mono,
uint8_t oversample) { uint8_t oversample) {
self->clock_pin = clock_pin; // PA10, PA20 -> SCK0, PB11 -> SCK1 self->clock_pin = clock_pin; // PA10, PA20 -> SCK0, PB11 -> SCK1
#ifdef SAMD21 #ifdef SAMD21
if (clock_pin == &pin_PA10 if (clock_pin == &pin_PA10
#if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20) #if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20)
|| clock_pin == &pin_PA20 || clock_pin == &pin_PA20
#endif #endif
) {
self->clock_unit = 0;
#if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11)
} else if (clock_pin == &pin_PB11) {
self->clock_unit = 1;
#endif
#endif
#ifdef SAM_D5X_E5X
if (clock_pin == &pin_PA10 || clock_pin == &pin_PB16) {
self->clock_unit = 0;
} else if (clock_pin == &pin_PB12
#if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28)
|| data_pin == &pin_PB28) {
#else
) { ) {
#endif self->clock_unit = 0;
self->clock_unit = 1; #if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11)
} else if (clock_pin == &pin_PB11) {
self->clock_unit = 1;
#endif #endif
#else
#ifdef SAM_D5X_E5X
if (clock_pin == &pin_PA10 || clock_pin == &pin_PB16) {
self->clock_unit = 0;
} else if (clock_pin == &pin_PB12
#if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28)
|| data_pin == &pin_PB28
#endif
) {
self->clock_unit = 1;
#endif
#endif
} else { } else {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_clock); raise_ValueError_invalid_pin_name(MP_QSTR_clock);
} }
self->data_pin = data_pin; // PA07, PA19 -> SD0, PA08, PB16 -> SD1 self->data_pin = data_pin; // PA07, PA19 -> SD0, PA08, PB16 -> SD1
@ -136,23 +138,23 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
#endif #endif
) { ) {
self->serializer = 0; self->serializer = 0;
} } else if (false
else if (false #if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08)
#if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) || data_pin == &pin_PA08
|| data_pin == &pin_PA08 #endif
#endif #if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16)
#if defined (PIN_PB16) && !defined(IGNORE_PIN_PB16) || data_pin == &pin_PB16
|| data_pin == &pin_PB16 #endif
#endif ) {
) {
self->serializer = 1; self->serializer = 1;
#endif #else
#ifdef SAM_D5X_E5X #ifdef SAM_D5X_E5X
if (data_pin == &pin_PB10 || data_pin == &pin_PA22) { if (data_pin == &pin_PB10 || data_pin == &pin_PA22) {
self->serializer = 1; self->serializer = 1;
#endif #endif
#endif
} else { } else {
mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_data); raise_ValueError_invalid_pin_name(MP_QSTR_data);
} }
if (!(bit_depth == 16 || bit_depth == 8) || !mono || oversample != OVERSAMPLING) { if (!(bit_depth == 16 || bit_depth == 8) || !mono || oversample != OVERSAMPLING) {
@ -163,7 +165,8 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
if (I2S->CTRLA.bit.ENABLE == 0) { if (I2S->CTRLA.bit.ENABLE == 0) {
I2S->CTRLA.bit.SWRST = 1; I2S->CTRLA.bit.SWRST = 1;
while (I2S->CTRLA.bit.SWRST == 1) {} while (I2S->CTRLA.bit.SWRST == 1) {
}
} else { } else {
#ifdef SAMD21 #ifdef SAMD21
if ((I2S->CTRLA.vec.SEREN & (1 << self->serializer)) != 0) { if ((I2S->CTRLA.vec.SEREN & (1 << self->serializer)) != 0) {
@ -183,10 +186,10 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
#define GPIO_I2S_FUNCTION GPIO_PIN_FUNCTION_G #define GPIO_I2S_FUNCTION GPIO_PIN_FUNCTION_G
#endif #endif
uint32_t clock_divisor = (uint32_t) roundf( 48000000.0f / sample_rate / oversample); uint32_t clock_divisor = (uint32_t)roundf(48000000.0f / sample_rate / oversample);
float mic_clock_freq = 48000000.0f / clock_divisor; float mic_clock_freq = 48000000.0f / clock_divisor;
self->sample_rate = mic_clock_freq / oversample; self->sample_rate = mic_clock_freq / oversample;
if (mic_clock_freq < MIN_MIC_CLOCK || clock_divisor == 0) { if (mic_clock_freq < MIN_MIC_CLOCK || clock_divisor == 0) {
mp_raise_ValueError(translate("sampling rate out of range")); mp_raise_ValueError(translate("sampling rate out of range"));
} }
// Find a free GCLK to generate the MCLK signal. // Find a free GCLK to generate the MCLK signal.
@ -202,9 +205,9 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
// Clock unit configuration // Clock unit configuration
uint32_t clkctrl = I2S_CLKCTRL_MCKSEL_GCLK | uint32_t clkctrl = I2S_CLKCTRL_MCKSEL_GCLK |
I2S_CLKCTRL_NBSLOTS(2) | I2S_CLKCTRL_NBSLOTS(2) |
I2S_CLKCTRL_FSWIDTH_SLOT | I2S_CLKCTRL_FSWIDTH_SLOT |
I2S_CLKCTRL_SLOTSIZE_16; I2S_CLKCTRL_SLOTSIZE_16;
// Serializer configuration // Serializer configuration
#ifdef SAMD21 #ifdef SAMD21
@ -241,11 +244,11 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self,
self->bit_depth = bit_depth; self->bit_depth = bit_depth;
} }
bool common_hal_audiobusio_pdmin_deinited(audiobusio_pdmin_obj_t* self) { bool common_hal_audiobusio_pdmin_deinited(audiobusio_pdmin_obj_t *self) {
return self->clock_pin == NULL; return self->clock_pin == NULL;
} }
void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) { void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t *self) {
if (common_hal_audiobusio_pdmin_deinited(self)) { if (common_hal_audiobusio_pdmin_deinited(self)) {
return; return;
} }
@ -264,24 +267,24 @@ void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) {
self->data_pin = NULL; self->data_pin = NULL;
} }
uint8_t common_hal_audiobusio_pdmin_get_bit_depth(audiobusio_pdmin_obj_t* self) { uint8_t common_hal_audiobusio_pdmin_get_bit_depth(audiobusio_pdmin_obj_t *self) {
return self->bit_depth; return self->bit_depth;
} }
uint32_t common_hal_audiobusio_pdmin_get_sample_rate(audiobusio_pdmin_obj_t* self) { uint32_t common_hal_audiobusio_pdmin_get_sample_rate(audiobusio_pdmin_obj_t *self) {
return self->sample_rate; return self->sample_rate;
} }
static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length, static void setup_dma(audiobusio_pdmin_obj_t *self, uint32_t length,
DmacDescriptor* descriptor, DmacDescriptor *descriptor,
DmacDescriptor* second_descriptor, DmacDescriptor *second_descriptor,
uint32_t words_per_buffer, uint8_t words_per_sample, uint32_t words_per_buffer, uint8_t words_per_sample,
uint32_t* first_buffer, uint32_t* second_buffer) { uint32_t *first_buffer, uint32_t *second_buffer) {
descriptor->BTCTRL.reg = DMAC_BTCTRL_VALID | descriptor->BTCTRL.reg = DMAC_BTCTRL_VALID |
DMAC_BTCTRL_BLOCKACT_NOACT | DMAC_BTCTRL_BLOCKACT_NOACT |
DMAC_BTCTRL_EVOSEL_BLOCK | DMAC_BTCTRL_EVOSEL_BLOCK |
DMAC_BTCTRL_DSTINC | DMAC_BTCTRL_DSTINC |
DMAC_BTCTRL_BEATSIZE_WORD; DMAC_BTCTRL_BEATSIZE_WORD;
// Block transfer count is the number of beats per block (aka descriptor). // Block transfer count is the number of beats per block (aka descriptor).
// In this case there are two bytes per beat so divide the length by two. // In this case there are two bytes per beat so divide the length by two.
@ -291,7 +294,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length,
} }
descriptor->BTCNT.reg = block_transfer_count; descriptor->BTCNT.reg = block_transfer_count;
descriptor->DSTADDR.reg = ((uint32_t) first_buffer + sizeof(uint32_t) * block_transfer_count); descriptor->DSTADDR.reg = ((uint32_t)first_buffer + sizeof(uint32_t) * block_transfer_count);
descriptor->DESCADDR.reg = 0; descriptor->DESCADDR.reg = 0;
if (length * words_per_sample > words_per_buffer) { if (length * words_per_sample > words_per_buffer) {
descriptor->DESCADDR.reg = ((uint32_t)second_descriptor); descriptor->DESCADDR.reg = ((uint32_t)second_descriptor);
@ -314,7 +317,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length,
block_transfer_count = length * words_per_sample - words_per_buffer; block_transfer_count = length * words_per_sample - words_per_buffer;
second_descriptor->DESCADDR.reg = 0; second_descriptor->DESCADDR.reg = 0;
} }
second_descriptor->DSTADDR.reg = ((uint32_t) second_buffer + sizeof(uint32_t) * block_transfer_count); second_descriptor->DSTADDR.reg = ((uint32_t)second_buffer + sizeof(uint32_t) * block_transfer_count);
second_descriptor->BTCNT.reg = block_transfer_count; second_descriptor->BTCNT.reg = block_transfer_count;
#ifdef SAMD21 #ifdef SAMD21
@ -324,10 +327,10 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length,
second_descriptor->SRCADDR.reg = (uint32_t)&I2S->RXDATA; second_descriptor->SRCADDR.reg = (uint32_t)&I2S->RXDATA;
#endif #endif
second_descriptor->BTCTRL.reg = DMAC_BTCTRL_VALID | second_descriptor->BTCTRL.reg = DMAC_BTCTRL_VALID |
DMAC_BTCTRL_BLOCKACT_NOACT | DMAC_BTCTRL_BLOCKACT_NOACT |
DMAC_BTCTRL_EVOSEL_BLOCK | DMAC_BTCTRL_EVOSEL_BLOCK |
DMAC_BTCTRL_DSTINC | DMAC_BTCTRL_DSTINC |
DMAC_BTCTRL_BEATSIZE_WORD; DMAC_BTCTRL_BEATSIZE_WORD;
} }
} }
@ -341,7 +344,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length,
// higher sample rate than specified. Then after the audio is // higher sample rate than specified. Then after the audio is
// recorded, a more expensive filter non-real-time filter could be // recorded, a more expensive filter non-real-time filter could be
// used to down-sample and low-pass. // used to down-sample and low-pass.
const uint16_t sinc_filter [OVERSAMPLING] = { const uint16_t sinc_filter[OVERSAMPLING] = {
0, 2, 9, 21, 39, 63, 94, 132, 0, 2, 9, 21, 39, 63, 94, 132,
179, 236, 302, 379, 467, 565, 674, 792, 179, 236, 302, 379, 467, 565, 674, 792,
920, 1055, 1196, 1341, 1487, 1633, 1776, 1913, 920, 1055, 1196, 1341, 1487, 1633, 1776, 1913,
@ -353,26 +356,26 @@ const uint16_t sinc_filter [OVERSAMPLING] = {
}; };
#ifdef SAMD21 #ifdef SAMD21
#define REPEAT_16_TIMES(X) do { for(uint8_t j=0; j<4; j++) { X X X X } } while (0) #define REPEAT_16_TIMES(X) do { for (uint8_t j = 0; j < 4; j++) { X X X X } } while (0)
#else #else
#define REPEAT_16_TIMES(X) do { X X X X X X X X X X X X X X X X } while(0) #define REPEAT_16_TIMES(X) do { X X X X X X X X X X X X X X X X } while (0)
#endif #endif
static uint16_t filter_sample(uint32_t pdm_samples[4]) { static uint16_t filter_sample(uint32_t pdm_samples[4]) {
uint16_t running_sum = 0; uint16_t running_sum = 0;
const uint16_t *filter_ptr = sinc_filter; const uint16_t *filter_ptr = sinc_filter;
for (uint8_t i = 0; i < OVERSAMPLING/16; i++) { for (uint8_t i = 0; i < OVERSAMPLING / 16; i++) {
// The sample is 16-bits right channel in the upper two bytes and 16-bits left channel // The sample is 16-bits right channel in the upper two bytes and 16-bits left channel
// in the lower two bytes. // in the lower two bytes.
// We just ignore the upper bits // We just ignore the upper bits
uint32_t pdm_sample = pdm_samples[i]; uint32_t pdm_sample = pdm_samples[i];
REPEAT_16_TIMES( { REPEAT_16_TIMES({
if (pdm_sample & 0x8000) { if (pdm_sample & 0x8000) {
running_sum += *filter_ptr; running_sum += *filter_ptr;
}
filter_ptr++;
pdm_sample <<= 1;
} }
filter_ptr++;
pdm_sample <<= 1;
}
); );
} }
return running_sum; return running_sum;
@ -380,8 +383,8 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) {
// output_buffer may be a byte buffer or a halfword buffer. // output_buffer may be a byte buffer or a halfword buffer.
// output_buffer_length is the number of slots, not the number of bytes. // output_buffer_length is the number of slots, not the number of bytes.
uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* self, uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t *self,
uint16_t* output_buffer, uint32_t output_buffer_length) { uint16_t *output_buffer, uint32_t output_buffer_length) {
uint8_t dma_channel = dma_allocate_channel(); uint8_t dma_channel = dma_allocate_channel();
pdmin_event_channel = find_sync_event_channel_raise(); pdmin_event_channel = find_sync_event_channel_raise();
pdmin_dma_block_done = false; pdmin_dma_block_done = false;
@ -399,7 +402,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
COMPILER_ALIGNED(16) DmacDescriptor second_descriptor; COMPILER_ALIGNED(16) DmacDescriptor second_descriptor;
setup_dma(self, output_buffer_length, dma_descriptor(dma_channel), &second_descriptor, setup_dma(self, output_buffer_length, dma_descriptor(dma_channel), &second_descriptor,
words_per_buffer, words_per_sample, first_buffer, second_buffer); words_per_buffer, words_per_sample, first_buffer, second_buffer);
uint8_t trigger_source = I2S_DMAC_ID_RX_0; uint8_t trigger_source = I2S_DMAC_ID_RX_0;
#ifdef SAMD21 #ifdef SAMD21
@ -444,7 +447,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
// Flip back and forth between processing the first and second buffers. // Flip back and forth between processing the first and second buffers.
uint32_t *buffer = first_buffer; uint32_t *buffer = first_buffer;
DmacDescriptor* descriptor = dma_descriptor(dma_channel); DmacDescriptor *descriptor = dma_descriptor(dma_channel);
if (buffers_processed % 2 == 1) { if (buffers_processed % 2 == 1) {
buffer = second_buffer; buffer = second_buffer;
descriptor = &second_descriptor; descriptor = &second_descriptor;
@ -459,7 +462,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
uint16_t value = filter_sample(buffer + i * words_per_sample); uint16_t value = filter_sample(buffer + i * words_per_sample);
if (self->bit_depth == 8) { if (self->bit_depth == 8) {
// Truncate to 8 bits. // Truncate to 8 bits.
((uint8_t*) output_buffer)[values_output] = value >> 8; ((uint8_t *)output_buffer)[values_output] = value >> 8;
} else { } else {
output_buffer[values_output] = value; output_buffer[values_output] = value;
} }
@ -471,7 +474,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
// Compute how many more samples we need, and if the last buffer is the last // Compute how many more samples we need, and if the last buffer is the last
// set of samples needed, adjust the DMA count to only fetch as necessary. // set of samples needed, adjust the DMA count to only fetch as necessary.
remaining_samples_needed = output_buffer_length - values_output; remaining_samples_needed = output_buffer_length - values_output;
if (remaining_samples_needed <= samples_per_buffer*2 && if (remaining_samples_needed <= samples_per_buffer * 2 &&
remaining_samples_needed > samples_per_buffer) { remaining_samples_needed > samples_per_buffer) {
// Adjust the DMA settings for the current buffer, which will be processed // Adjust the DMA settings for the current buffer, which will be processed
// after the other buffer, which is now receiving samples via DMA. // after the other buffer, which is now receiving samples via DMA.
@ -484,7 +487,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se
// Set up to receive the last set of samples (don't include the alternate buffer, now in use). // Set up to receive the last set of samples (don't include the alternate buffer, now in use).
uint32_t samples_needed_for_last_buffer = remaining_samples_needed - samples_per_buffer; uint32_t samples_needed_for_last_buffer = remaining_samples_needed - samples_per_buffer;
descriptor->BTCNT.reg = samples_needed_for_last_buffer * words_per_sample; descriptor->BTCNT.reg = samples_needed_for_last_buffer * words_per_sample;
descriptor->DSTADDR.reg = ((uint32_t) buffer) descriptor->DSTADDR.reg = ((uint32_t)buffer)
+ samples_needed_for_last_buffer * words_per_sample * sizeof(buffer[0]); + samples_needed_for_last_buffer * words_per_sample * sizeof(buffer[0]);
// Break chain to alternate buffer. // Break chain to alternate buffer.

View File

@ -35,7 +35,7 @@
#include "shared-bindings/audioio/AudioOut.h" #include "shared-bindings/audioio/AudioOut.h"
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate/translate.h"
#include "atmel_start_pins.h" #include "atmel_start_pins.h"
#include "hal/include/hal_gpio.h" #include "hal/include/hal_gpio.h"
@ -136,20 +136,21 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
mp_raise_ValueError(translate("Right channel unsupported")); mp_raise_ValueError(translate("Right channel unsupported"));
} }
if (left_channel != &pin_PA02) { if (left_channel != &pin_PA02) {
mp_raise_ValueError(translate("Invalid pin")); raise_ValueError_invalid_pin();
} }
claim_pin(left_channel); claim_pin(left_channel);
#endif #endif
#ifdef SAM_D5X_E5X #ifdef SAM_D5X_E5X
self->right_channel = NULL; self->right_channel = NULL;
if (left_channel != &pin_PA02 && left_channel != &pin_PA05) { if (left_channel != &pin_PA02 && left_channel != &pin_PA05) {
mp_raise_ValueError(translate("Invalid pin for left channel")); raise_ValueError_invalid_pin_name(MP_QSTR_left_channel);
} }
if (right_channel != NULL && right_channel != &pin_PA02 && right_channel != &pin_PA05) { if (right_channel != NULL && right_channel != &pin_PA02 && right_channel != &pin_PA05) {
mp_raise_ValueError(translate("Invalid pin for right channel")); raise_ValueError_invalid_pin_name(MP_QSTR_right_channel);
} }
if (right_channel == left_channel) { if (right_channel == left_channel) {
mp_raise_ValueError(translate("Cannot output both channels on the same pin")); mp_raise_ValueError_varg(translate("%q and %q must be different"),
MP_QSTR_left_channel, MP_QSTR_right_channel);
} }
claim_pin(left_channel); claim_pin(left_channel);
if (right_channel != NULL) { if (right_channel != NULL) {
@ -376,14 +377,13 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
audio_dma_result result = AUDIO_DMA_OK; audio_dma_result result = AUDIO_DMA_OK;
uint32_t sample_rate = audiosample_sample_rate(sample); uint32_t sample_rate = audiosample_sample_rate(sample);
#ifdef SAMD21 #ifdef SAMD21
uint32_t max_sample_rate = 350000; const uint32_t max_sample_rate = 350000;
#endif #endif
#ifdef SAM_D5X_E5X #ifdef SAM_D5X_E5X
uint32_t max_sample_rate = 1000000; const uint32_t max_sample_rate = 1000000;
#endif #endif
if (sample_rate > max_sample_rate) { mp_arg_validate_int_max(sample_rate, max_sample_rate, MP_QSTR_sample_rate);
mp_raise_ValueError_varg(translate("Sample rate too high. It must be less than %d"), max_sample_rate);
}
#ifdef SAMD21 #ifdef SAMD21
result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0, result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0,
false /* output unsigned */, false /* output unsigned */,

View File

@ -34,7 +34,8 @@
#include "samd/sercom.h" #include "samd/sercom.h"
#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/__init__.h"
#include "supervisor/shared/translate.h" #include "shared-bindings/microcontroller/Pin.h"
#include "supervisor/shared/translate/translate.h"
#include "common-hal/busio/__init__.h" #include "common-hal/busio/__init__.h"
@ -76,7 +77,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
self->sda_pin = NO_PIN; self->sda_pin = NO_PIN;
Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux);
if (sercom == NULL) { if (sercom == NULL) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
#if CIRCUITPY_REQUIRE_I2C_PULLUPS #if CIRCUITPY_REQUIRE_I2C_PULLUPS
@ -122,15 +123,12 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
// The maximum frequency divisor gives a clock rate of around 48MHz/2/255 // The maximum frequency divisor gives a clock rate of around 48MHz/2/255
// but set_baudrate does not diagnose this problem. (This is not the // but set_baudrate does not diagnose this problem. (This is not the
// exact cutoff, but no frequency well under 100kHz is available) // exact cutoff, but no frequency well under 100kHz is available)
if (frequency < 95000) { if (frequency < 95000 &&
mp_raise_ValueError(translate("Unsupported baudrate")); i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) {
}
if (i2c_m_sync_set_baudrate(&self->i2c_desc, 0, frequency / 1000) != ERR_NONE) {
reset_pin_number(sda->number); reset_pin_number(sda->number);
reset_pin_number(scl->number); reset_pin_number(scl->number);
common_hal_busio_i2c_deinit(self); common_hal_busio_i2c_deinit(self);
mp_raise_ValueError(translate("Unsupported baudrate")); mp_arg_error_invalid(MP_QSTR_frequency);
} }
self->sda_pin = sda->number; self->sda_pin = sda->number;

View File

@ -25,6 +25,7 @@
*/ */
#include "shared-bindings/busio/SPI.h" #include "shared-bindings/busio/SPI.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "py/mperrno.h" #include "py/mperrno.h"
#include "py/runtime.h" #include "py/runtime.h"
@ -32,8 +33,8 @@
#include "peripheral_clk_config.h" #include "peripheral_clk_config.h"
#include "supervisor/board.h" #include "supervisor/board.h"
#include "supervisor/shared/translate/translate.h"
#include "common-hal/busio/__init__.h" #include "common-hal/busio/__init__.h"
#include "common-hal/microcontroller/Pin.h"
#include "hal/include/hal_gpio.h" #include "hal/include/hal_gpio.h"
#include "hal/include/hal_spi_m_sync.h" #include "hal/include/hal_spi_m_sync.h"
@ -133,7 +134,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
} }
} }
if (sercom == NULL) { if (sercom == NULL) {
mp_raise_ValueError(translate("Invalid pins")); raise_ValueError_invalid_pins();
} }
// Set up SPI clocks on SERCOM. // Set up SPI clocks on SERCOM.

Some files were not shown because too many files have changed in this diff Show More