summaryrefslogtreecommitdiff
path: root/examples
AgeCommit message (Collapse)Author
2024-12-23examples/natmod/re: Fix build on RV32 with alloca.Alessandro Gatti
This fixes compilation of the `re` natmod example when built with Picolibc in the CI environment. Ubuntu 22.04's combination of its bare metal RISC-V toolchain and its version of Picolibc makes the `alloca` symbol more elusive than it should be. This commit makes the `re` natmod try harder to get an `alloca` implementation. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-12-23tools/mpy_ld.py: Add native modules support for RV32 code.Alessandro Gatti
This commit adds support for RV32IMC native modules, as in embedding native code into a self-contained MPY module and and make its exported functions available to the MicroPython environment. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-09-17examples/natmod: Fix URL links in README.md.Matt Trentini
Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
2024-08-28examples/network: Support full URLs in HTTP(S) client examples.Damien George
Not just the domain name. This gives better HTTP 1.0 examples if someone wants to copy them. Signed-off-by: Damien George <damien@micropython.org>
2024-08-28examples/network: Use SSLContext instead of old ssl.wrap_socket.Damien George
`ssl.wrap_socket()` is deprecated in CPython, so use `SSLContext` instead, so the example is a good example to copy. Signed-off-by: Damien George <damien@micropython.org>
2024-08-28examples/network: Support IPv4 and IPv6 in HTTP client examples.Damien George
The main changes here are to pass the address family and socket type to `getaddrinfo()`, and then use the result of the address lookup when creating the socket, so it has the correct address family. This allows both IPv4 and IPv6 to work, because the socket is created with the correct AF_INETx type for the address. Also add some more comments to the examples to explain what's going on. Fixes issue #15580. Signed-off-by: Damien George <damien@micropython.org>
2024-08-14py: Add new cstack API for stack checking, with limit margin macro.Angus Gratton
Currently the stack limit margin is hard-coded in each port's call to `mp_stack_set_limit()`, but on threaded ports it's fiddlier and can lead to bugs (such as incorrect thread stack margin on esp32). This commit provides a new API to initialise the C Stack in one function call, with a config macro to set the margin. Where possible the new call is inlined to reduce code size in thread-free ports. Intended replacement for `MP_TASK_STACK_LIMIT_MARGIN` on esp32. The previous `stackctrl.h` API is still present and unmodified apart from a deprecation comment. However it's not available when the `MICROPY_PREVIEW_VERSION_2` macro is set. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-25examples/usercmodule/cexample: Add more advanced native class.Laurens Valk
This adds a separate `AdvancedTimer` class that demonstrates a few more advanced concepts usch as custom handlers for printing and attributes. Signed-off-by: Laurens Valk <laurens@pybricks.com>
2024-05-24examples/natmod/btree: Make btree.open use mp_arg_parse_all for kwargs.Damien George
Python code is no longer needed to implement keyword arguments in `btree.open()`, it can now be done in C. Signed-off-by: Damien George <damien@micropython.org>
2024-05-23examples/natmod/features4: Create custom FactorialError as exc example.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-15examples/usb: Add README that points out the alternative usb modules.Angus Gratton
If someone starts from this directory then they won't know they exist, otherwise. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-13examples/network: Add example of HTTPS client using non-blocking socket.Damien George
Non-blocking SSL streams can be difficult to get right, so provide a working example, of a HTTPS client. Signed-off-by: Damien George <damien@micropython.org>
2024-05-13examples/network: Rename SSL examples to start with https.Damien George
It's better for discoverability to have these examples named `https_xxx.py` rather than `http_xxx_ssl.py`. Signed-off-by: Damien George <damien@micropython.org>
2024-05-13examples/usb: Add a USBDevice example implementing the DFU protocol.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-05-13examples/usb: Add a very simple USBDevice example with host.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-03-28examples/natmod/framebuf: Enable FrameBuffer.poly method.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-03-16all: Update extmod, ports, examples to build with new berkeley-db lib.Damien George
This provides a MicroPython-specific berkeley-db configuration in extmod/berkeley-db/berkeley_db_config_port.h, and cleans up the include path for this library. Fixes issue #13092. Signed-off-by: Damien George <damien@micropython.org>
2024-03-07all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton
The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. The original reason for this was to have the option to define it to nothing so that all static functions become global functions and therefore visible to certain debug tools, so one could do function size comparison and other things. This STATIC feature is rarely (if ever) used. And with the use of LTO and heavy inline optimisation, analysing the size of individual functions when they are not static is not a good representation of the size of code when fully optimised. So the macro does not have much use and it's simpler to just remove it. Then you know exactly what it's doing. For example, newcomers don't have to learn what the STATIC macro is and why it exists. Reading the code is also less "loud" with a lowercase static. One other minor point in favour of removing it, is that it stops bugs with `STATIC inline`, which should always be `static inline`. Methodology for this commit was: 1) git ls-files | egrep '\.[ch]$' | \ xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/" 2) Do some manual cleanup in the diff by searching for the word STATIC in comments and changing those back. 3) "git-grep STATIC docs/", manually fixed those cases. 4) "rg -t python STATIC", manually fixed codegen lines that used STATIC. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-15embed: Improve stack top estimation.YAMAMOTO Takashi
Obtaining the stack-top via a few function calls may yield a pointer which is too deep within the stack. So require the user to obtain it from a higher level (or via some other means). Fixes issue #11781. Signed-off-by: YAMAMOTO Takashi <yamamoto@midokura.com>
2024-01-31examples/embedding: Add -fno-common to the sample compiler flags.Angus Gratton
This makes no difference when files are linked directly into a target application, but on macOS additional steps are needed to index common symbols in static libraries. See https://stackoverflow.com/a/26581710 By not creating any common symbols, this problem is bypassed. This will also trigger linker errors if there are cases where the same symbol is defined in the host application. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-11-17py/obj: Fix mp_obj_is_type compilation with C++.stijn
Fixes issue #12951. Signed-off-by: stijn <stijn@ignitron.net>
2023-11-03examples/pins.py: Remove this pins printing example.Jim Mussared
It's not supported on all ports, adds complexity to the build to generate pins_af.py, and can mostly be replicated just by printing the pin objects. Remove support for generating pins_af.py from all ports (nrf, stm32, renesas-ra, mimxrt, rp2). This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-16extmod/modframebuf: Remove FrameBuffer1 from natmod build.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-10-03all: Fix various spelling mistakes found by codespell 2.2.6.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-09-29examples/unix/machine_bios.py: Fix typo.Thomas
Signed-off-by: Thomas <th.acker.0302@gmail.com>
2023-09-02examples/natmod: Add features4 as a class definition example.Jim Mussared
Also provide a basic README.md for dynamic native modules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-01examples/bluetooth: Link to aioble in BLE examples.Jim Mussared
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-09-01examples/bluetooth: Raise ValueError when advertising data is too large.Alexander Wilde
Signed-off-by: Alexander Wilde <alexander.wilde87@gmail.com>
2023-08-16examples/hwapi: Add missing import for 96Boards Carbon example.Angus Gratton
Found by Ruff checking F821. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-16all: Add missing imports for micropython.const.Angus Gratton
Found by Ruff checking F821. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2023-08-16examples: Mark asm, pio, etc. as noqa: F821 (undefined-name).Angus Gratton
These files all use decorators (@asm_thumb, @asm_pio) that add names to the function scope, that the linter cannot see. It's useful to clear them in the file not in pyproject.toml as example code will be copied and adapted elsewhere, and those developers may also use Ruff (we hope!) Signed-off-by: Angus Gratton <angus@redyak.com.au>
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-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-06-19examples/hwapi: Rename uasyncio to asyncio.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08all: Replace all uses of umodule in Python code.Jim Mussared
Applies to drivers/examples/extmod/port-modules/tools. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08examples/natmod: Rename umodule to module.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08all: Rename *umodule*.c to remove the "u" prefix.Jim Mussared
Updates any includes, and references from Makefiles/CMake. This essentially reverts what was done long ago in commit 136b5cbd7669e8318f8455fc2706da97a5b7994c This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08all: Rename UMODULE to MODULE in preprocessor/Makefile vars.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08all: Rename mod_umodule*, ^umodule* to remove the "u" prefix.Jim Mussared
This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-08all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere.Jim Mussared
This renames the builtin-modules, such that help('modules') and printing the module object will show "module" rather than "umodule". This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-06-01examples/usercmodule: Add a sub-package example.Jim Mussared
This demonstrates how to add a sub-package in a user c module, as well as how to define the necessary qstrs and enable the feature in the build. This is used by the unix coverage build to test this feature. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-05-02all: Fix cases of Python variable assigned but never used.Christian Clauss
This fixes ruff rule F841.
2023-04-27all: Fix spelling mistakes based on codespell check.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-04-26examples/bluetooth/ble_temperature_central.py: Remove service tuple.Jim Mussared
This is unused in the client, only needed in the server. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-03-20examples/usercmodule/cexample: Use mp_obj_malloc().David Lechner
Example code should use mp_obj_malloc() as well since people will likely copy this code. Signed-off-by: David Lechner <david@pybricks.com>
2023-02-15examples/bluetooth: Fix check for _conn_handle being None.Damien George
Fixes issue #10755. Signed-off-by: Damien George <damien@micropython.org>
2023-02-07examples/rp2: Add comment that examples using IO25 don't work on Pico W.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-02-02top: Update Python formatting to black "2023 stable style".Jim Mussared
See https://black.readthedocs.io/en/stable/the_black_code_style/index.html Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2023-01-20examples/embedding: Rework example to use ports/embed.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2023-01-12docs/rp2: Make LED have exactly 50% duty cycle in PIO 1Hz example.Stig Bjørlykke
This ensures the same number of cycles are used for LED on and LED off in the PIO 1Hz example. It's also possible to swap the first set() and the irq() to avoid using an extra instruction, but this tutorial is a good example of how to calculate the cycles. Signed-off-by: Stig Bjørlykke <stig@bjorlykke.org>