Skip to content

Commit 69b6674

Browse files
committed
MPy v1.22 merge: initial merge; not compiled yet
2 parents dfbbbad + 8cd1582 commit 69b6674

File tree

317 files changed

+4786
-4449
lines changed

Some content is hidden

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

317 files changed

+4786
-4449
lines changed

.git-blame-ignore-revs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# all: Update Python formatting to ruff-format.
2+
bbd8760bd9a2302e5abee29db279102bb11d7732
3+
14
# all: Fix various spelling mistakes found by codespell 2.2.6.
25
cf490a70917a1b2d38ba9b58e763e0837d0f7ca7
36

.gitattributes

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
*.props text eol=crlf
1111
*.bat text eol=crlf
1212

13+
# CIRCUITPY-CHANGE: add some more binary types.
1314
# These are binary so should never be modified by git.
1415
*.a binary
16+
*.ico binary
1517
*.png binary
1618
*.jpg binary
1719
*.dxf binary
1820
*.mpy binary
21+
*.der binary
1922
*.deb binary
2023
*.zip binary
2124
*.pdf binary
@@ -24,11 +27,4 @@
2427
# These should also not be modified by git.
2528
tests/basics/string_cr_conversion.py -text
2629
tests/basics/string_crlf_conversion.py -text
27-
ports/stm32/pybcdc.inf_template -text
28-
ports/stm32/usbhost/** -text
29-
ports/cc3200/hal/aes.c -text
30-
ports/cc3200/hal/aes.h -text
31-
ports/cc3200/hal/des.c -text
32-
ports/cc3200/hal/i2s.c -text
33-
ports/cc3200/hal/i2s.h -text
34-
ports/cc3200/version.h -text
30+
# CIRCUITPY-CHANGE: remove non-CircuitPython tests

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
# CIRCUITPY-CHANGES: many additions
6+
57
# Compiled Sources
68
###################
79
*.o

.pre-commit-config.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# SPDX-License-Identifier: Unlicense
44

5+
# CIRCUITPY-CHANGE: CircuitPython-specific.
6+
57
repos:
68
- repo: https://github.com/pre-commit/pre-commit-hooks
79
rev: v4.0.1

LICENSE

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,15 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
23+
--------------------------------------------------------------------------------
24+
25+
#CIRCUITPY-CHANGE:
26+
27+
Unless specified otherwise (see below), the above license and copyright applies
28+
to all files derived from MicroPython in this repository.
29+
30+
Individual files may include additional copyright holders and specify other licenses.
31+
See the comments and SPDX headers.

docs/library/sys.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Constants
4949
.. data:: maxsize
5050

5151
Maximum value which a native integer type can hold on the current platform,
52-
or maximum value representable by CircuitPython integer type, if it's smaller
52+
or maximum value representable by the CircuitPython integer type, if it's smaller
5353
than platform max value (that is the case for CircuitPython ports without
5454
long int support).
5555

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22

33
# Directory that the project lives in, aka ../..
4-
SITE_ROOT = '/'.join(os.path.dirname(__file__).split('/')[0:-2])
4+
SITE_ROOT = "/".join(os.path.dirname(__file__).split("/")[0:-2])
55

66
TEMPLATE_DIRS = (
7-
"%s/templates/" % SITE_ROOT, # Your custom template directory, before the RTD one to override it.
8-
"%s/readthedocs/templates/" % SITE_ROOT, # Default RTD template dir
7+
"%s/templates/"
8+
% SITE_ROOT, # Your custom template directory, before the RTD one to override it.
9+
"%s/readthedocs/templates/" % SITE_ROOT, # Default RTD template dir
910
)
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
.. _micropython2_migration:
2+
3+
MicroPython 2.0 Migration Guide
4+
===============================
5+
6+
MicroPython 2.0 is the (currently in development, not yet available) next major
7+
release of MicroPython.
8+
9+
After maintaining API compatibility for almost a decade with the ``1.x`` series, in
10+
order to unblock some project-wide improvements MicroPython 2.0 will introduce a
11+
small number of breaking API changes that will require some programs to be
12+
updated. This guide explains how to update your Python code to accommodate these
13+
changes.
14+
15+
This document is a work-in-progress. As more work is done on MicroPython 2.0,
16+
more items will be added to the lists below.
17+
18+
**Note:** There are currently no MicroPython 2.0 firmware builds available for
19+
download. You can build it yourself by enabling the ``MICROPY_PREVIEW_VERSION_2``
20+
config option. As it gets closer to being ready for release, builds will be
21+
provided for both ``1.x.y`` and ``2.0.0-preview``.
22+
23+
Hardware and peripherals
24+
------------------------
25+
26+
Overview
27+
~~~~~~~~
28+
29+
The goal is to improve consistency in the :mod:`machine` APIs across different
30+
ports, making it easier to write code, documentation, and tutorials that work on
31+
any supported microcontroller.
32+
33+
This means that some ports' APIs need to change to match other ports.
34+
35+
Changes
36+
~~~~~~~
37+
38+
*None yet*
39+
40+
OS & filesystem
41+
---------------
42+
43+
Overview
44+
~~~~~~~~
45+
46+
The primary goal is to support the ability to execute :term:`.mpy files <.mpy
47+
file>` directly from the filesystem without first copying them into RAM. This
48+
improves code deployment time and reduces memory overhead and fragmentation.
49+
50+
Additionally, a further goal is to support a more flexible way of configuring
51+
partitions, filesystem types, and options like USB mass storage.
52+
53+
Changes
54+
~~~~~~~
55+
56+
*None yet*
57+
58+
CPython compatibility
59+
---------------------
60+
61+
Overview
62+
~~~~~~~~
63+
64+
The goal is to improve compatibility with CPython by removing MicroPython
65+
extensions from CPython APIs. In most cases this means moving existing
66+
MicroPython-specific functions or classes to new modules.
67+
68+
This makes it easier to write code that works on both CPython and MicroPython,
69+
which is useful for development and testing.
70+
71+
Changes
72+
~~~~~~~
73+
74+
*None yet*

examples/usercmodule/cppexample/example.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
extern "C" {
22
#include <examplemodule.h>
3+
#include <py/objstr.h>
34

45
// Here we implement the function using C++ code, but since it's
56
// declaration has to be compatible with C everything goes in extern "C" scope.
67
mp_obj_t cppfunc(mp_obj_t a_obj, mp_obj_t b_obj) {
8+
// The following no-ops are just here to verify the static assertions used in
9+
// the public API all compile with C++.
10+
MP_STATIC_ASSERT_STR_ARRAY_COMPATIBLE;
11+
if (mp_obj_is_type(a_obj, &mp_type_BaseException)) {
12+
}
13+
714
// Prove we have (at least) C++11 features.
815
const auto a = mp_obj_get_int(a_obj);
916
const auto b = mp_obj_get_int(b_obj);

extmod/extmod.mk

+95
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# and provides rules to build 3rd-party components for extmod modules.
33

44
# CIRCUITPY-CHANGE: many extmod modules removed
5+
# CIRCUITPY-CHANGE: modzlib.c still used
56
SRC_EXTMOD_C += \
67
extmod/modasyncio.c \
78
extmod/modbinascii.c \
@@ -37,6 +38,96 @@ SRC_QSTR += $(SRC_EXTMOD_C)
3738
CFLAGS += $(CFLAGS_EXTMOD) $(CFLAGS_THIRDPARTY)
3839
LDFLAGS += $(LDFLAGS_EXTMOD) $(LDFLAGS_THIRDPARTY)
3940

41+
################################################################################
42+
# libm/libm_dbl math library
43+
44+
# Single-precision math library.
45+
SRC_LIB_LIBM_C += $(addprefix lib/libm/,\
46+
acoshf.c \
47+
asinfacosf.c \
48+
asinhf.c \
49+
atan2f.c \
50+
atanf.c \
51+
atanhf.c \
52+
ef_rem_pio2.c \
53+
erf_lgamma.c \
54+
fmodf.c \
55+
kf_cos.c \
56+
kf_rem_pio2.c \
57+
kf_sin.c \
58+
kf_tan.c \
59+
log1pf.c \
60+
math.c \
61+
nearbyintf.c \
62+
roundf.c \
63+
sf_cos.c \
64+
sf_erf.c \
65+
sf_frexp.c \
66+
sf_ldexp.c \
67+
sf_modf.c \
68+
sf_sin.c \
69+
sf_tan.c \
70+
wf_lgamma.c \
71+
wf_tgamma.c \
72+
)
73+
74+
# Choose only one of these sqrt implementations, software or hardware.
75+
SRC_LIB_LIBM_SQRT_SW_C += lib/libm/ef_sqrt.c
76+
SRC_LIB_LIBM_SQRT_HW_C += lib/libm/thumb_vfp_sqrtf.c
77+
78+
# Double-precision math library.
79+
SRC_LIB_LIBM_DBL_C += $(addprefix lib/libm_dbl/,\
80+
__cos.c \
81+
__expo2.c \
82+
__fpclassify.c \
83+
__rem_pio2.c \
84+
__rem_pio2_large.c \
85+
__signbit.c \
86+
__sin.c \
87+
__tan.c \
88+
acos.c \
89+
acosh.c \
90+
asin.c \
91+
asinh.c \
92+
atan.c \
93+
atan2.c \
94+
atanh.c \
95+
ceil.c \
96+
cos.c \
97+
cosh.c \
98+
copysign.c \
99+
erf.c \
100+
exp.c \
101+
expm1.c \
102+
floor.c \
103+
fmod.c \
104+
frexp.c \
105+
ldexp.c \
106+
lgamma.c \
107+
log.c \
108+
log10.c \
109+
log1p.c \
110+
modf.c \
111+
nearbyint.c \
112+
pow.c \
113+
rint.c \
114+
round.c \
115+
scalbn.c \
116+
sin.c \
117+
sinh.c \
118+
tan.c \
119+
tanh.c \
120+
tgamma.c \
121+
trunc.c \
122+
)
123+
124+
# Choose only one of these sqrt implementations, software or hardware.
125+
SRC_LIB_LIBM_DBL_SQRT_SW_C += lib/libm_dbl/sqrt.c
126+
SRC_LIB_LIBM_DBL_SQRT_HW_C += lib/libm_dbl/thumb_vfp_sqrt.c
127+
128+
# Too many warnings in libm_dbl, disable for now.
129+
$(BUILD)/lib/libm_dbl/%.o: CFLAGS += -Wno-double-promotion -Wno-float-conversion
130+
40131
################################################################################
41132
# VFS FAT FS
42133

@@ -75,6 +166,7 @@ SRC_THIRDPARTY_C += $(addprefix $(LITTLEFS_DIR)/,\
75166
lfs2_util.c \
76167
)
77168

169+
# CIRCUITPY-CHANGE: -Wno-missing-field-initializers instead of -Wno-shadow
78170
$(BUILD)/$(LITTLEFS_DIR)/lfs2.o: CFLAGS += -Wno-missing-field-initializers
79171
endif
80172

@@ -235,6 +327,9 @@ SRC_THIRDPARTY_C += $(addprefix $(LWIP_DIR)/,\
235327
core/ipv6/nd6.c \
236328
netif/ethernet.c \
237329
)
330+
ifeq ($(MICROPY_PY_LWIP_LOOPBACK),1)
331+
CFLAGS_EXTMOD += -DLWIP_NETIF_LOOPBACK=1
332+
endif
238333
ifeq ($(MICROPY_PY_LWIP_SLIP),1)
239334
CFLAGS_EXTMOD += -DMICROPY_PY_LWIP_SLIP=1
240335
SRC_THIRDPARTY_C += $(LWIP_DIR)/netif/slipif.c

extmod/lwip-include/lwipopts.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef uint32_t sys_prot_t;
2323
#define LWIP_NETCONN 0
2424
#define LWIP_SOCKET 0
2525

26+
// CIRCUITPY-CHANGE: #if instead of #ifdef
2627
#if MICROPY_PY_LWIP_SLIP
2728
#define LWIP_HAVE_SLIPIF 1
2829
#endif

extmod/misc.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ bool mp_os_dupterm_is_builtin_stream(mp_const_obj_t stream);
3939
void mp_os_dupterm_stream_detached_attached(mp_obj_t stream_detached, mp_obj_t stream_attached);
4040
uintptr_t mp_os_dupterm_poll(uintptr_t poll_flags);
4141
int mp_os_dupterm_rx_chr(void);
42-
void mp_os_dupterm_tx_strn(const char *str, size_t len);
42+
int mp_os_dupterm_tx_strn(const char *str, size_t len);
4343
void mp_os_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc);
4444
#else
45-
#define mp_os_dupterm_tx_strn(s, l)
45+
static inline int mp_os_dupterm_tx_strn(const char *s, size_t l) {
46+
return -1;
47+
}
4648
#endif
4749

4850
#endif // MICROPY_INCLUDED_EXTMOD_MISC_H

extmod/modasyncio.c

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#if MICROPY_PY_ASYNCIO
3333

34+
// CIRCUITPY-CHANGE
3435
#if CIRCUITPY && !(defined(__unix__) || defined(__APPLE__))
3536
#include "shared-bindings/supervisor/__init__.h"
3637
#endif
@@ -308,6 +309,7 @@ STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) {
308309
STATIC mp_obj_t task_iternext(mp_obj_t self_in) {
309310
mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in);
310311
if (TASK_IS_DONE(self)) {
312+
// CIRCUITPY-CHANGE
311313
if (self->data == mp_const_none) {
312314
// Task finished but has already been sent to the loop's exception handler.
313315
mp_raise_StopIteration(MP_OBJ_NULL);

extmod/modbinascii.c

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#if MICROPY_PY_BINASCII
3636

37+
// CIRCUITPY-CHANGE: added
3738
static void check_not_unicode(const mp_obj_t arg) {
3839
#if MICROPY_CPYTHON_COMPAT
3940
if (mp_obj_is_str(arg)) {

extmod/modhashlib.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) {
114114

115115
#else
116116

117+
// CIRCUITPY-CHNAGE
117118
static void check_not_unicode(const mp_obj_t arg) {
118119
#if MICROPY_CPYTHON_COMPAT
119120
if (mp_obj_is_str(arg)) {
@@ -136,6 +137,7 @@ STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args
136137
}
137138

138139
STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) {
140+
// CIRCUITPY-CHANGE
139141
check_not_unicode(arg);
140142
mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in);
141143
hashlib_ensure_not_final(self);
@@ -306,7 +308,7 @@ STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) {
306308

307309
#if MICROPY_SSL_MBEDTLS
308310

309-
#if MBEDTLS_VERSION_NUMBER < 0x02070000
311+
#if MBEDTLS_VERSION_NUMBER < 0x02070000 || MBEDTLS_VERSION_NUMBER >= 0x03000000
310312
#define mbedtls_md5_starts_ret mbedtls_md5_starts
311313
#define mbedtls_md5_update_ret mbedtls_md5_update
312314
#define mbedtls_md5_finish_ret mbedtls_md5_finish

0 commit comments

Comments
 (0)