【GD32E503评测】+ littlegl移植到GD32E503V-EVAL
<p class="MsoTitle" style="text-align:center; text-indent:36pt; margin-top:16px; margin-bottom:4px"><span style="font-size:16pt"><span style="line-height:150%"><span style="font-family:Cambria,serif"><span style="font-weight:bold">LittlevGL<span style="font-family:宋体">移植到</span>GD32E503V</span></span></span></span></p><p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">前面已经成功的移植了tos到GD32E503V处理器上,基于tos,将LittlevGL移植到GD32E503V-eval开发板。</span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><b><span lang="EN-US" style="font-size:14.0pt"><span style="background:white"><span style="line-height:150%">LittlevGL</span></span></span></b><b><span style="font-size:14.0pt"><span style="background:white"><span style="line-height:150%">介绍</span></span></span></b></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">LittlevGL</span><span style="background:white">是一个免费的开放源代码图形库,它提供创建嵌入式GUI所需的一切,它具有易于使用的图形元素,精美的视觉效果和低内存占用。</span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体">特性:</span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="color:#333333">16, 32 or 64 bit microcontroller or processor</span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="color:#333333">16 MHz clock speed</span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="color:#333333">8 kB RAM for static data and >2 KB RAM for dynamic data (graphical objects)</span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="color:#333333">64 kB program memory (flash)</span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="color:#333333">支持GPU</span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><b><span style="font-size:14.0pt"><span style="background:white"><span style="line-height:150%">硬件连接关系</span></span></span></b></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> LittleGL</span><span style="background:white">系统需要LCD显示器和触摸屏输入两样主要的硬件设备。</span></span></span></span></p>
<p style="text-indent:0cm"></p>
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">图 LCD和触摸屏接口</span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">GD32E503V-EVAL</span><span style="background:white">开发板使用EXMC模块来控制LCD。通过GPIO模拟SPI接口连接触摸屏。</span></span></span></span></p>
<table align="center" class="MsoTableGrid" style="width:10.0cm; border-collapse:collapse; border:solid windowtext 1.0pt" width="378">
<tbody>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">LCD</span><span style="background:white">和触摸屏接口</span></span></span></span></p>
</td>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">GD32E503V </span><span style="background:white">端口</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">D0</span><span style="background:white">~D15</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">EXMC_D0</span><span style="background:white">~EXMC_D15</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">LCD_CS</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">PD7</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">LCD_RS</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">EXMC_A23</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">LCD_WR</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">PD5</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">LCD_RD</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">PD4</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">LCD_RST</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">NRST</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">TP_MISO</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">PA6</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">TP_MOSI</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">PA7</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">TP_SCK</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">PA5</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">TP_INT</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">PE5</span></span></span></span></p>
</td>
</tr>
<tr>
<td style="border:solid windowtext 1.0pt; width:213.05pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">TP_CS</span></span></span></span></p>
</td>
<td style="border-bottom:solid windowtext 1.0pt; width:213.05pt; border-top:none; border-left:none; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt" width="284">
<p align="center" style="text-align:center; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">PE6</span></span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p style="text-indent:36pt"> </p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><b><span style="font-size:14.0pt"><span style="background:white"><span style="line-height:150%">驱动代码</span></span></span></b></span></span></span></p>
<ol>
<li><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">LCD</span><span style="background:white">驱动</span></span></span></span></li>
</ol>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">我们在官方的驱动中已经包含了LCD的驱动代码,这里不详细解释。</span></span></span></span></p>
<ol start="2">
<li><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">触摸屏驱动</span></span></span></span></li>
</ol>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">官方驱动中包含了触摸屏驱动代码,直接使用就可以,不详细解释。</span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><b><span lang="EN-US" style="font-size:14.0pt"><span style="background:white"><span style="line-height:150%">LittleGL</span></span></span></b><b><span style="font-size:14.0pt"><span style="background:white"><span style="line-height:150%">移植</span></span></span></b></span></span></span></p>
<ol>
<li><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">目录结构</span></span></span></span></li>
</ol>
<p style="text-indent:36pt"></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">还包括一个example目录,我们在测试的时候会选择其中的一个加入工程中。</span></span></span></span></p>
<ol start="2">
<li><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">输入设备的移植</span></span></span></span></li>
</ol>
<p style="text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">输入设备在lvgl/port/lv_port_indev.c中,包括触摸屏,鼠标,键盘,编码器,和按键输入五中输入手段。</span></span></span></span></p>
<p style="text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">本次仅移植触摸屏输入方式,在void lv_port_indev_init(void)函数中,除触摸屏输入的初始化外,其它输入方式暂时隐藏起来。</span></span></span></span></p>
<p style="text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">触摸屏需要完成如下几个函数的移植:</span></span></span></span></p>
<ol start="12" style="list-style-type:lower-alpha">
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">static void touchpad_init(void)</span><span style="background:white">函数的移植,这个函数用来完成触摸屏的初始化工作,可以将官方提供的触摸屏初始化函数在此处调用。</span></span></span></span></li>
</ol>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">touch_panel_gpio_configure();</span></span></span></span></p>
<ol start="12" style="list-style-type:lower-alpha">
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">static bool touchpad_is_pressed(void)</span><span style="background:white">函数的移植,这个函数用来完成触摸屏被点击后的检测通知函数,将触摸屏的中断输入引脚PE5的状态检测放到这里。</span></span></span></span></li>
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)</span><span style="background:white">函数的移植,这个函数用来读取点击的触摸屏的位置信息。</span></span></span></span></li>
</ol>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="background:white">static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y)</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="background:white">{</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> /*Your code comes here*/</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="background:white">uint16_t touch_ad_x,touch_ad_y;</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="background:white">touch_ad_xy_get(&touch_ad_x, &touch_ad_y);</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> (*x) = touch_coordinate_x_get(touch_ad_x);</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> (*y) = LCD_Y - touch_coordinate_y_get(touch_ad_y);</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="background:white">}</span></span></span></span></p>
<ol start="3">
<li><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">显示设备的移植</span></span></span></span></li>
</ol>
<p style="text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">显示设备在lvgl/port/lv_port_disp.c中,包括显示设备初始化,和显示内容刷新及显示缓存的定义。</span></span></span></span></p>
<p style="text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">在void lv_port_disp_init(void)中,重点需要移植的内容:</span></span></span></span></p>
<ol start="12" style="list-style-type:lower-alpha">
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">显示设备的初始化</span></span></span></span></li>
</ol>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">static void disp_init(void)</span><span style="background:white">函数,将官方驱动中,显示设备的初始化函数放在这个函数中,完成显示设备初始化。</span></span></span></span></p>
<ol start="12" style="list-style-type:lower-alpha">
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">显示缓存设置</span></span></span></span></li>
</ol>
<p style="margin-left:48px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">这个是显存初始化中的一段说明,如下说明了显存包含3种类型的缓存,第一种为分配若干行的显示内容大小的内存作为显存,这是最小的显存分配方式,对于嵌入式系统中使用最广范的一种,通常分配为20行的内存空间;</span></span></span></span></p>
<p style="margin-left:48px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">第二种为分配两个大小相同的显示缓冲区,每个显示缓冲区为若干行显示内容对应的内存。这种方式通常采用DMA的方式刷新显示混存。</span></span></span></span></p>
<p style="margin-left:48px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">第三种为分配两个大小相同的显示缓冲区,每个显示缓冲区的大小为整个屏幕对应的显示内容对应的内存大小,这种方式对于屏幕的刷新速度是最快的,但是占用的内存也是最多的。</span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">/* LittlevGL requires a buffer where it draws the objects. The buffer's has to be greater than 1 display row</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> *</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * There are three buffering configurations:</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * 1. Create ONE buffer with some rows: </span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * LittlevGL will draw the display's content here and writes it to your display</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * </span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * 2. Create TWO buffer with some rows: </span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * LittlevGL will draw the display's content to a buffer and writes it your display.</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * You should use DMA to write the buffer's content to the display.</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * It will enable LittlevGL to draw the next part of the screen to the other buffer while</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * the data is being sent form the first buffer. It makes rendering and flushing parallel.</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * </span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * 3. Create TWO screen-sized buffer: </span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * Similar to 2) but the buffer have to be screen sized. When LittlevGL is ready it will give the</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * whole frame to display. This way you only need to change the frame buffer's address instead of</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * copying the pixels.</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * */</span></span></span></span></span></p>
<p style="text-indent:0cm"> </p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> /* Example for 1) */</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> static lv_disp_buf_t disp_buf_1;</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> static lv_color_t buf1_1; /*A buffer for 20 rows*/</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> lv_disp_buf_init(&disp_buf_1, buf1_1, NULL, LV_HOR_RES_MAX * 20); /*Initialize the display buffer*/</span></span></span></span></span></p>
<p style="text-indent:0cm"> </p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> /* Example for 2) */</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">// static lv_disp_buf_t disp_buf_2;</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">// static lv_color_t buf2_1; /*A buffer for 10 rows*/</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">// static lv_color_t buf2_2; /*An other buffer for 10 rows*/</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">// lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 40); /*Initialize the display buffer*/</span></span></span></span></span></p>
<p style="text-indent:0cm"> </p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> /* Example for 3) */</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">// static lv_disp_buf_t disp_buf_3;</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">// static lv_color_t buf3_1; /*A screen sized buffer*/</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">// static lv_color_t buf3_2; /*An other screen sized buffer*/</span></span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">// lv_disp_buf_init(&disp_buf_3, buf3_1, buf3_2, LV_HOR_RES_MAX * LV_VER_RES_MAX); /*Initialize the display buffer*/</span></span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">对于本次的显示缓存,采用第一种分配方式,20行的显示内容对应的内存大小。</span></span></span></span></p>
<ol start="12" style="list-style-type:lower-alpha">
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">屏幕尺寸大小定义</span></span></span></span></li>
</ol>
<p style="margin-left:24px; text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">这个地方重新定义了屏幕的尺寸,GD32E503V-eval的评估板对应的显示器为320x240,因此填充为如下。</span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> /*Set the resolution of the display*/</span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> disp_drv.hor_res = 240;</span></span></span></span></p>
<p style="text-indent:36pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> disp_drv.ver_res = 320;</span></span></span></span></p>
<ol start="12" style="list-style-type:lower-alpha">
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">显示刷新函数的移植</span></span></span></span></li>
</ol>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)</span><span style="background:white">的移植是最重要的物理设备接口函数,完成从显示缓存到LCD显示内容刷新的接口函数,利用官方提供的驱动接口,填充为:</span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">{</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"> </p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> int32_t x;</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> int32_t y;</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> for(y = area->y1; y <= area->y2; y++) {</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> for(x = area->x1; x <= area->x2; x++) {</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> /* Put a pixel to the display. For example: */</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> /* put_px(x, y, *color_p)*/</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> lcd_point_set(x, y,color_p->full);</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> color_p++;</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> }</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> }</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"> </p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> /* IMPORTANT!!!</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> * Inform the graphics library that you are ready with the flushing*/</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white"> lv_disp_flush_ready(disp_drv);</span></span></span></span></span></p>
<p style="margin-left:24px; text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:normal"><span style="font-family:宋体"><span lang="EN-US" style="font-size:10.5pt"><span style="background:white">}</span></span></span></span></span></p>
<ol start="4">
<li><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">运行的其它移植</span></span></span></span></li>
</ol>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">为了保证LittleGL的正确运行,还需要添加如下几个部分的添加。</span></span></span></span></p>
<ol start="12" style="list-style-type:lower-alpha">
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">1ms</span><span style="background:white">定时器的添加</span></span></span></span></li>
</ol>
<p style="text-indent:18.0pt"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">在系统的1ms定时器,必须添加</span>lv_tick_inc(1);的调用,用于gui的内容定时。</span></span></span></p>
<ol start="12" style="list-style-type:lower-alpha">
<li value="50"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">运行任务的添加</span></span></span></span></li>
</ol>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">为了让gui显示允许,需要创建一个任务来定时的刷新gui的函数。</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">基于tos的gui运行任务,通常要求任务堆栈不小于4K,优先级应略高。</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">#define LVGL_TASK_STK_SIZE 4096</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">extern void lvgl_task_entry(void *arg);</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">osThreadDef(lvgl_task_entry, osPriorityNormal, 1, LVGL_TASK_STK_SIZE);</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">在任务中应定时调用gui的处理函数。</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">void lvgl_task_entry(void *arg)</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">{</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">lv_init();</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> lv_port_disp_init();</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> lv_port_indev_init();</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">demo_create();</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> while (1) {</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> lv_task_handler();</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> tos_task_delay(30);</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white"> }</span></span></span></span></p>
<p style="margin-left:24px; text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span lang="EN-US" style="background:white">}</span></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"> <span style="background:white">到此LittleGL的gui移植已经基本完成。</span></span></span></span></p>
<p style="text-indent:0cm"> </p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><b><span lang="EN-US" style="font-size:14.0pt"><span style="background:white"><span style="line-height:150%">LittleGL demon</span></span></span></b><b><span style="font-size:14.0pt"><span style="background:white"><span style="line-height:150%">测试展示</span></span></span></b></span></span></span></p>
<p style="text-indent:0cm"><span style="font-size:12pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="background:white">我们在前面移植的基础上,添加example中的demo来展示一下实际的显示效果。 </span></span></span></span></p>
<p style="text-indent:0cm"> </p>
<p style="text-indent:36pt"></p>
<p style="text-indent:36pt"> </p>
<p style="text-indent:36pt"> </p>
<p style="text-indent:36pt"> </p>
页:
[1]