未验证 提交 da2e3977 编写于 作者: O openharmony_ci 提交者: Gitee

!2915 #I4Y1S4完成,请审批

Merge pull request !2915 from Annie_wang/PR1709
上级 f1fff312 870d79a3
master E0523 OpenHarmony-3.2-Beta1 OpenHarmony-3.2-Beta2 OpenHarmony-3.2-Beta3 OpenHarmony-3.2-Beta4 OpenHarmony-3.2-Beta5 OpenHarmony-3.2-Release OpenHarmony-4.0-Beta1 OpenHarmony-4.0-Beta2 OpenHarmony_filemanager_develop_20220505 OpenHarmony_filemanager_develop_20220614 TR4270 bak_OpenHarmony-4.0-Beta1_20230529 docs-modify feature_IDL_20220811 monthly_20220614 monthly_20220816 monthly_20221018 monthly_20230815 revert-merge-17651-master revert-merge-19334-OpenHarmony-4.0-Beta1 revert-merge-19586-master revert-merge-20613-master revert-merge-21757-OpenHarmony-4.0-Beta2 revert-merge-21765-OpenHarmony-4.0-Beta2 revert-merge-23766-master revert-merge-5580-master weekly_20220406 weekly_20220412 weekly_20220419 weekly_20220426 weekly_20220503 weekly_20220510 weekly_20220524 weekly_20220531 weekly_20220607 weekly_20220614 weekly_20220621 weekly_20220628 weekly_20220705 weekly_20220712 weekly_20220719 weekly_20220726 weekly_20220802 weekly_20220809 weekly_20220816 weekly_20220823 weekly_20220830 weekly_20220906 weekly_20220913 weekly_20220920 weekly_20220927 weekly_20221004 weekly_20221011 weekly_20221018 weekly_20221025 weekly_20221101 weekly_20221108 weekly_20221115 weekly_20221122 weekly_20221129 weekly_20221206 weekly_20221213 weekly_20221220 weekly_20221227 weekly_20230103 weekly_20230110 weekly_20230117 weekly_20230124 weekly_20230131 weekly_20230207 weekly_20230214 weekly_20230221 weekly_20230228 weekly_20230307 weekly_20230314 weekly_20230321 weekly_20230328 weekly_20230404 weekly_20230411 weekly_20230418 weekly_20230425 weekly_20230502 weekly_20230509 weekly_20230516 weekly_20230523 weekly_20230530 weekly_20230606 weekly_20230613 weekly_20230619 weekly_20230626 weekly_20230627 weekly_20230704 weekly_20230712 weekly_20230725 weekly_20230801 weekly_20230808 weekly_20230815 weekly_20230822 weekly_20230829 weekly_20230905 OpenHarmony-v4.0-Beta2 OpenHarmony-v4.0-Beta1 OpenHarmony-v3.2.3-Release OpenHarmony-v3.2.2-Release OpenHarmony-v3.2.1-Release OpenHarmony-v3.2-Release OpenHarmony-v3.2-Beta5 OpenHarmony-v3.2-Beta4 OpenHarmony-v3.2-Beta3 OpenHarmony-v3.2-Beta2 OpenHarmony-v3.2-Beta1
无相关合并请求
......@@ -9,6 +9,7 @@
- [HDF Development Example](driver-hdf-sample.md)
- [Platform Driver Development](driver-develop.md)
- [ADC](driver-platform-adc-develop.md)
- [DAC](driver-platform-dac-develop.md)
- [GPIO](driver-platform-gpio-develop.md)
- [HDMI](driver-platform-hdmi-develop.md)
- [I2C](driver-platform-i2c-develop.md)
......@@ -26,6 +27,7 @@
- [Watchdog](driver-platform-watchdog-develop.md)
- [Platform Driver Usage](driver-platform.md)
- [ADC](driver-platform-adc-des.md)
- [DAC](driver-platform-dac-des.md)
- [GPIO](driver-platform-gpio-des.md)
- [HDMI](driver-platform-hdmi-des.md)
- [I2C](driver-platform-i2c-des.md)
......
......@@ -2,6 +2,8 @@
- **[ADC](driver-platform-adc-develop.md)**
- **[DAC](driver-platform-dac-develop.md)**
- **[GPIO](driver-platform-gpio-develop.md)**
- **[HDMI](driver-platform-hdmi-develop.md)**
......
# DAC
## Overview
### DAC
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:
- Opening or closing a DAC device
- Setting the target digital-to-analog (DA) value
### 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.
- Resolution
The number of binary bits that can be converted by a DAC. A greater number of bits indicates a higher resolution.
- Conversion precision
Difference between the actual output value of the DAC and the theoretical value when the maximum value is added to the input end. The conversion precision of a DAC converter varies depending on the structure of the chip integrated on the DAC and the interface circuit configuration. The ideal conversion precision value should be as small as possible. To achieve optimal DAC conversion precision, the DAC must have high resolution. In addition, errors in the devices or power supply of the interface circuits will affect the conversion precision. When the error exceeds a certain degree, a DAC conversion error will be caused.
- Conversion speed
The conversion speed is determined by the setup time. The setup time is the period from the time the input suddenly changes from all 0s to all 1s to the time the output voltage remains within the FSR ± ½LSB (or FSR ± x%FSR). It is the maximum response time of the DAC, and hence used to measure the conversion speed.
The full scale range (FSR) is the maximum range of the output signal amplitude of a DAC. Different DACs have different FSRs, which can be limited by positive and negative currents or voltages.
The least significant byte (LSB) refers to bit 0 (the least significant bit) in a binary number.
### 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.
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/>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.
**Figure 1** Unified service mode
![](figures/unified-service-mode.png "DAC-unified-service-mode")
### Constraints
Currently, the DAC module supports only the kernels (LiteOS) of mini and small systems.
## Development Guidelines
### 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.
### Available APIs
The table below describes the APIs of the DAC module. For more details, see API Reference.
**Table 1** DAC driver APIs
| API | Description |
| :------------------------------------------------------------| :------------ |
| DevHandle DacOpen(uint32_t number) | Opens a DAC device. |
| void DacClose(DevHandle handle) | Closes a DAC device. |
| int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val) | Sets the target DA value. |
### How to Develop
The figure below illustrates the process of using a DAC device.
**Figure 2** Process of using a DAC device
![](figures/process-of-using-DAC.png "Process of using a DAC")
#### Opening a DAC Device
Call **DacOpen()** to open a DAC device before performing the DA conversion.
```
DevHandle DacOpen(uint32_t number);
```
**Table 2** Description of DacOpen
| **Parameter** | Description |
| ---------- | ----------------- |
| number | DAC device number. |
| **Return Value**| **Description** |
| NULL | Failed to open the DAC device. |
| Device handle | Handle of the DAC device opened.|
Open device 1 of the two ADC devices (numbered 0 and 1) in the system.
```
DevHandle dacHandle = NULL; /* DAC device handle /
/* Open the DAC device. */
dacHandle = DacOpen(1);
if (dacHandle == NULL) {
HDF_LOGE("DacOpen: failed\n");
return;
}
```
#### Setting the Target DA Value
```
int32_t DacWrite(DevHandle handle, uint32_t channel, uint32_t val);
```
**Table 3** Description of DacWrite
| **Parameter** | Description |
| ---------- | -------------- |
| handle | DAC device handle. |
| channel | DAC channel number. |
| val | DA value to set. |
| **Return Value**| **Description**|
| 0 | The operation is successful. |
| Negative value | The operation failed. |
```
/* Write the target DA value through the DAC_CHANNEL_NUM channel. */
ret = DacWrite(dacHandle, DAC_CHANNEL_NUM, val);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: tp DAC write reg fail!:%d", __func__, ret);
DacClose(dacHandle);
return -1;
}
```
#### Closing a DAC Device
After the DAC communication is complete, call **DacClose()** to close the DAC device.
```
void DacClose(DevHandle handle);
```
**Table 4** Description of DacClose
| **Parameter** | Description |
| ---------- | -------------- |
| handle | DAC device handle. |
| **Return Value**| **Description**|
| void | - |
Example:
```
DacClose(dacHandle); /* Close the DAC device. */
```
## Development Example
The procedure is as follows:
1. Open the DAC device based on the device number and obtain the device handle.
2. Set the DA value. If the operation fails, close the device handle.
3. Close the DAC device handle if the access to the DAC is complete.
You can obtain the operation result by printing the log information based on the **val**.
```
#include "hdmi_if.h" /* Header file for DAC APIs */
#include "hdf_log.h" /* Header file for log APIs */
/* Define device 0, channel 1. */
#define DAC_DEVICE_NUM 0
#define DAC_CHANNEL_NUM 1
/* Main entry of DAC routines. */
static int32_t TestCaseDac(void)
{
// Set the target DA value.
uint32_t val = 2;
int32_t ret;
DevHandle dacHandle;
/* Open the DAC device. */
dacHandle = DacOpen(DAC_DEVICE_NUM);
if (dacHandle == NULL) {
HDF_LOGE("%s: Open DAC%u fail!", __func__, DAC_DEVICE_NUM);
return -1;
}
/* Write data. */
ret = DacWrite(dacHandle, DAC_CHANNEL_NUM, val);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: tp DAC write reg fail!:%d", __func__, ret);
DacClose(dacHandle);
return -1;
}
/* Close the DAC device. */
DacClose(dacHandle);
return 0;
}
```
此差异已折叠。
......@@ -2,6 +2,8 @@
- **[ADC](driver-platform-adc-des.md)**
- **[DAC](driver-platform-dac-des.md)**
- **[GPIO](driver-platform-gpio-des.md)**
- **[HDMI](driver-platform-hdmi-des.md)**
......
en/device-dev/driver/figures/process-of-using-DAC.png

3.2 KB

en/device-dev/driver/figures/unified-service-mode.png

69.7 KB | W: 0px | H: 0px

en/device-dev/driver/figures/unified-service-mode.png

71.1 KB | W: 0px | H: 0px

en/device-dev/driver/figures/unified-service-mode.png
en/device-dev/driver/figures/unified-service-mode.png
en/device-dev/driver/figures/unified-service-mode.png
en/device-dev/driver/figures/unified-service-mode.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部