summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-07-21 15:12:04 -0700
committerScott Shawcroft <scott@tannewt.org>2020-07-21 15:12:04 -0700
commit1b3bc980683664876c17862762fdbdd5f378ba7d (patch)
treebfb734cb54095d56451e1516c34044cfc38f5f91
parent900edb2b8e118ff36b708afe65363e5929f00ad8 (diff)
parentcb7df2e1ed7c9866b43994e4013497702d8da727 (diff)
Merge remote-tracking branch 'adafruit/main' into bytearray_find
-rw-r--r--.github/workflows/build.yml2
m---------frozen/circuitpython-stage0
-rwxr-xr-xmain.c8
-rw-r--r--ports/atmel-samd/boards/aloriumtech_evo_m51/mpconfigboard.mk2
-rwxr-xr-xports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk2
-rw-r--r--ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk1
-rw-r--r--ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk22
-rw-r--r--ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.mk2
-rw-r--r--ports/atmel-samd/boards/uchip/mpconfigboard.mk8
-rw-r--r--ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk5
-rw-r--r--ports/atmel-samd/boards/winterbloom_big_honking_button/usermods/_bhb/bhb.c120
-rw-r--r--ports/atmel-samd/boards/winterbloom_big_honking_button/usermods/_bhb/micropython.mk6
-rw-r--r--ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk1
-rw-r--r--ports/atmel-samd/mpconfigport.mk3
-rw-r--r--ports/nrf/boards/particle_argon/mpconfigboard.mk4
-rw-r--r--ports/nrf/boards/particle_boron/mpconfigboard.mk4
-rw-r--r--ports/nrf/boards/particle_xenon/mpconfigboard.mk4
-rw-r--r--py/circuitpy_mpconfig.h5
-rw-r--r--py/mpz.c4
-rw-r--r--shared-bindings/network/__init__.c3
-rw-r--r--shared-bindings/socket/__init__.c3
-rw-r--r--shared-bindings/vectorio/Polygon.c15
-rw-r--r--shared-bindings/wiznet/__init__.c7
-rw-r--r--shared-module/displayio/__init__.c4
-rw-r--r--shared-module/framebufferio/FramebufferDisplay.c5
-rw-r--r--shared-module/framebufferio/FramebufferDisplay.h1
-rw-r--r--shared-module/vectorio/Polygon.c21
-rw-r--r--shared-module/vectorio/VectorShape.c4
-rw-r--r--supervisor/shared/background_callback.c8
-rw-r--r--supervisor/shared/tick.c4
-rw-r--r--supervisor/shared/usb/usb.c8
-rw-r--r--tools/extract_pyi.py142
32 files changed, 325 insertions, 103 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index d5ccfb71c..d809ba8cb 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -37,7 +37,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 sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid
+ pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid isort
- name: Versions
run: |
gcc --version
diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage
-Subproject 0d2c083a2fb57a1562d4806775f45273abbfbfa
+Subproject 9596a5904ed757e6fbffcf03e7aa77ae9ecf522
diff --git a/main.c b/main.c
index f928d0d62..a571c547a 100755
--- a/main.c
+++ b/main.c
@@ -97,6 +97,10 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
}
}
+#if MICROPY_ENABLE_PYSTACK
+static size_t PLACE_IN_DTCM_BSS(_pystack[CIRCUITPY_PYSTACK_SIZE / sizeof(size_t)]);
+#endif
+
void start_mp(supervisor_allocation* heap) {
reset_status_led();
autoreload_stop();
@@ -125,6 +129,10 @@ void start_mp(supervisor_allocation* heap) {
// Clear the readline history. It references the heap we're about to destroy.
readline_init0();
+ #if MICROPY_ENABLE_PYSTACK
+ mp_pystack_init(_pystack, _pystack + (sizeof(_pystack) / sizeof(size_t)));
+ #endif
+
#if MICROPY_ENABLE_GC
gc_init(heap->ptr, heap->ptr + heap->length / 4);
#endif
diff --git a/ports/atmel-samd/boards/aloriumtech_evo_m51/mpconfigboard.mk b/ports/atmel-samd/boards/aloriumtech_evo_m51/mpconfigboard.mk
index 28b1434fb..34301da3f 100644
--- a/ports/atmel-samd/boards/aloriumtech_evo_m51/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/aloriumtech_evo_m51/mpconfigboard.mk
@@ -13,6 +13,4 @@ EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = GD25Q16C
LONGINT_IMPL = MPZ
-CIRCUITPY_NETWORK = 1
-MICROPY_PY_WIZNET5K = 5500
CIRCUITPY_PS2IO = 1
diff --git a/ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk b/ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk
index 7a9e5a780..13ae59de4 100755
--- a/ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk
@@ -11,6 +11,4 @@ EXTERNAL_FLASH_DEVICE_COUNT = 2
EXTERNAL_FLASH_DEVICES = "W25Q64JV_IQ, S25FL064L"
LONGINT_IMPL = MPZ
-CIRCUITPY_NETWORK = 1
-MICROPY_PY_WIZNET5K = 5500
CIRCUITPY_PS2IO = 1
diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk
index febd2a6c3..9c7fe3398 100644
--- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk
@@ -13,7 +13,6 @@ LONGINT_IMPL = MPZ
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_DISPLAYIO = 0
-CIRCUITPY_NETWORK = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_AUDIOMP3 = 0
diff --git a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk
index b6490433e..e0adc11b0 100644
--- a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk
@@ -10,38 +10,32 @@ INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
-# TODO: Turn off analogio for now for space reasons, but restore it
-# when frozen module gets smaller.
-CIRCUITPY_ANALOGIO = 0
CIRCUITPY_AUDIOBUSIO = 0
+CIRCUITPY_AUDIOPWMIO = 0
+CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_BITBANGIO = 0
+CIRCUITPY_BITBANG_APA102 = 0
CIRCUITPY_FREQUENCYIO = 0
+CIRCUITPY_GAMEPADSHIFT = 0
CIRCUITPY_I2CPERIPHERAL = 0
CIRCUITPY_NEOPIXEL_WRITE = 0
-CIRCUITPY_NETWORK = 0
CIRCUITPY_PIXELBUF = 0
CIRCUITPY_PS2IO = 0
+CIRCUITPY_ROTARYIO = 0
CIRCUITPY_RTC = 0
+CIRCUITPY_SAMD = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0
-CIRCUITPY_AUDIOPWMIO = 0
-CIRCUITPY_AUDIOMP3 = 0
-CIRCUITPY_BITBANG_APA102 = 0
-CIRCUITPY_BLEIO = 0
-CIRCUITPY_GAMEPADSHIFT = 0
-CIRCUITPY_NETWORK = 0
-CIRCUITPY_ROTARYIO = 0
-CIRCUITPY_SAMD = 0
-CIRCUITPY_TOUCHIO = 0
CIRCUITPY_VECTORIO = 0
+CIRCUITPY_ANALOGIO = 1
CIRCUITPY_AUDIOMIXER = 1
CIRCUITPY_AUDIOIO = 1
CIRCUITPY_DISPLAYIO = 1
CIRCUITPY_GAMEPAD = 1
-CIRCUITPY_STAGE = 1
CIRCUITPY_MATH = 1
+CIRCUITPY_STAGE = 1
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pewpew_m4
CIRCUITPY_DISPLAY_FONT = $(TOP)/ports/atmel-samd/boards/ugame10/brutalist-6.bdf
diff --git a/ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.mk
index 13863e565..567f1db20 100644
--- a/ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/sparkfun_samd51_thing_plus/mpconfigboard.mk
@@ -12,6 +12,4 @@ EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = AT25SF041A
LONGINT_IMPL = MPZ
-CIRCUITPY_NETWORK = 1
-MICROPY_PY_WIZNET5K = 5500
CIRCUITPY_PS2IO = 1
diff --git a/ports/atmel-samd/boards/uchip/mpconfigboard.mk b/ports/atmel-samd/boards/uchip/mpconfigboard.mk
index 196068a1e..d08690a15 100644
--- a/ports/atmel-samd/boards/uchip/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/uchip/mpconfigboard.mk
@@ -10,9 +10,7 @@ INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = NONE
CIRCUITPY_FULL_BUILD = 0
-# Tweak inlining depending on language.
-ifeq ($(TRANSLATION), zh_Latn_pinyin)
+# Always use aggressive inlining
CFLAGS_INLINE_LIMIT = 45
-else
-CFLAGS_INLINE_LIMIT = 70
-endif
+
+SUPEROPT_GC = 0
diff --git a/ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk
index e06a2af7e..71586d6e0 100644
--- a/ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/winterbloom_big_honking_button/mpconfigboard.mk
@@ -24,10 +24,13 @@ CIRCUITPY_BLEIO = 0
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CPERIPHERAL = 0
-CIRCUITPY_NETWORK = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_PS2IO = 0
CIRCUITPY_USB_HID = 0
CIRCUITPY_USB_MIDI = 0
CIRCUITPY_RTC = 0
+
+# Enable board-specific modules
+USER_C_MODULES = boards/winterbloom_big_honking_button/usermods
+CFLAGS += -DMODULE_BHB_ENABLED=1
diff --git a/ports/atmel-samd/boards/winterbloom_big_honking_button/usermods/_bhb/bhb.c b/ports/atmel-samd/boards/winterbloom_big_honking_button/usermods/_bhb/bhb.c
new file mode 100644
index 000000000..54ce173d8
--- /dev/null
+++ b/ports/atmel-samd/boards/winterbloom_big_honking_button/usermods/_bhb/bhb.c
@@ -0,0 +1,120 @@
+#include "py/obj.h"
+#include "py/runtime.h"
+#include "shared-bindings/microcontroller/Pin.h"
+#include "samd/pins.h"
+#include "sam.h"
+
+STATIC mp_obj_t _bhb_read_adc(void);
+
+STATIC mp_obj_t _bhb_init_adc(void) {
+ claim_pin(&pin_PB08);
+ common_hal_never_reset_pin(&pin_PB08);
+
+ /* Enable the APB clock for the ADC. */
+ PM->APBCMASK.reg |= PM_APBCMASK_ADC;
+
+ /* Enable GCLK0 for the ADC */
+ GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN |
+ GCLK_CLKCTRL_GEN_GCLK0 |
+ GCLK_CLKCTRL_ID_ADC;
+
+ /* Wait for bus synchronization. */
+ while (GCLK->STATUS.bit.SYNCBUSY) {};
+
+ uint32_t bias = (*((uint32_t *) ADC_FUSES_BIASCAL_ADDR) & ADC_FUSES_BIASCAL_Msk) >> ADC_FUSES_BIASCAL_Pos;
+ uint32_t linearity = (*((uint32_t *) ADC_FUSES_LINEARITY_0_ADDR) & ADC_FUSES_LINEARITY_0_Msk) >> ADC_FUSES_LINEARITY_0_Pos;
+ linearity |= ((*((uint32_t *) ADC_FUSES_LINEARITY_1_ADDR) & ADC_FUSES_LINEARITY_1_Msk) >> ADC_FUSES_LINEARITY_1_Pos) << 5;
+
+ /* Wait for bus synchronization. */
+ while (ADC->STATUS.bit.SYNCBUSY) {};
+
+ /* Write the calibration data. */
+ ADC->CALIB.reg = ADC_CALIB_BIAS_CAL(bias) | ADC_CALIB_LINEARITY_CAL(linearity);
+
+ /* Use the internal VCC reference. This is 1/2 of what's on VCCA.
+ since VCCA is 3.3v, this is 1.65v.
+ */
+ ADC->REFCTRL.reg = ADC_REFCTRL_REFSEL_INTVCC1;
+
+ /* Capture 64 samples. */
+ ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_64 | ADC_AVGCTRL_ADJRES(4);
+
+ /* Set the clock prescaler to 32, which is the same as the CircuitPython default.
+ Set the resolution to 16 for averaging
+ */
+ ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV32 |
+ ADC_CTRLB_RESSEL_16BIT;
+
+ /* Configure the input parameters.
+
+ - GAIN_DIV2 means that the input voltage is halved. This is important
+ because the voltage reference is 1/2 of VCCA. So if you want to
+ measure 0-3.3v, you need to halve the input as well.
+
+ - MUXNEG_GND means that the ADC should compare the input value to GND.
+
+ - MUXPOS_PIN3 means that the ADC should read from AIN2, or PB08.
+ */
+ ADC->INPUTCTRL.reg = ADC_INPUTCTRL_GAIN_DIV2 |
+ ADC_INPUTCTRL_MUXNEG_GND |
+ ADC_INPUTCTRL_MUXPOS_PIN2;
+
+
+ /* Set PB08 as an input pin. */
+ PORT->Group[1].DIRCLR.reg = PORT_PB08;
+
+ /* Enable the peripheral multiplexer for PB08. */
+ PORT->Group[1].PINCFG[8].reg |= PORT_PINCFG_PMUXEN;
+
+ /* Set PB08 to function B which is analog input. */
+ PORT->Group[1].PMUX[4].reg |= PORT_PMUX_PMUXE_B;
+
+ /* Wait for bus synchronization. */
+ while (ADC->STATUS.bit.SYNCBUSY) {};
+
+ /* Enable the ADC. */
+ ADC->CTRLA.bit.ENABLE = true;
+
+ /* Make one read and throw it away, as per the datasheet. */
+ _bhb_read_adc();
+
+ return mp_const_none;
+}
+
+STATIC mp_obj_t _bhb_read_adc(void) {
+ /* Wait for bus synchronization. */
+ while (ADC->STATUS.bit.SYNCBUSY) {};
+
+ /* Start the ADC using a software trigger. */
+ ADC->SWTRIG.bit.START = true;
+
+ /* Wait for the result ready flag to be set. */
+ while (ADC->INTFLAG.bit.RESRDY == 0);
+
+ /* Clear the flag. */
+ ADC->INTFLAG.reg = ADC_INTFLAG_RESRDY;
+
+ /* Read the value. */
+ uint32_t result = ADC->RESULT.reg;
+
+ return MP_OBJ_NEW_SMALL_INT(result);
+}
+
+
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(_bhb_init_adc_obj, _bhb_init_adc);
+STATIC MP_DEFINE_CONST_FUN_OBJ_0(_bhb_read_adc_obj, _bhb_read_adc);
+
+STATIC const mp_rom_map_elem_t _bhb_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__bhb) },
+ { MP_ROM_QSTR(MP_QSTR_init_adc), MP_ROM_PTR(&_bhb_init_adc_obj) },
+ { MP_ROM_QSTR(MP_QSTR_read_adc), MP_ROM_PTR(&_bhb_read_adc_obj) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(_bhb_module_globals, _bhb_module_globals_table);
+
+const mp_obj_module_t _bhb_user_cmodule = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&_bhb_module_globals,
+};
+
+MP_REGISTER_MODULE(MP_QSTR__bhb, _bhb_user_cmodule, MODULE_BHB_ENABLED);
diff --git a/ports/atmel-samd/boards/winterbloom_big_honking_button/usermods/_bhb/micropython.mk b/ports/atmel-samd/boards/winterbloom_big_honking_button/usermods/_bhb/micropython.mk
new file mode 100644
index 000000000..9374ec34e
--- /dev/null
+++ b/ports/atmel-samd/boards/winterbloom_big_honking_button/usermods/_bhb/micropython.mk
@@ -0,0 +1,6 @@
+USERMODULES_DIR := $(USERMOD_DIR)
+
+# Add all C files to SRC_USERMOD.
+SRC_USERMOD += $(USERMODULES_DIR)/bhb.c
+
+CFLAGS_USERMOD += -I$(USERMODULES_DIR)
diff --git a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk
index 11592073f..9217cdf23 100644
--- a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk
+++ b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk
@@ -23,7 +23,6 @@ CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_GAMEPAD = 0
CIRCUITPY_I2CPERIPHERAL = 0
-CIRCUITPY_NETWORK = 0
CIRCUITPY_TOUCHIO = 0
CIRCUITPY_RGBMATRIX = 0
CIRCUITPY_PS2IO = 0
diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk
index face79fad..e4cf9ca83 100644
--- a/ports/atmel-samd/mpconfigport.mk
+++ b/ports/atmel-samd/mpconfigport.mk
@@ -54,8 +54,7 @@ CIRCUITPY_TOUCHIO_USE_NATIVE = 0
# The ifndef's allow overriding in mpconfigboard.mk.
ifndef CIRCUITPY_NETWORK
-CIRCUITPY_NETWORK = 1
-MICROPY_PY_WIZNET5K = 5500
+CIRCUITPY_NETWORK = 0
endif
ifndef CIRCUITPY_PS2IO
diff --git a/ports/nrf/boards/particle_argon/mpconfigboard.mk b/ports/nrf/boards/particle_argon/mpconfigboard.mk
index 2ca08b982..f8d3d2aca 100644
--- a/ports/nrf/boards/particle_argon/mpconfigboard.mk
+++ b/ports/nrf/boards/particle_argon/mpconfigboard.mk
@@ -8,7 +8,3 @@ MCU_CHIP = nrf52840
QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = "MX25L3233F"
-
-# Support for the Ethernet FeatherWing
-CIRCUITPY_NETWORK = 1
-MICROPY_PY_WIZNET5K = 5500
diff --git a/ports/nrf/boards/particle_boron/mpconfigboard.mk b/ports/nrf/boards/particle_boron/mpconfigboard.mk
index f03f43a7b..eada97a73 100644
--- a/ports/nrf/boards/particle_boron/mpconfigboard.mk
+++ b/ports/nrf/boards/particle_boron/mpconfigboard.mk
@@ -8,7 +8,3 @@ MCU_CHIP = nrf52840
QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = "MX25L3233F"
-
-# Support for the Ethernet FeatherWing
-CIRCUITPY_NETWORK = 1
-MICROPY_PY_WIZNET5K = 5500
diff --git a/ports/nrf/boards/particle_xenon/mpconfigboard.mk b/ports/nrf/boards/particle_xenon/mpconfigboard.mk
index 44309bbca..6062da378 100644
--- a/ports/nrf/boards/particle_xenon/mpconfigboard.mk
+++ b/ports/nrf/boards/particle_xenon/mpconfigboard.mk
@@ -8,7 +8,3 @@ MCU_CHIP = nrf52840
QSPI_FLASH_FILESYSTEM = 1
EXTERNAL_FLASH_DEVICE_COUNT = 1
EXTERNAL_FLASH_DEVICES = "MX25L3233F"
-
-# Support for the Ethernet FeatherWing
-CIRCUITPY_NETWORK = 1
-MICROPY_PY_WIZNET5K = 5500
diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h
index d05a246fc..a7853fabd 100644
--- a/py/circuitpy_mpconfig.h
+++ b/py/circuitpy_mpconfig.h
@@ -119,6 +119,7 @@
#define MICROPY_QSTR_BYTES_IN_HASH (1)
#define MICROPY_REPL_AUTO_INDENT (1)
#define MICROPY_REPL_EVENT_DRIVEN (0)
+#define MICROPY_ENABLE_PYSTACK (1)
#define MICROPY_STACK_CHECK (1)
#define MICROPY_STREAMS_NON_BLOCK (1)
#ifndef MICROPY_USE_INTERNAL_PRINTF
@@ -785,6 +786,10 @@ void supervisor_run_background_tasks_if_tick(void);
#define CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS 1000
#endif
+#ifndef CIRCUITPY_PYSTACK_SIZE
+#define CIRCUITPY_PYSTACK_SIZE 1024
+#endif
+
#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt"
#define CIRCUITPY_VERBOSE_BLE 0
diff --git a/py/mpz.c b/py/mpz.c
index 7800cdcc4..41b46f92f 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -444,6 +444,10 @@ STATIC size_t mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mpz_dig_t *
}
ilen = id - oidig;
+ // check to prevent usb starvation
+ #ifdef RUN_BACKGROUND_TASKS
+ RUN_BACKGROUND_TASKS;
+ #endif
}
return ilen;
diff --git a/shared-bindings/network/__init__.c b/shared-bindings/network/__init__.c
index 58aa13473..4bd543a0a 100644
--- a/shared-bindings/network/__init__.c
+++ b/shared-bindings/network/__init__.c
@@ -40,6 +40,9 @@
//| """Network Interface Management
//|
+//| .. warning:: This module is disabled in 6.x and will removed in 7.x. Please use networking
+//| libraries instead.
+//|
//| This module provides a registry of configured NICs.
//| It is used by the 'socket' module to look up a suitable
//| NIC when a socket is created."""
diff --git a/shared-bindings/socket/__init__.c b/shared-bindings/socket/__init__.c
index 0ded0218b..2485d8ef8 100644
--- a/shared-bindings/socket/__init__.c
+++ b/shared-bindings/socket/__init__.c
@@ -39,6 +39,9 @@
//| """TCP, UDP and RAW socket support
//|
+//| .. warning:: This module is disabled in 6.x and will removed in 7.x. Please use networking
+//| libraries instead. (Native networking will provide a socket compatible class.)
+//|
//| Create TCP, UDP and RAW sockets for communicating over the Internet."""
//|
diff --git a/shared-bindings/vectorio/Polygon.c b/shared-bindings/vectorio/Polygon.c
index 3443d9e42..1aca4611e 100644
--- a/shared-bindings/vectorio/Polygon.c
+++ b/shared-bindings/vectorio/Polygon.c
@@ -49,20 +49,7 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_ar
//|
STATIC mp_obj_t vectorio_polygon_obj_get_points(mp_obj_t self_in) {
vectorio_polygon_t *self = MP_OBJ_TO_PTR(self_in);
- mp_obj_t list = mp_obj_new_list(0, NULL);
-
- size_t len = 0;
- mp_obj_t *items;
- mp_obj_list_get(common_hal_vectorio_polygon_get_points(self), &len, &items);
-
- for (size_t i = 0; i < len; i += 2) {
- mp_obj_t tuple[] = { items[i], items[i+1] };
- mp_obj_list_append(
- list,
- mp_obj_new_tuple(2, tuple)
- );
- }
- return list;
+ return common_hal_vectorio_polygon_get_points(self);
}
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_polygon_get_points_obj, vectorio_polygon_obj_get_points);
diff --git a/shared-bindings/wiznet/__init__.c b/shared-bindings/wiznet/__init__.c
index bc7ff150f..8df06b546 100644
--- a/shared-bindings/wiznet/__init__.c
+++ b/shared-bindings/wiznet/__init__.c
@@ -35,7 +35,12 @@
#include "shared-module/network/__init__.h"
-//| """Support for WizNet hardware, including the WizNet 5500 Ethernet adaptor."""
+//| """Support for WizNet hardware, including the WizNet 5500 Ethernet adaptor.
+//|
+//|
+//| .. warning:: This module is disabled in 6.x and will removed in 7.x. Please use networking
+//| libraries instead.
+//| """
//|
extern const mod_network_nic_type_t mod_network_nic_type_wiznet5k;
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c
index c898bbb98..efc28470f 100644
--- a/shared-module/displayio/__init__.c
+++ b/shared-module/displayio/__init__.c
@@ -190,9 +190,7 @@ void reset_displays(void) {
common_hal_displayio_epaperdisplay_show(display, NULL);
#if CIRCUITPY_FRAMEBUFFERIO
} else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) {
- framebufferio_framebufferdisplay_obj_t* display = &displays[i].framebuffer_display;
- display->auto_refresh = true;
- common_hal_framebufferio_framebufferdisplay_show(display, NULL);
+ framebufferio_framebufferdisplay_reset(&displays[i].framebuffer_display);
#endif
}
}
diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c
index 7d09e0bae..2a90fa0d4 100644
--- a/shared-module/framebufferio/FramebufferDisplay.c
+++ b/shared-module/framebufferio/FramebufferDisplay.c
@@ -318,3 +318,8 @@ void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisp
gc_collect_ptr(self->framebuffer);
displayio_display_core_collect_ptrs(&self->core);
}
+
+void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t* self) {
+ common_hal_framebufferio_framebufferdisplay_set_auto_refresh(self, true);
+ common_hal_framebufferio_framebufferdisplay_show(self, NULL);
+}
diff --git a/shared-module/framebufferio/FramebufferDisplay.h b/shared-module/framebufferio/FramebufferDisplay.h
index 1b68d2ab0..ca1ab984a 100644
--- a/shared-module/framebufferio/FramebufferDisplay.h
+++ b/shared-module/framebufferio/FramebufferDisplay.h
@@ -55,6 +55,7 @@ typedef struct {
void framebufferio_framebufferdisplay_background(framebufferio_framebufferdisplay_obj_t* self);
void release_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self);
void reset_framebufferdisplay(framebufferio_framebufferdisplay_obj_t* self);
+void framebufferio_framebufferdisplay_reset(framebufferio_framebufferdisplay_obj_t* self);
void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisplay_obj_t* self);
diff --git a/shared-module/vectorio/Polygon.c b/shared-module/vectorio/Polygon.c
index 0025d4bfc..c44c13fd7 100644
--- a/shared-module/vectorio/Polygon.c
+++ b/shared-module/vectorio/Polygon.c
@@ -20,7 +20,7 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
size_t len = 0;
mp_obj_t *items;
mp_obj_list_get(points_tuple_list, &len, &items);
- VECTORIO_POLYGON_DEBUG("polygon_points_list len: %d\n", len);
+ VECTORIO_POLYGON_DEBUG(" self.len: %d, len: %d, ", self->len, len);
if ( len < 3 ) {
mp_raise_TypeError_varg(translate("Polygon needs at least 3 points"));
@@ -28,9 +28,11 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
if ( self->len < 2*len ) {
if ( self->points_list != NULL ) {
+ VECTORIO_POLYGON_DEBUG("free(%d), ", sizeof(self->points_list));
gc_free( self->points_list );
}
self->points_list = gc_alloc( 2 * len * sizeof(int), false, false );
+ VECTORIO_POLYGON_DEBUG("alloc(%p, %d)", self->points_list, 2 * len * sizeof(int));
}
self->len = 2*len;
@@ -56,22 +58,35 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t points_list) {
- VECTORIO_POLYGON_DEBUG("%p polygon_construct\n", self);
+ VECTORIO_POLYGON_DEBUG("%p polygon_construct: ", self);
self->points_list = NULL;
self->len = 0;
self->on_dirty.obj = NULL;
_clobber_points_list( self, points_list );
+ VECTORIO_POLYGON_DEBUG("\n");
}
mp_obj_t common_hal_vectorio_polygon_get_points(vectorio_polygon_t *self) {
- return self->points_list;
+ VECTORIO_POLYGON_DEBUG("%p common_hal_vectorio_polygon_get_points {len: %d, points_list: %p}\n", self, self->len, self->points_list);
+ mp_obj_t list = mp_obj_new_list(self->len/2, NULL);
+
+ for (size_t i = 0; i < self->len; i += 2) {
+ mp_obj_t tuple[] = { mp_obj_new_int(self->points_list[i]), mp_obj_new_int(self->points_list[i+1]) };
+ mp_obj_list_append(
+ list,
+ mp_obj_new_tuple(2, tuple)
+ );
+ }
+ return list;
}
void common_hal_vectorio_polygon_set_points(vectorio_polygon_t *self, mp_obj_t points_list) {
+ VECTORIO_POLYGON_DEBUG("%p common_hal_vectorio_polygon_set_points: ", self);
_clobber_points_list( self, points_list );
if (self->on_dirty.obj != NULL) {
self->on_dirty.event(self->on_dirty.obj);
}
+ VECTORIO_POLYGON_DEBUG("\n");
}
void common_hal_vectorio_polygon_set_on_dirty(vectorio_polygon_t *self, vectorio_event_t notification) {
diff --git a/shared-module/vectorio/VectorShape.c b/shared-module/vectorio/VectorShape.c
index bfe8a7b25..81f46b3fa 100644
--- a/shared-module/vectorio/VectorShape.c
+++ b/shared-module/vectorio/VectorShape.c
@@ -223,8 +223,8 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
pixel_to_get_x = (input_pixel.y - self->absolute_transform->dy * self->x - self->absolute_transform->y) / self->absolute_transform->dy;
pixel_to_get_y = (input_pixel.x - self->absolute_transform->dx * self->y - self->absolute_transform->x) / self->absolute_transform->dx;
} else {
- pixel_to_get_x = (input_pixel.x - self->absolute_transform->dx * self->x) / self->absolute_transform->dx;
- pixel_to_get_y = (input_pixel.y - self->absolute_transform->dy * self->y) / self->absolute_transform->dy;
+ pixel_to_get_x = (input_pixel.x - self->absolute_transform->dx * self->x - self->absolute_transform->x) / self->absolute_transform->dx;
+ pixel_to_get_y = (input_pixel.y - self->absolute_transform->dy * self->y - self->absolute_transform->y) / self->absolute_transform->dy;
}
VECTORIO_SHAPE_PIXEL_DEBUG(" get_pixel %p (%3d, %3d) -> ( %3d, %3d )", self->ishape.shape, input_pixel.x, input_pixel.y, pixel_to_get_x, pixel_to_get_y);
#ifdef VECTORIO_PERF
diff --git a/supervisor/shared/background_callback.c b/supervisor/shared/background_callback.c
index d10579c4f..8e12dd362 100644
--- a/supervisor/shared/background_callback.c
+++ b/supervisor/shared/background_callback.c
@@ -24,6 +24,8 @@
* THE SOFTWARE.
*/
+#include <string.h>
+
#include "py/gc.h"
#include "py/mpconfig.h"
#include "supervisor/background_callback.h"
@@ -101,6 +103,12 @@ void background_callback_end_critical_section() {
void background_callback_reset() {
CALLBACK_CRITICAL_BEGIN;
+ background_callback_t *cb = (background_callback_t*)callback_head;
+ while(cb) {
+ background_callback_t *next = cb->next;
+ memset(cb, 0, sizeof(*cb));
+ cb = next;
+ }
callback_head = NULL;
callback_tail = NULL;
in_background_callback = false;
diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c
index bc270030f..4af59f78e 100644
--- a/supervisor/shared/tick.c
+++ b/supervisor/shared/tick.c
@@ -66,7 +66,7 @@
static volatile uint64_t PLACE_IN_DTCM_BSS(background_ticks);
-static background_callback_t callback;
+static background_callback_t tick_callback;
volatile uint64_t last_finished_tick = 0;
@@ -119,7 +119,7 @@ void supervisor_tick(void) {
#endif
}
#endif
- background_callback_add(&callback, supervisor_background_tasks, NULL);
+ background_callback_add(&tick_callback, supervisor_background_tasks, NULL);
}
uint64_t supervisor_ticks_ms64() {
diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c
index 472be96d5..36b5ec05d 100644
--- a/supervisor/shared/usb/usb.c
+++ b/supervisor/shared/usb/usb.c
@@ -64,8 +64,8 @@ void usb_init(void) {
tusb_init();
#if MICROPY_KBD_EXCEPTION
- // Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() callback will be invoked when Ctrl+C is received
- // This callback always got invoked regardless of mp_interrupt_char value since we only set it once here
+ // Set Ctrl+C as wanted char, tud_cdc_rx_wanted_cb() usb_callback will be invoked when Ctrl+C is received
+ // This usb_callback always got invoked regardless of mp_interrupt_char value since we only set it once here
tud_cdc_set_wanted_char(CHAR_CTRL_C);
#endif
@@ -83,14 +83,14 @@ void usb_background(void) {
}
}
-static background_callback_t callback;
+static background_callback_t usb_callback;
static void usb_background_do(void* unused) {
usb_background();
}
void usb_irq_handler(void) {
tud_int_handler(0);
- background_callback_add(&callback, usb_background_do, NULL);
+ background_callback_add(&usb_callback, usb_background_do, NULL);
}
//--------------------------------------------------------------------+
diff --git a/tools/extract_pyi.py b/tools/extract_pyi.py
index b9366f6ba..e5da61035 100644
--- a/tools/extract_pyi.py
+++ b/tools/extract_pyi.py
@@ -2,24 +2,91 @@
#
# SPDX-License-Identifier: MIT
+import ast
import os
+import re
import sys
-import astroid
import traceback
-top_level = sys.argv[1].strip("/")
-stub_directory = sys.argv[2]
+import isort
+
+
+IMPORTS_IGNORE = frozenset({'int', 'float', 'bool', 'str', 'bytes', 'tuple', 'list', 'set', 'dict', 'bytearray', 'file', 'buffer'})
+IMPORTS_TYPING = frozenset({'Any', 'Optional', 'Union', 'Tuple', 'List', 'Sequence'})
+IMPORTS_TYPESHED = frozenset({'ReadableBuffer', 'WritableBuffer'})
+
+
+def is_any(node):
+ node_type = type(node)
+ if node is None:
+ return True
+ if node_type == ast.Name and node.id == "Any":
+ return True
+ if (node_type == ast.Attribute and type(node.value) == ast.Name
+ and node.value.id == "typing" and node.attr == "Any"):
+ return True
+ return False
+
+
+def report_missing_annotations(tree):
+ for node in ast.walk(tree):
+ node_type = type(node)
+ if node_type == ast.AnnAssign:
+ if is_any(node.annotation):
+ print(f"Missing attribute type on line {node.lineno}")
+ elif node_type == ast.arg:
+ if is_any(node.annotation) and node.arg != "self":
+ print(f"Missing argument type: {node.arg} on line {node.lineno}")
+ elif node_type == ast.FunctionDef:
+ if is_any(node.returns) and node.name != "__init__":
+ print(f"Missing return type: {node.name} on line {node.lineno}")
+
+
+def extract_imports(tree):
+ modules = set()
+ typing = set()
+ typeshed = set()
+
+ def collect_annotations(anno_tree):
+ if anno_tree is None:
+ return
+ for node in ast.walk(anno_tree):
+ node_type = type(node)
+ if node_type == ast.Name:
+ if node.id in IMPORTS_IGNORE:
+ continue
+ elif node.id in IMPORTS_TYPING:
+ typing.add(node.id)
+ elif node.id in IMPORTS_TYPESHED:
+ typeshed.add(node.id)
+ elif not node.id[0].isupper():
+ modules.add(node.id)
+
+ for node in ast.walk(tree):
+ node_type = type(node)
+ if (node_type == ast.AnnAssign) or (node_type == ast.arg):
+ collect_annotations(node.annotation)
+ elif node_type == ast.FunctionDef:
+ collect_annotations(node.returns)
+
+ return {
+ "modules": sorted(modules),
+ "typing": sorted(typing),
+ "typeshed": sorted(typeshed),
+ }
+
def convert_folder(top_level, stub_directory):
ok = 0
total = 0
filenames = sorted(os.listdir(top_level))
pyi_lines = []
+
for filename in filenames:
full_path = os.path.join(top_level, filename)
file_lines = []
if os.path.isdir(full_path):
- mok, mtotal = convert_folder(full_path, os.path.join(stub_directory, filename))
+ (mok, mtotal) = convert_folder(full_path, os.path.join(stub_directory, filename))
ok += mok
total += mtotal
elif filename.endswith(".c"):
@@ -44,44 +111,57 @@ def convert_folder(top_level, stub_directory):
pyi_lines.extend(file_lines)
if not pyi_lines:
- return ok, total
+ return (ok, total)
stub_filename = os.path.join(stub_directory, "__init__.pyi")
print(stub_filename)
stub_contents = "".join(pyi_lines)
- os.makedirs(stub_directory, exist_ok=True)
- with open(stub_filename, "w") as f:
- f.write(stub_contents)
# Validate that the module is a parseable stub.
total += 1
try:
- tree = astroid.parse(stub_contents)
- for i in tree.body:
- if 'name' in i.__dict__:
- print(i.__dict__['name'])
- for j in i.body:
- if isinstance(j, astroid.scoped_nodes.FunctionDef):
- if None in j.args.__dict__['annotations']:
- print(f"Missing parameter type: {j.__dict__['name']} on line {j.__dict__['lineno']}\n")
- if j.returns:
- if 'Any' in j.returns.__dict__.values():
- print(f"Missing return type: {j.__dict__['name']} on line {j.__dict__['lineno']}")
- elif isinstance(j, astroid.node_classes.AnnAssign):
- if 'name' in j.__dict__['annotation'].__dict__:
- if j.__dict__['annotation'].__dict__['name'] == 'Any':
- print(f"missing attribute type on line {j.__dict__['lineno']}")
-
+ tree = ast.parse(stub_contents)
+ imports = extract_imports(tree)
+ report_missing_annotations(tree)
ok += 1
- except astroid.exceptions.AstroidSyntaxError as e:
- e = e.__cause__
+ except SyntaxError as e:
traceback.print_exception(type(e), e, e.__traceback__)
+ return (ok, total)
+
+ # Add import statements
+ import_lines = ["from __future__ import annotations"]
+ import_lines.extend(f"import {m}" for m in imports["modules"])
+ import_lines.append("from typing import " + ", ".join(imports["typing"]))
+ import_lines.append("from _typeshed import " + ", ".join(imports["typeshed"]))
+ import_body = "\n".join(import_lines)
+ m = re.match(r'(\s*""".*?""")', stub_contents, flags=re.DOTALL)
+ if m:
+ stub_contents = m.group(1) + "\n\n" + import_body + "\n\n" + stub_contents[m.end():]
+ else:
+ stub_contents = import_body + "\n\n" + stub_contents
+ stub_contents = isort.code(stub_contents)
+
+ # Adjust blank lines
+ stub_contents = re.sub(r"\n+class", "\n\n\nclass", stub_contents)
+ stub_contents = re.sub(r"\n+def", "\n\n\ndef", stub_contents)
+ stub_contents = re.sub(r"\n+^(\s+)def", lambda m: f"\n\n{m.group(1)}def", stub_contents, flags=re.M)
+ stub_contents = stub_contents.strip() + "\n"
+
+ os.makedirs(stub_directory, exist_ok=True)
+ with open(stub_filename, "w") as f:
+ f.write(stub_contents)
+
print()
- return ok, total
+ return (ok, total)
+
+
+if __name__ == "__main__":
+ top_level = sys.argv[1].strip("/")
+ stub_directory = sys.argv[2]
-ok, total = convert_folder(top_level, stub_directory)
+ (ok, total) = convert_folder(top_level, stub_directory)
-print(f"{ok} ok out of {total}")
+ print(f"Parsing .pyi files: {total - ok} failed, {ok} passed")
-if ok != total:
- sys.exit(total - ok)
+ if ok != total:
+ sys.exit(total - ok)