1.设备框架参数更新。
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
* [关闭ADC设备](#关闭adc设备)
|
||||
* [控制ADC设备](#控制adc设备)
|
||||
* [设置/获取通道编号](#设置获取通道编号)
|
||||
* [设置/获取通道状态](#设置获取通道状态)
|
||||
* [设置/获取通道配置](#设置获取通道配置)
|
||||
* [读取ADC设备通道值](#读取adc设备通道值)
|
||||
* [使用示例:](#使用示例)
|
||||
<!-- TOC -->
|
||||
@@ -45,7 +45,7 @@ int mr_dev_close(int desc);
|
||||
| `=0` | 关闭成功 |
|
||||
| `<0` | 错误码 |
|
||||
|
||||
注:关闭设备时所有的通道都将被自动恢复到默认状态,重新打开后需要重新配置通道。
|
||||
注:关闭设备时所有的通道都将被自动恢复到默认配置,重新打开后需要重新配置通道(可关闭此功能)。
|
||||
|
||||
## 控制ADC设备
|
||||
|
||||
@@ -64,9 +64,9 @@ int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
|
||||
- `cmd`:命令码,支持以下命令:
|
||||
- `MR_CTL_ADC_SET_CHANNEL`:设置通道编号。
|
||||
- `MR_CTL_ADC_SET_CHANNEL_STATE`:设置通道状态。
|
||||
- `MR_CTL_ADC_SET_CHANNEL_CONFIG`:设置通道配置。
|
||||
- `MR_CTL_ADC_GET_CHANNEL`:获取通道编号。
|
||||
- `MR_CTL_ADC_GET_CHANNEL_STATE`:获取通道状态。
|
||||
- `MR_CTL_ADC_GET_CHANNEL_CONFIG`:获取通道配置。
|
||||
|
||||
### 设置/获取通道编号
|
||||
|
||||
@@ -84,20 +84,20 @@ int number;
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_GET_CHANNEL, &number);
|
||||
```
|
||||
|
||||
### 设置/获取通道状态
|
||||
### 设置/获取通道配置
|
||||
|
||||
通道状态:
|
||||
通道配置:
|
||||
|
||||
- `MR_ADC_STATE_DISABLE`:禁用通道。
|
||||
- `MR_ADC_STATE_ENABLE`:启用通道。
|
||||
- `MR_DISABLE`:禁用通道。
|
||||
- `MR_ENABLE`:启用通道。
|
||||
|
||||
```c
|
||||
/* 设置通道状态 */
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_SET_CHANNEL_STATE, MR_MAKE_LOCAL(int, MR_ADC_STATE_ENABLE));
|
||||
/* 设置通道配置 */
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
|
||||
/* 获取通道状态 */
|
||||
/* 获取通道配置 */
|
||||
int state;
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_GET_CHANNEL_STATE, &state);
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_GET_CHANNEL_CONFIG, &state);
|
||||
```
|
||||
|
||||
## 读取ADC设备通道值
|
||||
@@ -155,7 +155,7 @@ int adc_init(void)
|
||||
/* 设置到通道5 */
|
||||
mr_dev_ioctl(adc_ds, MR_CTL_ADC_SET_CHANNEL, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
/* 设置通道使能 */
|
||||
ret = mr_dev_ioctl(adc_ds, MR_CTL_ADC_SET_CHANNEL_STATE, MR_MAKE_LOCAL(int, MR_ADC_STATE_ENABLE));
|
||||
ret = mr_dev_ioctl(adc_ds, MR_CTL_ADC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
if (ret < 0)
|
||||
{
|
||||
mr_printf("Channel5 enable failed: %s\r\n", mr_strerror(ret));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* [Close ADC Device](#close-adc-device)
|
||||
* [Control ADC Device](#control-adc-device)
|
||||
* [Set/Get Channel Number](#setget-channel-number)
|
||||
* [Set/Get Channel Status](#setget-channel-status)
|
||||
* [Set/Get Channel configure](#setget-channel-configure)
|
||||
* [Read ADC Device Channel Value](#read-adc-device-channel-value)
|
||||
* [Usage Example:](#usage-example)
|
||||
<!-- TOC -->
|
||||
@@ -30,7 +30,9 @@ int mr_dev_open(const char *name, int oflags);
|
||||
- `name`: ADC device name usually is: `adcx`, `adc1`, `adc2`.
|
||||
- `oflags`: Open device flags, support `MR_OFLAG_RDONLY`.
|
||||
|
||||
Note: When using, the ADC device should be opened separately for different tasks according to actual situations, and the appropriate `oflags` should be used for management and permission control to ensure they will not interfere with each other.
|
||||
Note: When using, the ADC device should be opened separately for different tasks according to actual situations, and the
|
||||
appropriate `oflags` should be used for management and permission control to ensure they will not interfere with each
|
||||
other.
|
||||
|
||||
## Close ADC Device
|
||||
|
||||
@@ -45,7 +47,8 @@ int mr_dev_close(int desc);
|
||||
| `=0` | Close successfully |
|
||||
| `<0` | Error code |
|
||||
|
||||
Note: When closing the device, all channels will be automatically restored to the default state. The channel needs to be reconfigured after reopening.
|
||||
Note: When closing the device, all channels will be automatically restored to the default state. The channel needs to be
|
||||
reconfigured after reopening(This feature can be turned off).
|
||||
|
||||
## Control ADC Device
|
||||
|
||||
@@ -64,9 +67,9 @@ int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
|
||||
- `cmd`: Command code, supports the following commands:
|
||||
- `MR_CTL_ADC_SET_CHANNEL`: Set channel number.
|
||||
- `MR_CTL_ADC_SET_CHANNEL_STATE`: Set channel state.
|
||||
- `MR_CTL_ADC_SET_CHANNEL_CONFIG`: Set channel configure.
|
||||
- `MR_CTL_ADC_GET_CHANNEL`: Get channel number.
|
||||
- `MR_CTL_ADC_GET_CHANNEL_STATE`: Get channel state.
|
||||
- `MR_CTL_ADC_GET_CHANNEL_CONFIG`: Get channel configure.
|
||||
|
||||
### Set/Get Channel Number
|
||||
|
||||
@@ -84,20 +87,20 @@ int number;
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_GET_CHANNEL, &number);
|
||||
```
|
||||
|
||||
### Set/Get Channel Status
|
||||
### Set/Get Channel Configure
|
||||
|
||||
Channel status:
|
||||
Channel configure:
|
||||
|
||||
- `MR_ADC_STATE_DISABLE`: Disable channel.
|
||||
- `MR_ADC_STATE_ENABLE`: Enable channel.
|
||||
- `MR_DISABLE`: Disable channel.
|
||||
- `MR_ENABLE`: Enable channel.
|
||||
|
||||
```c
|
||||
/* Set channel status */
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_SET_CHANNEL_STATE, MR_MAKE_LOCAL(int, MR_ADC_STATE_ENABLE));
|
||||
/* Set channel configure */
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
|
||||
/* Get channel status */
|
||||
/* Get channel configure */
|
||||
int state;
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_GET_CHANNEL_STATE, &state);
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_GET_CHANNEL_CONFIG, &state);
|
||||
```
|
||||
|
||||
## Read ADC Device Channel Value
|
||||
@@ -156,7 +159,7 @@ int adc_init(void)
|
||||
/* Set to channel 5 */
|
||||
mr_dev_ioctl(adc_ds, MR_CTL_ADC_SET_CHANNEL, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
/* Set channel enable */
|
||||
ret = mr_dev_ioctl(adc_ds, MR_CTL_ADC_SET_CHANNEL_STATE, MR_MAKE_LOCAL(int, MR_ADC_STATE_ENABLE));
|
||||
ret = mr_dev_ioctl(adc_ds, MR_CTL_ADC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
if (ret < 0)
|
||||
{
|
||||
mr_printf("Channel5 enable failed: %s\r\n", mr_strerror(ret));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* [关闭DAC设备](#关闭dac设备)
|
||||
* [控制DAC设备](#控制dac设备)
|
||||
* [设置/获取通道编号](#设置获取通道编号)
|
||||
* [设置/获取通道状态](#设置获取通道状态)
|
||||
* [设置/获取通道配置](#设置获取通道配置)
|
||||
* [写入DAC设备通道值](#写入dac设备通道值)
|
||||
* [使用示例:](#使用示例)
|
||||
<!-- TOC -->
|
||||
@@ -45,7 +45,7 @@ int mr_dev_close(int desc);
|
||||
| `=0` | 关闭成功 |
|
||||
| `<0` | 错误码 |
|
||||
|
||||
注:关闭设备时所有的通道都将被自动恢复到默认状态,重新打开后需要重新配置通道。
|
||||
注:关闭设备时所有的通道都将被自动恢复到默认状态,重新打开后需要重新配置通道(可关闭此功能)。
|
||||
|
||||
## 控制DAC设备
|
||||
|
||||
@@ -64,9 +64,9 @@ int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
|
||||
- `cmd`:命令码,支持以下命令:
|
||||
- `MR_CTL_DAC_SET_CHANNEL`:设置通道编号。
|
||||
- `MR_CTL_DAC_SET_CHANNEL_STATE`:设置通道状态。
|
||||
- `MR_CTL_DAC_SET_CHANNEL_CONFIG`:设置通道配置。
|
||||
- `MR_CTL_DAC_GET_CHANNEL`:获取通道编号。
|
||||
- `MR_CTL_DAC_GET_CHANNEL_STATE`:获取通道状态。
|
||||
- `MR_CTL_DAC_GET_CHANNEL_CONFIG`:获取通道配置。
|
||||
|
||||
### 设置/获取通道编号
|
||||
|
||||
@@ -84,20 +84,20 @@ int number;
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_GET_CHANNEL, &number);
|
||||
```
|
||||
|
||||
### 设置/获取通道状态
|
||||
### 设置/获取通道配置
|
||||
|
||||
通道状态:
|
||||
通道配置:
|
||||
|
||||
- `MR_DAC_STATE_DISABLE`:禁用通道。
|
||||
- `MR_DAC_STATE_ENABLE`:启用通道。
|
||||
- `MR_DISABLE`:禁用通道。
|
||||
- `MR_ENABLE`:启用通道。
|
||||
|
||||
```c
|
||||
/* 设置通道状态 */
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_SET_CHANNEL_STATE, MR_MAKE_LOCAL(int, MR_DAC_STATE_ENABLE));
|
||||
/* 设置通道配置 */
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
|
||||
/* 获取通道状态 */
|
||||
/* 获取通道配置 */
|
||||
int state;
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_GET_CHANNEL_STATE, &state);
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_GET_CHANNEL_CONFIG, &state);
|
||||
```
|
||||
|
||||
## 写入DAC设备通道值
|
||||
@@ -155,7 +155,7 @@ int dac_init(void)
|
||||
/* 设置到通道5 */
|
||||
mr_dev_ioctl(dac_ds, MR_CTL_DAC_SET_CHANNEL, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
/* 设置通道使能 */
|
||||
ret = mr_dev_ioctl(dac_ds, MR_CTL_DAC_SET_CHANNEL_STATE, MR_MAKE_LOCAL(int, MR_DAC_STATE_ENABLE));
|
||||
ret = mr_dev_ioctl(dac_ds, MR_CTL_DAC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
if (ret < 0)
|
||||
{
|
||||
mr_printf("Channel5 enable failed: %s\r\n", mr_strerror(ret));
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* [Close DAC Device](#close-dac-device)
|
||||
* [Control DAC Device](#control-dac-device)
|
||||
* [Set/Get Channel Number](#setget-channel-number)
|
||||
* [Set/Get Channel Status](#setget-channel-status)
|
||||
* [Set/Get Channel Configure](#setget-channel-configure)
|
||||
* [Write DAC Device Channel Value](#write-dac-device-channel-value)
|
||||
* [Usage Example:](#usage-example)
|
||||
<!-- TOC -->
|
||||
@@ -30,7 +30,9 @@ int mr_dev_open(const char *name, int oflags);
|
||||
- `name`: DAC device name usually is: `dacx`, `dac1`, `dac2`.
|
||||
- `oflags`: Open device flags, support `MR_OFLAG_WRONLY`.
|
||||
|
||||
Note: When using, the DAC device should be opened separately for different tasks according to actual situations, and the appropriate `oflags` should be used for management and permission control to ensure they will not interfere with each other.
|
||||
Note: When using, the DAC device should be opened separately for different tasks according to actual situations, and the
|
||||
appropriate `oflags` should be used for management and permission control to ensure they will not interfere with each
|
||||
other.
|
||||
|
||||
## Close DAC Device
|
||||
|
||||
@@ -45,7 +47,8 @@ int mr_dev_close(int desc);
|
||||
| `=0` | Close successfully |
|
||||
| `<0` | Error code |
|
||||
|
||||
Note: When closing the device, all channels will be automatically restored to the default state. The channel needs to be reconfigured after reopening.
|
||||
Note: When closing the device, all channels will be automatically restored to the default state. The channel needs to be
|
||||
reconfigured after reopening(This feature can be turned off).
|
||||
|
||||
## Control DAC Device
|
||||
|
||||
@@ -64,9 +67,9 @@ int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
|
||||
- `cmd`: Command code, supports the following commands:
|
||||
- `MR_CTL_DAC_SET_CHANNEL`: Set channel number.
|
||||
- `MR_CTL_DAC_SET_CHANNEL_STATE`: Set channel state.
|
||||
- `MR_CTL_DAC_SET_CHANNEL_CONFIG`: Set channel configure.
|
||||
- `MR_CTL_DAC_GET_CHANNEL`: Get channel number.
|
||||
- `MR_CTL_DAC_GET_CHANNEL_STATE`: Get channel state.
|
||||
- `MR_CTL_DAC_GET_CHANNEL_CONFIG`: Get channel configure.
|
||||
|
||||
### Set/Get Channel Number
|
||||
|
||||
@@ -84,20 +87,20 @@ int number;
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_GET_CHANNEL, &number);
|
||||
```
|
||||
|
||||
### Set/Get Channel Status
|
||||
### Set/Get Channel Configure
|
||||
|
||||
Channel status:
|
||||
Channel configure:
|
||||
|
||||
- `MR_DAC_STATE_DISABLE`: Disable channel.
|
||||
- `MR_DAC_STATE_ENABLE`: Enable channel.
|
||||
- `MR_DISABLE`: Disable channel.
|
||||
- `MR_ENABLE`: Enable channel.
|
||||
|
||||
```c
|
||||
/* Set channel status */
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_SET_CHANNEL_STATE, MR_MAKE_LOCAL(int, MR_DAC_STATE_ENABLE));
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
|
||||
/* Get channel status */
|
||||
int state;
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_GET_CHANNEL_STATE, &state);
|
||||
mr_dev_ioctl(ds, MR_CTL_DAC_GET_CHANNEL_CONFIG, &state);
|
||||
```
|
||||
|
||||
## Write DAC Device Channel Value
|
||||
@@ -155,7 +158,7 @@ int dac_init(void)
|
||||
/* Set to channel 5 */
|
||||
mr_dev_ioctl(dac_ds, MR_CTL_DAC_SET_CHANNEL, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
/* Set channel enable */
|
||||
ret = mr_dev_ioctl(dac_ds, MR_CTL_DAC_SET_CHANNEL_STATE, MR_MAKE_LOCAL(int, MR_DAC_STATE_ENABLE));
|
||||
ret = mr_dev_ioctl(dac_ds, MR_CTL_DAC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
if (ret < 0)
|
||||
{
|
||||
mr_printf("Channel5 enable failed: %s\r\n", mr_strerror(ret));
|
||||
@@ -191,5 +194,5 @@ int main(void)
|
||||
}
|
||||
```
|
||||
|
||||
Enable DAC1 channel 5, output the DAC value every 500ms and print it
|
||||
Enable DAC1 channel 5, output the DAC value every 500ms and print it
|
||||
(the output value increases by 500 each time until reaching the maximum value 4095).
|
||||
|
||||
@@ -37,11 +37,12 @@ int mr_i2c_dev_register(struct mr_i2c_dev *i2c_dev, const char *name, int addr,
|
||||
| `=0` | Registration succeeds |
|
||||
| `<0` | Error code |
|
||||
|
||||
- `name`: The I2C device needs to bind to the specified I2C bus, and the name needs to add the bus name, such as: `i2c1/dev-name`.
|
||||
- `name`: The I2C device needs to bind to the specified I2C bus, and the name needs to add the bus name, such
|
||||
as: `i2c1/dev-name`.
|
||||
- `addr`: Device address (the lowest bit is read/write bit, please pass the address shifted to the left).
|
||||
- `addr_bits`: Device address bits:
|
||||
- `MR_I2C_ADDR_BITS_7`: 7-bit address.
|
||||
- `MR_I2C_ADDR_BITS_10`: 10-bit address.
|
||||
- `MR_I2C_ADDR_BITS_7`: 7-bit address.
|
||||
- `MR_I2C_ADDR_BITS_10`: 10-bit address.
|
||||
|
||||
## Open I2C Device
|
||||
|
||||
@@ -57,10 +58,13 @@ int mr_dev_open(const char *name, int oflags);
|
||||
| `>=0` | Device descriptor |
|
||||
| `<0` | Error code |
|
||||
|
||||
- `name`: The I2C device is bound to the I2C bus and needs to add the bus name, such as: `i2cx/dev-name`,`i2c1/dev-name`.
|
||||
- `name`: The I2C device is bound to the I2C bus and needs to add the bus name, such
|
||||
as: `i2cx/dev-name`,`i2c1/dev-name`.
|
||||
- `oflags`: Open device flags, support `MR_OFLAG_RDONLY`, `MR_OFLAG_WRONLY`, `MR_OFLAG_RDWR`.
|
||||
|
||||
Note: When using, the I2C device should be opened separately for different tasks according to the actual situation, and the appropriate `oflags` should be used for management and permission control to ensure that they will not interfere with each other.
|
||||
Note: When using, the I2C device should be opened separately for different tasks according to the actual situation, and
|
||||
the appropriate `oflags` should be used for management and permission control to ensure that they will not interfere
|
||||
with each other.
|
||||
|
||||
## Close I2C Device
|
||||
|
||||
@@ -91,16 +95,16 @@ int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
| `<0` | Error code |
|
||||
|
||||
- `cmd`: Command code, supports the following commands:
|
||||
- `MR_CTL_I2C_SET_CONFIG`: Set I2C device configuration.
|
||||
- `MR_CTL_I2C_SET_REG`: Set register value.
|
||||
- `MR_CTL_I2C_SET_RD_BUFSZ`: Set read buffer size.
|
||||
- `MR_CTL_I2C_CLR_RD_BUF`: Clear read buffer.
|
||||
- `MR_CTL_I2C_SET_RD_CALL`:Set read callback function.
|
||||
- `MR_CTL_I2C_GET_CONFIG`: Get I2C device configuration.
|
||||
- `MR_CTL_I2C_GET_REG`: Get register value.
|
||||
- `MR_CTL_I2C_GET_RD_BUFSZ`: Get read buffer size.
|
||||
- `MR_CTL_I2C_GET_RD_DATASZ`: Get read buffer data size.
|
||||
- `MR_CTL_I2C_GET_RD_CALL`:Get read callback function.
|
||||
- `MR_CTL_I2C_SET_CONFIG`: Set I2C device configuration.
|
||||
- `MR_CTL_I2C_SET_REG`: Set register value.
|
||||
- `MR_CTL_I2C_SET_RD_BUFSZ`: Set read buffer size.
|
||||
- `MR_CTL_I2C_CLR_RD_BUF`: Clear read buffer.
|
||||
- `MR_CTL_I2C_SET_RD_CALL`:Set read callback function.
|
||||
- `MR_CTL_I2C_GET_CONFIG`: Get I2C device configuration.
|
||||
- `MR_CTL_I2C_GET_REG`: Get register value.
|
||||
- `MR_CTL_I2C_GET_RD_BUFSZ`: Get read buffer size.
|
||||
- `MR_CTL_I2C_GET_RD_DATASZ`: Get read buffer data size.
|
||||
- `MR_CTL_I2C_GET_RD_CALL`:Get read callback function.
|
||||
|
||||
### Set/Get I2C Device Configuration
|
||||
|
||||
@@ -123,10 +127,12 @@ mr_dev_ioctl(ds, MR_CTL_I2C_GET_CONFIG, &config);
|
||||
Note:
|
||||
|
||||
- If not manually configured, the default configuration is:
|
||||
- Baud rate: `100000`
|
||||
- Master/slave mode: `MR_I2C_HOST`
|
||||
- Register bits: `MR_I2C_REG_BITS_8`
|
||||
- When an I2C device on the I2C bus is configured to slave mode, it will continuously occupy the I2C bus. At this point, other I2C devices cannot perform read/write operations until the I2C device in slave mode is reconfigured to master mode.
|
||||
- Baud rate: `100000`
|
||||
- Master/slave mode: `MR_I2C_HOST`
|
||||
- Register bits: `MR_I2C_REG_BITS_8`
|
||||
- When an I2C device on the I2C bus is configured to slave mode, it will continuously occupy the I2C bus. At this point,
|
||||
other I2C devices cannot perform read/write operations until the I2C device in slave mode is reconfigured to master
|
||||
mode.
|
||||
|
||||
### Set/Get Register Value
|
||||
|
||||
@@ -158,7 +164,8 @@ mr_dev_ioctl(ds, MR_CTL_I2C_SET_RD_BUFSZ, &size);
|
||||
mr_dev_ioctl(ds, MR_CTL_I2C_GET_RD_BUFSZ, &size);
|
||||
```
|
||||
|
||||
Note: If not manually configured, it will use the size configured in `Kconfig` (default 32Byte). The read buffer is only used in slave mode.
|
||||
Note: If not manually configured, it will use the size configured in `Kconfig` (default 32Byte). The read buffer is only
|
||||
used in slave mode.
|
||||
|
||||
### Clear Read Buffer
|
||||
|
||||
@@ -225,8 +232,11 @@ 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).
|
||||
- When the register parameter is not negative, the write operation of the register value is inserted before the read operation.
|
||||
- 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).
|
||||
- When the register parameter is not negative, the write operation of the register value is inserted before the read
|
||||
operation.
|
||||
|
||||
## Write I2C Device Data
|
||||
|
||||
@@ -254,7 +264,8 @@ if (size < 0)
|
||||
}
|
||||
```
|
||||
|
||||
Note: When the register parameter is not negative, a register value write operation will be inserted before the write operation.
|
||||
Note: When the register parameter is not negative, a register value write operation will be inserted before the write
|
||||
operation.
|
||||
|
||||
## Usage Example:
|
||||
|
||||
@@ -351,7 +362,8 @@ int main(void)
|
||||
}
|
||||
```
|
||||
|
||||
Connect I2C1 and I2C2 and perform sending and receiving test. I2C1 works as master and I2C2 works as slave. I2C2 will compare the received data with the sent data.
|
||||
Connect I2C1 and I2C2 and perform sending and receiving test. I2C1 works as master and I2C2 works as slave. I2C2 will
|
||||
compare the received data with the sent data.
|
||||
Since the register value is set, the register value will be received first before the data writing.
|
||||
|
||||
## Software I2C
|
||||
|
||||
@@ -67,11 +67,11 @@ int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
| `<0` | 错误码 |
|
||||
|
||||
- `cmd`:命令码,支持以下命令:
|
||||
- `MR_CTL_PIN_SET_NUMBER`:设置引脚编号。
|
||||
- `MR_CTL_PIN_SET_MODE`:设置引脚模式。
|
||||
- `MR_CTL_PIN_SET_EXTI_CALL`:设置外部中断回调函数。
|
||||
- `MR_CTL_PIN_GET_NUMBER`:获取引脚编号。
|
||||
- `MR_CTL_PIN_GET_EXTI_CALL`:获取外部中断回调函数。
|
||||
- `MR_CTL_PIN_SET_NUMBER`:设置引脚编号。
|
||||
- `MR_CTL_PIN_SET_MODE`:设置引脚模式。
|
||||
- `MR_CTL_PIN_SET_EXTI_CALL`:设置外部中断回调函数。
|
||||
- `MR_CTL_PIN_GET_NUMBER`:获取引脚编号。
|
||||
- `MR_CTL_PIN_GET_EXTI_CALL`:获取外部中断回调函数。
|
||||
|
||||
### 设置/获取引脚编号
|
||||
|
||||
@@ -144,7 +144,7 @@ int call(int desc, void *args)
|
||||
mr_dev_ioctl(ds, MR_CTL_PIN_SET_EXTI_CALL, call);
|
||||
|
||||
/* 获取外部中断回调函数 */
|
||||
int (*callback)(int, void *args);
|
||||
int (*callback)(int desc, void *args);
|
||||
mr_dev_ioctl(ds, MR_CTL_PIN_GET_EXTI_CALL, &callback);
|
||||
```
|
||||
|
||||
@@ -194,11 +194,11 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t size);
|
||||
| `>=0` | 写入数据大小 |
|
||||
| `<0` | 错误码 |
|
||||
|
||||
- 电平:`0`:低电平;`1`:高电平,推荐使用宏:`MR_PIN_LOW_LEVEL`、`MR_PIN_HIGH_LEVEL`。
|
||||
- 电平:`0`:低电平;`1`:高电平。
|
||||
|
||||
```c
|
||||
/* 写入引脚电平 */
|
||||
uint8_t pin_level = MR_PIN_HIGH_LEVEL;
|
||||
uint8_t pin_level = 1;
|
||||
int ret = mr_dev_write(ds, &pin_level, sizeof(pin_level));
|
||||
/* 是否写入成功 */
|
||||
if (ret != sizeof(pin_level))
|
||||
|
||||
@@ -34,7 +34,8 @@ int mr_dev_open(const char *name, int oflags);
|
||||
- `name`: The PIN device name is usually `"pin"`.
|
||||
- `oflags`: Open device flags, supports `MR_OFLAG_RDONLY`, `MR_OFLAG_WRONLY`, `MR_OFLAG_RDWR`.
|
||||
|
||||
Note: When using, different tasks should open the PIN device separately according to actual situations and use appropriate `oflags` for management and permission control to ensure they won't interfere with each other.
|
||||
Note: When using, different tasks should open the PIN device separately according to actual situations and use
|
||||
appropriate `oflags` for management and permission control to ensure they won't interfere with each other.
|
||||
|
||||
## Close PIN Device
|
||||
|
||||
@@ -49,7 +50,8 @@ int mr_dev_close(int desc);
|
||||
| `=0` | Close successfully |
|
||||
| `<0` | Error code |
|
||||
|
||||
Note: Closing the device will not restore the previous configuration by default. The user needs to restore it according to the actual situation.
|
||||
Note: Closing the device will not restore the previous configuration by default. The user needs to restore it according
|
||||
to the actual situation.
|
||||
|
||||
## Control PIN Device
|
||||
|
||||
@@ -77,9 +79,11 @@ int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
|
||||
#### Pin Number
|
||||
|
||||
Different MCUs have different GPIO quantities, functions, naming rules, etc. So MR uses digital numbers to define GPIO pins for unified interfaces on different MCUs.
|
||||
Different MCUs have different GPIO quantities, functions, naming rules, etc. So MR uses digital numbers to define GPIO
|
||||
pins for unified interfaces on different MCUs.
|
||||
|
||||
The default calculation formula is: `Number = Port * 16 + Pin`, where `Port` is the GPIO port number and `Pin` is the GPIO pin number.
|
||||
The default calculation formula is: `Number = Port * 16 + Pin`, where `Port` is the GPIO port number and `Pin` is the
|
||||
GPIO pin number.
|
||||
For example, `PC13` corresponds to `Port` C, `Pin` 13, then `Number = (C - A) * 16 + 13 = 32 + 13 = 45`.
|
||||
|
||||
Note: This rule may not apply to all MCUs. Special requirements need to check the low-level driver settings.
|
||||
@@ -144,14 +148,16 @@ int call(int desc, void *args)
|
||||
mr_dev_ioctl(ds, MR_CTL_PIN_SET_EXTI_CALL, call);
|
||||
|
||||
/* Get external interrupt callback function */
|
||||
int (*callback)(int, void *args);
|
||||
int (*callback)(int desc, void *args);
|
||||
mr_dev_ioctl(ds, MR_CTL_PIN_GET_EXTI_CALL, &callback);
|
||||
```
|
||||
|
||||
Note:
|
||||
|
||||
- Before setting the external interrupt mode, you need to configure the callback function, otherwise, it becomes a callback-free interrupt.
|
||||
- Even if the PIN device is closed, the callback function will not be invalid until the pin is set to a common mode (external interrupts will be ignored when the PIN device is closed).
|
||||
- Before setting the external interrupt mode, you need to configure the callback function, otherwise, it becomes a
|
||||
callback-free interrupt.
|
||||
- Even if the PIN device is closed, the callback function will not be invalid until the pin is set to a common mode (
|
||||
external interrupts will be ignored when the PIN device is closed).
|
||||
|
||||
## Read PIN Device Pin Level
|
||||
|
||||
@@ -194,11 +200,11 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t size);
|
||||
| `>=0` | Write data size |
|
||||
| `<0` | Error code |
|
||||
|
||||
- Level: `0`: Low level; `1`: High level, recommended to use macros:`MR_PIN_LOW_LEVEL`, `MR_PIN_HIGH_LEVEL`.
|
||||
- Level: `0`: Low level; `1`: High level.
|
||||
|
||||
```c
|
||||
/* Write pin level */
|
||||
uint8_t pin_level = MR_PIN_HIGH_LEVEL;
|
||||
uint8_t pin_level = 1;
|
||||
int ret = mr_dev_write(ds, &pin_level, sizeof(pin_level));
|
||||
/* Check if write successfully */
|
||||
if (ret != sizeof(pin_level))
|
||||
@@ -295,6 +301,8 @@ int main(void)
|
||||
```
|
||||
|
||||
After pressing the KEY, the LED will flip.
|
||||
Observe the serial port print, you can see the LED and KEY descriptors. Although the external interrupt of the KEY pin is configured by the KEY,
|
||||
no callback function is configured. Therefore, the KEY pin callback function inherits the previous configuration, that is, the callback function of the LED configuration,
|
||||
Observe the serial port print, you can see the LED and KEY descriptors. Although the external interrupt of the KEY pin
|
||||
is configured by the KEY,
|
||||
no callback function is configured. Therefore, the KEY pin callback function inherits the previous configuration, that
|
||||
is, the callback function of the LED configuration,
|
||||
so the descriptor printed in the KEY callback function is the descriptor of the LED.
|
||||
|
||||
@@ -134,6 +134,7 @@ if (size < 0)
|
||||
```
|
||||
|
||||
注:
|
||||
|
||||
- 时间单位为微妙。单次读取最小单位为`uint32_t`,即4个字节。
|
||||
- 运行时间指定时器启动后运行的时间,超时后重置。
|
||||
|
||||
@@ -153,6 +154,7 @@ ssize_t mr_dev_write(int desc, const void *buf, size_t size);
|
||||
| `<0` | 错误码 |
|
||||
|
||||
注:
|
||||
|
||||
- 时间单位为微妙。单次写入最小单位为`uint32_t`,即4个字节。
|
||||
- 当有一次写入多个单位数据时,仅实际生效最后一个有效数据(如果最后一个有效数据为`0`将关闭定时器)。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user