mirror of
https://github.com/micropython/micropython.git
synced 2025-12-23 13:20:13 +01:00
Compare commits
214 Commits
parse-byte
...
v1.9.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe45d78b1e | ||
|
|
5ae9586541 | ||
|
|
80e3f07e7f | ||
|
|
02b4b23319 | ||
|
|
b81fbf938f | ||
|
|
4dd523adbb | ||
|
|
6fb093282b | ||
|
|
10b76a9620 | ||
|
|
74ec52d857 | ||
|
|
05a2bb888f | ||
|
|
8f9af63c20 | ||
|
|
24c8eda744 | ||
|
|
0e80f345f8 | ||
|
|
9b9dbc5815 | ||
|
|
b9923262db | ||
|
|
c64eb4f8ce | ||
|
|
a33fca99a1 | ||
|
|
d1cd533134 | ||
|
|
f36975b679 | ||
|
|
328c1e78be | ||
|
|
9a7e3469b2 | ||
|
|
f4059dcc0c | ||
|
|
cfff12612f | ||
|
|
9956fd0710 | ||
|
|
f2baa9ec24 | ||
|
|
93ce125abe | ||
|
|
d6bf3658f4 | ||
|
|
0eb333e3cf | ||
|
|
9725a654bd | ||
|
|
c53ca32561 | ||
|
|
8fa3d2996c | ||
|
|
285ac58532 | ||
|
|
d90ade5e3e | ||
|
|
06f2fdbe61 | ||
|
|
e36821a766 | ||
|
|
c0ea91bc89 | ||
|
|
73e387cff6 | ||
|
|
5c437963d7 | ||
|
|
0a30ad96c8 | ||
|
|
5d7b0b237b | ||
|
|
65ba481cb0 | ||
|
|
829c329daf | ||
|
|
37282f8fc1 | ||
|
|
e39fcda8eb | ||
|
|
7c7c7b161d | ||
|
|
c59fc1419d | ||
|
|
a3afa8cfc4 | ||
|
|
1b7d6a7951 | ||
|
|
b1457db002 | ||
|
|
69da74e538 | ||
|
|
dc948e4d54 | ||
|
|
08a196697c | ||
|
|
81a06d2c9c | ||
|
|
d8d4e4dfbe | ||
|
|
25e140652b | ||
|
|
f599a38059 | ||
|
|
dc92f1c4ee | ||
|
|
d236d0c415 | ||
|
|
933eab46fc | ||
|
|
add933feaf | ||
|
|
6db132e130 | ||
|
|
53966fd9a8 | ||
|
|
c15be989ee | ||
|
|
4514f073c1 | ||
|
|
71c1a05d88 | ||
|
|
58ea239510 | ||
|
|
6f1a615427 | ||
|
|
ca2427c313 | ||
|
|
7df4083ac6 | ||
|
|
ea6692a83e | ||
|
|
98dd126e98 | ||
|
|
8c7db42ee3 | ||
|
|
ff93fd4f50 | ||
|
|
36f7952f76 | ||
|
|
0864a6957f | ||
|
|
f869d6b2e3 | ||
|
|
23faf88cab | ||
|
|
dfa563c71f | ||
|
|
a3dc1b1957 | ||
|
|
6c82cfc089 | ||
|
|
9e0cdb22f1 | ||
|
|
3289b9b7a7 | ||
|
|
b00040c43c | ||
|
|
54acd0b0f0 | ||
|
|
1394258f37 | ||
|
|
2ac1364688 | ||
|
|
01978648fd | ||
|
|
8e0b9f495b | ||
|
|
aba1f9167a | ||
|
|
c9a0b2a818 | ||
|
|
2f7827ba8f | ||
|
|
bdc6e86e07 | ||
|
|
62849b7010 | ||
|
|
9d836fedbd | ||
|
|
f008263022 | ||
|
|
8fa03fee77 | ||
|
|
d29b709642 | ||
|
|
4a314a6f63 | ||
|
|
8edc2e4b14 | ||
|
|
d36539df06 | ||
|
|
e2ba45c35f | ||
|
|
f7f4bf0321 | ||
|
|
db7f4aa2cb | ||
|
|
dbff0164b3 | ||
|
|
0ea73d2da7 | ||
|
|
f8f17f48c5 | ||
|
|
35e3435f6e | ||
|
|
b3b922f177 | ||
|
|
e04b478050 | ||
|
|
77e1da40e2 | ||
|
|
980b33177b | ||
|
|
ede8a0235b | ||
|
|
7885a425d7 | ||
|
|
96fd80db13 | ||
|
|
347de3e218 | ||
|
|
78602a217f | ||
|
|
fc9a6dd09e | ||
|
|
44f0a4d1e7 | ||
|
|
fdb2aa81b7 | ||
|
|
9dce823cfd | ||
|
|
72491b3e40 | ||
|
|
75163325ae | ||
|
|
280fb4d928 | ||
|
|
89f657f073 | ||
|
|
aca498c2b0 | ||
|
|
d42b89bc3a | ||
|
|
d7cd1d2027 | ||
|
|
da8c4c2653 | ||
|
|
b02be234e1 | ||
|
|
52620c6b0e | ||
|
|
eea5fcc442 | ||
|
|
6e06512e0f | ||
|
|
f54b3527f2 | ||
|
|
d1f909005a | ||
|
|
c46d480adc | ||
|
|
d6f9d64d97 | ||
|
|
eb84a830df | ||
|
|
de981040b3 | ||
|
|
9355cca610 | ||
|
|
e41bc3fcbb | ||
|
|
9b4666dad5 | ||
|
|
5671a11b81 | ||
|
|
bd71b3252a | ||
|
|
e6fbee0981 | ||
|
|
da1c80d850 | ||
|
|
cc7fece309 | ||
|
|
0708dd495f | ||
|
|
19f1b39d6f | ||
|
|
b8ee7ab5b9 | ||
|
|
c460f6f15a | ||
|
|
6d4cac088e | ||
|
|
50b9329eba | ||
|
|
d4d1c45a55 | ||
|
|
5c603bd0fd | ||
|
|
beeb7483d8 | ||
|
|
68c28174d0 | ||
|
|
069fc48bf6 | ||
|
|
21c889baeb | ||
|
|
81375eb470 | ||
|
|
3101a8fe32 | ||
|
|
f1dd0fd7df | ||
|
|
4a93801c12 | ||
|
|
01dd7804b8 | ||
|
|
a9862b3006 | ||
|
|
1aaba5cabe | ||
|
|
e354b0a0cb | ||
|
|
376618cd8a | ||
|
|
60749e57f2 | ||
|
|
77a48e8cd4 | ||
|
|
98da3cf407 | ||
|
|
689dae1211 | ||
|
|
ab9d7619fc | ||
|
|
d4b75f6b68 | ||
|
|
9950865c39 | ||
|
|
dd376a239d | ||
|
|
860eeeea9b | ||
|
|
1ee6c3771f | ||
|
|
bebff0dab0 | ||
|
|
2daacc5cee | ||
|
|
79d5acbd01 | ||
|
|
793d826d9d | ||
|
|
b349479a49 | ||
|
|
ca21aed0a1 | ||
|
|
6c9fca2aa9 | ||
|
|
0e420d48ee | ||
|
|
09547f0f51 | ||
|
|
4556bd2acd | ||
|
|
35be9e805f | ||
|
|
b565c36963 | ||
|
|
df6605eaba | ||
|
|
0102ee092b | ||
|
|
71c9cfb028 | ||
|
|
784909ce16 | ||
|
|
8388ec4e35 | ||
|
|
fe6f0354f6 | ||
|
|
e30ba2f1c7 | ||
|
|
6568001c00 | ||
|
|
293e81f31e | ||
|
|
05eba60d84 | ||
|
|
904eb2d9f3 | ||
|
|
58321dd985 | ||
|
|
be8e5744e6 | ||
|
|
613510bce8 | ||
|
|
d5336ba136 | ||
|
|
37379a2974 | ||
|
|
c5c095690f | ||
|
|
358a7ba014 | ||
|
|
7e6881cf7d | ||
|
|
3e1412a1fb | ||
|
|
a8052d343c | ||
|
|
41b4686dd7 | ||
|
|
b84268d49c | ||
|
|
fc483706d3 | ||
|
|
49316b864b |
23
.gitattributes
vendored
23
.gitattributes
vendored
@@ -15,16 +15,13 @@
|
||||
# These should also not be modified by git.
|
||||
tests/basics/string_cr_conversion.py -text
|
||||
tests/basics/string_crlf_conversion.py -text
|
||||
stmhal/pybcdc.inf_template -text
|
||||
stmhal/usbd_* -text
|
||||
stmhal/boards/*/stm32f4xx_hal_conf.h -text
|
||||
stmhal/cmsis/** -text
|
||||
stmhal/hal/** -text
|
||||
stmhal/usbdev/** -text
|
||||
stmhal/usbhost/** -text
|
||||
cc3200/hal/aes.c -text
|
||||
cc3200/hal/aes.h -text
|
||||
cc3200/hal/des.c -text
|
||||
cc3200/hal/i2s.c -text
|
||||
cc3200/hal/i2s.h -text
|
||||
cc3200/version.h -text
|
||||
ports/stm32/pybcdc.inf_template -text
|
||||
ports/stm32/usbd_* -text
|
||||
ports/stm32/usbdev/** -text
|
||||
ports/stm32/usbhost/** -text
|
||||
ports/cc3200/hal/aes.c -text
|
||||
ports/cc3200/hal/aes.h -text
|
||||
ports/cc3200/hal/des.c -text
|
||||
ports/cc3200/hal/i2s.c -text
|
||||
ports/cc3200/hal/i2s.h -text
|
||||
ports/cc3200/version.h -text
|
||||
|
||||
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -11,3 +11,7 @@
|
||||
[submodule "lib/berkeley-db-1.xx"]
|
||||
path = lib/berkeley-db-1.xx
|
||||
url = https://github.com/pfalcon/berkeley-db-1.xx
|
||||
[submodule "lib/stm32lib"]
|
||||
path = lib/stm32lib
|
||||
url = https://github.com/micropython/stm32lib
|
||||
branch = work-F4-1.13.1+F7-1.5.0+L4-1.3.0
|
||||
|
||||
51
.travis.yml
51
.travis.yml
@@ -19,49 +19,48 @@ before_script:
|
||||
- sudo apt-get install -y --force-yes gcc-arm-none-eabi
|
||||
# For teensy build
|
||||
- sudo apt-get install realpath
|
||||
# For coverage testing
|
||||
# cpp-coveralls 0.4 conflicts with urllib3 preinstalled in Travis VM
|
||||
- sudo pip install cpp-coveralls==0.3.12
|
||||
# For coverage testing (upgrade is used to get latest urllib3 version)
|
||||
- sudo pip install --upgrade cpp-coveralls
|
||||
- gcc --version
|
||||
- arm-none-eabi-gcc --version
|
||||
- python3 --version
|
||||
|
||||
script:
|
||||
- make -C mpy-cross
|
||||
- make -C minimal CROSS=1 build/firmware.bin
|
||||
- ls -l minimal/build/firmware.bin
|
||||
- make -C ports/minimal CROSS=1 build/firmware.bin
|
||||
- ls -l ports/minimal/build/firmware.bin
|
||||
- tools/check_code_size.sh
|
||||
- mkdir -p ${HOME}/persist
|
||||
# Save new firmware for reference, but only if building a main branch, not a pull request
|
||||
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then cp minimal/build/firmware.bin ${HOME}/persist/; fi'
|
||||
- make -C unix deplibs
|
||||
- make -C unix
|
||||
- make -C unix nanbox
|
||||
- make -C bare-arm
|
||||
- make -C qemu-arm test
|
||||
- make -C stmhal
|
||||
- make -C stmhal BOARD=PYBV11 MICROPY_PY_WIZNET5K=1 MICROPY_PY_CC3K=1
|
||||
- make -C stmhal BOARD=STM32F769DISC
|
||||
- make -C stmhal BOARD=STM32L476DISC
|
||||
- make -C teensy
|
||||
- make -C cc3200 BTARGET=application BTYPE=release
|
||||
- make -C cc3200 BTARGET=bootloader BTYPE=release
|
||||
- make -C windows CROSS_COMPILE=i686-w64-mingw32-
|
||||
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then cp ports/minimal/build/firmware.bin ${HOME}/persist/; fi'
|
||||
- make -C ports/unix deplibs
|
||||
- make -C ports/unix
|
||||
- make -C ports/unix nanbox
|
||||
- make -C ports/bare-arm
|
||||
- make -C ports/qemu-arm test
|
||||
- make -C ports/stm32
|
||||
- make -C ports/stm32 BOARD=PYBV11 MICROPY_PY_WIZNET5K=5200 MICROPY_PY_CC3K=1
|
||||
- make -C ports/stm32 BOARD=STM32F769DISC
|
||||
- make -C ports/stm32 BOARD=STM32L476DISC
|
||||
- make -C ports/teensy
|
||||
- make -C ports/cc3200 BTARGET=application BTYPE=release
|
||||
- make -C ports/cc3200 BTARGET=bootloader BTYPE=release
|
||||
- make -C ports/windows CROSS_COMPILE=i686-w64-mingw32-
|
||||
|
||||
# run tests without coverage info
|
||||
#- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests)
|
||||
#- (cd tests && MICROPY_CPYTHON3=python3.4 ./run-tests --emit native)
|
||||
|
||||
# run tests with coverage info
|
||||
- make -C unix coverage
|
||||
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests)
|
||||
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests -d thread)
|
||||
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests --emit native)
|
||||
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../unix/micropython_coverage ./run-tests --via-mpy -d basics float)
|
||||
- make -C ports/unix coverage
|
||||
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests)
|
||||
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -d thread)
|
||||
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --emit native)
|
||||
- (cd tests && MICROPY_CPYTHON3=python3.4 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests --via-mpy -d basics float)
|
||||
|
||||
# run coveralls coverage analysis (try to, even if some builds/tests failed)
|
||||
- (cd unix && coveralls --root .. --build-root . --gcov $(which gcov) --gcov-options '\-o build-coverage/' --include py --include extmod)
|
||||
- (cd ports/unix && coveralls --root ../.. --build-root . --gcov $(which gcov) --gcov-options '\-o build-coverage/' --include py --include extmod)
|
||||
|
||||
after_failure:
|
||||
- (cd tests && for exp in *.exp; do testbase=$(basename $exp .exp); echo -e "\nFAILURE $testbase"; diff -u $testbase.exp $testbase.out; done)
|
||||
- (grep "FAIL" qemu-arm/build/console.out)
|
||||
- (grep "FAIL" ports/qemu-arm/build/console.out)
|
||||
|
||||
74
README.md
74
README.md
@@ -34,10 +34,10 @@ Major components in this repository:
|
||||
core library.
|
||||
- mpy-cross/ -- the MicroPython cross-compiler which is used to turn scripts
|
||||
into precompiled bytecode.
|
||||
- unix/ -- a version of MicroPython that runs on Unix.
|
||||
- stmhal/ -- a version of MicroPython that runs on the PyBoard and similar
|
||||
- ports/unix/ -- a version of MicroPython that runs on Unix.
|
||||
- ports/stm32/ -- a version of MicroPython that runs on the PyBoard and similar
|
||||
STM32 boards (using ST's Cube HAL drivers).
|
||||
- minimal/ -- a minimal MicroPython port. Start with this if you want
|
||||
- ports/minimal/ -- a minimal MicroPython port. Start with this if you want
|
||||
to port MicroPython to another microcontroller.
|
||||
- tests/ -- test framework and test scripts.
|
||||
- docs/ -- user documentation in Sphinx reStructuredText format. Rendered
|
||||
@@ -45,13 +45,13 @@ Major components in this repository:
|
||||
to select needed board/port at the bottom left corner).
|
||||
|
||||
Additional components:
|
||||
- bare-arm/ -- a bare minimum version of MicroPython for ARM MCUs. Used
|
||||
- ports/bare-arm/ -- a bare minimum version of MicroPython for ARM MCUs. Used
|
||||
mostly to control code size.
|
||||
- teensy/ -- a version of MicroPython that runs on the Teensy 3.1
|
||||
- ports/teensy/ -- a version of MicroPython that runs on the Teensy 3.1
|
||||
(preliminary but functional).
|
||||
- pic16bit/ -- a version of MicroPython for 16-bit PIC microcontrollers.
|
||||
- cc3200/ -- a version of MicroPython that runs on the CC3200 from TI.
|
||||
- esp8266/ -- an experimental port for ESP8266 WiFi modules.
|
||||
- ports/pic16bit/ -- a version of MicroPython for 16-bit PIC microcontrollers.
|
||||
- ports/cc3200/ -- a version of MicroPython that runs on the CC3200 from TI.
|
||||
- ports/esp8266/ -- an experimental port for ESP8266 WiFi modules.
|
||||
- extmod/ -- additional (non-core) modules implemented in C.
|
||||
- tools/ -- various tools, including the pyboard.py module.
|
||||
- examples/ -- a few example Python scripts.
|
||||
@@ -59,7 +59,7 @@ Additional components:
|
||||
The subdirectories above may include READMEs with additional info.
|
||||
|
||||
"make" is used to build the components, or "gmake" on BSD-based systems.
|
||||
You will also need bash and Python (at least 2.7 or 3.3).
|
||||
You will also need bash, gcc, and Python (at least 2.7 or 3.3).
|
||||
|
||||
The Unix version
|
||||
----------------
|
||||
@@ -72,7 +72,8 @@ Alternatively, fallback implementation based on setjmp/longjmp can be used.
|
||||
|
||||
To build (see section below for required dependencies):
|
||||
|
||||
$ cd unix
|
||||
$ git submodule update --init
|
||||
$ cd ports/unix
|
||||
$ make axtls
|
||||
$ make
|
||||
|
||||
@@ -104,44 +105,49 @@ Standard library modules come from
|
||||
External dependencies
|
||||
---------------------
|
||||
|
||||
Building Unix version requires some dependencies installed. For
|
||||
Building MicroPython ports may require some dependencies installed.
|
||||
|
||||
For Unix port, `libffi` library and `pkg-config` tool are required. On
|
||||
Debian/Ubuntu/Mint derivative Linux distros, install `build-essential`
|
||||
(includes toolchain and make), `libffi-dev`, and `pkg-config` packages.
|
||||
|
||||
Other dependencies can be built together with MicroPython. Oftentimes,
|
||||
you need to do this to enable extra features or capabilities. To build
|
||||
Other dependencies can be built together with MicroPython. This may
|
||||
be required to enable extra features or capabilities, and in recent
|
||||
versions of MicroPython, these may be enabled by default. To build
|
||||
these additional dependencies, first fetch git submodules for them:
|
||||
|
||||
$ git submodule update --init
|
||||
|
||||
Use this same command to get the latest versions of dependencies, as
|
||||
they are updated from time to time. After that, in `unix/` dir, execute:
|
||||
Use the same command to get the latest versions of dependencies, as
|
||||
they are updated from time to time. After that, in the port directory
|
||||
(e.g. `ports/unix/`), execute:
|
||||
|
||||
$ make deplibs
|
||||
|
||||
This will build all available dependencies (regardless whether they
|
||||
are used or not). If you intend to build MicroPython with additional
|
||||
options (like cross-compiling), the same set of options should be passed
|
||||
to `make deplibs`. To actually enabled use of dependencies, edit
|
||||
`unix/mpconfigport.mk` file, which has inline descriptions of the options.
|
||||
For example, to build SSL module (required for `upip` tool described above),
|
||||
set `MICROPY_PY_USSL` to 1.
|
||||
to `make deplibs`. To actually enable/disable use of dependencies, edit
|
||||
`ports/unix/mpconfigport.mk` file, which has inline descriptions of the options.
|
||||
For example, to build SSL module (required for `upip` tool described above,
|
||||
and so enabled by dfeault), `MICROPY_PY_USSL` should be set to 1.
|
||||
|
||||
In `unix/mpconfigport.mk`, you can also disable some dependencies enabled
|
||||
by default, like FFI support, which requires libffi development files to
|
||||
be installed.
|
||||
For some ports, building required dependences is transparent, and happens
|
||||
automatically. They still need to be fetched with the git submodule command
|
||||
above.
|
||||
|
||||
The STM version
|
||||
---------------
|
||||
The STM32 version
|
||||
-----------------
|
||||
|
||||
The "stmhal" port requires an ARM compiler, arm-none-eabi-gcc, and associated
|
||||
bin-utils. For those using Arch Linux, you need arm-none-eabi-binutils and
|
||||
arm-none-eabi-gcc packages. Otherwise, try here:
|
||||
The "stm32" port requires an ARM compiler, arm-none-eabi-gcc, and associated
|
||||
bin-utils. For those using Arch Linux, you need arm-none-eabi-binutils,
|
||||
arm-none-eabi-gcc and arm-none-eabi-newlib packages. Otherwise, try here:
|
||||
https://launchpad.net/gcc-arm-embedded
|
||||
|
||||
To build:
|
||||
|
||||
$ cd stmhal
|
||||
$ git submodule update --init
|
||||
$ cd ports/stm32
|
||||
$ make
|
||||
|
||||
You then need to get your board into DFU mode. On the pyboard, connect the
|
||||
@@ -155,4 +161,14 @@ Then to flash the code via USB DFU to your device:
|
||||
This will use the included `tools/pydfu.py` script. If flashing the firmware
|
||||
does not work it may be because you don't have the correct permissions, and
|
||||
need to use `sudo make deploy`.
|
||||
See the README.md file in the stmhal/ directory for further details.
|
||||
See the README.md file in the ports/stm32/ directory for further details.
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
MicroPython is an open-source project and welcomes contributions. To be
|
||||
productive, please be sure to follow the
|
||||
[Contributors' Guidelines](https://github.com/micropython/micropython/wiki/ContributorGuidelines)
|
||||
and the [Code Conventions](https://github.com/micropython/micropython/blob/master/CODECONVENTIONS.md).
|
||||
Note that MicroPython is licenced under the MIT license, and all contributions
|
||||
should follow this license.
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013, 2014 Damien P. George
|
||||
* Copyright (c) 2015 Daniel Campora
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/mpstate.h"
|
||||
#include "mpexception.h"
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
STATIC void mpexception_set_user_interrupt (int chr, void *data);
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE EXPORTED DATA
|
||||
******************************************************************************/
|
||||
const char mpexception_value_invalid_arguments[] = "invalid argument(s) value";
|
||||
const char mpexception_num_type_invalid_arguments[] = "invalid argument(s) num/type";
|
||||
const char mpexception_uncaught[] = "uncaught exception";
|
||||
|
||||
int user_interrupt_char = -1;
|
||||
|
||||
/******************************************************************************
|
||||
DECLARE PRIVATE DATA
|
||||
******************************************************************************/
|
||||
STATIC void *user_interrupt_data = NULL;
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
void mpexception_init0 (void) {
|
||||
// Create an exception object for interrupting through the stdin uart
|
||||
MP_STATE_PORT(mp_const_user_interrupt) = mp_obj_new_exception(&mp_type_KeyboardInterrupt);
|
||||
mpexception_set_user_interrupt (-1, MP_STATE_PORT(mp_const_user_interrupt));
|
||||
}
|
||||
|
||||
void mpexception_set_interrupt_char (int c) {
|
||||
if (c != -1) {
|
||||
mp_obj_exception_clear_traceback(MP_STATE_PORT(mp_const_user_interrupt));
|
||||
}
|
||||
mpexception_set_user_interrupt(c, MP_STATE_PORT(mp_const_user_interrupt));
|
||||
}
|
||||
|
||||
// Call this function to raise a pending exception during an interrupt.
|
||||
// It will try to raise the exception "softly" by setting the
|
||||
// mp_pending_exception variable hoping that the VM will notice it.
|
||||
void mpexception_nlr_jump (void *o) {
|
||||
if (MP_STATE_PORT(mp_pending_exception) == MP_OBJ_NULL) {
|
||||
MP_STATE_PORT(mp_pending_exception) = o;
|
||||
}
|
||||
}
|
||||
|
||||
void mpexception_keyboard_nlr_jump (void) {
|
||||
mpexception_nlr_jump (user_interrupt_data);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
STATIC void mpexception_set_user_interrupt (int chr, void *data) {
|
||||
user_interrupt_char = chr;
|
||||
user_interrupt_data = data;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ copyright = '2014-2017, Damien P. George, Paul Sokolovsky, and contributors'
|
||||
#
|
||||
# We don't follow "The short X.Y version" vs "The full version, including alpha/beta/rc tags"
|
||||
# breakdown, so use the same version identifier for both to avoid confusion.
|
||||
version = release = '1.9.2'
|
||||
version = release = '1.9.3'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
||||
@@ -145,3 +145,43 @@ or by an exeption, for example using try/finally::
|
||||
# Use sock
|
||||
finally:
|
||||
sock.close()
|
||||
|
||||
|
||||
SSL/TLS limitations
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
ESP8266 uses `axTLS <http://axtls.sourceforge.net/>`_ library, which is one
|
||||
of the smallest TLS libraries with the compatible licensing. However, it
|
||||
also has some known issues/limitations:
|
||||
|
||||
1. No support for Diffie-Hellman (DH) key exchange and Elliptic-curve
|
||||
cryptography (ECC). This means it can't work with sites which force
|
||||
the use of these features (it works ok with classic RSA certifactes).
|
||||
2. Half-duplex communication nature. axTLS uses a single buffer for both
|
||||
sending and receiving, which leads to considerable memory saving and
|
||||
works well with protocols like HTTP. But there may be problems with
|
||||
protocols which don't follow classic request-response model.
|
||||
|
||||
Besides axTLS own limitations, the configuration used for MicroPython is
|
||||
highly optimized for code size, which leads to additional limitations
|
||||
(these may be lifted in the future):
|
||||
|
||||
3. Optimized RSA algorithms are not enabled, which may lead to slow
|
||||
SSL handshakes.
|
||||
4. Stored sessions are not supported (may allow faster repeated connections
|
||||
to the same site in some circumstances).
|
||||
|
||||
Besides axTLS specific limitations described above, there's another generic
|
||||
limitation with usage of TLS on the low-memory devices:
|
||||
|
||||
5. The TLS standard specifies the maximum length of the TLS record (unit
|
||||
of TLS communication, the entire record must be buffered before it can
|
||||
be processed) as 16KB. That's almost half of the available ESP8266 memory,
|
||||
and inside a more or less advanced application would be hard to allocate
|
||||
due to memory fragmentation issues. As a compromise, a smaller buffer is
|
||||
used, with the idea that the most interesting usage for SSL would be
|
||||
accessing various REST APIs, which usually require much smaller messages.
|
||||
The buffers size is on the order of 5KB, and is adjusted from time to
|
||||
time, taking as a reference being able to access https://google.com .
|
||||
The smaller buffer hower means that some sites can't be accessed using
|
||||
it, and it's not possible to stream large amounts of data.
|
||||
|
||||
@@ -223,6 +223,17 @@ and is accessed via the :ref:`machine.I2C <machine.I2C>` class::
|
||||
buf = bytearray(10) # create a buffer with 10 bytes
|
||||
i2c.writeto(0x3a, buf) # write the given buffer to the slave
|
||||
|
||||
Real time clock (RTC)
|
||||
---------------------
|
||||
|
||||
See :ref:`machine.RTC <machine.RTC>` ::
|
||||
|
||||
from machine import RTC
|
||||
|
||||
rtc = RTC()
|
||||
rtc.datetime((2017, 8, 23, 1, 12, 48, 0, 0)) # set a specific date and time
|
||||
rtc.datetime() # get date and time
|
||||
|
||||
Deep-sleep mode
|
||||
---------------
|
||||
|
||||
|
||||
@@ -20,6 +20,20 @@ To set the colour of pixels use::
|
||||
>>> np[1] = (0, 128, 0) # set to green, half brightness
|
||||
>>> np[2] = (0, 0, 64) # set to blue, quarter brightness
|
||||
|
||||
For LEDs with more than 3 colours, such as RGBW pixels or RGBY pixels, the
|
||||
NeoPixel class takes a ``bpp`` parameter. To setup a NeoPixel object for an
|
||||
RGBW Pixel, do the following::
|
||||
|
||||
>>> import machine, neopixel
|
||||
>>> np = neopixel.NeoPixel(machine.Pin(4), 8, bpp=4)
|
||||
|
||||
In a 4-bpp mode, remember to use 4-tuples instead of 3-tuples to set the colour.
|
||||
For example to set the first three pixels use::
|
||||
|
||||
>>> np[0] = (255, 0, 0, 128) # Orange in an RGBY Setup
|
||||
>>> np[1] = (0, 255, 0, 128) # Yellow-green in an RGBY Setup
|
||||
>>> np[2] = (0, 0, 255, 128) # Green-blue in an RGBY Setup
|
||||
|
||||
Then use the ``write()`` method to output the colours to the LEDs::
|
||||
|
||||
>>> np.write()
|
||||
|
||||
@@ -76,20 +76,24 @@ Example::
|
||||
Functions
|
||||
---------
|
||||
|
||||
.. function:: open(stream, \*, flags=0, cachesize=0, pagesize=0, minkeypage=0)
|
||||
.. function:: open(stream, \*, flags=0, pagesize=0, cachesize=0, minkeypage=0)
|
||||
|
||||
Open a database from a random-access `stream` (like an open file). All
|
||||
other parameters are optional and keyword-only, and allow to tweak advanced
|
||||
parameters of the database operation (most users will not need them):
|
||||
|
||||
* *flags* - Currently unused.
|
||||
* *cachesize* - Suggested maximum memory cache size in bytes. For a
|
||||
board with enough memory using larger values may improve performance.
|
||||
The value is only a recommendation, the module may use more memory if
|
||||
values set too low.
|
||||
* *pagesize* - Page size used for the nodes in BTree. Acceptable range
|
||||
is 512-65536. If 0, underlying I/O block size will be used (the best
|
||||
compromise between memory usage and performance).
|
||||
is 512-65536. If 0, a port-specific default will be used, optimized for
|
||||
port's memory usage and/or performance.
|
||||
* *cachesize* - Suggested memory cache size in bytes. For a
|
||||
board with enough memory using larger values may improve performance.
|
||||
Cache policy is as follows: entire cache is not allocated at once;
|
||||
instead, accessing a new page in database will allocate a memory buffer
|
||||
for it, until value specified by *cachesize* is reached. Then, these
|
||||
buffers will be managed using LRU (least recently used) policy. More
|
||||
buffers may still be allocated if needed (e.g., if a database contains
|
||||
big keys and/or values). Allocated cache buffers aren't reclaimed.
|
||||
* *minkeypage* - Minimum number of keys to store per page. Default value
|
||||
of 0 equivalent to 2.
|
||||
|
||||
|
||||
@@ -38,9 +38,9 @@ Constructors
|
||||
- *width* is the width of the FrameBuffer in pixels
|
||||
- *height* is the height of the FrameBuffer in pixels
|
||||
- *format* specifies the type of pixel used in the FrameBuffer;
|
||||
valid values are ``framebuf.MVLSB``, ``framebuf.RGB565``
|
||||
and ``framebuf.GS4_HMSB``. MVLSB is monochrome 1-bit color,
|
||||
RGB565 is RGB 16-bit color, and GS4_HMSB is grayscale 4-bit color.
|
||||
permissible values are listed under Constants below. These set the
|
||||
number of bits used to encode a color value and the layout of these
|
||||
bits in *buffer*.
|
||||
Where a color value c is passed to a method, c is a small integer
|
||||
with an encoding that is dependent on the format of the FrameBuffer.
|
||||
- *stride* is the number of pixels between each horizontal line
|
||||
@@ -110,8 +110,9 @@ Other methods
|
||||
corresponding color will be considered transparent: all pixels with that
|
||||
color value will not be drawn.
|
||||
|
||||
This method works between FrameBuffer's utilising different formats, but the
|
||||
resulting colors may be unexpected due to the mismatch in color formats.
|
||||
This method works between FrameBuffer instances utilising different formats,
|
||||
but the resulting colors may be unexpected due to the mismatch in color
|
||||
formats.
|
||||
|
||||
Constants
|
||||
---------
|
||||
|
||||
@@ -4,17 +4,44 @@
|
||||
class Signal -- control and sense external I/O devices
|
||||
======================================================
|
||||
|
||||
The Signal class is a simple extension of Pin class. Unlike Pin, which
|
||||
The Signal class is a simple extension of the `Pin` class. Unlike Pin, which
|
||||
can be only in "absolute" 0 and 1 states, a Signal can be in "asserted"
|
||||
(on) or "deasserted" (off) states, while being inverted (active-low) or
|
||||
not. Summing up, it adds logical inversion support to Pin functionality.
|
||||
not. In other words, it adds logical inversion support to Pin functionality.
|
||||
While this may seem a simple addition, it is exactly what is needed to
|
||||
support wide array of simple digital devices in a way portable across
|
||||
different boards, which is one of the major MicroPython goals. Regardless
|
||||
whether different users have an active-high or active-low LED, a normally
|
||||
open or normally closed relay - you can develop single, nicely looking
|
||||
of whether different users have an active-high or active-low LED, a normally
|
||||
open or normally closed relay - you can develop a single, nicely looking
|
||||
application which works with each of them, and capture hardware
|
||||
configuration differences in few lines on the config file of your app.
|
||||
configuration differences in few lines in the config file of your app.
|
||||
|
||||
Example::
|
||||
|
||||
from machine import Pin, Signal
|
||||
|
||||
# Suppose you have an active-high LED on pin 0
|
||||
led1_pin = Pin(0, Pin.OUT)
|
||||
# ... and active-low LED on pin 1
|
||||
led2_pin = Pin(1, Pin.OUT)
|
||||
|
||||
# Now to light up both of them using Pin class, you'll need to set
|
||||
# them to different values
|
||||
led1_pin.value(1)
|
||||
led2_pin.value(0)
|
||||
|
||||
# Signal class allows to abstract away active-high/active-low
|
||||
# difference
|
||||
led1 = Signal(led1_pin, invert=False)
|
||||
led2 = Signal(led2_pin, invert=True)
|
||||
|
||||
# Now lighting up them looks the same
|
||||
led1.value(1)
|
||||
led2.value(1)
|
||||
|
||||
# Even better:
|
||||
led1.on()
|
||||
led2.on()
|
||||
|
||||
Following is the guide when Signal vs Pin should be used:
|
||||
|
||||
@@ -33,11 +60,11 @@ architecture of MicroPython: Pin offers the lowest overhead, which may
|
||||
be important when bit-banging protocols. But Signal adds additional
|
||||
flexibility on top of Pin, at the cost of minor overhead (much smaller
|
||||
than if you implemented active-high vs active-low device differences in
|
||||
Python manually!). Also, Pin is low-level object which needs to be
|
||||
Python manually!). Also, Pin is a low-level object which needs to be
|
||||
implemented for each support board, while Signal is a high-level object
|
||||
which comes for free once Pin is implemented.
|
||||
|
||||
If in doubt, give the Signal a try! Once again, it is developed to save
|
||||
If in doubt, give the Signal a try! Once again, it is offered to save
|
||||
developers from the need to handle unexciting differences like active-low
|
||||
vs active-high signals, and allow other users to share and enjoy your
|
||||
application, instead of being frustrated by the fact that it doesn't
|
||||
|
||||
@@ -46,7 +46,7 @@ Functions
|
||||
|
||||
.. function:: mem_info([verbose])
|
||||
|
||||
Print information about currently used memory. If the *verbose`* argument
|
||||
Print information about currently used memory. If the *verbose* argument
|
||||
is given then extra information is printed.
|
||||
|
||||
The information that is printed is implementation dependent, but currently
|
||||
|
||||
@@ -9,7 +9,7 @@ This module provides network drivers and routing configuration. To use this
|
||||
module, a MicroPython variant/build with network capabilities must be installed.
|
||||
Network drivers for specific hardware are available within this module and are
|
||||
used to configure hardware network interface(s). Network services provided
|
||||
by configured interfaces are then available for use via the :mod:`socket`
|
||||
by configured interfaces are then available for use via the :mod:`usocket`
|
||||
module.
|
||||
|
||||
For example::
|
||||
@@ -39,9 +39,9 @@ Common network adapter interface
|
||||
================================
|
||||
|
||||
This section describes an (implied) abstract base class for all network
|
||||
interface classes implemented by different ports of MicroPython for
|
||||
different hardware. This means that MicroPython does not actually
|
||||
provide `AbstractNIC` class, but any actual NIC class, as described
|
||||
interface classes implemented by `MicroPython ports <MicroPython port>`
|
||||
for different hardware. This means that MicroPython does not actually
|
||||
provide ``AbstractNIC`` class, but any actual NIC class, as described
|
||||
in the following sections, implements methods as described here.
|
||||
|
||||
.. class:: AbstractNIC(id=None, ...)
|
||||
@@ -72,8 +72,7 @@ parameter should be `id`.
|
||||
connection parameters. For various medium types, there are different
|
||||
sets of predefined/recommended parameters, among them:
|
||||
|
||||
* WiFi: *bssid* keyword to connect by BSSID (MAC address) instead
|
||||
of access point name
|
||||
* WiFi: *bssid* keyword to connect to a specific BSSID (MAC address)
|
||||
|
||||
.. method:: disconnect()
|
||||
|
||||
@@ -225,7 +224,9 @@ parameter should be `id`.
|
||||
==============
|
||||
|
||||
This class allows you to control WIZnet5x00 Ethernet adaptors based on
|
||||
the W5200 and W5500 chipsets (only W5200 tested).
|
||||
the W5200 and W5500 chipsets. The particular chipset that is supported
|
||||
by the firmware is selected at compile-time via the MICROPY_PY_WIZNET5K
|
||||
option.
|
||||
|
||||
Example usage::
|
||||
|
||||
@@ -269,6 +270,11 @@ parameter should be `id`.
|
||||
Methods
|
||||
-------
|
||||
|
||||
.. method:: wiznet5k.isconnected()
|
||||
|
||||
Returns ``True`` if the physical Ethernet link is connected and up.
|
||||
Returns ``False`` otherwise.
|
||||
|
||||
.. method:: wiznet5k.ifconfig([(ip, subnet, gateway, dns)])
|
||||
|
||||
Get/set IP address, subnet mask, gateway and DNS.
|
||||
@@ -333,9 +339,12 @@ parameter should be `id`.
|
||||
argument is passed. Otherwise, query current state if no argument is
|
||||
provided. Most other methods require active interface.
|
||||
|
||||
.. method:: wlan.connect(ssid, password)
|
||||
.. method:: wlan.connect(ssid=None, password=None, \*, bssid=None)
|
||||
|
||||
Connect to the specified wireless network, using the specified password.
|
||||
If *bssid* is given then the connection will be restricted to the
|
||||
access-point with that MAC address (the *ssid* must also be specified
|
||||
in this case).
|
||||
|
||||
.. method:: wlan.disconnect()
|
||||
|
||||
@@ -411,18 +420,19 @@ parameter should be `id`.
|
||||
print(ap.config('channel'))
|
||||
|
||||
Following are commonly supported parameters (availability of a specific parameter
|
||||
depends on network technology type, driver, and MicroPython port).
|
||||
depends on network technology type, driver, and `MicroPython port`).
|
||||
|
||||
========= ===========
|
||||
Parameter Description
|
||||
========= ===========
|
||||
mac MAC address (bytes)
|
||||
essid WiFi access point name (string)
|
||||
channel WiFi channel (integer)
|
||||
hidden Whether ESSID is hidden (boolean)
|
||||
authmode Authentication mode supported (enumeration, see module constants)
|
||||
password Access password (string)
|
||||
========= ===========
|
||||
============= ===========
|
||||
Parameter Description
|
||||
============= ===========
|
||||
mac MAC address (bytes)
|
||||
essid WiFi access point name (string)
|
||||
channel WiFi channel (integer)
|
||||
hidden Whether ESSID is hidden (boolean)
|
||||
authmode Authentication mode supported (enumeration, see module constants)
|
||||
password Access password (string)
|
||||
dhcp_hostname The DHCP hostname to use
|
||||
============= ===========
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.. currentmodule:: pyb
|
||||
.. _pyb.Accel:
|
||||
|
||||
class Accel -- accelerometer control
|
||||
====================================
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.. currentmodule:: pyb
|
||||
.. _pyb.CAN:
|
||||
|
||||
class CAN -- controller area network communication bus
|
||||
======================================================
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.. currentmodule:: pyb
|
||||
.. _pyb.LCD:
|
||||
|
||||
class LCD -- LCD control for the LCD touch-sensor pyskin
|
||||
========================================================
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.. currentmodule:: pyb
|
||||
.. _pyb.Switch:
|
||||
|
||||
class Switch -- switch object
|
||||
=============================
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.. currentmodule:: pyb
|
||||
.. _pyb.USB_HID:
|
||||
|
||||
class USB_HID -- USB Human Interface Device (HID)
|
||||
=================================================
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
.. currentmodule:: pyb
|
||||
.. _pyb.USB_VCP:
|
||||
|
||||
class USB_VCP -- USB virtual comm port
|
||||
======================================
|
||||
|
||||
@@ -89,8 +89,22 @@ Functions
|
||||
Return a bytes object with n random bytes. Whenever possible, it is
|
||||
generated by the hardware random number generator.
|
||||
|
||||
.. function:: dupterm(stream_object)
|
||||
.. function:: dupterm(stream_object, index=0)
|
||||
|
||||
Duplicate or switch MicroPython terminal (the REPL) on the passed stream-like
|
||||
object. The given object must implement the ``readinto()`` and ``write()``
|
||||
methods. If ``None`` is passed, previously set redirection is cancelled.
|
||||
Duplicate or switch the MicroPython terminal (the REPL) on the given stream-like
|
||||
object. The *stream_object* argument must implement the ``readinto()`` and
|
||||
``write()`` methods. The stream should be in non-blocking mode and
|
||||
``readinto()`` should return ``None`` if there is no data available for reading.
|
||||
|
||||
After calling this function all terminal output is repeated on this stream,
|
||||
and any input that is available on the stream is passed on to the terminal input.
|
||||
|
||||
The *index* parameter should be a non-negative integer and specifies which
|
||||
duplication slot is set. A given port may implement more than one slot (slot 0
|
||||
will always be available) and in that case terminal input and output is
|
||||
duplicated on all the slots that are set.
|
||||
|
||||
If ``None`` is passed as the *stream_object* then duplication is cancelled on
|
||||
the slot given by *index*.
|
||||
|
||||
The function returns the previous stream-like object in the given slot.
|
||||
|
||||
@@ -34,6 +34,8 @@ Supported operators are:
|
||||
|
||||
``'+?'``
|
||||
|
||||
``'|'``
|
||||
|
||||
``'()'``
|
||||
Grouping. Each group is capturing (a substring it captures can be accessed
|
||||
with `match.group()` method).
|
||||
|
||||
@@ -66,12 +66,18 @@ Methods
|
||||
|
||||
Tuples returned may contain more than 2 elements as described above.
|
||||
|
||||
.. method:: poll.ipoll([timeout])
|
||||
.. method:: poll.ipoll(timeout=-1, flags=0)
|
||||
|
||||
Like :meth:`poll.poll`, but instead returns an iterator which yields
|
||||
callee-owned tuples. This function provides efficient, allocation-free
|
||||
`callee-owned tuples`. This function provides efficient, allocation-free
|
||||
way to poll on streams.
|
||||
|
||||
If *flags* is 1, one-shot behavior for events is employed: streams for
|
||||
which events happened, event mask will be automatically reset (equivalent
|
||||
to ``poll.modify(obj, 0)``), so new events for such a stream won't be
|
||||
processed until new mask is set with `poll.modify()`. This behavior is
|
||||
useful for asynchronous I/O schedulers.
|
||||
|
||||
.. admonition:: Difference to CPython
|
||||
:class: attention
|
||||
|
||||
|
||||
@@ -68,7 +68,16 @@ Functions
|
||||
|
||||
.. function:: socket(af=AF_INET, type=SOCK_STREAM, proto=IPPROTO_TCP)
|
||||
|
||||
Create a new socket using the given address family, socket type and protocol number.
|
||||
Create a new socket using the given address family, socket type and
|
||||
protocol number. Note that specifying *proto* in most cases is not
|
||||
required (and not recommended, as some MicroPython ports may omit
|
||||
``IPPROTO_*`` constants). Instead, *type* argument will select needed
|
||||
protocol automatically::
|
||||
|
||||
# Create STREAM TCP socket
|
||||
socket(AF_INET, SOCK_STREAM)
|
||||
# Create DGRAM UDP socket
|
||||
socket(AF_INET, SOCK_DGRAM)
|
||||
|
||||
.. function:: getaddrinfo(host, port)
|
||||
|
||||
@@ -80,8 +89,8 @@ Functions
|
||||
|
||||
The following example shows how to connect to a given url::
|
||||
|
||||
s = socket.socket()
|
||||
s.connect(socket.getaddrinfo('www.micropython.org', 80)[0][-1])
|
||||
s = usocket.socket()
|
||||
s.connect(usocket.getaddrinfo('www.micropython.org', 80)[0][-1])
|
||||
|
||||
.. admonition:: Difference to CPython
|
||||
:class: attention
|
||||
@@ -96,13 +105,29 @@ Functions
|
||||
from an exception object). The use of negative values is a provisional
|
||||
detail which may change in the future.
|
||||
|
||||
.. function:: inet_ntop(af, bin_addr)
|
||||
|
||||
Convert a binary network address *bin_addr* of the given address family *af*
|
||||
to a textual representation::
|
||||
|
||||
>>> usocket.inet_ntop(usocket.AF_INET, b"\x7f\0\0\1")
|
||||
'127.0.0.1'
|
||||
|
||||
.. function:: inet_pton(af, txt_addr)
|
||||
|
||||
Convert a textual network address *txt_addr* of the given address family *af*
|
||||
to a binary representation::
|
||||
|
||||
>>> usocket.inet_pton(usocket.AF_INET, "1.2.3.4")
|
||||
b'\x01\x02\x03\x04'
|
||||
|
||||
Constants
|
||||
---------
|
||||
|
||||
.. data:: AF_INET
|
||||
AF_INET6
|
||||
|
||||
Address family types. Availability depends on a particular board.
|
||||
Address family types. Availability depends on a particular `MicroPython port`.
|
||||
|
||||
.. data:: SOCK_STREAM
|
||||
SOCK_DGRAM
|
||||
@@ -112,17 +137,21 @@ Constants
|
||||
.. data:: IPPROTO_UDP
|
||||
IPPROTO_TCP
|
||||
|
||||
IP protocol numbers.
|
||||
IP protocol numbers. Availability depends on a particular `MicroPython port`.
|
||||
Note that you don't need to specify these in a call to `usocket.socket()`,
|
||||
because `SOCK_STREAM` socket type automatically selects `IPPROTO_TCP`, and
|
||||
`SOCK_DGRAM` - `IPPROTO_UDP`. Thus, the only real use of these constants
|
||||
is as an argument to `setsockopt()`.
|
||||
|
||||
.. data:: usocket.SOL_*
|
||||
|
||||
Socket option levels (an argument to `setsockopt()`). The exact
|
||||
inventory depends on a MicroPython port.
|
||||
inventory depends on a `MicroPython port`.
|
||||
|
||||
.. data:: usocket.SO_*
|
||||
|
||||
Socket options (an argument to `setsockopt()`). The exact
|
||||
inventory depends on a MicroPython port.
|
||||
inventory depends on a `MicroPython port`.
|
||||
|
||||
Constants specific to WiPy:
|
||||
|
||||
@@ -208,12 +237,30 @@ Methods
|
||||
|
||||
.. method:: socket.settimeout(value)
|
||||
|
||||
**Note**: Not every port supports this method, see below.
|
||||
|
||||
Set a timeout on blocking socket operations. The value argument can be a nonnegative floating
|
||||
point number expressing seconds, or None. If a non-zero value is given, subsequent socket operations
|
||||
will raise an `OSError` exception if the timeout period value has elapsed before the operation has
|
||||
completed. If zero is given, the socket is put in non-blocking mode. If None is given, the socket
|
||||
is put in blocking mode.
|
||||
|
||||
Not every `MicroPython port` supports this method. A more portable and
|
||||
generic solution is to use `uselect.poll` object. This allows to wait on
|
||||
multiple objects at the same time (and not just on sockets, but on generic
|
||||
stream objects which support polling). Example::
|
||||
|
||||
# Instead of:
|
||||
s.settimeout(1.0) # time in seconds
|
||||
s.read(10) # may timeout
|
||||
|
||||
# Use:
|
||||
poller = uselect.poll()
|
||||
poller.register(s, uselect.POLLIN)
|
||||
res = poller.poll(1000) # time in milliseconds
|
||||
if not res:
|
||||
# s is still not ready for input, i.e. operation timed out
|
||||
|
||||
.. admonition:: Difference to CPython
|
||||
:class: attention
|
||||
|
||||
@@ -281,7 +328,7 @@ Methods
|
||||
|
||||
Return value: number of bytes written.
|
||||
|
||||
.. exception:: socket.error
|
||||
.. exception:: usocket.error
|
||||
|
||||
MicroPython does NOT have this exception.
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ facilities for network sockets, both client-side and server-side.
|
||||
Functions
|
||||
---------
|
||||
|
||||
.. function:: ssl.wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, ca_certs=None)
|
||||
.. function:: ussl.wrap_socket(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=CERT_NONE, ca_certs=None)
|
||||
|
||||
Takes a stream *sock* (usually usocket.socket instance of ``SOCK_STREAM`` type),
|
||||
and returns an instance of ssl.SSLSocket, which wraps the underlying stream in
|
||||
@@ -23,12 +23,12 @@ Functions
|
||||
server-side SSL socket should be created from a normal socket returned from
|
||||
`accept()` on a non-SSL listening server socket.
|
||||
|
||||
Depending on the underlying module implementation for a particular board,
|
||||
some or all keyword arguments above may be not supported.
|
||||
Depending on the underlying module implementation in a particular
|
||||
`MicroPython port`, some or all keyword arguments above may be not supported.
|
||||
|
||||
.. warning::
|
||||
|
||||
Some implementations of ``ssl`` module do NOT validate server certificates,
|
||||
Some implementations of ``ussl`` module do NOT validate server certificates,
|
||||
which makes an SSL connection established prone to man-in-the-middle attacks.
|
||||
|
||||
Exceptions
|
||||
@@ -41,8 +41,8 @@ Exceptions
|
||||
Constants
|
||||
---------
|
||||
|
||||
.. data:: ssl.CERT_NONE
|
||||
ssl.CERT_OPTIONAL
|
||||
ssl.CERT_REQUIRED
|
||||
.. data:: ussl.CERT_NONE
|
||||
ussl.CERT_OPTIONAL
|
||||
ussl.CERT_REQUIRED
|
||||
|
||||
Supported values for *cert_reqs* parameter.
|
||||
|
||||
@@ -39,17 +39,32 @@ Use the :mod:`time <utime>` module::
|
||||
start = time.ticks_ms() # get value of millisecond counter
|
||||
delta = time.ticks_diff(time.ticks_ms(), start) # compute time difference
|
||||
|
||||
LEDs
|
||||
----
|
||||
Internal LEDs
|
||||
-------------
|
||||
|
||||
See :ref:`pyb.LED <pyb.LED>`. ::
|
||||
|
||||
from pyb import LED
|
||||
|
||||
led = LED(1) # red led
|
||||
led = LED(1) # 1=red, 2=green, 3=yellow, 4=blue
|
||||
led.toggle()
|
||||
led.on()
|
||||
led.off()
|
||||
|
||||
# LEDs 3 and 4 support PWM intensity (0-255)
|
||||
LED(4).intensity() # get intensity
|
||||
LED(4).intensity(128) # set intensity to half
|
||||
|
||||
Internal switch
|
||||
---------------
|
||||
|
||||
See :ref:`pyb.Switch <pyb.Switch>`. ::
|
||||
|
||||
from pyb import Switch
|
||||
|
||||
sw = Switch()
|
||||
sw.value() # returns True or False
|
||||
sw.callback(lambda: pyb.LED(1).toggle())
|
||||
|
||||
Pins and GPIO
|
||||
-------------
|
||||
@@ -99,6 +114,17 @@ See :ref:`pyb.Timer <pyb.Timer>`. ::
|
||||
tim.freq(0.5) # 0.5 Hz
|
||||
tim.callback(lambda t: pyb.LED(1).toggle())
|
||||
|
||||
RTC (real time clock)
|
||||
---------------------
|
||||
|
||||
See :ref:`pyb.RTC <pyb.RTC>` ::
|
||||
|
||||
from pyb import RTC
|
||||
|
||||
rtc = RTC()
|
||||
rtc.datetime((2017, 8, 23, 1, 12, 48, 0, 0)) # set a specific date and time
|
||||
rtc.datetime() # get date and time
|
||||
|
||||
PWM (pulse width modulation)
|
||||
----------------------------
|
||||
|
||||
@@ -167,3 +193,25 @@ See :ref:`pyb.I2C <pyb.I2C>`. ::
|
||||
i2c.recv(5, 0x42) # receive 5 bytes from slave
|
||||
i2c.mem_read(2, 0x42, 0x10) # read 2 bytes from slave 0x42, slave memory 0x10
|
||||
i2c.mem_write('xy', 0x42, 0x10) # write 2 bytes to slave 0x42, slave memory 0x10
|
||||
|
||||
CAN bus (controller area network)
|
||||
---------------------------------
|
||||
|
||||
See :ref:`pyb.CAN <pyb.CAN>`. ::
|
||||
|
||||
from pyb import CAN
|
||||
|
||||
can = CAN(1, CAN.LOOPBACK)
|
||||
can.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))
|
||||
can.send('message!', 123) # send a message with id 123
|
||||
can.recv(0) # receive message on FIFO 0
|
||||
|
||||
Internal accelerometer
|
||||
----------------------
|
||||
|
||||
See :ref:`pyb.Accel <pyb.Accel>`. ::
|
||||
|
||||
from pyb import Accel
|
||||
|
||||
accel = Accel()
|
||||
print(accel.x(), accel.y(), accel.z(), accel.tilt())
|
||||
|
||||
@@ -60,10 +60,10 @@ One problem you might find is that if you stop the script and then start it agai
|
||||
for l in leds:
|
||||
l.off()
|
||||
|
||||
The Fourth Special LED
|
||||
----------------------
|
||||
The Special LEDs
|
||||
----------------
|
||||
|
||||
The blue LED is special. As well as turning it on and off, you can control the intensity using the intensity() method. This takes a number between 0 and 255 that determines how bright it is. The following script makes the blue LED gradually brighter then turns it off again. ::
|
||||
The yellow and blue LEDs are special. As well as turning them on and off, you can control their intensity using the intensity() method. This takes a number between 0 and 255 that determines how bright it is. The following script makes the blue LED gradually brighter then turns it off again. ::
|
||||
|
||||
led = pyb.LED(4)
|
||||
intensity = 0
|
||||
@@ -72,4 +72,4 @@ The blue LED is special. As well as turning it on and off, you can control the i
|
||||
led.intensity(intensity)
|
||||
pyb.delay(20)
|
||||
|
||||
You can call intensity() on the other LEDs but they can only be off or on. 0 sets them off and any other number up to 255 turns them on.
|
||||
You can call intensity() on LEDs 1 and 2 but they can only be off or on. 0 sets them off and any other number up to 255 turns them on.
|
||||
|
||||
@@ -15,4 +15,4 @@ It's as simple as::
|
||||
if uart.any():
|
||||
usb.write(uart.read(256))
|
||||
|
||||
pass_through(pyb.USB_VCP(), pyb.UART(1, 9600))
|
||||
pass_through(pyb.USB_VCP(), pyb.UART(1, 9600, timeout=0))
|
||||
|
||||
@@ -279,7 +279,7 @@ After importing the modules, execute:
|
||||
|
||||
Then copy and paste all the Q(xxx) lines into a text editor. Check for and
|
||||
remove lines which are obviously invalid. Open the file qstrdefsport.h which
|
||||
will be found in stmhal (or the equivalent directory for the architecture in
|
||||
will be found in ports/stm32 (or the equivalent directory for the architecture in
|
||||
use). Copy and paste the corrected lines at the end of the file. Save the file,
|
||||
rebuild and flash the firmware. The outcome can be checked by importing the
|
||||
modules and again issuing:
|
||||
|
||||
@@ -56,9 +56,9 @@ Glossary
|
||||
which provides implementations for many modules from CPython's
|
||||
standard library. However, large subset of these modules require
|
||||
POSIX-like environment (Linux, MacOS, Windows may be partially
|
||||
supported), and thus would work or make sense only with MicroPython
|
||||
Unix port. Some subset of modules is however usable for baremetal ports
|
||||
too.
|
||||
supported), and thus would work or make sense only with
|
||||
`MicroPython Unix port`. Some subset of modules is however usable
|
||||
for `baremetal` ports too.
|
||||
|
||||
Unlike monolithic :term:`CPython` stdlib, micropython-lib modules
|
||||
are intended to be installed individually - either using manual
|
||||
|
||||
@@ -21,6 +21,7 @@ This summarises the points detailed below and lists the principal recommendation
|
||||
|
||||
* Keep the code as short and simple as possible.
|
||||
* Avoid memory allocation: no appending to lists or insertion into dictionaries, no floating point.
|
||||
* Consider using ``micropython.schedule`` to work around the above constraint.
|
||||
* Where an ISR returns multiple bytes use a pre-allocated ``bytearray``. If multiple integers are to be
|
||||
shared between an ISR and the main program consider an array (``array.array``).
|
||||
* Where data is shared between the main program and an ISR, consider disabling interrupts prior to accessing
|
||||
@@ -79,7 +80,7 @@ example causes two LED's to flash at different rates.
|
||||
self.led.toggle()
|
||||
|
||||
red = Foo(pyb.Timer(4, freq=1), pyb.LED(1))
|
||||
greeen = Foo(pyb.Timer(2, freq=0.8), pyb.LED(2))
|
||||
green = Foo(pyb.Timer(2, freq=0.8), pyb.LED(2))
|
||||
|
||||
In this example the ``red`` instance associates timer 4 with LED 1: when a timer 4 interrupt occurs ``red.cb()``
|
||||
is called causing LED 1 to change state. The ``green`` instance operates similarly: a timer 2 interrupt
|
||||
@@ -158,6 +159,26 @@ On platforms with hardware floating point (such as the Pyboard) the inline ARM T
|
||||
round this limitation. This is because the processor stores float values in a machine word; values can be shared
|
||||
between the ISR and main program code via an array of floats.
|
||||
|
||||
Using micropython.schedule
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This function enables an ISR to schedule a callback for execution "very soon". The callback is queued for
|
||||
execution which will take place at a time when the heap is not locked. Hence it can create Python objects
|
||||
and use floats. The callback is also guaranteed to run at a time when the main program has completed any
|
||||
update of Python objects, so the callback will not encounter partially updated objects.
|
||||
|
||||
Typical usage is to handle sensor hardware. The ISR acquires data from the hardware and enables it to
|
||||
issue a further interrupt. It then schedules a callback to process the data.
|
||||
|
||||
Scheduled callbacks should comply with the principles of interrupt handler design outlined below. This is to
|
||||
avoid problems resulting from I/O activity and the modification of shared data which can arise in any code
|
||||
which pre-empts the main program loop.
|
||||
|
||||
Execution time needs to be considered in relation to the frequency with which interrupts can occur. If an
|
||||
interrupt occurs while the previous callback is executing, a further instance of the callback will be queued
|
||||
for execution; this will run after the current instance has completed. A sustained high interrupt repetition
|
||||
rate therefore carries a risk of unconstrained queue growth and eventual failure with a ``RuntimeError``.
|
||||
|
||||
Exceptions
|
||||
----------
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "pin.h"
|
||||
#include "led.h"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# MicroPython SSD1306 OLED driver, I2C and SPI interfaces
|
||||
|
||||
from micropython import const
|
||||
import time
|
||||
import framebuf
|
||||
|
||||
|
||||
@@ -32,8 +31,21 @@ class SSD1306:
|
||||
self.external_vcc = external_vcc
|
||||
self.pages = self.height // 8
|
||||
self.buffer = bytearray(self.pages * self.width)
|
||||
self.framebuf = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MVLSB)
|
||||
self.poweron()
|
||||
fb = framebuf.FrameBuffer(self.buffer, self.width, self.height, framebuf.MONO_VLSB)
|
||||
self.framebuf = fb
|
||||
# Provide methods for accessing FrameBuffer graphics primitives. This is a
|
||||
# workround because inheritance from a native class is currently unsupported.
|
||||
# http://docs.micropython.org/en/latest/pyboard/library/framebuf.html
|
||||
self.fill = fb.fill
|
||||
self.pixel = fb.pixel
|
||||
self.hline = fb.hline
|
||||
self.vline = fb.vline
|
||||
self.line = fb.line
|
||||
self.rect = fb.rect
|
||||
self.fill_rect = fb.fill_rect
|
||||
self.text = fb.text
|
||||
self.scroll = fb.scroll
|
||||
self.blit = fb.blit
|
||||
self.init_display()
|
||||
|
||||
def init_display(self):
|
||||
@@ -66,6 +78,9 @@ class SSD1306:
|
||||
def poweroff(self):
|
||||
self.write_cmd(SET_DISP | 0x00)
|
||||
|
||||
def poweron(self):
|
||||
self.write_cmd(SET_DISP | 0x01)
|
||||
|
||||
def contrast(self, contrast):
|
||||
self.write_cmd(SET_CONTRAST)
|
||||
self.write_cmd(contrast)
|
||||
@@ -88,18 +103,6 @@ class SSD1306:
|
||||
self.write_cmd(self.pages - 1)
|
||||
self.write_data(self.buffer)
|
||||
|
||||
def fill(self, col):
|
||||
self.framebuf.fill(col)
|
||||
|
||||
def pixel(self, x, y, col):
|
||||
self.framebuf.pixel(x, y, col)
|
||||
|
||||
def scroll(self, dx, dy):
|
||||
self.framebuf.scroll(dx, dy)
|
||||
|
||||
def text(self, string, x, y, col=1):
|
||||
self.framebuf.text(string, x, y, col)
|
||||
|
||||
|
||||
class SSD1306_I2C(SSD1306):
|
||||
def __init__(self, width, height, i2c, addr=0x3c, external_vcc=False):
|
||||
@@ -121,9 +124,6 @@ class SSD1306_I2C(SSD1306):
|
||||
self.i2c.write(buf)
|
||||
self.i2c.stop()
|
||||
|
||||
def poweron(self):
|
||||
pass
|
||||
|
||||
|
||||
class SSD1306_SPI(SSD1306):
|
||||
def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):
|
||||
@@ -135,6 +135,12 @@ class SSD1306_SPI(SSD1306):
|
||||
self.dc = dc
|
||||
self.res = res
|
||||
self.cs = cs
|
||||
import time
|
||||
self.res(1)
|
||||
time.sleep_ms(1)
|
||||
self.res(0)
|
||||
time.sleep_ms(10)
|
||||
self.res(1)
|
||||
super().__init__(width, height, external_vcc)
|
||||
|
||||
def write_cmd(self, cmd):
|
||||
@@ -152,10 +158,3 @@ class SSD1306_SPI(SSD1306):
|
||||
self.cs(0)
|
||||
self.spi.write(buf)
|
||||
self.cs(1)
|
||||
|
||||
def poweron(self):
|
||||
self.res(1)
|
||||
time.sleep_ms(1)
|
||||
self.res(0)
|
||||
time.sleep_ms(10)
|
||||
self.res(1)
|
||||
|
||||
@@ -49,10 +49,8 @@ STATIC uint8_t buf[SECTOR_SIZE];
|
||||
void mp_spiflash_init(mp_spiflash_t *self) {
|
||||
mp_hal_pin_write(self->cs, 1);
|
||||
mp_hal_pin_output(self->cs);
|
||||
mp_hal_pin_write(self->spi.sck, 0);
|
||||
mp_hal_pin_output(self->spi.sck);
|
||||
mp_hal_pin_output(self->spi.mosi);
|
||||
mp_hal_pin_input(self->spi.miso);
|
||||
const mp_machine_spi_p_t *protocol = self->spi->type->protocol;
|
||||
protocol->init(self->spi, 0, NULL, (mp_map_t*)&mp_const_empty_map);
|
||||
}
|
||||
|
||||
STATIC void mp_spiflash_acquire_bus(mp_spiflash_t *self) {
|
||||
@@ -66,7 +64,8 @@ STATIC void mp_spiflash_release_bus(mp_spiflash_t *self) {
|
||||
}
|
||||
|
||||
STATIC void mp_spiflash_transfer(mp_spiflash_t *self, size_t len, const uint8_t *src, uint8_t *dest) {
|
||||
mp_machine_soft_spi_transfer(&self->spi.base, len, src, dest);
|
||||
const mp_machine_spi_p_t *protocol = self->spi->type->protocol;
|
||||
protocol->transfer(self->spi, len, src, dest);
|
||||
}
|
||||
|
||||
STATIC int mp_spiflash_wait_sr(mp_spiflash_t *self, uint8_t mask, uint8_t val, uint32_t timeout) {
|
||||
|
||||
@@ -30,8 +30,7 @@
|
||||
|
||||
typedef struct _mp_spiflash_t {
|
||||
mp_hal_pin_obj_t cs;
|
||||
// TODO replace with generic SPI object
|
||||
mp_machine_soft_spi_obj_t spi;
|
||||
mp_obj_base_t *spi; // object must have protocol pointing to mp_machine_spi_p_t struct
|
||||
} mp_spiflash_t;
|
||||
|
||||
void mp_spiflash_init(mp_spiflash_t *self);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""Test for nrf24l01 module."""
|
||||
|
||||
import struct
|
||||
import pyb
|
||||
from pyb import Pin, SPI
|
||||
import utime
|
||||
from machine import Pin, SPI
|
||||
from nrf24l01 import NRF24L01
|
||||
|
||||
pipes = (b'\xf0\xf0\xf0\xf0\xe1', b'\xf0\xf0\xf0\xf0\xd2')
|
||||
@@ -24,7 +24,7 @@ def master():
|
||||
while num_successes < num_needed and num_failures < num_needed:
|
||||
# stop listening and send packet
|
||||
nrf.stop_listening()
|
||||
millis = pyb.millis()
|
||||
millis = utime.ticks_ms()
|
||||
led_state = max(1, (led_state << 1) & 0x0f)
|
||||
print('sending:', millis, led_state)
|
||||
try:
|
||||
@@ -36,10 +36,10 @@ def master():
|
||||
nrf.start_listening()
|
||||
|
||||
# wait for response, with 250ms timeout
|
||||
start_time = pyb.millis()
|
||||
start_time = utime.ticks_ms()
|
||||
timeout = False
|
||||
while not nrf.any() and not timeout:
|
||||
if pyb.elapsed_millis(start_time) > 250:
|
||||
if utime.ticks_diff(utime.ticks_ms(), start_time) > 250:
|
||||
timeout = True
|
||||
|
||||
if timeout:
|
||||
@@ -51,11 +51,11 @@ def master():
|
||||
got_millis, = struct.unpack('i', nrf.recv())
|
||||
|
||||
# print response and round-trip delay
|
||||
print('got response:', got_millis, '(delay', pyb.millis() - got_millis, 'ms)')
|
||||
print('got response:', got_millis, '(delay', utime.ticks_diff(utime.ticks_ms(), got_millis), 'ms)')
|
||||
num_successes += 1
|
||||
|
||||
# delay then loop
|
||||
pyb.delay(250)
|
||||
utime.sleep_ms(250)
|
||||
|
||||
print('master finished sending; successes=%d, failures=%d' % (num_successes, num_failures))
|
||||
|
||||
@@ -69,18 +69,19 @@ def slave():
|
||||
print('NRF24L01 slave mode, waiting for packets... (ctrl-C to stop)')
|
||||
|
||||
while True:
|
||||
pyb.wfi()
|
||||
machine.idle()
|
||||
if nrf.any():
|
||||
while nrf.any():
|
||||
buf = nrf.recv()
|
||||
millis, led_state = struct.unpack('ii', buf)
|
||||
print('received:', millis, led_state)
|
||||
for i in range(4):
|
||||
if led_state & (1 << i):
|
||||
pyb.LED(i + 1).on()
|
||||
for led in leds:
|
||||
if led_state & 1:
|
||||
led.on()
|
||||
else:
|
||||
pyb.LED(i + 1).off()
|
||||
pyb.delay(15)
|
||||
led.off()
|
||||
led_state >>= 1
|
||||
utime.sleep_ms(15)
|
||||
|
||||
nrf.stop_listening()
|
||||
try:
|
||||
@@ -90,6 +91,12 @@ def slave():
|
||||
print('sent response')
|
||||
nrf.start_listening()
|
||||
|
||||
try:
|
||||
import pyb
|
||||
leds = [pyb.LED(i + 1) for i in range(4)]
|
||||
except:
|
||||
leds = []
|
||||
|
||||
print('NRF24L01 test module loaded')
|
||||
print('NRF24L01 pinout for test:')
|
||||
print(' CE on Y4')
|
||||
|
||||
@@ -52,10 +52,9 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "py/mpthread.h"
|
||||
#include "socket.h"
|
||||
|
||||
extern void HAL_Delay(uint32_t);
|
||||
|
||||
#define SOCK_ANY_PORT_NUM 0xC000;
|
||||
|
||||
static uint16_t sock_any_port = SOCK_ANY_PORT_NUM;
|
||||
@@ -242,7 +241,7 @@ int8_t WIZCHIP_EXPORT(connect)(uint8_t sn, uint8_t * addr, uint16_t port)
|
||||
#endif
|
||||
return SOCKERR_TIMEOUT;
|
||||
}
|
||||
HAL_Delay(1);
|
||||
MICROPY_THREAD_YIELD();
|
||||
}
|
||||
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
|
||||
setSUBR((uint8_t*)"\x00\x00\x00\x00");
|
||||
@@ -317,6 +316,7 @@ int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len)
|
||||
}
|
||||
if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
|
||||
if(len <= freesize) break;
|
||||
MICROPY_THREAD_YIELD();
|
||||
}
|
||||
wiz_send_data(sn, buf, len);
|
||||
#if _WIZCHIP_ == 5200
|
||||
@@ -368,7 +368,7 @@ int32_t WIZCHIP_EXPORT(recv)(uint8_t sn, uint8_t * buf, uint16_t len)
|
||||
}
|
||||
if((sock_io_mode & (1<<sn)) && (recvsize == 0)) return SOCK_BUSY;
|
||||
if(recvsize != 0) break;
|
||||
HAL_Delay(1);
|
||||
MICROPY_THREAD_YIELD();
|
||||
};
|
||||
if(recvsize < len) len = recvsize;
|
||||
wiz_recv_data(sn, buf, len);
|
||||
@@ -416,7 +416,7 @@ int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t
|
||||
if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
|
||||
if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
|
||||
if(len <= freesize) break;
|
||||
HAL_Delay(1);
|
||||
MICROPY_THREAD_YIELD();
|
||||
};
|
||||
wiz_send_data(sn, buf, len);
|
||||
|
||||
@@ -446,7 +446,7 @@ int32_t WIZCHIP_EXPORT(sendto)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t
|
||||
return SOCKERR_TIMEOUT;
|
||||
}
|
||||
////////////
|
||||
HAL_Delay(1);
|
||||
MICROPY_THREAD_YIELD();
|
||||
}
|
||||
#if _WIZCHIP_ == 5200 // for W5200 ARP errata
|
||||
setSUBR((uint8_t*)"\x00\x00\x00\x00");
|
||||
@@ -486,6 +486,7 @@ int32_t WIZCHIP_EXPORT(recvfrom)(uint8_t sn, uint8_t * buf, uint16_t len, uint8_
|
||||
if(getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
|
||||
if( (sock_io_mode & (1<<sn)) && (pack_len == 0) ) return SOCK_BUSY;
|
||||
if(pack_len != 0) break;
|
||||
MICROPY_THREAD_YIELD();
|
||||
};
|
||||
}
|
||||
sock_pack_info[sn] = PACK_COMPLETED;
|
||||
|
||||
@@ -57,6 +57,16 @@
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
#define LPC_SSP0 (0)
|
||||
|
||||
static void Chip_SSP_ReadFrames_Blocking(int dummy, uint8_t *buf, uint32_t len) {
|
||||
WIZCHIP.IF.SPI._read_bytes(buf, len);
|
||||
}
|
||||
|
||||
static void Chip_SSP_WriteFrames_Blocking(int dummy, const uint8_t *buf, uint32_t len) {
|
||||
WIZCHIP.IF.SPI._write_bytes(buf, len);
|
||||
}
|
||||
|
||||
uint8_t WIZCHIP_READ(uint32_t AddrSel)
|
||||
{
|
||||
uint8_t ret;
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../wizchip_conf.h"
|
||||
#include "board.h"
|
||||
|
||||
#define _W5500_IO_BASE_ 0x00000000
|
||||
|
||||
|
||||
@@ -56,7 +56,9 @@
|
||||
* @todo You should select one, \b 5100, \b 5200 ,\b 5500 or etc. \n\n
|
||||
* ex> <code> #define \_WIZCHIP_ 5500 </code>
|
||||
*/
|
||||
#ifndef _WIZCHIP_
|
||||
#define _WIZCHIP_ 5200 // 5100, 5200, 5500
|
||||
#endif
|
||||
|
||||
#define _WIZCHIP_IO_MODE_NONE_ 0x0000
|
||||
#define _WIZCHIP_IO_MODE_BUS_ 0x0100 /**< Bus interface mode */
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../drivers/onewire/ds18x20.py
|
||||
@@ -1 +0,0 @@
|
||||
../../drivers/onewire/onewire.py
|
||||
@@ -1 +0,0 @@
|
||||
../../tools/upip.py
|
||||
@@ -1 +0,0 @@
|
||||
../../tools/upip_utarfile.py
|
||||
@@ -8,6 +8,12 @@ class LEDClass:
|
||||
def value(self, v):
|
||||
print(self.id, v)
|
||||
|
||||
def on(self):
|
||||
self.value(1)
|
||||
|
||||
def off(self):
|
||||
self.value(0)
|
||||
|
||||
|
||||
LED = LEDClass(1)
|
||||
LED2 = LEDClass(12)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Print a nice list of pins, their current settings, and available afs.
|
||||
# Requires pins_af.py from stmhal/build-PYBV10/ directory.
|
||||
# Requires pins_af.py from ports/stm32/build-PYBV10/ directory.
|
||||
|
||||
import pyb
|
||||
import pins_af
|
||||
|
||||
@@ -269,7 +269,7 @@ int mp_machine_soft_i2c_readfrom(mp_obj_base_t *self_in, uint16_t addr, uint8_t
|
||||
/******************************************************************************/
|
||||
// MicroPython bindings for I2C
|
||||
|
||||
STATIC void machine_i2c_obj_init_helper(machine_i2c_obj_t *self, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
STATIC void machine_i2c_obj_init_helper(machine_i2c_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_scl, ARG_sda, ARG_freq, ARG_timeout };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ },
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "extmod/machine_mem.h"
|
||||
#include "py/nlr.h"
|
||||
|
||||
#if MICROPY_PY_MACHINE
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "extmod/virtpin.h"
|
||||
#include "extmod/machine_pinbase.h"
|
||||
|
||||
// PinBase class
|
||||
|
||||
@@ -40,10 +41,8 @@ typedef struct _mp_pinbase_t {
|
||||
mp_obj_base_t base;
|
||||
} mp_pinbase_t;
|
||||
|
||||
STATIC const mp_obj_type_t pinbase_type;
|
||||
|
||||
STATIC mp_pinbase_t pinbase_singleton = {
|
||||
.base = { &pinbase_type },
|
||||
STATIC const mp_pinbase_t pinbase_singleton = {
|
||||
.base = { &machine_pinbase_type },
|
||||
};
|
||||
|
||||
STATIC mp_obj_t pinbase_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
|
||||
@@ -35,8 +35,9 @@
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj);
|
||||
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
int mp_uos_dupterm_rx_chr(void);
|
||||
void mp_uos_dupterm_tx_strn(const char *str, size_t len);
|
||||
void mp_uos_deactivate(const char *msg, mp_obj_t exc);
|
||||
void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc);
|
||||
#else
|
||||
#define mp_uos_dupterm_tx_strn(s, l)
|
||||
#endif
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
#include <errno.h> // for declaration of global errno variable
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/runtime0.h"
|
||||
#include "py/stream.h"
|
||||
|
||||
#if MICROPY_PY_BTREE
|
||||
@@ -281,7 +279,7 @@ STATIC mp_obj_t btree_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t btree_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
STATIC mp_obj_t btree_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
mp_obj_btree_t *self = MP_OBJ_TO_PTR(lhs_in);
|
||||
switch (op) {
|
||||
case MP_BINARY_OP_IN: {
|
||||
|
||||
@@ -27,13 +27,11 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if MICROPY_PY_FRAMEBUF
|
||||
|
||||
#include "stmhal/font_petme128_8x8.h"
|
||||
#include "ports/stm32/font_petme128_8x8.h"
|
||||
|
||||
typedef struct _mp_obj_framebuf_t {
|
||||
mp_obj_base_t base;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/objlist.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
@@ -1033,7 +1032,7 @@ STATIC mp_obj_t lwip_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
|
||||
break;
|
||||
}
|
||||
case MOD_NETWORK_SOCK_DGRAM:
|
||||
mp_raise_NotImplementedError("");
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1070,7 +1069,7 @@ STATIC mp_obj_t lwip_socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(lwip_socket_setblocking_obj, lwip_socket_setblocking);
|
||||
|
||||
STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t lwip_socket_setsockopt(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args; // always 4
|
||||
lwip_socket_obj_t *socket = args[0];
|
||||
|
||||
@@ -1120,7 +1119,7 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_setsockopt_obj, 4, 4, lwip_socket_setsockopt);
|
||||
|
||||
STATIC mp_obj_t lwip_socket_makefile(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
STATIC mp_obj_t lwip_socket_makefile(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
return args[0];
|
||||
}
|
||||
|
||||
@@ -28,13 +28,10 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/binary.h"
|
||||
#include "extmod/modubinascii.h"
|
||||
|
||||
#include "uzlib/tinf.h"
|
||||
|
||||
mp_obj_t mod_binascii_hexlify(size_t n_args, const mp_obj_t *args) {
|
||||
// Second argument is for an extension to allow a separator to be used
|
||||
// between values.
|
||||
@@ -221,6 +218,8 @@ mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) {
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj, mod_binascii_b2a_base64);
|
||||
|
||||
#if MICROPY_PY_UBINASCII_CRC32
|
||||
#include "uzlib/tinf.h"
|
||||
|
||||
mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/objtuple.h"
|
||||
#include "py/binary.h"
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if MICROPY_PY_UHASHLIB
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/objlist.h"
|
||||
#include "py/runtime0.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if MICROPY_PY_UHEAPQ
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/objlist.h"
|
||||
#include "py/objstringio.h"
|
||||
#include "py/parsenum.h"
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
//#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
|
||||
#if MICROPY_PY_URANDOM
|
||||
|
||||
@@ -28,13 +28,15 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/binary.h"
|
||||
#include "py/objstr.h"
|
||||
#include "py/stackctrl.h"
|
||||
|
||||
#if MICROPY_PY_URE
|
||||
|
||||
#define re1_5_stack_chk() MP_STACK_CHECK()
|
||||
|
||||
#include "re1.5/re1.5.h"
|
||||
|
||||
#define FLAG_DEBUG 0x1000
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
|
||||
@@ -52,7 +51,11 @@ struct ssl_args {
|
||||
STATIC const mp_obj_type_t ussl_socket_type;
|
||||
|
||||
STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||
#else
|
||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||
#endif
|
||||
o->base.type = &ussl_socket_type;
|
||||
o->buf = NULL;
|
||||
o->bytes_left = 0;
|
||||
@@ -153,7 +156,7 @@ STATIC mp_obj_t socket_setblocking(mp_obj_t self_in, mp_obj_t flag_in) {
|
||||
// Currently supports only blocking mode
|
||||
(void)self_in;
|
||||
if (!mp_obj_is_true(flag_in)) {
|
||||
mp_raise_NotImplementedError("");
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
@@ -179,6 +182,9 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&socket_close_obj) },
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&socket_close_obj) },
|
||||
#endif
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(ussl_socket_locals_dict, ussl_socket_locals_dict_table);
|
||||
|
||||
@@ -31,10 +31,8 @@
|
||||
#include <string.h>
|
||||
#include <errno.h> // needed because mp_is_nonblocking_error uses system error codes
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/obj.h"
|
||||
|
||||
// mbedtls_time_t
|
||||
#include "mbedtls/platform.h"
|
||||
@@ -67,23 +65,30 @@ struct ssl_args {
|
||||
|
||||
STATIC const mp_obj_type_t ussl_socket_type;
|
||||
|
||||
static void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) {
|
||||
#ifdef MBEDTLS_DEBUG_C
|
||||
STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, const char *str) {
|
||||
(void)ctx;
|
||||
(void)level;
|
||||
printf("DBG:%s:%04d: %s\n", file, line, str);
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: FIXME!
|
||||
int null_entropy_func(void *data, unsigned char *output, size_t len) {
|
||||
STATIC int null_entropy_func(void *data, unsigned char *output, size_t len) {
|
||||
(void)data;
|
||||
(void)output;
|
||||
(void)len;
|
||||
// enjoy random bytes
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
|
||||
STATIC int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
|
||||
mp_obj_t sock = *(mp_obj_t*)ctx;
|
||||
|
||||
const mp_stream_p_t *sock_stream = mp_get_stream_raise(sock, MP_STREAM_OP_WRITE);
|
||||
int err;
|
||||
|
||||
int out_sz = sock_stream->write(sock, buf, len, &err);
|
||||
mp_uint_t out_sz = sock_stream->write(sock, buf, len, &err);
|
||||
if (out_sz == MP_STREAM_ERROR) {
|
||||
if (mp_is_nonblocking_error(err)) {
|
||||
return MBEDTLS_ERR_SSL_WANT_WRITE;
|
||||
@@ -94,13 +99,13 @@ int _mbedtls_ssl_send(void *ctx, const byte *buf, size_t len) {
|
||||
}
|
||||
}
|
||||
|
||||
int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
|
||||
STATIC int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
|
||||
mp_obj_t sock = *(mp_obj_t*)ctx;
|
||||
|
||||
const mp_stream_p_t *sock_stream = mp_get_stream_raise(sock, MP_STREAM_OP_READ);
|
||||
int err;
|
||||
|
||||
int out_sz = sock_stream->read(sock, buf, len, &err);
|
||||
mp_uint_t out_sz = sock_stream->read(sock, buf, len, &err);
|
||||
if (out_sz == MP_STREAM_ERROR) {
|
||||
if (mp_is_nonblocking_error(err)) {
|
||||
return MBEDTLS_ERR_SSL_WANT_READ;
|
||||
@@ -113,7 +118,11 @@ int _mbedtls_ssl_recv(void *ctx, byte *buf, size_t len) {
|
||||
|
||||
|
||||
STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
mp_obj_ssl_socket_t *o = m_new_obj_with_finaliser(mp_obj_ssl_socket_t);
|
||||
#else
|
||||
mp_obj_ssl_socket_t *o = m_new_obj(mp_obj_ssl_socket_t);
|
||||
#endif
|
||||
o->base.type = &ussl_socket_type;
|
||||
|
||||
int ret;
|
||||
@@ -123,8 +132,10 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
mbedtls_x509_crt_init(&o->cert);
|
||||
mbedtls_pk_init(&o->pkey);
|
||||
mbedtls_ctr_drbg_init(&o->ctr_drbg);
|
||||
#ifdef MBEDTLS_DEBUG_C
|
||||
// Debug level (0-4)
|
||||
mbedtls_debug_set_threshold(0);
|
||||
#endif
|
||||
|
||||
mbedtls_entropy_init(&o->entropy);
|
||||
const byte seed[] = "upy";
|
||||
@@ -144,7 +155,9 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
|
||||
|
||||
mbedtls_ssl_conf_authmode(&o->conf, MBEDTLS_SSL_VERIFY_NONE);
|
||||
mbedtls_ssl_conf_rng(&o->conf, mbedtls_ctr_drbg_random, &o->ctr_drbg);
|
||||
#ifdef MBEDTLS_DEBUG_C
|
||||
mbedtls_ssl_conf_dbg(&o->conf, mbedtls_debug, NULL);
|
||||
#endif
|
||||
|
||||
ret = mbedtls_ssl_setup(&o->ssl, &o->conf);
|
||||
if (ret != 0) {
|
||||
@@ -270,6 +283,9 @@ STATIC const mp_rom_map_elem_t ussl_socket_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socket_setblocking_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&socket_close_obj) },
|
||||
#if MICROPY_PY_USSL_FINALISER
|
||||
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&socket_close_obj) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_getpeercert), MP_ROM_PTR(&mod_ssl_getpeercert_obj) },
|
||||
};
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/objlist.h"
|
||||
#include "py/runtime0.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/smallint.h"
|
||||
|
||||
@@ -148,7 +146,7 @@ STATIC mp_obj_t mod_utimeq_heappop(mp_obj_t heap_in, mp_obj_t list_ref) {
|
||||
}
|
||||
mp_obj_list_t *ret = MP_OBJ_TO_PTR(list_ref);
|
||||
if (!MP_OBJ_IS_TYPE(list_ref, &mp_type_list) || ret->len < 3) {
|
||||
mp_raise_TypeError("");
|
||||
mp_raise_TypeError(NULL);
|
||||
}
|
||||
|
||||
struct qentry *item = &heap->items[0];
|
||||
@@ -189,7 +187,7 @@ STATIC mp_obj_t mod_utimeq_dump(mp_obj_t heap_in) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_utimeq_dump_obj, mod_utimeq_dump);
|
||||
#endif
|
||||
|
||||
STATIC mp_obj_t utimeq_unary_op(mp_uint_t op, mp_obj_t self_in) {
|
||||
STATIC mp_obj_t utimeq_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
mp_obj_utimeq_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
switch (op) {
|
||||
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/mperrno.h"
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/builtin.h"
|
||||
@@ -310,7 +308,7 @@ STATIC mp_obj_t webrepl_set_password(mp_obj_t passwd_in) {
|
||||
size_t len;
|
||||
const char *passwd = mp_obj_str_get_data(passwd_in, &len);
|
||||
if (len > sizeof(webrepl_passwd) - 1) {
|
||||
mp_raise_ValueError("");
|
||||
mp_raise_ValueError(NULL);
|
||||
}
|
||||
strcpy(webrepl_passwd, passwd);
|
||||
return mp_const_none;
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "extmod/modwebsocket.h"
|
||||
|
||||
@@ -55,7 +55,7 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
|
||||
for (cnt = 0; *re != ']'; re++, cnt++) {
|
||||
if (!*re) return NULL;
|
||||
EMIT(PC++, *re);
|
||||
if (re[1] == '-') {
|
||||
if (re[1] == '-' && re[2] != ']') {
|
||||
re += 2;
|
||||
}
|
||||
EMIT(PC++, *re);
|
||||
|
||||
@@ -48,6 +48,9 @@ void printre(Regexp*);
|
||||
#ifndef re1_5_fatal
|
||||
void re1_5_fatal(char*);
|
||||
#endif
|
||||
#ifndef re1_5_stack_chk
|
||||
#define re1_5_stack_chk()
|
||||
#endif
|
||||
void *mal(int);
|
||||
|
||||
struct Prog
|
||||
|
||||
@@ -9,7 +9,9 @@ recursiveloop(char *pc, const char *sp, Subject *input, const char **subp, int n
|
||||
{
|
||||
const char *old;
|
||||
int off;
|
||||
|
||||
|
||||
re1_5_stack_chk();
|
||||
|
||||
for(;;) {
|
||||
if(inst_is_consumer(*pc)) {
|
||||
// If we need to match a character, but there's none left, it's fail
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Paul Sokolovsky
|
||||
* Copyright (c) 2017 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -27,66 +28,118 @@
|
||||
#include <string.h>
|
||||
#include "py/mpconfig.h"
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/objtuple.h"
|
||||
#include "py/objarray.h"
|
||||
#include "py/stream.h"
|
||||
#include "lib/utils/interrupt_char.h"
|
||||
|
||||
#if MICROPY_PY_OS_DUPTERM
|
||||
|
||||
void mp_uos_deactivate(const char *msg, mp_obj_t exc) {
|
||||
mp_obj_t term = MP_STATE_PORT(term_obj);
|
||||
MP_STATE_PORT(term_obj) = NULL;
|
||||
void mp_uos_deactivate(size_t dupterm_idx, const char *msg, mp_obj_t exc) {
|
||||
mp_obj_t term = MP_STATE_VM(dupterm_objs[dupterm_idx]);
|
||||
MP_STATE_VM(dupterm_objs[dupterm_idx]) = MP_OBJ_NULL;
|
||||
mp_printf(&mp_plat_print, msg);
|
||||
if (exc != MP_OBJ_NULL) {
|
||||
mp_obj_print_exception(&mp_plat_print, exc);
|
||||
}
|
||||
mp_stream_close(term);
|
||||
nlr_buf_t nlr;
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
mp_stream_close(term);
|
||||
nlr_pop();
|
||||
} else {
|
||||
// Ignore any errors during stream closing
|
||||
}
|
||||
}
|
||||
|
||||
int mp_uos_dupterm_rx_chr(void) {
|
||||
for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) {
|
||||
if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nlr_buf_t nlr;
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
mp_obj_t readinto_m[3];
|
||||
mp_load_method(MP_STATE_VM(dupterm_objs[idx]), MP_QSTR_readinto, readinto_m);
|
||||
readinto_m[2] = MP_STATE_VM(dupterm_arr_obj);
|
||||
mp_obj_t res = mp_call_method_n_kw(1, 0, readinto_m);
|
||||
if (res == mp_const_none) {
|
||||
nlr_pop();
|
||||
} else if (res == MP_OBJ_NEW_SMALL_INT(0)) {
|
||||
nlr_pop();
|
||||
mp_uos_deactivate(idx, "dupterm: EOF received, deactivating\n", MP_OBJ_NULL);
|
||||
} else {
|
||||
mp_buffer_info_t bufinfo;
|
||||
mp_get_buffer_raise(MP_STATE_VM(dupterm_arr_obj), &bufinfo, MP_BUFFER_READ);
|
||||
nlr_pop();
|
||||
if (*(byte*)bufinfo.buf == mp_interrupt_char) {
|
||||
// Signal keyboard interrupt to be raised as soon as the VM resumes
|
||||
mp_keyboard_interrupt();
|
||||
return -2;
|
||||
}
|
||||
return *(byte*)bufinfo.buf;
|
||||
}
|
||||
} else {
|
||||
mp_uos_deactivate(idx, "dupterm: Exception in read() method, deactivating: ", nlr.ret_val);
|
||||
}
|
||||
}
|
||||
|
||||
// No chars available
|
||||
return -1;
|
||||
}
|
||||
|
||||
void mp_uos_dupterm_tx_strn(const char *str, size_t len) {
|
||||
if (MP_STATE_PORT(term_obj) != MP_OBJ_NULL) {
|
||||
for (size_t idx = 0; idx < MICROPY_PY_OS_DUPTERM; ++idx) {
|
||||
if (MP_STATE_VM(dupterm_objs[idx]) == MP_OBJ_NULL) {
|
||||
continue;
|
||||
}
|
||||
nlr_buf_t nlr;
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
mp_obj_t write_m[3];
|
||||
mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_write, write_m);
|
||||
mp_load_method(MP_STATE_VM(dupterm_objs[idx]), MP_QSTR_write, write_m);
|
||||
|
||||
mp_obj_array_t *arr = MP_OBJ_TO_PTR(MP_STATE_PORT(dupterm_arr_obj));
|
||||
mp_obj_array_t *arr = MP_OBJ_TO_PTR(MP_STATE_VM(dupterm_arr_obj));
|
||||
void *org_items = arr->items;
|
||||
arr->items = (void*)str;
|
||||
arr->len = len;
|
||||
write_m[2] = MP_STATE_PORT(dupterm_arr_obj);
|
||||
write_m[2] = MP_STATE_VM(dupterm_arr_obj);
|
||||
mp_call_method_n_kw(1, 0, write_m);
|
||||
arr = MP_OBJ_TO_PTR(MP_STATE_PORT(dupterm_arr_obj));
|
||||
arr = MP_OBJ_TO_PTR(MP_STATE_VM(dupterm_arr_obj));
|
||||
arr->items = org_items;
|
||||
arr->len = 1;
|
||||
nlr_pop();
|
||||
} else {
|
||||
mp_uos_deactivate("dupterm: Exception in write() method, deactivating: ", nlr.ret_val);
|
||||
mp_uos_deactivate(idx, "dupterm: Exception in write() method, deactivating: ", nlr.ret_val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_uos_dupterm(mp_uint_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
if (MP_STATE_PORT(term_obj) == MP_OBJ_NULL) {
|
||||
return mp_const_none;
|
||||
} else {
|
||||
return MP_STATE_PORT(term_obj);
|
||||
}
|
||||
} else {
|
||||
if (args[0] == mp_const_none) {
|
||||
MP_STATE_PORT(term_obj) = MP_OBJ_NULL;
|
||||
} else {
|
||||
MP_STATE_PORT(term_obj) = args[0];
|
||||
if (MP_STATE_PORT(dupterm_arr_obj) == MP_OBJ_NULL) {
|
||||
MP_STATE_PORT(dupterm_arr_obj) = mp_obj_new_bytearray(1, "");
|
||||
}
|
||||
}
|
||||
return mp_const_none;
|
||||
STATIC mp_obj_t mp_uos_dupterm(size_t n_args, const mp_obj_t *args) {
|
||||
mp_int_t idx = 0;
|
||||
if (n_args == 2) {
|
||||
idx = mp_obj_get_int(args[1]);
|
||||
}
|
||||
|
||||
if (idx < 0 || idx >= MICROPY_PY_OS_DUPTERM) {
|
||||
mp_raise_ValueError("invalid dupterm index");
|
||||
}
|
||||
|
||||
mp_obj_t previous_obj = MP_STATE_VM(dupterm_objs[idx]);
|
||||
if (previous_obj == MP_OBJ_NULL) {
|
||||
previous_obj = mp_const_none;
|
||||
}
|
||||
if (args[0] == mp_const_none) {
|
||||
MP_STATE_VM(dupterm_objs[idx]) = MP_OBJ_NULL;
|
||||
} else {
|
||||
MP_STATE_VM(dupterm_objs[idx]) = args[0];
|
||||
if (MP_STATE_VM(dupterm_arr_obj) == MP_OBJ_NULL) {
|
||||
MP_STATE_VM(dupterm_arr_obj) = mp_obj_new_bytearray(1, "");
|
||||
}
|
||||
}
|
||||
|
||||
return previous_obj;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj, 0, 1, mp_uos_dupterm);
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_uos_dupterm_obj, 1, 2, mp_uos_dupterm);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/runtime0.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
#include "py/mperrno.h"
|
||||
@@ -39,6 +38,10 @@
|
||||
#include "extmod/vfs_fat.h"
|
||||
#endif
|
||||
|
||||
// For mp_vfs_proxy_call, the maximum number of additional args that can be passed.
|
||||
// A fixed maximum size is used to avoid the need for a costly variable array.
|
||||
#define PROXY_MAX_ARGS (2)
|
||||
|
||||
// path is the path to lookup and *path_out holds the path within the VFS
|
||||
// object (starts with / if an absolute path).
|
||||
// Returns MP_VFS_ROOT for root dir (and then path_out is undefined) and
|
||||
@@ -98,6 +101,7 @@ STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) {
|
||||
}
|
||||
|
||||
STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) {
|
||||
assert(n_args <= PROXY_MAX_ARGS);
|
||||
if (vfs == MP_VFS_NONE) {
|
||||
// mount point not found
|
||||
mp_raise_OSError(MP_ENODEV);
|
||||
@@ -106,7 +110,7 @@ STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_
|
||||
// can't do operation on root dir
|
||||
mp_raise_OSError(MP_EPERM);
|
||||
}
|
||||
mp_obj_t meth[n_args + 2];
|
||||
mp_obj_t meth[2 + PROXY_MAX_ARGS];
|
||||
mp_load_method(vfs->obj, meth_name, meth);
|
||||
if (args != NULL) {
|
||||
memcpy(meth + 2, args, n_args * sizeof(*args));
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mperrno.h"
|
||||
#include "lib/oofatfs/ff.h"
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "py/mperrno.h"
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#if MICROPY_VFS_FAT
|
||||
|
||||
#include <string.h>
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "lib/oofatfs/ff.h"
|
||||
#include "extmod/vfs_fat.h"
|
||||
|
||||
Submodule lib/axtls updated: 9b3092eb3b...dac9176cac
Submodule lib/berkeley-db-1.xx updated: dab957dacd...35aaec4418
@@ -3,5 +3,5 @@
|
||||
NORETURN void abort_(void);
|
||||
|
||||
NORETURN void abort_(void) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_RuntimeError, "abort() called"));
|
||||
mp_raise_msg(&mp_type_RuntimeError, "abort() called");
|
||||
}
|
||||
|
||||
@@ -48,20 +48,15 @@ float copysignf(float x, float y) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// some compilers define log2f in terms of logf
|
||||
#ifdef log2f
|
||||
#undef log2f
|
||||
#endif
|
||||
// some compilers have _M_LN2 defined in math.h, some don't
|
||||
#ifndef _M_LN2
|
||||
#define _M_LN2 (0.69314718055994530942)
|
||||
#endif
|
||||
float log2f(float x) { return logf(x) / (float)_M_LN2; }
|
||||
|
||||
static const float _M_LN10 = 2.30258509299404; // 0x40135d8e
|
||||
float log10f(float x) { return logf(x) / (float)_M_LN10; }
|
||||
|
||||
float tanhf(float x) { return sinhf(x) / coshf(x); }
|
||||
float tanhf(float x) {
|
||||
if (isinf(x)) {
|
||||
return copysignf(1, x);
|
||||
}
|
||||
return sinhf(x) / coshf(x);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/nlr.h"
|
||||
#include "py/runtime.h"
|
||||
#include "lib/netutils/netutils.h"
|
||||
|
||||
|
||||
1
lib/stm32lib
Submodule
1
lib/stm32lib
Submodule
Submodule lib/stm32lib added at d2bcfda543
@@ -29,7 +29,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/compile.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/repl.h"
|
||||
|
||||
Binary file not shown.
@@ -65,7 +65,7 @@ SRC_C = \
|
||||
# Add fmode when compiling with mingw gcc
|
||||
COMPILER_TARGET := $(shell $(CC) -dumpmachine)
|
||||
ifneq (,$(findstring mingw,$(COMPILER_TARGET)))
|
||||
SRC_C += windows/fmode.c
|
||||
SRC_C += ports/windows/fmode.c
|
||||
endif
|
||||
|
||||
OBJ = $(PY_O)
|
||||
|
||||
@@ -29,14 +29,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "py/mpstate.h"
|
||||
#include "py/compile.h"
|
||||
#include "py/persistentcode.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/stackctrl.h"
|
||||
#ifdef _WIN32
|
||||
#include "windows/fmode.h"
|
||||
#include "ports/windows/fmode.h"
|
||||
#endif
|
||||
|
||||
// Command line options, with their defaults
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
include ../py/mkenv.mk
|
||||
include ../../py/mkenv.mk
|
||||
|
||||
# qstr definitions (must come before including py.mk)
|
||||
QSTR_DEFS = qstrdefsport.h
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "py/nlr.h"
|
||||
#include "py/compile.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/repl.h"
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user