mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 00:50:24 +08:00
docs: Remove trailing spaces and convert tabs to spaces.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
5ca56aaf16
commit
d9d67adef1
@ -16,4 +16,3 @@ live in the main MicroPython repository.
|
|||||||
|
|
||||||
cmodules.rst
|
cmodules.rst
|
||||||
natmod.rst
|
natmod.rst
|
||||||
|
|
@ -4,7 +4,7 @@ Getting Started
|
|||||||
===============
|
===============
|
||||||
|
|
||||||
This guide covers a step-by-step process on setting up version control, obtaining and building
|
This guide covers a step-by-step process on setting up version control, obtaining and building
|
||||||
a copy of the source code for a port, building the documentation, running tests, and a description of the
|
a copy of the source code for a port, building the documentation, running tests, and a description of the
|
||||||
directory structure of the MicroPython code base.
|
directory structure of the MicroPython code base.
|
||||||
|
|
||||||
Source control with git
|
Source control with git
|
||||||
@ -16,7 +16,7 @@ code is pulled and pushed to and from the main repository. Install the respectiv
|
|||||||
of Git for your operating system to follow through the rest of the steps.
|
of Git for your operating system to follow through the rest of the steps.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
For a reference on the installation instructions, please refer to
|
For a reference on the installation instructions, please refer to
|
||||||
the `Git installation instructions <https://git-scm.com/book/en/v2/Getting-Started-Installing-Git>`_.
|
the `Git installation instructions <https://git-scm.com/book/en/v2/Getting-Started-Installing-Git>`_.
|
||||||
Learn about the basic git commands in this `Git Handbook <https://guides.github.com/introduction/git-handbook/>`_
|
Learn about the basic git commands in this `Git Handbook <https://guides.github.com/introduction/git-handbook/>`_
|
||||||
or any other sources on the internet.
|
or any other sources on the internet.
|
||||||
@ -58,12 +58,12 @@ MicroPython repository.
|
|||||||
After the above configuration, your setup should be similar to this:
|
After the above configuration, your setup should be similar to this:
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
$ git remote -v
|
$ git remote -v
|
||||||
origin https://github.com/<your-user-name>/micropython (fetch)
|
origin https://github.com/<your-user-name>/micropython (fetch)
|
||||||
origin https://github.com/<your-user-name>/micropython (push)
|
origin https://github.com/<your-user-name>/micropython (push)
|
||||||
upstream https://github.com/micropython/micropython (fetch)
|
upstream https://github.com/micropython/micropython (fetch)
|
||||||
upstream https://github.com/micropython/micropython (push)
|
upstream https://github.com/micropython/micropython (push)
|
||||||
|
|
||||||
You should now have a copy of the source code. By default, you are pointing
|
You should now have a copy of the source code. By default, you are pointing
|
||||||
to the master branch. To prepare for further development, it is recommended
|
to the master branch. To prepare for further development, it is recommended
|
||||||
@ -73,7 +73,7 @@ to work on a development branch.
|
|||||||
|
|
||||||
$ git checkout -b dev-branch
|
$ git checkout -b dev-branch
|
||||||
|
|
||||||
You can give it any name. You will have to compile MicroPython whenever you change
|
You can give it any name. You will have to compile MicroPython whenever you change
|
||||||
to a different branch.
|
to a different branch.
|
||||||
|
|
||||||
Compile and build the code
|
Compile and build the code
|
||||||
@ -140,8 +140,8 @@ If it built successfully, you should see a message similar to this:
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
LINK mpy-cross
|
LINK mpy-cross
|
||||||
text data bss dec hex filename
|
text data bss dec hex filename
|
||||||
279328 776 880 280984 44998 mpy-cross
|
279328 776 880 280984 44998 mpy-cross
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
@ -181,8 +181,8 @@ If MicroPython built correctly, you should see the following:
|
|||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
LINK micropython
|
LINK micropython
|
||||||
text data bss dec hex filename
|
text data bss dec hex filename
|
||||||
412033 5680 2496 420209 66971 micropython
|
412033 5680 2496 420209 66971 micropython
|
||||||
|
|
||||||
Now run it:
|
Now run it:
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ as detailed in the :ref:`required_dependencies` section, then build:
|
|||||||
$ make submodules
|
$ make submodules
|
||||||
$ make
|
$ make
|
||||||
|
|
||||||
Please refer to the `stm32 documentation <https://github.com/micropython/micropython/tree/master/ports/stm32>`_
|
Please refer to the `stm32 documentation <https://github.com/micropython/micropython/tree/master/ports/stm32>`_
|
||||||
for more details on flashing the firmware.
|
for more details on flashing the firmware.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
@ -259,7 +259,7 @@ Build the docs:
|
|||||||
|
|
||||||
$ make html
|
$ make html
|
||||||
|
|
||||||
Open ``docs/build/html/index.html`` in your browser to view the docs locally. Refer to the
|
Open ``docs/build/html/index.html`` in your browser to view the docs locally. Refer to the
|
||||||
documentation on `importing your documentation
|
documentation on `importing your documentation
|
||||||
<https://docs.readthedocs.io/en/stable/intro/import-guide.html>`_ to use Read the Docs.
|
<https://docs.readthedocs.io/en/stable/intro/import-guide.html>`_ to use Read the Docs.
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ This chapter covers a tour of MicroPython from the perspective of a developer, c
|
|||||||
to MicroPython. It acts as a comprehensive resource on the implementation details of MicroPython
|
to MicroPython. It acts as a comprehensive resource on the implementation details of MicroPython
|
||||||
for both novice and expert contributors.
|
for both novice and expert contributors.
|
||||||
|
|
||||||
Development around MicroPython usually involves modifying the core runtime, porting or
|
Development around MicroPython usually involves modifying the core runtime, porting or
|
||||||
maintaining a new library. This guide describes at great depth, the implementation
|
maintaining a new library. This guide describes at great depth, the implementation
|
||||||
details of MicroPython including a getting started guide, compiler internals, porting
|
details of MicroPython including a getting started guide, compiler internals, porting
|
||||||
MicroPython to a new platform and implementing a core MicroPython library.
|
MicroPython to a new platform and implementing a core MicroPython library.
|
||||||
@ -24,4 +24,3 @@ MicroPython to a new platform and implementing a core MicroPython library.
|
|||||||
publiccapi.rst
|
publiccapi.rst
|
||||||
extendingmicropython.rst
|
extendingmicropython.rst
|
||||||
porting.rst
|
porting.rst
|
||||||
|
|
@ -59,7 +59,7 @@ Processing happens in the following stages:
|
|||||||
information. Note that this step only uses files that have changed, which
|
information. Note that this step only uses files that have changed, which
|
||||||
means that ``qstr.i.last`` will only contain data from files that have
|
means that ``qstr.i.last`` will only contain data from files that have
|
||||||
changed since the last compile.
|
changed since the last compile.
|
||||||
|
|
||||||
2. ``qstr.split`` is an empty file created after running ``makeqstrdefs.py split``
|
2. ``qstr.split`` is an empty file created after running ``makeqstrdefs.py split``
|
||||||
on qstr.i.last. It's just used as a dependency to indicate that the step ran.
|
on qstr.i.last. It's just used as a dependency to indicate that the step ran.
|
||||||
This script outputs one file per input C file, ``genhdr/qstr/...file.c.qstr``,
|
This script outputs one file per input C file, ``genhdr/qstr/...file.c.qstr``,
|
||||||
|
@ -415,14 +415,14 @@ I2S bus
|
|||||||
See :ref:`machine.I2S <machine.I2S>`. ::
|
See :ref:`machine.I2S <machine.I2S>`. ::
|
||||||
|
|
||||||
from machine import I2S, Pin
|
from machine import I2S, Pin
|
||||||
|
|
||||||
i2s = I2S(0, sck=Pin(13), ws=Pin(14), sd=Pin(34), mode=I2S.TX, bits=16, format=I2S.STEREO, rate=44100, ibuf=40000) # create I2S object
|
i2s = I2S(0, sck=Pin(13), ws=Pin(14), sd=Pin(34), mode=I2S.TX, bits=16, format=I2S.STEREO, rate=44100, ibuf=40000) # create I2S object
|
||||||
i2s.write(buf) # write buffer of audio samples to I2S device
|
i2s.write(buf) # write buffer of audio samples to I2S device
|
||||||
|
|
||||||
i2s = I2S(1, sck=Pin(33), ws=Pin(25), sd=Pin(32), mode=I2S.RX, bits=16, format=I2S.MONO, rate=22050, ibuf=40000) # create I2S object
|
i2s = I2S(1, sck=Pin(33), ws=Pin(25), sd=Pin(32), mode=I2S.RX, bits=16, format=I2S.MONO, rate=22050, ibuf=40000) # create I2S object
|
||||||
i2s.readinto(buf) # fill buffer with audio samples from I2S device
|
i2s.readinto(buf) # fill buffer with audio samples from I2S device
|
||||||
|
|
||||||
The I2S class is currently available as a Technical Preview. During the preview period, feedback from
|
The I2S class is currently available as a Technical Preview. During the preview period, feedback from
|
||||||
users is encouraged. Based on this feedback, the I2S class API and implementation may be changed.
|
users is encouraged. Based on this feedback, the I2S class API and implementation may be changed.
|
||||||
|
|
||||||
ESP32 has two I2S buses with id=0 and id=1
|
ESP32 has two I2S buses with id=0 and id=1
|
||||||
|
@ -34,8 +34,8 @@ Please refer to the documentation for your board for further details.
|
|||||||
Getting the firmware
|
Getting the firmware
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
The first thing you need to do is download the most recent MicroPython firmware
|
The first thing you need to do is download the most recent MicroPython firmware
|
||||||
.bin file to load onto your ESP32 device. You can download it from the
|
.bin file to load onto your ESP32 device. You can download it from the
|
||||||
`MicroPython downloads page <https://micropython.org/download#esp32>`_.
|
`MicroPython downloads page <https://micropython.org/download#esp32>`_.
|
||||||
From here, you have 3 main choices:
|
From here, you have 3 main choices:
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ Please refer to the documentation for your board for further details.
|
|||||||
Getting the firmware
|
Getting the firmware
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
The first thing you need to do is download the most recent MicroPython firmware
|
The first thing you need to do is download the most recent MicroPython firmware
|
||||||
.bin file to load onto your ESP8266 device. You can download it from the
|
.bin file to load onto your ESP8266 device. You can download it from the
|
||||||
`MicroPython downloads page <http://micropython.org/download#esp8266>`_.
|
`MicroPython downloads page <http://micropython.org/download#esp8266>`_.
|
||||||
From here, you have 3 main choices
|
From here, you have 3 main choices
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ such, only daily builds for 512kb modules are provided.
|
|||||||
Deploying the firmware
|
Deploying the firmware
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
Once you have the MicroPython firmware (compiled code), you need to load it onto
|
Once you have the MicroPython firmware (compiled code), you need to load it onto
|
||||||
your ESP8266 device. There are two main steps to do this: first you
|
your ESP8266 device. There are two main steps to do this: first you
|
||||||
need to put your device in boot-loader mode, and second you need to copy across
|
need to put your device in boot-loader mode, and second you need to copy across
|
||||||
the firmware. The exact procedure for these steps is highly dependent on the
|
the firmware. The exact procedure for these steps is highly dependent on the
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
.. module:: esp
|
.. module:: esp
|
||||||
:synopsis: functions related to the ESP8266 and ESP32
|
:synopsis: functions related to the ESP8266 and ESP32
|
||||||
|
|
||||||
The ``esp`` module contains specific functions related to both the ESP8266 and
|
The ``esp`` module contains specific functions related to both the ESP8266 and
|
||||||
ESP32 modules. Some functions are only available on one or the other of these
|
ESP32 modules. Some functions are only available on one or the other of these
|
||||||
ports.
|
ports.
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ Functions
|
|||||||
|
|
||||||
Pop the first item from the ``heap``, and return it. Raise ``IndexError`` if
|
Pop the first item from the ``heap``, and return it. Raise ``IndexError`` if
|
||||||
``heap`` is empty.
|
``heap`` is empty.
|
||||||
|
|
||||||
The returned item will be the smallest item in the ``heap``.
|
The returned item will be the smallest item in the ``heap``.
|
||||||
|
|
||||||
.. function:: heapify(x)
|
.. function:: heapify(x)
|
||||||
|
@ -313,7 +313,7 @@ Advanced commands
|
|||||||
specified by :meth:`LCD160CR.set_spi_win`, starting from the top-left corner.
|
specified by :meth:`LCD160CR.set_spi_win`, starting from the top-left corner.
|
||||||
|
|
||||||
The `framebuf <framebuf.html>`_ module can be used to construct frame buffers
|
The `framebuf <framebuf.html>`_ module can be used to construct frame buffers
|
||||||
and provides drawing primitives. Using a frame buffer will improve
|
and provides drawing primitives. Using a frame buffer will improve
|
||||||
performance of animations when compared to drawing directly to the screen.
|
performance of animations when compared to drawing directly to the screen.
|
||||||
|
|
||||||
.. method:: LCD160CR.set_scroll(on)
|
.. method:: LCD160CR.set_scroll(on)
|
||||||
|
@ -27,13 +27,13 @@ Constructors
|
|||||||
Create an ADC object associated with the given pin.
|
Create an ADC object associated with the given pin.
|
||||||
This allows you to then read analog values on that pin.
|
This allows you to then read analog values on that pin.
|
||||||
For more info check the `pinout and alternate functions
|
For more info check the `pinout and alternate functions
|
||||||
table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
|
table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
|
ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
|
||||||
can withstand). When GP2, GP3, GP4 or GP5 are remapped to the
|
can withstand). When GP2, GP3, GP4 or GP5 are remapped to the
|
||||||
ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
|
ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
|
||||||
then the maximum allowed input is 3.6V.
|
then the maximum allowed input is 3.6V.
|
||||||
|
|
||||||
Methods
|
Methods
|
||||||
|
@ -4,91 +4,91 @@
|
|||||||
class I2S -- Inter-IC Sound bus protocol
|
class I2S -- Inter-IC Sound bus protocol
|
||||||
========================================
|
========================================
|
||||||
|
|
||||||
I2S is a synchronous serial protocol used to connect digital audio devices.
|
I2S is a synchronous serial protocol used to connect digital audio devices.
|
||||||
At the physical level, a bus consists of 3 lines: SCK, WS, SD.
|
At the physical level, a bus consists of 3 lines: SCK, WS, SD.
|
||||||
The I2S class supports controller operation. Peripheral operation is not supported.
|
The I2S class supports controller operation. Peripheral operation is not supported.
|
||||||
|
|
||||||
The I2S class is currently available as a Technical Preview. During the preview period, feedback from
|
The I2S class is currently available as a Technical Preview. During the preview period, feedback from
|
||||||
users is encouraged. Based on this feedback, the I2S class API and implementation may be changed.
|
users is encouraged. Based on this feedback, the I2S class API and implementation may be changed.
|
||||||
|
|
||||||
I2S objects can be created and initialized using::
|
I2S objects can be created and initialized using::
|
||||||
|
|
||||||
from machine import I2S
|
from machine import I2S
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
|
|
||||||
# ESP32
|
# ESP32
|
||||||
sck_pin = Pin(14) # Serial clock output
|
sck_pin = Pin(14) # Serial clock output
|
||||||
ws_pin = Pin(13) # Word clock output
|
ws_pin = Pin(13) # Word clock output
|
||||||
sd_pin = Pin(12) # Serial data output
|
sd_pin = Pin(12) # Serial data output
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
# PyBoards
|
# PyBoards
|
||||||
sck_pin = Pin("Y6") # Serial clock output
|
sck_pin = Pin("Y6") # Serial clock output
|
||||||
ws_pin = Pin("Y5") # Word clock output
|
ws_pin = Pin("Y5") # Word clock output
|
||||||
sd_pin = Pin("Y8") # Serial data output
|
sd_pin = Pin("Y8") # Serial data output
|
||||||
|
|
||||||
audio_out = I2S(2,
|
audio_out = I2S(2,
|
||||||
sck=sck_pin, ws=ws_pin, sd=sd_pin,
|
sck=sck_pin, ws=ws_pin, sd=sd_pin,
|
||||||
mode=I2S.TX,
|
mode=I2S.TX,
|
||||||
bits=16,
|
bits=16,
|
||||||
format=I2S.MONO,
|
format=I2S.MONO,
|
||||||
rate=44100,
|
rate=44100,
|
||||||
ibuf=20000)
|
ibuf=20000)
|
||||||
|
|
||||||
audio_in = I2S(2,
|
audio_in = I2S(2,
|
||||||
sck=sck_pin, ws=ws_pin, sd=sd_pin,
|
sck=sck_pin, ws=ws_pin, sd=sd_pin,
|
||||||
mode=I2S.RX,
|
mode=I2S.RX,
|
||||||
bits=32,
|
bits=32,
|
||||||
format=I2S.STEREO,
|
format=I2S.STEREO,
|
||||||
rate=22050,
|
rate=22050,
|
||||||
ibuf=20000)
|
ibuf=20000)
|
||||||
|
|
||||||
3 modes of operation are supported:
|
3 modes of operation are supported:
|
||||||
- blocking
|
- blocking
|
||||||
- non-blocking
|
- non-blocking
|
||||||
- uasyncio
|
- uasyncio
|
||||||
|
|
||||||
blocking::
|
blocking::
|
||||||
|
|
||||||
num_written = audio_out.write(buf) # blocks until buf emptied
|
num_written = audio_out.write(buf) # blocks until buf emptied
|
||||||
|
|
||||||
num_read = audio_in.readinto(buf) # blocks until buf filled
|
num_read = audio_in.readinto(buf) # blocks until buf filled
|
||||||
|
|
||||||
non-blocking::
|
non-blocking::
|
||||||
|
|
||||||
audio_out.irq(i2s_callback) # i2s_callback is called when buf is emptied
|
audio_out.irq(i2s_callback) # i2s_callback is called when buf is emptied
|
||||||
num_written = audio_out.write(buf) # returns immediately
|
num_written = audio_out.write(buf) # returns immediately
|
||||||
|
|
||||||
audio_in.irq(i2s_callback) # i2s_callback is called when buf is filled
|
audio_in.irq(i2s_callback) # i2s_callback is called when buf is filled
|
||||||
num_read = audio_in.readinto(buf) # returns immediately
|
num_read = audio_in.readinto(buf) # returns immediately
|
||||||
|
|
||||||
uasyncio::
|
uasyncio::
|
||||||
|
|
||||||
swriter = uasyncio.StreamWriter(audio_out)
|
swriter = uasyncio.StreamWriter(audio_out)
|
||||||
swriter.write(buf)
|
swriter.write(buf)
|
||||||
await swriter.drain()
|
await swriter.drain()
|
||||||
|
|
||||||
sreader = uasyncio.StreamReader(audio_in)
|
sreader = uasyncio.StreamReader(audio_in)
|
||||||
num_read = await sreader.readinto(buf)
|
num_read = await sreader.readinto(buf)
|
||||||
|
|
||||||
Constructor
|
Constructor
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
.. class:: I2S(id, *, sck, ws, sd, mode, bits, format, rate, ibuf)
|
.. class:: I2S(id, *, sck, ws, sd, mode, bits, format, rate, ibuf)
|
||||||
|
|
||||||
Construct an I2S object of the given id:
|
Construct an I2S object of the given id:
|
||||||
|
|
||||||
- ``id`` identifies a particular I2S bus.
|
- ``id`` identifies a particular I2S bus.
|
||||||
|
|
||||||
``id`` is board and port specific:
|
``id`` is board and port specific:
|
||||||
|
|
||||||
- PYBv1.0/v1.1: has one I2S bus with id=2.
|
- PYBv1.0/v1.1: has one I2S bus with id=2.
|
||||||
- PYBD-SFxW: has two I2S buses with id=1 and id=2.
|
- PYBD-SFxW: has two I2S buses with id=1 and id=2.
|
||||||
- ESP32: has two I2S buses with id=0 and id=1.
|
- ESP32: has two I2S buses with id=0 and id=1.
|
||||||
|
|
||||||
Keyword-only parameters that are supported on all ports:
|
Keyword-only parameters that are supported on all ports:
|
||||||
|
|
||||||
- ``sck`` is a pin object for the serial clock line
|
- ``sck`` is a pin object for the serial clock line
|
||||||
- ``ws`` is a pin object for the word select line
|
- ``ws`` is a pin object for the word select line
|
||||||
- ``sd`` is a pin object for the serial data line
|
- ``sd`` is a pin object for the serial data line
|
||||||
@ -97,9 +97,9 @@ Constructor
|
|||||||
- ``format`` specifies channel format, STEREO or MONO
|
- ``format`` specifies channel format, STEREO or MONO
|
||||||
- ``rate`` specifies audio sampling rate (samples/s)
|
- ``rate`` specifies audio sampling rate (samples/s)
|
||||||
- ``ibuf`` specifies internal buffer length (bytes)
|
- ``ibuf`` specifies internal buffer length (bytes)
|
||||||
|
|
||||||
For all ports, DMA runs continuously in the background and allows user applications to perform other operations while
|
For all ports, DMA runs continuously in the background and allows user applications to perform other operations while
|
||||||
sample data is transfered between the internal buffer and the I2S peripheral unit.
|
sample data is transfered between the internal buffer and the I2S peripheral unit.
|
||||||
Increasing the size of the internal buffer has the potential to increase the time that user applications can perform non-I2S operations
|
Increasing the size of the internal buffer has the potential to increase the time that user applications can perform non-I2S operations
|
||||||
before underflow (e.g. ``write`` method) or overflow (e.g. ``readinto`` method).
|
before underflow (e.g. ``write`` method) or overflow (e.g. ``readinto`` method).
|
||||||
|
|
||||||
@ -109,37 +109,37 @@ Methods
|
|||||||
.. method:: I2S.init(sck, ...)
|
.. method:: I2S.init(sck, ...)
|
||||||
|
|
||||||
see Constructor for argument descriptions
|
see Constructor for argument descriptions
|
||||||
|
|
||||||
.. method:: I2S.deinit()
|
.. method:: I2S.deinit()
|
||||||
|
|
||||||
Deinitialize the I2S bus
|
Deinitialize the I2S bus
|
||||||
|
|
||||||
.. method:: I2S.readinto(buf)
|
.. method:: I2S.readinto(buf)
|
||||||
|
|
||||||
Read audio samples into the buffer specified by ``buf``. ``buf`` must support the buffer protocol, such as bytearray or array.
|
Read audio samples into the buffer specified by ``buf``. ``buf`` must support the buffer protocol, such as bytearray or array.
|
||||||
"buf" byte ordering is little-endian. For Stereo format, left channel sample precedes right channel sample. For Mono format,
|
"buf" byte ordering is little-endian. For Stereo format, left channel sample precedes right channel sample. For Mono format,
|
||||||
the left channel sample data is used.
|
the left channel sample data is used.
|
||||||
Returns number of bytes read
|
Returns number of bytes read
|
||||||
|
|
||||||
.. method:: I2S.write(buf)
|
.. method:: I2S.write(buf)
|
||||||
|
|
||||||
Write audio samples contained in ``buf``. ``buf`` must support the buffer protocol, such as bytearray or array.
|
Write audio samples contained in ``buf``. ``buf`` must support the buffer protocol, such as bytearray or array.
|
||||||
"buf" byte ordering is little-endian. For Stereo format, left channel sample precedes right channel sample. For Mono format,
|
"buf" byte ordering is little-endian. For Stereo format, left channel sample precedes right channel sample. For Mono format,
|
||||||
the sample data is written to both the right and left channels.
|
the sample data is written to both the right and left channels.
|
||||||
Returns number of bytes written
|
Returns number of bytes written
|
||||||
|
|
||||||
.. method:: I2S.irq(handler)
|
.. method:: I2S.irq(handler)
|
||||||
|
|
||||||
Set a callback. ``handler`` is called when ``buf`` is emptied (``write`` method) or becomes full (``readinto`` method).
|
Set a callback. ``handler`` is called when ``buf`` is emptied (``write`` method) or becomes full (``readinto`` method).
|
||||||
Setting a callback changes the ``write`` and ``readinto`` methods to non-blocking operation.
|
Setting a callback changes the ``write`` and ``readinto`` methods to non-blocking operation.
|
||||||
``handler`` is called in the context of the MicroPython scheduler.
|
``handler`` is called in the context of the MicroPython scheduler.
|
||||||
|
|
||||||
.. staticmethod:: I2S.shift(*, buf, bits, shift)
|
.. staticmethod:: I2S.shift(*, buf, bits, shift)
|
||||||
|
|
||||||
bitwise shift of all samples contained in ``buf``. ``bits`` specifies sample size in bits. ``shift`` specifies the number of bits to shift each sample.
|
bitwise shift of all samples contained in ``buf``. ``bits`` specifies sample size in bits. ``shift`` specifies the number of bits to shift each sample.
|
||||||
Positive for left shift, negative for right shift.
|
Positive for left shift, negative for right shift.
|
||||||
Typically used for volume control. Each bit shift changes sample volume by 6dB.
|
Typically used for volume control. Each bit shift changes sample volume by 6dB.
|
||||||
|
|
||||||
Constants
|
Constants
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ Constructors
|
|||||||
|
|
||||||
.. class:: SD(id,... )
|
.. class:: SD(id,... )
|
||||||
|
|
||||||
Create a SD card object. See ``init()`` for parameters if initialization.
|
Create a SD card object. See ``init()`` for parameters if initialization.
|
||||||
|
|
||||||
Methods
|
Methods
|
||||||
-------
|
-------
|
||||||
|
@ -50,7 +50,7 @@ vary from platform to platform.
|
|||||||
- *mosi* can be used to specify an SPI mosi pin.
|
- *mosi* can be used to specify an SPI mosi pin.
|
||||||
|
|
||||||
- *cs* can be used to specify an SPI chip select pin.
|
- *cs* can be used to specify an SPI chip select pin.
|
||||||
|
|
||||||
- *freq* selects the SD/MMC interface frequency in Hz (only supported on the ESP32).
|
- *freq* selects the SD/MMC interface frequency in Hz (only supported on the ESP32).
|
||||||
|
|
||||||
Implementation-specific details
|
Implementation-specific details
|
||||||
|
@ -50,9 +50,9 @@ Methods
|
|||||||
|
|
||||||
- ``mode`` can be one of:
|
- ``mode`` can be one of:
|
||||||
|
|
||||||
- ``TimerWiPy.ONE_SHOT`` - The timer runs once until the configured
|
- ``TimerWiPy.ONE_SHOT`` - The timer runs once until the configured
|
||||||
period of the channel expires.
|
period of the channel expires.
|
||||||
- ``TimerWiPy.PERIODIC`` - The timer runs periodically at the configured
|
- ``TimerWiPy.PERIODIC`` - The timer runs periodically at the configured
|
||||||
frequency of the channel.
|
frequency of the channel.
|
||||||
- ``TimerWiPy.PWM`` - Output a PWM signal on a pin.
|
- ``TimerWiPy.PWM`` - Output a PWM signal on a pin.
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ Methods
|
|||||||
The operating mode is is the one configured to the Timer object that was used to
|
The operating mode is is the one configured to the Timer object that was used to
|
||||||
create the channel.
|
create the channel.
|
||||||
|
|
||||||
- ``channel`` if the width of the timer is 16-bit, then must be either ``TIMER.A``, ``TIMER.B``.
|
- ``channel`` if the width of the timer is 16-bit, then must be either ``TIMER.A``, ``TIMER.B``.
|
||||||
If the width is 32-bit then it **must be** ``TIMER.A | TIMER.B``.
|
If the width is 32-bit then it **must be** ``TIMER.A | TIMER.B``.
|
||||||
|
|
||||||
Keyword only arguments:
|
Keyword only arguments:
|
||||||
|
@ -64,7 +64,7 @@ Methods
|
|||||||
- *timeout_char* specifies the time to wait between characters (in ms).
|
- *timeout_char* specifies the time to wait between characters (in ms).
|
||||||
- *invert* specifies which lines to invert.
|
- *invert* specifies which lines to invert.
|
||||||
- *flow* specifies which hardware flow control signals to use. The value
|
- *flow* specifies which hardware flow control signals to use. The value
|
||||||
is a bitmask.
|
is a bitmask.
|
||||||
|
|
||||||
- ``0`` will ignore hardware flow control signals.
|
- ``0`` will ignore hardware flow control signals.
|
||||||
- ``UART.RTS`` will enable receive flow control by using the RTS output pin to
|
- ``UART.RTS`` will enable receive flow control by using the RTS output pin to
|
||||||
|
@ -24,7 +24,7 @@ Constructors
|
|||||||
|
|
||||||
Create a WDT object and start it. The timeout must be given in milliseconds.
|
Create a WDT object and start it. The timeout must be given in milliseconds.
|
||||||
Once it is running the timeout cannot be changed and the WDT cannot be stopped either.
|
Once it is running the timeout cannot be changed and the WDT cannot be stopped either.
|
||||||
|
|
||||||
Notes: On the esp32 the minimum timeout is 1 second. On the esp8266 a timeout
|
Notes: On the esp32 the minimum timeout is 1 second. On the esp8266 a timeout
|
||||||
cannot be specified, it is determined by the underlying system.
|
cannot be specified, it is determined by the underlying system.
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ Classes
|
|||||||
machine.UART.rst
|
machine.UART.rst
|
||||||
machine.SPI.rst
|
machine.SPI.rst
|
||||||
machine.I2C.rst
|
machine.I2C.rst
|
||||||
machine.I2S.rst
|
machine.I2S.rst
|
||||||
machine.RTC.rst
|
machine.RTC.rst
|
||||||
machine.Timer.rst
|
machine.Timer.rst
|
||||||
machine.WDT.rst
|
machine.WDT.rst
|
||||||
|
@ -120,7 +120,7 @@ Methods
|
|||||||
- *value* if not None will set the port output value before enabling the pin.
|
- *value* if not None will set the port output value before enabling the pin.
|
||||||
|
|
||||||
- *alt* can be used when mode is ``Pin.AF_PP`` or ``Pin.AF_OD`` to set the
|
- *alt* can be used when mode is ``Pin.AF_PP`` or ``Pin.AF_OD`` to set the
|
||||||
index or name of one of the alternate functions associated with a pin.
|
index or name of one of the alternate functions associated with a pin.
|
||||||
This arg was previously called *af* which can still be used if needed.
|
This arg was previously called *af* which can still be used if needed.
|
||||||
|
|
||||||
Returns: ``None``.
|
Returns: ``None``.
|
||||||
|
@ -225,20 +225,20 @@ I2S bus
|
|||||||
See :ref:`machine.I2S <machine.I2S>`. ::
|
See :ref:`machine.I2S <machine.I2S>`. ::
|
||||||
|
|
||||||
from machine import I2S, Pin
|
from machine import I2S, Pin
|
||||||
|
|
||||||
i2s = I2S(2, sck=Pin('Y6'), ws=Pin('Y5'), sd=Pin('Y8'), mode=I2S.TX, bits=16, format=I2S.STEREO, rate=44100, ibuf=40000) # create I2S object
|
i2s = I2S(2, sck=Pin('Y6'), ws=Pin('Y5'), sd=Pin('Y8'), mode=I2S.TX, bits=16, format=I2S.STEREO, rate=44100, ibuf=40000) # create I2S object
|
||||||
i2s.write(buf) # write buffer of audio samples to I2S device
|
i2s.write(buf) # write buffer of audio samples to I2S device
|
||||||
|
|
||||||
i2s = I2S(1, sck=Pin('X5'), ws=Pin('X6'), sd=Pin('Y4'), mode=I2S.RX, bits=16, format=I2S.MONO, rate=22050, ibuf=40000) # create I2S object
|
i2s = I2S(1, sck=Pin('X5'), ws=Pin('X6'), sd=Pin('Y4'), mode=I2S.RX, bits=16, format=I2S.MONO, rate=22050, ibuf=40000) # create I2S object
|
||||||
i2s.readinto(buf) # fill buffer with audio samples from I2S device
|
i2s.readinto(buf) # fill buffer with audio samples from I2S device
|
||||||
|
|
||||||
The I2S class is currently available as a Technical Preview. During the preview period, feedback from
|
The I2S class is currently available as a Technical Preview. During the preview period, feedback from
|
||||||
users is encouraged. Based on this feedback, the I2S class API and implementation may be changed.
|
users is encouraged. Based on this feedback, the I2S class API and implementation may be changed.
|
||||||
|
|
||||||
PYBv1.0/v1.1 has one I2S bus with id=2.
|
PYBv1.0/v1.1 has one I2S bus with id=2.
|
||||||
PYBD-SFxW has two I2S buses with id=1 and id=2.
|
PYBD-SFxW has two I2S buses with id=1 and id=2.
|
||||||
I2S is shared with SPI.
|
I2S is shared with SPI.
|
||||||
|
|
||||||
CAN bus (controller area network)
|
CAN bus (controller area network)
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ We will start by using the accelerometer to turn on a light if it is not flat. :
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
x = accel.x()
|
x = accel.x()
|
||||||
if abs(x) > SENSITIVITY:
|
if abs(x) > SENSITIVITY:
|
||||||
light.on()
|
light.on()
|
||||||
else:
|
else:
|
||||||
light.off()
|
light.off()
|
||||||
@ -61,7 +61,7 @@ use the ``y()`` value and more LEDs we can turn the pyboard into a spirit level.
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
x = accel.x()
|
x = accel.x()
|
||||||
if x > SENSITIVITY:
|
if x > SENSITIVITY:
|
||||||
xlights[0].on()
|
xlights[0].on()
|
||||||
xlights[1].off()
|
xlights[1].off()
|
||||||
elif x < -SENSITIVITY:
|
elif x < -SENSITIVITY:
|
||||||
@ -72,7 +72,7 @@ use the ``y()`` value and more LEDs we can turn the pyboard into a spirit level.
|
|||||||
xlights[1].off()
|
xlights[1].off()
|
||||||
|
|
||||||
y = accel.y()
|
y = accel.y()
|
||||||
if y > SENSITIVITY:
|
if y > SENSITIVITY:
|
||||||
ylights[0].on()
|
ylights[0].on()
|
||||||
ylights[1].off()
|
ylights[1].off()
|
||||||
elif y < -SENSITIVITY:
|
elif y < -SENSITIVITY:
|
||||||
|
@ -47,7 +47,7 @@ Here, n keeps track of the current LED and every time the loop is executed we cy
|
|||||||
One problem you might find is that if you stop the script and then start it again that the LEDs are stuck on from the previous run, ruining our carefully choreographed disco. We can fix this by turning all the LEDs off when we initialise the script and then using a try/finally block. When you press CTRL-C, MicroPython generates a VCPInterrupt exception. Exceptions normally mean something has gone wrong and you can use a try: command to "catch" an exception. In this case it is just the user interrupting the script, so we don't need to catch the error but just tell MicroPython what to do when we exit. The finally block does this, and we use it to make sure all the LEDs are off. The full code is::
|
One problem you might find is that if you stop the script and then start it again that the LEDs are stuck on from the previous run, ruining our carefully choreographed disco. We can fix this by turning all the LEDs off when we initialise the script and then using a try/finally block. When you press CTRL-C, MicroPython generates a VCPInterrupt exception. Exceptions normally mean something has gone wrong and you can use a try: command to "catch" an exception. In this case it is just the user interrupting the script, so we don't need to catch the error but just tell MicroPython what to do when we exit. The finally block does this, and we use it to make sure all the LEDs are off. The full code is::
|
||||||
|
|
||||||
leds = [pyb.LED(i) for i in range(1,5)]
|
leds = [pyb.LED(i) for i in range(1,5)]
|
||||||
for l in leds:
|
for l in leds:
|
||||||
l.off()
|
l.off()
|
||||||
|
|
||||||
n = 0
|
n = 0
|
||||||
|
@ -73,7 +73,7 @@ indicate that you should type the text after it at the prompt. In the end, once
|
|||||||
you have entered the text ``print("hello pyboard!")`` and pressed Enter, the output
|
you have entered the text ``print("hello pyboard!")`` and pressed Enter, the output
|
||||||
on your screen should look like it does above.
|
on your screen should look like it does above.
|
||||||
|
|
||||||
If you already know some python you can now try some basic commands here.
|
If you already know some python you can now try some basic commands here.
|
||||||
|
|
||||||
If any of this is not working you can try either a hard reset or a soft reset;
|
If any of this is not working you can try either a hard reset or a soft reset;
|
||||||
see below.
|
see below.
|
||||||
|
@ -21,7 +21,7 @@ To enter safe mode, do the following steps:
|
|||||||
4. The LEDs will then cycle green to orange to green+orange and back again.
|
4. The LEDs will then cycle green to orange to green+orange and back again.
|
||||||
5. Keep holding down USR until *only the orange LED is lit*, and then let
|
5. Keep holding down USR until *only the orange LED is lit*, and then let
|
||||||
go of the USR switch.
|
go of the USR switch.
|
||||||
6. The orange LED should flash quickly 4 times, and then turn off.
|
6. The orange LED should flash quickly 4 times, and then turn off.
|
||||||
7. You are now in safe mode.
|
7. You are now in safe mode.
|
||||||
|
|
||||||
In safe mode, the ``boot.py`` and ``main.py`` files are not executed, and so
|
In safe mode, the ``boot.py`` and ``main.py`` files are not executed, and so
|
||||||
|
@ -3,7 +3,7 @@ Hints and tips
|
|||||||
|
|
||||||
The following are some examples of the use of the inline assembler and some
|
The following are some examples of the use of the inline assembler and some
|
||||||
information on how to work around its limitations. In this document the term
|
information on how to work around its limitations. In this document the term
|
||||||
"assembler function" refers to a function declared in Python with the
|
"assembler function" refers to a function declared in Python with the
|
||||||
``@micropython.asm_thumb`` decorator, whereas "subroutine" refers to assembler
|
``@micropython.asm_thumb`` decorator, whereas "subroutine" refers to assembler
|
||||||
code called from within an assembler function.
|
code called from within an assembler function.
|
||||||
|
|
||||||
@ -106,8 +106,8 @@ function can return multiple values by assigning them to array elements.
|
|||||||
Assembler functions have no means of determining the length of an array:
|
Assembler functions have no means of determining the length of an array:
|
||||||
this will need to be passed to the function.
|
this will need to be passed to the function.
|
||||||
|
|
||||||
This use of arrays can be extended to enable more than three arrays to be used.
|
This use of arrays can be extended to enable more than three arrays to be used.
|
||||||
This is done using indirection: the ``uctypes`` module supports ``addressof()``
|
This is done using indirection: the ``uctypes`` module supports ``addressof()``
|
||||||
which will return the address of an array passed as its argument. Thus you can
|
which will return the address of an array passed as its argument. Thus you can
|
||||||
populate an integer array with the addresses of other arrays:
|
populate an integer array with the addresses of other arrays:
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ store constant data:
|
|||||||
|
|
||||||
As in the string example, at runtime a reference to the arbitrarily large
|
As in the string example, at runtime a reference to the arbitrarily large
|
||||||
integer is assigned to the variable ``bar``. That reference occupies a
|
integer is assigned to the variable ``bar``. That reference occupies a
|
||||||
single machine word.
|
single machine word.
|
||||||
|
|
||||||
It might be expected that tuples of integers could be employed for the purpose
|
It might be expected that tuples of integers could be employed for the purpose
|
||||||
of storing constant data with minimal RAM use. With the current compiler this
|
of storing constant data with minimal RAM use. With the current compiler this
|
||||||
|
@ -36,7 +36,7 @@ Algorithms
|
|||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
||||||
The most important aspect of designing any routine for performance is ensuring that
|
The most important aspect of designing any routine for performance is ensuring that
|
||||||
the best algorithm is employed. This is a topic for textbooks rather than for a
|
the best algorithm is employed. This is a topic for textbooks rather than for a
|
||||||
MicroPython guide but spectacular performance gains can sometimes be achieved
|
MicroPython guide but spectacular performance gains can sometimes be achieved
|
||||||
by adopting algorithms known for their efficiency.
|
by adopting algorithms known for their efficiency.
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ no adaptation (but see below). It is invoked by means of a function decorator:
|
|||||||
buf = self.linebuf # Cached object
|
buf = self.linebuf # Cached object
|
||||||
# code
|
# code
|
||||||
|
|
||||||
There are certain limitations in the current implementation of the native code emitter.
|
There are certain limitations in the current implementation of the native code emitter.
|
||||||
|
|
||||||
* Context managers are not supported (the ``with`` statement).
|
* Context managers are not supported (the ``with`` statement).
|
||||||
* Generators are not supported.
|
* Generators are not supported.
|
||||||
@ -222,7 +222,7 @@ increase in compiled code size.
|
|||||||
The Viper code emitter
|
The Viper code emitter
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
The optimisations discussed above involve standards-compliant Python code. The
|
The optimisations discussed above involve standards-compliant Python code. The
|
||||||
Viper code emitter is not fully compliant. It supports special Viper native data types
|
Viper code emitter is not fully compliant. It supports special Viper native data types
|
||||||
in pursuit of performance. Integer processing is non-compliant because it uses machine
|
in pursuit of performance. Integer processing is non-compliant because it uses machine
|
||||||
words: arithmetic on 32 bit hardware is performed modulo 2**32.
|
words: arithmetic on 32 bit hardware is performed modulo 2**32.
|
||||||
@ -237,7 +237,7 @@ bit manipulations. It is invoked using a decorator:
|
|||||||
def foo(self, arg: int) -> int:
|
def foo(self, arg: int) -> int:
|
||||||
# code
|
# code
|
||||||
|
|
||||||
As the above fragment illustrates it is beneficial to use Python type hints to assist the Viper optimiser.
|
As the above fragment illustrates it is beneficial to use Python type hints to assist the Viper optimiser.
|
||||||
Type hints provide information on the data types of arguments and of the return value; these
|
Type hints provide information on the data types of arguments and of the return value; these
|
||||||
are a standard Python language feature formally defined here `PEP0484 <https://www.python.org/dev/peps/pep-0484/>`_.
|
are a standard Python language feature formally defined here `PEP0484 <https://www.python.org/dev/peps/pep-0484/>`_.
|
||||||
Viper supports its own set of types namely ``int``, ``uint`` (unsigned integer), ``ptr``, ``ptr8``,
|
Viper supports its own set of types namely ``int``, ``uint`` (unsigned integer), ``ptr``, ``ptr8``,
|
||||||
|
@ -154,7 +154,7 @@ See :ref:`machine.RTC <machine.RTC>` ::
|
|||||||
pass
|
pass
|
||||||
# do some non blocking operations
|
# do some non blocking operations
|
||||||
# warning printing on an irq via telnet is not
|
# warning printing on an irq via telnet is not
|
||||||
# possible, only via UART
|
# possible, only via UART
|
||||||
|
|
||||||
# create a RTC alarm that expires after 5 seconds
|
# create a RTC alarm that expires after 5 seconds
|
||||||
rtc.alarm(time=5000, repeat=False)
|
rtc.alarm(time=5000, repeat=False)
|
||||||
@ -179,7 +179,7 @@ See :ref:`machine.SD <machine.SD>`. ::
|
|||||||
sd = SD()
|
sd = SD()
|
||||||
os.mount(sd, '/sd')
|
os.mount(sd, '/sd')
|
||||||
|
|
||||||
WLAN (WiFi)
|
WLAN (WiFi)
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. ::
|
See :ref:`network.WLAN <network.WLAN>` and :mod:`machine`. ::
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
Reset and boot modes
|
Reset and boot modes
|
||||||
====================
|
====================
|
||||||
|
|
||||||
There are soft resets and hard resets.
|
There are soft resets and hard resets.
|
||||||
|
|
||||||
- A soft reset simply clears the state of the MicroPython virtual machine,
|
- A soft reset simply clears the state of the MicroPython virtual machine,
|
||||||
but leaves hardware peripherals unaffected. To do a soft reset, simply press
|
but leaves hardware peripherals unaffected. To do a soft reset, simply press
|
||||||
**Ctrl+D** on the REPL, or within a script do::
|
**Ctrl+D** on the REPL, or within a script do::
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
@ -5,7 +5,7 @@ Timers can be used for a great variety of tasks, calling a function periodically
|
|||||||
counting events, and generating a PWM signal are among the most common use cases.
|
counting events, and generating a PWM signal are among the most common use cases.
|
||||||
Each timer consists of two 16-bit channels and this channels can be tied together to
|
Each timer consists of two 16-bit channels and this channels can be tied together to
|
||||||
form one 32-bit timer. The operating mode needs to be configured per timer, but then
|
form one 32-bit timer. The operating mode needs to be configured per timer, but then
|
||||||
the period (or the frequency) can be independently configured on each channel.
|
the period (or the frequency) can be independently configured on each channel.
|
||||||
By using the callback method, the timer event can call a Python function.
|
By using the callback method, the timer event can call a Python function.
|
||||||
|
|
||||||
Example usage to toggle an LED at a fixed frequency::
|
Example usage to toggle an LED at a fixed frequency::
|
||||||
|
@ -13,9 +13,9 @@ You can check the current mode (which is always ``WLAN.AP`` after power up)::
|
|||||||
|
|
||||||
>>> wlan.mode()
|
>>> wlan.mode()
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
When you change the WLAN mode following the instructions below, your WLAN
|
When you change the WLAN mode following the instructions below, your WLAN
|
||||||
connection to the WiPy will be broken. This means you will not be able
|
connection to the WiPy will be broken. This means you will not be able
|
||||||
to run these commands interactively over the WLAN.
|
to run these commands interactively over the WLAN.
|
||||||
|
|
||||||
There are two ways around this::
|
There are two ways around this::
|
||||||
|
Loading…
Reference in New Issue
Block a user