1.文档优化。

This commit is contained in:
MacRsh
2024-02-02 16:38:44 +08:00
parent fd3a6eb97c
commit e70112c961
16 changed files with 109 additions and 112 deletions

View File

@@ -135,7 +135,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 读取数据缓冲区 | | buf | 读取数据缓冲区 |
| size | 读取数据大小 | | count | 读取数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 读取数据大小 | | `>=0` | 读取数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |

View File

@@ -139,7 +139,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
| | | | | |
| desc | Device descriptor | | desc | Device descriptor |
| buf | Read data buffer | | buf | Read data buffer |
| size | Read data size | | count | Read data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Read data size | | `>=0` | Read data size |
| `<0` | Error code | | `<0` | Error code |

View File

@@ -135,7 +135,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 写入数据缓冲区 | | buf | 写入数据缓冲区 |
| size | 写入数据大小 | | count | 写入数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 写入数据大小 | | `>=0` | 写入数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |

View File

@@ -138,7 +138,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|------------------|-------------------| |------------------|-------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Write data buffer | | buf | Write data buffer |
| size | Write data size | | count | Write data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Write data size | | `>=0` | Write data size |
| `<0` | Error code | | `<0` | Error code |

View File

@@ -272,7 +272,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 读取数据缓冲区 | | buf | 读取数据缓冲区 |
| size | 读取数据大小 | | count | 读取数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 读取数据大小 | | `>=0` | 读取数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -290,7 +290,7 @@ if (size < 0)
注: 注:
- 主机模式下,将使用轮询方式同步读取数据。从机模式下,未设置读缓冲区将使用轮询方式同步读取数据,设置读缓冲区后将从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 - 主机模式下,将使用轮询方式同步读取数据。从机模式下,从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。
- 当寄存器参数不为负数时,将在读取操作前插入寄存器值的写入操作。 - 当寄存器参数不为负数时,将在读取操作前插入寄存器值的写入操作。
## 写入I2C设备数据 ## 写入I2C设备数据
@@ -303,7 +303,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 写入数据缓冲区 | | buf | 写入数据缓冲区 |
| size | 写入数据大小 | | count | 写入数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 写入数据大小 | | `>=0` | 写入数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -424,13 +424,13 @@ int main(void)
### 注册软件I2C总线 ### 注册软件I2C总线
```c ```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总线结构体指针 | | soft_i2c_bus | 软件I2C总线结构体指针 |
| name | 总线名称 | | path | 总线 |
| scl_pin | SCL引脚编号 | | scl_pin | SCL引脚编号 |
| sda_pin | SDA引脚编号 | | sda_pin | SDA引脚编号 |
| **返回值** | | | **返回值** | |

View File

@@ -280,7 +280,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
| | | | | |
| desc | Device descriptor | | desc | Device descriptor |
| buf | Read data buffer | | buf | Read data buffer |
| size | Read data size | | count | Read data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Read data size | | `>=0` | Read data size |
| `<0` | Error code | | `<0` | Error code |
@@ -298,9 +298,8 @@ if (size < 0)
Note: Note:
- In host mode, data is read synchronously in polling mode. In slave mode, if the read buffer is not set, the data is - In host mode, data is read synchronously in polling mode. In slave mode,
read synchronously in polling mode. After the read buffer is set, the specified amount of data is read from the read reads a specified amount of data from the read buffer (returns the size of the data actually read).
buffer (the size of the actual read data is returned).
- When the register parameter is not negative, the write operation of the register value is inserted before the read - When the register parameter is not negative, the write operation of the register value is inserted before the read
operation. operation.
@@ -314,7 +313,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|------------------|-------------------| |------------------|-------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Write data buffer | | buf | Write data buffer |
| size | Write data size | | count | Write data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Write data size | | `>=0` | Write data size |
| `<0` | Error code | | `<0` | Error code |
@@ -437,13 +436,13 @@ Note: Software I2C requires enabling PIN device.
### Register Software I2C Bus ### Register Software I2C Bus
```c ```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 | | Parameter | Description |
|------------------|------------------------------------| |------------------|------------------------------------|
| soft_i2c_bus | Software I2C bus structure pointer | | soft_i2c_bus | Software I2C bus structure pointer |
| name | Bus name | | path | Bus path |
| scl_pin | SCL pin number | | scl_pin | SCL pin number |
| sda_pin | SDA pin number | | sda_pin | SDA pin number |
| **Return Value** | | | **Return Value** | |

View File

@@ -209,7 +209,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 读取数据缓冲区 | | buf | 读取数据缓冲区 |
| size | 读取数据大小 | | count | 读取数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 读取数据大小 | | `>=0` | 读取数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -235,7 +235,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 写入数据缓冲区 | | buf | 写入数据缓冲区 |
| size | 写入数据大小 | | count | 写入数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 写入数据大小 | | `>=0` | 写入数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |

View File

@@ -213,7 +213,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|------------------|-------------------| |------------------|-------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Read data buffer | | buf | Read data buffer |
| size | Read data size | | count | Read data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Read data size | | `>=0` | Read data size |
| `<0` | Error code | | `<0` | Error code |
@@ -239,7 +239,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|------------------|-------------------| |------------------|-------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Write data buffer | | buf | Write data buffer |
| size | Write data size | | count | Write data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Write data size | | `>=0` | Write data size |
| `<0` | Error code | | `<0` | Error code |

View File

@@ -167,7 +167,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 读取数据缓冲区 | | buf | 读取数据缓冲区 |
| size | 读取数据大小 | | count | 读取数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 读取数据大小 | | `>=0` | 读取数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -195,7 +195,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 写入数据缓冲区 | | buf | 写入数据缓冲区 |
| size | 写入数据大小 | | count | 写入数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 写入数据大小 | | `>=0` | 写入数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -260,19 +260,20 @@ int main(void)
{ {
/* 自动初始化pwm_init函数将在此处自动调用 */ /* 自动初始化pwm_init函数将在此处自动调用 */
mr_auto_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) 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);
} }
} }
``` ```

View File

@@ -165,14 +165,14 @@ mr_dev_ioctl(ds, (-(0x01)), &freq);
ssize_t mr_dev_read(int desc, void *buf, size_t count); ssize_t mr_dev_read(int desc, void *buf, size_t count);
``` ```
| Parameter | Description | | Parameter | Description |
|------------------|-------------------------| |------------------|----------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Buffer for reading data | | buf | Read data buffer |
| size | Size of reading data | | count | Read data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Size of reading data | | `>=0` | Size of reading data |
| `<0` | Error code | | `<0` | Error code |
```c ```c
/* Read duty cycle */ /* 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); ssize_t mr_dev_write(int desc, const void *buf, size_t count);
``` ```
| Parameter | Description | | Parameter | Description |
|------------------|-------------------------| |------------------|----------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Buffer for writing data | | buf | Write data buffer |
| size | Size of writing data | | count | Write data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Size of writing data | | `>=0` | Size of writing data |
| `<0` | Error code | | `<0` | Error code |
```c ```c
/* Write duty cycle */ /* Write duty cycle */
@@ -264,19 +264,20 @@ int main(void)
{ {
/* Automatically initialize (pwm_init function will be automatically called here) */ /* Automatically initialize (pwm_init function will be automatically called here) */
mr_auto_init(); 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) 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);
} }
} }
``` ```

View File

@@ -252,7 +252,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 读取数据缓冲区 | | buf | 读取数据缓冲区 |
| size | 读取数据大小 | | count | 读取数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 读取数据大小 | | `>=0` | 读取数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -268,7 +268,7 @@ if (size < 0)
} }
``` ```
注:当未设置读缓冲区时将使用轮询方式同步读取数据(无法保证完整接收数据)。当设置读缓冲区后将从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 注:当未设置读缓冲区时将使用轮询方式同步读取数据。当设置读缓冲区后将从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。
## 写入SERIAL设备数据 ## 写入SERIAL设备数据
@@ -280,7 +280,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 写入数据缓冲区 | | buf | 写入数据缓冲区 |
| size | 写入数据大小 | | count | 写入数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 写入数据大小 | | `>=0` | 写入数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -296,8 +296,7 @@ if (size < 0)
} }
``` ```
注:当未设置写缓冲区且未使用 `MR_O_NONBLOCK` 打开时将使用轮询方式同步写入数据 注:当使用 `MR_O_NONBLOCK` 打开时会将数据写入写缓冲区返回实际写入的数据大小通过中断或DMA异步发送数据发送完成后会触发写回调函数
当设置写缓冲区后会将数据写入写缓冲区返回实际写入的数据大小通过中断或DMA异步发送数据发送完成后会触发写回调函数。
当有数据在异步发送时,写入锁将自动上锁,此时无法同步写入,直至异步发送完成。 当有数据在异步发送时,写入锁将自动上锁,此时无法同步写入,直至异步发送完成。
## 使用示例 ## 使用示例

View File

@@ -260,14 +260,14 @@ mr_dev_ioctl(ds, MR_IOC_GWCB, &callback);
ssize_t mr_dev_read(int desc, void *buf, size_t count); ssize_t mr_dev_read(int desc, void *buf, size_t count);
``` ```
| Parameter | Description | | Parameter | Description |
|------------------|--------------------------| |------------------|----------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Buffer to read data into | | buf | Read data buffer |
| size | Size of data to read | | count | Read data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Number of bytes read | | `>=0` | Number of bytes read |
| `<0` | Error code | | `<0` | Error code |
```c ```c
char buf[128]; 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 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
data). 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). number of bytes read).
## Write Data to SERIAL Device ## 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); ssize_t mr_dev_write(int desc, const void *buf, size_t count);
``` ```
| Parameter | Description | | Parameter | Description |
|------------------|---------------------------| |------------------|-------------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Buffer with data to write | | buf | Write data buffer |
| size | Size of data to write | | count | Write data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Number of bytes written | | `>=0` | Number of bytes written |
| `<0` | Error code | | `<0` | Error code |
```c ```c
char buf[] = {"hello world"}; 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 Note: When opened with `MR_O_NONBLOCK`, the data is written to the write buffer (returns the size of the data actually written),
synchronous writing. When a write buffer is set, it will write the data to the write buffer (return the actual number of the data is sent asynchronously by interrupt or DMA, and the write callback function is triggered when the sending is complete.
bytes written), and asynchronously send the data through interrupt or DMA. The write callback function will be triggered When data is sent asynchronously, the write lock is automatically locked. In this case,
after sending is complete. When data is being asynchronously sent, the write lock will automatically be locked, and data cannot be written synchronously until the asynchronous transmission is complete.
synchronous writing is not allowed until asynchronous sending is complete.
## Example ## Example

View File

@@ -324,7 +324,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 读取数据缓冲区 | | buf | 读取数据缓冲区 |
| size | 读取数据大小 | | count | 读取数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 读取数据大小 | | `>=0` | 读取数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -342,7 +342,7 @@ if (size < 0)
注: 注:
- 主机模式下,将使用轮询方式同步读取数据。从机模式下,未设置读缓冲区将使用轮询方式同步读取数据,设置读缓冲区后将从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。 - 主机模式下,将使用轮询方式同步读取数据。从机模式下,从读缓冲区读取指定数量的数据(返回实际读取的数据大小)。
- 当寄存器参数不为负数时,将在读取操作前插入寄存器值的写入操作。 - 当寄存器参数不为负数时,将在读取操作前插入寄存器值的写入操作。
## 写入SPI设备数据 ## 写入SPI设备数据
@@ -355,7 +355,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 写入数据缓冲区 | | buf | 写入数据缓冲区 |
| size | 写入数据大小 | | count | 写入数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 写入数据大小 | | `>=0` | 写入数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |

View File

@@ -335,14 +335,14 @@ if (size < 0)
ssize_t mr_dev_read(int desc, void *buf, size_t count); ssize_t mr_dev_read(int desc, void *buf, size_t count);
``` ```
| Parameter | Description | | Parameter | Description |
|------------------|-------------------------| |------------------|-------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Buffer for reading data | | buf | Read data buffer |
| size | Size of data to read | | count | Read data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Size of data read | | `>=0` | Size of data read |
| `<0` | Error code | | `<0` | Error code |
```c ```c
uint8_t buf[128]; uint8_t buf[128];
@@ -359,9 +359,8 @@ if (size < 0)
Note: Note:
- In master mode, polling will be used for synchronous reading. In slave mode, if read buffer is not set, polling will - In master mode, polling will be used for synchronous reading. In slave mode,
be used for synchronous reading; if read buffer is set, data of the specified size will be read from the read buffer ( reads a specified amount of data from the read buffer (returns the size of the data actually read).
returns actual size of data read).
- The register value writing will be inserted before the reading operation if the register parameter is not negative. - The register value writing will be inserted before the reading operation if the register parameter is not negative.
## Write SPI Device Data ## Write SPI Device Data
@@ -370,14 +369,14 @@ Note:
ssize_t mr_dev_write(int desc, const void *buf, size_t count); ssize_t mr_dev_write(int desc, const void *buf, size_t count);
``` ```
| Parameter | Description | | Parameter | Description |
|------------------|-------------------------| |------------------|----------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Buffer for writing data | | buf | Write data buffer |
| size | Size of data to write | | count | Write data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Size of data written | | `>=0` | Size of data written |
| `<0` | Error code | | `<0` | Error code |
```c ```c
uint8_t buf[] = {0x01, 0x02, 0x03, 0x04}; uint8_t buf[] = {0x01, 0x02, 0x03, 0x04};

View File

@@ -145,7 +145,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 读取数据缓冲区 | | buf | 读取数据缓冲区 |
| size | 读取数据大小 | | count | 读取数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 读取数据大小 | | `>=0` | 读取数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |
@@ -176,7 +176,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|---------|---------| |---------|---------|
| desc | 设备描述符 | | desc | 设备描述符 |
| buf | 写入数据缓冲区 | | buf | 写入数据缓冲区 |
| size | 写入数据大小 | | count | 写入数据大小 |
| **返回值** | | | **返回值** | |
| `>=0` | 写入数据大小 | | `>=0` | 写入数据大小 |
| `<0` | 错误码 | | `<0` | 错误码 |

View File

@@ -147,7 +147,7 @@ ssize_t mr_dev_read(int desc, void *buf, size_t count);
|------------------|-------------------| |------------------|-------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Read data buffer | | buf | Read data buffer |
| size | Read data size | | count | Read data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Read data size | | `>=0` | Read data size |
| `<0` | Error code | | `<0` | Error code |
@@ -178,7 +178,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t count);
|------------------|-------------------| |------------------|-------------------|
| desc | Device descriptor | | desc | Device descriptor |
| buf | Write data buffer | | buf | Write data buffer |
| size | Write data size | | count | Write data size |
| **Return Value** | | | **Return Value** | |
| `>=0` | Write data size | | `>=0` | Write data size |
| `<0` | Error code | | `<0` | Error code |