MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dac_vol_sample

Function dac_vol_sample

bsp/hc32/tests/test_dac.c:31–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29#endif /* HC32F4A8 && BSP_USING_DAC2 */
30
31static int dac_vol_sample(int argc, char *argv[])
32{
33 char dac_device_name[] = "dac1";
34 rt_uint8_t channel = 1;
35 rt_uint8_t max_channel = 2;
36 rt_dac_device_t dac_dev;
37 rt_uint32_t value = 1365; /* 默认1.1V */
38 rt_uint32_t convertBits;
39 rt_uint32_t vol;
40 rt_err_t ret = RT_EOK;
41
42 /* 参数无输入或者输入错误按照默认值处理 */
43 if (argc >= 2)
44 {
45 if (0 == rt_strcmp(argv[1], "dac1"))
46 {
47 rt_strcpy(dac_device_name, "dac1");
48 max_channel = 2;
49 }
50#if defined (HC32F4A0) || defined (HC32F472) || defined (HC32F4A8) || defined (HC32F334)
51 else if (0 == rt_strcmp(argv[1], "dac2"))
52 {
53 rt_strcpy(dac_device_name, "dac2");
54#if defined (HC32F4A0) || defined (HC32F472) || defined (HC32F4A8)
55 max_channel = 2;
56#elif defined (HC32F334)
57 max_channel = 1;
58#endif
59 }
60#endif
61#if defined (HC32F472)
62 else if (0 == rt_strcmp(argv[1], "dac3"))
63 {
64 rt_strcpy(dac_device_name, "dac3");
65 max_channel = 2;
66 }
67 else if (0 == rt_strcmp(argv[1], "dac4"))
68 {
69 rt_strcpy(dac_device_name, "dac4");
70 max_channel = 2;
71 }
72#endif
73 else
74 {
75 rt_kprintf("The chip hasn't the dac unit!\r\n");
76 return -RT_ERROR;
77 }
78 }
79#if (defined (HC32F4A8) || defined (HC32F4A0)) && defined (BSP_USING_DAC2)
80 EthPhyDisable();
81#endif
82 /* 查找设备 */
83 dac_dev = (rt_dac_device_t)rt_device_find(dac_device_name);
84 if (dac_dev == RT_NULL)
85 {
86 rt_kprintf("dac sample run failed! can't find %s device!\n", dac_device_name);
87 return -RT_ERROR;
88 }

Callers

nothing calls this directly

Calls 8

rt_strcmpFunction · 0.85
rt_strcpyFunction · 0.85
rt_kprintfFunction · 0.85
rt_device_findFunction · 0.85
rt_device_controlFunction · 0.85
rt_dac_enableFunction · 0.85
rt_dac_writeFunction · 0.85
EthPhyDisableFunction · 0.50

Tested by

no test coverage detected