Switch to ruff like MicroPython

This commit is contained in:
Scott Shawcroft 2025-02-04 11:56:12 -08:00
parent 7f0cc9e7b4
commit e277540f7a
No known key found for this signature in database
338 changed files with 1764 additions and 950 deletions

View file

@ -6,7 +6,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
@ -39,10 +39,23 @@ repos:
- id: formatting
name: Formatting
entry: python3 tools/codeformat.py
types_or: [c, python]
types: [c]
language: system
exclude: |
(?x)^(
lib/tinyusb|
ports/raspberrypi/sdk
)
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.4
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "v2.5.0"
hooks:
- id: pyproject-fmt

163
conf.py
View file

@ -35,12 +35,12 @@ from sphinx.ext import intersphinx
# 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
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('docs'))
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath("docs"))
sys.path.insert(0, os.path.abspath("."))
import shared_bindings_matrix
master_doc = 'docs/index'
master_doc = "docs/index"
# Grab the JSON values to use while building the module support matrix
# in 'shared-bindings/index.rst'
@ -56,55 +56,65 @@ for board, matrix_info in modules_support_matrix.items():
modules_support_matrix_reverse[module].append(board)
modules_support_matrix_reverse = dict(
(module, sorted(boards))
for module, boards in modules_support_matrix_reverse.items()
(module, sorted(boards)) for module, boards in modules_support_matrix_reverse.items()
)
html_context = {
'support_matrix': modules_support_matrix,
'support_matrix_reverse': modules_support_matrix_reverse
"support_matrix": modules_support_matrix,
"support_matrix_reverse": modules_support_matrix_reverse,
}
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = '1.3'
needs_sphinx = "1.3"
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinxcontrib.jquery",
'sphinxcontrib.rsvgconverter',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx_search.extension',
'rstjinja',
'myst_parser',
"sphinxcontrib.rsvgconverter",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx_search.extension",
"rstjinja",
"myst_parser",
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['templates', "docs/templates"]
templates_path = ["templates", "docs/templates"]
# The suffix of source filenames.
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
".rst": "restructuredtext",
".md": "markdown",
}
extensions.append('autoapi.extension')
extensions.append("autoapi.extension")
autoapi_type = 'python'
autoapi_type = "python"
# Uncomment this if debugging autoapi
autoapi_keep_files = True
autoapi_dirs = [os.path.join('circuitpython-stubs', x) for x in os.listdir('circuitpython-stubs') if os.path.exists(os.path.join("circuitpython-stubs", x, "__init__.pyi"))]
autoapi_dirs = [
os.path.join("circuitpython-stubs", x)
for x in os.listdir("circuitpython-stubs")
if os.path.exists(os.path.join("circuitpython-stubs", x, "__init__.pyi"))
]
print("autoapi_dirs", autoapi_dirs)
autoapi_add_toctree_entry = False
autoapi_options = ['members', 'undoc-members', 'private-members', 'show-inheritance', 'special-members', 'show-module-summary']
autoapi_template_dir = 'docs/autoapi/templates'
autoapi_options = [
"members",
"undoc-members",
"private-members",
"show-inheritance",
"special-members",
"show-module-summary",
]
autoapi_template_dir = "docs/autoapi/templates"
autoapi_python_class_content = "both"
autoapi_python_use_implicit_namespaces = True
autoapi_root = "shared-bindings"
@ -115,10 +125,12 @@ autoapi_file_patterns = ["*.pyi"]
# See https://github.com/sphinx-doc/sphinx/issues/12300
suppress_warnings = ["config.cache"]
def autoapi_prepare_jinja_env(jinja_env):
jinja_env.globals['support_matrix_reverse'] = modules_support_matrix_reverse
redirects_file = 'docs/redirects.txt'
def autoapi_prepare_jinja_env(jinja_env):
jinja_env.globals["support_matrix_reverse"] = modules_support_matrix_reverse
redirects_file = "docs/redirects.txt"
# The encoding of source files.
# source_encoding = 'utf-8-sig'
@ -130,8 +142,8 @@ redirects_file = 'docs/redirects.txt'
current_date = time.localtime()
# General information about the project.
project = 'Adafruit CircuitPython'
copyright = f'2014-{current_date.tm_year}, MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)'
project = "Adafruit CircuitPython"
copyright = f"2014-{current_date.tm_year}, MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)"
# These are overwritten on ReadTheDocs.
# The version info for the project you're documenting, acts as replacement for
@ -143,15 +155,11 @@ copyright = f'2014-{current_date.tm_year}, MicroPython & CircuitPython contribut
final_version = ""
git_describe = subprocess.run(
["python", "py/version.py"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8"
["python", "py/version.py"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8"
)
if git_describe.returncode == 0:
git_version = re.search(
r"^\d(?:\.\d){0,2}(?:\-(?:alpha|beta|rc)\.\d+){0,1}",
str(git_describe.stdout)
r"^\d(?:\.\d){0,2}(?:\-(?:alpha|beta|rc)\.\d+){0,1}", str(git_describe.stdout)
)
if git_version:
final_version = git_version[0]
@ -176,14 +184,11 @@ include_patterns = [
# Top directory documentation
"*.rst",
"*.md",
# Docs inherited from microypython (but not templates or README.md, see below)
"docs/**",
# Module documentation
"shared-bindings/**",
"ports/*/bindings/**",
# Port READMEs in various formats
"ports/*/README*",
]
@ -191,7 +196,7 @@ exclude_patterns = ["docs/autoapi/templates/**", "docs/README.md"]
# The reST default role (used for this markup: `text`) to use for all
# documents.
default_role = 'any'
default_role = "any"
# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True
@ -205,7 +210,7 @@ default_role = 'any'
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
@ -223,7 +228,8 @@ rst_epilog = """
# -- Options for HTML output ----------------------------------------------
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
@ -247,12 +253,12 @@ html_theme = 'sphinx_rtd_theme'
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
html_favicon = 'docs/static/favicon.ico'
html_favicon = "docs/static/favicon.ico"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['docs/static']
html_static_path = ["docs/static"]
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
@ -261,7 +267,7 @@ html_static_path = ['docs/static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%d %b %Y'
html_last_updated_fmt = "%d %b %Y"
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
@ -301,7 +307,7 @@ html_last_updated_fmt = '%d %b %Y'
# html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'CircuitPythondoc'
htmlhelp_basename = "CircuitPythondoc"
# -- Options for LaTeX output ---------------------------------------------
@ -309,27 +315,30 @@ htmlhelp_basename = 'CircuitPythondoc'
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# Include 3 levels of headers in PDF ToC
'preamble': r'''
"preamble": r"""
\setcounter{tocdepth}{2}
\hbadness=99999
\hfuzz=20pt
\usepackage{pdflscape}
''',
""",
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
("docs/pdf", 'CircuitPython.tex', 'CircuitPython Documentation',
'CircuitPython Contributors', 'manual'),
(
"docs/pdf",
"CircuitPython.tex",
"CircuitPython Documentation",
"CircuitPython Contributors",
"manual",
),
# Uncomment this if you want to build a PDF of the board -> module support matrix.
# ("shared-bindings/support_matrix", 'SupportMatrix.tex', 'Board Support Matrix',
# 'CircuitPython Contributors', 'manual'),
@ -361,8 +370,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'CircuitPython', 'CircuitPython Documentation',
['CircuitPython contributors'], 1),
("index", "CircuitPython", "CircuitPython Documentation", ["CircuitPython contributors"], 1),
]
# If true, show URL addresses after external links.
@ -375,9 +383,15 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'CircuitPython', 'CircuitPython Documentation',
'CircuitPython contributors', 'CircuitPython', 'Python for Microcontrollers.',
'Miscellaneous'),
(
master_doc,
"CircuitPython",
"CircuitPython Documentation",
"CircuitPython contributors",
"CircuitPython",
"Python for Microcontrollers.",
"Miscellaneous",
),
]
# Documents to append as an appendix to all manuals.
@ -394,10 +408,15 @@ texinfo_documents = [
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"python": ('https://docs.python.org/3/', None),
"register": ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),
"mcp2515": ('https://circuitpython.readthedocs.io/projects/mcp2515/en/latest/', None),
"typing": ('https://circuitpython.readthedocs.io/projects/adafruit-circuitpython-typing/en/latest/', None)}
intersphinx_mapping = {
"python": ("https://docs.python.org/3/", None),
"register": ("https://circuitpython.readthedocs.io/projects/register/en/latest/", None),
"mcp2515": ("https://circuitpython.readthedocs.io/projects/mcp2515/en/latest/", None),
"typing": (
"https://circuitpython.readthedocs.io/projects/adafruit-circuitpython-typing/en/latest/",
None,
),
}
# Adapted from sphinxcontrib-redirects
from sphinx.builders import html as builders
@ -415,20 +434,21 @@ def generate_redirects(app):
return
if not isinstance(app.builder, builders.StandaloneHTMLBuilder):
logging.warn("The 'sphinxcontib-redirects' plugin is only supported "
"by the 'html' builder and subclasses. Skipping...")
logging.warn(
"The 'sphinxcontib-redirects' plugin is only supported "
"by the 'html' builder and subclasses. Skipping..."
)
logging.warn(f"Builder is {app.builder.name} ({type(app.builder)})")
return
with open(path) as redirects:
for line in redirects.readlines():
from_path, to_path = line.rstrip().split(' ')
from_path, to_path = line.rstrip().split(" ")
logging.debug("Redirecting '%s' to '%s'" % (from_path, to_path))
from_path = os.path.splitext(from_path)[0] + ".html"
to_path_prefix = '..%s' % os.path.sep * (
len(from_path.split(os.path.sep)) - 1)
to_path_prefix = "..%s" % os.path.sep * (len(from_path.split(os.path.sep)) - 1)
to_path = to_path_prefix + to_path
redirected_filename = os.path.join(app.builder.outdir, from_path)
@ -436,8 +456,9 @@ def generate_redirects(app):
if not os.path.exists(redirected_directory):
os.makedirs(redirected_directory)
with open(redirected_filename, 'w') as f:
f.write(TEMPLATE % urllib.parse.quote(to_path, '#/'))
with open(redirected_filename, "w") as f:
f.write(TEMPLATE % urllib.parse.quote(to_path, "#/"))
def adafruit_typing_workaround(app, env, node, contnode):
# Sphinx marks a requesting node that uses circuitpython-typing
@ -493,7 +514,7 @@ def setup(app):
app.add_css_file("customstyle.css")
app.add_css_file("filter.css")
app.add_js_file("filter.js")
app.add_config_value('redirects_file', 'redirects', 'env')
app.connect('builder-inited', generate_redirects)
app.connect('missing-reference', adafruit_typing_workaround)
app.add_config_value("redirects_file", "redirects", "env")
app.connect("builder-inited", generate_redirects)
app.connect("missing-reference", adafruit_typing_workaround)
app.add_transform(CoreModuleTransform)

View file

@ -3,11 +3,13 @@
import re
def render_with_jinja(docname, source):
if re.search('^\s*.. jinja$', source[0], re.M):
if re.search("^\s*.. jinja$", source[0], re.M):
return True
return False
def rstjinja(app, docname, source):
"""
Render our pages as a jinja template for fancy templating goodness.
@ -24,18 +26,15 @@ def rstjinja(app, docname, source):
print(f"rendering {docname} as jinja templates")
if app.builder.format == "html":
rendered = app.builder.templates.render_string(
src, app.config.html_context
)
rendered = app.builder.templates.render_string(src, app.config.html_context)
else:
from sphinx.util.template import BaseRenderer
renderer = BaseRenderer()
rendered = renderer.render_string(
src,
app.config.html_context
)
rendered = renderer.render_string(src, app.config.html_context)
source[0] = rendered
def setup(app):
app.connect("source-read", rstjinja)

View file

@ -58,8 +58,7 @@ ALIASES_BY_BOARD = {
ALIASES_BRAND_NAMES = {
"circuitplayground_express_4h": "Adafruit Circuit Playground Express 4-H",
"circuitplayground_express_digikey_pycon2019":
"Circuit Playground Express Digi-Key PyCon 2019",
"circuitplayground_express_digikey_pycon2019": "Circuit Playground Express Digi-Key PyCon 2019",
"edgebadge": "Adafruit EdgeBadge",
"pyportal_pynt": "Adafruit PyPortal Pynt",
"gemma_m0_pycon2018": "Adafruit Gemma M0 PyCon 2018",
@ -119,8 +118,12 @@ def get_bindings():
bindings_modules = []
for d in get_circuitpython_root_dir().glob("ports/*/bindings"):
bindings_modules.extend(module.name for module in d.iterdir() if d.is_dir())
return shared_bindings_modules + bindings_modules + MODULES_NOT_IN_BINDINGS + \
list(ADDITIONAL_MODULES.keys())
return (
shared_bindings_modules
+ bindings_modules
+ MODULES_NOT_IN_BINDINGS
+ list(ADDITIONAL_MODULES.keys())
)
def get_board_mapping():
@ -188,16 +191,23 @@ def get_settings_from_makefile(port_dir, board_name):
This list must explicitly include any setting queried by tools/ci_set_matrix.py.
"""
if os.getenv('NO_BINDINGS_MATRIX'):
return {
'CIRCUITPY_BUILD_EXTENSIONS': '.bin'
}
if os.getenv("NO_BINDINGS_MATRIX"):
return {"CIRCUITPY_BUILD_EXTENSIONS": ".bin"}
contents = subprocess.run(
["make", "-C", port_dir, "-f", "Makefile", f"BOARD={board_name}",
"print-CFLAGS", "print-CIRCUITPY_BUILD_EXTENSIONS",
"print-FROZEN_MPY_DIRS", "print-SRC_PATTERNS",
"print-SRC_SUPERVISOR"],
[
"make",
"-C",
port_dir,
"-f",
"Makefile",
f"BOARD={board_name}",
"print-CFLAGS",
"print-CIRCUITPY_BUILD_EXTENSIONS",
"print-FROZEN_MPY_DIRS",
"print-SRC_PATTERNS",
"print-SRC_SUPERVISOR",
],
encoding="utf-8",
errors="replace",
stdout=subprocess.PIPE,
@ -213,8 +223,8 @@ def get_settings_from_makefile(port_dir, board_name):
settings = {}
for line in contents.stdout.split("\n"):
if line.startswith('CFLAGS ='):
for m in re.findall(r'-D([A-Z][A-Z0-9_]*)=(\d+)', line):
if line.startswith("CFLAGS ="):
for m in re.findall(r"-D([A-Z][A-Z0-9_]*)=(\d+)", line):
settings[m[0]] = m[1]
elif m := re.match(r"^([A-Z][A-Z0-9_]*) = (.*)$", line):
settings[m.group(1)] = m.group(2)
@ -259,11 +269,13 @@ def get_repository_url(directory):
repository_urls[directory] = path
return path
def remove_prefix(s, prefix):
if not s.startswith(prefix):
raise ValueError(f"{s=} does not start with {prefix=}")
return s.removeprefix(prefix)
def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
"""
Go through the list of frozen directories and extract the python modules.
@ -275,7 +287,7 @@ def frozen_modules_from_dirs(frozen_mpy_dirs, withurl):
"""
frozen_modules = []
for frozen_path in filter(lambda x: x, frozen_mpy_dirs.split(" ")):
frozen_path = remove_prefix(frozen_path, '../../')
frozen_path = remove_prefix(frozen_path, "../../")
source_dir = get_circuitpython_root_dir() / frozen_path
url_repository = get_repository_url(source_dir)
for sub in source_dir.glob("*"):
@ -304,9 +316,14 @@ def lookup_setting(settings, key, default=""):
return value
def support_matrix_by_board(use_branded_name=True, withurl=True,
add_port=False, add_chips=False,
add_pins=False, add_branded_name=False):
def support_matrix_by_board(
use_branded_name=True,
withurl=True,
add_port=False,
add_chips=False,
add_pins=False,
add_branded_name=False,
):
"""Compiles a list of the available core modules available for each
board.
"""
@ -335,9 +352,7 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
else:
with open(board_directory / "mpconfigboard.h") as get_name:
board_contents = get_name.read()
board_name_re = re.search(
r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", board_contents
)
board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", board_contents)
if board_name_re:
branded_name = board_name_re.group(1).strip('"')
if '"' in branded_name: # sometimes the closing " is not at line end
@ -352,9 +367,7 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
if add_chips:
with open(board_directory / "mpconfigboard.h") as get_name:
board_contents = get_name.read()
mcu_re = re.search(
r'(?<=MICROPY_HW_MCU_NAME)\s+(.+)', board_contents
)
mcu_re = re.search(r"(?<=MICROPY_HW_MCU_NAME)\s+(.+)", board_contents)
if mcu_re:
mcu = mcu_re.group(1).strip('"')
if '"' in mcu: # in case the closing " is not at line end
@ -363,14 +376,12 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
mcu = ""
with open(board_directory / "mpconfigboard.mk") as get_name:
board_contents = get_name.read()
flash_re = re.search(
r'(?<=EXTERNAL_FLASH_DEVICES)\s+=\s+(.+)', board_contents
)
flash_re = re.search(r"(?<=EXTERNAL_FLASH_DEVICES)\s+=\s+(.+)", board_contents)
if flash_re:
# deal with the variability in the way multiple flash chips
# are denoted. We want them to end up as a quoted,
# comma separated string
flash = flash_re.group(1).replace('"','')
flash = flash_re.group(1).replace('"', "")
flash = f'"{flash}"'
else:
flash = ""
@ -406,18 +417,13 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
if "CIRCUITPY_BUILD_EXTENSIONS" in settings:
board_extensions = settings["CIRCUITPY_BUILD_EXTENSIONS"]
if isinstance(board_extensions, str):
board_extensions = [
extension.strip()
for extension in board_extensions.split(",")
]
board_extensions = [extension.strip() for extension in board_extensions.split(",")]
else:
raise OSError(f"Board extensions undefined: {board_name}.")
frozen_modules = []
if "FROZEN_MPY_DIRS" in settings:
frozen_modules = frozen_modules_from_dirs(
settings["FROZEN_MPY_DIRS"], withurl
)
frozen_modules = frozen_modules_from_dirs(settings["FROZEN_MPY_DIRS"], withurl)
if frozen_modules:
frozen_modules.sort()
@ -437,12 +443,7 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
board_info["flash"] = flash
if add_pins:
board_info["pins"] = pins
board_matrix = [
(
board_name,
board_info
)
]
board_matrix = [(board_name, board_info)]
if board_id in ALIASES_BY_BOARD:
for alias in ALIASES_BY_BOARD[board_id]:
if use_branded_name:
@ -464,16 +465,10 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
board_info["flash"] = flash
if add_pins:
board_info["pins"] = pins
board_matrix.append(
(
alias,
board_info
)
)
board_matrix.append((alias, board_info))
return board_matrix # this is now a list of (board,modules)
board_mapping = get_board_mapping()
real_boards = []
for board in board_mapping:
@ -483,9 +478,7 @@ def support_matrix_by_board(use_branded_name=True, withurl=True,
mapped_exec = executor.map(support_matrix, real_boards)
# flatmap with comprehensions
boards = dict(
sorted(
[board for matrix in mapped_exec for board in matrix], key=lambda x: x[0]
)
sorted([board for matrix in mapped_exec for board in matrix], key=lambda x: x[0])
)
return boards

View file

@ -74,6 +74,7 @@ MP_PROPERTY_GETTER(samd_clock_frequency_obj,
//| calibration: int
//| """Clock calibration. Not all clocks can be calibrated."""
//|
//|
static mp_obj_t samd_clock_get_calibration(mp_obj_t self_in) {
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int_from_uint(clock_get_calibration(self->type, self->index));

View file

@ -11,6 +11,7 @@
#include "bindings/samd/Clock.h"
//| """SAMD implementation settings"""
//|
//| """:mod:`samd.clock` --- samd clock names
//| --------------------------------------------------------

View file

@ -1,380 +0,0 @@
# This file is part of the CircuitPython project: https://circuitpython.org
#
# SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# This helper generates the pinout tables in ../README.rst.
import os
import os.path
pins = [
"PA00",
"PA01",
"PA02",
"PA03",
"PB08",
"PB09",
"PA04",
"PA05",
"PA06",
"PA07",
"PA08",
"PA09",
"PA10",
"PA11",
"PB10",
"PB11",
"PA12",
"PA13",
"PA14",
"PA15",
"PA16",
"PA17",
"PA18",
"PA19",
"PA20",
"PA21",
"PA22",
"PA23",
"PA24",
"PA25",
"PB22",
"PB23",
"PA27",
"PA28",
"PA29",
"PA30",
"PA31",
"PB02",
"PB03",
]
# Dictionary keys: [board][pin] = list of pin names
mapping = {}
QSTR = " { MP_OBJ_NEW_QSTR(MP_QSTR_"
for board in os.listdir("boards"):
if not os.path.isdir("boards/" + board):
continue
mapping[board] = {}
with open("boards/" + board + "/pins.c", "r") as f:
for line in f:
if line.startswith(QSTR):
board_name, _, pin = line.split(")")
board_name = board_name[len(QSTR) :]
pin = pin[-8:-4]
if pin not in mapping[board]:
mapping[board][pin] = []
mapping[board][pin].append(board_name)
column_width = {}
for board in mapping:
column_width[board] = len(board)
for pin in mapping[board]:
l = len(" / ".join("``" + x + "``" for x in mapping[board][pin]))
column_width[board] = max(l, column_width[board])
first_column_width = len("`microcontroller.pin`")
print("=" * first_column_width, end="")
total_board_width = -2
for board in column_width:
column = " " + "=" * column_width[board]
total_board_width += len(column)
print(column, end="")
print()
print("`microcontroller.pin` `board`")
print("-" * first_column_width + " " + "-" * total_board_width)
print("Datasheet".ljust(first_column_width), end="")
for board in column_width:
print(" " + board.ljust(column_width[board]), end="")
print()
print("=" * first_column_width, end="")
for board in column_width:
column = " " + "=" * column_width[board]
print(column, end="")
print()
for pin in pins:
print(pin.ljust(first_column_width), end="")
for board in column_width:
if pin in mapping[board]:
names = " / ".join("``" + x + "``" for x in mapping[board][pin])
print(" " + names.ljust(column_width[board]), end="")
else:
print(" " * (column_width[board] + 2), end="")
print()
print("=" * first_column_width, end="")
for board in column_width:
column = " " + "=" * column_width[board]
print(column, end="")
print()
print()
print()
# Generate pin capabilities too.
ALL_BUT_USB = list(pins)
ALL_BUT_USB.remove("PA24")
ALL_BUT_USB.remove("PA25")
# dictionary is [module][class] = [pins]
capabilities = {
"analogio": {
"AnalogIn": [
"PA02",
"PA03",
"PB08",
"PB09",
"PA04",
"PA05",
"PA06",
"PA07",
"PA08",
"PA09",
"PA10",
"PA11",
"PB02",
"PB03",
],
"AnalogOut": ["PA02"],
},
"audioio": {"AudioOut": ["PA02"]},
"bitbangio": {"I2C": ALL_BUT_USB, "SPI": ALL_BUT_USB},
"busio": {
"I2C - SDA": ["PA00", "PB08", "PA08", "PA12", "PA16", "PA22", "PB02"], # SERCOM pad 0
"I2C - SCL": ["PA01", "PB09", "PA09", "PA13", "PA17", "PA23", "PB03"], # SERCOM pad 1
"SPI - MISO": [
"PA00",
"PA01",
"PB08",
"PB09",
"PA04",
"PA05",
"PA06",
"PA07",
"PA08",
"PA09",
"PA10",
"PA11",
"PB10",
"PB11",
"PA12",
"PA13",
"PA14",
"PA15",
"PA16",
"PA17",
"PA18",
"PA19",
"PA20",
"PA21",
"PA22",
"PA23",
"PB22",
"PB23",
"PA30",
"PA31",
"PB02",
"PB03",
], # any SERCOM pad
"SPI - MOSI": [
"PA00",
"PB08",
"PA04",
"PA06",
"PA08",
"PA10",
"PA11",
"PB10",
"PB11",
"PA14",
"PA15",
"PA16",
"PA18",
"PA19",
"PA20",
"PA21",
"PA22",
"PB22",
"PB23",
"PA30",
"PA31",
"PB02",
], # any pad but 1
"SPI - SCK": [
"PA01",
"PB09",
"PA05",
"PA07",
"PA09",
"PA11",
"PB11",
"PA13",
"PA15",
"PA17",
"PA19",
"PA21",
"PA23",
"PB23",
"PA31",
"PB03",
], # 1 or 3
"UART - RX": [
"PA00",
"PA01",
"PB08",
"PB09",
"PA04",
"PA05",
"PA06",
"PA07",
"PA08",
"PA09",
"PA10",
"PA11",
"PB10",
"PB11",
"PA12",
"PA13",
"PA14",
"PA15",
"PA16",
"PA17",
"PA18",
"PA19",
"PA20",
"PA21",
"PA22",
"PA23",
"PB22",
"PB23",
"PA30",
"PA31",
"PB02",
"PB03",
], # any pad
"UART - TX": [
"PA00",
"PB08",
"PA04",
"PA06",
"PA08",
"PA10",
"PB10",
"PA12",
"PA14",
"PA16",
"PA18",
"PA20",
"PA22",
"PB22",
"PA30",
"PB02",
], # pad 0 or 2
},
"digitalio": {"DigitalInOut": ALL_BUT_USB},
"onewireio": {"OneWire": ALL_BUT_USB},
"pulseio": {
"PulseIn": ALL_BUT_USB,
"PWMOut": [
"PA01",
"PB09",
"PA04",
"PA05",
"PA06",
"PA07",
"PA08",
"PA09",
"PA10",
"PA11",
"PB10",
"PB11",
"PA12",
"PA13",
"PA14",
"PA15",
"PA16",
"PA17",
"PA18",
"PA19",
"PA20",
"PA21",
"PA22",
"PA23",
"PA30",
"PA31",
],
},
"ps2io": {"Ps2": ALL_BUT_USB},
"touchio": {
"TouchIn": ["PA02", "PA03", "PB08", "PB09", "PA04", "PA05", "PA06", "PA07", "PB02", "PB03"]
},
}
column_width = {}
for module in capabilities:
for c in capabilities[module]:
column_width[module + c] = max(len("**Yes**"), len(c))
module_width = {}
for module in capabilities:
module_width[module] = 0
for c in capabilities[module]:
module_width[module] += column_width[module + c] + 2
module_width[module] -= 2
if module_width[module] < (len(module) + 2):
column_width[module + c] += len(module) + 2 - module_width[module]
module_width[module] = len(module) + 2
first_column_width = len("`microcontroller.pin`")
print("=" * first_column_width, end="")
for module in capabilities:
for c in capabilities[module]:
print(" " + "=" * column_width[module + c], end="")
print()
print("`microcontroller.pin`", end="")
for module in capabilities:
print(" " + ("`" + module + "`").ljust(module_width[module]), end="")
print()
print("-" * first_column_width, end="")
for module in capabilities:
print(" " + "-" * module_width[module], end="")
print()
print("Datasheet".ljust(first_column_width), end="")
for module in capabilities:
for c in capabilities[module]:
print(" " + c.ljust(column_width[module + c]), end="")
print()
print("=" * first_column_width, end="")
for module in capabilities:
for c in capabilities[module]:
print(" " + "=" * column_width[module + c], end="")
print()
for pin in pins:
print(pin.ljust(first_column_width), end="")
for module in capabilities:
for c in capabilities[module]:
if pin in capabilities[module][c]:
print(" " + "**Yes**".ljust(column_width[module + c]), end="")
else:
print(" " * (column_width[module + c] + 2), end="")
print()
print("=" * first_column_width, end="")
for module in capabilities:
for c in capabilities[module]:
print(" " + "=" * column_width[module + c], end="")
print()

View file

@ -15,8 +15,8 @@ def defines(name, suffix):
{{&pin_{pin}, {instance}, PIN_{pin}, {pinmux} & 0xffff}},
#endif"""
)
print(f"{{NULL, 0, 0}}")
print(f"}};")
print("{NULL, 0, 0}")
print("};")
print()

View file

@ -14,8 +14,8 @@ def defines(name, function):
{{&pin_{pin}, {instance}, PIN_{pin}, {pinmux} & 0xffff}},
#endif"""
)
print(f"{{NULL, 0, 0}}")
print(f"}};")
print("{NULL, 0, 0}")
print("};")
print()

View file

@ -26,6 +26,7 @@
//|
//| A Framebuffer is often used in conjunction with a
//| `framebufferio.FramebufferDisplay`."""
//|
static mp_obj_t videocore_framebuffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_width, ARG_height, };
@ -51,6 +52,7 @@ static mp_obj_t videocore_framebuffer_make_new(const mp_obj_type_t *type, size_t
//| rgbmatrix instance. After deinitialization, no further operations
//| may be performed."""
//| ...
//|
static mp_obj_t videocore_framebuffer_deinit(mp_obj_t self_in) {
videocore_framebuffer_obj_t *self = (videocore_framebuffer_obj_t *)self_in;
common_hal_videocore_framebuffer_deinit(self);
@ -79,6 +81,7 @@ MP_PROPERTY_GETTER(videocore_framebuffer_width_obj,
//| height: int
//| """The height of the display, in pixels"""
//|
//|
static mp_obj_t videocore_framebuffer_get_height(mp_obj_t self_in) {
videocore_framebuffer_obj_t *self = (videocore_framebuffer_obj_t *)self_in;
check_for_deinit(self);

View file

@ -595,11 +595,11 @@ def main():
if subprocess.call("cd " + sys.path[0] + "; ./reset_board.sh", shell=True) == 0:
print("auto reset board success!!")
do_wait_reset = False
bootrom_msg = writer.cancel_autoboot()
writer.cancel_autoboot()
if ConfigArgs.DTR_RESET:
do_wait_reset = False
bootrom_msg = writer.cancel_autoboot()
writer.cancel_autoboot()
if ConfigArgs.WAIT_RESET is False and do_wait_reset is True:
rx = writer.recv()
@ -617,7 +617,7 @@ def main():
# Wait to reset the board
print("Please press RESET button on target board")
sys.stdout.flush()
bootrom_msg = writer.cancel_autoboot()
writer.cancel_autoboot()
# Remove files
if ConfigArgs.ERASE_NAME:

View file

@ -70,6 +70,7 @@
//| :param framebuffer_count: The number of framebuffers (1 for single-buffered and 2 for double-buffered)
//| :param grab_mode: When to grab a new frame
//| """
//|
static mp_obj_t espcamera_camera_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_data_pins, ARG_pixel_clock_pin, ARG_vsync_pin, ARG_href_pin, ARG_i2c, ARG_external_clock_pin, ARG_external_clock_frequency, ARG_powerdown_pin, ARG_reset_pin, ARG_pixel_format, ARG_frame_size, ARG_jpeg_quality, ARG_framebuffer_count, ARG_grab_mode, NUM_ARGS };
static const mp_arg_t allowed_args[] = {
@ -143,6 +144,7 @@ static mp_obj_t espcamera_camera_make_new(const mp_obj_type_t *type, size_t n_ar
//| def deinit(self) -> None:
//| """Deinitialises the camera and releases all memory resources for reuse."""
//| ...
//|
static mp_obj_t espcamera_camera_deinit(mp_obj_t self_in) {
espcamera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_espcamera_camera_deinit(self);
@ -159,12 +161,14 @@ static void check_for_deinit(espcamera_camera_obj_t *self) {
//| def __enter__(self) -> Camera:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t espcamera_camera_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
return espcamera_camera_deinit(args[0]);
@ -173,6 +177,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espcamera_camera___exit___obj, 4, 4,
//| frame_available: bool
//| """True if a frame is available, False otherwise"""
//|
static mp_obj_t espcamera_camera_frame_available_get(const mp_obj_t self_in) {
espcamera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -193,6 +198,7 @@ MP_PROPERTY_GETTER(espcamera_camera_frame_available_obj,
//| If `pixel_format` is `PixelFormat.JPEG`, the returned value is a read-only `memoryview`.
//| Otherwise, the returned value is a read-only `displayio.Bitmap`.
//| """
//|
static mp_obj_t espcamera_camera_take(size_t n_args, const mp_obj_t *args) {
espcamera_camera_obj_t *self = MP_OBJ_TO_PTR(args[0]);
mp_float_t timeout = n_args < 2 ? MICROPY_FLOAT_CONST(0.25) : mp_obj_get_float(args[1]);
@ -229,6 +235,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espcamera_camera_take_obj, 1, 2, espc
//| the other properties to set, they are set together in a single function call.
//|
//| If an argument is unspecified or None, then the setting is unchanged."""
//|
static mp_obj_t espcamera_camera_reconfigure(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
espcamera_camera_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@ -912,6 +919,7 @@ MP_PROPERTY_GETTER(espcamera_camera_grab_mode_obj,
//| framebuffer_count: int
//| """True if double buffering is used"""
//|
//|
static mp_obj_t espcamera_camera_get_framebuffer_count(const mp_obj_t self_in) {
espcamera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -26,6 +26,7 @@
//|
//| """
//|
//|
//| class GrabMode:
//| """Controls when a new frame is grabbed."""
@ -36,6 +37,7 @@
//| LATEST: GrabMode
//| """Except when 1 frame buffer is used, queue will always contain the last ``fb_count`` frames"""
//|
//|
MAKE_ENUM_VALUE(espcamera_grab_mode_type, grab_mode, WHEN_EMPTY, CAMERA_GRAB_WHEN_EMPTY);
MAKE_ENUM_VALUE(espcamera_grab_mode_type, grab_mode, LATEST, CAMERA_GRAB_LATEST);
@ -65,6 +67,7 @@ camera_grab_mode_t validate_grab_mode(mp_obj_t obj, qstr arg_name) {
//| JPEG: PixelFormat
//| """A compressed format"""
//|
//|
MAKE_ENUM_VALUE(espcamera_pixel_format_type, pixel_format, RGB565, PIXFORMAT_RGB565);
MAKE_ENUM_VALUE(espcamera_pixel_format_type, pixel_format, GRAYSCALE, PIXFORMAT_GRAYSCALE);
@ -153,6 +156,7 @@ pixformat_t validate_pixel_format(mp_obj_t obj, qstr arg_name) {
//| QSXGA: FrameSize
//| """2560x1920"""
//|
//|
MAKE_ENUM_VALUE(espcamera_frame_size_type, frame_size, R96X96, FRAMESIZE_96X96);
MAKE_ENUM_VALUE(espcamera_frame_size_type, frame_size, R240X240, FRAMESIZE_240X240);
@ -222,6 +226,7 @@ framesize_t validate_frame_size(mp_obj_t obj, qstr arg_name) {
//| GAIN_64X: GainCeiling
//| GAIN_128X: GainCeiling
//|
//|
MAKE_ENUM_VALUE(espcamera_gain_ceiling_type, gain_ceiling, GAIN_2X, GAINCEILING_2X);
MAKE_ENUM_VALUE(espcamera_gain_ceiling_type, gain_ceiling, GAIN_4X, GAINCEILING_4X);

View file

@ -20,11 +20,13 @@
//| that could be implemented by other frameworks. It should only include ESP-IDF specific
//| things."""
//|
//|
//| def heap_caps_get_total_size() -> int:
//| """Return the total size of the ESP-IDF, which includes the CircuitPython heap."""
//| ...
//|
//|
static mp_obj_t espidf_heap_caps_get_total_size(void) {
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_total_size(MALLOC_CAP_8BIT));
@ -35,6 +37,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_total_size_obj, espidf_heap_caps_
//| """Return total free memory in the ESP-IDF heap."""
//| ...
//|
//|
static mp_obj_t espidf_heap_caps_get_free_size(void) {
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_free_size(MALLOC_CAP_8BIT));
@ -45,6 +48,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_free_size_obj, espidf_heap_caps_g
//| """Return the size of largest free memory block in the ESP-IDF heap."""
//| ...
//|
//|
static mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
return MP_OBJ_NEW_SMALL_INT(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
@ -58,6 +62,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_he
//| layout of data in nvs has changed. The old data will be lost when you perform this operation.
//| """
//|
//|
static mp_obj_t espidf_erase_nvs(void) {
ESP_ERROR_CHECK(nvs_flash_deinit());
ESP_ERROR_CHECK(nvs_flash_erase());
@ -84,6 +89,7 @@ static void espidf_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_pr
//|
//| ...
//|
//|
MP_DEFINE_CONST_OBJ_TYPE(
mp_type_espidf_IDFError,
MP_QSTR_IDFError,
@ -99,6 +105,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
//|
//| ...
//|
//|
NORETURN void mp_raise_espidf_MemoryError(void) {
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
}
@ -116,6 +123,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
//| def get_total_psram() -> int:
//| """Returns the number of bytes of psram detected, or 0 if psram is not present or not configured"""
//|
//|
static mp_obj_t espidf_get_total_psram(void) {
return MP_OBJ_NEW_SMALL_INT(common_hal_espidf_get_total_psram());
}

View file

@ -41,6 +41,7 @@ static void espnow_check_for_deinit(espnow_obj_t *self) {
//| `wifi_phy_rate_t <https://docs.espressif.com/projects/esp-idf/en/release-v4.4/esp32/api-reference/network/esp_wifi.html#_CPPv415wifi_phy_rate_t>`_
//| """
//| ...
//|
static mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_buffer_size, ARG_phy_rate };
static const mp_arg_t allowed_args[] = {
@ -71,6 +72,7 @@ static mp_obj_t espnow_make_new(const mp_obj_type_t *type, size_t n_args, size_t
//| def deinit(self) -> None:
//| """Deinitializes ESP-NOW and releases it for another program."""
//| ...
//|
static mp_obj_t espnow_deinit(mp_obj_t self_in) {
espnow_obj_t *self = MP_OBJ_TO_PTR(self_in);
espnow_check_for_deinit(self);
@ -82,12 +84,14 @@ static MP_DEFINE_CONST_FUN_OBJ_1(espnow_deinit_obj, espnow_deinit);
//| def __enter__(self) -> ESPNow:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t espnow_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
return espnow_deinit(args[0]);
@ -109,6 +113,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow___exit___obj, 4, 4, espnow_obj
//| :param Peer peer: Send message to this peer. If `None`, send to all registered peers.
//| """
//| ...
//|
static mp_obj_t espnow_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_message, ARG_peer };
static const mp_arg_t allowed_args[] = {
@ -143,6 +148,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(espnow_send_obj, 2, espnow_send);
//|
//| :returns: An `ESPNowPacket` if available in the buffer, otherwise `None`."""
//| ...
//|
static mp_obj_t espnow_read(mp_obj_t self_in) {
espnow_obj_t *self = MP_OBJ_TO_PTR(self_in);
espnow_check_for_deinit(self);
@ -204,6 +210,7 @@ MP_PROPERTY_GETTER(espnow_read_failure_obj,
//|
//| :param ReadableBuffer pmk: The ESP-NOW Primary Master Key (length = 16 bytes)."""
//| ...
//|
static mp_obj_t espnow_set_pmk(mp_obj_t self_in, mp_obj_t key) {
espnow_obj_t *self = MP_OBJ_TO_PTR(self_in);
espnow_check_for_deinit(self);
@ -325,6 +332,7 @@ static const mp_stream_p_t espnow_stream_p = {
//| """Return the number of `bytes` available to read. Used to implement ``len()``."""
//| ...
//|
//|
static mp_obj_t espnow_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
espnow_obj_t *self = MP_OBJ_TO_PTR(self_in);
espnow_check_for_deinit(self);

View file

@ -21,6 +21,7 @@
//| time: int
//| """The time in milliseconds since the device last booted when the packet was received."""
//|
//|
const mp_obj_namedtuple_type_t espnow_packet_type_obj = {
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ESPNowPacket),

View file

@ -32,6 +32,7 @@
//| :param bool encrypted: Whether or not to use encryption.
//| """
//| ...
//|
static mp_obj_t espnow_peer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_mac, ARG_lmk, ARG_channel, ARG_interface, ARG_encrypted };
static const mp_arg_t allowed_args[] = {
@ -167,6 +168,7 @@ MP_PROPERTY_GETSET(espnow_peer_interface_obj,
//| encrypted: bool
//| """Whether or not to use encryption."""
//|
//|
static mp_obj_t espnow_peer_get_encrypted(const mp_obj_t self_in) {
espnow_peer_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(self->peer_info.encrypt);

View file

@ -21,6 +21,7 @@
//| def __init__(self) -> None:
//| """You cannot create an instance of `Peers`."""
//| ...
//|
//| def append(self, peer: Peer) -> None:
//| """Append peer.
@ -28,6 +29,7 @@
//| :param Peer peer: The peer object to append.
//| """
//| ...
//|
static mp_obj_t espnow_peers_append(mp_obj_t self_in, mp_obj_t arg) {
espnow_peer_obj_t *peer = MP_OBJ_TO_PTR(mp_arg_validate_type(arg, &espnow_peer_type, MP_QSTR_Peer));
CHECK_ESP_RESULT(esp_now_add_peer(&peer->peer_info));
@ -43,6 +45,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(espnow_peers_append_obj, espnow_peers_append);
//| """
//| ...
//|
//|
static mp_obj_t espnow_peers_remove(mp_obj_t self_in, mp_obj_t arg) {
espnow_peer_obj_t *peer = MP_OBJ_TO_PTR(mp_arg_validate_type(arg, &espnow_peer_type, MP_QSTR_Peer));
CHECK_ESP_RESULT(esp_now_del_peer(peer->peer_info.peer_addr));

View file

@ -51,6 +51,7 @@
//| for packet in packets:
//| print(packet)
//| """
//|
//| ...
//|

View file

@ -20,6 +20,7 @@ MAKE_ENUM_VALUE(espulp_architecture_type, architecture, RISCV, RISCV);
//| RISCV: Architecture
//| """The ULP RISC-V Coprocessor."""
//|
//|
MAKE_ENUM_MAP(espulp_architecture) {
MAKE_ENUM_MAP_ENTRY(architecture, FSM),
MAKE_ENUM_MAP_ENTRY(architecture, RISCV),

View file

@ -22,6 +22,7 @@
//| :param Architecture arch: The ulp arch.
//| """
//| ...
//|
static mp_obj_t espulp_ulp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_arch };
static const mp_arg_t allowed_args[] = {
@ -49,6 +50,7 @@ static void check_for_deinit(espulp_ulp_obj_t *self) {
//| def deinit(self) -> None:
//| """Deinitialises the ULP and releases it for another program."""
//| ...
//|
static mp_obj_t espulp_ulp_deinit(mp_obj_t self_in) {
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_espulp_ulp_deinit(self);
@ -59,12 +61,14 @@ static MP_DEFINE_CONST_FUN_OBJ_1(espulp_ulp_deinit_obj, espulp_ulp_deinit);
//| def __enter__(self) -> ULP:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t espulp_ulp_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
return espulp_ulp_deinit(args[0]);
@ -79,6 +83,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espulp_ulp___exit___obj, 4, 4, espulp
//| By default, the value stored in period index 0 is used.
//| :param int period_us: The wakeup period given in microseconds."""
//| ...
//|
static mp_obj_t espulp_ulp_set_wakeup_period(mp_obj_t self_in, mp_obj_t period_index, mp_obj_t period_us) {
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -95,7 +100,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(espulp_ulp_set_wakeup_period_obj, espulp_ulp_se
//| program: ReadableBuffer,
//| *,
//| entrypoint: int = 0,
//| pins: Sequence[microcontroller.Pin] = ()
//| pins: Sequence[microcontroller.Pin] = (),
//| ) -> None:
//| """Loads the program into ULP memory and then runs the program.
//|
@ -107,6 +112,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(espulp_ulp_set_wakeup_period_obj, espulp_ulp_se
//| :param Sequence[microcontroller.Pin] pins: Pins made available to the ULP.
//| The pins are claimed and not reset until `halt()` is called."""
//| ...
//|
static mp_obj_t espulp_ulp_run(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
check_for_deinit(self);
@ -155,6 +161,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(espulp_ulp_run_obj, 2, espulp_ulp_run);
//| Note: for the FSM ULP, a running ULP program is not actually interrupted.
//| Instead, only the wakeup timer is stopped."""
//| ...
//|
static mp_obj_t espulp_ulp_halt(mp_obj_t self_in) {
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -167,6 +174,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(espulp_ulp_halt_obj, espulp_ulp_halt);
//| arch: Architecture
//| """The ulp architecture. (read-only)"""
//|
//|
static mp_obj_t espulp_ulp_get_arch(mp_obj_t self_in) {
espulp_ulp_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -20,6 +20,7 @@
//| :param ULP ulp: The ulp instance"""
//| ...
//|
//|
static mp_obj_t espulp_ulpalarm_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_ulp };
static const mp_arg_t allowed_args[] = {

View file

@ -33,14 +33,17 @@
//| print(shared_mem[0])
//| # ulp.halt()
//| """
//|
//| ...
//|
//|
//| def get_rtc_gpio_number(pin: microcontroller.Pin) -> Optional[int]:
//| """Return the RTC GPIO number of the given pin or None if not connected
//| to RTC GPIO."""
//| ...
//|
//|
static mp_obj_t espulp_get_rtc_gpio_number(mp_obj_t pin_obj) {
const mcu_pin_obj_t *pin = validate_obj_is_pin(pin_obj, MP_QSTR_pin);

View file

@ -29,7 +29,7 @@ def validate(sdk_config, circuitpy_config):
if circuitpy_config.get(var):
with open(partition_table) as f:
content = f.read()
if not "ota_1" in content:
if "ota_1" not in content:
raise SystemExit(
f"{var} is incompatible with {partition_table=} (no ota_1 partition)"
)

View file

@ -157,7 +157,7 @@ def sym_default(sym):
default=False,
help="Updates the sdkconfigs outside of the board directory.",
)
def update(debug, board, update_all):
def update(debug, board, update_all): # noqa: C901: too complex
"""Updates related sdkconfig files based on the build directory version that
was likely modified by menuconfig."""
@ -202,7 +202,7 @@ def update(debug, board, update_all):
kconfig_path = pathlib.Path(f"build-{board}/esp-idf/kconfigs.in")
kconfig_path = pathlib.Path(f"esp-idf/Kconfig")
kconfig_path = pathlib.Path("esp-idf/Kconfig")
kconfig = kconfiglib.Kconfig(kconfig_path)
input_config = pathlib.Path(f"build-{board}/esp-idf/sdkconfig")
@ -230,7 +230,7 @@ def update(debug, board, update_all):
sdkconfigs.extend((flash_size_config, flash_mode_config, flash_freq_config))
if psram_size != "0":
psram_config = pathlib.Path(f"esp-idf-config/sdkconfig-psram.defaults")
psram_config = pathlib.Path("esp-idf-config/sdkconfig-psram.defaults")
psram_size_config = pathlib.Path(f"esp-idf-config/sdkconfig-psram-{psram_size}.defaults")
psram_mode_config = pathlib.Path(f"esp-idf-config/sdkconfig-psram-{psram_mode}.defaults")
psram_freq_config = pathlib.Path(f"esp-idf-config/sdkconfig-psram-{psram_freq}.defaults")
@ -238,7 +238,7 @@ def update(debug, board, update_all):
target_config = pathlib.Path(f"esp-idf-config/sdkconfig-{target}.defaults")
sdkconfigs.append(target_config)
if ble_enabled:
ble_config = pathlib.Path(f"esp-idf-config/sdkconfig-ble.defaults")
ble_config = pathlib.Path("esp-idf-config/sdkconfig-ble.defaults")
sdkconfigs.append(ble_config)
board_config = pathlib.Path(f"boards/{board}/sdkconfig")
# Don't include the board file in cp defaults. The board may have custom

View file

@ -288,7 +288,7 @@ for device in devices:
pins_h.append("// Pads can be reset. Other pins like USB cannot be.")
pins_h.append(f"#define PAD_COUNT ({pin_number})")
pins_h.append(f"#define PIN_COUNT (PAD_COUNT + {len(usb_pins)})")
pins_h.append(f"extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT];")
pins_h.append("extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT];")
pins_h.append("")
out_dir.mkdir(exist_ok=True)
@ -307,7 +307,7 @@ for device in devices:
"",
]
for ptype in SIGNALS:
for ptype, signals in SIGNALS:
instances = all_peripherals[ptype]
short_name = ptype.lower()
if short_name.startswith("lp"):
@ -323,7 +323,7 @@ for device in devices:
f"{ptype}_Type *const mcu_{short_name}_banks[{len(instances)}] = {{ {joined_instances} }};"
)
periph_c.append("")
for signal in SIGNALS[ptype]:
for signal in signals:
pin_count = 0
for instance in instances:
if instance not in peripheral_inputs or signal not in peripheral_inputs[instance]:
@ -357,8 +357,8 @@ for device in devices:
periph_c.append(
f" PERIPH_PIN({instance_number}, {alt}, {select_input}, {input_value}, &pin_{pin_name}),"
)
periph_c.append(f"}};")
periph_c.append(f"")
periph_c.append("};")
periph_c.append("")
periph_h.append("")
pwm_outputs.sort(key=lambda x: x[:3])
@ -373,7 +373,7 @@ for device in devices:
periph_c.append(
f" PWM_PIN(PWM{pwm_instance}, kPWM_Module_{module}, kPWM_Pwm{channel}, IOMUXC_{pin_name}_{connection}, &pin_{pin_name}),"
)
periph_c.append(f"}};")
periph_c.append("};")
periph_c.append("")
periph_h.append("")

View file

@ -35,6 +35,7 @@ void bindings_cyw43_wifi_enforce_pm(void) {
//| in :py:mod:`board`. A `CywPin` can be used as a DigitalInOut, but not with other
//| peripherals such as `PWMOut`."""
//|
//|
MP_DEFINE_CONST_OBJ_TYPE(
cyw43_pin_type,
MP_QSTR_CywPin,
@ -51,6 +52,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
//| PM_DISABLED: int
//| """Disable power management and always use highest power mode. CircuitPython sets this value at reset time, because it provides the best connectivity reliability."""
//|
//|
//| def set_power_management(value: int) -> None:
//| """Set the power management register
//|
@ -80,6 +82,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
//| usage.
//| """
//|
//|
static mp_obj_t cyw43_set_power_management(const mp_obj_t value_in) {
mp_int_t value = mp_obj_get_int(value_in);
power_management_value = value;
@ -91,6 +94,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(cyw43_set_power_management_obj, cyw43_set_power
//| def get_power_management() -> int:
//| """Retrieve the power management register"""
//|
//|
static mp_obj_t cyw43_get_power_management() {
return mp_obj_new_int(power_management_value);
}

View file

@ -85,6 +85,7 @@
//| :param int color_depth: the color depth of the framebuffer in bits. 1, 2 for grayscale
//| and 4 (RP2350 only), 8 or 16 for color
//| """
//|
static mp_obj_t picodvi_framebuffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_width, ARG_height, ARG_clk_dp, ARG_clk_dn, ARG_red_dp, ARG_red_dn, ARG_green_dp,
@ -136,6 +137,7 @@ static mp_obj_t picodvi_framebuffer_make_new(const mp_obj_type_t *type, size_t n
//| `picodvi.Framebuffer` instance. After deinitialization, no further operations
//| may be performed."""
//| ...
//|
static mp_obj_t picodvi_framebuffer_deinit(mp_obj_t self_in) {
picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in;
common_hal_picodvi_framebuffer_deinit(self);
@ -164,6 +166,7 @@ MP_PROPERTY_GETTER(picodvi_framebuffer_width_obj,
//| height: int
//| """The width of the framebuffer, in pixels. It may be doubled for output."""
//|
//|
static mp_obj_t picodvi_framebuffer_get_height(mp_obj_t self_in) {
picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in;
check_for_deinit(self);

View file

@ -32,6 +32,7 @@
//| MovStatusType_piov0 = Literal["txfifo"]
//| """A type representing the string ``"txfifo"``. This value is supported on RP2350 and RP2040. For type-checking only, not actually defined in CircuitPython."""
//|
//|
//| class StateMachine:
//| """A single PIO StateMachine
//|
@ -161,6 +162,7 @@
//| :param MovStatusType mov_status_n: The FIFO depth or IRQ the ``mov status`` instruction checks for. For ``mov_status irq`` this includes the encoding of the ``next``/``prev`` selection bits.
//| """
//| ...
//|
static int one_of(qstr_short_t what, mp_obj_t arg, size_t n_options, const qstr_short_t options[], const int values[]) {
for (size_t i = 0; i < n_options; i++) {
@ -357,6 +359,7 @@ static mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
//| def deinit(self) -> None:
//| """Turn off the state machine and release its resources."""
//| ...
//|
static mp_obj_t rp2pio_statemachine_obj_deinit(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_rp2pio_statemachine_deinit(self);
@ -368,11 +371,13 @@ MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_deinit_obj, rp2pio_statemachine_ob
//| """No-op used by Context Managers.
//| Provided by context manager helper."""
//| ...
//|
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t rp2pio_statemachine_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_rp2pio_statemachine_deinit(args[0]);
@ -390,6 +395,7 @@ static void check_for_deinit(rp2pio_statemachine_obj_t *self) {
//| def restart(self) -> None:
//| """Resets this state machine, runs any init and enables the clock."""
//| ...
//|
// TODO: "and any others given. They must share an underlying PIO. An exception will be raised otherwise.""
static mp_obj_t rp2pio_statemachine_restart(mp_obj_t self_obj) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_obj);
@ -408,6 +414,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_restart_obj, rp2pio_statemachine_r
//| This can be used to output internal state to the RX FIFO and then
//| read with `readinto`."""
//| ...
//|
static mp_obj_t rp2pio_statemachine_run(mp_obj_t self_obj, mp_obj_t instruction_obj) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_obj);
check_for_deinit(self);
@ -426,6 +433,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(rp2pio_statemachine_run_obj, rp2pio_statemachine_run);
//| def stop(self) -> None:
//| """Stops the state machine clock. Use `restart` to enable it."""
//| ...
//|
static mp_obj_t rp2pio_statemachine_stop(mp_obj_t self_obj) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_obj);
check_for_deinit(self);
@ -457,6 +465,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_stop_obj, rp2pio_statemachine_stop
//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``
//| :param bool swap: For 2- and 4-byte elements, swap (reverse) the byte order"""
//| ...
//|
static mp_obj_t rp2pio_statemachine_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end, ARG_swap };
static const mp_arg_t allowed_args[] = {
@ -545,6 +554,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_write_obj, 2, rp2pio_statemachine
//| :param bool swap: For 2- and 4-byte elements, swap (reverse) the byte order
//| """
//| ...
//|
static void fill_buf_info(sm_buf_info *info, mp_obj_t obj, size_t *stride_in_bytes, mp_uint_t direction) {
if (obj != mp_const_none) {
@ -602,6 +612,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_background_write_obj, 1, rp2pio_s
//| """Immediately stop a background write, if one is in progress. Any
//| DMA in progress is halted, but items already in the TX FIFO are not
//| affected."""
//|
static mp_obj_t rp2pio_statemachine_obj_stop_background_write(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
bool ok = common_hal_rp2pio_statemachine_stop_background_write(self);
@ -634,6 +645,7 @@ MP_PROPERTY_GETTER(rp2pio_statemachine_writing_obj,
//| If the number is 0, then a `StateMachine.background_write` call will not block.
//| Note that `pending` is a deprecated alias for `pending_write` and will be removed
//| in a future version of CircuitPython."""
//|
static mp_obj_t rp2pio_statemachine_obj_get_pending_write(mp_obj_t self_in) {
@ -688,6 +700,7 @@ MP_PROPERTY_GETTER(rp2pio_statemachine_pending_write_obj,
//| :param bool swap: For 2- and 4-byte elements, swap (reverse) the byte order
//| """
//| ...
//|
static mp_obj_t rp2pio_statemachine_background_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@ -729,6 +742,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_background_read_obj, 1, rp2pio_st
//| """Immediately stop a background read, if one is in progress. Any
//| DMA in progress is halted, but items already in the RX FIFO are not
//| affected."""
//|
static mp_obj_t rp2pio_statemachine_obj_stop_background_read(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
bool ok = common_hal_rp2pio_statemachine_stop_background_read(self);
@ -757,6 +771,7 @@ MP_PROPERTY_GETTER(rp2pio_statemachine_reading_obj,
//| """Returns the number of pending buffers for background reading.
//|
//| If the number is 0, then a `StateMachine.background_read` call will not block."""
//|
static mp_obj_t rp2pio_statemachine_obj_get_pending_read(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_int(common_hal_rp2pio_statemachine_get_pending_read(self));
@ -793,6 +808,7 @@ MP_PROPERTY_GETTER(rp2pio_statemachine_pending_read_obj,
//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``
//| :param bool swap: For 2- and 4-byte elements, swap (reverse) the byte order"""
//| ...
//|
static mp_obj_t rp2pio_statemachine_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end, ARG_swap };
@ -863,6 +879,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_readinto_obj, 2, rp2pio_statemach
//| :param bool swap_in: For 2- and 4-rx elements, swap (reverse) the byte order for the buffer being received (read)
//| """
//| ...
//|
static mp_obj_t rp2pio_statemachine_write_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer_out, ARG_buffer_in, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end, ARG_swap_out, ARG_swap_in };
@ -928,6 +945,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(rp2pio_statemachine_write_readinto_obj, 2, rp2pio_sta
//| def clear_rxfifo(self) -> None:
//| """Clears any unread bytes in the rxfifo."""
//| ...
//|
static mp_obj_t rp2pio_statemachine_obj_clear_rxfifo(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_rp2pio_statemachine_clear_rxfifo(self);
@ -938,6 +956,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_clear_rxfifo_obj, rp2pio_statemach
//| def clear_txstall(self) -> None:
//| """Clears the txstall flag."""
//| ...
//|
static mp_obj_t rp2pio_statemachine_obj_clear_txstall(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_rp2pio_statemachine_clear_txstall(self);
@ -1093,6 +1112,7 @@ MP_PROPERTY_GETTER(rp2pio_statemachine_last_read_obj,
//| changes or restarts.
//| """
//|
//|
static mp_obj_t rp2pio_statemachine_obj_get_last_write(mp_obj_t self_in) {
rp2pio_statemachine_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -24,11 +24,13 @@
//| See the warning in `digitalio` for more information.
//| """
//|
//|
//| def pins_are_sequential(pins: List[microcontroller.Pin]) -> bool:
//| """Return True if the pins have sequential GPIO numbers, False otherwise"""
//| ...
//|
//|
static mp_obj_t rp2pio_pins_are_sequential(mp_obj_t pins_obj) {
size_t len;
mp_obj_t *items;

View file

@ -45,8 +45,6 @@ def main(input_template: pathlib.Path, output_path: pathlib.Path, skus: str = ty
quad_ok = quad_enable_status_byte is not None and quad_enable_bit_mask is not None
max_clock_speed_mhz = min((x.get("max_clock_speed_mhz", 1000) for x in flashes["nvm"]))
default_power_of_two = None
for nvm in flashes["nvm"]:
capacity = nvm.get("capacity", 0)

View file

@ -124,7 +124,7 @@ def make_pin_function_lists(functions, pins):
fcn_list[pin][i] = 1
i += 1
for pin in pins.keys():
if not pin in fcn_list:
if pin not in fcn_list:
fcn_list[pin] = []
decl += make_pin_function_list_decl(pin, fcn_list[pin])

View file

@ -31,7 +31,7 @@ def test_dac_digital(p_in, p_out):
def test_dual(pair1, pair2):
# verifies that the DACs can be set independently
print(f"Running pair test\n")
print("Running pair test\n")
pin1_in = analogio.AnalogIn(pair1[0])
pin1_out = analogio.AnalogOut(pair1[1])
pin2_in = analogio.AnalogIn(pair2[0])

View file

@ -13,9 +13,9 @@ assert board.ENABLE_3V3 is not None
# Then the symbol "board.DISCHARGE_3V3" is defined
assert board.DISCHARGE_3V3 is not None
# And the symbol "board.DISABLE_DISCHARGING" is defined to be "True"
assert board.DISABLE_DISCHARGING is not None and board.DISABLE_DISCHARGING == True
assert board.DISABLE_DISCHARGING is not None and board.DISABLE_DISCHARGING
# And the symbol "board.ENABLE_DISCHARGING" is defined to be "False"
assert board.ENABLE_DISCHARGING is not None and board.ENABLE_DISCHARGING == False
assert board.ENABLE_DISCHARGING is not None and not board.ENABLE_DISCHARGING
# Scenario: Toggle ENBLE_3V3
# Given I have a LED connected between the 3V3 and GND pins

View file

@ -60,6 +60,7 @@ static zephyr_serial_uart_obj_t *native_uart(mp_obj_t uart_obj) {
//| def deinit(self) -> None:
//| """Deinitialises the UART and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t _zephyr_serial_uart_obj_deinit(mp_obj_t self_in) {
zephyr_serial_uart_obj_t *self = native_uart(self_in);
zephyr_serial_uart_deinit(self);
@ -76,12 +77,14 @@ static void check_for_deinit(zephyr_serial_uart_obj_t *self) {
//| def __enter__(self) -> UART:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t _zephyr_serial_uart_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
zephyr_serial_uart_deinit(MP_OBJ_TO_PTR(args[0]));
@ -104,6 +107,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(_zephyr_serial_uart___exit___obj, 4,
//| :return: Data read
//| :rtype: bytes or None"""
//| ...
//|
//| def readinto(self, buf: WriteableBuffer) -> Optional[int]:
//| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
@ -113,6 +117,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(_zephyr_serial_uart___exit___obj, 4,
//|
//| *New in CircuitPython 4.0:* No length parameter is permitted."""
//| ...
//|
//| def readline(self) -> bytes:
//| """Read a line, ending in a newline character, or
@ -123,6 +128,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(_zephyr_serial_uart___exit___obj, 4,
//| :return: the line read
//| :rtype: bytes or None"""
//| ...
//|
//| def write(self, buf: ReadableBuffer) -> Optional[int]:
//| """Write the buffer of bytes to the bus.
@ -132,6 +138,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(_zephyr_serial_uart___exit___obj, 4,
//| :return: the number of bytes written
//| :rtype: int or None"""
//| ...
//|
// These three methods are used by the shared stream methods.
static mp_uint_t _zephyr_serial_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
@ -212,6 +219,7 @@ MP_PROPERTY_GETTER(_zephyr_serial_uart_in_waiting_obj,
//| timeout: float
//| """The current timeout, in seconds (float)."""
//|
static mp_obj_t _zephyr_serial_uart_obj_get_timeout(mp_obj_t self_in) {
zephyr_serial_uart_obj_t *self = native_uart(self_in);
check_for_deinit(self);
@ -238,6 +246,7 @@ MP_PROPERTY_GETSET(_zephyr_serial_uart_timeout_obj,
//| """Discard any unread characters in the input buffer."""
//| ...
//|
//|
static mp_obj_t _zephyr_serial_uart_obj_reset_input_buffer(mp_obj_t self_in) {
zephyr_serial_uart_obj_t *self = native_uart(self_in);
check_for_deinit(self);

View file

@ -15,8 +15,7 @@
#include "py/runtime.h"
//| """Zephyr UART driver for fixed busses.
//| """
//| """Zephyr UART driver for fixed busses."""
static const mp_rom_map_elem_t zephyr_serial_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_zephyr_serial) },

View file

@ -502,7 +502,7 @@ async def build_circuitpython():
not autogen_board_info_fn.exists()
or autogen_board_info_fn.read_text() != tomlkit.dumps(autogen_board_info)
):
logger.error(f"autogen_board_info.toml is out of date.")
logger.error("autogen_board_info.toml is out of date.")
raise RuntimeError(
f"autogen_board_info.toml is missing or out of date. Please run `make BOARD={board}` locally and commit {autogen_board_info_fn}."
)
@ -519,7 +519,6 @@ async def build_circuitpython():
source_files.append(file)
qstr_flags = "-DNO_QSTR"
async with asyncio.TaskGroup() as tg:
extra_source_flags = {}
for source_file in source_files:
tg.create_task(
preprocess_and_split_defs(

View file

@ -318,7 +318,7 @@ def parse_depfile(f):
if dep.startswith("/"):
extradeps.append(pathlib.Path(dep))
else:
extradeps.append(self.srcdir / dep)
raise RuntimeError(f"Unexpected depfile entry {dep}")
class Compiler:
@ -397,40 +397,3 @@ class Compiler:
working_directory=self.srcdir,
extradeps=objects,
)
async def link(
self,
objects: list[pathlib.Path],
output_file: pathlib.Path,
linker_script: pathlib.Path,
flags: list[str] = [],
print_memory_use=True,
output_map_file=True,
gc_sections=True,
):
output_file.parent.mkdir(parents=True, exist_ok=True)
link_flags = []
if print_memory_use:
link_flags.append("-Wl,--print-memory-usage")
if output_map_file:
link_flags.append(
"-Wl,-Map="
+ str(output_file.with_suffix(".elf.map").relative_to(caller_directory))
)
if gc_sections:
link_flags.append("-Wl,--gc-sections")
await run_command(
[
self.c_compiler,
*link_flags,
*flags,
*objects,
"-fuse-ld=lld",
"-T",
linker_script,
"-o",
output_file,
],
description=f"Link {output_file.relative_to(cwd)}",
working_directory=caller_directory,
)

View file

@ -93,7 +93,7 @@ CONNECTORS = {
@cpbuild.run_in_thread
def zephyr_dts_to_cp_board(builddir, zephyrbuilddir):
def zephyr_dts_to_cp_board(builddir, zephyrbuilddir): # noqa: C901
board_dir = builddir / "board"
# Auto generate board files from device tree.
@ -125,8 +125,6 @@ def zephyr_dts_to_cp_board(builddir, zephyrbuilddir):
# print(board_id_yaml)
# board_name = board_id_yaml["name"]
enabled_modules = []
dts = zephyrbuilddir / "zephyr.dts"
edt_pickle = dtlib.DT(dts)
node2alias = {}

View file

@ -90,8 +90,8 @@ def translate(translation_file, i18ns):
translations = []
for original in i18ns:
unescaped = original
for s in C_ESCAPES:
unescaped = unescaped.replace(C_ESCAPES[s], s)
for s, replacement in C_ESCAPES.items():
unescaped = unescaped.replace(replacement, s)
if original == "en_US":
translation = table.info()["language"]
else:
@ -593,12 +593,15 @@ def output_translation_data(encoding_table, i18ns, out):
total_text_compressed_size += len(compressed)
decompressed = decompress(encoding_table, compressed, encoded_length_bits)
assert decompressed == translation, (decompressed, translation)
for c in C_ESCAPES:
decompressed = decompressed.replace(c, C_ESCAPES[c])
for c, replacement in C_ESCAPES.items():
decompressed = decompressed.replace(c, replacement)
formatted = ["{:d}".format(x) for x in compressed]
out.write(
"const struct compressed_string translation{} = {{ .data = {}, .tail = {{ {} }} }}; // {}\n".format(
i, formatted[0], ", ".join(formatted[1:]), original, decompressed
i,
formatted[0],
", ".join(formatted[1:]),
original,
)
)
total_text_size += len(translation.encode("utf-8"))

View file

@ -65,7 +65,7 @@ def make_version_header(repo_path, filename):
""" % (
git_tag,
git_hash,
datetime.date.today().strftime("%Y-%m-%d"),
build_date.strftime("%Y-%m-%d"),
ver[0].replace("v", ""),
ver[1],
ver[2],

View file

@ -4,3 +4,58 @@
[tool.setuptools_scm]
# can be empty if no extra settings are needed, presence enables setuptools-scm
# Ruff settings copied from MicroPython
[tool.ruff]
target-version = "py37"
line-length = 99
# Exclude third-party code from linting and formatting. Ruff doesn't know how to ignore submodules.
# Exclude the following tests:
# repl_: not real python files
# viper_args: uses f(*)
extend-exclude = [
"extmod/ulab",
"frozen",
"lib",
"ports/analog/msdk",
"ports/atmel-samd/asf4",
"ports/broadcom/peripherals",
"ports/espressif/esp-idf",
"ports/espressif/esp-protocols",
"ports/raspberrypi/sdk",
"ports/silabs/gecko_sdk",
"ports/silabs/tools/slc_cli_linux",
"ports/stm/st_driver",
"tests/*/repl_*.py",
"tests/micropython/viper_args.py",
"tools/adabot",
"tools/bitmap_font",
"tools/cc1",
"tools/huffman",
"tools/msgfmt.py",
"tools/python-semver",
"tools/uf2",
]
# Exclude third-party code, and exclude the following tests:
# basics: needs careful attention before applying automatic formatting
format.exclude = [ "tests/basics/*.py" ]
lint.extend-select = [ "C9", "PLC" ]
lint.ignore = [
"E401",
"E402",
"E722",
"E731",
"E741",
"F401",
"F403",
"F405",
"PLC1901",
]
# manifest.py files are evaluated with some global names pre-defined
lint.per-file-ignores."**/manifest.py" = [ "F821" ]
lint.per-file-ignores."ports/**/boards/**/manifest_*.py" = [ "F821" ]
# Exclude all tests from linting (does not apply to formatting).
lint.per-file-ignores."tests/**/*.py" = [ "ALL" ]
lint.mccabe.max-complexity = 40

View file

@ -14,7 +14,7 @@ requests-cache
polib
# For pre-commit
black
ruff
pyyaml
pre-commit
micropython-uncrustify

View file

@ -1,10 +1,11 @@
import pathlib
paths = pathlib.Path(".").glob("**/*.c")
translate_h = "#include \"supervisor/shared/translate/translate.h\""
translate_h = '#include "supervisor/shared/translate/translate.h"'
for p in paths:
if "esp-idf" in p:
continue
lines = p.read_text().split("\n")
if "#include \"py/runtime.h\"" in lines and translate_h in lines:
if '#include "py/runtime.h"' in lines and translate_h in lines:
lines.remove(translate_h)
p.write_text("\n".join(lines))

View file

@ -62,6 +62,7 @@
//| Use `_bleio.adapter` to access the sole instance already available.
//| """
//| ...
//|
static mp_obj_t bleio_adapter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if CIRCUITPY_BLEIO_HCI
bleio_adapter_obj_t *self = common_hal_bleio_allocate_adapter_or_raise();
@ -135,6 +136,7 @@ MP_PROPERTY_GETSET(bleio_adapter_address_obj,
//| """name of the BLE adapter used once connected.
//| The name is "CIRCUITPY" + the last four hex digits of ``adapter.address``,
//| to make it easy to distinguish multiple CircuitPython boards."""
//|
static mp_obj_t _bleio_adapter_get_name(mp_obj_t self) {
return MP_OBJ_FROM_PTR(common_hal_bleio_adapter_get_name(self));
}
@ -161,7 +163,7 @@ MP_PROPERTY_GETSET(bleio_adapter_name_obj,
//| timeout: int = 0,
//| interval: float = 0.1,
//| tx_power: int = 0,
//| directed_to: Optional[Address] = None
//| directed_to: Optional[Address] = None,
//| ) -> None:
//| """Starts advertising until `stop_advertising` is called or if connectable, another device
//| connects to us.
@ -181,6 +183,7 @@ MP_PROPERTY_GETSET(bleio_adapter_name_obj,
//| :param int tx_power: transmitter power while advertising in dBm
//| :param Address directed_to: peer to advertise directly to"""
//| ...
//|
static mp_obj_t bleio_adapter_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_adapter_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@ -243,6 +246,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_start_advertising_obj, 1, bleio_
//| def stop_advertising(self) -> None:
//| """Stop sending advertising packets."""
//| ...
//|
static mp_obj_t bleio_adapter_stop_advertising(mp_obj_t self_in) {
bleio_adapter_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -262,7 +266,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_stop_advertising_obj, bleio_adapt
//| interval: float = 0.1,
//| window: float = 0.1,
//| minimum_rssi: int = -80,
//| active: bool = True
//| active: bool = True,
//| ) -> Iterable[ScanEntry]:
//| """Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are
//| filtered and returned separately.
@ -282,6 +286,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_stop_advertising_obj, bleio_adapt
//| :returns: an iterable of `_bleio.ScanEntry` objects
//| :rtype: iterable"""
//| ...
//|
static mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_prefixes, ARG_buffer_size, ARG_extended, ARG_timeout, ARG_interval, ARG_window, ARG_minimum_rssi, ARG_active };
static const mp_arg_t allowed_args[] = {
@ -346,6 +351,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_start_scan_obj, 1, bleio_adapter
//| def stop_scan(self) -> None:
//| """Stop the current scan."""
//| ...
//|
static mp_obj_t bleio_adapter_stop_scan(mp_obj_t self_in) {
bleio_adapter_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -381,6 +387,7 @@ MP_PROPERTY_GETTER(bleio_adapter_connected_obj,
//| connections: Tuple[Connection]
//| """Tuple of active connections including those initiated through
//| :py:meth:`_bleio.Adapter.connect`. (read-only)"""
//|
static mp_obj_t bleio_adapter_get_connections(mp_obj_t self) {
return common_hal_bleio_adapter_get_connections(self);
}
@ -395,6 +402,7 @@ MP_PROPERTY_GETTER(bleio_adapter_connections_obj,
//| :param Address address: The address of the peripheral to connect to
//| :param float/int timeout: Try to connect for timeout seconds."""
//| ...
//|
static mp_obj_t bleio_adapter_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_adapter_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@ -418,6 +426,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_connect_obj, 1, bleio_adapter_co
//| """Erase all bonding information stored in flash memory."""
//| ...
//|
//|
static mp_obj_t bleio_adapter_erase_bonding(mp_obj_t self_in) {
bleio_adapter_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -26,6 +26,7 @@
//| :param int address_type: one of the integer values: `PUBLIC`, `RANDOM_STATIC`,
//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`."""
//| ...
//|
static mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_address, ARG_address_type };
static const mp_arg_t allowed_args[] = {
@ -86,6 +87,7 @@ MP_PROPERTY_GETTER(bleio_address_address_bytes_obj,
//|
//| One of the integer values: `PUBLIC`, `RANDOM_STATIC`, `RANDOM_PRIVATE_RESOLVABLE`,
//| or `RANDOM_PRIVATE_NON_RESOLVABLE`."""
//|
static mp_obj_t bleio_address_get_type(mp_obj_t self_in) {
bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -99,6 +101,7 @@ MP_PROPERTY_GETTER(bleio_address_type_obj,
//| def __eq__(self, other: object) -> bool:
//| """Two Address objects are equal if their addresses and address types are equal."""
//| ...
//|
static mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
switch (op) {
// Two Addresses are equal if their address bytes and address_type are equal
@ -124,6 +127,7 @@ static mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_o
//| def __hash__(self) -> int:
//| """Returns a hash for the Address data."""
//| ...
//|
static mp_obj_t bleio_address_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
switch (op) {
// Two Addresses are equal if their address bytes and address_type are equal
@ -166,6 +170,7 @@ static void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
//| RANDOM_PRIVATE_NON_RESOLVABLE: int
//| """A randomly generated address that changes on every connection."""
//|
//|
static const mp_rom_map_elem_t bleio_address_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_address_bytes_obj) },
{ MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_type_obj) },

View file

@ -19,6 +19,7 @@
//| def __init__(self) -> None:
//| """You cannot create an instance of :py:class:`~_bleio.Attribute`."""
//| ...
//|
static const mp_rom_map_elem_t bleio_attribute_locals_dict_table[] = {
@ -42,6 +43,7 @@ static const mp_rom_map_elem_t bleio_attribute_locals_dict_table[] = {
//|
//| SIGNED_WITH_MITM: int
//| """security_mode: authenticated data signing, without man-in-the-middle protection"""
//|
//|
{ MP_ROM_QSTR(MP_QSTR_NO_ACCESS), MP_ROM_INT(SECURITY_MODE_NO_ACCESS) },
{ MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(SECURITY_MODE_OPEN) },

View file

@ -25,6 +25,7 @@
//| Remote Characteristic objects are created by `Connection.discover_remote_services()`
//| as part of remote Services."""
//| ...
//|
//| @classmethod
//| def add_to_service(
@ -38,7 +39,7 @@
//| max_length: int = 20,
//| fixed_length: bool = False,
//| initial_value: Optional[ReadableBuffer] = None,
//| user_description: Optional[str] = None
//| user_description: Optional[str] = None,
//| ) -> Characteristic:
//| """Create a new Characteristic object, and add it to this Service.
//|
@ -63,6 +64,7 @@
//|
//| :return: the new Characteristic."""
//| ...
//|
static mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// class is arg[0], which we can ignore.
@ -143,6 +145,7 @@ static MP_DEFINE_CONST_CLASSMETHOD_OBJ(bleio_characteristic_add_to_service_obj,
//| def deinit(self) -> None:
//| """Deinitialises the Characteristic and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t bleio_characteristic_deinit(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_bleio_characteristic_deinit(self);
@ -246,6 +249,7 @@ MP_PROPERTY_GETTER(bleio_characteristic_descriptors_obj,
//| service: Service
//| """The Service this Characteristic is a part of."""
//|
static mp_obj_t bleio_characteristic_get_service(mp_obj_t self_in) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -264,6 +268,7 @@ MP_PROPERTY_GETTER(bleio_characteristic_service_obj,
//| :param float indicate: True if Characteristic should receive indications of remote writes
//| """
//| ...
//|
static mp_obj_t bleio_characteristic_set_cccd(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
check_for_deinit(self);
@ -312,6 +317,7 @@ static const mp_rom_map_elem_t bleio_characteristic_locals_dict_table[] = {
//|
//| WRITE_NO_RESPONSE: int
//| """property: clients may write this characteristic; no response will be sent back"""
//|
//|
{ MP_ROM_QSTR(MP_QSTR_BROADCAST), MP_ROM_INT(CHAR_PROP_BROADCAST) },
{ MP_ROM_QSTR(MP_QSTR_INDICATE), MP_ROM_INT(CHAR_PROP_INDICATE) },

View file

@ -37,6 +37,7 @@ static void raise_error_if_not_connected(bleio_characteristic_buffer_obj_t *self
//| :param int buffer_size: Size of ring buffer that stores incoming data coming from client.
//| Must be >= 1."""
//| ...
//|
static mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_characteristic, ARG_timeout, ARG_buffer_size, };
static const mp_arg_t allowed_args[] = {
@ -95,6 +96,7 @@ static void check_for_deinit(bleio_characteristic_buffer_obj_t *self) {
//| :return: the line read
//| :rtype: int or None"""
//| ...
//|
// These three methods are used by the shared stream methods.
static mp_uint_t bleio_characteristic_buffer_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
@ -140,6 +142,7 @@ static mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t r
//| in_waiting: int
//| """The number of bytes in the input buffer, available to be read"""
//|
static mp_obj_t bleio_characteristic_buffer_obj_get_in_waiting(mp_obj_t self_in) {
bleio_characteristic_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -158,6 +161,7 @@ MP_PROPERTY_GETTER(bleio_characteristic_buffer_in_waiting_obj,
//| def reset_input_buffer(self) -> None:
//| """Discard any unread characters in the input buffer."""
//| ...
//|
static mp_obj_t bleio_characteristic_buffer_obj_reset_input_buffer(mp_obj_t self_in) {
bleio_characteristic_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -170,6 +174,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_buffer_reset_input_buffer_
//| """Disable permanently."""
//| ...
//|
//|
static mp_obj_t bleio_characteristic_buffer_deinit(mp_obj_t self_in) {
bleio_characteristic_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_bleio_characteristic_buffer_deinit(self);

View file

@ -56,6 +56,7 @@ void bleio_connection_ensure_connected(bleio_connection_obj_t *self) {
//| def disconnect(self) -> None:
//| """Disconnects from the remote peripheral. Does nothing if already disconnected."""
//| ...
//|
static mp_obj_t bleio_connection_disconnect(mp_obj_t self_in) {
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(self_in);
// common_hal_bleio_connection_disconnect() does nothing if already disconnected.
@ -71,6 +72,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_disconnect_obj, bleio_connecti
//| **Limitation**: Currently ``bond``must be ``True``: bonding always occurs.
//| """
//| ...
//|
static mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@ -117,6 +119,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_pair_obj, 1, bleio_connection
//|
//| :return: A tuple of `_bleio.Service` objects provided by the remote peripheral."""
//| ...
//|
static mp_obj_t bleio_connection_discover_remote_services(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@ -188,6 +191,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_get_connection_interval_obj, b
//| But for a regular characteristic read or write, may be sent in multiple packets,
//| so this limit does not apply."""
//|
//|
static mp_obj_t bleio_connection_get_max_packet_length(mp_obj_t self_in) {
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -35,7 +35,7 @@
//| write_perm: int = Attribute.OPEN,
//| max_length: int = 20,
//| fixed_length: bool = False,
//| initial_value: ReadableBuffer = b""
//| initial_value: ReadableBuffer = b"",
//| ) -> Descriptor:
//| """Create a new Descriptor object, and add it to this Service.
//|
@ -55,6 +55,7 @@
//|
//| :return: the new Descriptor."""
//| ...
//|
static mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
// class is arg[0], which we can ignore.
@ -147,6 +148,7 @@ MP_PROPERTY_GETTER(bleio_descriptor_characteristic_obj,
//| value: bytearray
//| """The value of this descriptor."""
//|
//|
static mp_obj_t bleio_descriptor_get_value(mp_obj_t self_in) {
bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -21,7 +21,7 @@
//| characteristic: Characteristic,
//| *,
//| buffer_size: int,
//| max_packet_size: Optional[int] = None
//| max_packet_size: Optional[int] = None,
//| ) -> None:
//| """Accumulates a Characteristic's incoming packets in a FIFO buffer and facilitates packet aware
//| outgoing writes. A packet's size is either the characteristic length or the maximum transmission
@ -39,6 +39,7 @@
//| :param int max_packet_size: Maximum size of packets. Overrides value from the characteristic.
//| (Remote characteristics may not have the correct length.)"""
//| ...
//|
static mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_characteristic, ARG_buffer_size, ARG_max_packet_size };
static const mp_arg_t allowed_args[] = {
@ -79,6 +80,7 @@ static void check_for_deinit(bleio_packet_buffer_obj_t *self) {
//| :return: number of bytes read and stored into ``buf``
//| :rtype: int"""
//| ...
//|
static mp_obj_t bleio_packet_buffer_readinto(mp_obj_t self_in, mp_obj_t buffer_obj) {
bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -104,6 +106,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_
//| :return: number of bytes written. May include header bytes when packet is empty.
//| :rtype: int"""
//| ...
//|
// TODO: Add a kwarg `merge=False` to dictate whether subsequent writes are merged into a pending
// one.
static mp_obj_t bleio_packet_buffer_write(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@ -149,6 +152,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(bleio_packet_buffer_write_obj, 1, bleio_packet
//| def deinit(self) -> None:
//| """Disable permanently."""
//| ...
//|
static mp_obj_t bleio_packet_buffer_deinit(mp_obj_t self_in) {
bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_bleio_packet_buffer_deinit(self);
@ -175,6 +179,7 @@ MP_PROPERTY_GETTER(bleio_packet_buffer_incoming_packet_length_obj,
//| outgoing_packet_length: int
//| """Maximum length in bytes of a packet we are writing."""
//|
//|
static mp_obj_t bleio_packet_buffer_get_outgoing_packet_length(mp_obj_t self_in) {
bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -30,6 +30,7 @@
//| than the scan filtering which accepts any advertisements that match any of the prefixes
//| where ``match_all`` is False."""
//| ...
//|
static mp_obj_t bleio_scanentry_matches(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@ -97,6 +98,7 @@ MP_PROPERTY_GETTER(bleio_scanentry_connectable_obj,
//| scan_response: bool
//| """True if the entry was a scan response. (read-only)"""
//|
//|
static mp_obj_t scanentry_get_scan_response(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(common_hal_bleio_scanentry_get_scan_response(self));

View file

@ -40,6 +40,7 @@ static mp_obj_t scanresults_iternext(mp_obj_t self_in) {
//| """
//| ...
//|
//|
MP_DEFINE_CONST_OBJ_TYPE(
bleio_scanresults_type,

View file

@ -27,6 +27,7 @@
//|
//| :return: the new Service"""
//| ...
//|
static mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_uuid, ARG_secondary };
static const mp_arg_t allowed_args[] = {
@ -51,6 +52,7 @@ static mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
//| def deinit(self) -> None:
//| """Disable and deinitialise the Service."""
//| ...
//|
static mp_obj_t bleio_service_deinit(mp_obj_t self_in) {
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_bleio_service_deinit(self);
@ -99,6 +101,7 @@ MP_PROPERTY_GETTER(bleio_service_secondary_obj,
//|
//| Will be ``None`` if the 128-bit UUID for this service is not known."""
//|
//|
static mp_obj_t bleio_service_get_uuid(mp_obj_t self_in) {
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -30,6 +30,7 @@
//| :param value: The uuid value to encapsulate
//| :type value: int, ~circuitpython_typing.ReadableBuffer or str"""
//| ...
//|
static mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mp_arg_check_num(n_args, n_kw, 1, 1, false);
@ -138,6 +139,7 @@ MP_PROPERTY_GETTER(bleio_uuid_uuid128_obj,
//| 16-bit Bluetooth SIG assigned UUID. (read-only) 32-bit UUIDs are not currently supported.
//|
//| :type: int"""
//|
static mp_obj_t bleio_uuid_get_size(mp_obj_t self_in) {
bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_uuid_get_size(self));
@ -152,6 +154,7 @@ MP_PROPERTY_GETTER(bleio_uuid_size_obj,
//| def pack_into(self, buffer: WriteableBuffer, offset: int = 0) -> None:
//| """Packs the UUID into the given buffer at the given offset."""
//| ...
//|
static mp_obj_t bleio_uuid_pack_into(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
@ -214,6 +217,7 @@ static mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
//| """Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit."""
//| ...
//|
//|
static mp_obj_t bleio_uuid_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
switch (op) {
// Two UUID's are equal if their uuid16 values match or their uuid128 values match.

View file

@ -41,17 +41,20 @@
//| Pico W boards do *not* support BLE using the on-board CYW43 co-processor,
//| but do support using an external AirLift.
//| """
//|
//| adapter: Adapter
//| """BLE Adapter used to manage device discovery and connections.
//| This object is the sole instance of `_bleio.Adapter`."""
//|
//|
//| class BluetoothError(Exception):
//| """Catchall exception for Bluetooth related errors."""
//|
//| ...
//|
//|
MP_DEFINE_BLEIO_EXCEPTION(BluetoothError, Exception)
NORETURN void mp_raise_bleio_BluetoothError(mp_rom_error_text_t fmt, ...) {
va_list argptr;
@ -67,6 +70,7 @@ NORETURN void mp_raise_bleio_BluetoothError(mp_rom_error_text_t fmt, ...) {
//|
//| ...
//|
//|
MP_DEFINE_BLEIO_EXCEPTION(RoleError, bleio_BluetoothError)
NORETURN void mp_raise_bleio_RoleError(mp_rom_error_text_t msg) {
mp_raise_msg(&mp_type_bleio_RoleError, msg);
@ -77,6 +81,7 @@ NORETURN void mp_raise_bleio_RoleError(mp_rom_error_text_t msg) {
//|
//| ...
//|
//|
MP_DEFINE_BLEIO_EXCEPTION(SecurityError, bleio_BluetoothError)
NORETURN void mp_raise_bleio_SecurityError(mp_rom_error_text_t fmt, ...) {
va_list argptr;
@ -108,6 +113,7 @@ static mp_obj_dict_t bleio_module_globals;
//| Raises `NotImplementedError` when the adapter is a singleton and cannot be set."""
//| ...
//|
//|
mp_obj_t bleio_set_adapter(mp_obj_t adapter_obj) {
#if CIRCUITPY_BLEIO_HCI
(void)mp_arg_validate_type_or_none(adapter_obj, &bleio_adapter_type, MP_QSTR_adapter);

View file

@ -25,9 +25,11 @@
//| contains methods for constructing EVE command
//| buffers and appending basic graphics commands."""
//|
//|
//| class _EVE:
//| def __init__(self) -> None:
//| """Create an _EVE object"""
//|
typedef struct _mp_obj__EVE_t {
mp_obj_base_t base;
common_hal__eve_t _eve;
@ -38,7 +40,10 @@ static const mp_obj_type_t _EVE_type;
#define EVEHAL(s) \
(&((mp_obj__EVE_t *)mp_obj_cast_to_native_base((s), &_EVE_type))->_eve)
//| def register(self, o: object) -> None: ...
//| def register(self, o: object) -> None:
//| """Register an object's ``write()`` function"""
//| ...
//|
static mp_obj_t _register(mp_obj_t self, mp_obj_t o) {
common_hal__eve_t *eve = EVEHAL(self);
mp_load_method(o, MP_QSTR_write, eve->dest);
@ -46,7 +51,11 @@ static mp_obj_t _register(mp_obj_t self, mp_obj_t o) {
}
static MP_DEFINE_CONST_FUN_OBJ_2(register_obj, _register);
//| def setmodel(self, m: int) -> None: ...
//|
//| def setmodel(self, m: int) -> None:
//| """Set the model number of the EVE chip"""
//| ...
//|
static mp_obj_t _setmodel(mp_obj_t self, mp_obj_t m) {
common_hal__eve_t *eve = EVEHAL(self);
eve->model = mp_obj_get_int_truncated(m);
@ -54,11 +63,13 @@ static mp_obj_t _setmodel(mp_obj_t self, mp_obj_t m) {
}
static MP_DEFINE_CONST_FUN_OBJ_2(setmodel_obj, _setmodel);
//|
//| def flush(self) -> None:
//| """Send any queued drawing commands directly to the hardware.
//|
//| :param int width: The width of the grid in tiles, or 1 for sprites."""
//| ...
//|
static mp_obj_t _flush(mp_obj_t self) {
common_hal__eve_flush(EVEHAL(self));
return mp_const_none;
@ -70,6 +81,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(flush_obj, _flush);
//|
//| :param ~circuitpython_typing.ReadableBuffer b: The bytes to add"""
//| ...
//|
static mp_obj_t _cc(mp_obj_t self, mp_obj_t b) {
mp_buffer_info_t buffer_info;
mp_get_buffer_raise(b, &buffer_info, MP_BUFFER_READ);
@ -89,6 +101,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(cc_obj, _cc);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _alphafunc(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t func = mp_obj_get_int_truncated(a0);
@ -106,6 +119,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(alphafunc_obj, _alphafunc);
//| Valid primitives are ``BITMAPS``, ``POINTS``, ``LINES``, ``LINE_STRIP``, ``EDGE_STRIP_R``, ``EDGE_STRIP_L``, ``EDGE_STRIP_A``, ``EDGE_STRIP_B`` and ``RECTS``.
//| """
//| ...
//|
static mp_obj_t _begin(mp_obj_t self, mp_obj_t a0) {
uint32_t prim = mp_obj_get_int_truncated(a0);
@ -119,6 +133,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(begin_obj, _begin);
//|
//| :param int format: bitmap pixel format."""
//| ...
//|
static mp_obj_t _bitmapextformat(mp_obj_t self, mp_obj_t a0) {
uint32_t fmt = mp_obj_get_int_truncated(a0);
@ -135,6 +150,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(bitmapextformat_obj, _bitmapextformat);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _bitmaphandle(mp_obj_t self, mp_obj_t a0) {
uint32_t handle = mp_obj_get_int_truncated(a0);
@ -149,6 +165,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(bitmaphandle_obj, _bitmaphandle);
//| :param int linestride: high part of bitmap line stride, in bytes. Range 0-7
//| :param int height: high part of bitmap height, in lines. Range 0-3"""
//| ...
//|
static mp_obj_t _bitmaplayouth(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t linestride = mp_obj_get_int_truncated(a0);
@ -165,6 +182,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(bitmaplayouth_obj, _bitmaplayouth);
//| :param int linestride: bitmap line stride, in bytes. Range 0-1023
//| :param int height: bitmap height, in lines. Range 0-511"""
//| ...
//|
static mp_obj_t _bitmaplayout(size_t n_args, const mp_obj_t *args) {
uint32_t format = mp_obj_get_int_truncated(args[1]);
@ -181,6 +199,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaplayout_obj, 4, 4, _bitmaplayout
//| :param int width: high part of drawn bitmap width, in pixels. Range 0-3
//| :param int height: high part of drawn bitmap height, in pixels. Range 0-3"""
//| ...
//|
static mp_obj_t _bitmapsizeh(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t width = mp_obj_get_int_truncated(a0);
@ -199,6 +218,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(bitmapsizeh_obj, _bitmapsizeh);
//| :param int width: drawn bitmap width, in pixels. Range 0-511
//| :param int height: drawn bitmap height, in pixels. Range 0-511"""
//| ...
//|
static mp_obj_t _bitmapsize(size_t n_args, const mp_obj_t *args) {
uint32_t filter = mp_obj_get_int_truncated(args[1]);
@ -217,6 +237,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmapsize_obj, 6, 6, _bitmapsize);
//| :param int addr: Bitmap start address, pixel-aligned, low part.
//| """
//| ...
//|
static mp_obj_t _bitmapsource(mp_obj_t self, mp_obj_t a0) {
uint32_t addr = mp_obj_get_int_truncated(a0);
@ -231,6 +252,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(bitmapsource_obj, _bitmapsource);
//| :param int addr: Bitmap start address, pixel-aligned, high part.
//| """
//| ...
//|
static mp_obj_t _bitmapsourceh(mp_obj_t self, mp_obj_t a0) {
uint32_t addr = mp_obj_get_int_truncated(a0);
@ -247,6 +269,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(bitmapsourceh_obj, _bitmapsourceh);
//| :param int b: blue component source channel. Range 0-7
//| :param int a: alpha component source channel. Range 0-7"""
//| ...
//|
static mp_obj_t _bitmapswizzle(size_t n_args, const mp_obj_t *args) {
uint32_t r = mp_obj_get_int_truncated(args[1]);
@ -268,6 +291,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmapswizzle_obj, 5, 5, _bitmapswizz
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static void _transform1(uint32_t *p, uint32_t *v, size_t n_args, const mp_obj_t *args) {
common_hal__eve_t *eve = EVEHAL(args[0]);
@ -313,6 +337,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransforma_obj, 2, 3, _bitmaptr
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _bitmaptransformb(size_t n_args, const mp_obj_t *args) {
uint32_t p, v;
@ -332,6 +357,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransformb_obj, 2, 3, _bitmaptr
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _bitmaptransformc(mp_obj_t self, mp_obj_t a0) {
common_hal__eve_t *eve = EVEHAL(self);
@ -357,6 +383,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(bitmaptransformc_obj, _bitmaptransformc);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _bitmaptransformd(size_t n_args, const mp_obj_t *args) {
uint32_t p, v;
@ -376,6 +403,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransformd_obj, 2, 3, _bitmaptr
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _bitmaptransforme(size_t n_args, const mp_obj_t *args) {
uint32_t p, v;
@ -395,6 +423,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaptransforme_obj, 2, 3, _bitmaptr
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _bitmaptransformf(mp_obj_t self, mp_obj_t a0) {
common_hal__eve_t *eve = EVEHAL(self);
@ -419,6 +448,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(bitmaptransformf_obj, _bitmaptransformf);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _blendfunc(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t src = mp_obj_get_int_truncated(a0);
@ -433,6 +463,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(blendfunc_obj, _blendfunc);
//|
//| :param int dest: display list address. Range 0-65535"""
//| ...
//|
static mp_obj_t _call(mp_obj_t self, mp_obj_t a0) {
uint32_t dest = mp_obj_get_int_truncated(a0);
@ -449,6 +480,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(call_obj, _call);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _cell(mp_obj_t self, mp_obj_t a0) {
uint32_t cell = mp_obj_get_int_truncated(a0);
@ -465,6 +497,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(cell_obj, _cell);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _clearcolora(mp_obj_t self, mp_obj_t a0) {
uint32_t alpha = mp_obj_get_int_truncated(a0);
@ -483,6 +516,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(clearcolora_obj, _clearcolora);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _clearcolorrgb(size_t n_args, const mp_obj_t *args) {
uint32_t red = mp_obj_get_int_truncated(args[1]);
@ -500,6 +534,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(clearcolorrgb_obj, 4, 4, _clearcolorr
//| :param int s: clear stencil buffer. Range 0-1
//| :param int t: clear tag buffer. Range 0-1"""
//| ...
//|
static mp_obj_t _clear(size_t n_args, const mp_obj_t *args) {
uint32_t c = (n_args > 1) ? mp_obj_get_int_truncated(args[1]) : 1;
@ -518,6 +553,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(clear_obj, 1, 4, _clear);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _clearstencil(mp_obj_t self, mp_obj_t a0) {
uint32_t s = mp_obj_get_int_truncated(a0);
@ -533,6 +569,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(clearstencil_obj, _clearstencil);
//|
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//|
static mp_obj_t _cleartag(mp_obj_t self, mp_obj_t a0) {
uint32_t s = mp_obj_get_int_truncated(a0);
@ -549,6 +586,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(cleartag_obj, _cleartag);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _colora(mp_obj_t self, mp_obj_t a0) {
uint32_t alpha = mp_obj_get_int_truncated(a0);
@ -568,6 +606,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(colora_obj, _colora);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _colormask(size_t n_args, const mp_obj_t *args) {
uint32_t r = mp_obj_get_int_truncated(args[1]);
@ -589,6 +628,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(colormask_obj, 5, 5, _colormask);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _colorrgb(size_t n_args, const mp_obj_t *args) {
uint32_t red = mp_obj_get_int_truncated(args[1]);
@ -602,6 +642,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(colorrgb_obj, 4, 4, _colorrgb);
//| def Display(self) -> None:
//| """End the display list"""
//| ...
//|
static mp_obj_t _display(mp_obj_t self) {
@ -616,6 +657,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(display_obj, _display);
//| :meth:`Vertex2ii` and :meth:`Vertex2f` calls are ignored until the next :meth:`Begin`.
//| """
//| ...
//|
static mp_obj_t _end(mp_obj_t self) {
@ -629,6 +671,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(end_obj, _end);
//|
//| :param int dest: display list address. Range 0-65535"""
//| ...
//|
static mp_obj_t _jump(mp_obj_t self, mp_obj_t a0) {
uint32_t dest = mp_obj_get_int_truncated(a0);
@ -642,6 +685,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(jump_obj, _jump);
//|
//| :param int m: macro register to read. Range 0-1"""
//| ...
//|
static mp_obj_t _macro(mp_obj_t self, mp_obj_t a0) {
uint32_t m = mp_obj_get_int_truncated(a0);
@ -653,6 +697,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(macro_obj, _macro);
//| def Nop(self) -> None:
//| """No operation"""
//| ...
//|
static mp_obj_t _nop(mp_obj_t self) {
@ -669,6 +714,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(nop_obj, _nop);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _palettesource(mp_obj_t self, mp_obj_t a0) {
uint32_t addr = mp_obj_get_int_truncated(a0);
@ -685,6 +731,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(palettesource_obj, _palettesource);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _palettesourceh(mp_obj_t self, mp_obj_t a0) {
uint32_t addr = mp_obj_get_int_truncated(a0);
@ -696,6 +743,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(palettesourceh_obj, _palettesourceh);
//| def RestoreContext(self) -> None:
//| """Restore the current graphics context from the context stack"""
//| ...
//|
static mp_obj_t _restorecontext(mp_obj_t self) {
@ -707,6 +755,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(restorecontext_obj, _restorecontext);
//| def Return(self) -> None:
//| """Return from a previous call command"""
//| ...
//|
static mp_obj_t _return(mp_obj_t self) {
@ -718,6 +767,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(return_obj, _return);
//| def SaveContext(self) -> None:
//| """Push the current graphics context on the context stack"""
//| ...
//|
static mp_obj_t _savecontext(mp_obj_t self) {
@ -735,6 +785,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(savecontext_obj, _savecontext);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _scissorsize(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t width = mp_obj_get_int_truncated(a0);
@ -753,6 +804,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(scissorsize_obj, _scissorsize);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _scissorxy(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t x = mp_obj_get_int_truncated(a0);
@ -772,6 +824,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(scissorxy_obj, _scissorxy);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _stencilfunc(size_t n_args, const mp_obj_t *args) {
uint32_t func = mp_obj_get_int_truncated(args[1]);
@ -790,6 +843,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stencilfunc_obj, 4, 4, _stencilfunc);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _stencilmask(mp_obj_t self, mp_obj_t a0) {
uint32_t mask = mp_obj_get_int_truncated(a0);
@ -807,6 +861,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(stencilmask_obj, _stencilmask);
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _stencilop(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
uint32_t sfail = mp_obj_get_int_truncated(a0);
@ -824,6 +879,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(stencilop_obj, _stencilop);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _tagmask(mp_obj_t self, mp_obj_t a0) {
uint32_t mask = mp_obj_get_int_truncated(a0);
@ -840,6 +896,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(tagmask_obj, _tagmask);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _tag(mp_obj_t self, mp_obj_t a0) {
uint32_t s = mp_obj_get_int_truncated(a0);
@ -863,6 +920,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(vertexformat_obj, _vertexformat);
//|
//| This method is an alternative to :meth:`Vertex2f`."""
//| ...
//|
static mp_obj_t _vertex2ii(size_t n_args, const mp_obj_t *args) {
uint32_t x = mp_obj_get_int_truncated(args[1]);
@ -950,6 +1008,7 @@ static bool is_vector(mp_obj_t a) {
//| :param float x: pixel x-coordinate
//| :param float y: pixel y-coordinate"""
//| ...
//|
static mp_obj_t _vertex2f(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
#if CIRCUITPY_ULAB
if (is_vector(a0) && is_vector(a1)) {
@ -978,6 +1037,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(vertex2f_obj, _vertex2f);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _linewidth(mp_obj_t self, mp_obj_t a0) {
mp_float_t width = mp_obj_get_float(a0);
@ -994,6 +1054,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(linewidth_obj, _linewidth);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _pointsize(mp_obj_t self, mp_obj_t a0) {
mp_float_t size = mp_obj_get_float(a0);
@ -1010,6 +1071,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(pointsize_obj, _pointsize);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _vertextranslatex(mp_obj_t self, mp_obj_t a0) {
mp_float_t x = mp_obj_get_float(a0);
@ -1026,6 +1088,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatex_obj, _vertextranslatex);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
static mp_obj_t _vertextranslatey(mp_obj_t self, mp_obj_t a0) {
@ -1043,6 +1106,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatey_obj, _vertextranslatey);
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
//| """
//| ...
//|
// }
@ -1058,6 +1122,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatey_obj, _vertextranslatey);
//| This method is used by the ``eve`` module to efficiently add
//| commands to the FIFO."""
//| ...
//|
static mp_obj_t _cmd0(mp_obj_t self, mp_obj_t n) {
uint32_t code = 0xffffff00 | mp_obj_get_int_truncated(n);
@ -1080,6 +1145,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(cmd0_obj, _cmd0);
//| commands to the FIFO."""
//| ...
//|
//|
static mp_obj_t _cmd(size_t n_args, const mp_obj_t *args) {
mp_obj_t self = args[0];
mp_obj_t num = args[1];

View file

@ -41,6 +41,7 @@
//| buttons are connected to rows of the matrix)."""
//| ...
//|
//|
static mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_buffer, ARG_rows, ARG_cols, ARG_buttons };
static const mp_arg_t allowed_args[] = {

View file

@ -15,9 +15,11 @@
//| from adafruit_pixelbuf import PixelBuf, PixelReturnType, PixelSequence, PixelType
//|
//|
//| class PixelMap:
//| def __init__(self, pixelbuf: PixelBuf, indices: Tuple[Union[int, Tuple[int]]]) -> None:
//| """Construct a PixelMap object that uses the given indices of the underlying pixelbuf"""
//|
static mp_obj_t pixelmap_pixelmap_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_pixelbuf, ARG_indices };
@ -116,6 +118,7 @@ MP_PROPERTY_GETTER(pixelmap_pixelmap_byteorder_obj,
//|
//| def fill(self, color: PixelType) -> None:
//| """Fill all the pixels in the map with the given color"""
//|
static mp_obj_t pixelmap_pixelmap_fill(const mp_obj_t self_in, const mp_obj_t color) {
pixelmap_pixelmap_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -127,6 +130,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(pixelmap_pixelmap_fill_obj, pixelmap_pixelmap_fill);
//|
//| def indices(self, index: int) -> Tuple[int]:
//| """Return the PixelBuf indices for a PixelMap index"""
//|
static mp_obj_t pixelmap_pixelmap_indices(const mp_obj_t self_in, const mp_obj_t index) {
pixelmap_pixelmap_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -156,6 +160,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(pixelmap_pixelmap_indices_obj, pixelmap_pixelmap_indic
//| For RGBW byteorders, if given only RGB values either as an int or as a tuple, the white value
//| is used instead when the red, green, and blue values are the same."""
//| ...
//|
static mp_obj_t pixelmap_pixelmap_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
pixelmap_pixelmap_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (value == MP_OBJ_NULL) {
@ -200,6 +205,7 @@ static mp_obj_t pixelmap_pixelmap_subscr(mp_obj_t self_in, mp_obj_t index_in, mp
//| def __len__(self) -> int:
//| """Length of the map"""
//|
static mp_obj_t pixelmap_pixelmap_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
pixelmap_pixelmap_obj_t *self = MP_OBJ_TO_PTR(self_in);
switch (op) {
@ -217,6 +223,7 @@ static mp_obj_t pixelmap_pixelmap_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
//| when `auto_write` is True."""
//| ...
//|
//|
static mp_obj_t pixelmap_pixelmap_show(mp_obj_t self_in) {
pixelmap_pixelmap_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -33,6 +33,7 @@
//| This class is intended for internal use in the ``stage`` library and
//| it shouldn't be used on its own."""
//| ...
//|
static mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args,
size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 4, 5, false);
@ -75,6 +76,7 @@ static mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args,
//| def move(self, x: int, y: int) -> None:
//| """Set the offset of the layer to the specified values."""
//| ...
//|
static mp_obj_t layer_move(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
layer_obj_t *self = MP_OBJ_TO_PTR(self_in);
self->x = mp_obj_get_int(x_in);
@ -88,6 +90,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(layer_move_obj, layer_move);
//| graphic."""
//| ...
//|
//|
static mp_obj_t layer_frame(mp_obj_t self_in, mp_obj_t frame_in,
mp_obj_t rotation_in) {
layer_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -33,6 +33,7 @@
//| This class is intended for internal use in the ``stage`` library and
//| it shouldn't be used on its own."""
//| ...
//|
static mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args,
size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 5, 5, false);
@ -70,6 +71,7 @@ static mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args,
//| """Set the offset of the text to the specified values."""
//| ...
//|
//|
static mp_obj_t text_move(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
text_obj_t *self = MP_OBJ_TO_PTR(self_in);
self->x = mp_obj_get_int(x_in);

View file

@ -19,6 +19,7 @@
//| The `_stage` module contains native code to speed-up the ```stage`` Library
//| <https://github.com/python-ugame/circuitpython-stage>`_."""
//|
//|
//| def render(
//| x0: int,
//| y0: int,
@ -50,6 +51,7 @@
//| This function is intended for internal use in the ``stage`` library
//| and all the necessary checks are performed there."""
//|
//|
static mp_obj_t stage_render(size_t n_args, const mp_obj_t *args) {
uint16_t x0 = mp_obj_get_int(args[0]);
uint16_t y0 = mp_obj_get_int(args[1]);

View file

@ -43,7 +43,9 @@
//| with device:
//| device.write(bytes_read)
//| """
//|
//| ...
//|
static mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
adafruit_bus_device_i2cdevice_obj_t *self =
mp_obj_malloc(adafruit_bus_device_i2cdevice_obj_t, &adafruit_bus_device_i2cdevice_type);
@ -69,6 +71,7 @@ static mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type
//| def __enter__(self) -> I2CDevice:
//| """Context manager entry to lock bus."""
//| ...
//|
static mp_obj_t adafruit_bus_device_i2cdevice_obj___enter__(mp_obj_t self_in) {
adafruit_bus_device_i2cdevice_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_adafruit_bus_device_i2cdevice_lock(self);
@ -79,6 +82,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(adafruit_bus_device_i2cdevice___enter___obj, ad
//| def __exit__(self) -> None:
//| """Automatically unlocks the bus on exit."""
//| ...
//|
static mp_obj_t adafruit_bus_device_i2cdevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
common_hal_adafruit_bus_device_i2cdevice_unlock(MP_OBJ_TO_PTR(args[0]));
return mp_const_none;
@ -86,6 +90,7 @@ static mp_obj_t adafruit_bus_device_i2cdevice_obj___exit__(size_t n_args, const
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_i2cdevice___exit___obj, 4, 4, adafruit_bus_device_i2cdevice_obj___exit__);
//| import sys
//|
//| def readinto(
//| self, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize
//| ) -> None:
@ -100,6 +105,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(adafruit_bus_device_i2cdevice___exit_
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
//| """
//| ...
//|
static mp_obj_t adafruit_bus_device_i2cdevice_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end };
static const mp_arg_t allowed_args[] = {
@ -134,6 +140,7 @@ static mp_obj_t adafruit_bus_device_i2cdevice_readinto(size_t n_args, const mp_o
static MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 1, adafruit_bus_device_i2cdevice_readinto);
//| import sys
//|
//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
//| """Write the bytes from ``buffer`` to the device, then transmit a stop bit.
//|
@ -146,6 +153,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_readinto_obj, 1,
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
//| """
//| ...
//|
static mp_obj_t adafruit_bus_device_i2cdevice_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end };
static const mp_arg_t allowed_args[] = {
@ -180,6 +188,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 1, adafruit_
//| import sys
//|
//| def write_then_readinto(
//| self,
//| out_buffer: ReadableBuffer,
@ -188,7 +197,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 1, adafruit_
//| out_start: int = 0,
//| out_end: int = sys.maxsize,
//| in_start: int = 0,
//| in_end: int = sys.maxsize
//| in_end: int = sys.maxsize,
//| ) -> None:
//| """Write the bytes from ``out_buffer`` to the device, then immediately
//| reads into ``in_buffer`` from the device.
@ -210,6 +219,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(adafruit_bus_device_i2cdevice_write_obj, 1, adafruit_
//| """
//| ...
//|
//|
static mp_obj_t adafruit_bus_device_i2cdevice_write_then_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
static const mp_arg_t allowed_args[] = {

View file

@ -27,7 +27,7 @@
//| baudrate: int = 100000,
//| polarity: int = 0,
//| phase: int = 0,
//| extra_clocks: int = 0
//| extra_clocks: int = 0,
//| ) -> None:
//| """
//| Represents a single SPI device and manages locking the bus and the device address.
@ -55,7 +55,9 @@
//| # A second transaction
//| with device as spi:
//| spi.write(bytes_read)"""
//|
//| ...
//|
static mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
adafruit_bus_device_spidevice_obj_t *self =
mp_obj_malloc(adafruit_bus_device_spidevice_obj_t, &adafruit_bus_device_spidevice_type);
@ -97,6 +99,7 @@ static mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type
//| def __enter__(self) -> busio.SPI:
//| """Starts a SPI transaction by configuring the SPI and asserting chip select."""
//| ...
//|
static mp_obj_t adafruit_bus_device_spidevice_obj___enter__(mp_obj_t self_in) {
adafruit_bus_device_spidevice_obj_t *self = MP_OBJ_TO_PTR(self_in);
return common_hal_adafruit_bus_device_spidevice_enter(self);
@ -109,6 +112,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(adafruit_bus_device_spidevice___enter___obj, ad
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
//|
static mp_obj_t adafruit_bus_device_spidevice_obj___exit__(size_t n_args, const mp_obj_t *args) {
common_hal_adafruit_bus_device_spidevice_exit(MP_OBJ_TO_PTR(args[0]));
return mp_const_none;

View file

@ -41,7 +41,7 @@ static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t
//| brightness: float = 0,
//| auto_write: bool = False,
//| header: ReadableBuffer = b"",
//| trailer: ReadableBuffer = b""
//| trailer: ReadableBuffer = b"",
//| ) -> None:
//| """Create a PixelBuf object of the specified size, byteorder, and bits per pixel.
//|
@ -61,6 +61,7 @@ static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t
//| :param ~circuitpython_typing.ReadableBuffer trailer: Sequence of bytes to always send after pixel values.
//| """
//| ...
//|
static mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_size, ARG_byteorder, ARG_brightness, ARG_auto_write, ARG_header, ARG_trailer };
static const mp_arg_t allowed_args[] = {
@ -201,6 +202,7 @@ MP_PROPERTY_GETSET(pixelbuf_pixelbuf_auto_write_obj,
//| byteorder: str
//| """byteorder string for the buffer (read-only)"""
//|
static mp_obj_t pixelbuf_pixelbuf_obj_get_byteorder(mp_obj_t self_in) {
return common_hal_adafruit_pixelbuf_pixelbuf_get_byteorder_string(self_in);
}
@ -224,6 +226,7 @@ static mp_obj_t pixelbuf_pixelbuf_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
//| """Transmits the color data to the pixels so that they are shown. This is done automatically
//| when `auto_write` is True."""
//| ...
//|
static mp_obj_t pixelbuf_pixelbuf_show(mp_obj_t self_in) {
common_hal_adafruit_pixelbuf_pixelbuf_show(self_in);
@ -234,6 +237,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_show_obj, pixelbuf_pixelbuf_s
//| def fill(self, color: PixelType) -> None:
//| """Fills the given pixelbuf with the given color."""
//| ...
//|
static mp_obj_t pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t value) {
common_hal_adafruit_pixelbuf_pixelbuf_fill(self_in, value);
@ -267,6 +271,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(pixelbuf_pixelbuf_fill_obj, pixelbuf_pixelbuf_f
//| is used instead when the red, green, and blue values are the same."""
//| ...
//|
//|
static mp_obj_t pixelbuf_pixelbuf_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
if (value == MP_OBJ_NULL) {
// delete item

View file

@ -19,6 +19,7 @@
//| MODE_CBC: int
//| MODE_CTR: int
//|
//|
//| class AES:
//| """Encrypt and decrypt AES streams"""
//|
@ -50,6 +51,7 @@
//| cipher.encrypt_into(inp, outp)
//| hexlify(outp)"""
//| ...
//|
static mp_obj_t aesio_aes_make_new(const mp_obj_type_t *type, size_t n_args,
size_t n_kw, const mp_obj_t *all_args) {
@ -114,6 +116,7 @@ static mp_obj_t aesio_aes_make_new(const mp_obj_type_t *type, size_t n_args,
//| :param ~circuitpython_typing.ReadableBuffer IV: Initialization vector to use
//| for CBC or CTR mode"""
//| ...
//|
static mp_obj_t aesio_aes_rekey(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
aesio_aes_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
enum { ARG_key, ARG_IV };
@ -177,6 +180,7 @@ static void validate_length(aesio_aes_obj_t *self, size_t src_length,
//| buffers must be a multiple of 16 bytes, and must be equal length. For
//| CTR mode, there are no restrictions."""
//| ...
//|
static mp_obj_t aesio_aes_encrypt_into(mp_obj_t self_in, mp_obj_t src, mp_obj_t dest) {
aesio_aes_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -200,6 +204,7 @@ static MP_DEFINE_CONST_FUN_OBJ_3(aesio_aes_encrypt_into_obj, aesio_aes_encrypt_i
//| CTR mode, there are no restrictions."""
//| ...
//|
//|
static mp_obj_t aesio_aes_decrypt_into(mp_obj_t self_in, mp_obj_t src, mp_obj_t dest) {
aesio_aes_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -43,6 +43,7 @@
//| def __len__(self) -> int:
//| """Return the length. This is used by (`len`)"""
//| ...
//|
static mp_obj_t alarm_sleep_memory_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
alarm_sleep_memory_obj_t *self = MP_OBJ_TO_PTR(self_in);
uint16_t len = common_hal_alarm_sleep_memory_get_length(self);
@ -75,6 +76,7 @@ static MP_DEFINE_CONST_DICT(alarm_sleep_memory_locals_dict, alarm_sleep_memory_l
//| """Set the value at the given index."""
//| ...
//|
//|
static mp_obj_t alarm_sleep_memory_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
if (value == MP_OBJ_NULL) {
// delete item

View file

@ -44,6 +44,7 @@
//| For more information about working with alarms and light/deep sleep in CircuitPython,
//| see `this Learn guide <https://learn.adafruit.com/deep-sleep-with-circuitpython>`_.
//| """
//|
//| sleep_memory: SleepMemory
//| """Memory that persists during deep sleep.
@ -54,6 +55,7 @@
//| If no alarm occurred since the last hard reset or soft restart, value is ``None``.
//| """
//|
//|
// wake_alarm is implemented as a dictionary entry, so there's no code here.
@ -90,6 +92,7 @@ static void validate_objs_are_alarms(size_t n_args, const mp_obj_t *objs) {
//| """
//| ...
//|
//|
static mp_obj_t alarm_light_sleep_until_alarms(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return mp_const_none;
@ -172,6 +175,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_light_sleep_until_alarms_obj, 1, MP_OB
//| """
//| ...
//|
//|
static mp_obj_t alarm_exit_and_deep_sleep_until_alarms(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_preserve_dios };
static const mp_arg_t allowed_args[] = {

View file

@ -40,6 +40,7 @@
//| pulls it high.
//| """
//| ...
//|
static mp_obj_t alarm_pin_pinalarm_make_new(const mp_obj_type_t *type, mp_uint_t n_args, size_t n_kw, const mp_obj_t *all_args) {
alarm_pin_pinalarm_obj_t *self = mp_obj_malloc(alarm_pin_pinalarm_obj_t, &alarm_pin_pinalarm_type);
enum { ARG_pin, ARG_value, ARG_edge, ARG_pull };
@ -81,6 +82,7 @@ MP_PROPERTY_GETTER(alarm_pin_pinalarm_pin_obj,
//| value: bool
//| """The value on which to trigger."""
//|
//|
static mp_obj_t alarm_pin_pinalarm_obj_get_value(mp_obj_t self_in) {
alarm_pin_pinalarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_bool(common_hal_alarm_pin_pinalarm_get_value(self));

View file

@ -37,6 +37,7 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
//| due to this time alarm.
//| """
//| ...
//|
static mp_obj_t alarm_time_timealarm_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
alarm_time_timealarm_obj_t *self = mp_obj_malloc(alarm_time_timealarm_obj_t, &alarm_time_timealarm_type);
@ -96,6 +97,7 @@ static mp_obj_t alarm_time_timealarm_make_new(const mp_obj_type_t *type,
//| by this property only as a `time.monotonic()` time.
//| """
//|
//|
static mp_obj_t alarm_time_timealarm_obj_get_monotonic_time(mp_obj_t self_in) {
alarm_time_timealarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
return mp_obj_new_float(common_hal_alarm_time_timealarm_get_monotonic_time(self));

View file

@ -23,6 +23,7 @@
//| **Limitations:** Not available on SAMD, Nordic, or RP2040.
//| """
//| ...
//|
static mp_obj_t alarm_touch_touchalarm_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
alarm_touch_touchalarm_obj_t *self = mp_obj_malloc(alarm_touch_touchalarm_obj_t, &alarm_touch_touchalarm_type);
@ -45,6 +46,7 @@ static mp_obj_t alarm_touch_touchalarm_make_new(const mp_obj_type_t *type,
//| pin: microcontroller.Pin
//| """The trigger pin."""
//|
//|
static mp_obj_t alarm_touch_touchalarm_obj_get_pin(mp_obj_t self_in) {
alarm_touch_touchalarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_FROM_PTR(self->pin);

View file

@ -42,6 +42,7 @@
//| :param ~microcontroller.Pin pin: the pin to read from
//| :param ~int sample_rate: rate: sampling frequency, in samples per second"""
//| ...
//|
static mp_obj_t analogbufio_bufferedin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_pin, ARG_sample_rate };
static const mp_arg_t allowed_args[] = {
@ -66,6 +67,7 @@ static mp_obj_t analogbufio_bufferedin_make_new(const mp_obj_type_t *type, size_
//| def deinit(self) -> None:
//| """Shut down the `BufferedIn` and release the pin for other use."""
//| ...
//|
static mp_obj_t analogbufio_bufferedin_deinit(mp_obj_t self_in) {
analogbufio_bufferedin_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_analogbufio_bufferedin_deinit(self);
@ -81,12 +83,14 @@ static void check_for_deinit(analogbufio_bufferedin_obj_t *self) {
//| def __enter__(self) -> BufferedIn:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t analogbufio_bufferedin___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_analogbufio_bufferedin_deinit(args[0]);
@ -110,6 +114,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(analogbufio_bufferedin___exit___obj,
//| """
//| ...
//|
//|
static mp_obj_t analogbufio_bufferedin_obj_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_loop };
static const mp_arg_t allowed_args[] = {

View file

@ -46,6 +46,7 @@ MP_WEAK const mcu_pin_obj_t *common_hal_analogio_analogin_validate_pin(mp_obj_t
//| when you read a value. You can retry the read.
//| """
//| ...
//|
static mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
mp_uint_t n_args, size_t n_kw, const mp_obj_t *args) {
// check number of arguments
@ -62,6 +63,7 @@ static mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
//| def deinit(self) -> None:
//| """Turn off the AnalogIn and release the pin for other use."""
//| ...
//|
static mp_obj_t analogio_analogin_deinit(mp_obj_t self_in) {
analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_analogio_analogin_deinit(self);
@ -77,12 +79,14 @@ static void check_for_deinit(analogio_analogin_obj_t *self) {
//| def __enter__(self) -> AnalogIn:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t analogio_analogin___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_analogio_analogin_deinit(args[0]);
@ -110,6 +114,7 @@ MP_PROPERTY_GETTER(analogio_analogin_value_obj,
//| ``float`` in Volts. Note the ADC value may not scale to the actual voltage linearly
//| at ends of the analog range."""
//|
//|
static mp_obj_t analogio_analogin_obj_get_reference_voltage(mp_obj_t self_in) {
analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -36,6 +36,7 @@
//|
//| """
//| ...
//|
static mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t n_args, size_t n_kw, const mp_obj_t *args) {
// check arguments
mp_arg_check_num(n_args, n_kw, 1, 1, false);
@ -51,6 +52,7 @@ static mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t
//| def deinit(self) -> None:
//| """Turn off the AnalogOut and release the pin for other use."""
//| ...
//|
static mp_obj_t analogio_analogout_deinit(mp_obj_t self_in) {
analogio_analogout_obj_t *self = self_in;
@ -63,12 +65,14 @@ static MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogout_deinit_obj, analogio_analogo
//| def __enter__(self) -> AnalogOut:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t analogio_analogout___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_analogio_analogout_deinit(args[0]);
@ -82,6 +86,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(analogio_analogout___exit___obj, 4, 4
//| Even if the underlying digital to analog converter (DAC) is lower
//| resolution, the value is 16-bit."""
//|
//|
static mp_obj_t analogio_analogout_obj_set_value(mp_obj_t self_in, mp_obj_t value) {
analogio_analogout_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (common_hal_analogio_analogout_deinited(self)) {

View file

@ -16,8 +16,10 @@
//|
//| |see_cpython_module| :mod:`cpython:atexit`.
//| """
//|
//| ...
//|
//|
//| def register(
//| func: Callable[..., Any], *args: Optional[Any], **kwargs: Optional[Any]
@ -38,6 +40,7 @@
//| """
//| ...
//|
//|
static mp_obj_t atexit_register(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
shared_module_atexit_register(pos_args[0], (n_args - 1), ((n_args > 1) ? &pos_args[1] : NULL), kw_args);
return pos_args[0];
@ -53,6 +56,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(atexit_register_obj, 1, atexit_register);
//| """
//| ...
//|
//|
static mp_obj_t atexit_unregister(const mp_obj_t self_in) {
shared_module_atexit_unregister(&self_in);
return mp_const_none;

View file

@ -24,7 +24,7 @@
//| data: microcontroller.Pin,
//| *,
//| main_clock: Optional[microcontroller.Pin] = None,
//| left_justified: bool = False
//| left_justified: bool = False,
//| ) -> None:
//| """Create a I2SOut object associated with the given pins.
//|
@ -76,6 +76,7 @@
//| pass
//| print("stopped")"""
//| ...
//|
static mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if !CIRCUITPY_AUDIOBUSIO_I2SOUT
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_I2SOut);
@ -109,6 +110,7 @@ static mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
//| def deinit(self) -> None:
//| """Deinitialises the I2SOut and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t audiobusio_i2sout_deinit(mp_obj_t self_in) {
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiobusio_i2sout_deinit(self);
@ -125,12 +127,14 @@ static void check_for_deinit(audiobusio_i2sout_obj_t *self) {
//| def __enter__(self) -> I2SOut:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audiobusio_i2sout_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiobusio_i2sout_deinit(args[0]);
@ -147,6 +151,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_i2sout___exit___obj, 4, 4,
//|
//| The sample itself should consist of 8 bit or 16 bit samples."""
//| ...
//|
static mp_obj_t audiobusio_i2sout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_sample, ARG_loop };
static const mp_arg_t allowed_args[] = {
@ -168,6 +173,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiobusio_i2sout_play_obj, 1, audiobusio_i2sout_obj_
//| def stop(self) -> None:
//| """Stops playback."""
//| ...
//|
static mp_obj_t audiobusio_i2sout_obj_stop(mp_obj_t self_in) {
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -178,6 +184,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_stop_obj, audiobusio_i2sout_obj_stop
//| playing: bool
//| """True when the audio sample is being output. (read-only)"""
//|
static mp_obj_t audiobusio_i2sout_obj_get_playing(mp_obj_t self_in) {
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -191,6 +198,7 @@ MP_PROPERTY_GETTER(audiobusio_i2sout_playing_obj,
//| def pause(self) -> None:
//| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
//| ...
//|
static mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) {
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -206,6 +214,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_pause_obj, audiobusio_i2sout_obj_pau
//| def resume(self) -> None:
//| """Resumes sample playback after :py:func:`pause`."""
//| ...
//|
static mp_obj_t audiobusio_i2sout_obj_resume(mp_obj_t self_in) {
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -221,6 +230,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_resume_obj, audiobusio_i2sout_obj_re
//| paused: bool
//| """True when playback is paused. (read-only)"""
//|
//|
static mp_obj_t audiobusio_i2sout_obj_get_paused(mp_obj_t self_in) {
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -27,7 +27,7 @@
//| bit_depth: int = 8,
//| mono: bool = True,
//| oversample: int = 64,
//| startup_delay: float = 0.11
//| startup_delay: float = 0.11,
//| ) -> None:
//| """Create a PDMIn object associated with the given pins. This allows you to
//| record audio signals from the given pins. Individual ports may put further
@ -70,7 +70,9 @@
//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16) as mic:
//| mic.record(b, len(b))
//| """
//|
//| ...
//|
static mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if !CIRCUITPY_AUDIOBUSIO_PDMIN
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_PDMIn);
@ -127,6 +129,7 @@ static mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar
//| def deinit(self) -> None:
//| """Deinitialises the PDMIn and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t audiobusio_pdmin_deinit(mp_obj_t self_in) {
audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiobusio_pdmin_deinit(self);
@ -142,11 +145,13 @@ static void check_for_deinit(audiobusio_pdmin_obj_t *self) {
//| def __enter__(self) -> PDMIn:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context."""
//| ...
//|
static mp_obj_t audiobusio_pdmin_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiobusio_pdmin_deinit(args[0]);
@ -166,6 +171,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_pdmin___exit___obj, 4, 4,
//| :return: The number of samples recorded. If this is less than ``destination_length``,
//| some samples were missed due to processing time."""
//| ...
//|
static mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destination, mp_obj_t destination_length) {
audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_obj);
check_for_deinit(self);
@ -198,6 +204,7 @@ MP_DEFINE_CONST_FUN_OBJ_3(audiobusio_pdmin_record_obj, audiobusio_pdmin_obj_reco
//| """The actual sample_rate of the recording. This may not match the constructed
//| sample rate due to internal clock limitations."""
//|
//|
static mp_obj_t audiobusio_pdmin_obj_get_sample_rate(mp_obj_t self_in) {
audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -22,7 +22,7 @@
//| *,
//| channel_count: int = 1,
//| sample_rate: int = 8000,
//| single_buffer: bool = True
//| single_buffer: bool = True,
//| ) -> None:
//| """Create a RawSample based on the given buffer of values. If channel_count is more than
//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the
@ -77,6 +77,7 @@
//| pwm.stop()
//| pwm.deinit()"""
//| ...
//|
static mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_buffer, ARG_channel_count, ARG_sample_rate, ARG_single_buffer };
static const mp_arg_t allowed_args[] = {
@ -111,6 +112,7 @@ static mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_a
//| def deinit(self) -> None:
//| """Deinitialises the RawSample and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t audioio_rawsample_deinit(mp_obj_t self_in) {
audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audioio_rawsample_deinit(self);
@ -127,12 +129,14 @@ static void check_for_deinit(audioio_rawsample_obj_t *self) {
//| def __enter__(self) -> RawSample:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audioio_rawsample_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audioio_rawsample_deinit(args[0]);
@ -146,6 +150,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_rawsample___exit___obj, 4, 4,
//| sample. This will not change the sample rate of any active playback. Call ``play`` again to
//| change it."""
//|
//|
static mp_obj_t audioio_rawsample_obj_get_sample_rate(mp_obj_t self_in) {
audioio_rawsample_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -50,6 +50,7 @@
//| print("stopped")
//| """
//| ...
//|
static mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, 2, false);
mp_obj_t arg = args[0];
@ -79,6 +80,7 @@ static mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_ar
//| def deinit(self) -> None:
//| """Deinitialises the WaveFile and releases all memory resources for reuse."""
//| ...
//|
static mp_obj_t audioio_wavefile_deinit(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audioio_wavefile_deinit(self);
@ -95,12 +97,14 @@ static void check_for_deinit(audioio_wavefile_obj_t *self) {
//| def __enter__(self) -> WaveFile:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audioio_wavefile_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audioio_wavefile_deinit(args[0]);
@ -145,6 +149,7 @@ MP_PROPERTY_GETTER(audioio_wavefile_bits_per_sample_obj,
//| channel_count: int
//| """Number of audio channels. (read only)"""
//|
//|
static mp_obj_t audioio_wavefile_obj_get_channel_count(mp_obj_t self_in) {
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -76,6 +76,7 @@
//| synth.release(note)
//| time.sleep(5)"""
//| ...
//|
static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_max_delay_ms, ARG_delay_ms, ARG_decay, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, ARG_freq_shift, };
static const mp_arg_t allowed_args[] = {
@ -112,6 +113,7 @@ static mp_obj_t audiodelays_echo_make_new(const mp_obj_type_t *type, size_t n_ar
//| def deinit(self) -> None:
//| """Deinitialises the Echo."""
//| ...
//|
static mp_obj_t audiodelays_echo_deinit(mp_obj_t self_in) {
audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiodelays_echo_deinit(self);
@ -128,12 +130,14 @@ static void check_for_deinit(audiodelays_echo_obj_t *self) {
//| def __enter__(self) -> Echo:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audiodelays_echo_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiodelays_echo_deinit(args[0]);
@ -224,6 +228,7 @@ MP_PROPERTY_GETSET(audiodelays_echo_freq_shift_obj,
//| playing: bool
//| """True when the effect is playing a sample. (read-only)"""
//|
static mp_obj_t audiodelays_echo_obj_get_playing(mp_obj_t self_in) {
audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -240,6 +245,7 @@ MP_PROPERTY_GETTER(audiodelays_echo_playing_obj,
//|
//| The sample must match the encoding settings given in the constructor."""
//| ...
//|
static mp_obj_t audiodelays_echo_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_sample, ARG_loop };
static const mp_arg_t allowed_args[] = {
@ -263,6 +269,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiodelays_echo_play_obj, 1, audiodelays_echo_obj_pl
//| """Stops playback of the sample. The echo continues playing."""
//| ...
//|
//|
static mp_obj_t audiodelays_echo_obj_stop(mp_obj_t self_in) {
audiodelays_echo_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -31,6 +31,7 @@
//| WAVESHAPE: DistortionMode
//| """Waveshaper distortions are used mainly by electronic musicians to achieve an extra-abrasive sound."""
//|
//|
MAKE_ENUM_VALUE(audiofilters_distortion_mode_type, distortion_mode, CLIP, DISTORTION_MODE_CLIP);
MAKE_ENUM_VALUE(audiofilters_distortion_mode_type, distortion_mode, LOFI, DISTORTION_MODE_LOFI);
@ -110,6 +111,7 @@ static audiofilters_distortion_mode validate_distortion_mode(mp_obj_t obj, qstr
//| synth.release(note)
//| time.sleep(5)"""
//| ...
//|
static mp_obj_t audiofilters_distortion_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_drive, ARG_pre_gain, ARG_post_gain, ARG_mode, ARG_soft_clip, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, };
@ -150,6 +152,7 @@ static mp_obj_t audiofilters_distortion_make_new(const mp_obj_type_t *type, size
//| def deinit(self) -> None:
//| """Deinitialises the Distortion."""
//| ...
//|
static mp_obj_t audiofilters_distortion_deinit(mp_obj_t self_in) {
audiofilters_distortion_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiofilters_distortion_deinit(self);
@ -166,12 +169,14 @@ static void check_for_deinit(audiofilters_distortion_obj_t *self) {
//| def __enter__(self) -> Distortion:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audiofilters_distortion_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiofilters_distortion_deinit(args[0]);
@ -299,6 +304,7 @@ MP_PROPERTY_GETSET(audiofilters_distortion_mix_obj,
//| playing: bool
//| """True when the effect is playing a sample. (read-only)"""
//|
static mp_obj_t audiofilters_distortion_obj_get_playing(mp_obj_t self_in) {
audiofilters_distortion_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -315,6 +321,7 @@ MP_PROPERTY_GETTER(audiofilters_distortion_playing_obj,
//|
//| The sample must match the encoding settings given in the constructor."""
//| ...
//|
static mp_obj_t audiofilters_distortion_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_sample, ARG_loop };
static const mp_arg_t allowed_args[] = {
@ -338,6 +345,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_distortion_play_obj, 1, audiofilters_dis
//| """Stops playback of the sample."""
//| ...
//|
//|
static mp_obj_t audiofilters_distortion_obj_stop(mp_obj_t self_in) {
audiofilters_distortion_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -68,6 +68,7 @@
//| synth.release(note)
//| time.sleep(5)"""
//| ...
//|
static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_filter, ARG_mix, ARG_buffer_size, ARG_sample_rate, ARG_bits_per_sample, ARG_samples_signed, ARG_channel_count, };
static const mp_arg_t allowed_args[] = {
@ -99,6 +100,7 @@ static mp_obj_t audiofilters_filter_make_new(const mp_obj_type_t *type, size_t n
//| def deinit(self) -> None:
//| """Deinitialises the Filter."""
//| ...
//|
static mp_obj_t audiofilters_filter_deinit(mp_obj_t self_in) {
audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiofilters_filter_deinit(self);
@ -115,12 +117,14 @@ static void check_for_deinit(audiofilters_filter_obj_t *self) {
//| def __enter__(self) -> Filter:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audiofilters_filter_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiofilters_filter_deinit(args[0]);
@ -172,6 +176,7 @@ MP_PROPERTY_GETSET(audiofilters_filter_mix_obj,
//| playing: bool
//| """True when the effect is playing a sample. (read-only)"""
//|
static mp_obj_t audiofilters_filter_obj_get_playing(mp_obj_t self_in) {
audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -188,6 +193,7 @@ MP_PROPERTY_GETTER(audiofilters_filter_playing_obj,
//|
//| The sample must match the encoding settings given in the constructor."""
//| ...
//|
static mp_obj_t audiofilters_filter_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_sample, ARG_loop };
static const mp_arg_t allowed_args[] = {
@ -211,6 +217,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiofilters_filter_play_obj, 1, audiofilters_filter_
//| """Stops playback of the sample."""
//| ...
//|
//|
static mp_obj_t audiofilters_filter_obj_stop(mp_obj_t self_in) {
audiofilters_filter_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -23,7 +23,7 @@
//| left_channel: microcontroller.Pin,
//| *,
//| right_channel: Optional[microcontroller.Pin] = None,
//| quiescent_value: int = 0x8000
//| quiescent_value: int = 0x8000,
//| ) -> None:
//| """Create a AudioOut object associated with the given pin(s). This allows you to
//| play audio signals out on the given pin(s).
@ -74,6 +74,7 @@
//| pass
//| print("stopped")"""
//| ...
//|
static mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
static const mp_arg_t allowed_args[] = {
@ -99,6 +100,7 @@ static mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
//| def deinit(self) -> None:
//| """Deinitialises the AudioOut and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t audioio_audioout_deinit(mp_obj_t self_in) {
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audioio_audioout_deinit(self);
@ -114,12 +116,14 @@ static void check_for_deinit(audioio_audioout_obj_t *self) {
//| def __enter__(self) -> AudioOut:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audioio_audioout_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audioio_audioout_deinit(args[0]);
@ -138,6 +142,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_audioout___exit___obj, 4, 4,
//| resolution will use the highest order bits to output. For example, the SAMD21 has a 10 bit
//| DAC that ignores the lowest 6 bits when playing 16 bit samples."""
//| ...
//|
static mp_obj_t audioio_audioout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_sample, ARG_loop };
static const mp_arg_t allowed_args[] = {
@ -159,6 +164,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audioio_audioout_play_obj, 1, audioio_audioout_obj_pl
//| def stop(self) -> None:
//| """Stops playback and resets to the start of the sample."""
//| ...
//|
static mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -169,6 +175,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_stop_obj, audioio_audioout_obj_stop);
//| playing: bool
//| """True when an audio sample is being output even if `paused`. (read-only)"""
//|
static mp_obj_t audioio_audioout_obj_get_playing(mp_obj_t self_in) {
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -182,6 +189,7 @@ MP_PROPERTY_GETTER(audioio_audioout_playing_obj,
//| def pause(self) -> None:
//| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
//| ...
//|
static mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) {
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -197,6 +205,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_pause_obj, audioio_audioout_obj_pause
//| def resume(self) -> None:
//| """Resumes sample playback after :py:func:`pause`."""
//| ...
//|
static mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -212,6 +221,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_resume_obj, audioio_audioout_obj_resu
//| paused: bool
//| """True when playback is paused. (read-only)"""
//|
//|
static mp_obj_t audioio_audioout_obj_get_paused(mp_obj_t self_in) {
audioio_audioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -62,6 +62,7 @@
//| time.sleep(1)
//| print("stopped")"""
//| ...
//|
static mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate };
static const mp_arg_t allowed_args[] = {
@ -98,6 +99,7 @@ static mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar
//| def deinit(self) -> None:
//| """Deinitialises the Mixer and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t audiomixer_mixer_deinit(mp_obj_t self_in) {
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiomixer_mixer_deinit(self);
@ -114,12 +116,14 @@ static void check_for_deinit(audiomixer_mixer_obj_t *self) {
//| def __enter__(self) -> Mixer:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audiomixer_mixer_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiomixer_mixer_deinit(args[0]);
@ -158,6 +162,7 @@ MP_PROPERTY_GETTER(audiomixer_mixer_sample_rate_obj,
//|
//| >>> mixer.voice
//| (<MixerVoice>,)"""
//|
static mp_obj_t audiomixer_mixer_obj_get_voice(mp_obj_t self_in) {
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -178,6 +183,7 @@ MP_PROPERTY_GETTER(audiomixer_mixer_voice_obj,
//|
//| The sample must match the Mixer's encoding settings given in the constructor."""
//| ...
//|
static mp_obj_t audiomixer_mixer_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_sample, ARG_voice, ARG_loop };
static const mp_arg_t allowed_args[] = {
@ -206,6 +212,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixer_play_obj, 1, audiomixer_mixer_obj_pl
//| """Stops playback of the sample on the given voice."""
//| ...
//|
//|
static mp_obj_t audiomixer_mixer_obj_stop_voice(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_voice };
static const mp_arg_t allowed_args[] = {

View file

@ -25,6 +25,7 @@
//| def __init__(self) -> None:
//| """MixerVoice instance object(s) created by `audiomixer.Mixer`."""
//| ...
//|
// TODO: support mono or stereo voices
static mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false);
@ -44,6 +45,7 @@ static mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t
//| The sample must match the `audiomixer.Mixer`'s encoding settings given in the constructor.
//| """
//| ...
//|
static mp_obj_t audiomixer_mixervoice_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_sample, ARG_loop };
static const mp_arg_t allowed_args[] = {
@ -63,6 +65,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_play_obj, 1, audiomixer_mixervo
//| def stop(self) -> None:
//| """Stops playback of the sample on this voice."""
//| ...
//|
static mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_voice };
static const mp_arg_t allowed_args[] = {
@ -120,6 +123,7 @@ MP_PROPERTY_GETSET(audiomixer_mixervoice_loop_obj,
//| playing: bool
//| """True when this voice is being output. (read-only)"""
//|
//|
static mp_obj_t audiomixer_mixervoice_obj_get_playing(mp_obj_t self_in) {
audiomixer_mixervoice_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -80,6 +80,7 @@
//| that the socket closes when the stream ends.
//| """
//| ...
//|
static mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, 2, false);
@ -112,6 +113,7 @@ static mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar
//| def deinit(self) -> None:
//| """Deinitialises the MP3 and releases all memory resources for reuse."""
//| ...
//|
static mp_obj_t audiomp3_mp3file_deinit(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiomp3_mp3file_deinit(self);
@ -128,12 +130,14 @@ static void check_for_deinit(audiomp3_mp3file_obj_t *self) {
//| def __enter__(self) -> MP3Decoder:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audiomp3_mp3file_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiomp3_mp3file_deinit(args[0]);
@ -143,6 +147,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomp3_mp3file___exit___obj, 4, 4,
//| file: typing.BinaryIO
//| """File to play back."""
//|
static mp_obj_t audiomp3_mp3file_obj_get_file(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -166,6 +171,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(audiomp3_mp3file_set_file_obj, audiomp3_mp3file_obj_se
//| def open(self, filepath: str) -> None:
//| """Takes in the name of a mp3 file, opens it, and replaces the old playback file."""
//| ...
//|
static mp_obj_t audiomp3_mp3file_obj_open(mp_obj_t self_in, mp_obj_t path) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -245,6 +251,7 @@ MP_PROPERTY_GETTER(audiomp3_mp3file_rms_level_obj,
//| samples_decoded: int
//| """The number of audio samples decoded from the current file. (read only)"""
//|
//|
static mp_obj_t audiomp3_mp3file_obj_get_samples_decoded(mp_obj_t self_in) {
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -23,7 +23,7 @@
//| left_channel: microcontroller.Pin,
//| *,
//| right_channel: Optional[microcontroller.Pin] = None,
//| quiescent_value: int = 0x8000
//| quiescent_value: int = 0x8000,
//| ) -> None:
//| """Create a PWMAudioOut object associated with the given pin(s). This allows you to
//| play audio signals out on the given pin(s). In contrast to mod:`audioio`,
@ -81,6 +81,7 @@
//| pass
//| print("stopped")"""
//| ...
//|
static mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
static const mp_arg_t allowed_args[] = {
@ -108,6 +109,7 @@ static mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_
//| def deinit(self) -> None:
//| """Deinitialises the PWMAudioOut and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t audiopwmio_pwmaudioout_deinit(mp_obj_t self_in) {
audiopwmio_pwmaudioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_audiopwmio_pwmaudioout_deinit(self);
@ -123,12 +125,14 @@ static void check_for_deinit(audiopwmio_pwmaudioout_obj_t *self) {
//| def __enter__(self) -> PWMAudioOut:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t audiopwmio_pwmaudioout_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_audiopwmio_pwmaudioout_deinit(args[0]);
@ -146,6 +150,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiopwmio_pwmaudioout___exit___obj,
//| The sample itself should consist of 16 bit samples. Microcontrollers with a lower output
//| resolution will use the highest order bits to output."""
//| ...
//|
static mp_obj_t audiopwmio_pwmaudioout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_sample, ARG_loop };
static const mp_arg_t allowed_args[] = {
@ -167,6 +172,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(audiopwmio_pwmaudioout_play_obj, 1, audiopwmio_pwmaud
//| def stop(self) -> None:
//| """Stops playback and resets to the start of the sample."""
//| ...
//|
static mp_obj_t audiopwmio_pwmaudioout_obj_stop(mp_obj_t self_in) {
audiopwmio_pwmaudioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -177,6 +183,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiopwmio_pwmaudioout_stop_obj, audiopwmio_pwmaudioou
//| playing: bool
//| """True when an audio sample is being output even if `paused`. (read-only)"""
//|
static mp_obj_t audiopwmio_pwmaudioout_obj_get_playing(mp_obj_t self_in) {
audiopwmio_pwmaudioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -190,6 +197,7 @@ MP_PROPERTY_GETTER(audiopwmio_pwmaudioout_playing_obj,
//| def pause(self) -> None:
//| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
//| ...
//|
static mp_obj_t audiopwmio_pwmaudioout_obj_pause(mp_obj_t self_in) {
audiopwmio_pwmaudioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -205,6 +213,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiopwmio_pwmaudioout_pause_obj, audiopwmio_pwmaudioo
//| def resume(self) -> None:
//| """Resumes sample playback after :py:func:`pause`."""
//| ...
//|
static mp_obj_t audiopwmio_pwmaudioout_obj_resume(mp_obj_t self_in) {
audiopwmio_pwmaudioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -220,6 +229,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(audiopwmio_pwmaudioout_resume_obj, audiopwmio_pwmaudio
//| paused: bool
//| """True when playback is paused. (read-only)"""
//|
//|
static mp_obj_t audiopwmio_pwmaudioout_obj_get_paused(mp_obj_t self_in) {
audiopwmio_pwmaudioout_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);

View file

@ -77,6 +77,7 @@
//| :param bool free_bus: Determines whether the SPI bus passed in will be freed when the frame buffer is freed (optional).
//| """
//| ...
//|
static mp_obj_t aurora_epaper_framebuffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_spi_bus, ARG_chip_select, ARG_reset, ARG_busy, ARG_discharge, ARG_width, ARG_height, ARG_power, ARG_free_bus, NUM_ARGS };
static const mp_arg_t allowed_args[] = {
@ -124,6 +125,7 @@ static mp_int_t aurora_epaper_framebuffer_get_buffer(mp_obj_t self_in, mp_buffer
//| AuroraMemoryFramebuffer instance. After deinitialization, no further operations
//| may be performed."""
//| ...
//|
static mp_obj_t aurora_epaper_framebuffer_deinit(mp_obj_t self_in) {
aurora_epaper_framebuffer_obj_t *self = (aurora_epaper_framebuffer_obj_t *)self_in;
common_hal_aurora_epaper_framebuffer_deinit(self);
@ -137,6 +139,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(aurora_epaper_framebuffer_deinit_obj, aurora_ep
//| Higher temperature means faster update speed.
//| """
//| ...
//|
static mp_obj_t aurora_epaper_frambuffer_set_temperature(mp_obj_t self_in, mp_obj_t temperature) {
aurora_epaper_framebuffer_obj_t *self = (aurora_epaper_framebuffer_obj_t *)self_in;
@ -151,6 +154,7 @@ static MP_DEFINE_CONST_FUN_OBJ_2(aurora_epaper_frambuffer_set_temperature_obj, a
//| If you have multiple displays this could be used to keep the other active on soft reset."""
//| ...
//|
//|
static mp_obj_t aurora_epaper_framebuffer_get_free_bus(mp_obj_t self_in) {
aurora_epaper_framebuffer_obj_t *self = (aurora_epaper_framebuffer_obj_t *)self_in;
return mp_obj_new_bool(self->free_bus);

View file

@ -26,7 +26,7 @@
//| sda: microcontroller.Pin,
//| *,
//| frequency: int = 400000,
//| timeout: int = 255
//| timeout: int = 255,
//| ) -> None:
//| """I2C is a two-wire protocol for communicating between devices. At the
//| physical level it consists of 2 wires: SCL and SDA, the clock and data
@ -45,6 +45,7 @@
//| :param int frequency: The clock frequency of the bus
//| :param int timeout: The maximum clock stretching timeout in microseconds"""
//| ...
//|
static mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
static const mp_arg_t allowed_args[] = {
@ -67,6 +68,7 @@ static mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
//| def deinit(self) -> None:
//| """Releases control of the underlying hardware so other classes can use it."""
//| ...
//|
static mp_obj_t bitbangio_i2c_obj_deinit(mp_obj_t self_in) {
bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
shared_module_bitbangio_i2c_deinit(self);
@ -83,12 +85,14 @@ static void check_for_deinit(bitbangio_i2c_obj_t *self) {
//| def __enter__(self) -> I2C:
//| """No-op used in Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware on context exit. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t bitbangio_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
shared_module_bitbangio_i2c_deinit(args[0]);
@ -109,6 +113,7 @@ static void check_lock(bitbangio_i2c_obj_t *self) {
//| :return: ``True`` if a device at ``address`` responds; ``False`` otherwise
//| :rtype: bool"""
//| ...
//|
static mp_obj_t bitbangio_i2c_probe(mp_obj_t self_in, mp_obj_t address_obj) {
bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -124,6 +129,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_i2c_probe_obj, bitbangio_i2c_probe);
//| those that respond. A device responds if it pulls the SDA line low after
//| its address (including a read bit) is sent on the bus."""
//| ...
//|
static mp_obj_t bitbangio_i2c_scan(mp_obj_t self_in) {
bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -143,6 +149,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_scan_obj, bitbangio_i2c_scan);
//| def try_lock(self) -> bool:
//| """Attempts to grab the I2C lock. Returns True on success."""
//| ...
//|
static mp_obj_t bitbangio_i2c_obj_try_lock(mp_obj_t self_in) {
bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -153,6 +160,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_try_lock_obj, bitbangio_i2c_obj_try_lock
//| def unlock(self) -> None:
//| """Releases the I2C lock."""
//| ...
//|
static mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) {
bitbangio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -162,6 +170,7 @@ static mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_i2c_obj_unlock);
//| import sys
//|
//| def readfrom_into(
//| self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize
//| ) -> None:
@ -178,6 +187,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_i2c_obj_unlock);
//| :param int start: Index to start writing at
//| :param int end: Index to write up to but not include"""
//| ...
//|
// Shared arg parsing for readfrom_into and writeto_then_readfrom.
static void readfrom(bitbangio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end) {
mp_buffer_info_t bufinfo;
@ -219,6 +229,7 @@ static mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 1, bitbangio_i2c_readfrom_into);
//| import sys
//|
//| def writeto(
//| self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize
//| ) -> None:
@ -239,6 +250,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 1, bitbangio_i2c_rea
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
//| """
//| ...
//|
// Shared arg parsing for writeto and writeto_then_readfrom.
static void writeto(bitbangio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end, bool stop) {
// get the buffer to write the data from
@ -284,6 +296,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_wr
//| import sys
//|
//| def writeto_then_readfrom(
//| self,
//| address: int,
@ -293,7 +306,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_wr
//| out_start: int = 0,
//| out_end: int = sys.maxsize,
//| in_start: int = 0,
//| in_end: int = sys.maxsize
//| in_end: int = sys.maxsize,
//| ) -> None:
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
@ -317,6 +330,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_wr
//| """
//| ...
//|
//|
static mp_obj_t bitbangio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_address, ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
static const mp_arg_t allowed_args[] = {

View file

@ -52,6 +52,7 @@
//| :param ~microcontroller.Pin MOSI: the Main Out Selected In pin.
//| :param ~microcontroller.Pin MISO: the Main In Selected Out pin."""
//| ...
//|
// TODO(tannewt): Support LSB SPI.
static mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
@ -76,6 +77,7 @@ static mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args,
//| def deinit(self) -> None:
//| """Turn off the SPI bus."""
//| ...
//|
static mp_obj_t bitbangio_spi_obj_deinit(mp_obj_t self_in) {
bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
shared_module_bitbangio_spi_deinit(self);
@ -92,12 +94,14 @@ static void check_for_deinit(bitbangio_spi_obj_t *self) {
//| def __enter__(self) -> SPI:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t bitbangio_spi_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
shared_module_bitbangio_spi_deinit(args[0]);
@ -123,6 +127,7 @@ static void check_lock(bitbangio_spi_obj_t *self) {
//| or second (1). Rising or falling depends on clock polarity.
//| :param int bits: the number of bits per word"""
//| ...
//|
static mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits };
static const mp_arg_t allowed_args[] = {
@ -153,6 +158,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_configure_obj, 1, bitbangio_spi_configu
//| :return: True when lock has been grabbed
//| :rtype: bool"""
//| ...
//|
static mp_obj_t bitbangio_spi_obj_try_lock(mp_obj_t self_in) {
bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -163,6 +169,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_try_lock_obj, bitbangio_spi_obj_try_lock
//| def unlock(self) -> None:
//| """Releases the SPI lock."""
//| ...
//|
static mp_obj_t bitbangio_spi_obj_unlock(mp_obj_t self_in) {
bitbangio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -172,6 +179,7 @@ static mp_obj_t bitbangio_spi_obj_unlock(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_unlock_obj, bitbangio_spi_obj_unlock);
//| import sys
//|
//| def write(self, buf: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
//| """Write the data contained in ``buf``. Requires the SPI being locked.
//| If the buffer is empty, nothing happens.
@ -185,6 +193,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_unlock_obj, bitbangio_spi_obj_unlock);
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
//| """
//| ...
//|
static mp_obj_t bitbangio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end };
static const mp_arg_t allowed_args[] = {
@ -224,13 +233,14 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_write_obj, 1, bitbangio_spi_write);
//| import sys
//|
//| def readinto(
//| self,
//| buffer: WriteableBuffer,
//| *,
//| start: int = 0,
//| end: int = sys.maxsize,
//| write_value: int = 0
//| write_value: int = 0,
//| ) -> None:
//| """Read into ``buffer`` while writing ``write_value`` for each byte read.
//| The SPI object must be locked.
@ -246,6 +256,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_write_obj, 1, bitbangio_spi_write);
//| :param int write_value: value to write while reading
//| """
//| ...
//|
static mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end, ARG_write_value };
static const mp_arg_t allowed_args[] = {
@ -285,6 +296,7 @@ static mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *pos_args,
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_readinto_obj, 1, bitbangio_spi_readinto);
//| import sys
//|
//| def write_readinto(
//| self,
//| out_buffer: ReadableBuffer,
@ -293,7 +305,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_readinto_obj, 1, bitbangio_spi_readinto
//| out_start: int = 0,
//| out_end: int = sys.maxsize,
//| in_start: int = 0,
//| in_end: int = sys.maxsize
//| in_end: int = sys.maxsize,
//| ) -> None:
//| """Write out the data in ``out_buffer`` while simultaneously reading data into ``in_buffer``.
//| The SPI object must be locked.
@ -319,6 +331,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_readinto_obj, 1, bitbangio_spi_readinto
//| """
//| ...
//|
//|
static mp_obj_t bitbangio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
static const mp_arg_t allowed_args[] = {

View file

@ -12,6 +12,7 @@
#include "shared-bindings/displayio/Palette.h"
#include "shared-bindings/bitmapfilter/__init__.h"
//|
//|
//| def morph(
//| bitmap: displayio.Bitmap,
@ -79,6 +80,7 @@
//| bitmapfilter.morph(bitmap, kernel_gauss_3, 1/sum(kernel_gauss_3))
//| """
//|
//|
static mp_float_t get_m(mp_obj_t mul_obj, int sum) {
@ -165,6 +167,7 @@ static mp_float_t float_subscr(mp_obj_t o, int i) {
//| The ``r`` parameter gives the scale factor for the red channel of
//| pixels, and so forth."""
//|
//|
static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_type = {
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ChannelScale),
.n_fields = 3,
@ -198,6 +201,7 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_type = {
//| ) -> None:
//| """Construct a ChannelScaleOffset object"""
//|
//|
static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_offset_type = {
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ChannelScaleOffset),
.n_fields = 6,
@ -253,6 +257,7 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_scale_offset_type = {
//| ) -> None:
//| """Construct a ChannelMixer object"""
//|
//|
static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_type = {
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ChannelMixer),
.n_fields = 9,
@ -305,6 +310,7 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_type = {
//| ) -> None:
//| """Construct a ChannelMixerOffset object"""
//|
//|
static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_offset_type = {
NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_ChannelMixerOffset),
.n_fields = 12,
@ -351,6 +357,7 @@ static const mp_obj_namedtuple_type_t bitmapfilter_channel_mixer_offset_type = {
//| Only pixels set to a non-zero value in the mask are modified.
//| """
//|
//|
static mp_obj_t bitmapfilter_mix(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_bitmap, ARG_weights, ARG_mask };
static const mp_arg_t allowed_args[] = {
@ -424,6 +431,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_mix_obj, 0, bitmapfilter_mix);
//| PIL and ImageMagic both call this "solarize".
//| """
//|
//|
static mp_obj_t bitmapfilter_solarize(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_bitmap, ARG_threshold, ARG_mask };
static const mp_arg_t allowed_args[] = {
@ -458,6 +466,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_solarize_obj, 0, bitmapfilter_solarize);
//| ThreeLookupFunctions = Tuple[LookupFunction, LookupFunction, LookupFunction]
//| """Any sequenceof three `LookupFunction` objects"""
//|
//|
//| def lookup(
//| bitmap: displayio.Bitmap,
//| lookup: LookupFunction | ThreeLookupFunctions,
@ -487,6 +496,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_solarize_obj, 0, bitmapfilter_solarize);
//| Only pixels set to a non-zero value in the mask are modified.
//| """
//|
//|
static int scaled_lut(int maxval, mp_obj_t func, int i) {
mp_obj_t obj = mp_call_function_1(func, mp_obj_new_float(i / (mp_float_t)maxval));
@ -566,6 +576,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_lookup_obj, 0, bitmapfilter_lookup);
//| Only pixels set to a non-zero value in the mask are modified.
//| """
//|
//|
static mp_obj_t bitmapfilter_false_color(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_bitmap, ARG_palette, ARG_mask };
static const mp_arg_t allowed_args[] = {
@ -612,6 +623,7 @@ static uint8_t *get_blend_table(mp_obj_t lookup, int mode) {
//| There is not actually a BlendTable type. The real type is actually any
//| buffer 4096 bytes in length."""
//|
//|
//| def blend_precompute(lookup: BlendFunction, table: BlendTable | None = None) -> BlendTable:
//| """Precompute a BlendTable from a BlendFunction
//|
@ -628,6 +640,7 @@ static uint8_t *get_blend_table(mp_obj_t lookup, int mode) {
//| return a * .33 + b * .67
//| """
//|
//|
static mp_obj_t blend_precompute(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_lookup, ARG_table };
static const mp_arg_t allowed_args[] = {
@ -652,6 +665,7 @@ static mp_obj_t blend_precompute(size_t n_args, const mp_obj_t *pos_args, mp_map
}
MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_blend_precompute_obj, 0, blend_precompute);
//|
//|
//| def blend(
//| dest: displayio.Bitmap,
@ -673,6 +687,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmapfilter_blend_precompute_obj, 0, blend_precomput
//| The destination bitmap is returned.
//| """
//|
//|
static mp_obj_t bitmapfilter_blend(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_dest, ARG_src1, ARG_src2, ARG_lookup, ARG_mask };

View file

@ -52,6 +52,7 @@ bitmaptools_rect_t bitmaptools_validate_coord_range_pair(const mp_arg_val_t in[4
//| for information about using the :py:mod:`displayio` module.
//| """
//|
//|
static int16_t validate_point(mp_obj_t point, int16_t default_value) {
// Checks if point is None and returns default_value, otherwise decodes integer value
@ -141,7 +142,7 @@ static void validate_clip_region(displayio_bitmap_t *bitmap, mp_obj_t clip0_tupl
//| source_clip1: Tuple[int, int],
//| angle: float,
//| scale: float,
//| skip_index: int
//| skip_index: int,
//| ) -> None:
//| """Inserts the source bitmap region into the destination bitmap with rotation
//| (angle), scale and clipping (both on source and destination bitmaps).
@ -176,6 +177,7 @@ static void validate_clip_region(displayio_bitmap_t *bitmap, mp_obj_t clip0_tupl
//| set to None to copy all pixels"""
//| ...
//|
//|
static mp_obj_t bitmaptools_obj_rotozoom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARG_source_bitmap,
ARG_ox, ARG_oy, ARG_dest_clip0, ARG_dest_clip1,
@ -284,6 +286,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_rotozoom_obj, 0, bitmaptools_obj_rotozoom
//| Screen: BlendMode
//| """Blend based on the value in each color channel. The result keeps the lighter colors and discards darker colors."""
//|
//|
MAKE_ENUM_VALUE(bitmaptools_blendmode_type, bitmaptools_blendmode, Normal, BITMAPTOOLS_BLENDMODE_NORMAL);
MAKE_ENUM_VALUE(bitmaptools_blendmode_type, bitmaptools_blendmode, Screen, BITMAPTOOLS_BLENDMODE_SCREEN);
@ -327,6 +330,7 @@ MAKE_ENUM_TYPE(bitmaptools, BlendMode, bitmaptools_blendmode);
//| For the L8 colorspace, the bitmaps must have a bits-per-value of 8.
//| For the RGB colorspaces, they must have a bits-per-value of 16."""
//|
//|
static mp_obj_t bitmaptools_alphablend(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARG_source_bitmap_1, ARG_source_bitmap_2, ARG_colorspace, ARG_factor_1, ARG_factor_2, ARG_blendmode, ARG_skip_source1_index, ARG_skip_source2_index};
@ -429,6 +433,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_alphablend_obj, 0, bitmaptools_alphablend
//| fill region in the destination bitmap"""
//| ...
//|
//|
static mp_obj_t bitmaptools_obj_fill_region(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARGS_X1_Y1_X2_Y2, ARG_value};
@ -477,6 +482,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_fill_region_obj, 0, bitmaptools_obj_fill_
//| value color in the enclosed area in the destination bitmap"""
//| ...
//|
//|
static mp_obj_t bitmaptools_obj_boundary_fill(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_fill_color_value, ARG_replaced_color_value};
@ -537,6 +543,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_boundary_fill_obj, 0, bitmaptools_obj_bou
//| line in the destination bitmap"""
//| ...
//|
//|
static mp_obj_t bitmaptools_obj_draw_line(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_value};
@ -623,6 +630,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_draw_line_obj, 0, bitmaptools_obj_draw_li
//| """
//| ...
//|
//|
static mp_obj_t bitmaptools_obj_draw_polygon(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARG_xs, ARG_ys, ARG_value, ARG_close};
@ -705,6 +713,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_draw_polygon_obj, 0, bitmaptools_obj_draw
//| """
//| ...
//|
//|
static mp_obj_t bitmaptools_arrayblit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_bitmap, ARG_data, ARGS_X1_Y1_X2_Y2, ARG_skip_index };
static const mp_arg_t allowed_args[] = {
@ -768,6 +777,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_arrayblit_obj, 0, bitmaptools_arrayblit);
//| """
//| ...
//|
//|
static mp_obj_t bitmaptools_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_bitmap, ARG_file, ARG_bits_per_pixel, ARG_element_size, ARG_reverse_pixels_in_element, ARG_swap_bytes_in_element, ARG_reverse_rows };
@ -830,6 +840,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_readinto_obj, 0, bitmaptools_readinto);
//| FloydStenberg: "DitherAlgorithm"
//| """The Floyd-Stenberg dither"""
//|
//|
MAKE_ENUM_VALUE(bitmaptools_dither_algorithm_type, dither_algorithm, Atkinson, DITHER_ALGORITHM_ATKINSON);
MAKE_ENUM_VALUE(bitmaptools_dither_algorithm_type, dither_algorithm, FloydStenberg, DITHER_ALGORITHM_FLOYD_STENBERG);
@ -858,6 +869,7 @@ MAKE_ENUM_TYPE(bitmaptools, DitherAlgorithm, bitmaptools_dither_algorithm);
//| """
//| ...
//|
//|
static mp_obj_t bitmaptools_dither(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_dest_bitmap, ARG_source_bitmap, ARG_source_colorspace, ARG_algorithm };
static const mp_arg_t allowed_args[] = {
@ -951,6 +963,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_dither_obj, 0, bitmaptools_dither);
//|
//| ...
//|
//|
static mp_obj_t bitmaptools_obj_draw_circle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_radius, ARG_value};
@ -1000,7 +1013,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_draw_circle_obj, 0, bitmaptools_obj_draw_
//| x2: int | None = None,
//| y2: int | None = None,
//| skip_source_index: int | None = None,
//| skip_dest_index: int | None = None
//| skip_dest_index: int | None = None,
//| ) -> None:
//| """Inserts the source_bitmap region defined by rectangular boundaries
//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location.
@ -1021,6 +1034,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_draw_circle_obj, 0, bitmaptools_obj_draw_
//| by the pixels from the source"""
//| ...
//|
//|
static mp_obj_t bitmaptools_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_destination, ARG_source, ARG_x, ARG_y, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_skip_source_index, ARG_skip_dest_index};
static const mp_arg_t allowed_args[] = {

View file

@ -11,6 +11,7 @@
//| """Routines for low-level manipulation of binary data"""
//|
//|
//| def bit_transpose(
//| input: ReadableBuffer, output: WriteableBuffer, width: int = 8
@ -35,6 +36,7 @@
//| Returns the output buffer."""
//| ...
//|
//|
static mp_obj_t bit_transpose(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_input, ARG_output, ARG_width };

View file

@ -33,12 +33,14 @@
//|
//| .. warning:: The board module varies by board. The APIs documented here may or may not be
//| available on a specific board."""
//|
//| board_id: str
//| """Board ID string. The unique identifier for the board model in
//| circuitpython, as well as on circuitpython.org.
//| Example: "hallowing_m0_express"."""
//|
//|
//| def I2C() -> busio.I2C:
//| """Returns the `busio.I2C` object for the board's designated I2C bus(es).
@ -46,6 +48,7 @@
//| """
//| ...
//|
//|
#if CIRCUITPY_BOARD_I2C
static mp_obj_t board_i2c_0(void) {
return common_hal_board_create_i2c(0);
@ -64,6 +67,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c_0);
//| """
//| ...
//|
//|
#if CIRCUITPY_BOARD_SPI
static mp_obj_t board_spi_0(void) {
return common_hal_board_create_spi(0);
@ -82,6 +86,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi_0);
//| """
//| ...
//|
//|
#if CIRCUITPY_BOARD_UART
static mp_obj_t board_uart_0(void) {
return common_hal_board_create_uart(0);

View file

@ -28,6 +28,7 @@
//| ]
//| """:py:class:`fourwire.FourWire`, :py:class:`paralleldisplaybus.ParallelBus` or :py:class:`i2cdisplaybus.I2CDisplayBus`"""
//|
//|
//| class BusDisplay:
//| """Manage updating a display over a display bus
@ -65,7 +66,7 @@
//| auto_refresh: bool = True,
//| native_frames_per_second: int = 60,
//| backlight_on_high: bool = True,
//| SH1107_addressing: bool = False
//| SH1107_addressing: bool = False,
//| ) -> None:
//| r"""Create a Display object on the given display bus (`FourWire`, `paralleldisplaybus.ParallelBus` or `I2CDisplayBus`).
//|
@ -125,6 +126,7 @@
//| :param int backlight_pwm_frequency: The frequency to use to drive the PWM for backlight brightness control. Default is 50000.
//| """
//| ...
//|
static mp_obj_t busdisplay_busdisplay_make_new(const mp_obj_type_t *type, size_t n_args,
size_t n_kw, const mp_obj_t *all_args) {
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart,
@ -236,7 +238,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(busdisplay_busdisplay_show_obj, busdisplay_busdisplay_
//| self,
//| *,
//| target_frames_per_second: Optional[int] = None,
//| minimum_frames_per_second: int = 0
//| minimum_frames_per_second: int = 0,
//| ) -> bool:
//| """When auto_refresh is off, and :py:attr:`target_frames_per_second` is not `None` this waits
//| for the target frame rate and then refreshes the display,
@ -258,6 +260,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(busdisplay_busdisplay_show_obj, busdisplay_busdisplay_
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second.
//| """
//| ...
//|
static mp_obj_t busdisplay_busdisplay_obj_refresh(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_target_frames_per_second, ARG_minimum_frames_per_second };
static const mp_arg_t allowed_args[] = {
@ -395,6 +398,7 @@ MP_PROPERTY_GETTER(busdisplay_busdisplay_bus_obj,
//| If the root group is set to `displayio.CIRCUITPYTHON_TERMINAL`, the default CircuitPython terminal will be shown.
//| If the root group is set to ``None``, no output will be shown.
//| """
//|
static mp_obj_t busdisplay_busdisplay_obj_get_root_group(mp_obj_t self_in) {
busdisplay_busdisplay_obj_t *self = native_display(self_in);
return common_hal_busdisplay_busdisplay_get_root_group(self);
@ -426,6 +430,7 @@ MP_PROPERTY_GETSET(busdisplay_busdisplay_root_group_obj,
//| """
//| ...
//|
//|
static mp_obj_t busdisplay_busdisplay_obj_fill_row(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_y, ARG_buffer };
static const mp_arg_t allowed_args[] = {

View file

@ -25,7 +25,7 @@
//| sda: microcontroller.Pin,
//| *,
//| frequency: int = 100000,
//| timeout: int = 255
//| timeout: int = 255,
//| ) -> None:
//| """I2C is a two-wire protocol for communicating between devices. At the
//| physical level it consists of 2 wires: SCL and SDA, the clock and data
@ -46,6 +46,7 @@
//| :class:`bitbangio.I2C`; ignored for :class:`busio.I2C`)
//| """
//| ...
//|
static mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if CIRCUITPY_BUSIO_I2C
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
@ -74,6 +75,7 @@ static mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
//| def deinit(self) -> None:
//| """Releases control of the underlying hardware so other classes can use it."""
//| ...
//|
static mp_obj_t busio_i2c_obj_deinit(mp_obj_t self_in) {
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_busio_i2c_deinit(self);
@ -90,12 +92,14 @@ static void check_for_deinit(busio_i2c_obj_t *self) {
//| def __enter__(self) -> I2C:
//| """No-op used in Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware on context exit. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t busio_i2c_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_busio_i2c_deinit(MP_OBJ_TO_PTR(args[0]));
@ -117,6 +121,7 @@ static void check_lock(busio_i2c_obj_t *self) {
//| :return: ``True`` if a device at ``address`` responds; ``False`` otherwise
//| :rtype: bool"""
//| ...
//|
static mp_obj_t busio_i2c_probe(mp_obj_t self_in, mp_obj_t address_obj) {
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -134,6 +139,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(busio_i2c_probe_obj, busio_i2c_probe);
//| :return: List of device ids on the I2C bus
//| :rtype: list"""
//| ...
//|
static mp_obj_t busio_i2c_scan(mp_obj_t self_in) {
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -156,6 +162,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_scan_obj, busio_i2c_scan);
//| :return: True when lock has been grabbed
//| :rtype: bool"""
//| ...
//|
static mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) {
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -166,6 +173,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock);
//| def unlock(self) -> None:
//| """Releases the I2C lock."""
//| ...
//|
static mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) {
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
@ -175,6 +183,7 @@ static mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
//| import sys
//|
//| def readfrom_into(
//| self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: int = sys.maxsize
//| ) -> None:
@ -190,6 +199,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock);
//| :param int start: beginning of buffer slice
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``"""
//| ...
//|
static mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_address, ARG_buffer, ARG_start, ARG_end };
static const mp_arg_t allowed_args[] = {
@ -231,6 +241,7 @@ static mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args,
MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 1, busio_i2c_readfrom_into);
//| import sys
//|
//| def writeto(
//| self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize
//| ) -> None:
@ -250,6 +261,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 1, busio_i2c_readfrom_in
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
//| """
//| ...
//|
static mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_address, ARG_buffer, ARG_start, ARG_end };
static const mp_arg_t allowed_args[] = {
@ -292,6 +304,7 @@ static mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_ma
static MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
//| import sys
//|
//| def writeto_then_readfrom(
//| self,
//| address: int,
@ -301,7 +314,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
//| out_start: int = 0,
//| out_end: int = sys.maxsize,
//| in_start: int = 0,
//| in_end: int = sys.maxsize
//| in_end: int = sys.maxsize,
//| ) -> None:
//| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
@ -325,6 +338,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto);
//| """
//| ...
//|
//|
static mp_obj_t busio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_address, ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
static const mp_arg_t allowed_args[] = {

View file

@ -80,6 +80,7 @@
//| **Limitations:** ``half_duplex`` is available only on STM; other chips do not have the hardware support.
//| """
//| ...
//|
// TODO(tannewt): Support LSB SPI.
@ -115,6 +116,7 @@ static mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
//| def deinit(self) -> None:
//| """Turn off the SPI bus."""
//| ...
//|
static mp_obj_t busio_spi_obj_deinit(mp_obj_t self_in) {
busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_busio_spi_deinit(self);
@ -126,11 +128,13 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_deinit_obj, busio_spi_obj_deinit);
//| """No-op used by Context Managers.
//| Provided by context manager helper."""
//| ...
//|
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t busio_spi_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_busio_spi_deinit(MP_OBJ_TO_PTR(args[0]));
@ -175,6 +179,7 @@ static void check_for_deinit(busio_spi_obj_t *self) {
//| Two SPI objects may be created, except on the Circuit Playground Bluefruit,
//| which allows only one (to allow for an additional I2C object)."""
//| ...
//|
static mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits };
@ -208,6 +213,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_configure_obj, 1, busio_spi_configure);
//| :return: True when lock has been grabbed
//| :rtype: bool"""
//| ...
//|
static mp_obj_t busio_spi_obj_try_lock(mp_obj_t self_in) {
busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -218,6 +224,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_try_lock_obj, busio_spi_obj_try_lock);
//| def unlock(self) -> None:
//| """Releases the SPI lock."""
//| ...
//|
static mp_obj_t busio_spi_obj_unlock(mp_obj_t self_in) {
busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -228,6 +235,7 @@ static mp_obj_t busio_spi_obj_unlock(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_unlock_obj, busio_spi_obj_unlock);
//| import sys
//|
//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
//| """Write the data contained in ``buffer``. The SPI object must be locked.
//| If the buffer is empty, nothing happens.
@ -241,6 +249,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_unlock_obj, busio_spi_obj_unlock);
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
//| """
//| ...
//|
static mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end };
@ -281,13 +290,14 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_obj, 1, busio_spi_write);
//| import sys
//|
//| def readinto(
//| self,
//| buffer: WriteableBuffer,
//| *,
//| start: int = 0,
//| end: int = sys.maxsize,
//| write_value: int = 0
//| write_value: int = 0,
//| ) -> None:
//| """Read into ``buffer`` while writing ``write_value`` for each byte read.
//| The SPI object must be locked.
@ -305,6 +315,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_obj, 1, busio_spi_write);
//| :param int write_value: value to write while reading
//| """
//| ...
//|
static mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_start, ARG_end, ARG_write_value };
@ -345,6 +356,7 @@ static mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 1, busio_spi_readinto);
//| import sys
//|
//| def write_readinto(
//| self,
//| out_buffer: ReadableBuffer,
@ -353,7 +365,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 1, busio_spi_readinto);
//| out_start: int = 0,
//| out_end: int = sys.maxsize,
//| in_start: int = 0,
//| in_end: int = sys.maxsize
//| in_end: int = sys.maxsize,
//| ) -> None:
//| """Write out the data in ``out_buffer`` while simultaneously reading data into ``in_buffer``.
//| The SPI object must be locked.
@ -378,6 +390,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 1, busio_spi_readinto);
//| :param int in_end: end of ``in_buffer slice``; if not specified, use ``len(in_buffer)``
//| """
//| ...
//|
static mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
@ -438,6 +451,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_readinto_obj, 1, busio_spi_write_read
//| """The actual SPI bus frequency. This may not match the frequency requested
//| due to internal limitations."""
//|
//|
static mp_obj_t busio_spi_obj_get_frequency(mp_obj_t self_in) {
busio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);

View file

@ -54,7 +54,7 @@
//| parity: Optional[Parity] = None,
//| stop: int = 1,
//| timeout: float = 1,
//| receiver_buffer_size: int = 64
//| receiver_buffer_size: int = 64,
//| ) -> None:
//| """A common bidirectional serial protocol that uses an an agreed upon speed
//| rather than a shared clock line.
@ -83,6 +83,7 @@
//| RS485 specifications intermittently.
//| """
//| ...
//|
typedef struct {
mp_obj_base_t base;
} busio_uart_parity_obj_t;
@ -178,6 +179,7 @@ static busio_uart_obj_t *native_uart(mp_obj_t uart_obj) {
//| def deinit(self) -> None:
//| """Deinitialises the UART and releases any hardware resources for reuse."""
//| ...
//|
static mp_obj_t busio_uart_obj_deinit(mp_obj_t self_in) {
busio_uart_obj_t *self = native_uart(self_in);
common_hal_busio_uart_deinit(self);
@ -194,12 +196,14 @@ static void check_for_deinit(busio_uart_obj_t *self) {
//| def __enter__(self) -> UART:
//| """No-op used by Context Managers."""
//| ...
//|
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
static mp_obj_t busio_uart_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_busio_uart_deinit(MP_OBJ_TO_PTR(args[0]));
@ -222,6 +226,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
//| :return: Data read
//| :rtype: bytes or None"""
//| ...
//|
//| def readinto(self, buf: WriteableBuffer) -> Optional[int]:
//| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
@ -231,6 +236,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
//|
//| *New in CircuitPython 4.0:* No length parameter is permitted."""
//| ...
//|
//| def readline(self) -> bytes:
//| """Read a line, ending in a newline character, or
@ -241,6 +247,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
//| :return: the line read
//| :rtype: bytes or None"""
//| ...
//|
//| def write(self, buf: ReadableBuffer) -> Optional[int]:
//| """Write the buffer of bytes to the bus.
@ -250,6 +257,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
//| :return: the number of bytes written
//| :rtype: int or None"""
//| ...
//|
// These three methods are used by the shared stream methods.
static mp_uint_t busio_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
@ -330,6 +338,7 @@ MP_PROPERTY_GETTER(busio_uart_in_waiting_obj,
//| timeout: float
//| """The current timeout, in seconds (float)."""
//|
static mp_obj_t busio_uart_obj_get_timeout(mp_obj_t self_in) {
busio_uart_obj_t *self = native_uart(self_in);
check_for_deinit(self);
@ -356,6 +365,7 @@ MP_PROPERTY_GETSET(busio_uart_timeout_obj,
//| """Discard any unread characters in the input buffer."""
//| ...
//|
//|
static mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
busio_uart_obj_t *self = native_uart(self_in);
check_for_deinit(self);
@ -372,6 +382,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_o
//| EVEN: int
//| """Total number of ones should be even."""
//|
//|
const mp_obj_type_t busio_uart_parity_type;
const busio_uart_parity_obj_t busio_uart_parity_odd_obj = {

View file

@ -39,6 +39,7 @@
//| def __init__(self) -> None:
//| """Initialize camera."""
//| ...
//|
static mp_obj_t camera_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
camera_obj_t *self = mp_obj_malloc(camera_obj_t, &camera_type);
// No arguments
@ -51,6 +52,7 @@ static mp_obj_t camera_make_new(const mp_obj_type_t *type, size_t n_args, size_t
//| def deinit(self) -> None:
//| """De-initialize camera."""
//| ...
//|
static mp_obj_t camera_obj_deinit(mp_obj_t self_in) {
camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_camera_deinit(self);
@ -72,6 +74,7 @@ static void check_for_deinit(camera_obj_t *self) {
//| :rtype: int"""
//| ...
//|
//|
static mp_obj_t camera_obj_take_picture(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_buffer, ARG_width, ARG_height, ARG_format };
static const mp_arg_t allowed_args[] = {

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