Wykres commitów

174 Commity (master)

Autor SHA1 Wiadomość Data
Angus Gratton 68e0dfce0a all: Apply Ruff 0.11.6 reformatting changes.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-04-24 16:54:10 +10:00
Angus Gratton d887a021e8 top: Bump the Ruff version to 0.11.6.
With small code fixes to match.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-04-24 16:53:59 +10:00
Angus Gratton f8c8875e25 lora: Fix SNR value in SX126x received packets.
Wasn't being treated as a signed value.

Fixes issue #999.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2025-04-24 16:20:47 +10:00
Matthias Urlichs 9307e21dfb usb-device-cdc: Optimise writing small data so it doesn't require alloc.
Only allocate a memoryview when the (first) write was partial.

Signed-off-by: Matthias Urlichs <matthias@urlichs.de>
2025-04-13 13:27:47 +10:00
Leonard Techel f72f3f1a39 lora-sx126x: Fix invert_iq_rx / invert_iq_tx behaviour.
This commit fixes a typo and changes a tuple that needs to be mutable to a
list (because other parts of the code change elements of this list).

Signed-off-by: Damien George <damien@micropython.org>
2025-04-10 22:39:40 +10:00
Damien George 221a877f8a nrf24l10: Bump minor version.
Due to the previous three commits.

Signed-off-by: Damien George <damien@micropython.org>
2025-04-10 22:33:53 +10:00
marcsello c7103bb464 nrf24l01: Optimize status reading.
The value of the STATUS register is always transmitted by the chip when
reading any command.  So a R_REGISTER command and the turnaround time can
be spared by issuing a NOP command instead.

This implementation suggested by the datasheet.

This operation is compatible with both nRF24L01 and nRF24L01+.

Signed-off-by: Marcell Pünkösd <punkosdmarcell@rocketmail.com>
2025-04-10 22:31:47 +10:00
marcsello bd1ab77324 nrf24l01: Properly handle timeout.
The timeout condition was not handled before.  Upon timeout, this caused
the chip to stay active until another send command changed it's state.

Sometimes when it was unable to transmit the data, it got stuck in the tx
fifo causing it to fill up over time, which set the TX_FULL flag in the
STATUS register.

Since there was no exceptions raised, the user code could not differentiate
a successful send or a timeout condition.

Signed-off-by: Marcell Pünkösd <punkosdmarcell@rocketmail.com>
2025-04-10 22:29:46 +10:00
marcsello 3e859d2118 nrf24l01: Increase startup delay.
According to the datasheet of the NRF240L1 chip, 150 μs startup time is
only acceptable when the chip is clocked externally.  Most modules use a
crystal, which require 1.5 ms to settle.  It should be okay to wait more in
both cases, for a reliable startup.

Signed-off-by: Marcell Pünkösd <punkosdmarcell@rocketmail.com>
2025-04-10 22:25:40 +10:00
Damien George 98d0a2b69a umqtt.simple: Restore legacy ssl/ssl_params arguments.
Commit 35d41dbb0e changed the API for using
SSL with umqtt, but only did a minor version increase.  This broke various
uses of this library, eg
https://github.com/aws-samples/aws-iot-core-getting-started-micropython

Reinstate the original API for specifying an SSL connection.  This library
now supports the following:
- default, ssl=None or ssl=False: no SSL
- ssl=True and optional ssl_params specified: use ssl.wrap_socket
- ssl=<SSLContext instance>: use provided SSL context to wrap socket

Signed-off-by: Damien George <damien@micropython.org>
2025-04-10 21:10:01 +10:00
Damien George 96e17b65d1 mip: Make mip.install() skip /rom*/lib directories.
If a ROMFS is mounted then "/rom/lib" is usually in `sys.path` before the
writable filesystem's "lib" entry.  The ROMFS directory cannot be installed
to, so skip it if found.

Signed-off-by: Damien George <damien@micropython.org>
2025-03-11 16:27:09 +11:00
Glenn Moloney b379e4fb4c mip: Allow relative URLs in package.json.
This allows to specify relative URLs in package.json, which are resolved
relative to the package.json URL. This mirrors the functionality added to
mpremote in https://github.com/micropython/micropython/pull/12477.

Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2025-02-24 14:23:06 +11:00
Angus Gratton a0ceed8269 aioespnow,webrepl: Use recommended network.WLAN.IF_[AP|STA] constants.
Removes the deprecated network.[AP|STA]_IF form.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-11-07 12:48:55 +11:00
Prabhu Ullagaddi d6faaf8472 umqtt.simple: Add optional socket timeout to connect method.
If there are any network issues, mqtt will block on the socket
non-deterministically.  This commit introduces a `timeout` option which
can be used to set a finite timeout on the socket.  Upon any issue, mqtth
lib will throw exception.
2024-11-07 11:51:33 +11:00
Joris van der Wel 68e3e07bc7 aioble: Pass additional connection arguments to gap_connect.
This allows the following arguments to be passed to `device.connect()`:

* scan_duration_ms
* min_conn_interval_us
* max_conn_interval_us

These are passed as-is to `gap_connect()`.  The default value for all of
these is `None`, which causes gap_connect to use its own defaults.

Signed-off-by: Joris van der Wel <joris@jorisvanderwel.com>
2024-10-18 13:03:39 +11:00
Felix Dörre a7cd740b64 usb-device: Allow signaling capability of remote_wakeup.
To use this feature you need to create a usb device signaling remote wakeup
and then enable remote wakeup on the host (on linux write enabled to
/sys/bus/usb/devices/<device>/power/wakeup). Then you can wake up the host
when is on standby using USBDevice.remote_wakeup.

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-10-18 12:54:48 +11:00
Jatty Andriean 7f5ac83865 lora-sx127x: Fix configuring the implicit header option in the _SX127x.
The `_reg_update` method must be called after updating the implicit header
option's bit.

Signed-off-by: Jatty Andriean <jandriea@outlook.com>
2024-10-18 12:33:23 +11:00
Angus Gratton c61ca51c67 usb: Tidy up the description of TinyUSB callbacks.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-17 11:20:00 +10:00
Angus Gratton 01f45c118f usb: Add a note about buffer thread safety.
This is to replace a commit which added locking here but caused some other
problems. The idea behind the Buffer class is that a single producer can
call pend_write() more than once and it's idempotent, however this is very
complex to extend across multiple threads.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-11 17:13:53 +10:00
Angus Gratton 1d3c722b7d usb: Fix race if transfers are submitted by a thread.
The USB pending transfer flag was cleared before calling the completion
callback, to allow the callback code to call submit_xfer() again.

Unfortunately this isn't safe in a multi-threaded environment, as another
thread may see the endpoint is available before the callback is done
executing and submit a new transfer.

Rather than adding extra locking, specifically treat the transfer as still
pending if checked from another thread while the callback is executing.

Closes #874

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-11 17:13:53 +10:00
Angus Gratton 27e4d73bc2 umqtt.robust: Remove reference to missing example.
It looks like this example file was not added to the original commit back
in 6190cec14a.

Fixes issue #320.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-08 22:48:33 +10:00
Max Holliday 60d137029f lora-sx126x: Change to class-level memoryview for _cmd buf.
Currently, the LoRa SX126x driver dynamically creates at least one,
sometimes two, memoryview objects with each call to `_cmd`.  This commit
simply provides the class with a long-lived memoryview object for `_cmd` to
easily slice as necessary.

Unlike the SX127x chips, Semtech unfortunately designed the SX126x modems
to be more command-centric (as opposed to directly setting registers).
Given the amount `_cmd` is called during normal device operation, even a
minor improvement here should have a decent impact.

Basic TX and RX tests pass on hardware.

Signed-off-by: Max Holliday <maholli@stanford.edu>
2024-07-23 15:12:50 +10:00
Damien George fbf7e120c6 usb-device-keyboard: Fix ; and ` keycode names.
They should be named as the un-shifted version.

Signed-off-by: Damien George <damien@micropython.org>
2024-07-03 17:21:55 +10:00
Angus Gratton 0a91a37563 usb-device-cdc: Fix lost data in read() path if short reads happened.
If the CDC receive buffer was full and some code read less than 64 bytes
(wMaxTransferSize), the CDC code would submit an OUT transfer with N<64
bytes length to fill the buffer back up.

However if the host had more than N bytes to send then it would still send
the full 64 bytes (correctly) in the transfer. The remaining (64-N) bytes
would be lost.

Adds the restriction that CDCInterface rxbuf has to be at least 64 bytes.

Fixes issue #885.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-07-03 17:17:38 +10:00
Damien George 2b3bd5b7e0 aioble/multitests: Store a reference to tasks and cancel when done.
Storing references to tasks is required by CPython, and enforced by Ruff
RUF006.  In this case it's also reasonable to cancel these tasks once the
test is finished.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-14 10:35:06 +10:00
Damien George 84ba452113 all: Use non-u versions of built-in modules.
This changes almost all uses of "u-module" to just "module" for the
following built-in modules:
- binascii
- collections
- errno
- io
- json
- socket
- struct
- sys
- time

There are some remaining uses of "u-module" naming, for the cases where the
built-in module is extended in Python, eg `python-stdlib/os` uses `uos`.

Also, there are remaining uses of `utime` when non-standard (compared to
CPython) functions are used, like `utime.ticks_ms()`.

Signed-off-by: Damien George <damien@micropython.org>
2024-06-14 10:35:06 +10:00
Damien George 7271f1ddc7 all: Change use of "uasyncio" to "asyncio".
Signed-off-by: Damien George <damien@micropython.org>
2024-06-14 10:29:46 +10:00
Damien George 2c30a4e91b aioble/multitests: Use multitest.output_metric for perf results.
The perf multitests now "pass" when run.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-25 20:51:51 +10:00
Damien George 1e792c39d3 aioble/multitests: Adjust expected output for write capture test.
Testing shows that the first two writes always go through and the rest are
dropped, so update the .exp file to match that.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-25 20:51:51 +10:00
Damien George 63736c182a aioble/multitests: Add test for advertising and scanning services.
This tests both encoding and decoding multiple 16-bit and 32-bit services
within the one advertising field.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-25 20:51:51 +10:00
Damien George 46e243c592 aioble/central.py: Fix ScanResult.services when decoding UUIDs.
Fixes are needed to support the cases of:
- There may be more than one UUID per advertising field.
- The UUID advertising field may be empty (no UUIDs).
- Constructing 32-bit `bluetooth.UUID()` entities, which must be done by
  passing in a 4-byte bytes object, not an integer.

Signed-off-by: Damien George <damien@micropython.org>
2024-05-25 18:27:37 +10:00
Trent Piepho e5389eb26a aioble/peripheral.py: Place multiple UUIDs in single advertisement LTV.
When multiple UUIDs of the same size are advertised, they should all be
listed in a single LTV.  Supplement to the Bluetooth Core Specification,
Part A, §1.1.1:  "A packet or data block shall not contain more than one
instance for each Service UUID data size."

When aioble construct the advertisement data, it is creating a new data
block for each UUID that contains only that single UUID.  Rather than,
e.g., a single 16-bit UUID block with a list of multiple UUIDs.

Not only is this against the specification, it wastes two bytes of limited
advertisement space per UUID beyond the first for the repeated data block
length and type fields.

Fix this by grouping each UUID size together.

Signed-off-by: Trent Piepho <tpiepho@gmail.com>
2024-05-24 21:42:33 +10:00
Rob Knegjens db7f9a18d4 aioble/device.py: Make default timeout None for disconnected() method.
The value for the `timeout_ms` optional argument to
`DeviceConnection.disconnected()` async method is changed from 60000 to
None.  This way users awaiting a device disconnection using `await
connection.disconnected()` won't be surprised by a 1 minute timeout.
2024-05-24 19:13:42 +10:00
Andrew Leech e7f605df33 aioble/device.py: Always create connection._event.
If the client disconnects immediately after connection, the irq can be run
before the initial connect handler has finished.
2024-05-24 19:03:49 +10:00
Rob Knegjens f0b683218e aioble/examples/temp_client.py: Check connection before reading temp.
Only read from the temp characteristic if the connection is still active.
Improves the example by avoiding a TypeError exception if/when the sensor
disconnects.
2024-05-24 18:48:10 +10:00
Stephen More d4362d5cc3 aioble/examples/temp_sensor.py: Wait forever for client to disconnect.
This sets the disconnected timeout to None, so that the peripheral waits
forever for the client to disconnect.  Previously the peripheral would
abort the connection after 60 seconds (because that's the default timeout).

Signed-off-by: Stephen More <stephen.more@gmail.com>
2024-05-24 18:05:19 +10:00
Stephen More 191494ede7 aioble/examples/temp_sensor.py: Properly notify on update.
This ensures that the peripheral notifies subscribed clients when the
characteristic is written to.

Signed-off-by: Stephen More <stephen.more@gmail.com>
2024-05-24 18:03:41 +10:00
Angus Gratton 00fc3fd37b all: Enable ruff E401 and E402 import lints.
Mostly small cleanups to put each top-level import on its own line.  But
explicitly disable the lint for examples/tests which insert the current
directory into the path before importing.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-17 17:06:33 +10:00
Angus Gratton 992eecfed4 all: Enable Ruff lint F541 'f-string without any placeholders'.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-15 18:11:46 +10:00
Angus Gratton 6c6fab1db1 all: Enable ruff F841 'Local variable is assigned to but never used'.
Most of these look like they were used for print debugging and then kept in
when the print statements were removed or commented.

Some look like missing or incomplete functionality, these have been marked
with comments where possible.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-05-15 18:05:21 +10:00
Jon Foster cb281a4177 ntptime: Fix Year 2036 bug.
Fix NTP client - it would report the wrong time after 7 Feb 2036.

Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
2024-05-15 15:36:02 +10:00
Damien George 7206da4645 mip: Bump minor version.
The previous commit added a new feature (ability to install from GitLab).

Signed-off-by: Damien George <damien@micropython.org>
2024-05-15 13:53:01 +10:00
Olivier Lenoir 57cbc34840 mip: Add support to mip install from GitLab.
Modify _rewrite_url() to allow mip install from `gitlab:` repository.

Signed-off-by: Olivier Lenoir <olivier.len02@gmail.com>
2024-05-15 13:43:06 +10:00
Angus Gratton 583bc0da70 usb: Add USB device support packages.
These packages build on top of machine.USBDevice() to provide high level
and flexible support for implementing USB devices in Python code.

Additional credits, as per included copyright notices:

- CDC support based on initial implementation by @hoihu with fixes by
  @linted.

- MIDI support based on initial implementation by @paulhamsh.

- HID keypad example based on work by @turmoni.

- Everyone who tested and provided feedback on early versions of these
  packages.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-30 15:57:50 +10:00
iabdalkader 661efa48f0 senml: Use the updated cbor2 API.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-19 17:29:22 +11:00
Angus Gratton 224246531e lora-sx126x: Clean up some struct formatting.
Changes are cosmetic - and maybe very minor code size - but not functional.
_reg_read() was calling struct.packinto() with an incorrect number of
arguments but it seems like MicroPython didn't mind, as result is correct
for both versions.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-20 16:58:38 +11:00
Angus Gratton 35bb7952ba lora-sx126x: Fix syncword setting.
Fixes issue #796.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-20 16:58:08 +11:00
Angus Gratton 546284817a lora-sx127x: Implement missing syncword support.
This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-20 16:58:06 +11:00
Angus Gratton ad6ab5a78c lora-sync: Fix race with fast or failed send().
If send completes before the first call to poll_send(), the driver could
get stuck in _sync_wait(). This had much less impact before rp2 port went
tickless, as _sync_wait(will_irq=True) calls machine.idle() which may not
wake very frequently on a tickless port.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-20 16:57:50 +11:00
Angus Gratton b712103519 lora-sx126x: Fix invalid default configuration after reset.
According to the docs, only freq_khz was needed for working output.
However:

- Without output_power setting, no output from SX1262 antenna (theory:
  output routed to the SX1261 antenna).

- SF,BW,etc. settings were different from the SX127x power on defaults, so
  modems with an identical configuration were unable to communicate.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-20 16:44:57 +11:00