From e70112c961c8f81febbf01c58e4a01d590e3a89d Mon Sep 17 00:00:00 2001 From: MacRsh Date: Fri, 2 Feb 2024 16:38:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=87=E6=A1=A3=E4=BC=98=E5=8C=96=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- document/device/adc/adc.md | 2 +- document/device/adc/adc_EN.md | 2 +- document/device/dac/dac.md | 2 +- document/device/dac/dac_EN.md | 2 +- document/device/i2c/i2c.md | 10 +++--- document/device/i2c/i2c_EN.md | 13 ++++--- document/device/pin/pin.md | 4 +-- document/device/pin/pin_EN.md | 4 +-- document/device/pwm/pwm.md | 25 +++++++------- document/device/pwm/pwm_EN.md | 53 +++++++++++++++-------------- document/device/serial/serial.md | 9 +++-- document/device/serial/serial_EN.md | 44 ++++++++++++------------ document/device/spi/spi.md | 6 ++-- document/device/spi/spi_EN.md | 37 ++++++++++---------- document/device/timer/timer.md | 4 +-- document/device/timer/timer_EN.md | 4 +-- 16 files changed, 109 insertions(+), 112 deletions(-) diff --git a/document/device/adc/adc.md b/document/device/adc/adc.md index 0a02002..c89ca2d 100644 --- a/document/device/adc/adc.md +++ b/document/device/adc/adc.md @@ -135,7 +135,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 读取数据缓冲区 | -| size | 读取数据大小 | +| count | 读取数据大小 | | **返回值** | | | `>=0` | 读取数据大小 | | `<0` | 错误码 | diff --git a/document/device/adc/adc_EN.md b/document/device/adc/adc_EN.md index 33a1671..0256e6e 100644 --- a/document/device/adc/adc_EN.md +++ b/document/device/adc/adc_EN.md @@ -139,7 +139,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); | | | | desc | Device descriptor | | buf | Read data buffer | -| size | Read data size | +| count | Read data size | | **Return Value** | | | `>=0` | Read data size | | `<0` | Error code | diff --git a/document/device/dac/dac.md b/document/device/dac/dac.md index 7f085cb..da82e38 100644 --- a/document/device/dac/dac.md +++ b/document/device/dac/dac.md @@ -135,7 +135,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 写入数据缓冲区 | -| size | 写入数据大小 | +| count | 写入数据大小 | | **返回值** | | | `>=0` | 写入数据大小 | | `<0` | 错误码 | diff --git a/document/device/dac/dac_EN.md b/document/device/dac/dac_EN.md index 658c0be..da4bf13 100644 --- a/document/device/dac/dac_EN.md +++ b/document/device/dac/dac_EN.md @@ -138,7 +138,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |------------------|-------------------| | desc | Device descriptor | | buf | Write data buffer | -| size | Write data size | +| count | Write data size | | **Return Value** | | | `>=0` | Write data size | | `<0` | Error code | diff --git a/document/device/i2c/i2c.md b/document/device/i2c/i2c.md index 7ddfd72..77df8ae 100644 --- a/document/device/i2c/i2c.md +++ b/document/device/i2c/i2c.md @@ -272,7 +272,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 读取数据缓冲区 | -| size | 读取数据大小 | +| count | 读取数据大小 | | **返回值** | | | `>=0` | 读取数据大小 | | `<0` | 错误码 | @@ -290,7 +290,7 @@ if (size < 0) 注: -- 主机模式下,将使用轮询方式同步读取数据。从机模式下,未设置读缓冲区将使用轮询方式同步读取数据,设置读缓冲区后将从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 +- 主机模式下,将使用轮询方式同步读取数据。从机模式下,从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 - 当寄存器参数不为负数时,将在读取操作前插入寄存器值的写入操作。 ## 写入I2C设备数据 @@ -303,7 +303,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 写入数据缓冲区 | -| size | 写入数据大小 | +| count | 写入数据大小 | | **返回值** | | | `>=0` | 写入数据大小 | | `<0` | 错误码 | @@ -424,13 +424,13 @@ int main(void) ### 注册软件I2C总线 ```c -int mr_soft_i2c_bus_register(struct mr_soft_i2c_bus *soft_i2c_bus, const char *name, int scl_pin, int sda_pin); +int mr_soft_i2c_bus_register(struct mr_soft_i2c_bus *soft_i2c_bus, const char *path, int scl_pin, int sda_pin); ``` | 参数 | 描述 | |--------------|--------------| | soft_i2c_bus | 软件I2C总线结构体指针 | -| name | 总线名称 | +| path | 总线 | | scl_pin | SCL引脚编号 | | sda_pin | SDA引脚编号 | | **返回值** | | diff --git a/document/device/i2c/i2c_EN.md b/document/device/i2c/i2c_EN.md index ec7fa08..a24681f 100644 --- a/document/device/i2c/i2c_EN.md +++ b/document/device/i2c/i2c_EN.md @@ -280,7 +280,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); | | | | desc | Device descriptor | | buf | Read data buffer | -| size | Read data size | +| count | Read data size | | **Return Value** | | | `>=0` | Read data size | | `<0` | Error code | @@ -298,9 +298,8 @@ if (size < 0) Note: -- In host mode, data is read synchronously in polling mode. In slave mode, if the read buffer is not set, the data is - read synchronously in polling mode. After the read buffer is set, the specified amount of data is read from the read - buffer (the size of the actual read data is returned). +- In host mode, data is read synchronously in polling mode. In slave mode, + reads a specified amount of data from the read buffer (returns the size of the data actually read). - When the register parameter is not negative, the write operation of the register value is inserted before the read operation. @@ -314,7 +313,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |------------------|-------------------| | desc | Device descriptor | | buf | Write data buffer | -| size | Write data size | +| count | Write data size | | **Return Value** | | | `>=0` | Write data size | | `<0` | Error code | @@ -437,13 +436,13 @@ Note: Software I2C requires enabling PIN device. ### Register Software I2C Bus ```c -int mr_soft_i2c_bus_register(struct mr_soft_i2c_bus *soft_i2c_bus, const char *name, int scl_pin, int sda_pin); +int mr_soft_i2c_bus_register(struct mr_soft_i2c_bus *soft_i2c_bus, const char *path, int scl_pin, int sda_pin); ``` | Parameter | Description | |------------------|------------------------------------| | soft_i2c_bus | Software I2C bus structure pointer | -| name | Bus name | +| path | Bus path | | scl_pin | SCL pin number | | sda_pin | SDA pin number | | **Return Value** | | diff --git a/document/device/pin/pin.md b/document/device/pin/pin.md index 5ab68c3..ca94c2f 100644 --- a/document/device/pin/pin.md +++ b/document/device/pin/pin.md @@ -209,7 +209,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 读取数据缓冲区 | -| size | 读取数据大小 | +| count | 读取数据大小 | | **返回值** | | | `>=0` | 读取数据大小 | | `<0` | 错误码 | @@ -235,7 +235,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 写入数据缓冲区 | -| size | 写入数据大小 | +| count | 写入数据大小 | | **返回值** | | | `>=0` | 写入数据大小 | | `<0` | 错误码 | diff --git a/document/device/pin/pin_EN.md b/document/device/pin/pin_EN.md index 8ab88c3..b68602a 100644 --- a/document/device/pin/pin_EN.md +++ b/document/device/pin/pin_EN.md @@ -213,7 +213,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |------------------|-------------------| | desc | Device descriptor | | buf | Read data buffer | -| size | Read data size | +| count | Read data size | | **Return Value** | | | `>=0` | Read data size | | `<0` | Error code | @@ -239,7 +239,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |------------------|-------------------| | desc | Device descriptor | | buf | Write data buffer | -| size | Write data size | +| count | Write data size | | **Return Value** | | | `>=0` | Write data size | | `<0` | Error code | diff --git a/document/device/pwm/pwm.md b/document/device/pwm/pwm.md index aa9c73f..c9581d7 100644 --- a/document/device/pwm/pwm.md +++ b/document/device/pwm/pwm.md @@ -167,7 +167,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 读取数据缓冲区 | -| size | 读取数据大小 | +| count | 读取数据大小 | | **返回值** | | | `>=0` | 读取数据大小 | | `<0` | 错误码 | @@ -195,7 +195,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 写入数据缓冲区 | -| size | 写入数据大小 | +| count | 写入数据大小 | | **返回值** | | | `>=0` | 写入数据大小 | | `<0` | 错误码 | @@ -260,19 +260,20 @@ int main(void) { /* 自动初始化(pwm_init函数将在此处自动调用) */ mr_auto_init(); + + /* 写入占空比 */ + uint32_t duty = 500000; + int ret = mr_dev_write(pwm_ds, &duty, sizeof(duty)); + /* 是否写入成功 */ + if (ret != sizeof(duty)) + { + mr_printf("Write failed: %s\r\n", mr_strerror(ret)); + return ret; + } while(1) { - /* 写入占空比 */ - uint32_t duty = 500000; - int ret = mr_dev_write(pwm_ds, &duty, sizeof(duty)); - /* 是否写入成功 */ - if (ret != sizeof(duty)) - { - mr_printf("Write failed: %s\r\n", mr_strerror(ret)); - return ret; - } - mr_delay_ms(1000); + } } ``` diff --git a/document/device/pwm/pwm_EN.md b/document/device/pwm/pwm_EN.md index 5eb133b..e102fe7 100644 --- a/document/device/pwm/pwm_EN.md +++ b/document/device/pwm/pwm_EN.md @@ -165,14 +165,14 @@ mr_dev_ioctl(ds, (-(0x01)), &freq); ssize_t mr_dev_read(int desc, void *buf, size_t count); ``` -| Parameter | Description | -|------------------|-------------------------| -| desc | Device descriptor | -| buf | Buffer for reading data | -| size | Size of reading data | -| **Return Value** | | -| `>=0` | Size of reading data | -| `<0` | Error code | +| Parameter | Description | +|------------------|----------------------| +| desc | Device descriptor | +| buf | Read data buffer | +| count | Read data size | +| **Return Value** | | +| `>=0` | Size of reading data | +| `<0` | Error code | ```c /* Read duty cycle */ @@ -194,14 +194,14 @@ The minimum unit for single reading is `uint32_t`, which is 4 bytes. ssize_t mr_dev_write(int desc, const void *buf, size_t count); ``` -| Parameter | Description | -|------------------|-------------------------| -| desc | Device descriptor | -| buf | Buffer for writing data | -| size | Size of writing data | -| **Return Value** | | -| `>=0` | Size of writing data | -| `<0` | Error code | +| Parameter | Description | +|------------------|----------------------| +| desc | Device descriptor | +| buf | Write data buffer | +| count | Write data size | +| **Return Value** | | +| `>=0` | Size of writing data | +| `<0` | Error code | ```c /* Write duty cycle */ @@ -264,19 +264,20 @@ int main(void) { /* Automatically initialize (pwm_init function will be automatically called here) */ mr_auto_init(); + + /* Write duty cycle */ + uint32_t duty = 500000; + int ret = mr_dev_write(pwm_ds, &duty, sizeof(duty)); + /* Check if writing succeeds */ + if (ret != sizeof(duty)) + { + mr_printf("Write failed: %s\r\n", mr_strerror(ret)); + return ret; + } while(1) { - /* Write duty cycle */ - uint32_t duty = 500000; - int ret = mr_dev_write(pwm_ds, &duty, sizeof(duty)); - /* Check if writing succeeds */ - if (ret != sizeof(duty)) - { - mr_printf("Write failed: %s\r\n", mr_strerror(ret)); - return ret; - } - mr_delay_ms(1000); + } } ``` diff --git a/document/device/serial/serial.md b/document/device/serial/serial.md index 48c2d17..13e249a 100644 --- a/document/device/serial/serial.md +++ b/document/device/serial/serial.md @@ -252,7 +252,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 读取数据缓冲区 | -| size | 读取数据大小 | +| count | 读取数据大小 | | **返回值** | | | `>=0` | 读取数据大小 | | `<0` | 错误码 | @@ -268,7 +268,7 @@ if (size < 0) } ``` -注:当未设置读缓冲区时将使用轮询方式同步读取数据(无法保证完整接收数据)。当设置读缓冲区后将从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 +注:当未设置读缓冲区时将使用轮询方式同步读取数据。当设置读缓冲区后将从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 ## 写入SERIAL设备数据 @@ -280,7 +280,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 写入数据缓冲区 | -| size | 写入数据大小 | +| count | 写入数据大小 | | **返回值** | | | `>=0` | 写入数据大小 | | `<0` | 错误码 | @@ -296,8 +296,7 @@ if (size < 0) } ``` -注:当未设置写缓冲区且未使用 `MR_O_NONBLOCK` 打开时将使用轮询方式同步写入数据。 -当设置写缓冲区后会将数据写入写缓冲区(返回实际写入的数据大小),通过中断或DMA异步发送数据,发送完成后会触发写回调函数。 +注:当使用 `MR_O_NONBLOCK` 打开时,会将数据写入写缓冲区(返回实际写入的数据大小),通过中断或DMA异步发送数据,发送完成后会触发写回调函数。 当有数据在异步发送时,写入锁将自动上锁,此时无法同步写入,直至异步发送完成。 ## 使用示例 diff --git a/document/device/serial/serial_EN.md b/document/device/serial/serial_EN.md index a7a9e53..7766303 100644 --- a/document/device/serial/serial_EN.md +++ b/document/device/serial/serial_EN.md @@ -260,14 +260,14 @@ mr_dev_ioctl(ds, MR_IOC_GWCB, &callback); ssize_t mr_dev_read(int desc, void *buf, size_t count); ``` -| Parameter | Description | -|------------------|--------------------------| -| desc | Device descriptor | -| buf | Buffer to read data into | -| size | Size of data to read | -| **Return Value** | | -| `>=0` | Number of bytes read | -| `<0` | Error code | +| Parameter | Description | +|------------------|----------------------| +| desc | Device descriptor | +| buf | Read data buffer | +| count | Read data size | +| **Return Value** | | +| `>=0` | Number of bytes read | +| `<0` | Error code | ```c char buf[128]; @@ -280,8 +280,7 @@ if (size < 0) } ``` -Note: When no read buffer is set, it will use polling mode for synchronous reading (cannot ensure complete reception of -data). When a read buffer is set, it will read the specified amount of data from the read buffer (return the actual +Note: When no read buffer is set, it will use polling mode for synchronous reading. When a read buffer is set, it will read the specified amount of data from the read buffer (return the actual number of bytes read). ## Write Data to SERIAL Device @@ -290,14 +289,14 @@ number of bytes read). ssize_t mr_dev_write(int desc, const void *buf, size_t count); ``` -| Parameter | Description | -|------------------|---------------------------| -| desc | Device descriptor | -| buf | Buffer with data to write | -| size | Size of data to write | -| **Return Value** | | -| `>=0` | Number of bytes written | -| `<0` | Error code | +| Parameter | Description | +|------------------|-------------------------| +| desc | Device descriptor | +| buf | Write data buffer | +| count | Write data size | +| **Return Value** | | +| `>=0` | Number of bytes written | +| `<0` | Error code | ```c char buf[] = {"hello world"}; @@ -310,11 +309,10 @@ if (size < 0) } ``` -Note: When no write buffer is set and not using `MR_O_NONBLOCK` for opening, it will use polling mode for -synchronous writing. When a write buffer is set, it will write the data to the write buffer (return the actual number of -bytes written), and asynchronously send the data through interrupt or DMA. The write callback function will be triggered -after sending is complete. When data is being asynchronously sent, the write lock will automatically be locked, and -synchronous writing is not allowed until asynchronous sending is complete. +Note: When opened with `MR_O_NONBLOCK`, the data is written to the write buffer (returns the size of the data actually written), +the data is sent asynchronously by interrupt or DMA, and the write callback function is triggered when the sending is complete. +When data is sent asynchronously, the write lock is automatically locked. In this case, +data cannot be written synchronously until the asynchronous transmission is complete. ## Example diff --git a/document/device/spi/spi.md b/document/device/spi/spi.md index fcf9083..e234340 100644 --- a/document/device/spi/spi.md +++ b/document/device/spi/spi.md @@ -324,7 +324,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 读取数据缓冲区 | -| size | 读取数据大小 | +| count | 读取数据大小 | | **返回值** | | | `>=0` | 读取数据大小 | | `<0` | 错误码 | @@ -342,7 +342,7 @@ if (size < 0) 注: -- 主机模式下,将使用轮询方式同步读取数据。从机模式下,未设置读缓冲区将使用轮询方式同步读取数据,设置读缓冲区后将从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 +- 主机模式下,将使用轮询方式同步读取数据。从机模式下,从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 - 当寄存器参数不为负数时,将在读取操作前插入寄存器值的写入操作。 ## 写入SPI设备数据 @@ -355,7 +355,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 写入数据缓冲区 | -| size | 写入数据大小 | +| count | 写入数据大小 | | **返回值** | | | `>=0` | 写入数据大小 | | `<0` | 错误码 | diff --git a/document/device/spi/spi_EN.md b/document/device/spi/spi_EN.md index a46b874..0a88335 100644 --- a/document/device/spi/spi_EN.md +++ b/document/device/spi/spi_EN.md @@ -335,14 +335,14 @@ if (size < 0) ssize_t mr_dev_read(int desc, void *buf, size_t count); ``` -| Parameter | Description | -|------------------|-------------------------| -| desc | Device descriptor | -| buf | Buffer for reading data | -| size | Size of data to read | -| **Return Value** | | -| `>=0` | Size of data read | -| `<0` | Error code | +| Parameter | Description | +|------------------|-------------------| +| desc | Device descriptor | +| buf | Read data buffer | +| count | Read data size | +| **Return Value** | | +| `>=0` | Size of data read | +| `<0` | Error code | ```c uint8_t buf[128]; @@ -359,9 +359,8 @@ if (size < 0) Note: -- In master mode, polling will be used for synchronous reading. In slave mode, if read buffer is not set, polling will - be used for synchronous reading; if read buffer is set, data of the specified size will be read from the read buffer ( - returns actual size of data read). +- In master mode, polling will be used for synchronous reading. In slave mode, + reads a specified amount of data from the read buffer (returns the size of the data actually read). - The register value writing will be inserted before the reading operation if the register parameter is not negative. ## Write SPI Device Data @@ -370,14 +369,14 @@ Note: ssize_t mr_dev_write(int desc, const void *buf, size_t count); ``` -| Parameter | Description | -|------------------|-------------------------| -| desc | Device descriptor | -| buf | Buffer for writing data | -| size | Size of data to write | -| **Return Value** | | -| `>=0` | Size of data written | -| `<0` | Error code | +| Parameter | Description | +|------------------|----------------------| +| desc | Device descriptor | +| buf | Write data buffer | +| count | Write data size | +| **Return Value** | | +| `>=0` | Size of data written | +| `<0` | Error code | ```c uint8_t buf[] = {0x01, 0x02, 0x03, 0x04}; diff --git a/document/device/timer/timer.md b/document/device/timer/timer.md index 148fee5..aeac6a7 100644 --- a/document/device/timer/timer.md +++ b/document/device/timer/timer.md @@ -145,7 +145,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 读取数据缓冲区 | -| size | 读取数据大小 | +| count | 读取数据大小 | | **返回值** | | | `>=0` | 读取数据大小 | | `<0` | 错误码 | @@ -176,7 +176,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |---------|---------| | desc | 设备描述符 | | buf | 写入数据缓冲区 | -| size | 写入数据大小 | +| count | 写入数据大小 | | **返回值** | | | `>=0` | 写入数据大小 | | `<0` | 错误码 | diff --git a/document/device/timer/timer_EN.md b/document/device/timer/timer_EN.md index bd14652..07356f5 100644 --- a/document/device/timer/timer_EN.md +++ b/document/device/timer/timer_EN.md @@ -147,7 +147,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count); |------------------|-------------------| | desc | Device descriptor | | buf | Read data buffer | -| size | Read data size | +| count | Read data size | | **Return Value** | | | `>=0` | Read data size | | `<0` | Error code | @@ -178,7 +178,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count); |------------------|-------------------| | desc | Device descriptor | | buf | Write data buffer | -| size | Write data size | +| count | Write data size | | **Return Value** | | | `>=0` | Write data size | | `<0` | Error code |