Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
175ca2ee
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
175ca2ee
编写于
4月 22, 2022
作者:
mysterywolf
提交者:
guo
4月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[dac] add get resolution method
上级
778be73c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
8 deletion
+29
-8
bsp/stm32/libraries/HAL_Drivers/drv_dac.c
bsp/stm32/libraries/HAL_Drivers/drv_dac.c
+13
-0
components/drivers/include/drivers/dac.h
components/drivers/include/drivers/dac.h
+2
-0
components/drivers/misc/adc.c
components/drivers/misc/adc.c
+1
-1
components/drivers/misc/dac.c
components/drivers/misc/dac.c
+13
-7
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_dac.c
浏览文件 @
175ca2ee
...
@@ -105,6 +105,18 @@ static rt_err_t stm32_dac_disabled(struct rt_dac_device *device, rt_uint32_t cha
...
@@ -105,6 +105,18 @@ static rt_err_t stm32_dac_disabled(struct rt_dac_device *device, rt_uint32_t cha
return
RT_EOK
;
return
RT_EOK
;
}
}
static
rt_uint8_t
stm32_dac_get_resolution
(
struct
rt_dac_device
*
device
)
{
DAC_HandleTypeDef
*
stm32_dac_handler
;
RT_ASSERT
(
device
!=
RT_NULL
);
stm32_dac_handler
=
device
->
parent
.
user_data
;
(
void
)
stm32_dac_handler
;
return
12
;
/* TODO */
}
static
rt_err_t
stm32_set_dac_value
(
struct
rt_dac_device
*
device
,
rt_uint32_t
channel
,
rt_uint32_t
*
value
)
static
rt_err_t
stm32_set_dac_value
(
struct
rt_dac_device
*
device
,
rt_uint32_t
channel
,
rt_uint32_t
*
value
)
{
{
uint32_t
dac_channel
;
uint32_t
dac_channel
;
...
@@ -162,6 +174,7 @@ static const struct rt_dac_ops stm_dac_ops =
...
@@ -162,6 +174,7 @@ static const struct rt_dac_ops stm_dac_ops =
.
disabled
=
stm32_dac_disabled
,
.
disabled
=
stm32_dac_disabled
,
.
enabled
=
stm32_dac_enabled
,
.
enabled
=
stm32_dac_enabled
,
.
convert
=
stm32_set_dac_value
,
.
convert
=
stm32_set_dac_value
,
.
get_resolution
=
stm32_dac_get_resolution
,
};
};
static
int
stm32_dac_init
(
void
)
static
int
stm32_dac_init
(
void
)
...
...
components/drivers/include/drivers/dac.h
浏览文件 @
175ca2ee
...
@@ -18,6 +18,7 @@ struct rt_dac_ops
...
@@ -18,6 +18,7 @@ struct rt_dac_ops
rt_err_t
(
*
disabled
)(
struct
rt_dac_device
*
device
,
rt_uint32_t
channel
);
rt_err_t
(
*
disabled
)(
struct
rt_dac_device
*
device
,
rt_uint32_t
channel
);
rt_err_t
(
*
enabled
)(
struct
rt_dac_device
*
device
,
rt_uint32_t
channel
);
rt_err_t
(
*
enabled
)(
struct
rt_dac_device
*
device
,
rt_uint32_t
channel
);
rt_err_t
(
*
convert
)(
struct
rt_dac_device
*
device
,
rt_uint32_t
channel
,
rt_uint32_t
*
value
);
rt_err_t
(
*
convert
)(
struct
rt_dac_device
*
device
,
rt_uint32_t
channel
,
rt_uint32_t
*
value
);
rt_uint8_t
(
*
get_resolution
)(
struct
rt_dac_device
*
device
);
};
};
struct
rt_dac_device
struct
rt_dac_device
...
@@ -31,6 +32,7 @@ typedef enum
...
@@ -31,6 +32,7 @@ typedef enum
{
{
RT_DAC_CMD_ENABLE
=
RT_DEVICE_CTRL_BASE
(
DAC
)
+
0
,
RT_DAC_CMD_ENABLE
=
RT_DEVICE_CTRL_BASE
(
DAC
)
+
0
,
RT_DAC_CMD_DISABLE
=
RT_DEVICE_CTRL_BASE
(
DAC
)
+
1
,
RT_DAC_CMD_DISABLE
=
RT_DEVICE_CTRL_BASE
(
DAC
)
+
1
,
RT_DAC_CMD_GET_RESOLUTION
=
RT_DEVICE_CTRL_BASE
(
DAC
)
+
2
,
}
rt_dac_cmd_t
;
}
rt_dac_cmd_t
;
rt_err_t
rt_hw_dac_register
(
rt_dac_device_t
dac
,
const
char
*
name
,
const
struct
rt_dac_ops
*
ops
,
const
void
*
user_data
);
rt_err_t
rt_hw_dac_register
(
rt_dac_device_t
dac
,
const
char
*
name
,
const
struct
rt_dac_ops
*
ops
,
const
void
*
user_data
);
...
...
components/drivers/misc/adc.c
浏览文件 @
175ca2ee
...
@@ -58,7 +58,7 @@ static rt_err_t _adc_control(rt_device_t dev, int cmd, void *args)
...
@@ -58,7 +58,7 @@ static rt_err_t _adc_control(rt_device_t dev, int cmd, void *args)
if
(
resolution
!=
0
)
if
(
resolution
!=
0
)
{
{
*
((
rt_uint8_t
*
)
args
)
=
resolution
;
*
((
rt_uint8_t
*
)
args
)
=
resolution
;
LOG_D
(
"
ADC resolution:%d
"
,
resolution
);
LOG_D
(
"
resolution: %d bits
"
,
resolution
);
result
=
RT_EOK
;
result
=
RT_EOK
;
}
}
}
}
...
...
components/drivers/misc/dac.c
浏览文件 @
175ca2ee
...
@@ -40,21 +40,27 @@ static rt_size_t _dac_write(rt_device_t dev, rt_off_t pos, const void *buffer, r
...
@@ -40,21 +40,27 @@ static rt_size_t _dac_write(rt_device_t dev, rt_off_t pos, const void *buffer, r
static
rt_err_t
_dac_control
(
rt_device_t
dev
,
int
cmd
,
void
*
args
)
static
rt_err_t
_dac_control
(
rt_device_t
dev
,
int
cmd
,
void
*
args
)
{
{
rt_err_t
result
=
RT_EOK
;
rt_err_t
result
=
-
RT_EINVAL
;
rt_dac_device_t
dac
=
(
struct
rt_dac_device
*
)
dev
;
rt_dac_device_t
dac
=
(
struct
rt_dac_device
*
)
dev
;
if
(
dac
->
ops
->
enabled
==
RT_NULL
)
if
(
cmd
==
RT_DAC_CMD_ENABLE
&&
dac
->
ops
->
enabled
)
{
return
-
RT_ENOSYS
;
}
if
(
cmd
==
RT_DAC_CMD_ENABLE
)
{
{
result
=
dac
->
ops
->
enabled
(
dac
,
(
rt_uint32_t
)
args
);
result
=
dac
->
ops
->
enabled
(
dac
,
(
rt_uint32_t
)
args
);
}
}
else
if
(
cmd
==
RT_DAC_CMD_DISABLE
)
else
if
(
cmd
==
RT_DAC_CMD_DISABLE
&&
dac
->
ops
->
enabled
)
{
{
result
=
dac
->
ops
->
disabled
(
dac
,
(
rt_uint32_t
)
args
);
result
=
dac
->
ops
->
disabled
(
dac
,
(
rt_uint32_t
)
args
);
}
}
else
if
(
cmd
==
RT_DAC_CMD_GET_RESOLUTION
&&
dac
->
ops
->
get_resolution
)
{
rt_uint8_t
resolution
=
dac
->
ops
->
get_resolution
(
dac
);
if
(
resolution
!=
0
)
{
*
((
rt_uint8_t
*
)
args
)
=
resolution
;
LOG_D
(
"resolution: %d bits"
,
resolution
);
result
=
RT_EOK
;
}
}
return
result
;
return
result
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录