Skip to content

Commit 2a682a1

Browse files
committed
Docs: implications of uasyncio V2.2. aswitch: remove asyn dependency.
1 parent 3d4e398 commit 2a682a1

File tree

4 files changed

+69
-46
lines changed

4 files changed

+69
-46
lines changed

FASTPOLL.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,24 @@ formerly provided by `asyncio_priority.py` is now implemented.
6060

6161
# 1. Installation
6262

63-
Install and test uasyncio on the target hardware. Replace `core.py` and
64-
`__init__.py` with the files in the `fast_io` directory.
65-
66-
In MicroPython 1.9 `uasyncio` was implemented as a frozen module on the
67-
ESP8266. To install this version it is necessary to build the firmware with the
68-
above two files implemented as frozen bytecode. See
69-
[ESP Platforms](./FASTPOLL.md#6-esp-platforms) for general comments on the
63+
The basic approach is to install and test `uasyncio` on the target hardware.
64+
Replace `core.py` and `__init__.py` with the files in the `fast_io` directory.
65+
66+
The current MicroPython release build (1.9.4) has `uasyncio` implemented as a
67+
frozen module. The following options for installing `fast_io` exist:
68+
69+
1. Use a daily build, install `uasyncio` as per the tutorial then replace the
70+
above files.
71+
2. Build the firmware with the `fast_io` version implemented as frozen
72+
bytecode.
73+
3. Use a release build. Install as in 1. above. Then change the module search
74+
order by modifying `sys.path`. The initial entry `''` specifies frozen
75+
bytecode. If this is deleted and appended to the end, frozen files will only
76+
be found if there is no match in the filesystem.
77+
78+
See [ESP Platforms](./FASTPOLL.md#6-esp-platforms) for general comments on the
7079
suitability of ESP platforms for systems requiring fast response.
7180

72-
It is possible to load modules in the filesystem in preference to frozen ones
73-
by modifying `sys.path`. However the ESP8266 probably has too little RAM for
74-
this to be useful.
75-
7681
## 1.1 Benchmarks
7782

7883
The benchmarks directory contains files demonstrating the performance gains

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,20 @@ This repository comprises the following parts.
3535

3636
# 2. Version and installation of uasyncio
3737

38+
As of 24th Dec 2018 Paul Sokolovsky has released uasyncio V2.2. This version
39+
is on PyPi and requires his [Pycopy](https://github.com/pfalcon/micropython)
40+
fork of MicroPython.
41+
42+
I support only the official build of MicroPython. The library code guaranteed
43+
to work with this build is in [micropython-lib](https://github.com/micropython/micropython-lib).
44+
Most of the resources in here should work with Paul's forks (the great majority
45+
work with CPython). I am unlikely to fix issues which are only evident in an
46+
unofficial fork.
47+
3848
The documentation and code in this repository assume `uasyncio` version
39-
2.0.x, which is the version on PyPi and in the official micropython-lib. This
40-
requires firmware dated 22nd Feb 2018 or later. Use of the stream I/O mechanism
41-
requires firmware after 17th June 2018.
49+
2.0.x, the version in [micropython-lib](https://github.com/micropython/micropython-lib).
50+
This requires firmware dated 22nd Feb 2018 or later. Use of the stream I/O
51+
mechanism requires firmware after 17th June 2018.
4252

4353
See [tutorial](./TUTORIAL.md#installing-uasyncio-on-bare-metal) for
4454
installation instructions.

TUTORIAL.md

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,42 +91,38 @@ CPython V3.5 and above.
9191

9292
## 0.1 Installing uasyncio on bare metal
9393

94-
MicroPython libraries are located on [PyPi](https://pypi.python.org/pypi).
95-
Libraries to be installed are:
96-
97-
* micropython-uasyncio
98-
* micropython-uasyncio.queues
99-
* micropython-uasyncio.synchro
94+
If a release build of firmware is used no installation is necessary as uasyncio
95+
is compiled into the build. The current release build (V1.9.4) does not support
96+
asynchronous stream I/O.
97+
98+
The following instructions cover the case where a release build is not used or
99+
where a later official `uasyncio` version is required for stream I/O. The
100+
instructions have changed as the version on PyPi is no longer compatible with
101+
official MicroPython firmware.
102+
103+
The following instructions describe copying the bare minimum of files to a
104+
target device, also the case where `uasyncio` is to be frozen into a compiled
105+
build as bytecode. For the latest release compatible with official firmware
106+
files must be copied from the official
107+
[micropython-lib](https://github.com/micropython/micropython-lib).
108+
109+
Clone the library to a PC with
110+
```
111+
git clone https://github.com/micropython/micropython-lib.git
112+
```
113+
On the target hardware create a `uasyncio` directory and copy the following
114+
files to it:
115+
* `uasyncio/uasyncio/__init__.py`
116+
* `uasyncio.core/uasyncio/core.py`
117+
* `uasyncio.synchro/uasyncio/synchro.py`
118+
* `uasyncio.queues/uasyncio/queues.py`
100119

101120
The `queues` and `synchro` modules are optional, but are required to run all
102121
the examples below.
103122

104-
The official approach is to use the `upip` utility as described
105-
[here](https://github.com/micropython/micropython-lib). Network enabled
106-
hardware has this included in the firmware so it can be run locally. This is
107-
the preferred approach.
108-
109-
On non-networked hardware there are two options. One is to use `upip` under a
110-
Linux real or virtual machine. This involves installing and building the Unix
111-
version of MicroPython, using `upip` to install to a directory on the PC, and
112-
then copying the library to the target.
113-
114-
The need for Linux and the Unix build may be avoided by using
115-
[micropip.py](https://github.com/peterhinch/micropython-samples/tree/master/micropip).
116-
This runs under Python 3.2 or above. Create a temporary directory on your PC
117-
and install to that. Then copy the contents of the temporary directory to the
118-
device. The following assume Linux and a temporary directory named `~/syn` -
119-
adapt to suit your OS. The first option requires that `micropip.py` has
120-
executable permission.
121-
122-
```
123-
$ ./micropip.py install -p ~/syn micropython-uasyncio
124-
$ python3 -m micropip.py install -p ~/syn micropython-uasyncio
125-
```
126-
127123
The `uasyncio` modules may be frozen as bytecode in the usual way, by placing
128-
the `uasyncio` and `collections` directories in the port's `modules` directory
129-
and rebuilding.
124+
the `uasyncio` directory and its contents in the port's `modules` directory and
125+
rebuilding.
130126

131127
###### [Main README](./README.md)
132128

aswitch.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,20 @@
3030

3131
import uasyncio as asyncio
3232
import utime as time
33-
from asyn import launch
33+
# Remove dependency on asyn to save RAM:
3434
# launch: run a callback or initiate a coroutine depending on which is passed.
35+
async def _g():
36+
pass
37+
type_coro = type(_g())
38+
39+
# If a callback is passed, run it and return.
40+
# If a coro is passed initiate it and return.
41+
# coros are passed by name i.e. not using function call syntax.
42+
def launch(func, tup_args):
43+
res = func(*tup_args)
44+
if isinstance(res, type_coro):
45+
loop = asyncio.get_event_loop()
46+
loop.create_task(res)
3547

3648

3749
class Delay_ms(object):

0 commit comments

Comments
 (0)