docs: sync up line number for api reference

This commit is contained in:
unknown 2022-05-07 18:40:41 +08:00
parent 179ea878c7
commit 5a1c257f96
7 changed files with 75 additions and 48 deletions

View File

@ -85,8 +85,7 @@ Send ESP-NOW Data
Call :cpp:func:`esp_now_send()` to send ESP-NOW data and :cpp:func:`esp_now_register_send_cb()` to register sending callback function. It will return `ESP_NOW_SEND_SUCCESS` in sending callback function if the data is received successfully on the MAC layer. Otherwise, it will return `ESP_NOW_SEND_FAIL`. Several reasons can lead to ESP-NOW fails to send data. For example, the destination device doesn't exist; the channels of the devices are not the same; the action frame is lost when transmitting on the air, etc. It is not guaranteed that application layer can receive the data. If necessary, send back ack data when receiving ESP-NOW data. If receiving ack data timeouts, retransmit the ESP-NOW data. A sequence number can also be assigned to ESP-NOW data to drop the duplicate data.
If there is a lot of ESP-NOW data to send, call :cpp:func:`esp_now_send()` to send less than or equal to 250 bytes of data once a time.
Note that too short interval between sending two ESP-NOW data may lead to disorder of sending callback function. So, it is recommended that sending the next ESP-NOW data after the sending callback function of the previous sending has returned. The sending callback function runs from a high-priority Wi-Fi task. So, do not do lengthy operations in the callback function. Instead, post the necessary data to a queue and handle it from a lower priority task.
If there is a lot of ESP-NOW data to send, call :cpp:func:`esp_now_send()` to send less than or equal to 250 bytes of data once a time. Note that too short interval between sending two ESP-NOW data may lead to disorder of sending callback function. So, it is recommended that sending the next ESP-NOW data after the sending callback function of the previous sending has returned. The sending callback function runs from a high-priority Wi-Fi task. So, do not do lengthy operations in the callback function. Instead, post the necessary data to a queue and handle it from a lower priority task.
Receiving ESP-NOW Data
----------------------

View File

@ -104,7 +104,7 @@ Application Example
}
}
Simple HTTP server example
Simple HTTP Server Example
^^^^^^^^^^^^^^^^^^^^^^^^^^
Check HTTP server example under :example:`protocols/http_server/simple` where handling of arbitrary content lengths, reading request headers and URL query parameters, and setting response headers is demonstrated.
@ -152,11 +152,10 @@ Persistent Connections Example
Check the example under :example:`protocols/http_server/persistent_sockets`.
Websocket server
Websocket Server
----------------
HTTP server provides a simple websocket support if the feature is enabled in menuconfig, please see :ref:`CONFIG_HTTPD_WS_SUPPORT`.
Please check the example under :example:`protocols/http_server/ws_echo_server`
The HTTP server component provides websocket support. The websocket feature can be enabled in menuconfig using the :ref:`CONFIG_HTTPD_WS_SUPPORT` option. Please refer to the :example:`protocols/http_server/ws_echo_server` example which demonstrates usage of the websocket feature.
API Reference

View File

@ -34,4 +34,3 @@ ESP-IDF 目前支持两个主机堆栈。基于 Bluedroid 的堆栈(默认)
* :example_file:`GATT 客户端安全性示例 <bluetooth/bluedroid/ble/gatt_security_client/tutorial/Gatt_Security_Client_Example_Walkthrough.md>`
* :example_file:`GATT 服务端安全性示例 <bluetooth/bluedroid/ble/gatt_security_server/tutorial/Gatt_Security_Server_Example_Walkthrough.md>`
* :example_file:`GATT 客户端多连接示例 <bluetooth/bluedroid/ble/gattc_multi_connect/tutorial/Gatt_Client_Multi_Connection_Example_Walkthrough.md>`

View File

@ -85,8 +85,7 @@ ESP-NOW 采用 CCMP 方法保护供应商特定动作帧的安全,具体可参
调用 :cpp:func:`esp_now_send()` 发送 ESP-NOW 数据,调用 :cpp:func:`esp_now_register_send_cb` 注册发送回调函数。如果 MAC 层成功接收到数据,则该函数将返回 `ESP_NOW_SEND_SUCCESS` 事件。否则,它将返回 `ESP_NOW_SEND_FAIL`。ESP-NOW 数据发送失败可能有几种原因,比如目标设备不存在、设备的信道不相同、动作帧在传输过程中丢失等。应用层并不一定可以总能接收到数据。如果需要,应用层可在接收 ESP-NOW 数据时发回一个应答 (ACK) 数据。如果接收 ACK 数据超时,则将重新传输 ESP-NOW 数据。可以为 ESP-NOW 数据设置序列号,从而删除重复的数据。
如果有大量 ESP-NOW 数据要发送,则调用 :cpp:func:`esp_now_send()` 一次性发送不大于 250 字节的数据。
请注意,两个 ESP-NOW 数据包的发送间隔太短可能导致回调函数返回混乱。因此,建议在等到上一次回调函数返回 ACK 后再发送下一个 ESP-NOW 数据。发送回调函数从高优先级的 Wi-Fi 任务中运行。因此,不要在回调函数中执行冗长的操作。相反,将必要的数据发布到队列,并交给优先级较低的任务处理。
如果有大量 ESP-NOW 数据要发送,调用 ``esp_now_send()`` 时需注意单次发送的数据不能超过 250 字节。请注意,两个 ESP-NOW 数据包的发送间隔太短可能导致回调函数返回混乱。因此,建议在等到上一次回调函数返回 ACK 后再发送下一个 ESP-NOW 数据。发送回调函数从高优先级的 Wi-Fi 任务中运行。因此,不要在回调函数中执行冗长的操作。相反,将必要的数据发布到队列,并交给优先级较低的任务处理。
接收 ESP-NOW 数据
----------------------
@ -110,4 +109,3 @@ API 参考
-------------
.. include-build-file:: inc/esp_now.inc

View File

@ -20,13 +20,19 @@ I2C 具有简单且制造成本低廉等优点,主要用于低速外围设备
I2C 驱动程序管理在 I2C 总线上设备的通信,该驱动程序具备以下功能:
- 在主机模式下读写字节
- 支持从机模式
.. only:: SOC_I2C_SUPPORT_SLAVE
- 支持从机模式
- 读取并写入寄存器,然后由主机读取/写入
使用驱动程序
---------------
{IDF_TARGET_I2C_ROLE:default="主机或从机", esp32c2="主机"}
以下部分将指导您完成 I2C 驱动程序配置和工作的基本步骤:
1. :ref:`i2c-api-configure-driver` - 设置初始化参数如主机模式或从机模式SDA 和 SCL 使用的 GPIO 管脚,时钟速度等)
@ -34,6 +40,9 @@ I2C 驱动程序管理在 I2C 总线上设备的通信,该驱动程序具备
3. 根据是为主机还是从机配置驱动程序,选择合适的项目
a) :ref:`i2c-api-master-mode` - 发起通信(主机模式)
.. only:: SOC_I2C_SUPPORT_SLAVE
b) :ref:`i2c-api-slave-mode` - 响应主机消息(从机模式)
4. :ref:`i2c-api-interrupt-handling` - 配置 I2C 中断服务
@ -56,7 +65,10 @@ I2C 驱动程序管理在 I2C 总线上设备的通信,该驱动程序具备
- 是否启用 {IDF_TARGET_NAME} 的内部上拉电阻
- (仅限主机模式)设置 I2C **时钟速度**
- (仅限从机模式)设置以下内容:
.. only:: SOC_I2C_SUPPORT_SLAVE
- (仅限从机模式)设置以下内容:
* 是否应启用 **10 位寻址模式**
* 定义 **从机地址**
@ -78,9 +90,11 @@ I2C 驱动程序管理在 I2C 总线上设备的通信,该驱动程序具备
// .clk_flags = 0, /*!< Optional, you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here. */
};
配置示例(从机):
.. only:: SOC_I2C_SUPPORT_SLAVE
.. code-block:: c
配置示例(从机):
.. code-block:: c
int i2c_slave_port = I2C_SLAVE_NUM;
i2c_config_t conf_slave = {
@ -201,7 +215,11 @@ I2C 驱动程序管理在 I2C 总线上设备的通信,该驱动程序具备
- 端口号,从 :cpp:type:`i2c_port_t` 中二选一
- 主机或从机模式,从 :cpp:type:`i2c_mode_t` 中选择
- 仅限从机模式分配用于在从机模式下发送和接收数据的缓存区大小。I2C 是一个以主机为中心的总线,数据只能根据主机的请求从从机传输到主机。因此,从机通常有一个发送缓存区,供从应用程序写入数据使用。数据保留在发送缓存区中,由主机自行读取。
.. only:: SOC_I2C_SUPPORT_SLAVE
- 仅限从机模式分配用于在从机模式下发送和接收数据的缓存区大小。I2C 是一个以主机为中心的总线,数据只能根据主机的请求从从机传输到主机。因此,从机通常有一个发送缓存区,供从应用程序写入数据使用。数据保留在发送缓存区中,由主机自行读取。
- 用于分配中断的标志(请参考 :component_file:`esp_hw_support/include/esp_intr_alloc.h` 中 ESP_INTR_FLAG_* 值)
.. _i2c-api-master-mode:
@ -278,27 +296,32 @@ I2C 驱动程序管理在 I2C 总线上设备的通信,该驱动程序具备
i2c_master_write_byte(cmd, (ESP_SLAVE_ADDR << 1) | I2C_MASTER_READ, ACK_EN);
.. _i2c-api-slave-mode:
.. only:: SOC_I2C_SUPPORT_SLAVE
从机模式下通信
^^^^^^^^^^^^^^^^^^^^^^
.. _i2c-api-slave-mode:
安装 I2C 驱动程序后, {IDF_TARGET_NAME} 即可与其他 I2C 设备通信。
从机模式下通信
^^^^^^^^^^^^^^^^^^^^^^
API 为从机提供以下功能:
安装 I2C 驱动程序后, {IDF_TARGET_NAME} 即可与其他 I2C 设备通信。
- :cpp:func:`i2c_slave_read_buffer`
API 为从机提供以下功能:
- :cpp:func:`i2c_slave_read_buffer`
当主机将数据写入从机时,从机将自动将其存储在接收缓存区中。从机应用程序可自行调用函数 :cpp:func:`i2c_slave_read_buffer`。如果接收缓存区中没有数据,此函数还具有一个参数用于指定阻塞时间。这将允许从机应用程序在指定的超时设定内等待数据到达缓存区。
- :cpp:func:`i2c_slave_write_buffer`
- :cpp:func:`i2c_slave_write_buffer`
发送缓存区是用于存储从机要以 FIFO 顺序发送给主机的所有数据。在主机请求接收前,这些数据一直存储在发送缓存区。函数 :cpp:func:`i2c_slave_write_buffer` 有一个参数,用于指定发送缓存区已满时的块时间。这将允许从机应用程序在指定的超时设定内等待发送缓存区中足够的可用空间。
:example:`peripherals/i2c` 中可找到介绍如何使用这些功能的代码示例。
:example:`peripherals/i2c` 中可找到介绍如何使用这些功能的代码示例。
.. _i2c-api-interrupt-handling:
.. _i2c-api-interrupt-handling:
.. only:: not SOC_I2C_SUPPORT_SLAVE
.. _i2c-api-interrupt-handling:
中断处理
^^^^^^^^^^^

View File

@ -27,12 +27,14 @@ HTTP Server 组件提供了在 ESP32 上运行轻量级 Web 服务器的功能
return ESP_OK;
}
/* URI 处理函数,在客户端发起 POST /uri 请求时被调用 */
/* URI 处理函数,在客户端发起 POST/uri 请求时被调用 */
esp_err_t post_handler(httpd_req_t *req)
{
/* 定义 HTTP POST 请求数据的目标缓存区
* httpd_req_recv() 只接收 char* 数据,但也可以是任意二进制数据(需要类型转换)
* 对于字符串数据null 终止符会被省略content_len 会给出字符串的长度 */
* httpd_req_recv() 只接收 char* 数据,但也可以是
* 任意二进制数据(需要类型转换)
* 对于字符串数据null 终止符会被省略,
* content_len 会给出字符串的长度 */
char content[100];
/* 如果内容长度大于缓冲区则截断 */
@ -43,10 +45,12 @@ HTTP Server 组件提供了在 ESP32 上运行轻量级 Web 服务器的功能
/* 检查是否超时 */
if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
/* 如果是超时,可以调用 httpd_req_recv() 重试
* 简单起见,这里我们直接响应 HTTP 408请求超时错误给客户端 */
* 简单起见,这里我们直接
* 响应 HTTP 408请求超时错误给客户端 */
httpd_resp_send_408(req);
}
/* 如果发生了错误,返回 ESP_FAIL 可以确保底层套接字被关闭 */
/* 如果发生了错误,返回 ESP_FAIL 可以确保
* 底层套接字被关闭 */
return ESP_FAIL;
}
@ -64,7 +68,7 @@ HTTP Server 组件提供了在 ESP32 上运行轻量级 Web 服务器的功能
.user_ctx = NULL
};
/* POST /uri 的 URI 处理结构 */
/* POST/uri 的 URI 处理结构 */
httpd_uri_t uri_post = {
.uri = "/uri",
.method = HTTP_POST,
@ -127,7 +131,7 @@ HTTP 服务器具有长连接的功能,允许重复使用同一个连接(会
esp_err_t adder_post_handler(httpd_req_t *req)
{
/* 如果会话上下文还不存在则新建一个 */
/* 若上下文中不存在会话,则新建一个 */
if (! req->sess_ctx) {
req->sess_ctx = malloc(sizeof(ANY_DATA_TYPE)); /*!< 指向上下文数据 */
req->free_ctx = free_ctx_func; /*!< 释放上下文数据的函数 */
@ -148,6 +152,12 @@ HTTP 服务器具有长连接的功能,允许重复使用同一个连接(会
详情请参考位于 :example:`protocols/http_server/persistent_sockets` 的示例代码。
Websocket 服务器
----------------
HTTP 服务器组件提供 websocket 支持。可以在 menuconfig 中使用 :ref:`CONFIG_HTTPD_WS_SUPPORT` 选项启用 websocket 功能。有关如何使用 websocket 功能,请参阅 :example:`protocols/http_server/ws_echo_server` 目录下的示例代码。
API 参考
--------

View File

@ -98,7 +98,6 @@ FatFs 分区生成器
目前最新版本支持短文件名、长文件名、FAT12 和 FAT16。长文件名的上限是 255 个字符,文件名中可以包含多个 "." 字符以及其他字符如 "+"、","、";"、"="、"[" and also "]" 等。长文件名字符采用 utf-16 编码,而短文件名采用 utf-8 编码。
构建系统中使用 FatFs 分区生成器
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^