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 | 设备描述符 |
| buf | 读取数据缓冲区 |
| size | 读取数据大小 |
| count | 读取数据大小 |
| **返回值** | |
| `>=0` | 读取数据大小 |
| `<0` | 错误码 |

View File

@@ -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 |

View File

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

View File

@@ -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 |

View File

@@ -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引脚编号 |
| **返回值** | |

View File

@@ -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** | |

View File

@@ -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` | 错误码 |

View File

@@ -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 |

View File

@@ -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` | 错误码 |
@@ -261,8 +261,6 @@ int main(void)
/* 自动初始化pwm_init函数将在此处自动调用 */
mr_auto_init();
while(1)
{
/* 写入占空比 */
uint32_t duty = 500000;
int ret = mr_dev_write(pwm_ds, &duty, sizeof(duty));
@@ -272,7 +270,10 @@ int main(void)
mr_printf("Write failed: %s\r\n", mr_strerror(ret));
return ret;
}
mr_delay_ms(1000);
while(1)
{
}
}
```

View File

@@ -166,10 +166,10 @@ 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 |
| buf | Read data buffer |
| count | Read data size |
| **Return Value** | |
| `>=0` | Size of reading data |
| `<0` | Error code |
@@ -195,10 +195,10 @@ 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 |
| buf | Write data buffer |
| count | Write data size |
| **Return Value** | |
| `>=0` | Size of writing data |
| `<0` | Error code |
@@ -265,8 +265,6 @@ int main(void)
/* Automatically initialize (pwm_init function will be automatically called here) */
mr_auto_init();
while(1)
{
/* Write duty cycle */
uint32_t duty = 500000;
int ret = mr_dev_write(pwm_ds, &duty, sizeof(duty));
@@ -276,7 +274,10 @@ int main(void)
mr_printf("Write failed: %s\r\n", mr_strerror(ret));
return ret;
}
mr_delay_ms(1000);
while(1)
{
}
}
```

View File

@@ -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异步发送数据发送完成后会触发写回调函数
当有数据在异步发送时,写入锁将自动上锁,此时无法同步写入,直至异步发送完成。
## 使用示例

View File

@@ -261,10 +261,10 @@ 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 |
| buf | Read data buffer |
| count | Read data size |
| **Return Value** | |
| `>=0` | Number of bytes read |
| `<0` | Error code |
@@ -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
@@ -291,10 +290,10 @@ 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 |
| buf | Write data buffer |
| count | Write data size |
| **Return Value** | |
| `>=0` | Number of bytes written |
| `<0` | Error code |
@@ -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

View File

@@ -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` | 错误码 |

View File

@@ -336,10 +336,10 @@ 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 |
| buf | Read data buffer |
| count | Read data size |
| **Return Value** | |
| `>=0` | Size of data read |
| `<0` | Error code |
@@ -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
@@ -371,10 +370,10 @@ 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 |
| buf | Write data buffer |
| count | Write data size |
| **Return Value** | |
| `>=0` | Size of data written |
| `<0` | Error code |

View File

@@ -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` | 错误码 |

View File

@@ -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 |