未验证 提交 e9eac4b0 编写于 作者: K king_he 提交者: Gitee

update zh-cn/device-dev/driver/driver-platform-pwm-des.md.

Signed-off-by: Nking_he <6384784@qq.com>
上级 e9bfd639
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
PWM是脉冲宽度调制(Pulse Width Modulation)的缩写,是一种对模拟信号电平进行数字编码并将其转换为脉冲的技术。常用于马达控制、背光亮度调节等。 PWM是脉冲宽度调制(Pulse Width Modulation)的缩写,是一种对模拟信号电平进行数字编码并将其转换为脉冲的技术。常用于马达控制、背光亮度调节等。
PWM接口定义了操作PWM设备的通用方法集合,包括: PWM接口定义了操作PWM设备的通用方法集合,包括:
- PWM设备句柄获取和释放。 - PWM设备句柄获取和释放。
- PWM周期、占空比、极性的设置。 - PWM周期、占空比、极性的设置。
...@@ -23,7 +23,7 @@ PWM是脉冲宽度调制(Pulse Width Modulation)的缩写,是一种对模 ...@@ -23,7 +23,7 @@ PWM是脉冲宽度调制(Pulse Width Modulation)的缩写,是一种对模
| -------- | -------- | | -------- | -------- |
| duty | 占空时间,以纳秒为单位。 | | duty | 占空时间,以纳秒为单位。 |
| period | PWM周期,以纳秒为单位。 | | period | PWM周期,以纳秒为单位。 |
| number | 要生成的方波数。<br/>-&nbsp;正值:表示将生成指定数量的方波<br/>-&nbsp;0:表示方波将不断产生。 | | number | 要生成的方波数。<br/>-&nbsp;正值:表示将生成指定数量的方波<br/>-&nbsp;0:表示方波将不断产生。 |
| polarity | 极性:正极性/反极性。 | | polarity | 极性:正极性/反极性。 |
| status | 状态:启用状态/禁用状态。 | | status | 状态:启用状态/禁用状态。 |
...@@ -39,7 +39,7 @@ PWM是脉冲宽度调制(Pulse Width Modulation)的缩写,是一种对模 ...@@ -39,7 +39,7 @@ PWM是脉冲宽度调制(Pulse Width Modulation)的缩写,是一种对模
| PWM配置操作 | -&nbsp;PwmSetPeriod:设置PWM周期<br/>-&nbsp;PwmSetDuty:设置PWM占空时间<br/>-&nbsp;PwmSetPolarity:设置PWM极性 | | PWM配置操作 | -&nbsp;PwmSetPeriod:设置PWM周期<br/>-&nbsp;PwmSetDuty:设置PWM占空时间<br/>-&nbsp;PwmSetPolarity:设置PWM极性 |
| 设置/获取PWM配置信息 | -&nbsp;PwmSetConfig:设置PWM设备参数<br/>-&nbsp;PwmGetConfig:获取PWM设备参数 | | 设置/获取PWM配置信息 | -&nbsp;PwmSetConfig:设置PWM设备参数<br/>-&nbsp;PwmGetConfig:获取PWM设备参数 |
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**<br>
> 本文涉及的所有接口,仅限内核态使用,不支持在用户态使用。 > 本文涉及的所有接口,仅限内核态使用,不支持在用户态使用。
...@@ -70,7 +70,7 @@ DevHandle PwmOpen(uint32_t num); ...@@ -70,7 +70,7 @@ DevHandle PwmOpen(uint32_t num);
| -------- | -------- | | -------- | -------- |
| num | PWM设备编号 | | num | PWM设备编号 |
| **返回值** | **返回值描述** | | **返回值** | **返回值描述** |
| handle | 获取成功返回PWM设备句柄 | | handle | 获取成功返回PWM设备句柄 |
| NULL | 获取失败 | | NULL | 获取失败 |
假设系统中的PWM设备号为0,获取该PWM设备句柄的示例如下: 假设系统中的PWM设备号为0,获取该PWM设备句柄的示例如下:
...@@ -162,10 +162,10 @@ int32_t PwmDisable(DevHandle handle); ...@@ -162,10 +162,10 @@ int32_t PwmDisable(DevHandle handle);
``` ```
int32_t ret; int32_t ret;
/*禁用PWM设备*/ /* 禁用PWM设备 */
ret = PwmDisable(handle); ret = PwmDisable(handle);
if (ret != 0) { if (ret != 0) {
/*错误处理*/ /* 错误处理 */
} }
``` ```
...@@ -193,7 +193,7 @@ int32_t PwmSetPeriod(DevHandle handle, uint32_t period); ...@@ -193,7 +193,7 @@ int32_t PwmSetPeriod(DevHandle handle, uint32_t period);
``` ```
int32_t ret; int32_t ret;
/*设置周期为50000000纳秒*/ /* 设置周期为50000000纳秒 */
ret = PwmSetPeriod(handle, 50000000); ret = PwmSetPeriod(handle, 50000000);
if (ret != 0) { if (ret != 0) {
/*错误处理*/ /*错误处理*/
...@@ -224,10 +224,10 @@ int32_t PwmSetDuty(DevHandle handle, uint32_t duty); ...@@ -224,10 +224,10 @@ int32_t PwmSetDuty(DevHandle handle, uint32_t duty);
``` ```
int32_t ret; int32_t ret;
/*设置占空时间为25000000纳秒*/ /* 设置占空时间为25000000纳秒 */
ret = PwmSetDuty(handle, 25000000); ret = PwmSetDuty(handle, 25000000);
if (ret != 0) { if (ret != 0) {
/*错误处理*/ /* 错误处理 */
} }
``` ```
...@@ -255,10 +255,10 @@ int32_t PwmSetPolarity(DevHandle handle, uint8_t polarity); ...@@ -255,10 +255,10 @@ int32_t PwmSetPolarity(DevHandle handle, uint8_t polarity);
``` ```
int32_t ret; int32_t ret;
/*设置极性为反*/ /* 设置极性为反 */
ret = PwmSetPolarity(handle, PWM_INVERTED_POLARITY); ret = PwmSetPolarity(handle, PWM_INVERTED_POLARITY);
if (ret != 0) { if (ret != 0) {
/*错误处理*/ /* 错误处理 */
} }
``` ```
...@@ -286,16 +286,16 @@ int32_t PwmSetConfig(DevHandle handle, struct PwmConfig *config); ...@@ -286,16 +286,16 @@ int32_t PwmSetConfig(DevHandle handle, struct PwmConfig *config);
``` ```
int32_t ret; int32_t ret;
struct PwmConfig pcfg; struct PwmConfig pcfg;
pcfg.duty = 25000000; /*占空时间为25000000纳秒*/ pcfg.duty = 25000000; /* 占空时间为25000000纳秒 */
pcfg.period = 50000000; /*周期为50000000纳秒*/ pcfg.period = 50000000; /* 周期为50000000纳秒 */
pcfg.number = 0; /*不断产生方波*/ pcfg.number = 0; /* 不断产生方波 */
pcfg.polarity = PWM_INVERTED_POLARITY; /*极性为反*/ pcfg.polarity = PWM_INVERTED_POLARITY; /* 极性为反 */
pcfg.status = PWM_ENABLE_STATUS; /*运行状态为启用*/ pcfg.status = PWM_ENABLE_STATUS; /* 运行状态为启用 */
/*设置PWM设备参数*/ /* 设置PWM设备参数 */
ret = PwmSetConfig(handle, &pcfg); ret = PwmSetConfig(handle, &pcfg);
if (ret != 0) { if (ret != 0) {
/*错误处理*/ /* 错误处理 */
} }
``` ```
...@@ -345,11 +345,11 @@ void PwmTestSample(void) ...@@ -345,11 +345,11 @@ void PwmTestSample(void)
DevHandle handle = NULL; DevHandle handle = NULL;
struct PwmConfig pcfg; struct PwmConfig pcfg;
pcfg.duty = 20000000; /*占空时间为20000000纳秒*/ pcfg.duty = 20000000; /* 占空时间为20000000纳秒 */
pcfg.period = 40000000; /*周期为40000000纳秒*/ pcfg.period = 40000000; /* 周期为40000000纳秒 */
pcfg.number = 100; /*生成100个方波*/ pcfg.number = 100; /* 生成100个方波 */
pcfg.polarity = PWM_NORMAL_POLARITY; /*极性为正*/ pcfg.polarity = PWM_NORMAL_POLARITY; /* 极性为正 */
pcfg.status = PWM_ENABLE_STATUS; /*运行状态为启用*/ pcfg.status = PWM_ENABLE_STATUS; /* 运行状态为启用 */
/* PWM设备编号,要填写实际平台上的编号 */ /* PWM设备编号,要填写实际平台上的编号 */
num = 1; num = 1;
...@@ -361,49 +361,49 @@ void PwmTestSample(void) ...@@ -361,49 +361,49 @@ void PwmTestSample(void)
return; return;
} }
/*设置周期为50000000纳秒*/ /* 设置周期为50000000纳秒 */
ret = PwmSetPeriod(handle, 50000000); ret = PwmSetPeriod(handle, 50000000);
if (ret != 0) { if (ret != 0) {
HDF_LOGE("PwmSetPeriod: failed, ret %d\n", ret); HDF_LOGE("PwmSetPeriod: failed, ret %d\n", ret);
goto _ERR; goto _ERR;
} }
/*设置占空时间为25000000纳秒*/ /* 设置占空时间为25000000纳秒 */
ret = PwmSetDuty(handle, 25000000); ret = PwmSetDuty(handle, 25000000);
if (ret != 0) { if (ret != 0) {
HDF_LOGE("PwmSetDuty: failed, ret %d\n", ret); HDF_LOGE("PwmSetDuty: failed, ret %d\n", ret);
goto _ERR; goto _ERR;
} }
/*设置极性为反*/ /* 设置极性为反 */
ret = PwmSetPolarity(handle, PWM_INVERTED_POLARITY); ret = PwmSetPolarity(handle, PWM_INVERTED_POLARITY);
if (ret != 0) { if (ret != 0) {
HDF_LOGE("PwmSetPolarity: failed, ret %d\n", ret); HDF_LOGE("PwmSetPolarity: failed, ret %d\n", ret);
goto _ERR; goto _ERR;
} }
/*获取PWM设备参数*/ /* 获取PWM设备参数 */
ret = PwmGetConfig(handle, &pcfg); ret = PwmGetConfig(handle, &pcfg);
if (ret != 0) { if (ret != 0) {
HDF_LOGE("PwmGetConfig: failed, ret %d\n", ret); HDF_LOGE("PwmGetConfig: failed, ret %d\n", ret);
goto _ERR; goto _ERR;
} }
/*启用PWM设备*/ /* 启用PWM设备 */
ret = PwmEnable(handle); ret = PwmEnable(handle);
if (ret != 0) { if (ret != 0) {
HDF_LOGE("PwmEnable: failed, ret %d\n", ret); HDF_LOGE("PwmEnable: failed, ret %d\n", ret);
goto _ERR; goto _ERR;
} }
/*设置PWM设备参数*/ /* 设置PWM设备参数 */
ret = PwmSetConfig(handle, &pcfg); ret = PwmSetConfig(handle, &pcfg);
if (ret != 0) { if (ret != 0) {
HDF_LOGE("PwmSetConfig: failed, ret %d\n", ret); HDF_LOGE("PwmSetConfig: failed, ret %d\n", ret);
goto _ERR; goto _ERR;
} }
/*禁用PWM设备*/ /* 禁用PWM设备 */
ret = PwmDisable(handle); ret = PwmDisable(handle);
if (ret != 0) { if (ret != 0) {
HDF_LOGE("PwmDisable: failed, ret %d\n", ret); HDF_LOGE("PwmDisable: failed, ret %d\n", ret);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册