summaryrefslogtreecommitdiffstatshomepage
path: root/examples
Commit message (Collapse)AuthorAge
* examples/natmod/btree: Make btree.open use mp_arg_parse_all for kwargs.Damien George2024-05-24
| | | | | | | 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>
* examples/natmod/features4: Create custom FactorialError as exc example.Damien George2024-05-23
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/usb: Add README that points out the alternative usb modules.Angus Gratton2024-05-15
| | | | | | | If someone starts from this directory then they won't know they exist, otherwise. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* examples/network: Add example of HTTPS client using non-blocking socket.Damien George2024-05-13
| | | | | | | 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>
* examples/network: Rename SSL examples to start with https.Damien George2024-05-13
| | | | | | | 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>
* examples/usb: Add a USBDevice example implementing the DFU protocol.Damien George2024-05-13
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/usb: Add a very simple USBDevice example with host.Damien George2024-05-13
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/natmod/framebuf: Enable FrameBuffer.poly method.Damien George2024-03-28
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Update extmod, ports, examples to build with new berkeley-db lib.Damien George2024-03-16
| | | | | | | | | | 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>
* all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton2024-03-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* embed: Improve stack top estimation.YAMAMOTO Takashi2024-02-15
| | | | | | | | | | 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>
* examples/embedding: Add -fno-common to the sample compiler flags.Angus Gratton2024-01-31
| | | | | | | | | | | | | | | 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>
* py/obj: Fix mp_obj_is_type compilation with C++.stijn2023-11-17
| | | | | | Fixes issue #12951. Signed-off-by: stijn <stijn@ignitron.net>
* examples/pins.py: Remove this pins printing example.Jim Mussared2023-11-03
| | | | | | | | | | | | 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>
* extmod/modframebuf: Remove FrameBuffer1 from natmod build.Jim Mussared2023-10-16
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Fix various spelling mistakes found by codespell 2.2.6.Damien George2023-10-03
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/unix/machine_bios.py: Fix typo.Thomas2023-09-29
| | | | Signed-off-by: Thomas <th.acker.0302@gmail.com>
* examples/natmod: Add features4 as a class definition example.Jim Mussared2023-09-02
| | | | | | | | 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>
* examples/bluetooth: Link to aioble in BLE examples.Jim Mussared2023-09-01
| | | | Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/bluetooth: Raise ValueError when advertising data is too large.Alexander Wilde2023-09-01
| | | | Signed-off-by: Alexander Wilde <alexander.wilde87@gmail.com>
* examples/hwapi: Add missing import for 96Boards Carbon example.Angus Gratton2023-08-16
| | | | | | Found by Ruff checking F821. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* all: Add missing imports for micropython.const.Angus Gratton2023-08-16
| | | | | | Found by Ruff checking F821. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* examples: Mark asm, pio, etc. as noqa: F821 (undefined-name).Angus Gratton2023-08-16
| | | | | | | | | | | 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>
* examples/natmod/deflate: Add deflate as a dynamic native module.Jim Mussared2023-07-21
| | | | | | | | This replaces the previous zlib version. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Remove the zlib module.Jim Mussared2023-07-21
| | | | | | | | | | | | 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>
* examples/hwapi: Rename uasyncio to asyncio.Jim Mussared2023-06-19
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Replace all uses of umodule in Python code.Jim Mussared2023-06-08
| | | | | | | | Applies to drivers/examples/extmod/port-modules/tools. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/natmod: Rename umodule to module.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename *umodule*.c to remove the "u" prefix.Jim Mussared2023-06-08
| | | | | | | | | | | 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>
* all: Rename UMODULE to MODULE in preprocessor/Makefile vars.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename mod_umodule*, ^umodule* to remove the "u" prefix.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere.Jim Mussared2023-06-08
| | | | | | | | | 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>
* examples/usercmodule: Add a sub-package example.Jim Mussared2023-06-01
| | | | | | | | | | | 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>
* all: Fix cases of Python variable assigned but never used.Christian Clauss2023-05-02
| | | | This fixes ruff rule F841.
* all: Fix spelling mistakes based on codespell check.Damien George2023-04-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/bluetooth/ble_temperature_central.py: Remove service tuple.Jim Mussared2023-04-26
| | | | | | This is unused in the client, only needed in the server. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/usercmodule/cexample: Use mp_obj_malloc().David Lechner2023-03-20
| | | | | | | Example code should use mp_obj_malloc() as well since people will likely copy this code. Signed-off-by: David Lechner <david@pybricks.com>
* examples/bluetooth: Fix check for _conn_handle being None.Damien George2023-02-15
| | | | | | Fixes issue #10755. Signed-off-by: Damien George <damien@micropython.org>
* examples/rp2: Add comment that examples using IO25 don't work on Pico W.Damien George2023-02-07
| | | | Signed-off-by: Damien George <damien@micropython.org>
* top: Update Python formatting to black "2023 stable style".Jim Mussared2023-02-02
| | | | | | See https://black.readthedocs.io/en/stable/the_black_code_style/index.html Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/embedding: Rework example to use ports/embed.Damien George2023-01-20
| | | | Signed-off-by: Damien George <damien@micropython.org>
* docs/rp2: Make LED have exactly 50% duty cycle in PIO 1Hz example.Stig Bjørlykke2023-01-12
| | | | | | | | | 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>
* examples/usercmodule: Add example of a native C class.Laurens Valk2022-11-23
| | | | | | | | This shows how ports can add their own custom types/classes. It is part of the unix coverage build, so we can use it for tests too. Signed-off-by: Laurens Valk <laurens@pybricks.com>
* all: Use += rather than = everywhere for CFLAGS/LDFLAGS/LIBS.Jim Mussared2022-10-11
| | | | | | This avoids a surprise where an = can cancel out an earlier +=. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* top: Replace upip with mip everywhere.Jim Mussared2022-09-30
| | | | | | | | | | Updates all README.md and docs, and manifests to `require("mip")`. Also extend and improve the documentation on freezing and packaging. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/obj: Convert make_new into a mp_obj_type_t slot.Jim Mussared2022-09-19
| | | | | | | | | | | Instead of being an explicit field, it's now a slot like all the other methods. This is a marginal code size improvement because most types have a make_new (100/138 on PYBV11), however it improves consistency in how types are declared, removing the special case for make_new. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/obj: Merge getiter and iternext mp_obj_type_t slots.Jim Mussared2022-09-19
| | | | | | | | | | | | | | | | | | | | | | The goal here is to remove a slot (making way to turn make_new into a slot) as well as reduce code size by the ~40 references to mp_identity_getiter and mp_stream_unbuffered_iter. This introduces two new type flags: - MP_TYPE_FLAG_ITER_IS_ITERNEXT: This means that the "iter" slot in the type is "iternext", and should use the identity getiter. - MP_TYPE_FLAG_ITER_IS_CUSTOM: This means that the "iter" slot is a pointer to a mp_getiter_iternext_custom_t instance, which then defines both getiter and iternext. And a third flag that is the OR of both, MP_TYPE_FLAG_ITER_IS_STREAM: This means that the type should use the identity getiter, and mp_stream_unbuffered_iter as iternext. Finally, MP_TYPE_FLAG_ITER_IS_GETITER is defined as a no-op flag to give the default case where "iter" is "getiter". Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/obj: Add accessors for type slots and use everywhere.Jim Mussared2022-09-19
| | | | | | | This is a no-op, but sets the stage for changing the mp_obj_type_t representation. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/obj: Add "full" and "empty" non-variable-length mp_obj_type_t.Jim Mussared2022-09-19
| | | | | | | This will always have the maximum/minimum size of a mp_obj_type_t representation and can be used as a member in other structs. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Simplify buffer protocol to just a "get buffer" callback.Jim Mussared2022-09-19
| | | | | | | | | | | | | | The buffer protocol type only has a single member, and this existing layout creates problems for the upcoming split/slot-index mp_obj_type_t layout optimisations. If we need to make the buffer protocol more sophisticated in the future either we can rely on the mp_obj_type_t optimisations to just add additional slots to mp_obj_type_t or re-visit the buffer protocol then. This change is a no-op in terms of generated code. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>