Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
人间散章
rt-thread
提交
df634978
R
rt-thread
项目概览
人间散章
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
未验证
提交
df634978
编写于
10月 25, 2021
作者:
G
guo
提交者:
GitHub
10月 25, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5222 from mysterywolf/lcd
上级
e2bf5863
7f619606
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
276 addition
and
213 deletion
+276
-213
bsp/stm32/stm32f103-blue-pill/applications/SConscript
bsp/stm32/stm32f103-blue-pill/applications/SConscript
+3
-4
bsp/stm32/stm32f407-atk-explorer/applications/SConscript
bsp/stm32/stm32f407-atk-explorer/applications/SConscript
+3
-4
bsp/stm32/stm32l475-atk-pandora/applications/SConscript
bsp/stm32/stm32l475-atk-pandora/applications/SConscript
+4
-8
bsp/stm32/stm32l475-atk-pandora/board/Kconfig
bsp/stm32/stm32l475-atk-pandora/board/Kconfig
+7
-0
bsp/stm32/stm32l475-atk-pandora/board/SConscript
bsp/stm32/stm32l475-atk-pandora/board/SConscript
+2
-12
bsp/stm32/stm32l475-atk-pandora/board/ports/SConscript
bsp/stm32/stm32l475-atk-pandora/board/ports/SConscript
+1
-1
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/SConscript
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/SConscript
+16
-0
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/demo/lcd_sample.c
...2/stm32l475-atk-pandora/board/ports/lcd/demo/lcd_sample.c
+30
-0
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/demo/rttlogo.h
...tm32/stm32l475-atk-pandora/board/ports/lcd/demo/rttlogo.h
+0
-0
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/drv_lcd.c
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/drv_lcd.c
+3
-176
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/drv_lcd.h
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/drv_lcd.h
+3
-3
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/drv_lcd_font.h
...tm32/stm32l475-atk-pandora/board/ports/lcd/drv_lcd_font.h
+0
-0
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/lcd_qrcode.c
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/lcd_qrcode.c
+189
-0
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/lcd_qrcode.h
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/lcd_qrcode.h
+11
-0
components/libc/compilers/common/SConscript
components/libc/compilers/common/SConscript
+4
-5
未找到文件。
bsp/stm32/stm32f103-blue-pill/applications/SConscript
浏览文件 @
df634978
...
...
@@ -8,9 +8,8 @@ CPPPATH = [cwd]
group
=
DefineGroup
(
'Applications'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
list
=
os
.
listdir
(
cwd
)
for
d
in
list
:
path
=
os
.
path
.
join
(
cwd
,
d
)
if
os
.
path
.
isfile
(
os
.
path
.
join
(
path
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
d
,
'SConscript'
))
for
item
in
list
:
if
os
.
path
.
isfile
(
os
.
path
.
join
(
cwd
,
item
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
item
,
'SConscript'
))
Return
(
'group'
)
bsp/stm32/stm32f407-atk-explorer/applications/SConscript
浏览文件 @
df634978
...
...
@@ -8,9 +8,8 @@ src = Glob('*.c')
group
=
DefineGroup
(
'Applications'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
list
=
os
.
listdir
(
cwd
)
for
d
in
list
:
path
=
os
.
path
.
join
(
cwd
,
d
)
if
os
.
path
.
isfile
(
os
.
path
.
join
(
path
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
d
,
'SConscript'
))
for
item
in
list
:
if
os
.
path
.
isfile
(
os
.
path
.
join
(
cwd
,
item
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
item
,
'SConscript'
))
Return
(
'group'
)
bsp/stm32/stm32l475-atk-pandora/applications/SConscript
浏览文件 @
df634978
...
...
@@ -7,20 +7,16 @@ src = Split('''
main.c
'''
)
if
GetDepend
([
'BSP_USING_LCD_SAMPLE'
]):
src
+=
[
'lcd_sample.c'
]
if
GetDepend
([
'PKG_USING_NRF24L01'
]):
src
+=
[
'nrf24l01_init.c'
]
src
+=
Glob
(
'nrf24l01_init.c'
)
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'Applications'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
list
=
os
.
listdir
(
cwd
)
for
d
in
list
:
path
=
os
.
path
.
join
(
cwd
,
d
)
if
os
.
path
.
isfile
(
os
.
path
.
join
(
path
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
d
,
'SConscript'
))
for
item
in
list
:
if
os
.
path
.
isfile
(
os
.
path
.
join
(
cwd
,
item
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
item
,
'SConscript'
))
Return
(
'group'
)
bsp/stm32/stm32l475-atk-pandora/board/Kconfig
浏览文件 @
df634978
...
...
@@ -41,6 +41,13 @@ menu "Onboard Peripheral Drivers"
depends on BSP_USING_SPI_LCD && !BSP_USING_LVGL
default n
config BSP_USING_LCD_QRCODE
bool "Enable LCD to show QRCode"
depends on BSP_USING_SPI_LCD && !BSP_USING_LVGL
select BSP_USING_LCD_SAMPLE
select PKG_USING_QRCODE
default n
config BSP_USING_LVGL
bool "Enable LVGL for LCD"
select PKG_USING_LVGL
...
...
bsp/stm32/stm32l475-atk-pandora/board/SConscript
浏览文件 @
df634978
...
...
@@ -12,15 +12,12 @@ board.c
CubeMX_Config/Src/stm32l4xx_hal_msp.c
'''
)
if
GetDepend
(
'BSP_USING_KEY'
):
src
=
src
+
[
'ports/drv_key.c'
]
if
GetDepend
(
[
'BSP_USING_KEY'
]
):
src
+=
Glob
(
'ports/drv_key.c'
)
if
GetDepend
([
'BSP_USING_QSPI_FLASH'
]):
src
+=
Glob
(
'ports/drv_qspi_flash.c'
)
if
GetDepend
(
'BSP_USING_SPI_LCD'
):
src
=
src
+
[
'ports/drv_lcd.c'
]
if
GetDepend
([
'BSP_USING_SDCARD'
]):
src
+=
Glob
(
'ports/drv_sdcard.c'
)
...
...
@@ -39,7 +36,6 @@ if GetDepend(['BSP_USING_STM32_SDIO']):
path
=
[
cwd
]
path
+=
[
cwd
+
'/CubeMX_Config/Inc'
]
path
+=
[
cwd
+
'/ports'
]
if
GetDepend
([
'BSP_USING_AUDIO'
]):
path
+=
[
cwd
+
'/ports/audio'
]
...
...
@@ -56,10 +52,4 @@ elif rtconfig.CROSS_TOOL == 'iar':
CPPDEFINES
=
[
'STM32L475xx'
]
group
=
DefineGroup
(
'Drivers'
,
src
,
depend
=
[
''
],
CPPPATH
=
path
,
CPPDEFINES
=
CPPDEFINES
)
list
=
os
.
listdir
(
cwd
)
for
d
in
list
:
path
=
os
.
path
.
join
(
cwd
,
d
)
if
os
.
path
.
isfile
(
os
.
path
.
join
(
path
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
d
,
'SConscript'
))
Return
(
'group'
)
bsp/stm32/stm32l475-atk-pandora/board/ports/SConscript
浏览文件 @
df634978
...
...
@@ -3,8 +3,8 @@ from building import *
objs
=
[]
cwd
=
GetCurrentDir
()
list
=
os
.
listdir
(
cwd
)
list
=
os
.
listdir
(
cwd
)
for
item
in
list
:
if
os
.
path
.
isfile
(
os
.
path
.
join
(
cwd
,
item
,
'SConscript'
)):
objs
=
objs
+
SConscript
(
os
.
path
.
join
(
item
,
'SConscript'
))
...
...
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/SConscript
0 → 100644
浏览文件 @
df634978
from
building
import
*
import
os
cwd
=
GetCurrentDir
()
src
=
Glob
(
'*.c'
)
CPPPATH
=
[
cwd
]
if
GetDepend
([
'BSP_USING_LCD_QRCODE'
]):
src
=
src
+
Glob
(
'lcd_qrcode.c'
)
if
GetDepend
([
'BSP_USING_LCD_SAMPLE'
]):
src
=
src
+
Glob
(
'demo/lcd_sample.c'
)
group
=
DefineGroup
(
'Drivers'
,
src
,
depend
=
[
'BSP_USING_SPI_LCD'
],
CPPPATH
=
CPPPATH
)
Return
(
'group'
)
bsp/stm32/stm32l475-atk-pandora/
applications
/lcd_sample.c
→
bsp/stm32/stm32l475-atk-pandora/
board/ports/lcd/demo
/lcd_sample.c
浏览文件 @
df634978
...
...
@@ -12,34 +12,19 @@
#include <rtdevice.h>
#include <board.h>
#include <drv_lcd.h>
#include <rttlogo.h>
#include <lcd_qrcode.h>
#include "rttlogo.h"
static
int
lcd_sample
(
void
)
{
/* 清屏 */
lcd_clear
(
WHITE
);
/* 显示 RT-Thread logo */
lcd_show_image
(
0
,
0
,
240
,
69
,
image_rttlogo
);
/* 设置背景色和前景色 */
lcd_set_color
(
WHITE
,
BLACK
);
/* 在 LCD 上显示字符 */
lcd_show_string
(
10
,
69
,
16
,
"Hello, RT-Thread!"
);
lcd_show_string
(
10
,
69
+
16
,
24
,
"RT-Thread"
);
lcd_show_string
(
10
,
69
+
16
+
24
,
32
,
"RT-Thread"
);
/* 在 LCD 上画线 */
lcd_draw_line
(
0
,
69
+
16
+
24
+
32
,
240
,
69
+
16
+
24
+
32
);
/* 在 LCD 上画一个同心圆 */
lcd_draw_point
(
120
,
194
);
for
(
int
i
=
0
;
i
<
46
;
i
+=
4
)
{
lcd_draw_circle
(
120
,
194
,
i
);
}
lcd_show_string
(
10
,
69
,
24
,
"Hello, RT-Thread!"
);
lcd_draw_line
(
0
,
69
+
24
,
240
,
69
+
24
);
#ifdef BSP_USING_LCD_QRCODE
lcd_show_qrcode
(
54
,
69
+
24
+
6
,
4
,
ECC_LOW
,
"https://www.rt-thread.org/"
,
4
);
#endif
return
RT_EOK
;
}
INIT_APP_EXPORT
(
lcd_sample
);
bsp/stm32/stm32l475-atk-pandora/
applications
/rttlogo.h
→
bsp/stm32/stm32l475-atk-pandora/
board/ports/lcd/demo
/rttlogo.h
浏览文件 @
df634978
文件已移动
bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c
→
bsp/stm32/stm32l475-atk-pandora/board/ports/
lcd/
drv_lcd.c
浏览文件 @
df634978
...
...
@@ -12,10 +12,10 @@
*/
#include <rtdevice.h>
#include "drv_spi.h"
#include <drv_lcd.h>
#include "drv_lcd_font.h"
#include <drv_gpio.h>
#include <drv_spi.h>
#include "drv_lcd.h"
#include "drv_lcd_font.h"
#define DBG_TAG "drv.lcd"
#define DBG_LVL DBG_INFO
...
...
@@ -885,176 +885,3 @@ rt_err_t lcd_show_image(rt_uint16_t x, rt_uint16_t y, rt_uint16_t length, rt_uin
return
RT_EOK
;
}
#ifdef PKG_USING_QRCODE
QRCode
qrcode
;
static
rt_uint8_t
get_enlargement_factor
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
size
)
{
rt_uint8_t
enlargement_factor
=
1
;
if
(
x
+
size
*
8
<=
LCD_W
&&
y
+
size
*
8
<=
LCD_H
)
{
enlargement_factor
=
8
;
}
else
if
(
x
+
size
*
4
<=
LCD_W
&&
y
+
size
*
4
<=
LCD_H
)
{
enlargement_factor
=
4
;
}
else
if
(
x
+
size
*
2
<=
LCD_W
&&
y
+
size
*
2
<=
LCD_H
)
{
enlargement_factor
=
2
;
}
return
enlargement_factor
;
}
static
void
show_qrcode_by_point
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
size
,
rt_uint8_t
enlargement_factor
)
{
rt_uint32_t
width
=
0
,
high
=
0
;
for
(
high
=
0
;
high
<
size
;
high
++
)
{
for
(
width
=
0
;
width
<
size
;
width
++
)
{
if
(
qrcode_getModule
(
&
qrcode
,
width
,
high
))
{
/* magnify pixel */
for
(
rt_uint32_t
offset_y
=
0
;
offset_y
<
enlargement_factor
;
offset_y
++
)
{
for
(
rt_uint32_t
offset_x
=
0
;
offset_x
<
enlargement_factor
;
offset_x
++
)
{
lcd_draw_point
(
x
+
enlargement_factor
*
width
+
offset_x
,
y
+
enlargement_factor
*
high
+
offset_y
);
}
}
}
}
}
}
static
void
show_qrcode_by_line
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
size
,
rt_uint8_t
enlargement_factor
,
rt_uint8_t
*
qrcode_buf
)
{
rt_uint32_t
width
=
0
,
high
=
0
;
for
(
high
=
0
;
high
<
qrcode
.
size
;
high
++
)
{
for
(
width
=
0
;
width
<
qrcode
.
size
;
width
++
)
{
if
(
qrcode_getModule
(
&
qrcode
,
width
,
high
))
{
/* magnify pixel */
for
(
rt_uint32_t
offset_y
=
0
;
offset_y
<
enlargement_factor
;
offset_y
++
)
{
for
(
rt_uint32_t
offset_x
=
0
;
offset_x
<
enlargement_factor
;
offset_x
++
)
{
/* save the information of modules */
qrcode_buf
[
2
*
(
enlargement_factor
*
width
+
offset_x
+
offset_y
*
qrcode
.
size
*
enlargement_factor
)]
=
FORE_COLOR
>>
8
;
qrcode_buf
[
2
*
(
enlargement_factor
*
width
+
offset_x
+
offset_y
*
qrcode
.
size
*
enlargement_factor
)
+
1
]
=
FORE_COLOR
;
}
}
}
else
{
/* magnify pixel */
for
(
rt_uint32_t
offset_y
=
0
;
offset_y
<
enlargement_factor
;
offset_y
++
)
{
for
(
rt_uint32_t
offset_x
=
0
;
offset_x
<
enlargement_factor
;
offset_x
++
)
{
/* save the information of blank */
qrcode_buf
[
2
*
(
enlargement_factor
*
width
+
offset_x
+
offset_y
*
qrcode
.
size
*
enlargement_factor
)]
=
BACK_COLOR
>>
8
;
qrcode_buf
[
2
*
(
enlargement_factor
*
width
+
offset_x
+
offset_y
*
qrcode
.
size
*
enlargement_factor
)
+
1
]
=
BACK_COLOR
;
}
}
}
}
/* display a line of qrcode */
lcd_show_image
(
x
,
y
+
high
*
enlargement_factor
,
qrcode
.
size
*
enlargement_factor
,
enlargement_factor
,
qrcode_buf
);
}
}
/**
* display the qrcode on the lcd.
* size = (4 * version +17) * enlargement
*
* @param x x position
* @param y y position
* @param version version of qrcode
* @param ecc level of error correction
* @param data string
* @param enlargement enlargement_factor
*
* @return 0: display success
* -1: generate qrcode failed
* -5: memory low
*/
rt_err_t
lcd_show_qrcode
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
version
,
rt_uint8_t
ecc
,
const
char
*
data
,
rt_uint8_t
enlargement
)
{
RT_ASSERT
(
data
);
rt_int8_t
result
=
0
;
rt_uint8_t
enlargement_factor
=
1
;
rt_uint8_t
*
qrcode_buf
=
RT_NULL
;
if
(
x
+
version
*
4
+
17
>
LCD_W
||
y
+
version
*
4
+
17
>
LCD_H
)
{
LOG_E
(
"The qrcode is too big!"
);
return
-
RT_ERROR
;
}
rt_uint8_t
*
qrcodeBytes
=
(
rt_uint8_t
*
)
rt_calloc
(
1
,
qrcode_getBufferSize
(
version
));
if
(
qrcodeBytes
==
RT_NULL
)
{
LOG_E
(
"no memory for qrcode!"
);
return
-
RT_ENOMEM
;
}
/* generate qrcode */
result
=
qrcode_initText
(
&
qrcode
,
qrcodeBytes
,
version
,
ecc
,
data
);
if
(
result
>=
0
)
{
/* set enlargement factor */
if
(
enlargement
==
0
)
{
enlargement_factor
=
get_enlargement_factor
(
x
,
y
,
qrcode
.
size
);
}
else
{
enlargement_factor
=
enlargement
;
}
/* malloc memory for quick display of qrcode */
qrcode_buf
=
rt_malloc
(
qrcode
.
size
*
2
*
enlargement_factor
*
enlargement_factor
);
if
(
qrcode_buf
==
RT_NULL
)
{
/* clear lcd */
lcd_fill
(
x
,
y
,
x
+
qrcode
.
size
,
y
+
qrcode
.
size
,
BACK_COLOR
);
/* draw point to display qrcode */
show_qrcode_by_point
(
x
,
y
,
qrcode
.
size
,
enlargement_factor
);
}
else
{
/* quick display of qrcode */
show_qrcode_by_line
(
x
,
y
,
qrcode
.
size
,
enlargement_factor
,
qrcode_buf
);
}
result
=
RT_EOK
;
}
else
{
LOG_E
(
"QRCODE(%s) generate falied(%d)
\n
"
,
data
,
result
);
result
=
-
RT_ENOMEM
;
goto
__exit
;
}
__exit:
if
(
qrcodeBytes
)
{
rt_free
(
qrcodeBytes
);
}
if
(
qrcode_buf
)
{
rt_free
(
qrcode_buf
);
}
return
result
;
}
#endif
bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.h
→
bsp/stm32/stm32l475-atk-pandora/board/ports/
lcd/
drv_lcd.h
浏览文件 @
df634978
...
...
@@ -13,6 +13,7 @@
#define __DRV_LCD_H__
#include <rtthread.h>
#ifdef PKG_USING_QRCODE
#include <qrcode.h>
#endif
...
...
@@ -40,6 +41,8 @@
#define GRAY187 0XBDD7
#define GRAY240 0XF79E
extern
rt_uint16_t
BACK_COLOR
,
FORE_COLOR
;
void
lcd_clear
(
rt_uint16_t
color
);
void
lcd_address_set
(
rt_uint16_t
x1
,
rt_uint16_t
y1
,
rt_uint16_t
x2
,
rt_uint16_t
y2
);
void
lcd_set_color
(
rt_uint16_t
back
,
rt_uint16_t
fore
);
...
...
@@ -54,9 +57,6 @@ void lcd_fill_array(rt_uint16_t x_start, rt_uint16_t y_start, rt_uint16_t x_end,
void
lcd_show_num
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint32_t
num
,
rt_uint8_t
len
,
rt_uint32_t
size
);
rt_err_t
lcd_show_string
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint32_t
size
,
const
char
*
fmt
,
...);
rt_err_t
lcd_show_image
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint16_t
length
,
rt_uint16_t
wide
,
const
rt_uint8_t
*
p
);
#ifdef PKG_USING_QRCODE
rt_err_t
lcd_show_qrcode
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
version
,
rt_uint8_t
ecc
,
const
char
*
data
,
rt_uint8_t
enlargement
);
#endif
void
lcd_enter_sleep
(
void
);
void
lcd_exit_sleep
(
void
);
...
...
bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd_font.h
→
bsp/stm32/stm32l475-atk-pandora/board/ports/
lcd/
drv_lcd_font.h
浏览文件 @
df634978
文件已移动
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/lcd_qrcode.c
0 → 100644
浏览文件 @
df634978
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <rtconfig.h>
#ifdef BSP_USING_LCD_QRCODE
#include <qrcode.h>
#include "drv_lcd.h"
#include "lcd_qrcode.h"
#define DBG_TAG "drv.lcd.qrcode"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
static
QRCode
qrcode
;
static
rt_uint8_t
get_enlargement_factor
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
size
)
{
rt_uint8_t
enlargement_factor
=
1
;
if
(
x
+
size
*
8
<=
LCD_W
&&
y
+
size
*
8
<=
LCD_H
)
{
enlargement_factor
=
8
;
}
else
if
(
x
+
size
*
4
<=
LCD_W
&&
y
+
size
*
4
<=
LCD_H
)
{
enlargement_factor
=
4
;
}
else
if
(
x
+
size
*
2
<=
LCD_W
&&
y
+
size
*
2
<=
LCD_H
)
{
enlargement_factor
=
2
;
}
return
enlargement_factor
;
}
static
void
show_qrcode_by_point
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
size
,
rt_uint8_t
enlargement_factor
)
{
rt_uint32_t
width
=
0
,
high
=
0
;
for
(
high
=
0
;
high
<
size
;
high
++
)
{
for
(
width
=
0
;
width
<
size
;
width
++
)
{
if
(
qrcode_getModule
(
&
qrcode
,
width
,
high
))
{
/* magnify pixel */
for
(
rt_uint32_t
offset_y
=
0
;
offset_y
<
enlargement_factor
;
offset_y
++
)
{
for
(
rt_uint32_t
offset_x
=
0
;
offset_x
<
enlargement_factor
;
offset_x
++
)
{
lcd_draw_point
(
x
+
enlargement_factor
*
width
+
offset_x
,
y
+
enlargement_factor
*
high
+
offset_y
);
}
}
}
}
}
}
static
void
show_qrcode_by_line
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
size
,
rt_uint8_t
enlargement_factor
,
rt_uint8_t
*
qrcode_buf
)
{
rt_uint32_t
width
=
0
,
high
=
0
;
for
(
high
=
0
;
high
<
qrcode
.
size
;
high
++
)
{
for
(
width
=
0
;
width
<
qrcode
.
size
;
width
++
)
{
if
(
qrcode_getModule
(
&
qrcode
,
width
,
high
))
{
/* magnify pixel */
for
(
rt_uint32_t
offset_y
=
0
;
offset_y
<
enlargement_factor
;
offset_y
++
)
{
for
(
rt_uint32_t
offset_x
=
0
;
offset_x
<
enlargement_factor
;
offset_x
++
)
{
/* save the information of modules */
qrcode_buf
[
2
*
(
enlargement_factor
*
width
+
offset_x
+
offset_y
*
qrcode
.
size
*
enlargement_factor
)]
=
FORE_COLOR
>>
8
;
qrcode_buf
[
2
*
(
enlargement_factor
*
width
+
offset_x
+
offset_y
*
qrcode
.
size
*
enlargement_factor
)
+
1
]
=
FORE_COLOR
;
}
}
}
else
{
/* magnify pixel */
for
(
rt_uint32_t
offset_y
=
0
;
offset_y
<
enlargement_factor
;
offset_y
++
)
{
for
(
rt_uint32_t
offset_x
=
0
;
offset_x
<
enlargement_factor
;
offset_x
++
)
{
/* save the information of blank */
qrcode_buf
[
2
*
(
enlargement_factor
*
width
+
offset_x
+
offset_y
*
qrcode
.
size
*
enlargement_factor
)]
=
BACK_COLOR
>>
8
;
qrcode_buf
[
2
*
(
enlargement_factor
*
width
+
offset_x
+
offset_y
*
qrcode
.
size
*
enlargement_factor
)
+
1
]
=
BACK_COLOR
;
}
}
}
}
/* display a line of qrcode */
lcd_show_image
(
x
,
y
+
high
*
enlargement_factor
,
qrcode
.
size
*
enlargement_factor
,
enlargement_factor
,
qrcode_buf
);
}
}
/**
* display the qrcode on the lcd.
* size = (4 * version +17) * enlargement
*
* @param x x position
* @param y y position
* @param version version of qrcode
* @param ecc level of error correction
* @param data string
* @param enlargement enlargement_factor
*
* @return 0: display success
* -1: generate qrcode failed
* -5: memory low
*/
rt_err_t
lcd_show_qrcode
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
version
,
rt_uint8_t
ecc
,
const
char
*
data
,
rt_uint8_t
enlargement
)
{
RT_ASSERT
(
data
);
rt_int8_t
result
=
0
;
rt_uint8_t
enlargement_factor
=
1
;
rt_uint8_t
*
qrcode_buf
=
RT_NULL
;
if
(
x
+
version
*
4
+
17
>
LCD_W
||
y
+
version
*
4
+
17
>
LCD_H
)
{
LOG_E
(
"The qrcode is too big!"
);
return
-
RT_ERROR
;
}
rt_uint8_t
*
qrcodeBytes
=
(
rt_uint8_t
*
)
rt_calloc
(
1
,
qrcode_getBufferSize
(
version
));
if
(
qrcodeBytes
==
RT_NULL
)
{
LOG_E
(
"no memory for qrcode!"
);
return
-
RT_ENOMEM
;
}
/* generate qrcode */
result
=
qrcode_initText
(
&
qrcode
,
qrcodeBytes
,
version
,
ecc
,
data
);
if
(
result
>=
0
)
{
/* set enlargement factor */
if
(
enlargement
==
0
)
{
enlargement_factor
=
get_enlargement_factor
(
x
,
y
,
qrcode
.
size
);
}
else
{
enlargement_factor
=
enlargement
;
}
/* malloc memory for quick display of qrcode */
qrcode_buf
=
rt_malloc
(
qrcode
.
size
*
2
*
enlargement_factor
*
enlargement_factor
);
if
(
qrcode_buf
==
RT_NULL
)
{
/* clear lcd */
lcd_fill
(
x
,
y
,
x
+
qrcode
.
size
,
y
+
qrcode
.
size
,
BACK_COLOR
);
/* draw point to display qrcode */
show_qrcode_by_point
(
x
,
y
,
qrcode
.
size
,
enlargement_factor
);
}
else
{
/* quick display of qrcode */
show_qrcode_by_line
(
x
,
y
,
qrcode
.
size
,
enlargement_factor
,
qrcode_buf
);
}
result
=
RT_EOK
;
}
else
{
LOG_E
(
"QRCODE(%s) generate falied(%d)
\n
"
,
data
,
result
);
result
=
-
RT_ENOMEM
;
goto
__exit
;
}
__exit:
if
(
qrcodeBytes
)
{
rt_free
(
qrcodeBytes
);
}
if
(
qrcode_buf
)
{
rt_free
(
qrcode_buf
);
}
return
result
;
}
#endif
bsp/stm32/stm32l475-atk-pandora/board/ports/lcd/lcd_qrcode.h
0 → 100644
浏览文件 @
df634978
#ifndef __LCD_QRCODE_H__
#define __LCD_QRCODE_H__
#include <rtconfig.h>
#ifdef PKG_USING_QRCODE
#include <rtdef.h>
rt_err_t
lcd_show_qrcode
(
rt_uint16_t
x
,
rt_uint16_t
y
,
rt_uint8_t
version
,
rt_uint8_t
ecc
,
const
char
*
data
,
rt_uint8_t
enlargement
);
#endif
#endif
components/libc/compilers/common/SConscript
浏览文件 @
df634978
...
...
@@ -12,7 +12,7 @@ if GetDepend('RT_USING_LIBC'):
if
GetDepend
(
'RT_USING_POSIX'
)
==
False
:
SrcRemove
(
src
,
[
'unistd.c'
,
'delay.c'
])
elif
GetDepend
(
'RT_LIBC_USING_TIME'
):
src
+=
[
'time.c'
]
src
+=
Glob
(
'time.c'
)
if
rtconfig
.
CROSS_TOOL
==
'keil'
:
CPPDEFINES
=
[
'__CLK_TCK=RT_TICK_PER_SECOND'
]
...
...
@@ -22,9 +22,8 @@ else:
group
=
DefineGroup
(
'libc'
,
src
,
depend
=
[],
CPPPATH
=
CPPPATH
,
CPPDEFINES
=
CPPDEFINES
)
list
=
os
.
listdir
(
cwd
)
for
d
in
list
:
path
=
os
.
path
.
join
(
cwd
,
d
)
if
os
.
path
.
isfile
(
os
.
path
.
join
(
path
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
d
,
'SConscript'
))
for
item
in
list
:
if
os
.
path
.
isfile
(
os
.
path
.
join
(
cwd
,
item
,
'SConscript'
)):
group
=
group
+
SConscript
(
os
.
path
.
join
(
item
,
'SConscript'
))
Return
(
'group'
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录