Skip to content

Commit 8ed7b11

Browse files
authored
Merge branch 'main' into uzlib-module
2 parents 9d67e62 + 87e59a4 commit 8ed7b11

File tree

481 files changed

+11235
-3599
lines changed

Some content is hidden

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

481 files changed

+11235
-3599
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ jobs:
7272
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --emit native
7373
working-directory: tests
7474
- name: mpy Tests
75-
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --mpy-cross-flags='-mcache-lookup-bc' --via-mpy -d basics float micropython
75+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --via-mpy -d basics float micropython
7676
working-directory: tests
7777
- name: Native mpy Tests
78-
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --mpy-cross-flags='-mcache-lookup-bc' --via-mpy --emit native -d basics float micropython
78+
run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython-coverage ./run-tests.py -j1 --via-mpy --emit native -d basics float micropython
7979
working-directory: tests
8080
- name: Build native modules
8181
run: |

.github/workflows/ports_windows.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ on:
55
pull_request:
66
paths:
77
- '.github/workflows/*.yml'
8-
- 'tools/**'
9-
- 'py/**'
108
- 'extmod/**'
119
- 'lib/**'
10+
- 'mpy-cross/**'
1211
- 'ports/unix/**'
1312
- 'ports/windows/**'
13+
- 'py/**'
14+
- 'requirements*.txt'
15+
- 'tools/**'
1416

1517
concurrency:
1618
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -64,7 +66,7 @@ jobs:
6466
pip install wheel
6567
# requirements_dev.txt doesn't install on windows. (with msys2 python)
6668
# instead, pick a subset for what we want to do
67-
pip install cascadetoml jinja2 typer intelhex
69+
pip install cascadetoml jinja2 typer click intelhex
6870
# check that installed packages work....?
6971
which python; python --version; python -c "import cascadetoml"
7072
which python3; python3 --version; python3 -c "import cascadetoml"

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@
145145
url = https://github.com/adafruit/Adafruit_CircuitPython_RFM69.git
146146
[submodule "ports/espressif/esp-idf"]
147147
path = ports/espressif/esp-idf
148-
url = https://github.com/adafruit/esp-idf.git
149-
branch = circuitpython-v4.4
148+
url = https://github.com/espressif/esp-idf.git
149+
branch = release/v4.4
150150
[submodule "ports/espressif/certificates/nina-fw"]
151151
path = ports/espressif/certificates/nina-fw
152152
url = https://github.com/adafruit/nina-fw.git

LICENSE

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

3-
Copyright (c) 2013-2021 Damien P. George
3+
Copyright (c) 2013-2022 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

docs/library/binascii.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ Functions
3636
Encode binary data in base64 format, as in `RFC 3548
3737
<https://tools.ietf.org/html/rfc3548.html>`_. Returns the encoded data
3838
followed by a newline character, as a bytes object.
39+
40+
.. function:: crc32(data, value=0, /)
41+
42+
Compute CRC-32, the 32-bit checksum of the bytes in *data* starting with an
43+
initial CRC of *value*. The default initial CRC is 0. The algorithm is
44+
consistent with the ZIP file checksum.

docs/library/framebuf.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ For example::
2121
import framebuf
2222

2323
# FrameBuffer needs 2 bytes for every RGB565 pixel
24-
fbuf = framebuf.FrameBuffer(bytearray(10 * 100 * 2), 10, 100, framebuf.RGB565)
24+
fbuf = framebuf.FrameBuffer(bytearray(100 * 10 * 2), 100, 10, framebuf.RGB565)
2525

2626
fbuf.fill(0)
2727
fbuf.text('MicroPython!', 0, 0, 0xffff)
28-
fbuf.hline(0, 10, 96, 0xffff)
28+
fbuf.hline(0, 9, 96, 0xffff)
2929

3030
Constructors
3131
------------

docs/library/sys.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ Constants
8080

8181
A mutable list of directories to search for imported modules.
8282

83+
.. admonition:: Difference to CPython
84+
:class: attention
85+
86+
On MicroPython, an entry with the value ``".frozen"`` will indicate that import
87+
should search :term:`frozen modules <frozen module>` at that point in the search.
88+
If no frozen module is found then search will *not* look for a directory called
89+
``.frozen``, instead it will continue with the next entry in ``sys.path``.
90+
8391
.. data:: platform
8492

8593
The platform that CircuitPython is running on. For OS/RTOS ports, this is

extmod/extmod.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ set(MICROPY_SOURCE_EXTMOD
1010
${MICROPY_EXTMOD_DIR}/machine_i2c.c
1111
${MICROPY_EXTMOD_DIR}/machine_mem.c
1212
${MICROPY_EXTMOD_DIR}/machine_pulse.c
13+
${MICROPY_EXTMOD_DIR}/machine_pwm.c
1314
${MICROPY_EXTMOD_DIR}/machine_signal.c
1415
${MICROPY_EXTMOD_DIR}/machine_spi.c
1516
${MICROPY_EXTMOD_DIR}/modbluetooth.c
1617
${MICROPY_EXTMOD_DIR}/modbtree.c
1718
${MICROPY_EXTMOD_DIR}/modframebuf.c
19+
${MICROPY_EXTMOD_DIR}/modnetwork.c
1820
${MICROPY_EXTMOD_DIR}/modonewire.c
1921
${MICROPY_EXTMOD_DIR}/moduasyncio.c
2022
${MICROPY_EXTMOD_DIR}/modubinascii.c
@@ -23,9 +25,11 @@ set(MICROPY_SOURCE_EXTMOD
2325
${MICROPY_EXTMOD_DIR}/moduhashlib.c
2426
${MICROPY_EXTMOD_DIR}/moduheapq.c
2527
${MICROPY_EXTMOD_DIR}/modujson.c
28+
${MICROPY_EXTMOD_DIR}/moduplatform.c
2629
${MICROPY_EXTMOD_DIR}/modurandom.c
2730
${MICROPY_EXTMOD_DIR}/modure.c
2831
${MICROPY_EXTMOD_DIR}/moduselect.c
32+
${MICROPY_EXTMOD_DIR}/modusocket.c
2933
${MICROPY_EXTMOD_DIR}/modussl_axtls.c
3034
${MICROPY_EXTMOD_DIR}/modussl_mbedtls.c
3135
${MICROPY_EXTMOD_DIR}/modutimeq.c

extmod/modonewire.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "py/obj.h"
1010
#include "py/mphal.h"
1111

12+
#if MICROPY_PY_ONEWIRE
13+
1214
/******************************************************************************/
1315
// Low-level 1-Wire routines
1416

@@ -139,3 +141,5 @@ const mp_obj_module_t mp_module_onewire = {
139141
.base = { &mp_type_module },
140142
.globals = (mp_obj_dict_t *)&onewire_module_globals,
141143
};
144+
145+
#endif // MICROPY_PY_ONEWIRE

extmod/moduasyncio.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include "py/pairheap.h"
3030
#include "py/mphal.h"
3131

32+
#if CIRCUITPY && !(defined(__unix__) || defined(__APPLE__))
33+
#include "shared-bindings/supervisor/__init__.h"
34+
#endif
35+
3236
#if MICROPY_PY_UASYNCIO
3337

3438
// Used when task cannot be guaranteed to be non-NULL.
@@ -59,10 +63,12 @@ STATIC const mp_obj_type_t task_queue_type;
5963
STATIC const mp_obj_type_t task_type;
6064

6165
STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
66+
STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
6267

6368
/******************************************************************************/
6469
// Ticks for task ordering in pairing heap
6570

71+
#if !CIRCUITPY || (defined(__unix__) || defined(__APPLE__))
6672
STATIC mp_obj_t ticks(void) {
6773
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
6874
}
@@ -74,6 +80,20 @@ STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
7480
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
7581
return diff;
7682
}
83+
#else
84+
#define _TICKS_PERIOD (1lu << 29)
85+
#define _TICKS_MAX (_TICKS_PERIOD - 1)
86+
#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1)
87+
88+
#define ticks() supervisor_ticks_ms()
89+
90+
STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
91+
mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
92+
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in);
93+
mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
94+
return diff;
95+
}
96+
#endif
7797

7898
STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
7999
mp_obj_task_t *t1 = (mp_obj_task_t *)n1;
@@ -225,6 +245,11 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) {
225245
}
226246
STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel);
227247

248+
STATIC mp_obj_t task_await(mp_obj_t self_in) {
249+
return task_getiter(self_in, NULL);
250+
}
251+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_await_obj, task_await);
252+
228253
STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
229254
mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in);
230255
if (dest[0] == MP_OBJ_NULL) {
@@ -243,6 +268,9 @@ STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
243268
dest[1] = self_in;
244269
} else if (attr == MP_QSTR_ph_key) {
245270
dest[0] = self->ph_key;
271+
} else if (attr == MP_QSTR___await__) {
272+
dest[0] = MP_OBJ_FROM_PTR(&task_await_obj);
273+
dest[1] = self_in;
246274
}
247275
} else if (dest[1] != MP_OBJ_NULL) {
248276
// Store
@@ -301,7 +329,11 @@ STATIC const mp_obj_type_t task_type = {
301329
// C-level uasyncio module
302330

303331
STATIC const mp_rom_map_elem_t mp_module_uasyncio_globals_table[] = {
332+
#if CIRCUITPY
333+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__asyncio) },
334+
#else
304335
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__uasyncio) },
336+
#endif
305337
{ MP_ROM_QSTR(MP_QSTR_TaskQueue), MP_ROM_PTR(&task_queue_type) },
306338
{ MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_type) },
307339
};
@@ -312,4 +344,6 @@ const mp_obj_module_t mp_module_uasyncio = {
312344
.globals = (mp_obj_dict_t *)&mp_module_uasyncio_globals,
313345
};
314346

347+
MP_REGISTER_MODULE(MP_QSTR__asyncio, mp_module_uasyncio, MICROPY_PY_UASYNCIO);
348+
315349
#endif // MICROPY_PY_UASYNCIO

extmod/moduplatform.c

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2013-2021 Ibrahim Abdelkader <[email protected]>
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
*/
27+
28+
#include "py/runtime.h"
29+
#include "py/objtuple.h"
30+
#include "py/objstr.h"
31+
#include "py/mphal.h"
32+
#include "genhdr/mpversion.h"
33+
34+
#if MICROPY_PY_UPLATFORM
35+
36+
// platform - Access to underlying platform's identifying data
37+
38+
// TODO: Add more architectures, compilers and libraries.
39+
// See: https://sourceforge.net/p/predef/wiki/Home/
40+
41+
#if defined(__ARM_ARCH)
42+
#define PLATFORM_ARCH "arm"
43+
#elif defined(__x86_64__) || defined(_WIN64)
44+
#define PLATFORM_ARCH "x86_64"
45+
#elif defined(__i386__) || defined(_M_IX86)
46+
#define PLATFORM_ARCH "x86"
47+
#elif defined(__xtensa__) || defined(_M_IX86)
48+
#define PLATFORM_ARCH "xtensa"
49+
#else
50+
#define PLATFORM_ARCH ""
51+
#endif
52+
53+
#if defined(__GNUC__)
54+
#define PLATFORM_COMPILER \
55+
"GCC " \
56+
MP_STRINGIFY(__GNUC__) "." \
57+
MP_STRINGIFY(__GNUC_MINOR__) "." \
58+
MP_STRINGIFY(__GNUC_PATCHLEVEL__)
59+
#elif defined(__ARMCC_VERSION)
60+
#define PLATFORM_COMPILER \
61+
"ARMCC " \
62+
MP_STRINGIFY((__ARMCC_VERSION / 1000000)) "." \
63+
MP_STRINGIFY((__ARMCC_VERSION / 10000 % 100)) "." \
64+
MP_STRINGIFY((__ARMCC_VERSION % 10000))
65+
#elif defined(_MSC_VER)
66+
#if defined(_WIN64)
67+
#define COMPILER_BITS "64 bit"
68+
#elif defined(_M_IX86)
69+
#define COMPILER_BITS "32 bit"
70+
#else
71+
#define COMPILER_BITS ""
72+
#endif
73+
#define PLATFORM_COMPILER \
74+
"MSC v." MP_STRINGIFY(_MSC_VER) " " COMPILER_BITS
75+
#else
76+
#define PLATFORM_COMPILER ""
77+
#endif
78+
79+
#if defined(__GLIBC__)
80+
#define PLATFORM_LIBC_LIB "glibc"
81+
#define PLATFORM_LIBC_VER \
82+
MP_STRINGIFY(__GLIBC__) "." \
83+
MP_STRINGIFY(__GLIBC_MINOR__)
84+
#elif defined(__NEWLIB__)
85+
#define PLATFORM_LIBC_LIB "newlib"
86+
#define PLATFORM_LIBC_VER _NEWLIB_VERSION
87+
#else
88+
#define PLATFORM_LIBC_LIB ""
89+
#define PLATFORM_LIBC_VER ""
90+
#endif
91+
92+
#if defined(__linux)
93+
#define PLATFORM_SYSTEM "Linux"
94+
#elif defined(__unix__)
95+
#define PLATFORM_SYSTEM "Unix"
96+
#elif defined(__CYGWIN__)
97+
#define PLATFORM_SYSTEM "Cygwin"
98+
#elif defined(_WIN32)
99+
#define PLATFORM_SYSTEM "Windows"
100+
#else
101+
#define PLATFORM_SYSTEM "MicroPython"
102+
#endif
103+
104+
#ifndef MICROPY_PLATFORM_VERSION
105+
#define MICROPY_PLATFORM_VERSION ""
106+
#endif
107+
108+
STATIC const MP_DEFINE_STR_OBJ(info_platform_obj, PLATFORM_SYSTEM "-" MICROPY_VERSION_STRING "-" \
109+
PLATFORM_ARCH "-" MICROPY_PLATFORM_VERSION "-with-" PLATFORM_LIBC_LIB "" PLATFORM_LIBC_VER);
110+
STATIC const MP_DEFINE_STR_OBJ(info_python_compiler_obj, PLATFORM_COMPILER);
111+
STATIC const MP_DEFINE_STR_OBJ(info_libc_lib_obj, PLATFORM_LIBC_LIB);
112+
STATIC const MP_DEFINE_STR_OBJ(info_libc_ver_obj, PLATFORM_LIBC_VER);
113+
STATIC const mp_rom_obj_tuple_t info_libc_tuple_obj = {
114+
{&mp_type_tuple}, 2, {MP_ROM_PTR(&info_libc_lib_obj), MP_ROM_PTR(&info_libc_ver_obj)}
115+
};
116+
117+
STATIC mp_obj_t platform_platform(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
118+
return MP_OBJ_FROM_PTR(&info_platform_obj);
119+
}
120+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_platform_obj, 0, platform_platform);
121+
122+
STATIC mp_obj_t platform_python_compiler(void) {
123+
return MP_OBJ_FROM_PTR(&info_python_compiler_obj);
124+
}
125+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(platform_python_compiler_obj, platform_python_compiler);
126+
127+
STATIC mp_obj_t platform_libc_ver(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
128+
return MP_OBJ_FROM_PTR(&info_libc_tuple_obj);
129+
}
130+
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_libc_ver_obj, 0, platform_libc_ver);
131+
132+
STATIC const mp_rom_map_elem_t modplatform_globals_table[] = {
133+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uplatform) },
134+
{ MP_ROM_QSTR(MP_QSTR_platform), MP_ROM_PTR(&platform_platform_obj) },
135+
{ MP_ROM_QSTR(MP_QSTR_python_compiler), MP_ROM_PTR(&platform_python_compiler_obj) },
136+
{ MP_ROM_QSTR(MP_QSTR_libc_ver), MP_ROM_PTR(&platform_libc_ver_obj) },
137+
};
138+
139+
STATIC MP_DEFINE_CONST_DICT(modplatform_globals, modplatform_globals_table);
140+
141+
const mp_obj_module_t mp_module_uplatform = {
142+
.base = { &mp_type_module },
143+
.globals = (mp_obj_dict_t *)&modplatform_globals,
144+
};
145+
146+
#endif // MICROPY_PY_UPLATFORM

extmod/modure.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,16 @@ MP_REGISTER_MODULE(MP_QSTR_re, mp_module_ure, MICROPY_PY_URE);
477477
// only if module is enabled by config setting.
478478

479479
#define re1_5_fatal(x) assert(!x)
480+
480481
#include "lib/re1.5/compilecode.c"
482+
#include "lib/re1.5/recursiveloop.c"
483+
#include "lib/re1.5/charclass.c"
484+
481485
#if MICROPY_PY_URE_DEBUG
486+
// Make sure the output print statements go to the same output as other Python output.
487+
#define printf(...) mp_printf(&mp_plat_print, __VA_ARGS__)
482488
#include "lib/re1.5/dumpcode.c"
489+
#undef printf
483490
#endif
484-
#include "lib/re1.5/recursiveloop.c"
485-
#include "lib/re1.5/charclass.c"
486491

487492
#endif // MICROPY_PY_URE

extmod/uasyncio/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __init__(self):
3636
self.state = None
3737
self.exc = StopIteration()
3838

39-
def __iter__(self):
39+
def __await__(self):
4040
return self
4141

4242
def __next__(self):

0 commit comments

Comments
 (0)