2015-10-14 06:32:01 -04:00
|
|
|
:mod:`machine` --- functions related to the board
|
|
|
|
=================================================
|
|
|
|
|
|
|
|
.. module:: machine
|
|
|
|
:synopsis: functions related to the board
|
|
|
|
|
|
|
|
The ``machine`` module contains specific functions related to the board.
|
|
|
|
|
|
|
|
Reset related functions
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
.. function:: reset()
|
|
|
|
|
2016-04-03 13:40:27 -04:00
|
|
|
Resets the device in a manner similar to pushing the external RESET
|
2015-10-14 06:32:01 -04:00
|
|
|
button.
|
|
|
|
|
2016-04-17 10:40:08 -04:00
|
|
|
.. function:: reset_cause()
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-04-17 10:40:08 -04:00
|
|
|
Get the reset cause. See :ref:`constants <machine_constants>` for the possible return values.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
.. only:: port_wipy
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
Interrupt related functions
|
|
|
|
---------------------------
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
.. function:: disable_irq()
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
Disable interrupt requests.
|
|
|
|
Returns the previous IRQ state: ``False``/``True`` for disabled/enabled IRQs
|
|
|
|
respectively. This return value can be passed to enable_irq to restore
|
|
|
|
the IRQ to its original state.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
.. function:: enable_irq(state=True)
|
|
|
|
|
|
|
|
Enable interrupt requests.
|
|
|
|
If ``state`` is ``True`` (the default value) then IRQs are enabled.
|
|
|
|
If ``state`` is ``False`` then IRQs are disabled. The most common use of
|
|
|
|
this function is to pass it the value returned by ``disable_irq`` to
|
|
|
|
exit a critical section.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
Power related functions
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
.. function:: freq()
|
|
|
|
|
2016-04-15 10:06:11 -04:00
|
|
|
.. only:: not port_wipy
|
|
|
|
|
|
|
|
Returns CPU frequency in hertz.
|
|
|
|
|
|
|
|
.. only:: port_wipy
|
|
|
|
|
|
|
|
Returns a tuple of clock frequencies: ``(sysclk,)``
|
|
|
|
These correspond to:
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-04-15 10:06:11 -04:00
|
|
|
- sysclk: frequency of the CPU
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
.. function:: idle()
|
|
|
|
|
|
|
|
Gates the clock to the CPU, useful to reduce power consumption at any time during
|
|
|
|
short or long periods. Peripherals continue working and execution resumes as soon
|
|
|
|
as any interrupt is triggered (including the systick which has a period of 1ms).
|
|
|
|
|
|
|
|
.. function:: sleep()
|
|
|
|
|
|
|
|
Stops the CPU and disables all peripherals except for WLAN. Execution is resumed from
|
|
|
|
the point where the sleep was requested. Wake sources are ``Pin``, ``RTC`` and ``WLAN``.
|
|
|
|
|
|
|
|
.. function:: deepsleep()
|
|
|
|
|
|
|
|
Stops the CPU and all peripherals including WLAN. Execution is resumed from main, just
|
|
|
|
as with a reset. The reset cause can be checked to know that we are coming from
|
2016-05-03 05:26:55 -04:00
|
|
|
``machine.DEEPSLEEP``. Wake sources are ``Pin`` and ``RTC``.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
.. only:: port_wipy
|
|
|
|
|
|
|
|
.. function:: wake_reason()
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
Get the wake reason. See :ref:`constants <machine_constants>` for the possible return values.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
Miscellaneous functions
|
|
|
|
-----------------------
|
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
.. only:: port_wipy
|
|
|
|
|
|
|
|
.. function:: main(filename)
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
Set the filename of the main script to run after boot.py is finished. If
|
|
|
|
this function is not called then the default file main.py will be executed.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
It only makes sense to call this function from within boot.py.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
.. function:: rng()
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
Return a 24-bit software generated random number.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
.. function:: unique_id()
|
|
|
|
|
2016-05-03 05:15:29 -04:00
|
|
|
Returns a byte string with a unique idenifier of a board/SoC. It will vary
|
|
|
|
from a board/SoC instance to another, if underlying hardware allows. Length
|
|
|
|
varies by hardware (so use substring of a full value if you expect a short
|
|
|
|
ID). In some MicroPython ports, ID corresponds to the network MAC address.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
.. _machine_constants:
|
|
|
|
|
|
|
|
Constants
|
|
|
|
---------
|
|
|
|
|
|
|
|
.. data:: machine.IDLE
|
|
|
|
.. data:: machine.SLEEP
|
|
|
|
.. data:: machine.DEEPSLEEP
|
|
|
|
|
|
|
|
irq wake values
|
|
|
|
|
|
|
|
.. data:: machine.POWER_ON
|
|
|
|
.. data:: machine.HARD_RESET
|
|
|
|
.. data:: machine.WDT_RESET
|
|
|
|
.. data:: machine.DEEPSLEEP_RESET
|
|
|
|
.. data:: machine.SOFT_RESET
|
|
|
|
|
|
|
|
reset causes
|
|
|
|
|
|
|
|
.. data:: machine.WLAN_WAKE
|
|
|
|
.. data:: machine.PIN_WAKE
|
|
|
|
.. data:: machine.RTC_WAKE
|
|
|
|
|
|
|
|
wake reasons
|
|
|
|
|
|
|
|
Classes
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 1
|
|
|
|
|
|
|
|
machine.ADC.rst
|
|
|
|
machine.I2C.rst
|
|
|
|
machine.Pin.rst
|
|
|
|
machine.RTC.rst
|
|
|
|
machine.SD.rst
|
|
|
|
machine.SPI.rst
|
|
|
|
machine.Timer.rst
|
|
|
|
machine.UART.rst
|
|
|
|
machine.WDT.rst
|