Skip to content

Commit 0147697

Browse files
committed
Merge remote-tracking branch 'origin/master' into moat
2 parents 6d91982 + 68e3e07 commit 0147697

File tree

198 files changed

+4325
-543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+4325
-543
lines changed

.github/workflows/package_tests.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Package tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- uses: actions/setup-python@v4
11+
- name: Setup environment
12+
run: source tools/ci.sh && ci_package_tests_setup_micropython
13+
- name: Setup libraries
14+
run: source tools/ci.sh && ci_package_tests_setup_lib
15+
- name: Run tests
16+
run: source tools/ci.sh && ci_package_tests_run

CONTRIBUTING.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,20 @@ Pages](https://docs.github.com/en/pages):
102102
"truthy" value).
103103
5. The settings for GitHub Actions and GitHub Pages features should not need to
104104
be changed from the repository defaults, unless you've explicitly disabled
105-
them.
105+
Actions or Pages in your fork.
106106

107107
The next time you push commits to a branch in your fork, GitHub Actions will run
108108
an additional step in the "Build All Packages" workflow named "Publish Packages
109-
for branch".
109+
for branch". This step runs in *your fork*, but if you open a pull request then
110+
this workflow is not shown in the Pull Request's "Checks". These run in the
111+
upstream repository. Navigate to your fork's Actions tab in order to see
112+
the additional "Publish Packages for branch" step.
110113

111114
Anyone can then install these packages as described under [Installing packages
112-
from forks](README.md#installing-packages-from-forks). The exact commands are also
113-
quoted in the GitHub Actions log for the "Publish Packages for branch" step.
115+
from forks](README.md#installing-packages-from-forks).
116+
117+
The exact command is also quoted in the GitHub Actions log in your fork's
118+
Actions for the "Publish Packages for branch" step of "Build All Packages".
114119

115120
#### Opting Back Out
116121

micropython/aioespnow/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A supplementary module which extends the micropython `espnow` module to provide
44
`asyncio` support.
55

66
- Asyncio support is available on all ESP32 targets as well as those ESP8266
7-
boards which include the `uasyncio` module (ie. ESP8266 devices with at least
7+
boards which include the `asyncio` module (ie. ESP8266 devices with at least
88
2MB flash storage).
99

1010
## API reference
@@ -52,7 +52,7 @@ A small async server example::
5252
```python
5353
import network
5454
import aioespnow
55-
import uasyncio as asyncio
55+
import asyncio
5656

5757
# A WLAN interface must be active to send()/recv()
5858
network.WLAN(network.STA_IF).active(True)

micropython/aioespnow/aioespnow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# aioespnow module for MicroPython on ESP32 and ESP8266
22
# MIT license; Copyright (c) 2022 Glenn Moloney @glenn20
33

4-
import uasyncio as asyncio
4+
import asyncio
55
import espnow
66

77

8-
# Modelled on the uasyncio.Stream class (extmod/stream/stream.py)
9-
# NOTE: Relies on internal implementation of uasyncio.core (_io_queue)
8+
# Modelled on the asyncio.Stream class (extmod/asyncio/stream.py)
9+
# NOTE: Relies on internal implementation of asyncio.core (_io_queue)
1010
class AIOESPNow(espnow.ESPNow):
1111
# Read one ESPNow message
1212
async def arecv(self):

micropython/aiorepl/aiorepl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def execute(code, g, s):
4141
code = "return {}".format(code)
4242

4343
code = """
44-
import uasyncio as asyncio
44+
import asyncio
4545
async def __code():
4646
{}
4747

micropython/bluetooth/aioble-central/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.2.1")
1+
metadata(version="0.3.0")
22

33
require("aioble-core")
44

micropython/bluetooth/aioble-core/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.2.0")
1+
metadata(version="0.4.0")
22

33
package(
44
"aioble",

micropython/bluetooth/aioble-peripheral/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(version="0.2.0")
1+
metadata(version="0.2.1")
22

33
require("aioble-core")
44

micropython/bluetooth/aioble/aioble/central.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import bluetooth
77
import struct
88

9-
import uasyncio as asyncio
9+
import asyncio
1010

1111
from .core import (
1212
ensure_active,
@@ -104,7 +104,9 @@ async def _cancel_pending():
104104

105105
# Start connecting to a peripheral.
106106
# Call device.connect() rather than using method directly.
107-
async def _connect(connection, timeout_ms):
107+
async def _connect(
108+
connection, timeout_ms, scan_duration_ms, min_conn_interval_us, max_conn_interval_us
109+
):
108110
device = connection.device
109111
if device in _connecting:
110112
return
@@ -122,7 +124,13 @@ async def _connect(connection, timeout_ms):
122124

123125
try:
124126
with DeviceTimeout(None, timeout_ms):
125-
ble.gap_connect(device.addr_type, device.addr)
127+
ble.gap_connect(
128+
device.addr_type,
129+
device.addr,
130+
scan_duration_ms,
131+
min_conn_interval_us,
132+
max_conn_interval_us,
133+
)
126134

127135
# Wait for the connected IRQ.
128136
await connection._event.wait()
@@ -195,12 +203,14 @@ def name(self):
195203

196204
# Generator that enumerates the service UUIDs that are advertised.
197205
def services(self):
198-
for u in self._decode_field(_ADV_TYPE_UUID16_INCOMPLETE, _ADV_TYPE_UUID16_COMPLETE):
199-
yield bluetooth.UUID(struct.unpack("<H", u)[0])
200-
for u in self._decode_field(_ADV_TYPE_UUID32_INCOMPLETE, _ADV_TYPE_UUID32_COMPLETE):
201-
yield bluetooth.UUID(struct.unpack("<I", u)[0])
202-
for u in self._decode_field(_ADV_TYPE_UUID128_INCOMPLETE, _ADV_TYPE_UUID128_COMPLETE):
203-
yield bluetooth.UUID(u)
206+
for uuid_len, codes in (
207+
(2, (_ADV_TYPE_UUID16_INCOMPLETE, _ADV_TYPE_UUID16_COMPLETE)),
208+
(4, (_ADV_TYPE_UUID32_INCOMPLETE, _ADV_TYPE_UUID32_COMPLETE)),
209+
(16, (_ADV_TYPE_UUID128_INCOMPLETE, _ADV_TYPE_UUID128_COMPLETE)),
210+
):
211+
for u in self._decode_field(*codes):
212+
for i in range(0, len(u), uuid_len):
213+
yield bluetooth.UUID(u[i : i + uuid_len])
204214

205215
# Generator that returns (manufacturer_id, data) tuples.
206216
def manufacturer(self, filter=None):

micropython/bluetooth/aioble/aioble/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from micropython import const
55
from collections import deque
6-
import uasyncio as asyncio
6+
import asyncio
77
import struct
88

99
import bluetooth

micropython/bluetooth/aioble/aioble/device.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from micropython import const
55

6-
import uasyncio as asyncio
6+
import asyncio
77
import binascii
88

99
from .core import ble, register_irq_handler, log_error
@@ -132,14 +132,26 @@ def __str__(self):
132132
def addr_hex(self):
133133
return binascii.hexlify(self.addr, ":").decode()
134134

135-
async def connect(self, timeout_ms=10000):
135+
async def connect(
136+
self,
137+
timeout_ms=10000,
138+
scan_duration_ms=None,
139+
min_conn_interval_us=None,
140+
max_conn_interval_us=None,
141+
):
136142
if self._connection:
137143
return self._connection
138144

139145
# Forward to implementation in central.py.
140146
from .central import _connect
141147

142-
await _connect(DeviceConnection(self), timeout_ms)
148+
await _connect(
149+
DeviceConnection(self),
150+
timeout_ms,
151+
scan_duration_ms,
152+
min_conn_interval_us,
153+
max_conn_interval_us,
154+
)
143155

144156
# Start the device task that will clean up after disconnection.
145157
self._connection._run_task()
@@ -164,7 +176,7 @@ def __init__(self, device):
164176

165177
# This event is fired by the IRQ both for connection and disconnection
166178
# and controls the device_task.
167-
self._event = None
179+
self._event = asyncio.ThreadSafeFlag()
168180

169181
# If we're waiting for a pending MTU exchange.
170182
self._mtu_event = None
@@ -207,15 +219,12 @@ async def device_task(self):
207219
t._task.cancel()
208220

209221
def _run_task(self):
210-
# Event will be already created this if we initiated connection.
211-
self._event = self._event or asyncio.ThreadSafeFlag()
212-
213222
self._task = asyncio.create_task(self.device_task())
214223

215224
async def disconnect(self, timeout_ms=2000):
216225
await self.disconnected(timeout_ms, disconnect=True)
217226

218-
async def disconnected(self, timeout_ms=60000, disconnect=False):
227+
async def disconnected(self, timeout_ms=None, disconnect=False):
219228
if not self.is_connected():
220229
return
221230

micropython/bluetooth/aioble/aioble/l2cap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from micropython import const
55

6-
import uasyncio as asyncio
6+
import asyncio
77

88
from .core import ble, log_error, register_irq_handler
99
from .device import DeviceConnection

micropython/bluetooth/aioble/aioble/peripheral.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import bluetooth
77
import struct
88

9-
import uasyncio as asyncio
9+
import asyncio
1010

1111
from .core import (
1212
ensure_active,
@@ -129,14 +129,13 @@ async def advertise(
129129
# Services are prioritised to go in the advertising data because iOS supports
130130
# filtering scan results by service only, so services must come first.
131131
if services:
132-
for uuid in services:
133-
b = bytes(uuid)
134-
if len(b) == 2:
135-
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID16_COMPLETE, b)
136-
elif len(b) == 4:
137-
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID32_COMPLETE, b)
138-
elif len(b) == 16:
139-
resp_data = _append(adv_data, resp_data, _ADV_TYPE_UUID128_COMPLETE, b)
132+
for uuid_len, code in (
133+
(2, _ADV_TYPE_UUID16_COMPLETE),
134+
(4, _ADV_TYPE_UUID32_COMPLETE),
135+
(16, _ADV_TYPE_UUID128_COMPLETE),
136+
):
137+
if uuids := [bytes(uuid) for uuid in services if len(bytes(uuid)) == uuid_len]:
138+
resp_data = _append(adv_data, resp_data, code, b"".join(uuids))
140139

141140
if name:
142141
resp_data = _append(adv_data, resp_data, _ADV_TYPE_NAME, name)

micropython/bluetooth/aioble/aioble/security.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# MIT license; Copyright (c) 2021 Jim Mussared
33

44
from micropython import const, schedule
5-
import uasyncio as asyncio
5+
import asyncio
66
import binascii
77
import json
88

micropython/bluetooth/aioble/aioble/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from micropython import const
55
from collections import deque
66
import bluetooth
7-
import uasyncio as asyncio
7+
import asyncio
88

99
from .core import (
1010
ensure_active,

micropython/bluetooth/aioble/examples/l2cap_file_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
import sys
77

8+
# ruff: noqa: E402
89
sys.path.append("")
910

1011
from micropython import const
1112

12-
import uasyncio as asyncio
13+
import asyncio
1314
import aioble
1415
import bluetooth
1516

@@ -85,7 +86,7 @@ async def size(self, path):
8586
async def download(self, path, dest):
8687
size = await self.size(path)
8788

88-
send_seq = await self._command(_COMMAND_SEND, path.encode())
89+
await self._command(_COMMAND_SEND, path.encode())
8990

9091
with open(dest, "wb") as f: # noqa: ASYNC101
9192
total = 0
@@ -97,7 +98,7 @@ async def download(self, path, dest):
9798
total += n
9899

99100
async def list(self, path):
100-
send_seq = await self._command(_COMMAND_LIST, path.encode())
101+
await self._command(_COMMAND_LIST, path.encode())
101102
results = bytearray()
102103
buf = bytearray(self._channel.our_mtu)
103104
mv = memoryview(buf)

micropython/bluetooth/aioble/examples/l2cap_file_server.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
import sys
1818

19+
# ruff: noqa: E402
1920
sys.path.append("")
2021

2122
from micropython import const
2223

23-
import uasyncio as asyncio
24+
import asyncio
2425
import aioble
2526
import bluetooth
2627

@@ -132,23 +133,20 @@ async def control_task(connection):
132133
file = msg[2:].decode()
133134

134135
if command == _COMMAND_SEND:
135-
op_seq = seq
136136
send_file = file
137137
l2cap_event.set()
138138
elif command == _COMMAND_RECV:
139-
op_seq = seq
140139
recv_file = file
141140
l2cap_event.set()
142141
elif command == _COMMAND_LIST:
143-
op_seq = seq
144142
list_path = file
145143
l2cap_event.set()
146144
elif command == _COMMAND_SIZE:
147145
try:
148146
stat = os.stat(file)
149147
size = stat[6]
150148
status = 0
151-
except OSError as e:
149+
except OSError:
152150
size = 0
153151
status = _STATUS_NOT_FOUND
154152
control_characteristic.notify(

micropython/bluetooth/aioble/examples/temp_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import sys
22

3+
# ruff: noqa: E402
34
sys.path.append("")
45

56
from micropython import const
67

7-
import uasyncio as asyncio
8+
import asyncio
89
import aioble
910
import bluetooth
1011

@@ -54,7 +55,7 @@ async def main():
5455
print("Timeout discovering services/characteristics")
5556
return
5657

57-
while True:
58+
while connection.is_connected():
5859
temp_deg_c = _decode_temperature(await temp_characteristic.read())
5960
print("Temperature: {:.2f}".format(temp_deg_c))
6061
await asyncio.sleep_ms(1000)

0 commit comments

Comments
 (0)