Previously the desired output type was specified. Now make the type part
of the function name. Because this function is used in a few places this
saves code size due to smaller call-site.
This makes `mp_obj_new_str_type_from_vstr` a private function of objstr.c
(which is almost the only place where the output type isn't a compile-time
constant).
This saves ~140 bytes on PYBV11.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Rather than drawing the entire boundary to catch missing pixels, just
detect the cases where boundary pixels are skipped during node calculation
and pre-emptively draw them then.
This adds 72 bytes on PYBV11, but makes filled poly() 20% faster.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Add method for drawing polygons.
For non-filled polygons, uses the existing line-drawing code to render
arbitrary polygons using the given coords list, at the given x,y position,
in the given colour.
For filled polygons, arbitrary closed polygons are rendered using a fast
point-in-polygon algorithm to determine where the edges of the polygon lie
on each pixel row.
Tests and documentation updates are also included.
Signed-off-by: Mat Booth <mat.booth@gmail.com>
We plan to add `ellipse` and `poly` methods, but rather than having to
implement a `fill_xyz` version of each, we can make them take an optional
fill argument. This commit add this to `rect` as a starting point.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Several methods extract mp_int_t from adjacent arguments. This reduces
code size for the repeated calls to mp_obj_get_int.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Since commit e65d1e69e8 there is no longer an
io.FileIO class, so this option is no longer needed.
This option also controlled whether or not files supported being opened in
binary mode (eg 'rb'), and could, if disabled, lead to confusion as to why
opening a file in binary mode silently did the wrong thing (it would just
open in text mode if MICROPY_PY_IO_FILEIO was disabled).
The various VFS implementations (POSIX, FAT, LFS) were the only places
where enabling this option made a difference, and in almost all cases where
one of these filesystems were enabled, MICROPY_PY_IO_FILEIO was also
enabled. So it makes sense to just unconditionally enable this feature
(ability to open a file in binary mode) in all cases, and so just remove
this config option altogether. That makes configuration simpler and means
binary file support always exists (and opening a file in binary mode is
arguably more fundamental than opening in text mode, so if anything should
be configurable then it should be the ability to open in text mode).
Signed-off-by: Damien George <damien@micropython.org>
This is useful in situations where the ThreadSafeFlag is reused and needs
to be cleared of any previous, unwanted event.
For example, clear the flag at the start of an operation, trigger the
operation (eg an I2C write), then (a)wait for an external event to set the
flag (eg a pin IRQ). Further events may trigger the flag again but these
are unwanted and should be cleared before the next cycle starts.
These were added in Python 3.5.
Enabled via MICROPY_PY_BUILTINS_BYTES_HEX, and enabled by default for all
ports that currently have ubinascii.
Rework ubinascii to use the implementation of these methods.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Instead of using the fixed machine_spi_type entity to get the SPI transfer
function, this transfer function is now extracted dynamically from the type
of the SPI object.
This allows the SPI object used to communicate with the WIZNET5K hardware
to be SoftSPI or hardware SPI, or anything that has the SPI protocol (at
the C level).
Signed-off-by: Damien George <damien@micropython.org>
Avoiding conflicts between the IRQ and an active transfers. Before this
change the device could lock up in heavy traffic situations.
Fix found and code supplied by @omogenot.
If nic.active(True) is called several times in a row, the device may lock
up. Even if that is bad coding practice, calling wiznet5k_deinit() in
wiznet5k_init() prevents the lock.
Drop an obsolete and wrong argument check, which prevented specifying a pin
for the interrupt signal. The proper checks are now done further down in
the code.
The ntptime module was previously only included in the ESP8266 port. This
commit factors that module out into the extmod directory, makes it support
different epochs, and includes it in the rp2 port.
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.