.. currentmodule:: esp32 :mod:`esp32` --- functionality specific to the ESP32 :mod:`esp32` --- 特定于ESP32的功能 ==================================================== .. module:: esp32 :synopsis: functionality specific to the ESP32 :synopsis: 特定于ESP32的功能 The ``esp32`` module contains functions and classes specifically aimed at controlling ESP32 modules. “esp32”模块包含专门针对的函数和类 控制ESP32模块。 Functions 功能 --------- .. function:: wake_on_touch(wake) Configure whether or not a touch will wake the device from sleep. *wake* should be a boolean value. 配置触摸是否将唤醒设备从睡眠。 *wake*应该是一个布尔值。 .. function:: wake_on_ext0(pin, level) Configure how EXT0 wakes the device from sleep. *pin* can be ``None`` or a valid Pin object. *level* should be ``esp32.WAKEUP_ALL_LOW`` or ``esp32.WAKEUP_ANY_HIGH``. 配置EXT0如何将设备从睡眠中唤醒。*pin*可以是“无” 或有效的Pin对象。*级别*应该是esp32。WAKEUP_ALL_LOW”或 ``esp32.WAKEUP_ANY_HIGH``。 .. function:: wake_on_ext1(pins, level) Configure how EXT1 wakes the device from sleep. *pins* can be ``None`` or a tuple/list of valid Pin objects. *level* should be ``esp32.WAKEUP_ALL_LOW`` or ``esp32.WAKEUP_ANY_HIGH``. 配置EXT1如何将设备从睡眠中唤醒。*pins*可以是“None” 或有效Pin对象的元组/列表。*level*应该是``esp32.WAKEUP_ALL_LOW`` 或``esp32.WAKEUP_ANY_HIGH``。 .. function:: raw_temperature() Read the raw value of the internal temperature sensor, returning an integer. 读取内部温度传感器的原始值,返回一个整数。 .. function:: hall_sensor() Read the raw value of the internal Hall sensor, returning an integer. 读取内部霍尔传感器的原始值,返回一个整数。 Flash partitions ---------------- This class gives access to the partitions in the device's flash memory. 这个类提供对设备闪存中的分区的访问。 .. class:: Partition(id) Create an object representing a partition. *id* can be a string which is the label of the partition to retrieve, or one of the constants: ``BOOT`` or ``RUNNING``. 创建一个表示分区的对象。*id*可以是字符串,也就是标签 的分区,或一个常量:``BOOT`` 或 ``RUNNING``。 .. classmethod:: Partition.find(type=TYPE_APP, subtype=0xff, label=None) Find a partition specified by *type*, *subtype* and *label*. Returns a (possibly empty) list of Partition objects. 查找由*类型*、*子类型*和*标签*指定的分区。返回一个 分区对象列表(可能为空)。 .. method:: Partition.info() Returns a 6-tuple ``(type, subtype, addr, size, label, encrypted)``. 返回一个6元组“(类型、子类型、地址、大小、标签、加密)”。 .. method:: Partition.readblocks(block_num, buf) .. method:: Partition.readblocks(block_num, buf, offset) .. method:: Partition.writeblocks(block_num, buf) .. method:: Partition.writeblocks(block_num, buf, offset) .. method:: Partition.ioctl(cmd, arg) These methods implement the simple and :ref:`extended ` block protocol defined by :class:`uos.AbstractBlockDev`. 这些方法实现了simple和:ref: ' extended <块-设备-接口> '定义的块协议 类:“uos.AbstractBlockDev”。 .. method:: Partition.set_boot() Sets the partition as the boot partition. 将分区设置为引导分区。 .. method:: Partition.get_next_update() Gets the next update partition after this one, and returns a new Partition object. 获取此分区之后的下一个更新分区,并返回一个新的分区对象。 Constants ~~~~~~~~~ .. data:: Partition.BOOT Partition.RUNNING Used in the `Partition` constructor to fetch various partitions. 在“Partition”构造函数中用于获取不同的分区。 .. data:: Partition.TYPE_APP Partition.TYPE_DATA Used in `Partition.find` to specify the partition type. 使用`Partition.find`查找以指定分区类型。 .. _esp32.RMT: RMT --- The RMT (Remote Control) module, specific to the ESP32, was originally designed to send and receive infrared remote control signals. However, due to a flexible design and very accurate (as low as 12.5ns) pulse generation, it can also be used to transmit or receive many other types of digital signals:: 针对ESP32的RMT(远程控制)模块是最初设计的 发送和接收红外遥控信号。但是,由于灵活 设计非常精确(低至12.5ns)的脉冲产生,也可以 用于发射或接收许多其他类型的数字信号:: import esp32 from machine import Pin 从机器进口销 r = esp32.RMT(0, pin=Pin(18), clock_div=8) r # RMT(channel=0, pin=18, source_freq=80000000, clock_div=8) # The channel resolution is 100ns (1/(source_freq/clock_div)). r.write_pulses((1, 20, 2, 40), start=0) # Send 0 for 100ns, 1 for 2000ns, 0 for 200ns, 1 for 4000ns The input to the RMT module is an 80MHz clock (in the future it may be able to configure the input clock but, for now, it's fixed). ``clock_div`` *divides* the clock input which determines the resolution of the RMT channel. The numbers specificed in ``write_pulses`` are multiplied by the resolution to define the pulses. RMT模块的输入是一个80MHz的时钟(将来它可能能够做到) 配置输入时钟,但目前,它是固定的)。“clock_div ' ' *分* 决定RMT信道分辨率的时钟输入。的 在' ' write_pulse ' '中指定的数字乘以分辨率 定义脉冲。 ``clock_div`` is an 8-bit divider (0-255) and each pulse can be defined by multiplying the resolution by a 15-bit (0-32,768) number. There are eight channels (0-7) and each can have a different clock divider. ``clock_div``是一个8位分配器(0-255),每个脉冲可以定义 将分辨率乘以一个15位(0-32,768)的数字。有八个 通道(0-7)和每个可以有一个不同的时钟分频器。 So, in the example above, the 80MHz clock is divided by 8. Thus the resolution is (1/(80Mhz/8)) 100ns. Since the ``start`` level is 0 and toggles with each number, the bitstream is ``0101`` with durations of [100ns, 2000ns, 100ns, 4000ns]. 因此,在上面的例子中,80MHz时钟被8除以。因此, 分辨率为(1/(80Mhz/8)) 100ns。因为“开始”级别是0和切换 对于每个数字,比特流为' ' 0101 ' ',持续时间为[100ns, 2000ns, 100 ns 4000 ns)。 For more details see Espressif's `ESP-IDF RMT documentation. 更多细节请参见Espressif的ESP-IDF RMT文档。 `_. .. Warning:: .. 警告:: The current MicroPython RMT implementation lacks some features, most notably receiving pulses and carrier transmit. RMT should be considered a *beta feature* and the interface may change in the future. 目前的MicroPython RMT实现缺少一些特性,最明显的是 接收脉冲和载波传输。RMT应该被认为是a *beta特性*和界面可能在未来改变。 .. class:: RMT(channel, \*, pin=None, clock_div=8) This class provides access to one of the eight RMT channels. *channel* is required and identifies which RMT channel (0-7) will be configured. *pin*, also required, configures which Pin is bound to the RMT channel. *clock_div* is an 8-bit clock divider that divides the source clock (80MHz) to the RMT channel allowing the resolution to be specified. 这个类提供对八个RMT通道之一的访问。* *频道 必需的,并确定将配置哪个RMT通道(0-7)。*销*, 同样需要,配置哪个大头针被绑定到RMT通道。* clock_div * 是将源时钟(80MHz)分成RMT的8位时钟分频器吗 通道允许指定的分辨率。 .. method:: RMT.source_freq() Returns the source clock frequency. Currently the source clock is not configurable so this will always return 80MHz. 返回源时钟频率。目前源时钟不是 可配置,因此它总是返回80MHz。 .. method:: RMT.clock_div() Return the clock divider. Note that the channel resolution is ``1 / (source_freq / clock_div)``. 返回时钟分压器。请注意,通道分辨率是 ``1 / (source_freq / clock_div)`` .. method:: RMT.wait_done(timeout=0) Returns True if `RMT.write_pulses` has completed. 如果RMT返回True。write_pulses”已完成。 If *timeout* (defined in ticks of ``source_freq / clock_div``) is specified the method will wait for *timeout* or until `RMT.write_pulses` is complete, returning ``False`` if the channel continues to transmit. 如果指定了*timeout*(定义为' ' source_freq / clock_div ' ') 该方法将等待*超时*或直到' RMT。write_pulses”完成, 如果信道继续传输,则返回“False”。 .. Warning:: Avoid using ``wait_done()`` if looping is enabled. 如果启用了循环,避免使用``wait_done()`` 。 .. method:: RMT.loop(enable_loop) Configure looping on the channel, allowing a stream of pulses to be indefinitely repeated. *enable_loop* is bool, set to True to enable looping. 在通道上配置循环,允许脉冲流被 无限期的重复。*enable_loop*是bool,设置为True以启用循环。 .. method:: RMT.write_pulses(pulses, start) Begin sending *pulses*, a list or tuple defining the stream of pulses. The length of each pulse is defined by a number to be multiplied by the channel resolution ``(1 / (source_freq / clock_div))``. *start* defines whether the stream starts at 0 or 1. 开始发送*脉冲*,一个定义脉冲流的列表或元组。的 每个脉冲的长度由一个要乘以信道的数字来定义 分辨率' ' (1 / (source_freq / clock_div)) ' '。定义是否 流从0或1开始。 The Ultra-Low-Power co-processor 超低功耗的协同处理器 -------------------------------- .. class:: ULP() This class provides access to the Ultra-Low-Power co-processor. 这个类提供对超低功耗协处理器的访问。 .. method:: ULP.set_wakeup_period(period_index, period_us) Set the wake-up period. 设置唤醒时间。 .. method:: ULP.load_binary(load_addr, program_binary) Load a *program_binary* into the ULP at the given *load_addr*. 在给定的*load_addr*下将*program_binary*加载到ULP中。 .. method:: ULP.run(entry_point) Start the ULP running at the given *entry_point*. 在给定的*entry_point*上启动运行ULP。 Constants 常量 --------- .. data:: esp32.WAKEUP_ALL_LOW esp32.WAKEUP_ANY_HIGH Selects the wake level for pins. 选择引脚的尾迹高度。