Skip to content

Commit fed3081

Browse files
Merge branch 'main' into ports/analog/add-busio
2 parents 3524b1d + 363be5f commit fed3081

File tree

582 files changed

+14179
-5840
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

582 files changed

+14179
-5840
lines changed

.codespell/ignore-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ ftbfs
2626
straightaway
2727
ftbs
2828
ftb
29+
curren

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ bin/
3939
circuitpython-stubs/
4040
test-stubs/
4141
build-*/
42+
docs/genrst/
4243

43-
# Test failure outputs
44+
# Test failure outputs and intermediate artifacts
4445
######################
4546
tests/results/*
47+
tests/ports/unix/ffi_lib.so
4648

4749
# Python cache files
4850
######################
@@ -76,6 +78,7 @@ TAGS
7678
####################
7779
*~
7880

81+
# MacOS desktop metadata files
7982
*.DS_Store
8083
**/*.DS_Store
8184
*.icloud
@@ -100,6 +103,7 @@ TAGS
100103
.cache
101104

102105
**/CLAUDE.local.md
106+
.claude
103107

104108
# windsurf rules
105109
.windsurfrules

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
url = https://github.com/micropython/axtls.git
88
[submodule "lib/libffi"]
99
path = lib/libffi
10-
url = https://github.com/atgreen/libffi
10+
url = https://github.com/libffi/libffi
1111
[submodule "lib/berkeley-db-1.xx"]
1212
path = lib/berkeley-db-1.xx
1313
url = https://github.com/micropython/berkeley-db-1.xx

LICENSE

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013-2023 Damien P. George
3+
Copyright (c) 2013-2025 Damien P. George
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -22,8 +22,6 @@ THE SOFTWARE.
2222

2323
--------------------------------------------------------------------------------
2424

25-
# CIRCUITPY-CHANGE:
26-
2725
Unless specified otherwise (see below), the above license and copyright applies
2826
to all files derived from MicroPython in this repository.
2927

Makefile

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,22 @@ epub:
156156
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
157157

158158
latex:
159-
$(PYTHON) docs/prepare_readme_for_latex.py
160159
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
161-
mv README.rst.bak README.rst
162160
@echo
163161
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
164162
@echo "Run \`make' in that directory to run these through (pdf)latex" \
165163
"(use \`make latexpdf' here to do that automatically)."
166164

167165
# seems to be malfunctioning
168166
latexpdf:
169-
$(PYTHON) docs/prepare_readme_for_latex.py
170167
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
171-
mv README.rst.bak README.rst
172168
@echo "Running LaTeX files through pdflatex..."
173169
$(MAKE) -C $(BUILDDIR)/latex all-pdf
174170
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
175171

176172
# seems to be malfunctioning
177173
latexpdfja:
178-
$(PYTHON) docs/prepare_readme_for_latex.py
179174
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
180-
mv README.rst.bak README.rst
181175
@echo "Running LaTeX files through platex and dvipdfmx..."
182176
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
183177
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
@@ -277,20 +271,20 @@ check-translate:
277271

278272
.PHONY: stubs
279273
stubs:
280-
@rm -rf circuitpython-stubs
281-
@mkdir circuitpython-stubs
282-
@$(PYTHON) tools/extract_pyi.py shared-bindings/ $(STUBDIR)
283-
@$(PYTHON) tools/extract_pyi.py extmod/ulab/code/ $(STUBDIR)/ulab
284-
@for d in ports/*/bindings; do \
274+
rm -rf circuitpython-stubs
275+
mkdir circuitpython-stubs
276+
$(PYTHON) tools/extract_pyi.py shared-bindings/ $(STUBDIR)
277+
$(PYTHON) tools/extract_pyi.py extmod/ulab/code/ $(STUBDIR)/ulab
278+
for d in ports/*/bindings; do \
285279
$(PYTHON) tools/extract_pyi.py "$$d" $(STUBDIR); done
286-
@sed -e "s,__version__,`python -msetuptools_scm`," < setup.py-stubs > circuitpython-stubs/setup.py
287-
@cp README.rst-stubs circuitpython-stubs/README.rst
288-
@cp MANIFEST.in-stubs circuitpython-stubs/MANIFEST.in
289-
@$(PYTHON) tools/board_stubs/build_board_specific_stubs/board_stub_builder.py
290-
@cp -r tools/board_stubs/circuitpython_setboard circuitpython-stubs/circuitpython_setboard
291-
@$(PYTHON) -m build circuitpython-stubs
292-
@touch circuitpython-stubs/board/__init__.py
293-
@touch circuitpython-stubs/board_definitions/__init__.py
280+
sed -e "s,__version__,`python -msetuptools_scm`," < setup.py-stubs > circuitpython-stubs/setup.py
281+
cp README.rst-stubs circuitpython-stubs/README.rst
282+
cp MANIFEST.in-stubs circuitpython-stubs/MANIFEST.in
283+
$(PYTHON) tools/board_stubs/build_board_specific_stubs/board_stub_builder.py
284+
cp -r tools/board_stubs/circuitpython_setboard circuitpython-stubs/circuitpython_setboard
285+
$(PYTHON) -m build circuitpython-stubs
286+
touch circuitpython-stubs/board/__init__.py
287+
touch circuitpython-stubs/board_definitions/__init__.py
294288

295289
.PHONY: check-stubs
296290
check-stubs: stubs

docs/library/array.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Classes
1919
array are given by an `iterable`. If it is not provided, an empty
2020
array is created.
2121

22+
In addition to the methods below, array objects also implement the buffer
23+
protocol. This means the contents of the entire array can be accessed as raw
24+
bytes via a `memoryview` or other interfaces which use this protocol.
25+
2226
.. method:: append(val)
2327

2428
Append new element ``val`` to the end of array, growing it.

docs/library/binascii.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ Functions
3939

4040
.. function:: crc32(data, value=0, /)
4141

42-
Compute CRC-32, the 32-bit checksum of the bytes in *data* starting with an
42+
Compute CRC-32, the 32-bit checksum of the bytes in ``data`` starting with an
4343
initial CRC of *value*. The default initial CRC is 0. The algorithm is
4444
consistent with the ZIP file checksum.

docs/library/builtins.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Functions and types
3131

3232
.. class:: bytearray()
3333

34+
|see_cpython| `python:bytearray`.
35+
3436
.. class:: bytes()
3537

3638
|see_cpython| `python:bytes`.
@@ -86,15 +88,9 @@ Functions and types
8688

8789
.. class:: int()
8890

89-
.. classmethod:: from_bytes(bytes, byteorder)
90-
91-
In CircuitPython, the ``byteorder`` parameter must be positional (this is
92-
compatible with CPython).
93-
94-
.. method:: to_bytes(size, byteorder)
91+
.. classmethod:: from_bytes(bytes, byteorder="big", *, signed=False)
9592

96-
In CircuitPython, the ``byteorder`` parameter must be positional (this is
97-
compatible with CPython).
93+
.. method:: to_bytes(length=1, byteorder="big", *, signed=False)
9894

9995
.. function:: isinstance()
10096

docs/library/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ These libraries are not currently enabled in any CircuitPython build, but may be
3333
json.rst
3434
platform.rst
3535
re.rst
36-
sys.rst
3736
select.rst
37+
sys.rst
3838

3939
Omitted ``string`` functions
4040
----------------------------

docs/library/micropython.rst

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
:mod:`micropython` -- MicroPython extensions and internals
2-
==========================================================
1+
:mod:`micropython` -- access and control MicroPython internals
2+
==============================================================
33

44
.. module:: micropython
55
:synopsis: access and control MicroPython internals
@@ -26,3 +26,132 @@ Functions
2626
provided as part of the :mod:`micropython` module mainly so that scripts can be
2727
written which run under both CPython and MicroPython, by following the above
2828
pattern.
29+
30+
.. CIRCUITPY-CHANGE: REMOVE .. function:: opt_level([level])
31+
32+
If *level* is given then this function sets the optimisation level for subsequent
33+
compilation of scripts, and returns ``None``. Otherwise it returns the current
34+
optimisation level.
35+
36+
The optimisation level controls the following compilation features:
37+
38+
- Assertions: at level 0 assertion statements are enabled and compiled into the
39+
bytecode; at levels 1 and higher assertions are not compiled.
40+
- Built-in ``__debug__`` variable: at level 0 this variable expands to ``True``;
41+
at levels 1 and higher it expands to ``False``.
42+
- Source-code line numbers: at levels 0, 1 and 2 source-code line number are
43+
stored along with the bytecode so that exceptions can report the line number
44+
they occurred at; at levels 3 and higher line numbers are not stored.
45+
46+
The default optimisation level is usually level 0.
47+
48+
.. CIRCUITPY-CHANGE: REMOVE .. function:: alloc_emergency_exception_buf(size)
49+
50+
Allocate *size* bytes of RAM for the emergency exception buffer (a good
51+
size is around 100 bytes). The buffer is used to create exceptions in cases
52+
when normal RAM allocation would fail (eg within an interrupt handler) and
53+
therefore give useful traceback information in these situations.
54+
55+
A good way to use this function is to put it at the start of your main script
56+
(eg ``boot.py`` or ``main.py``) and then the emergency exception buffer will be active
57+
for all the code following it.
58+
59+
.. CIRCUITPY-CHANGE: REMOVE .. function:: mem_info([verbose])
60+
61+
Print information about currently used memory. If the *verbose* argument
62+
is given then extra information is printed.
63+
64+
The information that is printed is implementation dependent, but currently
65+
includes the amount of stack and heap used. In verbose mode it prints out
66+
the entire heap indicating which blocks are used and which are free.
67+
68+
.. CIRCUITPY-CHANGE: REMOVE .. function:: qstr_info([verbose])
69+
70+
Print information about currently interned strings. If the *verbose*
71+
argument is given then extra information is printed.
72+
73+
The information that is printed is implementation dependent, but currently
74+
includes the number of interned strings and the amount of RAM they use. In
75+
verbose mode it prints out the names of all RAM-interned strings.
76+
77+
.. CIRCUITPY-CHANGE: REMOVE .. function:: stack_use()
78+
79+
Return an integer representing the current amount of stack that is being
80+
used. The absolute value of this is not particularly useful, rather it
81+
should be used to compute differences in stack usage at different points.
82+
83+
.. CIRCUITPY-CHANGE: REMOVE .. function:: heap_lock()
84+
.. CIRCUITPY-CHANGE: REMOVE .. function:: heap_unlock()
85+
.. CIRCUITPY-CHANGE: REMOVE .. function:: heap_locked()
86+
87+
Lock or unlock the heap. When locked no memory allocation can occur and a
88+
`builtins.MemoryError` will be raised if any heap allocation is attempted.
89+
`heap_locked()` returns a true value if the heap is currently locked.
90+
91+
These functions can be nested, ie `heap_lock()` can be called multiple times
92+
in a row and the lock-depth will increase, and then `heap_unlock()` must be
93+
called the same number of times to make the heap available again.
94+
95+
Both `heap_unlock()` and `heap_locked()` return the current lock depth
96+
(after unlocking for the former) as a non-negative integer, with 0 meaning
97+
the heap is not locked.
98+
99+
If the REPL becomes active with the heap locked then it will be forcefully
100+
unlocked.
101+
102+
Note: `heap_locked()` is not enabled on most ports by default,
103+
requires ``MICROPY_PY_MICROPYTHON_HEAP_LOCKED``.
104+
105+
.. CIRCUITPY-CHANGE: REMOVE .. function:: kbd_intr(chr)
106+
107+
Set the character that will raise a `KeyboardInterrupt` exception. By
108+
default this is set to 3 during script execution, corresponding to Ctrl-C.
109+
Passing -1 to this function will disable capture of Ctrl-C, and passing 3
110+
will restore it.
111+
112+
This function can be used to prevent the capturing of Ctrl-C on the
113+
incoming stream of characters that is usually used for the REPL, in case
114+
that stream is used for other purposes.
115+
116+
.. CIRCUITPY-CHANGE: REMOVE .. function:: schedule(func, arg)
117+
118+
Schedule the function *func* to be executed "very soon". The function
119+
is passed the value *arg* as its single argument. "Very soon" means that
120+
the MicroPython runtime will do its best to execute the function at the
121+
earliest possible time, given that it is also trying to be efficient, and
122+
that the following conditions hold:
123+
124+
- A scheduled function will never preempt another scheduled function.
125+
- Scheduled functions are always executed "between opcodes" which means
126+
that all fundamental Python operations (such as appending to a list)
127+
are guaranteed to be atomic.
128+
- A given port may define "critical regions" within which scheduled
129+
functions will never be executed. Functions may be scheduled within
130+
a critical region but they will not be executed until that region
131+
is exited. An example of a critical region is a preempting interrupt
132+
handler (an IRQ).
133+
134+
A use for this function is to schedule a callback from a preempting IRQ.
135+
Such an IRQ puts restrictions on the code that runs in the IRQ (for example
136+
the heap may be locked) and scheduling a function to call later will lift
137+
those restrictions.
138+
139+
On multi-threaded ports, the scheduled function's behaviour depends on
140+
whether the Global Interpreter Lock (GIL) is enabled for the specific port:
141+
142+
- If GIL is enabled, the function can preempt any thread and run in its
143+
context.
144+
- If GIL is disabled, the function will only preempt the main thread and run
145+
in its context.
146+
147+
Note: If `schedule()` is called from a preempting IRQ, when memory
148+
allocation is not allowed and the callback to be passed to `schedule()` is
149+
a bound method, passing this directly will fail. This is because creating a
150+
reference to a bound method causes memory allocation. A solution is to
151+
create a reference to the method in the class constructor and to pass that
152+
reference to `schedule()`. This is discussed in detail here
153+
:ref:`reference documentation <isr_rules>` under "Creation of Python
154+
objects".
155+
156+
There is a finite queue to hold the scheduled functions and `schedule()`
157+
will raise a `RuntimeError` if the queue is full.

0 commit comments

Comments
 (0)