summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-07-21examples/natmod/deflate: Add deflate as a dynamic native module.Jim Mussared
This replaces the previous zlib version. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21docs/library/deflate: Add docs for deflate.DeflateIO.Jim Mussared
Also update zlib & gzip docs to describe the micropython-lib modules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21tests/extmod: Add deflate.DeflateIO tests.Jim Mussared
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21extmod/moddeflate: Add deflate module providing the DeflateIO class.Jim Mussared
This provides similar functionality to the former zlib.DecompIO and especially CPython's gzip.GzipFile for both compression and decompression. This class can be used directly, and also can be used from Python to implement (via io.BytesIO) zlib.decompress and zlib.compress, as well as gzip.GzipFile. Enable/disable this on all ports/boards that zlib was previously configured for. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21lib/uzlib: Add a source_read_data var to pass to source_read_cb.Jim Mussared
For better abstraction for users of this API. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21lib/uzlib/defl_static: Optimize zlib_start/finish_block.Jim Mussared
Collapsing the two adjacent calls to outbits saves 32 bytes. Bringing defl_static.c into lz77.c allows better inlining, saves 24 bytes. Merge the Outbuf/uzlib_lz77_state_t structs, a minor simplification that doesn't change code size. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21lib/uzlib/tinflate: Implement more compact lookup tables.Jim Mussared
Saves 68 bytes on PYBV11. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21lib/uzlib: Combine zlib/gzip header parsing to allow auto-detect.Jim Mussared
This supports `wbits` values between +40 to +47. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21lib/uzlib: Clean up tinf -> uzlib rename.Jim Mussared
This library used a mix of "tinf" and "uzlib" to refer to itself. Remove all use of "tinf" in the public API. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21lib/uzlib/defl_static: Implement some code size improvements.Jim Mussared
This commit makes the following changes: - Replace 256-byte reverse-bits-in-byte lookup table with computation. - Replace length and distance code lookup tables with computation. - Remove comp_disabled check (it's unused). - Make the dest_write_cb take the data pointer directly, rather than the Outbuf. Saves 500 bytes on PYBV11. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21lib/uzlib/lz77: Always use separate history buffer.Jim Mussared
Because we only use the streaming source, this is just extra code size. Saves 64 bytes on PYBV11. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21lib/uzlib: Add memory-efficient, streaming LZ77 compression support.Damien George
The compression algorithm implemented in this commit uses much less memory compared to the standard way of implementing it using a hash table and large look-back window. In particular the algorithm here doesn't allocate hash table to store indices into the history of the previously seen text. Instead it simply does a brute-force-search of the history text to find a match for the compressor. This is slower (linear search vs hash table lookup) but with a small enough history (eg 512 bytes) it's not that slow. And a small history does not impact the compression too much. To give some more concrete numbers comparing memory use between the approaches: - Standard approach: inplace compression, all text to compress must be in RAM (or at least memory addressable), and then an additional 16k bytes RAM of hash table pointers, pointing into the text - The approach in this commit: streaming compression, only a limited amount of previous text must be in RAM (user selectable, defaults to 512 bytes). To compress, say, 1k of data, the standard approach requires all that data to be in RAM, plus an additional 16k of RAM for the hash table pointers. With this commit, you only need the 1k of data in RAM. Or if it's streaming from a file (or elsewhere), you could get away with only 256 bytes of RAM for the sliding history and still get very decent compression. In summary: because compression takes such a large amount of RAM (in the standard algorithm) and it's not really suitable for microcontrollers, the approach taken in this commit is to minimise RAM usage as much as possible, and still have acceptable performance (speed and compression ratio). Signed-off-by: Damien George <damien@micropython.org>
2023-07-21py/stream: Add mp_stream___exit___obj that calls mp_stream_close.Jim Mussared
There are enough places that implement __exit__ by forwarding directly to mp_stream_close that this saves code size. For the cases where __exit__ is a no-op, additionally make their MP_STREAM_CLOSE ioctl handled as a no-op. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21all: Remove the zlib module.Jim Mussared
This will be replaced with a new deflate module providing the same functionality, with an optional frozen Python wrapper providing a replacement zlib module. binascii.crc32 is temporarily disabled. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-21esp32/CMakeLists: Enable multiple extra component directories in build.Mark Grosen
The EXTRA_COMPONENT_DIRS variable is a list so adding a directory so should be done via append, not set. This enables boards to use other components in the build. See: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#optional-project-variables
2023-07-20esp32/boards/ARDUINO_NANO_ESP32: Add support for Arduino Nano ESP32.Luca Burelli
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20shared/tinyusb: Avoid symbol clash on targets with external TinyUSB.Luca Burelli
On targets that provide a reference TinyUSB implementation, like ESP32, the SDK already defines and implements standard callback functions such as tud_cdc_line_state_cb(). This causes a symbol clash when enabling shared implementations like the MicroPython 1200 touch functionality. To avoid this symbol clash, add an optional macro to allow ports to use a different function name in the shared implementation. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20esp32/usb: Add custom TinyUSB callback support.Luca Burelli
Allow boards to define their own additional USB callbacks. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20esp32/modmachine: Add generic machine.bootloader().Luca Burelli
Implement a standard machine.bootloader() method for ESP32-series devices. No default implementation, each board can enable it as required. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20esp32: Collect properties from IDF-managed components as well.Luca Burelli
Some targets like the ESP32-S3 use the IDF Component Manager to provide additional dependencies to the build. Make sure to include these extra components when collecting properties used by MicroPython-specific build steps, like qstr preprocessing. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2023-07-20stm32/boards/B_L072Z_LRWAN1: Lower default ROM level to "Core".Angus Gratton
Re-enable some features required for the board to still build and the lora driver to run. This board only has 192KB of flash total, so default stm32 build is very close to the limit. Before: LINK build-B_L072Z_LRWAN1/firmware.elf text data bss dec hex filename 184352 68 14112 198532 30784 build-B_L072Z_LRWAN1/firmware.elf (12256 bytes free) After: LINK build-B_L072Z_LRWAN1/firmware.elf text data bss dec hex filename 155028 68 14052 169148 294bc build-B_L072Z_LRWAN1/firmware.elf (41580 bytes free) This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-07-20stm32/boards/B_L072Z_LRWAN1: Add pin definitions for internal SX1262.Angus Gratton
Includes fixing the SCK connection pin. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-07-20esp32: Add support for board-named pins and the Pin.board dict.Damien George
This adds named-pins support to the esp32 port, following other ports. Since the name of esp32 CPU pins is just GPIOx, where x is an integer, the Pin.cpu dict is not supported and CPU pins are just retrieved via their existing integer "name" (the cost of adding Pin.cpu is about 800 bytes, mostly due to the additional qstrs). What this commit supports is the Pin.board dict and constructing a pin by names given by a board. These names are defined in a pins.csv file at the board level. If no such file exists then Pin.board exists but is empty. As part of this commit, pin and pin IRQ objects are optimised to reduce their size in flash (by removing their gpio_num_t entry). The net change in firmware size for this commit is about -132 bytes. Signed-off-by: Damien George <damien@micropython.org>
2023-07-20renesas-ra/machine_spi: Consistently use machine_pin_find to get pin.robert-hh
Sometimes mp_hal_get_pin_obj() was used. machine_pin_find() is the internal name, and the external interface is mp_hal_get_pin_obj(). Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20esp8266/machine_pin: Accept an integer argument to mp_obj_get_pin_obj.robert-hh
Allowing the machine.pwm() and esp.apa102() module to accept Pin(x) integer parameters. Not so much of a gain, just consistent with other ports. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20esp32: Use always machine_pin_get_id for getting a Pin id.robert-hh
This applies to all machine modules which have pins as arguments. Since machine_pin_get_id() calls pin_find(), these pin arguments may be at the moment either integer objects or Pin objects. That allows for instance to write uart = UART(1, tx=Pin(4), rx=Pin(5)) instead of uart = UART(1, tx=4, rx=5) which is consistent with other ports. Since this handling is done at a single place in the code, extending that scheme to accept strings for named pins is easy. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20esp32/machine_pin: Add a pin-find func and use it in machine_pin_get_id.robert-hh
The new machine_pin_find() function accepts a Pin object and a integer object as input and returns a pin object. That can be extended later to accept a string object, once named pins are supported. Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-20rp2/machine_pin: Factor out pin-find code from machine_pin_make_new.robert-hh
And use it in mp_hal_get_pin_obj() and machine_pin_make_new(). That way, mp_hal_get_pin_obj() accepts both int and str objects as argument, allowing use of a pin specifier instead of a pin object in the constructor of devices which need a pin as parameter. E.g. instead of uart = UART(0, tx=Pin(0), rx=Pin(1)) one can write: uart = UART(0, tx=0, rx=1) Signed-off-by: robert-hh <robert@hammelrath.com>
2023-07-14esp32/machine_timer: Switch from legacy driver to timer HAL.Damien George
The legacy driver was deprecated in IDF v5, and crashes when the ISR handler is called. Instead of fixing the legacy code, this commit reworks the machine.Timer class to use the low-level HAL driver. Tested on ESP32, ESP32S2, ESP32S3 and ESP32C3. Behaviour is the same as it was before this commit, except the way the Timer object is printed, it now gives more useful information (timer id, mode, period in ms). Fixes issue #11970. Signed-off-by: Damien George <damien@micropython.org>
2023-07-13py/builtinimport: Fix built-in imports when external import is disabled.Jim Mussared
Follow-up to 24c02c4eb5f11200f876bb57cd63a9d0bae91fd3 for when MICROPY_ENABLE_EXTERNAL_IMPORT=0. It now needs to try both extensible and non-extensible modules. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-07-13py/compile: Fix async for's stack handling of iterator expression.Damien George
Prior to this fix, async for assumed the iterator expression was a simple identifier, and used that identifier as a local to store the intermediate iterator object. This is incorrect behaviour. This commit fixes the issue by keeping the iterator object on the stack as an anonymous local variable. Fixes issue #11511. Signed-off-by: Damien George <damien@micropython.org>
2023-07-13webassembly: Replace typeof window check with ENVIRONMENT_IS_NODE flag.Nicholas H.Tollervey
When the "typeof window" check is run within a web worker the window is undefined, causing an error because "require" is only defined in a Node environment. Change the logic to reflect the true intentions of when this code should run, ie in Node only. Signed-off-by: Damien George <damien@micropython.org>
2023-07-13renesas-ra,stm32: Remove duplicate machine module from constants list.Damien George
In the u-module renaming done in 30628d1bb782006c88325a086ddfcd5c2e5ddbb4, these duplicate lines were accidentally left. Signed-off-by: Damien George <damien@micropython.org>
2023-07-13stm32/mpconfigport: Always define MICROPY_SOFT_TIMER_TICKS_MS.Damien George
Even if MICROPY_PY_MACHINE is disabled, the soft timer is still used. Signed-off-by: Damien George <damien@micropython.org>
2023-07-13stm32/qspi: Allow qspi_write_cmd_data to write cmd with 1 data byte.Victor Rajewski
The existing qspi for stm32 implementation can only send a spi command with exactly 0 or 2 data bytes. Certain spiflash chips (e.g. AT25SF321B) have commands that only take a single data byte, and will ignore the command if more than that is sent. This commit allows sending a command with a single data byte. Signed-off-by: Victor Rajewski <victor@allumeenergy.com.au>
2023-07-13stm32/adc: Fix pyb.ADCAll.read_core_bat on G4 and L4 MCUs.Yuuki NAGAO
Update adc_refcor before reading ADC_CHANNEL_VBAT because VREFINT_CAL is at VDDA=3.0V. Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13stm32/adc: Add workaround for ADC errata with G4 MCUs.Yuuki NAGAO
For STM32G4, there is a errata on ADC that may get wrong ADC result. According to the errata sheet, this can be avoid by performing two consecutive ADC conversions and keep second result. Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13stm32/machine_adc: Fix machine.ADC to work on G4 MCUs.Yuuki NAGAO
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13stm32/adc: Fix reading internal ADC channels on G4 MCUs.Yuuki NAGAO
For STM32G4 series, the internal sensors are connected to: - ADC1_IN16: Temperature sensor - ADC1_IN17: Battery voltage monitoring - ADC1_IN18: Internal voltage reference but ADC_CHANNEL_TEMPSENSOR_ADC1, ADC_CHANNEL_VBAT, ADC_CHANNEL_VREFINT are not defined as 16, 17, 18. This commit converts channel 16, 17, 18 to ADC_CHANNEL_x in adc_get_internal_channel(). Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13stm32/adc: Fix pyb.ADCAll.read_core_temp for G4 MCUs.Yuuki NAGAO
For STM32G4, * TS_CAL1 raw data acquired at a temperature of 30°C * TS_CAL2 raw data acquired at a temperature of 130°C Also, these values are at VDDA=3.0V. Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13stm32/adc: Fix ADC clock prescaler for G4 MCUs.Yuuki NAGAO
For STM32G4, ADC clock frequency should be equal or less than 60MHz. To satisfy this specification, ADC clock prescaler should be equal or greater than 4 (For example, NUCLEO_G474RE runs 170MHz). In addition, to obtain accurate internal channel value, the ADC clock prescaler is set to 16 because vbat needs at least 12us (16/170*247.5=23.3us). Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13stm32/dac: Fix dac.write_timed on G4 MCUs to use 32-bit DMA access.Yuuki NAGAO
For STMG4 MCUs, the peripheral registers for DAC have to be accessed by words (32bits) because DAC is connected to AHB directly. (This requirement is also there for other MCU series. However, if DAC is connected to APB like F4/L1/L4 MCUs, AHB byte or half-word transfer is changed into a 32-bit APB transfer. This means that PSIZE does not have to be DMA_PDATAALIGN_WORD on these MCUs, and in fact must be BYTE/HALFWORD to function correctly.) Fixes issue #9563. Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-07-13docs/esp32/quickref: Add LAN example for WT32-ETH01 version 1.4.Elvis Pfutzenreuter
This board requires slightly different configuration to work. It is important to hard reset (cycle power) if you try to initialize LAN and it fails, before trying again with new parameters. Discussion: https://github.com/orgs/micropython/discussions/11446 AliExpress purchase link: https://pt.aliexpress.com/item/1005002023196214.html Signed-off-by: Elvis Pfutzenreuter <epxx@epxx.co>
2023-07-13esp32/network_wlan: Wait for STA/AP START/STOP event in wlan.active.Glenn Moloney
This is a fix for commit bccbaa92b1fc6237f0f49a7f07cc194835fbf4e3: - Should only wait for WIFI_EVENT_STA_START when invoked on the STA_IF interface. - The WIFI_EVENT_STA_START event is generated every time the STA_IF interface is set active(True) and it was previously inactive, ie. not only after calling esp_wifi_start(). - Also wait for WIFI_EVENT_STA_STOP when deactivating the interface. - Also wait for relevant AP events. Fixes issue #11910. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com> Signed-off-by: Damien George <damien@micropython.org>
2023-07-12esp32/boards/GENERIC_OTA: Enable silent checks to reduce firmware size.Damien George
Enabling mDNS put this firmware over the limit of the OTA partition size, so tweak the compiler settings to reduce the firmware size. Signed-off-by: Damien George <damien@micropython.org>
2023-07-11esp32: Re-enable mDNS after move to IDF v5.0.2.Carlosgg
mDNS was disabled in e4650125b88a35f074097f16d84a8f49bd22ac06. This commit re-enables it. For reference see: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/migration-guides/release-5.x/5.0/removed-components.html Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
2023-07-11stm32/modmachine: Make machine_reset_cause_obj public.Damien George
To match the other functions in the machine module, in particular so that MICROPY_PY_MACHINE can be disabled without getting a compiler warning about unused code. Signed-off-by: Damien George <damien@micropython.org>
2023-07-11stm32/modmachine: Remove duplicate machine_timer_type declaration.Tobias Thyrrestrup
Signed-off-by: Tobias Thyrrestrup <tt@LEGO.com>
2023-06-27stm32: Modify RCC->APB2ENR directly instead of HAL API.Yuuki NAGAO
Also, it is needed only when USB is enabled. Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
2023-06-27stm32: Add USB support for STM32L1 MCUs.Yuuki NAGAO
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>