commit
0d8bca92e2
|
@ -34,7 +34,7 @@ jobs:
|
|||
run: |
|
||||
sudo apt-get install -y eatmydata
|
||||
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64
|
||||
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinxcontrib-svg2pdfconverter polib pyyaml
|
||||
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid
|
||||
- name: Versions
|
||||
run: |
|
||||
gcc --version
|
||||
|
@ -64,6 +64,8 @@ jobs:
|
|||
- name: mpy Tests
|
||||
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 --via-mpy -d basics float
|
||||
working-directory: tests
|
||||
- name: Stubs
|
||||
run: make stubs -j2
|
||||
- name: Docs
|
||||
run: sphinx-build -E -W -b html . _build/html
|
||||
- name: Translations
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
############
|
||||
dist/
|
||||
*.egg-info
|
||||
.eggs
|
||||
|
||||
# Logs and Databases
|
||||
######################
|
||||
|
@ -51,6 +52,7 @@ _build
|
|||
# Generated rst files
|
||||
######################
|
||||
genrst/
|
||||
/autoapi/
|
||||
|
||||
# ctags and similar
|
||||
###################
|
||||
|
|
9
Makefile
9
Makefile
|
@ -67,9 +67,10 @@ help:
|
|||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/*
|
||||
rm -rf autoapi
|
||||
rm -rf $(STUBDIR) $(DISTDIR) *.egg-info
|
||||
|
||||
html:
|
||||
html: stubs
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
@ -213,8 +214,10 @@ check-translate: locale/circuitpython.pot $(wildcard locale/*.po)
|
|||
$(PYTHON) tools/check_translations.py $^
|
||||
|
||||
stubs:
|
||||
rst2pyi $(VALIDATE) shared-bindings/ $(STUBDIR)
|
||||
python setup.py sdist
|
||||
@mkdir -p circuitpython-stubs
|
||||
@$(PYTHON) tools/extract_pyi.py shared-bindings/ $(STUBDIR)
|
||||
@$(PYTHON) tools/extract_pyi.py ports/atmel-samd/bindings $(STUBDIR)
|
||||
@$(PYTHON) setup.py -q sdist
|
||||
|
||||
update-frozen-libraries:
|
||||
@echo "Updating all frozen libraries to latest tagged version."
|
||||
|
|
15
conf.py
15
conf.py
|
@ -55,7 +55,6 @@ extensions = [
|
|||
'sphinx.ext.todo',
|
||||
'sphinx.ext.coverage',
|
||||
'rstjinja',
|
||||
'c2rst',
|
||||
'recommonmark',
|
||||
]
|
||||
|
||||
|
@ -66,9 +65,18 @@ templates_path = ['templates']
|
|||
source_suffix = {
|
||||
'.rst': 'restructuredtext',
|
||||
'.md': 'markdown',
|
||||
'.c': ''
|
||||
}
|
||||
|
||||
extensions.append('autoapi.extension')
|
||||
|
||||
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')]
|
||||
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_python_use_implicit_namespaces = True
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
@ -78,7 +86,7 @@ source_suffix = {
|
|||
|
||||
# General information about the project.
|
||||
project = 'Adafruit CircuitPython'
|
||||
copyright = '2014-2018, MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)'
|
||||
copyright = '2014-2020, 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
|
||||
|
@ -105,6 +113,7 @@ exclude_patterns = ["**/build*",
|
|||
".git",
|
||||
".venv",
|
||||
".direnv",
|
||||
"docs/autoapi",
|
||||
"docs/README.md",
|
||||
"drivers",
|
||||
"examples",
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
{% if not obj.display %}
|
||||
:orphan:
|
||||
|
||||
{% endif %}
|
||||
:mod:`{{ obj.name }}`
|
||||
======={{ "=" * obj.name|length }}
|
||||
|
||||
.. py:module:: {{ obj.name }}
|
||||
|
||||
{% if obj.docstring %}
|
||||
.. autoapi-nested-parse::
|
||||
|
||||
{{ obj.docstring|prepare_docstring|indent(3) }}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% block subpackages %}
|
||||
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
|
||||
{% if visible_subpackages %}
|
||||
.. toctree::
|
||||
:titlesonly:
|
||||
:maxdepth: 3
|
||||
|
||||
{% for subpackage in visible_subpackages %}
|
||||
{{ subpackage.short_name }}/index.rst
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block submodules %}
|
||||
{% set visible_submodules = obj.submodules|selectattr("display")|list %}
|
||||
{% if visible_submodules %}
|
||||
|
||||
.. toctree::
|
||||
:titlesonly:
|
||||
:maxdepth: 1
|
||||
|
||||
{% for submodule in visible_submodules %}
|
||||
{{ submodule.short_name }}/index.rst
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
{% if obj.all is not none %}
|
||||
{% set visible_children = obj.children|selectattr("short_name", "in", obj.all)|list %}
|
||||
{% elif obj.type is equalto("package") %}
|
||||
{% set visible_children = obj.children|selectattr("display")|list %}
|
||||
{% else %}
|
||||
{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %}
|
||||
{% endif %}
|
||||
{% if visible_children %}
|
||||
|
||||
{% set visible_classes = visible_children|selectattr("type", "equalto", "class")|list %}
|
||||
{% set visible_functions = visible_children|selectattr("type", "equalto", "function")|list %}
|
||||
{% if "show-module-summary" in autoapi_options and (visible_classes or visible_functions) %}
|
||||
{% block classes %}
|
||||
{% if visible_classes %}
|
||||
Classes
|
||||
~~~~~~~
|
||||
|
||||
.. autoapisummary::
|
||||
|
||||
{% for klass in visible_classes %}
|
||||
{{ klass.id }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block functions %}
|
||||
{% if visible_functions %}
|
||||
Functions
|
||||
~~~~~~~~~
|
||||
|
||||
.. autoapisummary::
|
||||
|
||||
{% for function in visible_functions %}
|
||||
{{ function.id }}
|
||||
{% endfor %}
|
||||
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% endif %}
|
||||
{% for obj_item in visible_children %}
|
||||
{{ obj_item.rendered|indent(0) }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
|
@ -1,31 +0,0 @@
|
|||
def c2rst(app, docname, source):
|
||||
""" Pre-parse '.c' & '.h' files that contain rST source.
|
||||
"""
|
||||
# Make sure we're outputting HTML
|
||||
if app.builder.format != 'html':
|
||||
return
|
||||
|
||||
fname = app.env.doc2path(docname)
|
||||
if (not fname.endswith(".c") and
|
||||
not fname.endswith(".h")):
|
||||
#print("skipping:", fname)
|
||||
return
|
||||
|
||||
src = source[0]
|
||||
|
||||
stripped = []
|
||||
for line in src.split("\n"):
|
||||
line = line.strip()
|
||||
if line == "//|":
|
||||
stripped.append("")
|
||||
elif line.startswith("//| "):
|
||||
stripped.append(line[len("//| "):])
|
||||
stripped = "\r\n".join(stripped)
|
||||
|
||||
rendered = app.builder.templates.render_string(
|
||||
stripped, app.config.html_context
|
||||
)
|
||||
source[0] = rendered
|
||||
|
||||
def setup(app):
|
||||
app.connect("source-read", c2rst)
|
|
@ -21,4 +21,4 @@ Port Specific modules
|
|||
---------------------
|
||||
|
||||
.. toctree::
|
||||
bindings/samd/__init__
|
||||
../../autoapi/samd/index
|
||||
|
|
|
@ -30,18 +30,12 @@
|
|||
#include "py/objproperty.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
//| .. currentmodule:: samd
|
||||
//| import typing
|
||||
//| class Clock:
|
||||
//| """Identifies a clock on the microcontroller.
|
||||
//|
|
||||
//| :class:`Clock` --- Clock reference
|
||||
//| ------------------------------------------
|
||||
//|
|
||||
//| Identifies a clock on the microcontroller.
|
||||
//|
|
||||
//| .. class:: Clock
|
||||
//|
|
||||
//| Identifies a clock on the microcontroller. They are fixed by the
|
||||
//| hardware so they cannot be constructed on demand. Instead, use
|
||||
//| `samd.clock` to reference the desired clock.
|
||||
//| They are fixed by the hardware so they cannot be constructed on demand. Instead, use
|
||||
//| ``samd.clock`` to reference the desired clock."""
|
||||
//|
|
||||
|
||||
STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
|
||||
|
@ -50,9 +44,8 @@ STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print
|
|||
mp_printf(print, "%q.%q.%q", MP_QSTR_samd, MP_QSTR_clock, self->name);
|
||||
}
|
||||
|
||||
//| .. attribute:: enabled
|
||||
//|
|
||||
//| Is the clock enabled? (read-only)
|
||||
//| enabled: bool = ...
|
||||
//| """Is the clock enabled? (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t samd_clock_get_enabled(mp_obj_t self_in) {
|
||||
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -69,9 +62,8 @@ const mp_obj_property_t samd_clock_enabled_obj = {
|
|||
},
|
||||
};
|
||||
|
||||
//| .. attribute:: parent
|
||||
//|
|
||||
//| Clock parent. (read-only)
|
||||
//| parent: typing.Union(Clock | None) = ...
|
||||
//| """Clock parent. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t samd_clock_get_parent(mp_obj_t self_in) {
|
||||
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -98,9 +90,8 @@ const mp_obj_property_t samd_clock_parent_obj = {
|
|||
},
|
||||
};
|
||||
|
||||
//| .. attribute:: frequency
|
||||
//|
|
||||
//| Clock frequency. (read-only)
|
||||
//| frequency: int = ...
|
||||
//| """Clock frequency in Herz. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t samd_clock_get_frequency(mp_obj_t self_in) {
|
||||
samd_clock_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -117,9 +108,8 @@ const mp_obj_property_t samd_clock_frequency_obj = {
|
|||
},
|
||||
};
|
||||
|
||||
//| .. attribute:: calibration
|
||||
//|
|
||||
//| Clock calibration. Not all clocks can be calibrated.
|
||||
//| 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);
|
||||
|
|
|
@ -30,29 +30,16 @@
|
|||
|
||||
#include "bindings/samd/Clock.h"
|
||||
|
||||
//| :mod:`samd` --- SAMD implementation settings
|
||||
//| =================================================
|
||||
//|
|
||||
//| .. module:: samd
|
||||
//| :synopsis: SAMD implementation settings
|
||||
//| :platform: SAMD21
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Clock
|
||||
//|
|
||||
//| """SAMD implementation settings"""
|
||||
|
||||
//| :mod:`samd.clock` --- samd clock names
|
||||
//| """:mod:`samd.clock` --- samd clock names
|
||||
//| --------------------------------------------------------
|
||||
//|
|
||||
//| .. module:: samd.clock
|
||||
//| :synopsis: samd clock names
|
||||
//| :platform: SAMD21
|
||||
//|
|
||||
//| References to clocks as named by the microcontroller
|
||||
//| References to clocks as named by the microcontroller"""
|
||||
//|
|
||||
const mp_obj_module_t samd_clock_module = {
|
||||
.base = { &mp_type_module },
|
||||
|
|
|
@ -323,7 +323,6 @@ $(filter $(SRC_PATTERNS), \
|
|||
)
|
||||
|
||||
SRC_BINDINGS_ENUMS += \
|
||||
help.c \
|
||||
util.c
|
||||
|
||||
SRC_SHARED_MODULE_ALL = \
|
||||
|
|
18
setup.py
18
setup.py
|
@ -1,18 +1,32 @@
|
|||
from datetime import datetime
|
||||
from setuptools import setup
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
stub_root = Path("circuitpython-stubs")
|
||||
stubs = [p.relative_to(stub_root).as_posix() for p in stub_root.glob("*.pyi")]
|
||||
|
||||
now = datetime.utcnow()
|
||||
version = now.strftime("%Y.%m.%d")
|
||||
git_out = subprocess.check_output(["git", "describe", "--tags"])
|
||||
version = git_out.strip().decode("utf-8")
|
||||
|
||||
# Detect a development build and mutate it to be valid semver and valid python version.
|
||||
pieces = version.split("-")
|
||||
if len(pieces) > 2:
|
||||
# Merge the commit portion onto the commit count since the tag.
|
||||
pieces[-2] += "+" + pieces[-1]
|
||||
pieces.pop()
|
||||
# Merge the commit count and build to the pre-release identifier.
|
||||
pieces[-2] += ".dev." + pieces[-1]
|
||||
pieces.pop()
|
||||
version = "-".join(pieces)
|
||||
|
||||
setup(
|
||||
name="circuitpython-stubs",
|
||||
description="PEP 561 type stubs for CircuitPython",
|
||||
url="https://github.com/adafruit/circuitpython",
|
||||
maintainer="CircuitPythonistas",
|
||||
maintainer_email="circuitpython@adafruit.com",
|
||||
author_email="circuitpython@adafruit.com",
|
||||
version=version,
|
||||
license="MIT",
|
||||
|
|
|
@ -47,35 +47,32 @@
|
|||
#define INTERVAL_MAX_STRING "40.959375"
|
||||
#define WINDOW_DEFAULT (0.1f)
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class Adapter:
|
||||
//| """BLE adapter
|
||||
//|
|
||||
//| :class:`Adapter` --- BLE adapter
|
||||
//| ----------------------------------------------------
|
||||
//| The Adapter manages the discovery and connection to other nearby Bluetooth Low Energy devices.
|
||||
//| This part of the Bluetooth Low Energy Specification is known as Generic Access Profile (GAP).
|
||||
//|
|
||||
//| The Adapter manages the discovery and connection to other nearby Bluetooth Low Energy devices.
|
||||
//| This part of the Bluetooth Low Energy Specification is known as Generic Access Profile (GAP).
|
||||
//| Discovery of other devices happens during a scanning process that listens for small packets of
|
||||
//| information, known as advertisements, that are broadcast unencrypted. The advertising packets
|
||||
//| have two different uses. The first is to broadcast a small piece of data to anyone who cares and
|
||||
//| and nothing more. These are known as Beacons. The second class of advertisement is to promote
|
||||
//| additional functionality available after the devices establish a connection. For example, a
|
||||
//| BLE keyboard may advertise that it can provide key information, but not what the key info is.
|
||||
//|
|
||||
//| Discovery of other devices happens during a scanning process that listens for small packets of
|
||||
//| information, known as advertisements, that are broadcast unencrypted. The advertising packets
|
||||
//| have two different uses. The first is to broadcast a small piece of data to anyone who cares and
|
||||
//| and nothing more. These are known as Beacons. The second class of advertisement is to promote
|
||||
//| additional functionality available after the devices establish a connection. For example, a
|
||||
//| BLE keyboard may advertise that it can provide key information, but not what the key info is.
|
||||
//|
|
||||
//| The built-in BLE adapter can do both parts of this process: it can scan for other device
|
||||
//| advertisements and it can advertise its own data. Furthermore, Adapters can accept incoming
|
||||
//| connections and also initiate connections.
|
||||
//| The built-in BLE adapter can do both parts of this process: it can scan for other device
|
||||
//| advertisements and it can advertise its own data. Furthermore, Adapters can accept incoming
|
||||
//| connections and also initiate connections."""
|
||||
//|
|
||||
|
||||
//| .. class:: Adapter()
|
||||
//|
|
||||
//| You cannot create an instance of `_bleio.Adapter`.
|
||||
//| Use `_bleio.adapter` to access the sole instance available.
|
||||
//| def __init__(self, ):
|
||||
//| """You cannot create an instance of `_bleio.Adapter`.
|
||||
//| Use `_bleio.adapter` to access the sole instance available."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
//| .. attribute:: enabled
|
||||
//|
|
||||
//| State of the BLE adapter.
|
||||
//| enabled: Any = ...
|
||||
//| """State of the BLE adapter."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_adapter_get_enabled(mp_obj_t self) {
|
||||
return mp_obj_new_bool(common_hal_bleio_adapter_get_enabled(self));
|
||||
|
@ -98,9 +95,8 @@ const mp_obj_property_t bleio_adapter_enabled_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: address
|
||||
//|
|
||||
//| MAC address of the BLE adapter. (read-only)
|
||||
//| address: Any = ...
|
||||
//| """MAC address of the BLE adapter. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_adapter_get_address(mp_obj_t self) {
|
||||
return MP_OBJ_FROM_PTR(common_hal_bleio_adapter_get_address(self));
|
||||
|
@ -115,11 +111,10 @@ const mp_obj_property_t bleio_adapter_address_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: name
|
||||
//|
|
||||
//| 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.
|
||||
//| name: Any = ...
|
||||
//| """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));
|
||||
|
@ -140,18 +135,18 @@ const mp_obj_property_t bleio_adapter_name_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. method:: start_advertising(data, *, scan_response=None, connectable=True, interval=0.1)
|
||||
//| def start_advertising(self, data: buf, *, scan_response: buf = None, connectable: bool = True, interval: float = 0.1) -> Any:
|
||||
//| """Starts advertising until `stop_advertising` is called or if connectable, another device
|
||||
//| connects to us.
|
||||
//|
|
||||
//| Starts advertising until `stop_advertising` is called or if connectable, another device
|
||||
//| connects to us.
|
||||
//| .. warning: If data is longer than 31 bytes, then this will automatically advertise as an
|
||||
//| extended advertisement that older BLE 4.x clients won't be able to scan for.
|
||||
//|
|
||||
//| .. warning: If data is longer than 31 bytes, then this will automatically advertise as an
|
||||
//| extended advertisement that older BLE 4.x clients won't be able to scan for.
|
||||
//|
|
||||
//| :param buf data: advertising data packet bytes
|
||||
//| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed.
|
||||
//| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral.
|
||||
//| :param float interval: advertising interval, in seconds
|
||||
//| :param buf data: advertising data packet bytes
|
||||
//| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed.
|
||||
//| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral.
|
||||
//| :param float interval: advertising interval, in seconds"""
|
||||
//| ...
|
||||
//|
|
||||
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]);
|
||||
|
@ -198,9 +193,10 @@ STATIC mp_obj_t bleio_adapter_start_advertising(mp_uint_t n_args, const mp_obj_t
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_start_advertising_obj, 2, bleio_adapter_start_advertising);
|
||||
|
||||
//| .. method:: stop_advertising()
|
||||
//| def stop_advertising(self, ) -> Any:
|
||||
//| """Stop sending advertising packets."""
|
||||
//| ...
|
||||
//|
|
||||
//| 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);
|
||||
|
||||
|
@ -210,25 +206,25 @@ STATIC mp_obj_t bleio_adapter_stop_advertising(mp_obj_t self_in) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_stop_advertising_obj, bleio_adapter_stop_advertising);
|
||||
|
||||
//| .. method:: start_scan(prefixes=b"", \*, buffer_size=512, extended=False, timeout=None, interval=0.1, window=0.1, minimum_rssi=-80, active=True)
|
||||
//| def start_scan(self, prefixes: sequence = b"", *, buffer_size: int = 512, extended: bool = False, timeout: float = None, interval: float = 0.1, window: float = 0.1, minimum_rssi: int = -80, active: bool = True) -> Any:
|
||||
//| """Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are
|
||||
//| filtered and returned separately.
|
||||
//|
|
||||
//| Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are
|
||||
//| filtered and returned separately.
|
||||
//|
|
||||
//| :param sequence prefixes: Sequence of byte string prefixes to filter advertising packets
|
||||
//| with. A packet without an advertising structure that matches one of the prefixes is
|
||||
//| ignored. Format is one byte for length (n) and n bytes of prefix and can be repeated.
|
||||
//| :param int buffer_size: the maximum number of advertising bytes to buffer.
|
||||
//| :param bool extended: When True, support extended advertising packets. Increasing buffer_size is recommended when this is set.
|
||||
//| :param float timeout: the scan timeout in seconds. If None, will scan until `stop_scan` is called.
|
||||
//| :param float interval: the interval (in seconds) between the start of two consecutive scan windows
|
||||
//| Must be in the range 0.0025 - 40.959375 seconds.
|
||||
//| :param float window: the duration (in seconds) to scan a single BLE channel.
|
||||
//| window must be <= interval.
|
||||
//| :param int minimum_rssi: the minimum rssi of entries to return.
|
||||
//| :param bool active: retrieve scan responses for scannable advertisements.
|
||||
//| :returns: an iterable of `_bleio.ScanEntry` objects
|
||||
//| :rtype: iterable
|
||||
//| :param sequence prefixes: Sequence of byte string prefixes to filter advertising packets
|
||||
//| with. A packet without an advertising structure that matches one of the prefixes is
|
||||
//| ignored. Format is one byte for length (n) and n bytes of prefix and can be repeated.
|
||||
//| :param int buffer_size: the maximum number of advertising bytes to buffer.
|
||||
//| :param bool extended: When True, support extended advertising packets. Increasing buffer_size is recommended when this is set.
|
||||
//| :param float timeout: the scan timeout in seconds. If None, will scan until `stop_scan` is called.
|
||||
//| :param float interval: the interval (in seconds) between the start of two consecutive scan windows
|
||||
//| Must be in the range 0.0025 - 40.959375 seconds.
|
||||
//| :param float window: the duration (in seconds) to scan a single BLE channel.
|
||||
//| window must be <= interval.
|
||||
//| :param int minimum_rssi: the minimum rssi of entries to return.
|
||||
//| :param bool active: retrieve scan responses for scannable advertisements.
|
||||
//| :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 };
|
||||
|
@ -283,9 +279,10 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_start_scan_obj, 1, bleio_adapter_start_scan);
|
||||
|
||||
//| .. method:: stop_scan()
|
||||
//| def stop_scan(self, ) -> Any:
|
||||
//| """Stop the current scan."""
|
||||
//| ...
|
||||
//|
|
||||
//| 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);
|
||||
|
||||
|
@ -295,10 +292,9 @@ STATIC mp_obj_t bleio_adapter_stop_scan(mp_obj_t self_in) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_stop_scan_obj, bleio_adapter_stop_scan);
|
||||
|
||||
//| .. attribute:: connected
|
||||
//|
|
||||
//| True when the adapter is connected to another device regardless of who initiated the
|
||||
//| connection. (read-only)
|
||||
//| connected: Any = ...
|
||||
//| """True when the adapter is connected to another device regardless of who initiated the
|
||||
//| connection. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_adapter_get_connected(mp_obj_t self) {
|
||||
return mp_obj_new_bool(common_hal_bleio_adapter_get_connected(self));
|
||||
|
@ -313,10 +309,9 @@ const mp_obj_property_t bleio_adapter_connected_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: connections
|
||||
//|
|
||||
//| Tuple of active connections including those initiated through
|
||||
//| :py:meth:`_bleio.Adapter.connect`. (read-only)
|
||||
//| connections: Any = ...
|
||||
//| """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);
|
||||
|
@ -330,12 +325,12 @@ const mp_obj_property_t bleio_adapter_connections_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. method:: connect(address, *, timeout)
|
||||
//| def connect(self, address: Address, *, timeout: float/int) -> Any:
|
||||
//| """Attempts a connection to the device with the given address.
|
||||
//|
|
||||
//| Attempts a connection to the device with the given address.
|
||||
//|
|
||||
//| :param Address address: The address of the peripheral to connect to
|
||||
//| :param float/int timeout: Try to connect for timeout seconds.
|
||||
//| :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]);
|
||||
|
@ -360,9 +355,10 @@ STATIC mp_obj_t bleio_adapter_connect(mp_uint_t n_args, const mp_obj_t *pos_args
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_connect_obj, 2, bleio_adapter_connect);
|
||||
|
||||
//| .. method:: erase_bonding()
|
||||
//| def erase_bonding(self, ) -> Any:
|
||||
//| """Erase all bonding information stored in flash memory."""
|
||||
//| ...
|
||||
//|
|
||||
//| 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);
|
||||
|
||||
|
|
|
@ -34,22 +34,18 @@
|
|||
#include "shared-bindings/_bleio/Address.h"
|
||||
#include "shared-module/_bleio/Address.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//|
|
||||
//| :class:`Address` -- BLE address
|
||||
//| =========================================================
|
||||
//|
|
||||
//| Encapsulates the address of a BLE device.
|
||||
//| class Address:
|
||||
//| """Encapsulates the address of a BLE device."""
|
||||
//|
|
||||
|
||||
//| .. class:: Address(address, address_type)
|
||||
//| def __init__(self, address: buf, address_type: Any):
|
||||
//| """Create a new Address object encapsulating the address value.
|
||||
//| The value itself can be one of:
|
||||
//|
|
||||
//| Create a new Address object encapsulating the address value.
|
||||
//| The value itself can be one of:
|
||||
//|
|
||||
//| :param buf address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes.
|
||||
//| :param int address_type: one of the integer values: `PUBLIC`, `RANDOM_STATIC`,
|
||||
//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`.
|
||||
//| :param buf address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes.
|
||||
//| :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, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_address, ARG_address_type };
|
||||
|
@ -81,9 +77,8 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. attribute:: address_bytes
|
||||
//|
|
||||
//| The bytes that make up the device address (read-only).
|
||||
//| address_bytes: Any = ...
|
||||
//| """The bytes that make up the device address (read-only).
|
||||
//|
|
||||
//| Note that the ``bytes`` object returned is in little-endian order:
|
||||
//| The least significant byte is ``address_bytes[0]``. So the address will
|
||||
|
@ -97,7 +92,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
//| >>> _bleio.adapter.address
|
||||
//| <Address c8:1d:f5:ed:a8:35>
|
||||
//| >>> _bleio.adapter.address.address_bytes
|
||||
//| b'5\xa8\xed\xf5\x1d\xc8'
|
||||
//| b'5\\xa8\\xed\\xf5\\x1d\\xc8'"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) {
|
||||
bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -113,12 +108,11 @@ const mp_obj_property_t bleio_address_address_bytes_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: type
|
||||
//|
|
||||
//| The address type (read-only).
|
||||
//| type: Any = ...
|
||||
//| """The address type (read-only).
|
||||
//|
|
||||
//| One of the integer values: `PUBLIC`, `RANDOM_STATIC`, `RANDOM_PRIVATE_RESOLVABLE`,
|
||||
//| or `RANDOM_PRIVATE_NON_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);
|
||||
|
@ -134,9 +128,9 @@ const mp_obj_property_t bleio_address_type_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: __eq__(other)
|
||||
//|
|
||||
//| Two Address objects are equal if their addresses and address types are equal.
|
||||
//| def __eq__(self, other: Any) -> Any:
|
||||
//| """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) {
|
||||
|
@ -160,9 +154,9 @@ STATIC mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_o
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __hash__()
|
||||
//|
|
||||
//| Returns a hash for the Address data.
|
||||
//| def __hash__(self, ) -> Any:
|
||||
//| """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) {
|
||||
|
@ -193,22 +187,18 @@ STATIC void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_pr
|
|||
buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]);
|
||||
}
|
||||
|
||||
//| .. data:: PUBLIC
|
||||
//| PUBLIC: Any = ...
|
||||
//| """A publicly known address, with a company ID (high 24 bits)and company-assigned part (low 24 bits)."""
|
||||
//|
|
||||
//| A publicly known address, with a company ID (high 24 bits)and company-assigned part (low 24 bits).
|
||||
//| RANDOM_STATIC: Any = ...
|
||||
//| """A randomly generated address that does not change often. It may never change or may change after
|
||||
//| a power cycle."""
|
||||
//|
|
||||
//| .. data:: RANDOM_STATIC
|
||||
//| RANDOM_PRIVATE_RESOLVABLE: Any = ...
|
||||
//| """An address that is usable when the peer knows the other device's secret Identity Resolving Key (IRK)."""
|
||||
//|
|
||||
//| A randomly generated address that does not change often. It may never change or may change after
|
||||
//| a power cycle.
|
||||
//|
|
||||
//| .. data:: RANDOM_PRIVATE_RESOLVABLE
|
||||
//|
|
||||
//| An address that is usable when the peer knows the other device's secret Identity Resolving Key (IRK).
|
||||
//|
|
||||
//| .. data:: RANDOM_PRIVATE_NON_RESOLVABLE
|
||||
//|
|
||||
//| A randomly generated address that changes on every connection.
|
||||
//| RANDOM_PRIVATE_NON_RESOLVABLE: Any = ...
|
||||
//| """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) },
|
||||
|
|
|
@ -29,52 +29,40 @@
|
|||
#include "shared-bindings/_bleio/Characteristic.h"
|
||||
#include "shared-bindings/_bleio/UUID.h"
|
||||
|
||||
//
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class Attribute:
|
||||
//| """Definitions associated with all BLE attributes: characteristics, descriptors, etc.
|
||||
//|
|
||||
//| :class:`Attribute` -- BLE Attribute
|
||||
//| =========================================================
|
||||
//| :py:class:`~_bleio.Attribute` is, notionally, a superclass of
|
||||
//| :py:class:`~Characteristic` and :py:class:`~Descriptor`,
|
||||
//| but is not defined as a Python superclass of those classes."""
|
||||
//|
|
||||
//| Definitions associated with all BLE attributes: characteristics, descriptors, etc.
|
||||
//| :py:class:`~_bleio.Attribute` is, notionally, a superclass of
|
||||
//| :py:class:`~Characteristic` and :py:class:`~Descriptor`,
|
||||
//| but is not defined as a Python superclass of those classes.
|
||||
//|
|
||||
//| .. class:: Attribute()
|
||||
//|
|
||||
//| You cannot create an instance of :py:class:`~_bleio.Attribute`.
|
||||
//| def __init__(self, ):
|
||||
//| """You cannot create an instance of :py:class:`~_bleio.Attribute`."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t bleio_attribute_locals_dict_table[] = {
|
||||
|
||||
//| .. data:: NO_ACCESS
|
||||
//| NO_ACCESS: Any = ...
|
||||
//| """security mode: access not allowed"""
|
||||
//|
|
||||
//| security mode: access not allowed
|
||||
//| OPEN: Any = ...
|
||||
//| """security_mode: no security (link is not encrypted)"""
|
||||
//|
|
||||
//| .. data:: OPEN
|
||||
//| ENCRYPT_NO_MITM: Any = ...
|
||||
//| """security_mode: unauthenticated encryption, without man-in-the-middle protection"""
|
||||
//|
|
||||
//| security_mode: no security (link is not encrypted)
|
||||
//| ENCRYPT_WITH_MITM: Any = ...
|
||||
//| """security_mode: authenticated encryption, with man-in-the-middle protection"""
|
||||
//|
|
||||
//| .. data:: ENCRYPT_NO_MITM
|
||||
//| LESC_ENCRYPT_WITH_MITM: Any = ...
|
||||
//| """security_mode: LESC encryption, with man-in-the-middle protection"""
|
||||
//|
|
||||
//| security_mode: unauthenticated encryption, without man-in-the-middle protection
|
||||
//| SIGNED_NO_MITM: Any = ...
|
||||
//| """security_mode: unauthenticated data signing, without man-in-the-middle protection"""
|
||||
//|
|
||||
//| .. data:: ENCRYPT_WITH_MITM
|
||||
//|
|
||||
//| security_mode: authenticated encryption, with man-in-the-middle protection
|
||||
//|
|
||||
//| .. data:: LESC_ENCRYPT_WITH_MITM
|
||||
//|
|
||||
//| security_mode: LESC encryption, with man-in-the-middle protection
|
||||
//|
|
||||
//| .. data:: SIGNED_NO_MITM
|
||||
//|
|
||||
//| security_mode: unauthenticated data signing, without man-in-the-middle protection
|
||||
//|
|
||||
//| .. data:: SIGNED_WITH_MITM
|
||||
//|
|
||||
//| security_mode: authenticated data signing, without man-in-the-middle protection
|
||||
//| SIGNED_WITH_MITM: Any = ...
|
||||
//| """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) },
|
||||
|
|
|
@ -33,45 +33,41 @@
|
|||
#include "shared-bindings/_bleio/Service.h"
|
||||
#include "shared-bindings/_bleio/UUID.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class Characteristic:
|
||||
//| """Stores information about a BLE service characteristic and allows reading
|
||||
//| and writing of the characteristic's value."""
|
||||
//|
|
||||
//| :class:`Characteristic` -- BLE service characteristic
|
||||
//| =========================================================
|
||||
//|
|
||||
//| Stores information about a BLE service characteristic and allows reading
|
||||
//| and writing of the characteristic's value.
|
||||
//|
|
||||
//| .. class:: Characteristic
|
||||
//|
|
||||
//| There is no regular constructor for a Characteristic. A new local Characteristic can be created
|
||||
//| and attached to a Service by calling `add_to_service()`.
|
||||
//| Remote Characteristic objects are created by `Connection.discover_remote_services()`
|
||||
//| as part of remote Services.
|
||||
//| def __init__(self, ):
|
||||
//| """There is no regular constructor for a Characteristic. A new local Characteristic can be created
|
||||
//| and attached to a Service by calling `add_to_service()`.
|
||||
//| Remote Characteristic objects are created by `Connection.discover_remote_services()`
|
||||
//| as part of remote Services."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
//| .. method:: add_to_service(service, uuid, *, properties=0, read_perm=Attribute.OPEN, write_perm=Attribute.OPEN, max_length=20, fixed_length=False, initial_value=None)
|
||||
//| def add_to_service(self, service: Service, uuid: UUID, *, properties: int = 0, read_perm: int = Attribute.OPEN, write_perm: int = Attribute.OPEN, max_length: int = 20, fixed_length: bool = False, initial_value: buf = None) -> Any:
|
||||
//| """Create a new Characteristic object, and add it to this Service.
|
||||
//|
|
||||
//| Create a new Characteristic object, and add it to this Service.
|
||||
//| :param Service service: The service that will provide this characteristic
|
||||
//| :param UUID uuid: The uuid of the characteristic
|
||||
//| :param int properties: The properties of the characteristic,
|
||||
//| specified as a bitmask of these values bitwise-or'd together:
|
||||
//| `BROADCAST`, `INDICATE`, `NOTIFY`, `READ`, `WRITE`, `WRITE_NO_RESPONSE`.
|
||||
//| :param int read_perm: Specifies whether the characteristic can be read by a client, and if so, which
|
||||
//| security mode is required. Must be one of the integer values `Attribute.NO_ACCESS`, `Attribute.OPEN`,
|
||||
//| `Attribute.ENCRYPT_NO_MITM`, `Attribute.ENCRYPT_WITH_MITM`, `Attribute.LESC_ENCRYPT_WITH_MITM`,
|
||||
//| `Attribute.SIGNED_NO_MITM`, or `Attribute.SIGNED_WITH_MITM`.
|
||||
//| :param int write_perm: Specifies whether the characteristic can be written by a client, and if so, which
|
||||
//| security mode is required. Values allowed are the same as ``read_perm``.
|
||||
//| :param int max_length: Maximum length in bytes of the characteristic value. The maximum allowed is
|
||||
//| is 512, or possibly 510 if ``fixed_length`` is False. The default, 20, is the maximum
|
||||
//| number of data bytes that fit in a single BLE 4.x ATT packet.
|
||||
//| :param bool fixed_length: True if the characteristic value is of fixed length.
|
||||
//| :param buf initial_value: The initial value for this characteristic. If not given, will be
|
||||
//| filled with zeros.
|
||||
//|
|
||||
//| :param Service service: The service that will provide this characteristic
|
||||
//| :param UUID uuid: The uuid of the characteristic
|
||||
//| :param int properties: The properties of the characteristic,
|
||||
//| specified as a bitmask of these values bitwise-or'd together:
|
||||
//| `BROADCAST`, `INDICATE`, `NOTIFY`, `READ`, `WRITE`, `WRITE_NO_RESPONSE`.
|
||||
//| :param int read_perm: Specifies whether the characteristic can be read by a client, and if so, which
|
||||
//| security mode is required. Must be one of the integer values `Attribute.NO_ACCESS`, `Attribute.OPEN`,
|
||||
//| `Attribute.ENCRYPT_NO_MITM`, `Attribute.ENCRYPT_WITH_MITM`, `Attribute.LESC_ENCRYPT_WITH_MITM`,
|
||||
//| `Attribute.SIGNED_NO_MITM`, or `Attribute.SIGNED_WITH_MITM`.
|
||||
//| :param int write_perm: Specifies whether the characteristic can be written by a client, and if so, which
|
||||
//| security mode is required. Values allowed are the same as ``read_perm``.
|
||||
//| :param int max_length: Maximum length in bytes of the characteristic value. The maximum allowed is
|
||||
//| is 512, or possibly 510 if ``fixed_length`` is False. The default, 20, is the maximum
|
||||
//| number of data bytes that fit in a single BLE 4.x ATT packet.
|
||||
//| :param bool fixed_length: True if the characteristic value is of fixed length.
|
||||
//| :param buf initial_value: The initial value for this characteristic. If not given, will be
|
||||
//| filled with zeros.
|
||||
//|
|
||||
//| :return: the new Characteristic.
|
||||
//| :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.
|
||||
|
@ -145,11 +141,10 @@ STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bleio_characteristic_add_to_service_obj,
|
|||
|
||||
|
||||
|
||||
//| .. attribute:: properties
|
||||
//|
|
||||
//| An int bitmask representing which properties are set, specified as bitwise or'ing of
|
||||
//| properties: Any = ...
|
||||
//| """An int bitmask representing which properties are set, specified as bitwise or'ing of
|
||||
//| of these possible values.
|
||||
//| `BROADCAST`, `INDICATE`, `NOTIFY`, `READ`, `WRITE`, `WRITE_NO_RESPONSE`.
|
||||
//| `BROADCAST`, `INDICATE`, `NOTIFY`, `READ`, `WRITE`, `WRITE_NO_RESPONSE`."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_characteristic_get_properties(mp_obj_t self_in) {
|
||||
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -165,11 +160,10 @@ const mp_obj_property_t bleio_characteristic_properties_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: uuid
|
||||
//| uuid: Any = ...
|
||||
//| """The UUID of this characteristic. (read-only)
|
||||
//|
|
||||
//| The UUID of this characteristic. (read-only)
|
||||
//|
|
||||
//| Will be ``None`` if the 128-bit UUID for this characteristic is not known.
|
||||
//| Will be ``None`` if the 128-bit UUID for this characteristic is not known."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_characteristic_get_uuid(mp_obj_t self_in) {
|
||||
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -186,9 +180,8 @@ const mp_obj_property_t bleio_characteristic_uuid_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: value
|
||||
//|
|
||||
//| The value of this characteristic.
|
||||
//| value: Any = ...
|
||||
//| """The value of this characteristic."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_characteristic_get_value(mp_obj_t self_in) {
|
||||
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -218,9 +211,8 @@ const mp_obj_property_t bleio_characteristic_value_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: descriptors
|
||||
//|
|
||||
//| A tuple of :py:class:`Descriptor` that describe this characteristic. (read-only)
|
||||
//| descriptors: Any = ...
|
||||
//| """A tuple of :py:class:`Descriptor` that describe this characteristic. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_characteristic_get_descriptors(mp_obj_t self_in) {
|
||||
bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -249,9 +241,8 @@ const mp_obj_property_t bleio_characteristic_descriptors_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: service (read-only)
|
||||
//|
|
||||
//| The Service this Characteristic is a part of.
|
||||
//| service: Any = ...
|
||||
//| """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);
|
||||
|
@ -267,12 +258,12 @@ const mp_obj_property_t bleio_characteristic_service_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. method:: set_cccd(*, notify=False, indicate=False)
|
||||
//| def set_cccd(self, *, notify: bool = False, indicate: float = False) -> Any:
|
||||
//| """Set the remote characteristic's CCCD to enable or disable notification and indication.
|
||||
//|
|
||||
//| Set the remote characteristic's CCCD to enable or disable notification and indication.
|
||||
//|
|
||||
//| :param bool notify: True if Characteristic should receive notifications of remote writes
|
||||
//| :param float indicate: True if Characteristic should receive indications of remote writes
|
||||
//| :param bool notify: True if Characteristic should receive notifications of remote writes
|
||||
//| :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]);
|
||||
|
@ -300,29 +291,23 @@ STATIC const mp_rom_map_elem_t bleio_characteristic_locals_dict_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_set_cccd), MP_ROM_PTR(&bleio_characteristic_set_cccd_obj) },
|
||||
|
||||
// Bitmask constants to represent properties
|
||||
//| .. data:: BROADCAST
|
||||
//| BROADCAST: Any = ...
|
||||
//| """property: allowed in advertising packets"""
|
||||
//|
|
||||
//| property: allowed in advertising packets
|
||||
//| INDICATE: Any = ...
|
||||
//| """property: server will indicate to the client when the value is set and wait for a response"""
|
||||
//|
|
||||
//| .. data:: INDICATE
|
||||
//| NOTIFY: Any = ...
|
||||
//| """property: server will notify the client when the value is set"""
|
||||
//|
|
||||
//| property: server will indicate to the client when the value is set and wait for a response
|
||||
//| READ: Any = ...
|
||||
//| """property: clients may read this characteristic"""
|
||||
//|
|
||||
//| .. data:: NOTIFY
|
||||
//| WRITE: Any = ...
|
||||
//| """property: clients may write this characteristic; a response will be sent back"""
|
||||
//|
|
||||
//| property: server will notify the client when the value is set
|
||||
//|
|
||||
//| .. data:: READ
|
||||
//|
|
||||
//| property: clients may read this characteristic
|
||||
//|
|
||||
//| .. data:: WRITE
|
||||
//|
|
||||
//| property: clients may write this characteristic; a response will be sent back
|
||||
//|
|
||||
//| .. data:: WRITE_NO_RESPONSE
|
||||
//|
|
||||
//| property: clients may write this characteristic; no response will be sent back
|
||||
//| WRITE_NO_RESPONSE: Any = ...
|
||||
//| """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) },
|
||||
|
|
|
@ -41,24 +41,21 @@ STATIC void raise_error_if_not_connected(bleio_characteristic_buffer_obj_t *self
|
|||
}
|
||||
}
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class CharacteristicBuffer:
|
||||
//| """Accumulates a Characteristic's incoming values in a FIFO buffer."""
|
||||
//|
|
||||
//| :class:`CharacteristicBuffer` -- BLE Service incoming values buffer.
|
||||
//| =====================================================================
|
||||
//| def __init__(self, characteristic: Characteristic, *, timeout: int = 1, buffer_size: int = 64):
|
||||
//|
|
||||
//| Accumulates a Characteristic's incoming values in a FIFO buffer.
|
||||
//| """Monitor the given Characteristic. Each time a new value is written to the Characteristic
|
||||
//| add the newly-written bytes to a FIFO buffer.
|
||||
//|
|
||||
//| .. class:: CharacteristicBuffer(characteristic, *, timeout=1, buffer_size=64)
|
||||
//|
|
||||
//| Monitor the given Characteristic. Each time a new value is written to the Characteristic
|
||||
//| add the newly-written bytes to a FIFO buffer.
|
||||
//|
|
||||
//| :param Characteristic characteristic: The Characteristic to monitor.
|
||||
//| It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic
|
||||
//| in a remote Service that a Central has connected to.
|
||||
//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters.
|
||||
//| :param int buffer_size: Size of ring buffer that stores incoming data coming from client.
|
||||
//| Must be >= 1.
|
||||
//| :param Characteristic characteristic: The Characteristic to monitor.
|
||||
//| It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic
|
||||
//| in a remote Service that a Central has connected to.
|
||||
//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters.
|
||||
//| :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, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_characteristic, ARG_timeout, ARG_buffer_size, };
|
||||
|
@ -103,29 +100,29 @@ STATIC void check_for_deinit(bleio_characteristic_buffer_obj_t *self) {
|
|||
|
||||
// These are standard stream methods. Code is in py/stream.c.
|
||||
//
|
||||
//| .. method:: read(nbytes=None)
|
||||
//| def read(self, nbytes: Any = None) -> Any:
|
||||
//| """Read characters. If ``nbytes`` is specified then read at most that many
|
||||
//| bytes. Otherwise, read everything that arrives until the connection
|
||||
//| times out. Providing the number of bytes expected is highly recommended
|
||||
//| because it will be faster.
|
||||
//|
|
||||
//| Read characters. If ``nbytes`` is specified then read at most that many
|
||||
//| bytes. Otherwise, read everything that arrives until the connection
|
||||
//| times out. Providing the number of bytes expected is highly recommended
|
||||
//| because it will be faster.
|
||||
//| :return: Data read
|
||||
//| :rtype: bytes or None"""
|
||||
//| ...
|
||||
//|
|
||||
//| :return: Data read
|
||||
//| :rtype: bytes or None
|
||||
//| def readinto(self, buf: Any) -> Any:
|
||||
//| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
|
||||
//|
|
||||
//| .. method:: readinto(buf)
|
||||
//| :return: number of bytes read and stored into ``buf``
|
||||
//| :rtype: int or None (on a non-blocking error)"""
|
||||
//| ...
|
||||
//|
|
||||
//| Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
|
||||
//| def readline(self, ) -> Any:
|
||||
//| """Read a line, ending in a newline character.
|
||||
//|
|
||||
//| :return: number of bytes read and stored into ``buf``
|
||||
//| :rtype: int or None (on a non-blocking error)
|
||||
//|
|
||||
//| .. method:: readline()
|
||||
//|
|
||||
//| Read a line, ending in a newline character.
|
||||
//|
|
||||
//| :return: the line read
|
||||
//| :rtype: int or None
|
||||
//| :return: the line read
|
||||
//| :rtype: int or None"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
// These three methods are used by the shared stream methods.
|
||||
|
@ -170,9 +167,8 @@ STATIC mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t r
|
|||
return ret;
|
||||
}
|
||||
|
||||
//| .. attribute:: in_waiting
|
||||
//|
|
||||
//| The number of bytes in the input buffer, available to be read
|
||||
//| in_waiting: Any = ...
|
||||
//| """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);
|
||||
|
@ -188,9 +184,9 @@ const mp_obj_property_t bleio_characteristic_buffer_in_waiting_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: reset_input_buffer()
|
||||
//|
|
||||
//| Discard any unread characters in the input buffer.
|
||||
//| def reset_input_buffer(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -200,9 +196,9 @@ STATIC mp_obj_t bleio_characteristic_buffer_obj_reset_input_buffer(mp_obj_t self
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_buffer_reset_input_buffer_obj, bleio_characteristic_buffer_obj_reset_input_buffer);
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Disable permanently.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
|
|
@ -42,28 +42,24 @@
|
|||
#include "shared-bindings/_bleio/Characteristic.h"
|
||||
#include "shared-bindings/_bleio/Service.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class Connection:
|
||||
//| """A BLE connection to another device. Used to discover and interact with services on the other
|
||||
//| device.
|
||||
//|
|
||||
//| :class:`Connection` -- A BLE connection
|
||||
//| =========================================================
|
||||
//| Usage::
|
||||
//|
|
||||
//| A BLE connection to another device. Used to discover and interact with services on the other
|
||||
//| device.
|
||||
//| import _bleio
|
||||
//|
|
||||
//| Usage::
|
||||
//| my_entry = None
|
||||
//| for entry in _bleio.adapter.scan(2.5):
|
||||
//| if entry.name is not None and entry.name == 'InterestingPeripheral':
|
||||
//| my_entry = entry
|
||||
//| break
|
||||
//|
|
||||
//| import _bleio
|
||||
//| if not my_entry:
|
||||
//| raise Exception("'InterestingPeripheral' not found")
|
||||
//|
|
||||
//| my_entry = None
|
||||
//| for entry in _bleio.adapter.scan(2.5):
|
||||
//| if entry.name is not None and entry.name == 'InterestingPeripheral':
|
||||
//| my_entry = entry
|
||||
//| break
|
||||
//|
|
||||
//| if not my_entry:
|
||||
//| raise Exception("'InterestingPeripheral' not found")
|
||||
//|
|
||||
//| connection = _bleio.adapter.connect(my_entry.address, timeout=10)
|
||||
//| connection = _bleio.adapter.connect(my_entry.address, timeout=10)"""
|
||||
//|
|
||||
|
||||
void bleio_connection_ensure_connected(bleio_connection_obj_t *self) {
|
||||
|
@ -72,15 +68,15 @@ void bleio_connection_ensure_connected(bleio_connection_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. class:: Connection()
|
||||
//| def __init__(self, ):
|
||||
//| """Connections cannot be made directly. Instead, to initiate a connection use `Adapter.connect`.
|
||||
//| Connections may also be made when another device initiates a connection. To use a Connection
|
||||
//| created by a peer, read the `Adapter.connections` property.
|
||||
//| ...
|
||||
//|
|
||||
//| Connections cannot be made directly. Instead, to initiate a connection use `Adapter.connect`.
|
||||
//| Connections may also be made when another device initiates a connection. To use a Connection
|
||||
//| created by a peer, read the `Adapter.connections` property.
|
||||
//|
|
||||
//| .. method:: disconnect()
|
||||
//|
|
||||
//| Disconnects from the remote peripheral. Does nothing if already disconnected.
|
||||
//| def disconnect(self, ) -> Any:
|
||||
//| ""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);
|
||||
|
@ -91,9 +87,9 @@ STATIC mp_obj_t bleio_connection_disconnect(mp_obj_t self_in) {
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_disconnect_obj, bleio_connection_disconnect);
|
||||
|
||||
|
||||
//| .. method:: pair(*, bond=True)
|
||||
//|
|
||||
//| Pair to the peer to improve security.
|
||||
//| def pair(self, *, bond: Any = True) -> Any:
|
||||
//| """Pair to the peer to improve security."""
|
||||
//| ...
|
||||
//|
|
||||
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]);
|
||||
|
@ -113,29 +109,29 @@ STATIC mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_pair_obj, 1, bleio_connection_pair);
|
||||
|
||||
//| .. method:: discover_remote_services(service_uuids_whitelist=None)
|
||||
//| def discover_remote_services(self, service_uuids_whitelist: iterable = None) -> Any:
|
||||
//| """Do BLE discovery for all services or for the given service UUIDS,
|
||||
//| to find their handles and characteristics, and return the discovered services.
|
||||
//| `Connection.connected` must be True.
|
||||
//|
|
||||
//| Do BLE discovery for all services or for the given service UUIDS,
|
||||
//| to find their handles and characteristics, and return the discovered services.
|
||||
//| `Connection.connected` must be True.
|
||||
//| :param iterable service_uuids_whitelist:
|
||||
//|
|
||||
//| :param iterable service_uuids_whitelist:
|
||||
//| an iterable of :py:class:~`UUID` objects for the services provided by the peripheral
|
||||
//| that you want to use.
|
||||
//|
|
||||
//| an iterable of :py:class:~`UUID` objects for the services provided by the peripheral
|
||||
//| that you want to use.
|
||||
//| The peripheral may provide more services, but services not listed are ignored
|
||||
//| and will not be returned.
|
||||
//|
|
||||
//| The peripheral may provide more services, but services not listed are ignored
|
||||
//| and will not be returned.
|
||||
//| If service_uuids_whitelist is None, then all services will undergo discovery, which can be
|
||||
//| slow.
|
||||
//|
|
||||
//| If service_uuids_whitelist is None, then all services will undergo discovery, which can be
|
||||
//| slow.
|
||||
//| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you
|
||||
//| you must have already created a :py:class:~`UUID` object for that UUID in order for the
|
||||
//| service or characteristic to be discovered. Creating the UUID causes the UUID to be
|
||||
//| registered for use. (This restriction may be lifted in the future.)
|
||||
//|
|
||||
//| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you
|
||||
//| you must have already created a :py:class:~`UUID` object for that UUID in order for the
|
||||
//| service or characteristic to be discovered. Creating the UUID causes the UUID to be
|
||||
//| registered for use. (This restriction may be lifted in the future.)
|
||||
//|
|
||||
//| :return: A tuple of `_bleio.Service` objects provided by the remote peripheral.
|
||||
//| :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]);
|
||||
|
@ -156,9 +152,8 @@ STATIC mp_obj_t bleio_connection_discover_remote_services(mp_uint_t n_args, cons
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_discover_remote_services_obj, 1, bleio_connection_discover_remote_services);
|
||||
|
||||
//| .. attribute:: connected
|
||||
//|
|
||||
//| True if connected to the remote peer.
|
||||
//| connected: Any = ...
|
||||
//| """True if connected to the remote peer."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_connection_get_connected(mp_obj_t self_in) {
|
||||
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -175,9 +170,8 @@ const mp_obj_property_t bleio_connection_connected_obj = {
|
|||
};
|
||||
|
||||
|
||||
//| .. attribute:: paired
|
||||
//|
|
||||
//| True if paired to the remote peer.
|
||||
//| paired: Any = ...
|
||||
//| """True if paired to the remote peer."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_connection_get_paired(mp_obj_t self_in) {
|
||||
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -194,17 +188,15 @@ const mp_obj_property_t bleio_connection_paired_obj = {
|
|||
};
|
||||
|
||||
|
||||
//| .. attribute:: connection_interval
|
||||
//|
|
||||
//| Time between transmissions in milliseconds. Will be multiple of 1.25ms. Lower numbers
|
||||
//| connection_interval: Any = ...
|
||||
//| """Time between transmissions in milliseconds. Will be multiple of 1.25ms. Lower numbers
|
||||
//| increase speed and decrease latency but increase power consumption.
|
||||
//|
|
||||
//| When setting connection_interval, the peer may reject the new interval and
|
||||
//| `connection_interval` will then remain the same.
|
||||
//|
|
||||
//| Apple has additional guidelines that dictate should be a multiple of 15ms except if HID is
|
||||
//| available. When HID is available Apple devices may accept 11.25ms intervals.
|
||||
//|
|
||||
//| available. When HID is available Apple devices may accept 11.25ms intervals."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_connection_get_connection_interval(mp_obj_t self_in) {
|
||||
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -214,15 +206,14 @@ STATIC mp_obj_t bleio_connection_get_connection_interval(mp_obj_t self_in) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_get_connection_interval_obj, bleio_connection_get_connection_interval);
|
||||
|
||||
//| .. attribute:: max_packet_length
|
||||
//|
|
||||
//| The maximum number of data bytes that can be sent in a single transmission,
|
||||
//| attribute: Any = ...
|
||||
//| """The maximum number of data bytes that can be sent in a single transmission,
|
||||
//| not including overhead bytes.
|
||||
//|
|
||||
//| This is the maximum number of bytes that can be sent in a notification,
|
||||
//| which must be sent in a single packet.
|
||||
//| But for a regular characteristic read or write, may be sent in multiple packets,
|
||||
//| so this limit does not apply.
|
||||
//| 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);
|
||||
|
|
|
@ -33,41 +33,38 @@
|
|||
#include "shared-bindings/_bleio/Descriptor.h"
|
||||
#include "shared-bindings/_bleio/UUID.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class Descriptor:
|
||||
//| """Stores information about a BLE descriptor.
|
||||
//|
|
||||
//| :class:`Descriptor` -- BLE descriptor
|
||||
//| =========================================================
|
||||
//| Descriptors are attached to BLE characteristics and provide contextual
|
||||
//| information about the characteristic."""
|
||||
//|
|
||||
//| Stores information about a BLE descriptor.
|
||||
//| Descriptors are attached to BLE characteristics and provide contextual
|
||||
//| information about the characteristic.
|
||||
//| def __init__(self, ):
|
||||
//| """There is no regular constructor for a Descriptor. A new local Descriptor can be created
|
||||
//| and attached to a Characteristic by calling `add_to_characteristic()`.
|
||||
//| Remote Descriptor objects are created by `Connection.discover_remote_services()`
|
||||
//| as part of remote Characteristics in the remote Services that are discovered.
|
||||
//|
|
||||
//| .. class:: Descriptor
|
||||
//| .. classmethod:: add_to_characteristic(characteristic, uuid, *, read_perm=`Attribute.OPEN`, write_perm=`Attribute.OPEN`, max_length=20, fixed_length=False, initial_value=b'')
|
||||
//|
|
||||
//| There is no regular constructor for a Descriptor. A new local Descriptor can be created
|
||||
//| and attached to a Characteristic by calling `add_to_characteristic()`.
|
||||
//| Remote Descriptor objects are created by `Connection.discover_remote_services()`
|
||||
//| as part of remote Characteristics in the remote Services that are discovered.
|
||||
//| Create a new Descriptor object, and add it to this Service.
|
||||
//|
|
||||
//| .. classmethod:: add_to_characteristic(characteristic, uuid, *, read_perm=`Attribute.OPEN`, write_perm=`Attribute.OPEN`, max_length=20, fixed_length=False, initial_value=b'')
|
||||
//| :param Characteristic characteristic: The characteristic that will hold this descriptor
|
||||
//| :param UUID uuid: The uuid of the descriptor
|
||||
//| :param int read_perm: Specifies whether the descriptor can be read by a client, and if so, which
|
||||
//| security mode is required. Must be one of the integer values `Attribute.NO_ACCESS`, `Attribute.OPEN`,
|
||||
//| `Attribute.ENCRYPT_NO_MITM`, `Attribute.ENCRYPT_WITH_MITM`, `Attribute.LESC_ENCRYPT_WITH_MITM`,
|
||||
//| `Attribute.SIGNED_NO_MITM`, or `Attribute.SIGNED_WITH_MITM`.
|
||||
//| :param int write_perm: Specifies whether the descriptor can be written by a client, and if so, which
|
||||
//| security mode is required. Values allowed are the same as ``read_perm``.
|
||||
//| :param int max_length: Maximum length in bytes of the descriptor value. The maximum allowed is
|
||||
//| is 512, or possibly 510 if ``fixed_length`` is False. The default, 20, is the maximum
|
||||
//| number of data bytes that fit in a single BLE 4.x ATT packet.
|
||||
//| :param bool fixed_length: True if the descriptor value is of fixed length.
|
||||
//| :param buf initial_value: The initial value for this descriptor.
|
||||
//|
|
||||
//| Create a new Descriptor object, and add it to this Service.
|
||||
//|
|
||||
//| :param Characteristic characteristic: The characteristic that will hold this descriptor
|
||||
//| :param UUID uuid: The uuid of the descriptor
|
||||
//| :param int read_perm: Specifies whether the descriptor can be read by a client, and if so, which
|
||||
//| security mode is required. Must be one of the integer values `Attribute.NO_ACCESS`, `Attribute.OPEN`,
|
||||
//| `Attribute.ENCRYPT_NO_MITM`, `Attribute.ENCRYPT_WITH_MITM`, `Attribute.LESC_ENCRYPT_WITH_MITM`,
|
||||
//| `Attribute.SIGNED_NO_MITM`, or `Attribute.SIGNED_WITH_MITM`.
|
||||
//| :param int write_perm: Specifies whether the descriptor can be written by a client, and if so, which
|
||||
//| security mode is required. Values allowed are the same as ``read_perm``.
|
||||
//| :param int max_length: Maximum length in bytes of the descriptor value. The maximum allowed is
|
||||
//| is 512, or possibly 510 if ``fixed_length`` is False. The default, 20, is the maximum
|
||||
//| number of data bytes that fit in a single BLE 4.x ATT packet.
|
||||
//| :param bool fixed_length: True if the descriptor value is of fixed length.
|
||||
//| :param buf initial_value: The initial value for this descriptor.
|
||||
//|
|
||||
//| :return: the new Descriptor.
|
||||
//| :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.
|
||||
|
@ -135,9 +132,8 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_descriptor_add_to_characteristic_fun_obj, 3, bleio_descriptor_add_to_characteristic);
|
||||
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bleio_descriptor_add_to_characteristic_obj, MP_ROM_PTR(&bleio_descriptor_add_to_characteristic_fun_obj));
|
||||
|
||||
//| .. attribute:: uuid
|
||||
//|
|
||||
//| The descriptor uuid. (read-only)
|
||||
//| uuid: Any = ...
|
||||
//| """The descriptor uuid. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_descriptor_get_uuid(mp_obj_t self_in) {
|
||||
bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -154,9 +150,8 @@ const mp_obj_property_t bleio_descriptor_uuid_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: characteristic (read-only)
|
||||
//|
|
||||
//| The Characteristic this Descriptor is a part of.
|
||||
//| characteristic: Any = ...
|
||||
//| """The Characteristic this Descriptor is a part of."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_descriptor_get_characteristic(mp_obj_t self_in) {
|
||||
bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -172,9 +167,8 @@ const mp_obj_property_t bleio_descriptor_characteristic_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: value
|
||||
//|
|
||||
//| The value of this descriptor.
|
||||
//| value: Any = ...
|
||||
//| """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);
|
||||
|
|
|
@ -35,29 +35,28 @@
|
|||
#include "shared-bindings/_bleio/UUID.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class PacketBuffer:
|
||||
//| """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
|
||||
//| unit (MTU) minus overhead, whichever is smaller. The MTU can change so check `incoming_packet_length`
|
||||
//| and `outgoing_packet_length` before creating a buffer to store data.
|
||||
//|
|
||||
//| :class:`PacketBuffer` -- Packet-oriented characteristic usage.
|
||||
//| =====================================================================
|
||||
//| When we're the server, we ignore all connections besides the first to subscribe to
|
||||
//| notifications."""
|
||||
//|
|
||||
//| 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
|
||||
//| unit (MTU) minus overhead, whichever is smaller. The MTU can change so check `incoming_packet_length`
|
||||
//| and `outgoing_packet_length` before creating a buffer to store data.
|
||||
//| def __init__(self, characteristic: Characteristic, *, buffer_size: int):
|
||||
//| """Monitor the given Characteristic. Each time a new value is written to the Characteristic
|
||||
//| add the newly-written bytes to a FIFO buffer.
|
||||
//|
|
||||
//| When we're the server, we ignore all connections besides the first to subscribe to
|
||||
//| notifications.
|
||||
//| Monitor the given Characteristic. Each time a new value is written to the Characteristic
|
||||
//| add the newly-written packet of bytes to a FIFO buffer.
|
||||
//|
|
||||
//| .. class:: PacketBuffer(characteristic, *, buffer_size)
|
||||
//|
|
||||
//| Monitor the given Characteristic. Each time a new value is written to the Characteristic
|
||||
//| add the newly-written packet of bytes to a FIFO buffer.
|
||||
//|
|
||||
//| :param Characteristic characteristic: The Characteristic to monitor.
|
||||
//| It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic
|
||||
//| in a remote Service that a Central has connected to.
|
||||
//| :param int buffer_size: Size of ring buffer (in packets of the Characteristic's maximum
|
||||
//| length) that stores incoming packets coming from the peer.
|
||||
//| :param Characteristic characteristic: The Characteristic to monitor.
|
||||
//| It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic
|
||||
//| in a remote Service that a Central has connected to.
|
||||
//| :param int buffer_size: Size of ring buffer (in packets of the Characteristic's maximum
|
||||
//| length) that stores incoming packets coming from the peer."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_characteristic, ARG_buffer_size };
|
||||
|
@ -94,13 +93,13 @@ STATIC void check_for_deinit(bleio_packet_buffer_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: readinto(buf)
|
||||
//| def readinto(self, buf: Any) -> Any:
|
||||
//| """Reads a single BLE packet into the ``buf``. Raises an exception if the next packet is longer
|
||||
//| than the given buffer. Use `packet_size` to read the maximum length of a single packet.
|
||||
//|
|
||||
//| Reads a single BLE packet into the ``buf``. Raises an exception if the next packet is longer
|
||||
//| than the given buffer. Use `packet_size` to read the maximum length of a single packet.
|
||||
//|
|
||||
//| :return: number of bytes read and stored into ``buf``
|
||||
//| :rtype: int
|
||||
//| :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);
|
||||
|
@ -118,15 +117,15 @@ STATIC mp_obj_t bleio_packet_buffer_readinto(mp_obj_t self_in, mp_obj_t buffer_o
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_buffer_readinto);
|
||||
|
||||
//| .. method:: write(data, *, header=None)
|
||||
//| def write(self, data: Any, *, header: Any = None) -> Any:
|
||||
//| """Writes all bytes from data into the same outgoing packet. The bytes from header are included
|
||||
//| before data when the pending packet is currently empty.
|
||||
//|
|
||||
//| Writes all bytes from data into the same outgoing packet. The bytes from header are included
|
||||
//| before data when the pending packet is currently empty.
|
||||
//| This does not block until the data is sent. It only blocks until the data is pending.
|
||||
//|
|
||||
//| This does not block until the data is sent. It only blocks until the data is pending.
|
||||
//|
|
||||
//| :return: number of bytes written. May include header bytes when packet is empty.
|
||||
//| :rtype: int
|
||||
//| :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.
|
||||
|
@ -170,10 +169,9 @@ STATIC mp_obj_t bleio_packet_buffer_write(mp_uint_t n_args, const mp_obj_t *pos_
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_packet_buffer_write_obj, 1, bleio_packet_buffer_write);
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Disable permanently.
|
||||
//|
|
||||
//| def deinit(self) -> Any:
|
||||
//| """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);
|
||||
|
@ -181,15 +179,13 @@ STATIC mp_obj_t bleio_packet_buffer_deinit(mp_obj_t self_in) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_packet_buffer_deinit_obj, bleio_packet_buffer_deinit);
|
||||
|
||||
//| .. attribute:: packet_size
|
||||
//|
|
||||
//| `packet_size` is the same as `incoming_packet_length`.
|
||||
//| packet_size: int = ...
|
||||
//| """`packet_size` is the same as `incoming_packet_length`.
|
||||
//| The name `packet_size` is deprecated and
|
||||
//| will be removed in CircuitPython 6.0.0.
|
||||
//| will be removed in CircuitPython 6.0.0."""
|
||||
//|
|
||||
//| .. attribute:: incoming_packet_length
|
||||
//|
|
||||
//| Maximum length in bytes of a packet we are reading.
|
||||
//| incoming_packet_length: Any = ...
|
||||
//| """Maximum length in bytes of a packet we are reading."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_packet_buffer_get_incoming_packet_length(mp_obj_t self_in) {
|
||||
bleio_packet_buffer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -209,9 +205,8 @@ const mp_obj_property_t bleio_packet_buffer_incoming_packet_length_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: outgoing_packet_length
|
||||
//|
|
||||
//| Maximum length in bytes of a packet we are writing.
|
||||
//| 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);
|
||||
|
|
|
@ -35,25 +35,21 @@
|
|||
#include "shared-bindings/_bleio/UUID.h"
|
||||
#include "shared-module/_bleio/ScanEntry.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//|
|
||||
//| :class:`ScanEntry` -- BLE scan data
|
||||
//| =========================================================
|
||||
//|
|
||||
//| Encapsulates information about a device that was received during scanning. It can be
|
||||
//| advertisement or scan response data. This object may only be created by a `_bleio.ScanResults`:
|
||||
//| it has no user-visible constructor.
|
||||
//| class ScanEntry:
|
||||
//| """Encapsulates information about a device that was received during scanning. It can be
|
||||
//| advertisement or scan response data. This object may only be created by a `_bleio.ScanResults`:
|
||||
//| it has no user-visible constructor."""
|
||||
//|
|
||||
|
||||
//| .. class:: ScanEntry()
|
||||
//| def __init__(self, ):
|
||||
//| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`."""
|
||||
//| ...
|
||||
//|
|
||||
//| Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.
|
||||
//|
|
||||
//| .. method:: matches(prefixes, *, all=True)
|
||||
//|
|
||||
//| Returns True if the ScanEntry matches all prefixes when ``all`` is True. This is stricter
|
||||
//| than the scan filtering which accepts any advertisements that match any of the prefixes
|
||||
//| where all is False.
|
||||
//| def matches(self, prefixes: Any, *, all: Any = True) -> Any:
|
||||
//| """Returns True if the ScanEntry matches all prefixes when ``all`` is True. This is stricter
|
||||
//| than the scan filtering which accepts any advertisements that match any of the prefixes
|
||||
//| where 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]);
|
||||
|
@ -67,16 +63,15 @@ STATIC mp_obj_t bleio_scanentry_matches(mp_uint_t n_args, const mp_obj_t *pos_ar
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[ARG_prefixes].u_obj, &bufinfo, MP_BUFFER_READ);
|
||||
return mp_obj_new_bool(common_hal_bleio_scanentry_matches(self, bufinfo.buf, bufinfo.len, args[ARG_all].u_bool));
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanentry_matches_obj, 2, bleio_scanentry_matches);
|
||||
|
||||
//| .. attribute:: address
|
||||
//|
|
||||
//| The address of the device (read-only), of type `_bleio.Address`.
|
||||
//| address: Any = ...
|
||||
//| """The address of the device (read-only), of type `_bleio.Address`."""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_scanentry_get_address(mp_obj_t self_in) {
|
||||
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -91,9 +86,8 @@ const mp_obj_property_t bleio_scanentry_address_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: advertisement_bytes
|
||||
//|
|
||||
//| All the advertisement data present in the packet, returned as a ``bytes`` object. (read-only)
|
||||
//| advertisement_bytes: Any = ...
|
||||
//| """All the advertisement data present in the packet, returned as a ``bytes`` object. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t scanentry_get_advertisement_bytes(mp_obj_t self_in) {
|
||||
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -108,9 +102,8 @@ const mp_obj_property_t bleio_scanentry_advertisement_bytes_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: rssi
|
||||
//|
|
||||
//| The signal strength of the device at the time of the scan, in integer dBm. (read-only)
|
||||
//| rssi: Any = ...
|
||||
//| """The signal strength of the device at the time of the scan, in integer dBm. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t scanentry_get_rssi(mp_obj_t self_in) {
|
||||
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -125,9 +118,8 @@ const mp_obj_property_t bleio_scanentry_rssi_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: connectable
|
||||
//|
|
||||
//| True if the device can be connected to. (read-only)
|
||||
//| connectable: Any = ...
|
||||
//| """True if the device can be connected to. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t scanentry_get_connectable(mp_obj_t self_in) {
|
||||
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -142,9 +134,8 @@ const mp_obj_property_t bleio_scanentry_connectable_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: scan_response
|
||||
//|
|
||||
//| True if the entry was a scan response. (read-only)
|
||||
//| scan_response: Any = ...
|
||||
//| """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);
|
||||
|
|
|
@ -32,13 +32,9 @@
|
|||
#include "py/runtime.h"
|
||||
#include "shared-bindings/_bleio/ScanResults.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//|
|
||||
//| :class:`ScanResults` -- An Iterator over BLE scanning results
|
||||
//| ===============================================================
|
||||
//|
|
||||
//| Iterates over advertising data received while scanning. This object is always created
|
||||
//| by a `_bleio.Adapter`: it has no user-visible constructor.
|
||||
//| class ScanResults:
|
||||
//| """Iterates over advertising data received while scanning. This object is always created
|
||||
//| by a `_bleio.Adapter`: it has no user-visible constructor."""
|
||||
//|
|
||||
STATIC mp_obj_t scanresults_iternext(mp_obj_t self_in) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(self_in, &bleio_scanresults_type));
|
||||
|
@ -50,18 +46,18 @@ STATIC mp_obj_t scanresults_iternext(mp_obj_t self_in) {
|
|||
return MP_OBJ_STOP_ITERATION;
|
||||
}
|
||||
|
||||
//| .. class:: ScanResults()
|
||||
//| def __init__(self, ):
|
||||
//| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`."""
|
||||
//| ...
|
||||
//|
|
||||
//| Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.
|
||||
//| def __iter__(self, ) -> Any:
|
||||
//| """Returns itself since it is the iterator."""
|
||||
//| ...
|
||||
//|
|
||||
//| .. method:: __iter__()
|
||||
//|
|
||||
//| Returns itself since it is the iterator.
|
||||
//|
|
||||
//| .. method:: __next__()
|
||||
//|
|
||||
//| Returns the next `_bleio.ScanEntry`. Blocks if none have been received and scanning is still
|
||||
//| active. Raises `StopIteration` if scanning is finished and no other results are available.
|
||||
//| def __next__(self, ) -> Any:
|
||||
//| """Returns the next `_bleio.ScanEntry`. Blocks if none have been received and scanning is still
|
||||
//| active. Raises `StopIteration` if scanning is finished and no other results are available."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
const mp_obj_type_t bleio_scanresults_type = {
|
||||
|
|
|
@ -32,25 +32,21 @@
|
|||
#include "shared-bindings/_bleio/Service.h"
|
||||
#include "shared-bindings/_bleio/UUID.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class Service:
|
||||
//| """Stores information about a BLE service and its characteristics."""
|
||||
//|
|
||||
//| :class:`Service` -- BLE GATT Service
|
||||
//| =========================================================
|
||||
//| def __init__(self, uuid: UUID, *, secondary: bool = False):
|
||||
//| """Create a new Service identified by the specified UUID. It can be accessed by all
|
||||
//| connections. This is known as a Service server. Client Service objects are created via
|
||||
//| `Connection.discover_remote_services`.
|
||||
//|
|
||||
//| Stores information about a BLE service and its characteristics.
|
||||
//| To mark the Service as secondary, pass `True` as :py:data:`secondary`.
|
||||
//|
|
||||
//| .. class:: Service(uuid, *, secondary=False)
|
||||
//| :param UUID uuid: The uuid of the service
|
||||
//| :param bool secondary: If the service is a secondary one
|
||||
//|
|
||||
//| Create a new Service identified by the specified UUID. It can be accessed by all
|
||||
//| connections. This is known as a Service server. Client Service objects are created via
|
||||
//| `Connection.discover_remote_services`.
|
||||
//|
|
||||
//| To mark the Service as secondary, pass `True` as :py:data:`secondary`.
|
||||
//|
|
||||
//| :param UUID uuid: The uuid of the service
|
||||
//| :param bool secondary: If the service is a secondary one
|
||||
//
|
||||
//| :return: the new Service
|
||||
//| :return: the new Service"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_uuid, ARG_secondary };
|
||||
|
@ -77,10 +73,9 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return MP_OBJ_FROM_PTR(service);
|
||||
}
|
||||
|
||||
//| .. attribute:: characteristics
|
||||
//|
|
||||
//| A tuple of :py:class:`Characteristic` designating the characteristics that are offered by
|
||||
//| this service. (read-only)
|
||||
//| characteristics: Any = ...
|
||||
//| """A tuple of :py:class:`Characteristic` designating the characteristics that are offered by
|
||||
//| this service. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_service_get_characteristics(mp_obj_t self_in) {
|
||||
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -97,9 +92,8 @@ const mp_obj_property_t bleio_service_characteristics_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: remote
|
||||
//|
|
||||
//| True if this is a service provided by a remote device. (read-only)
|
||||
//| remote: Any = ...
|
||||
//| """True if this is a service provided by a remote device. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_service_get_remote(mp_obj_t self_in) {
|
||||
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -115,9 +109,8 @@ const mp_obj_property_t bleio_service_remote_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: secondary
|
||||
//|
|
||||
//| True if this is a secondary service. (read-only)
|
||||
//| secondary: Any = ...
|
||||
//| """True if this is a secondary service. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_service_get_secondary(mp_obj_t self_in) {
|
||||
bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -133,11 +126,10 @@ const mp_obj_property_t bleio_service_secondary_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj },
|
||||
};
|
||||
|
||||
//| .. attribute:: uuid
|
||||
//| uuid: Any = ...
|
||||
//| """The UUID of this service. (read-only)
|
||||
//|
|
||||
//| The UUID of this service. (read-only)
|
||||
//|
|
||||
//| Will be ``None`` if the 128-bit UUID for this service is not known.
|
||||
//| 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);
|
||||
|
|
|
@ -33,28 +33,23 @@
|
|||
#include "py/runtime.h"
|
||||
#include "shared-bindings/_bleio/UUID.h"
|
||||
|
||||
//| .. currentmodule:: _bleio
|
||||
//| class UUID:
|
||||
//| """A 16-bit or 128-bit UUID. Can be used for services, characteristics, descriptors and more."""
|
||||
//|
|
||||
//| :class:`UUID` -- BLE UUID
|
||||
//| =========================================================
|
||||
//| def __init__(self, value: Any):
|
||||
//| """Create a new UUID or UUID object encapsulating the uuid value.
|
||||
//| The value can be one of:
|
||||
//|
|
||||
//| A 16-bit or 128-bit UUID. Can be used for services, characteristics, descriptors and more.
|
||||
//| - an `int` value in range 0 to 0xFFFF (Bluetooth SIG 16-bit UUID)
|
||||
//| - a buffer object (bytearray, bytes) of 16 bytes in little-endian order (128-bit UUID)
|
||||
//| - a string of hex digits of the form 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
||||
//|
|
||||
|
||||
//| .. class:: UUID(value)
|
||||
//| Creating a 128-bit UUID registers the UUID with the onboard BLE software, and provides a
|
||||
//| temporary 16-bit UUID that can be used in place of the full 128-bit UUID.
|
||||
//|
|
||||
//| Create a new UUID or UUID object encapsulating the uuid value.
|
||||
//| The value can be one of:
|
||||
//|
|
||||
//| - an `int` value in range 0 to 0xFFFF (Bluetooth SIG 16-bit UUID)
|
||||
//| - a buffer object (bytearray, bytes) of 16 bytes in little-endian order (128-bit UUID)
|
||||
//| - a string of hex digits of the form 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
||||
//|
|
||||
//| Creating a 128-bit UUID registers the UUID with the onboard BLE software, and provides a
|
||||
//| temporary 16-bit UUID that can be used in place of the full 128-bit UUID.
|
||||
//|
|
||||
//| :param value: The uuid value to encapsulate
|
||||
//| :type value: int or typing.ByteString
|
||||
//| :param value: The uuid value to encapsulate
|
||||
//| :type value: int or typing.ByteString"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
|
@ -125,11 +120,10 @@ STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, co
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. attribute:: uuid16
|
||||
//| uuid16: Any = ...
|
||||
//| """The 16-bit part of the UUID. (read-only)
|
||||
//|
|
||||
//| The 16-bit part of the UUID. (read-only)
|
||||
//|
|
||||
//| :type: int
|
||||
//| :type: int"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_uuid_get_uuid16(mp_obj_t self_in) {
|
||||
bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -145,12 +139,11 @@ const mp_obj_property_t bleio_uuid_uuid16_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: uuid128
|
||||
//|
|
||||
//| The 128-bit value of the UUID
|
||||
//| uuid128: Any = ...
|
||||
//| """The 128-bit value of the UUID
|
||||
//| Raises AttributeError if this is a 16-bit UUID. (read-only)
|
||||
//|
|
||||
//| :type: bytes
|
||||
//| :type: bytes"""
|
||||
//|
|
||||
STATIC mp_obj_t bleio_uuid_get_uuid128(mp_obj_t self_in) {
|
||||
bleio_uuid_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -172,12 +165,11 @@ const mp_obj_property_t bleio_uuid_uuid128_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: size
|
||||
//|
|
||||
//| 128 if this UUID represents a 128-bit vendor-specific UUID. 16 if this UUID represents a
|
||||
//| size: Any = ...
|
||||
//| """128 if this UUID represents a 128-bit vendor-specific UUID. 16 if this UUID represents a
|
||||
//| 16-bit Bluetooth SIG assigned UUID. (read-only) 32-bit UUIDs are not currently supported.
|
||||
//|
|
||||
//| :type: int
|
||||
//| :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);
|
||||
|
@ -194,9 +186,9 @@ const mp_obj_property_t bleio_uuid_size_obj = {
|
|||
};
|
||||
|
||||
|
||||
//| .. method:: pack_into(buffer, offset=0)
|
||||
//|
|
||||
//| Packs the UUID into the given buffer at the given offset.
|
||||
//| def pack_into(self, buffer: Any, offset: Any = 0) -> Any:
|
||||
//| """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]);
|
||||
|
@ -210,7 +202,7 @@ STATIC mp_obj_t bleio_uuid_pack_into(mp_uint_t n_args, const mp_obj_t *pos_args,
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
|
||||
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_WRITE);
|
||||
|
||||
|
@ -256,11 +248,9 @@ STATIC mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
|||
}
|
||||
}
|
||||
|
||||
//|
|
||||
|
||||
//| .. method:: __eq__(other)
|
||||
//|
|
||||
//| Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit.
|
||||
//| def __eq__(self, other: Any) -> Any:
|
||||
//| """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) {
|
||||
|
|
|
@ -41,13 +41,7 @@
|
|||
#include "shared-bindings/_bleio/Service.h"
|
||||
#include "shared-bindings/_bleio/UUID.h"
|
||||
|
||||
//| :mod:`_bleio` --- Bluetooth Low Energy (BLE) communication
|
||||
//| ================================================================
|
||||
//|
|
||||
//| .. module:: _bleio
|
||||
//| :synopsis: Bluetooth Low Energy functionality
|
||||
//| :platform: nRF
|
||||
//|
|
||||
//| """
|
||||
//| The `_bleio` module provides necessary low-level functionality for communicating
|
||||
//| using Bluetooth Low Energy (BLE). The '_' prefix indicates this module is meant
|
||||
//| for internal use by libraries but not by the end user. Its API may change incompatibly
|
||||
|
@ -58,34 +52,17 @@
|
|||
//| provides higher-level convenience functionality, including predefined beacons, clients,
|
||||
//| servers.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Address
|
||||
//| Adapter
|
||||
//| Attribute
|
||||
//| Characteristic
|
||||
//| CharacteristicBuffer
|
||||
//| Connection
|
||||
//| Descriptor
|
||||
//| PacketBuffer
|
||||
//| ScanEntry
|
||||
//| ScanResults
|
||||
//| Service
|
||||
//| UUID
|
||||
//|
|
||||
//| .. attribute:: adapter
|
||||
//|
|
||||
//| BLE Adapter used to manage device discovery and connections.
|
||||
//| This object is the sole instance of `_bleio.Adapter`.
|
||||
//| This object is the sole instance of `_bleio.Adapter`."""
|
||||
//|
|
||||
|
||||
//| .. class:: BluetoothError(Exception)
|
||||
//|
|
||||
//| Catch all exception for Bluetooth related errors.
|
||||
//|
|
||||
|
||||
//| class BluetoothError:
|
||||
//| def __init__(self, Exception: Any):
|
||||
//| """Catch all exception for Bluetooth related errors."""
|
||||
//| ...
|
||||
MP_DEFINE_BLEIO_EXCEPTION(BluetoothError, Exception)
|
||||
|
||||
NORETURN void mp_raise_bleio_BluetoothError(const compressed_string_t* fmt, ...) {
|
||||
|
@ -95,10 +72,10 @@ NORETURN void mp_raise_bleio_BluetoothError(const compressed_string_t* fmt, ...)
|
|||
va_end(argptr);
|
||||
nlr_raise(exception);
|
||||
}
|
||||
|
||||
//| .. class:: ConnectionError(BluetoothError)
|
||||
//|
|
||||
//| Raised when a connection is unavailable.
|
||||
//| class ConnectionError:
|
||||
//| def __init__(self, BluetoothError: Any):
|
||||
//| """Raised when a connection is unavailable."""
|
||||
//| ...
|
||||
//|
|
||||
MP_DEFINE_BLEIO_EXCEPTION(ConnectionError, bleio_BluetoothError)
|
||||
NORETURN void mp_raise_bleio_ConnectionError(const compressed_string_t* fmt, ...) {
|
||||
|
@ -109,19 +86,20 @@ NORETURN void mp_raise_bleio_ConnectionError(const compressed_string_t* fmt, ...
|
|||
nlr_raise(exception);
|
||||
}
|
||||
|
||||
//| .. class:: RoleError(BluetoothError)
|
||||
//|
|
||||
//| Raised when a resource is used as the mismatched role. For example, if a local CCCD is
|
||||
//| attempted to be set but they can only be set when remote.
|
||||
//| class RoleError:
|
||||
//| def __init__(self, BluetoothError: Any):
|
||||
//| """Raised when a resource is used as the mismatched role. For example, if a local CCCD is
|
||||
//| attempted to be set but they can only be set when remote."""
|
||||
//| ...
|
||||
//|
|
||||
MP_DEFINE_BLEIO_EXCEPTION(RoleError, bleio_BluetoothError)
|
||||
NORETURN void mp_raise_bleio_RoleError(const compressed_string_t* msg) {
|
||||
mp_raise_msg(&mp_type_bleio_RoleError, msg);
|
||||
}
|
||||
|
||||
//| .. class:: SecurityError(BluetoothError)
|
||||
//|
|
||||
//| Raised when a security related error occurs.
|
||||
//| class SecurityError:
|
||||
//| def __init__(self, BluetoothError: Any):
|
||||
//| """Raised when a security related error occurs."""
|
||||
//| ...
|
||||
//|
|
||||
MP_DEFINE_BLEIO_EXCEPTION(SecurityError, bleio_BluetoothError)
|
||||
NORETURN void mp_raise_bleio_SecurityError(const compressed_string_t* fmt, ...) {
|
||||
|
|
|
@ -34,16 +34,11 @@
|
|||
#include "shared-module/_eve/__init__.h"
|
||||
#include "shared-bindings/_eve/__init__.h"
|
||||
|
||||
//| :mod:`_eve` --- low-level BridgeTek EVE bindings
|
||||
//| ================================================
|
||||
//|
|
||||
//| .. module:: _eve
|
||||
//| :synopsis: low-level BridgeTek EVE bindings
|
||||
//| :platform: SAMD21/SAMD51
|
||||
//| """Low-level BridgeTek EVE bindings
|
||||
//|
|
||||
//| The `_eve` module provides a class _EVE which
|
||||
//| contains methods for constructing EVE command
|
||||
//| buffers and appending basic graphics commands.
|
||||
//| contains methods for constructing EVE command
|
||||
//| buffers and appending basic graphics commands."""
|
||||
//|
|
||||
|
||||
typedef struct _mp_obj__EVE_t {
|
||||
|
@ -63,11 +58,11 @@ STATIC mp_obj_t _register(mp_obj_t self, mp_obj_t o) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(register_obj, _register);
|
||||
|
||||
//| .. method:: flush()
|
||||
//|
|
||||
//| Send any queued drawing commands directly to the hardware.
|
||||
//| def flush(self, ) -> Any:
|
||||
//| """Send any queued drawing commands directly to the hardware.
|
||||
//|
|
||||
//| :param int width: The width of the grid in tiles, or 1 for sprites.
|
||||
//| :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));
|
||||
|
@ -75,11 +70,11 @@ STATIC mp_obj_t _flush(mp_obj_t self) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(flush_obj, _flush);
|
||||
|
||||
//| .. method:: cc(b)
|
||||
//|
|
||||
//| Append bytes to the command FIFO.
|
||||
//| def cc(self, b: bytes) -> Any:
|
||||
//| """Append bytes to the command FIFO.
|
||||
//|
|
||||
//| :param bytes b: The bytes to add
|
||||
//| :param bytes b: The bytes to add"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t _cc(mp_obj_t self, mp_obj_t b) {
|
||||
mp_buffer_info_t buffer_info;
|
||||
|
@ -91,14 +86,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(cc_obj, _cc);
|
|||
|
||||
//{
|
||||
|
||||
//| .. method:: AlphaFunc(func, ref)
|
||||
//|
|
||||
//| Set the alpha test function
|
||||
//| def AlphaFunc(self, func: int, ref: int) -> Any:
|
||||
//| """Set the alpha test function
|
||||
//|
|
||||
//| :param int func: specifies the test function, one of ``NEVER``, ``LESS``, ``LEQUAL``, ``GREATER``, ``GEQUAL``, ``EQUAL``, ``NOTEQUAL``, or ``ALWAYS``. Range 0-7. The initial value is ALWAYS(7)
|
||||
//| :param int ref: specifies the reference value for the alpha test. Range 0-255. The initial value is 0
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -109,14 +104,14 @@ STATIC mp_obj_t _alphafunc(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(alphafunc_obj, _alphafunc);
|
||||
|
||||
//| .. method:: Begin(prim)
|
||||
//|
|
||||
//| Begin drawing a graphics primitive
|
||||
//| def Begin(self, prim: int) -> Any:
|
||||
//| """Begin drawing a graphics primitive
|
||||
//|
|
||||
//| :param int prim: graphics primitive.
|
||||
//|
|
||||
//| Valid primitives are ``BITMAPS``, ``POINTS``, ``LINES``, ``LINE_STRIP``, ``EDGE_STRIP_R``, ``EDGE_STRIP_L``, ``EDGE_STRIP_A``, ``EDGE_STRIP_B`` and ``RECTS``.
|
||||
//|
|
||||
//| 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);
|
||||
|
@ -125,11 +120,11 @@ STATIC mp_obj_t _begin(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(begin_obj, _begin);
|
||||
|
||||
//| .. method:: BitmapExtFormat(format)
|
||||
//| def BitmapExtFormat(self, format: int) -> Any:
|
||||
//| """Set the bitmap format
|
||||
//|
|
||||
//| Set the bitmap format
|
||||
//|
|
||||
//| :param int format: bitmap pixel format.
|
||||
//| :param int format: bitmap pixel format."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _bitmapextformat(mp_obj_t self, mp_obj_t a0) {
|
||||
|
@ -139,13 +134,13 @@ STATIC mp_obj_t _bitmapextformat(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bitmapextformat_obj, _bitmapextformat);
|
||||
|
||||
//| .. method:: BitmapHandle(handle)
|
||||
//|
|
||||
//| Set the bitmap handle
|
||||
//| def BitmapHandle(self, handle: int) -> Any:
|
||||
//| """Set the bitmap handle
|
||||
//|
|
||||
//| :param int handle: bitmap handle. Range 0-31. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -155,12 +150,12 @@ STATIC mp_obj_t _bitmaphandle(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bitmaphandle_obj, _bitmaphandle);
|
||||
|
||||
//| .. method:: BitmapLayoutH(linestride, height)
|
||||
//|
|
||||
//| Set the source bitmap memory format and layout for the current handle. high bits for large bitmaps
|
||||
//| def BitmapLayoutH(self, linestride: int, height: int) -> Any:
|
||||
//| """Set the source bitmap memory format and layout for the current handle. high bits for large bitmaps
|
||||
//|
|
||||
//| :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
|
||||
//| :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) {
|
||||
|
@ -171,13 +166,13 @@ STATIC mp_obj_t _bitmaplayouth(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(bitmaplayouth_obj, _bitmaplayouth);
|
||||
|
||||
//| .. method:: BitmapLayout(format, linestride, height)
|
||||
//|
|
||||
//| Set the source bitmap memory format and layout for the current handle
|
||||
//| def BitmapLayout(self, format: int, linestride: int, height: int) -> Any:
|
||||
//| """Set the source bitmap memory format and layout for the current handle
|
||||
//|
|
||||
//| :param int format: bitmap pixel format, or GLFORMAT to use BITMAP_EXT_FORMAT instead. Range 0-31
|
||||
//| :param int linestride: bitmap line stride, in bytes. Range 0-1023
|
||||
//| :param int height: bitmap height, in lines. Range 0-511
|
||||
//| :param int height: bitmap height, in lines. Range 0-511"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _bitmaplayout(size_t n_args, const mp_obj_t *args) {
|
||||
|
@ -189,12 +184,12 @@ STATIC mp_obj_t _bitmaplayout(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmaplayout_obj, 4, 4, _bitmaplayout);
|
||||
|
||||
//| .. method:: BitmapSizeH(width, height)
|
||||
//|
|
||||
//| Set the screen drawing of bitmaps for the current handle. high bits for large bitmaps
|
||||
//| def BitmapSizeH(self, width: int, height: int) -> Any:
|
||||
//| """Set the screen drawing of bitmaps for the current handle. high bits for large bitmaps
|
||||
//|
|
||||
//| :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
|
||||
//| :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) {
|
||||
|
@ -205,15 +200,15 @@ STATIC mp_obj_t _bitmapsizeh(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(bitmapsizeh_obj, _bitmapsizeh);
|
||||
|
||||
//| .. method:: BitmapSize(filter, wrapx, wrapy, width, height)
|
||||
//|
|
||||
//| Set the screen drawing of bitmaps for the current handle
|
||||
//| def BitmapSize(self, filter: int, wrapx: int, wrapy: int, width: int, height: int) -> Any:
|
||||
//| """Set the screen drawing of bitmaps for the current handle
|
||||
//|
|
||||
//| :param int filter: bitmap filtering mode, one of ``NEAREST`` or ``BILINEAR``. Range 0-1
|
||||
//| :param int wrapx: bitmap :math:`x` wrap mode, one of ``REPEAT`` or ``BORDER``. Range 0-1
|
||||
//| :param int wrapy: bitmap :math:`y` wrap mode, one of ``REPEAT`` or ``BORDER``. Range 0-1
|
||||
//| :param int width: drawn bitmap width, in pixels. Range 0-511
|
||||
//| :param int height: drawn bitmap height, 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) {
|
||||
|
@ -227,11 +222,11 @@ STATIC mp_obj_t _bitmapsize(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmapsize_obj, 6, 6, _bitmapsize);
|
||||
|
||||
//| .. method:: BitmapSource(addr)
|
||||
//| def BitmapSource(self, addr: int) -> Any:
|
||||
//| """Set the source address for bitmap graphics
|
||||
//|
|
||||
//| Set the source address for bitmap graphics
|
||||
//|
|
||||
//| :param int addr: Bitmap start address, pixel-aligned. May be in SRAM or flash. Range 0-16777215
|
||||
//| :param int addr: Bitmap start address, pixel-aligned. May be in SRAM or flash. Range 0-16777215"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _bitmapsource(mp_obj_t self, mp_obj_t a0) {
|
||||
|
@ -241,14 +236,14 @@ STATIC mp_obj_t _bitmapsource(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bitmapsource_obj, _bitmapsource);
|
||||
|
||||
//| .. method:: BitmapSwizzle(r, g, b, a)
|
||||
//|
|
||||
//| Set the source for the r,g,b and a channels of a bitmap
|
||||
//| def BitmapSwizzle(self, r: int, g: int, b: int, a: int) -> Any:
|
||||
//| """Set the source for the r,g,b and a channels of a bitmap
|
||||
//|
|
||||
//| :param int r: red component source channel. Range 0-7
|
||||
//| :param int g: green component source channel. Range 0-7
|
||||
//| :param int b: blue component source channel. Range 0-7
|
||||
//| :param int a: alpha 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) {
|
||||
|
@ -261,16 +256,16 @@ STATIC mp_obj_t _bitmapswizzle(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitmapswizzle_obj, 5, 5, _bitmapswizzle);
|
||||
|
||||
//| .. method:: BitmapTransformA(p, v)
|
||||
//|
|
||||
//| Set the :math:`a` component of the bitmap transform matrix
|
||||
//| def BitmapTransformA(self, p: Any, v: int) -> Any:
|
||||
//| """Set the :math:`a` component of the bitmap transform matrix
|
||||
//|
|
||||
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
|
||||
//| :param int v: The :math:`a` component of the bitmap transform matrix, in signed 8.8 or 1.15 bit fixed-point form. Range 0-131071. The initial value is 256
|
||||
//|
|
||||
//| The initial value is **p** = 0, **v** = 256. This represents the value 1.0.
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _bitmaptransforma(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
||||
|
@ -281,16 +276,16 @@ STATIC mp_obj_t _bitmaptransforma(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransforma_obj, _bitmaptransforma);
|
||||
|
||||
//| .. method:: BitmapTransformB(p, v)
|
||||
//|
|
||||
//| Set the :math:`b` component of the bitmap transform matrix
|
||||
//| def BitmapTransformB(self, p: Any, v: int) -> Any:
|
||||
//| """Set the :math:`b` component of the bitmap transform matrix
|
||||
//|
|
||||
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
|
||||
//| :param int v: The :math:`b` component of the bitmap transform matrix, in signed 8.8 or 1.15 bit fixed-point form. Range 0-131071. The initial value is 0
|
||||
//|
|
||||
//| The initial value is **p** = 0, **v** = 0. This represents the value 0.0.
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _bitmaptransformb(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
||||
|
@ -301,13 +296,13 @@ STATIC mp_obj_t _bitmaptransformb(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransformb_obj, _bitmaptransformb);
|
||||
|
||||
//| .. method:: BitmapTransformC(v)
|
||||
//|
|
||||
//| Set the :math:`c` component of the bitmap transform matrix
|
||||
//| def BitmapTransformC(self, v: int) -> Any:
|
||||
//| """Set the :math:`c` component of the bitmap transform matrix
|
||||
//|
|
||||
//| :param int v: The :math:`c` component of the bitmap transform matrix, in signed 15.8 bit fixed-point form. Range 0-16777215. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -317,16 +312,16 @@ STATIC mp_obj_t _bitmaptransformc(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bitmaptransformc_obj, _bitmaptransformc);
|
||||
|
||||
//| .. method:: BitmapTransformD(p, v)
|
||||
//|
|
||||
//| Set the :math:`d` component of the bitmap transform matrix
|
||||
//| def BitmapTransformD(self, p: Any, v: int) -> Any:
|
||||
//| """Set the :math:`d` component of the bitmap transform matrix
|
||||
//|
|
||||
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
|
||||
//| :param int v: The :math:`d` component of the bitmap transform matrix, in signed 8.8 or 1.15 bit fixed-point form. Range 0-131071. The initial value is 0
|
||||
//|
|
||||
//| The initial value is **p** = 0, **v** = 0. This represents the value 0.0.
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _bitmaptransformd(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
||||
|
@ -337,16 +332,16 @@ STATIC mp_obj_t _bitmaptransformd(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransformd_obj, _bitmaptransformd);
|
||||
|
||||
//| .. method:: BitmapTransformE(p, v)
|
||||
//|
|
||||
//| Set the :math:`e` component of the bitmap transform matrix
|
||||
//| def BitmapTransformE(self, p: Any, v: int) -> Any:
|
||||
//| """Set the :math:`e` component of the bitmap transform matrix
|
||||
//|
|
||||
//| :param int p: precision control: 0 is 8.8, 1 is 1.15. Range 0-1. The initial value is 0
|
||||
//| :param int v: The :math:`e` component of the bitmap transform matrix, in signed 8.8 or 1.15 bit fixed-point form. Range 0-131071. The initial value is 256
|
||||
//|
|
||||
//| The initial value is **p** = 0, **v** = 256. This represents the value 1.0.
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _bitmaptransforme(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
||||
|
@ -357,13 +352,13 @@ STATIC mp_obj_t _bitmaptransforme(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(bitmaptransforme_obj, _bitmaptransforme);
|
||||
|
||||
//| .. method:: BitmapTransformF(v)
|
||||
//|
|
||||
//| Set the :math:`f` component of the bitmap transform matrix
|
||||
//| def BitmapTransformF(self, v: int) -> Any:
|
||||
//| """Set the :math:`f` component of the bitmap transform matrix
|
||||
//|
|
||||
//| :param int v: The :math:`f` component of the bitmap transform matrix, in signed 15.8 bit fixed-point form. Range 0-16777215. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -373,14 +368,14 @@ STATIC mp_obj_t _bitmaptransformf(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bitmaptransformf_obj, _bitmaptransformf);
|
||||
|
||||
//| .. method:: BlendFunc(src, dst)
|
||||
//|
|
||||
//| Set pixel arithmetic
|
||||
//| def BlendFunc(self, src: int, dst: int) -> Any:
|
||||
//| """Set pixel arithmetic
|
||||
//|
|
||||
//| :param int src: specifies how the source blending factor is computed. One of ``ZERO``, ``ONE``, ``SRC_ALPHA``, ``DST_ALPHA``, ``ONE_MINUS_SRC_ALPHA`` or ``ONE_MINUS_DST_ALPHA``. Range 0-7. The initial value is SRC_ALPHA(2)
|
||||
//| :param int dst: specifies how the destination blending factor is computed, one of the same constants as **src**. Range 0-7. The initial value is ONE_MINUS_SRC_ALPHA(4)
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -391,11 +386,11 @@ STATIC mp_obj_t _blendfunc(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(blendfunc_obj, _blendfunc);
|
||||
|
||||
//| .. method:: Call(dest)
|
||||
//| def Call(self, dest: int) -> Any:
|
||||
//| """Execute a sequence of commands at another location in the display list
|
||||
//|
|
||||
//| Execute a sequence of commands at another location in the display list
|
||||
//|
|
||||
//| :param int dest: display list address. Range 0-65535
|
||||
//| :param int dest: display list address. Range 0-65535"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _call(mp_obj_t self, mp_obj_t a0) {
|
||||
|
@ -405,13 +400,13 @@ STATIC mp_obj_t _call(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(call_obj, _call);
|
||||
|
||||
//| .. method:: Cell(cell)
|
||||
//|
|
||||
//| Set the bitmap cell number for the vertex2f command
|
||||
//| def Cell(self, cell: int) -> Any:
|
||||
//| """Set the bitmap cell number for the vertex2f command
|
||||
//|
|
||||
//| :param int cell: bitmap cell number. Range 0-127. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -421,13 +416,13 @@ STATIC mp_obj_t _cell(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(cell_obj, _cell);
|
||||
|
||||
//| .. method:: ClearColorA(alpha)
|
||||
//|
|
||||
//| Set clear value for the alpha channel
|
||||
//| def ClearColorA(self, alpha: int) -> Any:
|
||||
//| """Set clear value for the alpha channel
|
||||
//|
|
||||
//| :param int alpha: alpha value used when the color buffer is cleared. Range 0-255. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -437,15 +432,15 @@ STATIC mp_obj_t _clearcolora(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(clearcolora_obj, _clearcolora);
|
||||
|
||||
//| .. method:: ClearColorRGB(red, green, blue)
|
||||
//|
|
||||
//| Set clear values for red, green and blue channels
|
||||
//| def ClearColorRGB(self, red: int, green: int, blue: int) -> Any:
|
||||
//| """Set clear values for red, green and blue channels
|
||||
//|
|
||||
//| :param int red: red value used when the color buffer is cleared. Range 0-255. The initial value is 0
|
||||
//| :param int green: green value used when the color buffer is cleared. Range 0-255. The initial value is 0
|
||||
//| :param int blue: blue value used when the color buffer is cleared. Range 0-255. The initial value is 0
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -457,13 +452,13 @@ STATIC mp_obj_t _clearcolorrgb(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(clearcolorrgb_obj, 4, 4, _clearcolorrgb);
|
||||
|
||||
//| .. method:: Clear(c, s, t)
|
||||
//|
|
||||
//| Clear buffers to preset values
|
||||
//| def Clear(self, c: int, s: int, t: int) -> Any:
|
||||
//| """Clear buffers to preset values
|
||||
//|
|
||||
//| :param int c: clear color buffer. Range 0-1
|
||||
//| :param int s: clear stencil buffer. Range 0-1
|
||||
//| :param int t: clear tag 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) {
|
||||
|
@ -475,13 +470,13 @@ STATIC mp_obj_t _clear(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(clear_obj, 1, 4, _clear);
|
||||
|
||||
//| .. method:: ClearStencil(s)
|
||||
//|
|
||||
//| Set clear value for the stencil buffer
|
||||
//| def ClearStencil(self, s: int) -> Any:
|
||||
//| """Set clear value for the stencil buffer
|
||||
//|
|
||||
//| :param int s: value used when the stencil buffer is cleared. Range 0-255. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -491,13 +486,12 @@ STATIC mp_obj_t _clearstencil(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(clearstencil_obj, _clearstencil);
|
||||
|
||||
//| .. method:: ClearTag(s)
|
||||
//|
|
||||
//| Set clear value for the tag buffer
|
||||
//| def ClearTag(self, s: int) -> Any:
|
||||
//| """Set clear value for the tag buffer
|
||||
//|
|
||||
//| :param int s: value used when the tag buffer is cleared. Range 0-255. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -507,13 +501,13 @@ STATIC mp_obj_t _cleartag(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(cleartag_obj, _cleartag);
|
||||
|
||||
//| .. method:: ColorA(alpha)
|
||||
//|
|
||||
//| Set the current color alpha
|
||||
//| def ColorA(self, alpha: int) -> Any:
|
||||
//| """Set the current color alpha
|
||||
//|
|
||||
//| :param int alpha: alpha for the current color. Range 0-255. The initial value is 255
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -523,16 +517,16 @@ STATIC mp_obj_t _colora(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(colora_obj, _colora);
|
||||
|
||||
//| .. method:: ColorMask(r, g, b, a)
|
||||
//|
|
||||
//| Enable and disable writing of frame buffer color components
|
||||
//| def ColorMask(self, r: int, g: int, b: int, a: int) -> Any:
|
||||
//| """Enable and disable writing of frame buffer color components
|
||||
//|
|
||||
//| :param int r: allow updates to the frame buffer red component. Range 0-1. The initial value is 1
|
||||
//| :param int g: allow updates to the frame buffer green component. Range 0-1. The initial value is 1
|
||||
//| :param int b: allow updates to the frame buffer blue component. Range 0-1. The initial value is 1
|
||||
//| :param int a: allow updates to the frame buffer alpha component. Range 0-1. The initial value is 1
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -545,15 +539,15 @@ STATIC mp_obj_t _colormask(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(colormask_obj, 5, 5, _colormask);
|
||||
|
||||
//| .. method:: ColorRGB(red, green, blue)
|
||||
//|
|
||||
//| Set the drawing color
|
||||
//| def ColorRGB(self, red: int, green: int, blue: int) -> Any:
|
||||
//| """Set the drawing color
|
||||
//|
|
||||
//| :param int red: red value for the current color. Range 0-255. The initial value is 255
|
||||
//| :param int green: green for the current color. Range 0-255. The initial value is 255
|
||||
//| :param int blue: blue for the current color. Range 0-255. The initial value is 255
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -565,9 +559,8 @@ STATIC mp_obj_t _colorrgb(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(colorrgb_obj, 4, 4, _colorrgb);
|
||||
|
||||
//| .. method:: Display()
|
||||
//|
|
||||
//| End the display list
|
||||
//| def Display(self, ) -> Any: ...
|
||||
//| """End the display list"""
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _display(mp_obj_t self) {
|
||||
|
@ -577,12 +570,12 @@ STATIC mp_obj_t _display(mp_obj_t self) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(display_obj, _display);
|
||||
|
||||
//| .. method:: End()
|
||||
//| def End(self, ) -> Any:
|
||||
//| """End drawing a graphics primitive
|
||||
//|
|
||||
//| End drawing a graphics primitive
|
||||
//| :meth:`Vertex2ii` and :meth:`Vertex2f` calls are ignored until the next :meth:`Begin`."""
|
||||
//| ...
|
||||
//|
|
||||
//| :meth:`Vertex2ii` and :meth:`Vertex2f` calls are ignored until the next :meth:`Begin`.
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _end(mp_obj_t self) {
|
||||
|
||||
|
@ -591,11 +584,11 @@ STATIC mp_obj_t _end(mp_obj_t self) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(end_obj, _end);
|
||||
|
||||
//| .. method:: Jump(dest)
|
||||
//| def Jump(self, dest: int) -> Any:
|
||||
//| """Execute commands at another location in the display list
|
||||
//|
|
||||
//| Execute commands at another location in the display list
|
||||
//|
|
||||
//| :param int dest: display list address. Range 0-65535
|
||||
//| :param int dest: display list address. Range 0-65535"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _jump(mp_obj_t self, mp_obj_t a0) {
|
||||
|
@ -605,13 +598,13 @@ STATIC mp_obj_t _jump(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(jump_obj, _jump);
|
||||
|
||||
//| .. method:: LineWidth(width)
|
||||
//|
|
||||
//| Set the width of rasterized lines
|
||||
//| def LineWidth(self, width: int) -> Any:
|
||||
//| """Set the width of rasterized lines
|
||||
//|
|
||||
//| :param int width: line width in :math:`1/16` pixel. Range 0-4095. The initial value is 16
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -621,11 +614,11 @@ STATIC mp_obj_t _linewidth(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(linewidth_obj, _linewidth);
|
||||
|
||||
//| .. method:: Macro(m)
|
||||
//| def Macro(self, m: int) -> Any:
|
||||
//| """Execute a single command from a macro register
|
||||
//|
|
||||
//| Execute a single command from a macro register
|
||||
//|
|
||||
//| :param int m: macro register to read. Range 0-1
|
||||
//| :param int m: macro register to read. Range 0-1"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _macro(mp_obj_t self, mp_obj_t a0) {
|
||||
|
@ -635,9 +628,9 @@ STATIC mp_obj_t _macro(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(macro_obj, _macro);
|
||||
|
||||
//| .. method:: Nop()
|
||||
//|
|
||||
//| No operation
|
||||
//| def Nop(self, ) -> Any:
|
||||
//| """No operation"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _nop(mp_obj_t self) {
|
||||
|
@ -647,13 +640,13 @@ STATIC mp_obj_t _nop(mp_obj_t self) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(nop_obj, _nop);
|
||||
|
||||
//| .. method:: PaletteSource(addr)
|
||||
//|
|
||||
//| Set the base address of the palette
|
||||
//| def PaletteSource(self, addr: int) -> Any:
|
||||
//| """Set the base address of the palette
|
||||
//|
|
||||
//| :param int addr: Address in graphics SRAM, 2-byte aligned. Range 0-4194303. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -663,13 +656,13 @@ STATIC mp_obj_t _palettesource(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(palettesource_obj, _palettesource);
|
||||
|
||||
//| .. method:: PointSize(size)
|
||||
//|
|
||||
//| Set the radius of rasterized points
|
||||
//| def PointSize(self, size: int) -> Any:
|
||||
//| """Set the radius of rasterized points
|
||||
//|
|
||||
//| :param int size: point radius in :math:`1/16` pixel. Range 0-8191. The initial value is 16
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -679,9 +672,9 @@ STATIC mp_obj_t _pointsize(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pointsize_obj, _pointsize);
|
||||
|
||||
//| .. method:: RestoreContext()
|
||||
//|
|
||||
//| Restore the current graphics context from the context stack
|
||||
//| def RestoreContext(self, ) -> Any:
|
||||
//| """Restore the current graphics context from the context stack"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _restorecontext(mp_obj_t self) {
|
||||
|
@ -691,9 +684,9 @@ STATIC mp_obj_t _restorecontext(mp_obj_t self) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(restorecontext_obj, _restorecontext);
|
||||
|
||||
//| .. method:: Return()
|
||||
//|
|
||||
//| Return from a previous call command
|
||||
//| def Return(self, ) -> Any:
|
||||
//| """Return from a previous call command"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _return(mp_obj_t self) {
|
||||
|
@ -703,9 +696,9 @@ STATIC mp_obj_t _return(mp_obj_t self) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(return_obj, _return);
|
||||
|
||||
//| .. method:: SaveContext()
|
||||
//|
|
||||
//| Push the current graphics context on the context stack
|
||||
//| def SaveContext(self, ) -> Any:
|
||||
//| """Push the current graphics context on the context stack"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _savecontext(mp_obj_t self) {
|
||||
|
@ -715,14 +708,14 @@ STATIC mp_obj_t _savecontext(mp_obj_t self) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(savecontext_obj, _savecontext);
|
||||
|
||||
//| .. method:: ScissorSize(width, height)
|
||||
//|
|
||||
//| Set the size of the scissor clip rectangle
|
||||
//| def ScissorSize(self, width: int, height: int) -> Any:
|
||||
//| """Set the size of the scissor clip rectangle
|
||||
//|
|
||||
//| :param int width: The width of the scissor clip rectangle, in pixels. Range 0-4095. The initial value is hsize
|
||||
//| :param int height: The height of the scissor clip rectangle, in pixels. Range 0-4095. The initial value is 2048
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -733,14 +726,14 @@ STATIC mp_obj_t _scissorsize(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(scissorsize_obj, _scissorsize);
|
||||
|
||||
//| .. method:: ScissorXY(x, y)
|
||||
//|
|
||||
//| Set the top left corner of the scissor clip rectangle
|
||||
//| def ScissorXY(self, x: int, y: int) -> Any:
|
||||
//| """Set the top left corner of the scissor clip rectangle
|
||||
//|
|
||||
//| :param int x: The :math:`x` coordinate of the scissor clip rectangle, in pixels. Range 0-2047. The initial value is 0
|
||||
//| :param int y: The :math:`y` coordinate of the scissor clip rectangle, in pixels. Range 0-2047. The initial value is 0
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -751,15 +744,15 @@ STATIC mp_obj_t _scissorxy(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(scissorxy_obj, _scissorxy);
|
||||
|
||||
//| .. method:: StencilFunc(func, ref, mask)
|
||||
//|
|
||||
//| Set function and reference value for stencil testing
|
||||
//| def StencilFunc(self, func: int, ref: int, mask: int) -> Any:
|
||||
//| """Set function and reference value for stencil testing
|
||||
//|
|
||||
//| :param int func: specifies the test function, one of ``NEVER``, ``LESS``, ``LEQUAL``, ``GREATER``, ``GEQUAL``, ``EQUAL``, ``NOTEQUAL``, or ``ALWAYS``. Range 0-7. The initial value is ALWAYS(7)
|
||||
//| :param int ref: specifies the reference value for the stencil test. Range 0-255. The initial value is 0
|
||||
//| :param int mask: specifies a mask that is ANDed with the reference value and the stored stencil value. Range 0-255. The initial value is 255
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -771,13 +764,13 @@ STATIC mp_obj_t _stencilfunc(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stencilfunc_obj, 4, 4, _stencilfunc);
|
||||
|
||||
//| .. method:: StencilMask(mask)
|
||||
//|
|
||||
//| Control the writing of individual bits in the stencil planes
|
||||
//| def StencilMask(self, mask: int) -> Any:
|
||||
//| """Control the writing of individual bits in the stencil planes
|
||||
//|
|
||||
//| :param int mask: the mask used to enable writing stencil bits. Range 0-255. The initial value is 255
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -787,14 +780,14 @@ STATIC mp_obj_t _stencilmask(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(stencilmask_obj, _stencilmask);
|
||||
|
||||
//| .. method:: StencilOp(sfail, spass)
|
||||
//|
|
||||
//| Set stencil test actions
|
||||
//| def StencilOp(self, sfail: int, spass: int) -> Any:
|
||||
//| """Set stencil test actions
|
||||
//|
|
||||
//| :param int sfail: specifies the action to take when the stencil test fails, one of ``KEEP``, ``ZERO``, ``REPLACE``, ``INCR``, ``INCR_WRAP``, ``DECR``, ``DECR_WRAP``, and ``INVERT``. Range 0-7. The initial value is KEEP(1)
|
||||
//| :param int spass: specifies the action to take when the stencil test passes, one of the same constants as **sfail**. Range 0-7. The initial value is KEEP(1)
|
||||
//|
|
||||
//| These values are part of the graphics context and are saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -805,13 +798,13 @@ STATIC mp_obj_t _stencilop(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(stencilop_obj, _stencilop);
|
||||
|
||||
//| .. method:: TagMask(mask)
|
||||
//|
|
||||
//| Control the writing of the tag buffer
|
||||
//| def TagMask(self, mask: int) -> Any:
|
||||
//| """Control the writing of the tag buffer
|
||||
//|
|
||||
//| :param int mask: allow updates to the tag buffer. Range 0-1. The initial value is 1
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -821,13 +814,13 @@ STATIC mp_obj_t _tagmask(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(tagmask_obj, _tagmask);
|
||||
|
||||
//| .. method:: Tag(s)
|
||||
//|
|
||||
//| Set the current tag value
|
||||
//| def Tag(self, s: int) -> Any:
|
||||
//| """Set the current tag value
|
||||
//|
|
||||
//| :param int s: tag value. Range 0-255. The initial value is 255
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -837,13 +830,13 @@ STATIC mp_obj_t _tag(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(tag_obj, _tag);
|
||||
|
||||
//| .. method:: VertexTranslateX(x)
|
||||
//|
|
||||
//| Set the vertex transformation's x translation component
|
||||
//| def VertexTranslateX(self, x: int) -> Any:
|
||||
//| """Set the vertex transformation's x translation component
|
||||
//|
|
||||
//| :param int x: signed x-coordinate in :math:`1/16` pixel. Range 0-131071. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| 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) {
|
||||
|
@ -853,13 +846,13 @@ STATIC mp_obj_t _vertextranslatex(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatex_obj, _vertextranslatex);
|
||||
|
||||
//| .. method:: VertexTranslateY(y)
|
||||
//|
|
||||
//| Set the vertex transformation's y translation component
|
||||
//| def VertexTranslateY(self, y: int) -> Any:
|
||||
//| """Set the vertex transformation's y translation component
|
||||
//|
|
||||
//| :param int y: signed y-coordinate in :math:`1/16` pixel. Range 0-131071. The initial value is 0
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
|
||||
|
@ -870,13 +863,13 @@ STATIC mp_obj_t _vertextranslatey(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertextranslatey_obj, _vertextranslatey);
|
||||
|
||||
//| .. method:: VertexFormat(frac)
|
||||
//|
|
||||
//| Set the precision of vertex2f coordinates
|
||||
//| def VertexFormat(self, frac: int) -> Any:
|
||||
//| """Set the precision of vertex2f coordinates
|
||||
//|
|
||||
//| :param int frac: Number of fractional bits in X,Y coordinates, 0-4. Range 0-7. The initial value is 4
|
||||
//|
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`.
|
||||
//| This value is part of the graphics context and is saved and restored by :meth:`SaveContext` and :meth:`RestoreContext`."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _vertexformat(mp_obj_t self, mp_obj_t a0) {
|
||||
|
@ -886,15 +879,15 @@ STATIC mp_obj_t _vertexformat(mp_obj_t self, mp_obj_t a0) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(vertexformat_obj, _vertexformat);
|
||||
|
||||
//| .. method:: Vertex2ii(x, y, handle, cell)
|
||||
//|
|
||||
//| :param int x: x-coordinate in pixels. Range 0-511
|
||||
//| def Vertex2ii(self, x: int, y: int, handle: int, cell: int) -> Any:
|
||||
//| """:param int x: x-coordinate in pixels. Range 0-511
|
||||
//| :param int y: y-coordinate in pixels. Range 0-511
|
||||
//| :param int handle: bitmap handle. Range 0-31
|
||||
//| :param int cell: cell number. Range 0-127
|
||||
//|
|
||||
//| This method is an alternative to :meth:`Vertex2f`.
|
||||
//|
|
||||
//| 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]);
|
||||
|
@ -961,12 +954,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(vertex2ii_obj, 3, 5, _vertex2ii);
|
|||
|
||||
// Hand-written functions {
|
||||
|
||||
//| .. method:: Vertex2f(b)
|
||||
//|
|
||||
//| Draw a point.
|
||||
//| def Vertex2f(self, b: Any) -> Any:
|
||||
//| """Draw a point.
|
||||
//|
|
||||
//| :param float x: pixel x-coordinate
|
||||
//| :param float y: pixel y-coordinate
|
||||
//| :param float y: pixel y-coordinate"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t _vertex2f(mp_obj_t self, mp_obj_t a0, mp_obj_t a1) {
|
||||
mp_float_t x = mp_obj_get_float(a0);
|
||||
|
@ -980,14 +973,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(vertex2f_obj, _vertex2f);
|
|||
#define ADD_X(self, x) \
|
||||
common_hal__eve_add(EVEHAL(self), sizeof(x), &(x));
|
||||
|
||||
//| .. method:: cmd0(n)
|
||||
//|
|
||||
//| Append the command word n to the FIFO
|
||||
//| def cmd0(self, n: int) -> Any:
|
||||
//| """Append the command word n to the FIFO
|
||||
//|
|
||||
//| :param int n: The command code
|
||||
//|
|
||||
//| This method is used by the ``eve`` module to efficiently add
|
||||
//| commands to the FIFO.
|
||||
//| commands to the FIFO."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t _cmd0(mp_obj_t self, mp_obj_t n) {
|
||||
|
@ -997,9 +990,8 @@ STATIC mp_obj_t _cmd0(mp_obj_t self, mp_obj_t n) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(cmd0_obj, _cmd0);
|
||||
|
||||
//| .. method:: cmd(n, fmt, args)
|
||||
//|
|
||||
//| Append a command packet to the FIFO.
|
||||
//| def cmd(self, n: int, fmt: str, args: tuple) -> Any:
|
||||
//| """Append a command packet to the FIFO.
|
||||
//|
|
||||
//| :param int n: The command code
|
||||
//| :param str fmt: The command format `struct` layout
|
||||
|
@ -1008,7 +1000,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(cmd0_obj, _cmd0);
|
|||
//| Supported format codes: h, H, i, I.
|
||||
//|
|
||||
//| This method is used by the ``eve`` module to efficiently add
|
||||
//| commands to the FIFO.
|
||||
//| commands to the FIFO."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t _cmd(size_t n_args, const mp_obj_t *args) {
|
||||
mp_obj_t self = args[0];
|
||||
|
|
|
@ -34,33 +34,28 @@
|
|||
#include "shared-module/_pew/PewPew.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
|
||||
//| .. currentmodule:: _pew
|
||||
//| class PewPew:
|
||||
//| """This is an internal module to be used by the ``pew.py`` library from
|
||||
//| https://github.com/pewpew-game/pew-pewpew-standalone-10.x to handle the
|
||||
//| LED matrix display and buttons on the ``pewpew10`` board.
|
||||
//|
|
||||
//| :class:`PewPew` -- LED matrix and button driver
|
||||
//| ===============================================
|
||||
//| Usage::
|
||||
//|
|
||||
//| This is an internal module to be used by the ``pew.py`` library from
|
||||
//| https://github.com/pewpew-game/pew-pewpew-standalone-10.x to handle the
|
||||
//| LED matrix display and buttons on the ``pewpew10`` board.
|
||||
//|
|
||||
//| Usage::
|
||||
//|
|
||||
//| This singleton class is instantiated by the ``pew`` library, and
|
||||
//| used internally by it. All user-visible interactions are done through
|
||||
//| that library.
|
||||
//| This singleton class is instantiated by the ``pew`` library, and
|
||||
//| used internally by it. All user-visible interactions are done through
|
||||
//| that library."""
|
||||
//|
|
||||
|
||||
//| .. class:: PewPew(buffer, rows, cols, buttons)
|
||||
//| def __init__(self, buffer: Any, rows: Any, cols: Any, buttons: Any):
|
||||
//| """Initializes matrix scanning routines.
|
||||
//|
|
||||
//| Initializes matrix scanning routines.
|
||||
//|
|
||||
//| The ``buffer`` is a 64 byte long ``bytearray`` that stores what should
|
||||
//| be displayed on the matrix. ``rows`` and ``cols`` are both lists of
|
||||
//| eight ``DigitalInputOutput`` objects that are connected to the matrix
|
||||
//| rows and columns. ``buttons`` is a ``DigitalInputOutput`` object that
|
||||
//| is connected to the common side of all buttons (the other sides of the
|
||||
//| buttons are connected to rows of the matrix).
|
||||
//| The ``buffer`` is a 64 byte long ``bytearray`` that stores what should
|
||||
//| be displayed on the matrix. ``rows`` and ``cols`` are both lists of
|
||||
//| eight ``DigitalInputOutput`` objects that are connected to the matrix
|
||||
//| rows and columns. ``buttons`` is a ``DigitalInputOutput`` object that
|
||||
//| is connected to the common side of all buttons (the other sides of the
|
||||
//| 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,
|
||||
const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
|
|
@ -41,17 +41,7 @@ STATIC mp_obj_t get_pressed(void) {
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_pressed_obj, get_pressed);
|
||||
|
||||
|
||||
//| :mod:`_pew` --- LED matrix driver
|
||||
//| ==================================
|
||||
//|
|
||||
//| .. module:: _pew
|
||||
//| :synopsis: LED matrix driver
|
||||
//| :platform: SAMD21
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| PewPew
|
||||
//| """LED matrix driver"""
|
||||
//|
|
||||
STATIC const mp_rom_map_elem_t pew_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__pew) },
|
||||
|
|
|
@ -44,31 +44,32 @@ extern const int32_t colorwheel(float pos);
|
|||
|
||||
static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t* parsed);
|
||||
|
||||
//| .. currentmodule:: _pixelbuf
|
||||
//| class PixelBuf:
|
||||
//| """A fast RGB[W] pixel buffer for LED and similar devices."""
|
||||
//|
|
||||
//| :class:`PixelBuf` -- A fast RGB[W] pixel buffer for LED and similar devices
|
||||
//| ===========================================================================
|
||||
//| def __init__(self, size: int, *, byteorder: str = "BGR", brightness: float = 0, auto_write: bool = False, header: bytes = b"", trailer: bytes = b""):
|
||||
//| """Create a PixelBuf object of the specified size, byteorder, and bits per pixel.
|
||||
//|
|
||||
//| :class:`~_pixelbuf.PixelBuf` implements an RGB[W] bytearray abstraction.
|
||||
//| When brightness is less than 1.0, a second buffer will be used to store the color values
|
||||
//| before they are adjusted for brightness.
|
||||
//|
|
||||
//| .. class:: PixelBuf(size, *, byteorder="BGR", brightness=0, auto_write=False, header=b"", trailer=b"")
|
||||
//| When ``P`` (pwm duration) is present as the 4th character of the byteorder
|
||||
//| string, the 4th value in the tuple/list for a pixel is the individual pixel
|
||||
//| brightness (0.0-1.0) and will enable a Dotstar compatible 1st byte in the
|
||||
//| output buffer (``buf``).
|
||||
//|
|
||||
//| Create a PixelBuf object of the specified size, byteorder, and bits per pixel.
|
||||
//| When ``P`` (pwm duration) is present as the first character of the byteorder
|
||||
//| string, the 4th value in the tuple/list for a pixel is the individual pixel
|
||||
//| brightness (0.0-1.0) and will enable a Dotstar compatible 1st byte in the
|
||||
//| output buffer (``buf``).
|
||||
//|
|
||||
//| When brightness is less than 1.0, a second buffer will be used to store the color values
|
||||
//| before they are adjusted for brightness.
|
||||
//|
|
||||
//| When ``P`` (pwm duration) is present as the first character of the byteorder
|
||||
//| string, the 4th value in the tuple/list for a pixel is the individual pixel
|
||||
//| brightness (0.0-1.0) and will enable a Dotstar compatible 1st byte in the
|
||||
//| output buffer (``buf``).
|
||||
//|
|
||||
//| :param ~int size: Number of pixels
|
||||
//| :param ~str byteorder: Byte order string (such as "BGR" or "BGRP")
|
||||
//| :param ~float brightness: Brightness (0 to 1.0, default 1.0)
|
||||
//| :param ~bool auto_write: Whether to automatically write pixels (Default False)
|
||||
//| :param bytes header: Sequence of bytes to always send before pixel values.
|
||||
//| :param bytes trailer: Sequence of bytes to always send after pixel values.
|
||||
//| :param ~int size: Number of pixels
|
||||
//| :param ~str byteorder: Byte order string (such as "BGR" or "PBGR")
|
||||
//| :param ~float brightness: Brightness (0 to 1.0, default 1.0)
|
||||
//| :param ~bool auto_write: Whether to automatically write pixels (Default False)
|
||||
//| :param bytes header: Sequence of bytes to always send before pixel values.
|
||||
//| :param bytes 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, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, MP_OBJ_FUN_ARGS_MAX, true);
|
||||
|
@ -156,9 +157,8 @@ static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t
|
|||
}
|
||||
}
|
||||
|
||||
//| .. attribute:: bpp
|
||||
//|
|
||||
//| The number of bytes per pixel in the buffer (read-only)
|
||||
//| bpp: Any = ...
|
||||
//| """The number of bytes per pixel in the buffer (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t pixelbuf_pixelbuf_obj_get_bpp(mp_obj_t self_in) {
|
||||
return MP_OBJ_NEW_SMALL_INT(common_hal__pixelbuf_pixelbuf_get_bpp(self_in));
|
||||
|
@ -173,12 +173,11 @@ const mp_obj_property_t pixelbuf_pixelbuf_bpp_obj = {
|
|||
};
|
||||
|
||||
|
||||
//| .. attribute:: brightness
|
||||
//|
|
||||
//| Float value between 0 and 1. Output brightness.
|
||||
//| brightness: Any = ...
|
||||
//| """Float value between 0 and 1. Output brightness.
|
||||
//|
|
||||
//| When brightness is less than 1.0, a second buffer will be used to store the color values
|
||||
//| before they are adjusted for brightness.
|
||||
//| before they are adjusted for brightness."""
|
||||
//|
|
||||
STATIC mp_obj_t pixelbuf_pixelbuf_obj_get_brightness(mp_obj_t self_in) {
|
||||
return mp_obj_new_float(common_hal__pixelbuf_pixelbuf_get_brightness(self_in));
|
||||
|
@ -205,9 +204,8 @@ const mp_obj_property_t pixelbuf_pixelbuf_brightness_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: auto_write
|
||||
//|
|
||||
//| Whether to automatically write the pixels after each update.
|
||||
//| auto_write: Any = ...
|
||||
//| """Whether to automatically write the pixels after each update."""
|
||||
//|
|
||||
STATIC mp_obj_t pixelbuf_pixelbuf_obj_get_auto_write(mp_obj_t self_in) {
|
||||
return mp_obj_new_bool(common_hal__pixelbuf_pixelbuf_get_auto_write(self_in));
|
||||
|
@ -228,9 +226,8 @@ const mp_obj_property_t pixelbuf_pixelbuf_auto_write_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: byteorder
|
||||
//|
|
||||
//| byteorder string for the buffer (read-only)
|
||||
//| byteorder: Any = ...
|
||||
//| """byteorder string for the buffer (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t pixelbuf_pixelbuf_obj_get_byteorder(mp_obj_t self_in) {
|
||||
return common_hal__pixelbuf_pixelbuf_get_byteorder_string(self_in);
|
||||
|
@ -253,10 +250,10 @@ STATIC mp_obj_t pixelbuf_pixelbuf_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: show()
|
||||
//|
|
||||
//| Transmits the color data to the pixels so that they are shown. This is done automatically
|
||||
//| when `auto_write` is True.
|
||||
//| def show(self, ) -> Any:
|
||||
//| """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) {
|
||||
|
@ -265,9 +262,9 @@ STATIC mp_obj_t pixelbuf_pixelbuf_show(mp_obj_t self_in) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_show_obj, pixelbuf_pixelbuf_show);
|
||||
|
||||
//| .. method:: fill(color)
|
||||
//|
|
||||
//| Fills the given pixelbuf with the given color.
|
||||
//| def fill(color: Any) -> Any:
|
||||
//| """Fills the given pixelbuf with the given color."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t value) {
|
||||
|
@ -277,17 +274,16 @@ STATIC mp_obj_t pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t value) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pixelbuf_pixelbuf_fill_obj, pixelbuf_pixelbuf_fill);
|
||||
|
||||
|
||||
//| .. method:: __getitem__(index)
|
||||
//| def __getitem__(self, index: Any) -> Any:
|
||||
//| """Returns the pixel value at the given index as a tuple of (Red, Green, Blue[, White]) values
|
||||
//| between 0 and 255."""
|
||||
//| ...
|
||||
//|
|
||||
//| Returns the pixel value at the given index as a tuple of (Red, Green, Blue[, White]) values
|
||||
//| between 0 and 255.
|
||||
//|
|
||||
//| .. method:: __setitem__(index, value)
|
||||
//|
|
||||
//| Sets the pixel value at the given index. Value can either be a tuple of (Red, Green, Blue
|
||||
//| [, White]) values between 0 and 255 or an integer where the red, green and blue values are
|
||||
//| packed into the lower three bytes (0xRRGGBB).
|
||||
//| def __setitem__(self, index: Any, value: Any) -> Any:
|
||||
//| """Sets the pixel value at the given index. Value can either be a tuple of (Red, Green, Blue
|
||||
//| [, White]) values between 0 and 255 or an integer where the red, green and blue values are
|
||||
//| packed into the lower three bytes (0xRRGGBB)."""
|
||||
//| ...
|
||||
//|
|
||||
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) {
|
||||
|
|
|
@ -33,33 +33,22 @@
|
|||
#include "shared-bindings/_pixelbuf/PixelBuf.h"
|
||||
|
||||
|
||||
//| :mod:`_pixelbuf` --- Fast RGB(W) pixel buffer and helpers
|
||||
//| ===========================================================
|
||||
|
||||
//| .. module:: _pixelbuf
|
||||
//| :synopsis: A fast RGB(W) pixel buffer library for like NeoPixel and DotStar.
|
||||
//| """A fast RGB(W) pixel buffer library for like NeoPixel and DotStar.
|
||||
//|
|
||||
//| The `_pixelbuf` module provides the :py:class:`PixelBuf` class to accelerate
|
||||
//| RGB(W) strip/matrix manipulation, such as DotStar and Neopixel.
|
||||
//|
|
||||
//| Byteorders are configured with strings, such as "RGB" or "RGBD".
|
||||
//| TODO: Pull in docs from pypixelbuf.
|
||||
//| Byteorders are configured with strings, such as "RGB" or "RGBD"."""
|
||||
// TODO: Pull in docs from pypixelbuf.
|
||||
|
||||
//| Libraries
|
||||
//| def colorwheel(n: int) -> Any:
|
||||
//| """C implementation of the common wheel() function found in many examples.
|
||||
//| Returns the colorwheel RGB value as an integer value for n (usable in :py:class:`PixelBuf`, neopixel, and dotstar)."""
|
||||
//| ...
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//| def wheel(n: Any) -> Any:
|
||||
//| """Use of wheel() is deprecated. Please use colorwheel()."""
|
||||
//|
|
||||
//| PixelBuf
|
||||
|
||||
|
||||
//| .. function:: colorwheel(n)
|
||||
//|
|
||||
//| C implementation of the common wheel() function found in many examples.
|
||||
//| Returns the colorwheel RGB value as an integer value for n (usable in :py:class:`PixelBuf`, neopixel, and dotstar).
|
||||
//|
|
||||
//| .. function:: wheel(n)
|
||||
//| Use of wheel() is deprecated. Please use colorwheel().
|
||||
|
||||
STATIC mp_obj_t pixelbuf_colorwheel(mp_obj_t n) {
|
||||
return MP_OBJ_NEW_SMALL_INT(colorwheel(MP_OBJ_IS_SMALL_INT(n) ? MP_OBJ_SMALL_INT_VALUE(n) : mp_obj_float_get(n)));
|
||||
|
|
|
@ -30,25 +30,23 @@
|
|||
#include "Layer.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: _stage
|
||||
//| class Layer:
|
||||
//| """Keep information about a single layer of graphics"""
|
||||
//|
|
||||
//| :class:`Layer` -- Keep information about a single layer of graphics
|
||||
//| ===================================================================
|
||||
//| def __init__(self, width: int, height: int, graphic: bytearray, palette: bytearray, grid: bytearray):
|
||||
//| """Keep internal information about a layer of graphics (either a
|
||||
//| ``Grid`` or a ``Sprite``) in a format suitable for fast rendering
|
||||
//| with the ``render()`` function.
|
||||
//|
|
||||
//| .. class:: Layer(width, height, graphic, palette, [grid])
|
||||
//| :param int width: The width of the grid in tiles, or 1 for sprites.
|
||||
//| :param int height: The height of the grid in tiles, or 1 for sprites.
|
||||
//| :param bytearray graphic: The graphic data of the tiles.
|
||||
//| :param bytearray palette: The color palette to be used.
|
||||
//| :param bytearray grid: The contents of the grid map.
|
||||
//|
|
||||
//| Keep internal information about a layer of graphics (either a
|
||||
//| ``Grid`` or a ``Sprite``) in a format suitable for fast rendering
|
||||
//| with the ``render()`` function.
|
||||
//|
|
||||
//| :param int width: The width of the grid in tiles, or 1 for sprites.
|
||||
//| :param int height: The height of the grid in tiles, or 1 for sprites.
|
||||
//| :param bytearray graphic: The graphic data of the tiles.
|
||||
//| :param bytearray palette: The color palette to be used.
|
||||
//| :param bytearray grid: The contents of the grid map.
|
||||
//|
|
||||
//| This class is intended for internal use in the ``stage`` library and
|
||||
//| it shouldn't be used on its own.
|
||||
//| 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,
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
|
@ -90,9 +88,9 @@ STATIC mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: move(x, y)
|
||||
//|
|
||||
//| Set the offset of the layer to the specified values.
|
||||
//| def move(self, x: Any, y: Any) -> Any:
|
||||
//| """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);
|
||||
|
@ -102,10 +100,10 @@ STATIC mp_obj_t layer_move(mp_obj_t self_in, mp_obj_t x_in, mp_obj_t y_in) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(layer_move_obj, layer_move);
|
||||
|
||||
//| .. method:: frame(frame, rotation)
|
||||
//|
|
||||
//| Set the animation frame of the sprite, and optionally rotation its
|
||||
//| graphic.
|
||||
//| def frame(self, frame: Any, rotation: Any) -> Any:
|
||||
//| """Set the animation frame of the sprite, and optionally rotation its
|
||||
//| graphic."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t layer_frame(mp_obj_t self_in, mp_obj_t frame_in,
|
||||
mp_obj_t rotation_in) {
|
||||
|
|
|
@ -30,25 +30,23 @@
|
|||
#include "Text.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: _stage
|
||||
//| class Text:
|
||||
//| """Keep information about a single grid of text"""
|
||||
//|
|
||||
//| :class:`Text` -- Keep information about a single text of text
|
||||
//| ==============================================================
|
||||
//| def __init__(self, width: int, height: int, font: bytearray, palette: bytearray, chars: bytearray):
|
||||
//| """Keep internal information about a grid of text
|
||||
//| in a format suitable for fast rendering
|
||||
//| with the ``render()`` function.
|
||||
//|
|
||||
//| .. class:: Text(width, height, font, palette, chars)
|
||||
//| :param int width: The width of the grid in tiles, or 1 for sprites.
|
||||
//| :param int height: The height of the grid in tiles, or 1 for sprites.
|
||||
//| :param bytearray font: The font data of the characters.
|
||||
//| :param bytearray palette: The color palette to be used.
|
||||
//| :param bytearray chars: The contents of the character grid.
|
||||
//|
|
||||
//| Keep internal information about a text of text
|
||||
//| in a format suitable for fast rendering
|
||||
//| with the ``render()`` function.
|
||||
//|
|
||||
//| :param int width: The width of the grid in tiles, or 1 for sprites.
|
||||
//| :param int height: The height of the grid in tiles, or 1 for sprites.
|
||||
//| :param bytearray font: The font data of the characters.
|
||||
//| :param bytearray palette: The color palette to be used.
|
||||
//| :param bytearray chars: The contents of the character grid.
|
||||
//|
|
||||
//| This class is intended for internal use in the ``stage`` library and
|
||||
//| it shouldn't be used on its own.
|
||||
//| 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,
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
|
@ -84,9 +82,9 @@ STATIC mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: move(x, y)
|
||||
//|
|
||||
//| Set the offset of the text to the specified values.
|
||||
//| def move(self, x: Any, y: Any) -> Any:
|
||||
//| """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);
|
||||
|
|
|
@ -34,26 +34,13 @@
|
|||
#include "Layer.h"
|
||||
#include "Text.h"
|
||||
|
||||
//| :mod:`_stage` --- C-level helpers for animation of sprites on a stage
|
||||
//| =====================================================================
|
||||
//|
|
||||
//| .. module:: _stage
|
||||
//| :synopsis: C-level helpers for animation of sprites on a stage
|
||||
//| :platform: SAMD21
|
||||
//| """C-level helpers for animation of sprites on a stage
|
||||
//|
|
||||
//| The `_stage` module contains native code to speed-up the ```stage`` Library
|
||||
//| <https://github.com/python-ugame/circuitpython-stage>`_.
|
||||
//| Libraries
|
||||
//| <https://github.com/python-ugame/circuitpython-stage>`_."""
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Layer
|
||||
//| Text
|
||||
//|
|
||||
//| .. function:: render(x0, y0, x1, y1, layers, buffer, display[, scale[, background]])
|
||||
//|
|
||||
//| Render and send to the display a fragment of the screen.
|
||||
//| def render(x0: int, y0: int, x1: int, y1: int, layers: list, buffer: bytearray, display: displayio.Display, scale: int, background: int) -> Any:
|
||||
//| """Render and send to the display a fragment of the screen.
|
||||
//|
|
||||
//| :param int x0: Left edge of the fragment.
|
||||
//| :param int y0: Top edge of the fragment.
|
||||
|
@ -70,7 +57,8 @@
|
|||
//| valid.
|
||||
//|
|
||||
//| This function is intended for internal use in the ``stage`` library
|
||||
//| and all the necessary checks are performed there.
|
||||
//| 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]);
|
||||
|
|
|
@ -31,23 +31,10 @@
|
|||
|
||||
#include "__init__.h"
|
||||
|
||||
//| :mod:`aesio` --- AES encryption routines
|
||||
//| ========================================
|
||||
//|
|
||||
//| .. module:: aesio
|
||||
//| :synopsis: Embedded implementation of AES
|
||||
//| """AES encryption routines
|
||||
//|
|
||||
//| The `AES` module contains classes used to implement encryption
|
||||
//| and decryption. It aims to be low overhead in terms of memory.
|
||||
//|
|
||||
//|
|
||||
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| aes
|
||||
//| and decryption. It aims to be low overhead in terms of memory."""
|
||||
|
||||
|
||||
STATIC const mp_obj_tuple_t mp_aes_key_size_obj = {
|
||||
|
|
|
@ -9,35 +9,31 @@
|
|||
|
||||
// Defined at the end of this file
|
||||
|
||||
//| .. currentmodule:: aesio
|
||||
//| class AES:
|
||||
//| """Encrypt and decrypt AES streams"""
|
||||
//|
|
||||
//| :class:`aesio` -- Encrypt and decrypt AES streams
|
||||
//| =====================================================
|
||||
//| def __init__(self, key, mode=0, iv=None, segment_size=8) -> Any:
|
||||
//| """Create a new AES state with the given key.
|
||||
//|
|
||||
//| An object that represents an AES stream, including the current state.
|
||||
//| :param bytearray key: A 16-, 24-, or 32-byte key
|
||||
//| :param int mode: AES mode to use. One of: AES.MODE_ECB, AES.MODE_CBC, or
|
||||
//| AES.MODE_CTR
|
||||
//| :param bytearray iv: Initialization vector to use for CBC or CTR mode
|
||||
//|
|
||||
//| .. class:: AES(key, mode=0, iv=None, segment_size=8)
|
||||
//| Additional arguments are supported for legacy reasons.
|
||||
//|
|
||||
//| Create a new AES state with the given key.
|
||||
//| Encrypting a string::
|
||||
//|
|
||||
//| :param bytearray key: A 16-, 24-, or 32-byte key
|
||||
//| :param int mode: AES mode to use. One of: AES.MODE_ECB, AES.MODE_CBC, or
|
||||
//| AES.MODE_CTR
|
||||
//| :param bytearray iv: Initialization vector to use for CBC or CTR mode
|
||||
//| import aesio
|
||||
//| from binascii import hexlify
|
||||
//|
|
||||
//| Additional arguments are supported for legacy reasons.
|
||||
//|
|
||||
//| Encrypting a string::
|
||||
//|
|
||||
//| import aesio
|
||||
//| from binascii import hexlify
|
||||
//|
|
||||
//| key = b'Sixteen byte key'
|
||||
//| inp = b'Circuit Python!!' # Note: 16-bytes long
|
||||
//| outp = bytearray(len(inp))
|
||||
//| cipher = aesio.AES(key, aesio.mode.MODE_ECB)
|
||||
//| cipher.encrypt_into(inp, outp)
|
||||
//| hexlify(outp)
|
||||
//| key = b'Sixteen byte key'
|
||||
//| inp = b'Circuit Python!!' # Note: 16-bytes long
|
||||
//| outp = bytearray(len(inp))
|
||||
//| cipher = aesio.AES(key, aesio.mode.MODE_ECB)
|
||||
//| 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,
|
||||
|
@ -156,12 +152,13 @@ STATIC void validate_length(aesio_aes_obj_t *self, size_t src_length,
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: encrypt_into(src, dest)
|
||||
//| def encrypt_into(src, dest) -> None:
|
||||
//| """Encrypt the buffer from ``src`` into ``dest``.
|
||||
//|
|
||||
//| Encrypt the buffer from ``src`` into ``dest``.
|
||||
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
|
||||
//| buffers must be a multiple of 16 bytes, and must be equal length. For
|
||||
//| CTX mode, there are no restrictions.
|
||||
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
|
||||
//| buffers must be a multiple of 16 bytes, and must be equal length. For
|
||||
//| CTX mode, there are no restrictions."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t aesio_aes_encrypt_into(mp_obj_t aesio_obj, mp_obj_t src,
|
||||
mp_obj_t dest) {
|
||||
|
@ -186,12 +183,13 @@ STATIC mp_obj_t aesio_aes_encrypt_into(mp_obj_t aesio_obj, mp_obj_t src,
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(aesio_aes_encrypt_into_obj,
|
||||
aesio_aes_encrypt_into);
|
||||
|
||||
//| .. method:: decrypt_into(src, dest)
|
||||
//| def decrypt_into(src, dest) -> None:
|
||||
//|
|
||||
//| Decrypt the buffer from ``src`` into ``dest``.
|
||||
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
|
||||
//| buffers must be a multiple of 16 bytes, and must be equal length. For
|
||||
//| CTX mode, there are no restrictions.
|
||||
//| """Decrypt the buffer from ``src`` into ``dest``.
|
||||
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
|
||||
//| buffers must be a multiple of 16 bytes, and must be equal length. For
|
||||
//| CTX mode, there are no restrictions."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t aesio_aes_decrypt_into(mp_obj_t aesio_obj, mp_obj_t src,
|
||||
mp_obj_t dest) {
|
||||
|
|
|
@ -36,26 +36,24 @@
|
|||
#include "shared-bindings/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| .. currentmodule:: analogio
|
||||
//| class AnalogIn:
|
||||
//| """Read analog voltage levels
|
||||
//|
|
||||
//| :class:`AnalogIn` -- read analog voltage
|
||||
//| ============================================
|
||||
//| Usage::
|
||||
//|
|
||||
//| Usage::
|
||||
//| import analogio
|
||||
//| from board import *
|
||||
//|
|
||||
//| import analogio
|
||||
//| from board import *
|
||||
//|
|
||||
//| adc = analogio.AnalogIn(A1)
|
||||
//| val = adc.value
|
||||
//| adc = analogio.AnalogIn(A1)
|
||||
//| val = adc.value"""
|
||||
//|
|
||||
|
||||
//| .. class:: AnalogIn(pin)
|
||||
//| def __init__(self, pin: microcontroller.Pin):
|
||||
//| """Use the AnalogIn on the given pin. The reference voltage varies by
|
||||
//| platform so use ``reference_voltage`` to read the configured setting.
|
||||
//|
|
||||
//| Use the AnalogIn on the given pin. The reference voltage varies by
|
||||
//| platform so use ``reference_voltage`` to read the configured setting.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin pin: the pin to read from
|
||||
//| :param ~microcontroller.Pin pin: the pin to read from"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
|
||||
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
|
@ -72,9 +70,9 @@ STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type,
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Turn off the AnalogIn and release the pin for other use.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -88,16 +86,16 @@ STATIC void check_for_deinit(analogio_analogin_obj_t *self) {
|
|||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -106,12 +104,11 @@ STATIC mp_obj_t analogio_analogin___exit__(size_t n_args, const mp_obj_t *args)
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(analogio_analogin___exit___obj, 4, 4, analogio_analogin___exit__);
|
||||
|
||||
//| .. attribute:: value
|
||||
//|
|
||||
//| The value on the analog pin between 0 and 65535 inclusive (16-bit). (read-only)
|
||||
//| value: Any = ...
|
||||
//| """The value on the analog pin between 0 and 65535 inclusive (16-bit). (read-only)
|
||||
//|
|
||||
//| Even if the underlying analog to digital converter (ADC) is lower
|
||||
//| resolution, the value is 16-bit.
|
||||
//| resolution, the value is 16-bit."""
|
||||
//|
|
||||
STATIC mp_obj_t analogio_analogin_obj_get_value(mp_obj_t self_in) {
|
||||
analogio_analogin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -127,10 +124,9 @@ const mp_obj_property_t analogio_analogin_value_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: reference_voltage
|
||||
//|
|
||||
//| The maximum voltage measurable (also known as the reference voltage) as a
|
||||
//| `float` in Volts.
|
||||
//| reference_voltage: Any = ...
|
||||
//| """The maximum voltage measurable (also known as the reference voltage) as a
|
||||
//| `float` in Volts."""
|
||||
//|
|
||||
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);
|
||||
|
|
|
@ -36,27 +36,22 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: analogio
|
||||
//| class AnalogOut:
|
||||
//| """Output analog values (a specific voltage).
|
||||
//|
|
||||
//| :class:`AnalogOut` -- output analog voltage
|
||||
//| ============================================
|
||||
//| Example usage::
|
||||
//|
|
||||
//| The AnalogOut is used to output analog values (a specific voltage).
|
||||
//| import analogio
|
||||
//| from microcontroller import pin
|
||||
//|
|
||||
//| Example usage::
|
||||
//| dac = analogio.AnalogOut(pin.PA02) # output on pin PA02
|
||||
//| dac.value = 32768 # makes PA02 1.65V"""
|
||||
//|
|
||||
//| import analogio
|
||||
//| from microcontroller import pin
|
||||
//| def __init__(self, pin: microcontroller.Pin):
|
||||
//| """Use the AnalogOut on the given pin.
|
||||
//|
|
||||
//| dac = analogio.AnalogOut(pin.PA02) # output on pin PA02
|
||||
//| dac.value = 32768 # makes PA02 1.65V
|
||||
//|
|
||||
|
||||
//| .. class:: AnalogOut(pin)
|
||||
//|
|
||||
//| Use the AnalogOut on the given pin.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin pin: the pin to output to
|
||||
//| :param ~microcontroller.Pin pin: the pin to output to"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
// check arguments
|
||||
|
@ -71,9 +66,9 @@ STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Turn off the AnalogOut and release the pin for other use.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -84,16 +79,16 @@ STATIC mp_obj_t analogio_analogout_deinit(mp_obj_t self_in) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(analogio_analogout_deinit_obj, analogio_analogout_deinit);
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -102,12 +97,12 @@ STATIC mp_obj_t analogio_analogout___exit__(size_t n_args, const mp_obj_t *args)
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(analogio_analogout___exit___obj, 4, 4, analogio_analogout___exit__);
|
||||
|
||||
//| .. attribute:: value
|
||||
//|
|
||||
//| The value on the analog pin between 0 and 65535 inclusive (16-bit). (write-only)
|
||||
//| value: Any = ...
|
||||
//| """The value on the analog pin between 0 and 65535 inclusive (16-bit). (write-only)
|
||||
//|
|
||||
//| Even if the underlying digital to analog converter (DAC) is lower
|
||||
//| resolution, the value is 16-bit.
|
||||
//| 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)) {
|
||||
|
|
|
@ -34,25 +34,12 @@
|
|||
#include "shared-bindings/analogio/AnalogIn.h"
|
||||
#include "shared-bindings/analogio/AnalogOut.h"
|
||||
|
||||
//| :mod:`analogio` --- Analog hardware support
|
||||
//| =================================================
|
||||
//|
|
||||
//| .. module:: analogio
|
||||
//| :synopsis: Analog hardware support
|
||||
//| :platform: SAMD21, ESP8266
|
||||
//| """Analog hardware support
|
||||
//|
|
||||
//| The `analogio` module contains classes to provide access to analog IO
|
||||
//| typically implemented with digital-to-analog (DAC) and analog-to-digital
|
||||
//| (ADC) converters.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| AnalogIn
|
||||
//| AnalogOut
|
||||
//|
|
||||
//| All classes change hardware state and should be deinitialized when they
|
||||
//| are no longer needed if the program continues after use. To do so, either
|
||||
//| call :py:meth:`!deinit` or use a context manager. See
|
||||
|
@ -70,7 +57,7 @@
|
|||
//| This example will initialize the the device, read
|
||||
//| :py:data:`~analogio.AnalogIn.value` and then
|
||||
//| :py:meth:`~analogio.AnalogIn.deinit` the hardware. The last step is optional
|
||||
//| because CircuitPython will do it automatically after the program finishes.
|
||||
//| because CircuitPython will do it automatically after the program finishes."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t analogio_module_globals_table[] = {
|
||||
|
|
|
@ -35,64 +35,60 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiobusio
|
||||
//| class I2SOut:
|
||||
//| """Output an I2S audio signal"""
|
||||
//|
|
||||
//| :class:`I2SOut` -- Output an I2S audio signal
|
||||
//| ========================================================
|
||||
//| def __init__(self, bit_clock: microcontroller.Pin, word_select: microcontroller.Pin, data: microcontroller.Pin, *, left_justified: bool):
|
||||
//| """Create a I2SOut object associated with the given pins.
|
||||
//|
|
||||
//| I2S is used to output an audio signal on an I2S bus.
|
||||
//| :param ~microcontroller.Pin bit_clock: The bit clock (or serial clock) pin
|
||||
//| :param ~microcontroller.Pin word_select: The word select (or left/right clock) pin
|
||||
//| :param ~microcontroller.Pin data: The data pin
|
||||
//| :param bool left_justified: True when data bits are aligned with the word select clock. False
|
||||
//| when they are shifted by one to match classic I2S protocol.
|
||||
//|
|
||||
//| .. class:: I2SOut(bit_clock, word_select, data, *, left_justified)
|
||||
//| Simple 8ksps 440 Hz sine wave on `Metro M0 Express <https://www.adafruit.com/product/3505>`_
|
||||
//| using `UDA1334 Breakout <https://www.adafruit.com/product/3678>`_::
|
||||
//|
|
||||
//| Create a I2SOut object associated with the given pins.
|
||||
//| import audiobusio
|
||||
//| import audiocore
|
||||
//| import board
|
||||
//| import array
|
||||
//| import time
|
||||
//| import math
|
||||
//|
|
||||
//| :param ~microcontroller.Pin bit_clock: The bit clock (or serial clock) pin
|
||||
//| :param ~microcontroller.Pin word_select: The word select (or left/right clock) pin
|
||||
//| :param ~microcontroller.Pin data: The data pin
|
||||
//| :param bool left_justified: True when data bits are aligned with the word select clock. False
|
||||
//| when they are shifted by one to match classic I2S protocol.
|
||||
//| # Generate one period of sine wave.
|
||||
//| length = 8000 // 440
|
||||
//| sine_wave = array.array("H", [0] * length)
|
||||
//| for i in range(length):
|
||||
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
|
||||
//|
|
||||
//| Simple 8ksps 440 Hz sine wave on `Metro M0 Express <https://www.adafruit.com/product/3505>`_
|
||||
//| using `UDA1334 Breakout <https://www.adafruit.com/product/3678>`_::
|
||||
//| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
|
||||
//| i2s = audiobusio.I2SOut(board.D1, board.D0, board.D9)
|
||||
//| i2s.play(sine_wave, loop=True)
|
||||
//| time.sleep(1)
|
||||
//| i2s.stop()
|
||||
//|
|
||||
//| import audiobusio
|
||||
//| import audiocore
|
||||
//| import board
|
||||
//| import array
|
||||
//| import time
|
||||
//| import math
|
||||
//| Playing a wave file from flash::
|
||||
//|
|
||||
//| # Generate one period of sine wave.
|
||||
//| length = 8000 // 440
|
||||
//| sine_wave = array.array("H", [0] * length)
|
||||
//| for i in range(length):
|
||||
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
|
||||
//|
|
||||
//| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
|
||||
//| i2s = audiobusio.I2SOut(board.D1, board.D0, board.D9)
|
||||
//| i2s.play(sine_wave, loop=True)
|
||||
//| time.sleep(1)
|
||||
//| i2s.stop()
|
||||
//|
|
||||
//| Playing a wave file from flash::
|
||||
//|
|
||||
//| import board
|
||||
//| import audioio
|
||||
//| import audiocore
|
||||
//| import audiobusio
|
||||
//| import digitalio
|
||||
//| import board
|
||||
//| import audioio
|
||||
//| import audiocore
|
||||
//| import audiobusio
|
||||
//| import digitalio
|
||||
//|
|
||||
//|
|
||||
//| f = open("cplay-5.1-16bit-16khz.wav", "rb")
|
||||
//| wav = audiocore.WaveFile(f)
|
||||
//| f = open("cplay-5.1-16bit-16khz.wav", "rb")
|
||||
//| wav = audiocore.WaveFile(f)
|
||||
//|
|
||||
//| a = audiobusio.I2SOut(board.D1, board.D0, board.D9)
|
||||
//| a = audiobusio.I2SOut(board.D1, board.D0, board.D9)
|
||||
//|
|
||||
//| print("playing")
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")
|
||||
//| print("playing")
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified };
|
||||
|
@ -116,9 +112,9 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the I2SOut and releases any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -132,16 +128,16 @@ STATIC void check_for_deinit(audiobusio_i2sout_obj_t *self) {
|
|||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -151,14 +147,14 @@ STATIC mp_obj_t audiobusio_i2sout_obj___exit__(size_t n_args, const mp_obj_t *ar
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_i2sout___exit___obj, 4, 4, audiobusio_i2sout_obj___exit__);
|
||||
|
||||
|
||||
//| .. method:: play(sample, *, loop=False)
|
||||
//| def play(self, sample: Any, *, loop: Any = False) -> Any:
|
||||
//| """Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//|
|
||||
//| Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| The sample itself should consist of 8 bit or 16 bit samples.
|
||||
//| 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 };
|
||||
|
@ -178,9 +174,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_play(size_t n_args, const mp_obj_t *pos_ar
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiobusio_i2sout_play_obj, 1, audiobusio_i2sout_obj_play);
|
||||
|
||||
//| .. method:: stop()
|
||||
//|
|
||||
//| Stops playback.
|
||||
//| def stop(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -190,9 +186,8 @@ STATIC mp_obj_t audiobusio_i2sout_obj_stop(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_stop_obj, audiobusio_i2sout_obj_stop);
|
||||
|
||||
//| .. attribute:: playing
|
||||
//|
|
||||
//| True when the audio sample is being output. (read-only)
|
||||
//| playing: Any = ...
|
||||
//| """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);
|
||||
|
@ -208,9 +203,9 @@ const mp_obj_property_t audiobusio_i2sout_playing_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: pause()
|
||||
//|
|
||||
//| Stops playback temporarily while remembering the position. Use `resume` to resume playback.
|
||||
//| def pause(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -224,9 +219,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_pause_obj, audiobusio_i2sout_obj_pause);
|
||||
|
||||
//| .. method:: resume()
|
||||
//|
|
||||
//| Resumes sample playback after :py:func:`pause`.
|
||||
//| def resume(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -240,9 +235,8 @@ STATIC mp_obj_t audiobusio_i2sout_obj_resume(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_resume_obj, audiobusio_i2sout_obj_resume);
|
||||
|
||||
//| .. attribute:: paused
|
||||
//|
|
||||
//| True when playback is paused. (read-only)
|
||||
//| paused: Any = ...
|
||||
//| """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);
|
||||
|
|
|
@ -36,56 +36,52 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiobusio
|
||||
//| class PDMIn:
|
||||
//| """Record an input PDM audio stream"""
|
||||
//|
|
||||
//| :class:`PDMIn` -- Record an input PDM audio stream
|
||||
//| ========================================================
|
||||
//| def __init__(self, clock_pin: microcontroller.Pin, data_pin: microcontroller.Pin, *, sample_rate: int = 16000, bit_depth: int = 8, mono: bool = True, oversample: int = 64, startup_delay: float = 0.11):
|
||||
//| """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
|
||||
//| restrictions on the recording parameters. The overall sample rate is
|
||||
//| determined by `sample_rate` x ``oversample``, and the total must be 1MHz or
|
||||
//| higher, so `sample_rate` must be a minimum of 16000.
|
||||
//|
|
||||
//| PDMIn can be used to record an input audio signal on a given set of pins.
|
||||
//|
|
||||
//| .. class:: PDMIn(clock_pin, data_pin, *, sample_rate=16000, bit_depth=8, mono=True, oversample=64, startup_delay=0.11)
|
||||
//|
|
||||
//| 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
|
||||
//| restrictions on the recording parameters. The overall sample rate is
|
||||
//| determined by `sample_rate` x ``oversample``, and the total must be 1MHz or
|
||||
//| higher, so `sample_rate` must be a minimum of 16000.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin clock_pin: The pin to output the clock to
|
||||
//| :param ~microcontroller.Pin data_pin: The pin to read the data from
|
||||
//| :param int sample_rate: Target sample_rate of the resulting samples. Check `sample_rate` for actual value.
|
||||
//| Minimum sample_rate is about 16000 Hz.
|
||||
//| :param int bit_depth: Final number of bits per sample. Must be divisible by 8
|
||||
//| :param bool mono: True when capturing a single channel of audio, captures two channels otherwise
|
||||
//| :param int oversample: Number of single bit samples to decimate into a final sample. Must be divisible by 8
|
||||
//| :param float startup_delay: seconds to wait after starting microphone clock
|
||||
//| to allow microphone to turn on. Most require only 0.01s; some require 0.1s. Longer is safer.
|
||||
//| Must be in range 0.0-1.0 seconds.
|
||||
//| :param ~microcontroller.Pin clock_pin: The pin to output the clock to
|
||||
//| :param ~microcontroller.Pin data_pin: The pin to read the data from
|
||||
//| :param int sample_rate: Target sample_rate of the resulting samples. Check `sample_rate` for actual value.
|
||||
//| Minimum sample_rate is about 16000 Hz.
|
||||
//| :param int bit_depth: Final number of bits per sample. Must be divisible by 8
|
||||
//| :param bool mono: True when capturing a single channel of audio, captures two channels otherwise
|
||||
//| :param int oversample: Number of single bit samples to decimate into a final sample. Must be divisible by 8
|
||||
//| :param float startup_delay: seconds to wait after starting microphone clock
|
||||
//| to allow microphone to turn on. Most require only 0.01s; some require 0.1s. Longer is safer.
|
||||
//| Must be in range 0.0-1.0 seconds."""
|
||||
//|
|
||||
|
||||
//| Record 8-bit unsigned samples to buffer::
|
||||
//| """Record 8-bit unsigned samples to buffer::
|
||||
//|
|
||||
//| import audiobusio
|
||||
//| import board
|
||||
//| import audiobusio
|
||||
//| import board
|
||||
//|
|
||||
//| # Prep a buffer to record into
|
||||
//| b = bytearray(200)
|
||||
//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000) as mic:
|
||||
//| mic.record(b, len(b))
|
||||
//| # Prep a buffer to record into
|
||||
//| b = bytearray(200)
|
||||
//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000) as mic:
|
||||
//| mic.record(b, len(b))
|
||||
//|
|
||||
//| Record 16-bit unsigned samples to buffer::
|
||||
//| Record 16-bit unsigned samples to buffer::
|
||||
//|
|
||||
//| import audiobusio
|
||||
//| import board
|
||||
//| import audiobusio
|
||||
//| import board
|
||||
//|
|
||||
//| # Prep a buffer to record into. The array interface doesn't allow for
|
||||
//| # constructing with a set size so we append to it until we have the size
|
||||
//| # we want.
|
||||
//| b = array.array("H")
|
||||
//| for i in range(200):
|
||||
//| b.append(0)
|
||||
//| with audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16) as mic:
|
||||
//| mic.record(b, len(b))
|
||||
//| # Prep a buffer to record into. The array interface doesn't allow for
|
||||
//| # constructing with a set size so we append to it until we have the size
|
||||
//| # we want.
|
||||
//| b = array.array("H")
|
||||
//| for i in range(200):
|
||||
//| b.append(0)
|
||||
//| 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, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_clock_pin, ARG_data_pin, ARG_sample_rate, ARG_bit_depth, ARG_mono, ARG_oversample, ARG_startup_delay };
|
||||
|
@ -138,9 +134,9 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the PDMIn and releases any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -154,15 +150,15 @@ STATIC void check_for_deinit(audiobusio_pdmin_obj_t *self) {
|
|||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -172,17 +168,17 @@ STATIC mp_obj_t audiobusio_pdmin_obj___exit__(size_t n_args, const mp_obj_t *arg
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_pdmin___exit___obj, 4, 4, audiobusio_pdmin_obj___exit__);
|
||||
|
||||
|
||||
//| .. method:: record(destination, destination_length)
|
||||
//| def record(self, destination: Any, destination_length: Any) -> Any:
|
||||
//| """Records destination_length bytes of samples to destination. This is
|
||||
//| blocking.
|
||||
//|
|
||||
//| Records destination_length bytes of samples to destination. This is
|
||||
//| blocking.
|
||||
//| An IOError may be raised when the destination is too slow to record the
|
||||
//| audio at the given rate. For internal flash, writing all 1s to the file
|
||||
//| before recording is recommended to speed up writes.
|
||||
//|
|
||||
//| An IOError may be raised when the destination is too slow to record the
|
||||
//| audio at the given rate. For internal flash, writing all 1s to the file
|
||||
//| before recording is recommended to speed up writes.
|
||||
//|
|
||||
//| :return: The number of samples recorded. If this is less than ``destination_length``,
|
||||
//| some samples were missed due to processing time.
|
||||
//| :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);
|
||||
|
@ -214,10 +210,9 @@ STATIC mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destinat
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(audiobusio_pdmin_record_obj, audiobusio_pdmin_obj_record);
|
||||
|
||||
//| .. attribute:: sample_rate
|
||||
//|
|
||||
//| The actual sample_rate of the recording. This may not match the constructed
|
||||
//| sample rate due to internal clock limitations.
|
||||
//| sample_rate: Any = ...
|
||||
//| """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);
|
||||
|
|
|
@ -34,29 +34,16 @@
|
|||
#include "shared-bindings/audiobusio/I2SOut.h"
|
||||
#include "shared-bindings/audiobusio/PDMIn.h"
|
||||
|
||||
//| :mod:`audiobusio` --- Support for audio input and output over digital bus
|
||||
//| =========================================================================
|
||||
//|
|
||||
//| .. module:: audiobusio
|
||||
//| :synopsis: Support for audio input and output over digital bus
|
||||
//| :platform: SAMD21
|
||||
//| """Support for audio input and output over digital buses
|
||||
//|
|
||||
//| The `audiobusio` module contains classes to provide access to audio IO
|
||||
//| over digital buses. These protocols are used to communicate audio to other
|
||||
//| chips in the same circuit. It doesn't include audio interconnect protocols
|
||||
//| such as S/PDIF.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| I2SOut
|
||||
//| PDMIn
|
||||
//|
|
||||
//| All libraries change hardware state and should be deinitialized when they
|
||||
//| are no longer needed. To do so, either call :py:meth:`!deinit` or use a
|
||||
//| context manager.
|
||||
//| context manager."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audiobusio_module_globals_table[] = {
|
||||
|
|
|
@ -35,44 +35,40 @@
|
|||
#include "shared-bindings/audiocore/RawSample.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiocore
|
||||
//| class RawSample:
|
||||
//| """A raw audio sample buffer in memory"""
|
||||
//|
|
||||
//| :class:`RawSample` -- A raw audio sample buffer
|
||||
//| ========================================================
|
||||
//| def __init__(self, buffer: array.array, *, channel_count: int = 1, sample_rate: int = 8000):
|
||||
//| """Create a RawSample based on the given buffer of signed values. If channel_count is more than
|
||||
//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the
|
||||
//| first sample will be for channel 1, the second sample will be for channel two, the third for
|
||||
//| channel 1 and so on.
|
||||
//|
|
||||
//| An in-memory sound sample
|
||||
//| :param array.array buffer: An `array.array` with samples
|
||||
//| :param int channel_count: The number of channels in the buffer
|
||||
//| :param int sample_rate: The desired playback sample rate
|
||||
//|
|
||||
//| .. class:: RawSample(buffer, *, channel_count=1, sample_rate=8000)
|
||||
//| Simple 8ksps 440 Hz sin wave::
|
||||
//|
|
||||
//| Create a RawSample based on the given buffer of signed values. If channel_count is more than
|
||||
//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the
|
||||
//| first sample will be for channel 1, the second sample will be for channel two, the third for
|
||||
//| channel 1 and so on.
|
||||
//| import audiocore
|
||||
//| import audioio
|
||||
//| import board
|
||||
//| import array
|
||||
//| import time
|
||||
//| import math
|
||||
//|
|
||||
//| :param array.array buffer: An `array.array` with samples
|
||||
//| :param int channel_count: The number of channels in the buffer
|
||||
//| :param int sample_rate: The desired playback sample rate
|
||||
//| # Generate one period of sine wav.
|
||||
//| length = 8000 // 440
|
||||
//| sine_wave = array.array("h", [0] * length)
|
||||
//| for i in range(length):
|
||||
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15))
|
||||
//|
|
||||
//| Simple 8ksps 440 Hz sin wave::
|
||||
//|
|
||||
//| import audiocore
|
||||
//| import audioio
|
||||
//| import board
|
||||
//| import array
|
||||
//| import time
|
||||
//| import math
|
||||
//|
|
||||
//| # Generate one period of sine wav.
|
||||
//| length = 8000 // 440
|
||||
//| sine_wave = array.array("h", [0] * length)
|
||||
//| for i in range(length):
|
||||
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15))
|
||||
//|
|
||||
//| dac = audioio.AudioOut(board.SPEAKER)
|
||||
//| sine_wave = audiocore.RawSample(sine_wave)
|
||||
//| dac.play(sine_wave, loop=True)
|
||||
//| time.sleep(1)
|
||||
//| dac.stop()
|
||||
//| dac = audioio.AudioOut(board.SPEAKER)
|
||||
//| sine_wave = audiocore.RawSample(sine_wave)
|
||||
//| dac.play(sine_wave, loop=True)
|
||||
//| time.sleep(1)
|
||||
//| dac.stop()"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_buffer, ARG_channel_count, ARG_sample_rate };
|
||||
|
@ -105,9 +101,9 @@ STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_a
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the AudioOut and releases any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialises the AudioOut 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);
|
||||
|
@ -122,16 +118,16 @@ STATIC void check_for_deinit(audioio_rawsample_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -140,12 +136,11 @@ STATIC mp_obj_t audioio_rawsample_obj___exit__(size_t n_args, const mp_obj_t *ar
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_rawsample___exit___obj, 4, 4, audioio_rawsample_obj___exit__);
|
||||
|
||||
//| .. attribute:: sample_rate
|
||||
//|
|
||||
//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second).
|
||||
//| sample_rate: Any = ...
|
||||
//| """32 bit value that dictates how quickly samples are played in Hertz (cycles per second).
|
||||
//| When the sample is looped, this can change the pitch output without changing the underlying
|
||||
//| sample. This will not change the sample rate of any active playback. Call ``play`` again to
|
||||
//| change it.
|
||||
//| 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);
|
||||
|
|
|
@ -33,43 +33,41 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiocore
|
||||
//| class WaveFile:
|
||||
//| """Load a wave file for audio playback
|
||||
//|
|
||||
//| :class:`WaveFile` -- Load a wave file for audio playback
|
||||
//| ========================================================
|
||||
//| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must
|
||||
//| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating
|
||||
//| an internal buffer."""
|
||||
//|
|
||||
//| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must
|
||||
//| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating
|
||||
//| an internal buffer.
|
||||
//| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
|
||||
//| """Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
|
||||
//|
|
||||
//| .. class:: WaveFile(file[, buffer])
|
||||
//|
|
||||
//| Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
|
||||
//|
|
||||
//| :param typing.BinaryIO file: Already opened wave file
|
||||
//| :param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two 512 byte buffers are allocated internally.
|
||||
//| :param typing.BinaryIO file: Already opened wave file
|
||||
//| :param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two 512 byte buffers are allocated internally.
|
||||
//|
|
||||
//|
|
||||
//| Playing a wave file from flash::
|
||||
//| Playing a wave file from flash::
|
||||
//|
|
||||
//| import board
|
||||
//| import audiocore
|
||||
//| import audioio
|
||||
//| import digitalio
|
||||
//| import board
|
||||
//| import audiocore
|
||||
//| import audioio
|
||||
//| import digitalio
|
||||
//|
|
||||
//| # Required for CircuitPlayground Express
|
||||
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
|
||||
//| speaker_enable.switch_to_output(value=True)
|
||||
//| # Required for CircuitPlayground Express
|
||||
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
|
||||
//| speaker_enable.switch_to_output(value=True)
|
||||
//|
|
||||
//| data = open("cplay-5.1-16bit-16khz.wav", "rb")
|
||||
//| wav = audiocore.WaveFile(data)
|
||||
//| a = audioio.AudioOut(board.A0)
|
||||
//| data = open("cplay-5.1-16bit-16khz.wav", "rb")
|
||||
//| wav = audiocore.WaveFile(data)
|
||||
//| a = audioio.AudioOut(board.A0)
|
||||
//|
|
||||
//| print("playing")
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")
|
||||
//| print("playing")
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 2, false);
|
||||
|
@ -93,10 +91,9 @@ STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the WaveFile and releases all memory resources for reuse.
|
||||
//|
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -110,16 +107,16 @@ STATIC void check_for_deinit(audioio_wavefile_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -128,11 +125,10 @@ STATIC mp_obj_t audioio_wavefile_obj___exit__(size_t n_args, const mp_obj_t *arg
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_wavefile___exit___obj, 4, 4, audioio_wavefile_obj___exit__);
|
||||
|
||||
//| .. attribute:: sample_rate
|
||||
//|
|
||||
//| 32 bit value that dictates how quickly samples are loaded into the DAC
|
||||
//| sample_rate: Any = ...
|
||||
//| """32 bit value that dictates how quickly samples are loaded into the DAC
|
||||
//| in Hertz (cycles per second). When the sample is looped, this can change
|
||||
//| the pitch output without changing the underlying sample.
|
||||
//| the pitch output without changing the underlying sample."""
|
||||
//|
|
||||
STATIC mp_obj_t audioio_wavefile_obj_get_sample_rate(mp_obj_t self_in) {
|
||||
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -156,9 +152,8 @@ const mp_obj_property_t audioio_wavefile_sample_rate_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: bits_per_sample
|
||||
//|
|
||||
//| Bits per sample. (read only)
|
||||
//| bits_per_sample: Any = ...
|
||||
//| """Bits per sample. (read only)"""
|
||||
//|
|
||||
STATIC mp_obj_t audioio_wavefile_obj_get_bits_per_sample(mp_obj_t self_in) {
|
||||
audioio_wavefile_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -173,10 +168,8 @@ const mp_obj_property_t audioio_wavefile_bits_per_sample_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj,
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: channel_count
|
||||
//|
|
||||
//| Number of audio channels. (read only)
|
||||
//| channel_count: Any = ...
|
||||
//| """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);
|
||||
|
|
|
@ -35,22 +35,7 @@
|
|||
#include "shared-bindings/audiocore/WaveFile.h"
|
||||
//#include "shared-bindings/audiomixer/Mixer.h"
|
||||
|
||||
//| :mod:`audiocore` --- Support for audio samples and mixer
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: audiocore
|
||||
//| :synopsis: Support for audio samples and mixer
|
||||
//| :platform: SAMD21
|
||||
//|
|
||||
//| The `audiocore` module contains core classes for audio IO
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| RawSample
|
||||
//| WaveFile
|
||||
//| """Support for audio samples"""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audiocore_module_globals_table[] = {
|
||||
|
|
|
@ -36,63 +36,59 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audioio
|
||||
//| class AudioOut:
|
||||
//| """Output an analog audio signal"""
|
||||
//|
|
||||
//| :class:`AudioOut` -- Output an analog audio signal
|
||||
//| ========================================================
|
||||
//| def __init__(self, left_channel: microcontroller.Pin, *, right_channel: microcontroller.Pin = None, quiescent_value: int = 0x8000):
|
||||
//| """Create a AudioOut object associated with the given pin(s). This allows you to
|
||||
//| play audio signals out on the given pin(s).
|
||||
//|
|
||||
//| AudioOut can be used to output an analog audio signal on a given pin.
|
||||
//| :param ~microcontroller.Pin left_channel: The pin to output the left channel to
|
||||
//| :param ~microcontroller.Pin right_channel: The pin to output the right channel to
|
||||
//| :param int quiescent_value: The output value when no signal is present. Samples should start
|
||||
//| and end with this value to prevent audible popping.
|
||||
//|
|
||||
//| .. class:: AudioOut(left_channel, *, right_channel=None, quiescent_value=0x8000)
|
||||
//| Simple 8ksps 440 Hz sin wave::
|
||||
//|
|
||||
//| Create a AudioOut object associated with the given pin(s). This allows you to
|
||||
//| play audio signals out on the given pin(s).
|
||||
//| import audiocore
|
||||
//| import audioio
|
||||
//| import board
|
||||
//| import array
|
||||
//| import time
|
||||
//| import math
|
||||
//|
|
||||
//| :param ~microcontroller.Pin left_channel: The pin to output the left channel to
|
||||
//| :param ~microcontroller.Pin right_channel: The pin to output the right channel to
|
||||
//| :param int quiescent_value: The output value when no signal is present. Samples should start
|
||||
//| and end with this value to prevent audible popping.
|
||||
//| # Generate one period of sine wav.
|
||||
//| length = 8000 // 440
|
||||
//| sine_wave = array.array("H", [0] * length)
|
||||
//| for i in range(length):
|
||||
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
|
||||
//|
|
||||
//| Simple 8ksps 440 Hz sin wave::
|
||||
//| dac = audioio.AudioOut(board.SPEAKER)
|
||||
//| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
|
||||
//| dac.play(sine_wave, loop=True)
|
||||
//| time.sleep(1)
|
||||
//| dac.stop()
|
||||
//|
|
||||
//| import audiocore
|
||||
//| import audioio
|
||||
//| import board
|
||||
//| import array
|
||||
//| import time
|
||||
//| import math
|
||||
//| Playing a wave file from flash::
|
||||
//|
|
||||
//| # Generate one period of sine wav.
|
||||
//| length = 8000 // 440
|
||||
//| sine_wave = array.array("H", [0] * length)
|
||||
//| for i in range(length):
|
||||
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
|
||||
//| import board
|
||||
//| import audioio
|
||||
//| import digitalio
|
||||
//|
|
||||
//| dac = audioio.AudioOut(board.SPEAKER)
|
||||
//| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
|
||||
//| dac.play(sine_wave, loop=True)
|
||||
//| time.sleep(1)
|
||||
//| dac.stop()
|
||||
//| # Required for CircuitPlayground Express
|
||||
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
|
||||
//| speaker_enable.switch_to_output(value=True)
|
||||
//|
|
||||
//| Playing a wave file from flash::
|
||||
//| data = open("cplay-5.1-16bit-16khz.wav", "rb")
|
||||
//| wav = audiocore.WaveFile(data)
|
||||
//| a = audioio.AudioOut(board.A0)
|
||||
//|
|
||||
//| import board
|
||||
//| import audioio
|
||||
//| import digitalio
|
||||
//|
|
||||
//| # Required for CircuitPlayground Express
|
||||
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
|
||||
//| speaker_enable.switch_to_output(value=True)
|
||||
//|
|
||||
//| data = open("cplay-5.1-16bit-16khz.wav", "rb")
|
||||
//| wav = audiocore.WaveFile(data)
|
||||
//| a = audioio.AudioOut(board.A0)
|
||||
//|
|
||||
//| print("playing")
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")
|
||||
//| print("playing")
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
|
||||
|
@ -115,9 +111,9 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the AudioOut and releases any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -131,16 +127,16 @@ STATIC void check_for_deinit(audioio_audioout_obj_t *self) {
|
|||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -150,16 +146,16 @@ STATIC mp_obj_t audioio_audioout_obj___exit__(size_t n_args, const mp_obj_t *arg
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audioio_audioout___exit___obj, 4, 4, audioio_audioout_obj___exit__);
|
||||
|
||||
|
||||
//| .. method:: play(sample, *, loop=False)
|
||||
//| def play(self, sample: Any, *, loop: Any = False) -> Any:
|
||||
//| """Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//|
|
||||
//| Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| The sample itself should consist of 16 bit samples. Microcontrollers with a lower output
|
||||
//| 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.
|
||||
//| The sample itself should consist of 16 bit samples. Microcontrollers with a lower output
|
||||
//| 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 };
|
||||
|
@ -179,9 +175,9 @@ STATIC mp_obj_t audioio_audioout_obj_play(size_t n_args, const mp_obj_t *pos_arg
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audioio_audioout_play_obj, 1, audioio_audioout_obj_play);
|
||||
|
||||
//| .. method:: stop()
|
||||
//|
|
||||
//| Stops playback and resets to the start of the sample.
|
||||
//| def stop(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -191,9 +187,8 @@ STATIC mp_obj_t audioio_audioout_obj_stop(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_stop_obj, audioio_audioout_obj_stop);
|
||||
|
||||
//| .. attribute:: playing
|
||||
//|
|
||||
//| True when an audio sample is being output even if `paused`. (read-only)
|
||||
//| playing: Any = ...
|
||||
//| """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);
|
||||
|
@ -209,9 +204,9 @@ const mp_obj_property_t audioio_audioout_playing_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: pause()
|
||||
//|
|
||||
//| Stops playback temporarily while remembering the position. Use `resume` to resume playback.
|
||||
//| def pause(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -225,9 +220,9 @@ STATIC mp_obj_t audioio_audioout_obj_pause(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_pause_obj, audioio_audioout_obj_pause);
|
||||
|
||||
//| .. method:: resume()
|
||||
//|
|
||||
//| Resumes sample playback after :py:func:`pause`.
|
||||
//| def resume(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -241,9 +236,8 @@ STATIC mp_obj_t audioio_audioout_obj_resume(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audioio_audioout_resume_obj, audioio_audioout_obj_resume);
|
||||
|
||||
//| .. attribute:: paused
|
||||
//|
|
||||
//| True when playback is paused. (read-only)
|
||||
//| paused: Any = ...
|
||||
//| """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);
|
||||
|
|
|
@ -42,22 +42,10 @@
|
|||
#include "shared-bindings/audiomixer/Mixer.h"
|
||||
#endif
|
||||
|
||||
//| :mod:`audioio` --- Support for audio input and output
|
||||
//| ======================================================
|
||||
//|
|
||||
//| .. module:: audioio
|
||||
//| :synopsis: Support for audio input and output
|
||||
//| :platform: SAMD21
|
||||
//| """Support for audio output
|
||||
//|
|
||||
//| The `audioio` module contains classes to provide access to audio IO.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| AudioOut
|
||||
//|
|
||||
//| All classes change hardware state and should be deinitialized when they
|
||||
//| are no longer needed if the program continues after use. To do so, either
|
||||
//| call :py:meth:`!deinit` or use a context manager. See
|
||||
|
@ -68,7 +56,7 @@
|
|||
//|
|
||||
//| For compatibility with CircuitPython 4.x, some builds allow the items in
|
||||
//| `audiocore` to be imported from `audioio`. This will be removed for all
|
||||
//| boards in a future build of CircuitPython.
|
||||
//| boards in a future build of CircuitPython."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audioio_module_globals_table[] = {
|
||||
|
|
|
@ -38,49 +38,45 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiomixer
|
||||
//| class Mixer:
|
||||
//| """Mixes one or more audio samples together into one sample."""
|
||||
//|
|
||||
//| :class:`Mixer` -- Mixes one or more audio samples together
|
||||
//| ===========================================================
|
||||
//| def __init__(self, voice_count: int = 2, buffer_size: int = 1024, channel_count: int = 2, bits_per_sample: int = 16, samples_signed: bool = True, sample_rate: int = 8000):
|
||||
//| """Create a Mixer object that can mix multiple channels with the same sample rate.
|
||||
//| Samples are accessed and controlled with the mixer's `audiomixer.MixerVoice` objects.
|
||||
//|
|
||||
//| Mixer mixes multiple samples into one sample.
|
||||
//| :param int voice_count: The maximum number of voices to mix
|
||||
//| :param int buffer_size: The total size in bytes of the buffers to mix into
|
||||
//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
|
||||
//| :param int bits_per_sample: The bits per sample of the samples being played
|
||||
//| :param bool samples_signed: Samples are signed (True) or unsigned (False)
|
||||
//| :param int sample_rate: The sample rate to be used for all samples
|
||||
//|
|
||||
//| .. class:: Mixer(voice_count=2, buffer_size=1024, channel_count=2, bits_per_sample=16, samples_signed=True, sample_rate=8000)
|
||||
//| Playing a wave file from flash::
|
||||
//|
|
||||
//| Create a Mixer object that can mix multiple channels with the same sample rate.
|
||||
//| Samples are accessed and controlled with the mixer's `audiomixer.MixerVoice` objects.
|
||||
//| import board
|
||||
//| import audioio
|
||||
//| import audiocore
|
||||
//| import audiomixer
|
||||
//| import digitalio
|
||||
//|
|
||||
//| :param int voice_count: The maximum number of voices to mix
|
||||
//| :param int buffer_size: The total size in bytes of the buffers to mix into
|
||||
//| :param int channel_count: The number of channels the source samples contain. 1 = mono; 2 = stereo.
|
||||
//| :param int bits_per_sample: The bits per sample of the samples being played
|
||||
//| :param bool samples_signed: Samples are signed (True) or unsigned (False)
|
||||
//| :param int sample_rate: The sample rate to be used for all samples
|
||||
//| a = audioio.AudioOut(board.A0)
|
||||
//| music = audiocore.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb"))
|
||||
//| drum = audiocore.WaveFile(open("drum.wav", "rb"))
|
||||
//| mixer = audiomixer.Mixer(voice_count=2, sample_rate=16000, channel_count=1,
|
||||
//| bits_per_sample=16, samples_signed=True)
|
||||
//|
|
||||
//| Playing a wave file from flash::
|
||||
//|
|
||||
//| import board
|
||||
//| import audioio
|
||||
//| import audiocore
|
||||
//| import audiomixer
|
||||
//| import digitalio
|
||||
//|
|
||||
//| a = audioio.AudioOut(board.A0)
|
||||
//| music = audiocore.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb"))
|
||||
//| drum = audiocore.WaveFile(open("drum.wav", "rb"))
|
||||
//| mixer = audiomixer.Mixer(voice_count=2, sample_rate=16000, channel_count=1,
|
||||
//| bits_per_sample=16, samples_signed=True)
|
||||
//|
|
||||
//| print("playing")
|
||||
//| # Have AudioOut play our Mixer source
|
||||
//| a.play(mixer)
|
||||
//| # Play the first sample voice
|
||||
//| mixer.voice[0].play(music)
|
||||
//| while mixer.playing:
|
||||
//| # Play the second sample voice
|
||||
//| mixer.voice[1].play(drum)
|
||||
//| time.sleep(1)
|
||||
//| print("stopped")
|
||||
//| print("playing")
|
||||
//| # Have AudioOut play our Mixer source
|
||||
//| a.play(mixer)
|
||||
//| # Play the first sample voice
|
||||
//| mixer.voice[0].play(music)
|
||||
//| while mixer.playing:
|
||||
//| # Play the second sample voice
|
||||
//| mixer.voice[1].play(drum)
|
||||
//| time.sleep(1)
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate };
|
||||
|
@ -125,9 +121,9 @@ STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the Mixer and releases any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -142,16 +138,16 @@ STATIC void check_for_deinit(audiomixer_mixer_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -160,9 +156,8 @@ STATIC mp_obj_t audiomixer_mixer_obj___exit__(size_t n_args, const mp_obj_t *arg
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomixer_mixer___exit___obj, 4, 4, audiomixer_mixer_obj___exit__);
|
||||
|
||||
//| .. attribute:: playing
|
||||
//|
|
||||
//| True when any voice is being output. (read-only)
|
||||
//| playing: Any = ...
|
||||
//| """True when any voice is being output. (read-only)"""
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_obj_get_playing(mp_obj_t self_in) {
|
||||
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -178,9 +173,8 @@ const mp_obj_property_t audiomixer_mixer_playing_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: sample_rate
|
||||
//|
|
||||
//| 32 bit value that dictates how quickly samples are played in Hertz (cycles per second).
|
||||
//| sample_rate: Any = ...
|
||||
//| """32 bit value that dictates how quickly samples are played in Hertz (cycles per second)."""
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixer_obj_get_sample_rate(mp_obj_t self_in) {
|
||||
audiomixer_mixer_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -196,14 +190,13 @@ const mp_obj_property_t audiomixer_mixer_sample_rate_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: voice
|
||||
//|
|
||||
//| A tuple of the mixer's `audiomixer.MixerVoice` object(s).
|
||||
//| voice: Any = ...
|
||||
//| """A tuple of the mixer's `audiomixer.MixerVoice` object(s).
|
||||
//|
|
||||
//| .. code-block:: python
|
||||
//|
|
||||
//| >>> mixer.voice
|
||||
//| (<MixerVoice>,)
|
||||
//| (<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);
|
||||
|
@ -218,14 +211,14 @@ const mp_obj_property_t audiomixer_mixer_voice_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: play(sample, *, voice=0, loop=False)
|
||||
//| def play(self, sample: Any, *, voice: Any = 0, loop: Any = False) -> Any:
|
||||
//| """Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//|
|
||||
//| Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| The sample must match the Mixer's encoding settings given in the constructor.
|
||||
//| 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 };
|
||||
|
@ -251,9 +244,9 @@ STATIC mp_obj_t audiomixer_mixer_obj_play(size_t n_args, const mp_obj_t *pos_arg
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixer_play_obj, 1, audiomixer_mixer_obj_play);
|
||||
|
||||
//| .. method:: stop_voice(voice=0)
|
||||
//|
|
||||
//| Stops playback of the sample on the given voice.
|
||||
//| def stop_voice(self, voice: Any = 0) -> Any:
|
||||
//| """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 };
|
||||
|
|
|
@ -37,16 +37,14 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiomixer
|
||||
//| class MixerVoice:
|
||||
//| """Voice objects used with Mixer
|
||||
//|
|
||||
//| :class:`MixerVoice` -- Voice objects used with Mixer
|
||||
//| =====================================================
|
||||
//| Used to access and control samples with `audiomixer.Mixer`."""
|
||||
//|
|
||||
//| Used to access and control samples with `audiomixer.Mixer`.
|
||||
//|
|
||||
//| .. class:: MixerVoice()
|
||||
//|
|
||||
//| MixerVoice instance object(s) created by `audiomixer.Mixer`.
|
||||
//| def __init__(self, ):
|
||||
//| """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, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
@ -58,14 +56,14 @@ STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: play(sample, *, loop=False)
|
||||
//| def play(self, sample: Any, *, loop: Any = False) -> Any:
|
||||
//| """Plays the sample once when ``loop=False``, and continuously when ``loop=True``.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//|
|
||||
//| Plays the sample once when ``loop=False``, and continuously when ``loop=True``.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiomixer.Mixer` or `audiocore.RawSample`.
|
||||
//|
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiomixer.Mixer` or `audiocore.RawSample`.
|
||||
//|
|
||||
//| The sample must match the `audiomixer.Mixer`'s encoding settings given in the constructor.
|
||||
//| 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 };
|
||||
|
@ -83,9 +81,9 @@ STATIC mp_obj_t audiomixer_mixervoice_obj_play(size_t n_args, const mp_obj_t *po
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_play_obj, 1, audiomixer_mixervoice_obj_play);
|
||||
|
||||
//| .. method:: stop()
|
||||
//|
|
||||
//| Stops playback of the sample on this voice.
|
||||
//| def stop(self, ) -> Any:
|
||||
//| """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 };
|
||||
|
@ -102,9 +100,8 @@ STATIC mp_obj_t audiomixer_mixervoice_obj_stop(size_t n_args, const mp_obj_t *po
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiomixer_mixervoice_stop_obj, 1, audiomixer_mixervoice_obj_stop);
|
||||
|
||||
//| .. attribute:: level()
|
||||
//|
|
||||
//| The volume level of a voice, as a floating point number between 0 and 1.
|
||||
//| level: Any = ...
|
||||
//| """The volume level of a voice, as a floating point number between 0 and 1."""
|
||||
//|
|
||||
STATIC mp_obj_t audiomixer_mixervoice_obj_get_level(mp_obj_t self_in) {
|
||||
return mp_obj_new_float(common_hal_audiomixer_mixervoice_get_level(self_in));
|
||||
|
@ -139,9 +136,8 @@ const mp_obj_property_t audiomixer_mixervoice_level_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: playing
|
||||
//|
|
||||
//| True when this voice is being output. (read-only)
|
||||
//| playing: Any = ...
|
||||
//| """True when this voice is being output. (read-only)"""
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t audiomixer_mixervoice_obj_get_playing(mp_obj_t self_in) {
|
||||
|
|
|
@ -32,21 +32,7 @@
|
|||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/audiomixer/Mixer.h"
|
||||
|
||||
//| :mod:`audiomixer` --- Support for audio mixer
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: audiomixer
|
||||
//| :synopsis: Support for audio mixer
|
||||
//|
|
||||
//| The `audiomixer` module contains core classes for mixing audio sources
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Mixer
|
||||
//| MixerVoice
|
||||
//| """Support for audio mixing"""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audiomixer_module_globals_table[] = {
|
||||
|
|
|
@ -34,41 +34,38 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiomp3
|
||||
//| class MP3:
|
||||
//| """Load a mp3 file for audio playback"""
|
||||
//|
|
||||
//| :class:`MP3Decoder` -- Load a mp3 file for audio playback
|
||||
//| =========================================================
|
||||
//| def __init__(self, file: typing.BinaryIO, buffer: bytearray):
|
||||
//|
|
||||
//| An object that decodes MP3 files for playback on an audio device.
|
||||
//| """Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
|
||||
//|
|
||||
//| .. class:: MP3(file[, buffer])
|
||||
//|
|
||||
//| Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`.
|
||||
//|
|
||||
//| :param typing.BinaryIO file: Already opened mp3 file
|
||||
//| :param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two buffers are allocated internally. The specific buffer size required depends on the mp3 file.
|
||||
//| :param typing.BinaryIO file: Already opened mp3 file
|
||||
//| :param bytearray buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two buffers are allocated internally. The specific buffer size required depends on the mp3 file.
|
||||
//|
|
||||
//|
|
||||
//| Playing a mp3 file from flash::
|
||||
//| Playing a mp3 file from flash::
|
||||
//|
|
||||
//| import board
|
||||
//| import audiomp3
|
||||
//| import audioio
|
||||
//| import digitalio
|
||||
//| import board
|
||||
//| import audiomp3
|
||||
//| import audioio
|
||||
//| import digitalio
|
||||
//|
|
||||
//| # Required for CircuitPlayground Express
|
||||
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
|
||||
//| speaker_enable.switch_to_output(value=True)
|
||||
//| # Required for CircuitPlayground Express
|
||||
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
|
||||
//| speaker_enable.switch_to_output(value=True)
|
||||
//|
|
||||
//| data = open("cplay-16bit-16khz-64kbps.mp3", "rb")
|
||||
//| mp3 = audiomp3.MP3Decoder(data)
|
||||
//| a = audioio.AudioOut(board.A0)
|
||||
//| data = open("cplay-16bit-16khz-64kbps.mp3", "rb")
|
||||
//| mp3 = audiomp3.MP3Decoder(data)
|
||||
//| a = audioio.AudioOut(board.A0)
|
||||
//|
|
||||
//| print("playing")
|
||||
//| a.play(mp3)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")
|
||||
//| print("playing")
|
||||
//| a.play(mp3)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 2, false);
|
||||
|
@ -92,9 +89,9 @@ STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the MP3 and releases all memory resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -109,16 +106,16 @@ STATIC void check_for_deinit(audiomp3_mp3file_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -127,9 +124,8 @@ STATIC mp_obj_t audiomp3_mp3file_obj___exit__(size_t n_args, const mp_obj_t *arg
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiomp3_mp3file___exit___obj, 4, 4, audiomp3_mp3file_obj___exit__);
|
||||
|
||||
//| .. attribute:: file
|
||||
//|
|
||||
//| File to play back.
|
||||
//| file: Any = ...
|
||||
//| """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);
|
||||
|
@ -158,11 +154,10 @@ const mp_obj_property_t audiomp3_mp3file_file_obj = {
|
|||
|
||||
|
||||
|
||||
//| .. attribute:: sample_rate
|
||||
//|
|
||||
//| 32 bit value that dictates how quickly samples are loaded into the DAC
|
||||
//| sample_rate: Any = ...
|
||||
//| """32 bit value that dictates how quickly samples are loaded into the DAC
|
||||
//| in Hertz (cycles per second). When the sample is looped, this can change
|
||||
//| the pitch output without changing the underlying sample.
|
||||
//| the pitch output without changing the underlying sample."""
|
||||
//|
|
||||
STATIC mp_obj_t audiomp3_mp3file_obj_get_sample_rate(mp_obj_t self_in) {
|
||||
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -186,9 +181,8 @@ const mp_obj_property_t audiomp3_mp3file_sample_rate_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: bits_per_sample
|
||||
//|
|
||||
//| Bits per sample. (read only)
|
||||
//| bits_per_sample: Any = ...
|
||||
//| """Bits per sample. (read only)"""
|
||||
//|
|
||||
STATIC mp_obj_t audiomp3_mp3file_obj_get_bits_per_sample(mp_obj_t self_in) {
|
||||
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -204,9 +198,8 @@ const mp_obj_property_t audiomp3_mp3file_bits_per_sample_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: channel_count
|
||||
//|
|
||||
//| Number of audio channels. (read only)
|
||||
//| channel_count: Any = ...
|
||||
//| """Number of audio channels. (read only)"""
|
||||
//|
|
||||
STATIC mp_obj_t audiomp3_mp3file_obj_get_channel_count(mp_obj_t self_in) {
|
||||
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -222,9 +215,8 @@ const mp_obj_property_t audiomp3_mp3file_channel_count_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: rms_level
|
||||
//|
|
||||
//| The RMS audio level of a recently played moment of audio. (read only)
|
||||
//| rms_level: Any = ...
|
||||
//| """The RMS audio level of a recently played moment of audio. (read only)"""
|
||||
//|
|
||||
STATIC mp_obj_t audiomp3_mp3file_obj_get_rms_level(mp_obj_t self_in) {
|
||||
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -31,20 +31,7 @@
|
|||
|
||||
#include "shared-bindings/audiomp3/MP3Decoder.h"
|
||||
|
||||
//| :mod:`audiomp3` --- Support for MP3-compressed audio files
|
||||
//| ==========================================================
|
||||
//|
|
||||
//| .. module:: audiomp3
|
||||
//| :synopsis: Support for mp3 files
|
||||
//|
|
||||
//| The `audiomp3` module contains an mp3 decoder
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| MP3Decoder
|
||||
//| """Support for MP3-compressed audio files"""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audiomp3_module_globals_table[] = {
|
||||
|
|
|
@ -36,66 +36,62 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiopwmio
|
||||
//| class PWMAudioOut:
|
||||
//| """Output an analog audio signal by varying the PWM duty cycle."""
|
||||
//|
|
||||
//| :class:`PWMAudioOut` -- Output an analog audio signal
|
||||
//| ========================================================
|
||||
//| def __init__(self, left_channel: microcontroller.Pin, *, right_channel: microcontroller.Pin = None, quiescent_value: int = 0x8000):
|
||||
//| """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`,
|
||||
//| the pin(s) specified are digital pins, and are driven with a device-dependent PWM
|
||||
//| signal.
|
||||
//|
|
||||
//| AudioOut can be used to output an analog audio signal on a given pin.
|
||||
//| :param ~microcontroller.Pin left_channel: The pin to output the left channel to
|
||||
//| :param ~microcontroller.Pin right_channel: The pin to output the right channel to
|
||||
//| :param int quiescent_value: The output value when no signal is present. Samples should start
|
||||
//| and end with this value to prevent audible popping.
|
||||
//|
|
||||
//| .. class:: PWMAudioOut(left_channel, *, right_channel=None, quiescent_value=0x8000)
|
||||
//| Simple 8ksps 440 Hz sin wave::
|
||||
//|
|
||||
//| 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`,
|
||||
//| the pin(s) specified are digital pins, and are driven with a device-dependent PWM
|
||||
//| signal.
|
||||
//| import audiocore
|
||||
//| import audiopwmio
|
||||
//| import board
|
||||
//| import array
|
||||
//| import time
|
||||
//| import math
|
||||
//|
|
||||
//| :param ~microcontroller.Pin left_channel: The pin to output the left channel to
|
||||
//| :param ~microcontroller.Pin right_channel: The pin to output the right channel to
|
||||
//| :param int quiescent_value: The output value when no signal is present. Samples should start
|
||||
//| and end with this value to prevent audible popping.
|
||||
//| # Generate one period of sine wav.
|
||||
//| length = 8000 // 440
|
||||
//| sine_wave = array.array("H", [0] * length)
|
||||
//| for i in range(length):
|
||||
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
|
||||
//|
|
||||
//| Simple 8ksps 440 Hz sin wave::
|
||||
//| dac = audiopwmio.PWMAudioOut(board.SPEAKER)
|
||||
//| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
|
||||
//| dac.play(sine_wave, loop=True)
|
||||
//| time.sleep(1)
|
||||
//| dac.stop()
|
||||
//|
|
||||
//| import audiocore
|
||||
//| import audiopwmio
|
||||
//| import board
|
||||
//| import array
|
||||
//| import time
|
||||
//| import math
|
||||
//| Playing a wave file from flash::
|
||||
//|
|
||||
//| # Generate one period of sine wav.
|
||||
//| length = 8000 // 440
|
||||
//| sine_wave = array.array("H", [0] * length)
|
||||
//| for i in range(length):
|
||||
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
|
||||
//| import board
|
||||
//| import audiocore
|
||||
//| import audiopwmio
|
||||
//| import digitalio
|
||||
//|
|
||||
//| dac = audiopwmio.PWMAudioOut(board.SPEAKER)
|
||||
//| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
|
||||
//| dac.play(sine_wave, loop=True)
|
||||
//| time.sleep(1)
|
||||
//| dac.stop()
|
||||
//| # Required for CircuitPlayground Express
|
||||
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
|
||||
//| speaker_enable.switch_to_output(value=True)
|
||||
//|
|
||||
//| Playing a wave file from flash::
|
||||
//| data = open("cplay-5.1-16bit-16khz.wav", "rb")
|
||||
//| wav = audiocore.WaveFile(data)
|
||||
//| a = audiopwmio.PWMAudioOut(board.SPEAKER)
|
||||
//|
|
||||
//| import board
|
||||
//| import audiocore
|
||||
//| import audiopwmio
|
||||
//| import digitalio
|
||||
//|
|
||||
//| # Required for CircuitPlayground Express
|
||||
//| speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
|
||||
//| speaker_enable.switch_to_output(value=True)
|
||||
//|
|
||||
//| data = open("cplay-5.1-16bit-16khz.wav", "rb")
|
||||
//| wav = audiocore.WaveFile(data)
|
||||
//| a = audiopwmio.PWMAudioOut(board.SPEAKER)
|
||||
//|
|
||||
//| print("playing")
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")
|
||||
//| print("playing")
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
|
||||
|
@ -118,9 +114,9 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the PWMAudioOut and releases any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -134,17 +130,16 @@ STATIC void check_for_deinit(audiopwmio_pwmaudioout_obj_t *self) {
|
|||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//|
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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]);
|
||||
|
@ -153,16 +148,16 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_obj___exit__(size_t n_args, const mp_obj_
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiopwmio_pwmaudioout___exit___obj, 4, 4, audiopwmio_pwmaudioout_obj___exit__);
|
||||
|
||||
|
||||
//| .. method:: play(sample, *, loop=False)
|
||||
//| def play(self, sample: Any, *, loop: Any = False) -> Any:
|
||||
//| """Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//|
|
||||
//| Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| The sample itself should consist of 16 bit samples. Microcontrollers with a lower output
|
||||
//| 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.
|
||||
//| The sample itself should consist of 16 bit samples. Microcontrollers with a lower output
|
||||
//| 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 audiopwmio_pwmaudioout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_sample, ARG_loop };
|
||||
|
@ -182,9 +177,9 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_obj_play(size_t n_args, const mp_obj_t *p
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiopwmio_pwmaudioout_play_obj, 1, audiopwmio_pwmaudioout_obj_play);
|
||||
|
||||
//| .. method:: stop()
|
||||
//|
|
||||
//| Stops playback and resets to the start of the sample.
|
||||
//| def stop(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -194,9 +189,8 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_obj_stop(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiopwmio_pwmaudioout_stop_obj, audiopwmio_pwmaudioout_obj_stop);
|
||||
|
||||
//| .. attribute:: playing
|
||||
//|
|
||||
//| True when an audio sample is being output even if `paused`. (read-only)
|
||||
//| playing: Any = ...
|
||||
//| """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);
|
||||
|
@ -212,9 +206,9 @@ const mp_obj_property_t audiopwmio_pwmaudioout_playing_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: pause()
|
||||
//|
|
||||
//| Stops playback temporarily while remembering the position. Use `resume` to resume playback.
|
||||
//| def pause(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -228,9 +222,9 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_obj_pause(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiopwmio_pwmaudioout_pause_obj, audiopwmio_pwmaudioout_obj_pause);
|
||||
|
||||
//| .. method:: resume()
|
||||
//|
|
||||
//| Resumes sample playback after :py:func:`pause`.
|
||||
//| def resume(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -244,9 +238,8 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_obj_resume(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiopwmio_pwmaudioout_resume_obj, audiopwmio_pwmaudioout_obj_resume);
|
||||
|
||||
//| .. attribute:: paused
|
||||
//|
|
||||
//| True when playback is paused. (read-only)
|
||||
//| paused: Any = ...
|
||||
//| """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);
|
||||
|
|
|
@ -33,29 +33,17 @@
|
|||
#include "shared-bindings/audiopwmio/__init__.h"
|
||||
#include "shared-bindings/audiopwmio/PWMAudioOut.h"
|
||||
|
||||
//| :mod:`audiopwmio` --- Support for audio input and output
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: audiopwmio
|
||||
//| :synopsis: Support for audio output via digital PWM
|
||||
//| :platform: NRF52
|
||||
//| """Audio output via digital PWM
|
||||
//|
|
||||
//| The `audiopwmio` module contains classes to provide access to audio IO.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| PWMAudioOut
|
||||
//|
|
||||
//| All classes change hardware state and should be deinitialized when they
|
||||
//| are no longer needed if the program continues after use. To do so, either
|
||||
//| call :py:meth:`!deinit` or use a context manager. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//|
|
||||
//| Since CircuitPython 5, `Mixer`, `RawSample` and `WaveFile` are moved
|
||||
//| to :mod:`audiocore`.
|
||||
//| to :mod:`audiocore`."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t audiopwmio_module_globals_table[] = {
|
||||
|
|
|
@ -37,21 +37,19 @@
|
|||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: bitbangio
|
||||
//| class I2C:
|
||||
//| """Two wire serial protocol"""
|
||||
//|
|
||||
//| :class:`I2C` --- Two wire serial protocol
|
||||
//| ------------------------------------------
|
||||
//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, *, frequency: int = 400000, timeout: int):
|
||||
//| """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
|
||||
//| lines respectively.
|
||||
//|
|
||||
//| .. class:: I2C(scl, sda, *, frequency=400000, timeout)
|
||||
//|
|
||||
//| 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
|
||||
//| lines respectively.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin scl: The clock pin
|
||||
//| :param ~microcontroller.Pin sda: The data pin
|
||||
//| :param int frequency: The clock frequency of the bus
|
||||
//| :param int timeout: The maximum clock stretching timeout in microseconds
|
||||
//| :param ~microcontroller.Pin scl: The clock pin
|
||||
//| :param ~microcontroller.Pin sda: The data pin
|
||||
//| :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, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
|
||||
|
@ -73,9 +71,9 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Releases control of the underlying hardware so other classes can use it.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -90,16 +88,16 @@ STATIC void check_for_deinit(bitbangio_i2c_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used in Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used in Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware on context exit. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -114,11 +112,11 @@ static void check_lock(bitbangio_i2c_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: scan()
|
||||
//|
|
||||
//| Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of
|
||||
//| 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.
|
||||
//| def scan(self, ) -> Any:
|
||||
//| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of
|
||||
//| 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);
|
||||
|
@ -136,9 +134,9 @@ STATIC mp_obj_t bitbangio_i2c_scan(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_scan_obj, bitbangio_i2c_scan);
|
||||
|
||||
//| .. method:: try_lock()
|
||||
//|
|
||||
//| Attempts to grab the I2C lock. Returns True on success.
|
||||
//| def try_lock(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -147,9 +145,9 @@ STATIC mp_obj_t bitbangio_i2c_obj_try_lock(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_try_lock_obj, bitbangio_i2c_obj_try_lock);
|
||||
|
||||
//| .. method:: unlock()
|
||||
//|
|
||||
//| Releases the I2C lock.
|
||||
//| def unlock(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -159,20 +157,20 @@ 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);
|
||||
|
||||
//| .. method:: readfrom_into(address, buffer, *, start=0, end=None)
|
||||
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> Any:
|
||||
//| """Read into ``buffer`` from the slave specified by ``address``.
|
||||
//| The number of bytes read will be the length of ``buffer``.
|
||||
//| At least one byte must be read.
|
||||
//|
|
||||
//| Read into ``buffer`` from the slave specified by ``address``.
|
||||
//| The number of bytes read will be the length of ``buffer``.
|
||||
//| At least one byte must be read.
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buf[start:end]`` will so it saves memory.
|
||||
//|
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buf[start:end]`` will so it saves memory.
|
||||
//|
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray buffer: buffer to write into
|
||||
//| :param int start: Index to start writing at
|
||||
//| :param int end: Index to write up to but not include
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray buffer: buffer to write into
|
||||
//| :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) {
|
||||
|
@ -211,25 +209,25 @@ 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, 3, bitbangio_i2c_readfrom_into);
|
||||
|
||||
//| .. method:: writeto(address, buffer, *, start=0, end=None, stop=True)
|
||||
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> Any:
|
||||
//| """Write the bytes from ``buffer`` to the slave specified by ``address`` and then transmits a
|
||||
//| stop bit. Use `writeto_then_readfrom` when needing a write, no stop and repeated start
|
||||
//| before a read.
|
||||
//|
|
||||
//| Write the bytes from ``buffer`` to the slave specified by ``address`` and then transmits a
|
||||
//| stop bit. Use `writeto_then_readfrom` when needing a write, no stop and repeated start
|
||||
//| before a read.
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buffer[start:end]`` will so it saves memory.
|
||||
//|
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buffer[start:end]`` will so it saves memory.
|
||||
//| Writing a buffer or slice of length zero is permitted, as it can be used
|
||||
//| to poll for the existence of a device.
|
||||
//|
|
||||
//| Writing a buffer or slice of length zero is permitted, as it can be used
|
||||
//| to poll for the existence of a device.
|
||||
//|
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray buffer: buffer containing the bytes to write
|
||||
//| :param int start: Index to start writing from
|
||||
//| :param int end: Index to read up to but not include
|
||||
//| :param bool stop: If true, output an I2C stop condition after the buffer is written.
|
||||
//| Deprecated. Will be removed in 6.x and act as stop=True.
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray buffer: buffer containing the bytes to write
|
||||
//| :param int start: Index to start writing from
|
||||
//| :param int end: Index to read up to but not include
|
||||
//| :param bool stop: If true, output an I2C stop condition after the buffer is written.
|
||||
//| Deprecated. Will be removed in 6.x and act as stop=True."""
|
||||
//| ...
|
||||
//|
|
||||
// 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) {
|
||||
|
@ -271,23 +269,22 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_writeto);
|
||||
|
||||
|
||||
//| .. method:: writeto_then_readfrom(address, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None)
|
||||
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> Any:
|
||||
//| """Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop
|
||||
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
|
||||
//| ``in_buffer`` can be the same buffer because they are used sequentially.
|
||||
//|
|
||||
//| Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop
|
||||
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
|
||||
//| ``in_buffer`` can be the same buffer because they are used sequentially.
|
||||
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
|
||||
//| will so it saves memory.
|
||||
//|
|
||||
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
|
||||
//| will so it saves memory.
|
||||
//|
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray out_buffer: buffer containing the bytes to write
|
||||
//| :param bytearray in_buffer: buffer to write into
|
||||
//| :param int out_start: Index to start writing from
|
||||
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param int in_start: Index to start writing at
|
||||
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray out_buffer: buffer containing the bytes to write
|
||||
//| :param bytearray in_buffer: buffer to write into
|
||||
//| :param int out_start: Index to start writing from
|
||||
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param int in_start: Index to start writing at
|
||||
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
|
||||
//|
|
||||
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 };
|
||||
|
|
|
@ -34,33 +34,32 @@
|
|||
#include "shared-bindings/bitbangio/OneWire.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| .. currentmodule:: bitbangio
|
||||
//| class OneWire:
|
||||
//| """Lowest-level of the Maxim OneWire protocol
|
||||
//|
|
||||
//| :class:`OneWire` -- Lowest-level of the Maxim OneWire protocol
|
||||
//| ===============================================================
|
||||
//| :class:`~bitbangio.OneWire` implements the timing-sensitive foundation of
|
||||
//| the Maxim (formerly Dallas Semi) OneWire protocol.
|
||||
//|
|
||||
//| :class:`~bitbangio.OneWire` implements the timing-sensitive foundation of
|
||||
//| the Maxim (formerly Dallas Semi) OneWire protocol.
|
||||
//| Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126"""
|
||||
//|
|
||||
//| Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126
|
||||
//| def __init__(self, pin: microcontroller.Pin):
|
||||
//|
|
||||
//| .. class:: OneWire(pin)
|
||||
//| """Create a OneWire object associated with the given pin. The object
|
||||
//| implements the lowest level timing-sensitive bits of the protocol.
|
||||
//|
|
||||
//| Create a OneWire object associated with the given pin. The object
|
||||
//| implements the lowest level timing-sensitive bits of the protocol.
|
||||
//| :param ~microcontroller.Pin pin: Pin to read pulses from.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin pin: Pin to read pulses from.
|
||||
//| Read a short series of pulses::
|
||||
//|
|
||||
//| Read a short series of pulses::
|
||||
//| import bitbangio
|
||||
//| import board
|
||||
//|
|
||||
//| import bitbangio
|
||||
//| import board
|
||||
//|
|
||||
//| onewire = bitbangio.OneWire(board.D7)
|
||||
//| onewire.reset()
|
||||
//| onewire.write_bit(True)
|
||||
//| onewire.write_bit(False)
|
||||
//| print(onewire.read_bit())
|
||||
//| onewire = bitbangio.OneWire(board.D7)
|
||||
//| onewire.reset()
|
||||
//| onewire.write_bit(True)
|
||||
//| onewire.write_bit(False)
|
||||
//| print(onewire.read_bit())"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin };
|
||||
|
@ -79,9 +78,9 @@ STATIC mp_obj_t bitbangio_onewire_make_new(const mp_obj_type_t *type, size_t n_a
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialize the OneWire bus and release any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialize the OneWire bus and release any hardware resources for reuse."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bitbangio_onewire_deinit(mp_obj_t self_in) {
|
||||
bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -96,16 +95,16 @@ STATIC void check_for_deinit(bitbangio_onewire_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bitbangio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
|
@ -114,9 +113,9 @@ STATIC mp_obj_t bitbangio_onewire_obj___exit__(size_t n_args, const mp_obj_t *ar
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_onewire___exit___obj, 4, 4, bitbangio_onewire_obj___exit__);
|
||||
|
||||
//| .. method:: reset()
|
||||
//|
|
||||
//| Reset the OneWire bus
|
||||
//| def reset(self, ) -> Any:
|
||||
//| """Reset the OneWire bus"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bitbangio_onewire_obj_reset(mp_obj_t self_in) {
|
||||
bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -126,12 +125,12 @@ STATIC mp_obj_t bitbangio_onewire_obj_reset(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_reset_obj, bitbangio_onewire_obj_reset);
|
||||
|
||||
//| .. method:: read_bit()
|
||||
//| def read_bit(self, ) -> Any:
|
||||
//| """Read in a bit
|
||||
//|
|
||||
//| Read in a bit
|
||||
//|
|
||||
//| :returns: bit state read
|
||||
//| :rtype: bool
|
||||
//| :returns: bit state read
|
||||
//| :rtype: bool"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bitbangio_onewire_obj_read_bit(mp_obj_t self_in) {
|
||||
bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -141,9 +140,9 @@ STATIC mp_obj_t bitbangio_onewire_obj_read_bit(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_onewire_read_bit_obj, bitbangio_onewire_obj_read_bit);
|
||||
|
||||
//| .. method:: write_bit(value)
|
||||
//|
|
||||
//| Write out a bit based on value.
|
||||
//| def write_bit(self, value: Any) -> Any:
|
||||
//| """Write out a bit based on value."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bitbangio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) {
|
||||
bitbangio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -39,26 +39,24 @@
|
|||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: bitbangio
|
||||
//| class SPI:
|
||||
//| """A 3-4 wire serial protocol
|
||||
//|
|
||||
//| :class:`SPI` -- a 3-4 wire serial protocol
|
||||
//| -----------------------------------------------
|
||||
//| SPI is a serial protocol that has exclusive pins for data in and out of the
|
||||
//| master. It is typically faster than :py:class:`~bitbangio.I2C` because a
|
||||
//| separate pin is used to control the active slave rather than a transmitted
|
||||
//| address. This class only manages three of the four SPI lines: `!clock`,
|
||||
//| `!MOSI`, `!MISO`. Its up to the client to manage the appropriate slave
|
||||
//| select line. (This is common because multiple slaves can share the `!clock`,
|
||||
//| `!MOSI` and `!MISO` lines and therefore the hardware.)"""
|
||||
//|
|
||||
//| SPI is a serial protocol that has exclusive pins for data in and out of the
|
||||
//| master. It is typically faster than :py:class:`~bitbangio.I2C` because a
|
||||
//| separate pin is used to control the active slave rather than a transmitted
|
||||
//| address. This class only manages three of the four SPI lines: `!clock`,
|
||||
//| `!MOSI`, `!MISO`. Its up to the client to manage the appropriate slave
|
||||
//| select line. (This is common because multiple slaves can share the `!clock`,
|
||||
//| `!MOSI` and `!MISO` lines and therefore the hardware.)
|
||||
//| def __init__(self, clock: microcontroller.Pin, MOSI: microcontroller.Pin = None, MISO: microcontroller.Pin = None):
|
||||
//| """Construct an SPI object on the given pins.
|
||||
//|
|
||||
//| .. class:: SPI(clock, MOSI=None, MISO=None)
|
||||
//|
|
||||
//| Construct an SPI object on the given pins.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin clock: the pin to use for the clock.
|
||||
//| :param ~microcontroller.Pin MOSI: the Master Out Slave In pin.
|
||||
//| :param ~microcontroller.Pin MISO: the Master In Slave Out pin.
|
||||
//| :param ~microcontroller.Pin clock: the pin to use for the clock.
|
||||
//| :param ~microcontroller.Pin MOSI: the Master Out Slave In pin.
|
||||
//| :param ~microcontroller.Pin MISO: the Master In Slave Out pin."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
// TODO(tannewt): Support LSB SPI.
|
||||
|
@ -82,9 +80,9 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Turn off the SPI bus.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -99,16 +97,16 @@ STATIC void check_for_deinit(bitbangio_spi_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -124,15 +122,15 @@ static void check_lock(bitbangio_spi_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: configure(*, baudrate=100000, polarity=0, phase=0, bits=8)
|
||||
//| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> Any:
|
||||
//| """Configures the SPI bus. Only valid when locked.
|
||||
//|
|
||||
//| Configures the SPI bus. Only valid when locked.
|
||||
//|
|
||||
//| :param int baudrate: the clock rate in Hertz
|
||||
//| :param int polarity: the base state of the clock line (0 or 1)
|
||||
//| :param int phase: the edge of the clock that data is captured. First (0)
|
||||
//| or second (1). Rising or falling depends on clock polarity.
|
||||
//| :param int bits: the number of bits per word
|
||||
//| :param int baudrate: the clock rate in Hertz
|
||||
//| :param int polarity: the base state of the clock line (0 or 1)
|
||||
//| :param int phase: the edge of the clock that data is captured. First (0)
|
||||
//| 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 };
|
||||
|
@ -166,12 +164,12 @@ STATIC mp_obj_t bitbangio_spi_configure(size_t n_args, const mp_obj_t *pos_args,
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_spi_configure_obj, 1, bitbangio_spi_configure);
|
||||
|
||||
//| .. method:: try_lock()
|
||||
//| def try_lock(self, ) -> Any:
|
||||
//| """Attempts to grab the SPI lock. Returns True on success.
|
||||
//|
|
||||
//| Attempts to grab the SPI lock. Returns True on success.
|
||||
//|
|
||||
//| :return: True when lock has been grabbed
|
||||
//| :rtype: bool
|
||||
//| :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);
|
||||
|
@ -180,9 +178,9 @@ STATIC mp_obj_t bitbangio_spi_obj_try_lock(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_try_lock_obj, bitbangio_spi_obj_try_lock);
|
||||
|
||||
//| .. method:: unlock()
|
||||
//|
|
||||
//| Releases the SPI lock.
|
||||
//| def unlock(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -192,10 +190,10 @@ 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);
|
||||
|
||||
//| .. method:: write(buf)
|
||||
//|
|
||||
//| Write the data contained in ``buf``. Requires the SPI being locked.
|
||||
//| If the buffer is empty, nothing happens.
|
||||
//| def write(self, buf: Any) -> Any:
|
||||
//| """Write the data contained in ``buf``. Requires the SPI being locked.
|
||||
//| If the buffer is empty, nothing happens."""
|
||||
//| ...
|
||||
//|
|
||||
// TODO(tannewt): Add support for start and end kwargs.
|
||||
STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) {
|
||||
|
@ -216,11 +214,11 @@ STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) {
|
|||
MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_spi_write_obj, bitbangio_spi_write);
|
||||
|
||||
|
||||
//| .. method:: readinto(buf)
|
||||
//|
|
||||
//| Read into the buffer specified by ``buf`` while writing zeroes.
|
||||
//| Requires the SPI being locked.
|
||||
//| If the number of bytes to read is 0, nothing happens.
|
||||
//| def readinto(self, buf: Any) -> Any:
|
||||
//| """Read into the buffer specified by ``buf`` while writing zeroes.
|
||||
//| Requires the SPI being locked.
|
||||
//| If the number of bytes to read is 0, nothing happens."""
|
||||
//| ...
|
||||
//|
|
||||
// TODO(tannewt): Add support for start and end kwargs.
|
||||
STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) {
|
||||
|
@ -240,19 +238,19 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_readinto_obj, 2, 2, bitbangio_spi_readinto);
|
||||
|
||||
//| .. method:: write_readinto(buffer_out, buffer_in, *, out_start=0, out_end=None, in_start=0, in_end=None)
|
||||
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: Any = 0, out_end: int = None, in_start: Any = 0, in_end: int = None) -> Any:
|
||||
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
|
||||
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
|
||||
//| must be equal.
|
||||
//| If buffer slice lengths are both 0, nothing happens.
|
||||
//|
|
||||
//| Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
|
||||
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
|
||||
//| must be equal.
|
||||
//| If buffer slice lengths are both 0, nothing happens.
|
||||
//|
|
||||
//| :param bytearray buffer_out: Write out the data in this buffer
|
||||
//| :param bytearray buffer_in: Read data into this buffer
|
||||
//| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
|
||||
//| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)``
|
||||
//| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
|
||||
//| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)``
|
||||
//| :param bytearray buffer_out: Write out the data in this buffer
|
||||
//| :param bytearray buffer_in: Read data into this buffer
|
||||
//| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
|
||||
//| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)``
|
||||
//| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
|
||||
//| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)``"""
|
||||
//| ...
|
||||
//|
|
||||
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_buffer_out, ARG_buffer_in, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
|
||||
|
|
|
@ -40,12 +40,7 @@
|
|||
|
||||
#include "py/runtime.h"
|
||||
|
||||
//| :mod:`bitbangio` --- Digital protocols implemented by the CPU
|
||||
//| =============================================================
|
||||
//|
|
||||
//| .. module:: bitbangio
|
||||
//| :synopsis: Digital protocols implemented by the CPU
|
||||
//| :platform: SAMD21, ESP8266
|
||||
//| """Digital protocols implemented by the CPU
|
||||
//|
|
||||
//| The `bitbangio` module contains classes to provide digital bus protocol
|
||||
//| support regardless of whether the underlying hardware exists to use the
|
||||
|
@ -55,15 +50,6 @@
|
|||
//| hardware to implement the protocols. Native implementations will be faster
|
||||
//| than bitbanged versions and have more capabilities.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| I2C
|
||||
//| OneWire
|
||||
//| SPI
|
||||
//|
|
||||
//| All classes change hardware state and should be deinitialized when they
|
||||
//| are no longer needed if the program continues after use. To do so, either
|
||||
//| call :py:meth:`!deinit` or use a context manager. See
|
||||
|
@ -81,7 +67,7 @@
|
|||
//| This example will initialize the the device, run
|
||||
//| :py:meth:`~bitbangio.I2C.scan` and then :py:meth:`~bitbangio.I2C.deinit` the
|
||||
//| hardware. The last step is optional because CircuitPython automatically
|
||||
//| resets hardware after a program finishes.
|
||||
//| resets hardware after a program finishes."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t bitbangio_module_globals_table[] = {
|
||||
|
|
|
@ -29,21 +29,17 @@
|
|||
|
||||
#include "shared-bindings/board/__init__.h"
|
||||
|
||||
//| :mod:`board` --- Board specific pin names
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: board
|
||||
//| :synopsis: Board specific pin names
|
||||
//| """Board specific pin names
|
||||
//|
|
||||
//| Common container for board base pin names. These will vary from board to
|
||||
//| board so don't expect portability when using this module.
|
||||
//|
|
||||
//| .. warning:: The board module varies by board. The APIs documented here may or may not be
|
||||
//| available on a specific board.
|
||||
//| available on a specific board."""
|
||||
|
||||
//| .. function:: I2C()
|
||||
//|
|
||||
//| Returns the `busio.I2C` object for the board designated SDA and SCL pins. It is a singleton.
|
||||
//| def I2C() -> Any:
|
||||
//| """Returns the `busio.I2C` object for the board designated SDA and SCL pins. It is a singleton."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
#if BOARD_I2C
|
||||
|
@ -65,10 +61,10 @@ mp_obj_t board_i2c(void) {
|
|||
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
|
||||
|
||||
|
||||
//| .. function:: SPI()
|
||||
//|
|
||||
//| Returns the `busio.SPI` object for the board designated SCK, MOSI and MISO pins. It is a
|
||||
//| singleton.
|
||||
//| def SPI() -> Any:
|
||||
//| """Returns the `busio.SPI` object for the board designated SCK, MOSI and MISO pins. It is a
|
||||
//| singleton."""
|
||||
//| ...
|
||||
//|
|
||||
#if BOARD_SPI
|
||||
mp_obj_t board_spi(void) {
|
||||
|
@ -89,15 +85,14 @@ mp_obj_t board_spi(void) {
|
|||
#endif
|
||||
MP_DEFINE_CONST_FUN_OBJ_0(board_spi_obj, board_spi);
|
||||
|
||||
//| .. function:: UART()
|
||||
//|
|
||||
//| Returns the `busio.UART` object for the board designated TX and RX pins. It is a singleton.
|
||||
//|
|
||||
//| The object created uses the default parameter values for `busio.UART`. If you need to set
|
||||
//| parameters that are not changeable after creation, such as ``receiver_buffer_size``,
|
||||
//| do not use `board.UART()`; instead create a `busio.UART` object explicitly with the
|
||||
//| desired parameters.
|
||||
//| def UART() -> Any:
|
||||
//| """Returns the `busio.UART` object for the board designated TX and RX pins. It is a singleton.
|
||||
//|
|
||||
//| The object created uses the default parameter values for `busio.UART`. If you need to set
|
||||
//| parameters that are not changeable after creation, such as ``receiver_buffer_size``,
|
||||
//| do not use `board.UART()`; instead create a `busio.UART` object explicitly with the
|
||||
//| desired parameters."""
|
||||
//| ...
|
||||
//|
|
||||
#if BOARD_UART
|
||||
mp_obj_t board_uart(void) {
|
||||
|
|
|
@ -36,33 +36,32 @@
|
|||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: busio
|
||||
//| class I2C:
|
||||
//| """Two wire serial protocol"""
|
||||
//|
|
||||
//| :class:`I2C` --- Two wire serial protocol
|
||||
//| ------------------------------------------
|
||||
//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, *, frequency: int = 400000, timeout: int = 255):
|
||||
//|
|
||||
//| .. class:: I2C(scl, sda, *, frequency=400000, timeout=255)
|
||||
//| """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
|
||||
//| lines respectively.
|
||||
//|
|
||||
//| 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
|
||||
//| lines respectively.
|
||||
//| .. seealso:: Using this class directly requires careful lock management.
|
||||
//| Instead, use :class:`~adafruit_bus_device.i2c_device.I2CDevice` to
|
||||
//| manage locks.
|
||||
//|
|
||||
//| .. seealso:: Using this class directly requires careful lock management.
|
||||
//| Instead, use :class:`~adafruit_bus_device.i2c_device.I2CDevice` to
|
||||
//| manage locks.
|
||||
//| .. seealso:: Using this class to directly read registers requires manual
|
||||
//| bit unpacking. Instead, use an existing driver or make one with
|
||||
//| :ref:`Register <register-module-reference>` data descriptors.
|
||||
//|
|
||||
//| .. seealso:: Using this class to directly read registers requires manual
|
||||
//| bit unpacking. Instead, use an existing driver or make one with
|
||||
//| :ref:`Register <register-module-reference>` data descriptors.
|
||||
//| :param ~microcontroller.Pin scl: The clock pin
|
||||
//| :param ~microcontroller.Pin sda: The data pin
|
||||
//| :param int frequency: The clock frequency in Hertz
|
||||
//| :param int timeout: The maximum clock stretching timeut - (used only for bitbangio.I2C; ignored for busio.I2C)
|
||||
//|
|
||||
//| :param ~microcontroller.Pin scl: The clock pin
|
||||
//| :param ~microcontroller.Pin sda: The data pin
|
||||
//| :param int frequency: The clock frequency in Hertz
|
||||
//| :param int timeout: The maximum clock stretching timeut - (used only for bitbangio.I2C; ignored for busio.I2C)
|
||||
//|
|
||||
//| .. note:: On the nRF52840, only one I2C object may be created,
|
||||
//| except on the Circuit Playground Bluefruit, which allows two,
|
||||
//| one for the onboard accelerometer, and one for offboard use.
|
||||
//| .. note:: On the nRF52840, only one I2C object may be created,
|
||||
//| except on the Circuit Playground Bluefruit, which allows two,
|
||||
//| one for the onboard accelerometer, and one for offboard use."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t);
|
||||
|
@ -84,9 +83,9 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, con
|
|||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Releases control of the underlying hardware so other classes can use it.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -101,16 +100,16 @@ STATIC void check_for_deinit(busio_i2c_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used in Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used in Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware on context exit. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -126,13 +125,14 @@ static void check_lock(busio_i2c_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: scan()
|
||||
//| def scan(self, ) -> Any:
|
||||
//|
|
||||
//| Scan all I2C addresses between 0x08 and 0x77 inclusive and return a
|
||||
//| list of those that respond.
|
||||
//| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a
|
||||
//| list of those that respond.
|
||||
//|
|
||||
//| :return: List of device ids on the I2C bus
|
||||
//| :rtype: list
|
||||
//| :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);
|
||||
|
@ -150,12 +150,12 @@ STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_scan_obj, busio_i2c_scan);
|
||||
|
||||
//| .. method:: try_lock()
|
||||
//| def try_lock(self, ) -> Any:
|
||||
//| """Attempts to grab the I2C lock. Returns True on success.
|
||||
//|
|
||||
//| Attempts to grab the I2C lock. Returns True on success.
|
||||
//|
|
||||
//| :return: True when lock has been grabbed
|
||||
//| :rtype: bool
|
||||
//| :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);
|
||||
|
@ -164,9 +164,9 @@ STATIC mp_obj_t busio_i2c_obj_try_lock(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_try_lock_obj, busio_i2c_obj_try_lock);
|
||||
|
||||
//| .. method:: unlock()
|
||||
//|
|
||||
//| Releases the I2C lock.
|
||||
//| def unlock(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -176,20 +176,20 @@ 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);
|
||||
|
||||
//| .. method:: readfrom_into(address, buffer, *, start=0, end=None)
|
||||
//| def readfrom_into(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None) -> Any:
|
||||
//| """Read into ``buffer`` from the slave specified by ``address``.
|
||||
//| The number of bytes read will be the length of ``buffer``.
|
||||
//| At least one byte must be read.
|
||||
//|
|
||||
//| Read into ``buffer`` from the slave specified by ``address``.
|
||||
//| The number of bytes read will be the length of ``buffer``.
|
||||
//| At least one byte must be read.
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buf[start:end]`` will so it saves memory.
|
||||
//|
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buf[start:end]`` will so it saves memory.
|
||||
//|
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray buffer: buffer to write into
|
||||
//| :param int start: Index to start writing at
|
||||
//| :param int end: Index to write up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray buffer: buffer to write into
|
||||
//| :param int start: Index to start writing at
|
||||
//| :param int end: Index to write up to but not include. Defaults to ``len(buffer)``"""
|
||||
//| ...
|
||||
//|
|
||||
// Shared arg parsing for readfrom_into and writeto_then_readfrom.
|
||||
STATIC void readfrom(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end) {
|
||||
|
@ -228,26 +228,26 @@ 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, 3, busio_i2c_readfrom_into);
|
||||
|
||||
//| .. method:: writeto(address, buffer, *, start=0, end=None, stop=True)
|
||||
//| def writeto(self, address: int, buffer: bytearray, *, start: int = 0, end: int = None, stop: bool = True) -> Any:
|
||||
//| """Write the bytes from ``buffer`` to the slave specified by ``address``.
|
||||
//| Transmits a stop bit when stop is True. Setting stop=False is deprecated and stop will be
|
||||
//| removed in CircuitPython 6.x. Use `writeto_then_readfrom` when needing a write, no stop and
|
||||
//| repeated start before a read.
|
||||
//|
|
||||
//| Write the bytes from ``buffer`` to the slave specified by ``address``.
|
||||
//| Transmits a stop bit when stop is True. Setting stop=False is deprecated and stop will be
|
||||
//| removed in CircuitPython 6.x. Use `writeto_then_readfrom` when needing a write, no stop and
|
||||
//| repeated start before a read.
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buffer[start:end]`` will so it saves memory.
|
||||
//|
|
||||
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like
|
||||
//| ``buffer[start:end]`` will so it saves memory.
|
||||
//| Writing a buffer or slice of length zero is permitted, as it can be used
|
||||
//| to poll for the existence of a device.
|
||||
//|
|
||||
//| Writing a buffer or slice of length zero is permitted, as it can be used
|
||||
//| to poll for the existence of a device.
|
||||
//|
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray buffer: buffer containing the bytes to write
|
||||
//| :param int start: Index to start writing from
|
||||
//| :param int end: Index to read up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param bool stop: If true, output an I2C stop condition after the buffer is written.
|
||||
//| Deprecated. Will be removed in 6.x and act as stop=True.
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray buffer: buffer containing the bytes to write
|
||||
//| :param int start: Index to start writing from
|
||||
//| :param int end: Index to read up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param bool stop: If true, output an I2C stop condition after the buffer is written.
|
||||
//| Deprecated. Will be removed in 6.x and act as stop=True."""
|
||||
//| ...
|
||||
//|
|
||||
// Shared arg parsing for writeto and writeto_then_readfrom.
|
||||
STATIC void writeto(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end, bool stop) {
|
||||
|
@ -287,23 +287,23 @@ 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);
|
||||
|
||||
//| .. method:: writeto_then_readfrom(address, out_buffer, in_buffer, *, out_start=0, out_end=None, in_start=0, in_end=None)
|
||||
//| def writeto_then_readfrom(self, address: int, out_buffer: bytearray, in_buffer: bytearray, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> Any:
|
||||
//| """Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop
|
||||
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
|
||||
//| ``in_buffer`` can be the same buffer because they are used sequentially.
|
||||
//|
|
||||
//| Write the bytes from ``out_buffer`` to the slave specified by ``address``, generate no stop
|
||||
//| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and
|
||||
//| ``in_buffer`` can be the same buffer because they are used sequentially.
|
||||
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
|
||||
//| will so it saves memory.
|
||||
//|
|
||||
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
|
||||
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
|
||||
//| will so it saves memory.
|
||||
//|
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray out_buffer: buffer containing the bytes to write
|
||||
//| :param bytearray in_buffer: buffer to write into
|
||||
//| :param int out_start: Index to start writing from
|
||||
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param int in_start: Index to start writing at
|
||||
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param int address: 7-bit device address
|
||||
//| :param bytearray out_buffer: buffer containing the bytes to write
|
||||
//| :param bytearray in_buffer: buffer to write into
|
||||
//| :param int out_start: Index to start writing from
|
||||
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
|
||||
//| :param int in_start: Index to start writing at
|
||||
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
|
||||
//| ...
|
||||
//|
|
||||
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 };
|
||||
|
|
|
@ -34,33 +34,32 @@
|
|||
#include "shared-bindings/busio/OneWire.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| .. currentmodule:: busio
|
||||
//| class OneWire:
|
||||
//| """Lowest-level of the Maxim OneWire protocol"""
|
||||
//|
|
||||
//| :class:`OneWire` -- Lowest-level of the Maxim OneWire protocol
|
||||
//| =================================================================
|
||||
//| def __init__(self, pin: microcontroller.Pin):
|
||||
//| """(formerly Dallas Semi) OneWire protocol.
|
||||
//|
|
||||
//| :class:`~busio.OneWire` implements the timing-sensitive foundation of the Maxim
|
||||
//| (formerly Dallas Semi) OneWire protocol.
|
||||
//| Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126
|
||||
//|
|
||||
//| Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126
|
||||
//| .. class:: OneWire(pin)
|
||||
//|
|
||||
//| .. class:: OneWire(pin)
|
||||
//| Create a OneWire object associated with the given pin. The object
|
||||
//| implements the lowest level timing-sensitive bits of the protocol.
|
||||
//|
|
||||
//| Create a OneWire object associated with the given pin. The object
|
||||
//| implements the lowest level timing-sensitive bits of the protocol.
|
||||
//| :param ~microcontroller.Pin pin: Pin connected to the OneWire bus
|
||||
//|
|
||||
//| :param ~microcontroller.Pin pin: Pin connected to the OneWire bus
|
||||
//| Read a short series of pulses::
|
||||
//|
|
||||
//| Read a short series of pulses::
|
||||
//| import busio
|
||||
//| import board
|
||||
//|
|
||||
//| import busio
|
||||
//| import board
|
||||
//|
|
||||
//| onewire = busio.OneWire(board.D7)
|
||||
//| onewire.reset()
|
||||
//| onewire.write_bit(True)
|
||||
//| onewire.write_bit(False)
|
||||
//| print(onewire.read_bit())
|
||||
//| onewire = busio.OneWire(board.D7)
|
||||
//| onewire.reset()
|
||||
//| onewire.write_bit(True)
|
||||
//| onewire.write_bit(False)
|
||||
//| print(onewire.read_bit())"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin };
|
||||
|
@ -78,9 +77,9 @@ STATIC mp_obj_t busio_onewire_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialize the OneWire bus and release any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialize the OneWire bus and release any hardware resources for reuse."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busio_onewire_deinit(mp_obj_t self_in) {
|
||||
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -95,16 +94,16 @@ STATIC void check_for_deinit(busio_onewire_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
|
@ -113,12 +112,12 @@ STATIC mp_obj_t busio_onewire_obj___exit__(size_t n_args, const mp_obj_t *args)
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_onewire___exit___obj, 4, 4, busio_onewire_obj___exit__);
|
||||
|
||||
//| .. method:: reset()
|
||||
//| def reset(self, ) -> Any:
|
||||
//| """Reset the OneWire bus and read presence
|
||||
//|
|
||||
//| Reset the OneWire bus and read presence
|
||||
//|
|
||||
//| :returns: False when at least one device is present
|
||||
//| :rtype: bool
|
||||
//| :returns: False when at least one device is present
|
||||
//| :rtype: bool"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busio_onewire_obj_reset(mp_obj_t self_in) {
|
||||
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -128,12 +127,12 @@ STATIC mp_obj_t busio_onewire_obj_reset(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_reset_obj, busio_onewire_obj_reset);
|
||||
|
||||
//| .. method:: read_bit()
|
||||
//| def read_bit(self, ) -> Any:
|
||||
//| """Read in a bit
|
||||
//|
|
||||
//| Read in a bit
|
||||
//|
|
||||
//| :returns: bit state read
|
||||
//| :rtype: bool
|
||||
//| :returns: bit state read
|
||||
//| :rtype: bool"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busio_onewire_obj_read_bit(mp_obj_t self_in) {
|
||||
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -143,9 +142,9 @@ STATIC mp_obj_t busio_onewire_obj_read_bit(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_onewire_read_bit_obj, busio_onewire_obj_read_bit);
|
||||
|
||||
//| .. method:: write_bit(value)
|
||||
//|
|
||||
//| Write out a bit based on value.
|
||||
//| def write_bit(self, value: Any) -> Any:
|
||||
//| """Write out a bit based on value."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t busio_onewire_obj_write_bit(mp_obj_t self_in, mp_obj_t bool_obj) {
|
||||
busio_onewire_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -40,43 +40,44 @@
|
|||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: busio
|
||||
|
||||
//| class SPI:
|
||||
//| """A 3-4 wire serial protocol
|
||||
//|
|
||||
//| :class:`SPI` -- a 3-4 wire serial protocol
|
||||
//| -----------------------------------------------
|
||||
//| SPI is a serial protocol that has exclusive pins for data in and out of the
|
||||
//| master. It is typically faster than :py:class:`~busio.I2C` because a
|
||||
//| separate pin is used to control the active slave rather than a transitted
|
||||
//| address. This class only manages three of the four SPI lines: `!clock`,
|
||||
//| `!MOSI`, `!MISO`. Its up to the client to manage the appropriate slave
|
||||
//| select line. (This is common because multiple slaves can share the `!clock`,
|
||||
//| `!MOSI` and `!MISO` lines and therefore the hardware.)"""
|
||||
//|
|
||||
//| SPI is a serial protocol that has exclusive pins for data in and out of the
|
||||
//| master. It is typically faster than :py:class:`~busio.I2C` because a
|
||||
//| separate pin is used to control the active slave rather than a transitted
|
||||
//| address. This class only manages three of the four SPI lines: `!clock`,
|
||||
//| `!MOSI`, `!MISO`. Its up to the client to manage the appropriate slave
|
||||
//| select line. (This is common because multiple slaves can share the `!clock`,
|
||||
//| `!MOSI` and `!MISO` lines and therefore the hardware.)
|
||||
//| def __init__(self, clock: microcontroller.Pin, MOSI: microcontroller.Pin = None, MISO: microcontroller.Pin = None):
|
||||
//|
|
||||
//| .. class:: SPI(clock, MOSI=None, MISO=None)
|
||||
//| """Construct an SPI object on the given pins.
|
||||
//|
|
||||
//| Construct an SPI object on the given pins.
|
||||
//| ..note:: The SPI peripherals allocated in order of desirability, if possible,
|
||||
//| such as highest speed and not shared use first. For instance, on the nRF52840,
|
||||
//| there is a single 32MHz SPI peripheral, and multiple 8MHz peripherals,
|
||||
//| some of which may also be used for I2C. The 32MHz SPI peripheral is returned
|
||||
//| first, then the exclusive 8MHz SPI peripheral, and finally the shared 8MHz
|
||||
//| peripherals.
|
||||
//|
|
||||
//| ..note:: The SPI peripherals allocated in order of desirability, if possible,
|
||||
//| such as highest speed and not shared use first. For instance, on the nRF52840,
|
||||
//| there is a single 32MHz SPI peripheral, and multiple 8MHz peripherals,
|
||||
//| some of which may also be used for I2C. The 32MHz SPI peripheral is returned
|
||||
//| first, then the exclusive 8MHz SPI peripheral, and finally the shared 8MHz
|
||||
//| peripherals.
|
||||
//| .. seealso:: Using this class directly requires careful lock management.
|
||||
//| Instead, use :class:`~adafruit_bus_device.spi_device.SPIDevice` to
|
||||
//| manage locks.
|
||||
//|
|
||||
//| .. seealso:: Using this class directly requires careful lock management.
|
||||
//| Instead, use :class:`~adafruit_bus_device.spi_device.SPIDevice` to
|
||||
//| manage locks.
|
||||
//| .. seealso:: Using this class to directly read registers requires manual
|
||||
//| bit unpacking. Instead, use an existing driver or make one with
|
||||
//| :ref:`Register <register-module-reference>` data descriptors.
|
||||
//|
|
||||
//| .. seealso:: Using this class to directly read registers requires manual
|
||||
//| bit unpacking. Instead, use an existing driver or make one with
|
||||
//| :ref:`Register <register-module-reference>` data descriptors.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin clock: the pin to use for the clock.
|
||||
//| :param ~microcontroller.Pin MOSI: the Master Out Slave In pin.
|
||||
//| :param ~microcontroller.Pin MISO: the Master In Slave Out pin.
|
||||
//| :param ~microcontroller.Pin clock: the pin to use for the clock.
|
||||
//| :param ~microcontroller.Pin MOSI: the Master Out Slave In pin.
|
||||
//| :param ~microcontroller.Pin MISO: the Master In Slave Out pin."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
|
||||
// TODO(tannewt): Support LSB SPI.
|
||||
STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
|
||||
|
@ -98,9 +99,9 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Turn off the SPI bus.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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);
|
||||
|
@ -109,16 +110,16 @@ STATIC mp_obj_t busio_spi_obj_deinit(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_deinit_obj, busio_spi_obj_deinit);
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers.
|
||||
//| Provided by context manager helper."""
|
||||
//| ...
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -140,29 +141,30 @@ STATIC void check_for_deinit(busio_spi_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: configure(*, baudrate=100000, polarity=0, phase=0, bits=8)
|
||||
//| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> Any:
|
||||
//| """Configures the SPI bus. The SPI object must be locked.
|
||||
//|
|
||||
//| Configures the SPI bus. The SPI object must be locked.
|
||||
//| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower
|
||||
//| due to the granularity of available clock settings.
|
||||
//| Check the `frequency` attribute for the actual clock rate.
|
||||
//| :param int polarity: the base state of the clock line (0 or 1)
|
||||
//| :param int phase: the edge of the clock that data is captured. First (0)
|
||||
//| or second (1). Rising or falling depends on clock polarity.
|
||||
//| :param int bits: the number of bits per word
|
||||
//|
|
||||
//| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower
|
||||
//| due to the granularity of available clock settings.
|
||||
//| Check the `frequency` attribute for the actual clock rate.
|
||||
//| :param int polarity: the base state of the clock line (0 or 1)
|
||||
//| :param int phase: the edge of the clock that data is captured. First (0)
|
||||
//| or second (1). Rising or falling depends on clock polarity.
|
||||
//| :param int bits: the number of bits per word
|
||||
//| .. note:: On the SAMD21, it is possible to set the baudrate to 24 MHz, but that
|
||||
//| speed is not guaranteed to work. 12 MHz is the next available lower speed, and is
|
||||
//| within spec for the SAMD21.
|
||||
//|
|
||||
//| .. note:: On the SAMD21, it is possible to set the baudrate to 24 MHz, but that
|
||||
//| speed is not guaranteed to work. 12 MHz is the next available lower speed, and is
|
||||
//| within spec for the SAMD21.
|
||||
//|
|
||||
//| .. note:: On the nRF52840, these baudrates are available: 125kHz, 250kHz, 1MHz, 2MHz, 4MHz,
|
||||
//| and 8MHz.
|
||||
//| If you pick a a baudrate other than one of these, the nearest lower
|
||||
//| baudrate will be chosen, with a minimum of 125kHz.
|
||||
//| Two SPI objects may be created, except on the Circuit Playground Bluefruit,
|
||||
//| which allows only one (to allow for an additional I2C object).
|
||||
//| .. note:: On the nRF52840, these baudrates are available: 125kHz, 250kHz, 1MHz, 2MHz, 4MHz,
|
||||
//| and 8MHz.
|
||||
//| If you pick a a baudrate other than one of these, the nearest lower
|
||||
//| baudrate will be chosen, with a minimum of 125kHz.
|
||||
//| 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 };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
|
@ -198,23 +200,25 @@ STATIC mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_configure_obj, 1, busio_spi_configure);
|
||||
|
||||
//| .. method:: try_lock()
|
||||
//| def try_lock(self, ) -> Any:
|
||||
//| """Attempts to grab the SPI lock. Returns True on success.
|
||||
//|
|
||||
//| Attempts to grab the SPI lock. Returns True on success.
|
||||
//|
|
||||
//| :return: True when lock has been grabbed
|
||||
//| :rtype: bool
|
||||
//| :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);
|
||||
return mp_obj_new_bool(common_hal_busio_spi_try_lock(self));
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_try_lock_obj, busio_spi_obj_try_lock);
|
||||
|
||||
//| .. method:: unlock()
|
||||
//|
|
||||
//| Releases the SPI lock.
|
||||
//| def unlock(self, ) -> Any:
|
||||
//| """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);
|
||||
check_for_deinit(self);
|
||||
|
@ -223,15 +227,16 @@ 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);
|
||||
|
||||
//| .. method:: write(buffer, *, start=0, end=None)
|
||||
//| def write(self, buffer: bytearray, *, start: Any = 0, end: int = None) -> Any:
|
||||
//| """Write the data contained in ``buffer``. The SPI object must be locked.
|
||||
//| If the buffer is empty, nothing happens.
|
||||
//|
|
||||
//| Write the data contained in ``buffer``. The SPI object must be locked.
|
||||
//| If the buffer is empty, nothing happens.
|
||||
//|
|
||||
//| :param bytearray buffer: Write out the data in this buffer
|
||||
//| :param int start: Start of the slice of ``buffer`` to write out: ``buffer[start:end]``
|
||||
//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``
|
||||
//| :param bytearray buffer: Write out the data in this buffer
|
||||
//| :param int start: Start of the slice of ``buffer`` to write out: ``buffer[start:end]``
|
||||
//| :param int end: End of the slice; this index is not included. Defaults to ``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 };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
|
@ -264,17 +269,18 @@ STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
|||
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_obj, 2, busio_spi_write);
|
||||
|
||||
|
||||
//| .. method:: readinto(buffer, *, start=0, end=None, write_value=0)
|
||||
//| def readinto(self, buffer: bytearray, *, start: Any = 0, end: int = None, write_value: int = 0) -> Any:
|
||||
//| """Read into ``buffer`` while writing ``write_value`` for each byte read.
|
||||
//| The SPI object must be locked.
|
||||
//| If the number of bytes to read is 0, nothing happens.
|
||||
//|
|
||||
//| Read into ``buffer`` while writing ``write_value`` for each byte read.
|
||||
//| The SPI object must be locked.
|
||||
//| If the number of bytes to read is 0, nothing happens.
|
||||
//|
|
||||
//| :param bytearray buffer: Read data into this buffer
|
||||
//| :param int start: Start of the slice of ``buffer`` to read into: ``buffer[start:end]``
|
||||
//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``
|
||||
//| :param int write_value: Value to write while reading. (Usually ignored.)
|
||||
//| :param bytearray buffer: Read data into this buffer
|
||||
//| :param int start: Start of the slice of ``buffer`` to read into: ``buffer[start:end]``
|
||||
//| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``
|
||||
//| :param int write_value: Value to write while reading. (Usually ignored.)"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
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 };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
|
@ -307,21 +313,22 @@ 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, 2, busio_spi_readinto);
|
||||
|
||||
//| .. method:: write_readinto(buffer_out, buffer_in, *, out_start=0, out_end=None, in_start=0, in_end=None)
|
||||
//| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: Any = 0, out_end: int = None, in_start: Any = 0, in_end: int = None) -> Any:
|
||||
//| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
|
||||
//| The SPI object must be locked.
|
||||
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
|
||||
//| must be equal.
|
||||
//| If buffer slice lengths are both 0, nothing happens.
|
||||
//|
|
||||
//| Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
|
||||
//| The SPI object must be locked.
|
||||
//| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
|
||||
//| must be equal.
|
||||
//| If buffer slice lengths are both 0, nothing happens.
|
||||
//|
|
||||
//| :param bytearray buffer_out: Write out the data in this buffer
|
||||
//| :param bytearray buffer_in: Read data into this buffer
|
||||
//| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
|
||||
//| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)``
|
||||
//| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
|
||||
//| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)``
|
||||
//| :param bytearray buffer_out: Write out the data in this buffer
|
||||
//| :param bytearray buffer_in: Read data into this buffer
|
||||
//| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
|
||||
//| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)``
|
||||
//| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
|
||||
//| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)``"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
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_buffer_out, ARG_buffer_in, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
|
@ -369,11 +376,11 @@ STATIC mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_write_readinto_obj, 2, busio_spi_write_readinto);
|
||||
|
||||
//| .. attribute:: frequency
|
||||
//|
|
||||
//| The actual SPI bus frequency. This may not match the frequency requested
|
||||
//| due to internal limitations.
|
||||
//| frequency: Any = ...
|
||||
//| """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);
|
||||
check_for_deinit(self);
|
||||
|
|
|
@ -42,33 +42,28 @@
|
|||
#define STREAM_DEBUG(...) (void)0
|
||||
// #define STREAM_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
|
||||
|
||||
|
||||
//| .. currentmodule:: busio
|
||||
//| class UART:
|
||||
//| """A bidirectional serial protocol"""
|
||||
//| def __init__(self, tx: microcontroller.Pin, rx: microcontroller.Pin, *, baudrate: int = 9600, bits: int = 8, parity: Parity = None, stop: int = 1, timeout: float = 1, receiver_buffer_size: int = 64):
|
||||
//| """A common bidirectional serial protocol that uses an an agreed upon speed
|
||||
//| rather than a shared clock line.
|
||||
//|
|
||||
//| :class:`UART` -- a bidirectional serial protocol
|
||||
//| =================================================
|
||||
//| :param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only.
|
||||
//| :param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only.
|
||||
//| :param ~microcontroller.Pin rts: the pin for rts, or ``None`` if rts not in use.
|
||||
//| :param ~microcontroller.Pin cts: the pin for cts, or ``None`` if cts not in use.
|
||||
//| :param ~microcontroller.Pin rs485_dir: the pin for rs485 direction setting, or ``None`` if rs485 not in use.
|
||||
//| :param bool rs485_invert: set to invert the sense of the rs485_dir pin.
|
||||
//| :param int baudrate: the transmit and receive speed.
|
||||
//| :param int bits: the number of bits per byte, 7, 8 or 9.
|
||||
//| :param Parity parity: the parity used for error checking.
|
||||
//| :param int stop: the number of stop bits, 1 or 2.
|
||||
//| :param float timeout: the timeout in seconds to wait for the first character and between subsequent characters when reading. Raises ``ValueError`` if timeout >100 seconds.
|
||||
//| :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.)
|
||||
//|
|
||||
//|
|
||||
//| .. class:: UART(tx, rx, *, baudrate=9600, bits=8, parity=None, stop=1, timeout=1, receiver_buffer_size=64)
|
||||
//|
|
||||
//| A common bidirectional serial protocol that uses an an agreed upon speed
|
||||
//| rather than a shared clock line.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin tx: the pin to transmit with, or ``None`` if this ``UART`` is receive-only.
|
||||
//| :param ~microcontroller.Pin rx: the pin to receive on, or ``None`` if this ``UART`` is transmit-only.
|
||||
//| :param ~microcontroller.Pin rts: the pin for rts, or ``None`` if rts not in use.
|
||||
//| :param ~microcontroller.Pin cts: the pin for cts, or ``None`` if cts not in use.
|
||||
//| :param ~microcontroller.Pin rs485_dir: the pin for rs485 direction setting, or ``None`` if rs485 not in use.
|
||||
//| :param bool rs485_invert: set to invert the sense of the rs485_dir pin.
|
||||
//| :param int baudrate: the transmit and receive speed.
|
||||
//| :param int bits: the number of bits per byte, 7, 8 or 9.
|
||||
//| :param Parity parity: the parity used for error checking.
|
||||
//| :param int stop: the number of stop bits, 1 or 2.
|
||||
//| :param float timeout: the timeout in seconds to wait for the first character and between subsequent characters when reading. Raises ``ValueError`` if timeout >100 seconds.
|
||||
//| :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.)
|
||||
//|
|
||||
//| *New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds.
|
||||
//| The new upper limit on ``timeout`` is meant to catch mistaken use of milliseconds.
|
||||
//| *New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds.
|
||||
//| The new upper limit on ``timeout`` is meant to catch mistaken use of milliseconds."""
|
||||
//| ...
|
||||
//|
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
|
@ -147,9 +142,9 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
|
|||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the UART and releases any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """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 = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -164,16 +159,16 @@ STATIC void check_for_deinit(busio_uart_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """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;
|
||||
|
@ -184,40 +179,43 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_
|
|||
|
||||
// These are standard stream methods. Code is in py/stream.c.
|
||||
//
|
||||
//| .. method:: read(nbytes=None)
|
||||
//| def read(self, nbytes: Any = None) -> Any:
|
||||
//| """Read characters. If ``nbytes`` is specified then read at most that many
|
||||
//| bytes. Otherwise, read everything that arrives until the connection
|
||||
//| times out. Providing the number of bytes expected is highly recommended
|
||||
//| because it will be faster.
|
||||
//|
|
||||
//| Read characters. If ``nbytes`` is specified then read at most that many
|
||||
//| bytes. Otherwise, read everything that arrives until the connection
|
||||
//| times out. Providing the number of bytes expected is highly recommended
|
||||
//| because it will be faster.
|
||||
//| :return: Data read
|
||||
//| :rtype: bytes or None"""
|
||||
//| ...
|
||||
//|
|
||||
//| :return: Data read
|
||||
//| :rtype: bytes or None
|
||||
//|
|
||||
//| .. method:: readinto(buf)
|
||||
//|
|
||||
//| Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
|
||||
//|
|
||||
//| :return: number of bytes read and stored into ``buf``
|
||||
//| :rtype: int or None (on a non-blocking error)
|
||||
//|
|
||||
//| *New in CircuitPython 4.0:* No length parameter is permitted.
|
||||
|
||||
//| .. method:: readline()
|
||||
//| def readinto(self, buf: Any) -> Any:
|
||||
//| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes.
|
||||
//|
|
||||
//| Read a line, ending in a newline character.
|
||||
//| :return: number of bytes read and stored into ``buf``
|
||||
//| :rtype: int or None (on a non-blocking error)
|
||||
//|
|
||||
//| :return: the line read
|
||||
//| :rtype: int or None
|
||||
//| *New in CircuitPython 4.0:* No length parameter is permitted."""
|
||||
//| ...
|
||||
//|
|
||||
//| .. method:: write(buf)
|
||||
|
||||
//| def readline(self, ) -> Any:
|
||||
//| """Read a line, ending in a newline character.
|
||||
//|
|
||||
//| Write the buffer of bytes to the bus.
|
||||
//| :return: the line read
|
||||
//| :rtype: int or None"""
|
||||
//| ...
|
||||
//|
|
||||
//| *New in CircuitPython 4.0:* ``buf`` must be bytes, not a string.
|
||||
|
||||
//| def write(self, buf: Any) -> Any:
|
||||
//| """Write the buffer of bytes to the bus.
|
||||
//|
|
||||
//| :return: the number of bytes written
|
||||
//| :rtype: int or None
|
||||
//| *New in CircuitPython 4.0:* ``buf`` must be bytes, not a string.
|
||||
//|
|
||||
//| :return: the number of bytes written
|
||||
//| :rtype: int or None"""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
// These three methods are used by the shared stream methods.
|
||||
|
@ -263,9 +261,8 @@ STATIC mp_uint_t busio_uart_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t
|
|||
return ret;
|
||||
}
|
||||
|
||||
//| .. attribute:: baudrate
|
||||
//|
|
||||
//| The current baudrate.
|
||||
//| baudrate: Any = ...
|
||||
//| """The current baudrate."""
|
||||
//|
|
||||
STATIC mp_obj_t busio_uart_obj_get_baudrate(mp_obj_t self_in) {
|
||||
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -290,9 +287,8 @@ const mp_obj_property_t busio_uart_baudrate_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: in_waiting
|
||||
//|
|
||||
//| The number of bytes in the input buffer, available to be read
|
||||
//| in_waiting: Any = ...
|
||||
//| """The number of bytes in the input buffer, available to be read"""
|
||||
//|
|
||||
STATIC mp_obj_t busio_uart_obj_get_in_waiting(mp_obj_t self_in) {
|
||||
busio_uart_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -308,9 +304,8 @@ const mp_obj_property_t busio_uart_in_waiting_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: timeout
|
||||
//|
|
||||
//| The current timeout, in seconds (float).
|
||||
//| timeout: Any = ...
|
||||
//| """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 = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -337,9 +332,8 @@ const mp_obj_property_t busio_uart_timeout_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: reset_input_buffer()
|
||||
//|
|
||||
//| Discard any unread characters in the input buffer.
|
||||
//| def reset_input_buffer(self, ) -> Any: ...
|
||||
//| """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 = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -349,17 +343,14 @@ STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_obj_reset_input_buffer);
|
||||
|
||||
//| .. class:: busio.UART.Parity()
|
||||
//| class Parity:
|
||||
//| """Enum-like class to define the parity used to verify correct data transfer."""
|
||||
//|
|
||||
//| Enum-like class to define the parity used to verify correct data transfer.
|
||||
//| ODD: Any = ...
|
||||
//| """Total number of ones should be odd."""
|
||||
//|
|
||||
//| .. data:: ODD
|
||||
//|
|
||||
//| Total number of ones should be odd.
|
||||
//|
|
||||
//| .. data:: EVEN
|
||||
//|
|
||||
//| Total number of ones should be even.
|
||||
//| EVEN: Any = ...
|
||||
//| """Total number of ones should be even."""
|
||||
//|
|
||||
const mp_obj_type_t busio_uart_parity_type;
|
||||
|
||||
|
|
|
@ -38,12 +38,7 @@
|
|||
|
||||
#include "py/runtime.h"
|
||||
|
||||
//| :mod:`busio` --- Hardware accelerated behavior
|
||||
//| =================================================
|
||||
//|
|
||||
//| .. module:: busio
|
||||
//| :synopsis: Hardware accelerated behavior
|
||||
//| :platform: SAMD21
|
||||
//| """Hardware accelerated external bus access
|
||||
//|
|
||||
//| The `busio` module contains classes to support a variety of serial
|
||||
//| protocols.
|
||||
|
@ -54,16 +49,6 @@
|
|||
//| then a RuntimeError will be raised. Use the `bitbangio` module to explicitly
|
||||
//| bitbang a serial protocol on any general purpose pins.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| I2C
|
||||
//| OneWire
|
||||
//| SPI
|
||||
//| UART
|
||||
//|
|
||||
//| All classes change hardware state and should be deinitialized when they
|
||||
//| are no longer needed if the program continues after use. To do so, either
|
||||
//| call :py:meth:`!deinit` or use a context manager. See
|
||||
|
@ -81,7 +66,7 @@
|
|||
//| This example will initialize the the device, run
|
||||
//| :py:meth:`~busio.I2C.scan` and then :py:meth:`~busio.I2C.deinit` the
|
||||
//| hardware. The last step is optional because CircuitPython automatically
|
||||
//| resets hardware after a program finishes.
|
||||
//| resets hardware after a program finishes."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t busio_module_globals_table[] = {
|
||||
|
|
|
@ -9,45 +9,41 @@
|
|||
#include "shared-bindings/countio/Counter.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| .. currentmodule:: countio
|
||||
//| class Counter:
|
||||
//| """Counter will keep track of the number of falling edge transistions (pulses) on a
|
||||
//| given pin"""
|
||||
//|
|
||||
//| :class:`Counter` -- Track the count of falling edge transistions (pulses) on a given pin
|
||||
//| ========================================================================================
|
||||
//| def __init__(self, pin_a):
|
||||
//| """Create a Counter object associated with the given pin. It tracks the number of
|
||||
//| falling pulses relative when the object is constructed.
|
||||
//|
|
||||
//| Counter will keep track of the number of falling edge transistions (pulses) on a given pin
|
||||
//| :param ~microcontroller.Pin pin_a: Pin to read pulses from.
|
||||
//|
|
||||
//| .. class:: Counter(pin_a)
|
||||
//|
|
||||
//| Create a Counter object associated with the given pin. It tracks the number of
|
||||
//| falling pulses relative when the object is constructed.
|
||||
//| For example::
|
||||
//|
|
||||
//| :param ~microcontroller.Pin pin_a: Pin to read pulses from.
|
||||
//|
|
||||
//| import countio
|
||||
//| import time
|
||||
//| from board import *
|
||||
//|
|
||||
//| For example::
|
||||
//|
|
||||
//| import countio
|
||||
//| import time
|
||||
//| from board import *
|
||||
//|
|
||||
//| pin_counter = countio.Counter(board.D1)
|
||||
//| #reset the count after 100 counts
|
||||
//| while True:
|
||||
//| if pin_counter.count == 100:
|
||||
//| pin_counter.reset()
|
||||
//| print(pin_counter.count)
|
||||
//| pin_counter = countio.Counter(board.D1)
|
||||
//| #reset the count after 100 counts
|
||||
//| while True:
|
||||
//| if pin_counter.count == 100:
|
||||
//| pin_counter.reset()
|
||||
//| print(pin_counter.count)"""
|
||||
//|
|
||||
STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pin_a };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_pin_a, MP_ARG_REQUIRED | MP_ARG_OBJ }
|
||||
|
||||
|
||||
};
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
const mcu_pin_obj_t* pin_a = validate_obj_is_free_pin(args[ARG_pin_a].u_obj);
|
||||
|
||||
|
||||
|
||||
countio_counter_obj_t *self = m_new_obj(countio_counter_obj_t);
|
||||
self->base.type = &countio_counter_type;
|
||||
|
@ -57,9 +53,8 @@ STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_arg
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitializes the Counter and releases any hardware resources for reuse.
|
||||
//| def deinit(self):
|
||||
//| """Deinitializes the Counter and releases any hardware resources for reuse."""
|
||||
//|
|
||||
STATIC mp_obj_t countio_counter_deinit(mp_obj_t self_in) {
|
||||
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -74,16 +69,14 @@ STATIC void check_for_deinit(countio_counter_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self):
|
||||
//| """No-op used by Context Managers."""
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self):
|
||||
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//|
|
||||
STATIC mp_obj_t countio_counter_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
|
@ -93,10 +86,8 @@ STATIC mp_obj_t countio_counter_obj___exit__(size_t n_args, const mp_obj_t *args
|
|||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(countio_counter___exit___obj, 4, 4, countio_counter_obj___exit__);
|
||||
|
||||
|
||||
//| .. attribute:: count
|
||||
//|
|
||||
//| The current count in terms of pulses.
|
||||
//|
|
||||
//| count: int = ...
|
||||
//| """The current count in terms of pulses."""
|
||||
//|
|
||||
STATIC mp_obj_t countio_counter_obj_get_count(mp_obj_t self_in) {
|
||||
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -122,6 +113,9 @@ const mp_obj_property_t countio_counter_count_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| def reset(self):
|
||||
//| """Resets the count back to 0."""
|
||||
//|
|
||||
STATIC mp_obj_t countio_counter_reset(mp_obj_t self_in){
|
||||
countio_counter_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
@ -129,7 +123,7 @@ STATIC mp_obj_t countio_counter_reset(mp_obj_t self_in){
|
|||
common_hal_countio_counter_reset(self);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(countio_counter_reset_obj, countio_counter_reset);
|
||||
|
||||
|
|
|
@ -8,22 +8,10 @@
|
|||
#include "shared-bindings/countio/__init__.h"
|
||||
#include "shared-bindings/countio/Counter.h"
|
||||
|
||||
//| :mod:`countio` --- Support for edge counting
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: countio
|
||||
//| :synopsis: Support for edge counting
|
||||
//| :platform: SAMD
|
||||
//| """Support for edge counting
|
||||
//|
|
||||
//| The `countio` module contains logic to read and count edge transistions
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Counter
|
||||
//|
|
||||
|
||||
//| .. warning:: This module is not available in some SAMD21 (aka M0) builds. See the
|
||||
//| :ref:`module-support-matrix` for more info.
|
||||
|
@ -32,7 +20,7 @@
|
|||
//| All classes change hardware state and should be deinitialized when they
|
||||
//| are no longer needed if the program continues after use. To do so, either
|
||||
//| call :py:meth:`!deinit` or use a context manager. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t countio_module_globals_table[] = {
|
||||
|
|
|
@ -43,23 +43,20 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: digitalio
|
||||
//| class DigitalInOut:
|
||||
//| """Digital input and output
|
||||
//|
|
||||
//| :class:`DigitalInOut` -- digital input and output
|
||||
//| =========================================================
|
||||
//| A DigitalInOut is used to digitally control I/O pins. For analog control of
|
||||
//| a pin, see the :py:class:`analogio.AnalogIn` and
|
||||
//| :py:class:`analogio.AnalogOut` classes."""
|
||||
//|
|
||||
//| A DigitalInOut is used to digitally control I/O pins. For analog control of
|
||||
//| a pin, see the :py:class:`analogio.AnalogIn` and
|
||||
//| :py:class:`analogio.AnalogOut` classes.
|
||||
//| def __init__(self, pin: microcontroller.Pin):
|
||||
//| """Create a new DigitalInOut object associated with the pin. Defaults to input
|
||||
//| with no pull. Use :py:meth:`switch_to_input` and
|
||||
//| :py:meth:`switch_to_output` to change the direction.
|
||||
//|
|
||||
|
||||
//| .. class:: DigitalInOut(pin)
|
||||
//|
|
||||
//| Create a new DigitalInOut object associated with the pin. Defaults to input
|
||||
//| with no pull. Use :py:meth:`switch_to_input` and
|
||||
//| :py:meth:`switch_to_output` to change the direction.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin pin: The pin to control
|
||||
//| :param ~microcontroller.Pin pin: The pin to control"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type,
|
||||
mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
|
@ -74,9 +71,9 @@ STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type,
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Turn off the DigitalInOut and release the pin for other use.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Turn off the DigitalInOut and release the pin for other use."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_obj_deinit(mp_obj_t self_in) {
|
||||
digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -85,16 +82,16 @@ STATIC mp_obj_t digitalio_digitalinout_obj_deinit(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(digitalio_digitalinout_deinit_obj, digitalio_digitalinout_obj_deinit);
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
|
@ -109,14 +106,13 @@ STATIC void check_for_deinit(digitalio_digitalinout_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| def switch_to_output(self, value: bool = False, drive_mode: digitalio.DriveMode = digitalio.DriveMode.PUSH_PULL) -> Any:
|
||||
//| """Set the drive mode and value and then switch to writing out digital
|
||||
//| values.
|
||||
//|
|
||||
//| .. method:: switch_to_output(value=False, drive_mode=digitalio.DriveMode.PUSH_PULL)
|
||||
//|
|
||||
//| Set the drive mode and value and then switch to writing out digital
|
||||
//| values.
|
||||
//|
|
||||
//| :param bool value: default value to set upon switching
|
||||
//| :param ~digitalio.DriveMode drive_mode: drive mode for the output
|
||||
//| :param bool value: default value to set upon switching
|
||||
//| :param ~digitalio.DriveMode drive_mode: drive mode for the output"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_value, ARG_drive_mode };
|
||||
|
@ -139,22 +135,22 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_output_obj, 1, digitalio_digitalinout_switch_to_output);
|
||||
|
||||
//| .. method:: switch_to_input(pull=None)
|
||||
//| def switch_to_input(self, pull: Pull = None) -> Any:
|
||||
//| """Set the pull and then switch to read in digital values.
|
||||
//|
|
||||
//| Set the pull and then switch to read in digital values.
|
||||
//| :param Pull pull: pull configuration for the input
|
||||
//|
|
||||
//| :param Pull pull: pull configuration for the input
|
||||
//| Example usage::
|
||||
//|
|
||||
//| Example usage::
|
||||
//| import digitalio
|
||||
//| import board
|
||||
//|
|
||||
//| import digitalio
|
||||
//| import board
|
||||
//|
|
||||
//| switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
|
||||
//| switch.switch_to_input(pull=digitalio.Pull.UP)
|
||||
//| # Or, after switch_to_input
|
||||
//| switch.pull = digitalio.Pull.UP
|
||||
//| print(switch.value)
|
||||
//| switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
|
||||
//| switch.switch_to_input(pull=digitalio.Pull.UP)
|
||||
//| # Or, after switch_to_input
|
||||
//| switch.pull = digitalio.Pull.UP
|
||||
//| print(switch.value)"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_switch_to_input(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_pull };
|
||||
|
@ -178,14 +174,13 @@ STATIC mp_obj_t digitalio_digitalinout_switch_to_input(size_t n_args, const mp_o
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(digitalio_digitalinout_switch_to_input_obj, 1, digitalio_digitalinout_switch_to_input);
|
||||
|
||||
//| .. attribute:: direction
|
||||
//|
|
||||
//| The direction of the pin.
|
||||
//| direction: Any = ...
|
||||
//| """The direction of the pin.
|
||||
//|
|
||||
//| Setting this will use the defaults from the corresponding
|
||||
//| :py:meth:`switch_to_input` or :py:meth:`switch_to_output` method. If
|
||||
//| you want to set pull, value or drive mode prior to switching, then use
|
||||
//| those methods instead.
|
||||
//| those methods instead."""
|
||||
//|
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
|
@ -225,9 +220,8 @@ const mp_obj_property_t digitalio_digitalio_direction_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: value
|
||||
//|
|
||||
//| The digital logic level of the pin.
|
||||
//| value: Any = ...
|
||||
//| """The digital logic level of the pin."""
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_obj_get_value(mp_obj_t self_in) {
|
||||
digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -256,12 +250,11 @@ const mp_obj_property_t digitalio_digitalinout_value_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: drive_mode
|
||||
//|
|
||||
//| The pin drive mode. One of:
|
||||
//| drive_mode: Any = ...
|
||||
//| """The pin drive mode. One of:
|
||||
//|
|
||||
//| - `digitalio.DriveMode.PUSH_PULL`
|
||||
//| - `digitalio.DriveMode.OPEN_DRAIN`
|
||||
//| - `digitalio.DriveMode.OPEN_DRAIN`"""
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_obj_get_drive_mode(mp_obj_t self_in) {
|
||||
digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -301,15 +294,14 @@ const mp_obj_property_t digitalio_digitalio_drive_mode_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: pull
|
||||
//|
|
||||
//| The pin pull direction. One of:
|
||||
//| pull: Any = ...
|
||||
//| """The pin pull direction. One of:
|
||||
//|
|
||||
//| - `digitalio.Pull.UP`
|
||||
//| - `digitalio.Pull.DOWN`
|
||||
//| - `None`
|
||||
//|
|
||||
//| :raises AttributeError: if `direction` is :py:data:`~digitalio.Direction.OUTPUT`.
|
||||
//| :raises AttributeError: if `direction` is :py:data:`~digitalio.Direction.OUTPUT`."""
|
||||
//|
|
||||
STATIC mp_obj_t digitalio_digitalinout_obj_get_pull(mp_obj_t self_in) {
|
||||
digitalio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -38,23 +38,19 @@
|
|||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
|
||||
//| .. currentmodule:: digitalio
|
||||
//| class Direction:
|
||||
//| """Defines the direction of a digital pin"""
|
||||
//|
|
||||
//| :class:`Direction` -- defines the direction of a digital pin
|
||||
//| =============================================================
|
||||
//| def __init__(self, ):
|
||||
//| """Enum-like class to define which direction the digital values are
|
||||
//| going."""
|
||||
//| ...
|
||||
//|
|
||||
//| .. class:: Direction
|
||||
//| INPUT: Any = ...
|
||||
//| """Read digital data in"""
|
||||
//|
|
||||
//| Enum-like class to define which direction the digital values are
|
||||
//| going.
|
||||
//|
|
||||
//| .. data:: INPUT
|
||||
//|
|
||||
//| Read digital data in
|
||||
//|
|
||||
//| .. data:: OUTPUT
|
||||
//|
|
||||
//| Write digital data out
|
||||
//| OUTPUT: Any = ...
|
||||
//| """Write digital data out"""
|
||||
//|
|
||||
const mp_obj_type_t digitalio_direction_type;
|
||||
|
||||
|
|
|
@ -26,24 +26,20 @@
|
|||
|
||||
#include "shared-bindings/digitalio/DriveMode.h"
|
||||
|
||||
//| .. currentmodule:: digitalio
|
||||
//| class DriveMode:
|
||||
//| """Defines the drive mode of a digital pin"""
|
||||
//|
|
||||
//| :class:`DriveMode` -- defines the drive mode of a digital pin
|
||||
//| =============================================================
|
||||
//| def __init__(self, ):
|
||||
//| """Enum-like class to define the drive mode used when outputting
|
||||
//| digital values."""
|
||||
//| ...
|
||||
//|
|
||||
//| .. class:: DriveMode
|
||||
//| PUSH_PULL: Any = ...
|
||||
//| """Output both high and low digital values"""
|
||||
//|
|
||||
//| Enum-like class to define the drive mode used when outputting
|
||||
//| digital values.
|
||||
//|
|
||||
//| .. data:: PUSH_PULL
|
||||
//|
|
||||
//| Output both high and low digital values
|
||||
//|
|
||||
//| .. data:: OPEN_DRAIN
|
||||
//|
|
||||
//| Output low digital values but go into high z for digital high. This is
|
||||
//| useful for i2c and other protocols that share a digital line.
|
||||
//| OPEN_DRAIN: Any = ...
|
||||
//| """Output low digital values but go into high z for digital high. This is
|
||||
//| useful for i2c and other protocols that share a digital line."""
|
||||
//|
|
||||
const mp_obj_type_t digitalio_drive_mode_type;
|
||||
|
||||
|
|
|
@ -26,25 +26,21 @@
|
|||
|
||||
#include "shared-bindings/digitalio/Pull.h"
|
||||
|
||||
//| .. currentmodule:: digitalio
|
||||
//| class Pull:
|
||||
//| """Defines the pull of a digital input pin"""
|
||||
//|
|
||||
//| :class:`Pull` -- defines the pull of a digital input pin
|
||||
//| =============================================================
|
||||
//| def __init__(self, ):
|
||||
//| """Enum-like class to define the pull value, if any, used while reading
|
||||
//| digital values in."""
|
||||
//| ...
|
||||
//|
|
||||
//| .. class:: Pull
|
||||
//| UP: Any = ...
|
||||
//| """When the input line isn't being driven the pull up can pull the state
|
||||
//| of the line high so it reads as true."""
|
||||
//|
|
||||
//| Enum-like class to define the pull value, if any, used while reading
|
||||
//| digital values in.
|
||||
//|
|
||||
//| .. data:: UP
|
||||
//|
|
||||
//| When the input line isn't being driven the pull up can pull the state
|
||||
//| of the line high so it reads as true.
|
||||
//|
|
||||
//| .. data:: DOWN
|
||||
//|
|
||||
//| When the input line isn't being driven the pull down can pull the
|
||||
//| state of the line low so it reads as false.
|
||||
//| DOWN: Any = ...
|
||||
//| """When the input line isn't being driven the pull down can pull the
|
||||
//| state of the line low so it reads as false."""
|
||||
//|
|
||||
const mp_obj_type_t digitalio_pull_type;
|
||||
|
||||
|
|
|
@ -38,25 +38,10 @@
|
|||
|
||||
#include "py/runtime.h"
|
||||
|
||||
//| :mod:`digitalio` --- Basic digital pin support
|
||||
//| =================================================
|
||||
//|
|
||||
//| .. module:: digitalio
|
||||
//| :synopsis: Basic digital pin support
|
||||
//| :platform: SAMD21, ESP8266
|
||||
//| """Basic digital pin support
|
||||
//|
|
||||
//| The `digitalio` module contains classes to provide access to basic digital IO.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| DigitalInOut
|
||||
//| Direction
|
||||
//| DriveMode
|
||||
//| Pull
|
||||
//|
|
||||
//| All classes change hardware state and should be deinitialized when they
|
||||
//| are no longer needed if the program continues after use. To do so, either
|
||||
//| call :py:meth:`!deinit` or use a context manager. See
|
||||
|
@ -86,7 +71,7 @@
|
|||
//| led.value = True
|
||||
//| time.sleep(0.1)
|
||||
//| led.value = False
|
||||
//| time.sleep(0.1)
|
||||
//| time.sleep(0.1)"""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t digitalio_module_globals_table[] = {
|
||||
|
|
|
@ -36,22 +36,18 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class Bitmap:
|
||||
//| """Stores values of a certain size in a 2D array"""
|
||||
//|
|
||||
//| :class:`Bitmap` -- Stores values in a 2D array
|
||||
//| ==========================================================================
|
||||
//| def __init__(self, width: int, height: int, value_count: int):
|
||||
//| """Create a Bitmap object with the given fixed size. Each pixel stores a value that is used to
|
||||
//| index into a corresponding palette. This enables differently colored sprites to share the
|
||||
//| underlying Bitmap. value_count is used to minimize the memory used to store the Bitmap.
|
||||
//|
|
||||
//| Stores values of a certain size in a 2D array
|
||||
//|
|
||||
//| .. class:: Bitmap(width, height, value_count)
|
||||
//|
|
||||
//| Create a Bitmap object with the given fixed size. Each pixel stores a value that is used to
|
||||
//| index into a corresponding palette. This enables differently colored sprites to share the
|
||||
//| underlying Bitmap. value_count is used to minimize the memory used to store the Bitmap.
|
||||
//|
|
||||
//| :param int width: The number of values wide
|
||||
//| :param int height: The number of values high
|
||||
//| :param int value_count: The number of possible pixel values.
|
||||
//| :param int width: The number of values wide
|
||||
//| :param int height: The number of values high
|
||||
//| :param int value_count: The number of possible pixel values."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 3, 3, false);
|
||||
|
@ -77,9 +73,8 @@ STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_ar
|
|||
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
//| .. attribute:: width
|
||||
//|
|
||||
//| Width of the bitmap. (read only)
|
||||
//| width: Any = ...
|
||||
//| """Width of the bitmap. (read only)"""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_bitmap_obj_get_width(mp_obj_t self_in) {
|
||||
displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -96,9 +91,8 @@ const mp_obj_property_t displayio_bitmap_width_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: height
|
||||
//|
|
||||
//| Height of the bitmap. (read only)
|
||||
//| height: Any = ...
|
||||
//| """Height of the bitmap. (read only)"""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_bitmap_obj_get_height(mp_obj_t self_in) {
|
||||
displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -115,23 +109,23 @@ const mp_obj_property_t displayio_bitmap_height_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: __getitem__(index)
|
||||
//| def __getitem__(self, index: Any) -> Any:
|
||||
//| """Returns the value at the given index. The index can either be an x,y tuple or an int equal
|
||||
//| to ``y * width + x``.
|
||||
//|
|
||||
//| Returns the value at the given index. The index can either be an x,y tuple or an int equal
|
||||
//| to ``y * width + x``.
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| This allows you to::
|
||||
//| print(bitmap[0,1])"""
|
||||
//| ...
|
||||
//|
|
||||
//| print(bitmap[0,1])
|
||||
//| def __setitem__(self, index: Any, value: Any) -> Any:
|
||||
//| """Sets the value at the given index. The index can either be an x,y tuple or an int equal
|
||||
//| to ``y * width + x``.
|
||||
//|
|
||||
//| .. method:: __setitem__(index, value)
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| Sets the value at the given index. The index can either be an x,y tuple or an int equal
|
||||
//| to ``y * width + x``.
|
||||
//|
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| bitmap[0,1] = 3
|
||||
//| bitmap[0,1] = 3"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value_obj) {
|
||||
if (value_obj == mp_const_none) {
|
||||
|
@ -178,9 +172,9 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
//| .. method:: fill(value)
|
||||
//|
|
||||
//| Fills the bitmap with the supplied palette index value.
|
||||
//| def fill(self, value: Any) -> Any:
|
||||
//| """Fills the bitmap with the supplied palette index value."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_bitmap_obj_fill(mp_obj_t self_in, mp_obj_t value_obj) {
|
||||
displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -36,18 +36,15 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class ColorConverter:
|
||||
//| """Converts one color format to another."""
|
||||
//|
|
||||
//| :class:`ColorConverter` -- Converts one color format to another
|
||||
//| =========================================================================================
|
||||
//| def __init__(self, *, dither: bool = False):
|
||||
//| """Create a ColorConverter object to convert color formats. Only supports RGB888 to RGB565
|
||||
//| currently.
|
||||
//| :param bool dither: Adds random noise to dither the output image"""
|
||||
//| ...
|
||||
//|
|
||||
//| Converts one color format to another.
|
||||
//|
|
||||
//| .. class:: ColorConverter(*, dither=False)
|
||||
//|
|
||||
//| Create a ColorConverter object to convert color formats. Only supports RGB888 to RGB565
|
||||
//| currently.
|
||||
//| :param bool dither: Adds random noise to dither the output image
|
||||
|
||||
// TODO(tannewt): Add support for other color formats.
|
||||
//|
|
||||
|
@ -68,9 +65,9 @@ STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, siz
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: convert(color)
|
||||
//|
|
||||
//| Converts the given RGB888 color to RGB565
|
||||
//| def convert(self, color: Any) -> Any:
|
||||
//| """Converts the given RGB888 color to RGB565"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t color_obj) {
|
||||
displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -87,10 +84,9 @@ STATIC mp_obj_t displayio_colorconverter_obj_convert(mp_obj_t self_in, mp_obj_t
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_colorconverter_convert_obj, displayio_colorconverter_obj_convert);
|
||||
|
||||
//| .. attribute:: dither
|
||||
//|
|
||||
//| When true the color converter dithers the output by adding random noise when
|
||||
//| truncating to display bitdepth
|
||||
//| dither: Any = ...
|
||||
//| """When true the color converter dithers the output by adding random noise when
|
||||
//| truncating to display bitdepth"""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_colorconverter_obj_get_dither(mp_obj_t self_in) {
|
||||
displayio_colorconverter_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -39,73 +39,71 @@
|
|||
#include "shared-module/displayio/__init__.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class Display:
|
||||
//| """Manage updating a display over a display bus
|
||||
//|
|
||||
//| :class:`Display` -- Manage updating a display over a display bus
|
||||
//| ==========================================================================
|
||||
//| This initializes a display and connects it into CircuitPython. Unlike other
|
||||
//| objects in CircuitPython, Display objects live until `displayio.release_displays()`
|
||||
//| is called. This is done so that CircuitPython can use the display itself.
|
||||
//|
|
||||
//| This initializes a display and connects it into CircuitPython. Unlike other
|
||||
//| objects in CircuitPython, Display objects live until `displayio.release_displays()`
|
||||
//| is called. This is done so that CircuitPython can use the display itself.
|
||||
//| Most people should not use this class directly. Use a specific display driver instead that will
|
||||
//| contain the initialization sequence at minimum."""
|
||||
//|
|
||||
//| Most people should not use this class directly. Use a specific display driver instead that will
|
||||
//| contain the initialization sequence at minimum.
|
||||
//| def __init__(self, display_bus: Any, init_sequence: buffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, set_vertical_scroll: int = 0, backlight_pin: microcontroller.Pin = None, brightness_command: int = None, brightness: bool = 1.0, auto_brightness: bool = False, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60):
|
||||
//| """Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
|
||||
//|
|
||||
//| .. class:: Display(display_bus, init_sequence, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, bytes_per_cell=1, reverse_pixels_in_byte=False, set_column_command=0x2a, set_row_command=0x2b, write_ram_command=0x2c, set_vertical_scroll=0, backlight_pin=None, brightness_command=None, brightness=1.0, auto_brightness=False, single_byte_bounds=False, data_as_commands=False, auto_refresh=True, native_frames_per_second=60)
|
||||
//| The ``init_sequence`` is bitpacked to minimize the ram impact. Every command begins with a
|
||||
//| command byte followed by a byte to determine the parameter count and if a delay is need after.
|
||||
//| When the top bit of the second byte is 1, the next byte will be the delay time in milliseconds.
|
||||
//| The remaining 7 bits are the parameter count excluding any delay byte. The third through final
|
||||
//| bytes are the remaining command parameters. The next byte will begin a new command definition.
|
||||
//| Here is a portion of ILI9341 init code:
|
||||
//|
|
||||
//| Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
|
||||
//| .. code-block:: python
|
||||
//|
|
||||
//| The ``init_sequence`` is bitpacked to minimize the ram impact. Every command begins with a
|
||||
//| command byte followed by a byte to determine the parameter count and if a delay is need after.
|
||||
//| When the top bit of the second byte is 1, the next byte will be the delay time in milliseconds.
|
||||
//| The remaining 7 bits are the parameter count excluding any delay byte. The third through final
|
||||
//| bytes are the remaining command parameters. The next byte will begin a new command definition.
|
||||
//| Here is a portion of ILI9341 init code:
|
||||
//| init_sequence = (b"\xe1\x0f\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F" # Set Gamma
|
||||
//| b"\x11\x80\x78"# Exit Sleep then delay 0x78 (120ms)
|
||||
//| b"\x29\x80\x78"# Display on then delay 0x78 (120ms)
|
||||
//| )
|
||||
//| display = displayio.Display(display_bus, init_sequence, width=320, height=240)
|
||||
//|
|
||||
//| .. code-block:: python
|
||||
//| The first command is 0xe1 with 15 (0xf) parameters following. The second and third are 0x11 and
|
||||
//| 0x29 respectively with delays (0x80) of 120ms (0x78) and no parameters. Multiple byte literals
|
||||
//| (b"") are merged together on load. The parens are needed to allow byte literals on subsequent
|
||||
//| lines.
|
||||
//|
|
||||
//| init_sequence = (b"\xe1\x0f\x00\x0E\x14\x03\x11\x07\x31\xC1\x48\x08\x0F\x0C\x31\x36\x0F" # Set Gamma
|
||||
//| b"\x11\x80\x78"# Exit Sleep then delay 0x78 (120ms)
|
||||
//| b"\x29\x80\x78"# Display on then delay 0x78 (120ms)
|
||||
//| )
|
||||
//| display = displayio.Display(display_bus, init_sequence, width=320, height=240)
|
||||
//| The initialization sequence should always leave the display memory access inline with the scan
|
||||
//| of the display to minimize tearing artifacts.
|
||||
//|
|
||||
//| The first command is 0xe1 with 15 (0xf) parameters following. The second and third are 0x11 and
|
||||
//| 0x29 respectively with delays (0x80) of 120ms (0x78) and no parameters. Multiple byte literals
|
||||
//| (b"") are merged together on load. The parens are needed to allow byte literals on subsequent
|
||||
//| lines.
|
||||
//|
|
||||
//| The initialization sequence should always leave the display memory access inline with the scan
|
||||
//| of the display to minimize tearing artifacts.
|
||||
//|
|
||||
//| :param display_bus: The bus that the display is connected to
|
||||
//| :type display_bus: displayio.FourWire or displayio.ParallelBus
|
||||
//| :param buffer init_sequence: Byte-packed initialization sequence.
|
||||
//| :param int width: Width in pixels
|
||||
//| :param int height: Height in pixels
|
||||
//| :param int colstart: The index if the first visible column
|
||||
//| :param int rowstart: The index if the first visible row
|
||||
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
|
||||
//| :param int color_depth: The number of bits of color per pixel transmitted. (Some displays
|
||||
//| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.)
|
||||
//| :param bool grayscale: True if the display only shows a single color.
|
||||
//| :param bool pixels_in_byte_share_row: True when pixels are less than a byte and a byte includes pixels from the same row of the display. When False, pixels share a column.
|
||||
//| :param int bytes_per_cell: Number of bytes per addressable memory location when color_depth < 8. When greater than one, bytes share a row or column according to pixels_in_byte_share_row.
|
||||
//| :param bool reverse_pixels_in_byte: Reverses the pixel order within each byte when color_depth < 8. Does not apply across multiple bytes even if there is more than one byte per cell (bytes_per_cell.)
|
||||
//| :param bool reverse_bytes_in_word: Reverses the order of bytes within a word when color_depth == 16
|
||||
//| :param int set_column_command: Command used to set the start and end columns to update
|
||||
//| :param int set_row_command: Command used so set the start and end rows to update
|
||||
//| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set.
|
||||
//| :param int set_vertical_scroll: Command used to set the first row to show
|
||||
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
|
||||
//| :param int brightness_command: Command to set display brightness. Usually available in OLED controllers.
|
||||
//| :param bool brightness: Initial display brightness. This value is ignored if auto_brightness is True.
|
||||
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
|
||||
//| :param bool single_byte_bounds: Display column and row commands use single bytes
|
||||
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
|
||||
//| :param bool auto_refresh: Automatically refresh the screen
|
||||
//| :param int native_frames_per_second: Number of display refreshes per second that occur with the given init_sequence.
|
||||
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on.
|
||||
//| :param display_bus: The bus that the display is connected to
|
||||
//| :type display_bus: displayio.FourWire or displayio.ParallelBus
|
||||
//| :param buffer init_sequence: Byte-packed initialization sequence.
|
||||
//| :param int width: Width in pixels
|
||||
//| :param int height: Height in pixels
|
||||
//| :param int colstart: The index if the first visible column
|
||||
//| :param int rowstart: The index if the first visible row
|
||||
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
|
||||
//| :param int color_depth: The number of bits of color per pixel transmitted. (Some displays
|
||||
//| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.)
|
||||
//| :param bool grayscale: True if the display only shows a single color.
|
||||
//| :param bool pixels_in_byte_share_row: True when pixels are less than a byte and a byte includes pixels from the same row of the display. When False, pixels share a column.
|
||||
//| :param int bytes_per_cell: Number of bytes per addressable memory location when color_depth < 8. When greater than one, bytes share a row or column according to pixels_in_byte_share_row.
|
||||
//| :param bool reverse_pixels_in_byte: Reverses the pixel order within each byte when color_depth < 8. Does not apply across multiple bytes even if there is more than one byte per cell (bytes_per_cell.)
|
||||
//| :param bool reverse_bytes_in_word: Reverses the order of bytes within a word when color_depth == 16
|
||||
//| :param int set_column_command: Command used to set the start and end columns to update
|
||||
//| :param int set_row_command: Command used so set the start and end rows to update
|
||||
//| :param int write_ram_command: Command used to write pixels values into the update region. Ignored if data_as_commands is set.
|
||||
//| :param int set_vertical_scroll: Command used to set the first row to show
|
||||
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
|
||||
//| :param int brightness_command: Command to set display brightness. Usually available in OLED controllers.
|
||||
//| :param bool brightness: Initial display brightness. This value is ignored if auto_brightness is True.
|
||||
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
|
||||
//| :param bool single_byte_bounds: Display column and row commands use single bytes
|
||||
//| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this.
|
||||
//| :param bool auto_refresh: Automatically refresh the screen
|
||||
//| :param int native_frames_per_second: Number of display refreshes per second that occur with the given init_sequence.
|
||||
//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high };
|
||||
|
@ -190,12 +188,13 @@ static displayio_display_obj_t* native_display(mp_obj_t display_obj) {
|
|||
return MP_OBJ_TO_PTR(native_display);
|
||||
}
|
||||
|
||||
//| .. method:: show(group)
|
||||
//| def show(self, group: Group) -> Any:
|
||||
//| """Switches to displaying the given group of layers. When group is None, the default
|
||||
//| CircuitPython terminal will be shown.
|
||||
//|
|
||||
//| Switches to displaying the given group of layers. When group is None, the default
|
||||
//| CircuitPython terminal will be shown.
|
||||
//| :param Group group: The group to show."""
|
||||
//| ...
|
||||
//|
|
||||
//| :param Group group: The group to show.
|
||||
STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
|
||||
displayio_display_obj_t *self = native_display(self_in);
|
||||
displayio_group_t* group = NULL;
|
||||
|
@ -211,21 +210,21 @@ STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in)
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show);
|
||||
|
||||
//| .. method:: refresh(*, target_frames_per_second=60, minimum_frames_per_second=1)
|
||||
//| def refresh(self, *, target_frames_per_second: int = 60, minimum_frames_per_second: int = 1) -> Any:
|
||||
//| """When auto refresh is off, waits for the target frame rate and then refreshes the display,
|
||||
//| returning True. If the call has taken too long since the last refresh call for the given
|
||||
//| target frame rate, then the refresh returns False immediately without updating the screen to
|
||||
//| hopefully help getting caught up.
|
||||
//|
|
||||
//| When auto refresh is off, waits for the target frame rate and then refreshes the display,
|
||||
//| returning True. If the call has taken too long since the last refresh call for the given
|
||||
//| target frame rate, then the refresh returns False immediately without updating the screen to
|
||||
//| hopefully help getting caught up.
|
||||
//| If the time since the last successful refresh is below the minimum frame rate, then an
|
||||
//| exception will be raised. Set minimum_frames_per_second to 0 to disable.
|
||||
//|
|
||||
//| If the time since the last successful refresh is below the minimum frame rate, then an
|
||||
//| exception will be raised. Set minimum_frames_per_second to 0 to disable.
|
||||
//| When auto refresh is on, updates the display immediately. (The display will also update
|
||||
//| without calls to this.)
|
||||
//|
|
||||
//| When auto refresh is on, updates the display immediately. (The display will also update
|
||||
//| without calls to this.)
|
||||
//|
|
||||
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
|
||||
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second.
|
||||
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
|
||||
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_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 };
|
||||
|
@ -246,9 +245,8 @@ STATIC mp_obj_t displayio_display_obj_refresh(size_t n_args, const mp_obj_t *pos
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_display_refresh_obj, 1, displayio_display_obj_refresh);
|
||||
|
||||
//| .. attribute:: auto_refresh
|
||||
//|
|
||||
//| True when the display is refreshed automatically.
|
||||
//| auto_refresh: Any = ...
|
||||
//| """True when the display is refreshed automatically."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_obj_get_auto_refresh(mp_obj_t self_in) {
|
||||
displayio_display_obj_t *self = native_display(self_in);
|
||||
|
@ -272,11 +270,10 @@ const mp_obj_property_t displayio_display_auto_refresh_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: brightness
|
||||
//|
|
||||
//| The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
|
||||
//| brightness: Any = ...
|
||||
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
|
||||
//| `auto_brightness` is True, the value of `brightness` will change automatically.
|
||||
//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False.
|
||||
//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) {
|
||||
displayio_display_obj_t *self = native_display(self_in);
|
||||
|
@ -310,12 +307,11 @@ const mp_obj_property_t displayio_display_brightness_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: auto_brightness
|
||||
//|
|
||||
//| True when the display brightness is adjusted automatically, based on an ambient
|
||||
//| auto_brightness: Any = ...
|
||||
//| """True when the display brightness is adjusted automatically, based on an ambient
|
||||
//| light sensor or other method. Note that some displays may have this set to True by default,
|
||||
//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False
|
||||
//| if `brightness` is set manually.
|
||||
//| if `brightness` is set manually."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_obj_get_auto_brightness(mp_obj_t self_in) {
|
||||
displayio_display_obj_t *self = native_display(self_in);
|
||||
|
@ -342,9 +338,8 @@ const mp_obj_property_t displayio_display_auto_brightness_obj = {
|
|||
|
||||
|
||||
|
||||
//| .. attribute:: width
|
||||
//|
|
||||
//| Gets the width of the board
|
||||
//| width: Any = ...
|
||||
//| Gets the width of the board
|
||||
//|
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_obj_get_width(mp_obj_t self_in) {
|
||||
|
@ -360,9 +355,8 @@ const mp_obj_property_t displayio_display_width_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: height
|
||||
//|
|
||||
//| Gets the height of the board
|
||||
//| height: Any = ...
|
||||
//| """Gets the height of the board"""
|
||||
//|
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_obj_get_height(mp_obj_t self_in) {
|
||||
|
@ -378,9 +372,8 @@ const mp_obj_property_t displayio_display_height_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: rotation
|
||||
//|
|
||||
//| The rotation of the display as an int in degrees.
|
||||
//| rotation: Any = ...
|
||||
//| """The rotation of the display as an int in degrees."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_obj_get_rotation(mp_obj_t self_in) {
|
||||
displayio_display_obj_t *self = native_display(self_in);
|
||||
|
@ -402,9 +395,8 @@ const mp_obj_property_t displayio_display_rotation_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: bus
|
||||
//|
|
||||
//| The bus being used by the display
|
||||
//| bus: Any = ...
|
||||
//| """The bus being used by the display"""
|
||||
//|
|
||||
//|
|
||||
STATIC mp_obj_t displayio_display_obj_get_bus(mp_obj_t self_in) {
|
||||
|
@ -421,12 +413,13 @@ const mp_obj_property_t displayio_display_bus_obj = {
|
|||
};
|
||||
|
||||
|
||||
//| .. method:: fill_row(y, buffer)
|
||||
//| def fill_row(self, y: int, buffer: bytearray) -> Any:
|
||||
//| """Extract the pixels from a single row
|
||||
//|
|
||||
//| Extract the pixels from a single row
|
||||
//| :param int y: The top edge of the area
|
||||
//| :param bytearray buffer: The buffer in which to place the pixel data"""
|
||||
//| ...
|
||||
//|
|
||||
//| :param int y: The top edge of the area
|
||||
//| :param bytearray buffer: The buffer in which to place the pixel data
|
||||
STATIC mp_obj_t displayio_display_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[] = {
|
||||
|
|
|
@ -39,55 +39,53 @@
|
|||
#include "shared-module/displayio/__init__.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class EPaperDisplay:
|
||||
//| """Manage updating an epaper display over a display bus
|
||||
//|
|
||||
//| :class:`EPaperDisplay` -- Manage updating an epaper display over a display bus
|
||||
//| ==============================================================================
|
||||
//| This initializes an epaper display and connects it into CircuitPython. Unlike other
|
||||
//| objects in CircuitPython, EPaperDisplay objects live until `displayio.release_displays()`
|
||||
//| is called. This is done so that CircuitPython can use the display itself.
|
||||
//|
|
||||
//| This initializes an epaper display and connects it into CircuitPython. Unlike other
|
||||
//| objects in CircuitPython, EPaperDisplay objects live until `displayio.release_displays()`
|
||||
//| is called. This is done so that CircuitPython can use the display itself.
|
||||
//| Most people should not use this class directly. Use a specific display driver instead that will
|
||||
//| contain the startup and shutdown sequences at minimum."""
|
||||
//|
|
||||
//| Most people should not use this class directly. Use a specific display driver instead that will
|
||||
//| contain the startup and shutdown sequences at minimum.
|
||||
//| def __init__(self, display_bus: Any, start_sequence: buffer, stop_sequence: buffer, *, width: int, height: int, ram_width: int, ram_height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, set_column_window_command: int = None, set_row_window_command: int = None, single_byte_bounds: Any = False, write_black_ram_command: int, black_bits_inverted: bool = False, write_color_ram_command: int = None, color_bits_inverted: bool = False, highlight_color: int = 0x000000, refresh_display_command: int, refresh_time: float = 40, busy_pin: microcontroller.Pin = None, busy_state: bool = True, seconds_per_frame: float = 180, always_toggle_chip_select: bool = False):
|
||||
//| """Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
|
||||
//|
|
||||
//| .. class:: EPaperDisplay(display_bus, start_sequence, stop_sequence, *, width, height, ram_width, ram_height, colstart=0, rowstart=0, rotation=0, set_column_window_command=None, set_row_window_command=None, single_byte_bounds=False, write_black_ram_command, black_bits_inverted=False, write_color_ram_command=None, color_bits_inverted=False, highlight_color=0x000000, refresh_display_command, refresh_time=40, busy_pin=None, busy_state=True, seconds_per_frame=180, always_toggle_chip_select=False)
|
||||
//| The ``start_sequence`` and ``stop_sequence`` are bitpacked to minimize the ram impact. Every
|
||||
//| command begins with a command byte followed by a byte to determine the parameter count and if
|
||||
//| a delay is need after. When the top bit of the second byte is 1, the next byte will be the
|
||||
//| delay time in milliseconds. The remaining 7 bits are the parameter count excluding any delay
|
||||
//| byte. The third through final bytes are the remaining command parameters. The next byte will
|
||||
//| begin a new command definition.
|
||||
//|
|
||||
//| Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
|
||||
//|
|
||||
//| The ``start_sequence`` and ``stop_sequence`` are bitpacked to minimize the ram impact. Every
|
||||
//| command begins with a command byte followed by a byte to determine the parameter count and if
|
||||
//| a delay is need after. When the top bit of the second byte is 1, the next byte will be the
|
||||
//| delay time in milliseconds. The remaining 7 bits are the parameter count excluding any delay
|
||||
//| byte. The third through final bytes are the remaining command parameters. The next byte will
|
||||
//| begin a new command definition.
|
||||
//|
|
||||
//| :param display_bus: The bus that the display is connected to
|
||||
//| :type display_bus: displayio.FourWire or displayio.ParallelBus
|
||||
//| :param buffer start_sequence: Byte-packed initialization sequence.
|
||||
//| :param buffer stop_sequence: Byte-packed initialization sequence.
|
||||
//| :param int width: Width in pixels
|
||||
//| :param int height: Height in pixels
|
||||
//| :param int ram_width: RAM width in pixels
|
||||
//| :param int ram_height: RAM height in pixels
|
||||
//| :param int colstart: The index if the first visible column
|
||||
//| :param int rowstart: The index if the first visible row
|
||||
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
|
||||
//| :param int set_column_window_command: Command used to set the start and end columns to update
|
||||
//| :param int set_row_window_command: Command used so set the start and end rows to update
|
||||
//| :param int set_current_column_command: Command used to set the current column location
|
||||
//| :param int set_current_row_command: Command used to set the current row location
|
||||
//| :param int write_black_ram_command: Command used to write pixels values into the update region
|
||||
//| :param bool black_bits_inverted: True if 0 bits are used to show black pixels. Otherwise, 1 means to show black.
|
||||
//| :param int write_color_ram_command: Command used to write pixels values into the update region
|
||||
//| :param bool color_bits_inverted: True if 0 bits are used to show the color. Otherwise, 1 means to show color.
|
||||
//| :param int highlight_color: RGB888 of source color to highlight with third ePaper color.
|
||||
//| :param int refresh_display_command: Command used to start a display refresh
|
||||
//| :param float refresh_time: Time it takes to refresh the display before the stop_sequence should be sent. Ignored when busy_pin is provided.
|
||||
//| :param microcontroller.Pin busy_pin: Pin used to signify the display is busy
|
||||
//| :param bool busy_state: State of the busy pin when the display is busy
|
||||
//| :param float seconds_per_frame: Minimum number of seconds between screen refreshes
|
||||
//| :param bool always_toggle_chip_select: When True, chip select is toggled every byte
|
||||
//| :param display_bus: The bus that the display is connected to
|
||||
//| :type display_bus: displayio.FourWire or displayio.ParallelBus
|
||||
//| :param buffer start_sequence: Byte-packed initialization sequence.
|
||||
//| :param buffer stop_sequence: Byte-packed initialization sequence.
|
||||
//| :param int width: Width in pixels
|
||||
//| :param int height: Height in pixels
|
||||
//| :param int ram_width: RAM width in pixels
|
||||
//| :param int ram_height: RAM height in pixels
|
||||
//| :param int colstart: The index if the first visible column
|
||||
//| :param int rowstart: The index if the first visible row
|
||||
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
|
||||
//| :param int set_column_window_command: Command used to set the start and end columns to update
|
||||
//| :param int set_row_window_command: Command used so set the start and end rows to update
|
||||
//| :param int set_current_column_command: Command used to set the current column location
|
||||
//| :param int set_current_row_command: Command used to set the current row location
|
||||
//| :param int write_black_ram_command: Command used to write pixels values into the update region
|
||||
//| :param bool black_bits_inverted: True if 0 bits are used to show black pixels. Otherwise, 1 means to show black.
|
||||
//| :param int write_color_ram_command: Command used to write pixels values into the update region
|
||||
//| :param bool color_bits_inverted: True if 0 bits are used to show the color. Otherwise, 1 means to show color.
|
||||
//| :param int highlight_color: RGB888 of source color to highlight with third ePaper color.
|
||||
//| :param int refresh_display_command: Command used to start a display refresh
|
||||
//| :param float refresh_time: Time it takes to refresh the display before the stop_sequence should be sent. Ignored when busy_pin is provided.
|
||||
//| :param microcontroller.Pin busy_pin: Pin used to signify the display is busy
|
||||
//| :param bool busy_state: State of the busy pin when the display is busy
|
||||
//| :param float seconds_per_frame: Minimum number of seconds between screen refreshes
|
||||
//| :param bool always_toggle_chip_select: When True, chip select is toggled every byte"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_display_bus, ARG_start_sequence, ARG_stop_sequence, ARG_width, ARG_height, ARG_ram_width, ARG_ram_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_set_column_window_command, ARG_set_row_window_command, ARG_set_current_column_command, ARG_set_current_row_command, ARG_write_black_ram_command, ARG_black_bits_inverted, ARG_write_color_ram_command, ARG_color_bits_inverted, ARG_highlight_color, ARG_refresh_display_command, ARG_refresh_time, ARG_busy_pin, ARG_busy_state, ARG_seconds_per_frame, ARG_always_toggle_chip_select };
|
||||
|
@ -170,12 +168,13 @@ static displayio_epaperdisplay_obj_t* native_display(mp_obj_t display_obj) {
|
|||
return MP_OBJ_TO_PTR(native_display);
|
||||
}
|
||||
|
||||
//| .. method:: show(group)
|
||||
//| def show(self, group: Group) -> Any:
|
||||
//| """Switches to displaying the given group of layers. When group is None, the default
|
||||
//| CircuitPython terminal will be shown.
|
||||
//|
|
||||
//| Switches to displaying the given group of layers. When group is None, the default
|
||||
//| CircuitPython terminal will be shown.
|
||||
//| :param Group group: The group to show."""
|
||||
//| ...
|
||||
//|
|
||||
//| :param Group group: The group to show.
|
||||
STATIC mp_obj_t displayio_epaperdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
|
||||
displayio_epaperdisplay_obj_t *self = native_display(self_in);
|
||||
displayio_group_t* group = NULL;
|
||||
|
@ -191,10 +190,10 @@ STATIC mp_obj_t displayio_epaperdisplay_obj_show(mp_obj_t self_in, mp_obj_t grou
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_epaperdisplay_show_obj, displayio_epaperdisplay_obj_show);
|
||||
|
||||
//| .. method:: refresh()
|
||||
//|
|
||||
//| Refreshes the display immediately or raises an exception if too soon. Use
|
||||
//| ``time.sleep(display.time_to_refresh)`` to sleep until a refresh can occur.
|
||||
//| def refresh(self, ) -> Any:
|
||||
//| """Refreshes the display immediately or raises an exception if too soon. Use
|
||||
//| ``time.sleep(display.time_to_refresh)`` to sleep until a refresh can occur."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_epaperdisplay_obj_refresh(mp_obj_t self_in) {
|
||||
displayio_epaperdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -206,10 +205,8 @@ STATIC mp_obj_t displayio_epaperdisplay_obj_refresh(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_epaperdisplay_refresh_obj, displayio_epaperdisplay_obj_refresh);
|
||||
|
||||
//| .. attribute:: time_to_refresh
|
||||
//|
|
||||
//| Time, in fractional seconds, until the ePaper display can be refreshed.
|
||||
//|
|
||||
//| time_to_refresh: Any = ...
|
||||
//| """Time, in fractional seconds, until the ePaper display can be refreshed."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_epaperdisplay_obj_get_time_to_refresh(mp_obj_t self_in) {
|
||||
displayio_epaperdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -224,10 +221,8 @@ const mp_obj_property_t displayio_epaperdisplay_time_to_refresh_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: width
|
||||
//|
|
||||
//| Gets the width of the display in pixels
|
||||
//|
|
||||
//| width: Any = ...
|
||||
//| """Gets the width of the display in pixels"""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_epaperdisplay_obj_get_width(mp_obj_t self_in) {
|
||||
displayio_epaperdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -242,10 +237,8 @@ const mp_obj_property_t displayio_epaperdisplay_width_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: height
|
||||
//|
|
||||
//| Gets the height of the display in pixels
|
||||
//|
|
||||
//| height: Any = ...
|
||||
//| """Gets the height of the display in pixels"""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_epaperdisplay_obj_get_height(mp_obj_t self_in) {
|
||||
displayio_epaperdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -260,10 +253,8 @@ const mp_obj_property_t displayio_epaperdisplay_height_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: bus
|
||||
//|
|
||||
//| The bus being used by the display
|
||||
//|
|
||||
//| bus: Any = ...
|
||||
//| """The bus being used by the display"""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_epaperdisplay_obj_get_bus(mp_obj_t self_in) {
|
||||
displayio_epaperdisplay_obj_t *self = native_display(self_in);
|
||||
|
|
|
@ -38,31 +38,27 @@
|
|||
#include "shared-module/displayio/__init__.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class FourWire:
|
||||
//| """Manage updating a display over SPI four wire protocol in the background while Python code runs.
|
||||
//| It doesn't handle display initialization."""
|
||||
//|
|
||||
//| :class:`FourWire` -- Manage updating a display over SPI four wire protocol
|
||||
//| ==========================================================================
|
||||
//| def __init__(self, spi_bus: busio.SPI, *, command: microcontroller.Pin, chip_select: microcontroller.Pin, reset: microcontroller.Pin = None, baudrate: int = 24000000, polarity: int = 0, phase: int = 0):
|
||||
//| """Create a FourWire object associated with the given pins.
|
||||
//|
|
||||
//| Manage updating a display over SPI four wire protocol in the background while Python code runs.
|
||||
//| It doesn't handle display initialization.
|
||||
//| The SPI bus and pins are then in use by the display until `displayio.release_displays()` is
|
||||
//| called even after a reload. (It does this so CircuitPython can use the display after your code
|
||||
//| is done.) So, the first time you initialize a display bus in code.py you should call
|
||||
//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run.
|
||||
//|
|
||||
//| .. class:: FourWire(spi_bus, *, command, chip_select, reset=None, baudrate=24000000, polarity=0, phase=0)
|
||||
//|
|
||||
//| Create a FourWire object associated with the given pins.
|
||||
//|
|
||||
//| The SPI bus and pins are then in use by the display until `displayio.release_displays()` is
|
||||
//| called even after a reload. (It does this so CircuitPython can use the display after your code
|
||||
//| is done.) So, the first time you initialize a display bus in code.py you should call
|
||||
//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run.
|
||||
//|
|
||||
//| :param busio.SPI spi_bus: The SPI bus that make up the clock and data lines
|
||||
//| :param microcontroller.Pin command: Data or command pin
|
||||
//| :param microcontroller.Pin chip_select: Chip select pin
|
||||
//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used
|
||||
//| :param int baudrate: Maximum baudrate in Hz for the display on the bus
|
||||
//| :param int polarity: the base state of the clock line (0 or 1)
|
||||
//| :param int phase: the edge of the clock that data is captured. First (0)
|
||||
//| or second (1). Rising or falling depends on clock polarity.
|
||||
//| :param busio.SPI spi_bus: The SPI bus that make up the clock and data lines
|
||||
//| :param microcontroller.Pin command: Data or command pin
|
||||
//| :param microcontroller.Pin chip_select: Chip select pin
|
||||
//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used
|
||||
//| :param int baudrate: Maximum baudrate in Hz for the display on the bus
|
||||
//| :param int polarity: the base state of the clock line (0 or 1)
|
||||
//| :param int phase: the edge of the clock that data is captured. First (0)
|
||||
//| or second (1). Rising or falling depends on clock polarity."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset, ARG_baudrate, ARG_polarity, ARG_phase };
|
||||
|
@ -100,10 +96,10 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_
|
|||
return self;
|
||||
}
|
||||
|
||||
//| .. method:: reset()
|
||||
//|
|
||||
//| Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
|
||||
//| is available.
|
||||
//| def reset(self, ) -> Any:
|
||||
//| """Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
|
||||
//| is available."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_obj_reset(mp_obj_t self_in) {
|
||||
displayio_fourwire_obj_t *self = self_in;
|
||||
|
@ -115,10 +111,10 @@ STATIC mp_obj_t displayio_fourwire_obj_reset(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_fourwire_reset_obj, displayio_fourwire_obj_reset);
|
||||
|
||||
//| .. method:: send(command, data, *, toggle_every_byte=False)
|
||||
//|
|
||||
//| Sends the given command value followed by the full set of data. Display state, such as
|
||||
//| vertical scroll, set via ``send`` may or may not be reset once the code is done.
|
||||
//| def send(self, command: Any, data: Any, *, toggle_every_byte: Any = False) -> Any:
|
||||
//| """Sends the given command value followed by the full set of data. Display state, such as
|
||||
//| vertical scroll, set via ``send`` may or may not be reset once the code is done."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_fourwire_obj_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_command, ARG_data, ARG_toggle_every_byte };
|
||||
|
|
|
@ -35,22 +35,18 @@
|
|||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class Group:
|
||||
//| """Manage a group of sprites and groups and how they are inter-related."""
|
||||
//|
|
||||
//| :class:`Group` -- Group together sprites and subgroups
|
||||
//| ==========================================================================
|
||||
//| def __init__(self, *, max_size: int = 4, scale: int = 1, x: int = 0, y: int = 0):
|
||||
//| """Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2
|
||||
//| leads to a layer's pixel being 2x2 pixels when in the group.
|
||||
//|
|
||||
//| Manage a group of sprites and groups and how they are inter-related.
|
||||
//|
|
||||
//| .. class:: Group(*, max_size=4, scale=1, x=0, y=0)
|
||||
//|
|
||||
//| Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2
|
||||
//| leads to a layer's pixel being 2x2 pixels when in the group.
|
||||
//|
|
||||
//| :param int max_size: The maximum group size.
|
||||
//| :param int scale: Scale of layer pixels in one dimension.
|
||||
//| :param int x: Initial x position within the parent.
|
||||
//| :param int y: Initial y position within the parent.
|
||||
//| :param int max_size: The maximum group size.
|
||||
//| :param int scale: Scale of layer pixels in one dimension.
|
||||
//| :param int x: Initial x position within the parent.
|
||||
//| :param int y: Initial y position within the parent."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_max_size, ARG_scale, ARG_x, ARG_y };
|
||||
|
@ -90,10 +86,9 @@ displayio_group_t* native_group(mp_obj_t group_obj) {
|
|||
return MP_OBJ_TO_PTR(native_group);
|
||||
}
|
||||
|
||||
//| .. attribute:: hidden
|
||||
//|
|
||||
//| True when the Group and all of it's layers are not visible. When False, the Group's layers
|
||||
//| are visible if they haven't been hidden.
|
||||
//| hidden: Any = ...
|
||||
//| """True when the Group and all of it's layers are not visible. When False, the Group's layers
|
||||
//| are visible if they haven't been hidden."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_get_hidden(mp_obj_t self_in) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
@ -116,10 +111,9 @@ const mp_obj_property_t displayio_group_hidden_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: scale
|
||||
//|
|
||||
//| Scales each pixel within the Group in both directions. For example, when scale=2 each pixel
|
||||
//| will be represented by 2x2 pixels.
|
||||
//| scale: Any = ...
|
||||
//| """Scales each pixel within the Group in both directions. For example, when scale=2 each pixel
|
||||
//| will be represented by 2x2 pixels."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_get_scale(mp_obj_t self_in) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
@ -146,9 +140,8 @@ const mp_obj_property_t displayio_group_scale_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: x
|
||||
//|
|
||||
//| X position of the Group in the parent.
|
||||
//| x: Any = ...
|
||||
//| """X position of the Group in the parent."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_get_x(mp_obj_t self_in) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
@ -172,9 +165,8 @@ const mp_obj_property_t displayio_group_x_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: y
|
||||
//|
|
||||
//| Y position of the Group in the parent.
|
||||
//| y: Any = ...
|
||||
//| """Y position of the Group in the parent."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_get_y(mp_obj_t self_in) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
@ -198,9 +190,9 @@ const mp_obj_property_t displayio_group_y_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: append(layer)
|
||||
//|
|
||||
//| Append a layer to the group. It will be drawn above other layers.
|
||||
//| def append(self, layer: Any) -> Any:
|
||||
//| """Append a layer to the group. It will be drawn above other layers."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_append(mp_obj_t self_in, mp_obj_t layer) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
@ -209,9 +201,9 @@ STATIC mp_obj_t displayio_group_obj_append(mp_obj_t self_in, mp_obj_t layer) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_append_obj, displayio_group_obj_append);
|
||||
|
||||
//| .. method:: insert(index, layer)
|
||||
//|
|
||||
//| Insert a layer into the group.
|
||||
//| def insert(self, index: Any, layer: Any) -> Any:
|
||||
//| """Insert a layer into the group."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_insert(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t layer) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
@ -222,9 +214,9 @@ STATIC mp_obj_t displayio_group_obj_insert(mp_obj_t self_in, mp_obj_t index_obj,
|
|||
MP_DEFINE_CONST_FUN_OBJ_3(displayio_group_insert_obj, displayio_group_obj_insert);
|
||||
|
||||
|
||||
//| .. method:: index(layer)
|
||||
//|
|
||||
//| Returns the index of the first copy of layer. Raises ValueError if not found.
|
||||
//| def index(self, layer: Any) -> Any:
|
||||
//| """Returns the index of the first copy of layer. Raises ValueError if not found."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_index(mp_obj_t self_in, mp_obj_t layer) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
@ -236,9 +228,9 @@ STATIC mp_obj_t displayio_group_obj_index(mp_obj_t self_in, mp_obj_t layer) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_index_obj, displayio_group_obj_index);
|
||||
|
||||
//| .. method:: pop(i=-1)
|
||||
//|
|
||||
//| Remove the ith item and return it.
|
||||
//| def pop(self, i: Any = -1) -> Any:
|
||||
//| """Remove the ith item and return it."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_pop(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_i };
|
||||
|
@ -259,9 +251,9 @@ STATIC mp_obj_t displayio_group_obj_pop(size_t n_args, const mp_obj_t *pos_args,
|
|||
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_group_pop_obj, 1, displayio_group_obj_pop);
|
||||
|
||||
|
||||
//| .. method:: remove(layer)
|
||||
//|
|
||||
//| Remove the first copy of layer. Raises ValueError if it is not present.
|
||||
//| def remove(self, layer: Any) -> Any:
|
||||
//| """Remove the first copy of layer. Raises ValueError if it is not present."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_group_obj_remove(mp_obj_t self_in, mp_obj_t layer) {
|
||||
mp_obj_t index = displayio_group_obj_index(self_in, layer);
|
||||
|
@ -272,9 +264,9 @@ STATIC mp_obj_t displayio_group_obj_remove(mp_obj_t self_in, mp_obj_t layer) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_remove_obj, displayio_group_obj_remove);
|
||||
|
||||
//| .. method:: __len__()
|
||||
//|
|
||||
//| Returns the number of layers in a Group
|
||||
//| def __len__(self, ) -> Any:
|
||||
//| """Returns the number of layers in a Group"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
@ -286,29 +278,29 @@ STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __getitem__(index)
|
||||
//| def __getitem__(self, index: Any) -> Any:
|
||||
//| """Returns the value at the given index.
|
||||
//|
|
||||
//| Returns the value at the given index.
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| This allows you to::
|
||||
//| print(group[0])"""
|
||||
//| ...
|
||||
//|
|
||||
//| print(group[0])
|
||||
//| def __setitem__(self, index: Any, value: Any) -> Any:
|
||||
//| """Sets the value at the given index.
|
||||
//|
|
||||
//| .. method:: __setitem__(index, value)
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| Sets the value at the given index.
|
||||
//| group[0] = sprite"""
|
||||
//| ...
|
||||
//|
|
||||
//| This allows you to::
|
||||
//| def __delitem__(self, index: Any) -> Any:
|
||||
//| """Deletes the value at the given index.
|
||||
//|
|
||||
//| group[0] = sprite
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| .. method:: __delitem__(index)
|
||||
//|
|
||||
//| Deletes the value at the given index.
|
||||
//|
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| del group[0]
|
||||
//| del group[0]"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t group_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value) {
|
||||
displayio_group_t *self = native_group(self_in);
|
||||
|
|
|
@ -38,26 +38,22 @@
|
|||
#include "shared-module/displayio/__init__.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class I2CDisplay:
|
||||
//| """Manage updating a display over I2C in the background while Python code runs.
|
||||
//| It doesn't handle display initialization."""
|
||||
//|
|
||||
//| :class:`I2CDisplay` -- Manage updating a display over I2C
|
||||
//| ==========================================================================
|
||||
//| def __init__(self, i2c_bus: busio.I2C, *, device_address: int, reset: microcontroller.Pin = None):
|
||||
//| """Create a I2CDisplay object associated with the given I2C bus and reset pin.
|
||||
//|
|
||||
//| Manage updating a display over I2C in the background while Python code runs.
|
||||
//| It doesn't handle display initialization.
|
||||
//| The I2C bus and pins are then in use by the display until `displayio.release_displays()` is
|
||||
//| called even after a reload. (It does this so CircuitPython can use the display after your code
|
||||
//| is done.) So, the first time you initialize a display bus in code.py you should call
|
||||
//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run.
|
||||
//|
|
||||
//| .. class:: I2CDisplay(i2c_bus, *, device_address, reset=None)
|
||||
//|
|
||||
//| Create a I2CDisplay object associated with the given I2C bus and reset pin.
|
||||
//|
|
||||
//| The I2C bus and pins are then in use by the display until `displayio.release_displays()` is
|
||||
//| called even after a reload. (It does this so CircuitPython can use the display after your code
|
||||
//| is done.) So, the first time you initialize a display bus in code.py you should call
|
||||
//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run.
|
||||
//|
|
||||
//| :param busio.I2C i2c_bus: The I2C bus that make up the clock and data lines
|
||||
//| :param int device_address: The I2C address of the device
|
||||
//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used
|
||||
//| :param busio.I2C i2c_bus: The I2C bus that make up the clock and data lines
|
||||
//| :param int device_address: The I2C address of the device
|
||||
//| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_i2c_bus, ARG_device_address, ARG_reset };
|
||||
|
@ -80,10 +76,10 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t
|
|||
return self;
|
||||
}
|
||||
|
||||
//| .. method:: reset()
|
||||
//|
|
||||
//| Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
|
||||
//| is available.
|
||||
//| def reset(self, ) -> Any:
|
||||
//| """Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
|
||||
//| is available."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_i2cdisplay_obj_reset(mp_obj_t self_in) {
|
||||
displayio_i2cdisplay_obj_t *self = self_in;
|
||||
|
@ -95,10 +91,10 @@ STATIC mp_obj_t displayio_i2cdisplay_obj_reset(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_i2cdisplay_reset_obj, displayio_i2cdisplay_obj_reset);
|
||||
|
||||
//| .. method:: send(command, data)
|
||||
//|
|
||||
//| Sends the given command value followed by the full set of data. Display state, such as
|
||||
//| vertical scroll, set via ``send`` may or may not be reset once the code is done.
|
||||
//| def send(self, command: Any, data: Any) -> Any:
|
||||
//| """Sends the given command value followed by the full set of data. Display state, such as
|
||||
//| vertical scroll, set via ``send`` may or may not be reset once the code is done."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_i2cdisplay_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) {
|
||||
mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj);
|
||||
|
|
|
@ -33,51 +33,47 @@
|
|||
#include "supervisor/shared/translate.h"
|
||||
#include "shared-bindings/displayio/OnDiskBitmap.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class OnDiskBitmap:
|
||||
//| """Loads values straight from disk. This minimizes memory use but can lead to
|
||||
//| much slower pixel load times. These load times may result in frame tearing where only part of
|
||||
//| the image is visible.
|
||||
//|
|
||||
//| :class:`OnDiskBitmap` -- Loads pixels straight from disk
|
||||
//| ==========================================================================
|
||||
//| It's easiest to use on a board with a built in display such as the `Hallowing M0 Express
|
||||
//| <https://www.adafruit.com/product/3900>`_.
|
||||
//|
|
||||
//| Loads values straight from disk. This minimizes memory use but can lead to
|
||||
//| much slower pixel load times. These load times may result in frame tearing where only part of
|
||||
//| the image is visible.
|
||||
//| .. code-block:: Python
|
||||
//|
|
||||
//| It's easiest to use on a board with a built in display such as the `Hallowing M0 Express
|
||||
//| <https://www.adafruit.com/product/3900>`_.
|
||||
//| import board
|
||||
//| import displayio
|
||||
//| import time
|
||||
//| import pulseio
|
||||
//|
|
||||
//| .. code-block:: Python
|
||||
//| board.DISPLAY.auto_brightness = False
|
||||
//| board.DISPLAY.brightness = 0
|
||||
//| splash = displayio.Group()
|
||||
//| board.DISPLAY.show(splash)
|
||||
//|
|
||||
//| import board
|
||||
//| import displayio
|
||||
//| import time
|
||||
//| import pulseio
|
||||
//| with open("/sample.bmp", "rb") as f:
|
||||
//| odb = displayio.OnDiskBitmap(f)
|
||||
//| face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter())
|
||||
//| splash.append(face)
|
||||
//| # Wait for the image to load.
|
||||
//| board.DISPLAY.refresh(target_frames_per_second=60)
|
||||
//|
|
||||
//| board.DISPLAY.auto_brightness = False
|
||||
//| board.DISPLAY.brightness = 0
|
||||
//| splash = displayio.Group()
|
||||
//| board.DISPLAY.show(splash)
|
||||
//| # Fade up the backlight
|
||||
//| for i in range(100):
|
||||
//| board.DISPLAY.brightness = 0.01 * i
|
||||
//| time.sleep(0.05)
|
||||
//|
|
||||
//| with open("/sample.bmp", "rb") as f:
|
||||
//| odb = displayio.OnDiskBitmap(f)
|
||||
//| face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter())
|
||||
//| splash.append(face)
|
||||
//| # Wait for the image to load.
|
||||
//| board.DISPLAY.refresh(target_frames_per_second=60)
|
||||
//| # Wait forever
|
||||
//| while True:
|
||||
//| pass"""
|
||||
//|
|
||||
//| # Fade up the backlight
|
||||
//| for i in range(100):
|
||||
//| board.DISPLAY.brightness = 0.01 * i
|
||||
//| time.sleep(0.05)
|
||||
//| def __init__(self, file: file):
|
||||
//| """Create an OnDiskBitmap object with the given file.
|
||||
//|
|
||||
//| # Wait forever
|
||||
//| while True:
|
||||
//| pass
|
||||
//|
|
||||
//| .. class:: OnDiskBitmap(file)
|
||||
//|
|
||||
//| Create an OnDiskBitmap object with the given file.
|
||||
//|
|
||||
//| :param file file: The open bitmap file
|
||||
//| :param file file: The open bitmap file"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
||||
|
@ -93,9 +89,8 @@ STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. attribute:: width
|
||||
//|
|
||||
//| Width of the bitmap. (read only)
|
||||
//| width: Any = ...
|
||||
//| """Width of the bitmap. (read only)"""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_ondiskbitmap_obj_get_width(mp_obj_t self_in) {
|
||||
displayio_ondiskbitmap_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -113,9 +108,8 @@ const mp_obj_property_t displayio_ondiskbitmap_width_obj = {
|
|||
|
||||
};
|
||||
|
||||
//| .. attribute:: height
|
||||
//|
|
||||
//| Height of the bitmap. (read only)
|
||||
//| height: Any = ...
|
||||
//| """Height of the bitmap. (read only)"""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_ondiskbitmap_obj_get_height(mp_obj_t self_in) {
|
||||
displayio_ondiskbitmap_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -36,19 +36,22 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//| class Palette:
|
||||
//| """Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to
|
||||
//| save memory."""
|
||||
//|
|
||||
//| :class:`Palette` -- Stores a mapping from bitmap pixel palette_indexes to display colors
|
||||
//| =========================================================================================
|
||||
//| def __init__(self, color_count: int):
|
||||
//| """Create a Palette object to store a set number of colors.
|
||||
//|
|
||||
//| Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to
|
||||
//| save memory.
|
||||
//| :param int color_count: The number of colors in the Palette"""
|
||||
//| ...
|
||||
//|
|
||||
//| .. class:: Palette(color_count)
|
||||
//|
|
||||
//| Create a Palette object to store a set number of colors.
|
||||
//|
|
||||
//| :param int color_count: The number of colors in the Palette
|
||||
// TODO(tannewt): Add support for other color formats.
|
||||
// TODO(tannewt): Add support for 8-bit alpha blending.
|
||||
//|
|
||||
|
@ -67,9 +70,9 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: __len__()
|
||||
//|
|
||||
//| Returns the number of colors in a Palette
|
||||
//| def __len__(self, ) -> Any:
|
||||
//| """Returns the number of colors in a Palette"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -81,21 +84,21 @@ STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __setitem__(index, value)
|
||||
//| def __setitem__(self, index: Any, value: Any) -> Any:
|
||||
//| """Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1.
|
||||
//|
|
||||
//| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1.
|
||||
//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value).
|
||||
//| Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), bytearray,
|
||||
//| or a tuple or list of 3 integers.
|
||||
//|
|
||||
//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value).
|
||||
//| Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), bytearray,
|
||||
//| or a tuple or list of 3 integers.
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| palette[0] = 0xFFFFFF # set using an integer
|
||||
//| palette[1] = b'\xff\xff\x00' # set using 3 bytes
|
||||
//| palette[2] = b'\xff\xff\x00\x00' # set using 4 bytes
|
||||
//| palette[3] = bytearray(b'\x00\x00\xFF') # set using a bytearay of 3 or 4 bytes
|
||||
//| palette[4] = (10, 20, 30) # set using a tuple of 3 integers
|
||||
//| palette[0] = 0xFFFFFF # set using an integer
|
||||
//| palette[1] = b'\xff\xff\x00' # set using 3 bytes
|
||||
//| palette[2] = b'\xff\xff\x00\x00' # set using 4 bytes
|
||||
//| palette[3] = bytearray(b'\x00\x00\xFF') # set using a bytearay of 3 or 4 bytes
|
||||
//| palette[4] = (10, 20, 30) # set using a tuple of 3 integers"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
|
||||
if (value == MP_OBJ_NULL) {
|
||||
|
@ -144,7 +147,7 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
//| .. method:: make_transparent(palette_index)
|
||||
//| def make_transparent(self, palette_index: Any) -> Any: ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_t palette_index_obj) {
|
||||
displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -158,7 +161,7 @@ STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_transparent_obj, displayio_palette_obj_make_transparent);
|
||||
|
||||
//| .. method:: make_opaque(palette_index)
|
||||
//| def make_opaque(self, palette_index: Any) -> Any: ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t palette_index_obj) {
|
||||
displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -37,31 +37,27 @@
|
|||
#include "shared-module/displayio/__init__.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class ParallelBus:
|
||||
//| """Manage updating a display over 8-bit parallel bus in the background while Python code runs. This
|
||||
//| protocol may be refered to as 8080-I Series Parallel Interface in datasheets. It doesn't handle
|
||||
//| display initialization."""
|
||||
//|
|
||||
//| :class:`ParallelBus` -- Manage updating a display over 8-bit parallel bus
|
||||
//| ==============================================================================
|
||||
//| def __init__(self, *, data0: microcontroller.Pin, command: microcontroller.Pin, chip_select: microcontroller.Pin, write: microcontroller.Pin, read: microcontroller.Pin, reset: microcontroller.Pin):
|
||||
//| """Create a ParallelBus object associated with the given pins. The bus is inferred from data0
|
||||
//| by implying the next 7 additional pins on a given GPIO port.
|
||||
//|
|
||||
//| Manage updating a display over 8-bit parallel bus in the background while Python code runs. This
|
||||
//| protocol may be refered to as 8080-I Series Parallel Interface in datasheets. It doesn't handle
|
||||
//| display initialization.
|
||||
//| The parallel bus and pins are then in use by the display until `displayio.release_displays()`
|
||||
//| is called even after a reload. (It does this so CircuitPython can use the display after your
|
||||
//| code is done.) So, the first time you initialize a display bus in code.py you should call
|
||||
//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run.
|
||||
//|
|
||||
//| .. class:: ParallelBus(*, data0, command, chip_select, write, read, reset)
|
||||
//|
|
||||
//| Create a ParallelBus object associated with the given pins. The bus is inferred from data0
|
||||
//| by implying the next 7 additional pins on a given GPIO port.
|
||||
//|
|
||||
//| The parallel bus and pins are then in use by the display until `displayio.release_displays()`
|
||||
//| is called even after a reload. (It does this so CircuitPython can use the display after your
|
||||
//| code is done.) So, the first time you initialize a display bus in code.py you should call
|
||||
//| :py:func`displayio.release_displays` first, otherwise it will error after the first code.py run.
|
||||
//|
|
||||
//| :param microcontroller.Pin data0: The first data pin. The rest are implied
|
||||
//| :param microcontroller.Pin command: Data or command pin
|
||||
//| :param microcontroller.Pin chip_select: Chip select pin
|
||||
//| :param microcontroller.Pin write: Write pin
|
||||
//| :param microcontroller.Pin read: Read pin
|
||||
//| :param microcontroller.Pin reset: Reset pin
|
||||
//| :param microcontroller.Pin data0: The first data pin. The rest are implied
|
||||
//| :param microcontroller.Pin command: Data or command pin
|
||||
//| :param microcontroller.Pin chip_select: Chip select pin
|
||||
//| :param microcontroller.Pin write: Write pin
|
||||
//| :param microcontroller.Pin read: Read pin
|
||||
//| :param microcontroller.Pin reset: Reset pin"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_data0, ARG_command, ARG_chip_select, ARG_write, ARG_read, ARG_reset };
|
||||
|
@ -90,11 +86,12 @@ STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t
|
|||
return self;
|
||||
}
|
||||
|
||||
//| .. method:: reset()
|
||||
//|
|
||||
//| Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
|
||||
//| is available.
|
||||
//| def reset(self, ) -> Any:
|
||||
//| """Performs a hardware reset via the reset pin. Raises an exception if called when no reset pin
|
||||
//| is available."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t displayio_parallelbus_obj_reset(mp_obj_t self_in) {
|
||||
displayio_parallelbus_obj_t *self = self_in;
|
||||
|
||||
|
@ -105,10 +102,10 @@ STATIC mp_obj_t displayio_parallelbus_obj_reset(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(displayio_parallelbus_reset_obj, displayio_parallelbus_obj_reset);
|
||||
|
||||
//| .. method:: send(command, data)
|
||||
//|
|
||||
//| Sends the given command value followed by the full set of data. Display state, such as
|
||||
//| vertical scroll, set via ``send`` may or may not be reset once the code is done.
|
||||
//| def send(self, command: Any, data: Any) -> Any:
|
||||
//| """Sends the given command value followed by the full set of data. Display state, such as
|
||||
//| vertical scroll, set via ``send`` may or may not be reset once the code is done."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_parallelbus_obj_send(mp_obj_t self, mp_obj_t command_obj, mp_obj_t data_obj) {
|
||||
mp_int_t command_int = MP_OBJ_SMALL_INT_VALUE(command_obj);
|
||||
|
|
|
@ -34,22 +34,18 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class Shape:
|
||||
//| """Represents a shape made by defining boundaries that may be mirrored."""
|
||||
//|
|
||||
//| :class:`Shape` -- Represents a shape by defining its bounds on each row
|
||||
//| ==========================================================================
|
||||
//| def __init__(self, width: int, height: int, *, mirror_x: bool = False, mirror_y: bool = False):
|
||||
//| """Create a Shape object with the given fixed size. Each pixel is one bit and is stored by the
|
||||
//| column boundaries of the shape on each row. Each row's boundary defaults to the full row.
|
||||
//|
|
||||
//| Represents any shape made by defining boundaries that may be mirrored.
|
||||
//|
|
||||
//| .. class:: Shape(width, height, *, mirror_x=False, mirror_y=False)
|
||||
//|
|
||||
//| Create a Shape object with the given fixed size. Each pixel is one bit and is stored by the
|
||||
//| column boundaries of the shape on each row. Each row's boundary defaults to the full row.
|
||||
//|
|
||||
//| :param int width: The number of pixels wide
|
||||
//| :param int height: The number of pixels high
|
||||
//| :param bool mirror_x: When true the left boundary is mirrored to the right.
|
||||
//| :param bool mirror_y: When true the top boundary is mirrored to the bottom.
|
||||
//| :param int width: The number of pixels wide
|
||||
//| :param int height: The number of pixels high
|
||||
//| :param bool mirror_x: When true the left boundary is mirrored to the right.
|
||||
//| :param bool mirror_y: When true the top boundary is mirrored to the bottom."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_width, ARG_height, ARG_mirror_x, ARG_mirror_y };
|
||||
|
@ -83,9 +79,9 @@ STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_arg
|
|||
}
|
||||
|
||||
|
||||
//| .. method:: set_boundary(y, start_x, end_x)
|
||||
//|
|
||||
//| Loads pre-packed data into the given row.
|
||||
//| def set_boundary(self, y: Any, start_x: Any, end_x: Any) -> Any:
|
||||
//| """Loads pre-packed data into the given row."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_shape_obj_set_boundary(size_t n_args, const mp_obj_t *args) {
|
||||
(void) n_args;
|
||||
|
|
|
@ -40,33 +40,30 @@
|
|||
#include "shared-bindings/displayio/Shape.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: displayio
|
||||
//| class TileGrid:
|
||||
//| """A grid of tiles sourced out of one bitmap
|
||||
//|
|
||||
//| :class:`TileGrid` -- A grid of tiles sourced out of one bitmap
|
||||
//| ==========================================================================
|
||||
//| Position a grid of tiles sourced from a bitmap and pixel_shader combination. Multiple grids
|
||||
//| can share bitmaps and pixel shaders.
|
||||
//|
|
||||
//| Position a grid of tiles sourced from a bitmap and pixel_shader combination. Multiple grids
|
||||
//| can share bitmaps and pixel shaders.
|
||||
//| A single tile grid is also known as a Sprite."""
|
||||
//|
|
||||
//| A single tile grid is also known as a Sprite.
|
||||
//| def __init__(self, bitmap: displayio.Bitmap, *, pixel_shader: displayio.Palette, width: int = 1, height: int = 1, tile_width: int = None, tile_height: int = None, default_tile: int = 0, x: int = 0, y: int = 0):
|
||||
//| """Create a TileGrid object. The bitmap is source for 2d pixels. The pixel_shader is used to
|
||||
//| convert the value and its location to a display native pixel color. This may be a simple color
|
||||
//| palette lookup, a gradient, a pattern or a color transformer.
|
||||
//|
|
||||
//| .. class:: TileGrid(bitmap, *, pixel_shader, width=1, height=1, tile_width=None, tile_height=None, default_tile=0, x=0, y=0)
|
||||
//| tile_width and tile_height match the height of the bitmap by default.
|
||||
//|
|
||||
//| Create a TileGrid object. The bitmap is source for 2d pixels. The pixel_shader is used to
|
||||
//| convert the value and its location to a display native pixel color. This may be a simple color
|
||||
//| palette lookup, a gradient, a pattern or a color transformer.
|
||||
//|
|
||||
//| tile_width and tile_height match the height of the bitmap by default.
|
||||
//|
|
||||
//| :param displayio.Bitmap bitmap: The bitmap storing one or more tiles.
|
||||
//| :param displayio.Palette pixel_shader: The pixel shader that produces colors from values
|
||||
//| :param int width: Width of the grid in tiles.
|
||||
//| :param int height: Height of the grid in tiles.
|
||||
//| :param int tile_width: Width of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap's dimensions.
|
||||
//| :param int tile_height: Height of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap's dimensions.
|
||||
//| :param int default_tile: Default tile index to show.
|
||||
//| :param int x: Initial x position of the left edge within the parent.
|
||||
//| :param int y: Initial y position of the top edge within the parent.
|
||||
//| :param displayio.Bitmap bitmap: The bitmap storing one or more tiles.
|
||||
//| :param displayio.Palette pixel_shader: The pixel shader that produces colors from values
|
||||
//| :param int width: Width of the grid in tiles.
|
||||
//| :param int height: Height of the grid in tiles.
|
||||
//| :param int tile_width: Width of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap's dimensions.
|
||||
//| :param int tile_height: Height of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap's dimensions.
|
||||
//| :param int default_tile: Default tile index to show.
|
||||
//| :param int x: Initial x position of the left edge within the parent.
|
||||
//| :param int y: Initial y position of the top edge within the parent."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_bitmap, ARG_pixel_shader, ARG_width, ARG_height, ARG_tile_width, ARG_tile_height, ARG_default_tile, ARG_x, ARG_y };
|
||||
|
@ -144,9 +141,8 @@ static displayio_tilegrid_t* native_tilegrid(mp_obj_t tilegrid_obj) {
|
|||
mp_obj_assert_native_inited(native_tilegrid);
|
||||
return MP_OBJ_TO_PTR(native_tilegrid);
|
||||
}
|
||||
//| .. attribute:: hidden
|
||||
//|
|
||||
//| True when the TileGrid is hidden. This may be False even when a part of a hidden Group.
|
||||
//| hidden: Any = ...
|
||||
//| """True when the TileGrid is hidden. This may be False even when a part of a hidden Group."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_tilegrid_obj_get_hidden(mp_obj_t self_in) {
|
||||
displayio_tilegrid_t *self = native_tilegrid(self_in);
|
||||
|
@ -169,9 +165,8 @@ const mp_obj_property_t displayio_tilegrid_hidden_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: x
|
||||
//|
|
||||
//| X position of the left edge in the parent.
|
||||
//| x: Any = ...
|
||||
//| """X position of the left edge in the parent."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_tilegrid_obj_get_x(mp_obj_t self_in) {
|
||||
displayio_tilegrid_t *self = native_tilegrid(self_in);
|
||||
|
@ -195,9 +190,8 @@ const mp_obj_property_t displayio_tilegrid_x_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: y
|
||||
//|
|
||||
//| Y position of the top edge in the parent.
|
||||
//| y: Any = ...
|
||||
//| """Y position of the top edge in the parent."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_tilegrid_obj_get_y(mp_obj_t self_in) {
|
||||
displayio_tilegrid_t *self = native_tilegrid(self_in);
|
||||
|
@ -221,9 +215,8 @@ const mp_obj_property_t displayio_tilegrid_y_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: flip_x
|
||||
//|
|
||||
//| If true, the left edge rendered will be the right edge of the right-most tile.
|
||||
//| flip_x: Any = ...
|
||||
//| """If true, the left edge rendered will be the right edge of the right-most tile."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_tilegrid_obj_get_flip_x(mp_obj_t self_in) {
|
||||
displayio_tilegrid_t *self = native_tilegrid(self_in);
|
||||
|
@ -246,9 +239,8 @@ const mp_obj_property_t displayio_tilegrid_flip_x_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: flip_y
|
||||
//|
|
||||
//| If true, the top edge rendered will be the bottom edge of the bottom-most tile.
|
||||
//| flip_y: Any = ...
|
||||
//| """If true, the top edge rendered will be the bottom edge of the bottom-most tile."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_tilegrid_obj_get_flip_y(mp_obj_t self_in) {
|
||||
displayio_tilegrid_t *self = native_tilegrid(self_in);
|
||||
|
@ -272,10 +264,9 @@ const mp_obj_property_t displayio_tilegrid_flip_y_obj = {
|
|||
};
|
||||
|
||||
|
||||
//| .. attribute:: transpose_xy
|
||||
//|
|
||||
//| If true, the TileGrid's axis will be swapped. When combined with mirroring, any 90 degree
|
||||
//| rotation can be achieved along with the corresponding mirrored version.
|
||||
//| transpose_xy: Any = ...
|
||||
//| """If true, the TileGrid's axis will be swapped. When combined with mirroring, any 90 degree
|
||||
//| rotation can be achieved along with the corresponding mirrored version."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_tilegrid_obj_get_transpose_xy(mp_obj_t self_in) {
|
||||
displayio_tilegrid_t *self = native_tilegrid(self_in);
|
||||
|
@ -298,9 +289,8 @@ const mp_obj_property_t displayio_tilegrid_transpose_xy_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: pixel_shader
|
||||
//|
|
||||
//| The pixel shader of the tilegrid.
|
||||
//| pixel_shader: Any = ...
|
||||
//| """The pixel shader of the tilegrid."""
|
||||
//|
|
||||
STATIC mp_obj_t displayio_tilegrid_obj_get_pixel_shader(mp_obj_t self_in) {
|
||||
displayio_tilegrid_t *self = native_tilegrid(self_in);
|
||||
|
@ -327,27 +317,27 @@ const mp_obj_property_t displayio_tilegrid_pixel_shader_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: __getitem__(index)
|
||||
//| def __getitem__(self, index: Any) -> Any:
|
||||
//| """Returns the tile index at the given index. The index can either be an x,y tuple or an int equal
|
||||
//| to ``y * width + x``.
|
||||
//|
|
||||
//| Returns the tile index at the given index. The index can either be an x,y tuple or an int equal
|
||||
//| to ``y * width + x``.
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| This allows you to::
|
||||
//| print(grid[0])"""
|
||||
//| ...
|
||||
//|
|
||||
//| print(grid[0])
|
||||
//| def __setitem__(self, index: Any, tile_index: Any) -> Any:
|
||||
//| """Sets the tile index at the given index. The index can either be an x,y tuple or an int equal
|
||||
//| to ``y * width + x``.
|
||||
//|
|
||||
//| .. method:: __setitem__(index, tile_index)
|
||||
//| This allows you to::
|
||||
//|
|
||||
//| Sets the tile index at the given index. The index can either be an x,y tuple or an int equal
|
||||
//| to ``y * width + x``.
|
||||
//| grid[0] = 10
|
||||
//|
|
||||
//| This allows you to::
|
||||
//| or::
|
||||
//|
|
||||
//| grid[0] = 10
|
||||
//|
|
||||
//| or::
|
||||
//|
|
||||
//| grid[0,0] = 10
|
||||
//| grid[0,0] = 10"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t tilegrid_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value_obj) {
|
||||
displayio_tilegrid_t *self = native_tilegrid(self_in);
|
||||
|
|
|
@ -43,44 +43,21 @@
|
|||
#include "shared-bindings/displayio/Shape.h"
|
||||
#include "shared-bindings/displayio/TileGrid.h"
|
||||
|
||||
//| :mod:`displayio` --- Native display driving
|
||||
//| =========================================================================
|
||||
//|
|
||||
//| .. module:: displayio
|
||||
//| :synopsis: Native helpers for driving displays
|
||||
//| :platform: SAMD21, SAMD51, nRF52
|
||||
//| """Native helpers for driving displays
|
||||
//|
|
||||
//| The `displayio` module contains classes to manage display output
|
||||
//| including synchronizing with refresh rates and partial updating.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| Bitmap
|
||||
//| ColorConverter
|
||||
//| Display
|
||||
//| EPaperDisplay
|
||||
//| FourWire
|
||||
//| Group
|
||||
//| I2CDisplay
|
||||
//| OnDiskBitmap
|
||||
//| Palette
|
||||
//| ParallelBus
|
||||
//| Shape
|
||||
//| TileGrid
|
||||
//| including synchronizing with refresh rates and partial updating."""
|
||||
//|
|
||||
|
||||
|
||||
//| .. function:: release_displays()
|
||||
//| def release_displays() -> Any:
|
||||
//| """Releases any actively used displays so their busses and pins can be used again. This will also
|
||||
//| release the builtin display on boards that have one. You will need to reinitialize it yourself
|
||||
//| afterwards. This may take seconds to complete if an active EPaperDisplay is refreshing.
|
||||
//|
|
||||
//| Releases any actively used displays so their busses and pins can be used again. This will also
|
||||
//| release the builtin display on boards that have one. You will need to reinitialize it yourself
|
||||
//| afterwards. This may take seconds to complete if an active EPaperDisplay is refreshing.
|
||||
//|
|
||||
//| Use this once in your code.py if you initialize a display. Place it right before the
|
||||
//| initialization so the display is active as long as possible.
|
||||
//| Use this once in your code.py if you initialize a display. Place it right before the
|
||||
//| initialization so the display is active as long as possible."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t displayio_release_displays(void) {
|
||||
common_hal_displayio_release_displays();
|
||||
|
|
|
@ -36,25 +36,20 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: fontio
|
||||
//| class BuiltinFont:
|
||||
//| """A font built into CircuitPython"""
|
||||
//|
|
||||
//| :class:`BuiltinFont` -- A font built into CircuitPython
|
||||
//| =========================================================================================
|
||||
//|
|
||||
//| A font built into CircuitPython.
|
||||
//|
|
||||
//| .. class:: BuiltinFont()
|
||||
//|
|
||||
//| Creation not supported. Available fonts are defined when CircuitPython is built. See the
|
||||
//| `Adafruit_CircuitPython_Bitmap_Font <https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font>`_
|
||||
//| library for dynamically loaded fonts.
|
||||
//| def __init__(self, ):
|
||||
//| """Creation not supported. Available fonts are defined when CircuitPython is built. See the
|
||||
//| `Adafruit_CircuitPython_Bitmap_Font <https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font>`_
|
||||
//| library for dynamically loaded fonts."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
//| .. attribute:: bitmap
|
||||
//|
|
||||
//| Bitmap containing all font glyphs starting with ASCII and followed by unicode. Use
|
||||
//| bitmap: Any = ...
|
||||
//| """Bitmap containing all font glyphs starting with ASCII and followed by unicode. Use
|
||||
//| `get_glyph` in most cases. This is useful for use with `displayio.TileGrid` and
|
||||
//| `terminalio.Terminal`.
|
||||
//| `terminalio.Terminal`."""
|
||||
//|
|
||||
STATIC mp_obj_t fontio_builtinfont_obj_get_bitmap(mp_obj_t self_in) {
|
||||
fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -69,9 +64,9 @@ const mp_obj_property_t fontio_builtinfont_bitmap_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: get_bounding_box()
|
||||
//|
|
||||
//| Returns the maximum bounds of all glyphs in the font in a tuple of two values: width, height.
|
||||
//| def get_bounding_box(self, ) -> Any:
|
||||
//| """Returns the maximum bounds of all glyphs in the font in a tuple of two values: width, height."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t fontio_builtinfont_obj_get_bounding_box(mp_obj_t self_in) {
|
||||
fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -81,9 +76,9 @@ STATIC mp_obj_t fontio_builtinfont_obj_get_bounding_box(mp_obj_t self_in) {
|
|||
MP_DEFINE_CONST_FUN_OBJ_1(fontio_builtinfont_get_bounding_box_obj, fontio_builtinfont_obj_get_bounding_box);
|
||||
|
||||
|
||||
//| .. method:: get_glyph(codepoint)
|
||||
//|
|
||||
//| Returns a `fontio.Glyph` for the given codepoint or None if no glyph is available.
|
||||
//| def get_glyph(self, codepoint: Any) -> Any:
|
||||
//| """Returns a `fontio.Glyph` for the given codepoint or None if no glyph is available."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t fontio_builtinfont_obj_get_glyph(mp_obj_t self_in, mp_obj_t codepoint_obj) {
|
||||
fontio_builtinfont_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -28,23 +28,29 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
//| .. currentmodule:: fontio
|
||||
//| class Glyph:
|
||||
//| """Storage of glyph info"""
|
||||
//|
|
||||
//| :class:`Glyph` -- Storage of glyph info
|
||||
//| ==========================================================================
|
||||
//| def __init__(self,
|
||||
//| bitmap: displayio.Bitmap,
|
||||
//| tile_index: int,
|
||||
//| width: int,
|
||||
//| height: int,
|
||||
//| dx: int,
|
||||
//| dy: int,
|
||||
//| shift_x: int,
|
||||
//| shift_y: int):
|
||||
//| """Named tuple used to capture a single glyph and its attributes.
|
||||
//|
|
||||
//| .. class:: Glyph(bitmap, tile_index, width, height, dx, dy, shift_x, shift_y)
|
||||
//|
|
||||
//| Named tuple used to capture a single glyph and its attributes.
|
||||
//|
|
||||
//| :param displayio.Bitmap bitmap: the bitmap including the glyph
|
||||
//| :param int tile_index: the tile index within the bitmap
|
||||
//| :param int width: the width of the glyph's bitmap
|
||||
//| :param int height: the height of the glyph's bitmap
|
||||
//| :param int dx: x adjustment to the bitmap's position
|
||||
//| :param int dy: y adjustment to the bitmap's position
|
||||
//| :param int shift_x: the x difference to the next glyph
|
||||
//| :param int shift_y: the y difference to the next glyph
|
||||
//| :param bitmap: the bitmap including the glyph
|
||||
//| :param tile_index: the tile index within the bitmap
|
||||
//| :param width: the width of the glyph's bitmap
|
||||
//| :param height: the height of the glyph's bitmap
|
||||
//| :param dx: x adjustment to the bitmap's position
|
||||
//| :param dy: y adjustment to the bitmap's position
|
||||
//| :param shift_x: the x difference to the next glyph
|
||||
//| :param shift_y: the y difference to the next glyph"""
|
||||
//| ...
|
||||
//|
|
||||
const mp_obj_namedtuple_type_t fontio_glyph_type = {
|
||||
.base = {
|
||||
|
|
|
@ -33,22 +33,7 @@
|
|||
#include "shared-bindings/fontio/BuiltinFont.h"
|
||||
#include "shared-bindings/fontio/Glyph.h"
|
||||
|
||||
//| :mod:`fontio` --- Core font related data structures
|
||||
//| =========================================================================
|
||||
//|
|
||||
//| .. module:: fontio
|
||||
//| :synopsis: Core font related data structures
|
||||
//| :platform: SAMD21, SAMD51, nRF52
|
||||
//|
|
||||
//| The `fontio` module contains classes to store font related information.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| BuiltinFont
|
||||
//| Glyph
|
||||
//| """Core font related data structures"""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t fontio_module_globals_table[] = {
|
||||
|
|
|
@ -40,23 +40,21 @@
|
|||
#include "shared-module/displayio/__init__.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: framebufferio
|
||||
//| class FramebufferDisplay:
|
||||
//| """Manage updating a display with framebuffer in RAM
|
||||
//|
|
||||
//| :class:`FramebufferDisplay` -- Manage updating a display with framebuffer in RAM
|
||||
//| ================================================================================
|
||||
//| This initializes a display and connects it into CircuitPython. Unlike other
|
||||
//| objects in CircuitPython, Display objects live until `displayio.release_displays()`
|
||||
//| is called. This is done so that CircuitPython can use the display itself."""
|
||||
//|
|
||||
//| This initializes a display and connects it into CircuitPython. Unlike other
|
||||
//| objects in CircuitPython, Display objects live until `displayio.release_displays()`
|
||||
//| is called. This is done so that CircuitPython can use the display itself.
|
||||
//| def __init__(self, framebuffer: Any, *, rotation: int = 0, auto_refresh: bool = True):
|
||||
//| """Create a Display object with the given framebuffer (a buffer, array, ulab.array, etc)
|
||||
//|
|
||||
//| .. class:: FramebufferDisplay(framebuffer, *, rotation=0, auto_refresh=True)
|
||||
//|
|
||||
//| Create a Display object with the given framebuffer (a buffer, array, ulab.array, etc)
|
||||
//|
|
||||
//| :param framebuffer: The framebuffer that the display is connected to
|
||||
//| :type framebuffer: any core object implementing the framebuffer protocol
|
||||
//| :param bool auto_refresh: Automatically refresh the screen
|
||||
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
|
||||
//| :param framebuffer: The framebuffer that the display is connected to
|
||||
//| :type framebuffer: any core object implementing the framebuffer protocol
|
||||
//| :param bool auto_refresh: Automatically refresh the screen
|
||||
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_framebuffer, ARG_rotation, ARG_auto_refresh, NUM_ARGS };
|
||||
|
@ -96,12 +94,12 @@ static framebufferio_framebufferdisplay_obj_t* native_display(mp_obj_t display_o
|
|||
return MP_OBJ_TO_PTR(native_display);
|
||||
}
|
||||
|
||||
//| .. method:: show(group)
|
||||
//| def show(self, group: Group) -> Any:
|
||||
//| """Switches to displaying the given group of layers. When group is None, the default
|
||||
//| CircuitPython terminal will be shown.
|
||||
//|
|
||||
//| Switches to displaying the given group of layers. When group is None, the default
|
||||
//| CircuitPython terminal will be shown.
|
||||
//|
|
||||
//| :param Group group: The group to show.
|
||||
//| :param Group group: The group to show."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
|
||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -118,21 +116,21 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_obj_show(mp_obj_t self_in, mp_o
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(framebufferio_framebufferdisplay_show_obj, framebufferio_framebufferdisplay_obj_show);
|
||||
|
||||
//| .. method:: refresh(*, target_frames_per_second=60, minimum_frames_per_second=1)
|
||||
//| def refresh(self, *, target_frames_per_second: int = 60, minimum_frames_per_second: int = 1) -> Any:
|
||||
//| """When auto refresh is off, waits for the target frame rate and then refreshes the display,
|
||||
//| returning True. If the call has taken too long since the last refresh call for the given
|
||||
//| target frame rate, then the refresh returns False immediately without updating the screen to
|
||||
//| hopefully help getting caught up.
|
||||
//|
|
||||
//| When auto refresh is off, waits for the target frame rate and then refreshes the display,
|
||||
//| returning True. If the call has taken too long since the last refresh call for the given
|
||||
//| target frame rate, then the refresh returns False immediately without updating the screen to
|
||||
//| hopefully help getting caught up.
|
||||
//| If the time since the last successful refresh is below the minimum frame rate, then an
|
||||
//| exception will be raised. Set minimum_frames_per_second to 0 to disable.
|
||||
//|
|
||||
//| If the time since the last successful refresh is below the minimum frame rate, then an
|
||||
//| exception will be raised. Set minimum_frames_per_second to 0 to disable.
|
||||
//| When auto refresh is on, updates the display immediately. (The display will also update
|
||||
//| without calls to this.)
|
||||
//|
|
||||
//| When auto refresh is on, updates the display immediately. (The display will also update
|
||||
//| without calls to this.)
|
||||
//|
|
||||
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
|
||||
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second.
|
||||
//| :param int target_frames_per_second: How many times a second `refresh` should be called and the screen updated.
|
||||
//| :param int minimum_frames_per_second: The minimum number of times the screen should be updated per second."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_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 };
|
||||
|
@ -153,9 +151,8 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_obj_refresh(size_t n_args, cons
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(framebufferio_framebufferdisplay_refresh_obj, 1, framebufferio_framebufferdisplay_obj_refresh);
|
||||
|
||||
//| .. attribute:: auto_refresh
|
||||
//|
|
||||
//| True when the display is refreshed automatically.
|
||||
//| auto_refresh: Any = ...
|
||||
//| """True when the display is refreshed automatically."""
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_auto_refresh(mp_obj_t self_in) {
|
||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -179,11 +176,10 @@ const mp_obj_property_t framebufferio_framebufferdisplay_auto_refresh_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: brightness
|
||||
//|
|
||||
//| The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
|
||||
//| brightness: Any = ...
|
||||
//| """The brightness of the display as a float. 0.0 is off and 1.0 is full brightness. When
|
||||
//| `auto_brightness` is True, the value of `brightness` will change automatically.
|
||||
//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False.
|
||||
//| If `brightness` is set, `auto_brightness` will be disabled and will be set to False."""
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_brightness(mp_obj_t self_in) {
|
||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -217,12 +213,11 @@ const mp_obj_property_t framebufferio_framebufferdisplay_brightness_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: auto_brightness
|
||||
//|
|
||||
//| True when the display brightness is adjusted automatically, based on an ambient
|
||||
//| auto_brightness: Any = ...
|
||||
//| """True when the display brightness is adjusted automatically, based on an ambient
|
||||
//| light sensor or other method. Note that some displays may have this set to True by default,
|
||||
//| but not actually implement automatic brightness adjustment. `auto_brightness` is set to False
|
||||
//| if `brightness` is set manually.
|
||||
//| if `brightness` is set manually."""
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_auto_brightness(mp_obj_t self_in) {
|
||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -249,9 +244,8 @@ const mp_obj_property_t framebufferio_framebufferdisplay_auto_brightness_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: width
|
||||
//|
|
||||
//| Gets the width of the framebuffer
|
||||
//| width: Any = ...
|
||||
//| """Gets the width of the framebuffer"""
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_width(mp_obj_t self_in) {
|
||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -266,9 +260,8 @@ const mp_obj_property_t framebufferio_framebufferdisplay_width_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: height
|
||||
//|
|
||||
//| Gets the height of the framebuffer
|
||||
//| height: Any = ...
|
||||
//| """Gets the height of the framebuffer"""
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_height(mp_obj_t self_in) {
|
||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -283,9 +276,8 @@ const mp_obj_property_t framebufferio_framebufferdisplay_height_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: rotation
|
||||
//|
|
||||
//| The rotation of the display as an int in degrees.
|
||||
//| rotation: Any = ...
|
||||
//| """The rotation of the display as an int in degrees."""
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_rotation(mp_obj_t self_in) {
|
||||
framebufferio_framebufferdisplay_obj_t *self = native_display(self_in);
|
||||
|
@ -307,9 +299,8 @@ const mp_obj_property_t framebufferio_framebufferdisplay_rotation_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. attribute:: framebuffer
|
||||
//|
|
||||
//| The framebuffer being used by the display
|
||||
//| framebuffer: Any = ...
|
||||
//| """The framebuffer being used by the display"""
|
||||
//|
|
||||
//|
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_framebuffer(mp_obj_t self_in) {
|
||||
|
@ -326,12 +317,13 @@ const mp_obj_property_t framebufferio_framebufferframebuffer_obj = {
|
|||
};
|
||||
|
||||
|
||||
//| .. method:: fill_row(y, buffer)
|
||||
//| def fill_row(self, y: int, buffer: bytearray) -> Any:
|
||||
//| """Extract the pixels from a single row
|
||||
//|
|
||||
//| Extract the pixels from a single row
|
||||
//| :param int y: The top edge of the area
|
||||
//| :param bytearray buffer: The buffer in which to place the pixel data"""
|
||||
//| ...
|
||||
//|
|
||||
//| :param int y: The top edge of the area
|
||||
//| :param bytearray buffer: The buffer in which to place the pixel data
|
||||
STATIC mp_obj_t framebufferio_framebufferdisplay_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[] = {
|
||||
|
|
|
@ -28,25 +28,13 @@
|
|||
#include "shared-bindings/framebufferio/__init__.h"
|
||||
#include "shared-bindings/framebufferio/FramebufferDisplay.h"
|
||||
|
||||
//| :mod:`framebufferio` --- Native framebuffer display driving
|
||||
//| =========================================================================
|
||||
//|
|
||||
//| .. module:: framebufferio
|
||||
//| :synopsis: Native helpers for driving displays
|
||||
//| :platform: SAMD51, nRF52
|
||||
//| """Native framebuffer display driving
|
||||
//|
|
||||
//| The `framebufferio` module contains classes to manage display output
|
||||
//| including synchronizing with refresh rates and partial updating.
|
||||
//| It is used in conjunction with classes from `displayio` to actually
|
||||
//| place items on the display; and classes like `RGBMatrix` to actually
|
||||
//| drive the display.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| FramebufferDisplay
|
||||
//| drive the display."""
|
||||
//|
|
||||
|
||||
#if CIRCUITPY_FRAMEBUFFERIO
|
||||
|
|
|
@ -35,43 +35,41 @@
|
|||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: frequencyio
|
||||
//| class FrequencyIn:
|
||||
//| """Read a frequency signal
|
||||
//|
|
||||
//| :class:`FrequencyIn` -- Read a frequency signal
|
||||
//| ========================================================
|
||||
//| FrequencyIn is used to measure the frequency, in hertz, of a digital signal
|
||||
//| on an incoming pin. Accuracy has shown to be within 10%, if not better. It
|
||||
//| is recommended to utilize an average of multiple samples to smooth out readings.
|
||||
//|
|
||||
//| FrequencyIn is used to measure the frequency, in hertz, of a digital signal
|
||||
//| on an incoming pin. Accuracy has shown to be within 10%, if not better. It
|
||||
//| is recommended to utilize an average of multiple samples to smooth out readings.
|
||||
//| Frequencies below 1KHz are not currently detectable.
|
||||
//|
|
||||
//| Frequencies below 1KHz are not currently detectable.
|
||||
//| FrequencyIn will not determine pulse width (use ``PulseIn``)."""
|
||||
//|
|
||||
//| FrequencyIn will not determine pulse width (use ``PulseIn``).
|
||||
//| def __init__(self, pin: microcontroller.Pin, capture_period: int = 10):
|
||||
//| """Create a FrequencyIn object associated with the given pin.
|
||||
//|
|
||||
//| .. class:: FrequencyIn(pin, capture_period=10)
|
||||
//| :param ~microcontroller.Pin pin: Pin to read frequency from.
|
||||
//| :param int capture_period: Keyword argument to set the measurement period, in
|
||||
//| milliseconds. Default is 10ms; range is 1ms - 500ms.
|
||||
//|
|
||||
//| Create a FrequencyIn object associated with the given pin.
|
||||
//| Read the incoming frequency from a pin::
|
||||
//|
|
||||
//| :param ~microcontroller.Pin pin: Pin to read frequency from.
|
||||
//| :param int capture_period: Keyword argument to set the measurement period, in
|
||||
//| milliseconds. Default is 10ms; range is 1ms - 500ms.
|
||||
//| import frequencyio
|
||||
//| import board
|
||||
//|
|
||||
//| Read the incoming frequency from a pin::
|
||||
//| frequency = frequencyio.FrequencyIn(board.D11)
|
||||
//|
|
||||
//| import frequencyio
|
||||
//| import board
|
||||
//| # Loop while printing the detected frequency
|
||||
//| while True:
|
||||
//| print(frequency.value)
|
||||
//|
|
||||
//| frequency = frequencyio.FrequencyIn(board.D11)
|
||||
//|
|
||||
//| # Loop while printing the detected frequency
|
||||
//| while True:
|
||||
//| print(frequency.value)
|
||||
//|
|
||||
//| # Optional clear() will reset the value
|
||||
//| # to zero. Without this, if the incoming
|
||||
//| # signal stops, the last reading will remain
|
||||
//| # as the value.
|
||||
//| frequency.clear()
|
||||
//| # Optional clear() will reset the value
|
||||
//| # to zero. Without this, if the incoming
|
||||
//| # signal stops, the last reading will remain
|
||||
//| # as the value.
|
||||
//| frequency.clear()"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
@ -96,9 +94,9 @@ STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size
|
|||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the FrequencyIn and releases any hardware resources for reuse.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialises the FrequencyIn and releases any hardware resources for reuse."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t frequencyio_frequencyin_deinit(mp_obj_t self_in) {
|
||||
frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -113,16 +111,16 @@ STATIC void check_for_deinit(frequencyio_frequencyin_obj_t *self) {
|
|||
}
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t frequencyio_frequencyin_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
|
@ -131,9 +129,9 @@ STATIC mp_obj_t frequencyio_frequencyin_obj___exit__(size_t n_args, const mp_obj
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(frequencyio_frequencyin___exit___obj, 4, 4, frequencyio_frequencyin_obj___exit__);
|
||||
|
||||
//| .. method:: pause()
|
||||
//|
|
||||
//| Pause frequency capture.
|
||||
//| def pause(self, ) -> Any:
|
||||
//| """Pause frequency capture."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t frequencyio_frequencyin_obj_pause(mp_obj_t self_in) {
|
||||
frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -144,9 +142,9 @@ STATIC mp_obj_t frequencyio_frequencyin_obj_pause(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_pause_obj, frequencyio_frequencyin_obj_pause);
|
||||
|
||||
//| .. method:: resume()
|
||||
//|
|
||||
//| Resumes frequency capture.
|
||||
//| def resume(self, ) -> Any:
|
||||
//| """Resumes frequency capture."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t frequencyio_frequencyin_obj_resume(mp_obj_t self_in) {
|
||||
frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -157,9 +155,9 @@ STATIC mp_obj_t frequencyio_frequencyin_obj_resume(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_resume_obj, frequencyio_frequencyin_obj_resume);
|
||||
|
||||
//| .. method:: clear()
|
||||
//|
|
||||
//| Clears the last detected frequency capture value.
|
||||
//| def clear(self, ) -> Any:
|
||||
//| """Clears the last detected frequency capture value."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
STATIC mp_obj_t frequencyio_frequencyin_obj_clear(mp_obj_t self_in) {
|
||||
|
@ -171,14 +169,13 @@ STATIC mp_obj_t frequencyio_frequencyin_obj_clear(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(frequencyio_frequencyin_clear_obj, frequencyio_frequencyin_obj_clear);
|
||||
|
||||
//| .. attribute:: capture_period
|
||||
//|
|
||||
//| The capture measurement period. Lower incoming frequencies will be measured
|
||||
//| capture_period: Any = ...
|
||||
//| """The capture measurement period. Lower incoming frequencies will be measured
|
||||
//| more accurately with longer capture periods. Higher frequencies are more
|
||||
//| accurate with shorter capture periods.
|
||||
//|
|
||||
//| .. note:: When setting a new ``capture_period``, all previous capture information is
|
||||
//| cleared with a call to ``clear()``.
|
||||
//| .. note:: When setting a new ``capture_period``, all previous capture information is
|
||||
//| cleared with a call to ``clear()``."""
|
||||
//|
|
||||
STATIC mp_obj_t frequencyio_frequencyin_obj_get_capture_period(mp_obj_t self_in) {
|
||||
frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
@ -204,9 +201,9 @@ const mp_obj_property_t frequencyio_frequencyin_capture_period_obj = {
|
|||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: __get__(index)
|
||||
//|
|
||||
//| Returns the value of the last frequency captured.
|
||||
//| def __get__(self, index: Any) -> Any:
|
||||
//| """Returns the value of the last frequency captured."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t frequencyio_frequencyin_obj_get_value(mp_obj_t self_in) {
|
||||
frequencyio_frequencyin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
|
|
|
@ -33,23 +33,8 @@
|
|||
#include "shared-bindings/frequencyio/__init__.h"
|
||||
#include "shared-bindings/frequencyio/FrequencyIn.h"
|
||||
|
||||
//| :mod:`frequencyio` --- Support for frequency based protocols
|
||||
//| =============================================================
|
||||
//| """Support for frequency based protocols
|
||||
//|
|
||||
//| .. module:: frequencyio
|
||||
//| :synopsis: Support for frequency based protocols
|
||||
//| :platform: SAMD51
|
||||
//|
|
||||
//| The `frequencyio` module contains classes to provide access to basic frequency IO.
|
||||
//|
|
||||
//| Libraries
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| FrequencyIn
|
||||
//|
|
||||
|
||||
//| .. warning:: This module is not available in SAMD21 builds. See the
|
||||
//| :ref:`module-support-matrix` for more info.
|
||||
//|
|
||||
|
@ -73,7 +58,7 @@
|
|||
//| :py:data:`~frequencyio.FrequencyIn.capture_period`, and then sleep 0.1 seconds.
|
||||
//| CircuitPython will automatically turn off FrequencyIn capture when it resets all
|
||||
//| hardware after program completion. Use ``deinit()`` or a ``with`` statement
|
||||
//| to do it yourself.
|
||||
//| to do it yourself."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t frequencyio_module_globals_table[] = {
|
||||
|
|
|
@ -35,65 +35,62 @@
|
|||
#include "supervisor/shared/translate.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
|
||||
//| .. currentmodule:: gamepad
|
||||
//| class GamePad:
|
||||
//| """Scan buttons for presses
|
||||
//|
|
||||
//| :class:`GamePad` -- Scan buttons for presses
|
||||
//| ============================================
|
||||
//| Usage::
|
||||
//|
|
||||
//| Usage::
|
||||
//| import board
|
||||
//| import digitalio
|
||||
//| import gamepad
|
||||
//| import time
|
||||
//|
|
||||
//| import board
|
||||
//| import digitalio
|
||||
//| import gamepad
|
||||
//| import time
|
||||
//|
|
||||
//| B_UP = 1 << 0
|
||||
//| B_DOWN = 1 << 1
|
||||
//| B_UP = 1 << 0
|
||||
//| B_DOWN = 1 << 1
|
||||
//|
|
||||
//|
|
||||
//| pad = gamepad.GamePad(
|
||||
//| digitalio.DigitalInOut(board.D10),
|
||||
//| digitalio.DigitalInOut(board.D11),
|
||||
//| )
|
||||
//| pad = gamepad.GamePad(
|
||||
//| digitalio.DigitalInOut(board.D10),
|
||||
//| digitalio.DigitalInOut(board.D11),
|
||||
//| )
|
||||
//|
|
||||
//| y = 0
|
||||
//| while True:
|
||||
//| buttons = pad.get_pressed()
|
||||
//| if buttons & B_UP:
|
||||
//| y -= 1
|
||||
//| print(y)
|
||||
//| elif buttons & B_DOWN:
|
||||
//| y += 1
|
||||
//| print(y)
|
||||
//| time.sleep(0.1)
|
||||
//| while buttons:
|
||||
//| # Wait for all buttons to be released.
|
||||
//| y = 0
|
||||
//| while True:
|
||||
//| buttons = pad.get_pressed()
|
||||
//| if buttons & B_UP:
|
||||
//| y -= 1
|
||||
//| print(y)
|
||||
//| elif buttons & B_DOWN:
|
||||
//| y += 1
|
||||
//| print(y)
|
||||
//| time.sleep(0.1)
|
||||
//| while buttons:
|
||||
//| # Wait for all buttons to be released.
|
||||
//| buttons = pad.get_pressed()
|
||||
//| time.sleep(0.1)"""
|
||||
//|
|
||||
|
||||
//| .. class:: GamePad([b1[, b2[, b3[, b4[, b5[, b6[, b7[, b8]]]]]]]])
|
||||
//| def __init__(self, b1: Any, b2: Any, b3: Any, b4: Any, b5: Any, b6: Any, b7: Any, b8: Any):
|
||||
//| """Initializes button scanning routines.
|
||||
//|
|
||||
//| Initializes button scanning routines.
|
||||
//| The ``b1``-``b8`` parameters are ``DigitalInOut`` objects, which
|
||||
//| immediately get switched to input with a pull-up, (unless they already
|
||||
//| were set to pull-down, in which case they remain so), and then scanned
|
||||
//| regularly for button presses. The order is the same as the order of
|
||||
//| bits returned by the ``get_pressed`` function. You can re-initialize
|
||||
//| it with different keys, then the new object will replace the previous
|
||||
//| one.
|
||||
//|
|
||||
//| The ``b1``-``b8`` parameters are ``DigitalInOut`` objects, which
|
||||
//| immediately get switched to input with a pull-up, (unless they already
|
||||
//| were set to pull-down, in which case they remain so), and then scanned
|
||||
//| regularly for button presses. The order is the same as the order of
|
||||
//| bits returned by the ``get_pressed`` function. You can re-initialize
|
||||
//| it with different keys, then the new object will replace the previous
|
||||
//| one.
|
||||
//| The basic feature required here is the ability to poll the keys at
|
||||
//| regular intervals (so that de-bouncing is consistent) and fast enough
|
||||
//| (so that we don't miss short button presses) while at the same time
|
||||
//| letting the user code run normally, call blocking functions and wait
|
||||
//| on delays.
|
||||
//|
|
||||
//| The basic feature required here is the ability to poll the keys at
|
||||
//| regular intervals (so that de-bouncing is consistent) and fast enough
|
||||
//| (so that we don't miss short button presses) while at the same time
|
||||
//| letting the user code run normally, call blocking functions and wait
|
||||
//| on delays.
|
||||
//|
|
||||
//| They button presses are accumulated, until the ``get_pressed`` method
|
||||
//| is called, at which point the button state is cleared, and the new
|
||||
//| button presses start to be recorded.
|
||||
//| They button presses are accumulated, until the ``get_pressed`` method
|
||||
//| is called, at which point the button state is cleared, and the new
|
||||
//| button presses start to be recorded."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
|
@ -117,15 +114,15 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return MP_OBJ_FROM_PTR(gamepad_singleton);
|
||||
}
|
||||
|
||||
//| .. method:: get_pressed()
|
||||
//|
|
||||
//| Get the status of buttons pressed since the last call and clear it.
|
||||
//| def get_pressed(self, ) -> Any:
|
||||
//| """Get the status of buttons pressed since the last call and clear it.
|
||||
//|
|
||||
//| Returns an 8-bit number, with bits that correspond to buttons,
|
||||
//| which have been pressed (or held down) since the last call to this
|
||||
//| function set to 1, and the remaining bits set to 0. Then it clears
|
||||
//| the button state, so that new button presses (or buttons that are
|
||||
//| held down) can be recorded for the next call.
|
||||
//| held down) can be recorded for the next call."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepad_get_pressed(mp_obj_t self_in) {
|
||||
gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
|
||||
|
@ -136,9 +133,9 @@ STATIC mp_obj_t gamepad_get_pressed(mp_obj_t self_in) {
|
|||
MP_DEFINE_CONST_FUN_OBJ_1(gamepad_get_pressed_obj, gamepad_get_pressed);
|
||||
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Disable button scanning.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Disable button scanning."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepad_deinit(mp_obj_t self_in) {
|
||||
common_hal_gamepad_gamepad_deinit(self_in);
|
||||
|
|
|
@ -29,17 +29,7 @@
|
|||
#include "shared-bindings/gamepad/GamePad.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| :mod:`gamepad` --- Button handling
|
||||
//| ==================================
|
||||
//|
|
||||
//| .. module:: gamepad
|
||||
//| :synopsis: Button handling
|
||||
//| :platform: SAMD21
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| GamePad
|
||||
//| """Button handling in the background"""
|
||||
//|
|
||||
STATIC const mp_rom_map_elem_t gamepad_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepad) },
|
||||
|
|
|
@ -33,24 +33,22 @@
|
|||
#include "supervisor/shared/translate.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
//| .. currentmodule:: gamepadshift
|
||||
//| class GamePadShift:
|
||||
//| """Scan buttons for presses through a shift register"""
|
||||
//|
|
||||
//| :class:`GamePadShift` -- Scan buttons for presses through a shift register
|
||||
//| ===========================================================================
|
||||
//| def __init__(self, clock: Any, data: Any, latch: Any):
|
||||
//| """Initializes button scanning routines.
|
||||
//|
|
||||
//| .. class:: GamePadShift(clock, data, latch)
|
||||
//| The ``clock``, ``data`` and ``latch`` parameters are ``DigitalInOut``
|
||||
//| objects connected to the shift register controlling the buttons.
|
||||
//|
|
||||
//| Initializes button scanning routines.
|
||||
//| They button presses are accumulated, until the ``get_pressed`` method
|
||||
//| is called, at which point the button state is cleared, and the new
|
||||
//| button presses start to be recorded.
|
||||
//|
|
||||
//| The ``clock``, ``data`` and ``latch`` parameters are ``DigitalInOut``
|
||||
//| objects connected to the shift register controlling the buttons.
|
||||
//|
|
||||
//| They button presses are accumulated, until the ``get_pressed`` method
|
||||
//| is called, at which point the button state is cleared, and the new
|
||||
//| button presses start to be recorded.
|
||||
//|
|
||||
//| Only one gamepad (`gamepad.GamePad` or `gamepadshift.GamePadShift`)
|
||||
//| may be used at a time.
|
||||
//| Only one gamepad (`gamepad.GamePad` or `gamepadshift.GamePadShift`)
|
||||
//| may be used at a time."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
|
@ -84,15 +82,15 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
return MP_OBJ_FROM_PTR(gamepad_singleton);
|
||||
}
|
||||
|
||||
//| .. method:: get_pressed()
|
||||
//|
|
||||
//| Get the status of buttons pressed since the last call and clear it.
|
||||
//| def get_pressed(self, ) -> Any:
|
||||
//| """Get the status of buttons pressed since the last call and clear it.
|
||||
//|
|
||||
//| Returns an 8-bit number, with bits that correspond to buttons,
|
||||
//| which have been pressed (or held down) since the last call to this
|
||||
//| function set to 1, and the remaining bits set to 0. Then it clears
|
||||
//| the button state, so that new button presses (or buttons that are
|
||||
//| held down) can be recorded for the next call.
|
||||
//| held down) can be recorded for the next call."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepadshift_get_pressed(mp_obj_t self_in) {
|
||||
gamepadshift_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
|
||||
|
@ -102,9 +100,9 @@ STATIC mp_obj_t gamepadshift_get_pressed(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gamepadshift_get_pressed_obj, gamepadshift_get_pressed);
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Disable button scanning.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Disable button scanning."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepadshift_deinit(mp_obj_t self_in) {
|
||||
common_hal_gamepadshift_gamepadshift_deinit(self_in);
|
||||
|
|
|
@ -30,17 +30,7 @@
|
|||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| :mod:`gamepadshift` --- Tracks button presses read through a shift register
|
||||
//| ===========================================================================
|
||||
//|
|
||||
//| .. module:: gamepadshift
|
||||
//| :synopsis: Tracks button presses read through a shift register
|
||||
//| :platform: SAMD21, SAMD51
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| GamePadShift
|
||||
//| """Tracks button presses read through a shift register"""
|
||||
//|
|
||||
STATIC const mp_rom_map_elem_t gamepadshift_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepadshift) },
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
//| :func:`help` - Built-in method to provide helpful information
|
||||
//| ==============================================================
|
||||
//|
|
||||
//| .. function:: help(object=None)
|
||||
//|
|
||||
//| Prints a help method about the given object. When ``object`` is none,
|
||||
//| prints general port information.
|
||||
//|
|
|
@ -0,0 +1,31 @@
|
|||
.. This file is part of the MicroPython project, http://micropython.org/
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
:func:`help` - Built-in method to provide helpful information
|
||||
==============================================================
|
||||
|
||||
.. function:: help(object=None)
|
||||
|
||||
Prints a help method about the given object. When ``object`` is none,
|
||||
prints general port information.
|
|
@ -49,20 +49,18 @@ STATIC mp_obj_t mp_obj_new_i2cslave_i2c_slave_request(i2cslave_i2c_slave_obj_t *
|
|||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
//| .. currentmodule:: i2cslave
|
||||
//| class I2CSlave:
|
||||
//| """Two wire serial protocol slave"""
|
||||
//|
|
||||
//| :class:`I2CSlave` --- Two wire serial protocol slave
|
||||
//| ----------------------------------------------------
|
||||
//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: tuple, smbus: bool = False):
|
||||
//| """I2C is a two-wire protocol for communicating between devices.
|
||||
//| This implements the slave side.
|
||||
//|
|
||||
//| .. class:: I2CSlave(scl, sda, addresses, smbus=False)
|
||||
//|
|
||||
//| I2C is a two-wire protocol for communicating between devices.
|
||||
//| This implements the slave side.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin scl: The clock pin
|
||||
//| :param ~microcontroller.Pin sda: The data pin
|
||||
//| :param tuple addresses: The I2C addresses to respond to (how many is hw dependent).
|
||||
//| :param bool smbus: Use SMBUS timings if the hardware supports it
|
||||
//| :param ~microcontroller.Pin scl: The clock pin
|
||||
//| :param ~microcontroller.Pin sda: The data pin
|
||||
//| :param tuple addresses: The I2C addresses to respond to (how many is hw dependent).
|
||||
//| :param bool smbus: Use SMBUS timings if the hardware supports it"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
i2cslave_i2c_slave_obj_t *self = m_new_obj(i2cslave_i2c_slave_obj_t);
|
||||
|
@ -104,9 +102,9 @@ STATIC mp_obj_t i2cslave_i2c_slave_make_new(const mp_obj_type_t *type, size_t n_
|
|||
return (mp_obj_t)self;
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Releases control of the underlying hardware so other classes can use it.
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Releases control of the underlying hardware so other classes can use it."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_obj_deinit(mp_obj_t self_in) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_type));
|
||||
|
@ -116,16 +114,16 @@ STATIC mp_obj_t i2cslave_i2c_slave_obj_deinit(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(i2cslave_i2c_slave_deinit_obj, i2cslave_i2c_slave_obj_deinit);
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used in Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used in Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware on context exit. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware on context exit. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cslave_i2c_slave_type));
|
||||
|
@ -135,13 +133,12 @@ STATIC mp_obj_t i2cslave_i2c_slave_obj___exit__(size_t n_args, const mp_obj_t *a
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cslave_i2c_slave___exit___obj, 4, 4, i2cslave_i2c_slave_obj___exit__);
|
||||
|
||||
//| .. method:: request(timeout=-1)
|
||||
//| def request(self, timeout: float = -1) -> Any:
|
||||
//| """Wait for an I2C request from a master.
|
||||
//|
|
||||
//| Wait for an I2C request from a master.
|
||||
//|
|
||||
//| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once
|
||||
//| :return: I2C Slave Request or None if timeout=-1 and there's no request
|
||||
//| :rtype: ~i2cslave.I2CSlaveRequest
|
||||
//| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once
|
||||
//| :return: I2C Slave Request or None if timeout=-1 and there's no request
|
||||
//| :rtype: ~i2cslave.I2CSlaveRequest"""
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cslave_i2c_slave_type));
|
||||
|
@ -228,34 +225,31 @@ const mp_obj_type_t i2cslave_i2c_slave_type = {
|
|||
.locals_dict = (mp_obj_dict_t*)&i2cslave_i2c_slave_locals_dict,
|
||||
};
|
||||
|
||||
|
||||
//| :class:`I2CSlaveRequest` --- I2C Slave Request
|
||||
//| ----------------------------------------------
|
||||
//| class I2CSlaveRequest:
|
||||
//|
|
||||
//| .. class:: I2CSlaveRequest(slave, address, is_read, is_restart)
|
||||
//| def __init__(self, slave: i2cslave.I2CSlave, address: int, is_read: bool, is_restart: bool):
|
||||
//| """I2C transfer request from a master.
|
||||
//| This cannot be instantiated directly, but is returned by :py:meth:`I2CSlave.request`.
|
||||
//|
|
||||
//| I2C transfer request from a master.
|
||||
//| This cannot be instantiated directly, but is returned by :py:meth:`I2CSlave.request`.
|
||||
//|
|
||||
//| :param ~i2cslave.I2CSlave slave: The I2C Slave receiving this request
|
||||
//| :param int address: I2C address
|
||||
//| :param bool is_read: I2C Master read request
|
||||
//| :param bool is_restart: Repeated Start Condition
|
||||
//| :param slave: The I2C Slave receiving this request
|
||||
//| :param address: I2C address
|
||||
//| :param is_read: I2C Master read request
|
||||
//| :param is_restart: Repeated Start Condition"""
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
mp_arg_check_num(n_args, kw_args, 4, 4, false);
|
||||
return mp_obj_new_i2cslave_i2c_slave_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3]));
|
||||
}
|
||||
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used in Context Managers.
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used in Context Managers."""
|
||||
//| ...
|
||||
//|
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Close the request.
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Close the request."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cslave_i2c_slave_request_type));
|
||||
|
@ -265,9 +259,8 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_obj___exit__(size_t n_args, const mp_
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cslave_i2c_slave_request___exit___obj, 4, 4, i2cslave_i2c_slave_request_obj___exit__);
|
||||
|
||||
//| .. attribute:: address
|
||||
//|
|
||||
//| The I2C address of the request.
|
||||
//| address: int = ...
|
||||
//| """The I2C address of the request."""
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_get_address(mp_obj_t self_in) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type));
|
||||
|
@ -276,9 +269,8 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_get_address(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_PROP_GET(i2cslave_i2c_slave_request_address_obj, i2cslave_i2c_slave_request_get_address);
|
||||
|
||||
//| .. attribute:: is_read
|
||||
//|
|
||||
//| The I2C master is reading from the device.
|
||||
//| is_read: bool = ...
|
||||
//| """The I2C master is reading from the device."""
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_read(mp_obj_t self_in) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type));
|
||||
|
@ -287,9 +279,8 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_read(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_PROP_GET(i2cslave_i2c_slave_request_is_read_obj, i2cslave_i2c_slave_request_get_is_read);
|
||||
|
||||
//| .. attribute:: is_restart
|
||||
//|
|
||||
//| Is Repeated Start Condition.
|
||||
//| is_restart: bool = ...
|
||||
//| """Is Repeated Start Condition."""
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_restart(mp_obj_t self_in) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type));
|
||||
|
@ -298,15 +289,14 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_get_is_restart(mp_obj_t self_in) {
|
|||
}
|
||||
MP_DEFINE_CONST_PROP_GET(i2cslave_i2c_slave_request_is_restart_obj, i2cslave_i2c_slave_request_get_is_restart);
|
||||
|
||||
//| .. method:: read(n=-1, ack=True)
|
||||
//| def read(self, n: int = -1, ack: bool = True) -> bytearray:
|
||||
//| """Read data.
|
||||
//| If ack=False, the caller is responsible for calling :py:meth:`I2CSlaveRequest.ack`.
|
||||
//|
|
||||
//| Read data.
|
||||
//| If ack=False, the caller is responsible for calling :py:meth:`I2CSlaveRequest.ack`.
|
||||
//|
|
||||
//| :param int n: Number of bytes to read (negative means all)
|
||||
//| :param bool ack: Whether or not to send an ACK after the n'th byte
|
||||
//| :return: Bytes read
|
||||
//| :rtype: bytearray
|
||||
//| :param n: Number of bytes to read (negative means all)
|
||||
//| :param ack: Whether or not to send an ACK after the n'th byte
|
||||
//| :return: Bytes read"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cslave_i2c_slave_request_type));
|
||||
|
@ -359,12 +349,12 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_read(size_t n_args, const mp_obj_t *p
|
|||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(i2cslave_i2c_slave_request_read_obj, 1, i2cslave_i2c_slave_request_read);
|
||||
|
||||
//| .. method:: write(buffer)
|
||||
//| def write(self, buffer: bytearray) -> int:
|
||||
//| """Write the data contained in buffer.
|
||||
//|
|
||||
//| Write the data contained in buffer.
|
||||
//|
|
||||
//| :param bytearray buffer: Write out the data in this buffer
|
||||
//| :return: Number of bytes written
|
||||
//| :param buffer: Write out the data in this buffer
|
||||
//| :return: Number of bytes written"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_write(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cslave_i2c_slave_request_type));
|
||||
|
@ -393,12 +383,12 @@ STATIC mp_obj_t i2cslave_i2c_slave_request_write(mp_obj_t self_in, mp_obj_t buf_
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2cslave_i2c_slave_request_write_obj, i2cslave_i2c_slave_request_write);
|
||||
|
||||
//| .. method:: ack(ack=True)
|
||||
//| def ack(self, ack: bool = True) -> Any:
|
||||
//| """Acknowledge or Not Acknowledge last byte received.
|
||||
//| Use together with :py:meth:`I2CSlaveRequest.read` ack=False.
|
||||
//|
|
||||
//| Acknowledge or Not Acknowledge last byte received.
|
||||
//| Use together with :py:meth:`I2CSlaveRequest.read` ack=False.
|
||||
//|
|
||||
//| :param bool ack: Whether to send an ACK or NACK
|
||||
//| :param ack: Whether to send an ACK or NACK"""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t i2cslave_i2c_slave_request_ack(uint n_args, const mp_obj_t *args) {
|
||||
mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cslave_i2c_slave_request_type));
|
||||
|
|
|
@ -35,22 +35,10 @@
|
|||
|
||||
#include "py/runtime.h"
|
||||
|
||||
//| :mod:`i2cslave` --- Two wire serial protocol slave
|
||||
//| ==================================================
|
||||
//|
|
||||
//| .. module:: i2cslave
|
||||
//| :synopsis: Two wire serial protocol slave
|
||||
//| :platform: SAMD21, SAMD51
|
||||
//| """Two wire serial protocol slave
|
||||
//|
|
||||
//| The `i2cslave` module contains classes to support a I2C slave.
|
||||
//|
|
||||
//| Classes
|
||||
//|
|
||||
//| .. toctree::
|
||||
//| :maxdepth: 3
|
||||
//|
|
||||
//| I2CSlave
|
||||
//|
|
||||
//| Example emulating 2 devices::
|
||||
//|
|
||||
//| import board
|
||||
|
@ -101,7 +89,7 @@
|
|||
//|
|
||||
//| Raspberry Pi in particular does not support this with its I2C hw block.
|
||||
//| This can be worked around by using the ``i2c-gpio`` bit banging driver.
|
||||
//| Since the RPi firmware uses the hw i2c, it's not possible to emulate a HAT eeprom.
|
||||
//| Since the RPi firmware uses the hw i2c, it's not possible to emulate a HAT eeprom."""
|
||||
//|
|
||||
|
||||
STATIC const mp_rom_map_elem_t i2cslave_module_globals_table[] = {
|
||||
|
|
|
@ -7,13 +7,17 @@ present or if flash space is limited. For example, a microcontroller without
|
|||
analog features will not have `analogio`. See the `support_matrix` page for
|
||||
a list of modules supported on each board.
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
|
||||
support_matrix
|
||||
|
||||
Modules
|
||||
---------
|
||||
|
||||
.. toctree::
|
||||
:glob:
|
||||
:maxdepth: 3
|
||||
:maxdepth: 2
|
||||
|
||||
support_matrix
|
||||
*/__init__
|
||||
../autoapi/*/index
|
||||
help
|
||||
|
|
|
@ -38,15 +38,10 @@
|
|||
#define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846)
|
||||
|
||||
|
||||
//| :mod:`math` --- mathematical functions
|
||||
//| ========================================================
|
||||
//|
|
||||
//| .. module:: math
|
||||
//| :synopsis: mathematical functions
|
||||
//| :platform: SAMD21/SAMD51
|
||||
//| """mathematical functions
|
||||
//|
|
||||
//| The `math` module provides some basic mathematical functions for
|
||||
//| working with floating-point numbers.
|
||||
//| working with floating-point numbers."""
|
||||
//|
|
||||
|
||||
STATIC NORETURN void math_error(void) {
|
||||
|
@ -83,182 +78,170 @@ STATIC NORETURN void math_error(void) {
|
|||
// 1.442695040888963407354163704 is 1/_M_LN2
|
||||
#define log2(x) (log(x) * 1.442695040888963407354163704)
|
||||
#endif
|
||||
//| Constants
|
||||
//| ---------
|
||||
//|
|
||||
//| .. data:: e
|
||||
//|
|
||||
//| base of the natural logarithm
|
||||
//|
|
||||
//| .. data:: pi
|
||||
//|
|
||||
//| the ratio of a circle's circumference to its diameter
|
||||
//|
|
||||
|
||||
//| Functions
|
||||
//| ---------
|
||||
//|
|
||||
//| .. function:: acos(x)
|
||||
//|
|
||||
//| Return the inverse cosine of ``x``.
|
||||
//|
|
||||
//| .. function:: asin(x)
|
||||
//|
|
||||
//| Return the inverse sine of ``x``.
|
||||
//|
|
||||
//| .. function:: atan(x)
|
||||
//|
|
||||
//| Return the inverse tangent of ``x``.
|
||||
//|
|
||||
//| .. function:: atan2(y,x)
|
||||
//|
|
||||
//| Return the principal value of the inverse tangent of ``y/x``.
|
||||
//|
|
||||
//| .. function:: ceil(x)
|
||||
//|
|
||||
//| Return an integer, being ``x`` rounded towards positive infinity.
|
||||
//|
|
||||
//| .. function:: copysign(x,y)
|
||||
//|
|
||||
//| Return ``x`` with the sign of ``y``.
|
||||
//|
|
||||
//| .. function:: cos(x)
|
||||
//|
|
||||
//| Return the cosine of ``x``.
|
||||
//|
|
||||
//| .. function:: degrees(x)
|
||||
//|
|
||||
//| Return radians ``x`` converted to degrees.
|
||||
//|
|
||||
//| .. function:: exp(x)
|
||||
//|
|
||||
//| Return the exponential of ``x``.
|
||||
//|
|
||||
//| .. function:: fabs(x)
|
||||
//|
|
||||
//| Return the absolute value of ``x``.
|
||||
//|
|
||||
//| .. function:: floor(x)
|
||||
//|
|
||||
//| Return an integer, being ``x`` rounded towards negative infinity.
|
||||
//|
|
||||
//| .. function:: fmod(x,y)
|
||||
//|
|
||||
//| Return the remainder of ``x/y``.
|
||||
//|
|
||||
//| .. function:: frexp(x)
|
||||
//|
|
||||
//| Decomposes a floating-point number into its mantissa and exponent.
|
||||
//| The returned value is the tuple ``(m, e)`` such that ``x == m * 2**e``
|
||||
//| exactly. If ``x == 0`` then the function returns ``(0.0, 0)``, otherwise
|
||||
//| the relation ``0.5 <= abs(m) < 1`` holds.
|
||||
//|
|
||||
//| .. function:: isfinite(x)
|
||||
//|
|
||||
//| Return ``True`` if ``x`` is finite.
|
||||
//|
|
||||
//| .. function:: isinf(x)
|
||||
//|
|
||||
//| Return ``True`` if ``x`` is infinite.
|
||||
//|
|
||||
//| .. function:: isnan(x)
|
||||
//|
|
||||
//| Return ``True`` if ``x`` is not-a-number
|
||||
//|
|
||||
//| .. function:: ldexp(x, exp)
|
||||
//|
|
||||
//| Return ``x * (2**exp)``.
|
||||
//|
|
||||
//| .. function:: modf(x)
|
||||
//|
|
||||
//| Return a tuple of two floats, being the fractional and integral parts of
|
||||
//| ``x``. Both return values have the same sign as ``x``.
|
||||
//|
|
||||
//| .. function:: pow(x, y)
|
||||
//|
|
||||
//| Returns ``x`` to the power of ``y``.
|
||||
//|
|
||||
//| .. function:: radians(x)
|
||||
//|
|
||||
//| Return degrees ``x`` converted to radians.
|
||||
//|
|
||||
//| .. function:: sin(x)
|
||||
//|
|
||||
//| Return the sine of ``x``.
|
||||
//|
|
||||
//| .. function:: sqrt(x)
|
||||
//|
|
||||
//| Returns the square root of ``x``.
|
||||
//|
|
||||
//| .. function:: tan(x)
|
||||
//|
|
||||
//| Return the tangent of ``x``.
|
||||
//|
|
||||
//| .. function:: trunc(x)
|
||||
//|
|
||||
//| Return an integer, being ``x`` rounded towards 0.
|
||||
//|
|
||||
//| e: Any = ...
|
||||
//| """base of the natural logarithm"""
|
||||
//|
|
||||
//| pi: Any = ...
|
||||
//| """the ratio of a circle's circumference to its diameter"""
|
||||
//|
|
||||
|
||||
//| def acos(x: Any) -> Any:
|
||||
//| """Return the inverse cosine of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def asin(x: Any) -> Any:
|
||||
//| """Return the inverse sine of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def atan(x: Any) -> Any:
|
||||
//| """Return the inverse tangent of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def atan2(y: Any, x: Any) -> Any:
|
||||
//| """Return the principal value of the inverse tangent of ``y/x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def ceil(x: Any) -> Any:
|
||||
//| """Return an integer, being ``x`` rounded towards positive infinity."""
|
||||
//| ...
|
||||
//|
|
||||
//| def copysign(x: Any, y: Any) -> Any:
|
||||
//| """Return ``x`` with the sign of ``y``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def cos(x: Any) -> Any:
|
||||
//| """Return the cosine of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def degrees(x: Any) -> Any:
|
||||
//| """Return radians ``x`` converted to degrees."""
|
||||
//| ...
|
||||
//|
|
||||
//| def exp(x: Any) -> Any:
|
||||
//| """Return the exponential of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def fabs(x: Any) -> Any:
|
||||
//| """Return the absolute value of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def floor(x: Any) -> Any:
|
||||
//| """Return an integer, being ``x`` rounded towards negative infinity."""
|
||||
//| ...
|
||||
//|
|
||||
//| def fmod(x: Any, y: Any) -> Any:
|
||||
//| """Return the remainder of ``x/y``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def frexp(x: Any) -> Any:
|
||||
//| """Decomposes a floating-point number into its mantissa and exponent.
|
||||
//| The returned value is the tuple ``(m, e)`` such that ``x == m * 2**e``
|
||||
//| exactly. If ``x == 0`` then the function returns ``(0.0, 0)``, otherwise
|
||||
//| the relation ``0.5 <= abs(m) < 1`` holds."""
|
||||
//| ...
|
||||
//|
|
||||
//| def isfinite(x: Any) -> Any:
|
||||
//| """Return ``True`` if ``x`` is finite."""
|
||||
//| ...
|
||||
//|
|
||||
//| def isinf(x: Any) -> Any:
|
||||
//| """Return ``True`` if ``x`` is infinite."""
|
||||
//| ...
|
||||
//|
|
||||
//| def isnan(x: Any) -> Any:
|
||||
//| """Return ``True`` if ``x`` is not-a-number"""
|
||||
//| ...
|
||||
//|
|
||||
//| def ldexp(x: Any, exp: Any) -> Any:
|
||||
//| """Return ``x * (2**exp)``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def modf(x: Any) -> Any:
|
||||
//| """Return a tuple of two floats, being the fractional and integral parts of
|
||||
//| ``x``. Both return values have the same sign as ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def pow(x: Any, y: Any) -> Any:
|
||||
//| """Returns ``x`` to the power of ``y``."""
|
||||
//|
|
||||
//| def radians(x: Any) -> Any:
|
||||
//| """Return degrees ``x`` converted to radians."""
|
||||
//|
|
||||
//| def sin(x: Any) -> Any:
|
||||
//| """Return the sine of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def sqrt(x: Any) -> Any:
|
||||
//| """Returns the square root of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def tan(x: Any) -> Any:
|
||||
//| """Return the tangent of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
//| def trunc(x: Any) -> Any:
|
||||
//| """Return an integer, being ``x`` rounded towards 0."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1_ERRCOND(sqrt, sqrt, (x < (mp_float_t)0.0))
|
||||
|
||||
MATH_FUN_2(pow, pow)
|
||||
|
||||
MATH_FUN_1(exp, exp)
|
||||
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
|
||||
// Special functions
|
||||
// -----------------
|
||||
//
|
||||
// .. function:: expm1(x)
|
||||
//
|
||||
// Return ``exp(x) - 1``.
|
||||
//
|
||||
//| def expm1(x):
|
||||
//| """Return ``exp(x) - 1``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(expm1, expm1)
|
||||
|
||||
// .. function:: log2(x)
|
||||
//
|
||||
// Return the base-2 logarithm of ``x``.
|
||||
//
|
||||
//| def log2(x):
|
||||
//| """Return the base-2 logarithm of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1_ERRCOND(log2, log2, (x <= (mp_float_t)0.0))
|
||||
|
||||
// .. function:: log10(x)
|
||||
//
|
||||
// Return the base-10 logarithm of ``x``.
|
||||
//
|
||||
//| def log10(x):
|
||||
//| """Return the base-10 logarithm of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1_ERRCOND(log10, log10, (x <= (mp_float_t)0.0))
|
||||
|
||||
// .. function:: cosh(x)
|
||||
//
|
||||
// Return the hyperbolic cosine of ``x``.
|
||||
//
|
||||
//| def cosh(x):
|
||||
//| """Return the hyperbolic cosine of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(cosh, cosh)
|
||||
|
||||
// .. function:: sinh(x)
|
||||
//
|
||||
// Return the hyperbolic sine of ``x``.
|
||||
//
|
||||
//| def sinh(x):
|
||||
//| """Return the hyperbolic sine of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(sinh, sinh)
|
||||
|
||||
// .. function:: tanh(x)
|
||||
//
|
||||
// Return the hyperbolic tangent of ``x``.
|
||||
//
|
||||
//| def tanh(x):
|
||||
//| """Return the hyperbolic tangent of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(tanh, tanh)
|
||||
|
||||
// .. function:: acosh(x)
|
||||
//
|
||||
// Return the inverse hyperbolic cosine of ``x``.
|
||||
//
|
||||
//| def acosh(x):
|
||||
//| """Return the inverse hyperbolic cosine of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(acosh, acosh)
|
||||
|
||||
// .. function:: asinh(x)
|
||||
//
|
||||
// Return the inverse hyperbolic sine of ``x``.
|
||||
//
|
||||
//| def asinh(x):
|
||||
//| """Return the inverse hyperbolic sine of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(asinh, asinh)
|
||||
|
||||
// .. function:: atanh(x)
|
||||
//
|
||||
// Return the inverse hyperbolic tangent of ``x``.
|
||||
//
|
||||
//| def atanh(x):
|
||||
//| """Return the inverse hyperbolic tangent of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(atanh, atanh)
|
||||
#endif
|
||||
|
||||
|
@ -297,28 +280,28 @@ MATH_FUN_1_TO_INT(trunc, trunc)
|
|||
MATH_FUN_2(ldexp, ldexp)
|
||||
#if MICROPY_PY_MATH_SPECIAL_FUNCTIONS
|
||||
|
||||
// .. function:: erf(x)
|
||||
//
|
||||
// Return the error function of ``x``.
|
||||
//
|
||||
//| def erf(x):
|
||||
//| """Return the error function of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(erf, erf)
|
||||
|
||||
// .. function:: erfc(x)
|
||||
//
|
||||
// Return the complementary error function of ``x``.
|
||||
//
|
||||
//| def erfc(x):
|
||||
//| """Return the complementary error function of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(erfc, erfc)
|
||||
|
||||
// .. function:: gamma(x)
|
||||
//
|
||||
// Return the gamma function of ``x``.
|
||||
//
|
||||
//| def gamma(x):
|
||||
//| """Return the gamma function of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(gamma, tgamma)
|
||||
|
||||
// .. function:: lgamma(x)
|
||||
//
|
||||
// Return the natural logarithm of the gamma function of ``x``.
|
||||
//
|
||||
//| def lgamma(x):
|
||||
//| """Return the natural logarithm of the gamma function of ``x``."""
|
||||
//| ...
|
||||
//|
|
||||
MATH_FUN_1(lgamma, lgamma)
|
||||
#endif
|
||||
//TODO: factorial, fsum
|
||||
|
|
|
@ -33,18 +33,14 @@
|
|||
#include "py/runtime.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: microcontroller
|
||||
//| class Pin:
|
||||
//| """Identifies an IO pin on the microcontroller."""
|
||||
//|
|
||||
//| :class:`Pin` --- Pin reference
|
||||
//| ------------------------------------------
|
||||
//|
|
||||
//| Identifies an IO pin on the microcontroller.
|
||||
//|
|
||||
//| .. class:: Pin()
|
||||
//|
|
||||
//| Identifies an IO pin on the microcontroller. They are fixed by the
|
||||
//| hardware so they cannot be constructed on demand. Instead, use
|
||||
//| `board` or `microcontroller.pin` to reference the desired pin.
|
||||
//| def __init__(self, ):
|
||||
//| """Identifies an IO pin on the microcontroller. They are fixed by the
|
||||
//| hardware so they cannot be constructed on demand. Instead, use
|
||||
//| `board` or `microcontroller.pin` to reference the desired pin."""
|
||||
//| ...
|
||||
//|
|
||||
|
||||
static void get_pin_name(const mcu_pin_obj_t *self, qstr* package, qstr* module, qstr* name) {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue