[stm32l475] improve the structrue of sconscript
This commit is contained in:
parent
e2bf5863d1
commit
7f619606a1
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-08-28 WillianChan first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
#include <drv_lcd.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);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_APP_EXPORT(lcd_sample);
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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'))
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
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')
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-08-28 WillianChan first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
#include <drv_lcd.h>
|
||||
#include <lcd_qrcode.h>
|
||||
#include "rttlogo.h"
|
||||
|
||||
static int lcd_sample(void)
|
||||
{
|
||||
lcd_clear(WHITE);
|
||||
lcd_show_image(0, 0, 240, 69, image_rttlogo);
|
||||
lcd_set_color(WHITE, BLACK);
|
||||
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);
|
|
@ -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
|
|
@ -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);
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* 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
|
|
@ -0,0 +1,11 @@
|
|||
#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
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue