Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
589cf078
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
589cf078
编写于
3月 25, 2022
作者:
L
liyan
提交者:
Gitee
3月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/device-dev/driver/driver-platform-regulator-des.md.
Signed-off-by:
N
li-yan339
<
liyan339@h-partners.com
>
上级
3058ec50
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
99 addition
and
124 deletion
+99
-124
zh-cn/device-dev/driver/driver-platform-regulator-des.md
zh-cn/device-dev/driver/driver-platform-regulator-des.md
+99
-124
未找到文件。
zh-cn/device-dev/driver/driver-platform-regulator-des.md
浏览文件 @
589cf078
# R
EGULATOR<a name="1"></a>
# R
egulator
-
[
概述
](
#section1
)
-
[
功能简介
](
#section2
)
-
[
基本概念
](
#section3
)
-
[
运作机制
](
#section4
)
-
[
约束与限制
](
#section5
)
-
[
使用指导
](
#section6
)
-
[
场景介绍
](
#section7
)
-
[
接口说明
](
#section8
)
-
[
开发步骤
](
#section9
)
-
[
使用实例
](
#section10
)
## 概述
<a name="section1"></a>
## 概述
### 功能简介
<a name="section2"></a>
### 功能简介
-
R
EGULATOR模块用于控制系统中某些设备的电压/电流供应。在嵌入式系统(尤其是手机)中,控制耗电量很重要,直接影响到电池的续航时间。所以,如果系统中某一个模块暂时不需要使用,就可以通过REGULATOR
关闭其电源供应;或者降低提供给该模块的电压、电流大小。
-
R
egulator模块用于控制系统中某些设备的电压/电流供应。在嵌入式系统(尤其是手机)中,控制耗电量很重要,直接影响到电池的续航时间。所以,如果系统中某一个模块暂时不需要使用,就可以通过Regulator
关闭其电源供应;或者降低提供给该模块的电压、电流大小。
-
R
EGULATOR接口定义了操作REGULATOR
设备的通用方法集合,包括:
-
R
egulator接口定义了操作Regulator
设备的通用方法集合,包括:
-
R
EGULATOR
设备句柄获取和销毁。
-
R
egulator
设备句柄获取和销毁。
-
R
EGULATOR
设备电压、电流的设置。
-
R
egulator
设备电压、电流的设置。
-
R
EGULATOR
设备使能和关闭。
-
R
egulator
设备使能和关闭。
-
R
EGULATOR
设备电压、电流和状态的获取。
-
R
egulator
设备电压、电流和状态的获取。
### 基本概念
<a name="section3"></a>
### 基本概念
-
校准器
-
校准器
...
@@ -31,73 +21,73 @@
...
@@ -31,73 +21,73 @@
-
Consumer
-
Consumer
由R
EGULATOR
供电的设备统称为Consumer, 其可分为静态和动态两类:
由R
egulator
供电的设备统称为Consumer, 其可分为静态和动态两类:
*
静态:不需要改变电压电流,只需要开关电源,通常在bootloader、firmware、kernel board阶段被设置。
*
静态:不需要改变电压电流,只需要开关电源,通常在bootloader、firmware、kernel board阶段被设置。
*
动态:根据操作需求改变电压电流。
*
动态:根据操作需求改变电压电流。
-
P
ower Management Ic
-
P
MI(Power Management Ic)
电源管理芯片,内含多个电源甚至其他子系统。
电源管理芯片,内含多个电源甚至其他子系统。
### 运作机制
<a name="section4"></a>
### 运作机制
在HDF框架中,R
EGULATOR模块接口适配模式采用统一服务模式,这需要一个设备服务来作为REGULATOR模块的管理器,统一处理外部访问,这会在配置文件中有所体现。统一服务模式适合于同类型设备对象较多的情况,如REGULATOR
可能同时具备十几个控制器,采用独立服务模式需要配置更多的设备节点,且服务会占据内存资源。
在HDF框架中,R
egulator模块接口适配模式采用统一服务模式,这需要一个设备服务来作为Regulator模块的管理器,统一处理外部访问,这会在配置文件中有所体现。统一服务模式适合于同类型设备对象较多的情况,如Regulator
可能同时具备十几个控制器,采用独立服务模式需要配置更多的设备节点,且服务会占据内存资源。
R
EGULATOR
模块各分层的作用为:接口层提供打开设备,写入数据,关闭设备接口的能力。核心层主要提供绑定设备、初始化设备以及释放设备的能力。适配层实现其他具体的功能。
R
egulator
模块各分层的作用为:接口层提供打开设备,写入数据,关闭设备接口的能力。核心层主要提供绑定设备、初始化设备以及释放设备的能力。适配层实现其他具体的功能。

说明:核心层可以调用接口层的函数,也可以通过钩子函数调用适配层函数,从而使得适配层间接的可以调用接口层函数,但是不可逆转接口层调用适配层函数。

说明:核心层可以调用接口层的函数,也可以通过钩子函数调用适配层函数,从而使得适配层间接的可以调用接口层函数,但是不可逆转接口层调用适配层函数。
图 1
统一服务模式结构图
**图 1**
统一服务模式结构图


### 约束与限制
<a name="section5"></a>
### 约束与限制
REGULATOR
模块当前仅支持轻量和小型系统内核(LiteOS) 。
Regulator
模块当前仅支持轻量和小型系统内核(LiteOS) 。
## 使用指导
<a name="section6"></a>
## 使用指导
### 场景介绍
<a name="section7"></a>
### 场景介绍
REGULATOR
主要用于:
Regulator
主要用于:
1.
用于控制系统中某些设备的电压/电流供应。
1.
用于控制系统中某些设备的电压/电流供应。
2.
用于稳压电源的管理
。
2.
用于稳压电源的管理。
### 接口说明
<a name="section8"></a>
### 接口说明
**表1**
R
EGULATOR
设备API功能介绍
**表1**
R
egulator
设备API功能介绍
| 接口名 | 描述 |
| 接口名 | 描述 |
| --------------------- | ------------------------- |
| --------------------- | ------------------------- |
| RegulatorOpen | 获取R
EGULATOR
设备驱动句柄 |
| RegulatorOpen | 获取R
egulator
设备驱动句柄 |
| RegulatorClose | 销毁R
EGULATOR
设备驱动句柄 |
| RegulatorClose | 销毁R
egulator
设备驱动句柄 |
| RegulatorEnable | 使能R
EGULATOR
|
| RegulatorEnable | 使能R
egulator
|
| RegulatorDisable | 禁用R
EGULATOR
|
| RegulatorDisable | 禁用R
egulator
|
| RegulatorForceDisable | 强制禁用R
EGULATOR
|
| RegulatorForceDisable | 强制禁用R
egulator
|
| RegulatorSetVoltage | 设置R
EGULATOR
输出电压 |
| RegulatorSetVoltage | 设置R
egulator
输出电压 |
| RegulatorGetVoltage | 获取R
EGULATOR
输出电压 |
| RegulatorGetVoltage | 获取R
egulator
输出电压 |
| RegulatorSetCurrent | 设置R
EGULATOR
输出电流 |
| RegulatorSetCurrent | 设置R
egulator
输出电流 |
| RegulatorGetCurrent | 获取R
EGULATOR
输出电流 |
| RegulatorGetCurrent | 获取R
egulator
输出电流 |
| RegulatorGetStatus | 获取R
EGULATOR
状态 |
| RegulatorGetStatus | 获取R
egulator
状态 |
### 开发步骤
<a name="section9"></a>
### 开发步骤
在操作系统启动过程中,驱动管理模块根据配置文件加载R
EGULATOR驱动,REGULATOR驱动会检测REGULATOR
器件并初始化驱动。
在操作系统启动过程中,驱动管理模块根据配置文件加载R
egulator驱动,Regulator驱动会检测Regulator
器件并初始化驱动。
使用R
EGULATOR设备的一般流程如
[
图1
](
#fig1_REGULATOR_des
)
所示。
使用R
egulator设备的一般流程如图2
所示。
**图
1**
REGULATOR设备使用流程图
<a
name=
"fig1_REGULATOR_des"
></a>
**图
2**
Regulator设备使用流程图


#### 获取R
EGULATOR
设备句柄
#### 获取R
egulator
设备句柄
在操作R
EGULATOR设备时,首先要调用RegulatorOpen获取REGULATOR设备句柄,该函数会返回指定设备名称的REGULATOR
设备句柄。
在操作R
egulator设备时,首先要调用RegulatorOpen获取Regulator设备句柄,该函数会返回指定设备名称的Regulator
设备句柄。
```
```
DevHandle RegulatorOpen(const char *name);
DevHandle RegulatorOpen(const char *name);
...
@@ -105,32 +95,30 @@ DevHandle RegulatorOpen(const char *name);
...
@@ -105,32 +95,30 @@ DevHandle RegulatorOpen(const char *name);
**表2**
RegulatorOpen参数和返回值描述
**表2**
RegulatorOpen参数和返回值描述
<a
name=
"table2"
></a>
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ---------- | ----------------------------- |
| ---------- | ----------------------------- |
| name | R
EGULATOR
设备名称 |
| name | R
egulator
设备名称 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
| handle | 获取成功返回R
EGULATOR
设备句柄 |
| handle | 获取成功返回R
egulator
设备句柄 |
| NULL | 获取失败 |
| NULL | 获取失败 |
```
```
/* R
EGULATOR
设备名称 */
/* R
egulator
设备名称 */
const char *name = "regulator_virtual_1";
const char *name = "regulator_virtual_1";
DevHandle handle = NULL;
DevHandle handle = NULL;
/* 获取R
EGULATOR
设备句柄 */
/* 获取R
egulator
设备句柄 */
handle = RegulatorOpen(name);
handle = RegulatorOpen(name);
if (handle == NULL) {
if (handle == NULL) {
/* 错误处理 */
/* 错误处理 */
}
}
```
```
#### 销毁R
EGULATOR
设备句柄
#### 销毁R
egulator
设备句柄
关闭R
EGULATOR
设备,系统释放对应的资源。
关闭R
egulator
设备,系统释放对应的资源。
```
```
void RegulatorClose(DevHandle handle);
void RegulatorClose(DevHandle handle);
...
@@ -138,31 +126,28 @@ void RegulatorClose(DevHandle handle);
...
@@ -138,31 +126,28 @@ void RegulatorClose(DevHandle handle);
**表3**
RegulatorClose参数描述
**表3**
RegulatorClose参数描述
<a
name=
"table3"
></a>
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ------ | ----------------- |
| ------ | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
```
```
/* 销毁R
EGULATOR
设备句柄 */
/* 销毁R
egulator
设备句柄 */
RegulatorClose(handle);
RegulatorClose(handle);
```
```
#### 使能
<a name="section3.4_REGULATOR_des"></a>
#### 使能
启用R
EGULATOR
设备。
启用R
egulator
设备。
```
```
int32_t RegulatorEnable(DevHandle handle);
int32_t RegulatorEnable(DevHandle handle);
```
```
**表4**
RegulatorEnable参数描述
<a
name=
"table4"
></a>
**表4**
RegulatorEnable参数描述
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ---------- | ----------------- |
| ---------- | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
| 0 | 使能成功 |
| 0 | 使能成功 |
| 负数 | 使能失败 |
| 负数 | 使能失败 |
...
@@ -172,16 +157,16 @@ int32_t RegulatorEnable(DevHandle handle);
...
@@ -172,16 +157,16 @@ int32_t RegulatorEnable(DevHandle handle);
```
```
int32_t ret;
int32_t ret;
/*启用R
EGULATOR
设备*/
/*启用R
egulator
设备*/
ret = RegulatorEnable(handle);
ret = RegulatorEnable(handle);
if (ret != 0) {
if (ret != 0) {
/*错误处理*/
/*错误处理*/
}
}
```
```
#### 禁用
<a name="section3.5_REGULATOR_des"></a>
#### 禁用
禁用R
EGULATOR设备
。
禁用R
egulator设备。如果Regulator设备状态为常开,或存在Regulator设备子节点未禁用,则禁用失败
。
```
```
int32_t RegulatorDisable(DevHandle handle);
int32_t RegulatorDisable(DevHandle handle);
...
@@ -191,7 +176,7 @@ int32_t RegulatorDisable(DevHandle handle);
...
@@ -191,7 +176,7 @@ int32_t RegulatorDisable(DevHandle handle);
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ---------- | ----------------- |
| ---------- | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
| 0 | 禁用成功 |
| 0 | 禁用成功 |
| 负数 | 禁用失败 |
| 负数 | 禁用失败 |
...
@@ -199,28 +184,27 @@ int32_t RegulatorDisable(DevHandle handle);
...
@@ -199,28 +184,27 @@ int32_t RegulatorDisable(DevHandle handle);
```
```
int32_t ret;
int32_t ret;
/*禁用R
EGULATOR设备,如果REGULATOR设备状态为常开,或存在REGULATOR设备子节点未禁用,则禁用失败
*/
/*禁用R
egulator设备
*/
ret = RegulatorDisable(handle);
ret = RegulatorDisable(handle);
if (ret != 0) {
if (ret != 0) {
/*错误处理*/
/*错误处理*/
}
}
```
```
#### 强制禁用
<a name="section3.6_REGULATOR_des"></a>
#### 强制禁用
强制禁用R
EGULATOR设备
。
强制禁用R
egulator设备。无论Regulator设备的状态是常开还是子节点已使能,Regulator设备都会被禁用
。
```
```
int32_t RegulatorForceDisable(DevHandle handle);
int32_t RegulatorForceDisable(DevHandle handle);
```
```
**表
5**
Regulator
Disable参数描述
**表
6**
RegulatorForce
Disable参数描述
<a
name=
"table5_REGULATOR_des"
></a>
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ---------- | ----------------- |
| ---------- | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
| 0 | 禁用成功 |
| 0 | 禁用成功 |
| 负数 | 禁用失败 |
| 负数 | 禁用失败 |
...
@@ -228,16 +212,16 @@ int32_t RegulatorForceDisable(DevHandle handle);
...
@@ -228,16 +212,16 @@ int32_t RegulatorForceDisable(DevHandle handle);
```
```
int32_t ret;
int32_t ret;
/*强制禁用R
EGULATOR设备,无论REGULATOR设备的状态是常开还是子节点已使能,REGULATOR设备都会被禁用
*/
/*强制禁用R
egulator设备
*/
ret = RegulatorForceDisable(handle);
ret = RegulatorForceDisable(handle);
if (ret != 0) {
if (ret != 0) {
/*错误处理*/
/*错误处理*/
}
}
```
```
#### 设置R
EGULATOR输出电压范围<a name="section3.7_REGULATOR_des"></a>
#### 设置R
egulator输出电压范围
设置R
EGULATOR
电压输出电压范围。
设置R
egulator
电压输出电压范围。
```
```
int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv);
int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv);
...
@@ -245,11 +229,9 @@ int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv);
...
@@ -245,11 +229,9 @@ int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv);
**表7**
RegulatorSetVoltage参数描述
**表7**
RegulatorSetVoltage参数描述
<a
name=
"table7_REGULATOR_des"
></a>
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ---------- | ----------------- |
| ---------- | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
| minUv | 最小电压 |
| minUv | 最小电压 |
| maxUv | 最大电压 |
| maxUv | 最大电压 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
...
@@ -258,19 +240,19 @@ int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv);
...
@@ -258,19 +240,19 @@ int32_t RegulatorSetVoltage(DevHandle handle, uint32_t minUv, uint32_t maxUv);
```
```
int32_t ret;
int32_t ret;
int32_t minUv = 0;
//最小电压为0Uv
int32_t minUv = 0;
//最小电压为0µV
int32_t maxUv = 20000;
//最大电压为20000Uv
int32_t maxUv = 20000;
//最大电压为20000µV
/*设置R
EGULATOR
电压输出电压范围*/
/*设置R
egulator
电压输出电压范围*/
ret = RegulatorSetVoltage(handle, minUv, maxUv);
ret = RegulatorSetVoltage(handle, minUv, maxUv);
if (ret != 0) {
if (ret != 0) {
/*错误处理*/
/*错误处理*/
}
}
```
```
#### 获取R
EGULATOR电压<a name="section3.8_REGULATOR_des"></a>
#### 获取R
egulator电压
获取R
EGULATOR
电压。
获取R
egulator
电压。
```
```
int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage);
int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage);
...
@@ -278,11 +260,10 @@ int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage);
...
@@ -278,11 +260,10 @@ int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage);
**表8**
RegulatorGetVoltage参数描述
**表8**
RegulatorGetVoltage参数描述
<a
name=
"table8_REGULATOR_des"
></a>
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ---------- | ----------------- |
| ---------- | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
|
*
voltage | 参数指针 |
|
*
voltage | 参数指针 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
| 0 | 获取成功 |
| 0 | 获取成功 |
...
@@ -292,16 +273,16 @@ int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage);
...
@@ -292,16 +273,16 @@ int32_t RegulatorGetVoltage(DevHandle handle, uint32_t *voltage);
int32_t ret;
int32_t ret;
uint32_t voltage;
uint32_t voltage;
/*获取R
EGULATOR
电压*/
/*获取R
egulator
电压*/
ret = RegulatorGetVoltage(handle, &voltage);
ret = RegulatorGetVoltage(handle, &voltage);
if (ret != 0) {
if (ret != 0) {
/*错误处理*/
/*错误处理*/
}
}
```
```
#### 设置R
EGULATOR输出电流范围<a name="section3.9_REGULATOR_des"></a>
#### 设置R
egulator输出电流范围
设置R
EGULATOR
输出电流范围。
设置R
egulator
输出电流范围。
```
```
int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa);
int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa);
...
@@ -309,11 +290,9 @@ int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa);
...
@@ -309,11 +290,9 @@ int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa);
**表9**
RegulatorSetCurrent参数描述
**表9**
RegulatorSetCurrent参数描述
<a
name=
"table9_REGULATOR_des"
></a>
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ---------- | ----------------- |
| ---------- | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
| minUa | 最小电流 |
| minUa | 最小电流 |
| maxUa | 最大电流 |
| maxUa | 最大电流 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
...
@@ -322,19 +301,19 @@ int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa);
...
@@ -322,19 +301,19 @@ int32_t RegulatorSetCurrent(DevHandle handle, uint32_t minUa, uint32_t maxUa);
```
```
int32_t ret;
int32_t ret;
int32_t minUa = 0;
//最小电流为0Ua
int32_t minUa = 0;
//最小电流为0μA
int32_t maxUa = 200; //最大电流为200
Ua
int32_t maxUa = 200; //最大电流为200
μA
/*设置R
EGULATOR
输出电流范围*/
/*设置R
egulator
输出电流范围*/
ret = RegulatorSetCurrent(handle, minUa, maxUa);
ret = RegulatorSetCurrent(handle, minUa, maxUa);
if (ret != 0) {
if (ret != 0) {
/*错误处理*/
/*错误处理*/
}
}
```
```
#### 获取R
EGULATOR电流<a name="section3.10_REGULATOR_des"></a>
#### 获取R
egulator电流
获取R
EGULATOR
电流。
获取R
egulator
电流。
```
```
int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent);
int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent);
...
@@ -342,11 +321,9 @@ int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent);
...
@@ -342,11 +321,9 @@ int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent);
**表10**
RegulatorGetCurrent参数描述
**表10**
RegulatorGetCurrent参数描述
<a
name=
"table10_REGULATOR_des"
></a>
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ----------- | ----------------- |
| ----------- | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
|
*
regCurrent | 参数指针 |
|
*
regCurrent | 参数指针 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
| 0 | 获取成功 |
| 0 | 获取成功 |
...
@@ -356,28 +333,26 @@ int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent);
...
@@ -356,28 +333,26 @@ int32_t RegulatorGetCurrent(DevHandle handle, uint32_t *regCurrent);
int32_t ret;
int32_t ret;
uint32_t regCurrent;
uint32_t regCurrent;
/*获取R
EGULATOR
电流*/
/*获取R
egulator
电流*/
ret = RegulatorGetCurrent(handle, ®Current);
ret = RegulatorGetCurrent(handle, ®Current);
if (ret != 0) {
if (ret != 0) {
/*错误处理*/
/*错误处理*/
}
}
```
```
#### 获取R
EGULATOR状态<a name="section3.11_REGULATOR_des"></a>
#### 获取R
egulator状态
获取R
EGULATOR
状态。
获取R
egulator
状态。
```
```
int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status);
int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status);
```
```
**表10**
RegulatorGetCurrent参数描述
**表11**
RegulatorGetStatus参数描述
<a
name=
"table10_REGULATOR_des"
></a>
| 参数 | 参数描述 |
| 参数 | 参数描述 |
| ---------- | ----------------- |
| ---------- | ----------------- |
| handle | R
EGULATOR
设备句柄 |
| handle | R
egulator
设备句柄 |
|
*
status | 参数指针 |
|
*
status | 参数指针 |
|
**返回值**
|
**返回值描述**
|
|
**返回值**
|
**返回值描述**
|
| 0 | 获取成功 |
| 0 | 获取成功 |
...
@@ -387,7 +362,7 @@ int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status);
...
@@ -387,7 +362,7 @@ int32_t RegulatorGetStatus(DevHandle handle, uint32_t *status);
int32_t ret;
int32_t ret;
uint32_t status;
uint32_t status;
/*获取R
EGULATOR
状态*/
/*获取R
egulator
状态*/
ret = RegulatorGetStatus(handle, &status);
ret = RegulatorGetStatus(handle, &status);
if (ret != 0) {
if (ret != 0) {
/*错误处理*/
/*错误处理*/
...
@@ -396,37 +371,37 @@ if (ret != 0) {
...
@@ -396,37 +371,37 @@ if (ret != 0) {
## 使用实例
<a name="section10"></a>
## 使用实例
R
EGULATOR设备完整的使用示例如下所示,首先获取REGULATOR设备句柄,然后使能,设置电压,获取电压、状态,禁用,最后销毁REGULATOR
设备句柄。
R
egulator设备完整的使用示例如下所示,首先获取Regulator设备句柄,然后使能,设置电压,获取电压、状态,禁用,最后销毁Regulator
设备句柄。
```
```
void RegulatorTestSample(void)
void RegulatorTestSample(void)
{
{
int32_t ret;
int32_t ret;
/* R
EGULATOR
设备名称 */
/* R
egulator
设备名称 */
const char *name = "regulator_virtual_1";
const char *name = "regulator_virtual_1";
DevHandle handle = NULL;
DevHandle handle = NULL;
/* 获取R
EGULATOR
设备句柄 */
/* 获取R
egulator
设备句柄 */
handle = RegulatorOpen(name);
handle = RegulatorOpen(name);
if (handle == NULL) {
if (handle == NULL) {
HDF_LOGE("RegulatorOpen: failed!\n");
HDF_LOGE("RegulatorOpen: failed!\n");
return;
return;
}
}
/*启用R
EGULATOR
设备*/
/*启用R
egulator
设备*/
ret = RegulatorEnable(handle);
ret = RegulatorEnable(handle);
if (ret != 0) {
if (ret != 0) {
HDF_LOGE("RegulatorEnable: failed, ret %d\n", ret);
HDF_LOGE("RegulatorEnable: failed, ret %d\n", ret);
goto _ERR;
goto _ERR;
}
}
int32_t minUv = 0; //最小电压为0
Uv
int32_t minUv = 0; //最小电压为0
µV
int32_t maxUv = 20000; //最大电压为20000
Uv
int32_t maxUv = 20000; //最大电压为20000
µV
/*设置R
EGULATOR
输出电压范围*/
/*设置R
egulator
输出电压范围*/
ret = RegulatorSetVoltage(handle, minUv, maxUv);
ret = RegulatorSetVoltage(handle, minUv, maxUv);
if (ret != 0) {
if (ret != 0) {
HDF_LOGE("RegulatorSetVoltage: failed, ret %d\n", ret);
HDF_LOGE("RegulatorSetVoltage: failed, ret %d\n", ret);
...
@@ -435,7 +410,7 @@ void RegulatorTestSample(void)
...
@@ -435,7 +410,7 @@ void RegulatorTestSample(void)
uint32_t voltage;
uint32_t voltage;
/*获取R
EGULATOR
电压*/
/*获取R
egulator
电压*/
ret = RegulatorGetVoltage(handle, &voltage);
ret = RegulatorGetVoltage(handle, &voltage);
if (ret != 0) {
if (ret != 0) {
HDF_LOGE("RegulatorGetVoltage: failed, ret %d\n", ret);
HDF_LOGE("RegulatorGetVoltage: failed, ret %d\n", ret);
...
@@ -444,14 +419,14 @@ void RegulatorTestSample(void)
...
@@ -444,14 +419,14 @@ void RegulatorTestSample(void)
uint32_t status;
uint32_t status;
/*获取R
EGULATOR
状态*/
/*获取R
egulator
状态*/
ret = RegulatorGetStatus(handle, &status);
ret = RegulatorGetStatus(handle, &status);
if (ret != 0) {
if (ret != 0) {
HDF_LOGE("RegulatorGetStatus: failed, ret %d\n", ret);
HDF_LOGE("RegulatorGetStatus: failed, ret %d\n", ret);
goto _ERR;
goto _ERR;
}
}
/*禁用R
EGULATOR
设备*/
/*禁用R
egulator
设备*/
ret = RegulatorDisable(handle);
ret = RegulatorDisable(handle);
if (ret != 0) {
if (ret != 0) {
HDF_LOGE("RegulatorDisable: failed, ret %d\n", ret);
HDF_LOGE("RegulatorDisable: failed, ret %d\n", ret);
...
@@ -459,7 +434,7 @@ void RegulatorTestSample(void)
...
@@ -459,7 +434,7 @@ void RegulatorTestSample(void)
}
}
_ERR:
_ERR:
/* 销毁R
EGULATOR
设备句柄 */
/* 销毁R
egulator
设备句柄 */
RegulatorClose(handle);
RegulatorClose(handle);
}
}
```
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录