Skip to content

Commit 7472ef5

Browse files
committed
Merge remote-tracking branch 'upstream/feature/usbd_python' into feature/usbd_python
2 parents eb47fa0 + 581a662 commit 7472ef5

File tree

61 files changed

+1003
-221
lines changed

Some content is hidden

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

61 files changed

+1003
-221
lines changed

.github/workflows/build_packages.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Build all packages
22

33
on: [push, pull_request]
44

5+
env:
6+
PACKAGE_INDEX_PATH: /tmp/micropython-lib-deploy
7+
58
jobs:
69
build:
710
runs-on: ubuntu-latest
@@ -14,3 +17,11 @@ jobs:
1417
run: source tools/ci.sh && ci_build_packages_check_manifest
1518
- name: Compile package index
1619
run: source tools/ci.sh && ci_build_packages_compile_index
20+
- name: Publish packages for branch
21+
if: vars.MICROPY_PUBLISH_MIP_INDEX && github.event_name == 'push' && ! github.event.deleted
22+
run: source tools/ci.sh && ci_push_package_index
23+
- name: Upload packages as artifact
24+
uses: actions/upload-artifact@v3
25+
with:
26+
name: packages-${{ github.sha }}
27+
path: ${{ env.PACKAGE_INDEX_PATH }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Cleanup published packages
2+
3+
on: delete
4+
5+
jobs:
6+
cleanup:
7+
runs-on: ubuntu-latest
8+
if: vars.MICROPY_PUBLISH_MIP_INDEX
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Clean up published files
12+
run: source tools/ci.sh && ci_cleanup_package_index ${{ github.event.ref }}

CONTRIBUTING.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,49 @@ There are some specific conventions and guidelines for micropython-lib:
6969

7070
* When porting an existing third-party package, please ensure that the source
7171
license is compatible.
72+
73+
* To make it easier for others to install packages directly from your PR before
74+
it is merged, consider opting-in to automatic package publishing (see
75+
[Publishing packages from forks](#publishing-packages-from-forks)). If you do
76+
this, consider quoting the [commands to install
77+
packages](README.md#installing-packages-from-forks) in your Pull Request
78+
description.
79+
80+
### Publishing packages from forks
81+
82+
You can easily publish the packages from your micropython-lib
83+
[fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks)
84+
by opting in to a system based on [GitHub
85+
Actions](https://docs.github.com/en/actions) and [GitHub
86+
Pages](https://docs.github.com/en/pages):
87+
88+
1. Open your fork's repository in the GitHub web interface.
89+
2. Navigate to "Settings" -> "Secrets and variables" -> "Actions" -> "Variables".
90+
3. Click "New repository variable"
91+
4. Create a variable named `MICROPY_PUBLISH_MIP_INDEX` with value `true` (or any
92+
"truthy" value).
93+
5. The settings for GitHub Actions and GitHub Pages features should not need to
94+
be changed from the repository defaults, unless you've explicitly disabled
95+
them.
96+
97+
The next time you push commits to a branch in your fork, GitHub Actions will run
98+
an additional step in the "Build All Packages" workflow named "Publish Packages
99+
for branch".
100+
101+
Anyone can then install these packages as described under [Installing packages
102+
from forks](README.md#installing-packages-from-forks). The exact commands are also
103+
quoted in the GitHub Actions log for the "Publish Packages for branch" step.
104+
105+
#### Opting Back Out
106+
107+
To opt-out again, delete the `MICROPY_PUBLISH_MIP_INDEX` variable and
108+
(optionally) delete the `gh-pages` branch from your fork.
109+
110+
*Note*: While enabled, all micropython-lib packages will be published each time
111+
a change is pushed to any branch in your fork. A commit is added to the
112+
`gh-pages` branch each time. In a busy repository, the `gh-pages` branch may
113+
become quite large. The actual `.git` directory size on disk should still be
114+
quite small, as most of the content will be duplicated. If you're worried that
115+
the `gh-pages` branch has become too large then you can always delete this
116+
branch from GitHub. GitHub Actions will create a new `gh-pages` branch the next
117+
time you push a change.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,37 @@ Note that unlike the other three approaches based on `mip` or `manifest.py`,
8484
you will need to manually resolve dependencies. You can inspect the relevant
8585
`manifest.py` file to view the list of dependencies for a given package.
8686

87+
## Installing packages from forks
88+
89+
It is possible to use the `mpremote mip install` or `mip.install()` methods to
90+
install packages built from a
91+
[fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks)
92+
of micropython-lib, if the fork's owner has opted in.
93+
94+
This can be useful to install packages from a pending Pull Request, for example.
95+
96+
First, the owner of the fork must opt-in as described under
97+
[Publishing packages from forks](CONTRIBUTING.md#publishing-packages-from-forks).
98+
99+
After this has happened, each time someone pushes to a branch in that fork then
100+
GitHub Actions will automatically publish the packages to a GitHub Pages site.
101+
102+
To install these packages, use commands such as:
103+
104+
```bash
105+
$ mpremote connect /dev/ttyUSB0 mip install --index https://USERNAME.github.io/micropython-lib/mip/BRANCH_NAME PACKAGE_NAME
106+
```
107+
108+
Or from a networked device:
109+
110+
```py
111+
import mip
112+
mip.install(PACKAGE_NAME, index="https://USERNAME.github.io/micropython-lib/mip/BRANCH_NAME")
113+
```
114+
115+
(Where `USERNAME`, `BRANCH_NAME` and `PACKAGE_NAME` are replaced with the owner
116+
of the fork, the branch the packages were built from, and the package name.)
117+
87118
## Contributing
88119

89120
We use [GitHub Discussions](https://github.com/micropython/micropython/discussions)

micropython/aioespnow/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# `aioespnow`
2+
3+
A supplementary module which extends the micropython `espnow` module to provide
4+
`asyncio` support.
5+
6+
- 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
8+
2MB flash storage).
9+
10+
## API reference
11+
12+
- class `AIOESPNow()`: inherits all the methods of the `ESPNow` class and
13+
extends the interface with the following async methods:
14+
15+
- `async AIOESPNow.arecv()`
16+
17+
Asyncio support for ESPNow.recv(). Note that this method does not take a
18+
timeout value as argument.
19+
20+
- `async AIOESPNow.airecv()`
21+
22+
Asyncio support for ESPNow.irecv(). Use this method to reduce memory
23+
fragmentation, as it will reuse common storage for each new message
24+
received, whereas the `arecv()` method will allocate new memory for every
25+
message received.
26+
27+
- `async AIOESPNow.asend(mac, msg, sync=True)`
28+
- `async AIOESPNow.asend(msg)`
29+
30+
Asyncio support for ESPNow.send().
31+
32+
- `__aiter__()/async __anext__()`
33+
34+
AIOESPNow also supports reading incoming messages by asynchronous
35+
iteration using `async for`, eg:
36+
37+
```python
38+
e = AIOESPNow()
39+
e.active(True)
40+
async def recv_till_halt(e):
41+
async for mac, msg in e:
42+
print(mac, msg)
43+
if msg == b'halt':
44+
break
45+
asyncio.run(recv_till_halt(e))
46+
```
47+
48+
## Example Usage
49+
50+
A small async server example::
51+
52+
```python
53+
import network
54+
import aioespnow
55+
import uasyncio as asyncio
56+
57+
# A WLAN interface must be active to send()/recv()
58+
network.WLAN(network.STA_IF).active(True)
59+
60+
e = aioespnow.AIOESPNow() # Returns AIOESPNow enhanced with async support
61+
e.active(True)
62+
peer = b'\xbb\xbb\xbb\xbb\xbb\xbb'
63+
e.add_peer(peer)
64+
65+
# Send a periodic ping to a peer
66+
async def heartbeat(e, peer, period=30):
67+
while True:
68+
if not await e.asend(peer, b'ping'):
69+
print("Heartbeat: peer not responding:", peer)
70+
else:
71+
print("Heartbeat: ping", peer)
72+
await asyncio.sleep(period)
73+
74+
# Echo any received messages back to the sender
75+
async def echo_server(e):
76+
async for mac, msg in e:
77+
print("Echo:", msg)
78+
try:
79+
await e.asend(mac, msg)
80+
except OSError as err:
81+
if len(err.args) > 1 and err.args[1] == 'ESP_ERR_ESPNOW_NOT_FOUND':
82+
e.add_peer(mac)
83+
await e.asend(mac, msg)
84+
85+
async def main(e, peer, timeout, period):
86+
asyncio.create_task(heartbeat(e, peer, period))
87+
asyncio.create_task(echo_server(e))
88+
await asyncio.sleep(timeout)
89+
90+
asyncio.run(main(e, peer, 120, 10))
91+
```

micropython/aioespnow/aioespnow.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# aioespnow module for MicroPython on ESP32 and ESP8266
2+
# MIT license; Copyright (c) 2022 Glenn Moloney @glenn20
3+
4+
import uasyncio as asyncio
5+
import espnow
6+
7+
8+
# Modelled on the uasyncio.Stream class (extmod/stream/stream.py)
9+
# NOTE: Relies on internal implementation of uasyncio.core (_io_queue)
10+
class AIOESPNow(espnow.ESPNow):
11+
# Read one ESPNow message
12+
async def arecv(self):
13+
yield asyncio.core._io_queue.queue_read(self)
14+
return self.recv(0) # type: ignore
15+
16+
async def airecv(self):
17+
yield asyncio.core._io_queue.queue_read(self)
18+
return self.irecv(0) # type: ignore
19+
20+
async def asend(self, mac, msg=None, sync=None):
21+
if msg is None:
22+
msg, mac = mac, None # If msg is None: swap mac and msg
23+
yield asyncio.core._io_queue.queue_write(self)
24+
return self.send(mac, msg, sync) # type: ignore
25+
26+
# "async for" support
27+
def __aiter__(self):
28+
return self
29+
30+
async def __anext__(self):
31+
return await self.airecv()

micropython/aioespnow/manifest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
metadata(
2+
description="Extends the micropython espnow module with methods to support asyncio.",
3+
version="0.1",
4+
)
5+
6+
module("aioespnow.py")

micropython/bluetooth/aioble-client/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.3.0")
22

33
require("aioble-core")
44

micropython/bluetooth/aioble-server/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.3.0")
22

33
require("aioble-core")
44

micropython/bluetooth/aioble/aioble/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class ClientDescriptor(BaseClientCharacteristic):
439439
def __init__(self, characteristic, dsc_handle, uuid):
440440
self.characteristic = characteristic
441441

442-
super().__init__(dsc_handle, _FLAG_READ | _FLAG_WRITE_NO_RESPONSE, uuid)
442+
super().__init__(dsc_handle, _FLAG_READ | _FLAG_WRITE, uuid)
443443

444444
def __str__(self):
445445
return "Descriptor: {} {} {}".format(self._value_handle, self.properties, self.uuid)

micropython/bluetooth/aioble/aioble/server.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838

3939
_FLAG_WRITE_CAPTURE = const(0x10000)
4040

41-
_FLAG_DESC_READ = const(1)
42-
_FLAG_DESC_WRITE = const(2)
43-
4441

4542
_WRITE_CAPTURE_QUEUE_LIMIT = const(10)
4643

@@ -307,14 +304,13 @@ class Descriptor(BaseCharacteristic):
307304
def __init__(self, characteristic, uuid, read=False, write=False, initial=None):
308305
characteristic.descriptors.append(self)
309306

310-
# Workaround for https://github.com/micropython/micropython/issues/6864
311307
flags = 0
312308
if read:
313-
flags |= _FLAG_DESC_READ
309+
flags |= _FLAG_READ
314310
if write:
311+
flags |= _FLAG_WRITE
315312
self._write_event = asyncio.ThreadSafeFlag()
316313
self._write_data = None
317-
flags |= _FLAG_DESC_WRITE
318314

319315
self.uuid = uuid
320316
self.flags = flags

micropython/bluetooth/aioble/manifest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# code. This allows (for development purposes) all the files to live in the
44
# one directory.
55

6-
metadata(version="0.2.1")
6+
metadata(version="0.3.1")
77

88
# Default installation gives you everything. Install the individual
99
# components (or a combination of them) if you want a more minimal install.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="Onewire driver.", version="0.1.0")
2+
13
module("onewire.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="WM8960 codec.", version="0.1.0")
2+
13
module("wm8960.py", opt=3)

micropython/drivers/display/lcd160cr/manifest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
metadata(description="LCD160CR driver.", version="0.1.0")
2+
13
options.defaults(test=False)
24

35
module("lcd160cr.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="SSD1306 OLED driver.", version="0.1.0")
2+
13
module("ssd1306.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="WS2812/NeoPixel driver.", version="0.1.0")
2+
13
module("neopixel.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="nrf24l01 2.4GHz radio driver.", version="0.1.0")
2+
13
module("nrf24l01.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="DHT11 & DHT22 temperature/humidity sensor driver.", version="0.1.0")
2+
13
module("dht.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
metadata(description="DS18x20 temperature sensor driver.", version="0.1.0")
2+
13
require("onewire")
24
module("ds18x20.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="HTS221 temperature/humidity sensor driver.", version="0.1.0")
2+
13
module("hts221.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="LPS22H temperature/pressure sensor driver.", version="0.1.0")
2+
13
module("lps22h.py", opt=3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="SDCard block device driver.", version="0.1.0")
2+
13
module("sdcard.py", opt=3)

micropython/net/ntptime/manifest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(description="NTP client.", version="0.1.0")
2+
13
module("ntptime.py", opt=3)

micropython/net/webrepl/manifest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
metadata(description="WebREPL server.", version="0.1.0")
2+
13
module("webrepl.py", opt=3)
24
module("webrepl_setup.py", opt=3)

micropython/senml/examples/base.py

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

2626

2727
from senml import *
28-
import utime as time
28+
import time
2929

3030

3131
pack = SenmlPack("device_name")

micropython/senml/examples/basic.py

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

2626

2727
from senml import *
28-
import utime as time
28+
import time
2929

3030

3131
pack = SenmlPack("device")

micropython/senml/examples/basic2.py

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

2626

2727
from senml import *
28-
import utime as time
28+
import time
2929

3030

3131
pack = SenmlPack("device_name")

0 commit comments

Comments
 (0)