1.更新内置命令名。2.移除驱动类型。3.设备回调支持每个设备描述符独立挂载,不限上限。4.offset修改为position,更强调写入位置概念。5.设备中断概念修正,父系设备中断不仅唤起自身的回调函数,同时也将递归唤醒子设备回调函数(更强调依赖关系)。6.增强doxygen规范,生成文档更完整。
This commit is contained in:
@@ -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 configure](#setget-channel-configure)
|
||||
* [Set/Get Channel Configure](#setget-channel-configure)
|
||||
* [Read ADC Device Channel Value](#read-adc-device-channel-value)
|
||||
* [Usage Example:](#usage-example)
|
||||
<!-- TOC -->
|
||||
@@ -16,22 +16,22 @@
|
||||
## Open ADC Device
|
||||
|
||||
```c
|
||||
int mr_dev_open(const char *name, int oflags);
|
||||
int mr_dev_open(const char *path, int flags);
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
|:----------------:|:-----------------:|
|
||||
| name | Device name |
|
||||
| oflags | Open device flags |
|
||||
| path | Device path |
|
||||
| flags | Open device flags |
|
||||
| **Return Value** | |
|
||||
| `>=0` | Device descriptor |
|
||||
| `<0` | Error code |
|
||||
|
||||
- `name`: ADC device name usually is: `adcx`, `adc1`, `adc2`.
|
||||
- `oflags`: Open device flags, support `MR_OFLAG_RDONLY`.
|
||||
- `path`: ADC device path usually is: `adcx`, `adc1`, `adc2`.
|
||||
- `flags`: Open device flags, support `MR_O_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
|
||||
appropriate `flags` should be used for management and permission control to ensure they will not interfere with each
|
||||
other.
|
||||
|
||||
## Close ADC Device
|
||||
@@ -66,10 +66,10 @@ int mr_dev_ioctl(int desc, int cmd, void *args);
|
||||
| `<0` | Error code |
|
||||
|
||||
- `cmd`: Command code, supports the following commands:
|
||||
- `MR_CTL_ADC_SET_CHANNEL`: Set channel number.
|
||||
- `MR_CTL_ADC_SET_CHANNEL_CONFIG`: Set channel configure.
|
||||
- `MR_CTL_ADC_GET_CHANNEL`: Get channel number.
|
||||
- `MR_CTL_ADC_GET_CHANNEL_CONFIG`: Get channel configure.
|
||||
- `MR_IOC_ADC_SET_CHANNEL`: Set channel number.
|
||||
- `MR_IOC_ADC_SET_CHANNEL_CONFIG`: Set channel configure.
|
||||
- `MR_IOC_ADC_GET_CHANNEL`: Get channel number.
|
||||
- `MR_IOC_ADC_GET_CHANNEL_CONFIG`: Get channel configure.
|
||||
|
||||
### Set/Get Channel Number
|
||||
|
||||
@@ -80,11 +80,11 @@ Channel number range: `0` ~ `31`.
|
||||
#define CHANNEL_NUMBER 5
|
||||
|
||||
/* Set channel number */
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_SET_CHANNEL, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
mr_dev_ioctl(ds, MR_IOC_ADC_SET_CHANNEL, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
|
||||
/* Get channel number */
|
||||
int number;
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_GET_CHANNEL, &number);
|
||||
mr_dev_ioctl(ds, MR_IOC_ADC_GET_CHANNEL, &number);
|
||||
```
|
||||
|
||||
Independent of ADC interface:
|
||||
@@ -94,11 +94,11 @@ Independent of ADC interface:
|
||||
#define CHANNEL_NUMBER 5
|
||||
|
||||
/* Set channel number */
|
||||
mr_dev_ioctl(ds, MR_CTL_SET_OFFSET, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
mr_dev_ioctl(ds, MR_IOC_SPOS, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
|
||||
/* Get channel number */
|
||||
int number;
|
||||
mr_dev_ioctl(ds, MR_CTL_GET_OFFSET, &number);
|
||||
mr_dev_ioctl(ds, MR_IOC_GPOS, &number);
|
||||
```
|
||||
|
||||
### Set/Get Channel Configure
|
||||
@@ -110,28 +110,28 @@ Channel configure:
|
||||
|
||||
```c
|
||||
/* Set channel configure */
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
mr_dev_ioctl(ds, MR_IOC_ADC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
|
||||
/* Get channel configure */
|
||||
int state;
|
||||
mr_dev_ioctl(ds, MR_CTL_ADC_GET_CHANNEL_CONFIG, &state);
|
||||
mr_dev_ioctl(ds, MR_IOC_ADC_GET_CHANNEL_CONFIG, &state);
|
||||
```
|
||||
|
||||
Independent of ADC interface:
|
||||
|
||||
```c
|
||||
/* Set channel configure */
|
||||
mr_dev_ioctl(ds, MR_CTL_SET_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
mr_dev_ioctl(ds, MR_IOC_SCFG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
|
||||
/* Get channel configure */
|
||||
int state;
|
||||
mr_dev_ioctl(ds, MR_CTL_GET_CONFIG, &state);
|
||||
mr_dev_ioctl(ds, MR_IOC_GCFG, &state);
|
||||
```
|
||||
|
||||
## Read ADC Device Channel Value
|
||||
|
||||
```c
|
||||
ssize_t mr_dev_read(int desc, void *buf, size_t size);
|
||||
ssize_t mr_dev_read(int desc, void *buf, size_t count);
|
||||
```
|
||||
|
||||
| Parameter | Description |
|
||||
@@ -168,29 +168,27 @@ Note: The read data is the raw ADC data. The minimum read unit is `uint32_t`, th
|
||||
/* Define ADC device descriptor */
|
||||
int adc_ds = -1;
|
||||
|
||||
int adc_init(void)
|
||||
void adc_init(void)
|
||||
{
|
||||
int ret = MR_EOK;
|
||||
|
||||
/* Initialize ADC */
|
||||
adc_ds = mr_dev_open("adc1", MR_OFLAG_RDONLY);
|
||||
adc_ds = mr_dev_open("adc1", MR_O_RDONLY);
|
||||
if (adc_ds < 0)
|
||||
{
|
||||
mr_printf("ADC1 open failed: %s\r\n", mr_strerror(adc_ds));
|
||||
return adc_ds;
|
||||
return;
|
||||
}
|
||||
/* Print ADC descriptor */
|
||||
mr_printf("ADC1 desc: %d\r\n", adc_ds);
|
||||
/* Set to channel 5 */
|
||||
mr_dev_ioctl(adc_ds, MR_CTL_ADC_SET_CHANNEL, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
mr_dev_ioctl(adc_ds, MR_IOC_ADC_SET_CHANNEL, MR_MAKE_LOCAL(int, CHANNEL_NUMBER));
|
||||
/* Set channel enable */
|
||||
ret = mr_dev_ioctl(adc_ds, MR_CTL_ADC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
ret = mr_dev_ioctl(adc_ds, MR_IOC_ADC_SET_CHANNEL_CONFIG, MR_MAKE_LOCAL(int, MR_ENABLE));
|
||||
if (ret < 0)
|
||||
{
|
||||
mr_printf("Channel5 enable failed: %s\r\n", mr_strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
return MR_EOK;
|
||||
}
|
||||
/* Export to automatic initialization (APP level) */
|
||||
MR_INIT_APP_EXPORT(adc_init);
|
||||
|
||||
Reference in New Issue
Block a user