gs001588 发表于 2022-6-20 23:39

【平头哥RVB2601开发板试用体验】一、多任务点灯RGB

本帖最后由 gs001588 于 2022-6-20 23:42 编辑

<p style="text-align: center;"><span style="font-size:16px;"><span style="font-family:宋体;">一、多任务点灯RGB</span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; <strong>hello world!hello led!</strong></span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 对于开发板,点灯似乎再平常不过了;对于学习操作系统来说,点灯也是必不可少。那么就LED闪起来吧!</span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 1、首先,看看RGB灯原理,及与CH2601的管脚连接关系。RGB一体灯采用共阳极性,低电平点亮,高电平或悬空熄灭。</span></span></p>

<p><br />
<span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; </span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 需要跳线帽将J3的3、4脚、5、6脚、7、8脚短接。</span></span><br />
<span style="font-size:16px;"><span style="font-family:宋体;"></span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 2、下载原始RGB灯测试程序&ldquo;ch2601_rgb_marquee_demo&rdquo;,保证库齐全,编译无错,程序可运行。在此模板基础上改为多任务,一个任务负责点一个颜色的灯。</span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 将&ldquo;app_config.h&rdquo;中配置RGB灯械的两个宏定义全部注释掉,不需要了。</span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 修改&ldquo;demo_task()&rdquo;函数如下图。注释掉&ldquo;led_pinmux_init()&rdquo;、&ldquo;led_refresh()&rdquo;,修改&ldquo;udelay(1000 * 1000)&rdquo;,用&ldquo;<span style="color:#ff0000;">aos_msleep(1)</span>&rdquo;替换。之后如果要用lvgl驱动oled显示的话,&ldquo;lv_tick_inc(1)&rdquo;非常重要,需要保留。</span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;"></span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 定义csi_gpio_pin_t r。在led_r_task()任务中依次,&ldquo;csi_pin_set_mux(PA7, PIN_FUNC_GPIO)&rdquo;复用PA7为GPIO功能;&ldquo;csi_gpio_pin_init(&amp;r, PA7)&rdquo;初始化关联r到PA7;&ldquo;csi_gpio_pin_dir&rdquo;设置r管脚为输出方向;&ldquo;csi_gpio_pin_write&rdquo;设置r管脚初始态为高(即led灭)。第一个aos_msleep(100),初始等待100ms;第二个aos_msleep(000),零延时,立即进入while循环;在while中实现,r灯亮0.5s,灭0.5s,等待其它任务2s。</span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;"></span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 同理,开启任务&ldquo;led_g_task() &rdquo;、&ldquo;led_b_task()&rdquo;。与前面的&ldquo;led_r_task()&rdquo;不同之处在于第二个aos_msleep延时分别设置为1s、2s。相信大家应该知道要做什么了,&mdash;&mdash;没错,就是在3秒之内,</span></span>R、G、B<span style="font-size:16px;"><span style="font-family:宋体;">三个灯依次闪亮一次,循环下去。</span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;"></span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;"></span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 声明任务函数,在主函数中添加3个任务,任务简单,栈不需要太大,开1024足够用了。</span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;"></span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 至此,程序代码全部修改完毕,编译下载到板卡,运行看效果。</span></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 3、3任务控制分别R、G、B三个灯依次闪亮。程序运行效果见视频</span></span></p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp;&nbsp;</span></span>4833dff7d1e45526e236fd383097bdf1</p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><span style="font-family:宋体;">&nbsp; &nbsp; 4、源代码附上:</span></span></p>

<p><span style="font-family:宋体;">&nbsp; &nbsp; </span><br />
<br />
&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

soso 发表于 2022-6-21 09:54

<p>期待后续哈</p>
页: [1]
查看完整版本: 【平头哥RVB2601开发板试用体验】一、多任务点灯RGB