RVB2601评估板试用 2 PWM的使用,既三色小灯驱动
本帖最后由 我爱下载 于 2021-7-27 15:25 编辑<p style="text-align: center;"><span style="font-size:20px;"><span lang="EN-US"><span style="150%"><span style="font-family:宋体">PWM</span></span></span><span style="150%"><span style="font-family:宋体">信号的使用,既三色LED驱动显示</span></span></span></p>
<p><strong><span style="font-size:20px;"> 1 概述</span></strong></p>
<p><span lang="EN-US" style="font-size:12.0pt"><span style="150%"><span style="font-family:宋体"> <span style="font-size:16px;">RVB2601</span></span></span></span><span style="font-size:16px;"><span style="150%"><span style="font-family:宋体">评估板包含RGB三基色LED一个,为了学习PWM信号的驱动,我们可以通过驱动三基色LED来完成。</span></span></span></p>
<p><strong><span style="font-size:20px;"> 2 硬件接口描述</span></strong></p>
<p> <span style="font-size:16px;"> </span></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p class="imagemiddle" style="text-align: center;"></p>
<p><span style="font-size:16px;">通过如上两个原理图对照可知。</span></p>
<table class="a5">
<tbody>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">序号</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">LED名称</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">GPIO(PWM)</span></p>
</td>
</tr>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">1</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">LED_BLUE</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">PA7(CH7)</span></p>
</td>
</tr>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">2</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">LED_GREEN</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">PA25(CH2)</span></p>
</td>
</tr>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">3</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">LED_RED</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">PA4(CH4)</span></p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p><strong><span style="font-size:20px;">3 软件驱动设计</span></strong> <span style="font-size:16px;"> </span></p>
<p> <span style="font-size:16px;"> 3.1 PWM的CSI接口</span></p>
<p style="text-align: left; margin-bottom: 10.2pt;"><span style="font-family: 'Helvetica'; font-size: 13.5pt; color: #333333;"> <span style="font-size:16px;">驱动采用</span></span><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">CSI接口实现。实际使用到</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">CSI接口如下所示:</span></span></p>
<table style="table-layout: auto;">
<tbody>
<tr>
<th>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">函数</span></p>
</th>
<th>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">说明</span></p>
</th>
</tr>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">csi_pwm_init</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">初始化</span></p>
</td>
</tr>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">csi_pwm_uninit</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">反初始化</span></p>
</td>
</tr>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">csi_pwm_out_config</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">配置输出模式</span></p>
</td>
</tr>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">csi_pwm_out_start</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">开始输出</span></p>
</td>
</tr>
<tr>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">csi_pwm_out_stop</span></p>
</td>
<td>
<p style="text-align: center; margin-top: 0; margin-bottom: 0;"><span style="font-size:16px;">停止输出</span></p>
</td>
</tr>
</tbody>
</table>
<p style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);"> PWM</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">接口详细说明</span></span></p>
<ul>
<li style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_init</span></span></li>
</ul>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;"> csi_error_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">csi_pwm_</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">init</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">(</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">csi_pwm_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> *</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">pwm</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">, </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">uint32_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">idx</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">)</span></p>
<p style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_t</span></span></p>
<table style="table-layout: auto;">
<tbody>
<tr>
<th>
<p style="text-align: center; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51); font-weight: bold;">成员</span></span></p>
</th>
<th>
<p style="text-align: center; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51); font-weight: bold;">类型</span></span></p>
</th>
<th>
<p style="text-align: center; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51); font-weight: bold;">说明</span></span></p>
</th>
</tr>
<tr>
<td>
<p style="text-align: left; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">dev</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_dev_t</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">设备统一句柄</span></span></p>
</td>
</tr>
<tr>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">callback</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">void (</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">callback)(</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_t</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);"> </span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">pwm</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">, </span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_event_t</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);"> event, uint32_t </span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">ch</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">, uint32_t </span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">time_us</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">, void *</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">arg</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">)</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">用户回</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">调函数</span></span></p>
</td>
</tr>
<tr>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">arg</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">void *</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">回</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">调函数</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">参数(用户自定义)</span></span></p>
</td>
</tr>
<tr>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">priv</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">void *</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">设备私有变量</span></span></p>
</td>
</tr>
</tbody>
</table>
<ul>
<li style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_uninit</span></span></li>
</ul>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;"> void</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #4271AE;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8E908C;">csi_pwm_</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8E908C;">uninit</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;">(</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;">csi_pwm_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;"> *</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;">pwm</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;">)</span></p>
<ul>
<li style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_out_config</span></span></li>
</ul>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;"> csi_error_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">csi_pwm_out_</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">config</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">(</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">csi_pwm_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> *</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">pwm, </span></p>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">uint32_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> channel, </span></p>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">uint32_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">period_us, </span></p>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">uint32_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">pulse_width_us,</span></p>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">csi_pwm_polarity_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> polarity)</span></p>
<p style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_polarity_t</span></span></p>
<table style="table-layout: auto;">
<tbody>
<tr>
<th>
<p style="text-align: center; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51); font-weight: bold;">类型</span></span></p>
</th>
<th>
<p style="text-align: center; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51); font-weight: bold;">说明</span></span></p>
</th>
</tr>
<tr>
<td>
<p style="text-align: left; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">PWM_POLARITY_HIGH</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">高电平</span></span></p>
</td>
</tr>
<tr>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">PWM_POLARITY_LOW</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">低电平</span></span></p>
</td>
</tr>
</tbody>
</table>
<ul>
<li style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_out_start</span></span></li>
</ul>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;"> csi_error_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">csi_pwm_out_</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">start</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">(</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">csi_pwm_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> *</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">pwm</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">, </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">uint32_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> channel)</span></p>
<ul>
<li style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pwm_out_stop</span></span></li>
</ul>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;"> void</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #4271AE;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8E908C;">csi_pwm_out_</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8E908C;">stop</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;">(</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;">csi_pwm_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;"> *</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;">pwm</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #F5871F;">, uint32_t channel)</span></p>
<p style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"> 3.2 PIN的CSI接口</span></p>
<p style="margin-top: 15.3pt; margin-bottom: 10.2pt;"> <span style="font-size:16px;"> 测试中用到的<span style="font-family: Helvetica; color: rgb(51, 51, 51);">PIN</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">的</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">CSI</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">接口说明如下所示:</span></span></p>
<table style="table-layout: auto;">
<tbody>
<tr>
<th>
<p style="text-align: center; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51); font-weight: bold;">函数</span></span></p>
</th>
<th>
<p style="text-align: center; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51); font-weight: bold;">说明</span></span></p>
</th>
</tr>
<tr>
<td>
<p style="text-align: left; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pin_set_mux</span></span></p>
</td>
<td>
<p style="margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">设置</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">PIN</span><span style="font-family: Helvetica; color: rgb(51, 51, 51);">的复用功能</span></span></p>
</td>
</tr>
</tbody>
</table>
<p style="margin-top: 0pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">接口详细说明</span></span></p>
<ul>
<li style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size:16px;"><span style="font-family: Helvetica; color: rgb(51, 51, 51);">csi_pin_set_mux</span></span></li>
</ul>
<p><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;"> csi_error_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">csi_pin_set_</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">mux</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">(</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">pin_name_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">pin_name</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">, </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #8959A8;">pin_func_t</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;"> </span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">pin_func</span><span style="font-family: 'Consolas'; font-size: 11.5pt; color: #333333;">)</span></p>
<p style="margin-top: 15.3pt; margin-bottom: 10.2pt;"><span style="font-size: 20px;"><b>4 软件测试代码</b></span> </p>
<p style="margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size:16px;"><span style="font-family: Consolas;"> 通过</span><span style="font-family: Consolas;">PWM</span><span style="font-family: Consolas;">接口完成三色灯</span><span style="font-family: Consolas;">亮度渐变调节</span><span style="font-family: Consolas;">驱动的测试程序。</span></span></p>
<p><span style="font-size:16px;"> 4.1 初始化</span></p>
<pre>
<code class="language-cpp">void led_pinmux_init()
{
csi_error_t ret;
csi_pin_set_mux(PA7, PA7_PWM_CH7); //设置PIN的复用功能
csi_pin_set_mux(PA25, PA25_PWM_CH2); //设置PIN的复用功能
csi_pin_set_mux(PA4, PA4_PWM_CH4); //设置PIN的复用功能
ret = csi_pwm_init(&r, 0); //初始化pwm设备
if (ret != CSI_OK) {
printf("===%s, %d\n", __FUNCTION__, __LINE__);
return ;
}
//配置pwm通道的输出模式
ret = csi_pwm_out_config(&r, 7 / 2, 300, 100, PWM_POLARITY_HIGH);
if (ret != CSI_OK) {
printf("===%s, %d\n", __FUNCTION__, __LINE__);
return ;
}
//配置pwm通道的输出模式
ret = csi_pwm_out_config(&r, 2 / 2, 300, 100, PWM_POLARITY_HIGH);
if (ret != CSI_OK) {
printf("===%s, %d\n", __FUNCTION__, __LINE__);
return ;
}
//配置pwm通道的输出模式
ret = csi_pwm_out_config(&r, 4 / 2, 300, 100, PWM_POLARITY_HIGH);
if (ret != CSI_OK) {
printf("===%s, %d\n", __FUNCTION__, __LINE__);
return ;
}
}
</code></pre>
<p><span style="font-size:16px;"> 4.2 三色led亮度PWM控制</span></p>
<ul>
<li><span style="font-size:16px;">点亮led</span></li>
</ul>
<pre>
<code class="language-cpp">csi_pwm_out_stop(&r, 2 / 2);
csi_pwm_out_stop(&r, 7 / 2);
csi_pwm_out_stop(&r, 4 / 2);
</code></pre>
<ul>
<li><span style="font-size:16px;">熄灭led</span></li>
</ul>
<pre>
<code class="language-cpp">csi_pwm_out_start(&r, 7 / 2);
csi_pwm_out_start(&r, 2 / 2);
csi_pwm_out_start(&r, 4 / 2);</code></pre>
<ul>
<li><span style="font-size:16px;">亮度调节控制</span></li>
</ul>
<pre>
<code class="language-cpp">voidft_led_slow_change(void)
{
csi_error_t ret;
if (g_led_refresh) {
if (g_ctr == 0)
{
ret = csi_pwm_out_config(&r, 7 / 2, 300, led_pwm_count, PWM_POLARITY_HIGH);
if (ret != CSI_OK) {
printf("===%s, %d\n", __FUNCTION__, __LINE__);
return ;
}
if(led_change_flag == 0)
{
if(led_pwm_count == 0)
{
csi_pwm_out_start(&r, 7 / 2);
csi_pwm_out_stop(&r, 2 / 2);
csi_pwm_out_stop(&r, 4 / 2);
}
led_pwm_count += 10;
if(led_pwm_count >= 300)
{
led_change_flag = 1;
}
}
else
{
if(led_pwm_count > 10)
{
led_pwm_count -= 10;
}
else
{
led_pwm_count = 0;
led_change_flag = 0;
g_ctr++;
if (g_ctr == 3) {
g_ctr = 0;
}
}
}
}
else if (g_ctr == 1)
{
//25
ret = csi_pwm_out_config(&r, 2 / 2, 300, led_pwm_count, PWM_POLARITY_HIGH);
if (ret != CSI_OK) {
printf("===%s, %d\n", __FUNCTION__, __LINE__);
return ;
}
if(led_change_flag == 0)
{
if(led_pwm_count == 0)
{
csi_pwm_out_start(&r, 2 / 2);
csi_pwm_out_stop(&r, 7 / 2);
csi_pwm_out_stop(&r, 4 / 2);
}
led_pwm_count += 10;
if(led_pwm_count >= 300)
{
led_change_flag = 1;
}
}
else
{
if(led_pwm_count > 10)
{
led_pwm_count -= 10;
}
else
{
led_pwm_count = 0;
led_change_flag = 0;
g_ctr++;
if (g_ctr == 3) {
g_ctr = 0;
}
}
}
}
else //2
{
//4
ret = csi_pwm_out_config(&r, 4 / 2, 300, led_pwm_count, PWM_POLARITY_HIGH);
if (ret != CSI_OK) {
printf("===%s, %d\n", __FUNCTION__, __LINE__);
return ;
}
if(led_change_flag == 0)
{
if(led_pwm_count == 0)
{
csi_pwm_out_start(&r, 4 / 2);
csi_pwm_out_stop(&r, 7 / 2);
csi_pwm_out_stop(&r, 2 / 2);
}
led_pwm_count += 10;
if(led_pwm_count >= 300)
{
led_change_flag = 1;
}
}
else
{
if(led_pwm_count > 10)
{
led_pwm_count -= 10;
}
else
{
led_pwm_count = 0;
led_change_flag = 0;
g_ctr++;
if (g_ctr == 3) {
g_ctr = 0;
}
}
}
}
}
}
</code></pre>
<p> </p>
<p><span style="font-size: 20px;"><b>5 演示视频</b></span> </p>
<p></p>
<p> </p>
<p>期待后续</p>
<p>视频刷不出来</p>
freebsder 发表于 2021-7-27 23:15
视频刷不出来
<p>后面是个GIF的动画,我这里可以看到,是不是网络问题</p>
我爱下载 发表于 2021-7-28 07:59
后面是个GIF的动画,我这里可以看到,是不是网络问题
<p>公司网络可以,晚上回去再试试。</p>
<p>什么是反初始化呢</p>
梦溪开物 发表于 2022-3-21 21:47
什么是反初始化呢
<p>例如,你将一个GPIO初始化为OUT_PP的方式,如果你不是用了,那么GPIO应该重新被初始化为复位后的默认状态,或者你认为的默认状态,这就是反初始化了。</p>
页:
[1]