summaryrefslogtreecommitdiff
path: root/extmod
AgeCommit message (Collapse)Author
2021-09-19extmod/nimble: Add nimble CMake fragment file.iabdalkader
2021-09-19extmod/mpbthci.h: Add mp_bluetooth_hci_uart_any prototype.iabdalkader
This allows drivers to use mpbthciport functions to read/write/poll UART.
2021-09-15extmod/modnetwork: Remove modnetwork socket u_state member.iabdalkader
To simplify the socket state. The CC3K driver (see drivers/cc3000/inc/socket.h and src/socket.c) has socket() returning an INT16 so there is now enough room to store it directly in the fileno member.
2021-09-15extmod/modnetwork: Remove STM32 references.iabdalkader
2021-09-15extmod/network_cyw43: Make consistent use of STA and AP constants.Damien George
The network.STA_IF and network.AP_IF constants are now independent to the CYW43_ITF_STA and CYW43_ITF_AP constants. Signed-off-by: Damien George <damien@micropython.org>
2021-09-15extmod/modnetwork: Define network interfaces in port config files.iabdalkader
So this network implementation becomes more generic.
2021-09-15extmod/modusocket: Add read/write stream methods to socket object.iabdalkader
Following other socket implementations.
2021-09-15extmod/modnetwork: Add extended socket state.iabdalkader
2021-09-15extmod/modnetwork: Add STA_IF and AP_IF constants.iabdalkader
2021-09-15extmod: Move modnetwork and modusocket from stm32 to extmod.iabdalkader
So they can be used by other ports.
2021-09-04extmod/machine_pwm: Factor out machine.PWM bindings to common code.Damien George
This commit refactors machine.PWM and creates extmod/machine_pwm.c. The esp8266, esp32 and rp2 ports all use this and provide implementations of the required PWM functionality. This helps to reduce code duplication and keep the same Python API across ports. This commit does not make any functional changes. Signed-off-by: Damien George <damien@micropython.org>
2021-09-02extmod/modonewire: Make _onewire module configurable via macro option.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-09-02extmod/machine_spi: Make SoftSPI configurable via macro option.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-09-02extmod/machine_i2c: Make SoftI2C configurable via macro option.Damien George
The zephyr port doesn't support SoftI2C so it's not enabled, and the legacy I2C constructor check can be removed. Signed-off-by: Damien George <damien@micropython.org>
2021-08-31drivers/cyw43: Make wifi join fail if interface is not active.Damien George
Otherwise the Python network object continues to report that it is attempting to connect. Also make the return error code consistent with wifi scan. Signed-off-by: Damien George <damien@micropython.org>
2021-08-25extmod/modframebuf: Enable blit between different formats via a palette.Peter Hinch
This achieves a substantial performance improvement when rendering glyphs to color displays, the benefit increasing proportional to the number of pixels in the glyph.
2021-08-19extmod: Add machine.bitstream.Jim Mussared
This is a generic API for synchronously bit-banging data on a pin. Initially this adds a single supported encoding, which supports controlling WS2812 LEDs. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-14extmod/modbluetooth: Add send_update arg to gatts_write.Jim Mussared
This allows the write to trigger a notification or indication, but only to subscribed clients. This is different to gatts_notify/gatts_indicate, which will unconditionally notify/indicate. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-08-13extmod/modlwip: Fix close and clean up of UDP and raw sockets.Damien George
The correct callback-deregister functions must be called dependent on the socket type, otherwise resources may not be freed correctly. Signed-off-by: Damien George <damien@micropython.org>
2021-08-07extmod/modujson: Add support for dump/dumps separators keyword-argument.Peter Züger
Optionally enabled via MICROPY_PY_UJSON_SEPARATORS. Enabled by default. For dump, make sure mp_get_stream_raise is called after mod_ujson_separators since CPython does it in this order (if both separators and stream are invalid, separators will raise an exception first). Add separators argument in the docs as well. Signed-off-by: Peter Züger <zueger.peter@icloud.com> Signed-off-by: Damien George <damien@micropython.org>
2021-07-31extmod/uasyncio: In open_connection use address info in socket creation.oclyke
Rudimentary support for various address families. Signed-off-by: oclyke <oclyke@gmail.com>
2021-07-23extmod/nimble: Add "memory stalling" mechanism for l2cap_send.Jim Mussared
When l2cap_send detects that the sys mempool is running low (used to store the outgoing HCI payloads), it will report stalled back to the application, and then only unstall once these HCI payloads have been sent. This prevents a situation where a remote receiver with very large MTU can cause NimBLE to queue up more than MYNEWT_VAL_MSYS_1_BLOCK_COUNT (i.e. 12) payloads, causing further attempts to send to fail with ENOMEM (even though the channel is not stalled and we have room in the channel mbufs). The regular credit/stall flow control is not effective here because the receiver's MTU is large enough that it will not activate (i.e. there are lots of credits available). Thresholds of 1/2 (stall) and 1/4 (unstall) chosen to allow headroom for other payloads (e.g. notifications) and that when a regular stall occurs it might keep sending (and creating more payloads) in the background.
2021-07-23extmod/nimble: Allow modbluetooth binding to hook "sent HCI packet".Jim Mussared
2021-07-23extmod/modbluetooth: Clamp MTU values to 32->UINT16_MAX.Jim Mussared
2021-07-22extmod/utime: Always invoke mp_hal_delay_ms when >= to 0ms.Josh Lloyd
This makes sleep_ms(0) useful as a "yield" so event processing and thread switching can take place. Fixes issue #5345.
2021-07-17extmod/btstack/btstack.mk: Use -Wno-implicit-fallthrough, not =0.Damien George
In 2ae3c890bd923b4c39bba3d2e2f2d75eca5dcc06, -Wimplicit-fallthrough=0 was added to get the build to pass. This option is equivalent to -Wno-implicit-fallthrough, and the latter is compatible with clang (while the former is not). Fixes issue #7546. Signed-off-by: Damien George <damien@micropython.org>
2021-07-17extmod/nimble: Fix leak in l2cap_send if send-while-stalled.Jim Mussared
A correctly-behaved application shouldn't do this, but in the case where the channel is stalled, there's still enough room in the mbuf pool, then we'll fail the send (BLE_HS_EBUSY) so the mbuf needs to be freed. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2021-07-17extmod/moduselect: Conditionally compile select().David Lechner
This adds #if MICROPY_PY_USELECT_SELECT around the uselect.select() function. According to the docs, this function is only for CPython compatibility and should not normally be used. So we can disable it and save a few bytes of flash space where possible. Signed-off-by: David Lechner <david@pybricks.com>
2021-07-15py: Introduce and use mp_raise_type_arg helper.Damien George
To reduce code size. Signed-off-by: Damien George <damien@micropython.org>
2021-07-12all: Update to point to files in new shared/ directory.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12extmod: Update for move of crypto-algorithms, re1.5, uzlib to lib.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12lib/crypto-algorithms: Move crypto-algorithms code from extmod to lib.Damien George
It's third-party code, and not necessarily tied to extmod. Signed-off-by: Damien George <damien@micropython.org>
2021-07-12lib/uzlib: Move uzlib code from extmod to lib.Damien George
It's third-party code, and not necessarily tied to extmod. Signed-off-by: Damien George <damien@micropython.org>
2021-07-12lib/re1.5: Move re1.5 code from extmod to lib.Damien George
It's third-party code, and not necessarily tied to extmod. Signed-off-by: Damien George <damien@micropython.org>
2021-07-08extmod/axtls-include: Add axtls_os_port.h to customise axTLS.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-26extmod/uasyncio: Get addr and bind server socket before creating task.Damien George
Currently when using uasyncio.start_server() the socket configuration is done inside a uasyncio.create_task() background function. If the address and port are already in use however this throws an OSError which cannot be cleanly caught behind the create_task(). This commit moves the getaddrinfo and socket binding to the start_server() function, and only creates the task if that succeeds. This means that any OSError from the initial socket configuration is propagated directly up the call stack, compatible with CPython behaviour. See #7444. Signed-off-by: Damien George <damien@micropython.org>
2021-06-24all: Fix signed shifts and NULL access errors from -fsanitize=undefined.Jeff Epler
Fixes the following (the line numbers match commit 0e87459e2bfd07): ../../extmod/crypto-algorithms/sha256.c:49:19: runtime error: left shif... ../../extmod/moduasyncio.c:106:35: runtime error: member access within ... ../../py/binary.c:210:13: runtime error: left shift of negative value -... ../../py/mpz.c:744:16: runtime error: negation of -9223372036854775808 ... ../../py/objint.c:109:22: runtime error: left shift of 1 by 31 places c... ../../py/objint_mpz.c:374:9: runtime error: left shift of 4611686018427... ../../py/objint_mpz.c:374:9: runtime error: left shift of negative valu... ../../py/parsenum.c:106:14: runtime error: left shift of 46116860184273... ../../py/runtime.c:395:33: runtime error: left shift of negative value ... ../../py/showbc.c:177:28: runtime error: left shift of negative value -... ../../py/vm.c:321:36: runtime error: left shift of negative value -1``` Testing was done on an amd64 Debian Buster system using gcc-8.3 and these settings: CFLAGS += -g3 -Og -fsanitize=undefined LDFLAGS += -fsanitize=undefined The introduced TASK_PAIRHEAP macro's conditional (x ? &x->i : NULL) assembles (under amd64 gcc 8.3 -Os) to the same as &x->i, since i is the initial field of the struct. However, for the purposes of undefined behavior analysis the conditional is needed. Signed-off-by: Jeff Epler <jepler@gmail.com>
2021-06-23extmod/btstack: Check that BLE is active before performing operations.Damien George
Otherwise it can easily lead to a hard crash. Signed-off-by: Damien George <damien@micropython.org>
2021-06-23extmod/btstack: Add missing call to mp_bluetooth_hci_uart_deinit.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-06-23stm32: Provide a custom BTstack runloop that integrates with soft timer.Damien George
It reschedules the BT HCI poll soft timer so that it is called exactly when the next timer expires. Signed-off-by: Damien George <damien@micropython.org>
2021-06-17extmod/nimble: Remove TODO comment about notify_custom freeing om.Damien George
The comments in NimBLE for ble_gattc_notify_custom() state that "This function consumes the supplied mbuf regardless of the outcome.". And inspection of NimBLE code shows that this is the case. So the comment can be removed. Signed-off-by: Damien George <damien@micropython.org>
2021-06-16extmod/uasyncio: Fix race with cancelled task waiting on finished task.Damien George
This commit fixes a problem with a race between cancellation of task A and completion of task B, when A waits on B. If task B completes just before task A is cancelled then the cancellation of A does not work. Instead, the CancelledError meant to cancel A gets passed through to B (that's expected behaviour) but B handles it as a "Task exception wasn't retrieved" scenario, printing out such a message (this is because finished tasks point their "coro" attribute to themselves to indicate they are done, and implement the throw() method, but that method inadvertently catches the CancelledError). The correct behaviour is for B to bounce that CancelledError back out. This bug is mainly seen when wait_for() is used, and in that context the symptoms are: - occurs when using wait_for(T, S), if the task T being waited on finishes at exactly the same time as the wait-for timeout S expires - task T will have run to completion - the "Task exception wasn't retrieved message" is printed with "<class 'CancelledError'>" as the error (ie no traceback) - the wait_for(T, S) call never returns (it's never put back on the uasyncio run queue) and all tasks waiting on this are blocked forever from running - uasyncio otherwise continues to function and other tasks continue to be scheduled as normal The fix here reworks the "waiting" attribute of Task to be called "state" and uses it to indicate whether a task is: running and not awaited on, running and awaited on, finished and not awaited on, or finished and awaited on. This means the task does not need to point "coro" to itself to indicate finished, and also allows removal of the throw() method. A benefit of this is that "Task exception wasn't retrieved" messages can go back to being able to print the name of the coroutine function. Fixes issue #7386. Signed-off-by: Damien George <damien@micropython.org>
2021-06-15extmod/uasyncio: Add readinto() method to Stream class.Mike Teachman
With docs and a multi-test using TCP server/client. This method is a MicroPython extension, although there is discussion of adding it to CPython: https://bugs.python.org/issue41305 Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
2021-06-08extmod/uasyncio: Fix start_server and wait_closed race condition.Miguel Grinberg
This fix prevents server.wait_closed() from raising an AttributeError when trying to access server.task. This can happen if it is called immediately after start_server().
2021-05-30extmod/modurandom: Support an argument of bits=0 to getrandbits.Damien George
This was changed in CPython 3.9; see https://bugs.python.org/issue40282. Signed-off-by: Damien George <damien@micropython.org>
2021-05-30extmod/modurandom: Add error message when getrandbits has bad value.Macarthur Inbody
The random module's getrandbits() method didn't give a proper error message when calling it with a value that was outside of the range of 1-32, which can lead to confusion using this function (which under CPython can accept numbers larger than 32). Now instead of simply giving a ValueError it gives an error message that states that the number of bits is constrained. Also, since the random module's functions getrandbits() and randint() differ from CPython, tests have been added to describe these differences. For getrandbits the relevant documentation is shown and added to the docs. The same is given for randint method so that the information is more easily found. Finally, since the int object lacks the bit_length() method there is a test for that method also to include within the docs, showing the difference to CPython.
2021-05-26extmod/moduhashlib: Put hash obj in final state after digest is called.Damien George
If digest is called then the hash object is put in a "final" state and calling update() or digest() again will raise a ValueError (instead of silently producing the wrong result). See issue #4119. Signed-off-by: Damien George <damien@micropython.org>
2021-05-06extmod/moductypes: Fix size and offset calculation for ARRAY of FLOAT32.Damien George
uctypes.FLOAT32 has a special value representation and uctypes_struct_scalar_size() should be used instead of GET_SCALAR_SIZE(). Signed-off-by: Damien George <damien@micropython.org>
2021-05-06extmod/moductypes: Replace numbers with macro constants.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-05-06extmod/moductypes: Remove double blank lines and debugging printf's.Damien George
Signed-off-by: Damien George <damien@micropython.org>