On ports with more than one filesystem, the type will be wrong, for example
if using LFS but FAT enabled, then the type will be FAT. So it's not
possible to use these classes to identify a file object type.
Furthermore, constructing an io.FileIO currently crashes on FAT, and
make_new isn't supported on LFS.
And the io.TextIOWrapper class does not match CPython at all.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
The device will respond to a non-WS request with a simple page that loads
websocket_content.js from a static host (http or https). However, even
if the resources are https, the page is still http and therefore allows
requesting to a WS (not WSS) websocket on the device.
Removed unused client_handshake from websocket_helper, and then merges the
remainder of this file (server_handshake) into webrepl.py (to reduce
firmware size). Also added the respond-as-HTTP handling to
server_handshake.
The default HTTP response is a simple page that sets the base URL and then
loads webrepl_content.js which document.write's the actual HTML.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
If the Bluetooth stack runs on another OS thread then synchronous BLE irq
callbacks, which block the Bluetooth stack until the callback to Python is
complete, must coordinate with the main thread and configure the
MicroPython thread-local-state.
This commit adds MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK which
can be enabled if the system has these requirements.
Signed-off-by: Damien George <damien@micropython.org>
Originally in drivers/ninaw10/nina_wifi_bsp.c but that isn't a QSTR source.
Also remove outdated commment about root pointers in mpconfigport.h.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This fixes two problems with the BTstack implementation of descriptor
discovery:
- The call to gatt_client_discover_characteristic_descriptors needs to have
value_handle set to the starting handle (actually characteristic handle)
to start the search from.
- The BTstack event for a descriptor query result is
GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT.
With this change the test tests/multi_bluetooth/ble_subscribe.py now passes
when BTstack is instance1 (for BTstack to pass as instance0 requires
gatts_write to support sending an update on BTstack).
Signed-off-by: Damien George <damien@micropython.org>
Add cert_reqs and cadata keyword-args to ssl.wrap_socket() and
ssl.CERT_NONE, ssl.CERT_OPTIONAL, ssl.CERT_REQUIRED constants to allow
certificate validation.
CPython doesn't accept cadata in ssl.wrap_socket(), but it does in
SSLContext.load_verify_locations(), so we use this name to at least match
the same name in load_verify_locations().
Add docs for these new arguments, as well as docs for the existing
server_hostname argument which is important for certificate validation.
Tests are added as well.
Signed-off-by: Carlos Gil <carlosgilglez@gmail.com>
All ports that use mbedtls use the custom error messages in
mp_mbedtls_errors.c. This commit simplifies the build so that ports don't
need to explicitly add this file, it's now used by default when mbedtls is
enabled.
Signed-off-by: Damien George <damien@micropython.org>
This uses MP_REGISTER_ROOT_POINTER() to register `bluetooth`
instead of using a conditional inside of mp_state_vm_t.
Signed-off-by: David Lechner <david@pybricks.com>
This uses MP_REGISTER_ROOT_POINTER() to register vfs_cur and
vfs_mount_table instead of using a conditional inside of mp_state_vm_t.
Signed-off-by: David Lechner <david@pybricks.com>
This uses MP_REGISTER_ROOT_POINTER() to register lwip_slip_stream
instead of using a conditional inside of mp_state_vm_t.
Signed-off-by: David Lechner <david@pybricks.com>
This uses MP_REGISTER_ROOT_POINTER() to register dupterm_objs
instead of using a conditional inside of mp_state_vm_t.
Signed-off-by: David Lechner <david@pybricks.com>
This uses MP_REGISTER_ROOT_POINTER() to register mod_network_nic_list and
removes the same from all mpconfigport.h.
Signed-off-by: David Lechner <david@pybricks.com>
This uses MP_REGISTER_ROOT_POINTER() to register bluetooth_nimble_memory
and bluetooth_nimble_root_pointers and removes the same from all
mpconfigport.h.
Signed-off-by: David Lechner <david@pybricks.com>
This uses MP_REGISTER_ROOT_POINTER() to register
bluetooth_btstack_root_pointers and removes the same from all
mpconfigport.h.
Signed-off-by: David Lechner <david@pybricks.com>
The main aim of this change is to reduce the number of heap allocations
when writing data to a stream. This is done in two ways:
1. Eliminate appending of data when .write() is called multiple times
before calling .drain(). With this commit, the data is written out
immediately if the underlying stream is not blocked, so there is no
accumulation of the data in a temporary buffer.
2. Eliminate copying of non-bytes objects passed to .write(). Prior to
this commit, passing a bytearray or memoryview to .write() would always
result in a copy of it being made and turned into a bytes object. That
won't happen now if the underlying stream is not blocked.
Also, this change makes .write () more closely implement the CPython
documented semantics: "The method attempts to write the data to the
underlying socket immediately. If that fails, the data is queued in an
internal write buffer until it can be sent."
This changes the btree implementation to use the buffer protocol for
reading key/values in all methods. `str` and `bytes` objects are not the
only bytes-like objects that could be used.
Documentation and tests are also updated.
Addresses issue #8748.
Signed-off-by: David Lechner <david@pybricks.com>
This separates extmod source files from `py.mk`. Previously, `py.mk`
assumed that every consumer of the py/ directory also wanted to include
extmod/. However, this is not the case. For example, building mpy-cross
uses py/ but doesn't need extmod/.
This commit moves all extmod-specific items from `py.mk` to `extmod.mk` and
explicitly includes `extmod.mk` in ports that use it.
Signed-off-by: David Lechner <david@pybricks.com>
The following changes are made:
- Guard entire file with MICROPY_PY_LWIP, so it can be included in the
build while still being disabled (for consistency with other extmod
modules).
- Add modlwip.c to list of all extmod source in py/py.mk and
extmod/extmod.cmake so all ports can easily use it.
- Move generic modlwip GIT_SUBMODULES build configuration code from
ports/rp2/CMakeLists.txt to extmod/extmod.cmake, so it can be reused by
other ports.
- Remove now unnecessary inclusion of modlwip.c in EXTMOD_SRC_C in esp8266
port, and in SRC_QSTR in mimxrt port.
Signed-off-by: Damien George <damien@micropython.org>
Rename WLAN keyword args to scan(), connect() and config() to be more
consistent across ports and WLAN drivers. This change is backwards
compatible and will support obsolete keyword args, except for positional
"essid" which is now deprecated in favor of "ssid".
The changed argument names are
- "essid" changed to "ssid"
- "auth" or "authmode" changed to "security"
- "password" changed to "key"
Addresses issue #8083.
When MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 is enabled the port's hardware
I2C transfer functions should support the MP_MACHINE_I2C_FLAG_WRITE1
option, but software I2C will not. So add a flag to the I2C protocol
struct so each individual protocol can indicate whether it supports this
option or not.
Fixes issue #8765.
Signed-off-by: Damien George <damien@micropython.org>
* The mbedtls config file path is hard-coded to the config file in
the stm32 port. Any port using this cmake fragment is not actually
using its own config file.
Otherwise include directories are added unconditionally to the build
variables if the component (submodule) is checked out. This can lead to,
eg, the esp32 build using lib/lwip header files, instead of lwip header
files from the IDF.
Fixes issue #8727.
Signed-off-by: Damien George <damien@micropython.org>
Otherwise this is essentially an infinite loop on ports that do not use
interrupts to service network interfaces.
Signed-off-by: Andrew Leech <andrew@alelec.net>
Originally based on both stm32/network_wiznet5k and stm32/modnwwiznet5k.
If MICROPY_PY_LWIP is enabled it uses the lwIP TCP stack in MicroPython,
communicating with the Wiznet controller in MACRAW mode. In this mode it
supports using the INTN pin from Wiznet controller to receive data from an
interrupt trigger.
If lwIP is not enabled, it runs in modnetwork/socket mode providing an
interface to the TCP stack running on the Wiznet controller chip. In this
mode it includes some updates by @irinakim12 from #8021, most notably
bringing in DHCP support.
Supports defining hardware pins in board config or dynamically set at
runtime. Sets a default MAC address in the random namespace from board
unique-id.
Signed-off-by: Andrew Leech <andrew@alelec.net>
This fixes the cases where the task being waited on finishes just before or
just after the wait_for itself is cancelled.
Fixes issue #8717.
Signed-off-by: Damien George <damien@micropython.org>
It's no longer needed because this macro is now processed after
preprocessing the source code via cpp (in the qstr extraction stage), which
means unused MP_REGISTER_MODULE's are filtered out by the preprocessor.
Signed-off-by: Damien George <damien@micropython.org>
The following changes are made:
- If MICROPY_VFS is enabled then mp_vfs_import_stat and mp_vfs_open are
automatically used for mp_import_stat and mp_builtin_open respectively.
- If MICROPY_PY_IO is enabled then "open" is automatically included in the
set of builtins, and points to mp_builtin_open_obj.
This helps to clean up and simplify the most common port configuration.
Signed-off-by: Damien George <damien@micropython.org>