diff --git a/devices/ble_hci/common-hal/_bleio/att.c b/devices/ble_hci/common-hal/_bleio/att.c index abfe7429f490..f649967ca98e 100644 --- a/devices/ble_hci/common-hal/_bleio/att.c +++ b/devices/ble_hci/common-hal/_bleio/att.c @@ -44,6 +44,7 @@ #include "shared-bindings/_bleio/Service.h" #include "shared-bindings/_bleio/UUID.h" #include "supervisor/shared/tick.h" +#include "supervisor/shared/translate/translate.h" STATIC uint16_t max_mtu = BT_ATT_DEFAULT_LE_MTU; // 23 STATIC unsigned long timeout = 5000; diff --git a/extmod/moduasyncio.c b/extmod/moduasyncio.c index 016ffcbc9982..c4c4d36ad8f0 100644 --- a/extmod/moduasyncio.c +++ b/extmod/moduasyncio.c @@ -33,6 +33,8 @@ #include "shared-bindings/supervisor/__init__.h" #endif +#include "supervisor/shared/translate/translate.h" + #if MICROPY_PY_UASYNCIO // Used when task cannot be guaranteed to be non-NULL. diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c index 7157be31fa7e..5aa9eacefdfe 100644 --- a/extmod/modubinascii.c +++ b/extmod/modubinascii.c @@ -11,6 +11,8 @@ #include "py/runtime.h" #include "py/binary.h" +#include "supervisor/shared/translate/translate.h" + static void check_not_unicode(const mp_obj_t arg) { #if MICROPY_CPYTHON_COMPAT if (mp_obj_is_str(arg)) { diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 265cbd6d5d67..f770ead00666 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -11,7 +11,7 @@ #include "py/objtuple.h" #include "py/binary.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_UCTYPES diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 741f43c74c33..a84254c56620 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -8,7 +8,7 @@ #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_UHASHLIB diff --git a/extmod/moduheapq.c b/extmod/moduheapq.c index 34867a583872..0200245f86d2 100644 --- a/extmod/moduheapq.c +++ b/extmod/moduheapq.c @@ -6,7 +6,7 @@ #include "py/objlist.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_UHEAPQ diff --git a/extmod/modujson.c b/extmod/modujson.c index 9a4db7c27377..cff02ae95ccd 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -13,7 +13,7 @@ #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_UJSON diff --git a/extmod/modutimeq.c b/extmod/modutimeq.c index 495675ad1d53..fcef14ce982d 100644 --- a/extmod/modutimeq.c +++ b/extmod/modutimeq.c @@ -10,7 +10,7 @@ #include "py/runtime.h" #include "py/smallint.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_UTIMEQ diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index b1eeac934b93..6a1a2d611144 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -10,7 +10,7 @@ #include "py/stream.h" #include "py/mperrno.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_UZLIB diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index ed5cc6095f55..d19a53a9efc3 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -20,7 +20,7 @@ #include "extmod/vfs_fat.h" #include "shared/timeutils/timeutils.h" #include "supervisor/filesystem.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if FF_MAX_SS == FF_MIN_SS #define SECSIZE(fs) (FF_MIN_SS) diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index a984ace4a256..94ddbe5f7be1 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -8,7 +8,7 @@ #include "py/runtime.h" #include "py/stream.h" #include "extmod/vfs_posix.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if (defined(MICROPY_VFS_POSIX) && MICROPY_VFS_POSIX) || (defined(MICROPY_VFS_POSIX_FILE) && MICROPY_VFS_POSIX_FILE) diff --git a/main.c b/main.c index 17fe8167f2bb..d2b3edb16a20 100644 --- a/main.c +++ b/main.c @@ -58,7 +58,7 @@ #include "supervisor/shared/status_leds.h" #include "supervisor/shared/tick.h" #include "supervisor/shared/traceback.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/shared/workflow.h" #include "supervisor/usb.h" #include "supervisor/workflow.h" diff --git a/mpy-cross/mpy-cross.mk b/mpy-cross/mpy-cross.mk index 825566efec4d..452e2f3c1f19 100644 --- a/mpy-cross/mpy-cross.mk +++ b/mpy-cross/mpy-cross.mk @@ -67,7 +67,7 @@ SRC_C += \ shared/runtime/gchelper_generic.c \ supervisor/stub/safe_mode.c \ supervisor/stub/stack.c \ - supervisor/shared/translate.c + supervisor/shared/translate/translate.c # Add fmode when compiling with mingw gcc COMPILER_TARGET := $(shell $(CC) -dumpmachine) @@ -78,6 +78,6 @@ endif OBJ = $(PY_CORE_O) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) -$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h +$(BUILD)/supervisor/shared/translate/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/compression.generated.h include $(TOP)/py/mkrules.mk diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 4bcbb5cf8397..a0a211edb0e7 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -123,8 +123,6 @@ $(echo PERIPHERALS_CHIP_FAMILY=$(PERIPHERALS_CHIP_FAMILY)) #Debugging/Optimization ifeq ($(DEBUG), 1) CFLAGS += -ggdb3 -Og -Os - # You may want to disable -flto if it interferes with debugging. - CFLAGS += -flto -flto-partition=one # You may want to enable these flags to make setting breakpoints easier. # CFLAGS += -fno-inline -fno-ipa-sra ifeq ($(CHIP_FAMILY), samd21) @@ -147,11 +145,8 @@ else CFLAGS += -finline-limit=$(CFLAGS_INLINE_LIMIT) endif - CFLAGS += -flto - ifeq ($(CIRCUITPY_FULL_BUILD),0) CFLAGS += --param inline-unit-growth=15 --param max-inline-insns-auto=20 - CFLAGS += -flto-partition=one endif ifdef CFLAGS_BOARD @@ -168,8 +163,7 @@ CFLAGS += \ -mcpu=cortex-m0plus \ -msoft-float \ -mfloat-abi=soft \ - -DSAMD21 \ - -flto-partition=one + -DSAMD21 endif ifeq ($(CHIP_FAMILY), samd51) CFLAGS += \ @@ -206,7 +200,6 @@ endif CFLAGS += -Wno-stringop-overread -Wno-stringop-overflow LDFLAGS = $(CFLAGS) -nostartfiles -Wl,-nostdlib -Wl,-T,$(GENERATED_LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs -LDFLAGS += -flto=$(shell $(NPROC)) LIBS := -lgcc -lc # Use toolchain libm if we're not using our own. @@ -277,6 +270,9 @@ SRC_ASF += \ hpl/oscctrl/hpl_oscctrl.c \ hpl/trng/hpl_trng.c \ +# Ignore these errors +$(BUILD)/asf4/same54/hpl/sercom/hpl_sercom.o: CFLAGS += -Wno-maybe-uninitialized + else ifeq ($(CHIP_FAMILY), same51) SRC_ASF += \ hal/src/hal_rand_sync.c \ diff --git a/ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk index 088748a0ccfe..1c337d6256eb 100644 --- a/ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk @@ -12,3 +12,5 @@ LONGINT_IMPL = MPZ CIRCUITPY__EVE = 1 CIRCUITPY_CANIO = 1 + +CIRCUITPY_LTO_PARTITION = one diff --git a/ports/atmel-samd/boards/matrixportal_m4/mpconfigboard.mk b/ports/atmel-samd/boards/matrixportal_m4/mpconfigboard.mk index fdedf9bc9b42..3a1d41762671 100644 --- a/ports/atmel-samd/boards/matrixportal_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/matrixportal_m4/mpconfigboard.mk @@ -10,6 +10,8 @@ QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C" LONGINT_IMPL = MPZ +CIRCUITPY_LTO_PARTITION = one + CIRCUITPY_AESIO = 0 CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_PARALLELDISPLAY = 0 diff --git a/ports/atmel-samd/common-hal/_pew/PewPew.c b/ports/atmel-samd/common-hal/_pew/PewPew.c index 40cd52134a43..c4d94e3dbd1c 100644 --- a/ports/atmel-samd/common-hal/_pew/PewPew.c +++ b/ports/atmel-samd/common-hal/_pew/PewPew.c @@ -35,7 +35,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/util.h" #include "samd/timers.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "timer_handler.h" diff --git a/ports/atmel-samd/common-hal/analogio/AnalogIn.c b/ports/atmel-samd/common-hal/analogio/AnalogIn.c index e6db95b3580d..d15be8308ae8 100644 --- a/ports/atmel-samd/common-hal/analogio/AnalogIn.c +++ b/ports/atmel-samd/common-hal/analogio/AnalogIn.c @@ -37,7 +37,7 @@ #include "samd/adc.h" #include "shared-bindings/analogio/AnalogIn.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "atmel_start_pins.h" #include "hal/include/hal_adc_sync.h" diff --git a/ports/atmel-samd/common-hal/analogio/AnalogOut.c b/ports/atmel-samd/common-hal/analogio/AnalogOut.c index 2f38fce700e2..b4d556429cd4 100644 --- a/ports/atmel-samd/common-hal/analogio/AnalogOut.c +++ b/ports/atmel-samd/common-hal/analogio/AnalogOut.c @@ -33,7 +33,7 @@ #include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/audioio/AudioOut.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "atmel_start_pins.h" #include "hal/include/hal_dac_sync.h" diff --git a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c index eb98cc8d27ed..447252aacea0 100644 --- a/ports/atmel-samd/common-hal/audiobusio/I2SOut.c +++ b/ports/atmel-samd/common-hal/audiobusio/I2SOut.c @@ -40,7 +40,7 @@ #include "shared-bindings/audiobusio/I2SOut.h" #include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "atmel_start_pins.h" #include "hal/include/hal_gpio.h" diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c index c3bdd9579355..6796fe03f830 100644 --- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c +++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -37,7 +37,7 @@ #include "shared-bindings/audiobusio/PDMIn.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "atmel_start_pins.h" #include "hal/include/hal_gpio.h" @@ -58,11 +58,11 @@ #define MIN_MIC_CLOCK 1000000 #ifdef SAMD21 -#define SERCTRL(name) I2S_SERCTRL_ ## name +#define SERCTRL(name) I2S_SERCTRL_##name #endif #ifdef SAM_D5X_E5X -#define SERCTRL(name) I2S_RXCTRL_ ## name +#define SERCTRL(name) I2S_RXCTRL_##name #endif // Set by interrupt handler when DMA block has finished transferring. @@ -80,46 +80,48 @@ void pdmin_reset(void) { pdmin_dma_block_done = false; pdmin_event_channel = EVSYS_SYNCH_NUM; - while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {} + while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) { + } I2S->INTENCLR.reg = I2S_INTENCLR_MASK; I2S->INTFLAG.reg = I2S_INTFLAG_MASK; I2S->CTRLA.reg &= ~I2S_SYNCBUSY_ENABLE; - while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {} + while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) { + } I2S->CTRLA.reg = I2S_CTRLA_SWRST; } // Caller validates that pins are free. -void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self, - const mcu_pin_obj_t* clock_pin, - const mcu_pin_obj_t* data_pin, - uint32_t sample_rate, - uint8_t bit_depth, - bool mono, - uint8_t oversample) { +void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self, + const mcu_pin_obj_t *clock_pin, + const mcu_pin_obj_t *data_pin, + uint32_t sample_rate, + uint8_t bit_depth, + bool mono, + uint8_t oversample) { self->clock_pin = clock_pin; // PA10, PA20 -> SCK0, PB11 -> SCK1 #ifdef SAMD21 - if (clock_pin == &pin_PA10 + if (clock_pin == &pin_PA10 #if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20) - || clock_pin == &pin_PA20 - #endif - ) { - self->clock_unit = 0; - #if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11) - } else if (clock_pin == &pin_PB11) { - self->clock_unit = 1; + || clock_pin == &pin_PA20 #endif + ) { + self->clock_unit = 0; + #if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11) + } else if (clock_pin == &pin_PB11) { + self->clock_unit = 1; #endif + #else #ifdef SAM_D5X_E5X - if (clock_pin == &pin_PA10 || clock_pin == &pin_PB16) { - self->clock_unit = 0; + if (clock_pin == &pin_PA10 || clock_pin == &pin_PB16) { + self->clock_unit = 0; } else if (clock_pin == &pin_PB12 - #if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28) - || data_pin == &pin_PB28) { - #else - ) { - #endif - self->clock_unit = 1; + #if defined(PIN_PB28) && !defined(IGNORE_PIN_PB28) + || data_pin == &pin_PB28 + #endif + ) { + self->clock_unit = 1; #endif + #endif } else { raise_ValueError_invalid_pin_name(MP_QSTR_clock); } @@ -136,21 +138,21 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self, #endif ) { self->serializer = 0; - } - else if (false - #if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) - || data_pin == &pin_PA08 - #endif - #if defined (PIN_PB16) && !defined(IGNORE_PIN_PB16) - || data_pin == &pin_PB16 - #endif - ) { + } else if (false + #if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) + || data_pin == &pin_PA08 + #endif + #if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16) + || data_pin == &pin_PB16 + #endif + ) { self->serializer = 1; - #endif + #else #ifdef SAM_D5X_E5X if (data_pin == &pin_PB10 || data_pin == &pin_PA22) { self->serializer = 1; #endif + #endif } else { raise_ValueError_invalid_pin_name(MP_QSTR_data); } @@ -163,7 +165,8 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self, if (I2S->CTRLA.bit.ENABLE == 0) { I2S->CTRLA.bit.SWRST = 1; - while (I2S->CTRLA.bit.SWRST == 1) {} + while (I2S->CTRLA.bit.SWRST == 1) { + } } else { #ifdef SAMD21 if ((I2S->CTRLA.vec.SEREN & (1 << self->serializer)) != 0) { @@ -183,10 +186,10 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self, #define GPIO_I2S_FUNCTION GPIO_PIN_FUNCTION_G #endif - uint32_t clock_divisor = (uint32_t) roundf( 48000000.0f / sample_rate / oversample); + uint32_t clock_divisor = (uint32_t)roundf(48000000.0f / sample_rate / oversample); float mic_clock_freq = 48000000.0f / clock_divisor; - self->sample_rate = mic_clock_freq / oversample; - if (mic_clock_freq < MIN_MIC_CLOCK || clock_divisor == 0) { + self->sample_rate = mic_clock_freq / oversample; + if (mic_clock_freq < MIN_MIC_CLOCK || clock_divisor == 0) { mp_raise_ValueError(translate("sampling rate out of range")); } // Find a free GCLK to generate the MCLK signal. @@ -202,9 +205,9 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self, // Clock unit configuration uint32_t clkctrl = I2S_CLKCTRL_MCKSEL_GCLK | - I2S_CLKCTRL_NBSLOTS(2) | - I2S_CLKCTRL_FSWIDTH_SLOT | - I2S_CLKCTRL_SLOTSIZE_16; + I2S_CLKCTRL_NBSLOTS(2) | + I2S_CLKCTRL_FSWIDTH_SLOT | + I2S_CLKCTRL_SLOTSIZE_16; // Serializer configuration #ifdef SAMD21 @@ -241,11 +244,11 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t* self, self->bit_depth = bit_depth; } -bool common_hal_audiobusio_pdmin_deinited(audiobusio_pdmin_obj_t* self) { +bool common_hal_audiobusio_pdmin_deinited(audiobusio_pdmin_obj_t *self) { return self->clock_pin == NULL; } -void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) { +void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t *self) { if (common_hal_audiobusio_pdmin_deinited(self)) { return; } @@ -264,24 +267,24 @@ void common_hal_audiobusio_pdmin_deinit(audiobusio_pdmin_obj_t* self) { self->data_pin = NULL; } -uint8_t common_hal_audiobusio_pdmin_get_bit_depth(audiobusio_pdmin_obj_t* self) { +uint8_t common_hal_audiobusio_pdmin_get_bit_depth(audiobusio_pdmin_obj_t *self) { return self->bit_depth; } -uint32_t common_hal_audiobusio_pdmin_get_sample_rate(audiobusio_pdmin_obj_t* self) { +uint32_t common_hal_audiobusio_pdmin_get_sample_rate(audiobusio_pdmin_obj_t *self) { return self->sample_rate; } -static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length, - DmacDescriptor* descriptor, - DmacDescriptor* second_descriptor, - uint32_t words_per_buffer, uint8_t words_per_sample, - uint32_t* first_buffer, uint32_t* second_buffer) { +static void setup_dma(audiobusio_pdmin_obj_t *self, uint32_t length, + DmacDescriptor *descriptor, + DmacDescriptor *second_descriptor, + uint32_t words_per_buffer, uint8_t words_per_sample, + uint32_t *first_buffer, uint32_t *second_buffer) { descriptor->BTCTRL.reg = DMAC_BTCTRL_VALID | - DMAC_BTCTRL_BLOCKACT_NOACT | - DMAC_BTCTRL_EVOSEL_BLOCK | - DMAC_BTCTRL_DSTINC | - DMAC_BTCTRL_BEATSIZE_WORD; + DMAC_BTCTRL_BLOCKACT_NOACT | + DMAC_BTCTRL_EVOSEL_BLOCK | + DMAC_BTCTRL_DSTINC | + DMAC_BTCTRL_BEATSIZE_WORD; // Block transfer count is the number of beats per block (aka descriptor). // In this case there are two bytes per beat so divide the length by two. @@ -291,7 +294,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length, } descriptor->BTCNT.reg = block_transfer_count; - descriptor->DSTADDR.reg = ((uint32_t) first_buffer + sizeof(uint32_t) * block_transfer_count); + descriptor->DSTADDR.reg = ((uint32_t)first_buffer + sizeof(uint32_t) * block_transfer_count); descriptor->DESCADDR.reg = 0; if (length * words_per_sample > words_per_buffer) { descriptor->DESCADDR.reg = ((uint32_t)second_descriptor); @@ -314,7 +317,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length, block_transfer_count = length * words_per_sample - words_per_buffer; second_descriptor->DESCADDR.reg = 0; } - second_descriptor->DSTADDR.reg = ((uint32_t) second_buffer + sizeof(uint32_t) * block_transfer_count); + second_descriptor->DSTADDR.reg = ((uint32_t)second_buffer + sizeof(uint32_t) * block_transfer_count); second_descriptor->BTCNT.reg = block_transfer_count; #ifdef SAMD21 @@ -324,10 +327,10 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length, second_descriptor->SRCADDR.reg = (uint32_t)&I2S->RXDATA; #endif second_descriptor->BTCTRL.reg = DMAC_BTCTRL_VALID | - DMAC_BTCTRL_BLOCKACT_NOACT | - DMAC_BTCTRL_EVOSEL_BLOCK | - DMAC_BTCTRL_DSTINC | - DMAC_BTCTRL_BEATSIZE_WORD; + DMAC_BTCTRL_BLOCKACT_NOACT | + DMAC_BTCTRL_EVOSEL_BLOCK | + DMAC_BTCTRL_DSTINC | + DMAC_BTCTRL_BEATSIZE_WORD; } } @@ -341,7 +344,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length, // higher sample rate than specified. Then after the audio is // recorded, a more expensive filter non-real-time filter could be // used to down-sample and low-pass. -const uint16_t sinc_filter [OVERSAMPLING] = { +const uint16_t sinc_filter[OVERSAMPLING] = { 0, 2, 9, 21, 39, 63, 94, 132, 179, 236, 302, 379, 467, 565, 674, 792, 920, 1055, 1196, 1341, 1487, 1633, 1776, 1913, @@ -353,26 +356,26 @@ const uint16_t sinc_filter [OVERSAMPLING] = { }; #ifdef SAMD21 -#define REPEAT_16_TIMES(X) do { for(uint8_t j=0; j<4; j++) { X X X X } } while (0) +#define REPEAT_16_TIMES(X) do { for (uint8_t j = 0; j < 4; j++) { X X X X } } while (0) #else -#define REPEAT_16_TIMES(X) do { X X X X X X X X X X X X X X X X } while(0) +#define REPEAT_16_TIMES(X) do { X X X X X X X X X X X X X X X X } while (0) #endif static uint16_t filter_sample(uint32_t pdm_samples[4]) { uint16_t running_sum = 0; const uint16_t *filter_ptr = sinc_filter; - for (uint8_t i = 0; i < OVERSAMPLING/16; i++) { + for (uint8_t i = 0; i < OVERSAMPLING / 16; i++) { // The sample is 16-bits right channel in the upper two bytes and 16-bits left channel // in the lower two bytes. // We just ignore the upper bits uint32_t pdm_sample = pdm_samples[i]; - REPEAT_16_TIMES( { - if (pdm_sample & 0x8000) { - running_sum += *filter_ptr; - } - filter_ptr++; - pdm_sample <<= 1; + REPEAT_16_TIMES({ + if (pdm_sample & 0x8000) { + running_sum += *filter_ptr; } + filter_ptr++; + pdm_sample <<= 1; + } ); } return running_sum; @@ -380,8 +383,8 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) { // output_buffer may be a byte buffer or a halfword buffer. // output_buffer_length is the number of slots, not the number of bytes. -uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* self, - uint16_t* output_buffer, uint32_t output_buffer_length) { +uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t *self, + uint16_t *output_buffer, uint32_t output_buffer_length) { uint8_t dma_channel = dma_allocate_channel(); pdmin_event_channel = find_sync_event_channel_raise(); pdmin_dma_block_done = false; @@ -399,7 +402,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se COMPILER_ALIGNED(16) DmacDescriptor second_descriptor; setup_dma(self, output_buffer_length, dma_descriptor(dma_channel), &second_descriptor, - words_per_buffer, words_per_sample, first_buffer, second_buffer); + words_per_buffer, words_per_sample, first_buffer, second_buffer); uint8_t trigger_source = I2S_DMAC_ID_RX_0; #ifdef SAMD21 @@ -444,7 +447,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se // Flip back and forth between processing the first and second buffers. uint32_t *buffer = first_buffer; - DmacDescriptor* descriptor = dma_descriptor(dma_channel); + DmacDescriptor *descriptor = dma_descriptor(dma_channel); if (buffers_processed % 2 == 1) { buffer = second_buffer; descriptor = &second_descriptor; @@ -459,7 +462,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se uint16_t value = filter_sample(buffer + i * words_per_sample); if (self->bit_depth == 8) { // Truncate to 8 bits. - ((uint8_t*) output_buffer)[values_output] = value >> 8; + ((uint8_t *)output_buffer)[values_output] = value >> 8; } else { output_buffer[values_output] = value; } @@ -471,7 +474,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se // Compute how many more samples we need, and if the last buffer is the last // set of samples needed, adjust the DMA count to only fetch as necessary. remaining_samples_needed = output_buffer_length - values_output; - if (remaining_samples_needed <= samples_per_buffer*2 && + if (remaining_samples_needed <= samples_per_buffer * 2 && remaining_samples_needed > samples_per_buffer) { // Adjust the DMA settings for the current buffer, which will be processed // after the other buffer, which is now receiving samples via DMA. @@ -484,7 +487,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se // Set up to receive the last set of samples (don't include the alternate buffer, now in use). uint32_t samples_needed_for_last_buffer = remaining_samples_needed - samples_per_buffer; descriptor->BTCNT.reg = samples_needed_for_last_buffer * words_per_sample; - descriptor->DSTADDR.reg = ((uint32_t) buffer) + descriptor->DSTADDR.reg = ((uint32_t)buffer) + samples_needed_for_last_buffer * words_per_sample * sizeof(buffer[0]); // Break chain to alternate buffer. diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index 1e1eb80e9ced..a565a77042ad 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -35,7 +35,7 @@ #include "shared-bindings/audioio/AudioOut.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "atmel_start_pins.h" #include "hal/include/hal_gpio.h" diff --git a/ports/atmel-samd/common-hal/busio/I2C.c b/ports/atmel-samd/common-hal/busio/I2C.c index c539cc3abcbd..2ca193c99f2b 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.c +++ b/ports/atmel-samd/common-hal/busio/I2C.c @@ -35,7 +35,7 @@ #include "samd/sercom.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "common-hal/busio/__init__.h" diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index fde15824c8d6..3bb0cabf9efb 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -33,6 +33,7 @@ #include "peripheral_clk_config.h" #include "supervisor/board.h" +#include "supervisor/shared/translate/translate.h" #include "common-hal/busio/__init__.h" #include "hal/include/hal_gpio.h" diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c index ce471f8c1aa3..3a9b628e0bc5 100644 --- a/ports/atmel-samd/common-hal/busio/UART.c +++ b/ports/atmel-samd/common-hal/busio/UART.c @@ -34,7 +34,7 @@ #include "py/mperrno.h" #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/shared/tick.h" #include "hpl_sercom_config.h" diff --git a/ports/atmel-samd/common-hal/countio/Counter.c b/ports/atmel-samd/common-hal/countio/Counter.c index c68b9e18efb1..e3694615ab05 100644 --- a/ports/atmel-samd/common-hal/countio/Counter.c +++ b/ports/atmel-samd/common-hal/countio/Counter.c @@ -7,7 +7,7 @@ #include "eic_handler.h" #include "samd/external_interrupts.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_countio_counter_construct(countio_counter_obj_t *self, const mcu_pin_obj_t *pin, countio_edge_t edge, digitalio_pull_t pull) { diff --git a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c index dee927ce88b0..8358ac4d876c 100644 --- a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c +++ b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c @@ -34,7 +34,7 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" digitalinout_result_t common_hal_digitalio_digitalinout_construct( digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) { diff --git a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c index 4a6a620603e6..22200c5d1cec 100644 --- a/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +++ b/ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -48,7 +48,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/time/__init__.h" #include "supervisor/shared/tick.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #ifdef SAMD21 #include "hpl/gclk/hpl_gclk_base.h" diff --git a/ports/atmel-samd/common-hal/microcontroller/Pin.c b/ports/atmel-samd/common-hal/microcontroller/Pin.c index 1460ece59ea9..b36286e5f268 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Pin.c +++ b/ports/atmel-samd/common-hal/microcontroller/Pin.c @@ -27,6 +27,7 @@ #include "py/runtime.h" #include "shared-bindings/microcontroller/Pin.h" +#include "supervisor/shared/translate/translate.h" #include "atmel_start_pins.h" #include "hal/include/hal_gpio.h" diff --git a/ports/atmel-samd/common-hal/microcontroller/__init__.c b/ports/atmel-samd/common-hal/microcontroller/__init__.c index 6856f4a48b09..60b35a2c5c69 100644 --- a/ports/atmel-samd/common-hal/microcontroller/__init__.c +++ b/ports/atmel-samd/common-hal/microcontroller/__init__.c @@ -36,7 +36,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" #include "supervisor/shared/safe_mode.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_mcu_delay_us(uint32_t delay) { mp_hal_delay_us(delay); diff --git a/ports/atmel-samd/common-hal/ps2io/Ps2.c b/ports/atmel-samd/common-hal/ps2io/Ps2.c index ad7b1108038e..43f40aa48ec8 100644 --- a/ports/atmel-samd/common-hal/ps2io/Ps2.c +++ b/ports/atmel-samd/common-hal/ps2io/Ps2.c @@ -43,7 +43,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/ps2io/Ps2.h" #include "supervisor/port.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #define STATE_IDLE 0 #define STATE_RECV 1 diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c index 8cc455c95821..8bf889bed3c7 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c @@ -44,7 +44,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/pulseio/PulseIn.h" #include "supervisor/shared/tick.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/port.h" // This timer is shared amongst all PulseIn objects as a higher resolution clock. diff --git a/ports/atmel-samd/common-hal/pulseio/PulseOut.c b/ports/atmel-samd/common-hal/pulseio/PulseOut.c index b0407a11363c..dc98e4bd1806 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseOut.c @@ -36,7 +36,7 @@ #include "py/gc.h" #include "py/runtime.h" #include "shared-bindings/pulseio/PulseOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "timer_handler.h" // This timer is shared amongst all PulseOut objects under the assumption that diff --git a/ports/atmel-samd/common-hal/pwmio/PWMOut.c b/ports/atmel-samd/common-hal/pwmio/PWMOut.c index 854e70094f6a..c6e9e07304e9 100644 --- a/ports/atmel-samd/common-hal/pwmio/PWMOut.c +++ b/ports/atmel-samd/common-hal/pwmio/PWMOut.c @@ -38,7 +38,7 @@ #include "hal/utils/include/utils_repeat_macro.h" #include "samd/pins.h" #include "samd/timers.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #undef ENABLE diff --git a/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c b/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c index 856fe04dbc86..d253e0967ec8 100644 --- a/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c @@ -33,7 +33,7 @@ #include "eic_handler.h" #include "samd/external_interrupts.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t *self, const mcu_pin_obj_t *pin_a, const mcu_pin_obj_t *pin_b) { diff --git a/ports/atmel-samd/common-hal/rtc/RTC.c b/ports/atmel-samd/common-hal/rtc/RTC.c index 455f176763ff..0ebb61e11bbd 100644 --- a/ports/atmel-samd/common-hal/rtc/RTC.c +++ b/ports/atmel-samd/common-hal/rtc/RTC.c @@ -37,7 +37,7 @@ #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/rtc/RTC.h" #include "supervisor/port.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // This is the time in seconds since 2000 that the RTC was started. // TODO: Change the offset to ticks so that it can be a subsecond adjustment. diff --git a/ports/atmel-samd/common-hal/sdioio/SDCard.c b/ports/atmel-samd/common-hal/sdioio/SDCard.c index 10ccb63a5505..7ce8a1e1b129 100644 --- a/ports/atmel-samd/common-hal/sdioio/SDCard.c +++ b/ports/atmel-samd/common-hal/sdioio/SDCard.c @@ -32,7 +32,7 @@ #include "shared-bindings/sdioio/SDCard.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "genhdr/sdiodata.h" diff --git a/ports/atmel-samd/common-hal/touchio/TouchIn.c b/ports/atmel-samd/common-hal/touchio/TouchIn.c index 1c0062d52afc..c3fae041fb73 100644 --- a/ports/atmel-samd/common-hal/touchio/TouchIn.c +++ b/ports/atmel-samd/common-hal/touchio/TouchIn.c @@ -33,7 +33,7 @@ #include "py/mphal.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/touchio/TouchIn.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // Native touchio only exists for SAMD21 #ifdef SAMD21 diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 9cd5b39d7016..66ebb54a6b45 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -9,6 +9,7 @@ USB_NUM_ENDPOINT_PAIRS = 8 CIRCUITPY_ROTARYIO_SOFTENCODER = 1 CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE ?= 1 +CIRCUITPY_LTO = 1 ###################################################################### # Put samd21-only choices here. @@ -78,6 +79,8 @@ endif SUPEROPT_GC = 0 SUPEROPT_VM = 0 +CIRCUITPY_LTO_PARTITION = one + ifeq ($(CIRCUITPY_FULL_BUILD),0) # On the smallest boards, this saves about 180 bytes. On other boards, it may -increase- space used. CFLAGS_BOARD = -fweb -frename-registers @@ -94,6 +97,10 @@ ifeq ($(CHIP_FAMILY),samd51) # No native touchio on SAMD51. CIRCUITPY_TOUCHIO_USE_NATIVE = 0 +ifeq ($(CIRCUITPY_FULL_BUILD),0) +CIRCUITPY_LTO_PARTITION ?= one +endif + # The ?='s allow overriding in mpconfigboard.mk. @@ -116,6 +123,10 @@ ifeq ($(CHIP_FAMILY),same51) # No native touchio on SAME51. CIRCUITPY_TOUCHIO_USE_NATIVE = 0 +ifeq ($(CIRCUITPY_FULL_BUILD),0) +CIRCUITPY_LTO_PARTITION ?= one +endif + # The ?='s allow overriding in mpconfigboard.mk. CIRCUITPY_ALARM ?= 1 diff --git a/ports/broadcom/Makefile b/ports/broadcom/Makefile index 921d26958a28..9731f819eb08 100644 --- a/ports/broadcom/Makefile +++ b/ports/broadcom/Makefile @@ -107,7 +107,7 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) # BCM CLFAGS -CFLAGS += -ffreestanding -nostartfiles -DMICROPY_HW_MCU_NAME="\"$(CHIP_VARIANT)\"" +CFLAGS += -nostartfiles -DMICROPY_HW_MCU_NAME="\"$(CHIP_VARIANT)\"" OPTIMIZATION_FLAGS ?= -O3 diff --git a/ports/broadcom/common-hal/digitalio/DigitalInOut.c b/ports/broadcom/common-hal/digitalio/DigitalInOut.c index 38a7cbb2b81a..d8ac3472de9d 100644 --- a/ports/broadcom/common-hal/digitalio/DigitalInOut.c +++ b/ports/broadcom/common-hal/digitalio/DigitalInOut.c @@ -32,7 +32,7 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "peripherals/broadcom/gpio.h" diff --git a/ports/broadcom/common-hal/sdioio/SDCard.c b/ports/broadcom/common-hal/sdioio/SDCard.c index 85a84ac213bc..27b36041de3b 100644 --- a/ports/broadcom/common-hal/sdioio/SDCard.c +++ b/ports/broadcom/common-hal/sdioio/SDCard.c @@ -35,7 +35,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" #include "supervisor/port.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "peripherals/broadcom/cpu.h" #include "peripherals/broadcom/defines.h" diff --git a/ports/cxd56/mpconfigport.mk b/ports/cxd56/mpconfigport.mk index 8787c55bccc6..813d85d4a7ac 100644 --- a/ports/cxd56/mpconfigport.mk +++ b/ports/cxd56/mpconfigport.mk @@ -3,6 +3,8 @@ USB_HIGHSPEED = 1 # Number of USB endpoint pairs. USB_NUM_ENDPOINT_PAIRS = 6 +CIRCUITPY_TRANSLATE_OBJECT = 1 + # Longints can be implemented as mpz, as longlong, or not LONGINT_IMPL = MPZ diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index 96360d06bd84..acdf496edb37 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -165,8 +165,6 @@ else # RISC-V is larger than xtensa so do -Os for it OPTIMIZATION_FLAGS ?= -Os endif - # TODO: Test with -flto - ### CFLAGS += -flto endif # option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk index aed663c250bf..b3c68b3b6242 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/mpconfigboard.mk @@ -6,9 +6,6 @@ USB_MANUFACTURER = "Adafruit" IDF_TARGET = esp32s3 -# Make room for build -CIRCUITPY_ULAB = 0 - INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = MPZ diff --git a/ports/espressif/common-hal/analogio/AnalogIn.c b/ports/espressif/common-hal/analogio/AnalogIn.c index 4d390e615ce3..a81a8add2276 100644 --- a/ports/espressif/common-hal/analogio/AnalogIn.c +++ b/ports/espressif/common-hal/analogio/AnalogIn.c @@ -28,7 +28,7 @@ #include "shared-bindings/analogio/AnalogIn.h" #include "py/mperrno.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "components/driver/include/driver/adc_common.h" #include "components/esp_adc_cal/include/esp_adc_cal.h" diff --git a/ports/espressif/common-hal/analogio/AnalogOut.c b/ports/espressif/common-hal/analogio/AnalogOut.c index 2bceefc9f78b..cc99d4faa146 100644 --- a/ports/espressif/common-hal/analogio/AnalogOut.c +++ b/ports/espressif/common-hal/analogio/AnalogOut.c @@ -33,7 +33,7 @@ #include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #ifdef CONFIG_IDF_TARGET_ESP32S2 #include "components/driver/include/driver/dac_common.h" diff --git a/ports/espressif/common-hal/audiobusio/I2SOut.c b/ports/espressif/common-hal/audiobusio/I2SOut.c index 6548f46071ce..440151e8819d 100644 --- a/ports/espressif/common-hal/audiobusio/I2SOut.c +++ b/ports/espressif/common-hal/audiobusio/I2SOut.c @@ -42,7 +42,7 @@ #include "shared-bindings/audiobusio/I2SOut.h" #include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "driver/i2s.h" diff --git a/ports/espressif/common-hal/busio/I2C.c b/ports/espressif/common-hal/busio/I2C.c index 23906fe2d24f..92bd4fb1576f 100644 --- a/ports/espressif/common-hal/busio/I2C.c +++ b/ports/espressif/common-hal/busio/I2C.c @@ -32,7 +32,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { diff --git a/ports/espressif/common-hal/busio/UART.c b/ports/espressif/common-hal/busio/UART.c index 27323fecf49e..7322abc8efae 100644 --- a/ports/espressif/common-hal/busio/UART.c +++ b/ports/espressif/common-hal/busio/UART.c @@ -38,7 +38,7 @@ #include "py/runtime.h" #include "py/stream.h" #include "supervisor/port.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/shared/tick.h" uint8_t never_reset_uart_mask = 0; diff --git a/ports/espressif/common-hal/countio/Counter.c b/ports/espressif/common-hal/countio/Counter.c index d18196051ff6..bdfc44522c56 100644 --- a/ports/espressif/common-hal/countio/Counter.c +++ b/ports/espressif/common-hal/countio/Counter.c @@ -29,7 +29,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_countio_counter_construct(countio_counter_obj_t *self, const mcu_pin_obj_t *pin, countio_edge_t edge, digitalio_pull_t pull) { diff --git a/ports/espressif/common-hal/digitalio/DigitalInOut.c b/ports/espressif/common-hal/digitalio/DigitalInOut.c index 1ab232b29add..a3e8f411473b 100644 --- a/ports/espressif/common-hal/digitalio/DigitalInOut.c +++ b/ports/espressif/common-hal/digitalio/DigitalInOut.c @@ -26,7 +26,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "components/driver/include/driver/gpio.h" diff --git a/ports/espressif/common-hal/microcontroller/Processor.c b/ports/espressif/common-hal/microcontroller/Processor.c index e4782c30ab87..5ceefa411fd4 100644 --- a/ports/espressif/common-hal/microcontroller/Processor.c +++ b/ports/espressif/common-hal/microcontroller/Processor.c @@ -33,7 +33,7 @@ #include "common-hal/microcontroller/Processor.h" #include "shared-bindings/microcontroller/Processor.h" #include "shared-bindings/microcontroller/ResetReason.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "esp_sleep.h" #include "esp_system.h" diff --git a/ports/litex/Makefile b/ports/litex/Makefile index 6fe9e46bece2..6b1e33c8d1ce 100644 --- a/ports/litex/Makefile +++ b/ports/litex/Makefile @@ -81,8 +81,6 @@ ifeq ($(DEBUG), 1) else CFLAGS += -DNDEBUG -ggdb3 OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions - # TODO: Test with -flto - ### CFLAGS += -flto endif # option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk @@ -99,7 +97,7 @@ LDFLAGS = $(CFLAGS) -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -W LIBS := -lgcc -lc -LDFLAGS += -flto -ffreestanding -nostartfiles -Wl,--gc-section -Wl,-Bstatic -Wl,-melf32lriscv -nostartfiles \ +LDFLAGS += -ffreestanding -nostartfiles -Wl,--gc-section -Wl,-Bstatic -Wl,-melf32lriscv -nostartfiles \ -Wl,--no-warn-mismatch \ -Wl,--build-id=none diff --git a/ports/litex/common-hal/digitalio/DigitalInOut.c b/ports/litex/common-hal/digitalio/DigitalInOut.c index 96cc95dfa6be..a48d698fcb3a 100644 --- a/ports/litex/common-hal/digitalio/DigitalInOut.c +++ b/ports/litex/common-hal/digitalio/DigitalInOut.c @@ -27,7 +27,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "csr.h" diff --git a/ports/litex/common-hal/microcontroller/Processor.c b/ports/litex/common-hal/microcontroller/Processor.c index ff2f041876e6..12c3787c79c1 100644 --- a/ports/litex/common-hal/microcontroller/Processor.c +++ b/ports/litex/common-hal/microcontroller/Processor.c @@ -31,7 +31,7 @@ #include "common-hal/microcontroller/Processor.h" #include "shared-bindings/microcontroller/Processor.h" #include "shared-bindings/microcontroller/ResetReason.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "csr.h" #include "generated/soc.h" diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile index 4a74b8fce536..4b05c9171435 100644 --- a/ports/mimxrt10xx/Makefile +++ b/ports/mimxrt10xx/Makefile @@ -75,7 +75,7 @@ INC += \ # NDEBUG disables assert() statements. This reduces code size pretty dramatically, per tannewt. -CFLAGS += -Os -ftree-vrp -DNDEBUG -ffreestanding +CFLAGS += -ftree-vrp -DNDEBUG # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=512 -DCFG_TUD_MSC_BUFSIZE=1024 @@ -84,12 +84,8 @@ CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_ # Never set -fno-inline because we use inline to move small functions into routines that must be # in RAM. If inlining is disallowed, then we may end up calling a function in flash when we cannot. ifeq ($(DEBUG), 1) - # You may want to disable -flto if it interferes with debugging. - # CFLAGS += -flto -flto-partition=none # You may want to enable these flags to make setting breakpoints easier. CFLAGS += -fno-ipa-sra -else - #CFLAGS += -flto -flto-partition=none endif CFLAGS += $(INC) -ggdb -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) -Werror=missing-prototypes @@ -105,7 +101,6 @@ CFLAGS += \ -mfloat-abi=hard \ -mfpu=fpv5-sp-d16 \ -DCPU_$(CHIP_VARIANT) \ - -DDEBUG \ -DIMXRT10XX \ -g3 -Wno-unused-parameter \ -ffunction-sections -fdata-sections -fstack-usage diff --git a/ports/mimxrt10xx/common-hal/analogio/AnalogOut.c b/ports/mimxrt10xx/common-hal/analogio/AnalogOut.c index de807e7e5cbb..14e1faab09f3 100644 --- a/ports/mimxrt10xx/common-hal/analogio/AnalogOut.c +++ b/ports/mimxrt10xx/common-hal/analogio/AnalogOut.c @@ -29,7 +29,7 @@ #include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) { mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_AnalogOut); diff --git a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c index 27753f47dc73..dde7b3badd58 100644 --- a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c +++ b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c @@ -36,7 +36,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #define IOMUXC_SW_MUX_CTL_PAD_MUX_MODE_ALT5 5U diff --git a/ports/mimxrt10xx/common-hal/microcontroller/__init__.c b/ports/mimxrt10xx/common-hal/microcontroller/__init__.c index 3ea454a2b34e..8de63061ad5c 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/__init__.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/__init__.c @@ -37,7 +37,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" #include "supervisor/shared/safe_mode.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #define DBL_TAP_REG SNVS->LPGPR[3] diff --git a/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c b/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c index 29f72e21e4de..97892b1095a7 100644 --- a/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +++ b/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -35,7 +35,7 @@ #include "fsl_pwm.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "periph.h" // Debug print support set to zero to enable debug printing diff --git a/ports/mimxrt10xx/common-hal/rtc/RTC.c b/ports/mimxrt10xx/common-hal/rtc/RTC.c index a58b37ae62c9..7ed65a3499c7 100644 --- a/ports/mimxrt10xx/common-hal/rtc/RTC.c +++ b/ports/mimxrt10xx/common-hal/rtc/RTC.c @@ -33,7 +33,7 @@ #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/rtc/RTC.h" #include "common-hal/rtc/RTC.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "fsl_snvs_hp.h" diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 68bc3cc41ca0..bbe102ffc8cc 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -84,14 +84,6 @@ INC += -I../../lib/mp-readline INC += -I../../lib/tinyusb/src INC += -I../../supervisor/shared/usb -ifeq ($(MCU_CHIP),nrf52833) - OPTIMIZATION_FLAGS ?= -Os -flto -flto-partition=one -else - ifeq ($(INTERNAL_FLASH_FILESYSTEM),1) - OPTIMIZATION_FLAGS ?= -Os -flto - endif -endif - #Debugging/Optimization ifeq ($(DEBUG), 1) CFLAGS += -ggdb3 diff --git a/ports/nrf/common-hal/analogio/AnalogIn.c b/ports/nrf/common-hal/analogio/AnalogIn.c index 347426af9921..b9d4b6a19944 100644 --- a/ports/nrf/common-hal/analogio/AnalogIn.c +++ b/ports/nrf/common-hal/analogio/AnalogIn.c @@ -29,7 +29,7 @@ #include "shared-bindings/analogio/AnalogIn.h" #include "shared-bindings/microcontroller/Pin.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "nrf_saadc.h" #include "nrf_gpio.h" @@ -77,7 +77,7 @@ uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { // Something else might have used the ADC in a different way, // so we completely re-initialize it. - nrf_saadc_value_t value; + nrf_saadc_value_t value = -1; const nrf_saadc_channel_config_t config = { .resistor_p = NRF_SAADC_RESISTOR_DISABLED, diff --git a/ports/nrf/common-hal/analogio/AnalogOut.c b/ports/nrf/common-hal/analogio/AnalogOut.c index 4efd56795a9e..38ff93567437 100644 --- a/ports/nrf/common-hal/analogio/AnalogOut.c +++ b/ports/nrf/common-hal/analogio/AnalogOut.c @@ -31,7 +31,7 @@ #include "py/mperrno.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) { mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_AnalogOut); diff --git a/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c b/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c index 6728bf1e4425..bc6302cb427f 100644 --- a/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c @@ -37,7 +37,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" #include "supervisor/shared/tick.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // TODO: This should be the same size as PWMOut.c:pwms[], but there's no trivial way to accomplish that STATIC audiopwmio_pwmaudioout_obj_t *active_audio[4]; diff --git a/ports/nrf/common-hal/busio/I2C.c b/ports/nrf/common-hal/busio/I2C.c index 6c645a512be6..2bd1416f5aff 100644 --- a/ports/nrf/common-hal/busio/I2C.c +++ b/ports/nrf/common-hal/busio/I2C.c @@ -32,7 +32,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "py/mperrno.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "nrfx_twim.h" #include "nrfx_spim.h" diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 5c08f500122f..04c502a4bd2e 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -33,7 +33,7 @@ #include "py/mperrno.h" #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "nrfx_uarte.h" #include "nrf_gpio.h" diff --git a/ports/nrf/common-hal/digitalio/DigitalInOut.c b/ports/nrf/common-hal/digitalio/DigitalInOut.c index b42d7dc70467..95e488f3b712 100644 --- a/ports/nrf/common-hal/digitalio/DigitalInOut.c +++ b/ports/nrf/common-hal/digitalio/DigitalInOut.c @@ -26,7 +26,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "nrf_gpio.h" diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c index fa2dfad6a49c..2fca3a3c0a60 100644 --- a/ports/nrf/common-hal/microcontroller/Processor.c +++ b/ports/nrf/common-hal/microcontroller/Processor.c @@ -31,7 +31,6 @@ #include "common-hal/alarm/__init__.h" #include "shared-bindings/microcontroller/ResetReason.h" -#include "supervisor/shared/translate.h" #include "nrfx_saadc.h" #ifdef BLUETOOTH_SD @@ -72,7 +71,7 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { } float common_hal_mcu_processor_get_voltage(void) { - nrf_saadc_value_t value; + nrf_saadc_value_t value = -1; const nrf_saadc_channel_config_t config = { .resistor_p = NRF_SAADC_RESISTOR_DISABLED, diff --git a/ports/nrf/common-hal/pulseio/PulseOut.c b/ports/nrf/common-hal/pulseio/PulseOut.c index 1c3c317a05c9..2f822b4184e5 100644 --- a/ports/nrf/common-hal/pulseio/PulseOut.c +++ b/ports/nrf/common-hal/pulseio/PulseOut.c @@ -35,7 +35,7 @@ #include "py/runtime.h" #include "shared-bindings/pulseio/PulseOut.h" #include "shared-bindings/pwmio/PWMOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // A single timer is shared amongst all PulseOut objects under the assumption that // the code is single threaded. diff --git a/ports/nrf/common-hal/pwmio/PWMOut.c b/ports/nrf/common-hal/pwmio/PWMOut.c index 619acdfab652..1bd38e7a6e7f 100644 --- a/ports/nrf/common-hal/pwmio/PWMOut.c +++ b/ports/nrf/common-hal/pwmio/PWMOut.c @@ -30,7 +30,7 @@ #include "py/runtime.h" #include "common-hal/pwmio/PWMOut.h" #include "shared-bindings/pwmio/PWMOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "nrf_gpio.h" diff --git a/ports/nrf/common-hal/rtc/RTC.c b/ports/nrf/common-hal/rtc/RTC.c index ecc687b5e9f8..29d308eccc60 100644 --- a/ports/nrf/common-hal/rtc/RTC.c +++ b/ports/nrf/common-hal/rtc/RTC.c @@ -33,7 +33,7 @@ #include "common-hal/rtc/RTC.h" #include "shared-bindings/rtc/RTC.h" #include "supervisor/port.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // This is the time in seconds since 2000 that the RTC was started. __attribute__((section(".uninitialized"))) static uint32_t rtc_offset[3]; diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index 6cbbce184682..f265ac194066 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -71,6 +71,12 @@ NRF_DEFINES += -DNRF52840_XXAA -DNRF52840 # Defined here because system_nrf52840.c doesn't #include any of our own include files. CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS +ifeq ($(INTERNAL_FLASH_FILESYSTEM),1) + OPTIMIZATION_FLAGS ?= -Os + CIRCUITPY_LTO = 1 + CIRCUITPY_LTO_PARTITION = balanced +endif + else ifeq ($(MCU_CHIP),nrf52833) MCU_SERIES = m4 @@ -87,5 +93,9 @@ SOFTDEV_VERSION ?= 7.0.1 BOOT_SETTING_ADDR = 0x7F000 NRF_DEFINES += -DNRF52833_XXAA -DNRF52833 +OPTIMIZATION_FLAGS ?= -Os + +CIRCUITPY_LTO = 1 +CIRCUITPY_LTO_PARTITION = one endif endif diff --git a/ports/raspberrypi/bindings/rp2pio/StateMachine.c b/ports/raspberrypi/bindings/rp2pio/StateMachine.c index 2c7efb09d855..1203f4abac21 100644 --- a/ports/raspberrypi/bindings/rp2pio/StateMachine.c +++ b/ports/raspberrypi/bindings/rp2pio/StateMachine.c @@ -40,7 +40,7 @@ #include "py/mperrno.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class StateMachine: diff --git a/ports/raspberrypi/common-hal/analogio/AnalogIn.c b/ports/raspberrypi/common-hal/analogio/AnalogIn.c index d164d9a18b05..b827068e1ae3 100644 --- a/ports/raspberrypi/common-hal/analogio/AnalogIn.c +++ b/ports/raspberrypi/common-hal/analogio/AnalogIn.c @@ -28,7 +28,7 @@ #include "shared-bindings/analogio/AnalogIn.h" #include "shared-bindings/microcontroller/Pin.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "src/rp2_common/hardware_adc/include/hardware/adc.h" diff --git a/ports/raspberrypi/common-hal/analogio/AnalogOut.c b/ports/raspberrypi/common-hal/analogio/AnalogOut.c index 4efd56795a9e..38ff93567437 100644 --- a/ports/raspberrypi/common-hal/analogio/AnalogOut.c +++ b/ports/raspberrypi/common-hal/analogio/AnalogOut.c @@ -31,7 +31,7 @@ #include "py/mperrno.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, const mcu_pin_obj_t *pin) { mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_AnalogOut); diff --git a/ports/raspberrypi/common-hal/audiobusio/I2SOut.c b/ports/raspberrypi/common-hal/audiobusio/I2SOut.c index 037163472d01..7db053a39def 100644 --- a/ports/raspberrypi/common-hal/audiobusio/I2SOut.c +++ b/ports/raspberrypi/common-hal/audiobusio/I2SOut.c @@ -37,7 +37,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-module/audiocore/__init__.h" #include "bindings/rp2pio/StateMachine.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" const uint16_t i2s_program[] = { // ; Load the next set of samples diff --git a/ports/raspberrypi/common-hal/audiobusio/PDMIn.c b/ports/raspberrypi/common-hal/audiobusio/PDMIn.c index 8301f9fde402..c3aadd2bbed1 100644 --- a/ports/raspberrypi/common-hal/audiobusio/PDMIn.c +++ b/ports/raspberrypi/common-hal/audiobusio/PDMIn.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "shared-bindings/audiobusio/PDMIn.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "audio_dma.h" diff --git a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c index 2f09124f4bf0..8b5c3accecd0 100644 --- a/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c @@ -39,7 +39,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "src/rp2040/hardware_structs/include/hardware/structs/dma.h" #include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" diff --git a/ports/raspberrypi/common-hal/countio/Counter.c b/ports/raspberrypi/common-hal/countio/Counter.c index 0ae773bdf3d6..44db12665645 100644 --- a/ports/raspberrypi/common-hal/countio/Counter.c +++ b/ports/raspberrypi/common-hal/countio/Counter.c @@ -2,7 +2,7 @@ #include "py/runtime.h" #include "py/mpstate.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/countio/Edge.h" #include "shared-bindings/digitalio/Pull.h" diff --git a/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c b/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c index a8a5a6b4d942..ef431d85069b 100644 --- a/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c +++ b/ports/raspberrypi/common-hal/digitalio/DigitalInOut.c @@ -32,7 +32,7 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" diff --git a/ports/raspberrypi/common-hal/microcontroller/__init__.c b/ports/raspberrypi/common-hal/microcontroller/__init__.c index ed68835e710d..3b656edc0711 100644 --- a/ports/raspberrypi/common-hal/microcontroller/__init__.c +++ b/ports/raspberrypi/common-hal/microcontroller/__init__.c @@ -38,7 +38,7 @@ #include "supervisor/filesystem.h" #include "supervisor/port.h" #include "supervisor/shared/safe_mode.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "src/rp2040/hardware_structs/include/hardware/structs/sio.h" #include "src/rp2_common/hardware_sync/include/hardware/sync.h" diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 71633fcef7e9..33e6b0d89c2c 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -32,7 +32,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/pulseio/PulseIn.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "bindings/rp2pio/StateMachine.h" #include "common-hal/pulseio/PulseIn.h" diff --git a/ports/raspberrypi/common-hal/pulseio/PulseOut.c b/ports/raspberrypi/common-hal/pulseio/PulseOut.c index 7704fdff6f2c..881e0035793b 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseOut.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseOut.c @@ -33,7 +33,7 @@ #include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/microcontroller/__init__.h" #include "common-hal/pwmio/PWMOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "src/rp2040/hardware_structs/include/hardware/structs/pwm.h" #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" #include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" diff --git a/ports/raspberrypi/common-hal/pwmio/PWMOut.c b/ports/raspberrypi/common-hal/pwmio/PWMOut.c index 958e848b9f08..e6f88f889453 100644 --- a/ports/raspberrypi/common-hal/pwmio/PWMOut.c +++ b/ports/raspberrypi/common-hal/pwmio/PWMOut.c @@ -32,7 +32,7 @@ #include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/microcontroller/Processor.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "src/rp2040/hardware_regs/include/hardware/platform_defs.h" #include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" diff --git a/ports/stm/Makefile b/ports/stm/Makefile index 5eeff2c80a48..afde51bdc041 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -88,8 +88,6 @@ else CFLAGS += -DNDEBUG OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions CFLAGS += -ggdb3 - # TODO: Test with -flto - # CFLAGS += -flto endif # to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk diff --git a/ports/stm/common-hal/analogio/AnalogIn.c b/ports/stm/common-hal/analogio/AnalogIn.c index 9ec93ccc8489..7bed932c71a7 100644 --- a/ports/stm/common-hal/analogio/AnalogIn.c +++ b/ports/stm/common-hal/analogio/AnalogIn.c @@ -27,7 +27,7 @@ #include "common-hal/analogio/AnalogIn.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/stm/common-hal/analogio/AnalogOut.c b/ports/stm/common-hal/analogio/AnalogOut.c index b2cdd501531c..3c2860c9ad80 100644 --- a/ports/stm/common-hal/analogio/AnalogOut.c +++ b/ports/stm/common-hal/analogio/AnalogOut.c @@ -33,7 +33,7 @@ #include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "common-hal/microcontroller/Pin.h" diff --git a/ports/stm/common-hal/busio/I2C.c b/ports/stm/common-hal/busio/I2C.c index 3ff437c80326..4faa5ca2ef34 100644 --- a/ports/stm/common-hal/busio/I2C.c +++ b/ports/stm/common-hal/busio/I2C.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "shared-bindings/microcontroller/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/microcontroller/Pin.h" // I2C timing specs for the H7 and F7 diff --git a/ports/stm/common-hal/busio/SPI.c b/ports/stm/common-hal/busio/SPI.c index a66a8dcb8853..7886e18a0cce 100644 --- a/ports/stm/common-hal/busio/SPI.c +++ b/ports/stm/common-hal/busio/SPI.c @@ -33,7 +33,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "supervisor/board.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/microcontroller/Pin.h" // Note that any bugs introduced in this file can cause crashes at startup diff --git a/ports/stm/common-hal/busio/UART.c b/ports/stm/common-hal/busio/UART.c index d3fdb83c88a1..171e915dd9b2 100644 --- a/ports/stm/common-hal/busio/UART.c +++ b/ports/stm/common-hal/busio/UART.c @@ -35,7 +35,7 @@ #include "py/mperrno.h" #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #define ALL_UARTS 0xFFFF diff --git a/ports/stm/common-hal/digitalio/DigitalInOut.c b/ports/stm/common-hal/digitalio/DigitalInOut.c index 39c72b73c9f4..3a0e27943bcc 100644 --- a/ports/stm/common-hal/digitalio/DigitalInOut.c +++ b/ports/stm/common-hal/digitalio/DigitalInOut.c @@ -28,7 +28,7 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/microcontroller/Pin.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // The HAL is sparse on obtaining register information, so we use the LLs here. #if (CPY_STM32H7) diff --git a/ports/stm/common-hal/microcontroller/Processor.c b/ports/stm/common-hal/microcontroller/Processor.c index 13c661a60ad7..67cf9a73e4a7 100644 --- a/ports/stm/common-hal/microcontroller/Processor.c +++ b/ports/stm/common-hal/microcontroller/Processor.c @@ -32,7 +32,7 @@ #endif #include "common-hal/microcontroller/Processor.h" #include "shared-bindings/microcontroller/ResetReason.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include STM32_HAL_H diff --git a/ports/stm/common-hal/pulseio/PulseOut.c b/ports/stm/common-hal/pulseio/PulseOut.c index fe3caa08b206..7725d8cdde47 100644 --- a/ports/stm/common-hal/pulseio/PulseOut.c +++ b/ports/stm/common-hal/pulseio/PulseOut.c @@ -33,7 +33,7 @@ #include "py/runtime.h" #include "shared-bindings/pulseio/PulseOut.h" #include "shared-bindings/pwmio/PWMOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include STM32_HAL_H #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/stm/common-hal/pwmio/PWMOut.c b/ports/stm/common-hal/pwmio/PWMOut.c index 6710f43f7dd7..45f00b901b91 100644 --- a/ports/stm/common-hal/pwmio/PWMOut.c +++ b/ports/stm/common-hal/pwmio/PWMOut.c @@ -29,7 +29,7 @@ #include "py/runtime.h" #include "common-hal/pwmio/PWMOut.h" #include "shared-bindings/pwmio/PWMOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/microcontroller/__init__.h" #include STM32_HAL_H diff --git a/ports/stm/common-hal/sdioio/SDCard.c b/ports/stm/common-hal/sdioio/SDCard.c index 40e6eddae105..8eeae2781dff 100644 --- a/ports/stm/common-hal/sdioio/SDCard.c +++ b/ports/stm/common-hal/sdioio/SDCard.c @@ -32,7 +32,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/util.h" #include "supervisor/board.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/stm/peripherals/timers.c b/ports/stm/peripherals/timers.c index f0054648fc6f..371b8f414bde 100644 --- a/ports/stm/peripherals/timers.c +++ b/ports/stm/peripherals/timers.c @@ -29,7 +29,7 @@ #include "py/gc.h" #include "py/obj.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/unix/Makefile b/ports/unix/Makefile index 9857ec5f8896..cd72b45fe689 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -233,7 +233,7 @@ SRC_C += \ supervisor/stub/filesystem.c \ supervisor/stub/safe_mode.c \ supervisor/stub/stack.c \ - supervisor/shared/translate.c \ + supervisor/shared/translate/translate.c \ $(SRC_MOD) \ $(wildcard $(VARIANT_DIR)/*.c) @@ -363,4 +363,4 @@ install: $(PROG) uninstall: -rm $(BINDIR)/$(PROG) -$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h +$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/compression.generated.h diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c index d1966c51f02a..d8b63b571e85 100644 --- a/ports/unix/modffi.c +++ b/ports/unix/modffi.c @@ -38,7 +38,7 @@ #include "py/objint.h" #include "py/gc.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" /* * modffi uses character codes to encode a value type, based on "struct" diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index 04ff325eefed..987c70b26e00 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -36,7 +36,7 @@ #include "extmod/machine_signal.h" #include "extmod/machine_pulse.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PLAT_DEV_MEM #include diff --git a/py/argcheck.c b/py/argcheck.c index 592b35940e29..cabfaeeaaee1 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -29,7 +29,7 @@ #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void mp_arg_check_num_sig(size_t n_args, size_t n_kw, uint32_t sig) { // TODO maybe take the function name as an argument so we can print nicer error messages diff --git a/py/bc.c b/py/bc.c index 33b94c4a9f1c..e1645dbff0e5 100644 --- a/py/bc.c +++ b/py/bc.c @@ -33,7 +33,7 @@ #include "py/bc0.h" #include "py/bc.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) diff --git a/py/binary.c b/py/binary.c index 06f0157567d4..439993c0f738 100644 --- a/py/binary.c +++ b/py/binary.c @@ -36,7 +36,7 @@ #include "py/objint.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // Helpers to work with binary-encoded data diff --git a/py/builtinevex.c b/py/builtinevex.c index a96a3a5344c8..46d4a1277a27 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "py/builtin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_COMPILE diff --git a/py/builtinhelp.c b/py/builtinhelp.c index 7411c57aae04..86632f6dde13 100644 --- a/py/builtinhelp.c +++ b/py/builtinhelp.c @@ -32,6 +32,8 @@ #include "py/mpconfig.h" #include "py/objmodule.h" +#include "supervisor/shared/translate/translate.h" + #if MICROPY_PY_BUILTINS_HELP const char mp_help_default_text[] = diff --git a/py/builtinimport.c b/py/builtinimport.c index d938cde7ea14..92f3150306d1 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -39,7 +39,7 @@ #include "py/builtin.h" #include "py/frozenmod.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 2514cbaa2b48..191893825593 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -67,6 +67,18 @@ else CFLAGS += -DCIRCUITPY_DEBUG=0 endif +CIRCUITPY_LTO ?= 0 +CIRCUITPY_LTO_PARTITION ?= balanced +ifeq ($(CIRCUITPY_LTO),1) +CFLAGS += -flto -flto-partition=$(CIRCUITPY_LTO_PARTITION) +endif + +# Produce an object file for translate.c instead of including it in a header. +# The header version can be optimized on non-LTO builds *if* inlining is allowed +# otherwise, it blows up the binary sizes with tons of translate copies. +CIRCUITPY_TRANSLATE_OBJECT ?= $(CIRCUITPY_LTO) +CFLAGS += -DCIRCUITPY_TRANSLATE_OBJECT=$(CIRCUITPY_TRANSLATE_OBJECT) + ### # Handle frozen modules. @@ -756,3 +768,6 @@ endif check-release-needs-clean-build: @echo "RELEASE_NEEDS_CLEAN_BUILD = $(RELEASE_NEEDS_CLEAN_BUILD)" + +# Ignore these errors +$(BUILD)/lib/libm/kf_rem_pio2.o: CFLAGS += -Wno-maybe-uninitialized diff --git a/py/compile.c b/py/compile.c index e5f341a6561c..432aeca56157 100644 --- a/py/compile.c +++ b/py/compile.c @@ -37,7 +37,7 @@ #include "py/asmbase.h" #include "py/persistentcode.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_ENABLE_COMPILER diff --git a/py/enum.c b/py/enum.c index 4728c7f11d5d..681c3b3103e5 100644 --- a/py/enum.c +++ b/py/enum.c @@ -27,6 +27,8 @@ #include "py/enum.h" #include "py/runtime.h" +#include "supervisor/shared/translate/translate.h" + mp_obj_t cp_enum_find(const mp_obj_type_t *type, int value) { const mp_obj_dict_t *dict = type->locals_dict; for (size_t i = 0; i < dict->map.used; i++) { diff --git a/py/lexer.c b/py/lexer.c index 196f9a2644ba..0d6de0d52252 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -32,7 +32,7 @@ #include "py/lexer.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_ENABLE_COMPILER diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 7222ded80545..2abbdedefdb0 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -4,7 +4,7 @@ This script works with Python 2.7, 3.3 and 3.4. For documentation about the format of compressed translated strings, see -supervisor/shared/translate.h +supervisor/shared/translate/translate.h """ from __future__ import print_function @@ -24,10 +24,6 @@ py = os.path.dirname(sys.argv[0]) top = os.path.dirname(py) -sys.path.append(os.path.join(top, "tools/huffman")) - -import huffman - # Python 2/3 compatibility: # - iterating through bytes is different # - codepoint2name lives in a different module @@ -262,326 +258,6 @@ def compute_hash(qstr, bytes_hash): return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1 -def translate(translation_file, i18ns): - with open(translation_file, "rb") as f: - table = gettext.GNUTranslations(f) - - translations = [] - for original in i18ns: - unescaped = original - for s in C_ESCAPES: - unescaped = unescaped.replace(C_ESCAPES[s], s) - translation = table.gettext(unescaped) - # Add in carriage returns to work in terminals - translation = translation.replace("\n", "\r\n") - translations.append((original, translation)) - return translations - - -class TextSplitter: - def __init__(self, words): - words = sorted(words, key=lambda x: len(x), reverse=True) - self.words = set(words) - if words: - pat = "|".join(re.escape(w) for w in words) + "|." - else: - pat = "." - self.pat = re.compile(pat, flags=re.DOTALL) - - def iter_words(self, text): - s = [] - words = self.words - for m in self.pat.finditer(text): - t = m.group(0) - if t in words: - if s: - yield (False, "".join(s)) - s = [] - yield (True, t) - else: - s.append(t) - if s: - yield (False, "".join(s)) - - def iter(self, text): - for m in self.pat.finditer(text): - yield m.group(0) - - -def iter_substrings(s, minlen, maxlen): - len_s = len(s) - maxlen = min(len_s, maxlen) - for n in range(minlen, maxlen + 1): - for begin in range(0, len_s - n + 1): - yield s[begin : begin + n] - - -def compute_huffman_coding(translations, compression_filename): - texts = [t[1] for t in translations] - words = [] - - start_unused = 0x80 - end_unused = 0xFF - max_ord = 0 - for text in texts: - for c in text: - ord_c = ord(c) - max_ord = max(ord_c, max_ord) - if 0x80 <= ord_c < 0xFF: - end_unused = min(ord_c, end_unused) - max_words = end_unused - 0x80 - - bits_per_codepoint = 16 if max_ord > 255 else 8 - values_type = "uint16_t" if max_ord > 255 else "uint8_t" - while len(words) < max_words: - # Until the dictionary is filled to capacity, use a heuristic to find - # the best "word" (2- to 11-gram) to add to it. - # - # The TextSplitter allows us to avoid considering parts of the text - # that are already covered by a previously chosen word, for example - # if "the" is in words then not only will "the" not be considered - # again, neither will "there" or "wither", since they have "the" - # as substrings. - extractor = TextSplitter(words) - counter = collections.Counter() - for t in texts: - for atom in extractor.iter(t): - counter[atom] += 1 - cb = huffman.codebook(counter.items()) - lengths = sorted(dict((v, len(cb[k])) for k, v in counter.items()).items()) - - def bit_length(s): - return sum(len(cb[c]) for c in s) - - def est_len(occ): - idx = bisect.bisect_left(lengths, (occ, 0)) - return lengths[idx][1] + 1 - - # The cost of adding a dictionary word is just its storage size - # while its savings is close to the difference between the original - # huffman bit-length of the string and the estimated bit-length - # of the dictionary word, times the number of times the word appears. - # - # The savings is not strictly accurate because including a word into - # the Huffman tree bumps up the encoding lengths of all words in the - # same subtree. In the extreme case when the new word is so frequent - # that it gets a one-bit encoding, all other words will cost an extra - # bit each. This is empirically modeled by the constant factor added to - # cost, but the specific value used isn't "proven" to be correct. - # - # Another source of inaccuracy is that compressed strings end up - # on byte boundaries, not bit boundaries, so saving 1 bit somewhere - # might not save a byte. - # - # In fact, when this change was first made, some translations (luckily, - # ones on boards not at all close to full) wasted up to 40 bytes, - # while the most constrained boards typically gained 100 bytes or - # more. - # - # The difference between the two is the estimated net savings, in bits. - def est_net_savings(s, occ): - savings = occ * (bit_length(s) - est_len(occ)) - cost = len(s) * bits_per_codepoint + 24 - return savings - cost - - counter = collections.Counter() - for t in texts: - for (found, word) in extractor.iter_words(t): - if not found: - for substr in iter_substrings(word, minlen=2, maxlen=11): - counter[substr] += 1 - - # Score the candidates we found. This is a semi-empirical formula that - # attempts to model the number of bits saved as closely as possible. - # - # It attempts to compute the codeword lengths of the original word - # to the codeword length the dictionary entry would get, times - # the number of occurrences, less the ovehead of the entries in the - # words[] array. - - scores = sorted( - ((s, -est_net_savings(s, occ)) for (s, occ) in counter.items() if occ > 1), - key=lambda x: x[1], - ) - - # Pick the one with the highest score. The score must be negative. - if not scores or scores[0][-1] >= 0: - break - - word = scores[0][0] - words.append(word) - - words.sort(key=len) - extractor = TextSplitter(words) - counter = collections.Counter() - for t in texts: - for atom in extractor.iter(t): - counter[atom] += 1 - cb = huffman.codebook(counter.items()) - - word_start = start_unused - word_end = word_start + len(words) - 1 - print("// # words", len(words)) - print("// words", words) - - values = [] - length_count = {} - renumbered = 0 - last_length = None - canonical = {} - for atom, code in sorted(cb.items(), key=lambda x: (len(x[1]), x[0])): - values.append(atom) - length = len(code) - if length not in length_count: - length_count[length] = 0 - length_count[length] += 1 - if last_length: - renumbered <<= length - last_length - canonical[atom] = "{0:0{width}b}".format(renumbered, width=length) - # print(f"atom={repr(atom)} code={code}", file=sys.stderr) - if len(atom) > 1: - o = words.index(atom) + 0x80 - s = "".join(C_ESCAPES.get(ch1, ch1) for ch1 in atom) - else: - s = C_ESCAPES.get(atom, atom) - o = ord(atom) - print("//", o, s, counter[atom], canonical[atom], renumbered) - renumbered += 1 - last_length = length - lengths = bytearray() - print("// length count", length_count) - - for i in range(1, max(length_count) + 2): - lengths.append(length_count.get(i, 0)) - print("// values", values, "lengths", len(lengths), lengths) - - print("//", values, lengths) - values = [(atom if len(atom) == 1 else chr(0x80 + words.index(atom))) for atom in values] - max_translation_encoded_length = max( - len(translation.encode("utf-8")) for (original, translation) in translations - ) - - maxlen = len(words[-1]) - minlen = len(words[0]) - wlencount = [len([None for w in words if len(w) == l]) for l in range(minlen, maxlen + 1)] - - with open(compression_filename, "w") as f: - f.write("typedef {} mchar_t;".format(values_type)) - f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths)))) - f.write( - "const mchar_t values[] = {{ {} }};\n".format(", ".join(str(ord(u)) for u in values)) - ) - f.write( - "#define compress_max_length_bits ({})\n".format( - max_translation_encoded_length.bit_length() - ) - ) - f.write( - "const mchar_t words[] = {{ {} }};\n".format( - ", ".join(str(ord(c)) for w in words for c in w) - ) - ) - f.write( - "const uint8_t wlencount[] = {{ {} }};\n".format(", ".join(str(p) for p in wlencount)) - ) - f.write("#define word_start {}\n".format(word_start)) - f.write("#define word_end {}\n".format(word_end)) - f.write("#define minlen {}\n".format(minlen)) - f.write("#define maxlen {}\n".format(maxlen)) - - return (values, lengths, words, canonical, extractor) - - -def decompress(encoding_table, encoded, encoded_length_bits): - (values, lengths, words, _, _) = encoding_table - dec = [] - this_byte = 0 - this_bit = 7 - b = encoded[this_byte] - bits = 0 - for i in range(encoded_length_bits): - bits <<= 1 - if 0x80 & b: - bits |= 1 - - b <<= 1 - if this_bit == 0: - this_bit = 7 - this_byte += 1 - if this_byte < len(encoded): - b = encoded[this_byte] - else: - this_bit -= 1 - length = bits - - i = 0 - while i < length: - bits = 0 - bit_length = 0 - max_code = lengths[0] - searched_length = lengths[0] - while True: - bits <<= 1 - if 0x80 & b: - bits |= 1 - - b <<= 1 - bit_length += 1 - if this_bit == 0: - this_bit = 7 - this_byte += 1 - if this_byte < len(encoded): - b = encoded[this_byte] - else: - this_bit -= 1 - if max_code > 0 and bits < max_code: - # print('{0:0{width}b}'.format(bits, width=bit_length)) - break - max_code = (max_code << 1) + lengths[bit_length] - searched_length += lengths[bit_length] - - v = values[searched_length + bits - max_code] - if v >= chr(0x80) and v < chr(0x80 + len(words)): - v = words[ord(v) - 0x80] - i += len(v.encode("utf-8")) - dec.append(v) - return "".join(dec) - - -def compress(encoding_table, decompressed, encoded_length_bits, len_translation_encoded): - if not isinstance(decompressed, str): - raise TypeError() - (_, _, _, canonical, extractor) = encoding_table - - enc = bytearray(len(decompressed) * 3) - current_bit = 7 - current_byte = 0 - - bits = encoded_length_bits + 1 - for i in range(bits - 1, 0, -1): - if len_translation_encoded & (1 << (i - 1)): - enc[current_byte] |= 1 << current_bit - if current_bit == 0: - current_bit = 7 - current_byte += 1 - else: - current_bit -= 1 - - for atom in extractor.iter(decompressed): - for b in canonical[atom]: - if b == "1": - enc[current_byte] |= 1 << current_bit - if current_bit == 0: - current_bit = 7 - current_byte += 1 - else: - current_bit -= 1 - - if current_bit != 7: - current_byte += 1 - return enc[:current_byte] - - def qstr_escape(qst): def esc_char(m): c = ord(m.group(0)) @@ -695,7 +371,7 @@ def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr): return '%d, %d, "%s"' % (qhash, qlen, qdata) -def print_qstr_data(encoding_table, qcfgs, qstrs, i18ns): +def print_qstr_data(qcfgs, qstrs, i18ns): # get config variables cfg_bytes_len = int(qcfgs["BYTES_IN_LEN"]) cfg_bytes_hash = int(qcfgs["BYTES_IN_HASH"]) @@ -708,7 +384,6 @@ def print_qstr_data(encoding_table, qcfgs, qstrs, i18ns): print('QDEF(MP_QSTRnull, 0, 0, "")') total_qstr_size = 0 - total_qstr_compressed_size = 0 # go through each qstr and print it out for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]): qbytes = make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr) @@ -716,34 +391,14 @@ def print_qstr_data(encoding_table, qcfgs, qstrs, i18ns): total_qstr_size += len(qstr) - total_text_size = 0 - total_text_compressed_size = 0 - max_translation_encoded_length = max( - len(translation.encode("utf-8")) for original, translation in i18ns + print( + "// Enumerate translated texts but don't actually include translations. Instead, the linker will link them in." ) - encoded_length_bits = max_translation_encoded_length.bit_length() - for original, translation in i18ns: - translation_encoded = translation.encode("utf-8") - compressed = compress( - encoding_table, translation, encoded_length_bits, len(translation_encoded) - ) - total_text_compressed_size += len(compressed) - decompressed = decompress(encoding_table, compressed, encoded_length_bits) - assert decompressed == translation - for c in C_ESCAPES: - decompressed = decompressed.replace(c, C_ESCAPES[c]) - print( - 'TRANSLATION("{}", {}) // {}'.format( - original, ", ".join(["{:d}".format(x) for x in compressed]), decompressed - ) - ) - total_text_size += len(translation.encode("utf-8")) + for i, original in enumerate(i18ns): + print('TRANSLATION("{}", {})'.format(original, i)) print() print("// {} bytes worth of qstr".format(total_qstr_size)) - print("// {} bytes worth of translations".format(total_text_size)) - print("// {} bytes worth of translations compressed".format(total_text_compressed_size)) - print("// {} bytes saved".format(total_text_size - total_text_compressed_size)) def print_qstr_enums(qstrs): @@ -769,19 +424,18 @@ def print_qstr_enums(qstrs): "infiles", metavar="N", type=str, nargs="+", help="an integer for the accumulator" ) parser.add_argument( - "--translation", default=None, type=str, help="translations for i18n() items" - ) - parser.add_argument( - "--compression_filename", default=None, type=str, help="header for compression info" + "--output_type", + default="enums", + type=str, + help="output definitions", + choices=("enums", "data"), ) args = parser.parse_args() qcfgs, qstrs, i18ns = parse_input_headers(args.infiles) - if args.translation: + if args.output_type == "data": i18ns = sorted(i18ns) - translations = translate(args.translation, i18ns) - encoding_table = compute_huffman_coding(translations, args.compression_filename) - print_qstr_data(encoding_table, qcfgs, qstrs, translations) + print_qstr_data(qcfgs, qstrs, i18ns) else: print_qstr_enums(qstrs) diff --git a/py/maketranslationdata.py b/py/maketranslationdata.py new file mode 100644 index 000000000000..c0ae85f4e026 --- /dev/null +++ b/py/maketranslationdata.py @@ -0,0 +1,526 @@ +""" +Process raw qstr file and output qstr data with length, hash and data bytes. + +This script works with Python 2.7, 3.3 and 3.4. + +For documentation about the format of compressed translated strings, see +supervisor/shared/translate/translate.h +""" + +from __future__ import print_function + +import bisect +import re +import sys + +import collections +import gettext +import os.path + +if hasattr(sys.stdout, "reconfigure"): + sys.stdout.reconfigure(encoding="utf-8") + sys.stderr.reconfigure(errors="backslashreplace") + +py = os.path.dirname(sys.argv[0]) +top = os.path.dirname(py) + +sys.path.append(os.path.join(top, "tools/huffman")) + +import huffman + +# Python 2/3 compatibility: +# - iterating through bytes is different +# - codepoint2name lives in a different module +import platform + +if platform.python_version_tuple()[0] == "2": + bytes_cons = lambda val, enc=None: bytearray(val) + from htmlentitydefs import codepoint2name +elif platform.python_version_tuple()[0] == "3": + bytes_cons = bytes + from html.entities import codepoint2name +# end compatibility code + +codepoint2name[ord("-")] = "hyphen" + +# add some custom names to map characters that aren't in HTML +codepoint2name[ord(" ")] = "space" +codepoint2name[ord("'")] = "squot" +codepoint2name[ord(",")] = "comma" +codepoint2name[ord(".")] = "dot" +codepoint2name[ord(":")] = "colon" +codepoint2name[ord(";")] = "semicolon" +codepoint2name[ord("/")] = "slash" +codepoint2name[ord("%")] = "percent" +codepoint2name[ord("#")] = "hash" +codepoint2name[ord("(")] = "paren_open" +codepoint2name[ord(")")] = "paren_close" +codepoint2name[ord("[")] = "bracket_open" +codepoint2name[ord("]")] = "bracket_close" +codepoint2name[ord("{")] = "brace_open" +codepoint2name[ord("}")] = "brace_close" +codepoint2name[ord("*")] = "star" +codepoint2name[ord("!")] = "bang" +codepoint2name[ord("\\")] = "backslash" +codepoint2name[ord("+")] = "plus" +codepoint2name[ord("$")] = "dollar" +codepoint2name[ord("=")] = "equals" +codepoint2name[ord("?")] = "question" +codepoint2name[ord("@")] = "at_sign" +codepoint2name[ord("^")] = "caret" +codepoint2name[ord("|")] = "pipe" +codepoint2name[ord("~")] = "tilde" + +C_ESCAPES = { + "\a": "\\a", + "\b": "\\b", + "\f": "\\f", + "\n": "\\n", + "\r": "\\r", + "\t": "\\t", + "\v": "\\v", + "'": "\\'", + '"': '\\"', +} + +# this must match the equivalent function in qstr.c +def compute_hash(qstr, bytes_hash): + hash = 5381 + for b in qstr: + hash = (hash * 33) ^ b + # Make sure that valid hash is never zero, zero means "hash not computed" + return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1 + + +def translate(translation_file, i18ns): + with open(translation_file, "rb") as f: + table = gettext.GNUTranslations(f) + + translations = [] + for original in i18ns: + unescaped = original + for s in C_ESCAPES: + unescaped = unescaped.replace(C_ESCAPES[s], s) + translation = table.gettext(unescaped) + # Add in carriage returns to work in terminals + translation = translation.replace("\n", "\r\n") + translations.append((original, translation)) + return translations + + +class TextSplitter: + def __init__(self, words): + words = sorted(words, key=lambda x: len(x), reverse=True) + self.words = set(words) + if words: + pat = "|".join(re.escape(w) for w in words) + "|." + else: + pat = "." + self.pat = re.compile(pat, flags=re.DOTALL) + + def iter_words(self, text): + s = [] + words = self.words + for m in self.pat.finditer(text): + t = m.group(0) + if t in words: + if s: + yield (False, "".join(s)) + s = [] + yield (True, t) + else: + s.append(t) + if s: + yield (False, "".join(s)) + + def iter(self, text): + for m in self.pat.finditer(text): + yield m.group(0) + + +def iter_substrings(s, minlen, maxlen): + len_s = len(s) + maxlen = min(len_s, maxlen) + for n in range(minlen, maxlen + 1): + for begin in range(0, len_s - n + 1): + yield s[begin : begin + n] + + +def compute_huffman_coding(translations, f): + texts = [t[1] for t in translations] + words = [] + + start_unused = 0x80 + end_unused = 0xFF + max_ord = 0 + for text in texts: + for c in text: + ord_c = ord(c) + max_ord = max(ord_c, max_ord) + if 0x80 <= ord_c < 0xFF: + end_unused = min(ord_c, end_unused) + max_words = end_unused - 0x80 + + bits_per_codepoint = 16 if max_ord > 255 else 8 + values_type = "uint16_t" if max_ord > 255 else "uint8_t" + while len(words) < max_words: + # Until the dictionary is filled to capacity, use a heuristic to find + # the best "word" (2- to 11-gram) to add to it. + # + # The TextSplitter allows us to avoid considering parts of the text + # that are already covered by a previously chosen word, for example + # if "the" is in words then not only will "the" not be considered + # again, neither will "there" or "wither", since they have "the" + # as substrings. + extractor = TextSplitter(words) + counter = collections.Counter() + for t in texts: + for atom in extractor.iter(t): + counter[atom] += 1 + cb = huffman.codebook(counter.items()) + lengths = sorted(dict((v, len(cb[k])) for k, v in counter.items()).items()) + + def bit_length(s): + return sum(len(cb[c]) for c in s) + + def est_len(occ): + idx = bisect.bisect_left(lengths, (occ, 0)) + return lengths[idx][1] + 1 + + # The cost of adding a dictionary word is just its storage size + # while its savings is close to the difference between the original + # huffman bit-length of the string and the estimated bit-length + # of the dictionary word, times the number of times the word appears. + # + # The savings is not strictly accurate because including a word into + # the Huffman tree bumps up the encoding lengths of all words in the + # same subtree. In the extreme case when the new word is so frequent + # that it gets a one-bit encoding, all other words will cost an extra + # bit each. This is empirically modeled by the constant factor added to + # cost, but the specific value used isn't "proven" to be correct. + # + # Another source of inaccuracy is that compressed strings end up + # on byte boundaries, not bit boundaries, so saving 1 bit somewhere + # might not save a byte. + # + # In fact, when this change was first made, some translations (luckily, + # ones on boards not at all close to full) wasted up to 40 bytes, + # while the most constrained boards typically gained 100 bytes or + # more. + # + # The difference between the two is the estimated net savings, in bits. + def est_net_savings(s, occ): + savings = occ * (bit_length(s) - est_len(occ)) + cost = len(s) * bits_per_codepoint + 24 + return savings - cost + + counter = collections.Counter() + for t in texts: + for (found, word) in extractor.iter_words(t): + if not found: + for substr in iter_substrings(word, minlen=2, maxlen=11): + counter[substr] += 1 + + # Score the candidates we found. This is a semi-empirical formula that + # attempts to model the number of bits saved as closely as possible. + # + # It attempts to compute the codeword lengths of the original word + # to the codeword length the dictionary entry would get, times + # the number of occurrences, less the ovehead of the entries in the + # words[] array. + + scores = sorted( + ((s, -est_net_savings(s, occ)) for (s, occ) in counter.items() if occ > 1), + key=lambda x: x[1], + ) + + # Pick the one with the highest score. The score must be negative. + if not scores or scores[0][-1] >= 0: + break + + word = scores[0][0] + words.append(word) + + words.sort(key=len) + extractor = TextSplitter(words) + counter = collections.Counter() + for t in texts: + for atom in extractor.iter(t): + counter[atom] += 1 + cb = huffman.codebook(counter.items()) + + word_start = start_unused + word_end = word_start + len(words) - 1 + f.write(f"// # words {len(words)}\n") + f.write(f"// words {words}\n") + + values = [] + length_count = {} + renumbered = 0 + last_length = None + canonical = {} + for atom, code in sorted(cb.items(), key=lambda x: (len(x[1]), x[0])): + values.append(atom) + length = len(code) + if length not in length_count: + length_count[length] = 0 + length_count[length] += 1 + if last_length: + renumbered <<= length - last_length + canonical[atom] = "{0:0{width}b}".format(renumbered, width=length) + # print(f"atom={repr(atom)} code={code}", file=sys.stderr) + if len(atom) > 1: + o = words.index(atom) + 0x80 + s = "".join(C_ESCAPES.get(ch1, ch1) for ch1 in atom) + else: + s = C_ESCAPES.get(atom, atom) + o = ord(atom) + f.write(f"// {o} {s} {counter[atom]} {canonical[atom]} {renumbered}\n") + renumbered += 1 + last_length = length + lengths = bytearray() + f.write(f"// length count {length_count}\n") + + for i in range(1, max(length_count) + 2): + lengths.append(length_count.get(i, 0)) + f.write(f"// values {values} lengths {len(lengths)} {lengths}\n") + + f.write(f"// {values} {lengths}\n") + values = [(atom if len(atom) == 1 else chr(0x80 + words.index(atom))) for atom in values] + max_translation_encoded_length = max( + len(translation.encode("utf-8")) for (original, translation) in translations + ) + + maxlen = len(words[-1]) + minlen = len(words[0]) + wlencount = [len([None for w in words if len(w) == l]) for l in range(minlen, maxlen + 1)] + + f.write("typedef {} mchar_t;\n".format(values_type)) + f.write("const uint8_t lengths[] = {{ {} }};\n".format(", ".join(map(str, lengths)))) + f.write("const mchar_t values[] = {{ {} }};\n".format(", ".join(str(ord(u)) for u in values))) + f.write( + "#define compress_max_length_bits ({})\n".format( + max_translation_encoded_length.bit_length() + ) + ) + f.write( + "const mchar_t words[] = {{ {} }};\n".format( + ", ".join(str(ord(c)) for w in words for c in w) + ) + ) + f.write("const uint8_t wlencount[] = {{ {} }};\n".format(", ".join(str(p) for p in wlencount))) + f.write("#define word_start {}\n".format(word_start)) + f.write("#define word_end {}\n".format(word_end)) + f.write("#define minlen {}\n".format(minlen)) + f.write("#define maxlen {}\n".format(maxlen)) + + return (values, lengths, words, canonical, extractor) + + +def decompress(encoding_table, encoded, encoded_length_bits): + (values, lengths, words, _, _) = encoding_table + dec = [] + this_byte = 0 + this_bit = 7 + b = encoded[this_byte] + bits = 0 + for i in range(encoded_length_bits): + bits <<= 1 + if 0x80 & b: + bits |= 1 + + b <<= 1 + if this_bit == 0: + this_bit = 7 + this_byte += 1 + if this_byte < len(encoded): + b = encoded[this_byte] + else: + this_bit -= 1 + length = bits + + i = 0 + while i < length: + bits = 0 + bit_length = 0 + max_code = lengths[0] + searched_length = lengths[0] + while True: + bits <<= 1 + if 0x80 & b: + bits |= 1 + + b <<= 1 + bit_length += 1 + if this_bit == 0: + this_bit = 7 + this_byte += 1 + if this_byte < len(encoded): + b = encoded[this_byte] + else: + this_bit -= 1 + if max_code > 0 and bits < max_code: + # print('{0:0{width}b}'.format(bits, width=bit_length)) + break + max_code = (max_code << 1) + lengths[bit_length] + searched_length += lengths[bit_length] + + v = values[searched_length + bits - max_code] + if v >= chr(0x80) and v < chr(0x80 + len(words)): + v = words[ord(v) - 0x80] + i += len(v.encode("utf-8")) + dec.append(v) + return "".join(dec) + + +def compress(encoding_table, decompressed, encoded_length_bits, len_translation_encoded): + if not isinstance(decompressed, str): + raise TypeError() + (_, _, _, canonical, extractor) = encoding_table + + enc = bytearray(len(decompressed) * 3) + current_bit = 7 + current_byte = 0 + + bits = encoded_length_bits + 1 + for i in range(bits - 1, 0, -1): + if len_translation_encoded & (1 << (i - 1)): + enc[current_byte] |= 1 << current_bit + if current_bit == 0: + current_bit = 7 + current_byte += 1 + else: + current_bit -= 1 + + for atom in extractor.iter(decompressed): + for b in canonical[atom]: + if b == "1": + enc[current_byte] |= 1 << current_bit + if current_bit == 0: + current_bit = 7 + current_byte += 1 + else: + current_bit -= 1 + + if current_bit != 7: + current_byte += 1 + return enc[:current_byte] + + +def qstr_escape(qst): + def esc_char(m): + c = ord(m.group(0)) + try: + name = codepoint2name[c] + except KeyError: + name = "0x%02x" % c + return "_" + name + "_" + + return re.sub(r"[^A-Za-z0-9_]", esc_char, qst) + + +def parse_input_headers(infiles): + i18ns = set() + + # read the qstrs in from the input files + for infile in infiles: + with open(infile, "rt") as f: + for line in f: + line = line.strip() + + match = re.match(r'^TRANSLATE\("(.*)"\)$', line) + if match: + i18ns.add(match.group(1)) + continue + + return i18ns + + +def escape_bytes(qstr): + if all(32 <= ord(c) <= 126 and c != "\\" and c != '"' for c in qstr): + # qstr is all printable ASCII so render it as-is (for easier debugging) + return qstr + else: + # qstr contains non-printable codes so render entire thing as hex pairs + qbytes = bytes_cons(qstr, "utf8") + return "".join(("\\x%02x" % b) for b in qbytes) + + +def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr): + qbytes = bytes_cons(qstr, "utf8") + qlen = len(qbytes) + qhash = compute_hash(qbytes, cfg_bytes_hash) + if qlen >= (1 << (8 * cfg_bytes_len)): + print("qstr is too long:", qstr) + assert False + qdata = escape_bytes(qstr) + return '%d, %d, "%s"' % (qhash, qlen, qdata) + + +def output_translation_data(encoding_table, i18ns, out): + # print out the starter of the generated C file + out.write("// This file was automatically generated by maketranslatedata.py\n") + out.write('#include "supervisor/shared/translate/compressed_string.h"\n') + out.write("\n") + + total_text_size = 0 + total_text_compressed_size = 0 + max_translation_encoded_length = max( + len(translation.encode("utf-8")) for original, translation in i18ns + ) + encoded_length_bits = max_translation_encoded_length.bit_length() + for i, translation in enumerate(i18ns): + original, translation = translation + translation_encoded = translation.encode("utf-8") + compressed = compress( + encoding_table, translation, encoded_length_bits, len(translation_encoded) + ) + total_text_compressed_size += len(compressed) + decompressed = decompress(encoding_table, compressed, encoded_length_bits) + assert decompressed == translation + for c in C_ESCAPES: + decompressed = decompressed.replace(c, C_ESCAPES[c]) + formatted = ["{:d}".format(x) for x in compressed] + out.write( + "const compressed_string_t translation{} = {{ .data = {}, .tail = {{ {} }} }}; // {}\n".format( + i, formatted[0], ", ".join(formatted[1:]), original, decompressed + ) + ) + total_text_size += len(translation.encode("utf-8")) + + out.write("\n") + out.write("// {} bytes worth of translations\n".format(total_text_size)) + out.write("// {} bytes worth of translations compressed\n".format(total_text_compressed_size)) + out.write("// {} bytes saved\n".format(total_text_size - total_text_compressed_size)) + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser( + description="Process QSTR definitions into headers for compilation" + ) + parser.add_argument( + "infiles", metavar="N", type=str, nargs="+", help="an integer for the accumulator" + ) + parser.add_argument( + "--translation", default=None, type=str, help="translations for i18n() items" + ) + parser.add_argument( + "--compression_filename", + type=argparse.FileType("w", encoding="UTF-8"), + help="header for compression info", + ) + parser.add_argument( + "--translation_filename", + type=argparse.FileType("w", encoding="UTF-8"), + help="c file for translation data", + ) + + args = parser.parse_args() + + i18ns = parse_input_headers(args.infiles) + i18ns = sorted(i18ns) + translations = translate(args.translation, i18ns) + encoding_table = compute_huffman_coding(translations, args.compression_filename) + output_translation_data(encoding_table, translations, args.translation_filename) diff --git a/py/mkrules.mk b/py/mkrules.mk index 6bef64fd82e1..ef0f66117d21 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -58,11 +58,11 @@ $(Q)$(CXX) $(CXXFLAGS) -c -MD -o $@ $< endef vpath %.c . $(TOP) $(USER_C_MODULES) $(DEVICES_MODULES) -$(BUILD)/%.o: %.c +$(BUILD)/%.o: %.c | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/qstrdefs.enum.h $(call compile_c) vpath %.cpp . $(TOP) $(USER_C_MODULES) -$(BUILD)/%.o: %.cpp +$(BUILD)/%.o: %.cpp | $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/qstrdefs.enum.h $(call compile_cxx) QSTR_GEN_EXTRA_CFLAGS += -DNO_QSTR -x c @@ -89,7 +89,7 @@ $(BUILD)/%.pp: %.c # the right .o's to get recompiled if the generated.h file changes. Adding # an order-only dependency to all of the .o's will cause the generated .h # to get built before we try to compile any of them. -$(OBJ): | $(HEADER_BUILD)/qstrdefs.enum.h $(HEADER_BUILD)/mpversion.h +$(OBJ): | $(HEADER_BUILD)/mpversion.h # The logic for qstr regeneration (applied by makeqstrdefs.py) is: # - if anything in QSTR_GLOBAL_DEPENDENCIES is newer, then process all source files ($^) diff --git a/py/modbuiltins.c b/py/modbuiltins.c index ebdbd52dfff4..91712812bc42 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -35,7 +35,7 @@ #include "py/builtin.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_FLOAT #include diff --git a/py/modmath.c b/py/modmath.c index 103310db5e7e..167d46d02be2 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -27,7 +27,7 @@ #include "py/builtin.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH diff --git a/py/modmicropython.c b/py/modmicropython.c index 0465a4eef89c..42c84e529221 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -32,7 +32,7 @@ #include "py/gc.h" #include "py/mphal.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // Various builtins specific to MicroPython runtime, // living in micropython module diff --git a/py/modstruct.c b/py/modstruct.c index c0b0fb78904b..17dfc548ab37 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -33,7 +33,7 @@ #include "py/objtuple.h" #include "py/binary.h" #include "py/parsenum.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_STRUCT diff --git a/py/modthread.c b/py/modthread.c index 333d750a36f8..a3960cddcb1e 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -30,7 +30,7 @@ #include "py/runtime.h" #include "py/stackctrl.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_THREAD diff --git a/py/moduerrno.c b/py/moduerrno.c index 743be0b85d0a..0ac0503ccc2c 100644 --- a/py/moduerrno.c +++ b/py/moduerrno.c @@ -30,7 +30,7 @@ #include "py/obj.h" #include "py/mperrno.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // This list can be defined per port in mpconfigport.h to tailor it to a // specific port's needs. If it's not defined then we provide a default. diff --git a/py/obj.c b/py/obj.c index cc7f9006e80d..da609aa8ce53 100644 --- a/py/obj.c +++ b/py/obj.c @@ -41,7 +41,7 @@ #include "supervisor/linker.h" #include "supervisor/shared/stack.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" const mp_obj_type_t *MICROPY_WRAP_MP_OBJ_GET_TYPE(mp_obj_get_type)(mp_const_obj_t o_in) { #if MICROPY_OBJ_IMMEDIATE_OBJS && MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A diff --git a/py/obj.h b/py/obj.h index 5f8f71ba0bba..8f38a4c7c02f 100644 --- a/py/obj.h +++ b/py/obj.h @@ -34,7 +34,7 @@ #include "py/mpprint.h" #include "py/runtime0.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/compressed_string.h" // This is the definition of the opaque MicroPython object type. // All concrete objects have an encoding within this type and the diff --git a/py/objarray.c b/py/objarray.c index b71687fb35d8..a66a73a5ac5f 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -34,7 +34,7 @@ #include "py/objstr.h" #include "py/objarray.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_BUILTINS_MEMORYVIEW diff --git a/py/objcomplex.c b/py/objcomplex.c index b37b059d59f5..f205249bb4fc 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -31,7 +31,7 @@ #include "py/parsenum.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_COMPLEX diff --git a/py/objdeque.c b/py/objdeque.c index 2d29d71e3b07..59c4c709fcc2 100644 --- a/py/objdeque.c +++ b/py/objdeque.c @@ -28,7 +28,7 @@ #include #include "py/mpconfig.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_COLLECTIONS_DEQUE diff --git a/py/objdict.c b/py/objdict.c index 5f233741fa75..306205d12f8a 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -34,7 +34,7 @@ #include "py/objstr.h" #include "supervisor/linker.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" const mp_obj_dict_t mp_const_empty_dict_obj = { .base = { .type = &mp_type_dict }, diff --git a/py/objexcept.c b/py/objexcept.c index fc0787631f08..230f9d11baaf 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -39,7 +39,7 @@ #include "py/gc.h" #include "py/mperrno.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // Number of items per traceback entry (file, line, block) #define TRACEBACK_ENTRY_LEN (3) diff --git a/py/objfloat.c b/py/objfloat.c index 6d1d10188cb0..f8261df93360 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -32,7 +32,7 @@ #include "py/parsenum.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_FLOAT diff --git a/py/objgenerator.c b/py/objgenerator.c index c63ea6b816ac..b18101cfa16b 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -35,7 +35,7 @@ #include "py/objfun.h" #include "py/stackctrl.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // Instance of GeneratorExit exception - needed by generator.close() const mp_obj_exception_t mp_const_GeneratorExit_obj = {{&mp_type_GeneratorExit}, (mp_obj_tuple_t *)&mp_const_empty_tuple_obj, (mp_obj_traceback_t *)&mp_const_empty_traceback_obj}; diff --git a/py/objint.c b/py/objint.c index 50bcbf56f86c..98178e7ffac2 100644 --- a/py/objint.c +++ b/py/objint.c @@ -35,7 +35,7 @@ #include "py/runtime.h" #include "py/binary.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_FLOAT #include diff --git a/py/objint_longlong.c b/py/objint_longlong.c index 368c74ec1d6c..67ec844f4799 100644 --- a/py/objint_longlong.c +++ b/py/objint_longlong.c @@ -32,7 +32,7 @@ #include "py/objint.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_FLOAT #include diff --git a/py/objint_mpz.c b/py/objint_mpz.c index b804ce28afae..fd74803fe7fa 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -33,7 +33,7 @@ #include "py/objint.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_FLOAT #include diff --git a/py/objlist.c b/py/objlist.c index 9d1949b7dc2e..434bca7d0a13 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "py/stackctrl.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" STATIC mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf); STATIC mp_obj_list_t *list_new(size_t n); diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index c970d1afba77..60a0a31847ae 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -33,7 +33,7 @@ #include "py/objnamedtuple.h" #include "py/objtype.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_COLLECTIONS diff --git a/py/objobject.c b/py/objobject.c index d9c75faff9e8..b32e5fac0d97 100644 --- a/py/objobject.c +++ b/py/objobject.c @@ -29,7 +29,7 @@ #include "py/objtype.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" typedef struct _mp_obj_object_t { mp_obj_base_t base; diff --git a/py/objrange.c b/py/objrange.c index b23ab23bd74e..b0c74815dcec 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -28,7 +28,7 @@ #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" /******************************************************************************/ /* range iterator */ diff --git a/py/objset.c b/py/objset.c index d7dda6ba59f2..237e4c24710d 100644 --- a/py/objset.c +++ b/py/objset.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "py/builtin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_SET diff --git a/py/objslice.c b/py/objslice.c index 142f62fdac8c..3172f798c008 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -30,7 +30,7 @@ #include "py/obj.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" /******************************************************************************/ /* slice object */ diff --git a/py/objstr.c b/py/objstr.c index 3d45383bb380..df735a45cd18 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -35,7 +35,7 @@ #include "py/runtime.h" #include "py/stackctrl.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_STR_OP_MODULO STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); diff --git a/py/objstringio.c b/py/objstringio.c index 336a041baf55..c6d22d6c89ee 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -33,7 +33,7 @@ #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_IO diff --git a/py/objstrunicode.c b/py/objstrunicode.c index eb79d5499150..0f26da62cf74 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -32,7 +32,7 @@ #include "py/objlist.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_STR_UNICODE diff --git a/py/objtuple.c b/py/objtuple.c index 90b0773bb4a5..87d16905df81 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "py/objtype.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" /******************************************************************************/ diff --git a/py/objtype.c b/py/objtype.c index 62ea1ed602d5..071065041f01 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -35,7 +35,7 @@ #include "py/runtime.h" #include "supervisor/shared/stack.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) diff --git a/py/parse.c b/py/parse.c index dee662b4ec33..b3be279c5bef 100644 --- a/py/parse.c +++ b/py/parse.c @@ -39,7 +39,7 @@ #include "py/objstr.h" #include "py/builtin.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_ENABLE_COMPILER diff --git a/py/parsenum.c b/py/parsenum.c index bd414882047f..adf2a4d84d60 100644 --- a/py/parsenum.c +++ b/py/parsenum.c @@ -32,7 +32,7 @@ #include "py/parsenum.h" #include "py/smallint.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_FLOAT #include diff --git a/py/persistentcode.c b/py/persistentcode.c index e604569fe277..787f724bf6bd 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -36,7 +36,7 @@ #include "py/objstr.h" #include "py/mpthread.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_PERSISTENT_CODE_SAVE diff --git a/py/proto.c b/py/proto.c index 9f110b9f9a62..d70a9d2aac26 100644 --- a/py/proto.c +++ b/py/proto.c @@ -28,6 +28,8 @@ #include "py/proto.h" #include "py/runtime.h" +#include "supervisor/shared/translate/translate.h" + #ifndef MICROPY_UNSAFE_PROTO const void *mp_proto_get(uint16_t name, mp_const_obj_t obj) { const mp_obj_type_t *type = mp_obj_get_type(obj); diff --git a/py/py.mk b/py/py.mk index f1864e58b375..6827fbe7867e 100644 --- a/py/py.mk +++ b/py/py.mk @@ -252,18 +252,23 @@ $(HEADER_BUILD)/qstrdefs.preprocessed.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEF # qstr data $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h $(STEPECHO) "GEN $@" - $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ + $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --output_type=enums $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ # Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get # created before we run the script to generate the .h # Note: we need to protect the qstr names from the preprocessor, so we wrap # the lines in "" and then unwrap after the preprocessor is finished. -$(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h +$(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h $(STEPECHO) "GEN $@" - $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ + $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --output_type=data $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ -$(PY_BUILD)/qstr.o: $(HEADER_BUILD)/qstrdefs.generated.h +$(PY_BUILD)/translations-$(TRANSLATION).c $(HEADER_BUILD)/compression.generated.h: $(PY_SRC)/maketranslationdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h + $(STEPECHO) "GEN $@" + $(Q)$(PYTHON) $(PY_SRC)/maketranslationdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo --translation_filename $(PY_BUILD)/translations-$(TRANSLATION).c $(HEADER_BUILD)/qstrdefs.preprocessed.h +PY_CORE_O += $(PY_BUILD)/translations-$(TRANSLATION).o + +$(PY_BUILD)/qstr.o: $(HEADER_BUILD)/qstrdefs.generated.h # build a list of registered modules for py/objmodule.c. $(HEADER_BUILD)/moduledefs.h: $(SRC_QSTR) $(QSTR_GLOBAL_DEPENDENCIES) | $(HEADER_BUILD)/mpversion.h diff --git a/py/qstr.c b/py/qstr.c index 41176ec5ab11..083e12d6f01e 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -35,6 +35,7 @@ #include "py/runtime.h" #include "supervisor/linker.h" +#include "supervisor/shared/translate/translate.h" // NOTE: we are using linear arrays to store and search for qstr's (unique strings, interned strings) // ultimately we will replace this with a static hash table of some kind diff --git a/py/runtime.c b/py/runtime.c index f2ad8728a54d..7fcad7366a7e 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -45,7 +45,7 @@ #include "py/stackctrl.h" #include "py/gc.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_PRINT (1) diff --git a/py/runtime.h b/py/runtime.h index dccdc2feedad..a78969780bb8 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -33,6 +33,8 @@ #include "supervisor/linker.h" +#include "supervisor/shared/translate/translate.h" + typedef enum { MP_VM_RETURN_NORMAL, MP_VM_RETURN_YIELD, diff --git a/py/sequence.c b/py/sequence.c index ee400ccd8dca..7befc857637a 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -28,7 +28,7 @@ #include #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // Helpers for sequence types diff --git a/py/stream.c b/py/stream.c index b12d693c629a..27609043fc27 100644 --- a/py/stream.c +++ b/py/stream.c @@ -31,7 +31,7 @@ #include "py/objstr.h" #include "py/stream.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // This file defines generic Python stream read/write methods which // dispatch to the underlying stream interface of an object. diff --git a/py/vm.c b/py/vm.c index 8cb01d3552d6..12a0f2d44577 100644 --- a/py/vm.c +++ b/py/vm.c @@ -37,6 +37,7 @@ #include "py/profile.h" #include "supervisor/linker.h" +#include "supervisor/shared/translate/translate.h" // *FORMAT-OFF* diff --git a/runtime.py b/runtime.py new file mode 100644 index 000000000000..28bf98962edc --- /dev/null +++ b/runtime.py @@ -0,0 +1,10 @@ +import pathlib +paths = pathlib.Path(".").glob("**/*.c") +translate_h = "#include \"supervisor/shared/translate/translate.h\"" +for p in paths: + if "esp-idf" in p: + continue + lines = p.read_text().split("\n") + if "#include \"py/runtime.h\"" in lines and translate_h in lines: + lines.remove(translate_h) + p.write_text("\n".join(lines)) diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 4015d31161dc..1a4356c71941 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -32,7 +32,7 @@ #include "shared-bindings/util.h" #include "PewPew.h" #include "common-hal/_pew/PewPew.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class PewPew: //| """This is an internal module to be used by the ``pew.py`` library from diff --git a/shared-bindings/_stage/Layer.c b/shared-bindings/_stage/Layer.c index c3c0aa1801a1..9e64a252dbd7 100644 --- a/shared-bindings/_stage/Layer.c +++ b/shared-bindings/_stage/Layer.c @@ -28,7 +28,7 @@ #include "__init__.h" #include "Layer.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Layer: //| """Keep information about a single layer of graphics""" diff --git a/shared-bindings/_stage/Text.c b/shared-bindings/_stage/Text.c index d6b22171d6e6..48747bfd6779 100644 --- a/shared-bindings/_stage/Text.c +++ b/shared-bindings/_stage/Text.c @@ -28,7 +28,7 @@ #include "__init__.h" #include "Text.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Text: //| """Keep information about a single grid of text""" diff --git a/shared-bindings/adafruit_bus_device/i2c_device/I2CDevice.c b/shared-bindings/adafruit_bus_device/i2c_device/I2CDevice.c index 327e8e72b471..3ae5fc2a2fa0 100644 --- a/shared-bindings/adafruit_bus_device/i2c_device/I2CDevice.c +++ b/shared-bindings/adafruit_bus_device/i2c_device/I2CDevice.c @@ -36,7 +36,7 @@ #include "shared/runtime/context_manager_helpers.h" #include "py/runtime.h" #include "py/smallint.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class I2CDevice: diff --git a/shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c b/shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c index 2c5708b83148..f7cc357e9102 100644 --- a/shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c +++ b/shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c @@ -35,7 +35,7 @@ #include "shared/runtime/buffer_helper.h" #include "shared/runtime/context_manager_helpers.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class SPIDevice: diff --git a/shared-bindings/alarm/SleepMemory.c b/shared-bindings/alarm/SleepMemory.c index 37223f1f3532..b4e68c964c7e 100644 --- a/shared-bindings/alarm/SleepMemory.c +++ b/shared-bindings/alarm/SleepMemory.c @@ -31,7 +31,7 @@ #include "py/runtime0.h" #include "shared-bindings/alarm/SleepMemory.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class SleepMemory: //| """Store raw bytes in RAM that persists during deep sleep. diff --git a/shared-bindings/alarm/pin/PinAlarm.c b/shared-bindings/alarm/pin/PinAlarm.c index ff3471678682..06ad77c56da0 100644 --- a/shared-bindings/alarm/pin/PinAlarm.c +++ b/shared-bindings/alarm/pin/PinAlarm.c @@ -33,7 +33,7 @@ #include "py/obj.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class PinAlarm: //| """Trigger an alarm when a pin changes state.""" diff --git a/shared-bindings/alarm/time/TimeAlarm.c b/shared-bindings/alarm/time/TimeAlarm.c index ab0274afa979..0b77913c9bad 100644 --- a/shared-bindings/alarm/time/TimeAlarm.c +++ b/shared-bindings/alarm/time/TimeAlarm.c @@ -33,7 +33,7 @@ #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/time/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE mp_obj_t MP_WEAK rtc_get_time_source_time(void) { diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c index 2f171c5a0f10..41c9b053eb15 100644 --- a/shared-bindings/analogio/AnalogOut.c +++ b/shared-bindings/analogio/AnalogOut.c @@ -34,7 +34,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class AnalogOut: //| """Output analog values (a specific voltage). diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index 93c316d3746e..7c660abc4aaa 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -33,7 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audiobusio/I2SOut.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class I2SOut: //| """Output an I2S audio signal""" diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index aa810f293088..29752a442ca9 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -34,7 +34,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audiobusio/PDMIn.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class PDMIn: //| """Record an input PDM audio stream""" diff --git a/shared-bindings/audiocore/RawSample.c b/shared-bindings/audiocore/RawSample.c index 82c02450babd..02d4bbaa2f97 100644 --- a/shared-bindings/audiocore/RawSample.c +++ b/shared-bindings/audiocore/RawSample.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "shared-bindings/util.h" #include "shared-bindings/audiocore/RawSample.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class RawSample: //| """A raw audio sample buffer in memory""" diff --git a/shared-bindings/audiocore/WaveFile.c b/shared-bindings/audiocore/WaveFile.c index 285bd7cbbe7d..b1c51a974656 100644 --- a/shared-bindings/audiocore/WaveFile.c +++ b/shared-bindings/audiocore/WaveFile.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "shared-bindings/audiocore/WaveFile.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class WaveFile: //| """Load a wave file for audio playback diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 0b4ed7b975f3..75ba7b5ec5c5 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -34,7 +34,7 @@ #include "shared-bindings/audioio/AudioOut.h" #include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class AudioOut: //| """Output an analog audio signal""" diff --git a/shared-bindings/audiomixer/Mixer.c b/shared-bindings/audiomixer/Mixer.c index 3ca6ccd5e3d2..47dbd94f1903 100644 --- a/shared-bindings/audiomixer/Mixer.c +++ b/shared-bindings/audiomixer/Mixer.c @@ -36,7 +36,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Mixer: //| """Mixes one or more audio samples together into one sample.""" diff --git a/shared-bindings/audiomixer/MixerVoice.c b/shared-bindings/audiomixer/MixerVoice.c index f02b9521af3d..f7bf16fb4966 100644 --- a/shared-bindings/audiomixer/MixerVoice.c +++ b/shared-bindings/audiomixer/MixerVoice.c @@ -35,7 +35,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class MixerVoice: //| """Voice objects used with Mixer diff --git a/shared-bindings/audiomp3/MP3Decoder.c b/shared-bindings/audiomp3/MP3Decoder.c index 16efa361b803..8251b26c733b 100644 --- a/shared-bindings/audiomp3/MP3Decoder.c +++ b/shared-bindings/audiomp3/MP3Decoder.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "shared-bindings/audiomp3/MP3Decoder.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class MP3Decoder: //| """Load a mp3 file for audio playback diff --git a/shared-bindings/audiopwmio/PWMAudioOut.c b/shared-bindings/audiopwmio/PWMAudioOut.c index 8118eb47f2e0..f4f36757505a 100644 --- a/shared-bindings/audiopwmio/PWMAudioOut.c +++ b/shared-bindings/audiopwmio/PWMAudioOut.c @@ -34,7 +34,7 @@ #include "shared-bindings/audiopwmio/PWMAudioOut.h" #include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class PWMAudioOut: //| """Output an analog audio signal by varying the PWM duty cycle.""" diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index 67c411120b71..9c0555dd5a4d 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -35,7 +35,7 @@ #include "shared/runtime/context_manager_helpers.h" #include "py/mperrno.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class I2C: //| """Two wire serial protocol""" diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 1f19f8c93952..103dd9fbaabb 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -37,7 +37,7 @@ #include "shared/runtime/context_manager_helpers.h" #include "py/mperrno.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class SPI: //| """A 3-4 wire serial protocol diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index e05e4e0546d1..b3afd9801d56 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -34,7 +34,7 @@ #include "shared/runtime/buffer_helper.h" #include "shared/runtime/context_manager_helpers.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class I2C: //| """Two wire serial protocol""" diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index af853b84acdf..eb89746d05bc 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -38,7 +38,7 @@ #include "py/mperrno.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class SPI: diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index 7a27b04aece1..baa7f2cdba9b 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -38,7 +38,7 @@ #include "py/objtype.h" #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #define STREAM_DEBUG(...) (void)0 // #define STREAM_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__) diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index a9026fbd59b1..ae72b5cb5599 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -41,7 +41,7 @@ #include "shared-bindings/digitalio/DriveMode.h" #include "shared-bindings/digitalio/Pull.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class DigitalInOut: //| """Digital input and output diff --git a/shared-bindings/digitalio/Pull.c b/shared-bindings/digitalio/Pull.c index 4db68dda1001..364be05de04e 100644 --- a/shared-bindings/digitalio/Pull.c +++ b/shared-bindings/digitalio/Pull.c @@ -26,6 +26,7 @@ #include "py/runtime.h" #include "shared-bindings/digitalio/Pull.h" +#include "supervisor/shared/translate/translate.h" //| class Pull: //| """Defines the pull of a digital input pin""" diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 3af152ffdc8c..ef5727261c12 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -34,7 +34,7 @@ #include "py/objproperty.h" #include "py/runtime.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Bitmap: //| """Stores values of a certain size in a 2D array diff --git a/shared-bindings/displayio/ColorConverter.c b/shared-bindings/displayio/ColorConverter.c index 18b88664c0e4..7b33b1ec8f5d 100644 --- a/shared-bindings/displayio/ColorConverter.c +++ b/shared-bindings/displayio/ColorConverter.c @@ -34,7 +34,7 @@ #include "py/objproperty.h" #include "py/runtime.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class ColorConverter: //| """Converts one color format to another.""" diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index b19c0bac5363..4b5db3392877 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -37,7 +37,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" #include "shared-module/displayio/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| _DisplayBus = Union['FourWire', 'paralleldisplay.ParallelBus', 'I2CDisplay'] //| """:py:class:`FourWire`, :py:class:`paralleldisplay.ParallelBus` or :py:class:`I2CDisplay`""" diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 94d2978cef34..81863b2a7aa4 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -37,7 +37,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" #include "shared-module/displayio/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class EPaperDisplay: //| """Manage updating an epaper display over a display bus diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c index 2aa80df61dc7..7e721692304f 100644 --- a/shared-bindings/displayio/FourWire.c +++ b/shared-bindings/displayio/FourWire.c @@ -37,7 +37,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" #include "shared-module/displayio/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class FourWire: //| """Manage updating a display over SPI four wire protocol in the background while Python code runs. diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index 75cc217af3d3..4a57b4a5f19f 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -33,7 +33,7 @@ #include "py/objproperty.h" #include "py/objtype.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Group: //| """Manage a group of sprites and groups and how they are inter-related.""" diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c index a637fc507169..86138d8a3692 100644 --- a/shared-bindings/displayio/I2CDisplay.c +++ b/shared-bindings/displayio/I2CDisplay.c @@ -37,7 +37,7 @@ #include "shared-bindings/busio/I2C.h" #include "shared-bindings/util.h" #include "shared-module/displayio/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class I2CDisplay: //| """Manage updating a display over I2C in the background while Python code runs. diff --git a/shared-bindings/displayio/OnDiskBitmap.c b/shared-bindings/displayio/OnDiskBitmap.c index aa749bf7f7eb..02c370c3c448 100644 --- a/shared-bindings/displayio/OnDiskBitmap.c +++ b/shared-bindings/displayio/OnDiskBitmap.c @@ -30,7 +30,7 @@ #include "py/runtime.h" #include "py/objproperty.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/displayio/OnDiskBitmap.h" //| class OnDiskBitmap: diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index ad6d7c319ae7..171a243a95da 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -34,7 +34,7 @@ #include "py/runtime.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Palette: //| """Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to diff --git a/shared-bindings/displayio/Shape.c b/shared-bindings/displayio/Shape.c index cbfe12d551ed..30a51dadce59 100644 --- a/shared-bindings/displayio/Shape.c +++ b/shared-bindings/displayio/Shape.c @@ -32,7 +32,7 @@ #include "py/objproperty.h" #include "py/runtime.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Shape: //| """Represents a shape made by defining boundaries that may be mirrored.""" diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index b1557a1777b0..d084d94be297 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -38,7 +38,7 @@ #include "shared-bindings/displayio/OnDiskBitmap.h" #include "shared-bindings/displayio/Palette.h" #include "shared-bindings/displayio/Shape.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class TileGrid: //| """A grid of tiles sourced out of one bitmap diff --git a/shared-bindings/fontio/BuiltinFont.c b/shared-bindings/fontio/BuiltinFont.c index 5c1b976e81a6..02d337379796 100644 --- a/shared-bindings/fontio/BuiltinFont.c +++ b/shared-bindings/fontio/BuiltinFont.c @@ -34,7 +34,7 @@ #include "py/runtime.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| from typing_extensions import Protocol # for compat with python < 3.8 //| diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index daff2174fabe..6af8f16ce8ba 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -38,7 +38,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" #include "shared-module/displayio/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class FramebufferDisplay: //| """Manage updating a display with framebuffer in RAM diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index 2f6ebd06c273..b72627b19f3c 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -33,7 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/frequencyio/FrequencyIn.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class FrequencyIn: //| """Read a frequency signal diff --git a/shared-bindings/math/__init__.c b/shared-bindings/math/__init__.c index 54dbf004adcc..f5fb45cb4da8 100644 --- a/shared-bindings/math/__init__.c +++ b/shared-bindings/math/__init__.c @@ -27,7 +27,7 @@ #include "py/builtin.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #if MICROPY_PY_BUILTINS_FLOAT diff --git a/shared-bindings/memorymonitor/AllocationAlarm.c b/shared-bindings/memorymonitor/AllocationAlarm.c index fe25a1a230d8..45e7019912f9 100644 --- a/shared-bindings/memorymonitor/AllocationAlarm.c +++ b/shared-bindings/memorymonitor/AllocationAlarm.c @@ -31,7 +31,7 @@ #include "py/runtime0.h" #include "shared-bindings/memorymonitor/AllocationAlarm.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class AllocationAlarm: //| diff --git a/shared-bindings/memorymonitor/AllocationSize.c b/shared-bindings/memorymonitor/AllocationSize.c index 1c39fdcd9203..ed8252b67ae5 100644 --- a/shared-bindings/memorymonitor/AllocationSize.c +++ b/shared-bindings/memorymonitor/AllocationSize.c @@ -31,7 +31,7 @@ #include "py/runtime0.h" #include "shared-bindings/memorymonitor/AllocationSize.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class AllocationSize: //| diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index db96519dc72c..840f468e2a50 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -31,7 +31,7 @@ #include "py/nlr.h" #include "py/obj.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Pin: //| """Identifies an IO pin on the microcontroller.""" diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index ff1b52eecdb7..067d6b0097c3 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -38,7 +38,7 @@ #include "py/objtype.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Processor: diff --git a/shared-bindings/microcontroller/__init__.c b/shared-bindings/microcontroller/__init__.c index 1b14b3293491..46382dc3e632 100644 --- a/shared-bindings/microcontroller/__init__.c +++ b/shared-bindings/microcontroller/__init__.c @@ -39,7 +39,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| """Pin references and cpu functionality //| diff --git a/shared-bindings/multiterminal/__init__.c b/shared-bindings/multiterminal/__init__.c index f3f8d1ab6c73..8726e9a65593 100644 --- a/shared-bindings/multiterminal/__init__.c +++ b/shared-bindings/multiterminal/__init__.c @@ -28,7 +28,7 @@ #include "py/obj.h" #include "py/mphal.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| """Manage additional terminal sources //| diff --git a/shared-bindings/neopixel_write/__init__.c b/shared-bindings/neopixel_write/__init__.c index d0234fe45162..e45e97017909 100644 --- a/shared-bindings/neopixel_write/__init__.c +++ b/shared-bindings/neopixel_write/__init__.c @@ -30,7 +30,7 @@ #include "py/runtime.h" #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // RGB LED timing information: diff --git a/shared-bindings/nvm/ByteArray.c b/shared-bindings/nvm/ByteArray.c index b01430c0783c..936e3bcee51a 100644 --- a/shared-bindings/nvm/ByteArray.c +++ b/shared-bindings/nvm/ByteArray.c @@ -29,7 +29,7 @@ #include "py/runtime.h" #include "py/runtime0.h" #include "shared-bindings/nvm/ByteArray.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class ByteArray: //| r"""Presents a stretch of non-volatile memory as a bytearray. diff --git a/shared-bindings/os/__init__.c b/shared-bindings/os/__init__.c index a8545d907961..4c249c368ee7 100644 --- a/shared-bindings/os/__init__.c +++ b/shared-bindings/os/__init__.c @@ -36,6 +36,7 @@ #include "py/objstr.h" #include "py/runtime.h" #include "shared-bindings/os/__init__.h" +#include "supervisor/shared/translate/translate.h" //| """functions that an OS normally provides //| diff --git a/shared-bindings/paralleldisplay/ParallelBus.c b/shared-bindings/paralleldisplay/ParallelBus.c index c93f363d1a9b..a8b37fa95698 100644 --- a/shared-bindings/paralleldisplay/ParallelBus.c +++ b/shared-bindings/paralleldisplay/ParallelBus.c @@ -35,7 +35,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" #include "shared-module/displayio/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class ParallelBus: //| """Manage updating a display over 8-bit parallel bus in the background while Python code runs. This diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c index 2ceca6b044eb..d84e788de53f 100644 --- a/shared-bindings/ps2io/Ps2.c +++ b/shared-bindings/ps2io/Ps2.c @@ -34,7 +34,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/ps2io/Ps2.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Ps2: //| """Communicate with a PS/2 keyboard or mouse diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index 21dfdae42cca..1769f5c7a8df 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -33,7 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/pulseio/PulseIn.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class PulseIn: //| """Measure a series of active and idle pulses. This is commonly used in infrared receivers diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index ac568231b9a4..3de2176ffc55 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -34,7 +34,7 @@ #include "shared-bindings/pulseio/PulseOut.h" #include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class PulseOut: //| """Pulse PWM "carrier" output on and off. This is commonly used in infrared remotes. The diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c index 524a857e647a..4acb2a6a8a15 100644 --- a/shared-bindings/pwmio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -33,7 +33,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) { diff --git a/shared-bindings/random/__init__.c b/shared-bindings/random/__init__.c index 63570fe7e76c..eee574d29e08 100644 --- a/shared-bindings/random/__init__.c +++ b/shared-bindings/random/__init__.c @@ -31,7 +31,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "shared-bindings/random/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| """pseudo-random numbers and choices //| diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index b07f90bd0166..9e755764872e 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -34,7 +34,7 @@ #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/rtc/RTC.h" #include "shared-bindings/time/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; diff --git a/shared-bindings/sdioio/SDCard.c b/shared-bindings/sdioio/SDCard.c index c06ce188261c..dbeb50ddf381 100644 --- a/shared-bindings/sdioio/SDCard.c +++ b/shared-bindings/sdioio/SDCard.c @@ -38,7 +38,7 @@ #include "py/mperrno.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class SDCard: //| """SD Card Block Interface with SDIO diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 277c8343e0ed..baf91a35c1c2 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -33,7 +33,7 @@ #include "py/objnamedtuple.h" #include "py/runtime.h" #include "shared-bindings/storage/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| """Storage management //| diff --git a/shared-bindings/struct/__init__.c b/shared-bindings/struct/__init__.c index c29c33c1c00a..5b63a15f1599 100644 --- a/shared-bindings/struct/__init__.c +++ b/shared-bindings/struct/__init__.c @@ -36,7 +36,7 @@ #include "py/parsenum.h" #include "shared-bindings/struct/__init__.h" #include "shared-module/struct/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| """Manipulation of c-style data //| diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index 6fcff963a6aa..cad8ccdeec53 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -36,7 +36,7 @@ #include "supervisor/shared/reload.h" #include "supervisor/shared/stack.h" #include "supervisor/shared/traceback.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/shared/workflow.h" #include "shared-bindings/microcontroller/__init__.h" diff --git a/shared-bindings/synthio/MidiTrack.c b/shared-bindings/synthio/MidiTrack.c index 7805c1a6a04c..e27ff903c661 100644 --- a/shared-bindings/synthio/MidiTrack.c +++ b/shared-bindings/synthio/MidiTrack.c @@ -32,7 +32,7 @@ #include "py/runtime.h" #include "shared-bindings/util.h" #include "shared-bindings/synthio/MidiTrack.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class MidiTrack: //| """Simple square-wave MIDI synth""" diff --git a/shared-bindings/terminalio/Terminal.c b/shared-bindings/terminalio/Terminal.c index cdeca591643a..c6fd389b12db 100644 --- a/shared-bindings/terminalio/Terminal.c +++ b/shared-bindings/terminalio/Terminal.c @@ -35,7 +35,7 @@ #include "py/runtime.h" #include "py/stream.h" #include "shared-bindings/fontio/BuiltinFont.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Terminal: //| """Display a character stream with a TileGrid""" diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c index 5b16ded0e4df..096c80d382e9 100644 --- a/shared-bindings/time/__init__.c +++ b/shared-bindings/time/__init__.c @@ -34,7 +34,7 @@ #include "shared/timeutils/timeutils.h" #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/time/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| """time and timing related functions //| diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c index 23b35253cb8b..729cf94d5d8a 100644 --- a/shared-bindings/touchio/TouchIn.c +++ b/shared-bindings/touchio/TouchIn.c @@ -36,7 +36,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/touchio/TouchIn.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class TouchIn: //| """Read the state of a capacitive touch sensor diff --git a/shared-bindings/usb_cdc/Serial.c b/shared-bindings/usb_cdc/Serial.c index 760efb627876..8a74380be375 100644 --- a/shared-bindings/usb_cdc/Serial.c +++ b/shared-bindings/usb_cdc/Serial.c @@ -33,7 +33,7 @@ #include "py/objproperty.h" #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Serial: //| """Receives cdc commands over USB""" diff --git a/shared-bindings/usb_cdc/__init__.c b/shared-bindings/usb_cdc/__init__.c index eabe26ad07d3..e23e289309c7 100644 --- a/shared-bindings/usb_cdc/__init__.c +++ b/shared-bindings/usb_cdc/__init__.c @@ -31,6 +31,7 @@ #include "shared-bindings/usb_cdc/__init__.h" #include "shared-bindings/usb_cdc/Serial.h" +#include "supervisor/shared/translate/translate.h" #include "py/runtime.h" diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 3f30a6264c73..f0074f9cac24 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -27,6 +27,7 @@ #include "py/objproperty.h" #include "shared-bindings/usb_hid/Device.h" #include "py/runtime.h" +#include "supervisor/shared/translate/translate.h" //| class Device: //| """HID Device specification""" diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index 3922ded03c1a..dcdf6933f743 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -31,6 +31,8 @@ #include "shared-bindings/usb_hid/__init__.h" #include "shared-bindings/usb_hid/Device.h" +#include "supervisor/shared/translate/translate.h" + //| """USB Human Interface Device //| //| The `usb_hid` module allows you to output data as a HID device.""" diff --git a/shared-bindings/usb_midi/PortIn.c b/shared-bindings/usb_midi/PortIn.c index 0056a0818a58..273fa77b35fb 100644 --- a/shared-bindings/usb_midi/PortIn.c +++ b/shared-bindings/usb_midi/PortIn.c @@ -33,7 +33,7 @@ #include "py/objproperty.h" #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class PortIn: //| """Receives midi commands over USB""" diff --git a/shared-bindings/usb_midi/PortOut.c b/shared-bindings/usb_midi/PortOut.c index c46840192435..d5652be5d448 100644 --- a/shared-bindings/usb_midi/PortOut.c +++ b/shared-bindings/usb_midi/PortOut.c @@ -33,7 +33,7 @@ #include "py/objproperty.h" #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class PortOut: //| """Sends midi messages to a computer over USB""" diff --git a/shared-bindings/usb_midi/__init__.c b/shared-bindings/usb_midi/__init__.c index ec065d1e184f..d3d5cf2626fa 100644 --- a/shared-bindings/usb_midi/__init__.c +++ b/shared-bindings/usb_midi/__init__.c @@ -32,6 +32,7 @@ #include "shared-bindings/usb_midi/__init__.h" #include "shared-bindings/usb_midi/PortIn.h" #include "shared-bindings/usb_midi/PortOut.h" +#include "supervisor/shared/translate/translate.h" #include "py/runtime.h" diff --git a/shared-bindings/util.c b/shared-bindings/util.c index c1ca01e0ad4f..5c5eafad4a01 100644 --- a/shared-bindings/util.c +++ b/shared-bindings/util.c @@ -30,7 +30,7 @@ #include "py/runtime.h" #include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // If so, deinit() has already been called on the object, so complain. void raise_deinited_error(void) { diff --git a/shared-bindings/vectorio/Circle.c b/shared-bindings/vectorio/Circle.c index ded186189602..f955cd2afeda 100644 --- a/shared-bindings/vectorio/Circle.c +++ b/shared-bindings/vectorio/Circle.c @@ -8,7 +8,7 @@ #include "py/objproperty.h" #include "py/objtype.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Circle: //| diff --git a/shared-bindings/vectorio/Polygon.c b/shared-bindings/vectorio/Polygon.c index ae9d7a01ca5b..60a4582e5a93 100644 --- a/shared-bindings/vectorio/Polygon.c +++ b/shared-bindings/vectorio/Polygon.c @@ -9,7 +9,7 @@ #include "py/objproperty.h" #include "py/objtype.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #define VECTORIO_POLYGON_DEBUG(...) (void)0 diff --git a/shared-bindings/vectorio/Rectangle.c b/shared-bindings/vectorio/Rectangle.c index 739a1ba9d1a6..34b9e1eabee8 100644 --- a/shared-bindings/vectorio/Rectangle.c +++ b/shared-bindings/vectorio/Rectangle.c @@ -7,7 +7,7 @@ #include "py/objtype.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| class Rectangle: //| def __init__(self, pixel_shader: Union[displayio.ColorConverter, displayio.Palette], width: int, height: int, x: int, y: int) -> None: diff --git a/shared-bindings/vectorio/VectorShape.c b/shared-bindings/vectorio/VectorShape.c index 6a3e192cb9af..ba55cfb85137 100644 --- a/shared-bindings/vectorio/VectorShape.c +++ b/shared-bindings/vectorio/VectorShape.c @@ -16,7 +16,7 @@ #include "py/objproperty.h" #include "py/objtype.h" #include "py/runtime.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // shape: The shape implementation to draw. diff --git a/shared-bindings/zlib/__init__.c b/shared-bindings/zlib/__init__.c index 65bec244e337..e3858d008dbb 100644 --- a/shared-bindings/zlib/__init__.c +++ b/shared-bindings/zlib/__init__.c @@ -39,7 +39,7 @@ #include "shared-bindings/zlib/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" //| """zlib decompression functionality //| diff --git a/shared-module/audiocore/WaveFile.c b/shared-module/audiocore/WaveFile.c index b4056e3f29a6..1b8753255157 100644 --- a/shared-module/audiocore/WaveFile.c +++ b/shared-module/audiocore/WaveFile.c @@ -33,7 +33,7 @@ #include "py/runtime.h" #include "shared-module/audiocore/WaveFile.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" struct wave_format_chunk { uint16_t audio_format; diff --git a/shared-module/audiomp3/MP3Decoder.c b/shared-module/audiomp3/MP3Decoder.c index d0b5428a11b6..506ed5eff250 100644 --- a/shared-module/audiomp3/MP3Decoder.c +++ b/shared-module/audiomp3/MP3Decoder.c @@ -35,7 +35,7 @@ #include "py/runtime.h" #include "shared-module/audiomp3/MP3Decoder.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/background_callback.h" #include "lib/mp3/src/mp3common.h" diff --git a/shared-module/bitbangio/I2C.c b/shared-module/bitbangio/I2C.c index eb897e122fcd..65926b8c0711 100644 --- a/shared-module/bitbangio/I2C.c +++ b/shared-module/bitbangio/I2C.c @@ -32,7 +32,7 @@ #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" STATIC void delay(bitbangio_i2c_obj_t *self) { // We need to use an accurate delay to get acceptable I2C diff --git a/shared-module/bitbangio/SPI.c b/shared-module/bitbangio/SPI.c index 972b0859780a..d740a214e70f 100644 --- a/shared-module/bitbangio/SPI.c +++ b/shared-module/bitbangio/SPI.c @@ -32,7 +32,7 @@ #include "shared-bindings/bitbangio/SPI.h" #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/microcontroller/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #define MAX_BAUDRATE (common_hal_mcu_get_clock_frequency() / 48) diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 7bd0d423391c..5d08c368b551 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -27,7 +27,7 @@ #include "shared-bindings/board/__init__.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-module/board/__init__.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "mpconfigboard.h" #include "py/runtime.h" diff --git a/shared-module/msgpack/__init__.c b/shared-module/msgpack/__init__.c index e1b98a9f9375..d32550722cc7 100644 --- a/shared-module/msgpack/__init__.c +++ b/shared-module/msgpack/__init__.c @@ -36,7 +36,7 @@ #include "py/runtime.h" #include "py/stream.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/msgpack/ExtType.h" #include "shared-bindings/msgpack/__init__.h" #include "shared-module/msgpack/__init__.h" diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index e36d3ec21e05..8806b7c8c6f9 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -38,6 +38,7 @@ #include "shared-bindings/storage/__init__.h" #include "supervisor/filesystem.h" #include "supervisor/flash.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/usb.h" #if CIRCUITPY_USB_MSC diff --git a/shared-module/struct/__init__.c b/shared-module/struct/__init__.c index a0abd16408db..e87321ae798c 100644 --- a/shared-module/struct/__init__.c +++ b/shared-module/struct/__init__.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "py/binary.h" #include "py/parsenum.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "shared-bindings/struct/__init__.h" STATIC void struct_validate_format(char fmt) { diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index 13e66058c28c..f92c93baa354 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -31,7 +31,7 @@ #include "shared-bindings/usb_hid/Device.h" #include "shared-module/usb_hid/__init__.h" #include "shared-module/usb_hid/Device.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/shared/tick.h" #include "tusb.h" diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 89a05c77b3f0..99be84542fd8 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -33,6 +33,7 @@ #include "shared-bindings/usb_hid/__init__.h" #include "shared-bindings/usb_hid/Device.h" #include "supervisor/memory.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/usb.h" static const uint8_t usb_hid_descriptor_template[] = { diff --git a/shared-module/usb_midi/PortIn.c b/shared-module/usb_midi/PortIn.c index b16b77cf97fb..a5c73aa256fd 100644 --- a/shared-module/usb_midi/PortIn.c +++ b/shared-module/usb_midi/PortIn.c @@ -26,7 +26,7 @@ #include "shared-bindings/usb_midi/PortIn.h" #include "shared-module/usb_midi/PortIn.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "tusb.h" size_t common_hal_usb_midi_portin_read(usb_midi_portin_obj_t *self, uint8_t *data, size_t len, int *errcode) { diff --git a/shared-module/usb_midi/PortOut.c b/shared-module/usb_midi/PortOut.c index 4005d8b77d00..c9d229635eb7 100644 --- a/shared-module/usb_midi/PortOut.c +++ b/shared-module/usb_midi/PortOut.c @@ -26,7 +26,7 @@ #include "shared-bindings/usb_midi/PortOut.h" #include "shared-module/usb_midi/PortOut.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "tusb.h" size_t common_hal_usb_midi_portout_write(usb_midi_portout_obj_t *self, const uint8_t *data, size_t len, int *errcode) { diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 8cac2ba8af31..ed1b8a05189d 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -34,6 +34,7 @@ #include "shared-bindings/usb_midi/PortIn.h" #include "shared-bindings/usb_midi/PortOut.h" #include "supervisor/memory.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/usb.h" #include "tusb.h" diff --git a/shared/libc/abort_.c b/shared/libc/abort_.c index 45a2e0deddd0..0c1d860aefc7 100644 --- a/shared/libc/abort_.c +++ b/shared/libc/abort_.c @@ -1,6 +1,6 @@ #include -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" NORETURN void abort_(void); diff --git a/shared/netutils/netutils.c b/shared/netutils/netutils.c index fe92e8bafb4d..030b1535cdd2 100644 --- a/shared/netutils/netutils.c +++ b/shared/netutils/netutils.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "shared/netutils/netutils.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" // Takes an array with a raw IPv4 address and returns something like '192.168.0.1'. mp_obj_t netutils_format_ipv4_addr(uint8_t *ip, netutils_endian_t endian) { diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index 7922cffc2bda..875a1a02201c 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -37,7 +37,7 @@ #include "supervisor/serial.h" #include "supervisor/shared/rgb_led_colors.h" #include "supervisor/shared/status_leds.h" -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include "supervisor/shared/tick.h" #define SAFE_MODE_DATA_GUARD 0xad0000af diff --git a/supervisor/shared/translate.h b/supervisor/shared/translate/compressed_string.h similarity index 90% rename from supervisor/shared/translate.h rename to supervisor/shared/translate/compressed_string.h index da58e1eb7857..e331a5866fcf 100644 --- a/supervisor/shared/translate.h +++ b/supervisor/shared/translate/compressed_string.h @@ -24,10 +24,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SUPERVISOR_TRANSLATE_H -#define MICROPY_INCLUDED_SUPERVISOR_TRANSLATE_H +#pragma once +#include #include +#include // The format of the compressed data is: // - the size of the uncompressed string in UTF-8 bytes, encoded as a @@ -77,17 +78,7 @@ typedef struct compressed_string { // Return the compressed, translated version of a source string // Usually, due to LTO, this is optimized into a load of a constant // pointer. -const compressed_string_t *translate(const char *c); +// const compressed_string_t *translate(const char *c); void serial_write_compressed(const compressed_string_t *compressed); char *decompress(const compressed_string_t *compressed, char *decompressed); uint16_t decompress_length(const compressed_string_t *compressed); - - -// Map MicroPython's error messages to our translations. -#if defined(MICROPY_ENABLE_DYNRUNTIME) && MICROPY_ENABLE_DYNRUNTIME -#define MP_ERROR_TEXT(x) (x) -#else -#define MP_ERROR_TEXT(x) translate(x) -#endif - -#endif // MICROPY_INCLUDED_SUPERVISOR_TRANSLATE_H diff --git a/supervisor/shared/translate.c b/supervisor/shared/translate/translate.c similarity index 88% rename from supervisor/shared/translate.c rename to supervisor/shared/translate/translate.c index fefda4600646..ae6c7524e519 100644 --- a/supervisor/shared/translate.c +++ b/supervisor/shared/translate/translate.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "supervisor/shared/translate.h" +#include "supervisor/shared/translate/translate.h" #include #include @@ -135,18 +135,6 @@ char *decompress(const compressed_string_t *compressed, char *decompressed) { return decompressed; } -inline -// gcc10 -flto has issues with this being always_inline for debug builds. -#if CIRCUITPY_DEBUG < 1 -__attribute__((always_inline)) +#if CIRCUITPY_TRANSLATE_OBJECT == 1 +#include "supervisor/shared/translate/translate_impl.h" #endif -const compressed_string_t *translate(const char *original) { - #ifndef NO_QSTR - #define QDEF(id, hash, len, str) - #define TRANSLATION(id, firstbyte, ...) if (strcmp(original, id) == 0) { static const compressed_string_t v = { .data = firstbyte, .tail = { __VA_ARGS__ } }; return &v; } else - #include "genhdr/qstrdefs.generated.h" -#undef TRANSLATION -#undef QDEF - #endif - return NULL; -} diff --git a/supervisor/shared/translate/translate.h b/supervisor/shared/translate/translate.h new file mode 100644 index 000000000000..8bb343cabe44 --- /dev/null +++ b/supervisor/shared/translate/translate.h @@ -0,0 +1,55 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 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. + */ + +#pragma once + +#include +#include +#include + +#include "supervisor/shared/translate/compressed_string.h" + +// Map MicroPython's error messages to our translations. +#if defined(MICROPY_ENABLE_DYNRUNTIME) && MICROPY_ENABLE_DYNRUNTIME +#define MP_ERROR_TEXT(x) (x) +#else +#define MP_ERROR_TEXT(x) translate(x) +#endif + +// translate() is a giant function with many strcmp calls. The assumption is +// that the build process will optimize this away and replace it with the +// appropriate compressed data for each call site. + +#if CIRCUITPY_TRANSLATE_OBJECT == 0 +// Without LTO, we need to include a copy of this function in each compilation +// unit so that the compile stage can do the optimization. Otherwise the linker +// will leave this as a giant function and have each call site call into it. +#include "supervisor/shared/translate/translate_impl.h" +#else +// In link time optimized (LTO) builds, we can compile this once into a .o and +// at link time the calls will be optimized. +const compressed_string_t *translate(const char *c); +#endif diff --git a/supervisor/shared/translate/translate_impl.h b/supervisor/shared/translate/translate_impl.h new file mode 100644 index 000000000000..ff90aae525d0 --- /dev/null +++ b/supervisor/shared/translate/translate_impl.h @@ -0,0 +1,60 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 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. + */ + +#pragma once + +#include +#include +#include + +#include "supervisor/shared/translate/compressed_string.h" + +#ifndef NO_QSTR +#define QDEF(id, hash, len, str) +#define TRANSLATION(english_id, number) extern compressed_string_t translation##number; +#include "genhdr/qstrdefs.generated.h" +#undef TRANSLATION +#undef QDEF +#endif + +#if CIRCUITPY_TRANSLATE_OBJECT == 0 +static +#endif +inline +// gcc10 -flto has issues with this being always_inline for debug builds. +#if CIRCUITPY_DEBUG < 1 +__attribute__((always_inline)) +#endif +const compressed_string_t *translate(const char *original) { + #ifndef NO_QSTR + #define QDEF(id, hash, len, str) + #define TRANSLATION(english_id, number) if (strcmp(original, english_id) == 0) { return &translation##number; } else + #include "genhdr/qstrdefs.generated.h" +#undef TRANSLATION +#undef QDEF + #endif + return NULL; +} diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index f4ca11db435d..d5c49aa7fc2e 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -15,7 +15,7 @@ SRC_SUPERVISOR = \ supervisor/shared/status_leds.c \ supervisor/shared/tick.c \ supervisor/shared/traceback.c \ - supervisor/shared/translate.c \ + supervisor/shared/translate/translate.c \ supervisor/shared/workflow.c ifeq ($(DISABLE_FILESYSTEM),1) @@ -156,7 +156,7 @@ ifeq ($(CIRCUITPY_DISPLAYIO), 1) supervisor/shared/display.c ifeq ($(CIRCUITPY_TERMINALIO), 1) - SUPERVISOR_O += $(BUILD)/autogen_display_resources.o + SUPERVISOR_O += $(BUILD)/autogen_display_resources-$(TRANSLATION).o endif endif @@ -190,14 +190,14 @@ endif USB_HIGHSPEED ?= 0 CFLAGS += -DUSB_HIGHSPEED=$(USB_HIGHSPEED) -$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h +$(BUILD)/supervisor/shared/translate/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h $(HEADER_BUILD)/compression.generated.h CIRCUITPY_DISPLAY_FONT ?= "../../tools/fonts/ter-u12n.bdf" -$(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD) +$(BUILD)/autogen_display_resources-$(TRANSLATION).c: ../../tools/gen_display_resources.py $(TOP)/locale/$(TRANSLATION).po Makefile | $(HEADER_BUILD) $(STEPECHO) "GEN $@" $(Q)install -d $(BUILD)/genhdr $(Q)$(PYTHON) ../../tools/gen_display_resources.py \ --font $(CIRCUITPY_DISPLAY_FONT) \ - --sample_file $(HEADER_BUILD)/qstrdefs.generated.h \ - --output_c_file $(BUILD)/autogen_display_resources.c + --sample_file $(TOP)/locale/$(TRANSLATION).po \ + --output_c_file $(BUILD)/autogen_display_resources-$(TRANSLATION).c