docs: Add initial draft documentation for the WiPy.

This makes all common files "port-aware" using the .. only directive.
This commit is contained in:
Daniel Campora 2015-06-10 23:29:56 +02:00
parent b630de1103
commit cfcf47c064
33 changed files with 2155 additions and 835 deletions

View File

@ -121,6 +121,8 @@ preferably in a virtualenv:
In `micropython/docs`, build the docs:
make html
make MICROPY_PORT=<port_name> BUILDDIR=<port_name>/build html
You'll find the index page at `micropython/docs/build/html/index.html`.
Where ``<port_name>`` can be ``port_unix``, ``port_pyboard``, ``port_wipy`` or ``port_esp8266``.
You'll find the index page at `micropython/docs/<port_name>/build/html/index.html`.

View File

@ -47,7 +47,7 @@ source_suffix = '.rst'
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
#master_doc = 'index'
# General information about the project.
project = 'MicroPython'
@ -297,3 +297,9 @@ html_context = {
'port_name':ports[micropy_port],
'all_ports':[(n, url_prefix + p) for p, n in ports.items()],
}
# Append the other ports' specific folders/files to the exclude pattern
exclude_patterns.extend([port + '*' for port in ports if port != micropy_port])
# Specify a custom master document based on the port name
master_doc = micropy_port + '_' + 'index'

View File

@ -1,20 +0,0 @@
MicroPython documentation contents
==================================
.. only:: port_pyboard
.. toctree::
pyboard/quickref.rst
pyboard/general.rst
pyboard/tutorial/index.rst
library/index.rst
pyboard/hardware/index.rst
license.rst
.. only:: port_esp8266
.. toctree::
library/index.rst
license.rst

View File

@ -0,0 +1,7 @@
MicroPython documentation contents
==================================
.. toctree::
library/index.rst
license.rst

15
docs/esp8266_index.rst Normal file
View File

@ -0,0 +1,15 @@
MicroPython documentation and references
========================================
.. toctree::
library/index.rst
license.rst
esp8266_contents.rst
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -1,29 +0,0 @@
MicroPython documentation and references
========================================
.. only:: port_pyboard
.. toctree::
pyboard/quickref.rst
pyboard/general.rst
pyboard/tutorial/index.rst
library/index.rst
pyboard/hardware/index.rst
license.rst
contents.rst
.. only:: port_esp8266
.. toctree::
library/index.rst
license.rst
contents.rst
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -17,6 +17,8 @@ The following standard Python libraries are built in to MicroPython.
For additional libraries, please download them from the `micropython-lib repository
<https://github.com/micropython/micropython-lib>`_.
.. only:: port_pyboard
.. toctree::
:maxdepth: 1
@ -29,6 +31,17 @@ For additional libraries, please download them from the `micropython-lib reposit
sys.rst
time.rst
.. only:: port_wipy
.. toctree::
:maxdepth: 1
gc.rst
os.rst
select.rst
sys.rst
time.rst
Python micro-libraries
----------------------
@ -43,6 +56,8 @@ For example, ``import json`` will first search for a file ``json.py`` or
directory ``json`` and load that package if it is found. If nothing is found,
it will fallback to loading the built-in ``ujson`` module.
.. only:: port_pyboard
.. toctree::
:maxdepth: 1
@ -55,6 +70,8 @@ it will fallback to loading the built-in ``ujson`` module.
usocket.rst
uzlib.rst
.. only:: port_pyboard
Libraries specific to the pyboard
---------------------------------
@ -66,6 +83,32 @@ The following libraries are specific to the pyboard.
pyb.rst
network.rst
.. only:: port_wipy
.. toctree::
:maxdepth: 1
ubinascii.rst
uhashlib.rst
uheapq.rst
ujson.rst
ure.rst
usocket.rst
.. only:: port_wipy
Libraries specific to the WiPy
---------------------------------
The following libraries are specific to the WiPy.
.. toctree::
:maxdepth: 2
pyb.rst
network.rst
.. only:: port_esp8266
Libraries specific to the ESP8266
@ -76,4 +119,5 @@ The following libraries are specific to the pyboard.
.. toctree::
:maxdepth: 2
pyb.rst
esp.rst

View File

@ -7,6 +7,8 @@
Functions
---------
.. only:: port_pyboard or port_unix
.. function:: mem_info([verbose])
Print information about currently used memory. If the ``verbose`` argument

View File

@ -27,6 +27,8 @@ For example::
data = s.recv(1000)
s.close()
.. only:: port_pyboard
class CC3K
==========
@ -175,3 +177,147 @@ Methods
.. method:: wiznet5k.regs()
Dump the WIZnet5x00 registers. Useful for debugging.
.. only:: port_wipy
class WLAN
==========
.. _network.WLAN:
This class provides a driver for WiFi network processor in the WiPy. Example usage::
import network
# setup as a station
nic = network.WLAN(WLAN.STA)
nic.connect('your-ssid', security=WLAN.WPA_WPA2, key='your-key')
while not nic.isconnected():
pyb.delay(50)
print(nic.ifconfig())
# now use socket as usual
...
Constructors
------------
.. class:: WLAN(mode, ssid, \*, security=WLAN.OPEN, key=None, channel=5)
Create a WLAN driver object, initialise the WLAN engine in station or AP mode.
Arguments are:
- ``mode`` can be either ``WLAN.STA`` or ``WLAN.AP``.
- ``ssid`` is a string with the ssid name. Only needed when mode is ``WLAN.AP``.
- ``security`` can be ``WLAN.OPEN``, ``WLAN.WEP`` or ``WLAN.WPA_WPA2``.
Only needed when mode is ``WLAN.AP``.
- ``key`` is a string with the ``WLAN.WPA_WPA2`` key or a byte array with the
``WLAN.WEP`` key. Not needed when mode is ``WLAN.STA`` or security is ``WLAN.OPEN``.
- ``channel`` a number in the range 1-11. Only needed when mode is ``WLAN.AP``.
For example, you can use::
# configure as an access point
nic = network.WLAN(WLAN.AP, 'wipy-wlan', security=WLAN.WPA_WPA2, key='www.wipy.io', channel=7)
or::
# configure as an station
nic = network.WLAN(WLAN.STA)
Methods
-------
.. method:: wlan.connect(ssid, \*, security=WLAN.OPEN, key=None, bssid=None, timeout=5000)
Connect to a wifi access point using the given SSID, and other security
parameters.
- ``bssid`` is the MAC address of the AP to connect to. Useful when there are several APs
with the same ssid.
- ``timeout`` is the maximum time in milliseconds to wait for the connection to succeed.
.. method:: wlan.scan()
Performs a network scan and returns a list of named tuples with (ssid, bssid, security, channel, rssi).
Note that channel is always ``None`` since this info is not provided by the WiPy.
.. method:: wlan.disconnect()
Disconnect from the wifi access point.
.. method:: wlan.isconnected()
Returns True if connected to a wifi access point and has a valid IP address,
False otherwise.
.. method:: wlan.ifconfig(['dhcp' or configtuple])
With no parameters given eturns a 4-tuple of ``(ip, subnet mask, gateway, DNS server)``.
if ``'dhcp'`` is passed as a parameter then the DHCP client is enabled and the IP params
are negotiated with the AP.
if the 4-tuple config is given then a static IP is configured. For example::
nic.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
.. method:: wlan.info()
Provides information about the current WLAN configuration. Returns a named tuple
of (mode, ssid, security, mac)
- ``mode`` can be either ``WLAN.STA`` or ``WLAN.AP``.
- ``ssid`` is a string with our ssid if in AP mode, ``None`` oterwise.
- ``security`` security type currently used.
- ``mac`` our MAC address.
.. method:: wlan.connections()
Returns a list of the devices currently connected. Each item in the list is a
tuple of ``(ssid, mac)``.
.. method:: wlan.antenna(antenna_type)
Selects the antenna type to be used. Must be either ``WLAN.INT_ANTENNA`` or
``WLAN.EXT_ANTENNA``.
.. method:: wlan.callback(wakes)
Create a callback to be triggered when a WLAN event occurs during ``pyb.Sleep.SUSPENDED``
mode. Events are triggered by socket activity or by WLAN connection/disconnection.
- ``wakes`` can only be ``pyb.Sleep.SUSPENDED``.
Returns a callback object.
Constants
---------
.. data:: WLAN.STA
WiFi station mode
.. data:: WLAN.AP
WiFi access point mode
.. data:: WLAN.OPEN
open network (no security)
.. data:: WLAN.WEP
WEP network security
.. data:: WLAN.WPA_WPA2
WPA/WPA2 network security
.. data:: WLAN.INT_ANTENNA
selects the internal antenna
.. data:: WLAN.EXT_ANTENNA
selects the external antenna

View File

@ -16,9 +16,15 @@ available physical drives are accessible from here. They are currently:
``/sd`` -- the SD card (if it exists)
.. only:: port_pyboard
On boot up, the current directory is ``/flash`` if no SD card is inserted,
otherwise it is ``/sd``.
.. only:: port_wipy
On boot up, the current directory is ``/flash``.
Functions
---------
@ -63,6 +69,12 @@ Functions
Return a bytes object with n random bytes, generated by the hardware
random number generator.
.. only:: port_wipy
.. function:: mkfs(drive)
Formats the specified drive, must be either ``/flash`` or ``/sd``.
Constants
---------

View File

@ -3,6 +3,8 @@
class ADC -- analog to digital conversion: read analog values on a pin
======================================================================
.. only:: port_pyboard
Usage::
import pyb
@ -16,15 +18,40 @@ Usage::
val = adc.read_core_vbat() # read MCU VBAT
val = adc.read_core_vref() # read MCU VREF
.. only:: port_wipy
Usage::
import pyb
adc = pyb.ADC(channel) # create an analog object on one of the 4 ADC channels
val = adc.read() # read an analog value
Constructors
------------
.. only:: port_pyboard
.. class:: pyb.ADC(pin)
Create an ADC object associated with the given pin.
This allows you to then read analog values on that pin.
.. only:: port_wipy
.. class:: pyb.ADC(channel)
Create an ADC object on the given channel. Each channel is associated
to a specific pin. For more info check the `pinout and alternate functions
table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
This allows you to then read analog values on that pin.
.. warning::
ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
can withstand). When GPIO2, GPIO3, GPIO4 or GPIO5 are remapped to the
ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
then the maximum allowed input is 3.6V.
Methods
-------
@ -34,6 +61,8 @@ Methods
Read the value on the analog pin and return it. The returned value
will be between 0 and 4095.
.. only:: port_pyboard
.. method:: adc.read_timed(buf, freq)
Read analog values into the given buffer at the given frequency. Buffer
@ -50,3 +79,13 @@ Methods
print(val) # print the value out
This function does not allocate any memory.
.. only:: port_wipy
.. method:: adc.enable()
Enable the ADC channel.
.. method:: adc.disable()
Disable the ADC channel.

View File

@ -0,0 +1,46 @@
.. _pyb.HeartBeat:
class HeartBeat -- heart beat LED
=================================
The HeartBeat class controls the heart beat led which by default
flashes once every 5s. The user can disable the HeartBeat and then
is free to control this LED manually through GPIO25 using the Pin
class. The GPIO25 can also be remapped as a PWM output, an this
can be used to control the light intesity of the heart beat LED.
Example usage::
hb = pyb.HeartBeat()
hb.disable() # disable the heart beat
hb.enable() # enable the heart beat
Constructors
------------
.. class:: pyb.HeartBeat()
Create a HeartBeat object.
Methods
-------
.. method:: heartbeat.enable()
Enable the heart beat. The LED will flash once every 5 seconds.
.. method:: heartbeat.disable()
Disable the heart beat. The LED can then be controlled manually.
Example::
import pyb
# disable the heart beat
pyb.HeartBeat().disable()
# get the GPIO25 pin object
hbl = pyb.Pin('GPIO25')
# toggle the led
hbl.toggle()
...

View File

@ -7,7 +7,11 @@ I2C is a two-wire protocol for communicating between devices. At the physical
level it consists of 2 wires: SCL and SDA, the clock and data lines respectively.
I2C objects are created attached to a specific bus. They can be initialised
when created, or initialised later on::
when created, or initialised later on.
.. only:: port_pyboard
Example::
from pyb import I2C
@ -17,9 +21,20 @@ when created, or initialised later on::
i2c.init(I2C.SLAVE, addr=0x42) # init as a slave with given address
i2c.deinit() # turn off the peripheral
.. only:: port_wipy
Example::
from pyb import I2C
i2c = I2C(1) # create on bus 1
i2c = I2C(1, I2C.MASTER) # create and init as a master
i2c.init(I2C.MASTER, baudrate=20000) # init as a master
i2c.deinit() # turn off the peripheral
Printing the i2c object gives you information about its configuration.
Basic methods for slave are send and recv::
The basic methods are send and recv::
i2c.send('abc') # send 3 bytes
i2c.send(0x42) # send a single byte, given by the number
@ -30,6 +45,8 @@ To receive inplace, first create a bytearray::
data = bytearray(3) # create a buffer
i2c.recv(data) # receive 3 bytes, writing them into data
.. only:: port_pyboard
You can specify a timeout (in ms)::
i2c.send(b'123', timeout=2000) # timout after 2 seconds
@ -40,6 +57,8 @@ A master must specify the recipient's address::
i2c.send('123', 0x42) # send 3 bytes to slave with address 0x42
i2c.send(b'456', addr=0x42) # keyword for address
.. only:: port_pyboard
Master also has other methods::
i2c.is_ready(0x42) # check if slave 0x42 is ready
@ -49,10 +68,24 @@ Master also has other methods::
# starting at address 2 in the slave
i2c.mem_write('abc', 0x42, 2, timeout=1000)
.. only:: port_wipy
There are also other methods::
i2c.is_ready(0x42) # check if slave 0x42 is ready
i2c.scan() # scan for slaves on the bus, returning
# a list of valid addresses
i2c.mem_read(3, 0x42, 2) # read 3 bytes from memory of slave 0x42,
# starting at address 2 in the slave
i2c.mem_write('abc', 0x42, 2) # write 'abc' (3 bytes) to memory of slave 0x42
# starting at address 2 in the slave
Constructors
------------
.. only:: port_pyboard
.. class:: pyb.I2C(bus, ...)
Construct an I2C object on the given bus. ``bus`` can be 1 or 2.
@ -66,6 +99,16 @@ Constructors
- ``I2C(1)`` is on the X position: ``(SCL, SDA) = (X9, X10) = (PB6, PB7)``
- ``I2C(2)`` is on the Y position: ``(SCL, SDA) = (Y9, Y10) = (PB10, PB11)``
.. only:: port_wipy
.. class:: pyb.I2C(bus, ...)
Construct an I2C object on the given bus. `bus` can only be 1.
With no additional parameters, the I2C object is created but not
initialised (it has the settings from the last initialisation of
the bus, if any). If extra arguments are given, the bus is initialised.
See `init` for parameters of initialisation.
Methods
-------
@ -74,6 +117,8 @@ Methods
Turn off the I2C bus.
.. only:: port_pyboard
.. method:: i2c.init(mode, \*, addr=0x12, baudrate=400000, gencall=False)
Initialise the I2C bus with the given parameters:
@ -83,10 +128,21 @@ Methods
- ``baudrate`` is the SCL clock rate (only sensible for a master)
- ``gencall`` is whether to support general call mode
.. only:: port_wipy
.. method:: i2c.init(mode, \*, baudrate=100000)
Initialise the I2C bus with the given parameters:
- ``mode`` must be ``I2C.MASTER``
- ``baudrate`` is the SCL clock rate
.. method:: i2c.is_ready(addr)
Check if an I2C device responds to the given address. Only valid when in master mode.
.. only:: port_pyboard
.. method:: i2c.mem_read(data, addr, memaddr, timeout=5000, addr_size=8)
Read from the memory of an I2C device:
@ -100,6 +156,22 @@ Methods
Returns the read data.
This is only valid in master mode.
.. only:: port_wipy
.. method:: i2c.mem_read(data, addr, memaddr, addr_size=8)
Read from the memory of an I2C device:
- ``data`` can be an integer (number of bytes to read) or a buffer to read into
- ``addr`` is the I2C device address
- ``memaddr`` is the memory location within the I2C device
- ``addr_size`` selects width of memaddr: 8 or 16 bits
Returns the read data.
This is only valid in master mode.
.. only:: port_pyboard
.. method:: i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8)
Write to the memory of an I2C device:
@ -113,6 +185,22 @@ Methods
Returns ``None``.
This is only valid in master mode.
.. only:: port_wipy
.. method:: i2c.mem_write(data, addr, memaddr, timeout=5000, addr_size=8)
Write to the memory of an I2C device:
- ``data`` can be an integer or a buffer to write from
- ``addr`` is the I2C device address
- ``memaddr`` is the memory location within the I2C device
- ``addr_size`` selects width of memaddr: 8 or 16 bits
Returns ``None``.
This is only valid in master mode.
.. only:: port_pyboard
.. method:: i2c.recv(recv, addr=0x00, timeout=5000)
Receive data on the bus:
@ -125,11 +213,26 @@ Methods
Return value: if ``recv`` is an integer then a new buffer of the bytes received,
otherwise the same buffer that was passed in to ``recv``.
.. only:: port_wipy
.. method:: i2c.recv(recv, addr=0x00)
Receive data on the bus:
- ``recv`` can be an integer, which is the number of bytes to receive,
or a mutable buffer, which will be filled with received bytes
- ``addr`` is the address to receive from (only required in master mode)
Return value: if ``recv`` is an integer then a new buffer of the bytes received,
otherwise the same buffer that was passed in to ``recv``.
.. method:: i2c.scan()
Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond.
Only valid when in master mode.
.. only:: port_pyboard
.. method:: i2c.send(send, addr=0x00, timeout=5000)
Send data on the bus:
@ -140,6 +243,16 @@ Methods
Return value: ``None``.
.. only:: port_wipy
.. method:: i2c.send(send, addr=0x00)
Send data on the bus:
- ``send`` is the data to send (an integer to send, or a buffer object)
- ``addr`` is the address to send to (only required in master mode)
Return value: ``None``.
Constants
---------
@ -148,6 +261,8 @@ Constants
for initialising the bus to master mode
.. only:: port_pyboard
.. data:: I2C.SLAVE
for initialising the bus to slave mode

View File

@ -9,6 +9,8 @@ digital logic level. For analog control of a pin, see the ADC class.
Usage Model:
.. only:: port_pyboard
All Board Pins are predefined as pyb.Pin.board.Name::
x1_pin = pyb.Pin.board.X1
@ -61,14 +63,51 @@ When a pin has the ``Pin.PULL_UP`` or ``Pin.PULL_DOWN`` pull-mode enabled,
that pin has an effective 40k Ohm resistor pulling it to 3V3 or GND
respectively (except pin Y5 which has 11k Ohm resistors).
.. only:: port_wipy
Board pins are identified by their string name::
g = pyb.Pin('GPIO9', af=0, mode=pyb.Pin.IN, type=pyb.Pin.STD, strength=pyb.Pin.S2MA)
You can also configure the Pin to generate interrupts. For instance::
def pincb(pin):
print(pin.info().name)
pin_int = pyb.Pin('GPIO10', af=0, mode=Pin.IN, type=pyb.Pin.STD_PD, strength=pyb.Pin.S2MA)
pin_int.callback (mode=pyb.Pin.INT_RISING, handler=pincb)
# the callback can be triggered manually
pin_int.callback()()
# to disable the callback
pin_int.callback().disable()
Now every time a falling edge is seen on the gpio pin, the callback will be
executed. Caution: mechanical push buttons have "bounce" and pushing or
releasing a switch will often generate multiple edges.
See: http://www.eng.utah.edu/~cs5780/debouncing.pdf for a detailed
explanation, along with various techniques for debouncing.
All pin objects go through the pin mapper to come up with one of the
gpio pins.
Constructors
------------
.. only:: port_pyboard
.. class:: pyb.Pin(id, ...)
Create a new Pin object associated with the id. If additional arguments are given,
they are used to initialise the pin. See :meth:`pin.init`.
.. only:: port_wipy
.. class:: pyb.Pin(name, ...)
Create a new Pin object associated with the name. If additional arguments are given,
they are used to initialise the pin. See :meth:`pin.init`.
.. only:: port_pyboard
Class methods
-------------
@ -93,26 +132,64 @@ Class methods
Methods
-------
.. only:: port_pyboard
.. method:: pin.init(mode, pull=Pin.PULL_NONE, af=-1)
Initialise the pin:
- ``mode`` can be one of:
- ``Pin.IN`` - configure the pin for input;
- ``Pin.OUT_PP`` - configure the pin for output, with push-pull control;
- ``Pin.OUT_OD`` - configure the pin for output, with open-drain control;
- ``Pin.AF_PP`` - configure the pin for alternate function, pull-pull;
- ``Pin.AF_OD`` - configure the pin for alternate function, open-drain;
- ``Pin.ANALOG`` - configure the pin for analog.
- ``pull`` can be one of:
- ``Pin.PULL_NONE`` - no pull up or down resistors;
- ``Pin.PULL_UP`` - enable the pull-up resistor;
- ``Pin.PULL_DOWN`` - enable the pull-down resistor.
- when mode is Pin.AF_PP or Pin.AF_OD, then af can be the index or name
- when mode is ``Pin.AF_PP`` or ``Pin.AF_OD``, then af can be the index or name
of one of the alternate functions associated with a pin.
Returns: ``None``.
.. only:: port_wipy
.. method:: pin.init(af, mode, type, strength)
Initialise the pin:
- ``af`` is the number of the alternate function. Please refer to the
`pinout and alternate functions table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
for the specific alternate functions that each pin supports.
- ``mode`` can be one of:
- ``Pin.OUT`` - no pull up or down resistors.
- ``Pin.IN`` - enable the pull-up resistor.
- ``type`` can be one of:
- ``Pin.STD`` - push-pull pin.
- ``Pin.STD_PU`` - push-pull pin with pull-up resistor.
- ``Pin.STD_PD`` - push-pull pin with pull-down resistor.
- ``Pin.OD`` - open drain pin.
- ``Pin.OD_PU`` - open drain pin with pull-up resistor.
- ``Pin.OD_PD`` - open drain pin with pull-down resistor.
- ``strength`` can be one of:
- ``Pin.S2MA`` - 2mA drive capability.
- ``Pin.S4MA`` - 4mA drive capability.
- ``Pin.S6MA`` - 6mA drive capability.
Returns: ``None``.
.. method:: pin.high()
Set the pin to a high logic level.
@ -130,6 +207,8 @@ Methods
anything that converts to a boolean. If it converts to ``True``, the pin
is set high, otherwise it is set low.
.. only:: port_pyboard
.. method:: pin.__str__()
Return a string describing the pin object.
@ -172,10 +251,54 @@ Methods
will match one of the allowed constants for the pull argument to the init
function.
.. only:: port_wipy
.. method:: pin.toggle()
Toggle the value of the pin.
.. method:: pin.info()
Return a 5-tuple with the configuration of the pin:
``(name, alternate-function, mode, type, strength)``
.. method:: pin.callback(mode, priority=1, handler=None, wakes=pyb.Sleep.ACTIVE)
Create a callback to be triggered when data is received on the UART.
- ``mode`` configures the pin level which can generate an interrupt. Possible values are:
- ``Pin.INT_FALLING`` interrupt on falling edge.
- ``Pin.INT_RISING`` interrupt on rising edge.
- ``Pin.INT_RISING_FALLING`` interrupt on rising and falling edge.
- ``Pin.INT_LOW_LEVEL`` interrupt on low level.
- ``Pin.INT_HIGH_LEVEL`` interrupt on high level.
- ``priority`` level of the interrupt. Can take values in the range 1-7.
Higher values represent higher priorities.
- ``handler`` is an optional function to be called when new characters arrive.
- ``wakes`` selects the power mode in which this interrupt can wake up the
board. Please note:
- If ``wakes=pyb.Sleep.ACTIVE`` any pin can wake the board.
- If ``wakes=pyb.Sleep.SUSPENDED`` pins ``GPIO2``, ``GPIO4``, ``GPIO10``,
``GPIO11``, GPIO17`` or ``GPIO24`` can wake the board. Note that only 1
of this pins can be enabled as a wake source at the same time, so, only
the last enabled pin as a ``pyb.Sleep.SUSPENDED`` wake source will have effect.
- If ``wakes=pyb.Sleep.SUSPENDED`` pins ``GPIO2``, ``GPIO4``, ``GPIO10``,
``GPIO11``, GPIO17`` and ``GPIO24`` can wake the board. In this case all this 6
pins can be enabled as a ``pyb.Sleep.HIBERNATE`` wake source at the same time.
- Values can be ORed to make a pin generate interrupts in more than one power
mode.
Returns a callback object.
Constants
---------
.. only:: port_pyboard
.. data:: Pin.AF_OD
initialise the pin to alternate-function mode with an open-drain drive
@ -212,6 +335,73 @@ Constants
enable the pull-up resistor on the pin
.. only:: port_wipy
.. data:: Pin.IN
input pin mode
.. data:: Pin.OUT
output pin mode
.. data:: Pin.STD
push-pull pin type
.. data:: Pin.STD_PU
push-pull pin with internall pull-up resistor
.. data:: Pin.STD_PD
push-pull pin with internall pull-down resistor
.. data:: Pin.OD
open-drain pin
.. data:: Pin.OD_PU
open-drain pin with pull-up resistor
.. data:: Pin.OD_PD
open-drain pin with pull-down resistor
.. data:: Pin.INT_FALLING
interrupt on falling edge
.. data:: Pin.INT_RISING
interrupt on rising edge
.. data:: Pin.INT_RISING_FALLING
interrupt on rising and falling edge
.. data:: Pin.INT_LOW_LEVEL
interrupt on low level
.. data:: Pin.INT_HIGH_LEVEL
interrupt on high level
.. data:: Pin.S2MA
2mA drive strength
.. data:: Pin.S4MA
4mA drive strength
.. data:: Pin.S6MA
6mA drive strength
.. only:: port_pyboard
class PinAF -- Pin Alternate Functions
======================================
@ -243,7 +433,6 @@ or::
pin = pyb.Pin(pyb.Pin.board.X3, mode=pyb.Pin.AF_PP, af=1)
Methods
-------

View File

@ -1,3 +1,5 @@
.. _pyb.RTC:
class RTC -- real time clock
============================
@ -38,6 +40,8 @@ Methods
``subseconds`` counts down from 255 to 0
.. only:: port_pyboard
.. method:: rtc.wakeup(timeout, callback=None)
Set the RTC wakeup timer to trigger repeatedly at every ``timeout``
@ -73,3 +77,15 @@ Methods
ppm; likewise the RTC clock it slowed by negative values. The
usable calibration range is:
(-511 * 0.954) ~= -487.5 ppm up to (512 * 0.954) ~= 488.5 ppm
.. only:: port_wipy
.. method:: rtc.callback(\*, value, handler=None, wakes=pyb.Sleep.ACTIVE)
Create a callback object triggered by a real time clock alarm.
- ``value`` is the alarm timeout in milliseconds. This parameter is required.
- ``handler`` is the function to be called when the callback is triggered.
- ``wakes`` specifies the power mode from where this interrupt can wake
up the system.

39
docs/library/pyb.SD.rst Normal file
View File

@ -0,0 +1,39 @@
.. _pyb.SD:
class SD -- secure digital memory card
======================================
The SD card class allows to configure and enable the memory card
module of the WiPy and automatically mount it as ``/sd`` as part
of the file system. There are several pin combinations that can be
used to wire the SD card socket to the WiPy and the pins used can
be specified in the constructor. Please check the `pinout and alternate functions
table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_ for
more info regarding the pins which can be remapped to be used with a SD card.
Example usage::
# data, clk and cmd pins must be passed along with
# their respective alternate functions
sd = pyb.SD('GPIO15', 8, 'GPIO16', 8, 'GPIO17', 8)
sd.enable() # enable and mount the SD card
sd.disable() # disable and unmount it
Constructors
------------
.. class:: pyb.SD(dat_pin, dat_pin_af, clk_pin, clk_pin_af, cmd_pin, cmd_pin_af)
Create a SD card object. Data, clock and cmd pins must be passed along with
their respective alternate functions.
Methods
-------
.. method:: sd.enable()
Enable the SD card and mount it on the file system. Accesible as ``/sd``.
.. method:: sd.disable()
Disable the SD card and remove it from the file system.

View File

@ -6,6 +6,8 @@ class SPI -- a master-driven serial protocol
SPI is a serial protocol that is driven by a master. At the physical level
there are 3 lines: SCK, MOSI, MISO.
.. only:: port_pyboard
See usage model of I2C; SPI is very similar. Main difference is
parameters to init the SPI bus::
@ -17,7 +19,19 @@ Only required parameter is mode, SPI.MASTER or SPI.SLAVE. Polarity can be
to sample data on the first or second clock edge respectively. Crc can be
None for no CRC, or a polynomial specifier.
Additional method for SPI::
.. only:: port_wipy
See usage model of I2C; SPI is very similar. Main difference is
parameters to init the SPI bus::
from pyb import SPI
spi = SPI(1, SPI.MASTER, baudrate=600000, polarity=1, phase=0)
Only required parameter is mode, must be SPI.MASTER. Polarity can be 0 or
1, and is the level the idle clock line sits at. Phase can be 0 or 1 to
sample data on the first or second clock edge respectively.
Additional methods for SPI::
data = spi.send_recv(b'1234') # send 4 bytes and receive 4 bytes
buf = bytearray(4)
@ -28,6 +42,8 @@ Additional method for SPI::
Constructors
------------
.. only:: port_pyboard
.. class:: pyb.SPI(bus, ...)
Construct an SPI object on the given bus. ``bus`` can be 1 or 2.
@ -44,6 +60,15 @@ Constructors
At the moment, the NSS pin is not used by the SPI driver and is free
for other use.
.. only:: port_wipy
.. class:: pyb.SPI(bus, ...)
Construct an SPI object on the given bus. ``bus`` can be only 1.
With no additional parameters, the SPI object is created but not
initialised (it has the settings from the last initialisation of
the bus, if any). If extra arguments are given, the bus is initialised.
See ``init`` for parameters of initialisation.
Methods
-------
@ -52,6 +77,8 @@ Methods
Turn off the SPI bus.
.. only:: port_pyboard
.. method:: spi.init(mode, baudrate=328125, \*, prescaler, polarity=1, phase=0, bits=8, firstbit=SPI.MSB, ti=False, crc=None)
Initialise the SPI bus with the given parameters:
@ -76,6 +103,27 @@ Methods
Printing the SPI object will show you the computed baudrate and the chosen
prescaler.
.. only:: port_wipy
.. method:: spi.init(mode, baudrate=328125, \*, polarity=1, phase=0, bits=8, nss=SPI.ACTIVE_LOW)
Initialise the SPI bus with the given parameters:
- ``mode`` must be ``SPI.MASTER``.
- ``baudrate`` is the SCK clock rate.
- ``polarity`` can be 0 or 1, and is the level the idle clock line sits at.
- ``phase`` can be 0 or 1 to sample data on the first or second clock edge
respectively.
- ``bits`` is the width of each transfer, accepted values are 8, 16 and 32.
- ``nss`` is the polarity of the slave select line. Can be ``SPI.ACTIVE_LOW``
or ``SPI.ACTIVE_HIGH``.
Note that the SPI clock frequency will not always be the requested baudrate.
Printing the SPI object will show you the computed baudrate and the chosen
prescaler.
.. only:: port_pyboard
.. method:: spi.recv(recv, \*, timeout=5000)
Receive data on the bus:
@ -87,6 +135,20 @@ Methods
Return value: if ``recv`` is an integer then a new buffer of the bytes received,
otherwise the same buffer that was passed in to ``recv``.
.. only:: port_wipy
.. method:: spi.recv(recv)
Receive data on the bus:
- ``recv`` can be an integer, which is the number of bytes to receive,
or a mutable buffer, which will be filled with received bytes.
Return value: if ``recv`` is an integer then a new buffer of the bytes received,
otherwise the same buffer that was passed in to ``recv``.
.. only:: port_pyboard
.. method:: spi.send(send, \*, timeout=5000)
Send data on the bus:
@ -96,6 +158,18 @@ Methods
Return value: ``None``.
.. only:: port_wipy
.. method:: spi.send(send)
Send data on the bus:
- ``send`` is the data to send (an integer to send, or a buffer object).
Return value: ``None``.
.. only:: port_pyboard
.. method:: spi.send_recv(send, recv=None, \*, timeout=5000)
Send and receive data on the bus at the same time:
@ -108,10 +182,24 @@ Methods
Return value: the buffer with the received bytes.
.. only:: port_wipy
.. method:: spi.send_recv(send, recv=None)
Send and receive data on the bus at the same time:
- ``send`` is the data to send (an integer to send, or a buffer object).
- ``recv`` is a mutable buffer which will be filled with received bytes.
It can be the same as ``send``, or omitted. If omitted, a new buffer will
be created.
Return value: the buffer with the received bytes.
Constants
---------
.. only:: port_pyboard
.. data:: SPI.MASTER
.. data:: SPI.SLAVE
@ -121,3 +209,14 @@ Constants
.. data:: SPI.MSB
set the first bit to be the least or most significant bit
.. only:: port_wipy
.. data:: SPI.MASTER
for initialising the SPI bus to master
.. data:: SPI.ACTIVE_LOW
.. data:: SPI.ACTIVE_HIGH
decides the polarity of the NSS pin

View File

@ -15,11 +15,18 @@ UART objects can be created and initialised using::
uart = UART(1, 9600) # init with given baudrate
uart.init(9600, bits=8, parity=None, stop=1) # init with given parameters
.. only:: port_pyboard
Bits can be 7, 8 or 9. Parity can be None, 0 (even) or 1 (odd). Stop can be 1 or 2.
*Note:* with parity=None, only 8 and 9 bits are supported. With parity enabled,
only 7 and 8 bits are supported.
.. only:: port_wipy
Bits can be 5, 6, 7, 8. Parity can be None, 0 (even) or 1 (odd). Stop can be 1 or 2.
A UART object acts like a stream object and reading and writing is done
using the standard stream methods::
@ -44,6 +51,8 @@ Earlier versions use ``uart.send`` and ``uart.recv``.
Constructors
------------
.. only:: port_pyboard
.. class:: pyb.UART(bus, ...)
Construct a UART object on the given bus. ``bus`` can be 1-6, or 'XA', 'XB', 'YA', or 'YB'.
@ -60,10 +69,22 @@ Constructors
- ``UART(3)`` is on ``YB``: ``(TX, RX) = (Y9, Y10) = (PB10, PB11)``
- ``UART(2)`` is on: ``(TX, RX) = (X3, X4) = (PA2, PA3)``
.. only:: port_wipy
.. class:: pyb.UART(bus, ...)
Construct a UART object on the given bus. ``bus`` can be 1 or 2.
With no additional parameters, the UART object is created but not
initialised (it has the settings from the last initialisation of
the bus, if any). If extra arguments are given, the bus is initialised.
See ``init`` for parameters of initialisation.
Methods
-------
.. method:: uart.init(baudrate, bits=8, parity=None, stop=1, \*, timeout=1000, timeout_char=0, read_buf_len=64)
.. only:: port_pyboard
.. method:: uart.init(baudrate, bits=8, parity=None, stop=1, \*, timeout=1000, flow=None, timeout_char=0, read_buf_len=64)
Initialise the UART bus with the given parameters:
@ -71,6 +92,8 @@ Methods
- ``bits`` is the number of bits per character, 7, 8 or 9.
- ``parity`` is the parity, ``None``, 0 (even) or 1 (odd).
- ``stop`` is the number of stop bits, 1 or 2.
- ``flow`` sets the flow control type. Can be None, ``UART.RTS``, ``UART.CTS``
or ``UART.RTS | UART.CTS``.
- ``timeout`` is the timeout in milliseconds to wait for the first character.
- ``timeout_char`` is the timeout in milliseconds to wait between characters.
- ``read_buf_len`` is the character length of the read buffer (0 to disable).
@ -85,6 +108,21 @@ Methods
*Note:* with parity=None, only 8 and 9 bits are supported. With parity enabled,
only 7 and 8 bits are supported.
.. only:: port_wipy
.. method:: uart.init(baudrate, bits=8, parity=None, stop=1, \*, timeout=1000, flow=None, timeout_char=0)
Initialise the UART bus with the given parameters:
- ``baudrate`` is the clock rate.
- ``bits`` is the number of bits per character, 7, 8 or 9.
- ``parity`` is the parity, ``None``, 0 (even) or 1 (odd).
- ``stop`` is the number of stop bits, 1 or 2.
- ``flow`` sets the flow control type. Can be None, ``UART.RTS``, ``UART.CTS``
or ``UART.RTS | UART.CTS``.
- ``timeout`` is the timeout in milliseconds to wait for the first character.
- ``timeout_char`` is the timeout in milliseconds to wait between characters.
.. method:: uart.deinit()
Turn off the UART bus.
@ -97,12 +135,19 @@ Methods
Read characters. If ``nbytes`` is specified then read at most that many bytes.
.. only:: port_pyboard
*Note:* for 9 bit characters each character takes two bytes, ``nbytes`` must
be even, and the number of characters is ``nbytes/2``.
Return value: a bytes object containing the bytes read in. Returns ``b''``
on timeout.
.. only:: port_wipy
Return value: a bytes object containing the bytes read in. Returns ``b''``
on timeout.
.. method:: uart.readall()
Read as much data as possible.
@ -130,6 +175,8 @@ Methods
.. method:: uart.write(buf)
.. only:: port_pyboard
Write the buffer of bytes to the bus. If characters are 7 or 8 bits wide
then each byte is one character. If characters are 9 bits wide then two
bytes are used for each character (little endian), and ``buf`` must contain
@ -137,6 +184,12 @@ Methods
Return value: number of bytes written.
.. only:: port_wipy
Write the buffer of bytes to the bus.
Return value: number of bytes written.
.. method:: uart.writechar(char)
Write a single character on the bus. ``char`` is an integer to write.
@ -147,3 +200,36 @@ Methods
Send a break condition on the bus. This drives the bus low for a duration
of 13 bits.
Return value: ``None``.
.. only:: port_wipy
.. method:: uart.callback(value, priority=1, handler=None)
Create a callback to be triggered when data is received on the UART.
- ``value`` sets the size in bytes of the Rx buffer. Every character
received is put into this buffer as long as there's space free.
- ``priority`` level of the interrupt. Can take values in the range 1-7.
Higher values represent higher priorities.
- ``handler`` an optional function to be called when new characters arrive.
.. note::
The handler will be called whenever any of the following two conditions are met:
- 4 new characters have been received.
- At least 1 new character is waiting in the Rx buffer and the Rx line has been
silent for the duration of 1 complete frame.
This means that when the handler function is called there might be 1, 2, 3 or 4
characters waiting.
Return a callback object.
Constants
---------
.. data:: UART.RTS
.. data:: UART.CTS
to select the flow control type

33
docs/library/pyb.WDT.rst Normal file
View File

@ -0,0 +1,33 @@
.. _pyb.WDT:
class WDT -- watchdog timer
===========================
The WDT is used to restart the system when the application crashes and ends
up into a non recoverable state. Once started it cannot be stopped or
reconfigured in any way. After enabling, the application must "kick" the
watchdog periodically to prevent it from expiring and resetting the system.
Example usage::
wdt = pyb.WDT(5000) # enable with a timeout of 5s
wdt.kick()
Constructors
------------
.. class:: pyb.WDT([timeout])
Create a WDT object. If the timeout is specified the WDT is started.
The timeout must be given in seconds and 1s the minimum value that
is accepted. Once it is running the timeout cannot be changed and
the WDT cannot be stopped either.
Methods
-------
.. method:: wdt.kick()
Kick the WDT to prevent it from resetting the system. The application
should place this call in a sensible place ensuring that the WDT is
only kicked after verifying that everything is functioning correctly.

View File

@ -1,10 +1,10 @@
:mod:`pyb` --- functions related to the pyboard
===============================================
:mod:`pyb` --- functions related to the board
=============================================
.. module:: pyb
:synopsis: functions related to the pyboard
:synopsis: functions related to the board
The ``pyb`` module contains specific functions related to the pyboard.
The ``pyb`` module contains specific functions related to the board.
Time related functions
----------------------
@ -63,11 +63,22 @@ Time related functions
Reset related functions
-----------------------
.. only:: port_pyboard
.. function:: hard_reset()
Resets the pyboard in a manner similar to pushing the external RESET
button.
.. only:: port_wipy
.. function:: reset()
Resets the WiPy in a manner similar to pushing the external RESET
button.
.. only:: port_pyboard
.. function:: bootloader()
Activate the bootloader without BOOT\* pins.
@ -93,6 +104,8 @@ Interrupt related functions
Power related functions
-----------------------
.. only:: port_pyboard
.. function:: freq([sysclk[, hclk[, pclk1[, pclk2]]]])
If given no arguments, returns a tuple of clock frequencies:
@ -161,9 +174,20 @@ Power related functions
See :meth:`rtc.wakeup` to configure a real-time-clock wakeup event.
.. only:: port_wipy
.. function:: freq([sysclk])
Returns a tuple of clock frequencies: ``(sysclk)``
These correspond to:
- sysclk: frequency of the CPU
Miscellaneous functions
-----------------------
.. only:: port_pyboard
.. function:: have_cdc()
Return True if USB is connected as a serial device, False otherwise.
@ -188,6 +212,8 @@ Miscellaneous functions
It only makes sense to call this function from within boot.py.
.. only:: port_pyboard
.. function:: mount(device, mountpoint, \*, readonly=False, mkfs=False)
Mount a block device and make it available as part of the filesystem.
@ -223,21 +249,40 @@ Miscellaneous functions
Get or set the UART object that the REPL is repeated on.
.. only:: port_pyboard
.. function:: rng()
Return a 30-bit hardware generated random number.
.. only:: port_wipy
.. function:: rng()
Return a 24-bit software generated random number.
.. function:: sync()
Sync all file systems.
.. only:: port_pyboard
.. function:: unique_id()
Returns a string of 12 bytes (96 bits), which is the unique ID for the MCU.
.. only:: port_wipy
.. function:: unique_id()
Returns a string of 6 bytes (48 bits), which is the unique ID for the MCU.
This also corresponds to the ``MAC address`` of the WiPy.
Classes
-------
.. only:: port_pyboard
.. toctree::
:maxdepth: 1
@ -257,3 +302,19 @@ Classes
pyb.Timer.rst
pyb.UART.rst
pyb.USB_VCP.rst
.. only:: port_wipy
.. toctree::
:maxdepth: 1
pyb.ADC.rst
pyb.HeartBeat.rst
pyb.I2C.rst
pyb.Pin.rst
pyb.RTC.rst
pyb.SD.rst
pyb.SPI.rst
pyb.Timer.rst
pyb.UART.rst
pyb.WDT.rst

View File

@ -31,11 +31,25 @@ Functions
which expresses a time as per localtime. It returns an integer which is
the number of seconds since Jan 1, 2000.
.. only:: port_pyboard
.. function:: sleep(seconds)
Sleep for the given number of seconds. Seconds can be a floating-point number to
sleep for a fractional number of seconds.
.. only:: port_esp8266
.. function:: sleep(seconds)
Sleep for the given number of seconds.
.. only:: port_wipy
.. function:: sleep(milliseconds)
Sleep for the given number of milliseconds.
.. function:: time()
Returns the number of seconds, as an integer, since 1/1/2000.

View File

@ -141,7 +141,7 @@ Module contents
at the given memory address.
Structure descriptors and instantiating structure objects
-----------------------------------------------------
---------------------------------------------------------
Given a structure descriptor dictionary and its layout type, you can
instantiate a specific structure instance at a given memory address

View File

@ -4,6 +4,8 @@
.. module:: uhashlib
:synopsis: hashing algorithm
.. only:: port_pyboard
This module implements binary data hashing algorithms. Currently, it
implements SHA256 algorithm. Choosing SHA256 was a deliberate choice,
as a modern, cryptographically secure algorithm. This means that a
@ -11,27 +13,69 @@ single algorithm can cover both usecases of "any hash algorithm" and
security-related usage, and thus save space omitting legacy algorithms
like MD5 or SHA1.
.. only:: port_wipy
This module implements binary data hashing algorithms. Currently, it
implements SHA1 and SHA256 algorithms only. These two algorithms are
more than enough for today's web applications.
Constructors
------------
.. only:: port_pyboard
.. class:: uhashlib.sha256([data])
Create a hasher object and optionally feed ``data`` into it.
.. only:: port_wipy
.. class:: uhashlib.sha1([data[, block_size]])
Create a sha1 hasher object and optionally feed ``data`` or ``data and block_size`` into it.
.. class:: uhashlib.sha256([data[, block_size]])
Create a sha256 hasher object and optionally feed ``data`` or ``data and block_size`` into it.
.. admonition:: CPython extension
:class: attention
Due to hardware implementation details of the WiPy, data must be buffered before being
digested, which would make impossible to calculate the hash of big blocks of data that
do not fit in RAM. In this case, since most likely the total size of the data is known
in advance, the size can be passed to the constructor and hence the HASH hardware engine
of the WiPy can be properly initialized without needing buffering. If ``block_size`` is
to be given, an initial chunk of ``data`` must be passed as well. **When using this extension,
care must be taken to make sure that the length of all intermediate chunks (including the
initial one) is a multiple of 4 bytes.** The last chunk may be of any length.
Example::
hash = uhashlib.sha1('abcd1234', 1001) # lenght of the initial piece is multiple of 4 bytes
hash.update('1234') # also multiple of 4 bytes
...
hash.update('12345') # last chunk may be of any length
hash.digest()
Methods
-------
.. method:: sha256.update(data)
.. method:: hash.update(data)
Feed more binary data into hash.
.. method:: sha256.digest()
.. method:: hash.digest()
Return hash for all data passed thru hash, as a bytes object. After this
method is called, more data cannot be fed into hash any longer.
.. method:: sha256.hexdigest()
.. only:: port_wipy
This method is NOT implemented. Use ``ubinascii.hexlify(sha256.digest())``
to achieve similar effect.
SHA1 hashes are 20-byte long. SHA256 hashes are 32-byte long.
.. method:: hash.hexdigest()
This method is NOT implemented. Use ``ubinascii.hexlify(hash.digest())``
to achieve a similar effect.

View File

@ -1,3 +1,5 @@
.. only:: port_pyboard
.. _quickref:
Quick reference for the pyboard

View File

@ -53,8 +53,8 @@ For example::
dac.write_timed(buf, 400 * len(buf), mode=DAC.CIRCULAR)
You can also play WAV files using the Python ``wave`` module. You can get
the wave module `here <http://micropython.org/resources/examples/wave.py>`_ and you will also need
the chunk module available `here <http://micropython.org/resources/examples/chunk.py>`_. Put these
the wave module `here <http://micropython.org/resources/examples/wave.py>`__ and you will also need
the chunk module available `here <http://micropython.org/resources/examples/chunk.py>`__. Put these
on your pyboard (either on the flash or the SD card in the top-level directory). You will need an
8-bit WAV file to play, such as `this one <http://micropython.org/resources/examples/test.wav>`_,
or to convert any file you have with the command::

View File

@ -60,7 +60,7 @@ enables the 4 touch sensors. The third line reads the touch
status and the ``touch`` variable holds the state of the 4 touch
buttons (A, B, X, Y).
There is a simple driver `here <http://micropython.org/resources/examples/mpr121.py>`_
There is a simple driver `here <http://micropython.org/resources/examples/mpr121.py>`__
which allows you to set the threshold and debounce parameters, and
easily read the touch status and electrode voltage levels. Copy
this script to your pyboard (either flash or SD card, in the top
@ -83,4 +83,4 @@ initialise the I2C bus using::
>>> m = mpr121.MPR121(pyb.I2C(2, pyb.I2C.MASTER))
There is also a demo which uses the LCD and the touch sensors together,
and can be found `here <http://micropython.org/resources/examples/lcddemo.py>`_.
and can be found `here <http://micropython.org/resources/examples/lcddemo.py>`__.

12
docs/pyboard_contents.rst Normal file
View File

@ -0,0 +1,12 @@
MicroPython documentation contents
==================================
.. toctree::
pyboard/quickref.rst
pyboard/general.rst
pyboard/tutorial/index.rst
library/index.rst
pyboard/hardware/index.rst
license.rst

19
docs/pyboard_index.rst Normal file
View File

@ -0,0 +1,19 @@
MicroPython documentation and references
========================================
.. toctree::
pyboard/quickref.rst
pyboard/general.rst
pyboard/tutorial/index.rst
library/index.rst
pyboard/hardware/index.rst
license.rst
pyboard_contents.rst
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -21,11 +21,11 @@
{% endfor %}.
</p-->
<p><strong>Documentation for MicroPython and the pyboard:</strong></p>
<p><strong>Documentation for MicroPython and {{ port_name }}:</strong></p>
<table class="contentstable"><tr>
<td width="40%" style="padding-left:2em;">
{% if port == "pyboard" %}
{% if port == "pyboard" or port == "wipy" %}
<p class="biglink">
<a class="biglink" href="{{ pathto(port + "/quickref") }}">Quick reference for {{ port_name }}</a><br/>
<span class="linkdescr">pinout for {{ port_name }} and snippets of useful code</span>
@ -34,6 +34,8 @@
<a class="biglink" href="{{ pathto(port + "/general") }}">General information about {{ port_name }}</a><br/>
<span class="linkdescr">read this first for a quick overview</span>
</p>
{% endif %}
{% if port == "pyboard" %}
<p class="biglink">
<a class="biglink" href="{{ pathto(port + "/tutorial/index") }}">Tutorials and code examples</a><br/>
<span class="linkdescr">start here</span>
@ -76,7 +78,7 @@
</td>
<td width="40%" style="padding-left:2em;">
<p class="biglink">
<a class="biglink" href="{{ pathto("contents") }}">Table of contents</a><br/>
<a class="biglink" href="{{ pathto(port + "_contents") }}">Table of contents</a><br/>
<span class="linkdescr">a list of all sections and subsections</span>
</p>
</td></tr>
@ -100,6 +102,12 @@
<a class="biglink" href="https://github.com/micropython">MicroPython on GitHub</a><br/>
<span class="linkdescr">contribute to the source code on GitHub</span>
</p>
{% if port == "wipy" %}
<p class="biglink">
<a class="biglink" href="http://wipy.io">The WiPy homepage</a><br/>
<span class="linkdescr">the official WiPy site</span>
</p>
{% endif %}
</td>
</tr></table>

59
docs/wipy/general.rst Normal file
View File

@ -0,0 +1,59 @@
General information about the WiPy
==================================
WLAN default behaviour
----------------------
When the WiPy boots with the default factory configuration starts in Access Point
mode with ``ssid: wipy-wlan`` and ``key: www.wipy.io``.
Connect to this network and the WiPy will be reachable at ``192.168.1.1``. In order
to gain access to the interactive prompt, open a telnet session to that IP address on
the default port (23). You will be asked for credentials:
``login: micro`` ``password: python``
Local file system and SD card
-----------------------------
There is a small internal file system (a drive) on the WiPy, called ``/flash``,
which is stored within the external serial flash memory. If a micro SD card
is hooked-up and enabled, it is available as ``/sd``.
When the WiPy boots up, it always boots from the ``boot.py`` located in the
``/flash`` file system. If during the boot process the SD card is enabled and
it's selected as the current drive then the WiPy will try to execute ``main.py``
that should be located in the SD card.
The file system is accessible via the native FTP server running in the WiPy.
Open your FTP client of choice and connect to:
``ftp://192.168.1.1`` ``user: micro`` ``password: python``
Boot modes
----------
If you power up normally, or press the reset button, the WiPy will boot
into standard mode: the ``boot.py`` file will be executed first, then
``main.py`` will run.
You can override this boot sequence by pulling ``GPIO28`` **up** during reset.
The heart beat LED will flash slowly 3 times to signal that safe boot is being
requested, and then 3 more times quickly to let you know that safe boot is
going to be performed. While safe booting, the WiPy runs the factory firmware
and skips the execution of ``boot.py`` and ``main.py``. This is useful to
recover from any crash situation.
The heart beat LED
------------------
By default the heart beat LED flashes once every 5s to signal that the system is
alive. This can be overridden through the HeartBeat class:
``pyb.HeartBeat().disable()``
There are currently 2 kinds of errors that you might see:
1. If the heart beat LED flashes quickly, then a Python script(eg ``main.py``)
has an error. Use the REPL to debug it.
2. If the heart beat LED stays on, then there was a hard fault, you cannot
recover from this, the only way out is by pressing the reset switch.

228
docs/wipy/quickref.rst Normal file
View File

@ -0,0 +1,228 @@
.. only:: port_wipy
.. _quickref_:
Quick reference for the WiPy
============================
.. image:: https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png
:alt: WiPy pinout and alternate functions table
:width: 800px
General board control
---------------------
See :mod:`pyb`. ::
import pyb
help(pyb) # display all members from the pyb module
pyb.delay(50) # wait 50 milliseconds
pyb.millis() # number of milliseconds since boot-up
pyb.freq() # get the CPU frequency
pyb.unique_id() # return the 6-byte unique id of the board (it's MAC address)
Pins and GPIO
-------------
See :ref:`pyb.Pin <pyb.Pin>`. ::
from pyb import Pin
# initialize GPIO2 in gpio mode (af=0) and make it an output
p_out = Pin('GPIO2', af=0, mode=Pin.OUT)
p_out.high()
p_out.low()
p_out.toggle()
# make GPIO1 an input with the pull-up enabled
p_in = Pin('GPIO1', af = 0, mode=Pin.IN, type = Pin.STD_PU)
p_in.value() # get value, 0 or 1
Timers
------
See :ref:`pyb.Timer <pyb.Timer>` and :ref:`pyb.Pin <pyb.Pin>`. ::
from pyb import Timer
from pyb import Pin
tim = Timer(1, mode=Timer.PERIODIC)
tim_a = tim.channel(Timer.A, freq=1000)
tim_a.time() # get the value in microseconds
tim_a.freq(1) # 1 Hz
p_out = Pin('GPIO2', af=0, mode=Pin.OUT)
tim_a.callback(handler=lambda t: p_out.toggle())
PWM (pulse width modulation)
----------------------------
See :ref:`pyb.Pin <pyb.Pin>` and :ref:`pyb.Timer <pyb.Timer>`. ::
from pyb import Timer
from pyb import Pin
# assign GPIO25 to alternate function 5 (PWM)
p_out = Pin('GPIO25', af=9, type=Pin.STD)
# timer 2 in PWM mode and width must be 16 buts
tim = Timer(2, mode=Timer.PWM, width=16)
# enable channel A @1KHz with a 50% duty cycle
tim_a = tim.channel(Timer.A, freq=1000, duty_cycle=50)
ADC (analog to digital conversion)
----------------------------------
See :ref:`pyb.ADC <pyb.ADC>`. ::
from pyb import ADC
adc = ADC(1)
adc.read() # read value, 0-4095
UART (serial bus)
-----------------
See :ref:`pyb.Pin <pyb.Pin>` and :ref:`pyb.UART <pyb.UART>`. ::
from pyb import Pin, UART
# first assign TX and RX to the correct pins
Pin('GPIO1', af=3, mode=Pin.STD_PU) # TX
Pin('GPIO2', af=3, mode=Pin.STD_PU) # RX
uart = UART(1, 9600)
uart.write('hello')
uart.read(5) # read up to 5 bytes
SPI bus
-------
See :ref:`pyb.Pin <pyb.Pin>` and :ref:`pyb.SPI <pyb.SPI>`. ::
from pyb import Pin, SPI
# first assign CLK, MISO, MOSI, CS to the correct pins
Pin('GPIO14', af=7, mode=Pin.STD) # CLK
Pin('GPIO15', af=7, mode=Pin.STD) # MISO
Pin('GPIO16', af=7, mode=Pin.STD) # MOSI
Pin('GPIO17', af=7, mode=Pin.STD) # NSS/CS
# configure the SPI master @ 2MHz
spi = SPI(1, SPI.MASTER, baudrate=200000, polarity=0, phase=0)
spi.send('hello')
spi.recv(5) # receive 5 bytes on the bus
spi.send_recv('hello') # send a receive 5 bytes
I2C bus
-------
See :ref:`pyb.Pin <pyb.Pin>` and :ref:`pyb.I2C <pyb.I2C>`. ::
from pyb import Pin, I2C
# first assign SCL and SDA to the correct pins
Pin('GPIO23', af=9, mode=Pin.STD_PU) # SCL
Pin('GPIO24', af=9, mode=Pin.STD_PU) # SDA
# configure the I2C bus
i2c = I2C(1, I2C.MASTER, baudrate=100000)
i2c.scan() # returns list of slave addresses
i2c.send('hello', 0x42) # send 5 bytes to slave with address 0x42
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
Watchdog timer (WDT)
--------------------
See :ref:`pyb.WDT <pyb.WDT>`. ::
from pyb import WDT
# enable the WDT with a timeout of 5s (1s is the minimum)
wdt = WDT(5000)
wdt.kick()
Real time clock (RTC)
---------------------
See :ref:`pyb.RTC <pyb.RTC>` and ``pyb.Sleep``. ::
from pyb import RTC, Sleep
rtc = pyb.RTC()
rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))
print(rtc.datetime())
def some_handler (rtc_obj):
# trigger the callback again in 30s
rtc_obj.callback(value=30000, handler=some_handler)
# create a RTC alarm that expires in 30s
rtc.callback(value=30000, handler=some_handler, wakes=Sleep.SUSPENDED)
# go into suspended mode waiting for the RTC alarm to expire and wake us up
Sleep.suspend()
SD card
-------
See :ref:`pyb.SD <pyb.SD>`. ::
from pyb import SD
# SD card pins need special configuration so we pass 'em to the constructor
# data pin, data af, clock pin, clock af, cmd pin, cmd af
sd = SD('GPIO15', 8, 'GPIO16', 8, 'GPIO17', 8)
sd.enable()
WLAN (WiFi)
-----------
See :ref:`network.WLAN <network.WLAN>` and ``pyb.Sleep``. ::
from network import WLAN
from pyb import Sleep
# configure the WLAN subsystem in station mode (the default is AP)
wifi = WLAN(WLAN.STA)
# go for fixed IP settings
wifi.ifconfig('192.168.0.107', '255.255.255.0', '192.168.0.1', '8.8.8.8')
wifi.scan() # scan for available netrworks
wifi.connect(ssid='mynetwork', security=2, key='mynetworkkey')
while not wifi.isconnected():
pass
print(wifi.ifconfig())
# enable wake on WLAN
wifi.callback(wakes=Sleep.SUSPENDED)
# go to sleep
Sleep.suspend()
# now, connect to the FTP or the Telnet server and the WiPy will wake-up
Sleep and power modes control
-----------------------------
See ``pyb.Sleep``. ::
from pyb import Sleep
Sleep.idle() # lowest sleep mode (~12mA), any interrupts wakes it up
Sleep.suspend() # everything except for WLAN is powered down (~950uA)
# wakes from Pin, RTC or WLAN
Sleep.hibernate() # deepest sleep mode, mcu starts from reset. Wakes from Pin and RTC.
Heart beat LED
-----------------------------
See :ref:`pyb.HeartBeat <pyb.HeartBeat>`. ::
from pyb import HeartBeat
# disable the heart beat indication (you are free to use this led connected to GPIO25)
HeartBeat.disable()
# enable the heart beat again
HeartBeat.enable()

9
docs/wipy_contents.rst Normal file
View File

@ -0,0 +1,9 @@
MicroPython documentation contents
==================================
.. toctree::
wipy/quickref.rst
wipy/general.rst
library/index.rst
license.rst

17
docs/wipy_index.rst Normal file
View File

@ -0,0 +1,17 @@
MicroPython documentation and references
========================================
.. toctree::
wipy/quickref.rst
wipy/general.rst
library/index.rst
license.rst
wipy_contents.rst
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`