Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
RT-Thread
rt-thread
提交
9684f34b
R
rt-thread
项目概览
RT-Thread
/
rt-thread
大约 1 年 前同步成功
通知
774
Star
8911
Fork
4735
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
9684f34b
编写于
11月 11, 2021
作者:
L
liukangcc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[update] add dma for lvgl.
上级
301856ac
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
143 addition
and
134 deletion
+143
-134
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/SConscript
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/SConscript
+3
-1
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/lv_conf.h
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/lv_conf.h
+5
-2
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/lv_port_disp.c
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/lv_port_disp.c
+135
-131
未找到文件。
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/SConscript
浏览文件 @
9684f34b
...
@@ -5,5 +5,7 @@ cwd = GetCurrentDir()
...
@@ -5,5 +5,7 @@ cwd = GetCurrentDir()
src
=
Glob
(
'*.c'
)
src
=
Glob
(
'*.c'
)
CPPPATH
=
[
cwd
]
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'LVGL-port'
,
src
,
depend
=
[
'BSP_USING_LVGL'
],
CPPPATH
=
CPPPATH
)
CPPDEFINES
=
[
'STM32F4'
]
group
=
DefineGroup
(
'LVGL-port'
,
src
,
depend
=
[
'BSP_USING_LVGL'
],
CPPPATH
=
CPPPATH
,
CPPDEFINES
=
CPPDEFINES
)
Return
(
'group'
)
Return
(
'group'
)
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/lv_conf.h
浏览文件 @
9684f34b
...
@@ -14,4 +14,7 @@
...
@@ -14,4 +14,7 @@
#define LV_USE_PERF_MONITOR 1
#define LV_USE_PERF_MONITOR 1
#define LV_COLOR_DEPTH 32
#define LV_COLOR_DEPTH 32
#define LV_USE_GPU_STM32_DMA2D 1
#define LV_GPU_DMA2D_CMSIS_INCLUDE "stm32f469xx.h"
#endif
#endif
bsp/stm32/stm32f469-st-disco/board/ports/lvgl/lv_port_disp.c
浏览文件 @
9684f34b
...
@@ -10,6 +10,10 @@
...
@@ -10,6 +10,10 @@
#include <lvgl.h>
#include <lvgl.h>
#include <lcd_port.h>
#include <lcd_port.h>
//#define DRV_DEBUG
#define LOG_TAG "lvgl.disp"
#include <drv_log.h>
/*A static or global variable to store the buffers*/
/*A static or global variable to store the buffers*/
static
lv_disp_draw_buf_t
disp_buf
;
static
lv_disp_draw_buf_t
disp_buf
;
...
@@ -18,184 +22,184 @@ static struct rt_device_graphic_info info;
...
@@ -18,184 +22,184 @@ static struct rt_device_graphic_info info;
static
lv_disp_drv_t
disp_drv
;
/*Descriptor of a display driver*/
static
lv_disp_drv_t
disp_drv
;
/*Descriptor of a display driver*/
typedef
struct
static
DMA_HandleTypeDef
DmaHandle
;
#define DMA_STREAM DMA2_Stream0
#define DMA_CHANNEL DMA_CHANNEL_0
#define DMA_STREAM_IRQ DMA2_Stream0_IRQn
#define DMA_STREAM_IRQHANDLER DMA2_Stream0_IRQHandler
static
int32_t
x1_flush
;
static
int32_t
y1_flush
;
static
int32_t
x2_flush
;
static
int32_t
y2_fill
;
static
int32_t
y_fill_act
;
static
const
lv_color_t
*
buf_to_flush
;
/**
* @brief DMA conversion complete callback
* @note This function is executed when the transfer complete interrupt
* is generated
* @retval None
*/
static
void
DMA_TransferComplete
(
DMA_HandleTypeDef
*
han
)
{
{
uint8_t
blue
;
y_fill_act
++
;
uint8_t
green
;
uint8_t
red
;
}
lv_color24_t
;
static
void
color_to16_maybe
(
lv_color16_t
*
dst
,
lv_color_t
*
src
)
if
(
y_fill_act
>
y2_fill
)
{
{
#if (LV_COLOR_DEPTH == 16)
lv_disp_flush_ready
(
&
disp_drv
);
dst
->
full
=
src
->
full
;
}
#else
else
dst
->
ch
.
blue
=
src
->
ch
.
blue
;
{
dst
->
ch
.
green
=
src
->
ch
.
green
;
buf_to_flush
+=
(
x2_flush
-
x1_flush
+
1
);
dst
->
ch
.
red
=
src
->
ch
.
red
;
/*##-7- Start the DMA transfer using the interrupt mode ####################*/
#endif
/* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */
/* Enable All the DMA interrupts */
if
(
HAL_DMA_Start_IT
(
han
,(
uint32_t
)
buf_to_flush
,
(
uint32_t
)
&
((
uint32_t
*
)
info
.
framebuffer
)[
y_fill_act
*
info
.
width
+
x1_flush
],
(
x2_flush
-
x1_flush
+
1
))
!=
HAL_OK
)
{
LOG_E
(
"HAL_DMA_Start_IT error"
);
while
(
1
);
/*Halt on error*/
}
}
}
}
static
void
color_to24
(
lv_color24_t
*
dst
,
lv_color_t
*
src
)
/**
* @brief DMA conversion error callback
* @note This function is executed when the transfer error interrupt
* is generated during DMA transfer
* @retval None
*/
static
void
DMA_TransferError
(
DMA_HandleTypeDef
*
han
)
{
{
dst
->
blue
=
src
->
ch
.
blue
;
LOG_E
(
"dma transfer error"
);
dst
->
green
=
src
->
ch
.
green
;
while
(
1
);
dst
->
red
=
src
->
ch
.
red
;
}
}
/*Flush the content of the internal buffer the specific area on the display
/**
*You can use DMA or any hardware acceleration to do this operation in the background but
* @brief This function handles DMA Stream interrupt request.
*'lv_disp_flush_ready()' has to be called when finished.*/
* @param None
static
void
lcd_fb_flush
(
lv_disp_drv_t
*
disp_drv
,
const
lv_area_t
*
area
,
lv_color_t
*
color_p
)
* @retval None
*/
void
DMA_STREAM_IRQHANDLER
(
void
)
{
{
int
x1
,
x2
,
y1
,
y2
;
rt_interrupt_enter
();
HAL_DMA_IRQHandler
(
&
DmaHandle
);
x1
=
area
->
x1
;
rt_interrupt_leave
();
x2
=
area
->
x2
;
}
y1
=
area
->
y1
;
y2
=
area
->
y2
;
/*Return if the area is out the screen*/
static
void
DMA_Config
(
void
)
if
(
x2
<
0
)
{
return
;
/*## -1- Enable DMA2 clock #################################################*/
if
(
y2
<
0
)
__HAL_RCC_DMA2_CLK_ENABLE
();
return
;
if
(
x1
>
info
.
width
-
1
)
return
;
if
(
y1
>
info
.
height
-
1
)
return
;
/*Truncate the area to the screen*/
/*##-2- Select the DMA functional Parameters ###############################*/
int32_t
act_x1
=
x1
<
0
?
0
:
x1
;
DmaHandle
.
Init
.
Channel
=
DMA_CHANNEL
;
/* DMA_CHANNEL_0 */
int32_t
act_y1
=
y1
<
0
?
0
:
y1
;
DmaHandle
.
Init
.
Direction
=
DMA_MEMORY_TO_MEMORY
;
/* M2M transfer mode */
int32_t
act_x2
=
x2
>
info
.
width
-
1
?
info
.
width
-
1
:
x2
;
DmaHandle
.
Init
.
PeriphInc
=
DMA_PINC_ENABLE
;
/* Peripheral increment mode Enable */
int32_t
act_y2
=
y2
>
info
.
height
-
1
?
info
.
height
-
1
:
y2
;
DmaHandle
.
Init
.
MemInc
=
DMA_MINC_ENABLE
;
/* Memory increment mode Enable */
DmaHandle
.
Init
.
PeriphDataAlignment
=
DMA_PDATAALIGN_WORD
;
/* Peripheral data alignment : 32bit */
DmaHandle
.
Init
.
MemDataAlignment
=
DMA_PDATAALIGN_WORD
;
/* memory data alignment : 32bit */
DmaHandle
.
Init
.
Mode
=
DMA_NORMAL
;
/* Normal DMA mode */
DmaHandle
.
Init
.
Priority
=
DMA_PRIORITY_HIGH
;
/* priority level : high */
DmaHandle
.
Init
.
FIFOMode
=
DMA_FIFOMODE_ENABLE
;
/* FIFO mode enabled */
DmaHandle
.
Init
.
FIFOThreshold
=
DMA_FIFO_THRESHOLD_1QUARTERFULL
;
/* FIFO threshold: 1/4 full */
DmaHandle
.
Init
.
MemBurst
=
DMA_MBURST_SINGLE
;
/* Memory burst */
DmaHandle
.
Init
.
PeriphBurst
=
DMA_PBURST_SINGLE
;
/* Peripheral burst */
uint32_t
x
;
DmaHandle
.
Instance
=
DMA_STREAM
;
uint32_t
y
;
long
int
location
=
0
;
/* 8 bit per pixel */
if
(
HAL_DMA_Init
(
&
DmaHandle
)
!=
HAL_OK
)
if
(
info
.
bits_per_pixel
==
8
)
{
uint8_t
*
fbp8
=
(
uint8_t
*
)
info
.
framebuffer
;
//TODO color convert maybe
for
(
y
=
act_y1
;
y
<=
act_y2
;
y
++
)
{
{
for
(
x
=
act_x1
;
x
<=
act_x2
;
x
++
)
while
(
1
);
{
location
=
(
x
)
+
(
y
)
*
info
.
width
;
fbp8
[
location
]
=
color_p
->
full
;
color_p
++
;
}
color_p
+=
x2
-
act_x2
;
}
}
}
/* 16 bit per pixel */
HAL_DMA_RegisterCallback
(
&
DmaHandle
,
HAL_DMA_XFER_CPLT_CB_ID
,
DMA_TransferComplete
);
else
if
(
info
.
bits_per_pixel
==
16
)
HAL_DMA_RegisterCallback
(
&
DmaHandle
,
HAL_DMA_XFER_ERROR_CB_ID
,
DMA_TransferError
);
{
lv_color16_t
*
fbp16
=
(
lv_color16_t
*
)
info
.
framebuffer
;
for
(
y
=
act_y1
;
y
<=
act_y2
;
y
++
)
{
for
(
x
=
act_x1
;
x
<=
act_x2
;
x
++
)
{
location
=
(
x
)
+
(
y
)
*
info
.
width
;
color_to16_maybe
(
&
fbp16
[
location
],
color_p
);
color_p
++
;
}
color_p
+=
x2
-
act_x2
;
HAL_NVIC_SetPriority
(
DMA_STREAM_IRQ
,
0
,
0
)
;
}
HAL_NVIC_EnableIRQ
(
DMA_STREAM_IRQ
);
}
}
/* 24 bit per pixel */
static
void
lcd_fb_flush
(
lv_disp_drv_t
*
disp_drv
,
const
lv_area_t
*
area
,
lv_color_t
*
color_p
)
else
if
(
info
.
bits_per_pixel
==
24
)
{
{
/*Return if the area is out the screen*/
lv_color24_t
*
fbp24
=
(
lv_color24_t
*
)
info
.
framebuffer
;
if
(
area
->
x2
<
0
)
return
;
if
(
area
->
y2
<
0
)
return
;
if
(
area
->
x1
>
info
.
width
-
1
)
return
;
if
(
area
->
y1
>
info
.
height
-
1
)
return
;
for
(
y
=
act_y1
;
y
<=
act_y2
;
y
++
)
/*Truncate the area to the screen*/
{
int32_t
act_x1
=
area
->
x1
<
0
?
0
:
area
->
x1
;
for
(
x
=
act_x1
;
x
<=
act_x2
;
x
++
)
int32_t
act_y1
=
area
->
y1
<
0
?
0
:
area
->
y1
;
{
int32_t
act_x2
=
area
->
x2
>
info
.
width
-
1
?
info
.
width
-
1
:
area
->
x2
;
location
=
(
x
)
+
(
y
)
*
info
.
width
;
int32_t
act_y2
=
area
->
y2
>
info
.
height
-
1
?
info
.
height
-
1
:
area
->
y2
;
color_to24
(
&
fbp24
[
location
],
color_p
);
color_p
++
;
}
color_p
+=
x2
-
act_x2
;
x1_flush
=
act_x1
;
}
y1_flush
=
act_y1
;
}
x2_flush
=
act_x2
;
y2_fill
=
act_y2
;
y_fill_act
=
act_y1
;
buf_to_flush
=
color_p
;
/* 32 bit per pixel */
if
(
HAL_DMA_Start_IT
(
&
DmaHandle
,(
uint32_t
)
buf_to_flush
,
else
if
(
info
.
bits_per_pixel
==
32
)
(
uint32_t
)
&
((
uint32_t
*
)
info
.
framebuffer
)[
y_fill_act
*
info
.
width
+
x1_flush
],
(
x2_flush
-
x1_flush
+
1
))
!=
HAL_OK
)
{
{
uint32_t
*
fbp32
=
(
uint32_t
*
)
info
.
framebuffer
;
LOG_E
(
"dma start it error"
);
//TODO
while
(
1
);
for
(
y
=
act_y1
;
y
<=
act_y2
;
y
++
)
{
for
(
x
=
act_x1
;
x
<=
act_x2
;
x
++
)
{
location
=
(
x
)
+
(
y
)
*
info
.
width
;
fbp32
[
location
]
=
color_p
->
full
;
color_p
++
;
}
color_p
+=
x2
-
act_x2
;
}
}
}
struct
rt_device_rect_info
rect_info
;
rect_info
.
x
=
x1
;
rect_info
.
y
=
y1
;
rect_info
.
width
=
x2
-
x1
+
1
;
rect_info
.
height
=
y2
-
y1
+
1
;
rt_device_control
(
lcd_device
,
RTGRAPHIC_CTRL_RECT_UPDATE
,
&
rect_info
);
lv_disp_flush_ready
(
disp_drv
);
}
}
void
lv_port_disp_init
(
void
)
void
lv_port_disp_init
(
void
)
{
{
rt_err_t
result
;
rt_err_t
result
;
lv_color_t
*
fbuf
;
void
*
buf_1
=
RT_NULL
;
void
*
buf_2
=
RT_NULL
;
lcd_device
=
rt_device_find
(
"lcd"
);
lcd_device
=
rt_device_find
(
"lcd"
);
if
(
lcd_device
==
0
)
if
(
lcd_device
==
0
)
{
{
rt_kprintf
(
"error!
\n
"
);
LOG_E
(
"error!
"
);
return
;
return
;
}
}
result
=
rt_device_open
(
lcd_device
,
0
);
result
=
rt_device_open
(
lcd_device
,
0
);
if
(
result
!=
RT_EOK
)
if
(
result
!=
RT_EOK
)
{
{
rt_kprintf
(
"error!
\n
"
);
LOG_E
(
"error!
"
);
return
;
return
;
}
}
/* get framebuffer address */
/* get framebuffer address */
result
=
rt_device_control
(
lcd_device
,
RTGRAPHIC_CTRL_GET_INFO
,
&
info
);
result
=
rt_device_control
(
lcd_device
,
RTGRAPHIC_CTRL_GET_INFO
,
&
info
);
if
(
result
!=
RT_EOK
)
if
(
result
!=
RT_EOK
)
{
{
rt_kprintf
(
"error!
\n
"
);
LOG_E
(
"error!
"
);
/* get device information failed */
/* get device information failed */
return
;
return
;
}
}
RT_ASSERT
(
info
.
bits_per_pixel
==
8
||
info
.
bits_per_pixel
==
16
||
RT_ASSERT
(
info
.
bits_per_pixel
==
8
||
info
.
bits_per_pixel
==
16
||
info
.
bits_per_pixel
==
24
||
info
.
bits_per_pixel
==
32
);
info
.
bits_per_pixel
==
24
||
info
.
bits_per_pixel
==
32
);
fbuf
=
rt_malloc
(
info
.
width
*
info
.
height
/
10
);
DMA_Config
();
if
(
!
fbuf
)
buf_1
=
rt_malloc
(
info
.
width
*
40
*
sizeof
(
lv_color_t
));
if
(
buf_1
==
RT_NULL
)
{
LOG_E
(
"malloc memory failed"
);
return
;
}
buf_2
=
rt_malloc
(
info
.
width
*
40
*
sizeof
(
lv_color_t
));
if
(
buf_2
==
RT_NULL
)
{
{
rt_kprintf
(
"Error: alloc disp buf fail
\n
"
);
LOG_E
(
"malloc memory failed
"
);
return
;
return
;
}
}
/*Initialize `disp_buf` with the buffer(s).
With only one buffer use NULL instead buf_2
*/
/*Initialize `disp_buf` with the buffer(s).*/
lv_disp_draw_buf_init
(
&
disp_buf
,
fbuf
,
RT_NULL
,
info
.
width
*
1
0
);
lv_disp_draw_buf_init
(
&
disp_buf
,
buf_1
,
buf_2
,
info
.
width
*
4
0
);
lv_disp_drv_init
(
&
disp_drv
);
/*Basic initialization*/
lv_disp_drv_init
(
&
disp_drv
);
/*Basic initialization*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录