提交 3e67ea50 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 de8dd534
# ADC<a name="1"></a> # ADC
## Overview<a name="section1"></a> ## Overview
### Function
An analog-to-digital converter (ADC) is a device that converts analog signals into digital signals. An analog-to-digital converter (ADC) is a device that converts analog signals into digital signals.
The ADC APIs provide a set of common functions for ADC data transfer, including: The ADC APIs provide a set of common functions for ADC data transfer, including:
- Opening or closing an ADC device - Opening or closing an ADC device
- Obtaining the analog-to-digital (AD) conversion result
### Basic Concepts
The ADC converts analog parameters into digital parameters for easy storage and computing. The technical specifications of the ADC include the following:
- Resolution
The number of binary bits that can be converted by an ADC. A greater number of bits indicates a higher resolution.
- Conversion error
Difference between the actual and theoretical digital values output by an ADC. It is expressed by a multiple of the least significant bit. Generally, the maximum output error is used.
- Transition time
Time required by an ADC to perform a complete conversion.
### Working Principles
In the Hardware Driver Foundation (HDF), the ADC module uses the unified service mode for API adaptation. In this mode, a service is used as the ADC manager to handle external access requests in a unified manner. The unified service mode applies when the system has multiple device objects of the same type. If the independent service mode is used in this case, more device nodes need to be configured and more memory resources will be consumed.
The ADC module is divided into the following layers:
- Interface layer: provides APIs for opening or closing a device and writing data.
- Core layer: provides the capabilities of binding, initializing, and releasing devices.
- Adaptation layer: implements driver-specific functions.
In addition to the power and ground cables, the ADC requires only one cable to connect to the target device. The figure below shows the physical connection.
- Obtaining the analog-to-digital (AD) conversion result **Figure 1** ADC physical connection
**Figure 1** ADC physical connection
![](figures/ADC_physical_connection.png "ADC_physical_connection")
## Available APIs<a name="section2"></a> ![](figures/ADC_physical_connection.png "ADC_physical_connection")
### Constraints
Currently, the ADC module supports only the kernels (LiteOS) of mini and small systems.
## Usage Guidelines
### When to Use
An ADC is usually used to convert an analog voltage into a digital parameter, for example, it is used with a microphone to collect sound, used with an NTC resistor to measure temperature, or converts the output of analog sensors into digital parameters.
### Available APIs
The table below describes the APIs of the ADC module. For more details, see API Reference.
**Table 1** APIs of the ADC driver **Table 1** APIs of the ADC driver
<a name="table1"></a>
| API | Description |
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="18.63%"><p>Category</p> | -------- | ---------------- |
</th> | AdcOpen | Opens an ADC device. |
<th class="cellrowborder" valign="top" width="28.03%"><p>API</p> | AdcClose | Closes an ADC device. |
</th> | AdcRead | Obtains the AD conversion result.|
<th class="cellrowborder" valign="top" width="53.339999999999996%"><p>Description</p>
</th> ### How to Develop
</tr>
</thead> The figure below shows the general development process.
<tbody><tr><td class="cellrowborder" bgcolor="#ffffff" rowspan="2" valign="top" width="18.63%"><p>Managing ADC devices</p>
</td> **Figure 2** Process of using ADC APIs
<td class="cellrowborder" valign="top" width="28.03%"><p>AdcOpen</p>
</td> ![](figures/using-ADC-process.png)
<td class="cellrowborder" valign="top" width="53.339999999999996%">Opens an ADC device.</p>
</td>
</tr> #### Opening an ADC Device.
<tr><td class="cellrowborder" valign="top"><p>AdcClose</p>
</td>
<td valign="top"><p>Closes an ADC device.</p>
</td>
</tr>
<tr><td class="cellrowborder" bgcolor="#ffffff" valign="top" width="18.63%"><p>Obtaining the conversion result</p>
</td>
<td class="cellrowborder" valign="top" width="28.03%"><p>AdcRead</p>
</td>
<td class="cellrowborder" valign="top" width="53.339999999999996%"><p>Reads the AD conversion result.</p>
</td>
</tr>
</table>
## Usage Guidelines<a name="section3"></a>
### How to Use<a name="section4"></a>
The figure below illustrates how to use the APIs.
**Figure 2** Using ADC driver APIs
![](figures/using-ADC-process.png "using-ADC-process.png")
### Opening an ADC Device<a name="section5"></a>
Call **AdcOpen** to open an ADC device. Call **AdcOpen** to open an ADC device.
...@@ -68,43 +83,20 @@ DevHandle AdcOpen(int16_t number); ...@@ -68,43 +83,20 @@ DevHandle AdcOpen(int16_t number);
**Table 2** Description of AdcOpen **Table 2** Description of AdcOpen
<a name="table2"></a>
| Parameter | Description |
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="20.66%"><p> Parameter</strong></p> | ---------- | ----------------- |
</th> | number | ADC device number. |
<th class="cellrowborder" valign="top" width="79.34%"><p><strong>Description</strong></p> | **Return Value**| **Description** |
</th> | NULL | The operation failed. |
</tr> | Device handle | The operation is successful. The handle of the ADC device opened is returned.|
</thead>
<tbody><tr><td class="cellrowborder" valign="top" width="20.66%"><p>number</p> Example: Open device 1 of the two ADCs (numbered 0 and 1) in the system.
</td>
<td class="cellrowborder" valign="top" width="79.34%"><p>ADC device number.</p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="20.66%"><p><strong>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="79.34%"><p><strong>Description</strong></p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="20.66%"><p>NULL</p>
</td>
<td class="cellrowborder" valign="top" width="79.34%"><p>Failed to open the ADC device.</p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="20.66%"><p>Device handle</p>
</td>
<td class="cellrowborder" valign="top" width="79.34%"><p>Handle of the ADC device opened.</p>
</td>
</tr>
</tbody>
</table>
For example, open device 1 of the two ADCs (numbered 0 and 1) in the system.
```c ```c
DevHandle adcHandle = NULL; /* ADC device handle / DevHandle adcHandle = NULL; /* ADC device handle /
/* Open the ADC device. */ /* Open ADC device 1. */
adcHandle = AdcOpen(1); adcHandle = AdcOpen(1);
if (adcHandle == NULL) { if (adcHandle == NULL) {
HDF_LOGE("AdcOpen: failed\n"); HDF_LOGE("AdcOpen: failed\n");
...@@ -112,7 +104,7 @@ if (adcHandle == NULL) { ...@@ -112,7 +104,7 @@ if (adcHandle == NULL) {
} }
``` ```
### Obtaining the AD Conversion Result<a name="section6"></a> #### Obtaining the AD Conversion Result
```c ```c
int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val); int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val);
...@@ -120,48 +112,30 @@ int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val); ...@@ -120,48 +112,30 @@ int32_t AdcRead(DevHandle handle, uint32_t channel, uint32_t *val);
**Table 3** Description of AdcRead **Table 3** Description of AdcRead
<a name="table3"></a>
| Parameter | Description |
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="50%"><p><strong> Parameter</strong></p> | ---------- | -------------- |
</th> | handle | ADC device handle. |
<th class="cellrowborder" valign="top" width="50%"><p><strong>Description</strong></p> | channel | ADC device channel number. |
</th> | val | Pointer to the AD conversion result. |
</tr> | **Return Value**| **Description**|
</thead> | 0 | The operation is successful. |
<tbody><tr><td class="cellrowborder" valign="top" width="50%"><p>handle</p> | Negative value | The operation failed. |
</td>
<td class="cellrowborder" valign="top" width="50%"><p>ADC device handle.</p> Example: Obtain the AD conversion result of channel 1.
</td>
</tr> ```c
<tr><td class="cellrowborder" valign="top" width="50%"><p>channel</p> uint32_t value;
</td> int32_t ret;
<td class="cellrowborder"valign="top" width="50%"><p>ADC device channel number.</p>
</td> ret = AdcRead(adcHandle, 1, &value);
</tr> if (ret != 0) {
<tr><td class="cellrowborder" valign="top" width="50%"><p>val</p> HDF_LOGE("ADC read fail!\n");
</td> return;
<td class="cellrowborder" valign="top" width="50%"><p>AD conversion result.</p> }
</td> ```
</tr>
<tr><td class="cellrowborder" valign="top" width="50%"><p><strong>Return Value</strong></p> #### Closing an ADC Device
</td>
<td class="cellrowborder" valign="top" width="50%"><p><strong>Description</strong></p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="50%"><p>0</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p>The operation is successful.</p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="50%"><p>Negative number</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p>Failed to obtain the AC conversion result.</p>
</td>
</tr>
</tbody>
</table>
### Closing an ADC Device<a name="section7"></a>
Call **AdcClose** to close the ADC device after the ADC communication is complete. Call **AdcClose** to close the ADC device after the ADC communication is complete.
```c ```c
...@@ -169,31 +143,12 @@ void AdcClose(DevHandle handle); ...@@ -169,31 +143,12 @@ void AdcClose(DevHandle handle);
``` ```
**Table 4** Description of AdcClose **Table 4** Description of AdcClose
<a name="table4"></a>
| Parameter | Description |
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="50%"><p> Parameter</p> | ------ | ----------- |
</th> | handle | ADC device handle.|
<th class="cellrowborder" valign="top" width="50%"><p>Description</p> | **Return Value**| **Description** |
</th> | N/A | N/A |
</tr>
</thead>
<tbody><tr><td class="cellrowborder" valign="top" width="50%"><p>handle</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p>ADC device handle.</p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="50%"><p><strong>Return Value</strong></p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p><strong>Description</strong></p>
</td>
</tr>
<tr><td class="cellrowborder" valign="top" width="50%"><p>None</p>
</td>
<td class="cellrowborder" valign="top" width="50%"><p>No value is returned if the ADC device is closed.</p>
</td>
</tr>
</tbody>
</table>
Example: Example:
...@@ -201,9 +156,9 @@ Example: ...@@ -201,9 +156,9 @@ Example:
AdcClose(adcHandle); /* Close the ADC device. */ AdcClose(adcHandle); /* Close the ADC device. */
``` ```
## Example<a name="section8"></a> ### Example
This following example shows how to use ADC APIs to manage an ADC device on a Hi3516D V300 development board. This following example shows how to use ADC APIs to manage an ADC device on a Hi3516D V300 board.
The basic hardware information is as follows: The basic hardware information is as follows:
...@@ -242,7 +197,7 @@ static int32_t TestCaseAdc(void) ...@@ -242,7 +197,7 @@ static int32_t TestCaseAdc(void)
for (i = 0; i < 30; i++) { for (i = 0; i < 30; i++) {
ret = AdcRead(adcHandle, ADC_CHANNEL_NUM, &readBuf[i]); ret = AdcRead(adcHandle, ADC_CHANNEL_NUM, &readBuf[i]);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: tp ADC write reg fail!:%d", __func__, ret); HDF_LOGE("%s: Failed to read ADC!:%d", __func__, ret);
AdcClose(adcHandle); AdcClose(adcHandle);
return -1; return -1;
} }
......
# DAC # DAC
## Overview ## Overview
### DAC ### DAC
...@@ -8,11 +7,9 @@ ...@@ -8,11 +7,9 @@
A digit-to-analog converter (DAC) is a device that converts a digital signal into an analog signal in electronics. A digit-to-analog converter (DAC) is a device that converts a digital signal into an analog signal in electronics.
The DAC APIs provide a set of methods for DAC data transfer, including: The DAC APIs provide a set of methods for DAC data transfer, including:
- Opening or closing a DAC device - Opening or closing a DAC device
- Setting the target digital-to-analog (DA) value - Setting the target digital-to-analog (DA) value
### Basic Concepts ### Basic Concepts
The DAC module provides the output channel for the process control computer system. It connects to the executor to implement automatic control of the production process. It is also an important module in the analog-to-digital converter using feedback technologies. The DAC module provides the output channel for the process control computer system. It connects to the executor to implement automatic control of the production process. It is also an important module in the analog-to-digital converter using feedback technologies.
...@@ -35,29 +32,31 @@ The DAC module provides the output channel for the process control computer syst ...@@ -35,29 +32,31 @@ The DAC module provides the output channel for the process control computer syst
### Working Principles ### Working Principles
In the Hardware Driver Foundation (HDF), the DAC module uses the unified service mode for API adaptation. In this mode, a device service is used as the DAC manager to handle access requests from the devices of the same type in a unified manner. The unified service mode applies to the scenario where there are many device objects of the same type. If the independent service mode is used, more device nodes need to be configured and memory resources will be consumed by services. The figure below shows the unified service mode. In the Hardware Driver Foundation (HDF), the DAC module uses the unified service mode for API adaptation. In this mode, a service is used as the DAC manager to handle external access requests in a unified manner. The unified service mode applies when the system has multiple device objects of the same type. If the independent service mode is used in this case, more device nodes need to be configured and more memory resources will be consumed. The figure below shows the unified service mode.
The DAC module is divided into the following layers: The DAC module is divided into the following layers:
- The interface layer provides APIs for opening or closing a device and writing data.
- The core layer provides the capabilities of binding, initializing, and releasing devices.
- The adaptation layer implements other functions.
>![](../public_sys-resources/icon-note.gif) **NOTE**<br> - Interface layer: provides APIs for opening or closing a device and writing data.
>The core layer can call the functions of the interface layer and uses the hook to call functions of the adaptation layer. In this way, the adaptation layer can indirectly call the functions of the interface layer, but the interface layer cannot call the functions of the adaptation layer. - Core layer: provides the capabilities of binding, initializing, and releasing devices.
- Adaptation layer: implements driver-specific functions.
>![](../public_sys-resources/icon-note.gif) **NOTE**
>
> The core layer can call the functions of the interface layer and uses a hook to call functions of the adaptation layer. In this way, the adaptation layer can indirectly call the functions of the interface layer, but the interface layer cannot call the functions of the adaptation layer.
**Figure 1** Unified service mode **Figure 1** Unified service mode
![](figures/unified-service-mode.png "DAC-unified-service-mode") ![](figures/unified-service-mode.png "DAC unified service mode")
### Constraints ### Constraints
Currently, the DAC module supports only the kernels (LiteOS) of mini and small systems. Currently, the DAC module supports only the kernels (LiteOS) of mini and small systems.
## Development Guidelines ## Usage Guidelines
### When to Use ### When to Use
The DAC module converts digital signals into analog signals in the form of current, voltage, or charge. It is mainly used in audio devices. Audio players and headsets use the DAC module as the digital-to-analog conversion channels. The DAC module converts digital signals into analog signals in the form of current, voltage, or charge. It is mainly used in audio devices. Audio players and headsets use the DAC module as the digital-to-analog conversion channels.
### Available APIs ### Available APIs
...@@ -65,45 +64,44 @@ The table below describes the APIs of the DAC module. For more details, see API ...@@ -65,45 +64,44 @@ The table below describes the APIs of the DAC module. For more details, see API
**Table 1** DAC driver APIs **Table 1** DAC driver APIs
| API | Description | | API | Description |
| :------------------------------------------------------------| :------------ | | ------------------------------------------------------------------ | ------------ |
| DevHandle DacOpen(uint32_t number) | Opens a DAC device. | | DevHandle DacOpen(uint32_t number) | Opens a DAC device. |
| void DacClose(DevHandle handle) | Closes a DAC device. | | void DacClose(DevHandle handle) | Closes a DAC device. |
| int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val) | Sets a target DA value. | | int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val) | Sets a target DA value.|
### How to Develop ### How to Develop
The figure below illustrates how to use the APIs. The figure below shows the general development process.
**Figure 2** Process of using DAC APIs
**Figure 2** Using DAC driver APIs
![](figures/using-DAC-process.png "using-DAC-process.png") ![](figures/using-DAC-process.png)
#### Opening a DAC Device #### Opening a DAC Device
Call **DacOpen()** to open a DAC device before performing the DA conversion. Call **DacOpen()** to open a DAC device before performing the DA conversion.
``` ```c++
DevHandle DacOpen(uint32_t number); DevHandle DacOpen(uint32_t number);
``` ```
**Table 2** Description of DacOpen **Table 2** Description of DacOpen
| **Parameter** | Description | | Parameter | Description |
| ---------- | ----------------- | | --------- | ---------------- |
| number | DAC device number. | | number | DAC device number. |
| **Return Value**| **Description** | | **Return Value**| **Description** |
| NULL | Failed to open the DAC device. | | NULL | The operation failed. |
| Device handle | Handle of the DAC device opened.| | Device handle | The operation is successful. The handle of the DAC device opened is returned.|
Open device 1 of the two ADC devices (numbered 0 and 1) in the system. Example: Open device 1 of the two DAC devices (numbered 0 and 1) in the system.
``` ```c++
DevHandle dacHandle = NULL; /* DAC device handle / DevHandle dacHandle = NULL; /* DAC device handle /
/* Open the DAC device. */ /* Open DAC device 1. */
dacHandle = DacOpen(1); dacHandle = DacOpen(1);
if (dacHandle == NULL) { if (dacHandle == NULL) {
HDF_LOGE("DacOpen: failed\n"); HDF_LOGE("DacOpen: failed\n");
...@@ -113,23 +111,22 @@ if (dacHandle == NULL) { ...@@ -113,23 +111,22 @@ if (dacHandle == NULL) {
#### Setting a Target DA Value #### Setting a Target DA Value
``` ```c++
int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val); int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val);
``` ```
**Table 3** Description of DacWrite **Table 3** Description of DacWrite
| Parameter | Description |
| **Parameter** | Description | | --------- | ------------ |
| ---------- | -------------- | | handle | DAC device handle. |
| handle | DAC device handle. | | channel | DAC channel number.|
| channel | DAC channel number. | | val | DA value to set. |
| val | DA value to set. |
| **Return Value**| **Description**| | **Return Value**| **Description**|
| 0 | The operation is successful. | | 0 | The operation is successful. |
| Negative value | The operation failed. | | Negative value | The operation failed. |
``` ```c++
/* Write the target DA value through the DAC_CHANNEL_NUM channel. */ /* Write the target DA value through the DAC_CHANNEL_NUM channel. */
ret = DacWrite(dacHandle, DAC_CHANNEL_NUM, val); ret = DacWrite(dacHandle, DAC_CHANNEL_NUM, val);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
...@@ -142,28 +139,25 @@ int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val); ...@@ -142,28 +139,25 @@ int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val);
#### Closing a DAC Device #### Closing a DAC Device
After the DAC communication is complete, call **DacClose()** to close the DAC device. After the DAC communication is complete, call **DacClose()** to close the DAC device.
``` ```c++
void DacClose(DevHandle handle); void DacClose(DevHandle handle);
``` ```
**Table 4** Description of DacClose **Table 4** Description of DacClose
| Parameter | Description |
| **Parameter** | Description | | --------- | ------------ |
| ---------- | -------------- | | handle | DAC device handle. |
| handle | DAC device handle. |
| **Return Value**| **Description**| | **Return Value**| **Description**|
| void | - | | void | - |
Example: Example:
``` ```c++
DacClose(dacHandle); /* Close the DAC device. */ DacClose(dacHandle); /* Close the DAC device. */
``` ```
## Development Example ## Example
The procedure is as follows: The procedure is as follows:
...@@ -173,8 +167,8 @@ The procedure is as follows: ...@@ -173,8 +167,8 @@ The procedure is as follows:
You can obtain the operation result by printing the log information based on the **val**. You can obtain the operation result by printing the log information based on the **val**.
``` ```c++
#include "hdmi_if.h" /* Header file for DAC APIs */ #include "dac_if.h" /* Header file for DAC APIs */
#include "hdf_log.h" /* Header file for log APIs */ #include "hdf_log.h" /* Header file for log APIs */
/* Define device 0, channel 1. */ /* Define device 0, channel 1. */
...@@ -209,4 +203,4 @@ static int32_t TestCaseDac(void) ...@@ -209,4 +203,4 @@ static int32_t TestCaseDac(void)
return 0; return 0;
} }
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册