Transition to hekate bdk layout
This commit is contained in:
parent
4425e81085
commit
4ffd4ce7f0
317 changed files with 60891 additions and 1003 deletions
98
bdk/libs/compr/blz.c
Normal file
98
bdk/libs/compr/blz.c
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) 2018 rajkosto
|
||||
* Copyright (c) 2018 SciresM
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "blz.h"
|
||||
|
||||
const blz_footer *blz_get_footer(const unsigned char *compData, unsigned int compDataLen, blz_footer *outFooter)
|
||||
{
|
||||
if (compDataLen < sizeof(blz_footer))
|
||||
return NULL;
|
||||
|
||||
const blz_footer *srcFooter = (const blz_footer*)&compData[compDataLen - sizeof(blz_footer)];
|
||||
if (outFooter != NULL)
|
||||
memcpy(outFooter, srcFooter, sizeof(blz_footer)); // Must be a memcpy because no umaligned accesses on ARMv4.
|
||||
|
||||
return srcFooter;
|
||||
}
|
||||
|
||||
// From https://github.com/SciresM/hactool/blob/master/kip.c which is exactly how kernel does it, thanks SciresM!
|
||||
int blz_uncompress_inplace(unsigned char *dataBuf, unsigned int compSize, const blz_footer *footer)
|
||||
{
|
||||
u32 addl_size = footer->addl_size;
|
||||
u32 header_size = footer->header_size;
|
||||
u32 cmp_and_hdr_size = footer->cmp_and_hdr_size;
|
||||
|
||||
unsigned char* cmp_start = &dataBuf[compSize] - cmp_and_hdr_size;
|
||||
u32 cmp_ofs = cmp_and_hdr_size - header_size;
|
||||
u32 out_ofs = cmp_and_hdr_size + addl_size;
|
||||
|
||||
while (out_ofs)
|
||||
{
|
||||
unsigned char control = cmp_start[--cmp_ofs];
|
||||
for (unsigned int i=0; i<8; i++)
|
||||
{
|
||||
if (control & 0x80)
|
||||
{
|
||||
if (cmp_ofs < 2)
|
||||
return 0; // Out of bounds.
|
||||
|
||||
cmp_ofs -= 2;
|
||||
u16 seg_val = ((unsigned int)(cmp_start[cmp_ofs + 1]) << 8) | cmp_start[cmp_ofs];
|
||||
u32 seg_size = ((seg_val >> 12) & 0xF) + 3;
|
||||
u32 seg_ofs = (seg_val & 0x0FFF) + 3;
|
||||
if (out_ofs < seg_size) // Kernel restricts segment copy to stay in bounds.
|
||||
seg_size = out_ofs;
|
||||
|
||||
out_ofs -= seg_size;
|
||||
|
||||
for (unsigned int j = 0; j < seg_size; j++)
|
||||
cmp_start[out_ofs + j] = cmp_start[out_ofs + j + seg_ofs];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Copy directly.
|
||||
if (cmp_ofs < 1)
|
||||
return 0; //out of bounds
|
||||
|
||||
cmp_start[--out_ofs] = cmp_start[--cmp_ofs];
|
||||
}
|
||||
control <<= 1;
|
||||
if (out_ofs == 0) // Blz works backwards, so if it reaches byte 0, it's done.
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int blz_uncompress_srcdest(const unsigned char *compData, unsigned int compDataLen, unsigned char *dstData, unsigned int dstSize)
|
||||
{
|
||||
blz_footer footer;
|
||||
const blz_footer *compFooterPtr = blz_get_footer(compData, compDataLen, &footer);
|
||||
if (compFooterPtr == NULL)
|
||||
return 0;
|
||||
|
||||
// Decompression must be done in-place, so need to copy the relevant compressed data first.
|
||||
unsigned int numCompBytes = (const unsigned char*)(compFooterPtr)-compData;
|
||||
memcpy(dstData, compData, numCompBytes);
|
||||
memset(&dstData[numCompBytes], 0, dstSize - numCompBytes);
|
||||
|
||||
return blz_uncompress_inplace(dstData, compDataLen, &footer);
|
||||
}
|
36
bdk/libs/compr/blz.h
Normal file
36
bdk/libs/compr/blz.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2018 rajkosto
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _BLZ_H_
|
||||
#define _BLZ_H_
|
||||
|
||||
#include <utils/types.h>
|
||||
|
||||
typedef struct _blz_footer
|
||||
{
|
||||
u32 cmp_and_hdr_size;
|
||||
u32 header_size;
|
||||
u32 addl_size;
|
||||
} blz_footer;
|
||||
|
||||
// Returns pointer to footer in compData if present, additionally copies it to outFooter if not NULL.
|
||||
const blz_footer *blz_get_footer(const unsigned char *compData, unsigned int compDataLen, blz_footer *outFooter);
|
||||
// Returns 0 on failure.
|
||||
int blz_uncompress_inplace(unsigned char *dataBuf, unsigned int compSize, const blz_footer *footer);
|
||||
// Returns 0 on failure.
|
||||
int blz_uncompress_srcdest(const unsigned char *compData, unsigned int compDataLen, unsigned char *dstData, unsigned int dstSize);
|
||||
|
||||
#endif
|
179
bdk/libs/compr/lz.c
Normal file
179
bdk/libs/compr/lz.c
Normal file
|
@ -0,0 +1,179 @@
|
|||
/*************************************************************************
|
||||
* Name: lz.c
|
||||
* Author: Marcus Geelnard
|
||||
* Description: LZ77 coder/decoder implementation.
|
||||
* Reentrant: Yes
|
||||
*
|
||||
* The LZ77 compression scheme is a substitutional compression scheme
|
||||
* proposed by Abraham Lempel and Jakob Ziv in 1977. It is very simple in
|
||||
* its design, and uses no fancy bit level compression.
|
||||
*
|
||||
* This is my first attempt at an implementation of a LZ77 code/decoder.
|
||||
*
|
||||
* The principle of the LZ77 compression algorithm is to store repeated
|
||||
* occurrences of strings as references to previous occurrences of the same
|
||||
* string. The point is that the reference consumes less space than the
|
||||
* string itself, provided that the string is long enough (in this
|
||||
* implementation, the string has to be at least 4 bytes long, since the
|
||||
* minimum coded reference is 3 bytes long). Also note that the term
|
||||
* "string" refers to any kind of byte sequence (it does not have to be
|
||||
* an ASCII string, for instance).
|
||||
*
|
||||
* The coder uses a brute force approach to finding string matches in the
|
||||
* history buffer (or "sliding window", if you wish), which is very, very
|
||||
* slow. I recon the complexity is somewhere between O(n^2) and O(n^3),
|
||||
* depending on the input data.
|
||||
*
|
||||
* There is also a faster implementation that uses a large working buffer
|
||||
* in which a "jump table" is stored, which is used to quickly find
|
||||
* possible string matches (see the source code for LZ_CompressFast() for
|
||||
* more information). The faster method is an order of magnitude faster,
|
||||
* but still quite slow compared to other compression methods.
|
||||
*
|
||||
* The upside is that decompression is very fast, and the compression ratio
|
||||
* is often very good.
|
||||
*
|
||||
* The reference to a string is coded as a (length,offset) pair, where the
|
||||
* length indicates the length of the string, and the offset gives the
|
||||
* offset from the current data position. To distinguish between string
|
||||
* references and literal strings (uncompressed bytes), a string reference
|
||||
* is preceded by a marker byte, which is chosen as the least common byte
|
||||
* symbol in the input data stream (this marker byte is stored in the
|
||||
* output stream as the first byte).
|
||||
*
|
||||
* Occurrences of the marker byte in the stream are encoded as the marker
|
||||
* byte followed by a zero byte, which means that occurrences of the marker
|
||||
* byte have to be coded with two bytes.
|
||||
*
|
||||
* The lengths and offsets are coded in a variable length fashion, allowing
|
||||
* values of any magnitude (up to 4294967295 in this implementation).
|
||||
*
|
||||
* With this compression scheme, the worst case compression result is
|
||||
* (257/256)*insize + 1.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
* Copyright (c) 2003-2006 Marcus Geelnard
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would
|
||||
* be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not
|
||||
* be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
* Marcus Geelnard
|
||||
* marcus.geelnard at home.se
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* INTERNAL FUNCTIONS *
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* _LZ_ReadVarSize() - Read unsigned integer with variable number of
|
||||
* bytes depending on value.
|
||||
*************************************************************************/
|
||||
|
||||
static int _LZ_ReadVarSize( unsigned int * x, const unsigned char * buf )
|
||||
{
|
||||
unsigned int y, b, num_bytes;
|
||||
|
||||
/* Read complete value (stop when byte contains zero in 8:th bit) */
|
||||
y = 0;
|
||||
num_bytes = 0;
|
||||
do
|
||||
{
|
||||
b = (unsigned int) (*buf ++);
|
||||
y = (y << 7) | (b & 0x0000007f);
|
||||
++ num_bytes;
|
||||
}
|
||||
while( b & 0x00000080 );
|
||||
|
||||
/* Store value in x */
|
||||
*x = y;
|
||||
|
||||
/* Return number of bytes read */
|
||||
return num_bytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* PUBLIC FUNCTIONS *
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* LZ_Uncompress() - Uncompress a block of data using an LZ77 decoder.
|
||||
* in - Input (compressed) buffer.
|
||||
* out - Output (uncompressed) buffer. This buffer must be large
|
||||
* enough to hold the uncompressed data.
|
||||
* insize - Number of input bytes.
|
||||
*************************************************************************/
|
||||
|
||||
void LZ_Uncompress( const unsigned char *in, unsigned char *out,
|
||||
unsigned int insize )
|
||||
{
|
||||
unsigned char marker, symbol;
|
||||
unsigned int i, inpos, outpos, length, offset;
|
||||
|
||||
/* Do we have anything to uncompress? */
|
||||
if( insize < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get marker symbol from input stream */
|
||||
marker = in[ 0 ];
|
||||
inpos = 1;
|
||||
|
||||
/* Main decompression loop */
|
||||
outpos = 0;
|
||||
do
|
||||
{
|
||||
symbol = in[ inpos ++ ];
|
||||
if( symbol == marker )
|
||||
{
|
||||
/* We had a marker byte */
|
||||
if( in[ inpos ] == 0 )
|
||||
{
|
||||
/* It was a single occurrence of the marker byte */
|
||||
out[ outpos ++ ] = marker;
|
||||
++ inpos;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Extract true length and offset */
|
||||
inpos += _LZ_ReadVarSize( &length, &in[ inpos ] );
|
||||
inpos += _LZ_ReadVarSize( &offset, &in[ inpos ] );
|
||||
|
||||
/* Copy corresponding data from history window */
|
||||
for( i = 0; i < length; ++ i )
|
||||
{
|
||||
out[ outpos ] = out[ outpos - offset ];
|
||||
++ outpos;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No marker, plain copy */
|
||||
out[ outpos ++ ] = symbol;
|
||||
}
|
||||
}
|
||||
while( inpos < insize );
|
||||
}
|
52
bdk/libs/compr/lz.h
Normal file
52
bdk/libs/compr/lz.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*************************************************************************
|
||||
* Name: lz.h
|
||||
* Author: Marcus Geelnard
|
||||
* Description: LZ77 coder/decoder interface.
|
||||
* Reentrant: Yes
|
||||
*-------------------------------------------------------------------------
|
||||
* Copyright (c) 2003-2006 Marcus Geelnard
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would
|
||||
* be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not
|
||||
* be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*
|
||||
* Marcus Geelnard
|
||||
* marcus.geelnard at home.se
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef _lz_h_
|
||||
#define _lz_h_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Function prototypes
|
||||
*************************************************************************/
|
||||
|
||||
void LZ_Uncompress( const unsigned char *in, unsigned char *out,
|
||||
unsigned int insize );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _lz_h_ */
|
86
bdk/libs/fatfs/diskio.h
Normal file
86
bdk/libs/fatfs/diskio.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*-----------------------------------------------------------------------/
|
||||
/ Low level disk interface modlue include file (C)ChaN, 2014 /
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO_DEFINED
|
||||
#define _DISKIO_DEFINED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <utils/types.h>
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
typedef enum {
|
||||
DRIVE_SD = 0,
|
||||
DRIVE_RAM = 1,
|
||||
DRIVE_EMMC = 2,
|
||||
DRIVE_BIS = 3
|
||||
} DDRIVE;
|
||||
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
|
||||
DSTATUS disk_initialize (BYTE pdrv);
|
||||
DSTATUS disk_status (BYTE pdrv);
|
||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl fucntion */
|
||||
|
||||
/* Generic command (Used by FatFs) */
|
||||
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
|
||||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
|
||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
|
||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
|
||||
|
||||
/* Generic command (Not used by FatFs) */
|
||||
#define CTRL_POWER 5 /* Get/Set power status */
|
||||
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
|
||||
#define CTRL_EJECT 7 /* Eject media */
|
||||
#define CTRL_FORMAT 8 /* Create physical format on the media */
|
||||
|
||||
/* MMC/SDC specific ioctl command */
|
||||
#define MMC_GET_TYPE 10 /* Get card type */
|
||||
#define MMC_GET_CSD 11 /* Get CSD */
|
||||
#define MMC_GET_CID 12 /* Get CID */
|
||||
#define MMC_GET_OCR 13 /* Get OCR */
|
||||
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
|
||||
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
|
||||
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
|
||||
|
||||
/* ATA/CF specific ioctl command */
|
||||
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||
#define ATA_GET_MODEL 21 /* Get model name */
|
||||
#define ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
6882
bdk/libs/fatfs/ff.c
Normal file
6882
bdk/libs/fatfs/ff.c
Normal file
File diff suppressed because it is too large
Load diff
394
bdk/libs/fatfs/ff.h
Normal file
394
bdk/libs/fatfs/ff.h
Normal file
|
@ -0,0 +1,394 @@
|
|||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - Generic FAT Filesystem module R0.13c /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 2018, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
/ that the following condition is met:
|
||||
|
||||
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||
/ this condition and the following disclaimer.
|
||||
/
|
||||
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||
/ and any warranties related to this software are DISCLAIMED.
|
||||
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||
/ by use of this software.
|
||||
/
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef FF_DEFINED
|
||||
#define FF_DEFINED 86604 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <utils/types.h> /* Basic integer types */
|
||||
#include <fatfs_cfg.h> /* FatFs configuration options */
|
||||
|
||||
#if FF_DEFINED != FFCONF_DEF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
|
||||
#endif
|
||||
|
||||
#if FF_STR_VOLUME_ID
|
||||
#ifndef FF_VOLUME_STRS
|
||||
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of path name strings on FatFs API */
|
||||
|
||||
#ifndef _INC_TCHAR
|
||||
#define _INC_TCHAR
|
||||
|
||||
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
||||
typedef WCHAR TCHAR;
|
||||
#define _T(x) L ## x
|
||||
#define _TEXT(x) L ## x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) u8 ## x
|
||||
#define _TEXT(x) u8 ## x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */
|
||||
typedef DWORD TCHAR;
|
||||
#define _T(x) U ## x
|
||||
#define _TEXT(x) U ## x
|
||||
#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
|
||||
#error Wrong FF_LFN_UNICODE setting
|
||||
#else /* ANSI/OEM code in SBCS/DBCS */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of file size variables */
|
||||
|
||||
#if FF_FS_EXFAT
|
||||
typedef QWORD FSIZE_t;
|
||||
#else
|
||||
typedef DWORD FSIZE_t;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Filesystem object structure (FATFS) */
|
||||
|
||||
typedef struct {
|
||||
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||
BYTE pdrv; /* Associated physical drive */
|
||||
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
WORD id; /* Volume mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
WORD csize; /* Cluster size [sectors] */
|
||||
#if FF_MAX_SS != FF_MIN_SS
|
||||
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if FF_USE_LFN
|
||||
WCHAR* lfnbuf; /* LFN working buffer */
|
||||
#endif
|
||||
#if FF_FS_EXFAT
|
||||
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
||||
#endif
|
||||
#if FF_FS_REENTRANT
|
||||
FF_SYNC_t sobj; /* Identifier of sync object */
|
||||
#endif
|
||||
#if !FF_FS_READONLY
|
||||
DWORD last_clst; /* Last allocated cluster */
|
||||
DWORD free_clst; /* Number of free clusters */
|
||||
#endif
|
||||
#if FF_FS_RPATH
|
||||
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
|
||||
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
|
||||
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
|
||||
#endif
|
||||
#endif
|
||||
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
||||
DWORD fsize; /* Size of an FAT [sectors] */
|
||||
DWORD volbase; /* Volume base sector */
|
||||
DWORD fatbase; /* FAT base sector */
|
||||
DWORD dirbase; /* Root directory base sector/cluster */
|
||||
DWORD database; /* Data base sector */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD bitbase; /* Allocation bitmap base sector */
|
||||
#endif
|
||||
DWORD winsect; /* Current sector appearing in the win[] */
|
||||
} FATFS;
|
||||
|
||||
|
||||
|
||||
/* Object ID and allocation information (FFOBJID) */
|
||||
|
||||
typedef struct {
|
||||
FATFS* fs; /* Pointer to the hosting volume of this object */
|
||||
WORD id; /* Hosting volume mount ID */
|
||||
BYTE attr; /* Object attribute */
|
||||
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
||||
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
||||
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */
|
||||
DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */
|
||||
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
|
||||
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
|
||||
DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */
|
||||
#endif
|
||||
#if FF_FS_LOCK
|
||||
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
} FFOBJID;
|
||||
|
||||
|
||||
|
||||
/* File object structure (FIL) */
|
||||
|
||||
typedef struct {
|
||||
#if !FF_FS_TINY
|
||||
BYTE buf[FF_MAX_SS]; /* File private data read/write window */
|
||||
#endif
|
||||
FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */
|
||||
BYTE flag; /* File status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
||||
DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !FF_FS_READONLY
|
||||
DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
||||
#endif
|
||||
#if FF_USE_FASTSEEK
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
|
||||
#endif
|
||||
} FIL;
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (DIR) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier */
|
||||
DWORD dptr; /* Current read/write offset */
|
||||
DWORD clust; /* Current cluster */
|
||||
DWORD sect; /* Current sector (0:Read operation has terminated) */
|
||||
BYTE* dir; /* Pointer to the directory item in the win[] */
|
||||
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||
#if FF_USE_LFN
|
||||
DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
|
||||
#endif
|
||||
#if FF_USE_FIND
|
||||
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||
#endif
|
||||
} DIR;
|
||||
|
||||
|
||||
|
||||
/* File information structure (FILINFO) */
|
||||
|
||||
typedef struct {
|
||||
FSIZE_t fsize; /* File size */
|
||||
WORD fdate; /* Modified date */
|
||||
WORD ftime; /* Modified time */
|
||||
BYTE fattrib; /* File attribute */
|
||||
#if FF_USE_LFN
|
||||
TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
|
||||
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
||||
#else
|
||||
TCHAR fname[12 + 1]; /* File name */
|
||||
#endif
|
||||
} FILINFO;
|
||||
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
typedef enum {
|
||||
FR_OK = 0, /* (0) Succeeded */
|
||||
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||
FR_NO_FILE, /* (4) Could not find the file */
|
||||
FR_NO_PATH, /* (5) Could not find the path */
|
||||
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
|
||||
#if FF_FASTFS
|
||||
FR_INVALID_PARAMETER, /* (19) Given parameter is invalid */
|
||||
FR_CLTBL_NO_INIT /* (20) The cluster table for fast seek/read/write was not created */
|
||||
#else
|
||||
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||
#endif
|
||||
} FRESULT;
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* FatFs module application interface */
|
||||
|
||||
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
|
||||
#ifdef FF_FASTFS
|
||||
FRESULT f_read_fast (FIL* fp, const void* buff, UINT btr); /* Fast read data from the file */
|
||||
FRESULT f_write_fast (FIL* fp, const void* buff, UINT btw); /* Fast write data to the file */
|
||||
#endif
|
||||
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate the file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
|
||||
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||
#ifdef FF_FASTFS
|
||||
DWORD *f_expand_cltbl (FIL* fp, UINT tblsz, DWORD *tbl, FSIZE_t ofs); /* Expand file and populate cluster table */
|
||||
#endif
|
||||
FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */
|
||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, BYTE opt, DWORD au, void* work, UINT len); /* Create a FAT volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const DWORD* szt, void* work); /* Divide a physical drive into some partitions */
|
||||
FRESULT f_setcp (WORD cp); /* Set current code page */
|
||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||
|
||||
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
||||
#define f_error(fp) ((fp)->err)
|
||||
#define f_tell(fp) ((fp)->fptr)
|
||||
#define f_size(fp) ((fp)->obj.objsize)
|
||||
#define f_rewind(fp) f_lseek((fp), 0)
|
||||
#define f_rewinddir(dp) f_readdir((dp), 0)
|
||||
#define f_rmdir(path) f_unlink(path)
|
||||
#define f_unmount(path) f_mount(0, path, 0)
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Additional user defined functions */
|
||||
|
||||
/* RTC function */
|
||||
#if !FF_FS_READONLY && !FF_FS_NORTC
|
||||
DWORD get_fattime (void);
|
||||
#endif
|
||||
|
||||
/* LFN support functions */
|
||||
#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
|
||||
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
|
||||
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
||||
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
||||
#endif
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||
void ff_memfree (void* mblock); /* Free memory block */
|
||||
#endif
|
||||
|
||||
/* Sync functions */
|
||||
#if FF_FS_REENTRANT
|
||||
int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Flags and offset address */
|
||||
|
||||
|
||||
/* File access mode and open method flags (3rd argument of f_open) */
|
||||
#define FA_READ 0x01
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define FA_OPEN_APPEND 0x30
|
||||
|
||||
/* Fast seek controls (2nd argument of f_lseek) */
|
||||
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
|
||||
|
||||
/* Format options (2nd argument of f_mkfs) */
|
||||
#define FM_FAT 0x01
|
||||
#define FM_FAT32 0x02
|
||||
#define FM_EXFAT 0x04
|
||||
#define FM_ANY 0x07
|
||||
#define FM_SFD 0x08
|
||||
|
||||
/* Filesystem type (FATFS.fs_type) */
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
#define FS_EXFAT 4
|
||||
|
||||
/* File attribute bits for directory entry (FILINFO.fattrib) */
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_VOL 0x08 /* Volume */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
#define AM_DEV 0x40 /* Device */
|
||||
#define AM_RVD 0x80 /* Reserved */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FF_DEFINED */
|
625
bdk/libs/fatfs/ffunicode.c
Normal file
625
bdk/libs/fatfs/ffunicode.c
Normal file
|
@ -0,0 +1,625 @@
|
|||
/*------------------------------------------------------------------------*/
|
||||
/* Unicode handling functions for FatFs R0.13c */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This module will occupy a huge memory in the .const section when the /
|
||||
/ FatFs is configured for LFN with DBCS. If the system has any Unicode /
|
||||
/ utilitiy for the code conversion, this module should be modified to use /
|
||||
/ that function to avoid silly memory consumption. /
|
||||
/-------------------------------------------------------------------------*/
|
||||
/*
|
||||
/ Copyright (C) 2018, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
/ that the following condition is met:
|
||||
/
|
||||
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||
/ this condition and the following disclaimer.
|
||||
/
|
||||
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||
/ and any warranties related to this software are DISCLAIMED.
|
||||
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||
/ by use of this software.
|
||||
*/
|
||||
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
#if FF_USE_LFN /* This module will be blanked at non-LFN configuration */
|
||||
|
||||
#if FF_DEFINED != 86604 /* Revision ID */
|
||||
#error Wrong include file (ff.h).
|
||||
#endif
|
||||
|
||||
#define MERGE2(a, b) a ## b
|
||||
#define CVTBL(tbl, cp) MERGE2(tbl, cp)
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Code Conversion Tables */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
#if FF_CODE_PAGE == 437 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc437[] = { /* CP437(U.S.) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 720 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc720[] = { /* CP720(Arabic) to Unicode conversion table */
|
||||
0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9, 0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627,
|
||||
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A,
|
||||
0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0x0650, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 737 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc737[] = { /* CP737(Greek) to Unicode conversion table */
|
||||
0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
|
||||
0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8,
|
||||
0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD, 0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E,
|
||||
0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 771 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc771[] = { /* CP771(KBL) to Unicode conversion table */
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x0104, 0x0105, 0x010C, 0x010D,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
|
||||
0x0118, 0x0119, 0x0116, 0x0117, 0x012E, 0x012F, 0x0160, 0x0161, 0x0172, 0x0173, 0x016A, 0x016B, 0x017D, 0x017E, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 775 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc775[] = { /* CP775(Baltic) to Unicode conversion table */
|
||||
0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107, 0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4,
|
||||
0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6, 0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118, 0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D,
|
||||
0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B, 0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144, 0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019,
|
||||
0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E, 0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 850 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc850[] = { /* CP850(Latin 1) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
|
||||
0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 852 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc852[] = { /* CP852(Latin 2) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7, 0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
|
||||
0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E, 0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A, 0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE, 0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161, 0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4,
|
||||
0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 855 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc855[] = { /* CP855(Cyrillic) to Unicode conversion table */
|
||||
0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404, 0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
|
||||
0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C, 0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A,
|
||||
0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414, 0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438, 0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E, 0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580,
|
||||
0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443, 0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116,
|
||||
0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D, 0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 857 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc857[] = { /* CP857(Turkish) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
|
||||
0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
|
||||
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000, 0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4,
|
||||
0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 860 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc860[] = { /* CP860(Portuguese) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E3, 0x00E0, 0x00C1, 0x00E7, 0x00EA, 0x00CA, 0x00E8, 0x00CD, 0x00D4, 0x00EC, 0x00C3, 0x00C2,
|
||||
0x00C9, 0x00C0, 0x00C8, 0x00F4, 0x00F5, 0x00F2, 0x00DA, 0x00F9, 0x00CC, 0x00D5, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x20A7, 0x00D3,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00D2, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 861 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc861[] = { /* CP861(Icelandic) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00D0, 0x00F0, 0x00DE, 0x00C4, 0x00C5,
|
||||
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00FE, 0x00FB, 0x00DD, 0x00FD, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00C1, 0x00CD, 0x00D3, 0x00DA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 862 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc862[] = { /* CP862(Hebrew) to Unicode conversion table */
|
||||
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
|
||||
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 863 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc863[] = { /* CP863(Canadian French) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00C2, 0x00E0, 0x00B6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x2017, 0x00C0,
|
||||
0x00C9, 0x00C8, 0x00CA, 0x00F4, 0x00CB, 0x00CF, 0x00FB, 0x00F9, 0x00A4, 0x00D4, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x00DB, 0x0192,
|
||||
0x00A6, 0x00B4, 0x00F3, 0x00FA, 0x00A8, 0x00BB, 0x00B3, 0x00AF, 0x00CE, 0x3210, 0x00AC, 0x00BD, 0x00BC, 0x00BE, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2219,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 864 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc864[] = { /* CP864(Arabic) to Unicode conversion table */
|
||||
0x00B0, 0x00B7, 0x2219, 0x221A, 0x2592, 0x2500, 0x2502, 0x253C, 0x2524, 0x252C, 0x251C, 0x2534, 0x2510, 0x250C, 0x2514, 0x2518,
|
||||
0x03B2, 0x221E, 0x03C6, 0x00B1, 0x00BD, 0x00BC, 0x2248, 0x00AB, 0x00BB, 0xFEF7, 0xFEF8, 0x0000, 0x0000, 0xFEFB, 0xFEFC, 0x0000,
|
||||
0x00A0, 0x00AD, 0xFE82, 0x00A3, 0x00A4, 0xFE84, 0x0000, 0x20AC, 0xFE8E, 0xFE8F, 0xFE95, 0xFE99, 0x060C, 0xFE9D, 0xFEA1, 0xFEA5,
|
||||
0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, 0x0668, 0x0669, 0xFED1, 0x061B, 0xFEB1, 0xFEB5, 0xFEB9, 0x061F,
|
||||
0x00A2, 0xFE80, 0xFE81, 0xFE83, 0xFE85, 0xFECA, 0xFE8B, 0xFE8D, 0xFE91, 0xFE93, 0xFE97, 0xFE9B, 0xFE9F, 0xFEA3, 0xFEA7, 0xFEA9,
|
||||
0xFEAB, 0xFEAD, 0xFEAF, 0xFEB3, 0xFEB7, 0xFEBB, 0xFEBF, 0xFEC1, 0xFEC5, 0xFECB, 0xFECF, 0x00A6, 0x00AC, 0x00F7, 0x00D7, 0xFEC9,
|
||||
0x0640, 0xFED3, 0xFED7, 0xFEDB, 0xFEDF, 0xFEE3, 0xFEE7, 0xFEEB, 0xFEED, 0xFEEF, 0xFEF3, 0xFEBD, 0xFECC, 0xFECE, 0xFECD, 0xFEE1,
|
||||
0xFE7D, 0x0651, 0xFEE5, 0xFEE9, 0xFEEC, 0xFEF0, 0xFEF2, 0xFED0, 0xFED5, 0xFEF5, 0xFEF6, 0xFEDD, 0xFED9, 0xFEF1, 0x25A0, 0x0000
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 865 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc865[] = { /* CP865(Nordic) to Unicode conversion table */
|
||||
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
|
||||
0x00C5, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192,
|
||||
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00A4,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
|
||||
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 866 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc866[] = { /* CP866(Russian) to Unicode conversion table */
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
|
||||
0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
#if FF_CODE_PAGE == 869 || FF_CODE_PAGE == 0
|
||||
static const WCHAR uc869[] = { /* CP869(Greek 2) to Unicode conversion table */
|
||||
0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x0386, 0x00B7, 0x00B7, 0x00AC, 0x00A6, 0x2018, 0x2019, 0x0388, 0x2015, 0x0389,
|
||||
0x038A, 0x03AA, 0x038C, 0x00B7, 0x00B7, 0x038E, 0x03AB, 0x00A9, 0x038F, 0x00B2, 0x00B3, 0x03AC, 0x00A3, 0x03AD, 0x03AE, 0x03AF,
|
||||
0x03CA, 0x0390, 0x03CC, 0x03CD, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x00BD, 0x0398, 0x0399, 0x00AB, 0x00BB,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x039A, 0x039B, 0x039C, 0x039D, 0x2563, 0x2551, 0x2557, 0x255D, 0x039E, 0x039F, 0x2510,
|
||||
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0A30, 0x03A1, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x03A3,
|
||||
0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x2518, 0x250C, 0x2588, 0x2584, 0x03B4, 0x03B5, 0x2580,
|
||||
0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x0384,
|
||||
0x00AD, 0x00B1, 0x03C5, 0x03C6, 0x03C7, 0x00A7, 0x03C8, 0x0385, 0x00B0, 0x00A8, 0x03C9, 0x03CB, 0x03B0, 0x03CE, 0x25A0, 0x00A0
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* OEM <==> Unicode conversions for static code page configuration */
|
||||
/* SBCS fixed code page */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
#if FF_CODE_PAGE != 0 && FF_CODE_PAGE < 900
|
||||
WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */
|
||||
DWORD uni, /* UTF-16 encoded character to be converted */
|
||||
WORD cp /* Code page for the conversion */
|
||||
)
|
||||
{
|
||||
WCHAR c = 0;
|
||||
const WCHAR *p = CVTBL(uc, FF_CODE_PAGE);
|
||||
|
||||
|
||||
if (uni < 0x80) { /* ASCII? */
|
||||
c = (WCHAR)uni;
|
||||
|
||||
} else { /* Non-ASCII */
|
||||
if (uni < 0x10000 && cp == FF_CODE_PAGE) { /* Is it in BMP and valid code page? */
|
||||
for (c = 0; c < 0x80 && uni != p[c]; c++) ;
|
||||
c = (c + 0x80) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
|
||||
WCHAR oem, /* OEM code to be converted */
|
||||
WORD cp /* Code page for the conversion */
|
||||
)
|
||||
{
|
||||
WCHAR c = 0;
|
||||
const WCHAR *p = CVTBL(uc, FF_CODE_PAGE);
|
||||
|
||||
|
||||
if (oem < 0x80) { /* ASCII? */
|
||||
c = oem;
|
||||
|
||||
} else { /* Extended char */
|
||||
if (cp == FF_CODE_PAGE) { /* Is it a valid code page? */
|
||||
if (oem < 0x100) c = p[oem - 0x80];
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* OEM <==> Unicode conversions for static code page configuration */
|
||||
/* DBCS fixed code page */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
#if FF_CODE_PAGE >= 900
|
||||
WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */
|
||||
DWORD uni, /* UTF-16 encoded character to be converted */
|
||||
WORD cp /* Code page for the conversion */
|
||||
)
|
||||
{
|
||||
const WCHAR *p;
|
||||
WCHAR c = 0, uc;
|
||||
UINT i = 0, n, li, hi;
|
||||
|
||||
|
||||
if (uni < 0x80) { /* ASCII? */
|
||||
c = (WCHAR)uni;
|
||||
|
||||
} else { /* Non-ASCII */
|
||||
if (uni < 0x10000 && cp == FF_CODE_PAGE) { /* Is it in BMP and valid code page? */
|
||||
uc = (WCHAR)uni;
|
||||
p = CVTBL(uni2oem, FF_CODE_PAGE);
|
||||
hi = sizeof CVTBL(uni2oem, FF_CODE_PAGE) / 4 - 1;
|
||||
li = 0;
|
||||
for (n = 16; n; n--) {
|
||||
i = li + (hi - li) / 2;
|
||||
if (uc == p[i * 2]) break;
|
||||
if (uc > p[i * 2]) {
|
||||
li = i;
|
||||
} else {
|
||||
hi = i;
|
||||
}
|
||||
}
|
||||
if (n != 0) c = p[i * 2 + 1];
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
|
||||
WCHAR oem, /* OEM code to be converted */
|
||||
WORD cp /* Code page for the conversion */
|
||||
)
|
||||
{
|
||||
const WCHAR *p;
|
||||
WCHAR c = 0;
|
||||
UINT i = 0, n, li, hi;
|
||||
|
||||
|
||||
if (oem < 0x80) { /* ASCII? */
|
||||
c = oem;
|
||||
|
||||
} else { /* Extended char */
|
||||
if (cp == FF_CODE_PAGE) { /* Is it valid code page? */
|
||||
p = CVTBL(oem2uni, FF_CODE_PAGE);
|
||||
hi = sizeof CVTBL(oem2uni, FF_CODE_PAGE) / 4 - 1;
|
||||
li = 0;
|
||||
for (n = 16; n; n--) {
|
||||
i = li + (hi - li) / 2;
|
||||
if (oem == p[i * 2]) break;
|
||||
if (oem > p[i * 2]) {
|
||||
li = i;
|
||||
} else {
|
||||
hi = i;
|
||||
}
|
||||
}
|
||||
if (n != 0) c = p[i * 2 + 1];
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* OEM <==> Unicode conversions for dynamic code page configuration */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
#if FF_CODE_PAGE == 0
|
||||
|
||||
static const WORD cp_code[] = { 437, 720, 737, 771, 775, 850, 852, 855, 857, 860, 861, 862, 863, 864, 865, 866, 869, 0};
|
||||
static const WCHAR* const cp_table[] = {uc437, uc720, uc737, uc771, uc775, uc850, uc852, uc855, uc857, uc860, uc861, uc862, uc863, uc864, uc865, uc866, uc869, 0};
|
||||
|
||||
|
||||
WCHAR ff_uni2oem ( /* Returns OEM code character, zero on error */
|
||||
DWORD uni, /* UTF-16 encoded character to be converted */
|
||||
WORD cp /* Code page for the conversion */
|
||||
)
|
||||
{
|
||||
const WCHAR *p;
|
||||
WCHAR c = 0, uc;
|
||||
UINT i, n, li, hi;
|
||||
|
||||
|
||||
if (uni < 0x80) { /* ASCII? */
|
||||
c = (WCHAR)uni;
|
||||
|
||||
} else { /* Non-ASCII */
|
||||
if (uni < 0x10000) { /* Is it in BMP? */
|
||||
uc = (WCHAR)uni;
|
||||
p = 0;
|
||||
if (cp < 900) { /* SBCS */
|
||||
for (i = 0; cp_code[i] != 0 && cp_code[i] != cp; i++) ; /* Get conversion table */
|
||||
p = cp_table[i];
|
||||
if (p) { /* Is it valid code page ? */
|
||||
for (c = 0; c < 0x80 && uc != p[c]; c++) ; /* Find OEM code in the table */
|
||||
c = (c + 0x80) & 0xFF;
|
||||
}
|
||||
} else { /* DBCS */
|
||||
switch (cp) { /* Get conversion table */
|
||||
case 932 : p = uni2oem932; hi = sizeof uni2oem932 / 4 - 1; break;
|
||||
case 936 : p = uni2oem936; hi = sizeof uni2oem936 / 4 - 1; break;
|
||||
case 949 : p = uni2oem949; hi = sizeof uni2oem949 / 4 - 1; break;
|
||||
case 950 : p = uni2oem950; hi = sizeof uni2oem950 / 4 - 1; break;
|
||||
}
|
||||
if (p) { /* Is it valid code page? */
|
||||
li = 0;
|
||||
for (n = 16; n; n--) { /* Find OEM code */
|
||||
i = li + (hi - li) / 2;
|
||||
if (uc == p[i * 2]) break;
|
||||
if (uc > p[i * 2]) {
|
||||
li = i;
|
||||
} else {
|
||||
hi = i;
|
||||
}
|
||||
}
|
||||
if (n != 0) c = p[i * 2 + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
WCHAR ff_oem2uni ( /* Returns Unicode character, zero on error */
|
||||
WCHAR oem, /* OEM code to be converted (DBC if >=0x100) */
|
||||
WORD cp /* Code page for the conversion */
|
||||
)
|
||||
{
|
||||
const WCHAR *p;
|
||||
WCHAR c = 0;
|
||||
UINT i, n, li, hi;
|
||||
|
||||
|
||||
if (oem < 0x80) { /* ASCII? */
|
||||
c = oem;
|
||||
|
||||
} else { /* Extended char */
|
||||
p = 0;
|
||||
if (cp < 900) { /* SBCS */
|
||||
for (i = 0; cp_code[i] != 0 && cp_code[i] != cp; i++) ; /* Get table */
|
||||
p = cp_table[i];
|
||||
if (p) { /* Is it a valid CP ? */
|
||||
if (oem < 0x100) c = p[oem - 0x80];
|
||||
}
|
||||
} else { /* DBCS */
|
||||
switch (cp) {
|
||||
case 932 : p = oem2uni932; hi = sizeof oem2uni932 / 4 - 1; break;
|
||||
case 936 : p = oem2uni936; hi = sizeof oem2uni936 / 4 - 1; break;
|
||||
case 949 : p = oem2uni949; hi = sizeof oem2uni949 / 4 - 1; break;
|
||||
case 950 : p = oem2uni950; hi = sizeof oem2uni950 / 4 - 1; break;
|
||||
}
|
||||
if (p) {
|
||||
li = 0;
|
||||
for (n = 16; n; n--) {
|
||||
i = li + (hi - li) / 2;
|
||||
if (oem == p[i * 2]) break;
|
||||
if (oem > p[i * 2]) {
|
||||
li = i;
|
||||
} else {
|
||||
hi = i;
|
||||
}
|
||||
}
|
||||
if (n != 0) c = p[i * 2 + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Unicode up-case conversion */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
DWORD ff_wtoupper ( /* Returns up-converted code point */
|
||||
DWORD uni /* Unicode code point to be up-converted */
|
||||
)
|
||||
{
|
||||
const WORD *p;
|
||||
WORD uc, bc, nc, cmd;
|
||||
static const WORD cvt1[] = { /* Compressed up conversion table for U+0000 - U+0FFF */
|
||||
/* Basic Latin */
|
||||
0x0061,0x031A,
|
||||
/* Latin-1 Supplement */
|
||||
0x00E0,0x0317,
|
||||
0x00F8,0x0307,
|
||||
0x00FF,0x0001,0x0178,
|
||||
/* Latin Extended-A */
|
||||
0x0100,0x0130,
|
||||
0x0132,0x0106,
|
||||
0x0139,0x0110,
|
||||
0x014A,0x012E,
|
||||
0x0179,0x0106,
|
||||
/* Latin Extended-B */
|
||||
0x0180,0x004D,0x0243,0x0181,0x0182,0x0182,0x0184,0x0184,0x0186,0x0187,0x0187,0x0189,0x018A,0x018B,0x018B,0x018D,0x018E,0x018F,0x0190,0x0191,0x0191,0x0193,0x0194,0x01F6,0x0196,0x0197,0x0198,0x0198,0x023D,0x019B,0x019C,0x019D,0x0220,0x019F,0x01A0,0x01A0,0x01A2,0x01A2,0x01A4,0x01A4,0x01A6,0x01A7,0x01A7,0x01A9,0x01AA,0x01AB,0x01AC,0x01AC,0x01AE,0x01AF,0x01AF,0x01B1,0x01B2,0x01B3,0x01B3,0x01B5,0x01B5,0x01B7,0x01B8,0x01B8,0x01BA,0x01BB,0x01BC,0x01BC,0x01BE,0x01F7,0x01C0,0x01C1,0x01C2,0x01C3,0x01C4,0x01C5,0x01C4,0x01C7,0x01C8,0x01C7,0x01CA,0x01CB,0x01CA,
|
||||
0x01CD,0x0110,
|
||||
0x01DD,0x0001,0x018E,
|
||||
0x01DE,0x0112,
|
||||
0x01F3,0x0003,0x01F1,0x01F4,0x01F4,
|
||||
0x01F8,0x0128,
|
||||
0x0222,0x0112,
|
||||
0x023A,0x0009,0x2C65,0x023B,0x023B,0x023D,0x2C66,0x023F,0x0240,0x0241,0x0241,
|
||||
0x0246,0x010A,
|
||||
/* IPA Extensions */
|
||||
0x0253,0x0040,0x0181,0x0186,0x0255,0x0189,0x018A,0x0258,0x018F,0x025A,0x0190,0x025C,0x025D,0x025E,0x025F,0x0193,0x0261,0x0262,0x0194,0x0264,0x0265,0x0266,0x0267,0x0197,0x0196,0x026A,0x2C62,0x026C,0x026D,0x026E,0x019C,0x0270,0x0271,0x019D,0x0273,0x0274,0x019F,0x0276,0x0277,0x0278,0x0279,0x027A,0x027B,0x027C,0x2C64,0x027E,0x027F,0x01A6,0x0281,0x0282,0x01A9,0x0284,0x0285,0x0286,0x0287,0x01AE,0x0244,0x01B1,0x01B2,0x0245,0x028D,0x028E,0x028F,0x0290,0x0291,0x01B7,
|
||||
/* Greek, Coptic */
|
||||
0x037B,0x0003,0x03FD,0x03FE,0x03FF,
|
||||
0x03AC,0x0004,0x0386,0x0388,0x0389,0x038A,
|
||||
0x03B1,0x0311,
|
||||
0x03C2,0x0002,0x03A3,0x03A3,
|
||||
0x03C4,0x0308,
|
||||
0x03CC,0x0003,0x038C,0x038E,0x038F,
|
||||
0x03D8,0x0118,
|
||||
0x03F2,0x000A,0x03F9,0x03F3,0x03F4,0x03F5,0x03F6,0x03F7,0x03F7,0x03F9,0x03FA,0x03FA,
|
||||
/* Cyrillic */
|
||||
0x0430,0x0320,
|
||||
0x0450,0x0710,
|
||||
0x0460,0x0122,
|
||||
0x048A,0x0136,
|
||||
0x04C1,0x010E,
|
||||
0x04CF,0x0001,0x04C0,
|
||||
0x04D0,0x0144,
|
||||
/* Armenian */
|
||||
0x0561,0x0426,
|
||||
|
||||
0x0000 /* EOT */
|
||||
};
|
||||
static const WORD cvt2[] = { /* Compressed up conversion table for U+1000 - U+FFFF */
|
||||
/* Phonetic Extensions */
|
||||
0x1D7D,0x0001,0x2C63,
|
||||
/* Latin Extended Additional */
|
||||
0x1E00,0x0196,
|
||||
0x1EA0,0x015A,
|
||||
/* Greek Extended */
|
||||
0x1F00,0x0608,
|
||||
0x1F10,0x0606,
|
||||
0x1F20,0x0608,
|
||||
0x1F30,0x0608,
|
||||
0x1F40,0x0606,
|
||||
0x1F51,0x0007,0x1F59,0x1F52,0x1F5B,0x1F54,0x1F5D,0x1F56,0x1F5F,
|
||||
0x1F60,0x0608,
|
||||
0x1F70,0x000E,0x1FBA,0x1FBB,0x1FC8,0x1FC9,0x1FCA,0x1FCB,0x1FDA,0x1FDB,0x1FF8,0x1FF9,0x1FEA,0x1FEB,0x1FFA,0x1FFB,
|
||||
0x1F80,0x0608,
|
||||
0x1F90,0x0608,
|
||||
0x1FA0,0x0608,
|
||||
0x1FB0,0x0004,0x1FB8,0x1FB9,0x1FB2,0x1FBC,
|
||||
0x1FCC,0x0001,0x1FC3,
|
||||
0x1FD0,0x0602,
|
||||
0x1FE0,0x0602,
|
||||
0x1FE5,0x0001,0x1FEC,
|
||||
0x1FF3,0x0001,0x1FFC,
|
||||
/* Letterlike Symbols */
|
||||
0x214E,0x0001,0x2132,
|
||||
/* Number forms */
|
||||
0x2170,0x0210,
|
||||
0x2184,0x0001,0x2183,
|
||||
/* Enclosed Alphanumerics */
|
||||
0x24D0,0x051A,
|
||||
0x2C30,0x042F,
|
||||
/* Latin Extended-C */
|
||||
0x2C60,0x0102,
|
||||
0x2C67,0x0106, 0x2C75,0x0102,
|
||||
/* Coptic */
|
||||
0x2C80,0x0164,
|
||||
/* Georgian Supplement */
|
||||
0x2D00,0x0826,
|
||||
/* Full-width */
|
||||
0xFF41,0x031A,
|
||||
|
||||
0x0000 /* EOT */
|
||||
};
|
||||
|
||||
|
||||
if (uni < 0x10000) { /* Is it in BMP? */
|
||||
uc = (WORD)uni;
|
||||
p = uc < 0x1000 ? cvt1 : cvt2;
|
||||
for (;;) {
|
||||
bc = *p++; /* Get the block base */
|
||||
if (bc == 0 || uc < bc) break; /* Not matched? */
|
||||
nc = *p++; cmd = nc >> 8; nc &= 0xFF; /* Get processing command and block size */
|
||||
if (uc < bc + nc) { /* In the block? */
|
||||
switch (cmd) {
|
||||
case 0: uc = p[uc - bc]; break; /* Table conversion */
|
||||
case 1: uc -= (uc - bc) & 1; break; /* Case pairs */
|
||||
case 2: uc -= 16; break; /* Shift -16 */
|
||||
case 3: uc -= 32; break; /* Shift -32 */
|
||||
case 4: uc -= 48; break; /* Shift -48 */
|
||||
case 5: uc -= 26; break; /* Shift -26 */
|
||||
case 6: uc += 8; break; /* Shift +8 */
|
||||
case 7: uc -= 80; break; /* Shift -80 */
|
||||
case 8: uc -= 0x1C60; break; /* Shift -0x1C60 */
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (cmd == 0) p += nc; /* Skip table if needed */
|
||||
}
|
||||
uni = uc;
|
||||
}
|
||||
|
||||
return uni;
|
||||
}
|
||||
|
||||
#endif /* #if FF_USE_LFN */
|
369
bdk/libs/lv_conf.h
Normal file
369
bdk/libs/lv_conf.h
Normal file
|
@ -0,0 +1,369 @@
|
|||
/*
|
||||
* Copyright (c) 2018 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LV_CONF_H
|
||||
#define LV_CONF_H
|
||||
|
||||
#include <utils/types.h>
|
||||
#include <memory_map.h>
|
||||
/*===================
|
||||
Dynamic memory
|
||||
*===================*/
|
||||
|
||||
/* Memory size which will be used by the library
|
||||
* to store the graphical objects and other data */
|
||||
#define LV_MEM_CUSTOM 0 /*1: use custom malloc/free, 0: use the built-in lv_mem_alloc/lv_mem_free*/
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
# define LV_MEM_SIZE NYX_LV_MEM_SZ /*Size memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
|
||||
# define LV_MEM_ATTR /*Complier prefix for big array declaration*/
|
||||
# define LV_MEM_ADR NYX_LV_MEM_ADR /*Set an address for memory pool instead of allocation it as an array. Can be in external SRAM too.*/
|
||||
# define LV_MEM_AUTO_DEFRAG 1 /*Automatically defrag on free*/
|
||||
#else /*LV_MEM_CUSTOM*/
|
||||
# define LV_MEM_CUSTOM_INCLUDE <mem/heap.h> /*Header for the dynamic memory function*/
|
||||
# define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/
|
||||
# define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/
|
||||
#endif /*LV_MEM_CUSTOM*/
|
||||
|
||||
/* Garbage Collector settings
|
||||
* Used if lvgl is binded to higher language and the memory is managed by that language */
|
||||
#define LV_ENABLE_GC 0
|
||||
#if LV_ENABLE_GC != 0
|
||||
# define LV_MEM_CUSTOM_REALLOC your_realloc /*Wrapper to realloc*/
|
||||
# define LV_MEM_CUSTOM_GET_SIZE your_mem_get_size /*Wrapper to lv_mem_get_size*/
|
||||
# define LV_GC_INCLUDE "gc.h" /*Include Garbage Collector related things*/
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
/*===================
|
||||
Graphical settings
|
||||
*===================*/
|
||||
|
||||
/* Horizontal and vertical resolution of the library.*/
|
||||
#define LV_HOR_RES (1280)
|
||||
#define LV_VER_RES (720)
|
||||
|
||||
/* Dot Per Inch: used to initialize default sizes. E.g. a button with width = LV_DPI / 2 -> half inch wide
|
||||
* (Not so important, you can adjust it to modify default sizes and spaces)*/
|
||||
#define LV_DPI 100
|
||||
|
||||
/* Enable anti-aliasing (lines, and radiuses will be smoothed) */
|
||||
#define LV_ANTIALIAS 1 /*1: Enable anti-aliasing*/
|
||||
|
||||
/*Screen refresh period in milliseconds*/
|
||||
#define LV_REFR_PERIOD 33
|
||||
|
||||
/*-----------------
|
||||
* VDB settings
|
||||
*----------------*/
|
||||
|
||||
/* VDB (Virtual Display Buffer) is an internal graphics buffer.
|
||||
* The GUI will be drawn into this buffer first and then
|
||||
* the buffer will be passed to your `disp_drv.disp_flush` function to
|
||||
* copy it to your frame buffer.
|
||||
* VDB is required for: buffered drawing, opacity, anti-aliasing and shadows
|
||||
* Learn more: https://docs.littlevgl.com/#Drawing*/
|
||||
|
||||
/* Size of the VDB in pixels. Typical size: ~1/10 screen. Must be >= LV_HOR_RES
|
||||
* Setting it to 0 will disable VDB and `disp_drv.disp_fill` and `disp_drv.disp_map` functions
|
||||
* will be called to draw to the frame buffer directly*/
|
||||
#define LV_VDB_SIZE (LV_VER_RES * LV_HOR_RES)
|
||||
|
||||
/* Bit-per-pixel of VDB. Useful for monochrome or non-standard color format displays.
|
||||
* Special formats are handled with `disp_drv.vdb_wr`)*/
|
||||
#define LV_VDB_PX_BPP LV_COLOR_SIZE /*LV_COLOR_SIZE comes from LV_COLOR_DEPTH below to set 8, 16 or 32 bit pixel size automatically */
|
||||
|
||||
/* Place VDB to a specific address (e.g. in external RAM)
|
||||
* 0: allocate automatically into RAM
|
||||
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
|
||||
#define LV_VDB_ADR NYX_LV_VDB_ADR
|
||||
|
||||
/* Use two Virtual Display buffers (VDB) to parallelize rendering and flushing
|
||||
* The flushing should use DMA to write the frame buffer in the background */
|
||||
#define LV_VDB_DOUBLE 0
|
||||
|
||||
/* Place VDB2 to a specific address (e.g. in external RAM)
|
||||
* 0: allocate automatically into RAM
|
||||
* LV_VDB_ADR_INV: to replace it later with `lv_vdb_set_adr()`*/
|
||||
#define LV_VDB2_ADR 0
|
||||
|
||||
/* Using true double buffering in `disp_drv.disp_flush` you will always get the image of the whole screen.
|
||||
* Your only task is to set the rendered image (`color_p` parameter) as frame buffer address or send it to your display.
|
||||
* The best if you do in the blank period of you display to avoid tearing effect.
|
||||
* Requires:
|
||||
* - LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES
|
||||
* - LV_VDB_DOUBLE = 1
|
||||
*/
|
||||
#define LV_VDB_TRUE_DOUBLE_BUFFERED 0
|
||||
|
||||
/*=================
|
||||
Misc. setting
|
||||
*=================*/
|
||||
|
||||
/*Input device settings*/
|
||||
#define LV_INDEV_READ_PERIOD 33 /*Input device read period in milliseconds*/
|
||||
#define LV_INDEV_POINT_MARKER 0 /*Mark the pressed points (required: USE_LV_REAL_DRAW = 1)*/
|
||||
#define LV_INDEV_DRAG_LIMIT 10 /*Drag threshold in pixels */
|
||||
#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */
|
||||
#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/
|
||||
#define LV_INDEV_LONG_PRESS_REP_TIME 1000 //Fix keyb /*Repeated trigger period in long press [ms] */
|
||||
|
||||
/*Color settings*/
|
||||
#define LV_COLOR_DEPTH 32 /*Color depth: 1/8/16/32*/
|
||||
#define LV_COLOR_16_SWAP 0 /*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/
|
||||
#define LV_COLOR_SCREEN_TRANSP 0 /*1: Enable screen transparency. Useful for OSD or other overlapping GUIs. Requires ARGB8888 colors*/
|
||||
#define LV_COLOR_TRANSP LV_COLOR_LIME /*Images pixels with this color will not be drawn (with chroma keying)*/
|
||||
|
||||
/*Text settings*/
|
||||
#define LV_TXT_UTF8 0 /*Enable UTF-8 coded Unicode character usage */
|
||||
#define LV_TXT_BREAK_CHARS " ,.;:-_" /*Can break texts on these chars*/
|
||||
#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */
|
||||
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */
|
||||
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */
|
||||
|
||||
/*Feature usage*/
|
||||
#define USE_LV_ANIMATION 1 /*1: Enable all animations*/
|
||||
#define USE_LV_SHADOW 1 /*1: Enable shadows*/
|
||||
#define USE_LV_GROUP 0 /*1: Enable object groups (for keyboards)*/
|
||||
#define USE_LV_GPU 0 /*1: Enable GPU interface*/
|
||||
#define USE_LV_REAL_DRAW 0 /*1: Enable function which draw directly to the frame buffer instead of VDB (required if LV_VDB_SIZE = 0)*/
|
||||
#define USE_LV_FILESYSTEM 0 /*1: Enable file system (might be required for images*/
|
||||
#define USE_LV_MULTI_LANG 0 /* Number of languages for labels to store (0: to disable this feature)*/
|
||||
|
||||
/*Compiler settings*/
|
||||
#define LV_ATTRIBUTE_TICK_INC /* Define a custom attribute to `lv_tick_inc` function */
|
||||
#define LV_ATTRIBUTE_TASK_HANDLER /* Define a custom attribute to `lv_task_handler` function */
|
||||
#define LV_COMPILER_VLA_SUPPORTED 1 /* 1: Variable length array is supported*/
|
||||
|
||||
/*HAL settings*/
|
||||
#define LV_TICK_CUSTOM 1 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */
|
||||
#if LV_TICK_CUSTOM == 1
|
||||
#define LV_TICK_CUSTOM_INCLUDE <utils/util.h> /*Header for the sys time function*/
|
||||
#define LV_TICK_CUSTOM_SYS_TIME_EXPR (get_tmr_ms()) /*Expression evaluating to current systime in ms*/
|
||||
#endif /*LV_TICK_CUSTOM*/
|
||||
|
||||
|
||||
/*Log settings*/
|
||||
#define USE_LV_LOG 0 /*Enable/disable the log module*/
|
||||
#if USE_LV_LOG
|
||||
/* How important log should be added:
|
||||
* LV_LOG_LEVEL_TRACE A lot of logs to give detailed information
|
||||
* LV_LOG_LEVEL_INFO Log important events
|
||||
* LV_LOG_LEVEL_WARN Log if something unwanted happened but didn't caused problem
|
||||
* LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail
|
||||
*/
|
||||
# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN
|
||||
/* 1: Print the log with 'printf'; 0: user need to register a callback*/
|
||||
# define LV_LOG_PRINTF 1
|
||||
#endif /*USE_LV_LOG*/
|
||||
|
||||
/*================
|
||||
* THEME USAGE
|
||||
*================*/
|
||||
#define LV_THEME_LIVE_UPDATE 0 /*1: Allow theme switching at run time. Uses 8..10 kB of RAM*/
|
||||
|
||||
#define USE_LV_THEME_HEKATE 1 /*Flat theme with bold colors and light shadows*/
|
||||
|
||||
/*==================
|
||||
* FONT USAGE
|
||||
*===================*/
|
||||
|
||||
/* More info about fonts: https://docs.littlevgl.com/#Fonts
|
||||
* To enable a built-in font use 1,2,4 or 8 values
|
||||
* which will determine the bit-per-pixel. Higher value means smoother fonts */
|
||||
#define LV_FONT_QUALITY 8
|
||||
|
||||
#define USE_UBUNTU_MONO LV_FONT_QUALITY
|
||||
|
||||
#define USE_INTERUI_20 LV_FONT_QUALITY
|
||||
#define USE_INTERUI_30 LV_FONT_QUALITY
|
||||
|
||||
#define USE_HEKATE_SYMBOL_20 USE_INTERUI_20
|
||||
#define USE_HEKATE_SYMBOL_30 USE_INTERUI_30
|
||||
#define USE_HEKATE_SYMBOL_120 LV_FONT_QUALITY
|
||||
|
||||
/* Optionally declare your custom fonts here.
|
||||
* You can use these fonts as default font too
|
||||
* and they will be available globally. E.g.
|
||||
* #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
|
||||
* LV_FONT_DECLARE(my_font_2) \
|
||||
*/
|
||||
#define LV_FONT_CUSTOM_DECLARE
|
||||
|
||||
#define LV_FONT_DEFAULT &interui_30 /*Always set a default font from the built-in fonts*/
|
||||
|
||||
/*===================
|
||||
* LV_OBJ SETTINGS
|
||||
*==================*/
|
||||
#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/
|
||||
#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/
|
||||
#define LV_OBJ_REALIGN 1 // 0 in OG gui /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
|
||||
|
||||
/*==================
|
||||
* LV OBJ X USAGE
|
||||
*================*/
|
||||
/*
|
||||
* Documentation of the object types: https://docs.littlevgl.com/#Object-types
|
||||
*/
|
||||
|
||||
/*****************
|
||||
* Simple object
|
||||
*****************/
|
||||
|
||||
/*Label (dependencies: -*/
|
||||
#define USE_LV_LABEL 1
|
||||
#if USE_LV_LABEL != 0
|
||||
# define LV_LABEL_SCROLL_SPEED 25 /*Hor, or ver. scroll speed [px/sec] in 'LV_LABEL_LONG_SCROLL/ROLL' mode*/
|
||||
#endif
|
||||
|
||||
/*Image (dependencies: lv_label*/
|
||||
#define USE_LV_IMG 1
|
||||
#if USE_LV_IMG != 0
|
||||
# define LV_IMG_CF_INDEXED 0 /*Enable indexed (palette) images*/
|
||||
# define LV_IMG_CF_ALPHA 0 /*Enable alpha indexed images*/
|
||||
#endif
|
||||
|
||||
/*Line (dependencies: -*/
|
||||
#define USE_LV_LINE 1
|
||||
|
||||
/*Arc (dependencies: -)*/
|
||||
#define USE_LV_ARC 0
|
||||
|
||||
/*******************
|
||||
* Container objects
|
||||
*******************/
|
||||
|
||||
/*Container (dependencies: -*/
|
||||
#define USE_LV_CONT 1
|
||||
|
||||
/*Page (dependencies: lv_cont)*/
|
||||
#define USE_LV_PAGE 1
|
||||
|
||||
/*Window (dependencies: lv_cont, lv_btn, lv_label, lv_img, lv_page)*/
|
||||
#define USE_LV_WIN 1
|
||||
|
||||
/*Tab (dependencies: lv_page, lv_btnm)*/
|
||||
#define USE_LV_TABVIEW 1
|
||||
# if USE_LV_TABVIEW != 0
|
||||
# define LV_TABVIEW_ANIM_TIME 0 /*Time of slide animation [ms] (0: no animation)*/
|
||||
#endif
|
||||
|
||||
/*Tileview (dependencies: lv_page) */
|
||||
#define USE_LV_TILEVIEW 0
|
||||
#if USE_LV_TILEVIEW
|
||||
# define LV_TILEVIEW_ANIM_TIME 0 /*Time of slide animation [ms] (0: no animation)*/
|
||||
#endif
|
||||
|
||||
/*************************
|
||||
* Data visualizer objects
|
||||
*************************/
|
||||
|
||||
/*Bar (dependencies: -)*/
|
||||
#define USE_LV_BAR 1
|
||||
|
||||
/*Line meter (dependencies: *;)*/
|
||||
#define USE_LV_LMETER 0
|
||||
|
||||
/*Gauge (dependencies:lv_bar, lv_lmeter)*/
|
||||
#define USE_LV_GAUGE 0
|
||||
|
||||
/*Chart (dependencies: -)*/
|
||||
#define USE_LV_CHART 0
|
||||
|
||||
/*Table (dependencies: lv_label)*/
|
||||
#define USE_LV_TABLE 1
|
||||
#if USE_LV_TABLE
|
||||
# define LV_TABLE_COL_MAX 12
|
||||
#endif
|
||||
|
||||
/*LED (dependencies: -)*/
|
||||
#define USE_LV_LED 0
|
||||
|
||||
/*Message box (dependencies: lv_rect, lv_btnm, lv_label)*/
|
||||
#define USE_LV_MBOX 1
|
||||
|
||||
/*Text area (dependencies: lv_label, lv_page)*/
|
||||
#define USE_LV_TA 1
|
||||
#if USE_LV_TA != 0
|
||||
# define LV_TA_CURSOR_BLINK_TIME 400 /*ms*/
|
||||
# define LV_TA_PWD_SHOW_TIME 1500 /*ms*/
|
||||
#endif
|
||||
|
||||
/*Spinbox (dependencies: lv_ta)*/
|
||||
#define USE_LV_SPINBOX 0
|
||||
|
||||
/*Calendar (dependencies: -)*/
|
||||
#define USE_LV_CALENDAR 0
|
||||
|
||||
/*Preload (dependencies: lv_arc)*/
|
||||
#define USE_LV_PRELOAD 0
|
||||
#if USE_LV_PRELOAD != 0
|
||||
# define LV_PRELOAD_DEF_ARC_LENGTH 60 /*[deg]*/
|
||||
# define LV_PRELOAD_DEF_SPIN_TIME 1000 /*[ms]*/
|
||||
# define LV_PRELOAD_DEF_ANIM LV_PRELOAD_TYPE_SPINNING_ARC
|
||||
#endif
|
||||
|
||||
/*Canvas (dependencies: lv_img)*/
|
||||
#define USE_LV_CANVAS 0
|
||||
/*************************
|
||||
* User input objects
|
||||
*************************/
|
||||
|
||||
/*Button (dependencies: lv_cont*/
|
||||
#define USE_LV_BTN 1
|
||||
#if USE_LV_BTN != 0
|
||||
# define LV_BTN_INK_EFFECT 0 /*Enable button-state animations - draw a circle on click (dependencies: USE_LV_ANIMATION)*/
|
||||
#endif
|
||||
|
||||
/*Image Button (dependencies: lv_btn*/
|
||||
#define USE_LV_IMGBTN 1
|
||||
#if USE_LV_IMGBTN
|
||||
# define LV_IMGBTN_TILED 0 /*1: The imgbtn requires left, mid and right parts and the width can be set freely*/
|
||||
#endif
|
||||
|
||||
/*Button matrix (dependencies: -)*/
|
||||
#define USE_LV_BTNM 1
|
||||
|
||||
/*Keyboard (dependencies: lv_btnm)*/
|
||||
#define USE_LV_KB 0
|
||||
|
||||
/*Check box (dependencies: lv_btn, lv_label)*/
|
||||
#define USE_LV_CB 1
|
||||
|
||||
/*List (dependencies: lv_page, lv_btn, lv_label, (lv_img optionally for icons ))*/
|
||||
#define USE_LV_LIST 1
|
||||
#if USE_LV_LIST != 0
|
||||
# define LV_LIST_FOCUS_TIME 100 /*Default animation time of focusing to a list element [ms] (0: no animation) */
|
||||
#endif
|
||||
|
||||
/*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/
|
||||
#define USE_LV_DDLIST 1
|
||||
#if USE_LV_DDLIST != 0
|
||||
# define LV_DDLIST_ANIM_TIME 100 /*Open and close default animation time [ms] (0: no animation)*/
|
||||
#endif
|
||||
|
||||
/*Roller (dependencies: lv_ddlist)*/
|
||||
#define USE_LV_ROLLER 1
|
||||
#if USE_LV_ROLLER != 0
|
||||
# define LV_ROLLER_ANIM_TIME 200 /*Focus animation time [ms] (0: no animation)*/
|
||||
#endif
|
||||
|
||||
/*Slider (dependencies: lv_bar)*/
|
||||
#define USE_LV_SLIDER 1
|
||||
|
||||
/*Switch (dependencies: lv_slider)*/
|
||||
#define USE_LV_SW 1
|
||||
|
||||
#endif /*LV_CONF_H*/
|
||||
|
46
bdk/libs/lvgl/docs/CODE_OF_CONDUCT.md
Normal file
46
bdk/libs/lvgl/docs/CODE_OF_CONDUCT.md
Normal file
|
@ -0,0 +1,46 @@
|
|||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [atom@github.com](mailto:atom@github.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
103
bdk/libs/lvgl/docs/CONTRIBUTING.md
Normal file
103
bdk/libs/lvgl/docs/CONTRIBUTING.md
Normal file
|
@ -0,0 +1,103 @@
|
|||
# Contributing to Littlev Graphics Library
|
||||
|
||||
**Welcome! It's glad to see that you are interested in contributing to LittlevGL! There are several types of task where you can help to build a better library! Let's see how to get started!**
|
||||
|
||||
|
||||
There are many different possibilities to join the community. If you have some time to work with us I'm sure you will find something that fits you! You can:
|
||||
- answer other's questions
|
||||
- report and/or fix bugs
|
||||
- suggest and/or implement new features
|
||||
- improve and/or translate the documentation
|
||||
- write a blog post about your experiences
|
||||
|
||||
But first, start with the most Frequently Asked Questions.
|
||||
|
||||
## FAQ about contributing
|
||||
|
||||
### What license does my code need to be under?
|
||||
|
||||
Any code added to LittlevGL must be licensed under [MIT](https://choosealicense.com/licenses/mit/) or another license that is fully compatible. Contributions under other licenses are highly likely to be rejected.
|
||||
|
||||
If you borrow code from another project, please make sure to add their copyright notice to your contribution.
|
||||
|
||||
### Where do I ask questions, give feedback, or report bugs?
|
||||
|
||||
We use the [forum](http://forum.littlevgl.com/) for questions, feature suggestions, and discussions.
|
||||
|
||||
We use [GitHub's issue tracker](https://github.com/littlevgl/lvgl/issues) to report bugs.
|
||||
|
||||
For both of these there are some rules:
|
||||
- Be kind and friendly.
|
||||
- Speak about one thing in one issue.
|
||||
- Give feedback and close the issue if your question is answered.
|
||||
- Explain exactly what you experience or expect. _"The button is not working"_ is not enough info to get help.
|
||||
- For most issues you should send an absolute minimal code example in order to reproduce the issue. Ideally this should be easily usable in the PC simulator.
|
||||
- Use [Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) to format your post.
|
||||
- If you don't get any answer in a week write a comment like "Can somebody help?". Maybe your issue wasn't noticed.
|
||||
|
||||
### How can I send fixes and improvements?
|
||||
Merging new code happens via Pull Requests. If you are still not familiar with the Pull Requests (PR for short) here is a quick guide about them:
|
||||
1. **Fork** the [lvgl repository](https://github.com/littlevgl/lvgl). To do this click the "Fork" button in the top right corner. It will "copy" the `lvgl` repository to your GitHub account (`https://github.com/your_name?tab=repositories`)
|
||||
2. **Clone** the forked repository and add your updates
|
||||
3. **Create a PR** on the GitHub on the page of you `lvgl` repository(`https://github.com/your_name/lvgl`) by hitting the "New pull request" button
|
||||
4. **Set the base branch**. It means where you want to merge your update. Bugfixes for the last release go to `master`, new features to the actual `dev-x.y` branch.
|
||||
5. **Describe** what is in the update. An example code is welcome if applicable.
|
||||
|
||||
Some advice:
|
||||
- If you are not sure about your fix or feature it's better to open an issue first, and discuss the details there.
|
||||
- Maybe your fix or update won't be perfect at first. Don't be afraid, just improve it and push the new commits. The PR will be updated accordingly.
|
||||
- If your update needs some extra work it's okay to say: _"I'm busy now and I will improve it soon"_ or _"Sorry, I don't have time to improve it, I hope it helps in this form too"_. So it's better to say don't have time to continue then saying nothing.
|
||||
- Please read and follow this [guide about the coding style](https://docs.littlevgl.com/#Coding-Style-Guide)
|
||||
|
||||
|
||||
### Where is the documentation?
|
||||
|
||||
You can read the documentation here: https://docs.littlevgl.com/
|
||||
You can edit the documentation here: https://github.com/littlevgl/doc
|
||||
|
||||
### Where is the blog?
|
||||
|
||||
You can read the blog here: https://blog.littlevgl.com/
|
||||
You can edit the blog here: https://github.com/littlevgl/blog
|
||||
|
||||
|
||||
## So how and where can I contribute?
|
||||
|
||||
### Answering other's questions
|
||||
|
||||
It's a great way to contribute to the library if you already use it. Just go the [issue tracker](https://github.com/littlevgl/lvgl/issues), read the titles and if you are already familiar with a topic, don't be shy, and write your suggestion.
|
||||
|
||||
### Reporting and/or fixing bugs
|
||||
For simple bugfixes (typos, missing error handling, fixing a warning) is fine to send a Pull request directly. However, for more complex bugs it's better to open an issue first. In the issue, you should describe how to reproduce the bug and even add the minimal code snippet.
|
||||
|
||||
### Suggesting and/or implementing new features
|
||||
If you have a good idea don't hesitate to share with us. It's even better if you have time to deal with its implementation. Don't be afraid if you still don't know LittlevGL well enough. We will help you to get started.
|
||||
|
||||
During the implementation don't forget the [Code style guide](https://docs.littlevgl.com/#Coding-Style-Guide).
|
||||
|
||||
### Improving and/or translating the documentation
|
||||
|
||||
The documentation of LittlevGL is written in Markdown and available [here](https://github.com/littlevgl/doc) for editing. If you find some parts of the documentation obscure or insufficient just search the related `.md` file, hit the edit icon and add your updates. This way a new Pull request will be generated automatically.
|
||||
|
||||
If you can devote more time to improve the documentation you can translate it!
|
||||
1. Just copy the English `.md` files from the root folder to `locale/LANGUAGE_CODE` (language code is e.g. DE, FR, ES etc)
|
||||
2. Append the language code the end of files (e.g. Welcome_fr.md)
|
||||
3. Update the filenames in `_Sidebar.md`
|
||||
4. Translate the page(s) you want
|
||||
5. Create a Pull request
|
||||
|
||||
### Writing a blog post about your experiences
|
||||
|
||||
Have ported LittlevGL to a new platform? Have you created a fancy GUI? Do you know a great trick?
|
||||
You can share your knowledge on LittelvGL's blog! It's super easy to add your own post:
|
||||
- Fork and clone the [blog repository](https://github.com/littlevgl/blog)
|
||||
- Add your post in Markdown to the `_posts` folder.
|
||||
- Store the images and other resources in a dedicated folder in `assets`
|
||||
- Create a Pull Request
|
||||
|
||||
The blog uses [Jekyll](https://jekyllrb.com/) to convert the `.md` files to a webpage. You can easily [run Jekyll offline](https://jekyllrb.com/docs/) to check your post before creating the Pull request
|
||||
|
||||
## Summary
|
||||
|
||||
I hope you have taken a liking to contribute to LittelvGL. A helpful and friendly community is waiting for you! :)
|
||||
|
1
bdk/libs/lvgl/docs/astyle_c
Normal file
1
bdk/libs/lvgl/docs/astyle_c
Normal file
|
@ -0,0 +1 @@
|
|||
--style=kr --convert-tabs --indent=spaces=4 --indent-switches --pad-oper --unpad-paren --align-pointer=middle --suffix=.bak --lineend=linux --min-conditional-indent=
|
1
bdk/libs/lvgl/docs/astyle_h
Normal file
1
bdk/libs/lvgl/docs/astyle_h
Normal file
|
@ -0,0 +1 @@
|
|||
--convert-tabs --indent=spaces=4
|
8
bdk/libs/lvgl/licence.txt
Normal file
8
bdk/libs/lvgl/licence.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
MIT licence
|
||||
Copyright (c) 2016 Gábor Kiss-Vámosi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
12
bdk/libs/lvgl/lv_core/lv_core.mk
Normal file
12
bdk/libs/lvgl/lv_core/lv_core.mk
Normal file
|
@ -0,0 +1,12 @@
|
|||
CSRCS += lv_group.c
|
||||
CSRCS += lv_indev.c
|
||||
CSRCS += lv_obj.c
|
||||
CSRCS += lv_refr.c
|
||||
CSRCS += lv_style.c
|
||||
CSRCS += lv_vdb.c
|
||||
CSRCS += lv_lang.c
|
||||
|
||||
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_core
|
||||
VPATH += :$(LVGL_DIR)/lvgl/lv_core
|
||||
|
||||
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core"
|
554
bdk/libs/lvgl/lv_core/lv_group.c
Normal file
554
bdk/libs/lvgl/lv_core/lv_group.c
Normal file
|
@ -0,0 +1,554 @@
|
|||
/**
|
||||
* @file lv_group.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_group.h"
|
||||
#if USE_LV_GROUP != 0
|
||||
#include <stddef.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void style_mod_def(lv_style_t * style);
|
||||
static void style_mod_edit_def(lv_style_t * style);
|
||||
static void lv_group_refocus(lv_group_t *g);
|
||||
static void obj_to_foreground(lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a new object group
|
||||
* @return pointer to the new object group
|
||||
*/
|
||||
lv_group_t * lv_group_create(void)
|
||||
{
|
||||
lv_group_t * group = lv_mem_alloc(sizeof(lv_group_t));
|
||||
lv_mem_assert(group);
|
||||
if(group == NULL) return NULL;
|
||||
lv_ll_init(&group->obj_ll, sizeof(lv_obj_t *));
|
||||
|
||||
group->style_mod = style_mod_def;
|
||||
group->style_mod_edit = style_mod_edit_def;
|
||||
group->obj_focus = NULL;
|
||||
group->frozen = 0;
|
||||
group->focus_cb = NULL;
|
||||
group->click_focus = 1;
|
||||
group->editing = 0;
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a group object
|
||||
* @param group pointer to a group
|
||||
*/
|
||||
void lv_group_del(lv_group_t * group)
|
||||
{
|
||||
/*Defocus the the currently focused object*/
|
||||
if(group->obj_focus != NULL) {
|
||||
(*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
|
||||
lv_obj_invalidate(*group->obj_focus);
|
||||
}
|
||||
|
||||
/*Remove the objects from the group*/
|
||||
lv_obj_t ** obj;
|
||||
LL_READ(group->obj_ll, obj) {
|
||||
(*obj)->group_p = NULL;
|
||||
}
|
||||
|
||||
lv_ll_clear(&(group->obj_ll));
|
||||
lv_mem_free(group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an object to a group
|
||||
* @param group pointer to a group
|
||||
* @param obj pointer to an object to add
|
||||
*/
|
||||
void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj)
|
||||
{
|
||||
if(group == NULL) return;
|
||||
|
||||
/*If the object is already in a group and focused then defocus it*/
|
||||
if(obj->group_p) {
|
||||
if(lv_obj_is_focused(obj)) {
|
||||
lv_group_refocus(obj->group_p);
|
||||
|
||||
LV_LOG_INFO("group: assign object to an other group");
|
||||
}
|
||||
}
|
||||
|
||||
obj->group_p = group;
|
||||
lv_obj_t ** next = lv_ll_ins_tail(&group->obj_ll);
|
||||
lv_mem_assert(next);
|
||||
if(next == NULL) return;
|
||||
*next = obj;
|
||||
|
||||
/* If the head and the tail is equal then there is only one object in the linked list.
|
||||
* In this case automatically activate it*/
|
||||
if(lv_ll_get_head(&group->obj_ll) == next) {
|
||||
lv_group_refocus(group);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an object from its group
|
||||
* @param obj pointer to an object to remove
|
||||
*/
|
||||
void lv_group_remove_obj(lv_obj_t * obj)
|
||||
{
|
||||
lv_group_t * g = obj->group_p;
|
||||
if(g == NULL) return;
|
||||
if(g->obj_focus == NULL) return; /*Just to be sure (Not possible if there is at least one object in the group)*/
|
||||
|
||||
/*Focus on the next object*/
|
||||
if(*g->obj_focus == obj) {
|
||||
/*If this is the only object in the group then focus to nothing.*/
|
||||
if(lv_ll_get_head(&g->obj_ll) == g->obj_focus && lv_ll_get_tail(&g->obj_ll) == g->obj_focus) {
|
||||
(*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
|
||||
}
|
||||
/*If there more objects in the group then focus to the next/prev object*/
|
||||
else {
|
||||
lv_group_refocus(g);
|
||||
}
|
||||
}
|
||||
|
||||
/* If the focuses object is still the same then it was the only object in the group but it will be deleted.
|
||||
* Set the `obj_focus` to NULL to get back to the initial state of the group with zero objects*/
|
||||
if(*g->obj_focus == obj) {
|
||||
g->obj_focus = NULL;
|
||||
}
|
||||
|
||||
/*Search the object and remove it from its group */
|
||||
lv_obj_t ** i;
|
||||
LL_READ(g->obj_ll, i) {
|
||||
if(*i == obj) {
|
||||
lv_ll_rem(&g->obj_ll, i);
|
||||
lv_mem_free(i);
|
||||
obj->group_p = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Focus on an object (defocus the current)
|
||||
* @param obj pointer to an object to focus on
|
||||
*/
|
||||
void lv_group_focus_obj(lv_obj_t * obj)
|
||||
{
|
||||
lv_group_t * g = obj->group_p;
|
||||
if(g == NULL) return;
|
||||
|
||||
if(g->frozen != 0) return;
|
||||
|
||||
/*On defocus edit mode must be leaved*/
|
||||
lv_group_set_editing(g, false);
|
||||
|
||||
lv_obj_t ** i;
|
||||
LL_READ(g->obj_ll, i) {
|
||||
if(*i == obj) {
|
||||
if(g->obj_focus == i) return; /*Don't focus the already focused object again*/
|
||||
if(g->obj_focus != NULL) {
|
||||
(*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
|
||||
lv_obj_invalidate(*g->obj_focus);
|
||||
}
|
||||
|
||||
g->obj_focus = i;
|
||||
|
||||
if(g->obj_focus != NULL) {
|
||||
(*g->obj_focus)->signal_func(*g->obj_focus, LV_SIGNAL_FOCUS, NULL);
|
||||
if(g->focus_cb) g->focus_cb(g);
|
||||
lv_obj_invalidate(*g->obj_focus);
|
||||
|
||||
/*If the object or its parent has `top == true` bring it to the foregorund*/
|
||||
obj_to_foreground(*g->obj_focus);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Focus the next object in a group (defocus the current)
|
||||
* @param group pointer to a group
|
||||
*/
|
||||
void lv_group_focus_next(lv_group_t * group)
|
||||
{
|
||||
if(group->frozen) return;
|
||||
|
||||
if(group->obj_focus) {
|
||||
(*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
|
||||
lv_obj_invalidate(*group->obj_focus);
|
||||
}
|
||||
|
||||
lv_obj_t ** obj_next;
|
||||
if(group->obj_focus == NULL) obj_next = lv_ll_get_head(&group->obj_ll);
|
||||
else obj_next = lv_ll_get_next(&group->obj_ll, group->obj_focus);
|
||||
|
||||
if(obj_next == NULL) {
|
||||
if(group->wrap) obj_next = lv_ll_get_head(&group->obj_ll);
|
||||
else obj_next = lv_ll_get_tail(&group->obj_ll);
|
||||
}
|
||||
group->obj_focus = obj_next;
|
||||
|
||||
if(group->obj_focus) {
|
||||
(*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_FOCUS, NULL);
|
||||
lv_obj_invalidate(*group->obj_focus);
|
||||
|
||||
if(group->focus_cb) group->focus_cb(group);
|
||||
|
||||
/*If the object or its parent has `top == true` bring it to the foregorund*/
|
||||
obj_to_foreground(*group->obj_focus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Focus the previous object in a group (defocus the current)
|
||||
* @param group pointer to a group
|
||||
*/
|
||||
void lv_group_focus_prev(lv_group_t * group)
|
||||
{
|
||||
if(group->frozen) return;
|
||||
|
||||
if(group->obj_focus) {
|
||||
(*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
|
||||
lv_obj_invalidate(*group->obj_focus);
|
||||
}
|
||||
|
||||
lv_obj_t ** obj_next;
|
||||
if(group->obj_focus == NULL) obj_next = lv_ll_get_tail(&group->obj_ll);
|
||||
else obj_next = lv_ll_get_prev(&group->obj_ll, group->obj_focus);
|
||||
|
||||
if(obj_next == NULL) {
|
||||
if(group->wrap) obj_next = lv_ll_get_tail(&group->obj_ll);
|
||||
else obj_next = lv_ll_get_head(&group->obj_ll);
|
||||
}
|
||||
group->obj_focus = obj_next;
|
||||
|
||||
if(group->obj_focus != NULL) {
|
||||
(*group->obj_focus)->signal_func(*group->obj_focus, LV_SIGNAL_FOCUS, NULL);
|
||||
lv_obj_invalidate(*group->obj_focus);
|
||||
|
||||
if(group->focus_cb) group->focus_cb(group);
|
||||
|
||||
/*If the object or its parent has `top == true` bring it to the foregorund*/
|
||||
obj_to_foreground(*group->obj_focus);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not let to change the focus from the current object
|
||||
* @param group pointer to a group
|
||||
* @param en true: freeze, false: release freezing (normal mode)
|
||||
*/
|
||||
void lv_group_focus_freeze(lv_group_t * group, bool en)
|
||||
{
|
||||
if(en == false) group->frozen = 0;
|
||||
else group->frozen = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a control character to the focuses object of a group
|
||||
* @param group pointer to a group
|
||||
* @param c a character (use LV_GROUP_KEY_.. to navigate)
|
||||
* @return result of focused object in group.
|
||||
*/
|
||||
lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c)
|
||||
{
|
||||
lv_obj_t * act = lv_group_get_focused(group);
|
||||
if(act == NULL) return LV_RES_OK;
|
||||
|
||||
return act->signal_func(act, LV_SIGNAL_CONTROLL, &c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function for a group which will modify the object's style if it is in focus
|
||||
* @param group pointer to a group
|
||||
* @param style_mod_func the style modifier function pointer
|
||||
*/
|
||||
void lv_group_set_style_mod_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func)
|
||||
{
|
||||
group->style_mod = style_mod_func;
|
||||
if(group->obj_focus != NULL) lv_obj_invalidate(*group->obj_focus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function for a group which will modify the object's style if it is in focus in edit mode
|
||||
* @param group pointer to a group
|
||||
* @param style_mod_func the style modifier function pointer
|
||||
*/
|
||||
void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func)
|
||||
{
|
||||
group->style_mod_edit = style_mod_func;
|
||||
if(group->obj_focus != NULL) lv_obj_invalidate(*group->obj_focus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function for a group which will be called when a new object is focused
|
||||
* @param group pointer to a group
|
||||
* @param focus_cb the call back function or NULL if unused
|
||||
*/
|
||||
void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb)
|
||||
{
|
||||
group->focus_cb = focus_cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually set the current mode (edit or navigate).
|
||||
* @param group pointer to group
|
||||
* @param edit: true: edit mode; false: navigate mode
|
||||
*/
|
||||
void lv_group_set_editing(lv_group_t * group, bool edit)
|
||||
{
|
||||
uint8_t en_val = edit ? 1 : 0;
|
||||
|
||||
if(en_val == group->editing) return; /*Do not set the same mode again*/
|
||||
|
||||
group->editing = en_val;
|
||||
lv_obj_t * focused = lv_group_get_focused(group);
|
||||
|
||||
if(focused) focused->signal_func(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again to properly leave edit mode*/
|
||||
|
||||
lv_obj_invalidate(focused);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked.
|
||||
* @param group pointer to group
|
||||
* @param en: true: enable `click_focus`
|
||||
*/
|
||||
void lv_group_set_click_focus(lv_group_t * group, bool en)
|
||||
{
|
||||
group->click_focus = en ? 1 : 0;
|
||||
}
|
||||
|
||||
void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy) {
|
||||
group->refocus_policy = policy & 0x01;
|
||||
}
|
||||
|
||||
static void lv_group_refocus(lv_group_t *g) {
|
||||
/*Refocus must temporarily allow wrapping to work correctly*/
|
||||
uint8_t temp_wrap = g->wrap;
|
||||
g->wrap = 1;
|
||||
|
||||
if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_NEXT)
|
||||
lv_group_focus_next(g);
|
||||
else if(g->refocus_policy == LV_GROUP_REFOCUS_POLICY_PREV)
|
||||
lv_group_focus_prev(g);
|
||||
/*Restore wrap property*/
|
||||
g->wrap = temp_wrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether focus next/prev will allow wrapping from first->last or last->first.
|
||||
* @param group pointer to group
|
||||
* @param en: true: enable `click_focus`
|
||||
*/
|
||||
void lv_group_set_wrap(lv_group_t * group, bool en)
|
||||
{
|
||||
group->wrap = en ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify a style with the set 'style_mod' function. The input style remains unchanged.
|
||||
* @param group pointer to group
|
||||
* @param style pointer to a style to modify
|
||||
* @return a copy of the input style but modified with the 'style_mod' function
|
||||
*/
|
||||
lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style)
|
||||
{
|
||||
lv_style_copy(&group->style_tmp, style);
|
||||
|
||||
if(group->editing) {
|
||||
if(group->style_mod_edit) group->style_mod_edit(&group->style_tmp);
|
||||
} else {
|
||||
if(group->style_mod) group->style_mod(&group->style_tmp);
|
||||
}
|
||||
return &group->style_tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the focused object or NULL if there isn't one
|
||||
* @param group pointer to a group
|
||||
* @return pointer to the focused object
|
||||
*/
|
||||
lv_obj_t * lv_group_get_focused(const lv_group_t * group)
|
||||
{
|
||||
if(!group) return NULL;
|
||||
if(group->obj_focus == NULL) return NULL;
|
||||
|
||||
return *group->obj_focus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a the style modifier function of a group
|
||||
* @param group pointer to a group
|
||||
* @return pointer to the style modifier function
|
||||
*/
|
||||
lv_group_style_mod_func_t lv_group_get_style_mod_cb(const lv_group_t * group)
|
||||
{
|
||||
if(!group) return false;
|
||||
return group->style_mod ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a the style modifier function of a group in edit mode
|
||||
* @param group pointer to a group
|
||||
* @return pointer to the style modifier function
|
||||
*/
|
||||
lv_group_style_mod_func_t lv_group_get_style_mod_edit_cb(const lv_group_t * group)
|
||||
{
|
||||
if(!group) return false;
|
||||
return group->style_mod_edit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the focus callback function of a group
|
||||
* @param group pointer to a group
|
||||
* @return the call back function or NULL if not set
|
||||
*/
|
||||
lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group)
|
||||
{
|
||||
if(!group) return false;
|
||||
return group->focus_cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current mode (edit or navigate).
|
||||
* @param group pointer to group
|
||||
* @return true: edit mode; false: navigate mode
|
||||
*/
|
||||
bool lv_group_get_editing(const lv_group_t * group)
|
||||
{
|
||||
if(!group) return false;
|
||||
return group->editing ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the `click_focus` attribute.
|
||||
* @param group pointer to group
|
||||
* @return true: `click_focus` is enabled; false: disabled
|
||||
*/
|
||||
bool lv_group_get_click_focus(const lv_group_t * group)
|
||||
{
|
||||
if(!group) return false;
|
||||
return group->click_focus ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether focus next/prev will allow wrapping from first->last or last->first object.
|
||||
* @param group pointer to group
|
||||
* @param en: true: wrapping enabled; false: wrapping disabled
|
||||
*/
|
||||
bool lv_group_get_wrap(lv_group_t * group)
|
||||
{
|
||||
if(!group) return false;
|
||||
return group->wrap ? true : false;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Default style modifier function
|
||||
* @param style pointer to a style to modify. (Typically group.style_tmp) It will be OVERWRITTEN.
|
||||
*/
|
||||
static void style_mod_def(lv_style_t * style)
|
||||
{
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
style->body.border.color = LV_COLOR_ORANGE;
|
||||
|
||||
/*If not empty or has border then emphasis the border*/
|
||||
if(style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
|
||||
|
||||
style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_ORANGE, LV_OPA_70);
|
||||
style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_ORANGE, LV_OPA_70);
|
||||
style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_ORANGE, LV_OPA_60);
|
||||
|
||||
style->text.color = lv_color_mix(style->text.color, LV_COLOR_ORANGE, LV_OPA_70);
|
||||
#else
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
style->body.border.color = LV_COLOR_BLACK;
|
||||
style->body.border.width = 2;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Default style modifier function
|
||||
* @param style pointer to a style to modify. (Typically group.style_tmp) It will be OVERWRITTEN.
|
||||
*/
|
||||
static void style_mod_edit_def(lv_style_t * style)
|
||||
{
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
style->body.border.color = LV_COLOR_GREEN;
|
||||
|
||||
/*If not empty or has border then emphasis the border*/
|
||||
if(style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
|
||||
|
||||
style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70);
|
||||
style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70);
|
||||
style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60);
|
||||
|
||||
style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70);
|
||||
#else
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
style->body.border.color = LV_COLOR_BLACK;
|
||||
style->body.border.width = 3;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static void obj_to_foreground(lv_obj_t * obj)
|
||||
{
|
||||
/*Search for 'top' attribute*/
|
||||
lv_obj_t * i = obj;
|
||||
lv_obj_t * last_top = NULL;
|
||||
while(i != NULL) {
|
||||
if(i->top != 0) last_top = i;
|
||||
i = lv_obj_get_parent(i);
|
||||
}
|
||||
|
||||
if(last_top != NULL) {
|
||||
/*Move the last_top object to the foreground*/
|
||||
lv_obj_t * par = lv_obj_get_parent(last_top);
|
||||
/*After list change it will be the new head*/
|
||||
lv_ll_chg_list(&par->child_ll, &par->child_ll, last_top);
|
||||
lv_obj_invalidate(last_top);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /*USE_LV_GROUP != 0*/
|
247
bdk/libs/lvgl/lv_core/lv_group.h
Normal file
247
bdk/libs/lvgl/lv_core/lv_group.h
Normal file
|
@ -0,0 +1,247 @@
|
|||
/**
|
||||
* @file lv_group.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_GROUP_H
|
||||
#define LV_GROUP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include "lv_obj.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
/*Predefined keys to control the focused object via lv_group_send(group, c)*/
|
||||
/*For compatibility in signal function define the keys regardless to LV_GROUP*/
|
||||
#define LV_GROUP_KEY_UP 17 /*0x11*/
|
||||
#define LV_GROUP_KEY_DOWN 18 /*0x12*/
|
||||
#define LV_GROUP_KEY_RIGHT 19 /*0x13*/
|
||||
#define LV_GROUP_KEY_LEFT 20 /*0x14*/
|
||||
#define LV_GROUP_KEY_ESC 27 /*0x1B*/
|
||||
#define LV_GROUP_KEY_DEL 127 /*0x7F*/
|
||||
#define LV_GROUP_KEY_BACKSPACE 8 /*0x08*/
|
||||
#define LV_GROUP_KEY_ENTER 10 /*0x0A, '\n'*/
|
||||
#define LV_GROUP_KEY_NEXT 9 /*0x09, '\t'*/
|
||||
#define LV_GROUP_KEY_PREV 11 /*0x0B, '*/
|
||||
|
||||
#if USE_LV_GROUP != 0
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
struct _lv_group_t;
|
||||
|
||||
typedef void (*lv_group_style_mod_func_t)(lv_style_t *);
|
||||
typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *);
|
||||
|
||||
typedef struct _lv_group_t
|
||||
{
|
||||
lv_ll_t obj_ll; /*Linked list to store the objects in the group */
|
||||
lv_obj_t ** obj_focus; /*The object in focus*/
|
||||
lv_group_style_mod_func_t style_mod; /*A function which modifies the style of the focused object*/
|
||||
lv_group_style_mod_func_t style_mod_edit;/*A function which modifies the style of the focused object*/
|
||||
lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/
|
||||
lv_style_t style_tmp; /*Stores the modified style of the focused object */
|
||||
uint8_t frozen :1; /*1: can't focus to new object*/
|
||||
uint8_t editing :1; /*1: Edit mode, 0: Navigate mode*/
|
||||
uint8_t click_focus :1; /*1: If an object in a group is clicked by an indev then it will be focused */
|
||||
uint8_t refocus_policy :1; /*1: Focus prev if focused on deletion. 0: Focus prev if focused on deletion.*/
|
||||
uint8_t wrap :1; /*1: Focus next/prev can wrap at end of list. 0: Focus next/prev stops at end of list.*/
|
||||
} lv_group_t;
|
||||
|
||||
typedef enum _lv_group_refocus_policy_t {
|
||||
LV_GROUP_REFOCUS_POLICY_NEXT = 0,
|
||||
LV_GROUP_REFOCUS_POLICY_PREV = 1
|
||||
} lv_group_refocus_policy_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a new object group
|
||||
* @return pointer to the new object group
|
||||
*/
|
||||
lv_group_t * lv_group_create(void);
|
||||
|
||||
/**
|
||||
* Delete a group object
|
||||
* @param group pointer to a group
|
||||
*/
|
||||
void lv_group_del(lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Add an object to a group
|
||||
* @param group pointer to a group
|
||||
* @param obj pointer to an object to add
|
||||
*/
|
||||
void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Remove an object from its group
|
||||
* @param obj pointer to an object to remove
|
||||
*/
|
||||
void lv_group_remove_obj(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Focus on an object (defocus the current)
|
||||
* @param obj pointer to an object to focus on
|
||||
*/
|
||||
void lv_group_focus_obj(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Focus the next object in a group (defocus the current)
|
||||
* @param group pointer to a group
|
||||
*/
|
||||
void lv_group_focus_next(lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Focus the previous object in a group (defocus the current)
|
||||
* @param group pointer to a group
|
||||
*/
|
||||
void lv_group_focus_prev(lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Do not let to change the focus from the current object
|
||||
* @param group pointer to a group
|
||||
* @param en true: freeze, false: release freezing (normal mode)
|
||||
*/
|
||||
void lv_group_focus_freeze(lv_group_t * group, bool en);
|
||||
|
||||
/**
|
||||
* Send a control character to the focuses object of a group
|
||||
* @param group pointer to a group
|
||||
* @param c a character (use LV_GROUP_KEY_.. to navigate)
|
||||
* @return result of focused object in group.
|
||||
*/
|
||||
lv_res_t lv_group_send_data(lv_group_t * group, uint32_t c);
|
||||
|
||||
/**
|
||||
* Set a function for a group which will modify the object's style if it is in focus
|
||||
* @param group pointer to a group
|
||||
* @param style_mod_func the style modifier function pointer
|
||||
*/
|
||||
void lv_group_set_style_mod_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func);
|
||||
|
||||
/**
|
||||
* Set a function for a group which will modify the object's style if it is in focus in edit mode
|
||||
* @param group pointer to a group
|
||||
* @param style_mod_func the style modifier function pointer
|
||||
*/
|
||||
void lv_group_set_style_mod_edit_cb(lv_group_t * group, lv_group_style_mod_func_t style_mod_func);
|
||||
|
||||
/**
|
||||
* Set a function for a group which will be called when a new object is focused
|
||||
* @param group pointer to a group
|
||||
* @param focus_cb the call back function or NULL if unused
|
||||
*/
|
||||
void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb);
|
||||
|
||||
/**
|
||||
* Set whether the next or previous item in a group is focused if the currently focussed obj is deleted.
|
||||
* @param group pointer to a group
|
||||
* @param new refocus policy enum
|
||||
*/
|
||||
void lv_group_set_refocus_policy(lv_group_t * group, lv_group_refocus_policy_t policy);
|
||||
|
||||
/**
|
||||
* Manually set the current mode (edit or navigate).
|
||||
* @param group pointer to group
|
||||
* @param edit: true: edit mode; false: navigate mode
|
||||
*/
|
||||
void lv_group_set_editing(lv_group_t * group, bool edit);
|
||||
|
||||
/**
|
||||
* Set the `click_focus` attribute. If enabled then the object will be focused then it is clicked.
|
||||
* @param group pointer to group
|
||||
* @param en: true: enable `click_focus`
|
||||
*/
|
||||
void lv_group_set_click_focus(lv_group_t * group, bool en);
|
||||
|
||||
/**
|
||||
* Set whether focus next/prev will allow wrapping from first->last or last->first object.
|
||||
* @param group pointer to group
|
||||
* @param en: true: wrapping enabled; false: wrapping disabled
|
||||
*/
|
||||
void lv_group_set_wrap(lv_group_t * group, bool en);
|
||||
|
||||
/**
|
||||
* Modify a style with the set 'style_mod' function. The input style remains unchanged.
|
||||
* @param group pointer to group
|
||||
* @param style pointer to a style to modify
|
||||
* @return a copy of the input style but modified with the 'style_mod' function
|
||||
*/
|
||||
lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style);
|
||||
|
||||
/**
|
||||
* Get the focused object or NULL if there isn't one
|
||||
* @param group pointer to a group
|
||||
* @return pointer to the focused object
|
||||
*/
|
||||
lv_obj_t * lv_group_get_focused(const lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Get a the style modifier function of a group
|
||||
* @param group pointer to a group
|
||||
* @return pointer to the style modifier function
|
||||
*/
|
||||
lv_group_style_mod_func_t lv_group_get_style_mod_cb(const lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Get a the style modifier function of a group in edit mode
|
||||
* @param group pointer to a group
|
||||
* @return pointer to the style modifier function
|
||||
*/
|
||||
lv_group_style_mod_func_t lv_group_get_style_mod_edit_cb(const lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Get the focus callback function of a group
|
||||
* @param group pointer to a group
|
||||
* @return the call back function or NULL if not set
|
||||
*/
|
||||
lv_group_focus_cb_t lv_group_get_focus_cb(const lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Get the current mode (edit or navigate).
|
||||
* @param group pointer to group
|
||||
* @return true: edit mode; false: navigate mode
|
||||
*/
|
||||
bool lv_group_get_editing(const lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Get the `click_focus` attribute.
|
||||
* @param group pointer to group
|
||||
* @return true: `click_focus` is enabled; false: disabled
|
||||
*/
|
||||
bool lv_group_get_click_focus(const lv_group_t * group);
|
||||
|
||||
/**
|
||||
* Get whether focus next/prev will allow wrapping from first->last or last->first object.
|
||||
* @param group pointer to group
|
||||
* @param en: true: wrapping enabled; false: wrapping disabled
|
||||
*/
|
||||
bool lv_group_get_wrap(lv_group_t * group);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_GROUP != 0*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_GROUP_H*/
|
971
bdk/libs/lvgl/lv_core/lv_indev.c
Normal file
971
bdk/libs/lvgl/lv_core/lv_indev.c
Normal file
|
@ -0,0 +1,971 @@
|
|||
/**
|
||||
* @file lv_indev_proc.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
********************/
|
||||
#include "lv_indev.h"
|
||||
|
||||
#include "../lv_hal/lv_hal_tick.h"
|
||||
#include "../lv_core/lv_group.h"
|
||||
#include "../lv_core/lv_refr.h"
|
||||
#include "../lv_misc/lv_task.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
#include "../lv_draw/lv_draw_rbasic.h"
|
||||
#include "lv_obj.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
#if LV_INDEV_DRAG_THROW <= 0
|
||||
#warning "LV_INDEV_DRAG_THROW must be greater than 0"
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
#if LV_INDEV_READ_PERIOD != 0
|
||||
static void indev_proc_task(void * param);
|
||||
static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data);
|
||||
static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data);
|
||||
static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data);
|
||||
static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data);
|
||||
static void indev_proc_press(lv_indev_proc_t * proc);
|
||||
static void indev_proc_release(lv_indev_proc_t * proc);
|
||||
static void indev_proc_reset_query_handler(lv_indev_t * indev);
|
||||
static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj);
|
||||
static void indev_drag(lv_indev_proc_t * state);
|
||||
static void indev_drag_throw(lv_indev_proc_t * state);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_indev_t * indev_act;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the display input device subsystem
|
||||
*/
|
||||
void lv_indev_init(void)
|
||||
{
|
||||
#if LV_INDEV_READ_PERIOD != 0
|
||||
lv_task_create(indev_proc_task, LV_INDEV_READ_PERIOD, LV_TASK_PRIO_MID, NULL);
|
||||
#endif
|
||||
|
||||
lv_indev_reset(NULL); /*Reset all input devices*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently processed input device. Can be used in action functions too.
|
||||
* @return pointer to the currently processed input device or NULL if no input device processing right now
|
||||
*/
|
||||
lv_indev_t * lv_indev_get_act(void)
|
||||
{
|
||||
return indev_act;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of an input device
|
||||
* @param indev pointer to an input device
|
||||
* @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`)
|
||||
*/
|
||||
lv_hal_indev_type_t lv_indev_get_type(const lv_indev_t * indev)
|
||||
{
|
||||
if(indev == NULL) return LV_INDEV_TYPE_NONE;
|
||||
|
||||
return indev->driver.type;
|
||||
}
|
||||
/**
|
||||
* Reset one or all input devices
|
||||
* @param indev pointer to an input device to reset or NULL to reset all of them
|
||||
*/
|
||||
void lv_indev_reset(lv_indev_t * indev)
|
||||
{
|
||||
if(indev) indev->proc.reset_query = 1;
|
||||
else {
|
||||
lv_indev_t * i = lv_indev_next(NULL);
|
||||
while(i) {
|
||||
i->proc.reset_query = 1;
|
||||
i = lv_indev_next(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the long press state of an input device
|
||||
* @param indev pointer to an input device
|
||||
*/
|
||||
void lv_indev_reset_lpr(lv_indev_t * indev)
|
||||
{
|
||||
indev->proc.long_pr_sent = 0;
|
||||
indev->proc.longpr_rep_timestamp = lv_tick_get();
|
||||
indev->proc.pr_timestamp = lv_tick_get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable input devices device by type
|
||||
* @param type Input device type
|
||||
* @param enable true: enable this type; false: disable this type
|
||||
*/
|
||||
void lv_indev_enable(lv_hal_indev_type_t type, bool enable)
|
||||
{
|
||||
lv_indev_t * i = lv_indev_next(NULL);
|
||||
|
||||
while(i) {
|
||||
if(i->driver.type == type) i->proc.disabled = enable == false ? 1 : 0;
|
||||
i = lv_indev_next(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON)
|
||||
* @param indev pointer to an input device
|
||||
* @param cur_obj pointer to an object to be used as cursor
|
||||
*/
|
||||
void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj)
|
||||
{
|
||||
if(indev->driver.type != LV_INDEV_TYPE_POINTER) return;
|
||||
|
||||
indev->cursor = cur_obj;
|
||||
if (indev->cursor)
|
||||
{
|
||||
lv_obj_set_parent(indev->cursor, lv_layer_sys());
|
||||
lv_obj_set_pos(indev->cursor, indev->proc.act_point.x, indev->proc.act_point.y);
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_LV_GROUP
|
||||
/**
|
||||
* Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD)
|
||||
* @param indev pointer to an input device
|
||||
* @param group point to a group
|
||||
*/
|
||||
void lv_indev_set_group(lv_indev_t * indev, lv_group_t * group)
|
||||
{
|
||||
if(indev->driver.type == LV_INDEV_TYPE_KEYPAD || indev->driver.type == LV_INDEV_TYPE_ENCODER) indev->group = group;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set the an array of points for LV_INDEV_TYPE_BUTTON.
|
||||
* These points will be assigned to the buttons to press a specific point on the screen
|
||||
* @param indev pointer to an input device
|
||||
* @param group point to a group
|
||||
*/
|
||||
void lv_indev_set_button_points(lv_indev_t * indev, const lv_point_t * points)
|
||||
{
|
||||
if(indev->driver.type == LV_INDEV_TYPE_BUTTON) indev->btn_points = points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set feedback callback for indev.
|
||||
* @param indev pointer to an input device
|
||||
* @param feedback feedback callback
|
||||
*/
|
||||
void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback)
|
||||
{
|
||||
indev->feedback = feedback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
|
||||
* @param indev pointer to an input device
|
||||
* @param point pointer to a point to store the result
|
||||
*/
|
||||
void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point)
|
||||
{
|
||||
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) {
|
||||
point->x = -1;
|
||||
point->y = -1;
|
||||
} else {
|
||||
point->x = indev->proc.act_point.x;
|
||||
point->y = indev->proc.act_point.y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD)
|
||||
* @param indev pointer to an input device
|
||||
* @return the last pressed key (0 on error)
|
||||
*/
|
||||
uint32_t lv_indev_get_key(const lv_indev_t * indev)
|
||||
{
|
||||
if(indev->driver.type != LV_INDEV_TYPE_KEYPAD) return 0;
|
||||
else return indev->proc.last_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is dragging with an input device or not (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
|
||||
* @param indev pointer to an input device
|
||||
* @return true: drag is in progress
|
||||
*/
|
||||
bool lv_indev_is_dragging(const lv_indev_t * indev)
|
||||
{
|
||||
if(indev == NULL) return false;
|
||||
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) return false;
|
||||
return indev->proc.drag_in_prog == 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vector of dragging of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
|
||||
* @param indev pointer to an input device
|
||||
* @param point pointer to a point to store the vector
|
||||
*/
|
||||
void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point)
|
||||
{
|
||||
if(indev == NULL) {
|
||||
point->x = 0;
|
||||
point->y = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) {
|
||||
point->x = 0;
|
||||
point->y = 0;
|
||||
} else {
|
||||
point->x = indev->proc.vect.x;
|
||||
point->y = indev->proc.vect.y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get elapsed time since last press
|
||||
* @param indev pointer to an input device (NULL to get the overall smallest inactivity)
|
||||
* @return Elapsed ticks (milliseconds) since last press
|
||||
*/
|
||||
uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev)
|
||||
{
|
||||
uint32_t t;
|
||||
|
||||
if(indev) return t = lv_tick_elaps(indev->last_activity_time);
|
||||
|
||||
lv_indev_t * i;
|
||||
t = UINT16_MAX;
|
||||
i = lv_indev_next(NULL);
|
||||
while(i) {
|
||||
t = LV_MATH_MIN(t, lv_tick_elaps(i->last_activity_time));
|
||||
i = lv_indev_next(i);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get feedback callback for indev.
|
||||
* @param indev pointer to an input device
|
||||
* @return feedback callback
|
||||
*/
|
||||
lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev)
|
||||
{
|
||||
return indev->feedback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do nothing until the next release
|
||||
* @param indev pointer to an input device
|
||||
*/
|
||||
void lv_indev_wait_release(lv_indev_t * indev)
|
||||
{
|
||||
indev->proc.wait_unil_release = 1;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#if LV_INDEV_READ_PERIOD != 0
|
||||
/**
|
||||
* Called periodically to handle the input devices
|
||||
* @param param unused
|
||||
*/
|
||||
static void indev_proc_task(void * param)
|
||||
{
|
||||
(void)param;
|
||||
|
||||
|
||||
LV_LOG_TRACE("indev task started");
|
||||
|
||||
lv_indev_data_t data;
|
||||
lv_indev_t * i;
|
||||
i = lv_indev_next(NULL);
|
||||
|
||||
/*Read and process all indevs*/
|
||||
while(i) {
|
||||
indev_act = i;
|
||||
|
||||
/*Handle reset query before processing the point*/
|
||||
indev_proc_reset_query_handler(i);
|
||||
|
||||
if(i->proc.disabled == 0) {
|
||||
bool more_to_read;
|
||||
do {
|
||||
/*Read the data*/
|
||||
more_to_read = lv_indev_read(i, &data);
|
||||
indev_proc_reset_query_handler(i); /*The active object might deleted even in the read function*/
|
||||
i->proc.state = data.state;
|
||||
|
||||
if(i->proc.state == LV_INDEV_STATE_PR) {
|
||||
i->last_activity_time = lv_tick_get();
|
||||
}
|
||||
|
||||
if(i->driver.type == LV_INDEV_TYPE_POINTER) {
|
||||
indev_pointer_proc(i, &data);
|
||||
} else if(i->driver.type == LV_INDEV_TYPE_KEYPAD) {
|
||||
indev_keypad_proc(i, &data);
|
||||
} else if(i->driver.type == LV_INDEV_TYPE_ENCODER) {
|
||||
indev_encoder_proc(i, &data);
|
||||
} else if(i->driver.type == LV_INDEV_TYPE_BUTTON) {
|
||||
indev_button_proc(i, &data);
|
||||
}
|
||||
/*Handle reset query if it happened in during processing*/
|
||||
indev_proc_reset_query_handler(i);
|
||||
} while(more_to_read);
|
||||
}
|
||||
i = lv_indev_next(i); /*Go to the next indev*/
|
||||
}
|
||||
|
||||
indev_act = NULL; /*End of indev processing, so no act indev*/
|
||||
|
||||
LV_LOG_TRACE("indev task finished");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process a new point from LV_INDEV_TYPE_POINTER input device
|
||||
* @param i pointer to an input device
|
||||
* @param data pointer to the data read from the input device
|
||||
*/
|
||||
static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
{
|
||||
/*Move the cursor if set and moved*/
|
||||
if(i->cursor != NULL &&
|
||||
(i->proc.last_point.x != data->point.x ||
|
||||
i->proc.last_point.y != data->point.y)) {
|
||||
/*Use cursor's center as pointer*/
|
||||
uint32_t off_x = lv_obj_get_width(i->cursor) >> 1;
|
||||
uint32_t off_y = lv_obj_get_height(i->cursor) >> 1;
|
||||
lv_obj_set_pos(i->cursor, data->point.x - off_x, data->point.y - off_y);
|
||||
}
|
||||
|
||||
i->proc.act_point.x = data->point.x;
|
||||
i->proc.act_point.y = data->point.y;
|
||||
|
||||
if(i->proc.state == LV_INDEV_STATE_PR) {
|
||||
#if LV_INDEV_POINT_MARKER != 0
|
||||
lv_area_t area;
|
||||
area.x1 = i->proc.act_point.x - (LV_INDEV_POINT_MARKER >> 1);
|
||||
area.y1 = i->proc.act_point.y - (LV_INDEV_POINT_MARKER >> 1);
|
||||
area.x2 = i->proc.act_point.x + ((LV_INDEV_POINT_MARKER >> 1) | 0x1);
|
||||
area.y2 = i->proc.act_point.y + ((LV_INDEV_POINT_MARKER >> 1) | 0x1);
|
||||
lv_rfill(&area, NULL, LV_COLOR_MAKE(0xFF, 0, 0), LV_OPA_COVER);
|
||||
#endif
|
||||
indev_proc_press(&i->proc);
|
||||
} else {
|
||||
indev_proc_release(&i->proc);
|
||||
}
|
||||
|
||||
i->proc.last_point.x = i->proc.act_point.x;
|
||||
i->proc.last_point.y = i->proc.act_point.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a new point from LV_INDEV_TYPE_KEYPAD input device
|
||||
* @param i pointer to an input device
|
||||
* @param data pointer to the data read from the input device
|
||||
*/
|
||||
static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
{
|
||||
#if USE_LV_GROUP
|
||||
if(i->group == NULL) return;
|
||||
|
||||
/*Key press happened*/
|
||||
if(data->state == LV_INDEV_STATE_PR &&
|
||||
i->proc.last_state == LV_INDEV_STATE_REL) {
|
||||
i->proc.pr_timestamp = lv_tick_get();
|
||||
lv_obj_t * focused = lv_group_get_focused(i->group);
|
||||
if(focused && data->key == LV_GROUP_KEY_ENTER) {
|
||||
focused->signal_func(focused, LV_SIGNAL_PRESSED, indev_act);
|
||||
}
|
||||
}
|
||||
/*Pressing*/
|
||||
else if(data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_PR) {
|
||||
if(data->key == LV_GROUP_KEY_ENTER &&
|
||||
i->proc.long_pr_sent == 0 &&
|
||||
lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) {
|
||||
/*On enter long press leave edit mode.*/
|
||||
lv_obj_t * focused = lv_group_get_focused(i->group);
|
||||
if(focused) {
|
||||
focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
|
||||
i->proc.long_pr_sent = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*Release happened*/
|
||||
else if(data->state == LV_INDEV_STATE_REL && i->proc.last_state == LV_INDEV_STATE_PR) {
|
||||
/*The user might clear the key when it was released. Always release the pressed key*/
|
||||
data->key = i->proc.last_key;
|
||||
|
||||
/* Edit mode is not used by KEYPAD devices.
|
||||
* So leave edit mode if we are in it before focusing on the next/prev object*/
|
||||
if(data->key == LV_GROUP_KEY_NEXT || data->key == LV_GROUP_KEY_PREV) {
|
||||
lv_group_set_editing(i->group, false);
|
||||
}
|
||||
|
||||
if(data->key == LV_GROUP_KEY_NEXT) {
|
||||
lv_group_focus_next(i->group);
|
||||
} else if(data->key == LV_GROUP_KEY_PREV) {
|
||||
lv_group_focus_prev(i->group);
|
||||
} else if(data->key == LV_GROUP_KEY_ENTER) {
|
||||
if(!i->proc.long_pr_sent) {
|
||||
lv_group_send_data(i->group, data->key);
|
||||
}
|
||||
} else {
|
||||
lv_group_send_data(i->group, data->key);
|
||||
}
|
||||
|
||||
if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/
|
||||
|
||||
i->proc.pr_timestamp = 0;
|
||||
i->proc.long_pr_sent = 0;
|
||||
}
|
||||
|
||||
i->proc.last_state = data->state;
|
||||
i->proc.last_key = data->key;
|
||||
#else
|
||||
(void)data; /*Unused*/
|
||||
(void)i; /*Unused*/
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a new point from LV_INDEV_TYPE_ENCODER input device
|
||||
* @param i pointer to an input device
|
||||
* @param data pointer to the data read from the input device
|
||||
*/
|
||||
static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
{
|
||||
#if USE_LV_GROUP
|
||||
if(i->group == NULL) return;
|
||||
|
||||
/*Process the steps first. They are valid only with released button*/
|
||||
if(data->state == LV_INDEV_STATE_REL) {
|
||||
/*In edit mode send LEFT/RIGHT keys*/
|
||||
if(lv_group_get_editing(i->group)) {
|
||||
int32_t s;
|
||||
if(data->enc_diff < 0) {
|
||||
for(s = 0; s < -data->enc_diff; s++) lv_group_send_data(i->group, LV_GROUP_KEY_LEFT);
|
||||
} else if(data->enc_diff > 0) {
|
||||
for(s = 0; s < data->enc_diff; s++) lv_group_send_data(i->group, LV_GROUP_KEY_RIGHT);
|
||||
}
|
||||
}
|
||||
/*In navigate mode focus on the next/prev objects*/
|
||||
else {
|
||||
int32_t s;
|
||||
if(data->enc_diff < 0) {
|
||||
for(s = 0; s < -data->enc_diff; s++) lv_group_focus_prev(i->group);
|
||||
} else if(data->enc_diff > 0) {
|
||||
for(s = 0; s < data->enc_diff; s++) lv_group_focus_next(i->group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Key press happened*/
|
||||
if(data->state == LV_INDEV_STATE_PR &&
|
||||
i->proc.last_state == LV_INDEV_STATE_REL) {
|
||||
i->proc.pr_timestamp = lv_tick_get();
|
||||
}
|
||||
/*Pressing*/
|
||||
else if(data->state == LV_INDEV_STATE_PR && i->proc.last_state == LV_INDEV_STATE_PR) {
|
||||
if(i->proc.long_pr_sent == 0 &&
|
||||
lv_tick_elaps(i->proc.pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) {
|
||||
/*On enter long press leave edit mode.*/
|
||||
lv_obj_t * focused = lv_group_get_focused(i->group);
|
||||
|
||||
bool editable = false;
|
||||
if(focused) focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable);
|
||||
|
||||
if(editable) {
|
||||
if(i->group->obj_ll.head != i->group->obj_ll.tail)
|
||||
lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/
|
||||
else if(focused)
|
||||
focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
|
||||
}
|
||||
/*If not editable then just send a long press signal*/
|
||||
else {
|
||||
if(focused)
|
||||
focused->signal_func(focused, LV_SIGNAL_LONG_PRESS, indev_act);
|
||||
}
|
||||
i->proc.long_pr_sent = 1;
|
||||
}
|
||||
}
|
||||
/*Release happened*/
|
||||
else if(data->state == LV_INDEV_STATE_REL && i->proc.last_state == LV_INDEV_STATE_PR) {
|
||||
lv_obj_t * focused = lv_group_get_focused(i->group);
|
||||
bool editable = false;
|
||||
if(focused) focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable);
|
||||
|
||||
/*The button was released on a non-editable object. Just send enter*/
|
||||
if(!editable) {
|
||||
lv_group_send_data(i->group, LV_GROUP_KEY_ENTER);
|
||||
}
|
||||
/*An object is being edited and the button is releases. Just send enter */
|
||||
else if(i->group->editing) {
|
||||
if(!i->proc.long_pr_sent || i->group->obj_ll.head == i->group->obj_ll.tail)
|
||||
lv_group_send_data(i->group, LV_GROUP_KEY_ENTER); /*Ignore long pressed enter release because it comes from mode switch*/
|
||||
}
|
||||
/*If the focused object is editable and now in navigate mode then enter edit mode*/
|
||||
else if(editable && !i->group->editing && !i->proc.long_pr_sent) {
|
||||
lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/
|
||||
}
|
||||
|
||||
if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/
|
||||
|
||||
i->proc.pr_timestamp = 0;
|
||||
i->proc.long_pr_sent = 0;
|
||||
}
|
||||
|
||||
i->proc.last_state = data->state;
|
||||
i->proc.last_key = data->key;
|
||||
#else
|
||||
(void)data; /*Unused*/
|
||||
(void)i; /*Unused*/
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Process new points from a input device. indev->state.pressed has to be set
|
||||
* @param indev pointer to an input device state
|
||||
* @param x x coordinate of the next point
|
||||
* @param y y coordinate of the next point
|
||||
*/
|
||||
static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
{
|
||||
i->proc.act_point.x = i->btn_points[data->btn].x;
|
||||
i->proc.act_point.y = i->btn_points[data->btn].y;
|
||||
|
||||
/*Still the same point is pressed*/
|
||||
if(i->proc.last_point.x == i->proc.act_point.x &&
|
||||
i->proc.last_point.y == i->proc.act_point.y &&
|
||||
data->state == LV_INDEV_STATE_PR) {
|
||||
#if LV_INDEV_POINT_MARKER != 0
|
||||
lv_area_t area;
|
||||
area.x1 = i->proc.act_point.x - (LV_INDEV_POINT_MARKER >> 1);
|
||||
area.y1 = i->proc.act_point.y - (LV_INDEV_POINT_MARKER >> 1);
|
||||
area.x2 = i->proc.act_point.x + ((LV_INDEV_POINT_MARKER >> 1) | 0x1);
|
||||
area.y2 = i->proc.act_point.y + ((LV_INDEV_POINT_MARKER >> 1) | 0x1);
|
||||
lv_rfill(&area, NULL, LV_COLOR_MAKE(0xFF, 0, 0), LV_OPA_COVER);
|
||||
#endif
|
||||
indev_proc_press(&i->proc);
|
||||
} else {
|
||||
/*If a new point comes always make a release*/
|
||||
indev_proc_release(&i->proc);
|
||||
}
|
||||
|
||||
i->proc.last_point.x = i->proc.act_point.x;
|
||||
i->proc.last_point.y = i->proc.act_point.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the pressed state of LV_INDEV_TYPE_POINER input devices
|
||||
* @param indev pointer to an input device 'proc'
|
||||
*/
|
||||
static void indev_proc_press(lv_indev_proc_t * proc)
|
||||
{
|
||||
lv_obj_t * pr_obj = proc->act_obj;
|
||||
|
||||
if(proc->wait_unil_release != 0) return;
|
||||
|
||||
/*If there is no last object then search*/
|
||||
if(proc->act_obj == NULL) {
|
||||
pr_obj = indev_search_obj(proc, lv_layer_top());
|
||||
if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act());
|
||||
}
|
||||
/*If there is last object but it is not dragged and not protected also search*/
|
||||
else if(proc->drag_in_prog == 0 &&
|
||||
lv_obj_is_protected(proc->act_obj, LV_PROTECT_PRESS_LOST) == false) {/*Now act_obj != NULL*/
|
||||
pr_obj = indev_search_obj(proc, lv_layer_top());
|
||||
if(pr_obj == NULL) pr_obj = indev_search_obj(proc, lv_scr_act());
|
||||
}
|
||||
/*If a dragable or a protected object was the last then keep it*/
|
||||
else {
|
||||
|
||||
}
|
||||
|
||||
/*If a new object was found reset some variables and send a pressed signal*/
|
||||
if(pr_obj != proc->act_obj) {
|
||||
|
||||
proc->last_point.x = proc->act_point.x;
|
||||
proc->last_point.y = proc->act_point.y;
|
||||
|
||||
/*If a new object found the previous was lost, so send a signal*/
|
||||
if(proc->act_obj != NULL) {
|
||||
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESS_LOST, indev_act);
|
||||
if(proc->reset_query != 0) return;
|
||||
}
|
||||
|
||||
proc->act_obj = pr_obj; /*Save the pressed object*/
|
||||
proc->last_obj = proc->act_obj; /*Refresh the last_obj*/
|
||||
|
||||
if(proc->act_obj != NULL) {
|
||||
/* Save the time when the obj pressed.
|
||||
* It is necessary to count the long press time.*/
|
||||
proc->pr_timestamp = lv_tick_get();
|
||||
proc->long_pr_sent = 0;
|
||||
proc->drag_range_out = 0;
|
||||
proc->drag_in_prog = 0;
|
||||
proc->drag_sum.x = 0;
|
||||
proc->drag_sum.y = 0;
|
||||
proc->vect.x = 0;
|
||||
proc->vect.y = 0;
|
||||
|
||||
/*Search for 'top' attribute*/
|
||||
lv_obj_t * i = proc->act_obj;
|
||||
lv_obj_t * last_top = NULL;
|
||||
while(i != NULL) {
|
||||
if(i->top != 0) last_top = i;
|
||||
i = lv_obj_get_parent(i);
|
||||
}
|
||||
|
||||
if(last_top != NULL) {
|
||||
/*Move the last_top object to the foreground*/
|
||||
lv_obj_t * par = lv_obj_get_parent(last_top);
|
||||
/*After list change it will be the new head*/
|
||||
lv_ll_chg_list(&par->child_ll, &par->child_ll, last_top);
|
||||
lv_obj_invalidate(last_top);
|
||||
}
|
||||
|
||||
/*Send a signal about the press*/
|
||||
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESSED, indev_act);
|
||||
if(proc->reset_query != 0) return;
|
||||
}
|
||||
}
|
||||
|
||||
/*Calculate the vector*/
|
||||
proc->vect.x = proc->act_point.x - proc->last_point.x;
|
||||
proc->vect.y = proc->act_point.y - proc->last_point.y;
|
||||
|
||||
/*If there is active object and it can be dragged run the drag*/
|
||||
if(proc->act_obj != NULL) {
|
||||
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESSING, indev_act);
|
||||
if(proc->reset_query != 0) return;
|
||||
|
||||
indev_drag(proc);
|
||||
if(proc->reset_query != 0) return;
|
||||
|
||||
/*If there is no drag then check for long press time*/
|
||||
if(proc->drag_in_prog == 0 && proc->long_pr_sent == 0) {
|
||||
/*Send a signal about the long press if enough time elapsed*/
|
||||
if(lv_tick_elaps(proc->pr_timestamp) > LV_INDEV_LONG_PRESS_TIME) {
|
||||
pr_obj->signal_func(pr_obj, LV_SIGNAL_LONG_PRESS, indev_act);
|
||||
if(proc->reset_query != 0) return;
|
||||
|
||||
/*Mark the signal sending to do not send it again*/
|
||||
proc->long_pr_sent = 1;
|
||||
|
||||
/*Save the long press time stamp for the long press repeat handler*/
|
||||
proc->longpr_rep_timestamp = lv_tick_get();
|
||||
}
|
||||
}
|
||||
/*Send long press repeated signal*/
|
||||
if(proc->drag_in_prog == 0 && proc->long_pr_sent == 1) {
|
||||
/*Send a signal about the long press repeate if enough time elapsed*/
|
||||
if(lv_tick_elaps(proc->longpr_rep_timestamp) > LV_INDEV_LONG_PRESS_REP_TIME) {
|
||||
pr_obj->signal_func(pr_obj, LV_SIGNAL_LONG_PRESS_REP, indev_act);
|
||||
if(proc->reset_query != 0) return;
|
||||
proc->longpr_rep_timestamp = lv_tick_get();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the released state of LV_INDEV_TYPE_POINER input devices
|
||||
* @param proc pointer to an input device 'proc'
|
||||
*/
|
||||
static void indev_proc_release(lv_indev_proc_t * proc)
|
||||
{
|
||||
if(proc->wait_unil_release != 0) {
|
||||
proc->act_obj = NULL;
|
||||
proc->last_obj = NULL;
|
||||
proc->pr_timestamp = 0;
|
||||
proc->longpr_rep_timestamp = 0;
|
||||
proc->wait_unil_release = 0;
|
||||
}
|
||||
|
||||
/*Forgot the act obj and send a released signal */
|
||||
if(proc->act_obj != NULL) {
|
||||
/* If the object was protected against press lost then it possible that
|
||||
* the object is already not pressed but still it is the `act_obj`.
|
||||
* In this case send the `LV_SIGNAL_RELEASED` if the indev is ON the `act_obj` */
|
||||
if(lv_obj_is_protected(proc->act_obj, LV_PROTECT_PRESS_LOST)) {
|
||||
/* Search the object on the current current coordinates.
|
||||
* The start object is the object itself. If not ON it the the result will be NULL*/
|
||||
lv_obj_t * obj_on = indev_search_obj(proc, proc->act_obj);
|
||||
if(obj_on == proc->act_obj) proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
|
||||
else proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_PRESS_LOST, indev_act);
|
||||
|
||||
}
|
||||
/* The simple case: `act_obj` was not protected against press lost.
|
||||
* If it is already not pressed then was handled in `indev_proc_press`*/
|
||||
else {
|
||||
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
|
||||
}
|
||||
|
||||
if(proc->reset_query != 0) return;
|
||||
|
||||
/*Handle click focus*/
|
||||
#if USE_LV_GROUP
|
||||
/*Edit mode is not used by POINTER devices. So leave edit mode if we are in it*/
|
||||
lv_group_t * act_g = lv_obj_get_group(proc->act_obj);
|
||||
if(lv_group_get_editing(act_g)) {
|
||||
lv_group_set_editing(act_g, false);
|
||||
}
|
||||
|
||||
/*Check, if the parent is in a group focus on it.*/
|
||||
if(lv_obj_is_protected(proc->act_obj, LV_PROTECT_CLICK_FOCUS) == false) { /*Respect the click protection*/
|
||||
lv_group_t * g = lv_obj_get_group(proc->act_obj);
|
||||
lv_obj_t * parent = proc->act_obj;
|
||||
|
||||
while(g == NULL) {
|
||||
parent = lv_obj_get_parent(parent);
|
||||
if(parent == NULL) break;
|
||||
if(lv_obj_is_protected(parent, LV_PROTECT_CLICK_FOCUS)) { /*Ignore is the protected against click focus*/
|
||||
parent = NULL;
|
||||
break;
|
||||
}
|
||||
g = lv_obj_get_group(parent);
|
||||
}
|
||||
|
||||
if(g != NULL && parent != NULL)
|
||||
if(lv_group_get_click_focus(g)) {
|
||||
lv_group_focus_obj(parent);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(proc->reset_query != 0) return;
|
||||
proc->act_obj = NULL;
|
||||
proc->pr_timestamp = 0;
|
||||
proc->longpr_rep_timestamp = 0;
|
||||
}
|
||||
|
||||
/*The reset can be set in the signal function.
|
||||
* In case of reset query ignore the remaining parts.*/
|
||||
if(proc->last_obj != NULL && proc->reset_query == 0) {
|
||||
indev_drag_throw(proc);
|
||||
if(proc->reset_query != 0) return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a new point from LV_INDEV_TYPE_BUTTON input device
|
||||
* @param i pointer to an input device
|
||||
* @param data pointer to the data read from the input device
|
||||
* Reset input device if a reset query has been sent to it
|
||||
* @param indev pointer to an input device
|
||||
*/
|
||||
static void indev_proc_reset_query_handler(lv_indev_t * indev)
|
||||
{
|
||||
if(indev->proc.reset_query) {
|
||||
indev->proc.act_obj = NULL;
|
||||
indev->proc.last_obj = NULL;
|
||||
indev->proc.drag_range_out = 0;
|
||||
indev->proc.drag_in_prog = 0;
|
||||
indev->proc.long_pr_sent = 0;
|
||||
indev->proc.pr_timestamp = 0;
|
||||
indev->proc.longpr_rep_timestamp = 0;
|
||||
indev->proc.drag_sum.x = 0;
|
||||
indev->proc.drag_sum.y = 0;
|
||||
indev->proc.reset_query = 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Search the most top, clickable object on the last point of an input device
|
||||
* @param proc pointer to the `lv_indev_proc_t` part of the input device
|
||||
* @param obj pointer to a start object, typically the screen
|
||||
* @return pointer to the found object or NULL if there was no suitable object
|
||||
*/
|
||||
static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj)
|
||||
{
|
||||
lv_obj_t * found_p = NULL;
|
||||
|
||||
/*If the point is on this object*/
|
||||
/*Check its children too*/
|
||||
if(lv_area_is_point_on(&obj->coords, &proc->act_point)) {
|
||||
lv_obj_t * i;
|
||||
|
||||
LL_READ(obj->child_ll, i) {
|
||||
found_p = indev_search_obj(proc, i);
|
||||
|
||||
/*If a child was found then break*/
|
||||
if(found_p != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*If then the children was not ok, and this obj is clickable
|
||||
* and it or its parent is not hidden then save this object*/
|
||||
if(found_p == NULL && lv_obj_get_click(obj) != false) {
|
||||
lv_obj_t * hidden_i = obj;
|
||||
while(hidden_i != NULL) {
|
||||
if(lv_obj_get_hidden(hidden_i) == true) break;
|
||||
hidden_i = lv_obj_get_parent(hidden_i);
|
||||
}
|
||||
/*No parent found with hidden == true*/
|
||||
if(hidden_i == NULL) found_p = obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return found_p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the dragging of indev_proc_p->act_obj
|
||||
* @param indev pointer to a input device state
|
||||
*/
|
||||
static void indev_drag(lv_indev_proc_t * state)
|
||||
{
|
||||
lv_obj_t * drag_obj = state->act_obj;
|
||||
|
||||
/*If drag parent is active check recursively the drag_parent attribute*/
|
||||
while(lv_obj_get_drag_parent(drag_obj) != false &&
|
||||
drag_obj != NULL) {
|
||||
drag_obj = lv_obj_get_parent(drag_obj);
|
||||
}
|
||||
|
||||
if(drag_obj == NULL) return;
|
||||
|
||||
if(lv_obj_get_drag(drag_obj) == false) return;
|
||||
|
||||
/*Count the movement by drag*/
|
||||
state->drag_sum.x += state->vect.x;
|
||||
state->drag_sum.y += state->vect.y;
|
||||
|
||||
/*Enough move?*/
|
||||
if(state->drag_range_out == 0) {
|
||||
/*If a move is greater then LV_DRAG_LIMIT then begin the drag*/
|
||||
if(LV_MATH_ABS(state->drag_sum.x) >= LV_INDEV_DRAG_LIMIT ||
|
||||
LV_MATH_ABS(state->drag_sum.y) >= LV_INDEV_DRAG_LIMIT) {
|
||||
state->drag_range_out = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*If the drag limit is stepped over then handle the dragging*/
|
||||
if(state->drag_range_out != 0) {
|
||||
/*Set new position if the vector is not zero*/
|
||||
if(state->vect.x != 0 ||
|
||||
state->vect.y != 0) {
|
||||
/*Get the coordinates of the object and modify them*/
|
||||
lv_coord_t act_x = lv_obj_get_x(drag_obj);
|
||||
lv_coord_t act_y = lv_obj_get_y(drag_obj);
|
||||
uint16_t inv_buf_size = lv_refr_get_buf_size(); /*Get the number of currently invalidated areas*/
|
||||
|
||||
lv_coord_t prev_x = drag_obj->coords.x1;
|
||||
lv_coord_t prev_y = drag_obj->coords.y1;
|
||||
lv_coord_t prev_par_w = lv_obj_get_width(lv_obj_get_parent(drag_obj));
|
||||
lv_coord_t prev_par_h = lv_obj_get_height(lv_obj_get_parent(drag_obj));
|
||||
|
||||
lv_obj_set_pos(drag_obj, act_x + state->vect.x, act_y + state->vect.y);
|
||||
|
||||
/*Set the drag in progress flag if the object is really moved*/
|
||||
|
||||
if(drag_obj->coords.x1 != prev_x || drag_obj->coords.y1 != prev_y) {
|
||||
if(state->drag_range_out != 0) { /*Send the drag begin signal on first move*/
|
||||
drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_BEGIN, indev_act);
|
||||
if(state->reset_query != 0) return;
|
||||
}
|
||||
state->drag_in_prog = 1;
|
||||
}
|
||||
/*If the object didn't moved then clear the invalidated areas*/
|
||||
else {
|
||||
/*In a special case if the object is moved on a page and
|
||||
* the scrollable has fit == true and the object is dragged of the page then
|
||||
* while its coordinate is not changing only the parent's size is reduced */
|
||||
lv_coord_t act_par_w = lv_obj_get_width(lv_obj_get_parent(drag_obj));
|
||||
lv_coord_t act_par_h = lv_obj_get_height(lv_obj_get_parent(drag_obj));
|
||||
if(act_par_w == prev_par_w && act_par_h == prev_par_h) {
|
||||
uint16_t new_inv_buf_size = lv_refr_get_buf_size();
|
||||
lv_refr_pop_from_buf(new_inv_buf_size - inv_buf_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle throwing by drag if the drag is ended
|
||||
* @param indev pointer to an input device state
|
||||
*/
|
||||
static void indev_drag_throw(lv_indev_proc_t * state)
|
||||
{
|
||||
if(state->drag_in_prog == 0) return;
|
||||
|
||||
/*Set new position if the vector is not zero*/
|
||||
lv_obj_t * drag_obj = state->last_obj;
|
||||
|
||||
/*If drag parent is active check recursively the drag_parent attribute*/
|
||||
while(lv_obj_get_drag_parent(drag_obj) != false &&
|
||||
drag_obj != NULL) {
|
||||
drag_obj = lv_obj_get_parent(drag_obj);
|
||||
}
|
||||
|
||||
if(drag_obj == NULL) return;
|
||||
|
||||
/*Return if the drag throw is not enabled*/
|
||||
if(lv_obj_get_drag_throw(drag_obj) == false) {
|
||||
state->drag_in_prog = 0;
|
||||
drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
|
||||
return;
|
||||
}
|
||||
|
||||
/*Reduce the vectors*/
|
||||
state->vect.x = state->vect.x * (100 - LV_INDEV_DRAG_THROW) / 100;
|
||||
state->vect.y = state->vect.y * (100 - LV_INDEV_DRAG_THROW) / 100;
|
||||
|
||||
if(state->vect.x != 0 ||
|
||||
state->vect.y != 0) {
|
||||
/*Get the coordinates and modify them*/
|
||||
lv_area_t coords_ori;
|
||||
lv_obj_get_coords(drag_obj, &coords_ori);
|
||||
lv_coord_t act_x = lv_obj_get_x(drag_obj) + state->vect.x;
|
||||
lv_coord_t act_y = lv_obj_get_y(drag_obj) + state->vect.y;
|
||||
lv_obj_set_pos(drag_obj, act_x, act_y);
|
||||
|
||||
lv_area_t coord_new;
|
||||
lv_obj_get_coords(drag_obj, &coord_new);
|
||||
|
||||
/*If non of the coordinates are changed then do not continue throwing*/
|
||||
if((coords_ori.x1 == coord_new.x1 || state->vect.x == 0) &&
|
||||
(coords_ori.y1 == coord_new.y1 || state->vect.y == 0)) {
|
||||
state->drag_in_prog = 0;
|
||||
state->vect.x = 0;
|
||||
state->vect.y = 0;
|
||||
drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
|
||||
|
||||
}
|
||||
}
|
||||
/*If the vectors become 0 -> drag_in_prog = 0 and send a drag end signal*/
|
||||
else {
|
||||
state->drag_in_prog = 0;
|
||||
drag_obj->signal_func(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
|
||||
}
|
||||
}
|
||||
#endif
|
157
bdk/libs/lvgl/lv_core/lv_indev.h
Normal file
157
bdk/libs/lvgl/lv_core/lv_indev.h
Normal file
|
@ -0,0 +1,157 @@
|
|||
/**
|
||||
* @file lv_indev_proc.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_INDEV_H
|
||||
#define LV_INDEV_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_obj.h"
|
||||
#include "../lv_hal/lv_hal_indev.h"
|
||||
#include "../lv_core/lv_group.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the display input device subsystem
|
||||
*/
|
||||
void lv_indev_init(void);
|
||||
|
||||
/**
|
||||
* Get the currently processed input device. Can be used in action functions too.
|
||||
* @return pointer to the currently processed input device or NULL if no input device processing right now
|
||||
*/
|
||||
lv_indev_t * lv_indev_get_act(void);
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of an input device
|
||||
* @param indev pointer to an input device
|
||||
* @return the type of the input device from `lv_hal_indev_type_t` (`LV_INDEV_TYPE_...`)
|
||||
*/
|
||||
lv_hal_indev_type_t lv_indev_get_type(const lv_indev_t * indev);
|
||||
|
||||
/**
|
||||
* Reset one or all input devices
|
||||
* @param indev pointer to an input device to reset or NULL to reset all of them
|
||||
*/
|
||||
void lv_indev_reset(lv_indev_t * indev);
|
||||
|
||||
/**
|
||||
* Reset the long press state of an input device
|
||||
* @param indev_proc pointer to an input device
|
||||
*/
|
||||
void lv_indev_reset_lpr(lv_indev_t * indev);
|
||||
|
||||
/**
|
||||
* Enable input devices device by type
|
||||
* @param type Input device type
|
||||
* @param enable true: enable this type; false: disable this type
|
||||
*/
|
||||
void lv_indev_enable(lv_hal_indev_type_t type, bool enable);
|
||||
|
||||
/**
|
||||
* Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and LV_INPUT_TYPE_BUTTON)
|
||||
* @param indev pointer to an input device
|
||||
* @param cur_obj pointer to an object to be used as cursor
|
||||
*/
|
||||
void lv_indev_set_cursor(lv_indev_t *indev, lv_obj_t *cur_obj);
|
||||
|
||||
#if USE_LV_GROUP
|
||||
/**
|
||||
* Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD)
|
||||
* @param indev pointer to an input device
|
||||
* @param group point to a group
|
||||
*/
|
||||
void lv_indev_set_group(lv_indev_t *indev, lv_group_t *group);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set the an array of points for LV_INDEV_TYPE_BUTTON.
|
||||
* These points will be assigned to the buttons to press a specific point on the screen
|
||||
* @param indev pointer to an input device
|
||||
* @param group point to a group
|
||||
*/
|
||||
void lv_indev_set_button_points(lv_indev_t *indev, const lv_point_t *points);
|
||||
|
||||
/**
|
||||
* Set feedback callback for indev.
|
||||
* @param indev pointer to an input device
|
||||
* @param feedback feedback callback
|
||||
*/
|
||||
void lv_indev_set_feedback(lv_indev_t *indev, lv_indev_feedback_t feedback);
|
||||
|
||||
/**
|
||||
* Get the last point of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
|
||||
* @param indev pointer to an input device
|
||||
* @param point pointer to a point to store the result
|
||||
*/
|
||||
void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point);
|
||||
|
||||
/**
|
||||
* Get the last key of an input device (for LV_INDEV_TYPE_KEYPAD)
|
||||
* @param indev pointer to an input device
|
||||
* @return the last pressed key (0 on error)
|
||||
*/
|
||||
uint32_t lv_indev_get_key(const lv_indev_t * indev);
|
||||
|
||||
/**
|
||||
* Check if there is dragging with an input device or not (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
|
||||
* @param indev pointer to an input device
|
||||
* @return true: drag is in progress
|
||||
*/
|
||||
bool lv_indev_is_dragging(const lv_indev_t * indev);
|
||||
|
||||
/**
|
||||
* Get the vector of dragging of an input device (for LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON)
|
||||
* @param indev pointer to an input device
|
||||
* @param point pointer to a point to store the vector
|
||||
*/
|
||||
void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point);
|
||||
/**
|
||||
* Get elapsed time since last press
|
||||
* @param indev pointer to an input device (NULL to get the overall smallest inactivity)
|
||||
* @return Elapsed ticks (milliseconds) since last press
|
||||
*/
|
||||
uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev);
|
||||
|
||||
/**
|
||||
* Get feedback callback for indev.
|
||||
* @param indev pointer to an input device
|
||||
* @return feedback callback
|
||||
*/
|
||||
lv_indev_feedback_t lv_indev_get_feedback(const lv_indev_t *indev);
|
||||
|
||||
/**
|
||||
* Do nothing until the next release
|
||||
* @param indev pointer to an input device
|
||||
*/
|
||||
void lv_indev_wait_release(lv_indev_t * indev);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_INDEV_H*/
|
117
bdk/libs/lvgl/lv_core/lv_lang.c
Normal file
117
bdk/libs/lvgl/lv_core/lv_lang.c
Normal file
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* @file lv_lang.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_lang.h"
|
||||
#if USE_LV_MULTI_LANG
|
||||
|
||||
#include "lv_obj.h"
|
||||
#include "../lv_misc/lv_gc.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lang_set_core(lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static uint8_t lang_act = 0;
|
||||
static const void * (*get_txt)(uint16_t);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Change the language
|
||||
* @param lang_id the id of the
|
||||
*/
|
||||
void lv_lang_set(uint8_t lang_id)
|
||||
{
|
||||
lang_act = lang_id;
|
||||
|
||||
lv_obj_t * i;
|
||||
LL_READ(LV_GC_ROOT(_lv_scr_ll), i) {
|
||||
i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL);
|
||||
|
||||
lang_set_core(i);
|
||||
}
|
||||
|
||||
lang_set_core(lv_scr_act());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function to get the texts of the set languages from a `txt_id`
|
||||
* @param fp a function pointer to get the texts
|
||||
*/
|
||||
void lv_lang_set_text_func(const void * (*fp)(uint16_t))
|
||||
{
|
||||
get_txt = fp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language
|
||||
* @param txt_id an ID of the text to get
|
||||
* @return the `txt_id` txt on the set language
|
||||
*/
|
||||
const void * lv_lang_get_text(uint16_t txt_id)
|
||||
{
|
||||
if(get_txt == NULL) {
|
||||
LV_LOG_WARN("lv_lang_get_text: text_func is not specified");
|
||||
return NULL; /*No text_get function specified */
|
||||
}
|
||||
if(txt_id == LV_LANG_TXT_ID_NONE) {
|
||||
LV_LOG_WARN("lv_lang_get_text: attempts to get invalid text ID");
|
||||
return NULL; /*Invalid txt_id*/
|
||||
}
|
||||
|
||||
return get_txt(txt_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return with ID of the currently selected language
|
||||
* @return pointer to the active screen object (loaded by 'lv_scr_load()')
|
||||
*/
|
||||
uint8_t lv_lang_act(void)
|
||||
{
|
||||
return lang_act;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Change the language of the children. (Called recursively)
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
static void lang_set_core(lv_obj_t * obj)
|
||||
{
|
||||
lv_obj_t * i;
|
||||
LL_READ(obj->child_ll, i) {
|
||||
i->signal_func(i, LV_SIGNAL_LANG_CHG, NULL);
|
||||
|
||||
lang_set_core(i);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /*USE_LV_MULTI_LANG*/
|
74
bdk/libs/lvgl/lv_core/lv_lang.h
Normal file
74
bdk/libs/lvgl/lv_core/lv_lang.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* @file lv_lang.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_LANG_H
|
||||
#define LV_LANG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_LV_MULTI_LANG
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Change the language
|
||||
* @param lang_id the id of the
|
||||
*/
|
||||
void lv_lang_set(uint8_t lang_id);
|
||||
|
||||
/**
|
||||
* Set a function to get the texts of the set languages from a `txt_id`
|
||||
* @param fp a function pointer to get the texts
|
||||
*/
|
||||
void lv_lang_set_text_func(const void * (*fp)(uint16_t));
|
||||
|
||||
/**
|
||||
* Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language
|
||||
* @param txt_id an ID of the text to get
|
||||
* @return the `txt_id` txt on the set language
|
||||
*/
|
||||
const void * lv_lang_get_text(uint16_t txt_id);
|
||||
|
||||
/**
|
||||
* Return with ID of the currently selected language
|
||||
* @return pointer to the active screen object (loaded by 'lv_scr_load()')
|
||||
*/
|
||||
uint8_t lv_lang_act(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_MULTI_LANG*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_LANG_H*/
|
1986
bdk/libs/lvgl/lv_core/lv_obj.c
Normal file
1986
bdk/libs/lvgl/lv_core/lv_obj.c
Normal file
File diff suppressed because it is too large
Load diff
840
bdk/libs/lvgl/lv_core/lv_obj.h
Normal file
840
bdk/libs/lvgl/lv_core/lv_obj.h
Normal file
|
@ -0,0 +1,840 @@
|
|||
/**
|
||||
* @file lv_obj.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_OBJ_H
|
||||
#define LV_OBJ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include "lv_style.h"
|
||||
#include "../lv_misc/lv_area.h"
|
||||
#include "../lv_misc/lv_mem.h"
|
||||
#include "../lv_misc/lv_ll.h"
|
||||
#include "../lv_misc/lv_color.h"
|
||||
#include "../lv_misc/lv_log.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/*Error check of lv_conf.h*/
|
||||
#if LV_HOR_RES == 0 || LV_VER_RES == 0
|
||||
#error "LittlevGL: LV_HOR_RES and LV_VER_RES must be greater than 0"
|
||||
#endif
|
||||
|
||||
#if LV_ANTIALIAS > 1
|
||||
#error "LittlevGL: LV_ANTIALIAS can be only 0 or 1"
|
||||
#endif
|
||||
|
||||
#if LV_VDB_SIZE == 0 && LV_ANTIALIAS != 0
|
||||
#error "LittlevGL: If LV_VDB_SIZE == 0 the anti-aliasing must be disabled"
|
||||
#endif
|
||||
|
||||
#if LV_VDB_SIZE > 0 && LV_VDB_SIZE < LV_HOR_RES
|
||||
#error "LittlevGL: Small Virtual Display Buffer (lv_conf.h: LV_VDB_SIZE >= LV_HOR_RES)"
|
||||
#endif
|
||||
|
||||
#if LV_VDB_SIZE == 0 && USE_LV_REAL_DRAW == 0
|
||||
#error "LittlevGL: If LV_VDB_SIZE = 0 Real drawing function are required (lv_conf.h: USE_LV_REAL_DRAW 1)"
|
||||
#endif
|
||||
|
||||
|
||||
#define LV_ANIM_IN 0x00 /*Animation to show an object. 'OR' it with lv_anim_builtin_t*/
|
||||
#define LV_ANIM_OUT 0x80 /*Animation to hide an object. 'OR' it with lv_anim_builtin_t*/
|
||||
#define LV_ANIM_DIR_MASK 0x80 /*ANIM_IN/ANIM_OUT mask*/
|
||||
|
||||
#define LV_MAX_ANCESTOR_NUM 8
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
struct _lv_obj_t;
|
||||
|
||||
enum
|
||||
{
|
||||
LV_DESIGN_DRAW_MAIN,
|
||||
LV_DESIGN_DRAW_POST,
|
||||
LV_DESIGN_COVER_CHK,
|
||||
};
|
||||
typedef uint8_t lv_design_mode_t;
|
||||
|
||||
typedef bool (* lv_design_func_t) (struct _lv_obj_t * obj, const lv_area_t * mask_p, lv_design_mode_t mode);
|
||||
|
||||
enum
|
||||
{
|
||||
LV_RES_INV = 0, /*Typically indicates that the object is deleted (become invalid) in the action function or an operation was failed*/
|
||||
LV_RES_OK, /*The object is valid (no deleted) after the action*/
|
||||
};
|
||||
typedef uint8_t lv_res_t;
|
||||
|
||||
enum
|
||||
{
|
||||
/*General signals*/
|
||||
LV_SIGNAL_CLEANUP,
|
||||
LV_SIGNAL_CHILD_CHG,
|
||||
LV_SIGNAL_CORD_CHG,
|
||||
LV_SIGNAL_STYLE_CHG,
|
||||
LV_SIGNAL_REFR_EXT_SIZE,
|
||||
LV_SIGNAL_LANG_CHG,
|
||||
LV_SIGNAL_GET_TYPE,
|
||||
|
||||
_LV_SIGNAL_FEEDBACK_SECTION_START,
|
||||
/*Input device related*/
|
||||
LV_SIGNAL_PRESSED,
|
||||
LV_SIGNAL_PRESSING,
|
||||
LV_SIGNAL_PRESS_LOST,
|
||||
LV_SIGNAL_RELEASED,
|
||||
LV_SIGNAL_LONG_PRESS,
|
||||
LV_SIGNAL_LONG_PRESS_REP,
|
||||
LV_SIGNAL_DRAG_BEGIN,
|
||||
LV_SIGNAL_DRAG_END,
|
||||
|
||||
/*Group related*/
|
||||
LV_SIGNAL_FOCUS,
|
||||
LV_SIGNAL_DEFOCUS,
|
||||
LV_SIGNAL_CONTROLL,
|
||||
_LV_SIGNAL_FEEDBACK_SECTION_END,
|
||||
LV_SIGNAL_GET_EDITABLE,
|
||||
};
|
||||
typedef uint8_t lv_signal_t;
|
||||
|
||||
typedef lv_res_t (* lv_signal_func_t) (struct _lv_obj_t * obj, lv_signal_t sign, void * param);
|
||||
|
||||
enum
|
||||
{
|
||||
LV_ALIGN_CENTER = 0,
|
||||
LV_ALIGN_IN_TOP_LEFT,
|
||||
LV_ALIGN_IN_TOP_MID,
|
||||
LV_ALIGN_IN_TOP_RIGHT,
|
||||
LV_ALIGN_IN_BOTTOM_LEFT,
|
||||
LV_ALIGN_IN_BOTTOM_MID,
|
||||
LV_ALIGN_IN_BOTTOM_RIGHT,
|
||||
LV_ALIGN_IN_LEFT_MID,
|
||||
LV_ALIGN_IN_RIGHT_MID,
|
||||
LV_ALIGN_OUT_TOP_LEFT,
|
||||
LV_ALIGN_OUT_TOP_MID,
|
||||
LV_ALIGN_OUT_TOP_RIGHT,
|
||||
LV_ALIGN_OUT_BOTTOM_LEFT,
|
||||
LV_ALIGN_OUT_BOTTOM_MID,
|
||||
LV_ALIGN_OUT_BOTTOM_RIGHT,
|
||||
LV_ALIGN_OUT_LEFT_TOP,
|
||||
LV_ALIGN_OUT_LEFT_MID,
|
||||
LV_ALIGN_OUT_LEFT_BOTTOM,
|
||||
LV_ALIGN_OUT_RIGHT_TOP,
|
||||
LV_ALIGN_OUT_RIGHT_MID,
|
||||
LV_ALIGN_OUT_RIGHT_BOTTOM,
|
||||
};
|
||||
typedef uint8_t lv_align_t;
|
||||
|
||||
#if LV_OBJ_REALIGN
|
||||
typedef struct {
|
||||
const struct _lv_obj_t * base;
|
||||
lv_coord_t xofs;
|
||||
lv_coord_t yofs;
|
||||
lv_align_t align;
|
||||
uint8_t auto_realign :1;
|
||||
uint8_t origo_align :1; /*1: the oigo (center of the object) was aligned with `lv_obj_align_origo`*/
|
||||
}lv_reailgn_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct _lv_obj_t
|
||||
{
|
||||
struct _lv_obj_t * par; /*Pointer to the parent object*/
|
||||
lv_ll_t child_ll; /*Linked list to store the children objects*/
|
||||
|
||||
lv_area_t coords; /*Coordinates of the object (x1, y1, x2, y2)*/
|
||||
|
||||
lv_signal_func_t signal_func; /*Object type specific signal function*/
|
||||
lv_design_func_t design_func; /*Object type specific design function*/
|
||||
|
||||
void * ext_attr; /*Object type specific extended data*/
|
||||
lv_style_t * style_p; /*Pointer to the object's style*/
|
||||
|
||||
#if LV_OBJ_FREE_PTR != 0
|
||||
void * free_ptr; /*Application specific pointer (set it freely)*/
|
||||
#endif
|
||||
|
||||
#if USE_LV_GROUP != 0
|
||||
void * group_p; /*Pointer to the group of the object*/
|
||||
#endif
|
||||
/*Attributes and states*/
|
||||
uint8_t click :1; /*1: Can be pressed by an input device*/
|
||||
uint8_t drag :1; /*1: Enable the dragging*/
|
||||
uint8_t drag_throw :1; /*1: Enable throwing with drag*/
|
||||
uint8_t drag_parent :1; /*1: Parent will be dragged instead*/
|
||||
uint8_t hidden :1; /*1: Object is hidden*/
|
||||
uint8_t top :1; /*1: If the object or its children is clicked it goes to the foreground*/
|
||||
uint8_t opa_scale_en :1; /*1: opa_scale is set*/
|
||||
uint8_t protect; /*Automatically happening actions can be prevented. 'OR'ed values from `lv_protect_t`*/
|
||||
lv_opa_t opa_scale; /*Scale down the opacity by this factor. Effects all children as well*/
|
||||
|
||||
lv_coord_t ext_size; /*EXTtend the size of the object in every direction. E.g. for shadow drawing*/
|
||||
#if LV_OBJ_REALIGN
|
||||
lv_reailgn_t realign;
|
||||
#endif
|
||||
|
||||
#ifdef LV_OBJ_FREE_NUM_TYPE
|
||||
LV_OBJ_FREE_NUM_TYPE free_num; /*Application specific identifier (set it freely)*/
|
||||
#endif
|
||||
} lv_obj_t;
|
||||
|
||||
typedef lv_res_t (*lv_action_t) (struct _lv_obj_t * obj);
|
||||
|
||||
/*Protect some attributes (max. 8 bit)*/
|
||||
enum
|
||||
{
|
||||
LV_PROTECT_NONE = 0x00,
|
||||
LV_PROTECT_CHILD_CHG = 0x01, /*Disable the child change signal. Used by the library*/
|
||||
LV_PROTECT_PARENT = 0x02, /*Prevent automatic parent change (e.g. in lv_page)*/
|
||||
LV_PROTECT_POS = 0x04, /*Prevent automatic positioning (e.g. in lv_cont layout)*/
|
||||
LV_PROTECT_FOLLOW = 0x08, /*Prevent the object be followed in automatic ordering (e.g. in lv_cont PRETTY layout)*/
|
||||
LV_PROTECT_PRESS_LOST= 0x10, /*If the `indev` was pressing this object but swiped out while pressing do not search other object.*/
|
||||
LV_PROTECT_CLICK_FOCUS= 0x20,/*Prevent focusing the object by clicking on it*/
|
||||
};
|
||||
typedef uint8_t lv_protect_t;
|
||||
|
||||
|
||||
/*Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/
|
||||
typedef struct {
|
||||
const char * type[LV_MAX_ANCESTOR_NUM]; /*[0]: the actual type, [1]: ancestor, [2] #1's ancestor ... [x]: "lv_obj" */
|
||||
} lv_obj_type_t;
|
||||
|
||||
enum
|
||||
{
|
||||
LV_ANIM_NONE = 0,
|
||||
LV_ANIM_FLOAT_TOP, /*Float from/to the top*/
|
||||
LV_ANIM_FLOAT_LEFT, /*Float from/to the left*/
|
||||
LV_ANIM_FLOAT_BOTTOM, /*Float from/to the bottom*/
|
||||
LV_ANIM_FLOAT_RIGHT, /*Float from/to the right*/
|
||||
LV_ANIM_GROW_H, /*Grow/shrink horizontally*/
|
||||
LV_ANIM_GROW_V, /*Grow/shrink vertically*/
|
||||
};
|
||||
typedef uint8_t lv_anim_builtin_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Init. the 'lv' library.
|
||||
*/
|
||||
void lv_init(void);
|
||||
|
||||
/*--------------------
|
||||
* Create and delete
|
||||
*-------------------*/
|
||||
|
||||
/**
|
||||
* Create a basic object
|
||||
* @param parent pointer to a parent object.
|
||||
* If NULL then a screen will be created
|
||||
* @param copy pointer to a base object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the new object
|
||||
*/
|
||||
lv_obj_t * lv_obj_create(lv_obj_t * parent,const lv_obj_t * copy);
|
||||
|
||||
/**
|
||||
* Delete 'obj' and all of its children
|
||||
* @param obj pointer to an object to delete
|
||||
* @return LV_RES_INV because the object is deleted
|
||||
*/
|
||||
lv_res_t lv_obj_del(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Delete all children of an object
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_clean(lv_obj_t *obj);
|
||||
|
||||
/**
|
||||
* Mark the object as invalid therefore its current position will be redrawn by 'lv_refr_task'
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_invalidate(const lv_obj_t * obj);
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/*--------------
|
||||
* Screen set
|
||||
*--------------*/
|
||||
|
||||
/**
|
||||
* Load a new screen
|
||||
* @param scr pointer to a screen
|
||||
*/
|
||||
void lv_scr_load(lv_obj_t * scr);
|
||||
|
||||
/*--------------------
|
||||
* Parent/children set
|
||||
*--------------------*/
|
||||
|
||||
/**
|
||||
* Set a new parent for an object. Its relative position will be the same.
|
||||
* @param obj pointer to an object. Can't be a screen.
|
||||
* @param parent pointer to the new parent object. (Can't be NULL)
|
||||
*/
|
||||
void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent);
|
||||
|
||||
/*--------------------
|
||||
* Coordinate set
|
||||
* ------------------*/
|
||||
|
||||
/**
|
||||
* Set relative the position of an object (relative to the parent)
|
||||
* @param obj pointer to an object
|
||||
* @param x new distance from the left side of the parent
|
||||
* @param y new distance from the top of the parent
|
||||
*/
|
||||
void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y);
|
||||
|
||||
/**
|
||||
* Set the x coordinate of a object
|
||||
* @param obj pointer to an object
|
||||
* @param x new distance from the left side from the parent
|
||||
*/
|
||||
void lv_obj_set_x(lv_obj_t * obj, lv_coord_t x);
|
||||
|
||||
/**
|
||||
* Set the y coordinate of a object
|
||||
* @param obj pointer to an object
|
||||
* @param y new distance from the top of the parent
|
||||
*/
|
||||
void lv_obj_set_y(lv_obj_t * obj, lv_coord_t y);
|
||||
|
||||
/**
|
||||
* Set the size of an object
|
||||
* @param obj pointer to an object
|
||||
* @param w new width
|
||||
* @param h new height
|
||||
*/
|
||||
void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h);
|
||||
|
||||
/**
|
||||
* Set the width of an object
|
||||
* @param obj pointer to an object
|
||||
* @param w new width
|
||||
*/
|
||||
void lv_obj_set_width(lv_obj_t * obj, lv_coord_t w);
|
||||
|
||||
/**
|
||||
* Set the height of an object
|
||||
* @param obj pointer to an object
|
||||
* @param h new height
|
||||
*/
|
||||
void lv_obj_set_height(lv_obj_t * obj, lv_coord_t h);
|
||||
|
||||
/**
|
||||
* Align an object to an other object.
|
||||
* @param obj pointer to an object to align
|
||||
* @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it.
|
||||
* @param align type of alignment (see 'lv_align_t' enum)
|
||||
* @param x_mod x coordinate shift after alignment
|
||||
* @param y_mod y coordinate shift after alignment
|
||||
*/
|
||||
void lv_obj_align(lv_obj_t * obj,const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod);
|
||||
|
||||
/**
|
||||
* Align an object to an other object.
|
||||
* @param obj pointer to an object to align
|
||||
* @param base pointer to an object (if NULL the parent is used). 'obj' will be aligned to it.
|
||||
* @param align type of alignment (see 'lv_align_t' enum)
|
||||
* @param x_mod x coordinate shift after alignment
|
||||
* @param y_mod y coordinate shift after alignment
|
||||
*/
|
||||
void lv_obj_align_origo(lv_obj_t * obj, const lv_obj_t * base, lv_align_t align, lv_coord_t x_mod, lv_coord_t y_mod);
|
||||
|
||||
/**
|
||||
* Realign the object based on the last `lv_obj_align` parameters.
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_realign(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Enable the automatic realign of the object when its size has changed based on the last `lv_obj_align` parameters.
|
||||
* @param obj pointer to an object
|
||||
* @param en true: enable auto realign; false: disable auto realign
|
||||
*/
|
||||
void lv_obj_set_auto_realign(lv_obj_t * obj, bool en);
|
||||
|
||||
/*---------------------
|
||||
* Appearance set
|
||||
*--------------------*/
|
||||
|
||||
/**
|
||||
* Set a new style for an object
|
||||
* @param obj pointer to an object
|
||||
* @param style_p pointer to the new style
|
||||
*/
|
||||
void lv_obj_set_style(lv_obj_t * obj, lv_style_t * style);
|
||||
|
||||
/**
|
||||
* Notify an object about its style is modified
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_refresh_style(lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Notify all object if a style is modified
|
||||
* @param style pointer to a style. Only the objects with this style will be notified
|
||||
* (NULL to notify all objects)
|
||||
*/
|
||||
void lv_obj_report_style_mod(lv_style_t * style);
|
||||
|
||||
/*-----------------
|
||||
* Attribute set
|
||||
*----------------*/
|
||||
|
||||
/**
|
||||
* Hide an object. It won't be visible and clickable.
|
||||
* @param obj pointer to an object
|
||||
* @param en true: hide the object
|
||||
*/
|
||||
void lv_obj_set_hidden(lv_obj_t * obj, bool en);
|
||||
|
||||
/**
|
||||
* Enable or disable the clicking of an object
|
||||
* @param obj pointer to an object
|
||||
* @param en true: make the object clickable
|
||||
*/
|
||||
void lv_obj_set_click(lv_obj_t * obj, bool en);
|
||||
|
||||
/**
|
||||
* Enable to bring this object to the foreground if it
|
||||
* or any of its children is clicked
|
||||
* @param obj pointer to an object
|
||||
* @param en true: enable the auto top feature
|
||||
*/
|
||||
void lv_obj_set_top(lv_obj_t * obj, bool en);
|
||||
|
||||
/**
|
||||
* Enable the dragging of an object
|
||||
* @param obj pointer to an object
|
||||
* @param en true: make the object dragable
|
||||
*/
|
||||
void lv_obj_set_drag(lv_obj_t * obj, bool en);
|
||||
|
||||
/**
|
||||
* Enable the throwing of an object after is is dragged
|
||||
* @param obj pointer to an object
|
||||
* @param en true: enable the drag throw
|
||||
*/
|
||||
void lv_obj_set_drag_throw(lv_obj_t * obj, bool en);
|
||||
|
||||
/**
|
||||
* Enable to use parent for drag related operations.
|
||||
* If trying to drag the object the parent will be moved instead
|
||||
* @param obj pointer to an object
|
||||
* @param en true: enable the 'drag parent' for the object
|
||||
*/
|
||||
void lv_obj_set_drag_parent(lv_obj_t * obj, bool en);
|
||||
|
||||
/**
|
||||
* Set editable parameter Used by groups and keyboard/encoder control.
|
||||
* Editable object has something inside to choose (the elements of a list)
|
||||
* @param obj pointer to an object
|
||||
* @param en true: enable editing
|
||||
*/
|
||||
//void lv_obj_set_editable(lv_obj_t * obj, bool en);
|
||||
|
||||
/**
|
||||
* Set the opa scale enable parameter (required to set opa_scale with `lv_obj_set_opa_scale()`)
|
||||
* @param obj pointer to an object
|
||||
* @param en true: opa scaling is enabled for this object and all children; false: no opa scaling
|
||||
*/
|
||||
void lv_obj_set_opa_scale_enable(lv_obj_t * obj, bool en);
|
||||
|
||||
/**
|
||||
* Set the opa scale of an object
|
||||
* @param obj pointer to an object
|
||||
* @param opa_scale a factor to scale down opacity [0..255]
|
||||
*/
|
||||
void lv_obj_set_opa_scale(lv_obj_t * obj, lv_opa_t opa_scale);
|
||||
|
||||
/**
|
||||
* Set a bit or bits in the protect filed
|
||||
* @param obj pointer to an object
|
||||
* @param prot 'OR'-ed values from `lv_protect_t`
|
||||
*/
|
||||
void lv_obj_set_protect(lv_obj_t * obj, uint8_t prot);
|
||||
|
||||
/**
|
||||
* Clear a bit or bits in the protect filed
|
||||
* @param obj pointer to an object
|
||||
* @param prot 'OR'-ed values from `lv_protect_t`
|
||||
*/
|
||||
void lv_obj_clear_protect(lv_obj_t * obj, uint8_t prot);
|
||||
|
||||
/**
|
||||
* Set the signal function of an object.
|
||||
* Always call the previous signal function in the new.
|
||||
* @param obj pointer to an object
|
||||
* @param fp the new signal function
|
||||
*/
|
||||
void lv_obj_set_signal_func(lv_obj_t * obj, lv_signal_func_t fp);
|
||||
|
||||
/**
|
||||
* Set a new design function for an object
|
||||
* @param obj pointer to an object
|
||||
* @param fp the new design function
|
||||
*/
|
||||
void lv_obj_set_design_func(lv_obj_t * obj, lv_design_func_t fp);
|
||||
|
||||
/*----------------
|
||||
* Other set
|
||||
*--------------*/
|
||||
|
||||
/**
|
||||
* Allocate a new ext. data for an object
|
||||
* @param obj pointer to an object
|
||||
* @param ext_size the size of the new ext. data
|
||||
* @return pointer to the allocated ext
|
||||
*/
|
||||
void * lv_obj_allocate_ext_attr(lv_obj_t * obj, uint16_t ext_size);
|
||||
|
||||
/**
|
||||
* Send a 'LV_SIGNAL_REFR_EXT_SIZE' signal to the object
|
||||
* @param obj pointer to an object
|
||||
*/
|
||||
void lv_obj_refresh_ext_size(lv_obj_t * obj);
|
||||
|
||||
#ifdef LV_OBJ_FREE_NUM_TYPE
|
||||
/**
|
||||
* Set an application specific number for an object.
|
||||
* It can help to identify objects in the application.
|
||||
* @param obj pointer to an object
|
||||
* @param free_num the new free number
|
||||
*/
|
||||
void lv_obj_set_free_num(lv_obj_t * obj, LV_OBJ_FREE_NUM_TYPE free_num);
|
||||
#endif
|
||||
|
||||
#if LV_OBJ_FREE_PTR != 0
|
||||
/**
|
||||
* Set an application specific pointer for an object.
|
||||
* It can help to identify objects in the application.
|
||||
* @param obj pointer to an object
|
||||
* @param free_p the new free pinter
|
||||
*/
|
||||
void lv_obj_set_free_ptr(lv_obj_t * obj, void * free_p);
|
||||
#endif
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
/**
|
||||
* Animate an object
|
||||
* @param obj pointer to an object to animate
|
||||
* @param type type of animation from 'lv_anim_builtin_t'. 'OR' it with ANIM_IN or ANIM_OUT
|
||||
* @param time time of animation in milliseconds
|
||||
* @param delay delay before the animation in milliseconds
|
||||
* @param cb a function to call when the animation is ready
|
||||
*/
|
||||
void lv_obj_animate(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint16_t delay, void (*cb) (lv_obj_t *));
|
||||
#endif
|
||||
|
||||
/*=======================
|
||||
* Getter functions
|
||||
*======================*/
|
||||
|
||||
/*------------------
|
||||
* Screen get
|
||||
*-----------------*/
|
||||
|
||||
/**
|
||||
* Return with a pointer to the active screen
|
||||
* @return pointer to the active screen object (loaded by 'lv_scr_load()')
|
||||
*/
|
||||
lv_obj_t * lv_scr_act(void);
|
||||
|
||||
/**
|
||||
* Return with the top layer. (Same on every screen and it is above the normal screen layer)
|
||||
* @return pointer to the top layer object (transparent screen sized lv_obj)
|
||||
*/
|
||||
lv_obj_t * lv_layer_top(void);
|
||||
|
||||
/**
|
||||
* Return with the system layer. (Same on every screen and it is above the all other layers)
|
||||
* It is used for example by the cursor
|
||||
* @return pointer to the system layer object (transparent screen sized lv_obj)
|
||||
*/
|
||||
lv_obj_t * lv_layer_sys(void);
|
||||
|
||||
/**
|
||||
* Return with the screen of an object
|
||||
* @param obj pointer to an object
|
||||
* @return pointer to a screen
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_screen(const lv_obj_t * obj);
|
||||
|
||||
/*---------------------
|
||||
* Parent/children get
|
||||
*--------------------*/
|
||||
|
||||
/**
|
||||
* Returns with the parent of an object
|
||||
* @param obj pointer to an object
|
||||
* @return pointer to the parent of 'obj'
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_parent(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Iterate through the children of an object (start from the "youngest, lastly created")
|
||||
* @param obj pointer to an object
|
||||
* @param child NULL at first call to get the next children
|
||||
* and the previous return value later
|
||||
* @return the child after 'act_child' or NULL if no more child
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child);
|
||||
|
||||
/**
|
||||
* Iterate through the children of an object (start from the "oldest", firstly created)
|
||||
* @param obj pointer to an object
|
||||
* @param child NULL at first call to get the next children
|
||||
* and the previous return value later
|
||||
* @return the child after 'act_child' or NULL if no more child
|
||||
*/
|
||||
lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child);
|
||||
|
||||
/**
|
||||
* Count the children of an object (only children directly on 'obj')
|
||||
* @param obj pointer to an object
|
||||
* @return children number of 'obj'
|
||||
*/
|
||||
uint16_t lv_obj_count_children(const lv_obj_t * obj);
|
||||
|
||||
/*---------------------
|
||||
* Coordinate get
|
||||
*--------------------*/
|
||||
|
||||
/**
|
||||
* Copy the coordinates of an object to an area
|
||||
* @param obj pointer to an object
|
||||
* @param cords_p pointer to an area to store the coordinates
|
||||
*/
|
||||
void lv_obj_get_coords(const lv_obj_t * obj, lv_area_t * cords_p);
|
||||
|
||||
/**
|
||||
* Get the x coordinate of object
|
||||
* @param obj pointer to an object
|
||||
* @return distance of 'obj' from the left side of its parent
|
||||
*/
|
||||
lv_coord_t lv_obj_get_x(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the y coordinate of object
|
||||
* @param obj pointer to an object
|
||||
* @return distance of 'obj' from the top of its parent
|
||||
*/
|
||||
lv_coord_t lv_obj_get_y(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the width of an object
|
||||
* @param obj pointer to an object
|
||||
* @return the width
|
||||
*/
|
||||
lv_coord_t lv_obj_get_width(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the height of an object
|
||||
* @param obj pointer to an object
|
||||
* @return the height
|
||||
*/
|
||||
lv_coord_t lv_obj_get_height(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the extended size attribute of an object
|
||||
* @param obj pointer to an object
|
||||
* @return the extended size attribute
|
||||
*/
|
||||
lv_coord_t lv_obj_get_ext_size(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the automatic realign property of the object.
|
||||
* @param obj pointer to an object
|
||||
* @return true: auto realign is enabled; false: auto realign is disabled
|
||||
*/
|
||||
bool lv_obj_get_auto_realign(lv_obj_t * obj);
|
||||
|
||||
/*-----------------
|
||||
* Appearance get
|
||||
*---------------*/
|
||||
|
||||
/**
|
||||
* Get the style pointer of an object (if NULL get style of the parent)
|
||||
* @param obj pointer to an object
|
||||
* @return pointer to a style
|
||||
*/
|
||||
lv_style_t * lv_obj_get_style(const lv_obj_t * obj);
|
||||
|
||||
/*-----------------
|
||||
* Attribute get
|
||||
*----------------*/
|
||||
|
||||
/**
|
||||
* Get the hidden attribute of an object
|
||||
* @param obj pointer to an object
|
||||
* @return true: the object is hidden
|
||||
*/
|
||||
bool lv_obj_get_hidden(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the click enable attribute of an object
|
||||
* @param obj pointer to an object
|
||||
* @return true: the object is clickable
|
||||
*/
|
||||
bool lv_obj_get_click(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the top enable attribute of an object
|
||||
* @param obj pointer to an object
|
||||
* @return true: the auto top feature is enabled
|
||||
*/
|
||||
bool lv_obj_get_top(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the drag enable attribute of an object
|
||||
* @param obj pointer to an object
|
||||
* @return true: the object is dragable
|
||||
*/
|
||||
bool lv_obj_get_drag(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the drag throw enable attribute of an object
|
||||
* @param obj pointer to an object
|
||||
* @return true: drag throw is enabled
|
||||
*/
|
||||
bool lv_obj_get_drag_throw(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the drag parent attribute of an object
|
||||
* @param obj pointer to an object
|
||||
* @return true: drag parent is enabled
|
||||
*/
|
||||
bool lv_obj_get_drag_parent(const lv_obj_t * obj);
|
||||
|
||||
|
||||
/**
|
||||
* Get the opa scale enable parameter
|
||||
* @param obj pointer to an object
|
||||
* @return true: opa scaling is enabled for this object and all children; false: no opa scaling
|
||||
*/
|
||||
lv_opa_t lv_obj_get_opa_scale_enable(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the opa scale parameter of an object
|
||||
* @param obj pointer to an object
|
||||
* @return opa scale [0..255]
|
||||
*/
|
||||
lv_opa_t lv_obj_get_opa_scale(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the protect field of an object
|
||||
* @param obj pointer to an object
|
||||
* @return protect field ('OR'ed values of `lv_protect_t`)
|
||||
*/
|
||||
uint8_t lv_obj_get_protect(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Check at least one bit of a given protect bitfield is set
|
||||
* @param obj pointer to an object
|
||||
* @param prot protect bits to test ('OR'ed values of `lv_protect_t`)
|
||||
* @return false: none of the given bits are set, true: at least one bit is set
|
||||
*/
|
||||
bool lv_obj_is_protected(const lv_obj_t * obj, uint8_t prot);
|
||||
|
||||
/**
|
||||
* Get the signal function of an object
|
||||
* @param obj pointer to an object
|
||||
* @return the signal function
|
||||
*/
|
||||
lv_signal_func_t lv_obj_get_signal_func(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get the design function of an object
|
||||
* @param obj pointer to an object
|
||||
* @return the design function
|
||||
*/
|
||||
lv_design_func_t lv_obj_get_design_func(const lv_obj_t * obj);
|
||||
|
||||
/*------------------
|
||||
* Other get
|
||||
*-----------------*/
|
||||
|
||||
/**
|
||||
* Get the ext pointer
|
||||
* @param obj pointer to an object
|
||||
* @return the ext pointer but not the dynamic version
|
||||
* Use it as ext->data1, and NOT da(ext)->data1
|
||||
*/
|
||||
void * lv_obj_get_ext_attr(const lv_obj_t * obj);
|
||||
|
||||
/**
|
||||
* Get object's and its ancestors type. Put their name in `type_buf` starting with the current type.
|
||||
* E.g. buf.type[0]="lv_btn", buf.type[1]="lv_cont", buf.type[2]="lv_obj"
|
||||
* @param obj pointer to an object which type should be get
|
||||
* @param buf pointer to an `lv_obj_type_t` buffer to store the types
|
||||
*/
|
||||
void lv_obj_get_type(lv_obj_t * obj, lv_obj_type_t * buf);
|
||||
|
||||
#ifdef LV_OBJ_FREE_NUM_TYPE
|
||||
/**
|
||||
* Get the free number
|
||||
* @param obj pointer to an object
|
||||
* @return the free number
|
||||
*/
|
||||
LV_OBJ_FREE_NUM_TYPE lv_obj_get_free_num(const lv_obj_t * obj);
|
||||
#endif
|
||||
|
||||
#if LV_OBJ_FREE_PTR != 0
|
||||
/**
|
||||
* Get the free pointer
|
||||
* @param obj pointer to an object
|
||||
* @return the free pointer
|
||||
*/
|
||||
void * lv_obj_get_free_ptr(const lv_obj_t * obj);
|
||||
#endif
|
||||
|
||||
#if USE_LV_GROUP
|
||||
/**
|
||||
* Get the group of the object
|
||||
* @param obj pointer to an object
|
||||
* @return the pointer to group of the object
|
||||
*/
|
||||
void * lv_obj_get_group(const lv_obj_t * obj);
|
||||
|
||||
|
||||
/**
|
||||
* Tell whether the object is the focused object of a group or not.
|
||||
* @param obj pointer to an object
|
||||
* @return true: the object is focused, false: the object is not focused or not in a group
|
||||
*/
|
||||
bool lv_obj_is_focused(const lv_obj_t * obj);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_OBJ_H*/
|
614
bdk/libs/lvgl/lv_core/lv_refr.c
Normal file
614
bdk/libs/lvgl/lv_core/lv_refr.c
Normal file
|
@ -0,0 +1,614 @@
|
|||
/**
|
||||
* @file lv_refr.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stddef.h>
|
||||
#include "lv_refr.h"
|
||||
#include "lv_vdb.h"
|
||||
#include "../lv_hal/lv_hal_tick.h"
|
||||
#include "../lv_hal/lv_hal_disp.h"
|
||||
#include "../lv_misc/lv_task.h"
|
||||
#include "../lv_misc/lv_mem.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef LV_INV_FIFO_SIZE
|
||||
#define LV_INV_FIFO_SIZE 32 /*The average count of objects on a screen */
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef struct {
|
||||
lv_area_t area;
|
||||
uint8_t joined;
|
||||
} lv_join_t;
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_refr_task(void * param);
|
||||
static void lv_refr_join_area(void);
|
||||
static void lv_refr_areas(void);
|
||||
#if LV_VDB_SIZE == 0
|
||||
static void lv_refr_area_no_vdb(const lv_area_t * area_p);
|
||||
#else
|
||||
static void lv_refr_area_with_vdb(const lv_area_t * area_p);
|
||||
static void lv_refr_area_part_vdb(const lv_area_t * area_p);
|
||||
#endif
|
||||
static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj);
|
||||
static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p);
|
||||
static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_join_t inv_buf[LV_INV_FIFO_SIZE];
|
||||
static uint16_t inv_buf_p;
|
||||
static void (*monitor_cb)(uint32_t, uint32_t); /*Monitor the rendering time*/
|
||||
static void (*round_cb)(lv_area_t *); /*If set then called to modify invalidated areas for special display controllers*/
|
||||
static uint32_t px_num;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the screen refresh subsystem
|
||||
*/
|
||||
void lv_refr_init(void)
|
||||
{
|
||||
inv_buf_p = 0;
|
||||
memset(inv_buf, 0, sizeof(inv_buf));
|
||||
|
||||
lv_task_t * task;
|
||||
task = lv_task_create(lv_refr_task, LV_REFR_PERIOD, LV_TASK_PRIO_MID, NULL);
|
||||
lv_task_ready(task); /*Be sure the screen will be refreshed immediately on start up*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraw the invalidated areas now.
|
||||
* Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can
|
||||
* prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar)
|
||||
* this function can be called when the screen should be updated.
|
||||
*/
|
||||
void lv_refr_now(void)
|
||||
{
|
||||
lv_refr_task(NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Invalidate an area
|
||||
* @param area_p pointer to area which should be invalidated
|
||||
*/
|
||||
void lv_inv_area(const lv_area_t * area_p)
|
||||
{
|
||||
/*Clear the invalidate buffer if the parameter is NULL*/
|
||||
if(area_p == NULL) {
|
||||
inv_buf_p = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
lv_area_t scr_area;
|
||||
scr_area.x1 = 0;
|
||||
scr_area.y1 = 0;
|
||||
scr_area.x2 = LV_HOR_RES - 1;
|
||||
scr_area.y2 = LV_VER_RES - 1;
|
||||
|
||||
lv_area_t com_area;
|
||||
bool suc;
|
||||
|
||||
suc = lv_area_intersect(&com_area, area_p, &scr_area);
|
||||
|
||||
/*The area is truncated to the screen*/
|
||||
if(suc != false) {
|
||||
if(round_cb) round_cb(&com_area);
|
||||
|
||||
/*Save only if this area is not in one of the saved areas*/
|
||||
uint16_t i;
|
||||
for(i = 0; i < inv_buf_p; i++) {
|
||||
if(lv_area_is_in(&com_area, &inv_buf[i].area) != false) return;
|
||||
}
|
||||
|
||||
/*Save the area*/
|
||||
if(inv_buf_p < LV_INV_FIFO_SIZE) {
|
||||
lv_area_copy(&inv_buf[inv_buf_p].area, &com_area);
|
||||
} else {/*If no place for the area add the screen*/
|
||||
inv_buf_p = 0;
|
||||
lv_area_copy(&inv_buf[inv_buf_p].area, &scr_area);
|
||||
}
|
||||
inv_buf_p ++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels
|
||||
* @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num))
|
||||
* time_ms: refresh time in [ms]
|
||||
* px_num: not the drawn pixels but the number of affected pixels of the screen
|
||||
* (more pixels are drawn because of overlapping objects)
|
||||
*/
|
||||
void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t))
|
||||
{
|
||||
monitor_cb = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an area is invalidated to modify the coordinates of the area.
|
||||
* Special display controllers may require special coordinate rounding
|
||||
* @param cb pointer to the a function which will modify the area
|
||||
*/
|
||||
void lv_refr_set_round_cb(void(*cb)(lv_area_t *))
|
||||
{
|
||||
round_cb = cb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of areas in the buffer
|
||||
* @return number of invalid areas
|
||||
*/
|
||||
uint16_t lv_refr_get_buf_size(void)
|
||||
{
|
||||
return inv_buf_p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop (delete) the last 'num' invalidated areas from the buffer
|
||||
* @param num number of areas to delete
|
||||
*/
|
||||
void lv_refr_pop_from_buf(uint16_t num)
|
||||
{
|
||||
if(inv_buf_p < num) inv_buf_p = 0;
|
||||
else inv_buf_p -= num;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Called periodically to handle the refreshing
|
||||
* @param param unused
|
||||
*/
|
||||
static void lv_refr_task(void * param)
|
||||
{
|
||||
(void)param;
|
||||
|
||||
LV_LOG_TRACE("display refresh task started");
|
||||
|
||||
uint32_t start = lv_tick_get();
|
||||
|
||||
if(lv_disp_get_active() == NULL) {
|
||||
LV_LOG_TRACE("No display is registered");
|
||||
return;
|
||||
}
|
||||
|
||||
lv_refr_join_area();
|
||||
|
||||
lv_refr_areas();
|
||||
|
||||
/*If refresh happened ...*/
|
||||
if(inv_buf_p != 0) {
|
||||
|
||||
/*In true double buffered mode copy the refreshed areas to the new VDB to keep it up to date*/
|
||||
#if LV_VDB_TRUE_DOUBLE_BUFFERED
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
vdb_p->area.x1 = 0;
|
||||
vdb_p->area.x2 = LV_HOR_RES-1;
|
||||
vdb_p->area.y1 = 0;
|
||||
vdb_p->area.y2 = LV_VER_RES - 1;
|
||||
|
||||
/*Flush the content of the VDB*/
|
||||
lv_vdb_flush();
|
||||
|
||||
/* With true double buffering the flushing should be only the address change of the current frame buffer
|
||||
* Wait until the address change is ready and copy the active content to the other frame buffer (new active VDB)
|
||||
* The changes will be written to the new VDB.*/
|
||||
lv_vdb_t * vdb_act = lv_vdb_get_active();
|
||||
lv_vdb_t * vdb_ina = lv_vdb_get_inactive();
|
||||
|
||||
uint8_t * buf_act = (uint8_t *) vdb_act->buf;
|
||||
uint8_t * buf_ina = (uint8_t *) vdb_ina->buf;
|
||||
|
||||
uint16_t a;
|
||||
for(a = 0; a < inv_buf_p; a++) {
|
||||
if(inv_buf[a].joined == 0) {
|
||||
lv_coord_t y;
|
||||
uint32_t start_offs = ((LV_HOR_RES * inv_buf[a].area.y1 + inv_buf[a].area.x1) * LV_VDB_PX_BPP) >> 3;
|
||||
uint32_t line_length = (lv_area_get_width(&inv_buf[a].area) * LV_VDB_PX_BPP) >> 3;
|
||||
|
||||
for(y = inv_buf[a].area.y1; y <= inv_buf[a].area.y2; y++) {
|
||||
memcpy(buf_act + start_offs, buf_ina + start_offs, line_length);
|
||||
start_offs += (LV_HOR_RES * LV_VDB_PX_BPP) >> 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*Clean up*/
|
||||
memset(inv_buf, 0, sizeof(inv_buf));
|
||||
inv_buf_p = 0;
|
||||
|
||||
/*Call monitor cb if present*/
|
||||
if(monitor_cb != NULL) {
|
||||
monitor_cb(lv_tick_elaps(start), px_num);
|
||||
}
|
||||
}
|
||||
|
||||
LV_LOG_TRACE("display refresh task finished");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Join the areas which has got common parts
|
||||
*/
|
||||
static void lv_refr_join_area(void)
|
||||
{
|
||||
uint32_t join_from;
|
||||
uint32_t join_in;
|
||||
lv_area_t joined_area;
|
||||
for(join_in = 0; join_in < inv_buf_p; join_in++) {
|
||||
if(inv_buf[join_in].joined != 0) continue;
|
||||
|
||||
/*Check all areas to join them in 'join_in'*/
|
||||
for(join_from = 0; join_from < inv_buf_p; join_from++) {
|
||||
/*Handle only unjoined areas and ignore itself*/
|
||||
if(inv_buf[join_from].joined != 0 || join_in == join_from) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*Check if the areas are on each other*/
|
||||
if(lv_area_is_on(&inv_buf[join_in].area,
|
||||
&inv_buf[join_from].area) == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lv_area_join(&joined_area, &inv_buf[join_in].area,
|
||||
&inv_buf[join_from].area);
|
||||
|
||||
/*Join two area only if the joined area size is smaller*/
|
||||
if(lv_area_get_size(&joined_area) <
|
||||
(lv_area_get_size(&inv_buf[join_in].area) + lv_area_get_size(&inv_buf[join_from].area))) {
|
||||
lv_area_copy(&inv_buf[join_in].area, &joined_area);
|
||||
|
||||
/*Mark 'join_form' is joined into 'join_in'*/
|
||||
inv_buf[join_from].joined = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the joined areas
|
||||
*/
|
||||
static void lv_refr_areas(void)
|
||||
{
|
||||
px_num = 0;
|
||||
uint32_t i;
|
||||
|
||||
for(i = 0; i < inv_buf_p; i++) {
|
||||
/*Refresh the unjoined areas*/
|
||||
if(inv_buf[i].joined == 0) {
|
||||
/*If there is no VDB do simple drawing*/
|
||||
#if LV_VDB_SIZE == 0
|
||||
lv_refr_area_no_vdb(&inv_buf[i].area);
|
||||
#else
|
||||
/*If VDB is used...*/
|
||||
lv_refr_area_with_vdb(&inv_buf[i].area);
|
||||
#endif
|
||||
if(monitor_cb != NULL) px_num += lv_area_get_size(&inv_buf[i].area);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if LV_VDB_SIZE == 0
|
||||
/**
|
||||
* Refresh an area if there is no Virtual Display Buffer
|
||||
* @param area_p pointer to an area to refresh
|
||||
*/
|
||||
static void lv_refr_area_no_vdb(const lv_area_t * area_p)
|
||||
{
|
||||
lv_obj_t * top_p;
|
||||
|
||||
/*Get top object which is not covered by others*/
|
||||
top_p = lv_refr_get_top_obj(area_p, lv_scr_act());
|
||||
|
||||
/*Do the refreshing*/
|
||||
lv_refr_obj_and_children(top_p, area_p);
|
||||
|
||||
/*Also refresh top and sys layer unconditionally*/
|
||||
lv_refr_obj_and_children(lv_layer_top(), area_p);
|
||||
lv_refr_obj_and_children(lv_layer_sys(), area_p);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* Refresh an area if there is Virtual Display Buffer
|
||||
* @param area_p pointer to an area to refresh
|
||||
*/
|
||||
static void lv_refr_area_with_vdb(const lv_area_t * area_p)
|
||||
{
|
||||
|
||||
#if LV_VDB_TRUE_DOUBLE_BUFFERED == 0
|
||||
/*Calculate the max row num*/
|
||||
lv_coord_t w = lv_area_get_width(area_p);
|
||||
lv_coord_t h = lv_area_get_height(area_p);
|
||||
lv_coord_t y2 = area_p->y2 >= LV_VER_RES ? y2 = LV_VER_RES - 1 : area_p->y2;
|
||||
|
||||
int32_t max_row = (uint32_t) LV_VDB_SIZE / w;
|
||||
|
||||
if(max_row > h) max_row = h;
|
||||
|
||||
|
||||
/*Round down the lines of VDB if rounding is added*/
|
||||
if(round_cb) {
|
||||
lv_area_t tmp;
|
||||
tmp.x1 = 0;
|
||||
tmp.x2 = 0;
|
||||
tmp.y1 = 0;
|
||||
|
||||
lv_coord_t y_tmp = max_row - 1;
|
||||
do {
|
||||
tmp.y2 = y_tmp;
|
||||
round_cb(&tmp);
|
||||
|
||||
/*If this height fits into `max_row` then fine*/
|
||||
if(lv_area_get_height(&tmp) <= max_row) break;
|
||||
|
||||
/*Decrement the height of the area until it fits into `max_row` after rounding*/
|
||||
y_tmp --;
|
||||
} while(y_tmp != 0);
|
||||
|
||||
if(y_tmp == 0) {
|
||||
LV_LOG_WARN("Can't set VDB height using the round function. (Wrong round_cb or to small VDB)");
|
||||
return;
|
||||
} else {
|
||||
max_row = tmp.y2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*Always use the full row*/
|
||||
lv_coord_t row;
|
||||
lv_coord_t row_last = 0;
|
||||
for(row = area_p->y1; row + max_row - 1 <= y2; row += max_row) {
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
if(!vdb_p) {
|
||||
LV_LOG_WARN("Invalid VDB pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Calc. the next y coordinates of VDB*/
|
||||
vdb_p->area.x1 = area_p->x1;
|
||||
vdb_p->area.x2 = area_p->x2;
|
||||
vdb_p->area.y1 = row;
|
||||
vdb_p->area.y2 = row + max_row - 1;
|
||||
if(vdb_p->area.y2 > y2) vdb_p->area.y2 = y2;
|
||||
row_last = vdb_p->area.y2;
|
||||
lv_refr_area_part_vdb(area_p);
|
||||
}
|
||||
|
||||
/*If the last y coordinates are not handled yet ...*/
|
||||
if(y2 != row_last) {
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
if(!vdb_p) {
|
||||
LV_LOG_WARN("Invalid VDB pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Calc. the next y coordinates of VDB*/
|
||||
vdb_p->area.x1 = area_p->x1;
|
||||
vdb_p->area.x2 = area_p->x2;
|
||||
vdb_p->area.y1 = row;
|
||||
vdb_p->area.y2 = y2;
|
||||
|
||||
/*Refresh this part too*/
|
||||
lv_refr_area_part_vdb(area_p);
|
||||
}
|
||||
#else
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
vdb_p->area.x1 = 0;
|
||||
vdb_p->area.x2 = LV_HOR_RES-1;
|
||||
vdb_p->area.y1 = 0;
|
||||
vdb_p->area.y2 = LV_VER_RES - 1;
|
||||
lv_refr_area_part_vdb(area_p);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh a part of an area which is on the actual Virtual Display Buffer
|
||||
* @param area_p pointer to an area to refresh
|
||||
*/
|
||||
static void lv_refr_area_part_vdb(const lv_area_t * area_p)
|
||||
{
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
if(!vdb_p) {
|
||||
LV_LOG_WARN("Invalid VDB pointer");
|
||||
return;
|
||||
}
|
||||
lv_obj_t * top_p;
|
||||
|
||||
/*Get the new mask from the original area and the act. VDB
|
||||
It will be a part of 'area_p'*/
|
||||
lv_area_t start_mask;
|
||||
lv_area_intersect(&start_mask, area_p, &vdb_p->area);
|
||||
|
||||
/*Get the most top object which is not covered by others*/
|
||||
top_p = lv_refr_get_top_obj(&start_mask, lv_scr_act());
|
||||
|
||||
/*Do the refreshing from the top object*/
|
||||
lv_refr_obj_and_children(top_p, &start_mask);
|
||||
|
||||
/*Also refresh top and sys layer unconditionally*/
|
||||
lv_refr_obj_and_children(lv_layer_top(), &start_mask);
|
||||
lv_refr_obj_and_children(lv_layer_sys(), &start_mask);
|
||||
|
||||
/* In true double buffered mode flush only once when all areas were rendered.
|
||||
* In normal mode flush after every area */
|
||||
#if LV_VDB_TRUE_DOUBLE_BUFFERED == 0
|
||||
/*Flush the content of the VDB*/
|
||||
lv_vdb_flush();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /*LV_VDB_SIZE == 0*/
|
||||
|
||||
/**
|
||||
* Search the most top object which fully covers an area
|
||||
* @param area_p pointer to an area
|
||||
* @param obj the first object to start the searching (typically a screen)
|
||||
* @return
|
||||
*/
|
||||
static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj)
|
||||
{
|
||||
lv_obj_t * i;
|
||||
lv_obj_t * found_p = NULL;
|
||||
|
||||
/*If this object is fully cover the draw area check the children too */
|
||||
if(lv_area_is_in(area_p, &obj->coords) && obj->hidden == 0) {
|
||||
LL_READ(obj->child_ll, i) {
|
||||
found_p = lv_refr_get_top_obj(area_p, i);
|
||||
|
||||
/*If a children is ok then break*/
|
||||
if(found_p != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*If no better children check this object*/
|
||||
if(found_p == NULL) {
|
||||
lv_style_t * style = lv_obj_get_style(obj);
|
||||
if(style->body.opa == LV_OPA_COVER &&
|
||||
obj->design_func(obj, area_p, LV_DESIGN_COVER_CHK) != false &&
|
||||
lv_obj_get_opa_scale(obj) == LV_OPA_COVER) {
|
||||
found_p = obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found_p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the refreshing from an object. Draw all its children and the youngers too.
|
||||
* @param top_p pointer to an objects. Start the drawing from it.
|
||||
* @param mask_p pointer to an area, the objects will be drawn only here
|
||||
*/
|
||||
static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p)
|
||||
{
|
||||
/* Normally always will be a top_obj (at least the screen)
|
||||
* but in special cases (e.g. if the screen has alpha) it won't.
|
||||
* In this case use the screen directly */
|
||||
if(top_p == NULL) top_p = lv_scr_act();
|
||||
|
||||
/*Refresh the top object and its children*/
|
||||
lv_refr_obj(top_p, mask_p);
|
||||
|
||||
/*Draw the 'younger' sibling objects because they can be on top_obj */
|
||||
lv_obj_t * par;
|
||||
lv_obj_t * i;
|
||||
lv_obj_t * border_p = top_p;
|
||||
|
||||
par = lv_obj_get_parent(top_p);
|
||||
|
||||
/*Do until not reach the screen*/
|
||||
while(par != NULL) {
|
||||
/*object before border_p has to be redrawn*/
|
||||
i = lv_ll_get_prev(&(par->child_ll), border_p);
|
||||
|
||||
while(i != NULL) {
|
||||
/*Refresh the objects*/
|
||||
lv_refr_obj(i, mask_p);
|
||||
i = lv_ll_get_prev(&(par->child_ll), i);
|
||||
}
|
||||
|
||||
/*The new border will be there last parents,
|
||||
*so the 'younger' brothers of parent will be refreshed*/
|
||||
border_p = par;
|
||||
/*Go a level deeper*/
|
||||
par = lv_obj_get_parent(par);
|
||||
}
|
||||
|
||||
/*Call the post draw design function of the parents of the to object*/
|
||||
par = lv_obj_get_parent(top_p);
|
||||
while(par != NULL) {
|
||||
par->design_func(par, mask_p, LV_DESIGN_DRAW_POST);
|
||||
par = lv_obj_get_parent(par);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh an object an all of its children. (Called recursively)
|
||||
* @param obj pointer to an object to refresh
|
||||
* @param mask_ori_p pointer to an area, the objects will be drawn only here
|
||||
*/
|
||||
static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p)
|
||||
{
|
||||
/*Do not refresh hidden objects*/
|
||||
if(obj->hidden != 0) return;
|
||||
|
||||
bool union_ok; /* Store the return value of area_union */
|
||||
/* Truncate the original mask to the coordinates of the parent
|
||||
* because the parent and its children are visible only here */
|
||||
lv_area_t obj_mask;
|
||||
lv_area_t obj_ext_mask;
|
||||
lv_area_t obj_area;
|
||||
lv_coord_t ext_size = obj->ext_size;
|
||||
lv_obj_get_coords(obj, &obj_area);
|
||||
obj_area.x1 -= ext_size;
|
||||
obj_area.y1 -= ext_size;
|
||||
obj_area.x2 += ext_size;
|
||||
obj_area.y2 += ext_size;
|
||||
union_ok = lv_area_intersect(&obj_ext_mask, mask_ori_p, &obj_area);
|
||||
|
||||
/*Draw the parent and its children only if they ore on 'mask_parent'*/
|
||||
if(union_ok != false) {
|
||||
|
||||
/* Redraw the object */
|
||||
obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_MAIN);
|
||||
//usleep(5 * 1000); /*DEBUG: Wait after every object draw to see the order of drawing*/
|
||||
|
||||
|
||||
/*Create a new 'obj_mask' without 'ext_size' because the children can't be visible there*/
|
||||
lv_obj_get_coords(obj, &obj_area);
|
||||
union_ok = lv_area_intersect(&obj_mask, mask_ori_p, &obj_area);
|
||||
if(union_ok != false) {
|
||||
lv_area_t mask_child; /*Mask from obj and its child*/
|
||||
lv_obj_t * child_p;
|
||||
lv_area_t child_area;
|
||||
LL_READ_BACK(obj->child_ll, child_p) {
|
||||
lv_obj_get_coords(child_p, &child_area);
|
||||
ext_size = child_p->ext_size;
|
||||
child_area.x1 -= ext_size;
|
||||
child_area.y1 -= ext_size;
|
||||
child_area.x2 += ext_size;
|
||||
child_area.y2 += ext_size;
|
||||
/* Get the union (common parts) of original mask (from obj)
|
||||
* and its child */
|
||||
union_ok = lv_area_intersect(&mask_child, &obj_mask, &child_area);
|
||||
|
||||
/*If the parent and the child has common area then refresh the child */
|
||||
if(union_ok) {
|
||||
/*Refresh the next children*/
|
||||
lv_refr_obj(child_p, &mask_child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If all the children are redrawn make 'post draw' design */
|
||||
obj->design_func(obj, &obj_ext_mask, LV_DESIGN_DRAW_POST);
|
||||
|
||||
}
|
||||
}
|
94
bdk/libs/lvgl/lv_core/lv_refr.h
Normal file
94
bdk/libs/lvgl/lv_core/lv_refr.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
* @file lv_refr.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_REFR_H
|
||||
#define LV_REFR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_obj.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the screen refresh subsystem
|
||||
*/
|
||||
void lv_refr_init(void);
|
||||
|
||||
/**
|
||||
* Redraw the invalidated areas now.
|
||||
* Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can
|
||||
* prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar)
|
||||
* this function can be called when the screen should be updated.
|
||||
*/
|
||||
void lv_refr_now(void);
|
||||
|
||||
/**
|
||||
* Invalidate an area
|
||||
* @param area_p pointer to area which should be invalidated
|
||||
*/
|
||||
void lv_inv_area(const lv_area_t * area_p);
|
||||
|
||||
/**
|
||||
* Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels
|
||||
* @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num))
|
||||
*/
|
||||
void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t));
|
||||
|
||||
/**
|
||||
* Called when an area is invalidated to modify the coordinates of the area.
|
||||
* Special display controllers may require special coordinate rounding
|
||||
* @param cb pointer to the a function which will modify the area
|
||||
*/
|
||||
void lv_refr_set_round_cb(void(*cb)(lv_area_t*));
|
||||
|
||||
/**
|
||||
* Get the number of areas in the buffer
|
||||
* @return number of invalid areas
|
||||
*/
|
||||
uint16_t lv_refr_get_buf_size(void);
|
||||
|
||||
/**
|
||||
* Pop (delete) the last 'num' invalidated areas from the buffer
|
||||
* @param num number of areas to delete
|
||||
*/
|
||||
void lv_refr_pop_from_buf(uint16_t num);
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_REFR_H*/
|
357
bdk/libs/lvgl/lv_core/lv_style.c
Normal file
357
bdk/libs/lvgl/lv_core/lv_style.c
Normal file
|
@ -0,0 +1,357 @@
|
|||
/*
|
||||
* Copyright (c) 2018 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_obj.h"
|
||||
#include "../lv_misc/lv_mem.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define STYLE_MIX_MAX 256
|
||||
#define STYLE_MIX_SHIFT 8 /*log2(STYLE_MIX_MAX)*/
|
||||
|
||||
#define VAL_PROP(v1, v2, r) v1 + (((v2-v1) * r) >> STYLE_MIX_SHIFT)
|
||||
#define STYLE_ATTR_MIX(attr, r) if(start->attr != end->attr) {res->attr = VAL_PROP(start->attr, end->attr, r);} else {res->attr = start->attr;}
|
||||
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
#if USE_LV_ANIMATION
|
||||
typedef struct {
|
||||
lv_style_t style_start; /*Save not only pointers because can be same as 'style_anim' then it will be modified too*/
|
||||
lv_style_t style_end;
|
||||
lv_style_t * style_anim;
|
||||
void (*end_cb)(void *);
|
||||
} lv_style_anim_dsc_t;
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
#if USE_LV_ANIMATION
|
||||
static void style_animator(lv_style_anim_dsc_t * dsc, int32_t val);
|
||||
static void style_animation_common_end_cb(void * ptr);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
lv_style_t lv_style_scr;
|
||||
lv_style_t lv_style_transp;
|
||||
lv_style_t lv_style_transp_fit;
|
||||
lv_style_t lv_style_transp_tight;
|
||||
lv_style_t lv_style_plain;
|
||||
lv_style_t lv_style_plain_color;
|
||||
lv_style_t lv_style_pretty;
|
||||
lv_style_t lv_style_pretty_color;
|
||||
lv_style_t lv_style_btn_rel;
|
||||
lv_style_t lv_style_btn_pr;
|
||||
lv_style_t lv_style_btn_tgl_rel;
|
||||
lv_style_t lv_style_btn_tgl_pr;
|
||||
lv_style_t lv_style_btn_ina;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Init the basic styles
|
||||
*/
|
||||
void lv_style_init(void)
|
||||
{
|
||||
/* Not White/Black/Gray colors are created by HSV model with
|
||||
* HUE = 210*/
|
||||
|
||||
/*Screen style*/
|
||||
lv_style_scr.glass = 0;
|
||||
lv_style_scr.body.opa = LV_OPA_COVER;
|
||||
lv_style_scr.body.main_color = LV_COLOR_BLACK;
|
||||
lv_style_scr.body.grad_color = LV_COLOR_BLACK;
|
||||
lv_style_scr.body.radius = 0;
|
||||
lv_style_scr.body.padding.ver = LV_DPI / 12;
|
||||
lv_style_scr.body.padding.hor = LV_DPI / 12;
|
||||
lv_style_scr.body.padding.inner = LV_DPI / 12;
|
||||
|
||||
lv_style_scr.body.border.color = LV_COLOR_WHITE;
|
||||
lv_style_scr.body.border.opa = LV_OPA_COVER;
|
||||
lv_style_scr.body.border.width = 0;
|
||||
lv_style_scr.body.border.part = LV_BORDER_FULL;
|
||||
|
||||
lv_style_scr.body.shadow.color = LV_COLOR_GRAY;
|
||||
lv_style_scr.body.shadow.type = LV_SHADOW_FULL;
|
||||
lv_style_scr.body.shadow.width = 0;
|
||||
|
||||
lv_style_scr.text.opa = LV_OPA_COVER;
|
||||
lv_style_scr.text.color = LV_COLOR_HEX(0xFBFBFB);
|
||||
lv_style_scr.text.font = LV_FONT_DEFAULT;
|
||||
lv_style_scr.text.letter_space = 3; // Important
|
||||
lv_style_scr.text.line_space = 2;
|
||||
|
||||
lv_style_scr.image.opa = LV_OPA_COVER;
|
||||
lv_style_scr.image.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
|
||||
lv_style_scr.image.intense = LV_OPA_TRANSP;
|
||||
|
||||
lv_style_scr.line.opa = LV_OPA_COVER;
|
||||
lv_style_scr.line.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
|
||||
lv_style_scr.line.width = 2;
|
||||
lv_style_scr.line.rounded = 0;
|
||||
|
||||
/*Plain style (by default near the same as the screen style)*/
|
||||
memcpy(&lv_style_plain, &lv_style_scr, sizeof(lv_style_t));
|
||||
|
||||
/*Plain color style*/
|
||||
memcpy(&lv_style_plain_color, &lv_style_plain, sizeof(lv_style_t));
|
||||
lv_style_plain_color.text.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0);
|
||||
lv_style_plain_color.image.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0);
|
||||
lv_style_plain_color.line.color = LV_COLOR_MAKE(0xf0, 0xf0, 0xf0);
|
||||
lv_style_plain_color.body.main_color = LV_COLOR_MAKE(0x55, 0x96, 0xd8);
|
||||
lv_style_plain_color.body.grad_color = lv_style_plain_color.body.main_color;
|
||||
|
||||
/*Pretty style */
|
||||
memcpy(&lv_style_pretty, &lv_style_plain, sizeof(lv_style_t));
|
||||
lv_style_pretty.text.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
|
||||
lv_style_pretty.image.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
|
||||
lv_style_pretty.line.color = LV_COLOR_MAKE(0x20, 0x20, 0x20);
|
||||
lv_style_pretty.body.main_color = LV_COLOR_WHITE;
|
||||
lv_style_pretty.body.grad_color = LV_COLOR_SILVER;
|
||||
lv_style_pretty.body.radius = LV_DPI / 15;
|
||||
lv_style_pretty.body.border.color = LV_COLOR_MAKE(0x40, 0x40, 0x40);
|
||||
lv_style_pretty.body.border.width = LV_DPI / 50 >= 1 ? LV_DPI / 50 : 1;
|
||||
lv_style_pretty.body.border.opa = LV_OPA_30;
|
||||
|
||||
/*Pretty color style*/
|
||||
memcpy(&lv_style_pretty_color, &lv_style_pretty, sizeof(lv_style_t));
|
||||
lv_style_pretty_color.text.color = LV_COLOR_MAKE(0xe0, 0xe0, 0xe0);
|
||||
lv_style_pretty_color.image.color = LV_COLOR_MAKE(0xe0, 0xe0, 0xe0);
|
||||
lv_style_pretty_color.line.color = LV_COLOR_MAKE(0xc0, 0xc0, 0xc0);
|
||||
lv_style_pretty_color.body.main_color = LV_COLOR_MAKE(0x6b, 0x9a, 0xc7);
|
||||
lv_style_pretty_color.body.grad_color = LV_COLOR_MAKE(0x2b, 0x59, 0x8b);
|
||||
lv_style_pretty_color.body.border.color = LV_COLOR_MAKE(0x15, 0x2c, 0x42);
|
||||
|
||||
/*Transparent style*/
|
||||
memcpy(&lv_style_transp, &lv_style_plain, sizeof(lv_style_t));
|
||||
lv_style_transp.body.empty = 1;
|
||||
lv_style_transp.glass = 1;
|
||||
lv_style_transp.body.border.width = 0;
|
||||
|
||||
/*Transparent fitting size*/
|
||||
memcpy(&lv_style_transp_fit, &lv_style_transp, sizeof(lv_style_t));
|
||||
lv_style_transp_fit.body.padding.hor = 0;
|
||||
lv_style_transp_fit.body.padding.ver = 0;
|
||||
|
||||
/*Transparent tight style*/
|
||||
memcpy(&lv_style_transp_tight, &lv_style_transp_fit, sizeof(lv_style_t));
|
||||
lv_style_transp_tight.body.padding.inner = 0;
|
||||
|
||||
/*Button released style*/
|
||||
memcpy(&lv_style_btn_rel, &lv_style_plain, sizeof(lv_style_t));
|
||||
lv_style_btn_rel.body.main_color = LV_COLOR_MAKE(0x76, 0xa2, 0xd0);
|
||||
lv_style_btn_rel.body.grad_color = LV_COLOR_MAKE(0x19, 0x3a, 0x5d);
|
||||
lv_style_btn_rel.body.radius = LV_DPI / 15;
|
||||
lv_style_btn_rel.body.padding.hor = LV_DPI / 4;
|
||||
lv_style_btn_rel.body.padding.ver = LV_DPI / 6;
|
||||
lv_style_btn_rel.body.padding.inner = LV_DPI / 10;
|
||||
lv_style_btn_rel.body.border.color = LV_COLOR_MAKE(0x0b, 0x19, 0x28);
|
||||
lv_style_btn_rel.body.border.width = LV_DPI / 50 >= 1 ? LV_DPI / 50 : 1;
|
||||
lv_style_btn_rel.body.border.opa = LV_OPA_70;
|
||||
lv_style_btn_rel.body.shadow.color = LV_COLOR_GRAY;
|
||||
lv_style_btn_rel.body.shadow.width = 0;
|
||||
lv_style_btn_rel.text.color = LV_COLOR_MAKE(0xff, 0xff, 0xff);
|
||||
lv_style_btn_rel.image.color = LV_COLOR_MAKE(0xff, 0xff, 0xff);
|
||||
|
||||
/*Button pressed style*/
|
||||
memcpy(&lv_style_btn_pr, &lv_style_btn_rel, sizeof(lv_style_t));
|
||||
lv_style_btn_pr.body.main_color = LV_COLOR_MAKE(0x33, 0x62, 0x94);
|
||||
lv_style_btn_pr.body.grad_color = LV_COLOR_MAKE(0x10, 0x26, 0x3c);
|
||||
lv_style_btn_pr.text.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
|
||||
lv_style_btn_pr.image.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
|
||||
lv_style_btn_pr.line.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
|
||||
|
||||
/*Button toggle released style*/
|
||||
memcpy(&lv_style_btn_tgl_rel, &lv_style_btn_rel, sizeof(lv_style_t));
|
||||
lv_style_btn_tgl_rel.body.main_color = LV_COLOR_MAKE(0x0a, 0x11, 0x22);
|
||||
lv_style_btn_tgl_rel.body.grad_color = LV_COLOR_MAKE(0x37, 0x62, 0x90);
|
||||
lv_style_btn_tgl_rel.body.border.color = LV_COLOR_MAKE(0x01, 0x07, 0x0d);
|
||||
lv_style_btn_tgl_rel.text.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4);
|
||||
lv_style_btn_tgl_rel.image.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4);
|
||||
lv_style_btn_tgl_rel.line.color = LV_COLOR_MAKE(0xc8, 0xdd, 0xf4);
|
||||
|
||||
/*Button toggle pressed style*/
|
||||
memcpy(&lv_style_btn_tgl_pr, &lv_style_btn_tgl_rel, sizeof(lv_style_t));
|
||||
lv_style_btn_tgl_pr.body.main_color = LV_COLOR_MAKE(0x02, 0x14, 0x27);
|
||||
lv_style_btn_tgl_pr.body.grad_color = LV_COLOR_MAKE(0x2b, 0x4c, 0x70);
|
||||
lv_style_btn_tgl_pr.text.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
|
||||
lv_style_btn_tgl_pr.image.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
|
||||
lv_style_btn_tgl_pr.line.color = LV_COLOR_MAKE(0xa4, 0xb5, 0xc6);
|
||||
|
||||
/*Button inactive style*/
|
||||
memcpy(&lv_style_btn_ina, &lv_style_btn_rel, sizeof(lv_style_t));
|
||||
lv_style_btn_ina.body.main_color = LV_COLOR_MAKE(0xd8, 0xd8, 0xd8);
|
||||
lv_style_btn_ina.body.grad_color = LV_COLOR_MAKE(0xd8, 0xd8, 0xd8);
|
||||
lv_style_btn_ina.body.border.color = LV_COLOR_MAKE(0x90, 0x90, 0x90);
|
||||
lv_style_btn_ina.text.color = LV_COLOR_MAKE(0x70, 0x70, 0x70);
|
||||
lv_style_btn_ina.image.color = LV_COLOR_MAKE(0x70, 0x70, 0x70);
|
||||
lv_style_btn_ina.line.color = LV_COLOR_MAKE(0x70, 0x70, 0x70);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy a style to an other
|
||||
* @param dest pointer to the destination style
|
||||
* @param src pointer to the source style
|
||||
*/
|
||||
void lv_style_copy(lv_style_t * dest, const lv_style_t * src)
|
||||
{
|
||||
memcpy(dest, src, sizeof(lv_style_t));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mix two styles according to a given ratio
|
||||
* @param start start style
|
||||
* @param end end style
|
||||
* @param res store the result style here
|
||||
* @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style
|
||||
*/
|
||||
void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio)
|
||||
{
|
||||
STYLE_ATTR_MIX(body.opa, ratio);
|
||||
STYLE_ATTR_MIX(body.radius, ratio);
|
||||
STYLE_ATTR_MIX(body.border.width, ratio);
|
||||
STYLE_ATTR_MIX(body.border.opa, ratio);
|
||||
STYLE_ATTR_MIX(body.shadow.width, ratio);
|
||||
STYLE_ATTR_MIX(body.padding.hor, ratio);
|
||||
STYLE_ATTR_MIX(body.padding.ver, ratio);
|
||||
STYLE_ATTR_MIX(body.padding.inner, ratio);
|
||||
STYLE_ATTR_MIX(text.line_space, ratio);
|
||||
STYLE_ATTR_MIX(text.letter_space, ratio);
|
||||
STYLE_ATTR_MIX(text.opa, ratio);
|
||||
STYLE_ATTR_MIX(line.width, ratio);
|
||||
STYLE_ATTR_MIX(line.opa, ratio);
|
||||
STYLE_ATTR_MIX(image.intense, ratio);
|
||||
STYLE_ATTR_MIX(image.opa, ratio);
|
||||
|
||||
lv_opa_t opa = ratio == STYLE_MIX_MAX ? LV_OPA_COVER : ratio;
|
||||
|
||||
res->body.main_color = lv_color_mix(end->body.main_color, start->body.main_color, opa);
|
||||
res->body.grad_color = lv_color_mix(end->body.grad_color, start->body.grad_color, opa);
|
||||
res->body.border.color = lv_color_mix(end->body.border.color, start->body.border.color, opa);
|
||||
res->body.shadow.color = lv_color_mix(end->body.shadow.color, start->body.shadow.color, opa);
|
||||
res->text.color = lv_color_mix(end->text.color, start->text.color, opa);
|
||||
res->image.color = lv_color_mix(end->image.color, start->image.color, opa);
|
||||
res->line.color = lv_color_mix(end->line.color, start->line.color, opa);
|
||||
|
||||
if(ratio < (STYLE_MIX_MAX >> 1)) {
|
||||
res->body.empty = start->body.empty;
|
||||
res->body.border.part = start->body.border.part;
|
||||
res->glass = start->glass;
|
||||
res->text.font = start->text.font;
|
||||
res->body.shadow.type = start->body.shadow.type;
|
||||
res->line.rounded = start->line.rounded;
|
||||
} else {
|
||||
res->body.empty = end->body.empty;
|
||||
res->body.border.part = end->body.border.part;
|
||||
res->glass = end->glass;
|
||||
res->text.font = end->text.font;
|
||||
res->body.shadow.type = end->body.shadow.type;
|
||||
res->line.rounded = end->line.rounded;
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
|
||||
/**
|
||||
* Create an animation from a pre-configured 'lv_style_anim_t' variable
|
||||
* @param anim pointer to a pre-configured 'lv_style_anim_t' variable (will be copied)
|
||||
* @return pointer to a descriptor. Really this variable will be animated. (Can be used in `lv_anim_del(dsc, NULL)`)
|
||||
*/
|
||||
void * lv_style_anim_create(lv_style_anim_t * anim)
|
||||
{
|
||||
lv_style_anim_dsc_t * dsc;
|
||||
dsc = lv_mem_alloc(sizeof(lv_style_anim_dsc_t));
|
||||
lv_mem_assert(dsc);
|
||||
if(dsc == NULL) return NULL;
|
||||
|
||||
dsc->style_anim = anim->style_anim;
|
||||
memcpy(&dsc->style_start, anim->style_start, sizeof(lv_style_t));
|
||||
memcpy(&dsc->style_end, anim->style_end, sizeof(lv_style_t));
|
||||
memcpy(dsc->style_anim, anim->style_start, sizeof(lv_style_t));
|
||||
dsc->end_cb = anim->end_cb;
|
||||
|
||||
|
||||
lv_anim_t a;
|
||||
a.var = (void *)dsc;
|
||||
a.start = 0;
|
||||
a.end = STYLE_MIX_MAX;
|
||||
a.fp = (lv_anim_fp_t)style_animator;
|
||||
a.path = lv_anim_path_linear;
|
||||
a.end_cb = style_animation_common_end_cb;
|
||||
a.act_time = anim->act_time;
|
||||
a.time = anim->time;
|
||||
a.playback = anim->playback;
|
||||
a.playback_pause = anim->playback_pause;
|
||||
a.repeat = anim->repeat;
|
||||
a.repeat_pause = anim->repeat_pause;
|
||||
|
||||
lv_anim_create(&a);
|
||||
|
||||
return dsc;
|
||||
}
|
||||
|
||||
#endif
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
#if USE_LV_ANIMATION
|
||||
/**
|
||||
* Used by the style animations to set the values of a style according to start and end style.
|
||||
* @param dsc the 'animated variable' set by lv_style_anim_create()
|
||||
* @param val the current state of the animation between 0 and LV_STYLE_ANIM_RES
|
||||
*/
|
||||
static void style_animator(lv_style_anim_dsc_t * dsc, int32_t val)
|
||||
{
|
||||
const lv_style_t * start = &dsc->style_start;
|
||||
const lv_style_t * end = &dsc->style_end;
|
||||
lv_style_t * act = dsc->style_anim;
|
||||
|
||||
lv_style_mix(start, end, act, val);
|
||||
|
||||
lv_obj_report_style_mod(dsc->style_anim);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a style animation is ready
|
||||
* It called the user defined call back and free the allocated memories
|
||||
* @param ptr the 'animated variable' set by lv_style_anim_create()
|
||||
*/
|
||||
static void style_animation_common_end_cb(void * ptr)
|
||||
{
|
||||
lv_style_anim_dsc_t * dsc = ptr; /*To avoid casting*/
|
||||
|
||||
if(dsc->end_cb) dsc->end_cb(dsc);
|
||||
|
||||
lv_mem_free(dsc);
|
||||
}
|
||||
|
||||
#endif
|
198
bdk/libs/lvgl/lv_core/lv_style.h
Normal file
198
bdk/libs/lvgl/lv_core/lv_style.h
Normal file
|
@ -0,0 +1,198 @@
|
|||
/**
|
||||
* @file lv_style.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_STYLE_H
|
||||
#define LV_STYLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../lv_misc/lv_color.h"
|
||||
#include "../lv_misc/lv_area.h"
|
||||
#include "../lv_misc/lv_font.h"
|
||||
#include "../lv_misc/lv_anim.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_RADIUS_CIRCLE (LV_COORD_MAX) /*A very big radius to always draw as circle*/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Border types (Use 'OR'ed values)*/
|
||||
enum
|
||||
{
|
||||
LV_BORDER_NONE = 0x00,
|
||||
LV_BORDER_BOTTOM = 0x01,
|
||||
LV_BORDER_TOP = 0x02,
|
||||
LV_BORDER_LEFT = 0x04,
|
||||
LV_BORDER_RIGHT = 0x08,
|
||||
LV_BORDER_FULL = 0x0F,
|
||||
LV_BORDER_INTERNAL = 0x10, /*FOR matrix-like objects (e.g. Button matrix)*/
|
||||
};
|
||||
typedef uint8_t lv_border_part_t;
|
||||
|
||||
/*Shadow types*/
|
||||
enum
|
||||
{
|
||||
LV_SHADOW_BOTTOM = 0,
|
||||
LV_SHADOW_FULL,
|
||||
};
|
||||
typedef uint8_t lv_shadow_type_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t glass :1; /*1: Do not inherit this style*/
|
||||
|
||||
struct {
|
||||
lv_color_t main_color;
|
||||
lv_color_t grad_color; /*`grad_color` will be removed in v6.0, use `aux_color` instead*/
|
||||
lv_coord_t radius;
|
||||
lv_opa_t opa;
|
||||
|
||||
struct {
|
||||
lv_color_t color;
|
||||
lv_coord_t width;
|
||||
lv_border_part_t part;
|
||||
lv_opa_t opa;
|
||||
} border;
|
||||
|
||||
struct {
|
||||
lv_color_t color;
|
||||
lv_coord_t width;
|
||||
lv_shadow_type_t type;
|
||||
} shadow;
|
||||
|
||||
struct {
|
||||
lv_coord_t ver;
|
||||
lv_coord_t hor;
|
||||
lv_coord_t inner;
|
||||
} padding;
|
||||
|
||||
uint8_t empty :1; /*Transparent background (border still drawn)*/
|
||||
} body;
|
||||
|
||||
|
||||
struct {
|
||||
lv_color_t color;
|
||||
const lv_font_t * font;
|
||||
lv_coord_t letter_space;
|
||||
lv_coord_t line_space;
|
||||
lv_opa_t opa;
|
||||
} text;
|
||||
|
||||
struct {
|
||||
lv_color_t color;
|
||||
lv_opa_t intense;
|
||||
lv_opa_t opa;
|
||||
} image;
|
||||
|
||||
struct {
|
||||
lv_color_t color;
|
||||
lv_coord_t width;
|
||||
lv_opa_t opa;
|
||||
uint8_t rounded :1; /*1: rounded line endings*/
|
||||
} line;
|
||||
} lv_style_t;
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
typedef struct {
|
||||
const lv_style_t * style_start; /*Pointer to the starting style*/
|
||||
const lv_style_t * style_end; /*Pointer to the destination style*/
|
||||
lv_style_t * style_anim; /*Pointer to a style to animate*/
|
||||
lv_anim_cb_t end_cb; /*Call it when the animation is ready (NULL if unused)*/
|
||||
int16_t time; /*Animation time in ms*/
|
||||
int16_t act_time; /*Current time in animation. Set to negative to make delay.*/
|
||||
uint16_t playback_pause; /*Wait before play back*/
|
||||
uint16_t repeat_pause; /*Wait before repeat*/
|
||||
uint8_t playback :1; /*When the animation is ready play it back*/
|
||||
uint8_t repeat :1; /*Repeat the animation infinitely*/
|
||||
} lv_style_anim_t;
|
||||
|
||||
/* Example initialization
|
||||
lv_style_anim_t a;
|
||||
a.style_anim = &style_to_anim;
|
||||
a.style_start = &style_1;
|
||||
a.style_end = &style_2;
|
||||
a.act_time = 0;
|
||||
a.time = 1000;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
a.end_cb = NULL;
|
||||
lv_style_anim_create(&a);
|
||||
*/
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Init the basic styles
|
||||
*/
|
||||
void lv_style_init (void);
|
||||
|
||||
/**
|
||||
* Copy a style to an other
|
||||
* @param dest pointer to the destination style
|
||||
* @param src pointer to the source style
|
||||
*/
|
||||
void lv_style_copy(lv_style_t * dest, const lv_style_t * src);
|
||||
|
||||
|
||||
/**
|
||||
* Mix two styles according to a given ratio
|
||||
* @param start start style
|
||||
* @param end end style
|
||||
* @param res store the result style here
|
||||
* @param ratio the ratio of mix [0..256]; 0: `start` style; 256: `end` style
|
||||
*/
|
||||
void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t * res, uint16_t ratio);
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
|
||||
/**
|
||||
* Create an animation from a pre-configured 'lv_style_anim_t' variable
|
||||
* @param anim pointer to a pre-configured 'lv_style_anim_t' variable (will be copied)
|
||||
* @return pointer to a descriptor. Really this variable will be animated. (Can be used in `lv_anim_del(dsc, NULL)`)
|
||||
*/
|
||||
void * lv_style_anim_create(lv_style_anim_t * anim);
|
||||
#endif
|
||||
|
||||
/*************************
|
||||
* GLOBAL VARIABLES
|
||||
*************************/
|
||||
extern lv_style_t lv_style_scr;
|
||||
extern lv_style_t lv_style_transp;
|
||||
extern lv_style_t lv_style_transp_fit;
|
||||
extern lv_style_t lv_style_transp_tight;
|
||||
extern lv_style_t lv_style_plain;
|
||||
extern lv_style_t lv_style_plain_color;
|
||||
extern lv_style_t lv_style_pretty;
|
||||
extern lv_style_t lv_style_pretty_color;
|
||||
extern lv_style_t lv_style_btn_rel;
|
||||
extern lv_style_t lv_style_btn_pr;
|
||||
extern lv_style_t lv_style_btn_tgl_rel;
|
||||
extern lv_style_t lv_style_btn_tgl_pr;
|
||||
extern lv_style_t lv_style_btn_ina;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_STYLE_H*/
|
207
bdk/libs/lvgl/lv_core/lv_vdb.c
Normal file
207
bdk/libs/lvgl/lv_core/lv_vdb.c
Normal file
|
@ -0,0 +1,207 @@
|
|||
/**
|
||||
* @file lv_vdb.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_vdb.h"
|
||||
#if LV_VDB_SIZE != 0
|
||||
|
||||
#include "../lv_hal/lv_hal_disp.h"
|
||||
#include "../lv_misc/lv_log.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef LV_ATTRIBUTE_FLUSH_READY
|
||||
#define LV_ATTRIBUTE_FLUSH_READY
|
||||
#endif
|
||||
|
||||
#ifndef LV_ATTRIBUTE_MEM_ALIGN
|
||||
#define LV_ATTRIBUTE_MEM_ALIGN
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/*Simple VDB*/
|
||||
#if LV_VDB_DOUBLE == 0
|
||||
# if LV_VDB_ADR == 0
|
||||
/*If the buffer address is not specified simply allocate it*/
|
||||
static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf[LV_VDB_SIZE_IN_BYTES];
|
||||
static lv_vdb_t vdb = {.buf = (lv_color_t *)vdb_buf};
|
||||
# else /*LV_VDB_ADR != 0*/
|
||||
/*If the buffer address is specified use that address*/
|
||||
static lv_vdb_t vdb = {.buf = (lv_color_t *)LV_VDB_ADR};
|
||||
# endif
|
||||
|
||||
/*LV_VDB_DOUBLE != 0*/
|
||||
#else
|
||||
/*Double VDB*/
|
||||
static uint8_t vdb_active = 0;
|
||||
# if LV_VDB_ADR == 0
|
||||
/*If the buffer address is not specified simply allocate it*/
|
||||
static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf1[LV_VDB_SIZE_IN_BYTES];
|
||||
static LV_ATTRIBUTE_MEM_ALIGN uint8_t vdb_buf2[LV_VDB_SIZE_IN_BYTES];
|
||||
static lv_vdb_t vdb[2] = {{.buf = (lv_color_t *) vdb_buf1}, {.buf = (lv_color_t *) vdb_buf2}};
|
||||
# else /*LV_VDB_ADR != 0*/
|
||||
/*If the buffer address is specified use that address*/
|
||||
static lv_vdb_t vdb[2] = {{.buf = (lv_color_t *)LV_VDB_ADR}, {.buf = (lv_color_t *)LV_VDB2_ADR}};
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static volatile bool vdb_flushing = false;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode
|
||||
* @return pointer to a 'vdb' variable
|
||||
*/
|
||||
lv_vdb_t * lv_vdb_get(void)
|
||||
{
|
||||
#if LV_VDB_DOUBLE == 0
|
||||
/* Wait until VDB is flushing.
|
||||
* (Until this user calls of 'lv_flush_ready()' in the display drivers's flush function*/
|
||||
while(vdb_flushing);
|
||||
|
||||
return &vdb;
|
||||
#else
|
||||
/*If already there is an active do nothing*/
|
||||
return &vdb[vdb_active];
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the content of the VDB
|
||||
*/
|
||||
void lv_vdb_flush(void)
|
||||
{
|
||||
lv_vdb_t * vdb_act = lv_vdb_get();
|
||||
if(!vdb_act) {
|
||||
LV_LOG_WARN("Invalid VDB pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Don't start a new flush while the previous is not finished*/
|
||||
#if LV_VDB_DOUBLE
|
||||
while(vdb_flushing);
|
||||
#endif /*LV_VDB_DOUBLE*/
|
||||
|
||||
vdb_flushing = true;
|
||||
|
||||
/*Flush the rendered content to the display*/
|
||||
lv_disp_flush(vdb_act->area.x1, vdb_act->area.y1, vdb_act->area.x2, vdb_act->area.y2, vdb_act->buf);
|
||||
|
||||
|
||||
#if LV_VDB_DOUBLE
|
||||
/*Make the other VDB active. The content of the current will be kept until the next flush*/
|
||||
vdb_active++;
|
||||
vdb_active &= 0x1;
|
||||
|
||||
/*If the screen is transparent initialize it when the new VDB is selected*/
|
||||
# if LV_COLOR_SCREEN_TRANSP
|
||||
memset(vdb[vdb_active].buf, 0x00, LV_VDB_SIZE_IN_BYTES);
|
||||
# endif /*LV_COLOR_SCREEN_TRANSP*/
|
||||
|
||||
#endif /*#if LV_VDB_DOUBLE*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`.
|
||||
* It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES`
|
||||
* @param buf1 address of the VDB.
|
||||
* @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0`
|
||||
*/
|
||||
void lv_vdb_set_adr(void * buf1, void * buf2)
|
||||
{
|
||||
#if LV_VDB_DOUBLE == 0
|
||||
(void) buf2; /*unused*/
|
||||
vdb.buf = buf1;
|
||||
#else
|
||||
vdb[0].buf = buf1;
|
||||
vdb[1].buf = buf2;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Call in the display driver's 'disp_flush' function when the flushing is finished
|
||||
*/
|
||||
LV_ATTRIBUTE_FLUSH_READY void lv_flush_ready(void)
|
||||
{
|
||||
vdb_flushing = false;
|
||||
|
||||
/*If the screen is transparent initialize it when the flushing is ready*/
|
||||
#if LV_VDB_DOUBLE == 0 && LV_COLOR_SCREEN_TRANSP
|
||||
memset(vdb_buf, 0x00, LV_VDB_SIZE_IN_BYTES);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1`
|
||||
* @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB
|
||||
*/
|
||||
lv_vdb_t * lv_vdb_get_active(void)
|
||||
{
|
||||
#if LV_VDB_DOUBLE == 0
|
||||
return &vdb;
|
||||
#else
|
||||
return &vdb[vdb_active];
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1`
|
||||
* @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB
|
||||
*/
|
||||
lv_vdb_t * lv_vdb_get_inactive(void)
|
||||
{
|
||||
#if LV_VDB_DOUBLE == 0
|
||||
return &vdb;
|
||||
#else
|
||||
return &vdb[(vdb_active + 1) & 0x1];
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the flushing is in progress or not
|
||||
* @return true: flushing is in progress; false: flushing ready
|
||||
*/
|
||||
bool lv_vdb_is_flushing(void)
|
||||
{
|
||||
return vdb_flushing;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#else
|
||||
|
||||
/**
|
||||
* Just for compatibility
|
||||
*/
|
||||
void lv_flush_ready(void)
|
||||
{
|
||||
/*Do nothing. It is used only for VDB*/
|
||||
}
|
||||
#endif
|
119
bdk/libs/lvgl/lv_core/lv_vdb.h
Normal file
119
bdk/libs/lvgl/lv_core/lv_vdb.h
Normal file
|
@ -0,0 +1,119 @@
|
|||
/**
|
||||
* @file lv_vdb.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_VDB_H
|
||||
#define LV_VDB_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if LV_VDB_SIZE != 0
|
||||
|
||||
#include "../lv_misc/lv_color.h"
|
||||
#include "../lv_misc/lv_area.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
/*Can be used in `lv_conf.h` the set an invalid address for the VDB. It should be replaced later by a valid address using `lv_vdb_set_adr()`*/
|
||||
#define LV_VDB_ADR_INV 8 /*8 is still too small to be valid but it's aligned on 64 bit machines as well*/
|
||||
|
||||
#ifndef LV_VDB_PX_BPP
|
||||
#define LV_VDB_PX_BPP LV_COLOR_SIZE /* Default is LV_COLOR_SIZE */
|
||||
#endif
|
||||
|
||||
|
||||
#if LV_VDB_TRUE_DOUBLE_BUFFERED && (LV_VDB_SIZE != LV_HOR_RES * LV_VER_RES || LV_VDB_DOUBLE == 0)
|
||||
#error "With LV_VDB_TRUE_DOUBLE_BUFFERED: (LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES and LV_VDB_DOUBLE = 1 is required"
|
||||
#endif
|
||||
|
||||
|
||||
/* The size of VDB in bytes.
|
||||
* (LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3): just divide by 8 to convert bits to bytes
|
||||
* (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0): add an extra byte to round up.
|
||||
* E.g. if LV_VDB_SIZE = 10 and LV_VDB_PX_BPP = 1 -> 10 bits -> 2 bytes*/
|
||||
#define LV_VDB_SIZE_IN_BYTES ((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0)
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
lv_area_t area;
|
||||
lv_color_t *buf;
|
||||
} lv_vdb_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode
|
||||
* @return pointer to a 'vdb' variable
|
||||
*/
|
||||
lv_vdb_t * lv_vdb_get(void);
|
||||
|
||||
/**
|
||||
* Flush the content of the vdb
|
||||
*/
|
||||
void lv_vdb_flush(void);
|
||||
|
||||
/**
|
||||
* Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`.
|
||||
* It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES`
|
||||
* @param buf1 address of the VDB.
|
||||
* @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0`
|
||||
*/
|
||||
void lv_vdb_set_adr(void * buf1, void * buf2);
|
||||
|
||||
/**
|
||||
* Call in the display driver's 'disp_flush' function when the flushing is finished
|
||||
*/
|
||||
void lv_flush_ready(void);
|
||||
|
||||
/**
|
||||
* Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1`
|
||||
* @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB
|
||||
*/
|
||||
lv_vdb_t * lv_vdb_get_active(void);
|
||||
|
||||
/**
|
||||
* Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1`
|
||||
* @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB
|
||||
*/
|
||||
lv_vdb_t * lv_vdb_get_inactive(void);
|
||||
|
||||
/**
|
||||
* Whether the flushing is in progress or not
|
||||
* @return true: flushing is in progress; false: flushing ready
|
||||
*/
|
||||
bool lv_vdb_is_flushing(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#else /*LV_VDB_SIZE != 0*/
|
||||
|
||||
/*Just for compatibility*/
|
||||
void lv_flush_ready(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_VDB_H*/
|
163
bdk/libs/lvgl/lv_draw/lv_draw.c
Normal file
163
bdk/libs/lvgl/lv_draw/lv_draw.c
Normal file
|
@ -0,0 +1,163 @@
|
|||
/**
|
||||
* @file lv_draw.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lv_draw.h"
|
||||
#include "lv_draw_rbasic.h"
|
||||
#include "lv_draw_vbasic.h"
|
||||
#include "../lv_misc/lv_fs.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
#include "../lv_misc/lv_ufs.h"
|
||||
#include "../lv_objx/lv_img.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
#if LV_VDB_SIZE != 0
|
||||
void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_vpx;
|
||||
void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_vfill;
|
||||
void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa) = lv_vletter;
|
||||
void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
|
||||
lv_color_t recolor, lv_opa_t recolor_opa) = lv_vmap;
|
||||
#else
|
||||
void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_rpx;
|
||||
void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_rfill;
|
||||
void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa) = lv_rletter;
|
||||
void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
|
||||
lv_color_t recolor, lv_opa_t recolor_opa) = lv_rmap;
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#if LV_ANTIALIAS != 0
|
||||
|
||||
/**
|
||||
* Get the opacity of a pixel based it's position in a line segment
|
||||
* @param seg segment length
|
||||
* @param px_id position of of a pixel which opacity should be get [0..seg-1]
|
||||
* @param base_opa the base opacity
|
||||
* @return the opacity of the given pixel
|
||||
*/
|
||||
lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa)
|
||||
{
|
||||
/* How to calculate the opacity of pixels on the edges which makes the anti-aliasing?
|
||||
* For example we have a line like this (y = -0.5 * x):
|
||||
*
|
||||
* | _ _
|
||||
* * * |
|
||||
*
|
||||
* Anti-aliased pixels come to the '*' characters
|
||||
* Calculate what percentage of the pixels should be covered if real line (not rasterized) would be drawn:
|
||||
* 1. A real line should start on (0;0) and end on (2;1)
|
||||
* 2. So the line intersection coordinates on the first pixel: (0;0) (1;0.5) -> 25% covered pixel in average
|
||||
* 3. For the second pixel: (1;0.5) (2;1) -> 75% covered pixel in average
|
||||
* 4. The equation: (px_id * 2 + 1) / (segment_width * 2)
|
||||
* segment_width: the line segment which is being anti-aliased (was 2 in the example)
|
||||
* px_id: pixel ID from 0 to (segment_width - 1)
|
||||
* result: [0..1] coverage of the pixel
|
||||
*/
|
||||
|
||||
/*Accelerate the common segment sizes to avoid division*/
|
||||
static const lv_opa_t seg1[1] = {128};
|
||||
static const lv_opa_t seg2[2] = {64, 192};
|
||||
static const lv_opa_t seg3[3] = {42, 128, 212};
|
||||
static const lv_opa_t seg4[4] = {32, 96, 159, 223};
|
||||
static const lv_opa_t seg5[5] = {26, 76, 128, 178, 230};
|
||||
static const lv_opa_t seg6[6] = {21, 64, 106, 148, 191, 234};
|
||||
static const lv_opa_t seg7[7] = {18, 55, 91, 128, 164, 200, 237};
|
||||
static const lv_opa_t seg8[8] = {16, 48, 80, 112, 143, 175, 207, 239};
|
||||
|
||||
static const lv_opa_t * seg_map[] = {seg1, seg2, seg3, seg4,
|
||||
seg5, seg6, seg7, seg8
|
||||
};
|
||||
|
||||
if(seg == 0) return LV_OPA_TRANSP;
|
||||
else if(seg < 8) return (uint32_t)((uint32_t)seg_map[seg - 1][px_id] * base_opa) >> 8;
|
||||
else {
|
||||
return ((px_id * 2 + 1) * base_opa) / (2 * seg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a vertical anti-aliasing segment (pixels with decreasing opacity)
|
||||
* @param x start point x coordinate
|
||||
* @param y start point y coordinate
|
||||
* @param length length of segment (negative value to start from 0 opacity)
|
||||
* @param mask draw only in this area
|
||||
* @param color color of pixels
|
||||
* @param opa maximum opacity
|
||||
*/
|
||||
void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
bool aa_inv = false;
|
||||
if(length < 0) {
|
||||
aa_inv = true;
|
||||
length = -length;
|
||||
}
|
||||
|
||||
lv_coord_t i;
|
||||
for(i = 0; i < length; i++) {
|
||||
lv_opa_t px_opa = lv_draw_aa_get_opa(length, i, opa);
|
||||
if(aa_inv) px_opa = opa - px_opa;
|
||||
px_fp(x, y + i, mask, color, px_opa);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a horizontal anti-aliasing segment (pixels with decreasing opacity)
|
||||
* @param x start point x coordinate
|
||||
* @param y start point y coordinate
|
||||
* @param length length of segment (negative value to start from 0 opacity)
|
||||
* @param mask draw only in this area
|
||||
* @param color color of pixels
|
||||
* @param opa maximum opacity
|
||||
*/
|
||||
void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
bool aa_inv = false;
|
||||
if(length < 0) {
|
||||
aa_inv = true;
|
||||
length = -length;
|
||||
}
|
||||
|
||||
lv_coord_t i;
|
||||
for(i = 0; i < length; i++) {
|
||||
lv_opa_t px_opa = lv_draw_aa_get_opa(length, i, opa);
|
||||
if(aa_inv) px_opa = opa - px_opa;
|
||||
px_fp(x + i, y, mask, color, px_opa);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
115
bdk/libs/lvgl/lv_draw/lv_draw.h
Normal file
115
bdk/libs/lvgl/lv_draw/lv_draw.h
Normal file
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* @file lv_draw.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_H
|
||||
#define LV_DRAW_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include "../lv_core/lv_style.h"
|
||||
#include "../lv_misc/lv_txt.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
/*If image pixels contains alpha we need to know how much byte is a pixel*/
|
||||
#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8
|
||||
# define LV_IMG_PX_SIZE_ALPHA_BYTE 2
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
# define LV_IMG_PX_SIZE_ALPHA_BYTE 3
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
# define LV_IMG_PX_SIZE_ALPHA_BYTE 4
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
enum {
|
||||
LV_IMG_SRC_VARIABLE,
|
||||
LV_IMG_SRC_FILE,
|
||||
LV_IMG_SRC_SYMBOL,
|
||||
LV_IMG_SRC_UNKNOWN,
|
||||
};
|
||||
typedef uint8_t lv_img_src_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
#if LV_ANTIALIAS != 0
|
||||
|
||||
/**
|
||||
* Get the opacity of a pixel based it's position in a line segment
|
||||
* @param seg segment length
|
||||
* @param px_id position of of a pixel which opacity should be get [0..seg-1]
|
||||
* @param base_opa the base opacity
|
||||
* @return the opacity of the given pixel
|
||||
*/
|
||||
lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa);
|
||||
|
||||
/**
|
||||
* Add a vertical anti-aliasing segment (pixels with decreasing opacity)
|
||||
* @param x start point x coordinate
|
||||
* @param y start point y coordinate
|
||||
* @param length length of segment (negative value to start from 0 opacity)
|
||||
* @param mask draw only in this area
|
||||
* @param color color of pixels
|
||||
* @param opa maximum opacity
|
||||
*/
|
||||
void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa);
|
||||
|
||||
/**
|
||||
* Add a horizontal anti-aliasing segment (pixels with decreasing opacity)
|
||||
* @param x start point x coordinate
|
||||
* @param y start point y coordinate
|
||||
* @param length length of segment (negative value to start from 0 opacity)
|
||||
* @param mask draw only in this area
|
||||
* @param color color of pixels
|
||||
* @param opa maximum opacity
|
||||
*/
|
||||
void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
extern void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa);
|
||||
extern void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa);
|
||||
extern void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa);
|
||||
extern void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
|
||||
lv_color_t recolor, lv_opa_t recolor_opa);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* POST INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_rect.h"
|
||||
#include "lv_draw_label.h"
|
||||
#include "lv_draw_img.h"
|
||||
#include "lv_draw_line.h"
|
||||
#include "lv_draw_triangle.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRAW_H*/
|
14
bdk/libs/lvgl/lv_draw/lv_draw.mk
Normal file
14
bdk/libs/lvgl/lv_draw/lv_draw.mk
Normal file
|
@ -0,0 +1,14 @@
|
|||
CSRCS += lv_draw_vbasic.c
|
||||
CSRCS += lv_draw_rbasic.c
|
||||
CSRCS += lv_draw.c
|
||||
CSRCS += lv_draw_rect.c
|
||||
CSRCS += lv_draw_label.c
|
||||
CSRCS += lv_draw_line.c
|
||||
CSRCS += lv_draw_img.c
|
||||
CSRCS += lv_draw_arc.c
|
||||
CSRCS += lv_draw_triangle.c
|
||||
|
||||
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_draw
|
||||
VPATH += :$(LVGL_DIR)/lvgl/lv_draw
|
||||
|
||||
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw"
|
264
bdk/libs/lvgl/lv_draw/lv_draw_arc.c
Normal file
264
bdk/libs/lvgl/lv_draw/lv_draw_arc.c
Normal file
|
@ -0,0 +1,264 @@
|
|||
/**
|
||||
* @file lv_draw_arc.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_arc.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static uint16_t fast_atan2(int x, int y);
|
||||
static void ver_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa);
|
||||
static void hor_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa);
|
||||
static bool deg_test_norm(uint16_t deg, uint16_t start, uint16_t end);
|
||||
static bool deg_test_inv(uint16_t deg, uint16_t start, uint16_t end);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Draw an arc. (Can draw pie too with great thickness.)
|
||||
* @param center_x the x coordinate of the center of the arc
|
||||
* @param center_y the y coordinate of the center of the arc
|
||||
* @param radius the radius of the arc
|
||||
* @param mask the arc will be drawn only in this mask
|
||||
* @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right)
|
||||
* @param end_angle the end angle of the arc
|
||||
* @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used)
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask,
|
||||
uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
lv_coord_t thickness = style->line.width;
|
||||
if(thickness > radius) thickness = radius;
|
||||
|
||||
lv_coord_t r_out = radius;
|
||||
lv_coord_t r_in = r_out - thickness;
|
||||
int16_t deg_base;
|
||||
int16_t deg;
|
||||
lv_coord_t x_start[4];
|
||||
lv_coord_t x_end[4];
|
||||
|
||||
lv_color_t color = style->line.color;
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->body.opa : (uint16_t)((uint16_t) style->body.opa * opa_scale) >> 8;
|
||||
|
||||
|
||||
bool (*deg_test)(uint16_t, uint16_t, uint16_t);
|
||||
if(start_angle <= end_angle) deg_test = deg_test_norm;
|
||||
else deg_test = deg_test_inv;
|
||||
|
||||
if(deg_test(270, start_angle, end_angle)) hor_line(center_x - r_out + 1, center_y, mask, thickness - 1, color, opa); // Left Middle
|
||||
if(deg_test(90, start_angle, end_angle)) hor_line(center_x + r_in, center_y, mask, thickness - 1, color, opa); // Right Middle
|
||||
if(deg_test(180, start_angle, end_angle)) ver_line(center_x, center_y - r_out + 1, mask, thickness - 1, color, opa); // Top Middle
|
||||
if(deg_test(0, start_angle, end_angle)) ver_line(center_x, center_y + r_in, mask, thickness - 1, color, opa); // Bottom middle
|
||||
|
||||
uint32_t r_out_sqr = r_out * r_out;
|
||||
uint32_t r_in_sqr = r_in * r_in;
|
||||
int16_t xi;
|
||||
int16_t yi;
|
||||
for(yi = -r_out; yi < 0; yi++) {
|
||||
x_start[0] = LV_COORD_MIN;
|
||||
x_start[1] = LV_COORD_MIN;
|
||||
x_start[2] = LV_COORD_MIN;
|
||||
x_start[3] = LV_COORD_MIN;
|
||||
x_end[0] = LV_COORD_MIN;
|
||||
x_end[1] = LV_COORD_MIN;
|
||||
x_end[2] = LV_COORD_MIN;
|
||||
x_end[3] = LV_COORD_MIN;
|
||||
for(xi = -r_out; xi < 0; xi++) {
|
||||
|
||||
uint32_t r_act_sqr = xi * xi + yi * yi;
|
||||
if(r_act_sqr > r_out_sqr) continue;
|
||||
|
||||
deg_base = fast_atan2(xi, yi) - 180;
|
||||
|
||||
deg = 180 + deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
if(x_start[0] == LV_COORD_MIN) x_start[0] = xi;
|
||||
} else if(x_start[0] != LV_COORD_MIN && x_end[0] == LV_COORD_MIN) {
|
||||
x_end[0] = xi - 1;
|
||||
}
|
||||
|
||||
deg = 360 - deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
if(x_start[1] == LV_COORD_MIN) x_start[1] = xi;
|
||||
} else if(x_start[1] != LV_COORD_MIN && x_end[1] == LV_COORD_MIN) {
|
||||
x_end[1] = xi - 1;
|
||||
}
|
||||
|
||||
deg = 180 - deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
if(x_start[2] == LV_COORD_MIN) x_start[2] = xi;
|
||||
} else if(x_start[2] != LV_COORD_MIN && x_end[2] == LV_COORD_MIN) {
|
||||
x_end[2] = xi - 1;
|
||||
}
|
||||
|
||||
deg = deg_base;
|
||||
if(deg_test(deg, start_angle, end_angle)) {
|
||||
if(x_start[3] == LV_COORD_MIN) x_start[3] = xi;
|
||||
} else if(x_start[3] != LV_COORD_MIN && x_end[3] == LV_COORD_MIN) {
|
||||
x_end[3] = xi - 1;
|
||||
}
|
||||
|
||||
if(r_act_sqr < r_in_sqr) break; /*No need to continue the iteration in x once we found the inner edge of the arc*/
|
||||
}
|
||||
|
||||
|
||||
if(x_start[0] != LV_COORD_MIN) {
|
||||
if(x_end[0] == LV_COORD_MIN) x_end[0] = xi - 1;
|
||||
hor_line(center_x + x_start[0], center_y + yi, mask, x_end[0] - x_start[0], color, opa);
|
||||
}
|
||||
|
||||
if(x_start[1] != LV_COORD_MIN) {
|
||||
if(x_end[1] == LV_COORD_MIN) x_end[1] = xi - 1;
|
||||
hor_line(center_x + x_start[1], center_y - yi, mask, x_end[1] - x_start[1], color, opa);
|
||||
}
|
||||
|
||||
if(x_start[2] != LV_COORD_MIN) {
|
||||
if(x_end[2] == LV_COORD_MIN) x_end[2] = xi - 1;
|
||||
hor_line(center_x - x_end[2], center_y + yi, mask, LV_MATH_ABS(x_end[2] - x_start[2]), color, opa);
|
||||
}
|
||||
|
||||
if(x_start[3] != LV_COORD_MIN) {
|
||||
if(x_end[3] == LV_COORD_MIN) x_end[3] = xi - 1;
|
||||
hor_line(center_x - x_end[3], center_y - yi, mask, LV_MATH_ABS(x_end[3] - x_start[3]), color, opa);
|
||||
}
|
||||
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
/*TODO*/
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t fast_atan2(int x, int y)
|
||||
{
|
||||
// Fast XY vector to integer degree algorithm - Jan 2011 www.RomanBlack.com
|
||||
// Converts any XY values including 0 to a degree value that should be
|
||||
// within +/- 1 degree of the accurate value without needing
|
||||
// large slow trig functions like ArcTan() or ArcCos().
|
||||
// NOTE! at least one of the X or Y values must be non-zero!
|
||||
// This is the full version, for all 4 quadrants and will generate
|
||||
// the angle in integer degrees from 0-360.
|
||||
// Any values of X and Y are usable including negative values provided
|
||||
// they are between -1456 and 1456 so the 16bit multiply does not overflow.
|
||||
|
||||
unsigned char negflag;
|
||||
unsigned char tempdegree;
|
||||
unsigned char comp;
|
||||
unsigned int degree; // this will hold the result
|
||||
//signed int x; // these hold the XY vector at the start
|
||||
//signed int y; // (and they will be destroyed)
|
||||
unsigned int ux;
|
||||
unsigned int uy;
|
||||
|
||||
// Save the sign flags then remove signs and get XY as unsigned ints
|
||||
negflag = 0;
|
||||
if(x < 0) {
|
||||
negflag += 0x01; // x flag bit
|
||||
x = (0 - x); // is now +
|
||||
}
|
||||
ux = x; // copy to unsigned var before multiply
|
||||
if(y < 0) {
|
||||
negflag += 0x02; // y flag bit
|
||||
y = (0 - y); // is now +
|
||||
}
|
||||
uy = y; // copy to unsigned var before multiply
|
||||
|
||||
// 1. Calc the scaled "degrees"
|
||||
if(ux > uy) {
|
||||
degree = (uy * 45) / ux; // degree result will be 0-45 range
|
||||
negflag += 0x10; // octant flag bit
|
||||
} else {
|
||||
degree = (ux * 45) / uy; // degree result will be 0-45 range
|
||||
}
|
||||
|
||||
// 2. Compensate for the 4 degree error curve
|
||||
comp = 0;
|
||||
tempdegree = degree; // use an unsigned char for speed!
|
||||
if(tempdegree > 22) { // if top half of range
|
||||
if(tempdegree <= 44) comp++;
|
||||
if(tempdegree <= 41) comp++;
|
||||
if(tempdegree <= 37) comp++;
|
||||
if(tempdegree <= 32) comp++; // max is 4 degrees compensated
|
||||
} else { // else is lower half of range
|
||||
if(tempdegree >= 2) comp++;
|
||||
if(tempdegree >= 6) comp++;
|
||||
if(tempdegree >= 10) comp++;
|
||||
if(tempdegree >= 15) comp++; // max is 4 degrees compensated
|
||||
}
|
||||
degree += comp; // degree is now accurate to +/- 1 degree!
|
||||
|
||||
// Invert degree if it was X>Y octant, makes 0-45 into 90-45
|
||||
if(negflag & 0x10) degree = (90 - degree);
|
||||
|
||||
// 3. Degree is now 0-90 range for this quadrant,
|
||||
// need to invert it for whichever quadrant it was in
|
||||
if(negflag & 0x02) { // if -Y
|
||||
if(negflag & 0x01) // if -Y -X
|
||||
degree = (180 + degree);
|
||||
else // else is -Y +X
|
||||
degree = (180 - degree);
|
||||
} else { // else is +Y
|
||||
if(negflag & 0x01) // if +Y -X
|
||||
degree = (360 - degree);
|
||||
}
|
||||
return degree;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
static void ver_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
lv_area_t area;
|
||||
lv_area_set(&area, x, y, x, y + len);
|
||||
|
||||
fill_fp(&area, mask, color, opa);
|
||||
}
|
||||
|
||||
static void hor_line(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_coord_t len, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
lv_area_t area;
|
||||
lv_area_set(&area, x, y, x + len, y);
|
||||
|
||||
fill_fp(&area, mask, color, opa);
|
||||
}
|
||||
|
||||
static bool deg_test_norm(uint16_t deg, uint16_t start, uint16_t end)
|
||||
{
|
||||
if(deg >= start && deg <= end) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
static bool deg_test_inv(uint16_t deg, uint16_t start, uint16_t end)
|
||||
{
|
||||
if(deg >= start || deg <= end) {
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
53
bdk/libs/lvgl/lv_draw/lv_draw_arc.h
Normal file
53
bdk/libs/lvgl/lv_draw/lv_draw_arc.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* @file lv_draw_arc.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_ARC_H
|
||||
#define LV_DRAW_ARC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Draw an arc. (Can draw pie too with great thickness.)
|
||||
* @param center_x the x coordinate of the center of the arc
|
||||
* @param center_y the y coordinate of the center of the arc
|
||||
* @param radius the radius of the arc
|
||||
* @param mask the arc will be drawn only in this mask
|
||||
* @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right)
|
||||
* @param end_angle the end angle of the arc
|
||||
* @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used)
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask,
|
||||
uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRAW_ARC*/
|
759
bdk/libs/lvgl/lv_draw/lv_draw_img.c
Normal file
759
bdk/libs/lvgl/lv_draw/lv_draw_img.c
Normal file
|
@ -0,0 +1,759 @@
|
|||
/**
|
||||
* @file lv_draw_img.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_img.h"
|
||||
#include "../lv_misc/lv_fs.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask,
|
||||
const void * src, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
|
||||
static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * style);
|
||||
static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
|
||||
static void lv_img_decoder_close(void);
|
||||
static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
|
||||
static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static bool decoder_custom;
|
||||
static const void * decoder_src;
|
||||
static lv_img_src_t decoder_src_type;
|
||||
static lv_img_header_t decoder_header;
|
||||
static const lv_style_t * decoder_style;
|
||||
#if USE_LV_FILESYSTEM
|
||||
static lv_fs_file_t decoder_file;
|
||||
#endif
|
||||
#if LV_IMG_CF_INDEXED
|
||||
static lv_color_t decoder_index_map[256];
|
||||
#endif
|
||||
|
||||
static lv_img_decoder_info_f_t lv_img_decoder_info_custom;
|
||||
static lv_img_decoder_open_f_t lv_img_decoder_open_custom;
|
||||
static lv_img_decoder_read_line_f_t lv_img_decoder_read_line_custom;
|
||||
static lv_img_decoder_close_f_t lv_img_decoder_close_custom;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Draw an image
|
||||
* @param coords the coordinates of the image
|
||||
* @param mask the image will be drawn only in this area
|
||||
* @param src pointer to a lv_color_t array which contains the pixels of the image
|
||||
* @param style style of the image
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,
|
||||
const void * src, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
if(src == NULL) {
|
||||
LV_LOG_WARN("Image draw: src is NULL");
|
||||
lv_draw_rect(coords, mask, &lv_style_plain, LV_OPA_COVER);
|
||||
lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
lv_res_t res;
|
||||
res = lv_img_draw_core(coords, mask, src, style, opa_scale);
|
||||
|
||||
if(res == LV_RES_INV) {
|
||||
LV_LOG_WARN("Image draw error");
|
||||
lv_draw_rect(coords, mask, &lv_style_plain, LV_OPA_COVER);
|
||||
lv_draw_label(coords, mask, &lv_style_plain, LV_OPA_COVER, "No\ndata", LV_TXT_FLAG_NONE, NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param src
|
||||
* @param header
|
||||
* @param style
|
||||
* @return
|
||||
*/
|
||||
lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header)
|
||||
{
|
||||
header->always_zero = 0;
|
||||
/*Try to get info with the custom functions first*/
|
||||
if(lv_img_decoder_info_custom) {
|
||||
lv_res_t custom_res;
|
||||
custom_res = lv_img_decoder_info_custom(src, header);
|
||||
if(custom_res == LV_RES_OK) return LV_RES_OK; /*Custom info has supported this source*/
|
||||
}
|
||||
|
||||
lv_img_src_t src_type = lv_img_src_get_type(src);
|
||||
if(src_type == LV_IMG_SRC_VARIABLE) {
|
||||
header->w = ((lv_img_dsc_t *)src)->header.w;
|
||||
header->h = ((lv_img_dsc_t *)src)->header.h;
|
||||
header->cf = ((lv_img_dsc_t *)src)->header.cf;
|
||||
}
|
||||
#if USE_LV_FILESYSTEM
|
||||
else if(src_type == LV_IMG_SRC_FILE) {
|
||||
lv_fs_file_t file;
|
||||
lv_fs_res_t res;
|
||||
uint32_t rn;
|
||||
res = lv_fs_open(&file, src, LV_FS_MODE_RD);
|
||||
if(res == LV_FS_RES_OK) {
|
||||
res = lv_fs_read(&file, header, sizeof(lv_img_header_t), &rn);
|
||||
}
|
||||
|
||||
/*Create a dummy header on fs error*/
|
||||
if(res != LV_FS_RES_OK || rn != sizeof(lv_img_header_t)) {
|
||||
header->w = LV_DPI;
|
||||
header->h = LV_DPI;
|
||||
header->cf = LV_IMG_CF_UNKOWN;
|
||||
}
|
||||
|
||||
lv_fs_close(&file);
|
||||
}
|
||||
#endif
|
||||
else if(src_type == LV_IMG_SRC_SYMBOL) {
|
||||
/*The size depend on the font but it is unknown here. It should be handled outside of the function*/
|
||||
header->w = 1;
|
||||
header->h = 1;
|
||||
/* Symbols always have transparent parts. Important because of cover check in the design function.
|
||||
* The actual value doesn't matter because lv_draw_label will draw it*/
|
||||
header->cf = LV_IMG_CF_ALPHA_1BIT;
|
||||
} else {
|
||||
LV_LOG_WARN("Image get info found unknown src type");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf)
|
||||
{
|
||||
uint8_t px_size = 0;
|
||||
|
||||
switch(cf) {
|
||||
case LV_IMG_CF_UNKOWN:
|
||||
case LV_IMG_CF_RAW:
|
||||
px_size = 0;
|
||||
break;
|
||||
case LV_IMG_CF_TRUE_COLOR:
|
||||
case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED:
|
||||
px_size = LV_COLOR_SIZE;
|
||||
break;
|
||||
case LV_IMG_CF_TRUE_COLOR_ALPHA:
|
||||
px_size = LV_IMG_PX_SIZE_ALPHA_BYTE << 3;
|
||||
break;
|
||||
case LV_IMG_CF_INDEXED_1BIT:
|
||||
case LV_IMG_CF_ALPHA_1BIT:
|
||||
px_size = 1;
|
||||
break;
|
||||
case LV_IMG_CF_INDEXED_2BIT:
|
||||
case LV_IMG_CF_ALPHA_2BIT:
|
||||
px_size = 2;
|
||||
break;
|
||||
case LV_IMG_CF_INDEXED_4BIT:
|
||||
case LV_IMG_CF_ALPHA_4BIT:
|
||||
px_size = 4;
|
||||
break;
|
||||
case LV_IMG_CF_INDEXED_8BIT:
|
||||
case LV_IMG_CF_ALPHA_8BIT:
|
||||
px_size = 8;
|
||||
break;
|
||||
default:
|
||||
px_size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return px_size;
|
||||
}
|
||||
|
||||
bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf)
|
||||
{
|
||||
bool is_chroma_keyed = false;
|
||||
|
||||
switch(cf) {
|
||||
case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED:
|
||||
case LV_IMG_CF_RAW_CHROMA_KEYED:
|
||||
case LV_IMG_CF_INDEXED_1BIT:
|
||||
case LV_IMG_CF_INDEXED_2BIT:
|
||||
case LV_IMG_CF_INDEXED_4BIT:
|
||||
case LV_IMG_CF_INDEXED_8BIT:
|
||||
is_chroma_keyed = true;
|
||||
break;
|
||||
default:
|
||||
is_chroma_keyed = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return is_chroma_keyed;
|
||||
}
|
||||
|
||||
|
||||
bool lv_img_color_format_has_alpha(lv_img_cf_t cf)
|
||||
{
|
||||
bool has_alpha = false;
|
||||
|
||||
switch(cf) {
|
||||
case LV_IMG_CF_TRUE_COLOR_ALPHA:
|
||||
case LV_IMG_CF_RAW_ALPHA:
|
||||
case LV_IMG_CF_ALPHA_1BIT:
|
||||
case LV_IMG_CF_ALPHA_2BIT:
|
||||
case LV_IMG_CF_ALPHA_4BIT:
|
||||
case LV_IMG_CF_ALPHA_8BIT:
|
||||
has_alpha = true;
|
||||
break;
|
||||
default:
|
||||
has_alpha = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return has_alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of an image source
|
||||
* @param src pointer to an image source:
|
||||
* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)
|
||||
* - a path to a file (e.g. "S:/folder/image.bin")
|
||||
* - or a symbol (e.g. SYMBOL_CLOSE)
|
||||
* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN
|
||||
*/
|
||||
lv_img_src_t lv_img_src_get_type(const void * src)
|
||||
{
|
||||
lv_img_src_t img_src_type = LV_IMG_SRC_UNKNOWN;
|
||||
|
||||
if(src == NULL) return img_src_type;
|
||||
const uint8_t * u8_p = src;
|
||||
|
||||
/*The first byte shows the type of the image source*/
|
||||
if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F) {
|
||||
img_src_type = LV_IMG_SRC_FILE; /*If it's an ASCII character then it's file name*/
|
||||
} else if(u8_p[0] >= 0x80) {
|
||||
img_src_type = LV_IMG_SRC_SYMBOL; /*Symbols begins after 0x7F*/
|
||||
} else {
|
||||
img_src_type = LV_IMG_SRC_VARIABLE; /*`lv_img_dsc_t` is design to the first byte < 0x20*/
|
||||
}
|
||||
|
||||
if (LV_IMG_SRC_UNKNOWN == img_src_type) {
|
||||
LV_LOG_WARN("lv_img_src_get_type: unknown image type");
|
||||
}
|
||||
|
||||
return img_src_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom decoder functions. See the typdefs of the function typed above for more info about them
|
||||
* @param info_fp info get function
|
||||
* @param open_fp open function
|
||||
* @param read_fp read line function
|
||||
* @param close_fp clode function
|
||||
*/
|
||||
void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp,
|
||||
lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp)
|
||||
{
|
||||
lv_img_decoder_info_custom = info_fp;
|
||||
lv_img_decoder_open_custom = open_fp;
|
||||
lv_img_decoder_read_line_custom = read_fp;
|
||||
lv_img_decoder_close_custom = close_fp;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask,
|
||||
const void * src, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
|
||||
lv_area_t mask_com; /*Common area of mask and coords*/
|
||||
bool union_ok;
|
||||
union_ok = lv_area_intersect(&mask_com, mask, coords);
|
||||
if(union_ok == false) {
|
||||
return LV_RES_OK; /*Out of mask. There is nothing to draw so the image is drawn successfully.*/
|
||||
}
|
||||
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->image.opa : (uint16_t)((uint16_t) style->image.opa * opa_scale) >> 8;
|
||||
|
||||
lv_img_header_t header;
|
||||
lv_res_t header_res;
|
||||
header_res = lv_img_dsc_get_info(src, &header);
|
||||
if(header_res != LV_RES_OK) {
|
||||
LV_LOG_WARN("Image draw can't get image info");
|
||||
lv_img_decoder_close();
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
bool chroma_keyed = lv_img_color_format_is_chroma_keyed(header.cf);
|
||||
bool alpha_byte = lv_img_color_format_has_alpha(header.cf);
|
||||
|
||||
const uint8_t * img_data = lv_img_decoder_open(src, style);
|
||||
if(img_data == LV_IMG_DECODER_OPEN_FAIL) {
|
||||
LV_LOG_WARN("Image draw cannot open the image resource");
|
||||
lv_img_decoder_close();
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
/* The decoder open could open the image and gave the entire uncompressed image.
|
||||
* Just draw it!*/
|
||||
if(img_data) {
|
||||
map_fp(coords, mask, img_data, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense);
|
||||
}
|
||||
/* The whole uncompressed image is not available. Try to read it line-by-line*/
|
||||
else {
|
||||
lv_coord_t width = lv_area_get_width(&mask_com);
|
||||
|
||||
#if LV_COMPILER_VLA_SUPPORTED
|
||||
uint8_t buf[(lv_area_get_width(&mask_com) * ((LV_COLOR_DEPTH >> 3) + 1))];
|
||||
#else
|
||||
uint8_t buf[LV_HOR_RES * ((LV_COLOR_DEPTH >> 3) + 1)]; /*+1 because of the possible alpha byte*/
|
||||
#endif
|
||||
lv_area_t line;
|
||||
lv_area_copy(&line, &mask_com);
|
||||
lv_area_set_height(&line, 1);
|
||||
lv_coord_t x = mask_com.x1 - coords->x1;
|
||||
lv_coord_t y = mask_com.y1 - coords->y1;
|
||||
lv_coord_t row;
|
||||
lv_res_t read_res;
|
||||
for(row = mask_com.y1; row <= mask_com.y2; row++) {
|
||||
read_res = lv_img_decoder_read_line(x, y, width, buf);
|
||||
if(read_res != LV_RES_OK) {
|
||||
lv_img_decoder_close();
|
||||
LV_LOG_WARN("Image draw can't read the line");
|
||||
return LV_RES_INV;
|
||||
}
|
||||
map_fp(&line, mask, buf, opa, chroma_keyed, alpha_byte, style->image.color, style->image.intense);
|
||||
line.y1++;
|
||||
line.y2++;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
lv_img_decoder_close();
|
||||
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * style)
|
||||
{
|
||||
decoder_custom = false;
|
||||
|
||||
/*Try to open with the custom functions first*/
|
||||
if(lv_img_decoder_open_custom) {
|
||||
const uint8_t * custom_res;
|
||||
custom_res = lv_img_decoder_open_custom(src, style);
|
||||
if(custom_res != LV_IMG_DECODER_OPEN_FAIL) {
|
||||
decoder_custom = true; /*Mark that custom decoder function should be used for this img source.*/
|
||||
return custom_res; /*Custom open supported this source*/
|
||||
}
|
||||
}
|
||||
|
||||
decoder_src = src;
|
||||
decoder_style = style;
|
||||
decoder_src_type = lv_img_src_get_type(src);
|
||||
|
||||
lv_res_t header_res;
|
||||
header_res = lv_img_dsc_get_info(src, &decoder_header);
|
||||
if(header_res == LV_RES_INV) {
|
||||
decoder_src = NULL;
|
||||
decoder_src_type = LV_IMG_SRC_UNKNOWN;
|
||||
LV_LOG_WARN("Built-in image decoder can't get the header info");
|
||||
return LV_IMG_DECODER_OPEN_FAIL;
|
||||
}
|
||||
|
||||
/*Open the file if it's a file*/
|
||||
if(decoder_src_type == LV_IMG_SRC_FILE) {
|
||||
#if USE_LV_FILESYSTEM
|
||||
lv_fs_res_t res = lv_fs_open(&decoder_file, src, LV_FS_MODE_RD);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
LV_LOG_WARN("Built-in image decoder can't open the file");
|
||||
return LV_IMG_DECODER_OPEN_FAIL;
|
||||
}
|
||||
#else
|
||||
LV_LOG_WARN("Image built-in decoder can read file because USE_LV_FILESYSTEM = 0");
|
||||
return LV_IMG_DECODER_OPEN_FAIL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*Process the different color formats*/
|
||||
lv_img_cf_t cf = decoder_header.cf;
|
||||
if(cf == LV_IMG_CF_TRUE_COLOR ||
|
||||
cf == LV_IMG_CF_TRUE_COLOR_ALPHA ||
|
||||
cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
|
||||
if(decoder_src_type == LV_IMG_SRC_VARIABLE) {
|
||||
/*In case of uncompressed formats if the image stored in the ROM/RAM simply give it's pointer*/
|
||||
return ((lv_img_dsc_t *)decoder_src)->data;
|
||||
} else {
|
||||
/*If it's file it need to be read line by line later*/
|
||||
return NULL;
|
||||
}
|
||||
} else if(cf == LV_IMG_CF_INDEXED_1BIT ||
|
||||
cf == LV_IMG_CF_INDEXED_2BIT ||
|
||||
cf == LV_IMG_CF_INDEXED_4BIT ||
|
||||
cf == LV_IMG_CF_INDEXED_8BIT) {
|
||||
|
||||
#if LV_IMG_CF_INDEXED
|
||||
#if USE_LV_FILESYSTEM
|
||||
lv_color32_t palette_file[256];
|
||||
#endif
|
||||
|
||||
lv_color32_t * palette_p = NULL;
|
||||
uint8_t px_size = lv_img_color_format_get_px_size(cf);
|
||||
uint32_t palette_size = 1 << px_size;
|
||||
|
||||
if(decoder_src_type == LV_IMG_SRC_FILE) {
|
||||
/*Read the palette from file*/
|
||||
#if USE_LV_FILESYSTEM
|
||||
lv_fs_seek(&decoder_file, 4); /*Skip the header*/
|
||||
lv_fs_read(&decoder_file, palette_file, palette_size * sizeof(lv_color32_t), NULL);
|
||||
palette_p = palette_file;
|
||||
#else
|
||||
LV_LOG_WARN("Image built-in decoder can read the palette because USE_LV_FILESYSTEM = 0");
|
||||
return LV_IMG_DECODER_OPEN_FAIL;
|
||||
#endif
|
||||
} else {
|
||||
/*The palette begins in the beginning of the image data. Just point to it.*/
|
||||
palette_p = (lv_color32_t *)((lv_img_dsc_t *)decoder_src)->data;
|
||||
}
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < palette_size; i++) {
|
||||
decoder_index_map[i] = LV_COLOR_MAKE(palette_p[i].red, palette_p[i].green, palette_p[i].blue);
|
||||
}
|
||||
return NULL;
|
||||
#else
|
||||
LV_LOG_WARN("Indexed (palette) images are not enabled in lv_conf.h. See LV_IMG_CF_INDEXED");
|
||||
return LV_IMG_DECODER_OPEN_FAIL;
|
||||
#endif
|
||||
} else if(cf == LV_IMG_CF_ALPHA_1BIT ||
|
||||
cf == LV_IMG_CF_ALPHA_2BIT ||
|
||||
cf == LV_IMG_CF_ALPHA_4BIT ||
|
||||
cf == LV_IMG_CF_ALPHA_8BIT) {
|
||||
#if LV_IMG_CF_ALPHA
|
||||
return NULL; /*Nothing to process*/
|
||||
#else
|
||||
LV_LOG_WARN("Alpha indexed images are not enabled in lv_conf.h. See LV_IMG_CF_ALPHA");
|
||||
return LV_IMG_DECODER_OPEN_FAIL;
|
||||
#endif
|
||||
} else {
|
||||
LV_LOG_WARN("Image decoder open: unknown color format")
|
||||
return LV_IMG_DECODER_OPEN_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
|
||||
{
|
||||
/*Try to read the line with the custom functions*/
|
||||
if(decoder_custom) {
|
||||
if(lv_img_decoder_read_line_custom) {
|
||||
lv_res_t custom_res;
|
||||
custom_res = lv_img_decoder_read_line_custom(x, y, len, buf);
|
||||
return custom_res;
|
||||
} else {
|
||||
LV_LOG_WARN("Image open with custom decoder but read not supported")
|
||||
}
|
||||
return LV_RES_INV; /*It"s an error if not returned earlier*/
|
||||
}
|
||||
|
||||
if(decoder_src_type == LV_IMG_SRC_FILE) {
|
||||
#if USE_LV_FILESYSTEM
|
||||
uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf);
|
||||
|
||||
lv_fs_res_t res;
|
||||
|
||||
if(decoder_header.cf == LV_IMG_CF_TRUE_COLOR ||
|
||||
decoder_header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA ||
|
||||
decoder_header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
|
||||
uint32_t pos = ((y * decoder_header.w + x) * px_size) >> 3;
|
||||
pos += 4; /*Skip the header*/
|
||||
res = lv_fs_seek(&decoder_file, pos);
|
||||
if(res != LV_FS_RES_OK) {
|
||||
LV_LOG_WARN("Built-in image decoder seek failed");
|
||||
return false;
|
||||
}
|
||||
uint32_t btr = len * (px_size >> 3);
|
||||
uint32_t br = 0;
|
||||
lv_fs_read(&decoder_file, buf, btr, &br);
|
||||
if(res != LV_FS_RES_OK || btr != br) {
|
||||
LV_LOG_WARN("Built-in image decoder read failed");
|
||||
return false;
|
||||
}
|
||||
} else if(decoder_header.cf == LV_IMG_CF_ALPHA_1BIT ||
|
||||
decoder_header.cf == LV_IMG_CF_ALPHA_2BIT ||
|
||||
decoder_header.cf == LV_IMG_CF_ALPHA_4BIT ||
|
||||
decoder_header.cf == LV_IMG_CF_ALPHA_8BIT) {
|
||||
|
||||
lv_img_built_in_decoder_line_alpha(x, y, len, buf);
|
||||
} else if(decoder_header.cf == LV_IMG_CF_INDEXED_1BIT ||
|
||||
decoder_header.cf == LV_IMG_CF_INDEXED_2BIT ||
|
||||
decoder_header.cf == LV_IMG_CF_INDEXED_4BIT ||
|
||||
decoder_header.cf == LV_IMG_CF_INDEXED_8BIT) {
|
||||
lv_img_built_in_decoder_line_indexed(x, y, len, buf);
|
||||
} else {
|
||||
LV_LOG_WARN("Built-in image decoder read not supports the color format");
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
LV_LOG_WARN("Image built-in decoder can't read file because USE_LV_FILESYSTEM = 0");
|
||||
return false;
|
||||
#endif
|
||||
} else if(decoder_src_type == LV_IMG_SRC_VARIABLE) {
|
||||
const lv_img_dsc_t * img_dsc = decoder_src;
|
||||
|
||||
if(img_dsc->header.cf == LV_IMG_CF_ALPHA_1BIT ||
|
||||
img_dsc->header.cf == LV_IMG_CF_ALPHA_2BIT ||
|
||||
img_dsc->header.cf == LV_IMG_CF_ALPHA_4BIT ||
|
||||
img_dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
|
||||
lv_img_built_in_decoder_line_alpha(x, y, len, buf);
|
||||
} else if(img_dsc->header.cf == LV_IMG_CF_INDEXED_1BIT ||
|
||||
img_dsc->header.cf == LV_IMG_CF_INDEXED_2BIT ||
|
||||
img_dsc->header.cf == LV_IMG_CF_INDEXED_4BIT ||
|
||||
img_dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
|
||||
lv_img_built_in_decoder_line_indexed(x, y, len, buf);
|
||||
} else {
|
||||
LV_LOG_WARN("Built-in image decoder not supports the color format");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void lv_img_decoder_close(void)
|
||||
{
|
||||
/*Try to close with the custom functions*/
|
||||
if(decoder_custom) {
|
||||
if(lv_img_decoder_close_custom) lv_img_decoder_close_custom();
|
||||
return;
|
||||
}
|
||||
|
||||
/*It was opened with built-in decoder*/
|
||||
if(decoder_src) {
|
||||
#if USE_LV_FILESYSTEM
|
||||
if(decoder_src_type == LV_IMG_SRC_FILE) {
|
||||
lv_fs_close(&decoder_file);
|
||||
}
|
||||
#endif
|
||||
decoder_src_type = LV_IMG_SRC_UNKNOWN;
|
||||
decoder_src = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
|
||||
{
|
||||
|
||||
#if LV_IMG_CF_ALPHA
|
||||
const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
|
||||
const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
|
||||
const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
|
||||
68, 85, 102, 119,
|
||||
136, 153, 170, 187,
|
||||
204, 221, 238, 255
|
||||
};
|
||||
|
||||
/*Simply fill the buffer with the color. Later only the alpha value will be modified.*/
|
||||
lv_color_t bg_color = decoder_style->image.color;
|
||||
lv_coord_t i;
|
||||
for(i = 0; i < len; i++) {
|
||||
#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
|
||||
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full;
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
/*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
|
||||
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full & 0xFF;
|
||||
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + 1] = (bg_color.full >> 8) & 0xFF;
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
*((uint32_t *)&buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE]) = bg_color.full;
|
||||
#else
|
||||
#error "Invalid LV_COLOR_DEPTH. Check it in lv_conf.h"
|
||||
#endif
|
||||
}
|
||||
|
||||
const lv_opa_t * opa_table = NULL;
|
||||
uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf);
|
||||
uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/
|
||||
|
||||
lv_coord_t w = 0;
|
||||
uint32_t ofs = 0;
|
||||
int8_t pos = 0;
|
||||
switch(decoder_header.cf) {
|
||||
case LV_IMG_CF_ALPHA_1BIT:
|
||||
w = (decoder_header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/
|
||||
if(decoder_header.w & 0x7) w++;
|
||||
ofs += w * y + (x >> 3); /*First pixel*/
|
||||
pos = 7 - (x & 0x7);
|
||||
opa_table = alpha1_opa_table;
|
||||
break;
|
||||
case LV_IMG_CF_ALPHA_2BIT:
|
||||
w = (decoder_header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/
|
||||
if(decoder_header.w & 0x3) w++;
|
||||
ofs += w * y + (x >> 2); /*First pixel*/
|
||||
pos = 6 - ((x & 0x3) * 2);
|
||||
opa_table = alpha2_opa_table;
|
||||
break;
|
||||
case LV_IMG_CF_ALPHA_4BIT:
|
||||
w = (decoder_header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/
|
||||
if(decoder_header.w & 0x1) w++;
|
||||
ofs += w * y + (x >> 1); /*First pixel*/
|
||||
pos = 4 - ((x & 0x1) * 4);
|
||||
opa_table = alpha4_opa_table;
|
||||
break;
|
||||
case LV_IMG_CF_ALPHA_8BIT:
|
||||
w = decoder_header.w; /*E.g. x = 7 -> w = 7 (bytes)*/
|
||||
ofs += w * y + x; /*First pixel*/
|
||||
pos = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
#if USE_LV_FILESYSTEM
|
||||
# if LV_COMPILER_VLA_SUPPORTED
|
||||
uint8_t fs_buf[w];
|
||||
# else
|
||||
uint8_t fs_buf[LV_HOR_RES];
|
||||
# endif
|
||||
#endif
|
||||
const uint8_t * data_tmp = NULL;
|
||||
if(decoder_src_type == LV_IMG_SRC_VARIABLE) {
|
||||
const lv_img_dsc_t * img_dsc = decoder_src;
|
||||
data_tmp = img_dsc->data + ofs;
|
||||
} else {
|
||||
#if USE_LV_FILESYSTEM
|
||||
lv_fs_seek(&decoder_file, ofs + 4); /*+4 to skip the header*/
|
||||
lv_fs_read(&decoder_file, fs_buf, w, NULL);
|
||||
data_tmp = fs_buf;
|
||||
#else
|
||||
LV_LOG_WARN("Image built-in alpha line reader can't read file because USE_LV_FILESYSTEM = 0");
|
||||
data_tmp = NULL; /*To avoid warnings*/
|
||||
return LV_RES_INV;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
uint8_t byte_act = 0;
|
||||
uint8_t val_act;
|
||||
for(i = 0; i < len; i ++) {
|
||||
val_act = (data_tmp[byte_act] & (mask << pos)) >> pos;
|
||||
|
||||
buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + LV_IMG_PX_SIZE_ALPHA_BYTE - 1] =
|
||||
decoder_header.cf == LV_IMG_CF_ALPHA_8BIT ? val_act : opa_table[val_act];
|
||||
|
||||
pos -= px_size;
|
||||
if(pos < 0) {
|
||||
pos = 8 - px_size;
|
||||
data_tmp++;
|
||||
}
|
||||
}
|
||||
|
||||
return LV_RES_OK;
|
||||
|
||||
#else
|
||||
LV_LOG_WARN("Image built-in alpha line reader failed because LV_IMG_CF_ALPHA is 0 in lv_conf.h");
|
||||
return LV_RES_INV;
|
||||
#endif
|
||||
}
|
||||
|
||||
static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
|
||||
{
|
||||
|
||||
#if LV_IMG_CF_INDEXED
|
||||
uint8_t px_size = lv_img_color_format_get_px_size(decoder_header.cf);
|
||||
uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/
|
||||
|
||||
lv_coord_t w = 0;
|
||||
int8_t pos = 0;
|
||||
uint32_t ofs = 0;
|
||||
switch(decoder_header.cf) {
|
||||
case LV_IMG_CF_INDEXED_1BIT:
|
||||
w = (decoder_header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/
|
||||
if(decoder_header.w & 0x7) w++;
|
||||
ofs += w * y + (x >> 3); /*First pixel*/
|
||||
ofs += 8; /*Skip the palette*/
|
||||
pos = 7 - (x & 0x7);
|
||||
break;
|
||||
case LV_IMG_CF_INDEXED_2BIT:
|
||||
w = (decoder_header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/
|
||||
if(decoder_header.w & 0x3) w++;
|
||||
ofs += w * y + (x >> 2); /*First pixel*/
|
||||
ofs += 16; /*Skip the palette*/
|
||||
pos = 6 - ((x & 0x3) * 2);
|
||||
break;
|
||||
case LV_IMG_CF_INDEXED_4BIT:
|
||||
w = (decoder_header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/
|
||||
if(decoder_header.w & 0x1) w++;
|
||||
ofs += w * y + (x >> 1); /*First pixel*/
|
||||
ofs += 64; /*Skip the palette*/
|
||||
pos = 4 - ((x & 0x1) * 4);
|
||||
break;
|
||||
case LV_IMG_CF_INDEXED_8BIT:
|
||||
w = decoder_header.w; /*E.g. x = 7 -> w = 7 (bytes)*/
|
||||
ofs += w * y + x; /*First pixel*/
|
||||
ofs += 1024; /*Skip the palette*/
|
||||
pos = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
#if USE_LV_FILESYSTEM
|
||||
# if LV_COMPILER_VLA_SUPPORTED
|
||||
uint8_t fs_buf[w];
|
||||
# else
|
||||
uint8_t fs_buf[LV_HOR_RES];
|
||||
# endif
|
||||
#endif
|
||||
const uint8_t * data_tmp = NULL;
|
||||
if(decoder_src_type == LV_IMG_SRC_VARIABLE) {
|
||||
const lv_img_dsc_t * img_dsc = decoder_src;
|
||||
data_tmp = img_dsc->data + ofs;
|
||||
} else {
|
||||
#if USE_LV_FILESYSTEM
|
||||
lv_fs_seek(&decoder_file, ofs + 4); /*+4 to skip the header*/
|
||||
lv_fs_read(&decoder_file, fs_buf, w, NULL);
|
||||
data_tmp = fs_buf;
|
||||
#else
|
||||
LV_LOG_WARN("Image built-in indexed line reader can't read file because USE_LV_FILESYSTEM = 0");
|
||||
data_tmp = NULL; /*To avoid warnings*/
|
||||
return LV_RES_INV;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t byte_act = 0;
|
||||
uint8_t val_act;
|
||||
lv_coord_t i;
|
||||
lv_color_t * cbuf = (lv_color_t *) buf;
|
||||
for(i = 0; i < len; i ++) {
|
||||
val_act = (data_tmp[byte_act] & (mask << pos)) >> pos;
|
||||
cbuf[i] = decoder_index_map[val_act];
|
||||
|
||||
pos -= px_size;
|
||||
if(pos < 0) {
|
||||
pos = 8 - px_size;
|
||||
data_tmp++;
|
||||
}
|
||||
}
|
||||
|
||||
return LV_RES_OK;
|
||||
#else
|
||||
LV_LOG_WARN("Image built-in indexed line reader failed because LV_IMG_CF_INDEXED is 0 in lv_conf.h");
|
||||
return LV_RES_INV;
|
||||
#endif
|
||||
}
|
167
bdk/libs/lvgl/lv_draw/lv_draw_img.h
Normal file
167
bdk/libs/lvgl/lv_draw/lv_draw_img.h
Normal file
|
@ -0,0 +1,167 @@
|
|||
/**
|
||||
* @file lv_draw_img.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_IMG_H
|
||||
#define LV_DRAW_IMG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw.h"
|
||||
#include "../lv_core/lv_obj.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_IMG_DECODER_OPEN_FAIL ((void*)(-1))
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
struct _lv_img_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The first 8 bit is very important to distinguish the different source types.
|
||||
* For more info see `lv_img_get_src_type()` in lv_img.c */
|
||||
uint32_t cf :5; /* Color format: See `lv_img_color_format_t`*/
|
||||
uint32_t always_zero :3; /*It the upper bits of the first byte. Always zero to look like a non-printable character*/
|
||||
|
||||
uint32_t reserved :2; /*Reserved to be used later*/
|
||||
|
||||
uint32_t w:11; /*Width of the image map*/
|
||||
uint32_t h:11; /*Height of the image map*/
|
||||
} lv_img_header_t;
|
||||
|
||||
/*Image color format*/
|
||||
enum {
|
||||
LV_IMG_CF_UNKOWN = 0,
|
||||
|
||||
LV_IMG_CF_RAW, /*Contains the file as it is. Needs custom decoder function*/
|
||||
LV_IMG_CF_RAW_ALPHA, /*Contains the file as it is. The image has alpha. Needs custom decoder function*/
|
||||
LV_IMG_CF_RAW_CHROMA_KEYED, /*Contains the file as it is. The image is chroma keyed. Needs custom decoder function*/
|
||||
|
||||
LV_IMG_CF_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/
|
||||
LV_IMG_CF_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/
|
||||
LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/
|
||||
|
||||
LV_IMG_CF_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/
|
||||
LV_IMG_CF_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/
|
||||
LV_IMG_CF_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/
|
||||
LV_IMG_CF_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/
|
||||
|
||||
LV_IMG_CF_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/
|
||||
LV_IMG_CF_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/
|
||||
LV_IMG_CF_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/
|
||||
LV_IMG_CF_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/
|
||||
};
|
||||
typedef uint8_t lv_img_cf_t;
|
||||
|
||||
/* Image header it is compatible with
|
||||
* the result image converter utility*/
|
||||
typedef struct
|
||||
{
|
||||
lv_img_header_t header;
|
||||
uint32_t data_size;
|
||||
const uint8_t * data;
|
||||
} lv_img_dsc_t;
|
||||
|
||||
/* Decoder function definitions */
|
||||
|
||||
|
||||
/**
|
||||
* Get info from an image and store in the `header`
|
||||
* @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type)
|
||||
* @param header store the info here
|
||||
* @return LV_RES_OK: info written correctly; LV_RES_INV: failed
|
||||
*/
|
||||
typedef lv_res_t (*lv_img_decoder_info_f_t)(const void * src, lv_img_header_t * header);
|
||||
|
||||
/**
|
||||
* Open an image for decoding. Prepare it as it is required to read it later
|
||||
* @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type)
|
||||
* @param style the style of image (maybe it will be required to determine a color or something)
|
||||
* @return there are 3 possible return values:
|
||||
* 1) buffer with the decoded image
|
||||
* 2) if can decode the whole image NULL. decoder_read_line will be called to read the image line-by-line
|
||||
* 3) LV_IMG_DECODER_OPEN_FAIL if the image format is unknown to the decoder or an error occurred
|
||||
*/
|
||||
typedef const uint8_t * (*lv_img_decoder_open_f_t)(const void * src, const lv_style_t * style);
|
||||
|
||||
/**
|
||||
* Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`.
|
||||
* Required only if the "open" function can't return with the whole decoded pixel array.
|
||||
* @param x start x coordinate
|
||||
* @param y startt y coordinate
|
||||
* @param len number of pixels to decode
|
||||
* @param buf a buffer to store the decoded pixels
|
||||
* @return LV_RES_OK: ok; LV_RES_INV: failed
|
||||
*/
|
||||
typedef lv_res_t (*lv_img_decoder_read_line_f_t)(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
|
||||
|
||||
/**
|
||||
* Close the pending decoding. Free resources etc.
|
||||
*/
|
||||
typedef void (*lv_img_decoder_close_f_t)(void);
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Draw an image
|
||||
* @param coords the coordinates of the image
|
||||
* @param mask the image will be drawn only in this area
|
||||
* @param src pointer to a lv_color_t array which contains the pixels of the image
|
||||
* @param style style of the image
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,
|
||||
const void * src, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of an image source
|
||||
* @param src pointer to an image source:
|
||||
* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)
|
||||
* - a path to a file (e.g. "S:/folder/image.bin")
|
||||
* - or a symbol (e.g. SYMBOL_CLOSE)
|
||||
* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN
|
||||
*/
|
||||
lv_img_src_t lv_img_src_get_type(const void * src);
|
||||
|
||||
/**
|
||||
* Set custom decoder functions. See the typdefs of the function typed above for more info about them
|
||||
* @param info_fp info get function
|
||||
* @param open_fp open function
|
||||
* @param read_fp read line function
|
||||
* @param close_fp clode function
|
||||
*/
|
||||
void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp,
|
||||
lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp);
|
||||
|
||||
lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header);
|
||||
|
||||
uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf);
|
||||
|
||||
bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf);
|
||||
|
||||
bool lv_img_color_format_has_alpha(lv_img_cf_t cf);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_TEMPL_H*/
|
264
bdk/libs/lvgl/lv_draw/lv_draw_label.c
Normal file
264
bdk/libs/lvgl/lv_draw/lv_draw_label.c
Normal file
|
@ -0,0 +1,264 @@
|
|||
/**
|
||||
* @file lv_draw_label.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_label.h"
|
||||
#include "lv_draw_rbasic.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LABEL_RECOLOR_PAR_LENGTH 6
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
enum {
|
||||
CMD_STATE_WAIT,
|
||||
CMD_STATE_PAR,
|
||||
CMD_STATE_IN,
|
||||
};
|
||||
typedef uint8_t cmd_state_t;
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static uint8_t hex_char_to_num(char hex);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Write a text
|
||||
* @param coords coordinates of the label
|
||||
* @param mask the label will be drawn only in this area
|
||||
* @param style pointer to a style
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
* @param txt 0 terminated text to write
|
||||
* @param flag settings for the text from 'txt_flag_t' enum
|
||||
* @param offset text offset in x and y direction (NULL if unused)
|
||||
*
|
||||
*/
|
||||
void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale,
|
||||
const char * txt, lv_txt_flag_t flag, lv_point_t * offset)
|
||||
{
|
||||
const lv_font_t * font = style->text.font;
|
||||
lv_coord_t w;
|
||||
if((flag & LV_TXT_FLAG_EXPAND) == 0) {
|
||||
/*Normally use the label's width as width*/
|
||||
w = lv_area_get_width(coords);
|
||||
} else {
|
||||
/*If EXAPND is enabled then not limit the text's width to the object's width*/
|
||||
lv_point_t p;
|
||||
lv_txt_get_size(&p, txt, style->text.font, style->text.letter_space, style->text.line_space, LV_COORD_MAX, flag);
|
||||
w = p.x;
|
||||
}
|
||||
|
||||
lv_coord_t line_height = lv_font_get_height(font) + style->text.line_space;
|
||||
|
||||
|
||||
/*Init variables for the first line*/
|
||||
lv_coord_t line_width = 0;
|
||||
lv_point_t pos;
|
||||
pos.x = coords->x1;
|
||||
pos.y = coords->y1;
|
||||
|
||||
lv_coord_t x_ofs = 0;
|
||||
lv_coord_t y_ofs = 0;
|
||||
if(offset != NULL) {
|
||||
x_ofs = offset->x;
|
||||
y_ofs = offset->y;
|
||||
pos.y += y_ofs;
|
||||
}
|
||||
|
||||
uint32_t line_start = 0;
|
||||
uint32_t line_end = lv_txt_get_next_line(txt, font, style->text.letter_space, w, flag);
|
||||
|
||||
/*Go the first visible line*/
|
||||
while(pos.y + line_height < mask->y1) {
|
||||
/*Go to next line*/
|
||||
line_start = line_end;
|
||||
line_end += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, w, flag);
|
||||
pos.y += line_height;
|
||||
|
||||
if(txt[line_start] == '\0') return;
|
||||
}
|
||||
|
||||
/*Align to middle*/
|
||||
if(flag & LV_TXT_FLAG_CENTER) {
|
||||
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
|
||||
font, style->text.letter_space, flag);
|
||||
|
||||
pos.x += (lv_area_get_width(coords) - line_width) / 2;
|
||||
|
||||
}
|
||||
/*Align to the right*/
|
||||
else if(flag & LV_TXT_FLAG_RIGHT) {
|
||||
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
|
||||
font, style->text.letter_space, flag);
|
||||
pos.x += lv_area_get_width(coords) - line_width;
|
||||
}
|
||||
|
||||
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->text.opa : (uint16_t)((uint16_t) style->text.opa * opa_scale) >> 8;
|
||||
|
||||
cmd_state_t cmd_state = CMD_STATE_WAIT;
|
||||
uint32_t i;
|
||||
uint16_t par_start = 0;
|
||||
lv_color_t recolor;
|
||||
lv_coord_t letter_w;
|
||||
|
||||
/*Real draw need a background color for higher bpp letter*/
|
||||
#if LV_VDB_SIZE == 0
|
||||
lv_rletter_set_background(style->body.main_color);
|
||||
#endif
|
||||
|
||||
|
||||
/*Write out all lines*/
|
||||
while(txt[line_start] != '\0') {
|
||||
if(offset != NULL) {
|
||||
pos.x += x_ofs;
|
||||
}
|
||||
/*Write all letter of a line*/
|
||||
cmd_state = CMD_STATE_WAIT;
|
||||
i = line_start;
|
||||
uint32_t letter;
|
||||
while(i < line_end) {
|
||||
letter = lv_txt_encoded_next(txt, &i);
|
||||
|
||||
/*Handle the re-color command*/
|
||||
if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
|
||||
if(letter == (uint32_t)LV_TXT_COLOR_CMD[0]) {
|
||||
if(cmd_state == CMD_STATE_WAIT) { /*Start char*/
|
||||
par_start = i;
|
||||
cmd_state = CMD_STATE_PAR;
|
||||
continue;
|
||||
} else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */
|
||||
cmd_state = CMD_STATE_WAIT;
|
||||
} else if(cmd_state == CMD_STATE_IN) { /*Command end */
|
||||
cmd_state = CMD_STATE_WAIT;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/*Skip the color parameter and wait the space after it*/
|
||||
if(cmd_state == CMD_STATE_PAR) {
|
||||
if(letter == ' ') {
|
||||
/*Get the parameter*/
|
||||
if(i - par_start == LABEL_RECOLOR_PAR_LENGTH + 1) {
|
||||
char buf[LABEL_RECOLOR_PAR_LENGTH + 1];
|
||||
memcpy(buf, &txt[par_start], LABEL_RECOLOR_PAR_LENGTH);
|
||||
buf[LABEL_RECOLOR_PAR_LENGTH] = '\0';
|
||||
int r, g, b;
|
||||
r = (hex_char_to_num(buf[0]) << 4) + hex_char_to_num(buf[1]);
|
||||
g = (hex_char_to_num(buf[2]) << 4) + hex_char_to_num(buf[3]);
|
||||
b = (hex_char_to_num(buf[4]) << 4) + hex_char_to_num(buf[5]);
|
||||
recolor = LV_COLOR_MAKE(r, g, b);
|
||||
} else {
|
||||
recolor.full = style->text.color.full;
|
||||
}
|
||||
cmd_state = CMD_STATE_IN; /*After the parameter the text is in the command*/
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
lv_color_t color = style->text.color;
|
||||
|
||||
if(cmd_state == CMD_STATE_IN) color = recolor;
|
||||
|
||||
letter_fp(&pos, mask, font, letter, color, opa);
|
||||
letter_w = lv_font_get_width(font, letter);
|
||||
|
||||
if(letter_w > 0){
|
||||
pos.x += letter_w + style->text.letter_space;
|
||||
}
|
||||
}
|
||||
/*Go to next line*/
|
||||
line_start = line_end;
|
||||
line_end += lv_txt_get_next_line(&txt[line_start], font, style->text.letter_space, w, flag);
|
||||
|
||||
pos.x = coords->x1;
|
||||
/*Align to middle*/
|
||||
if(flag & LV_TXT_FLAG_CENTER) {
|
||||
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
|
||||
font, style->text.letter_space, flag);
|
||||
|
||||
pos.x += (lv_area_get_width(coords) - line_width) / 2;
|
||||
|
||||
}
|
||||
/*Align to the right*/
|
||||
else if(flag & LV_TXT_FLAG_RIGHT) {
|
||||
line_width = lv_txt_get_width(&txt[line_start], line_end - line_start,
|
||||
font, style->text.letter_space, flag);
|
||||
pos.x += lv_area_get_width(coords) - line_width;
|
||||
}
|
||||
|
||||
/*Go the next line position*/
|
||||
pos.y += line_height;
|
||||
|
||||
if(pos.y > mask->y2) return;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Convert a hexadecimal characters to a number (0..15)
|
||||
* @param hex Pointer to a hexadecimal character (0..9, A..F)
|
||||
* @return the numerical value of `hex` or 0 on error
|
||||
*/
|
||||
static uint8_t hex_char_to_num(char hex)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
if(hex >= '0' && hex <= '9') {
|
||||
result = hex - '0';
|
||||
}
|
||||
else {
|
||||
if(hex >= 'a') hex -= 'a' - 'A'; /*Convert to upper case*/
|
||||
|
||||
switch(hex) {
|
||||
case 'A':
|
||||
result = 10;
|
||||
break;
|
||||
case 'B':
|
||||
result = 11;
|
||||
break;
|
||||
case 'C':
|
||||
result = 12;
|
||||
break;
|
||||
case 'D':
|
||||
result = 13;
|
||||
break;
|
||||
case 'E':
|
||||
result = 14;
|
||||
break;
|
||||
case 'F':
|
||||
result = 15;
|
||||
break;
|
||||
default:
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
53
bdk/libs/lvgl/lv_draw/lv_draw_label.h
Normal file
53
bdk/libs/lvgl/lv_draw/lv_draw_label.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* @file lv_draw_label.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_LABEL_H
|
||||
#define LV_DRAW_LABEL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Write a text
|
||||
* @param coords coordinates of the label
|
||||
* @param mask the label will be drawn only in this area
|
||||
* @param style pointer to a style
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
* @param txt 0 terminated text to write
|
||||
* @param flag settings for the text from 'txt_flag_t' enum
|
||||
* @param offset text offset in x and y direction (NULL if unused)
|
||||
*
|
||||
*/
|
||||
void lv_draw_label(const lv_area_t * coords,const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale,
|
||||
const char * txt, lv_txt_flag_t flag, lv_point_t * offset);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRAW_LABEL_H*/
|
607
bdk/libs/lvgl/lv_draw/lv_draw_line.c
Normal file
607
bdk/libs/lvgl/lv_draw/lv_draw_line.c
Normal file
|
@ -0,0 +1,607 @@
|
|||
/**
|
||||
* @file lv_draw_line.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stdio.h>
|
||||
#include "lv_draw.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#if LV_COMPILER_VLA_SUPPORTED == 0
|
||||
#define LINE_MAX_WIDTH 64
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef struct {
|
||||
lv_point_t p1;
|
||||
lv_point_t p2;
|
||||
lv_point_t p_act;
|
||||
lv_coord_t dx;
|
||||
lv_coord_t sx; /*-1: x1 < x2; 1: x2 >= x1*/
|
||||
lv_coord_t dy;
|
||||
lv_coord_t sy; /*-1: y1 < y2; 1: y2 >= y1*/
|
||||
lv_coord_t err;
|
||||
lv_coord_t e2;
|
||||
bool hor; /*Rather horizontal or vertical*/
|
||||
} line_draw_t;
|
||||
|
||||
typedef struct {
|
||||
lv_coord_t width;
|
||||
lv_coord_t width_1;
|
||||
lv_coord_t width_half;
|
||||
} line_width_t;
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void line_draw_hor(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
static void line_draw_ver(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
static void line_init(line_draw_t * line, const lv_point_t * p1, const lv_point_t * p2);
|
||||
static bool line_next(line_draw_t * line);
|
||||
static bool line_next_y(line_draw_t * line);
|
||||
static bool line_next_x(line_draw_t * line);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Draw a line
|
||||
* @param point1 first point of the line
|
||||
* @param point2 second point of the line
|
||||
* @param mask the line will be drawn only on this area
|
||||
* @param style pointer to a line's style
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask,
|
||||
const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
|
||||
if(style->line.width == 0) return;
|
||||
if(point1->x == point2->x && point1->y == point2->y) return;
|
||||
|
||||
line_draw_t main_line;
|
||||
lv_point_t p1;
|
||||
lv_point_t p2;
|
||||
|
||||
/*If the line if rather vertical then be sure y1 < y2 else x1 < x2*/
|
||||
|
||||
if(LV_MATH_ABS(point1->x - point2->x) > LV_MATH_ABS(point1->y - point2->y)) {
|
||||
|
||||
/*Steps less in y then x -> rather horizontal*/
|
||||
if(point1->x < point2->x) {
|
||||
p1.x = point1->x;
|
||||
p1.y = point1->y;
|
||||
p2.x = point2->x;
|
||||
p2.y = point2->y;
|
||||
} else {
|
||||
p1.x = point2->x;
|
||||
p1.y = point2->y;
|
||||
p2.x = point1->x;
|
||||
p2.y = point1->y;
|
||||
}
|
||||
} else {
|
||||
/*Steps less in x then y -> rather vertical*/
|
||||
if(point1->y < point2->y) {
|
||||
p1.x = point1->x;
|
||||
p1.y = point1->y;
|
||||
p2.x = point2->x;
|
||||
p2.y = point2->y;
|
||||
} else {
|
||||
p1.x = point2->x;
|
||||
p1.y = point2->y;
|
||||
p2.x = point1->x;
|
||||
p2.y = point1->y;
|
||||
}
|
||||
}
|
||||
|
||||
line_init(&main_line, &p1, &p2);
|
||||
|
||||
|
||||
/*Special case draw a horizontal line*/
|
||||
if(main_line.p1.y == main_line.p2.y) {
|
||||
line_draw_hor(&main_line, mask, style, opa_scale);
|
||||
}
|
||||
/*Special case draw a vertical line*/
|
||||
else if(main_line.p1.x == main_line.p2.x) {
|
||||
line_draw_ver(&main_line, mask, style, opa_scale);
|
||||
}
|
||||
/*Arbitrary skew line*/
|
||||
else {
|
||||
bool dir_ori = false;
|
||||
#if LV_ANTIALIAS
|
||||
lv_point_t p_tmp;
|
||||
|
||||
if(main_line.hor) {
|
||||
if(main_line.p1.y < main_line.p2.y) {
|
||||
dir_ori = true;
|
||||
p_tmp.x = main_line.p2.x;
|
||||
p_tmp.y = main_line.p2.y - 1;
|
||||
line_init(&main_line, &p1, &p_tmp);
|
||||
main_line.sy = LV_MATH_ABS(main_line.sy); /*The sign can change if the line becomes horizontal*/
|
||||
}
|
||||
else if(main_line.p1.y > main_line.p2.y) {
|
||||
dir_ori = false;
|
||||
p_tmp.x = main_line.p2.x;
|
||||
p_tmp.y = main_line.p2.y + 1;
|
||||
line_init(&main_line, &p1, &p_tmp);
|
||||
main_line.sy = -LV_MATH_ABS(main_line.sy); /*The sign can change if the line becomes horizontal*/
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(main_line.p1.x < main_line.p2.x) {
|
||||
dir_ori = true;
|
||||
p_tmp.x = main_line.p2.x - 1;
|
||||
p_tmp.y = main_line.p2.y;
|
||||
line_init(&main_line, &p1, &p_tmp);
|
||||
main_line.sx = LV_MATH_ABS(main_line.sx); /*The sign can change if the line becomes vertical*/
|
||||
}
|
||||
else if(main_line.p1.x > main_line.p2.x) {
|
||||
dir_ori = false;
|
||||
p_tmp.x = main_line.p2.x + 1;
|
||||
p_tmp.y = main_line.p2.y;
|
||||
line_init(&main_line, &p1, &p_tmp);
|
||||
main_line.sx = -LV_MATH_ABS(main_line.sx); /*The sign can change if the line becomes vertical*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
line_draw_skew(&main_line, dir_ori, mask, style, opa_scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
static void line_draw_hor(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
lv_coord_t width = style->line.width - 1;
|
||||
lv_coord_t width_half = width >> 1;
|
||||
lv_coord_t width_1 = width & 0x1;
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->line.opa : (uint16_t)((uint16_t) style->line.opa * opa_scale) >> 8;
|
||||
|
||||
lv_area_t act_area;
|
||||
act_area.x1 = main_line->p1.x;
|
||||
act_area.x2 = main_line->p2.x;
|
||||
act_area.y1 = main_line->p1.y - width_half - width_1;
|
||||
act_area.y2 = main_line->p2.y + width_half ;
|
||||
|
||||
lv_area_t draw_area;
|
||||
draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2);
|
||||
draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2);
|
||||
draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2);
|
||||
draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2);
|
||||
fill_fp(&draw_area, mask, style->line.color, opa);
|
||||
}
|
||||
|
||||
static void line_draw_ver(line_draw_t * main_line, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
lv_coord_t width = style->line.width - 1;
|
||||
lv_coord_t width_half = width >> 1;
|
||||
lv_coord_t width_1 = width & 0x1;
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->line.opa : (uint16_t)((uint16_t) style->line.opa * opa_scale) >> 8;
|
||||
|
||||
|
||||
lv_area_t act_area;
|
||||
act_area.x1 = main_line->p1.x - width_half;
|
||||
act_area.x2 = main_line->p2.x + width_half + width_1;
|
||||
act_area.y1 = main_line->p1.y;
|
||||
act_area.y2 = main_line->p2.y;
|
||||
|
||||
lv_area_t draw_area;
|
||||
draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2);
|
||||
draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2);
|
||||
draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2);
|
||||
draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2);
|
||||
fill_fp(&draw_area, mask, style->line.color, opa);
|
||||
}
|
||||
|
||||
static void line_draw_skew(line_draw_t * main_line, bool dir_ori, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale)
|
||||
{
|
||||
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER ? style->line.opa : (uint16_t)((uint16_t) style->line.opa * opa_scale) >> 8;
|
||||
|
||||
lv_point_t vect_main, vect_norm;
|
||||
vect_main.x = main_line->p2.x - main_line->p1.x;
|
||||
vect_main.y = main_line->p2.y - main_line->p1.y;
|
||||
|
||||
if(main_line->hor) {
|
||||
if(main_line->p1.y < main_line->p2.y + dir_ori) {
|
||||
vect_norm.x = - vect_main.y;
|
||||
vect_norm.y = vect_main.x;
|
||||
} else {
|
||||
vect_norm.x = vect_main.y;
|
||||
vect_norm.y = -vect_main.x;
|
||||
}
|
||||
} else {
|
||||
if(main_line->p1.x < main_line->p2.x + dir_ori) {
|
||||
vect_norm.x = vect_main.y;
|
||||
vect_norm.y = - vect_main.x;
|
||||
} else {
|
||||
vect_norm.x = - vect_main.y;
|
||||
vect_norm.y = vect_main.x;
|
||||
}
|
||||
}
|
||||
|
||||
/* In case of a short but tick line the perpendicular ending is longer then the real line.
|
||||
* it would break the calculations so make the normal vector larger*/
|
||||
vect_norm.x = vect_norm.x << 4;
|
||||
vect_norm.y = vect_norm.y << 4;
|
||||
|
||||
lv_coord_t width;
|
||||
width = style->line.width;
|
||||
|
||||
/* The pattern stores the points of the line ending. It has the good direction and length.
|
||||
* The worth case is the 45° line where pattern can have 1.41 x `width` points*/
|
||||
#if LV_COMPILER_VLA_SUPPORTED
|
||||
lv_point_t pattern[width * 2];
|
||||
#else
|
||||
lv_point_t pattern[LINE_MAX_WIDTH];
|
||||
#endif
|
||||
lv_coord_t i = 0;
|
||||
|
||||
/*Create a perpendicular pattern (a small line)*/
|
||||
if(width != 0) {
|
||||
line_draw_t pattern_line;
|
||||
lv_point_t p0 = {0, 0};
|
||||
line_init(&pattern_line, &p0, &vect_norm);
|
||||
|
||||
uint32_t width_sqr = width * width;
|
||||
/* Run for a lot of times. Meanwhile the real width will be determined as well */
|
||||
for(i = 0; i < (lv_coord_t)sizeof(pattern); i ++) {
|
||||
pattern[i].x = pattern_line.p_act.x;
|
||||
pattern[i].y = pattern_line.p_act.y;
|
||||
|
||||
/*Finish the pattern line if it's length equal to the desired width (Use Pythagoras theorem)*/
|
||||
uint32_t sqr = pattern_line.p_act.x * pattern_line.p_act.x + pattern_line.p_act.y * pattern_line.p_act.y;
|
||||
if(sqr >= width_sqr) {
|
||||
width = i;
|
||||
#if LV_ANTIALIAS
|
||||
width--;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
line_next(&pattern_line);
|
||||
}
|
||||
}
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
lv_coord_t width_safe = width;
|
||||
if(width == 0) width_safe = 1;
|
||||
|
||||
lv_coord_t aa_last_corner;
|
||||
aa_last_corner = 0;
|
||||
#endif
|
||||
|
||||
lv_coord_t x_center_ofs = 0;
|
||||
lv_coord_t y_center_ofs = 0;
|
||||
|
||||
if(width != 0) {
|
||||
x_center_ofs = pattern[width - 1].x / 2;
|
||||
y_center_ofs = pattern[width - 1].y / 2;
|
||||
}
|
||||
else {
|
||||
if(main_line->hor && main_line->p1.y >= main_line->p2.y + dir_ori) pattern[0].y --;
|
||||
if(!main_line->hor && main_line->p1.x >= main_line->p2.x + dir_ori) pattern[0].x --;
|
||||
}
|
||||
|
||||
/* Make the coordinates relative to the center */
|
||||
for(i = 0; i < width; i++) {
|
||||
pattern[i].x -= x_center_ofs;
|
||||
pattern[i].y -= y_center_ofs;
|
||||
#if LV_ANTIALIAS
|
||||
if(i != 0) {
|
||||
if(main_line->hor) {
|
||||
if(pattern[i - 1].x != pattern[i].x) {
|
||||
lv_coord_t seg_w = pattern[i].y - pattern[aa_last_corner].y;
|
||||
if(main_line->sy < 0) {
|
||||
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w + 1,
|
||||
seg_w, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w + 1,
|
||||
-seg_w, mask, style->line.color, opa);
|
||||
} else {
|
||||
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y,
|
||||
seg_w, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y,
|
||||
-seg_w, mask, style->line.color, opa);
|
||||
}
|
||||
aa_last_corner = i;
|
||||
}
|
||||
} else {
|
||||
if(pattern[i - 1].y != pattern[i].y) {
|
||||
lv_coord_t seg_w = pattern[i].x - pattern[aa_last_corner].x;
|
||||
if(main_line->sx < 0) {
|
||||
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||
seg_w, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w + 1, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||
-seg_w, mask, style->line.color, opa);
|
||||
} else {
|
||||
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||
seg_w, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||
-seg_w, mask, style->line.color, opa);
|
||||
}
|
||||
aa_last_corner = i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
/*Add the last part of anti-aliasing for the perpendicular ending*/
|
||||
if(width != 0) { /*Due to rounding error with very thin lines it looks ugly*/
|
||||
if(main_line->hor) {
|
||||
lv_coord_t seg_w = pattern[width_safe - 1].y - pattern[aa_last_corner].y;
|
||||
if(main_line->sy < 0) {
|
||||
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y + seg_w,
|
||||
seg_w + main_line->sy, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y + seg_w,
|
||||
-(seg_w + main_line->sy), mask, style->line.color, opa);
|
||||
|
||||
} else {
|
||||
lv_draw_aa_ver_seg(main_line->p1.x + pattern[aa_last_corner].x - 1, main_line->p1.y + pattern[aa_last_corner].y,
|
||||
seg_w + main_line->sy, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_ver_seg(main_line->p2.x + pattern[aa_last_corner].x + 1, main_line->p2.y + pattern[aa_last_corner].y,
|
||||
-(seg_w + main_line->sy), mask, style->line.color, opa);
|
||||
}
|
||||
} else {
|
||||
lv_coord_t seg_w = pattern[width_safe - 1].x - pattern[aa_last_corner].x;
|
||||
if(main_line->sx < 0) {
|
||||
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x + seg_w, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||
seg_w + main_line->sx, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x + seg_w, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||
-(seg_w + main_line->sx), mask, style->line.color, opa);
|
||||
|
||||
} else {
|
||||
lv_draw_aa_hor_seg(main_line->p1.x + pattern[aa_last_corner].x, main_line->p1.y + pattern[aa_last_corner].y - 1,
|
||||
seg_w + main_line->sx, mask, style->line.color, opa);
|
||||
|
||||
lv_draw_aa_hor_seg(main_line->p2.x + pattern[aa_last_corner].x, main_line->p2.y + pattern[aa_last_corner].y + 1,
|
||||
-(seg_w + main_line->sx), mask, style->line.color, opa);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
|
||||
/*Shift the anti aliasing on the edges (-1, 1 or 0 (zero only in case width == 0))*/
|
||||
lv_coord_t aa_shift1;
|
||||
lv_coord_t aa_shift2;
|
||||
|
||||
if(main_line->hor == false) {
|
||||
if(main_line->sx < 0) {
|
||||
aa_shift1 = -1;
|
||||
aa_shift2 = width == 0 ? 0 : aa_shift1;
|
||||
} else {
|
||||
aa_shift2 = 1;
|
||||
aa_shift1 = width == 0 ? 0 : aa_shift2;
|
||||
}
|
||||
} else {
|
||||
if(main_line->sy < 0) {
|
||||
aa_shift1 = -1;
|
||||
aa_shift2 = width == 0 ? 0 : aa_shift1;
|
||||
} else {
|
||||
aa_shift2 = 1;
|
||||
aa_shift1 = width == 0 ? 0 : aa_shift2;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
volatile lv_point_t prev_p;
|
||||
prev_p.x = main_line->p1.x;
|
||||
prev_p.y = main_line->p1.y;
|
||||
lv_area_t draw_area;
|
||||
bool first_run = true;
|
||||
|
||||
if(main_line->hor) {
|
||||
while(line_next_y(main_line)) {
|
||||
for(i = 0; i < width; i++) {
|
||||
draw_area.x1 = prev_p.x + pattern[i].x;
|
||||
draw_area.y1 = prev_p.y + pattern[i].y;
|
||||
draw_area.x2 = draw_area.x1 + main_line->p_act.x - prev_p.x - 1;
|
||||
draw_area.y2 = draw_area.y1;
|
||||
fill_fp(&draw_area, mask, style->line.color, opa);
|
||||
|
||||
/* Fill the gaps
|
||||
* When stepping in y one pixel remains empty on every corner (don't do this on the first segment ) */
|
||||
if(i != 0 && pattern[i].x != pattern[i - 1].x && !first_run) {
|
||||
px_fp(draw_area.x1, draw_area.y1 - main_line->sy, mask, style->line.color, opa);
|
||||
}
|
||||
}
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
lv_draw_aa_hor_seg(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1,
|
||||
-(main_line->p_act.x - prev_p.x), mask, style->line.color, opa);
|
||||
lv_draw_aa_hor_seg(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2,
|
||||
main_line->p_act.x - prev_p.x, mask, style->line.color, opa);
|
||||
#endif
|
||||
|
||||
first_run = false;
|
||||
|
||||
prev_p.x = main_line->p_act.x;
|
||||
prev_p.y = main_line->p_act.y;
|
||||
}
|
||||
|
||||
for(i = 0; i < width; i++) {
|
||||
draw_area.x1 = prev_p.x + pattern[i].x;
|
||||
draw_area.y1 = prev_p.y + pattern[i].y;
|
||||
draw_area.x2 = draw_area.x1 + main_line->p_act.x - prev_p.x;
|
||||
draw_area.y2 = draw_area.y1;
|
||||
fill_fp(&draw_area, mask, style->line.color, opa);
|
||||
|
||||
/* Fill the gaps
|
||||
* When stepping in y one pixel remains empty on every corner */
|
||||
if(i != 0 && pattern[i].x != pattern[i - 1].x && !first_run) {
|
||||
px_fp(draw_area.x1, draw_area.y1 - main_line->sy, mask, style->line.color, opa);
|
||||
}
|
||||
}
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
lv_draw_aa_hor_seg(prev_p.x + pattern[0].x, prev_p.y + pattern[0].y - aa_shift1,
|
||||
-(main_line->p_act.x - prev_p.x + 1), mask, style->line.color, opa);
|
||||
lv_draw_aa_hor_seg(prev_p.x + pattern[width_safe - 1].x, prev_p.y + pattern[width_safe - 1].y + aa_shift2,
|
||||
main_line->p_act.x - prev_p.x + 1, mask, style->line.color, opa);
|
||||
#endif
|
||||
}
|
||||
/*Rather a vertical line*/
|
||||
else {
|
||||
|
||||
while(line_next_x(main_line)) {
|
||||
for(i = 0; i < width; i++) {
|
||||
draw_area.x1 = prev_p.x + pattern[i].x;
|
||||
draw_area.y1 = prev_p.y + pattern[i].y;
|
||||
draw_area.x2 = draw_area.x1;
|
||||
draw_area.y2 = draw_area.y1 + main_line->p_act.y - prev_p.y - 1;
|
||||
|
||||
fill_fp(&draw_area, mask, style->line.color, opa);
|
||||
|
||||
/* Fill the gaps
|
||||
* When stepping in x one pixel remains empty on every corner (don't do this on the first segment ) */
|
||||
if(i != 0 && pattern[i].y != pattern[i - 1].y && !first_run) {
|
||||
px_fp(draw_area.x1 - main_line->sx, draw_area.y1, mask, style->line.color, opa);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
lv_draw_aa_ver_seg(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y,
|
||||
-(main_line->p_act.y - prev_p.y), mask, style->line.color, opa);
|
||||
lv_draw_aa_ver_seg(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y,
|
||||
main_line->p_act.y - prev_p.y, mask, style->line.color, opa);
|
||||
#endif
|
||||
|
||||
first_run = false;
|
||||
|
||||
prev_p.x = main_line->p_act.x;
|
||||
prev_p.y = main_line->p_act.y;
|
||||
}
|
||||
|
||||
/*Draw the last part*/
|
||||
for(i = 0; i < width; i++) {
|
||||
draw_area.x1 = prev_p.x + pattern[i].x;
|
||||
draw_area.y1 = prev_p.y + pattern[i].y;
|
||||
draw_area.x2 = draw_area.x1;
|
||||
draw_area.y2 = draw_area.y1 + main_line->p_act.y - prev_p.y;
|
||||
|
||||
fill_fp(&draw_area, mask, style->line.color, opa);
|
||||
|
||||
/* Fill the gaps
|
||||
* When stepping in x one pixel remains empty on every corner */
|
||||
if(i != 0 && pattern[i].y != pattern[i - 1].y && !first_run) {
|
||||
px_fp(draw_area.x1 - main_line->sx, draw_area.y1, mask, style->line.color, opa);
|
||||
}
|
||||
}
|
||||
|
||||
#if LV_ANTIALIAS
|
||||
lv_draw_aa_ver_seg(prev_p.x + pattern[0].x - aa_shift1, prev_p.y + pattern[0].y,
|
||||
-(main_line->p_act.y - prev_p.y + 1), mask, style->line.color, opa);
|
||||
lv_draw_aa_ver_seg(prev_p.x + pattern[width_safe - 1].x + aa_shift2, prev_p.y + pattern[width_safe - 1].y,
|
||||
main_line->p_act.y - prev_p.y + 1, mask, style->line.color, opa);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void line_init(line_draw_t * line, const lv_point_t * p1, const lv_point_t * p2)
|
||||
{
|
||||
line->p1.x = p1->x;
|
||||
line->p1.y = p1->y;
|
||||
line->p2.x = p2->x;
|
||||
line->p2.y = p2->y;
|
||||
|
||||
line->dx = LV_MATH_ABS(line->p2.x - line->p1.x);
|
||||
line->sx = line->p1.x < line->p2.x ? 1 : -1;
|
||||
line->dy = LV_MATH_ABS(line->p2.y - line->p1.y);
|
||||
line->sy = line->p1.y < line->p2.y ? 1 : -1;
|
||||
line->err = (line->dx > line->dy ? line->dx : -line->dy) / 2;
|
||||
line->e2 = 0;
|
||||
line->hor = line->dx > line->dy ? true : false; /*Rather horizontal or vertical*/
|
||||
|
||||
line->p_act.x = line->p1.x;
|
||||
line->p_act.y = line->p1.y;
|
||||
}
|
||||
|
||||
static bool line_next(line_draw_t * line)
|
||||
{
|
||||
if(line->p_act.x == line->p2.x && line->p_act.y == line->p2.y) return false;
|
||||
line->e2 = line->err;
|
||||
if(line->e2 > -line->dx) {
|
||||
line->err -= line->dy;
|
||||
line->p_act.x += line->sx;
|
||||
}
|
||||
if(line->e2 < line->dy) {
|
||||
line->err += line->dx;
|
||||
line->p_act.y += line->sy;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate until step one in y direction.
|
||||
* @param line
|
||||
* @return
|
||||
*/
|
||||
static bool line_next_y(line_draw_t * line)
|
||||
{
|
||||
lv_coord_t last_y = line->p_act.y;
|
||||
|
||||
do {
|
||||
if(!line_next(line)) return false;
|
||||
} while(last_y == line->p_act.y);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate until step one in x direction.
|
||||
* @param line
|
||||
* @return
|
||||
*/
|
||||
static bool line_next_x(line_draw_t * line)
|
||||
{
|
||||
lv_coord_t last_x = line->p_act.x;
|
||||
|
||||
do {
|
||||
if(!line_next(line)) return false;
|
||||
} while(last_x == line->p_act.x);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
49
bdk/libs/lvgl/lv_draw/lv_draw_line.h
Normal file
49
bdk/libs/lvgl/lv_draw/lv_draw_line.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* @file lv_draw_line.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_LINE_H
|
||||
#define LV_DRAW_LINE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Draw a line
|
||||
* @param point1 first point of the line
|
||||
* @param point2 second point of the line
|
||||
* @param mask the line will be drawn only on this area
|
||||
* @param style pointer to a line's style
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask,
|
||||
const lv_style_t * style, lv_opa_t opa_scale);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRAW_LINE_H*/
|
269
bdk/libs/lvgl/lv_draw/lv_draw_rbasic.c
Normal file
269
bdk/libs/lvgl/lv_draw/lv_draw_rbasic.c
Normal file
|
@ -0,0 +1,269 @@
|
|||
/**
|
||||
* @file lv_draw_rbasic.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_rbasic.h"
|
||||
#if USE_LV_REAL_DRAW != 0
|
||||
|
||||
#include "../lv_hal/lv_hal_disp.h"
|
||||
#include "../lv_misc/lv_font.h"
|
||||
#include "lv_draw.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_color_t letter_bg_color;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Put a pixel to the display
|
||||
* @param x x coordinate of the pixel
|
||||
* @param y y coordinate of the pixel
|
||||
* @param mask_p the pixel will be drawn on this area
|
||||
* @param color color of the pixel
|
||||
* @param opa opacity (ignored, only for compatibility with lv_vpx)
|
||||
*/
|
||||
void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
(void)opa; /*Opa is used only for compatibility with lv_vpx*/
|
||||
|
||||
lv_area_t area;
|
||||
area.x1 = x;
|
||||
area.y1 = y;
|
||||
area.x2 = x;
|
||||
area.y2 = y;
|
||||
|
||||
lv_rfill(&area, mask_p, color, LV_OPA_COVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill an area on the display
|
||||
* @param cords_p coordinates of the area to fill
|
||||
* @param mask_p fill only o this mask
|
||||
* @param color fill color
|
||||
* @param opa opacity (ignored, only for compatibility with lv_vfill)
|
||||
*/
|
||||
void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
|
||||
(void)opa; /*Opa is used only for compatibility with lv_vfill*/
|
||||
|
||||
lv_area_t masked_area;
|
||||
bool union_ok = true;
|
||||
|
||||
if(mask_p != NULL) {
|
||||
union_ok = lv_area_intersect(&masked_area, cords_p, mask_p);
|
||||
} else {
|
||||
lv_area_t scr_area;
|
||||
lv_area_set(&scr_area, 0, 0, LV_HOR_RES - 1, LV_VER_RES - 1);
|
||||
union_ok = lv_area_intersect(&masked_area, cords_p, &scr_area);
|
||||
}
|
||||
|
||||
if(union_ok != false) {
|
||||
lv_disp_fill(masked_area.x1, masked_area.y1, masked_area.x2, masked_area.y2, color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a letter to the display
|
||||
* @param pos_p left-top coordinate of the latter
|
||||
* @param mask_p the letter will be drawn only on this area
|
||||
* @param font_p pointer to font
|
||||
* @param letter a letter to draw
|
||||
* @param color color of letter
|
||||
* @param opa opacity of letter (ignored, only for compatibility with lv_vletter)
|
||||
*/
|
||||
void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
|
||||
const lv_font_t * font_p, uint32_t letter,
|
||||
lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
(void)opa; /*Opa is used only for compatibility with lv_vletter*/
|
||||
|
||||
static uint8_t bpp1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
|
||||
static uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
|
||||
static uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
|
||||
68, 85, 102, 119,
|
||||
136, 153, 170, 187,
|
||||
204, 221, 238, 255
|
||||
};
|
||||
|
||||
if(font_p == NULL) return;
|
||||
|
||||
uint8_t letter_w = lv_font_get_width(font_p, letter);
|
||||
uint8_t letter_h = lv_font_get_height(font_p);
|
||||
uint8_t bpp = lv_font_get_bpp(font_p, letter); /*Bit per pixel (1,2, 4 or 8)*/
|
||||
uint8_t * bpp_opa_table;
|
||||
uint8_t mask_init;
|
||||
uint8_t mask;
|
||||
|
||||
switch(bpp) {
|
||||
case 1:
|
||||
bpp_opa_table = bpp1_opa_table;
|
||||
mask_init = 0x80;
|
||||
break;
|
||||
case 2:
|
||||
bpp_opa_table = bpp2_opa_table;
|
||||
mask_init = 0xC0;
|
||||
break;
|
||||
case 4:
|
||||
bpp_opa_table = bpp4_opa_table;
|
||||
mask_init = 0xF0;
|
||||
break;
|
||||
case 8:
|
||||
bpp_opa_table = NULL;
|
||||
mask_init = 0xFF;
|
||||
break; /*No opa table, pixel value will be used directly*/
|
||||
default:
|
||||
return; /*Invalid bpp. Can't render the letter*/
|
||||
}
|
||||
|
||||
const uint8_t * map_p = lv_font_get_bitmap(font_p, letter);
|
||||
|
||||
if(map_p == NULL) return;
|
||||
|
||||
/*If the letter is completely out of mask don't draw it */
|
||||
if(pos_p->x + letter_w < mask_p->x1 || pos_p->x > mask_p->x2 ||
|
||||
pos_p->y + letter_h < mask_p->y1 || pos_p->y > mask_p->y2) return;
|
||||
|
||||
lv_coord_t col, row;
|
||||
uint8_t col_bit;
|
||||
uint8_t col_byte_cnt;
|
||||
uint8_t width_byte_scr = letter_w >> 3; /*Width in bytes (on the screen finally) (e.g. w = 11 -> 2 bytes wide)*/
|
||||
if(letter_w & 0x7) width_byte_scr++;
|
||||
uint8_t width_byte_bpp = (letter_w * bpp) >> 3; /*Letter width in byte. Real width in the font*/
|
||||
if((letter_w * bpp) & 0x7) width_byte_bpp++;
|
||||
|
||||
/* Calculate the col/row start/end on the map*/
|
||||
lv_coord_t col_start = pos_p->x >= mask_p->x1 ? 0 : mask_p->x1 - pos_p->x;
|
||||
lv_coord_t col_end = pos_p->x + letter_w <= mask_p->x2 ? letter_w : mask_p->x2 - pos_p->x + 1;
|
||||
lv_coord_t row_start = pos_p->y >= mask_p->y1 ? 0 : mask_p->y1 - pos_p->y;
|
||||
lv_coord_t row_end = pos_p->y + letter_h <= mask_p->y2 ? letter_h : mask_p->y2 - pos_p->y + 1;
|
||||
|
||||
/*Move on the map too*/
|
||||
map_p += (row_start * width_byte_bpp) + ((col_start * bpp) >> 3);
|
||||
|
||||
uint8_t letter_px;
|
||||
for(row = row_start; row < row_end; row ++) {
|
||||
col_byte_cnt = 0;
|
||||
col_bit = (col_start * bpp) % 8;
|
||||
mask = mask_init >> col_bit;
|
||||
for(col = col_start; col < col_end; col ++) {
|
||||
letter_px = (*map_p & mask) >> (8 - col_bit - bpp);
|
||||
if(letter_px != 0) {
|
||||
lv_rpx(pos_p->x + col, pos_p->y + row, mask_p, lv_color_mix(color, letter_bg_color, bpp == 8 ? letter_px : bpp_opa_table[letter_px]), LV_OPA_COVER);
|
||||
}
|
||||
|
||||
if(col_bit < 8 - bpp) {
|
||||
col_bit += bpp;
|
||||
mask = mask >> bpp;
|
||||
} else {
|
||||
col_bit = 0;
|
||||
col_byte_cnt ++;
|
||||
mask = mask_init;
|
||||
map_p ++;
|
||||
}
|
||||
}
|
||||
|
||||
map_p += (width_byte_bpp) - col_byte_cnt;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When the letter is ant-aliased it needs to know the background color
|
||||
* @param bg_color the background color of the currently drawn letter
|
||||
*/
|
||||
void lv_rletter_set_background(lv_color_t color)
|
||||
{
|
||||
letter_bg_color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a color map to the display (image)
|
||||
* @param cords_p coordinates the color map
|
||||
* @param mask_p the map will drawn only on this area
|
||||
* @param map_p pointer to a lv_color_t array
|
||||
* @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap')
|
||||
* @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels
|
||||
* @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it)
|
||||
* @param recolor mix the pixels with this color
|
||||
* @param recolor_opa the intense of recoloring
|
||||
*/
|
||||
void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
|
||||
lv_color_t recolor, lv_opa_t recolor_opa)
|
||||
{
|
||||
if(alpha_byte) return; /*Pixel level opacity i not supported in real map drawing*/
|
||||
|
||||
(void)opa; /*opa is used only for compatibility with lv_vmap*/
|
||||
lv_area_t masked_a;
|
||||
bool union_ok;
|
||||
|
||||
union_ok = lv_area_intersect(&masked_a, cords_p, mask_p);
|
||||
|
||||
/*If there are common part of the mask and map then draw the map*/
|
||||
if(union_ok == false) return;
|
||||
|
||||
/*Go to the first pixel*/
|
||||
lv_coord_t map_width = lv_area_get_width(cords_p);
|
||||
map_p += (masked_a.y1 - cords_p->y1) * map_width * sizeof(lv_color_t);
|
||||
map_p += (masked_a.x1 - cords_p->x1) * sizeof(lv_color_t);
|
||||
|
||||
lv_coord_t row;
|
||||
if(recolor_opa == LV_OPA_TRANSP && chroma_key == false) {
|
||||
lv_coord_t mask_w = lv_area_get_width(&masked_a) - 1;
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
lv_disp_map(masked_a.x1, row, masked_a.x1 + mask_w, row, (lv_color_t *)map_p);
|
||||
map_p += map_width * sizeof(lv_color_t); /*Next row on the map*/
|
||||
}
|
||||
} else {
|
||||
lv_color_t chroma_key_color = LV_COLOR_TRANSP;
|
||||
lv_coord_t col;
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
for(col = masked_a.x1; col <= masked_a.x2; col++) {
|
||||
lv_color_t * px_color = (lv_color_t *) &map_p[(uint32_t)(col - masked_a.x1) * sizeof(lv_color_t)];
|
||||
|
||||
if(chroma_key && chroma_key_color.full == px_color->full) continue;
|
||||
|
||||
if(recolor_opa != LV_OPA_TRANSP) {
|
||||
lv_color_t recolored_px = lv_color_mix(recolor, *px_color, recolor_opa);
|
||||
|
||||
lv_rpx(col, row, mask_p, recolored_px, LV_OPA_COVER);
|
||||
} else {
|
||||
lv_rpx(col, row, mask_p, *px_color, LV_OPA_COVER);
|
||||
}
|
||||
|
||||
}
|
||||
map_p += map_width * sizeof(lv_color_t); /*Next row on the map*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_REAL_DRAW*/
|
96
bdk/libs/lvgl/lv_draw/lv_draw_rbasic.h
Normal file
96
bdk/libs/lvgl/lv_draw/lv_draw_rbasic.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* @file lv_draw_rbasic..h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_RBASIC_H
|
||||
#define LV_DRAW_RBASIC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_LV_REAL_DRAW != 0
|
||||
|
||||
#include "../lv_misc/lv_color.h"
|
||||
#include "../lv_misc/lv_area.h"
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa);
|
||||
|
||||
/**
|
||||
* Fill an area on the display
|
||||
* @param cords_p coordinates of the area to fill
|
||||
* @param mask_p fill only o this mask
|
||||
* @param color fill color
|
||||
* @param opa opacity (ignored, only for compatibility with lv_vfill)
|
||||
*/
|
||||
void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
lv_color_t color, lv_opa_t opa);
|
||||
|
||||
/**
|
||||
* Draw a letter to the display
|
||||
* @param pos_p left-top coordinate of the latter
|
||||
* @param mask_p the letter will be drawn only on this area
|
||||
* @param font_p pointer to font
|
||||
* @param letter a letter to draw
|
||||
* @param color color of letter
|
||||
* @param opa opacity of letter (ignored, only for compatibility with lv_vletter)
|
||||
*/
|
||||
void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
|
||||
const lv_font_t * font_p, uint32_t letter,
|
||||
lv_color_t color, lv_opa_t opa);
|
||||
|
||||
/**
|
||||
* When the letter is ant-aliased it needs to know the background color
|
||||
* @param bg_color the background color of the currently drawn letter
|
||||
*/
|
||||
void lv_rletter_set_background(lv_color_t color);
|
||||
|
||||
|
||||
/**
|
||||
* Draw a color map to the display (image)
|
||||
* @param cords_p coordinates the color map
|
||||
* @param mask_p the map will drawn only on this area
|
||||
* @param map_p pointer to a lv_color_t array
|
||||
* @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap')
|
||||
* @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels
|
||||
* @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it)
|
||||
* @param recolor mix the pixels with this color
|
||||
* @param recolor_opa the intense of recoloring
|
||||
*/
|
||||
void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
|
||||
lv_color_t recolor, lv_opa_t recolor_opa);
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_REAL_DRAW*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRAW_RBASIC_H*/
|
1435
bdk/libs/lvgl/lv_draw/lv_draw_rect.c
Normal file
1435
bdk/libs/lvgl/lv_draw/lv_draw_rect.c
Normal file
File diff suppressed because it is too large
Load diff
48
bdk/libs/lvgl/lv_draw/lv_draw_rect.h
Normal file
48
bdk/libs/lvgl/lv_draw/lv_draw_rect.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* @file lv_draw_rect.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_RECT_H
|
||||
#define LV_DRAW_RECT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Draw a rectangle
|
||||
* @param coords the coordinates of the rectangle
|
||||
* @param mask the rectangle will be drawn only in this mask
|
||||
* @param style pointer to a style
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRAW_RECT_H*/
|
168
bdk/libs/lvgl/lv_draw/lv_draw_triangle.c
Normal file
168
bdk/libs/lvgl/lv_draw/lv_draw_triangle.c
Normal file
|
@ -0,0 +1,168 @@
|
|||
/**
|
||||
* @file lv_draw_triangle.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_triangle.h"
|
||||
#include "../lv_misc/lv_math.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static void point_swap(lv_point_t * p1, lv_point_t * p2);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
#if USE_LV_TRIANGLE != 0
|
||||
/**
|
||||
*
|
||||
* @param points pointer to an array with 3 points
|
||||
* @param mask the triangle will be drawn only in this mask
|
||||
* @param color color of the triangle
|
||||
*/
|
||||
void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color)
|
||||
{
|
||||
lv_point_t tri[3];
|
||||
|
||||
memcpy(tri, points, sizeof(tri));
|
||||
|
||||
/*Sort the vertices according to their y coordinate (0: y max, 1: y mid, 2:y min)*/
|
||||
if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]);
|
||||
if(tri[2].y < tri[1].y) point_swap(&tri[2], &tri[1]);
|
||||
if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]);
|
||||
|
||||
/*Return is the triangle is degenerated*/
|
||||
if(tri[0].x == tri[1].x && tri[0].y == tri[1].y) return;
|
||||
if(tri[1].x == tri[2].x && tri[1].y == tri[2].y) return;
|
||||
if(tri[0].x == tri[2].x && tri[0].y == tri[2].y) return;
|
||||
|
||||
if(tri[0].x == tri[1].x && tri[1].x == tri[2].x) return;
|
||||
if(tri[0].y == tri[1].y && tri[1].y == tri[2].y) return;
|
||||
|
||||
/*Draw the triangle*/
|
||||
lv_point_t edge1;
|
||||
lv_coord_t dx1 = LV_MATH_ABS(tri[0].x - tri[1].x);
|
||||
lv_coord_t sx1 = tri[0].x < tri[1].x ? 1 : -1;
|
||||
lv_coord_t dy1 = LV_MATH_ABS(tri[0].y - tri[1].y);
|
||||
lv_coord_t sy1 = tri[0].y < tri[1].y ? 1 : -1;
|
||||
lv_coord_t err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
|
||||
lv_coord_t err_tmp1;
|
||||
|
||||
lv_point_t edge2;
|
||||
lv_coord_t dx2 = LV_MATH_ABS(tri[0].x - tri[2].x);
|
||||
lv_coord_t sx2 = tri[0].x < tri[2].x ? 1 : -1;
|
||||
lv_coord_t dy2 = LV_MATH_ABS(tri[0].y - tri[2].y);
|
||||
lv_coord_t sy2 = tri[0].y < tri[2].y ? 1 : -1;
|
||||
lv_coord_t err2 = (dx1 > dy2 ? dx2 : -dy2) / 2;
|
||||
lv_coord_t err_tmp2;
|
||||
|
||||
lv_coord_t y1_tmp;
|
||||
lv_coord_t y2_tmp;
|
||||
|
||||
edge1.x = tri[0].x;
|
||||
edge1.y = tri[0].y;
|
||||
edge2.x = tri[0].x;
|
||||
edge2.y = tri[0].y;
|
||||
lv_area_t act_area;
|
||||
lv_area_t draw_area;
|
||||
|
||||
while(1) {
|
||||
act_area.x1 = edge1.x;
|
||||
act_area.x2 = edge2.x ;
|
||||
act_area.y1 = edge1.y;
|
||||
act_area.y2 = edge2.y ;
|
||||
|
||||
|
||||
draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2);
|
||||
draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2);
|
||||
draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2);
|
||||
draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2);
|
||||
draw_area.x2--; /*Do not draw most right pixel because it will be drawn by the adjacent triangle*/
|
||||
fill_fp(&draw_area, mask, color, LV_OPA_50);
|
||||
|
||||
/*Calc. the next point of edge1*/
|
||||
y1_tmp = edge1.y;
|
||||
do {
|
||||
if(edge1.x == tri[1].x && edge1.y == tri[1].y) {
|
||||
|
||||
dx1 = LV_MATH_ABS(tri[1].x - tri[2].x);
|
||||
sx1 = tri[1].x < tri[2].x ? 1 : -1;
|
||||
dy1 = LV_MATH_ABS(tri[1].y - tri[2].y);
|
||||
sy1 = tri[1].y < tri[2].y ? 1 : -1;
|
||||
err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
|
||||
} else if(edge1.x == tri[2].x && edge1.y == tri[2].y) return;
|
||||
err_tmp1 = err1;
|
||||
if(err_tmp1 > -dx1) {
|
||||
err1 -= dy1;
|
||||
edge1.x += sx1;
|
||||
}
|
||||
if(err_tmp1 < dy1) {
|
||||
err1 += dx1;
|
||||
edge1.y += sy1;
|
||||
}
|
||||
} while(edge1.y == y1_tmp);
|
||||
|
||||
/*Calc. the next point of edge2*/
|
||||
y2_tmp = edge2.y;
|
||||
do {
|
||||
if(edge2.x == tri[2].x && edge2.y == tri[2].y) return;
|
||||
err_tmp2 = err2;
|
||||
if(err_tmp2 > -dx2) {
|
||||
err2 -= dy2;
|
||||
edge2.x += sx2;
|
||||
}
|
||||
if(err_tmp2 < dy2) {
|
||||
err2 += dx2;
|
||||
edge2.y += sy2;
|
||||
}
|
||||
} while(edge2.y == y2_tmp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
||||
#if USE_LV_TRIANGLE != 0
|
||||
/**
|
||||
* Swap two points
|
||||
* p1 pointer to the first point
|
||||
* p2 pointer to the second point
|
||||
*/
|
||||
static void point_swap(lv_point_t * p1, lv_point_t * p2)
|
||||
{
|
||||
lv_point_t tmp;
|
||||
tmp.x = p1->x;
|
||||
tmp.y = p1->y;
|
||||
|
||||
p1->x = p2->x;
|
||||
p1->y = p2->y;
|
||||
|
||||
p2->x = tmp.x;
|
||||
p2->y = tmp.y;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
51
bdk/libs/lvgl/lv_draw/lv_draw_triangle.h
Normal file
51
bdk/libs/lvgl/lv_draw/lv_draw_triangle.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* @file lv_draw_triangle.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_TRIANGLE_H
|
||||
#define LV_DRAW_TRIANGLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/*Experimental use for 3D modeling*/
|
||||
#define USE_LV_TRIANGLE 1
|
||||
|
||||
#if USE_LV_TRIANGLE != 0
|
||||
/**
|
||||
*
|
||||
* @param points pointer to an array with 3 points
|
||||
* @param mask the triangle will be drawn only in this mask
|
||||
* @param color color of the triangle
|
||||
*/
|
||||
void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRAW_TRIANGLE_H*/
|
691
bdk/libs/lvgl/lv_draw/lv_draw_vbasic.c
Normal file
691
bdk/libs/lvgl/lv_draw/lv_draw_vbasic.c
Normal file
|
@ -0,0 +1,691 @@
|
|||
/**
|
||||
* @file lv_vdraw.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lv_draw_vbasic.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../lv_hal/lv_hal_disp.h"
|
||||
#include "../lv_misc/lv_area.h"
|
||||
#include "../lv_misc/lv_font.h"
|
||||
#include "../lv_misc/lv_color.h"
|
||||
#include "../lv_misc/lv_log.h"
|
||||
|
||||
#if LV_VDB_SIZE != 0
|
||||
|
||||
#include <stddef.h>
|
||||
#include "../lv_core/lv_vdb.h"
|
||||
#include "lv_draw.h"
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define VFILL_HW_ACC_SIZE_LIMIT 50 /*Always fill < 50 px with 'sw_color_fill' because of the hw. init overhead*/
|
||||
|
||||
#ifndef LV_ATTRIBUTE_MEM_ALIGN
|
||||
#define LV_ATTRIBUTE_MEM_ALIGN
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void sw_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
|
||||
static void sw_color_fill(lv_area_t * mem_area, lv_color_t * mem, const lv_area_t * fill_area, lv_color_t color, lv_opa_t opa);
|
||||
|
||||
#if LV_COLOR_SCREEN_TRANSP
|
||||
static inline lv_color_t color_mix_2_alpha(lv_color_t bg_color, lv_opa_t bg_opa, lv_color_t fg_color, lv_opa_t fg_opa);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Put a pixel in the Virtual Display Buffer
|
||||
* @param x pixel x coordinate
|
||||
* @param y pixel y coordinate
|
||||
* @param mask_p fill only on this mask (truncated to VDB area)
|
||||
* @param color pixel color
|
||||
* @param opa opacity of the area (0..255)
|
||||
*/
|
||||
void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
if(!vdb_p) {
|
||||
LV_LOG_WARN("Invalid VDB pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Pixel out of the mask*/
|
||||
if(x < mask_p->x1 || x > mask_p->x2 ||
|
||||
y < mask_p->y1 || y > mask_p->y2) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t vdb_width = lv_area_get_width(&vdb_p->area);
|
||||
|
||||
/*Make the coordinates relative to VDB*/
|
||||
x -= vdb_p->area.x1;
|
||||
y -= vdb_p->area.y1;
|
||||
|
||||
lv_disp_t * disp = lv_disp_get_active();
|
||||
if(disp->driver.vdb_wr) {
|
||||
disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, x, y, color, opa);
|
||||
} else {
|
||||
lv_color_t * vdb_px_p = vdb_p->buf + y * vdb_width + x;
|
||||
#if LV_COLOR_SCREEN_TRANSP == 0
|
||||
if(opa == LV_OPA_COVER) {
|
||||
*vdb_px_p = color;
|
||||
} else {
|
||||
*vdb_px_p = lv_color_mix(color, *vdb_px_p, opa);
|
||||
}
|
||||
#else
|
||||
*vdb_px_p = color_mix_2_alpha(*vdb_px_p, (*vdb_px_p).alpha, color, opa);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fill an area in the Virtual Display Buffer
|
||||
* @param cords_p coordinates of the area to fill
|
||||
* @param mask_p fill only o this mask (truncated to VDB area)
|
||||
* @param color fill color
|
||||
* @param opa opacity of the area (0..255)
|
||||
*/
|
||||
void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
lv_area_t res_a;
|
||||
bool union_ok;
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
if(!vdb_p) {
|
||||
LV_LOG_WARN("Invalid VDB pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Get the union of cord and mask*/
|
||||
/* The mask is already truncated to the vdb size
|
||||
* in 'lv_refr_area_with_vdb' function */
|
||||
union_ok = lv_area_intersect(&res_a, cords_p, mask_p);
|
||||
|
||||
/*If there are common part of the three area then draw to the vdb*/
|
||||
if(union_ok == false) return;
|
||||
|
||||
lv_area_t vdb_rel_a; /*Stores relative coordinates on vdb*/
|
||||
vdb_rel_a.x1 = res_a.x1 - vdb_p->area.x1;
|
||||
vdb_rel_a.y1 = res_a.y1 - vdb_p->area.y1;
|
||||
vdb_rel_a.x2 = res_a.x2 - vdb_p->area.x1;
|
||||
vdb_rel_a.y2 = res_a.y2 - vdb_p->area.y1;
|
||||
|
||||
lv_color_t * vdb_buf_tmp = vdb_p->buf;
|
||||
uint32_t vdb_width = lv_area_get_width(&vdb_p->area);
|
||||
/*Move the vdb_tmp to the first row*/
|
||||
vdb_buf_tmp += vdb_width * vdb_rel_a.y1;
|
||||
|
||||
|
||||
#if USE_LV_GPU
|
||||
static LV_ATTRIBUTE_MEM_ALIGN lv_color_t color_array_tmp[LV_HOR_RES]; /*Used by 'lv_disp_mem_blend'*/
|
||||
static lv_coord_t last_width = -1;
|
||||
|
||||
lv_coord_t w = lv_area_get_width(&vdb_rel_a);
|
||||
/*Don't use hw. acc. for every small fill (because of the init overhead)*/
|
||||
if(w < VFILL_HW_ACC_SIZE_LIMIT) {
|
||||
sw_color_fill(&vdb_p->area, vdb_p->buf, &vdb_rel_a, color, opa);
|
||||
}
|
||||
/*Not opaque fill*/
|
||||
else if(opa == LV_OPA_COVER) {
|
||||
/*Use hw fill if present*/
|
||||
if(lv_disp_is_mem_fill_supported()) {
|
||||
lv_coord_t row;
|
||||
for(row = vdb_rel_a.y1; row <= vdb_rel_a.y2; row++) {
|
||||
lv_disp_mem_fill(&vdb_buf_tmp[vdb_rel_a.x1], w, color);
|
||||
vdb_buf_tmp += vdb_width;
|
||||
}
|
||||
}
|
||||
/*Use hw blend if present and the area is not too small*/
|
||||
else if(lv_area_get_height(&vdb_rel_a) > VFILL_HW_ACC_SIZE_LIMIT &&
|
||||
lv_disp_is_mem_blend_supported()) {
|
||||
/*Fill a one line sized buffer with a color and blend this later*/
|
||||
if(color_array_tmp[0].full != color.full || last_width != w) {
|
||||
uint16_t i;
|
||||
for(i = 0; i < w; i++) {
|
||||
color_array_tmp[i].full = color.full;
|
||||
}
|
||||
last_width = w;
|
||||
}
|
||||
|
||||
/*Blend the filled line to every line VDB line-by-line*/
|
||||
lv_coord_t row;
|
||||
for(row = vdb_rel_a.y1; row <= vdb_rel_a.y2; row++) {
|
||||
lv_disp_mem_blend(&vdb_buf_tmp[vdb_rel_a.x1], color_array_tmp, w, opa);
|
||||
vdb_buf_tmp += vdb_width;
|
||||
}
|
||||
|
||||
}
|
||||
/*Else use sw fill if no better option*/
|
||||
else {
|
||||
sw_color_fill(&vdb_p->area, vdb_p->buf, &vdb_rel_a, color, opa);
|
||||
}
|
||||
|
||||
}
|
||||
/*Fill with opacity*/
|
||||
else {
|
||||
/*Use hw blend if present*/
|
||||
if(lv_disp_is_mem_blend_supported()) {
|
||||
if(color_array_tmp[0].full != color.full || last_width != w) {
|
||||
uint16_t i;
|
||||
for(i = 0; i < w; i++) {
|
||||
color_array_tmp[i].full = color.full;
|
||||
}
|
||||
|
||||
last_width = w;
|
||||
}
|
||||
lv_coord_t row;
|
||||
for(row = vdb_rel_a.y1; row <= vdb_rel_a.y2; row++) {
|
||||
lv_disp_mem_blend(&vdb_buf_tmp[vdb_rel_a.x1], color_array_tmp, w, opa);
|
||||
vdb_buf_tmp += vdb_width;
|
||||
}
|
||||
|
||||
}
|
||||
/*Use sw fill with opa if no better option*/
|
||||
else {
|
||||
sw_color_fill(&vdb_p->area, vdb_p->buf, &vdb_rel_a, color, opa);
|
||||
}
|
||||
|
||||
}
|
||||
#else
|
||||
sw_color_fill(&vdb_p->area, vdb_p->buf, &vdb_rel_a, color, opa);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a letter in the Virtual Display Buffer
|
||||
* @param pos_p left-top coordinate of the latter
|
||||
* @param mask_p the letter will be drawn only on this area (truncated to VDB area)
|
||||
* @param font_p pointer to font
|
||||
* @param letter a letter to draw
|
||||
* @param color color of letter
|
||||
* @param opa opacity of letter (0..255)
|
||||
*/
|
||||
void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
|
||||
const lv_font_t * font_p, uint32_t letter,
|
||||
lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
const uint8_t bpp1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
|
||||
const uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
|
||||
const uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
|
||||
68, 85, 102, 119,
|
||||
136, 153, 170, 187,
|
||||
204, 221, 238, 255
|
||||
};
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
if(font_p == NULL) {
|
||||
LV_LOG_WARN("Font: character's bitmap not found");
|
||||
return;
|
||||
}
|
||||
|
||||
lv_coord_t pos_x = pos_p->x;
|
||||
lv_coord_t pos_y = pos_p->y;
|
||||
uint8_t letter_w = lv_font_get_real_width(font_p, letter);
|
||||
uint8_t letter_h = lv_font_get_height(font_p);
|
||||
uint8_t bpp = lv_font_get_bpp(font_p, letter); /*Bit per pixel (1,2, 4 or 8)*/
|
||||
const uint8_t * bpp_opa_table;
|
||||
uint8_t mask_init;
|
||||
uint8_t mask;
|
||||
|
||||
if(lv_font_is_monospace(font_p, letter)) {
|
||||
pos_x += (lv_font_get_width(font_p, letter) - letter_w) / 2;
|
||||
}
|
||||
|
||||
|
||||
switch(bpp) {
|
||||
case 1:
|
||||
bpp_opa_table = bpp1_opa_table;
|
||||
mask_init = 0x80;
|
||||
break;
|
||||
case 2:
|
||||
bpp_opa_table = bpp2_opa_table;
|
||||
mask_init = 0xC0;
|
||||
break;
|
||||
case 4:
|
||||
bpp_opa_table = bpp4_opa_table;
|
||||
mask_init = 0xF0;
|
||||
break;
|
||||
case 8:
|
||||
bpp_opa_table = NULL;
|
||||
mask_init = 0xFF;
|
||||
break; /*No opa table, pixel value will be used directly*/
|
||||
default:
|
||||
return; /*Invalid bpp. Can't render the letter*/
|
||||
}
|
||||
|
||||
const uint8_t * map_p = lv_font_get_bitmap(font_p, letter);
|
||||
|
||||
if(map_p == NULL) return;
|
||||
|
||||
/*If the letter is completely out of mask don't draw it */
|
||||
if(pos_x + letter_w < mask_p->x1 || pos_x > mask_p->x2 ||
|
||||
pos_y + letter_h < mask_p->y1 || pos_y > mask_p->y2) return;
|
||||
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
if(!vdb_p) {
|
||||
LV_LOG_WARN("Invalid VDB pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
lv_coord_t vdb_width = lv_area_get_width(&vdb_p->area);
|
||||
lv_color_t * vdb_buf_tmp = vdb_p->buf;
|
||||
lv_coord_t col, row;
|
||||
uint8_t col_bit;
|
||||
uint8_t col_byte_cnt;
|
||||
uint8_t width_byte_scr = letter_w >> 3; /*Width in bytes (on the screen finally) (e.g. w = 11 -> 2 bytes wide)*/
|
||||
if(letter_w & 0x7) width_byte_scr++;
|
||||
uint8_t width_byte_bpp = (letter_w * bpp) >> 3; /*Letter width in byte. Real width in the font*/
|
||||
if((letter_w * bpp) & 0x7) width_byte_bpp++;
|
||||
|
||||
/* Calculate the col/row start/end on the map*/
|
||||
lv_coord_t col_start = pos_x >= mask_p->x1 ? 0 : mask_p->x1 - pos_x;
|
||||
lv_coord_t col_end = pos_x + letter_w <= mask_p->x2 ? letter_w : mask_p->x2 - pos_x + 1;
|
||||
lv_coord_t row_start = pos_y >= mask_p->y1 ? 0 : mask_p->y1 - pos_y;
|
||||
lv_coord_t row_end = pos_y + letter_h <= mask_p->y2 ? letter_h : mask_p->y2 - pos_y + 1;
|
||||
|
||||
/*Set a pointer on VDB to the first pixel of the letter*/
|
||||
vdb_buf_tmp += ((pos_y - vdb_p->area.y1) * vdb_width)
|
||||
+ pos_x - vdb_p->area.x1;
|
||||
|
||||
/*If the letter is partially out of mask the move there on VDB*/
|
||||
vdb_buf_tmp += (row_start * vdb_width) + col_start;
|
||||
|
||||
/*Move on the map too*/
|
||||
map_p += (row_start * width_byte_bpp) + ((col_start * bpp) >> 3);
|
||||
|
||||
lv_disp_t * disp = lv_disp_get_active();
|
||||
|
||||
uint8_t letter_px;
|
||||
lv_opa_t px_opa;
|
||||
for(row = row_start; row < row_end; row ++) {
|
||||
col_byte_cnt = 0;
|
||||
col_bit = (col_start * bpp) % 8;
|
||||
mask = mask_init >> col_bit;
|
||||
for(col = col_start; col < col_end; col ++) {
|
||||
letter_px = (*map_p & mask) >> (8 - col_bit - bpp);
|
||||
if(letter_px != 0) {
|
||||
if(opa == LV_OPA_COVER) {
|
||||
px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px];
|
||||
} else {
|
||||
px_opa = bpp == 8 ?
|
||||
(uint16_t)((uint16_t)letter_px * opa) >> 8 :
|
||||
(uint16_t)((uint16_t)bpp_opa_table[letter_px] * opa) >> 8;
|
||||
}
|
||||
|
||||
if(disp->driver.vdb_wr) {
|
||||
disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width,
|
||||
(col + pos_x) - vdb_p->area.x1, (row + pos_y) - vdb_p->area.y1,
|
||||
color, px_opa);
|
||||
} else {
|
||||
#if LV_COLOR_SCREEN_TRANSP == 0
|
||||
*vdb_buf_tmp = lv_color_mix(color, *vdb_buf_tmp, px_opa);
|
||||
#else
|
||||
*vdb_buf_tmp = color_mix_2_alpha(*vdb_buf_tmp, (*vdb_buf_tmp).alpha, color, px_opa);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
vdb_buf_tmp++;
|
||||
|
||||
if(col_bit < 8 - bpp) {
|
||||
col_bit += bpp;
|
||||
mask = mask >> bpp;
|
||||
} else {
|
||||
col_bit = 0;
|
||||
col_byte_cnt ++;
|
||||
mask = mask_init;
|
||||
map_p ++;
|
||||
}
|
||||
}
|
||||
|
||||
map_p += (width_byte_bpp) - col_byte_cnt;
|
||||
vdb_buf_tmp += vdb_width - (col_end - col_start); /*Next row in VDB*/
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a color map to the display (image)
|
||||
* @param cords_p coordinates the color map
|
||||
* @param mask_p the map will drawn only on this area (truncated to VDB area)
|
||||
* @param map_p pointer to a lv_color_t array
|
||||
* @param opa opacity of the map
|
||||
* @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels
|
||||
* @param alpha_byte true: extra alpha byte is inserted for every pixel
|
||||
* @param recolor mix the pixels with this color
|
||||
* @param recolor_opa the intense of recoloring
|
||||
*/
|
||||
void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
|
||||
lv_color_t recolor, lv_opa_t recolor_opa)
|
||||
{
|
||||
|
||||
if(opa < LV_OPA_MIN) return;
|
||||
if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
|
||||
|
||||
lv_area_t masked_a;
|
||||
bool union_ok;
|
||||
lv_vdb_t * vdb_p = lv_vdb_get();
|
||||
if(!vdb_p) {
|
||||
LV_LOG_WARN("Invalid VDB pointer");
|
||||
return;
|
||||
}
|
||||
|
||||
/*Get the union of map size and mask*/
|
||||
/* The mask is already truncated to the vdb size
|
||||
* in 'lv_refr_area_with_vdb' function */
|
||||
union_ok = lv_area_intersect(&masked_a, cords_p, mask_p);
|
||||
|
||||
/*If there are common part of the three area then draw to the vdb*/
|
||||
if(union_ok == false) return;
|
||||
|
||||
/*The pixel size in byte is different if an alpha byte is added too*/
|
||||
uint8_t px_size_byte = alpha_byte ? LV_IMG_PX_SIZE_ALPHA_BYTE : sizeof(lv_color_t);
|
||||
|
||||
/*If the map starts OUT of the masked area then calc. the first pixel*/
|
||||
lv_coord_t map_width = lv_area_get_width(cords_p);
|
||||
if(cords_p->y1 < masked_a.y1) {
|
||||
map_p += (uint32_t) map_width * ((masked_a.y1 - cords_p->y1)) * px_size_byte;
|
||||
}
|
||||
if(cords_p->x1 < masked_a.x1) {
|
||||
map_p += (masked_a.x1 - cords_p->x1) * px_size_byte;
|
||||
}
|
||||
|
||||
/*Stores coordinates relative to the current VDB*/
|
||||
masked_a.x1 = masked_a.x1 - vdb_p->area.x1;
|
||||
masked_a.y1 = masked_a.y1 - vdb_p->area.y1;
|
||||
masked_a.x2 = masked_a.x2 - vdb_p->area.x1;
|
||||
masked_a.y2 = masked_a.y2 - vdb_p->area.y1;
|
||||
|
||||
lv_coord_t vdb_width = lv_area_get_width(&vdb_p->area);
|
||||
lv_color_t * vdb_buf_tmp = vdb_p->buf;
|
||||
vdb_buf_tmp += (uint32_t) vdb_width * masked_a.y1; /*Move to the first row*/
|
||||
vdb_buf_tmp += (uint32_t) masked_a.x1; /*Move to the first col*/
|
||||
|
||||
lv_coord_t row;
|
||||
lv_coord_t map_useful_w = lv_area_get_width(&masked_a);
|
||||
|
||||
lv_disp_t * disp = lv_disp_get_active();
|
||||
|
||||
/*The simplest case just copy the pixels into the VDB*/
|
||||
if(chroma_key == false && alpha_byte == false && opa == LV_OPA_COVER && recolor_opa == LV_OPA_TRANSP) {
|
||||
|
||||
/*Use the custom VDB write function is exists*/
|
||||
if(disp->driver.vdb_wr) {
|
||||
lv_coord_t col;
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
for(col = 0; col < map_useful_w; col++) {
|
||||
lv_color_t px_color = *((lv_color_t *)&map_p[(uint32_t)col * px_size_byte]);
|
||||
disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, col + masked_a.x1, row, px_color, opa);
|
||||
}
|
||||
map_p += map_width * px_size_byte; /*Next row on the map*/
|
||||
}
|
||||
}
|
||||
/*Normal native VDB*/
|
||||
else {
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
#if USE_LV_GPU
|
||||
if(lv_disp_is_mem_blend_supported() == false) {
|
||||
sw_mem_blend(vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa);
|
||||
} else {
|
||||
lv_disp_mem_blend(vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa);
|
||||
}
|
||||
#else
|
||||
sw_mem_blend(vdb_buf_tmp, (lv_color_t *)map_p, map_useful_w, opa);
|
||||
#endif
|
||||
map_p += map_width * px_size_byte; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*In the other cases every pixel need to be checked one-by-one*/
|
||||
else {
|
||||
lv_color_t chroma_key_color = LV_COLOR_TRANSP;
|
||||
lv_coord_t col;
|
||||
lv_color_t last_img_px = LV_COLOR_BLACK;
|
||||
lv_color_t recolored_px = lv_color_mix(recolor, last_img_px, recolor_opa);
|
||||
for(row = masked_a.y1; row <= masked_a.y2; row++) {
|
||||
for(col = 0; col < map_useful_w; col++) {
|
||||
lv_opa_t opa_result = opa;
|
||||
uint8_t * px_color_p = (uint8_t *) &map_p[(uint32_t)col * px_size_byte];
|
||||
lv_color_t px_color;
|
||||
|
||||
/*Calculate with the pixel level alpha*/
|
||||
if(alpha_byte) {
|
||||
#if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
|
||||
px_color.full = px_color_p[0];
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
/*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
|
||||
px_color.full = px_color_p[0] + (px_color_p[1] << 8);
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
px_color = *((lv_color_t *)px_color_p);
|
||||
#endif
|
||||
lv_opa_t px_opa = *(px_color_p + LV_IMG_PX_SIZE_ALPHA_BYTE - 1);
|
||||
if(px_opa == LV_OPA_TRANSP) continue;
|
||||
else if(px_opa != LV_OPA_COVER) opa_result = (uint32_t)((uint32_t)px_opa * opa_result) >> 8;
|
||||
} else {
|
||||
px_color = *((lv_color_t *)px_color_p);
|
||||
}
|
||||
|
||||
/*Handle chroma key*/
|
||||
if(chroma_key && px_color.full == chroma_key_color.full) continue;
|
||||
|
||||
/*Re-color the pixel if required*/
|
||||
if(recolor_opa != LV_OPA_TRANSP) {
|
||||
if(last_img_px.full != px_color.full) { /*Minor acceleration: calculate only for new colors (save the last)*/
|
||||
last_img_px = px_color;
|
||||
recolored_px = lv_color_mix(recolor, last_img_px, recolor_opa);
|
||||
}
|
||||
/*Handle custom VDB write is present*/
|
||||
if(disp->driver.vdb_wr) {
|
||||
disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, col + masked_a.x1, row, recolored_px, opa_result);
|
||||
}
|
||||
/*Normal native VDB write*/
|
||||
else {
|
||||
if(opa_result == LV_OPA_COVER) vdb_buf_tmp[col].full = recolored_px.full;
|
||||
else vdb_buf_tmp[col] = lv_color_mix(recolored_px, vdb_buf_tmp[col], opa_result);
|
||||
}
|
||||
} else {
|
||||
/*Handle custom VDB write is present*/
|
||||
if(disp->driver.vdb_wr) {
|
||||
disp->driver.vdb_wr((uint8_t *)vdb_p->buf, vdb_width, col + masked_a.x1, row, px_color, opa_result);
|
||||
}
|
||||
/*Normal native VDB write*/
|
||||
else {
|
||||
if(opa_result == LV_OPA_COVER) vdb_buf_tmp[col] = px_color;
|
||||
else {
|
||||
#if LV_COLOR_SCREEN_TRANSP == 0
|
||||
vdb_buf_tmp[col] = lv_color_mix(px_color, vdb_buf_tmp[col], opa_result);
|
||||
#else
|
||||
vdb_buf_tmp[col] = color_mix_2_alpha(vdb_buf_tmp[col], vdb_buf_tmp[col].alpha, px_color, opa_result);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map_p += map_width * px_size_byte; /*Next row on the map*/
|
||||
vdb_buf_tmp += vdb_width; /*Next row on the VDB*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Blend pixels to destination memory using opacity
|
||||
* @param dest a memory address. Copy 'src' here.
|
||||
* @param src pointer to pixel map. Copy it to 'dest'.
|
||||
* @param length number of pixels in 'src'
|
||||
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
|
||||
*/
|
||||
static void sw_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
|
||||
{
|
||||
if(opa == LV_OPA_COVER) {
|
||||
memcpy(dest, src, length * sizeof(lv_color_t));
|
||||
} else {
|
||||
uint32_t col;
|
||||
for(col = 0; col < length; col++) {
|
||||
dest[col] = lv_color_mix(src[col], dest[col], opa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mem_area coordinates of 'mem' memory area
|
||||
* @param mem a memory address. Considered to a rectangular window according to 'mem_area'
|
||||
* @param fill_area coordinates of an area to fill. Relative to 'mem_area'.
|
||||
* @param color fill color
|
||||
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
|
||||
*/
|
||||
static void sw_color_fill(lv_area_t * mem_area, lv_color_t * mem, const lv_area_t * fill_area, lv_color_t color, lv_opa_t opa)
|
||||
{
|
||||
/*Set all row in vdb to the given color*/
|
||||
lv_coord_t row;
|
||||
lv_coord_t col;
|
||||
lv_coord_t mem_width = lv_area_get_width(mem_area);
|
||||
|
||||
lv_disp_t * disp = lv_disp_get_active();
|
||||
if(disp->driver.vdb_wr) {
|
||||
for(col = fill_area->x1; col <= fill_area->x2; col++) {
|
||||
for(row = fill_area->y1; row <= fill_area->y2; row++) {
|
||||
disp->driver.vdb_wr((uint8_t *)mem, mem_width, col, row, color, opa);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mem += fill_area->y1 * mem_width; /*Go to the first row*/
|
||||
|
||||
/*Run simpler function without opacity*/
|
||||
if(opa == LV_OPA_COVER) {
|
||||
|
||||
/*Fill the first row with 'color'*/
|
||||
for(col = fill_area->x1; col <= fill_area->x2; col++) {
|
||||
mem[col] = color;
|
||||
}
|
||||
|
||||
/*Copy the first row to all other rows*/
|
||||
lv_color_t * mem_first = &mem[fill_area->x1];
|
||||
lv_coord_t copy_size = (fill_area->x2 - fill_area->x1 + 1) * sizeof(lv_color_t);
|
||||
mem += mem_width;
|
||||
|
||||
for(row = fill_area->y1 + 1; row <= fill_area->y2; row++) {
|
||||
memcpy(&mem[fill_area->x1], mem_first, copy_size);
|
||||
mem += mem_width;
|
||||
}
|
||||
}
|
||||
/*Calculate with alpha too*/
|
||||
else {
|
||||
|
||||
#if LV_COLOR_SCREEN_TRANSP == 0
|
||||
lv_color_t bg_tmp = LV_COLOR_BLACK;
|
||||
lv_color_t opa_tmp = lv_color_mix(color, bg_tmp, opa);
|
||||
#endif
|
||||
for(row = fill_area->y1; row <= fill_area->y2; row++) {
|
||||
for(col = fill_area->x1; col <= fill_area->x2; col++) {
|
||||
#if LV_COLOR_SCREEN_TRANSP == 0
|
||||
/*If the bg color changed recalculate the result color*/
|
||||
if(mem[col].full != bg_tmp.full) {
|
||||
bg_tmp = mem[col];
|
||||
opa_tmp = lv_color_mix(color, bg_tmp, opa);
|
||||
}
|
||||
|
||||
mem[col] = opa_tmp;
|
||||
|
||||
#else
|
||||
mem[col] = color_mix_2_alpha(mem[col], mem[col].alpha, color, opa);
|
||||
#endif
|
||||
}
|
||||
mem += mem_width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if LV_COLOR_SCREEN_TRANSP
|
||||
|
||||
/**
|
||||
* Mix two colors. Both color can have alpha value. It requires ARGB888 colors.
|
||||
* @param bg_color background color
|
||||
* @param bg_opa alpha of the background color
|
||||
* @param fg_color foreground color
|
||||
* @param fg_opa alpha of the foreground color
|
||||
* @return the mixed color. the alpha channel (color.alpha) contains the result alpha
|
||||
*/
|
||||
static inline lv_color_t color_mix_2_alpha(lv_color_t bg_color, lv_opa_t bg_opa, lv_color_t fg_color, lv_opa_t fg_opa)
|
||||
{
|
||||
/* Pick the foreground if it's fully opaque or the Background is fully transparent*/
|
||||
if(fg_opa == LV_OPA_COVER && bg_opa <= LV_OPA_MIN) {
|
||||
fg_color.alpha = fg_opa;
|
||||
return fg_color;
|
||||
}
|
||||
/*Transparent foreground: use the Background*/
|
||||
else if(fg_opa <= LV_OPA_MIN) {
|
||||
return bg_color;
|
||||
}
|
||||
/*Opaque background: use simple mix*/
|
||||
else if(bg_opa >= LV_OPA_MAX) {
|
||||
return lv_color_mix(fg_color, bg_color, fg_opa);
|
||||
}
|
||||
/*Both colors have alpha. Expensive calculation need to be applied*/
|
||||
else {
|
||||
/*Save the parameters and the result. If they will be asked again don't compute again*/
|
||||
static lv_opa_t fg_opa_save = 0;
|
||||
static lv_opa_t bg_opa_save = 0;
|
||||
static lv_color_t c = {{0}};
|
||||
|
||||
if(fg_opa != fg_opa_save || bg_opa != bg_opa_save) {
|
||||
fg_opa_save = fg_opa;
|
||||
bg_opa_save = bg_opa;
|
||||
/*Info: https://en.wikipedia.org/wiki/Alpha_compositing#Analytical_derivation_of_the_over_operator*/
|
||||
lv_opa_t alpha_res = 255 - ((uint16_t)((uint16_t)(255 - fg_opa) * (255 - bg_opa)) >> 8);
|
||||
if(alpha_res == 0) {
|
||||
while(1);
|
||||
}
|
||||
lv_opa_t ratio = (uint16_t)((uint16_t) fg_opa * 255) / alpha_res;
|
||||
c = lv_color_mix(fg_color, bg_color, ratio);
|
||||
c.alpha = alpha_res;
|
||||
}
|
||||
return c;
|
||||
|
||||
}
|
||||
}
|
||||
#endif /*LV_COLOR_SCREEN_TRANSP*/
|
||||
|
||||
#endif
|
89
bdk/libs/lvgl/lv_draw/lv_draw_vbasic.h
Normal file
89
bdk/libs/lvgl/lv_draw/lv_draw_vbasic.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* @file lv_draw_vbasic.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_DRAW_VBASIC_H
|
||||
#define LV_DRAW_VBASIC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if LV_VDB_SIZE != 0
|
||||
|
||||
#include "../lv_misc/lv_color.h"
|
||||
#include "../lv_misc/lv_area.h"
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa);
|
||||
/**
|
||||
* Fill an area in the Virtual Display Buffer
|
||||
* @param cords_p coordinates of the area to fill
|
||||
* @param mask_p fill only o this mask
|
||||
* @param color fill color
|
||||
* @param opa opacity of the area (0..255)
|
||||
*/
|
||||
void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
lv_color_t color, lv_opa_t opa);
|
||||
|
||||
/**
|
||||
* Draw a letter in the Virtual Display Buffer
|
||||
* @param pos_p left-top coordinate of the latter
|
||||
* @param mask_p the letter will be drawn only on this area
|
||||
* @param font_p pointer to font
|
||||
* @param letter a letter to draw
|
||||
* @param color color of letter
|
||||
* @param opa opacity of letter (0..255)
|
||||
*/
|
||||
void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p,
|
||||
const lv_font_t * font_p, uint32_t letter,
|
||||
lv_color_t color, lv_opa_t opa);
|
||||
|
||||
/**
|
||||
* Draw a color map to the display (image)
|
||||
* @param cords_p coordinates the color map
|
||||
* @param mask_p the map will drawn only on this area (truncated to VDB area)
|
||||
* @param map_p pointer to a lv_color_t array
|
||||
* @param opa opacity of the map
|
||||
* @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels
|
||||
* @param alpha_byte true: extra alpha byte is inserted for every pixel
|
||||
* @param recolor mix the pixels with this color
|
||||
* @param recolor_opa the intense of recoloring
|
||||
*/
|
||||
void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p,
|
||||
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
|
||||
lv_color_t recolor, lv_opa_t recolor_opa);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_VDB_SIZE != 0*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_DRAW_RBASIC_H*/
|
58
bdk/libs/lvgl/lv_fonts/hekate_symbol_120.c
Normal file
58
bdk/libs/lvgl/lv_fonts/hekate_symbol_120.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
#include <memory_map.h>
|
||||
|
||||
#if USE_HEKATE_SYMBOL_120 != 0 /*Can be enabled in lv_conf.h*/
|
||||
|
||||
/***********************************************************************************
|
||||
* hekate-symbols-huge.ttf 120 px Font in U+f002 () .. U+f007 () range with all bpp
|
||||
* Sparse font with only these characters:
|
||||
***********************************************************************************/
|
||||
|
||||
/*Store the glyph descriptions*/
|
||||
static const lv_font_glyph_dsc_t hekate_symbol_120_glyph_dsc[] =
|
||||
{
|
||||
#if USE_HEKATE_SYMBOL_120 == 8
|
||||
{.w_px = 103, .glyph_index = 0}, /*Unicode: U+f002 ()*/
|
||||
{.w_px = 103, .glyph_index = 12360}, /*Unicode: U+f003 ()*/
|
||||
{.w_px = 103, .glyph_index = 24720}, /*Unicode: U+f005 ()*/
|
||||
{.w_px = 103, .glyph_index = 37080}, /*Unicode: U+f007 ()*/
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
lv_font_t hekate_symbol_120 =
|
||||
{
|
||||
.unicode_first = LV_SYMBOL_GLYPH_FIRST, /*First Unicode letter in this font*/
|
||||
.unicode_last = LV_SYMBOL_GLYPH_LAST, /*Last Unicode letter in this font*/
|
||||
.h_px = 120, /*Font height in pixels*/
|
||||
.glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x36E00), /*Bitmap of glyphs*/
|
||||
.glyph_dsc = hekate_symbol_120_glyph_dsc, /*Description of glyphs*/
|
||||
.glyph_cnt = 4, /*Number of glyphs in the font*/
|
||||
.unicode_list = NULL, /*List of unicode characters*/
|
||||
.get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/
|
||||
.get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/
|
||||
#if USE_HEKATE_SYMBOL_120 == 8
|
||||
.bpp = 8, /*Bit per pixel*/
|
||||
#endif
|
||||
.monospace = 0, /*Fix width (0: if not used)*/
|
||||
.next_page = NULL, /*Pointer to a font extension*/
|
||||
};
|
||||
|
||||
#endif /*USE_HEKATE_SYMBOL_100*/
|
159
bdk/libs/lvgl/lv_fonts/hekate_symbol_20.c
Normal file
159
bdk/libs/lvgl/lv_fonts/hekate_symbol_20.c
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
#include <memory_map.h>
|
||||
|
||||
#if USE_HEKATE_SYMBOL_20 != 0 /*Can be enabled in lv_conf.h*/
|
||||
|
||||
/***********************************************************************************
|
||||
* hekate-symbols.ttf 20 px Font in U+f000 () .. U+f2ee () range with all bpp
|
||||
* Sparse font with only these characters:
|
||||
***********************************************************************************/
|
||||
|
||||
/*Store the glyph descriptions*/
|
||||
static const lv_font_glyph_dsc_t hekate_symbol_20_glyph_dsc[] =
|
||||
{
|
||||
#if USE_HEKATE_SYMBOL_20 == 4
|
||||
{.w_px = 5, .glyph_index = 0}, /*Unicode: U+f001 ()*/
|
||||
{.w_px = 16, .glyph_index = 60}, /*Unicode: U+f008 ()*/
|
||||
{.w_px = 20, .glyph_index = 220}, /*Unicode: U+f00b ()*/
|
||||
{.w_px = 22, .glyph_index = 420}, /*Unicode: U+f00c ()*/
|
||||
{.w_px = 16, .glyph_index = 640}, /*Unicode: U+f00d ()*/
|
||||
{.w_px = 18, .glyph_index = 800}, /*Unicode: U+f011 ()*/
|
||||
{.w_px = 18, .glyph_index = 980}, /*Unicode: U+f013 ()*/
|
||||
{.w_px = 16, .glyph_index = 1160}, /*Unicode: U+f014 ()*/
|
||||
{.w_px = 23, .glyph_index = 1320}, /*Unicode: U+f015 ()*/
|
||||
{.w_px = 18, .glyph_index = 1560}, /*Unicode: U+f019 ()*/
|
||||
{.w_px = 23, .glyph_index = 1740}, /*Unicode: U+f01c ()*/
|
||||
{.w_px = 18, .glyph_index = 1980}, /*Unicode: U+f021 ()*/
|
||||
{.w_px = 18, .glyph_index = 2160}, /*Unicode: U+f026 ()*/
|
||||
{.w_px = 18, .glyph_index = 2340}, /*Unicode: U+f027 ()*/
|
||||
{.w_px = 13, .glyph_index = 2520}, /*Unicode: U+f028 ()*/
|
||||
{.w_px = 13, .glyph_index = 2660}, /*Unicode: U+f03e ()*/
|
||||
{.w_px = 16, .glyph_index = 2800}, /*Unicode: U+f040 ()*/
|
||||
{.w_px = 13, .glyph_index = 2960}, /*Unicode: U+f048 ()*/
|
||||
{.w_px = 13, .glyph_index = 3100}, /*Unicode: U+f04b ()*/
|
||||
{.w_px = 13, .glyph_index = 3240}, /*Unicode: U+f04c ()*/
|
||||
{.w_px = 9, .glyph_index = 3380}, /*Unicode: U+f04d ()*/
|
||||
{.w_px = 23, .glyph_index = 3480}, /*Unicode: U+f051 ()*/
|
||||
{.w_px = 21, .glyph_index = 3720}, /*Unicode: U+f052 ()*/
|
||||
{.w_px = 11, .glyph_index = 3940}, /*Unicode: U+f053 ()*/
|
||||
{.w_px = 11, .glyph_index = 4060}, /*Unicode: U+f054 ()*/
|
||||
{.w_px = 18, .glyph_index = 4180}, /*Unicode: U+f067 ()*/
|
||||
{.w_px = 18, .glyph_index = 4360}, /*Unicode: U+f068 ()*/
|
||||
{.w_px = 20, .glyph_index = 4540}, /*Unicode: U+f071 ()*/
|
||||
{.w_px = 20, .glyph_index = 4740}, /*Unicode: U+f074 ()*/
|
||||
{.w_px = 18, .glyph_index = 4940}, /*Unicode: U+f077 ()*/
|
||||
{.w_px = 18, .glyph_index = 5120}, /*Unicode: U+f078 ()*/
|
||||
{.w_px = 18, .glyph_index = 5300}, /*Unicode: U+f079 ()*/
|
||||
{.w_px = 20, .glyph_index = 5480}, /*Unicode: U+f07b ()*/
|
||||
{.w_px = 18, .glyph_index = 5680}, /*Unicode: U+f093 ()*/
|
||||
{.w_px = 25, .glyph_index = 5860}, /*Unicode: U+f095 ()*/
|
||||
{.w_px = 18, .glyph_index = 6120}, /*Unicode: U+f0c4 ()*/
|
||||
{.w_px = 16, .glyph_index = 6300}, /*Unicode: U+f0c5 ()*/
|
||||
{.w_px = 17, .glyph_index = 6460}, /*Unicode: U+f0c7 ()*/
|
||||
{.w_px = 8, .glyph_index = 6640}, /*Unicode: U+f0e7 ()*/
|
||||
{.w_px = 12, .glyph_index = 6720}, /*Unicode: U+f0f3 ()*/
|
||||
{.w_px = 23, .glyph_index = 6840}, /*Unicode: U+f11c ()*/
|
||||
{.w_px = 18, .glyph_index = 7080}, /*Unicode: U+f124 ()*/
|
||||
{.w_px = 13, .glyph_index = 7260}, /*Unicode: U+f15b ()*/
|
||||
{.w_px = 20, .glyph_index = 7400}, /*Unicode: U+f1eb ()*/
|
||||
{.w_px = 26, .glyph_index = 7600}, /*Unicode: U+f240 ()*/
|
||||
{.w_px = 26, .glyph_index = 7860}, /*Unicode: U+f241 ()*/
|
||||
{.w_px = 26, .glyph_index = 8120}, /*Unicode: U+f242 ()*/
|
||||
{.w_px = 26, .glyph_index = 8380}, /*Unicode: U+f243 ()*/
|
||||
{.w_px = 26, .glyph_index = 8640}, /*Unicode: U+f244 ()*/
|
||||
{.w_px = 20, .glyph_index = 8900}, /*Unicode: U+f293 ()*/
|
||||
|
||||
#elif USE_HEKATE_SYMBOL_20 == 8
|
||||
{.w_px = 5, .glyph_index = 0}, /*Unicode: U+f001 ()*/
|
||||
{.w_px = 16, .glyph_index = 100}, /*Unicode: U+f008 ()*/
|
||||
{.w_px = 20, .glyph_index = 420}, /*Unicode: U+f00b ()*/
|
||||
{.w_px = 22, .glyph_index = 820}, /*Unicode: U+f00c ()*/
|
||||
{.w_px = 16, .glyph_index = 1260}, /*Unicode: U+f00d ()*/
|
||||
{.w_px = 18, .glyph_index = 1580}, /*Unicode: U+f011 ()*/
|
||||
{.w_px = 18, .glyph_index = 1940}, /*Unicode: U+f013 ()*/
|
||||
{.w_px = 16, .glyph_index = 2300}, /*Unicode: U+f014 ()*/
|
||||
{.w_px = 23, .glyph_index = 2620}, /*Unicode: U+f015 ()*/
|
||||
{.w_px = 18, .glyph_index = 3080}, /*Unicode: U+f019 ()*/
|
||||
{.w_px = 23, .glyph_index = 3440}, /*Unicode: U+f01c ()*/
|
||||
{.w_px = 18, .glyph_index = 3900}, /*Unicode: U+f021 ()*/
|
||||
{.w_px = 18, .glyph_index = 4260}, /*Unicode: U+f026 ()*/
|
||||
{.w_px = 18, .glyph_index = 4620}, /*Unicode: U+f027 ()*/
|
||||
{.w_px = 13, .glyph_index = 4980}, /*Unicode: U+f028 ()*/
|
||||
{.w_px = 13, .glyph_index = 5240}, /*Unicode: U+f03e ()*/
|
||||
{.w_px = 16, .glyph_index = 5500}, /*Unicode: U+f040 ()*/
|
||||
{.w_px = 13, .glyph_index = 5820}, /*Unicode: U+f048 ()*/
|
||||
{.w_px = 13, .glyph_index = 6080}, /*Unicode: U+f04b ()*/
|
||||
{.w_px = 13, .glyph_index = 6340}, /*Unicode: U+f04c ()*/
|
||||
{.w_px = 9, .glyph_index = 6600}, /*Unicode: U+f04d ()*/
|
||||
{.w_px = 23, .glyph_index = 6780}, /*Unicode: U+f051 ()*/
|
||||
{.w_px = 21, .glyph_index = 7240}, /*Unicode: U+f052 ()*/
|
||||
{.w_px = 11, .glyph_index = 7660}, /*Unicode: U+f053 ()*/
|
||||
{.w_px = 11, .glyph_index = 7880}, /*Unicode: U+f054 ()*/
|
||||
{.w_px = 18, .glyph_index = 8100}, /*Unicode: U+f067 ()*/
|
||||
{.w_px = 18, .glyph_index = 8460}, /*Unicode: U+f068 ()*/
|
||||
{.w_px = 20, .glyph_index = 8820}, /*Unicode: U+f071 ()*/
|
||||
{.w_px = 20, .glyph_index = 9220}, /*Unicode: U+f074 ()*/
|
||||
{.w_px = 18, .glyph_index = 9620}, /*Unicode: U+f077 ()*/
|
||||
{.w_px = 18, .glyph_index = 9980}, /*Unicode: U+f078 ()*/
|
||||
{.w_px = 18, .glyph_index = 10340}, /*Unicode: U+f079 ()*/
|
||||
{.w_px = 20, .glyph_index = 10700}, /*Unicode: U+f07b ()*/
|
||||
{.w_px = 18, .glyph_index = 11100}, /*Unicode: U+f093 ()*/
|
||||
{.w_px = 25, .glyph_index = 11460}, /*Unicode: U+f095 ()*/
|
||||
{.w_px = 18, .glyph_index = 11960}, /*Unicode: U+f0c4 ()*/
|
||||
{.w_px = 16, .glyph_index = 12320}, /*Unicode: U+f0c5 ()*/
|
||||
{.w_px = 17, .glyph_index = 12640}, /*Unicode: U+f0c7 ()*/
|
||||
{.w_px = 8, .glyph_index = 12980}, /*Unicode: U+f0e7 ()*/
|
||||
{.w_px = 12, .glyph_index = 13140}, /*Unicode: U+f0f3 ()*/
|
||||
{.w_px = 23, .glyph_index = 13380}, /*Unicode: U+f11c ()*/
|
||||
{.w_px = 18, .glyph_index = 13840}, /*Unicode: U+f124 ()*/
|
||||
{.w_px = 13, .glyph_index = 14200}, /*Unicode: U+f15b ()*/
|
||||
{.w_px = 20, .glyph_index = 14460}, /*Unicode: U+f1eb ()*/
|
||||
{.w_px = 26, .glyph_index = 14860}, /*Unicode: U+f240 ()*/
|
||||
{.w_px = 26, .glyph_index = 15380}, /*Unicode: U+f241 ()*/
|
||||
{.w_px = 26, .glyph_index = 15900}, /*Unicode: U+f242 ()*/
|
||||
{.w_px = 26, .glyph_index = 16420}, /*Unicode: U+f243 ()*/
|
||||
{.w_px = 26, .glyph_index = 16940}, /*Unicode: U+f244 ()*/
|
||||
{.w_px = 20, .glyph_index = 17460}, /*Unicode: U+f293 ()*/
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
lv_font_t hekate_symbol_20 =
|
||||
{
|
||||
.unicode_first = LV_SYMBOL_GLYPH_FIRST, /*First Unicode letter in this font*/
|
||||
.unicode_last = LV_SYMBOL_GLYPH_LAST, /*Last Unicode letter in this font*/
|
||||
.h_px = 20, /*Font height in pixels*/
|
||||
//.glyph_bitmap = hekate_symbol_20_glyph_bitmap, /*Bitmap of glyphs*/
|
||||
.glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0xFC00),
|
||||
.glyph_dsc = hekate_symbol_20_glyph_dsc, /*Description of glyphs*/
|
||||
.glyph_cnt = 50, /*Number of glyphs in the font*/
|
||||
.unicode_list = NULL, /*List of unicode characters*/
|
||||
.get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/
|
||||
.get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/
|
||||
#if USE_HEKATE_SYMBOL_20 == 4
|
||||
.bpp = 4, /*Bit per pixel*/
|
||||
#elif USE_HEKATE_SYMBOL_20 == 8
|
||||
.bpp = 8, /*Bit per pixel*/
|
||||
#endif
|
||||
.monospace = 0, /*Fix width (0: if not used)*/
|
||||
.next_page = NULL, /*Pointer to a font extension*/
|
||||
};
|
||||
|
||||
#endif /*USE_HEKATE_SYMBOL_20*/
|
159
bdk/libs/lvgl/lv_fonts/hekate_symbol_30.c
Normal file
159
bdk/libs/lvgl/lv_fonts/hekate_symbol_30.c
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
#include <memory_map.h>
|
||||
|
||||
#if USE_HEKATE_SYMBOL_30 != 0 /*Can be enabled in lv_conf.h*/
|
||||
|
||||
/***********************************************************************************
|
||||
* hekate-symbols.ttf 30 px Font in U+f000 () .. U+f2ee () range with all bpp
|
||||
* Sparse font with only these characters:
|
||||
***********************************************************************************/
|
||||
|
||||
/*Store the glyph descriptions*/
|
||||
static const lv_font_glyph_dsc_t hekate_symbol_30_glyph_dsc[] =
|
||||
{
|
||||
#if USE_HEKATE_SYMBOL_30 == 4
|
||||
{.w_px = 7, .glyph_index = 0}, /*Unicode: U+f001 ()*/
|
||||
{.w_px = 25, .glyph_index = 120}, /*Unicode: U+f008 ()*/
|
||||
{.w_px = 27, .glyph_index = 510}, /*Unicode: U+f00b ()*/
|
||||
{.w_px = 31, .glyph_index = 930}, /*Unicode: U+f00c ()*/
|
||||
{.w_px = 22, .glyph_index = 1410}, /*Unicode: U+f00d ()*/
|
||||
{.w_px = 25, .glyph_index = 1740}, /*Unicode: U+f011 ()*/
|
||||
{.w_px = 25, .glyph_index = 2130}, /*Unicode: U+f013 ()*/
|
||||
{.w_px = 23, .glyph_index = 2520}, /*Unicode: U+f014 ()*/
|
||||
{.w_px = 34, .glyph_index = 2880}, /*Unicode: U+f015 ()*/
|
||||
{.w_px = 25, .glyph_index = 3390}, /*Unicode: U+f019 ()*/
|
||||
{.w_px = 32, .glyph_index = 3780}, /*Unicode: U+f01c ()*/
|
||||
{.w_px = 25, .glyph_index = 4260}, /*Unicode: U+f021 ()*/
|
||||
{.w_px = 25, .glyph_index = 4650}, /*Unicode: U+f026 ()*/
|
||||
{.w_px = 25, .glyph_index = 5040}, /*Unicode: U+f027 ()*/
|
||||
{.w_px = 20, .glyph_index = 5430}, /*Unicode: U+f028 ()*/
|
||||
{.w_px = 20, .glyph_index = 5730}, /*Unicode: U+f03e ()*/
|
||||
{.w_px = 25, .glyph_index = 6030}, /*Unicode: U+f040 ()*/
|
||||
{.w_px = 20, .glyph_index = 6420}, /*Unicode: U+f048 ()*/
|
||||
{.w_px = 20, .glyph_index = 6720}, /*Unicode: U+f04b ()*/
|
||||
{.w_px = 20, .glyph_index = 7020}, /*Unicode: U+f04c ()*/
|
||||
{.w_px = 13, .glyph_index = 7320}, /*Unicode: U+f04d ()*/
|
||||
{.w_px = 32, .glyph_index = 7530}, /*Unicode: U+f051 ()*/
|
||||
{.w_px = 30, .glyph_index = 8010}, /*Unicode: U+f052 ()*/
|
||||
{.w_px = 16, .glyph_index = 8460}, /*Unicode: U+f053 ()*/
|
||||
{.w_px = 16, .glyph_index = 8700}, /*Unicode: U+f054 ()*/
|
||||
{.w_px = 25, .glyph_index = 8940}, /*Unicode: U+f067 ()*/
|
||||
{.w_px = 25, .glyph_index = 9330}, /*Unicode: U+f068 ()*/
|
||||
{.w_px = 27, .glyph_index = 9720}, /*Unicode: U+f071 ()*/
|
||||
{.w_px = 29, .glyph_index = 10140}, /*Unicode: U+f074 ()*/
|
||||
{.w_px = 26, .glyph_index = 10590}, /*Unicode: U+f077 ()*/
|
||||
{.w_px = 26, .glyph_index = 10980}, /*Unicode: U+f078 ()*/
|
||||
{.w_px = 25, .glyph_index = 11370}, /*Unicode: U+f079 ()*/
|
||||
{.w_px = 29, .glyph_index = 11760}, /*Unicode: U+f07b ()*/
|
||||
{.w_px = 25, .glyph_index = 12210}, /*Unicode: U+f093 ()*/
|
||||
{.w_px = 37, .glyph_index = 12600}, /*Unicode: U+f095 ()*/
|
||||
{.w_px = 25, .glyph_index = 13170}, /*Unicode: U+f0c4 ()*/
|
||||
{.w_px = 23, .glyph_index = 13560}, /*Unicode: U+f0c5 ()*/
|
||||
{.w_px = 24, .glyph_index = 13920}, /*Unicode: U+f0c7 ()*/
|
||||
{.w_px = 13, .glyph_index = 14280}, /*Unicode: U+f0e7 ()*/
|
||||
{.w_px = 18, .glyph_index = 14490}, /*Unicode: U+f0f3 ()*/
|
||||
{.w_px = 33, .glyph_index = 14760}, /*Unicode: U+f11c ()*/
|
||||
{.w_px = 25, .glyph_index = 15270}, /*Unicode: U+f124 ()*/
|
||||
{.w_px = 20, .glyph_index = 15660}, /*Unicode: U+f15b ()*/
|
||||
{.w_px = 29, .glyph_index = 15960}, /*Unicode: U+f1eb ()*/
|
||||
{.w_px = 38, .glyph_index = 16410}, /*Unicode: U+f240 ()*/
|
||||
{.w_px = 38, .glyph_index = 16980}, /*Unicode: U+f241 ()*/
|
||||
{.w_px = 38, .glyph_index = 17550}, /*Unicode: U+f242 ()*/
|
||||
{.w_px = 38, .glyph_index = 18120}, /*Unicode: U+f243 ()*/
|
||||
{.w_px = 38, .glyph_index = 18690}, /*Unicode: U+f244 ()*/
|
||||
{.w_px = 29, .glyph_index = 19260}, /*Unicode: U+f293 ()*/
|
||||
|
||||
#elif USE_HEKATE_SYMBOL_30 == 8
|
||||
{.w_px = 7, .glyph_index = 0}, /*Unicode: U+f001 ()*/
|
||||
{.w_px = 25, .glyph_index = 210}, /*Unicode: U+f008 ()*/
|
||||
{.w_px = 27, .glyph_index = 960}, /*Unicode: U+f00b ()*/
|
||||
{.w_px = 31, .glyph_index = 1770}, /*Unicode: U+f00c ()*/
|
||||
{.w_px = 22, .glyph_index = 2700}, /*Unicode: U+f00d ()*/
|
||||
{.w_px = 25, .glyph_index = 3360}, /*Unicode: U+f011 ()*/
|
||||
{.w_px = 25, .glyph_index = 4110}, /*Unicode: U+f013 ()*/
|
||||
{.w_px = 23, .glyph_index = 4860}, /*Unicode: U+f014 ()*/
|
||||
{.w_px = 34, .glyph_index = 5550}, /*Unicode: U+f015 ()*/
|
||||
{.w_px = 25, .glyph_index = 6570}, /*Unicode: U+f019 ()*/
|
||||
{.w_px = 32, .glyph_index = 7320}, /*Unicode: U+f01c ()*/
|
||||
{.w_px = 25, .glyph_index = 8280}, /*Unicode: U+f021 ()*/
|
||||
{.w_px = 25, .glyph_index = 9030}, /*Unicode: U+f026 ()*/
|
||||
{.w_px = 25, .glyph_index = 9780}, /*Unicode: U+f027 ()*/
|
||||
{.w_px = 20, .glyph_index = 10530}, /*Unicode: U+f028 ()*/
|
||||
{.w_px = 20, .glyph_index = 11130}, /*Unicode: U+f03e ()*/
|
||||
{.w_px = 25, .glyph_index = 11730}, /*Unicode: U+f040 ()*/
|
||||
{.w_px = 20, .glyph_index = 12480}, /*Unicode: U+f048 ()*/
|
||||
{.w_px = 20, .glyph_index = 13080}, /*Unicode: U+f04b ()*/
|
||||
{.w_px = 20, .glyph_index = 13680}, /*Unicode: U+f04c ()*/
|
||||
{.w_px = 13, .glyph_index = 14280}, /*Unicode: U+f04d ()*/
|
||||
{.w_px = 32, .glyph_index = 14670}, /*Unicode: U+f051 ()*/
|
||||
{.w_px = 30, .glyph_index = 15630}, /*Unicode: U+f052 ()*/
|
||||
{.w_px = 16, .glyph_index = 16530}, /*Unicode: U+f053 ()*/
|
||||
{.w_px = 16, .glyph_index = 17010}, /*Unicode: U+f054 ()*/
|
||||
{.w_px = 25, .glyph_index = 17490}, /*Unicode: U+f067 ()*/
|
||||
{.w_px = 25, .glyph_index = 18240}, /*Unicode: U+f068 ()*/
|
||||
{.w_px = 27, .glyph_index = 18990}, /*Unicode: U+f071 ()*/
|
||||
{.w_px = 29, .glyph_index = 19800}, /*Unicode: U+f074 ()*/
|
||||
{.w_px = 26, .glyph_index = 20670}, /*Unicode: U+f077 ()*/
|
||||
{.w_px = 26, .glyph_index = 21450}, /*Unicode: U+f078 ()*/
|
||||
{.w_px = 25, .glyph_index = 22230}, /*Unicode: U+f079 ()*/
|
||||
{.w_px = 29, .glyph_index = 22980}, /*Unicode: U+f07b ()*/
|
||||
{.w_px = 25, .glyph_index = 23850}, /*Unicode: U+f093 ()*/
|
||||
{.w_px = 37, .glyph_index = 24600}, /*Unicode: U+f095 ()*/
|
||||
{.w_px = 25, .glyph_index = 25710}, /*Unicode: U+f0c4 ()*/
|
||||
{.w_px = 23, .glyph_index = 26460}, /*Unicode: U+f0c5 ()*/
|
||||
{.w_px = 24, .glyph_index = 27150}, /*Unicode: U+f0c7 ()*/
|
||||
{.w_px = 13, .glyph_index = 27870}, /*Unicode: U+f0e7 ()*/
|
||||
{.w_px = 18, .glyph_index = 28260}, /*Unicode: U+f0f3 ()*/
|
||||
{.w_px = 33, .glyph_index = 28800}, /*Unicode: U+f11c ()*/
|
||||
{.w_px = 25, .glyph_index = 29790}, /*Unicode: U+f124 ()*/
|
||||
{.w_px = 20, .glyph_index = 30540}, /*Unicode: U+f15b ()*/
|
||||
{.w_px = 29, .glyph_index = 31140}, /*Unicode: U+f1eb ()*/
|
||||
{.w_px = 38, .glyph_index = 32010}, /*Unicode: U+f240 ()*/
|
||||
{.w_px = 38, .glyph_index = 33150}, /*Unicode: U+f241 ()*/
|
||||
{.w_px = 38, .glyph_index = 34290}, /*Unicode: U+f242 ()*/
|
||||
{.w_px = 38, .glyph_index = 35430}, /*Unicode: U+f243 ()*/
|
||||
{.w_px = 38, .glyph_index = 36570}, /*Unicode: U+f244 ()*/
|
||||
{.w_px = 29, .glyph_index = 37710}, /*Unicode: U+f293 ()*/
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
lv_font_t hekate_symbol_30 =
|
||||
{
|
||||
.unicode_first = LV_SYMBOL_GLYPH_FIRST, /*First Unicode letter in this font*/
|
||||
.unicode_last = LV_SYMBOL_GLYPH_LAST, /*Last Unicode letter in this font*/
|
||||
.h_px = 30, /*Font height in pixels*/
|
||||
//.glyph_bitmap = hekate_symbol_30_glyph_bitmap, /*Bitmap of glyphs*/
|
||||
.glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x14200),
|
||||
.glyph_dsc = hekate_symbol_30_glyph_dsc, /*Description of glyphs*/
|
||||
.glyph_cnt = 50, /*Number of glyphs in the font*/
|
||||
.unicode_list = NULL, /*List of unicode characters*/
|
||||
.get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/
|
||||
.get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/
|
||||
#if USE_HEKATE_SYMBOL_30 == 4
|
||||
.bpp = 4, /*Bit per pixel*/
|
||||
#elif USE_HEKATE_SYMBOL_30 == 8
|
||||
.bpp = 8, /*Bit per pixel*/
|
||||
#endif
|
||||
.monospace = 0, /*Fix width (0: if not used)*/
|
||||
.next_page = NULL, /*Pointer to a font extension*/
|
||||
};
|
||||
|
||||
#endif /*USE_HEKATE_SYMBOL_30*/
|
248
bdk/libs/lvgl/lv_fonts/interui_20.c
Normal file
248
bdk/libs/lvgl/lv_fonts/interui_20.c
Normal file
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
#include <memory_map.h>
|
||||
|
||||
#if USE_INTERUI_20 != 0 /*Can be enabled in lv_conf.h*/
|
||||
|
||||
/***********************************************************************************
|
||||
* Inter-UI-Regular-stretched.ttf 20 px Font in U+0020 ( ) .. U+007e (~) range with all bpp
|
||||
***********************************************************************************/
|
||||
|
||||
/*Store the glyph descriptions*/
|
||||
static const lv_font_glyph_dsc_t interui_20_glyph_dsc[] =
|
||||
{
|
||||
#if USE_INTERUI_20 == 4
|
||||
{.w_px = 6, .glyph_index = 0}, /*Unicode: U+0020 ( )*/
|
||||
{.w_px = 3, .glyph_index = 60}, /*Unicode: U+0021 (!)*/
|
||||
{.w_px = 5, .glyph_index = 100}, /*Unicode: U+0022 (")*/
|
||||
{.w_px = 8, .glyph_index = 160}, /*Unicode: U+0023 (#)*/
|
||||
{.w_px = 9, .glyph_index = 240}, /*Unicode: U+0024 ($)*/
|
||||
{.w_px = 14, .glyph_index = 340}, /*Unicode: U+0025 (%)*/
|
||||
{.w_px = 12, .glyph_index = 480}, /*Unicode: U+0026 (&)*/
|
||||
{.w_px = 3, .glyph_index = 600}, /*Unicode: U+0027 (')*/
|
||||
{.w_px = 5, .glyph_index = 640}, /*Unicode: U+0028 (()*/
|
||||
{.w_px = 5, .glyph_index = 700}, /*Unicode: U+0029 ())*/
|
||||
{.w_px = 7, .glyph_index = 760}, /*Unicode: U+002a (*)*/
|
||||
{.w_px = 10, .glyph_index = 840}, /*Unicode: U+002b (+)*/
|
||||
{.w_px = 3, .glyph_index = 940}, /*Unicode: U+002c (,)*/
|
||||
{.w_px = 5, .glyph_index = 980}, /*Unicode: U+002d (-)*/
|
||||
{.w_px = 3, .glyph_index = 1040}, /*Unicode: U+002e (.)*/
|
||||
{.w_px = 8, .glyph_index = 1080}, /*Unicode: U+002f (/)*/
|
||||
{.w_px = 10, .glyph_index = 1160}, /*Unicode: U+0030 (0)*/
|
||||
{.w_px = 5, .glyph_index = 1260}, /*Unicode: U+0031 (1)*/
|
||||
{.w_px = 9, .glyph_index = 1320}, /*Unicode: U+0032 (2)*/
|
||||
{.w_px = 10, .glyph_index = 1420}, /*Unicode: U+0033 (3)*/
|
||||
{.w_px = 9, .glyph_index = 1520}, /*Unicode: U+0034 (4)*/
|
||||
{.w_px = 9, .glyph_index = 1620}, /*Unicode: U+0035 (5)*/
|
||||
{.w_px = 10, .glyph_index = 1720}, /*Unicode: U+0036 (6)*/
|
||||
{.w_px = 8, .glyph_index = 1820}, /*Unicode: U+0037 (7)*/
|
||||
{.w_px = 10, .glyph_index = 1900}, /*Unicode: U+0038 (8)*/
|
||||
{.w_px = 10, .glyph_index = 2000}, /*Unicode: U+0039 (9)*/
|
||||
{.w_px = 3, .glyph_index = 2100}, /*Unicode: U+003a (:)*/
|
||||
{.w_px = 3, .glyph_index = 2140}, /*Unicode: U+003b (;)*/
|
||||
{.w_px = 12, .glyph_index = 2180}, /*Unicode: U+003c (<)*/
|
||||
{.w_px = 10, .glyph_index = 2300}, /*Unicode: U+003d (=)*/
|
||||
{.w_px = 12, .glyph_index = 2400}, /*Unicode: U+003e (>)*/
|
||||
{.w_px = 8, .glyph_index = 2520}, /*Unicode: U+003f (?)*/
|
||||
{.w_px = 14, .glyph_index = 2600}, /*Unicode: U+0040 (@)*/
|
||||
{.w_px = 12, .glyph_index = 2740}, /*Unicode: U+0041 (A)*/
|
||||
{.w_px = 10, .glyph_index = 2860}, /*Unicode: U+0042 (B)*/
|
||||
{.w_px = 11, .glyph_index = 2960}, /*Unicode: U+0043 (C)*/
|
||||
{.w_px = 12, .glyph_index = 3080}, /*Unicode: U+0044 (D)*/
|
||||
{.w_px = 9, .glyph_index = 3200}, /*Unicode: U+0045 (E)*/
|
||||
{.w_px = 8, .glyph_index = 3300}, /*Unicode: U+0046 (F)*/
|
||||
{.w_px = 12, .glyph_index = 3380}, /*Unicode: U+0047 (G)*/
|
||||
{.w_px = 10, .glyph_index = 3500}, /*Unicode: U+0048 (H)*/
|
||||
{.w_px = 3, .glyph_index = 3600}, /*Unicode: U+0049 (I)*/
|
||||
{.w_px = 7, .glyph_index = 3640}, /*Unicode: U+004a (J)*/
|
||||
{.w_px = 10, .glyph_index = 3720}, /*Unicode: U+004b (K)*/
|
||||
{.w_px = 7, .glyph_index = 3820}, /*Unicode: U+004c (L)*/
|
||||
{.w_px = 15, .glyph_index = 3900}, /*Unicode: U+004d (M)*/
|
||||
{.w_px = 12, .glyph_index = 4060}, /*Unicode: U+004e (N)*/
|
||||
{.w_px = 14, .glyph_index = 4180}, /*Unicode: U+004f (O)*/
|
||||
{.w_px = 9, .glyph_index = 4320}, /*Unicode: U+0050 (P)*/
|
||||
{.w_px = 14, .glyph_index = 4420}, /*Unicode: U+0051 (Q)*/
|
||||
{.w_px = 9, .glyph_index = 4560}, /*Unicode: U+0052 (R)*/
|
||||
{.w_px = 9, .glyph_index = 4660}, /*Unicode: U+0053 (S)*/
|
||||
{.w_px = 9, .glyph_index = 4760}, /*Unicode: U+0054 (T)*/
|
||||
{.w_px = 12, .glyph_index = 4860}, /*Unicode: U+0055 (U)*/
|
||||
{.w_px = 12, .glyph_index = 4980}, /*Unicode: U+0056 (V)*/
|
||||
{.w_px = 18, .glyph_index = 5100}, /*Unicode: U+0057 (W)*/
|
||||
{.w_px = 10, .glyph_index = 5280}, /*Unicode: U+0058 (X)*/
|
||||
{.w_px = 10, .glyph_index = 5380}, /*Unicode: U+0059 (Y)*/
|
||||
{.w_px = 10, .glyph_index = 5480}, /*Unicode: U+005a (Z)*/
|
||||
{.w_px = 5, .glyph_index = 5580}, /*Unicode: U+005b ([)*/
|
||||
{.w_px = 8, .glyph_index = 5640}, /*Unicode: U+005c (\)*/
|
||||
{.w_px = 5, .glyph_index = 5720}, /*Unicode: U+005d (])*/
|
||||
{.w_px = 9, .glyph_index = 5780}, /*Unicode: U+005e (^)*/
|
||||
{.w_px = 8, .glyph_index = 5880}, /*Unicode: U+005f (_)*/
|
||||
{.w_px = 4, .glyph_index = 5960}, /*Unicode: U+0060 (`)*/
|
||||
{.w_px = 9, .glyph_index = 6000}, /*Unicode: U+0061 (a)*/
|
||||
{.w_px = 10, .glyph_index = 6100}, /*Unicode: U+0062 (b)*/
|
||||
{.w_px = 8, .glyph_index = 6200}, /*Unicode: U+0063 (c)*/
|
||||
{.w_px = 10, .glyph_index = 6280}, /*Unicode: U+0064 (d)*/
|
||||
{.w_px = 9, .glyph_index = 6380}, /*Unicode: U+0065 (e)*/
|
||||
{.w_px = 4, .glyph_index = 6480}, /*Unicode: U+0066 (f)*/
|
||||
{.w_px = 9, .glyph_index = 6520}, /*Unicode: U+0067 (g)*/
|
||||
{.w_px = 9, .glyph_index = 6620}, /*Unicode: U+0068 (h)*/
|
||||
{.w_px = 3, .glyph_index = 6720}, /*Unicode: U+0069 (i)*/
|
||||
{.w_px = 5, .glyph_index = 6760}, /*Unicode: U+006a (j)*/
|
||||
{.w_px = 8, .glyph_index = 6820}, /*Unicode: U+006b (k)*/
|
||||
{.w_px = 4, .glyph_index = 6900}, /*Unicode: U+006c (l)*/
|
||||
{.w_px = 13, .glyph_index = 6940}, /*Unicode: U+006d (m)*/
|
||||
{.w_px = 9, .glyph_index = 7080}, /*Unicode: U+006e (n)*/
|
||||
{.w_px = 10, .glyph_index = 7180}, /*Unicode: U+006f (o)*/
|
||||
{.w_px = 10, .glyph_index = 7280}, /*Unicode: U+0070 (p)*/
|
||||
{.w_px = 10, .glyph_index = 7380}, /*Unicode: U+0071 (q)*/
|
||||
{.w_px = 5, .glyph_index = 7480}, /*Unicode: U+0072 (r)*/
|
||||
{.w_px = 8, .glyph_index = 7540}, /*Unicode: U+0073 (s)*/
|
||||
{.w_px = 5, .glyph_index = 7620}, /*Unicode: U+0074 (t)*/
|
||||
{.w_px = 9, .glyph_index = 7680}, /*Unicode: U+0075 (u)*/
|
||||
{.w_px = 8, .glyph_index = 7780}, /*Unicode: U+0076 (v)*/
|
||||
{.w_px = 14, .glyph_index = 7860}, /*Unicode: U+0077 (w)*/
|
||||
{.w_px = 8, .glyph_index = 8000}, /*Unicode: U+0078 (x)*/
|
||||
{.w_px = 8, .glyph_index = 8080}, /*Unicode: U+0079 (y)*/
|
||||
{.w_px = 7, .glyph_index = 8160}, /*Unicode: U+007a (z)*/
|
||||
{.w_px = 4, .glyph_index = 8240}, /*Unicode: U+007b ({)*/
|
||||
{.w_px = 3, .glyph_index = 8280}, /*Unicode: U+007c (|)*/
|
||||
{.w_px = 4, .glyph_index = 8320}, /*Unicode: U+007d (})*/
|
||||
{.w_px = 6, .glyph_index = 8360}, /*Unicode: U+007e (~)*/
|
||||
|
||||
#elif USE_INTERUI_20 == 8
|
||||
{.w_px = 6, .glyph_index = 0}, /*Unicode: U+0020 ( )*/
|
||||
{.w_px = 3, .glyph_index = 120}, /*Unicode: U+0021 (!)*/
|
||||
{.w_px = 5, .glyph_index = 180}, /*Unicode: U+0022 (")*/
|
||||
{.w_px = 8, .glyph_index = 280}, /*Unicode: U+0023 (#)*/
|
||||
{.w_px = 9, .glyph_index = 440}, /*Unicode: U+0024 ($)*/
|
||||
{.w_px = 14, .glyph_index = 620}, /*Unicode: U+0025 (%)*/
|
||||
{.w_px = 12, .glyph_index = 900}, /*Unicode: U+0026 (&)*/
|
||||
{.w_px = 3, .glyph_index = 1140}, /*Unicode: U+0027 (')*/
|
||||
{.w_px = 5, .glyph_index = 1200}, /*Unicode: U+0028 (()*/
|
||||
{.w_px = 5, .glyph_index = 1300}, /*Unicode: U+0029 ())*/
|
||||
{.w_px = 7, .glyph_index = 1400}, /*Unicode: U+002a (*)*/
|
||||
{.w_px = 10, .glyph_index = 1540}, /*Unicode: U+002b (+)*/
|
||||
{.w_px = 3, .glyph_index = 1740}, /*Unicode: U+002c (,)*/
|
||||
{.w_px = 5, .glyph_index = 1800}, /*Unicode: U+002d (-)*/
|
||||
{.w_px = 3, .glyph_index = 1900}, /*Unicode: U+002e (.)*/
|
||||
{.w_px = 8, .glyph_index = 1960}, /*Unicode: U+002f (/)*/
|
||||
{.w_px = 10, .glyph_index = 2120}, /*Unicode: U+0030 (0)*/
|
||||
{.w_px = 5, .glyph_index = 2320}, /*Unicode: U+0031 (1)*/
|
||||
{.w_px = 9, .glyph_index = 2420}, /*Unicode: U+0032 (2)*/
|
||||
{.w_px = 10, .glyph_index = 2600}, /*Unicode: U+0033 (3)*/
|
||||
{.w_px = 9, .glyph_index = 2800}, /*Unicode: U+0034 (4)*/
|
||||
{.w_px = 9, .glyph_index = 2980}, /*Unicode: U+0035 (5)*/
|
||||
{.w_px = 10, .glyph_index = 3160}, /*Unicode: U+0036 (6)*/
|
||||
{.w_px = 8, .glyph_index = 3360}, /*Unicode: U+0037 (7)*/
|
||||
{.w_px = 10, .glyph_index = 3520}, /*Unicode: U+0038 (8)*/
|
||||
{.w_px = 10, .glyph_index = 3720}, /*Unicode: U+0039 (9)*/
|
||||
{.w_px = 3, .glyph_index = 3920}, /*Unicode: U+003a (:)*/
|
||||
{.w_px = 3, .glyph_index = 3980}, /*Unicode: U+003b (;)*/
|
||||
{.w_px = 12, .glyph_index = 4040}, /*Unicode: U+003c (<)*/
|
||||
{.w_px = 10, .glyph_index = 4280}, /*Unicode: U+003d (=)*/
|
||||
{.w_px = 12, .glyph_index = 4480}, /*Unicode: U+003e (>)*/
|
||||
{.w_px = 8, .glyph_index = 4720}, /*Unicode: U+003f (?)*/
|
||||
{.w_px = 14, .glyph_index = 4880}, /*Unicode: U+0040 (@)*/
|
||||
{.w_px = 12, .glyph_index = 5160}, /*Unicode: U+0041 (A)*/
|
||||
{.w_px = 10, .glyph_index = 5400}, /*Unicode: U+0042 (B)*/
|
||||
{.w_px = 11, .glyph_index = 5600}, /*Unicode: U+0043 (C)*/
|
||||
{.w_px = 12, .glyph_index = 5820}, /*Unicode: U+0044 (D)*/
|
||||
{.w_px = 9, .glyph_index = 6060}, /*Unicode: U+0045 (E)*/
|
||||
{.w_px = 8, .glyph_index = 6240}, /*Unicode: U+0046 (F)*/
|
||||
{.w_px = 12, .glyph_index = 6400}, /*Unicode: U+0047 (G)*/
|
||||
{.w_px = 10, .glyph_index = 6640}, /*Unicode: U+0048 (H)*/
|
||||
{.w_px = 3, .glyph_index = 6840}, /*Unicode: U+0049 (I)*/
|
||||
{.w_px = 7, .glyph_index = 6900}, /*Unicode: U+004a (J)*/
|
||||
{.w_px = 10, .glyph_index = 7040}, /*Unicode: U+004b (K)*/
|
||||
{.w_px = 7, .glyph_index = 7240}, /*Unicode: U+004c (L)*/
|
||||
{.w_px = 15, .glyph_index = 7380}, /*Unicode: U+004d (M)*/
|
||||
{.w_px = 12, .glyph_index = 7680}, /*Unicode: U+004e (N)*/
|
||||
{.w_px = 14, .glyph_index = 7920}, /*Unicode: U+004f (O)*/
|
||||
{.w_px = 9, .glyph_index = 8200}, /*Unicode: U+0050 (P)*/
|
||||
{.w_px = 14, .glyph_index = 8380}, /*Unicode: U+0051 (Q)*/
|
||||
{.w_px = 9, .glyph_index = 8660}, /*Unicode: U+0052 (R)*/
|
||||
{.w_px = 9, .glyph_index = 8840}, /*Unicode: U+0053 (S)*/
|
||||
{.w_px = 9, .glyph_index = 9020}, /*Unicode: U+0054 (T)*/
|
||||
{.w_px = 12, .glyph_index = 9200}, /*Unicode: U+0055 (U)*/
|
||||
{.w_px = 12, .glyph_index = 9440}, /*Unicode: U+0056 (V)*/
|
||||
{.w_px = 18, .glyph_index = 9680}, /*Unicode: U+0057 (W)*/
|
||||
{.w_px = 10, .glyph_index = 10040}, /*Unicode: U+0058 (X)*/
|
||||
{.w_px = 10, .glyph_index = 10240}, /*Unicode: U+0059 (Y)*/
|
||||
{.w_px = 10, .glyph_index = 10440}, /*Unicode: U+005a (Z)*/
|
||||
{.w_px = 5, .glyph_index = 10640}, /*Unicode: U+005b ([)*/
|
||||
{.w_px = 8, .glyph_index = 10740}, /*Unicode: U+005c (\)*/
|
||||
{.w_px = 5, .glyph_index = 10900}, /*Unicode: U+005d (])*/
|
||||
{.w_px = 9, .glyph_index = 11000}, /*Unicode: U+005e (^)*/
|
||||
{.w_px = 8, .glyph_index = 11180}, /*Unicode: U+005f (_)*/
|
||||
{.w_px = 4, .glyph_index = 11340}, /*Unicode: U+0060 (`)*/
|
||||
{.w_px = 9, .glyph_index = 11420}, /*Unicode: U+0061 (a)*/
|
||||
{.w_px = 10, .glyph_index = 11600}, /*Unicode: U+0062 (b)*/
|
||||
{.w_px = 8, .glyph_index = 11800}, /*Unicode: U+0063 (c)*/
|
||||
{.w_px = 10, .glyph_index = 11960}, /*Unicode: U+0064 (d)*/
|
||||
{.w_px = 9, .glyph_index = 12160}, /*Unicode: U+0065 (e)*/
|
||||
{.w_px = 4, .glyph_index = 12340}, /*Unicode: U+0066 (f)*/
|
||||
{.w_px = 9, .glyph_index = 12420}, /*Unicode: U+0067 (g)*/
|
||||
{.w_px = 9, .glyph_index = 12600}, /*Unicode: U+0068 (h)*/
|
||||
{.w_px = 3, .glyph_index = 12780}, /*Unicode: U+0069 (i)*/
|
||||
{.w_px = 5, .glyph_index = 12840}, /*Unicode: U+006a (j)*/
|
||||
{.w_px = 8, .glyph_index = 12940}, /*Unicode: U+006b (k)*/
|
||||
{.w_px = 4, .glyph_index = 13100}, /*Unicode: U+006c (l)*/
|
||||
{.w_px = 13, .glyph_index = 13180}, /*Unicode: U+006d (m)*/
|
||||
{.w_px = 9, .glyph_index = 13440}, /*Unicode: U+006e (n)*/
|
||||
{.w_px = 10, .glyph_index = 13620}, /*Unicode: U+006f (o)*/
|
||||
{.w_px = 10, .glyph_index = 13820}, /*Unicode: U+0070 (p)*/
|
||||
{.w_px = 10, .glyph_index = 14020}, /*Unicode: U+0071 (q)*/
|
||||
{.w_px = 5, .glyph_index = 14220}, /*Unicode: U+0072 (r)*/
|
||||
{.w_px = 8, .glyph_index = 14320}, /*Unicode: U+0073 (s)*/
|
||||
{.w_px = 5, .glyph_index = 14480}, /*Unicode: U+0074 (t)*/
|
||||
{.w_px = 9, .glyph_index = 14580}, /*Unicode: U+0075 (u)*/
|
||||
{.w_px = 8, .glyph_index = 14760}, /*Unicode: U+0076 (v)*/
|
||||
{.w_px = 14, .glyph_index = 14920}, /*Unicode: U+0077 (w)*/
|
||||
{.w_px = 8, .glyph_index = 15200}, /*Unicode: U+0078 (x)*/
|
||||
{.w_px = 8, .glyph_index = 15360}, /*Unicode: U+0079 (y)*/
|
||||
{.w_px = 7, .glyph_index = 15520}, /*Unicode: U+007a (z)*/
|
||||
{.w_px = 4, .glyph_index = 15660}, /*Unicode: U+007b ({)*/
|
||||
{.w_px = 3, .glyph_index = 15740}, /*Unicode: U+007c (|)*/
|
||||
{.w_px = 4, .glyph_index = 15800}, /*Unicode: U+007d (})*/
|
||||
{.w_px = 6, .glyph_index = 15880}, /*Unicode: U+007e (~)*/
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
lv_font_t interui_20 =
|
||||
{
|
||||
.unicode_first = 32, /*First Unicode letter in this font*/
|
||||
.unicode_last = 126, /*Last Unicode letter in this font*/
|
||||
.h_px = 20, /*Font height in pixels*/
|
||||
//.glyph_bitmap = interui_20_glyph_bitmap, /*Bitmap of glyphs*/
|
||||
.glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x3A00),
|
||||
.glyph_dsc = interui_20_glyph_dsc, /*Description of glyphs*/
|
||||
.glyph_cnt = 95, /*Number of glyphs in the font*/
|
||||
.unicode_list = NULL, /*Every character in the font from 'unicode_first' to 'unicode_last'*/
|
||||
.get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/
|
||||
.get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/
|
||||
#if USE_INTERUI_20 == 4
|
||||
.bpp = 4, /*Bit per pixel*/
|
||||
#elif USE_INTERUI_20 == 8
|
||||
.bpp = 8, /*Bit per pixel*/
|
||||
#endif
|
||||
.monospace = 0, /*Fix width (0: if not used)*/
|
||||
.next_page = NULL, /*Pointer to a font extension*/
|
||||
};
|
||||
|
||||
#endif /*USE_INTERUI_20*/
|
248
bdk/libs/lvgl/lv_fonts/interui_30.c
Normal file
248
bdk/libs/lvgl/lv_fonts/interui_30.c
Normal file
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
#include <memory_map.h>
|
||||
|
||||
#if USE_INTERUI_30 != 0 /*Can be enabled in lv_conf.h*/
|
||||
|
||||
/***********************************************************************************
|
||||
* Inter-UI-Regular-stretched.ttf 30 px Font in U+0020 ( ) .. U+007e (~) range with all bpp
|
||||
***********************************************************************************/
|
||||
|
||||
/*Store the glyph descriptions*/
|
||||
static const lv_font_glyph_dsc_t interui_30_glyph_dsc[] =
|
||||
{
|
||||
#if USE_INTERUI_30 == 4
|
||||
{.w_px = 8, .glyph_index = 0}, /*Unicode: U+0020 ( )*/
|
||||
{.w_px = 3, .glyph_index = 120}, /*Unicode: U+0021 (!)*/
|
||||
{.w_px = 6, .glyph_index = 180}, /*Unicode: U+0022 (")*/
|
||||
{.w_px = 13, .glyph_index = 270}, /*Unicode: U+0023 (#)*/
|
||||
{.w_px = 12, .glyph_index = 480}, /*Unicode: U+0024 ($)*/
|
||||
{.w_px = 18, .glyph_index = 660}, /*Unicode: U+0025 (%)*/
|
||||
{.w_px = 16, .glyph_index = 930}, /*Unicode: U+0026 (&)*/
|
||||
{.w_px = 3, .glyph_index = 1170}, /*Unicode: U+0027 (')*/
|
||||
{.w_px = 6, .glyph_index = 1230}, /*Unicode: U+0028 (()*/
|
||||
{.w_px = 7, .glyph_index = 1320}, /*Unicode: U+0029 ())*/
|
||||
{.w_px = 9, .glyph_index = 1440}, /*Unicode: U+002a (*)*/
|
||||
{.w_px = 16, .glyph_index = 1590}, /*Unicode: U+002b (+)*/
|
||||
{.w_px = 3, .glyph_index = 1830}, /*Unicode: U+002c (,)*/
|
||||
{.w_px = 8, .glyph_index = 1890}, /*Unicode: U+002d (-)*/
|
||||
{.w_px = 3, .glyph_index = 2010}, /*Unicode: U+002e (.)*/
|
||||
{.w_px = 11, .glyph_index = 2070}, /*Unicode: U+002f (/)*/
|
||||
{.w_px = 13, .glyph_index = 2250}, /*Unicode: U+0030 (0)*/
|
||||
{.w_px = 7, .glyph_index = 2460}, /*Unicode: U+0031 (1)*/
|
||||
{.w_px = 13, .glyph_index = 2580}, /*Unicode: U+0032 (2)*/
|
||||
{.w_px = 14, .glyph_index = 2790}, /*Unicode: U+0033 (3)*/
|
||||
{.w_px = 13, .glyph_index = 3000}, /*Unicode: U+0034 (4)*/
|
||||
{.w_px = 14, .glyph_index = 3210}, /*Unicode: U+0035 (5)*/
|
||||
{.w_px = 13, .glyph_index = 3420}, /*Unicode: U+0036 (6)*/
|
||||
{.w_px = 13, .glyph_index = 3630}, /*Unicode: U+0037 (7)*/
|
||||
{.w_px = 13, .glyph_index = 3840}, /*Unicode: U+0038 (8)*/
|
||||
{.w_px = 13, .glyph_index = 4050}, /*Unicode: U+0039 (9)*/
|
||||
{.w_px = 3, .glyph_index = 4260}, /*Unicode: U+003a (:)*/
|
||||
{.w_px = 3, .glyph_index = 4320}, /*Unicode: U+003b (;)*/
|
||||
{.w_px = 18, .glyph_index = 4380}, /*Unicode: U+003c (<)*/
|
||||
{.w_px = 16, .glyph_index = 4650}, /*Unicode: U+003d (=)*/
|
||||
{.w_px = 18, .glyph_index = 4890}, /*Unicode: U+003e (>)*/
|
||||
{.w_px = 12, .glyph_index = 5160}, /*Unicode: U+003f (?)*/
|
||||
{.w_px = 18, .glyph_index = 5340}, /*Unicode: U+0040 (@)*/
|
||||
{.w_px = 17, .glyph_index = 5610}, /*Unicode: U+0041 (A)*/
|
||||
{.w_px = 13, .glyph_index = 5880}, /*Unicode: U+0042 (B)*/
|
||||
{.w_px = 15, .glyph_index = 6090}, /*Unicode: U+0043 (C)*/
|
||||
{.w_px = 17, .glyph_index = 6330}, /*Unicode: U+0044 (D)*/
|
||||
{.w_px = 12, .glyph_index = 6600}, /*Unicode: U+0045 (E)*/
|
||||
{.w_px = 11, .glyph_index = 6780}, /*Unicode: U+0046 (F)*/
|
||||
{.w_px = 17, .glyph_index = 6960}, /*Unicode: U+0047 (G)*/
|
||||
{.w_px = 14, .glyph_index = 7230}, /*Unicode: U+0048 (H)*/
|
||||
{.w_px = 3, .glyph_index = 7440}, /*Unicode: U+0049 (I)*/
|
||||
{.w_px = 11, .glyph_index = 7500}, /*Unicode: U+004a (J)*/
|
||||
{.w_px = 14, .glyph_index = 7680}, /*Unicode: U+004b (K)*/
|
||||
{.w_px = 9, .glyph_index = 7890}, /*Unicode: U+004c (L)*/
|
||||
{.w_px = 23, .glyph_index = 8040}, /*Unicode: U+004d (M)*/
|
||||
{.w_px = 16, .glyph_index = 8400}, /*Unicode: U+004e (N)*/
|
||||
{.w_px = 19, .glyph_index = 8640}, /*Unicode: U+004f (O)*/
|
||||
{.w_px = 11, .glyph_index = 8940}, /*Unicode: U+0050 (P)*/
|
||||
{.w_px = 19, .glyph_index = 9120}, /*Unicode: U+0051 (Q)*/
|
||||
{.w_px = 13, .glyph_index = 9420}, /*Unicode: U+0052 (R)*/
|
||||
{.w_px = 12, .glyph_index = 9630}, /*Unicode: U+0053 (S)*/
|
||||
{.w_px = 14, .glyph_index = 9810}, /*Unicode: U+0054 (T)*/
|
||||
{.w_px = 16, .glyph_index = 10020}, /*Unicode: U+0055 (U)*/
|
||||
{.w_px = 18, .glyph_index = 10260}, /*Unicode: U+0056 (V)*/
|
||||
{.w_px = 27, .glyph_index = 10530}, /*Unicode: U+0057 (W)*/
|
||||
{.w_px = 15, .glyph_index = 10950}, /*Unicode: U+0058 (X)*/
|
||||
{.w_px = 15, .glyph_index = 11190}, /*Unicode: U+0059 (Y)*/
|
||||
{.w_px = 15, .glyph_index = 11430}, /*Unicode: U+005a (Z)*/
|
||||
{.w_px = 6, .glyph_index = 11670}, /*Unicode: U+005b ([)*/
|
||||
{.w_px = 11, .glyph_index = 11760}, /*Unicode: U+005c (\)*/
|
||||
{.w_px = 7, .glyph_index = 11940}, /*Unicode: U+005d (])*/
|
||||
{.w_px = 13, .glyph_index = 12060}, /*Unicode: U+005e (^)*/
|
||||
{.w_px = 12, .glyph_index = 12270}, /*Unicode: U+005f (_)*/
|
||||
{.w_px = 6, .glyph_index = 12450}, /*Unicode: U+0060 (`)*/
|
||||
{.w_px = 12, .glyph_index = 12540}, /*Unicode: U+0061 (a)*/
|
||||
{.w_px = 13, .glyph_index = 12720}, /*Unicode: U+0062 (b)*/
|
||||
{.w_px = 11, .glyph_index = 12930}, /*Unicode: U+0063 (c)*/
|
||||
{.w_px = 13, .glyph_index = 13110}, /*Unicode: U+0064 (d)*/
|
||||
{.w_px = 12, .glyph_index = 13320}, /*Unicode: U+0065 (e)*/
|
||||
{.w_px = 6, .glyph_index = 13500}, /*Unicode: U+0066 (f)*/
|
||||
{.w_px = 12, .glyph_index = 13590}, /*Unicode: U+0067 (g)*/
|
||||
{.w_px = 11, .glyph_index = 13770}, /*Unicode: U+0068 (h)*/
|
||||
{.w_px = 3, .glyph_index = 13950}, /*Unicode: U+0069 (i)*/
|
||||
{.w_px = 7, .glyph_index = 14010}, /*Unicode: U+006a (j)*/
|
||||
{.w_px = 12, .glyph_index = 14130}, /*Unicode: U+006b (k)*/
|
||||
{.w_px = 4, .glyph_index = 14310}, /*Unicode: U+006c (l)*/
|
||||
{.w_px = 19, .glyph_index = 14370}, /*Unicode: U+006d (m)*/
|
||||
{.w_px = 11, .glyph_index = 14670}, /*Unicode: U+006e (n)*/
|
||||
{.w_px = 14, .glyph_index = 14850}, /*Unicode: U+006f (o)*/
|
||||
{.w_px = 13, .glyph_index = 15060}, /*Unicode: U+0070 (p)*/
|
||||
{.w_px = 13, .glyph_index = 15270}, /*Unicode: U+0071 (q)*/
|
||||
{.w_px = 7, .glyph_index = 15480}, /*Unicode: U+0072 (r)*/
|
||||
{.w_px = 11, .glyph_index = 15600}, /*Unicode: U+0073 (s)*/
|
||||
{.w_px = 8, .glyph_index = 15780}, /*Unicode: U+0074 (t)*/
|
||||
{.w_px = 11, .glyph_index = 15900}, /*Unicode: U+0075 (u)*/
|
||||
{.w_px = 12, .glyph_index = 16080}, /*Unicode: U+0076 (v)*/
|
||||
{.w_px = 21, .glyph_index = 16260}, /*Unicode: U+0077 (w)*/
|
||||
{.w_px = 13, .glyph_index = 16590}, /*Unicode: U+0078 (x)*/
|
||||
{.w_px = 13, .glyph_index = 16800}, /*Unicode: U+0079 (y)*/
|
||||
{.w_px = 10, .glyph_index = 17010}, /*Unicode: U+007a (z)*/
|
||||
{.w_px = 6, .glyph_index = 17160}, /*Unicode: U+007b ({)*/
|
||||
{.w_px = 3, .glyph_index = 17250}, /*Unicode: U+007c (|)*/
|
||||
{.w_px = 5, .glyph_index = 17310}, /*Unicode: U+007d (})*/
|
||||
{.w_px = 8, .glyph_index = 17400}, /*Unicode: U+007e (~)*/
|
||||
|
||||
#elif USE_INTERUI_30 == 8
|
||||
{.w_px = 8, .glyph_index = 0}, /*Unicode: U+0020 ( )*/
|
||||
{.w_px = 3, .glyph_index = 240}, /*Unicode: U+0021 (!)*/
|
||||
{.w_px = 6, .glyph_index = 330}, /*Unicode: U+0022 (")*/
|
||||
{.w_px = 13, .glyph_index = 510}, /*Unicode: U+0023 (#)*/
|
||||
{.w_px = 12, .glyph_index = 900}, /*Unicode: U+0024 ($)*/
|
||||
{.w_px = 18, .glyph_index = 1260}, /*Unicode: U+0025 (%)*/
|
||||
{.w_px = 16, .glyph_index = 1800}, /*Unicode: U+0026 (&)*/
|
||||
{.w_px = 3, .glyph_index = 2280}, /*Unicode: U+0027 (')*/
|
||||
{.w_px = 6, .glyph_index = 2370}, /*Unicode: U+0028 (()*/
|
||||
{.w_px = 7, .glyph_index = 2550}, /*Unicode: U+0029 ())*/
|
||||
{.w_px = 9, .glyph_index = 2760}, /*Unicode: U+002a (*)*/
|
||||
{.w_px = 16, .glyph_index = 3030}, /*Unicode: U+002b (+)*/
|
||||
{.w_px = 3, .glyph_index = 3510}, /*Unicode: U+002c (,)*/
|
||||
{.w_px = 8, .glyph_index = 3600}, /*Unicode: U+002d (-)*/
|
||||
{.w_px = 3, .glyph_index = 3840}, /*Unicode: U+002e (.)*/
|
||||
{.w_px = 11, .glyph_index = 3930}, /*Unicode: U+002f (/)*/
|
||||
{.w_px = 13, .glyph_index = 4260}, /*Unicode: U+0030 (0)*/
|
||||
{.w_px = 7, .glyph_index = 4650}, /*Unicode: U+0031 (1)*/
|
||||
{.w_px = 13, .glyph_index = 4860}, /*Unicode: U+0032 (2)*/
|
||||
{.w_px = 14, .glyph_index = 5250}, /*Unicode: U+0033 (3)*/
|
||||
{.w_px = 13, .glyph_index = 5670}, /*Unicode: U+0034 (4)*/
|
||||
{.w_px = 14, .glyph_index = 6060}, /*Unicode: U+0035 (5)*/
|
||||
{.w_px = 13, .glyph_index = 6480}, /*Unicode: U+0036 (6)*/
|
||||
{.w_px = 13, .glyph_index = 6870}, /*Unicode: U+0037 (7)*/
|
||||
{.w_px = 13, .glyph_index = 7260}, /*Unicode: U+0038 (8)*/
|
||||
{.w_px = 13, .glyph_index = 7650}, /*Unicode: U+0039 (9)*/
|
||||
{.w_px = 3, .glyph_index = 8040}, /*Unicode: U+003a (:)*/
|
||||
{.w_px = 3, .glyph_index = 8130}, /*Unicode: U+003b (;)*/
|
||||
{.w_px = 18, .glyph_index = 8220}, /*Unicode: U+003c (<)*/
|
||||
{.w_px = 16, .glyph_index = 8760}, /*Unicode: U+003d (=)*/
|
||||
{.w_px = 18, .glyph_index = 9240}, /*Unicode: U+003e (>)*/
|
||||
{.w_px = 12, .glyph_index = 9780}, /*Unicode: U+003f (?)*/
|
||||
{.w_px = 18, .glyph_index = 10140}, /*Unicode: U+0040 (@)*/
|
||||
{.w_px = 17, .glyph_index = 10680}, /*Unicode: U+0041 (A)*/
|
||||
{.w_px = 13, .glyph_index = 11190}, /*Unicode: U+0042 (B)*/
|
||||
{.w_px = 15, .glyph_index = 11580}, /*Unicode: U+0043 (C)*/
|
||||
{.w_px = 17, .glyph_index = 12030}, /*Unicode: U+0044 (D)*/
|
||||
{.w_px = 12, .glyph_index = 12540}, /*Unicode: U+0045 (E)*/
|
||||
{.w_px = 11, .glyph_index = 12900}, /*Unicode: U+0046 (F)*/
|
||||
{.w_px = 17, .glyph_index = 13230}, /*Unicode: U+0047 (G)*/
|
||||
{.w_px = 14, .glyph_index = 13740}, /*Unicode: U+0048 (H)*/
|
||||
{.w_px = 3, .glyph_index = 14160}, /*Unicode: U+0049 (I)*/
|
||||
{.w_px = 11, .glyph_index = 14250}, /*Unicode: U+004a (J)*/
|
||||
{.w_px = 14, .glyph_index = 14580}, /*Unicode: U+004b (K)*/
|
||||
{.w_px = 9, .glyph_index = 15000}, /*Unicode: U+004c (L)*/
|
||||
{.w_px = 23, .glyph_index = 15270}, /*Unicode: U+004d (M)*/
|
||||
{.w_px = 16, .glyph_index = 15960}, /*Unicode: U+004e (N)*/
|
||||
{.w_px = 19, .glyph_index = 16440}, /*Unicode: U+004f (O)*/
|
||||
{.w_px = 11, .glyph_index = 17010}, /*Unicode: U+0050 (P)*/
|
||||
{.w_px = 19, .glyph_index = 17340}, /*Unicode: U+0051 (Q)*/
|
||||
{.w_px = 13, .glyph_index = 17910}, /*Unicode: U+0052 (R)*/
|
||||
{.w_px = 12, .glyph_index = 18300}, /*Unicode: U+0053 (S)*/
|
||||
{.w_px = 14, .glyph_index = 18660}, /*Unicode: U+0054 (T)*/
|
||||
{.w_px = 16, .glyph_index = 19080}, /*Unicode: U+0055 (U)*/
|
||||
{.w_px = 18, .glyph_index = 19560}, /*Unicode: U+0056 (V)*/
|
||||
{.w_px = 27, .glyph_index = 20100}, /*Unicode: U+0057 (W)*/
|
||||
{.w_px = 15, .glyph_index = 20910}, /*Unicode: U+0058 (X)*/
|
||||
{.w_px = 15, .glyph_index = 21360}, /*Unicode: U+0059 (Y)*/
|
||||
{.w_px = 15, .glyph_index = 21810}, /*Unicode: U+005a (Z)*/
|
||||
{.w_px = 6, .glyph_index = 22260}, /*Unicode: U+005b ([)*/
|
||||
{.w_px = 11, .glyph_index = 22440}, /*Unicode: U+005c (\)*/
|
||||
{.w_px = 7, .glyph_index = 22770}, /*Unicode: U+005d (])*/
|
||||
{.w_px = 13, .glyph_index = 22980}, /*Unicode: U+005e (^)*/
|
||||
{.w_px = 12, .glyph_index = 23370}, /*Unicode: U+005f (_)*/
|
||||
{.w_px = 6, .glyph_index = 23730}, /*Unicode: U+0060 (`)*/
|
||||
{.w_px = 12, .glyph_index = 23910}, /*Unicode: U+0061 (a)*/
|
||||
{.w_px = 13, .glyph_index = 24270}, /*Unicode: U+0062 (b)*/
|
||||
{.w_px = 11, .glyph_index = 24660}, /*Unicode: U+0063 (c)*/
|
||||
{.w_px = 13, .glyph_index = 24990}, /*Unicode: U+0064 (d)*/
|
||||
{.w_px = 12, .glyph_index = 25380}, /*Unicode: U+0065 (e)*/
|
||||
{.w_px = 6, .glyph_index = 25740}, /*Unicode: U+0066 (f)*/
|
||||
{.w_px = 12, .glyph_index = 25920}, /*Unicode: U+0067 (g)*/
|
||||
{.w_px = 11, .glyph_index = 26280}, /*Unicode: U+0068 (h)*/
|
||||
{.w_px = 3, .glyph_index = 26610}, /*Unicode: U+0069 (i)*/
|
||||
{.w_px = 7, .glyph_index = 26700}, /*Unicode: U+006a (j)*/
|
||||
{.w_px = 12, .glyph_index = 26910}, /*Unicode: U+006b (k)*/
|
||||
{.w_px = 4, .glyph_index = 27270}, /*Unicode: U+006c (l)*/
|
||||
{.w_px = 19, .glyph_index = 27390}, /*Unicode: U+006d (m)*/
|
||||
{.w_px = 11, .glyph_index = 27960}, /*Unicode: U+006e (n)*/
|
||||
{.w_px = 14, .glyph_index = 28290}, /*Unicode: U+006f (o)*/
|
||||
{.w_px = 13, .glyph_index = 28710}, /*Unicode: U+0070 (p)*/
|
||||
{.w_px = 13, .glyph_index = 29100}, /*Unicode: U+0071 (q)*/
|
||||
{.w_px = 7, .glyph_index = 29490}, /*Unicode: U+0072 (r)*/
|
||||
{.w_px = 11, .glyph_index = 29700}, /*Unicode: U+0073 (s)*/
|
||||
{.w_px = 8, .glyph_index = 30030}, /*Unicode: U+0074 (t)*/
|
||||
{.w_px = 11, .glyph_index = 30270}, /*Unicode: U+0075 (u)*/
|
||||
{.w_px = 12, .glyph_index = 30600}, /*Unicode: U+0076 (v)*/
|
||||
{.w_px = 21, .glyph_index = 30960}, /*Unicode: U+0077 (w)*/
|
||||
{.w_px = 13, .glyph_index = 31590}, /*Unicode: U+0078 (x)*/
|
||||
{.w_px = 13, .glyph_index = 31980}, /*Unicode: U+0079 (y)*/
|
||||
{.w_px = 10, .glyph_index = 32370}, /*Unicode: U+007a (z)*/
|
||||
{.w_px = 6, .glyph_index = 32670}, /*Unicode: U+007b ({)*/
|
||||
{.w_px = 3, .glyph_index = 32850}, /*Unicode: U+007c (|)*/
|
||||
{.w_px = 5, .glyph_index = 32940}, /*Unicode: U+007d (})*/
|
||||
{.w_px = 8, .glyph_index = 33090}, /*Unicode: U+007e (~)*/
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
lv_font_t interui_30 =
|
||||
{
|
||||
.unicode_first = 32, /*First Unicode letter in this font*/
|
||||
.unicode_last = 126, /*Last Unicode letter in this font*/
|
||||
.h_px = 30, /*Font height in pixels*/
|
||||
//.glyph_bitmap = interui_30_glyph_bitmap, /*Bitmap of glyphs*/
|
||||
.glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR + 0x7900),
|
||||
.glyph_dsc = interui_30_glyph_dsc, /*Description of glyphs*/
|
||||
.glyph_cnt = 95, /*Number of glyphs in the font*/
|
||||
.unicode_list = NULL, /*Every character in the font from 'unicode_first' to 'unicode_last'*/
|
||||
.get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/
|
||||
.get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/
|
||||
#if USE_INTERUI_30 == 4
|
||||
.bpp = 4, /*Bit per pixel*/
|
||||
#elif USE_INTERUI_30 == 8
|
||||
.bpp = 8, /*Bit per pixel*/
|
||||
#endif
|
||||
.monospace = 0, /*Fix width (0: if not used)*/
|
||||
.next_page = NULL, /*Pointer to a font extension*/
|
||||
};
|
||||
|
||||
#endif /*USE_INTERUI_30*/
|
100
bdk/libs/lvgl/lv_fonts/lv_font_builtin.c
Normal file
100
bdk/libs/lvgl/lv_fonts/lv_font_builtin.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lv_font_built_in.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_font_builtin.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the built-in fonts
|
||||
*/
|
||||
void lv_font_builtin_init(void)
|
||||
{
|
||||
/*InterUI 20*/
|
||||
#if USE_INTERUI_20 != 0
|
||||
lv_font_add(&interui_20, NULL);
|
||||
#endif
|
||||
|
||||
/*SYMBOL 20*/
|
||||
#if USE_HEKATE_SYMBOL_20 != 0
|
||||
#if USE_INTERUI_20 != 0
|
||||
lv_font_add(&hekate_symbol_20, &interui_20);
|
||||
#else
|
||||
lv_font_add(&hekate_symbol_20, NULL);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*InterUI 30*/
|
||||
#if USE_INTERUI_30 != 0
|
||||
lv_font_add(&interui_30, NULL);
|
||||
#endif
|
||||
|
||||
/*SYMBOL 30*/
|
||||
#if USE_HEKATE_SYMBOL_30 != 0
|
||||
#if USE_INTERUI_30 != 0
|
||||
lv_font_add(&hekate_symbol_30, &interui_30);
|
||||
#else
|
||||
lv_font_add(&hekate_symbol_30, NULL);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*MONO 12*/
|
||||
#if USE_UBUNTU_MONO != 0
|
||||
lv_font_add(&ubuntu_mono, NULL);
|
||||
#if USE_INTERUI_20 != 0
|
||||
lv_font_add(&hekate_symbol_20, &ubuntu_mono);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*Symbol 120*/
|
||||
#if USE_HEKATE_SYMBOL_120 != 0
|
||||
lv_font_add(&hekate_symbol_120, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
95
bdk/libs/lvgl/lv_fonts/lv_font_builtin.h
Normal file
95
bdk/libs/lvgl/lv_fonts/lv_font_builtin.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lv_font_builtin.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_FONT_BUILTIN_H
|
||||
#define LV_FONT_BUILTIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the built-in fonts
|
||||
*/
|
||||
void lv_font_builtin_init(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* FONT DECLARATIONS
|
||||
**********************/
|
||||
|
||||
/*20 px */
|
||||
#if USE_INTERUI_20
|
||||
LV_FONT_DECLARE(interui_20);
|
||||
#endif
|
||||
|
||||
#if USE_HEKATE_SYMBOL_20
|
||||
LV_FONT_DECLARE(hekate_symbol_20);
|
||||
#endif
|
||||
|
||||
/*30 px */
|
||||
#if USE_INTERUI_30
|
||||
LV_FONT_DECLARE(interui_30);
|
||||
#endif
|
||||
|
||||
#if USE_HEKATE_SYMBOL_30
|
||||
LV_FONT_DECLARE(hekate_symbol_30);
|
||||
#endif
|
||||
|
||||
#if USE_UBUNTU_MONO
|
||||
LV_FONT_DECLARE(ubuntu_mono);
|
||||
#endif
|
||||
|
||||
#if USE_HEKATE_SYMBOL_120
|
||||
LV_FONT_DECLARE(hekate_symbol_120);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_FONT_BUILTIN_H*/
|
14
bdk/libs/lvgl/lv_fonts/lv_fonts.mk
Normal file
14
bdk/libs/lvgl/lv_fonts/lv_fonts.mk
Normal file
|
@ -0,0 +1,14 @@
|
|||
CSRCS += lv_font_builtin.c
|
||||
CSRCS += hekate_symbol_10.c
|
||||
CSRCS += hekate_symbol_20.c
|
||||
CSRCS += hekate_symbol_30.c
|
||||
CSRCS += hekate_symbol_40.c
|
||||
CSRCS += interui_12.c
|
||||
CSRCS += interui_20.c
|
||||
CSRCS += interui_30.c
|
||||
CSRCS += interui_40.c
|
||||
|
||||
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_fonts
|
||||
VPATH += :$(LVGL_DIR)/lvgl/lv_fonts
|
||||
|
||||
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_fonts"
|
248
bdk/libs/lvgl/lv_fonts/ubuntu_mono.c
Normal file
248
bdk/libs/lvgl/lv_fonts/ubuntu_mono.c
Normal file
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../lv_misc/lv_font.h"
|
||||
|
||||
#include <memory_map.h>
|
||||
|
||||
#if USE_UBUNTU_MONO != 0 /*Can be enabled in lv_conf.h*/
|
||||
|
||||
/***********************************************************************************
|
||||
* UbuntuMono-B.ttf 20 px Font in U+0020 ( ) .. U+007e (~) range with all bpp
|
||||
***********************************************************************************/
|
||||
|
||||
/*Store the glyph descriptions*/
|
||||
static const lv_font_glyph_dsc_t ubuntu_mono_glyph_dsc[] =
|
||||
{
|
||||
#if USE_UBUNTU_MONO == 4
|
||||
{.w_px = 6, .glyph_index = 0}, /*Unicode: U+0020 ( )*/
|
||||
{.w_px = 2, .glyph_index = 60}, /*Unicode: U+0021 (!)*/
|
||||
{.w_px = 5, .glyph_index = 80}, /*Unicode: U+0022 (")*/
|
||||
{.w_px = 10, .glyph_index = 140}, /*Unicode: U+0023 (#)*/
|
||||
{.w_px = 8, .glyph_index = 240}, /*Unicode: U+0024 ($)*/
|
||||
{.w_px = 10, .glyph_index = 320}, /*Unicode: U+0025 (%)*/
|
||||
{.w_px = 10, .glyph_index = 420}, /*Unicode: U+0026 (&)*/
|
||||
{.w_px = 2, .glyph_index = 520}, /*Unicode: U+0027 (')*/
|
||||
{.w_px = 6, .glyph_index = 540}, /*Unicode: U+0028 (()*/
|
||||
{.w_px = 6, .glyph_index = 600}, /*Unicode: U+0029 ())*/
|
||||
{.w_px = 9, .glyph_index = 660}, /*Unicode: U+002a (*)*/
|
||||
{.w_px = 8, .glyph_index = 760}, /*Unicode: U+002b (+)*/
|
||||
{.w_px = 4, .glyph_index = 840}, /*Unicode: U+002c (,)*/
|
||||
{.w_px = 5, .glyph_index = 880}, /*Unicode: U+002d (-)*/
|
||||
{.w_px = 4, .glyph_index = 940}, /*Unicode: U+002e (.)*/
|
||||
{.w_px = 8, .glyph_index = 980}, /*Unicode: U+002f (/)*/
|
||||
{.w_px = 8, .glyph_index = 1060}, /*Unicode: U+0030 (0)*/
|
||||
{.w_px = 7, .glyph_index = 1140}, /*Unicode: U+0031 (1)*/
|
||||
{.w_px = 8, .glyph_index = 1220}, /*Unicode: U+0032 (2)*/
|
||||
{.w_px = 8, .glyph_index = 1300}, /*Unicode: U+0033 (3)*/
|
||||
{.w_px = 8, .glyph_index = 1380}, /*Unicode: U+0034 (4)*/
|
||||
{.w_px = 8, .glyph_index = 1460}, /*Unicode: U+0035 (5)*/
|
||||
{.w_px = 8, .glyph_index = 1540}, /*Unicode: U+0036 (6)*/
|
||||
{.w_px = 7, .glyph_index = 1620}, /*Unicode: U+0037 (7)*/
|
||||
{.w_px = 8, .glyph_index = 1700}, /*Unicode: U+0038 (8)*/
|
||||
{.w_px = 8, .glyph_index = 1780}, /*Unicode: U+0039 (9)*/
|
||||
{.w_px = 4, .glyph_index = 1860}, /*Unicode: U+003a (:)*/
|
||||
{.w_px = 4, .glyph_index = 1900}, /*Unicode: U+003b (;)*/
|
||||
{.w_px = 9, .glyph_index = 1940}, /*Unicode: U+003c (<)*/
|
||||
{.w_px = 8, .glyph_index = 2040}, /*Unicode: U+003d (=)*/
|
||||
{.w_px = 8, .glyph_index = 2120}, /*Unicode: U+003e (>)*/
|
||||
{.w_px = 8, .glyph_index = 2200}, /*Unicode: U+003f (?)*/
|
||||
{.w_px = 9, .glyph_index = 2280}, /*Unicode: U+0040 (@)*/
|
||||
{.w_px = 10, .glyph_index = 2380}, /*Unicode: U+0041 (A)*/
|
||||
{.w_px = 8, .glyph_index = 2480}, /*Unicode: U+0042 (B)*/
|
||||
{.w_px = 8, .glyph_index = 2560}, /*Unicode: U+0043 (C)*/
|
||||
{.w_px = 8, .glyph_index = 2640}, /*Unicode: U+0044 (D)*/
|
||||
{.w_px = 8, .glyph_index = 2720}, /*Unicode: U+0045 (E)*/
|
||||
{.w_px = 8, .glyph_index = 2800}, /*Unicode: U+0046 (F)*/
|
||||
{.w_px = 8, .glyph_index = 2880}, /*Unicode: U+0047 (G)*/
|
||||
{.w_px = 8, .glyph_index = 2960}, /*Unicode: U+0048 (H)*/
|
||||
{.w_px = 8, .glyph_index = 3040}, /*Unicode: U+0049 (I)*/
|
||||
{.w_px = 8, .glyph_index = 3120}, /*Unicode: U+004a (J)*/
|
||||
{.w_px = 9, .glyph_index = 3200}, /*Unicode: U+004b (K)*/
|
||||
{.w_px = 8, .glyph_index = 3300}, /*Unicode: U+004c (L)*/
|
||||
{.w_px = 9, .glyph_index = 3380}, /*Unicode: U+004d (M)*/
|
||||
{.w_px = 8, .glyph_index = 3480}, /*Unicode: U+004e (N)*/
|
||||
{.w_px = 8, .glyph_index = 3560}, /*Unicode: U+004f (O)*/
|
||||
{.w_px = 8, .glyph_index = 3640}, /*Unicode: U+0050 (P)*/
|
||||
{.w_px = 8, .glyph_index = 3720}, /*Unicode: U+0051 (Q)*/
|
||||
{.w_px = 8, .glyph_index = 3800}, /*Unicode: U+0052 (R)*/
|
||||
{.w_px = 8, .glyph_index = 3880}, /*Unicode: U+0053 (S)*/
|
||||
{.w_px = 8, .glyph_index = 3960}, /*Unicode: U+0054 (T)*/
|
||||
{.w_px = 8, .glyph_index = 4040}, /*Unicode: U+0055 (U)*/
|
||||
{.w_px = 9, .glyph_index = 4120}, /*Unicode: U+0056 (V)*/
|
||||
{.w_px = 9, .glyph_index = 4220}, /*Unicode: U+0057 (W)*/
|
||||
{.w_px = 10, .glyph_index = 4320}, /*Unicode: U+0058 (X)*/
|
||||
{.w_px = 10, .glyph_index = 4420}, /*Unicode: U+0059 (Y)*/
|
||||
{.w_px = 8, .glyph_index = 4520}, /*Unicode: U+005a (Z)*/
|
||||
{.w_px = 6, .glyph_index = 4600}, /*Unicode: U+005b ([)*/
|
||||
{.w_px = 8, .glyph_index = 4660}, /*Unicode: U+005c (\)*/
|
||||
{.w_px = 6, .glyph_index = 4740}, /*Unicode: U+005d (])*/
|
||||
{.w_px = 10, .glyph_index = 4800}, /*Unicode: U+005e (^)*/
|
||||
{.w_px = 10, .glyph_index = 4900}, /*Unicode: U+005f (_)*/
|
||||
{.w_px = 4, .glyph_index = 5000}, /*Unicode: U+0060 (`)*/
|
||||
{.w_px = 8, .glyph_index = 5040}, /*Unicode: U+0061 (a)*/
|
||||
{.w_px = 8, .glyph_index = 5120}, /*Unicode: U+0062 (b)*/
|
||||
{.w_px = 8, .glyph_index = 5200}, /*Unicode: U+0063 (c)*/
|
||||
{.w_px = 8, .glyph_index = 5280}, /*Unicode: U+0064 (d)*/
|
||||
{.w_px = 9, .glyph_index = 5360}, /*Unicode: U+0065 (e)*/
|
||||
{.w_px = 9, .glyph_index = 5460}, /*Unicode: U+0066 (f)*/
|
||||
{.w_px = 8, .glyph_index = 5560}, /*Unicode: U+0067 (g)*/
|
||||
{.w_px = 8, .glyph_index = 5640}, /*Unicode: U+0068 (h)*/
|
||||
{.w_px = 9, .glyph_index = 5720}, /*Unicode: U+0069 (i)*/
|
||||
{.w_px = 7, .glyph_index = 5820}, /*Unicode: U+006a (j)*/
|
||||
{.w_px = 9, .glyph_index = 5900}, /*Unicode: U+006b (k)*/
|
||||
{.w_px = 8, .glyph_index = 6000}, /*Unicode: U+006c (l)*/
|
||||
{.w_px = 8, .glyph_index = 6080}, /*Unicode: U+006d (m)*/
|
||||
{.w_px = 8, .glyph_index = 6160}, /*Unicode: U+006e (n)*/
|
||||
{.w_px = 8, .glyph_index = 6240}, /*Unicode: U+006f (o)*/
|
||||
{.w_px = 8, .glyph_index = 6320}, /*Unicode: U+0070 (p)*/
|
||||
{.w_px = 8, .glyph_index = 6400}, /*Unicode: U+0071 (q)*/
|
||||
{.w_px = 7, .glyph_index = 6480}, /*Unicode: U+0072 (r)*/
|
||||
{.w_px = 8, .glyph_index = 6560}, /*Unicode: U+0073 (s)*/
|
||||
{.w_px = 8, .glyph_index = 6640}, /*Unicode: U+0074 (t)*/
|
||||
{.w_px = 8, .glyph_index = 6720}, /*Unicode: U+0075 (u)*/
|
||||
{.w_px = 9, .glyph_index = 6800}, /*Unicode: U+0076 (v)*/
|
||||
{.w_px = 10, .glyph_index = 6900}, /*Unicode: U+0077 (w)*/
|
||||
{.w_px = 10, .glyph_index = 7000}, /*Unicode: U+0078 (x)*/
|
||||
{.w_px = 9, .glyph_index = 7100}, /*Unicode: U+0079 (y)*/
|
||||
{.w_px = 8, .glyph_index = 7200}, /*Unicode: U+007a (z)*/
|
||||
{.w_px = 7, .glyph_index = 7280}, /*Unicode: U+007b ({)*/
|
||||
{.w_px = 2, .glyph_index = 7360}, /*Unicode: U+007c (|)*/
|
||||
{.w_px = 8, .glyph_index = 7380}, /*Unicode: U+007d (})*/
|
||||
{.w_px = 9, .glyph_index = 7460}, /*Unicode: U+007e (~)*/
|
||||
|
||||
#elif USE_UBUNTU_MONO == 8
|
||||
{.w_px = 6, .glyph_index = 0}, /*Unicode: U+0020 ( )*/
|
||||
{.w_px = 2, .glyph_index = 120}, /*Unicode: U+0021 (!)*/
|
||||
{.w_px = 5, .glyph_index = 160}, /*Unicode: U+0022 (")*/
|
||||
{.w_px = 10, .glyph_index = 260}, /*Unicode: U+0023 (#)*/
|
||||
{.w_px = 8, .glyph_index = 460}, /*Unicode: U+0024 ($)*/
|
||||
{.w_px = 10, .glyph_index = 620}, /*Unicode: U+0025 (%)*/
|
||||
{.w_px = 10, .glyph_index = 820}, /*Unicode: U+0026 (&)*/
|
||||
{.w_px = 2, .glyph_index = 1020}, /*Unicode: U+0027 (')*/
|
||||
{.w_px = 6, .glyph_index = 1060}, /*Unicode: U+0028 (()*/
|
||||
{.w_px = 6, .glyph_index = 1180}, /*Unicode: U+0029 ())*/
|
||||
{.w_px = 9, .glyph_index = 1300}, /*Unicode: U+002a (*)*/
|
||||
{.w_px = 8, .glyph_index = 1480}, /*Unicode: U+002b (+)*/
|
||||
{.w_px = 4, .glyph_index = 1640}, /*Unicode: U+002c (,)*/
|
||||
{.w_px = 5, .glyph_index = 1720}, /*Unicode: U+002d (-)*/
|
||||
{.w_px = 4, .glyph_index = 1820}, /*Unicode: U+002e (.)*/
|
||||
{.w_px = 8, .glyph_index = 1900}, /*Unicode: U+002f (/)*/
|
||||
{.w_px = 8, .glyph_index = 2060}, /*Unicode: U+0030 (0)*/
|
||||
{.w_px = 7, .glyph_index = 2220}, /*Unicode: U+0031 (1)*/
|
||||
{.w_px = 8, .glyph_index = 2360}, /*Unicode: U+0032 (2)*/
|
||||
{.w_px = 8, .glyph_index = 2520}, /*Unicode: U+0033 (3)*/
|
||||
{.w_px = 8, .glyph_index = 2680}, /*Unicode: U+0034 (4)*/
|
||||
{.w_px = 8, .glyph_index = 2840}, /*Unicode: U+0035 (5)*/
|
||||
{.w_px = 8, .glyph_index = 3000}, /*Unicode: U+0036 (6)*/
|
||||
{.w_px = 7, .glyph_index = 3160}, /*Unicode: U+0037 (7)*/
|
||||
{.w_px = 8, .glyph_index = 3300}, /*Unicode: U+0038 (8)*/
|
||||
{.w_px = 8, .glyph_index = 3460}, /*Unicode: U+0039 (9)*/
|
||||
{.w_px = 4, .glyph_index = 3620}, /*Unicode: U+003a (:)*/
|
||||
{.w_px = 4, .glyph_index = 3700}, /*Unicode: U+003b (;)*/
|
||||
{.w_px = 9, .glyph_index = 3780}, /*Unicode: U+003c (<)*/
|
||||
{.w_px = 8, .glyph_index = 3960}, /*Unicode: U+003d (=)*/
|
||||
{.w_px = 8, .glyph_index = 4120}, /*Unicode: U+003e (>)*/
|
||||
{.w_px = 8, .glyph_index = 4280}, /*Unicode: U+003f (?)*/
|
||||
{.w_px = 9, .glyph_index = 4440}, /*Unicode: U+0040 (@)*/
|
||||
{.w_px = 10, .glyph_index = 4620}, /*Unicode: U+0041 (A)*/
|
||||
{.w_px = 8, .glyph_index = 4820}, /*Unicode: U+0042 (B)*/
|
||||
{.w_px = 8, .glyph_index = 4980}, /*Unicode: U+0043 (C)*/
|
||||
{.w_px = 8, .glyph_index = 5140}, /*Unicode: U+0044 (D)*/
|
||||
{.w_px = 8, .glyph_index = 5300}, /*Unicode: U+0045 (E)*/
|
||||
{.w_px = 8, .glyph_index = 5460}, /*Unicode: U+0046 (F)*/
|
||||
{.w_px = 8, .glyph_index = 5620}, /*Unicode: U+0047 (G)*/
|
||||
{.w_px = 8, .glyph_index = 5780}, /*Unicode: U+0048 (H)*/
|
||||
{.w_px = 8, .glyph_index = 5940}, /*Unicode: U+0049 (I)*/
|
||||
{.w_px = 8, .glyph_index = 6100}, /*Unicode: U+004a (J)*/
|
||||
{.w_px = 9, .glyph_index = 6260}, /*Unicode: U+004b (K)*/
|
||||
{.w_px = 8, .glyph_index = 6440}, /*Unicode: U+004c (L)*/
|
||||
{.w_px = 9, .glyph_index = 6600}, /*Unicode: U+004d (M)*/
|
||||
{.w_px = 8, .glyph_index = 6780}, /*Unicode: U+004e (N)*/
|
||||
{.w_px = 8, .glyph_index = 6940}, /*Unicode: U+004f (O)*/
|
||||
{.w_px = 8, .glyph_index = 7100}, /*Unicode: U+0050 (P)*/
|
||||
{.w_px = 8, .glyph_index = 7260}, /*Unicode: U+0051 (Q)*/
|
||||
{.w_px = 8, .glyph_index = 7420}, /*Unicode: U+0052 (R)*/
|
||||
{.w_px = 8, .glyph_index = 7580}, /*Unicode: U+0053 (S)*/
|
||||
{.w_px = 8, .glyph_index = 7740}, /*Unicode: U+0054 (T)*/
|
||||
{.w_px = 8, .glyph_index = 7900}, /*Unicode: U+0055 (U)*/
|
||||
{.w_px = 9, .glyph_index = 8060}, /*Unicode: U+0056 (V)*/
|
||||
{.w_px = 9, .glyph_index = 8240}, /*Unicode: U+0057 (W)*/
|
||||
{.w_px = 10, .glyph_index = 8420}, /*Unicode: U+0058 (X)*/
|
||||
{.w_px = 10, .glyph_index = 8620}, /*Unicode: U+0059 (Y)*/
|
||||
{.w_px = 8, .glyph_index = 8820}, /*Unicode: U+005a (Z)*/
|
||||
{.w_px = 6, .glyph_index = 8980}, /*Unicode: U+005b ([)*/
|
||||
{.w_px = 8, .glyph_index = 9100}, /*Unicode: U+005c (\)*/
|
||||
{.w_px = 6, .glyph_index = 9260}, /*Unicode: U+005d (])*/
|
||||
{.w_px = 10, .glyph_index = 9380}, /*Unicode: U+005e (^)*/
|
||||
{.w_px = 10, .glyph_index = 9580}, /*Unicode: U+005f (_)*/
|
||||
{.w_px = 4, .glyph_index = 9780}, /*Unicode: U+0060 (`)*/
|
||||
{.w_px = 8, .glyph_index = 9860}, /*Unicode: U+0061 (a)*/
|
||||
{.w_px = 8, .glyph_index = 10020}, /*Unicode: U+0062 (b)*/
|
||||
{.w_px = 8, .glyph_index = 10180}, /*Unicode: U+0063 (c)*/
|
||||
{.w_px = 8, .glyph_index = 10340}, /*Unicode: U+0064 (d)*/
|
||||
{.w_px = 9, .glyph_index = 10500}, /*Unicode: U+0065 (e)*/
|
||||
{.w_px = 9, .glyph_index = 10680}, /*Unicode: U+0066 (f)*/
|
||||
{.w_px = 8, .glyph_index = 10860}, /*Unicode: U+0067 (g)*/
|
||||
{.w_px = 8, .glyph_index = 11020}, /*Unicode: U+0068 (h)*/
|
||||
{.w_px = 9, .glyph_index = 11180}, /*Unicode: U+0069 (i)*/
|
||||
{.w_px = 7, .glyph_index = 11360}, /*Unicode: U+006a (j)*/
|
||||
{.w_px = 9, .glyph_index = 11500}, /*Unicode: U+006b (k)*/
|
||||
{.w_px = 8, .glyph_index = 11680}, /*Unicode: U+006c (l)*/
|
||||
{.w_px = 8, .glyph_index = 11840}, /*Unicode: U+006d (m)*/
|
||||
{.w_px = 8, .glyph_index = 12000}, /*Unicode: U+006e (n)*/
|
||||
{.w_px = 8, .glyph_index = 12160}, /*Unicode: U+006f (o)*/
|
||||
{.w_px = 8, .glyph_index = 12320}, /*Unicode: U+0070 (p)*/
|
||||
{.w_px = 8, .glyph_index = 12480}, /*Unicode: U+0071 (q)*/
|
||||
{.w_px = 7, .glyph_index = 12640}, /*Unicode: U+0072 (r)*/
|
||||
{.w_px = 8, .glyph_index = 12780}, /*Unicode: U+0073 (s)*/
|
||||
{.w_px = 8, .glyph_index = 12940}, /*Unicode: U+0074 (t)*/
|
||||
{.w_px = 8, .glyph_index = 13100}, /*Unicode: U+0075 (u)*/
|
||||
{.w_px = 9, .glyph_index = 13260}, /*Unicode: U+0076 (v)*/
|
||||
{.w_px = 10, .glyph_index = 13440}, /*Unicode: U+0077 (w)*/
|
||||
{.w_px = 10, .glyph_index = 13640}, /*Unicode: U+0078 (x)*/
|
||||
{.w_px = 9, .glyph_index = 13840}, /*Unicode: U+0079 (y)*/
|
||||
{.w_px = 8, .glyph_index = 14020}, /*Unicode: U+007a (z)*/
|
||||
{.w_px = 7, .glyph_index = 14180}, /*Unicode: U+007b ({)*/
|
||||
{.w_px = 2, .glyph_index = 14320}, /*Unicode: U+007c (|)*/
|
||||
{.w_px = 8, .glyph_index = 14360}, /*Unicode: U+007d (})*/
|
||||
{.w_px = 9, .glyph_index = 14520}, /*Unicode: U+007e (~)*/
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
lv_font_t ubuntu_mono =
|
||||
{
|
||||
.unicode_first = 32, /*First Unicode letter in this font*/
|
||||
.unicode_last = 126, /*Last Unicode letter in this font*/
|
||||
.h_px = 20, /*Font height in pixels*/
|
||||
//.glyph_bitmap = ubuntu_mono_glyph_bitmap, /*Bitmap of glyphs*/
|
||||
.glyph_bitmap = (const uint8_t *)(NYX_RES_ADDR),
|
||||
.glyph_dsc = ubuntu_mono_glyph_dsc, /*Description of glyphs*/
|
||||
.glyph_cnt = 95, /*Number of glyphs in the font*/
|
||||
.unicode_list = NULL, /*Every character in the font from 'unicode_first' to 'unicode_last'*/
|
||||
.get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/
|
||||
.get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/
|
||||
#if USE_UBUNTU_MONO == 4
|
||||
.bpp = 4, /*Bit per pixel*/
|
||||
#elif USE_UBUNTU_MONO == 8
|
||||
.bpp = 8, /*Bit per pixel*/
|
||||
#endif
|
||||
.monospace = 10, /*Fix width (0: if not used)*/
|
||||
.next_page = NULL, /*Pointer to a font extension*/
|
||||
};
|
||||
|
||||
#endif /*USE_UBUNTU_MONO*/
|
40
bdk/libs/lvgl/lv_hal/lv_hal.h
Normal file
40
bdk/libs/lvgl/lv_hal/lv_hal.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* @file hal.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HAL_H
|
||||
#define HAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_hal_disp.h"
|
||||
#include "lv_hal_indev.h"
|
||||
#include "lv_hal_tick.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
8
bdk/libs/lvgl/lv_hal/lv_hal.mk
Normal file
8
bdk/libs/lvgl/lv_hal/lv_hal.mk
Normal file
|
@ -0,0 +1,8 @@
|
|||
CSRCS += lv_hal_disp.c
|
||||
CSRCS += lv_hal_indev.c
|
||||
CSRCS += lv_hal_tick.c
|
||||
|
||||
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_hal
|
||||
VPATH += :$(LVGL_DIR)/lvgl/lv_hal
|
||||
|
||||
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal"
|
242
bdk/libs/lvgl/lv_hal/lv_hal_disp.c
Normal file
242
bdk/libs/lvgl/lv_hal/lv_hal_disp.c
Normal file
|
@ -0,0 +1,242 @@
|
|||
|
||||
/**
|
||||
* @file hal_disp.c
|
||||
*
|
||||
* @description HAL layer for display driver
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "../lv_hal/lv_hal_disp.h"
|
||||
#include "../lv_misc/lv_mem.h"
|
||||
#include "../lv_core/lv_obj.h"
|
||||
#include "../lv_misc/lv_gc.h"
|
||||
|
||||
#if defined(LV_GC_INCLUDE)
|
||||
# include LV_GC_INCLUDE
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_disp_t * active;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize a display driver with default values.
|
||||
* It is used to surly have known values in the fields ant not memory junk.
|
||||
* After it you can set the fields.
|
||||
* @param driver pointer to driver variable to initialize
|
||||
*/
|
||||
void lv_disp_drv_init(lv_disp_drv_t * driver)
|
||||
{
|
||||
driver->disp_fill = NULL;
|
||||
driver->disp_map = NULL;
|
||||
driver->disp_flush = NULL;
|
||||
|
||||
#if USE_LV_GPU
|
||||
driver->mem_blend = NULL;
|
||||
driver->mem_fill = NULL;
|
||||
#endif
|
||||
|
||||
#if LV_VDB_SIZE
|
||||
driver->vdb_wr = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an initialized display driver.
|
||||
* Automatically set the first display as active.
|
||||
* @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable)
|
||||
* @return pointer to the new display or NULL on error
|
||||
*/
|
||||
lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
|
||||
{
|
||||
lv_disp_t * node;
|
||||
|
||||
node = lv_mem_alloc(sizeof(lv_disp_t));
|
||||
lv_mem_assert(node);
|
||||
if(node == NULL) return NULL;
|
||||
|
||||
memcpy(&node->driver, driver, sizeof(lv_disp_drv_t));
|
||||
node->next = NULL;
|
||||
|
||||
/* Set first display as active by default */
|
||||
if(LV_GC_ROOT(_lv_disp_list) == NULL) {
|
||||
LV_GC_ROOT(_lv_disp_list) = node;
|
||||
active = node;
|
||||
lv_obj_invalidate(lv_scr_act());
|
||||
} else {
|
||||
((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next = node;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the active display
|
||||
* @param disp pointer to a display (return value of 'lv_disp_register')
|
||||
*/
|
||||
void lv_disp_set_active(lv_disp_t * disp)
|
||||
{
|
||||
active = disp;
|
||||
lv_obj_invalidate(lv_scr_act());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a pointer to the active display
|
||||
* @return pointer to the active display
|
||||
*/
|
||||
lv_disp_t * lv_disp_get_active(void)
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next display.
|
||||
* @param disp pointer to the current display. NULL to initialize.
|
||||
* @return the next display or NULL if no more. Give the first display when the parameter is NULL
|
||||
*/
|
||||
lv_disp_t * lv_disp_next(lv_disp_t * disp)
|
||||
{
|
||||
if(disp == NULL) {
|
||||
return LV_GC_ROOT(_lv_disp_list);
|
||||
} else {
|
||||
if(((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next == NULL) return NULL;
|
||||
else return ((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the content of the internal buffer (VDB) to the display
|
||||
* @param x1 left coordinate of the rectangle
|
||||
* @param x2 right coordinate of the rectangle
|
||||
* @param y1 top coordinate of the rectangle
|
||||
* @param y2 bottom coordinate of the rectangle
|
||||
* @param color_p fill color
|
||||
*/
|
||||
void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
|
||||
{
|
||||
if(active == NULL) return;
|
||||
if(active->driver.disp_fill != NULL) active->driver.disp_fill(x1, y1, x2, y2, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill a rectangular area with a color on the active display
|
||||
* @param x1 left coordinate of the rectangle
|
||||
* @param x2 right coordinate of the rectangle
|
||||
* @param y1 top coordinate of the rectangle
|
||||
* @param y2 bottom coordinate of the rectangle
|
||||
* @param color_p pointer to an array of colors
|
||||
*/
|
||||
void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t * color_p)
|
||||
{
|
||||
if(active == NULL) return;
|
||||
if(active->driver.disp_flush != NULL) {
|
||||
|
||||
LV_LOG_TRACE("disp flush started");
|
||||
active->driver.disp_flush(x1, y1, x2, y2, color_p);
|
||||
LV_LOG_TRACE("disp flush ready");
|
||||
|
||||
} else {
|
||||
LV_LOG_WARN("disp flush function registered");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a color map to a rectangular area on the active display
|
||||
* @param x1 left coordinate of the rectangle
|
||||
* @param x2 right coordinate of the rectangle
|
||||
* @param y1 top coordinate of the rectangle
|
||||
* @param y2 bottom coordinate of the rectangle
|
||||
* @param color_map pointer to an array of colors
|
||||
*/
|
||||
void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map)
|
||||
{
|
||||
if(active == NULL) return;
|
||||
if(active->driver.disp_map != NULL) active->driver.disp_map(x1, y1, x2, y2, color_map);
|
||||
}
|
||||
|
||||
#if USE_LV_GPU
|
||||
|
||||
/**
|
||||
* Blend pixels to a destination memory from a source memory
|
||||
* In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available)
|
||||
* @param dest a memory address. Blend 'src' here.
|
||||
* @param src pointer to pixel map. Blend it to 'dest'.
|
||||
* @param length number of pixels in 'src'
|
||||
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
|
||||
*/
|
||||
void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
|
||||
{
|
||||
if(active == NULL) return;
|
||||
if(active->driver.mem_blend != NULL) active->driver.mem_blend(dest, src, length, opa);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill a memory with a color (GPUs may support it)
|
||||
* In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available)
|
||||
* @param dest a memory address. Copy 'src' here.
|
||||
* @param src pointer to pixel map. Copy it to 'dest'.
|
||||
* @param length number of pixels in 'src'
|
||||
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
|
||||
*/
|
||||
void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color)
|
||||
{
|
||||
if(active == NULL) return;
|
||||
if(active->driver.mem_fill != NULL) active->driver.mem_fill(dest, length, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows if memory blending (by GPU) is supported or not
|
||||
* @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver
|
||||
*/
|
||||
bool lv_disp_is_mem_blend_supported(void)
|
||||
{
|
||||
if(active == NULL) return false;
|
||||
if(active->driver.mem_blend) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows if memory fill (by GPU) is supported or not
|
||||
* @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver
|
||||
*/
|
||||
bool lv_disp_is_mem_fill_supported(void)
|
||||
{
|
||||
if(active == NULL) return false;
|
||||
if(active->driver.mem_fill) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
173
bdk/libs/lvgl/lv_hal/lv_hal_disp.h
Normal file
173
bdk/libs/lvgl/lv_hal/lv_hal_disp.h
Normal file
|
@ -0,0 +1,173 @@
|
|||
/**
|
||||
* @file hal_disp.h
|
||||
*
|
||||
* @description Display Driver HAL interface header file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HAL_DISP_H
|
||||
#define HAL_DISP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stdint.h>
|
||||
#include "lv_hal.h"
|
||||
#include "../lv_misc/lv_color.h"
|
||||
#include "../lv_misc/lv_area.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Display Driver structure to be registered by HAL
|
||||
*/
|
||||
typedef struct _disp_drv_t {
|
||||
/*Write the internal buffer (VDB) to the display. 'lv_flush_ready()' has to be called when finished*/
|
||||
void (*disp_flush)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
|
||||
|
||||
/*Fill an area with a color on the display*/
|
||||
void (*disp_fill)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
|
||||
|
||||
/*Write pixel map (e.g. image) to the display*/
|
||||
void (*disp_map)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p);
|
||||
|
||||
/*Optional interface functions to use GPU*/
|
||||
#if USE_LV_GPU
|
||||
/*Blend two memories using opacity (GPU only)*/
|
||||
void (*mem_blend)(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
|
||||
|
||||
/*Fill a memory with a color (GPU only)*/
|
||||
void (*mem_fill)(lv_color_t * dest, uint32_t length, lv_color_t color);
|
||||
#endif
|
||||
|
||||
#if LV_VDB_SIZE
|
||||
/*Optional: Set a pixel in a buffer according to the requirements of the display*/
|
||||
void (*vdb_wr)(uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, lv_color_t color, lv_opa_t opa);
|
||||
#endif
|
||||
} lv_disp_drv_t;
|
||||
|
||||
typedef struct _disp_t {
|
||||
lv_disp_drv_t driver;
|
||||
struct _disp_t *next;
|
||||
} lv_disp_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize a display driver with default values.
|
||||
* It is used to surly have known values in the fields ant not memory junk.
|
||||
* After it you can set the fields.
|
||||
* @param driver pointer to driver variable to initialize
|
||||
*/
|
||||
void lv_disp_drv_init(lv_disp_drv_t *driver);
|
||||
|
||||
/**
|
||||
* Register an initialized display driver.
|
||||
* Automatically set the first display as active.
|
||||
* @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable)
|
||||
* @return pointer to the new display or NULL on error
|
||||
*/
|
||||
lv_disp_t * lv_disp_drv_register(lv_disp_drv_t *driver);
|
||||
|
||||
/**
|
||||
* Set the active display
|
||||
* @param disp pointer to a display (return value of 'lv_disp_register')
|
||||
*/
|
||||
void lv_disp_set_active(lv_disp_t * disp);
|
||||
|
||||
/**
|
||||
* Get a pointer to the active display
|
||||
* @return pointer to the active display
|
||||
*/
|
||||
lv_disp_t * lv_disp_get_active(void);
|
||||
|
||||
/**
|
||||
* Get the next display.
|
||||
* @param disp pointer to the current display. NULL to initialize.
|
||||
* @return the next display or NULL if no more. Give the first display when the parameter is NULL
|
||||
*/
|
||||
lv_disp_t * lv_disp_next(lv_disp_t * disp);
|
||||
|
||||
/**
|
||||
* Fill a rectangular area with a color on the active display
|
||||
* @param x1 left coordinate of the rectangle
|
||||
* @param x2 right coordinate of the rectangle
|
||||
* @param y1 top coordinate of the rectangle
|
||||
* @param y2 bottom coordinate of the rectangle
|
||||
* @param color_p pointer to an array of colors
|
||||
*/
|
||||
void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t *color_p);
|
||||
|
||||
/**
|
||||
* Fill a rectangular area with a color on the active display
|
||||
* @param x1 left coordinate of the rectangle
|
||||
* @param x2 right coordinate of the rectangle
|
||||
* @param y1 top coordinate of the rectangle
|
||||
* @param y2 bottom coordinate of the rectangle
|
||||
* @param color fill color
|
||||
*/
|
||||
void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color);
|
||||
|
||||
/**
|
||||
* Put a color map to a rectangular area on the active display
|
||||
* @param x1 left coordinate of the rectangle
|
||||
* @param x2 right coordinate of the rectangle
|
||||
* @param y1 top coordinate of the rectangle
|
||||
* @param y2 bottom coordinate of the rectangle
|
||||
* @param color_map pointer to an array of colors
|
||||
*/
|
||||
void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map);
|
||||
|
||||
#if USE_LV_GPU
|
||||
/**
|
||||
* Blend pixels to a destination memory from a source memory
|
||||
* In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available)
|
||||
* @param dest a memory address. Blend 'src' here.
|
||||
* @param src pointer to pixel map. Blend it to 'dest'.
|
||||
* @param length number of pixels in 'src'
|
||||
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
|
||||
*/
|
||||
void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);
|
||||
|
||||
/**
|
||||
* Fill a memory with a color (GPUs may support it)
|
||||
* In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available)
|
||||
* @param dest a memory address. Copy 'src' here.
|
||||
* @param src pointer to pixel map. Copy it to 'dest'.
|
||||
* @param length number of pixels in 'src'
|
||||
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
|
||||
*/
|
||||
void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color);
|
||||
/**
|
||||
* Shows if memory blending (by GPU) is supported or not
|
||||
* @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver
|
||||
*/
|
||||
bool lv_disp_is_mem_blend_supported(void);
|
||||
|
||||
/**
|
||||
* Shows if memory fill (by GPU) is supported or not
|
||||
* @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver
|
||||
*/
|
||||
bool lv_disp_is_mem_fill_supported(void);
|
||||
#endif
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
135
bdk/libs/lvgl/lv_hal/lv_hal_indev.c
Normal file
135
bdk/libs/lvgl/lv_hal/lv_hal_indev.c
Normal file
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
* @file hal_indev.c
|
||||
*
|
||||
* @description Input device HAL interface
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../lv_hal/lv_hal_indev.h"
|
||||
#include "../lv_misc/lv_mem.h"
|
||||
#include "../lv_misc/lv_gc.h"
|
||||
|
||||
#if defined(LV_GC_INCLUDE)
|
||||
# include LV_GC_INCLUDE
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize an input device driver with default values.
|
||||
* It is used to surly have known values in the fields ant not memory junk.
|
||||
* After it you can set the fields.
|
||||
* @param driver pointer to driver variable to initialize
|
||||
*/
|
||||
void lv_indev_drv_init(lv_indev_drv_t * driver)
|
||||
{
|
||||
driver->read = NULL;
|
||||
driver->type = LV_INDEV_TYPE_NONE;
|
||||
driver->user_data = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an initialized input device driver.
|
||||
* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
|
||||
* @return pointer to the new input device or NULL on error
|
||||
*/
|
||||
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver)
|
||||
{
|
||||
lv_indev_t * node;
|
||||
|
||||
node = lv_mem_alloc(sizeof(lv_indev_t));
|
||||
if(!node) return NULL;
|
||||
|
||||
memset(node, 0, sizeof(lv_indev_t));
|
||||
memcpy(&node->driver, driver, sizeof(lv_indev_drv_t));
|
||||
|
||||
node->next = NULL;
|
||||
node->proc.reset_query = 1;
|
||||
node->cursor = NULL;
|
||||
node->group = NULL;
|
||||
node->btn_points = NULL;
|
||||
|
||||
if(LV_GC_ROOT(_lv_indev_list) == NULL) {
|
||||
LV_GC_ROOT(_lv_indev_list) = node;
|
||||
} else {
|
||||
lv_indev_t * last = LV_GC_ROOT(_lv_indev_list);
|
||||
while(last->next)
|
||||
last = last->next;
|
||||
|
||||
last->next = node;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next input device.
|
||||
* @param indev pointer to the current input device. NULL to initialize.
|
||||
* @return the next input devise or NULL if no more. Give the first input device when the parameter is NULL
|
||||
*/
|
||||
lv_indev_t * lv_indev_next(lv_indev_t * indev)
|
||||
{
|
||||
|
||||
if(indev == NULL) {
|
||||
return LV_GC_ROOT(_lv_indev_list);
|
||||
} else {
|
||||
if(indev->next == NULL) return NULL;
|
||||
else return indev->next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from an input device.
|
||||
* @param indev pointer to an input device
|
||||
* @param data input device will write its data here
|
||||
* @return false: no more data; true: there more data to read (buffered)
|
||||
*/
|
||||
bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
|
||||
{
|
||||
bool cont = false;
|
||||
|
||||
memset(data, 0, sizeof(lv_indev_data_t));
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
|
||||
if(indev->driver.read) {
|
||||
data->user_data = indev->driver.user_data;
|
||||
|
||||
LV_LOG_TRACE("idnev read started");
|
||||
cont = indev->driver.read(data);
|
||||
LV_LOG_TRACE("idnev read finished");
|
||||
} else {
|
||||
LV_LOG_WARN("indev function registered");
|
||||
}
|
||||
|
||||
return cont;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
166
bdk/libs/lvgl/lv_hal/lv_hal_indev.h
Normal file
166
bdk/libs/lvgl/lv_hal/lv_hal_indev.h
Normal file
|
@ -0,0 +1,166 @@
|
|||
/**
|
||||
* @file hal_indev.h
|
||||
*
|
||||
* @description Input Device HAL interface layer header file
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HAL_INDEV_H
|
||||
#define HAL_INDEV_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stdint.h>
|
||||
#include "lv_hal.h"
|
||||
#include <utils/types.h>
|
||||
#include "../lv_misc/lv_area.h"
|
||||
#include "../lv_core/lv_obj.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Possible input device types*/
|
||||
enum {
|
||||
LV_INDEV_TYPE_NONE, /*Show uninitialized state*/
|
||||
LV_INDEV_TYPE_POINTER, /*Touch pad, mouse, external button*/
|
||||
LV_INDEV_TYPE_KEYPAD, /*Keypad or keyboard*/
|
||||
LV_INDEV_TYPE_BUTTON, /*External (hardware button) which is assinged to a specific point of the screen*/
|
||||
LV_INDEV_TYPE_ENCODER, /*Encoder with only Left, Right turn and a Button*/
|
||||
};
|
||||
typedef uint8_t lv_hal_indev_type_t;
|
||||
|
||||
/*States for input devices*/
|
||||
enum {
|
||||
LV_INDEV_STATE_REL = 0,
|
||||
LV_INDEV_STATE_PR
|
||||
};
|
||||
typedef uint8_t lv_indev_state_t;
|
||||
|
||||
/*Data type when an input device is read */
|
||||
typedef struct {
|
||||
union {
|
||||
lv_point_t point; /*For LV_INDEV_TYPE_POINTER the currently pressed point*/
|
||||
uint32_t key; /*For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
|
||||
uint32_t btn; /*For LV_INDEV_TYPE_BUTTON the currently pressed button*/
|
||||
int16_t enc_diff; /*For LV_INDEV_TYPE_ENCODER number of steps since the previous read*/
|
||||
};
|
||||
void *user_data; /*'lv_indev_drv_t.priv' for this driver*/
|
||||
lv_indev_state_t state; /*LV_INDEV_STATE_REL or LV_INDEV_STATE_PR*/
|
||||
} lv_indev_data_t;
|
||||
|
||||
/*Initialized by the user and registered by 'lv_indev_add()'*/
|
||||
typedef struct {
|
||||
lv_hal_indev_type_t type; /*Input device type*/
|
||||
bool (*read)(lv_indev_data_t *data); /*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/
|
||||
void *user_data; /*Pointer to user defined data, passed in 'lv_indev_data_t' on read*/
|
||||
} lv_indev_drv_t;
|
||||
|
||||
struct _lv_obj_t;
|
||||
|
||||
/*Run time data of input devices*/
|
||||
typedef struct _lv_indev_proc_t {
|
||||
lv_indev_state_t state;
|
||||
union {
|
||||
struct { /*Pointer and button data*/
|
||||
lv_point_t act_point;
|
||||
lv_point_t last_point;
|
||||
lv_point_t vect;
|
||||
lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DRAG_LIMIT*/
|
||||
struct _lv_obj_t * act_obj;
|
||||
struct _lv_obj_t * last_obj;
|
||||
|
||||
/*Flags*/
|
||||
uint8_t drag_range_out :1;
|
||||
uint8_t drag_in_prog :1;
|
||||
uint8_t wait_unil_release :1;
|
||||
};
|
||||
struct { /*Keypad data*/
|
||||
lv_indev_state_t last_state;
|
||||
uint32_t last_key;
|
||||
};
|
||||
};
|
||||
|
||||
uint32_t pr_timestamp; /*Pressed time stamp*/
|
||||
uint32_t longpr_rep_timestamp; /*Long press repeat time stamp*/
|
||||
|
||||
/*Flags*/
|
||||
uint8_t long_pr_sent :1;
|
||||
uint8_t reset_query :1;
|
||||
uint8_t disabled :1;
|
||||
} lv_indev_proc_t;
|
||||
|
||||
struct _lv_indev_t;
|
||||
|
||||
typedef void (*lv_indev_feedback_t)(struct _lv_indev_t *, lv_signal_t);
|
||||
|
||||
struct _lv_obj_t;
|
||||
struct _lv_group_t;
|
||||
|
||||
/*The main input device descriptor with driver, runtime data ('proc') and some additional information*/
|
||||
typedef struct _lv_indev_t {
|
||||
lv_indev_drv_t driver;
|
||||
lv_indev_proc_t proc;
|
||||
lv_indev_feedback_t feedback;
|
||||
uint32_t last_activity_time;
|
||||
union {
|
||||
struct _lv_obj_t *cursor; /*Cursor for LV_INPUT_TYPE_POINTER*/
|
||||
struct _lv_group_t *group; /*Keypad destination group*/
|
||||
const lv_point_t * btn_points; /*Array points assigned to the button ()screen will be pressed here by the buttons*/
|
||||
|
||||
};
|
||||
struct _lv_indev_t *next;
|
||||
} lv_indev_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize an input device driver with default values.
|
||||
* It is used to surly have known values in the fields ant not memory junk.
|
||||
* After it you can set the fields.
|
||||
* @param driver pointer to driver variable to initialize
|
||||
*/
|
||||
void lv_indev_drv_init(lv_indev_drv_t *driver);
|
||||
|
||||
/**
|
||||
* Register an initialized input device driver.
|
||||
* @param driver pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
|
||||
* @return pointer to the new input device or NULL on error
|
||||
*/
|
||||
lv_indev_t * lv_indev_drv_register(lv_indev_drv_t *driver);
|
||||
|
||||
/**
|
||||
* Get the next input device.
|
||||
* @param indev pointer to the current input device. NULL to initialize.
|
||||
* @return the next input devise or NULL if no more. Gives the first input device when the parameter is NULL
|
||||
*/
|
||||
lv_indev_t * lv_indev_next(lv_indev_t * indev);
|
||||
|
||||
/**
|
||||
* Read data from an input device.
|
||||
* @param indev pointer to an input device
|
||||
* @param data input device will write its data here
|
||||
* @return false: no more data; true: there more data to read (buffered)
|
||||
*/
|
||||
bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t *data);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
100
bdk/libs/lvgl/lv_hal/lv_hal_tick.c
Normal file
100
bdk/libs/lvgl/lv_hal/lv_hal_tick.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/**
|
||||
* @file systick.c
|
||||
* Provide access to the system tick with 1 millisecond resolution
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include "lv_hal_tick.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#if LV_TICK_CUSTOM == 1
|
||||
#include LV_TICK_CUSTOM_INCLUDE
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static uint32_t sys_time = 0;
|
||||
static volatile uint8_t tick_irq_flag;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* You have to call this function periodically
|
||||
* @param tick_period the call period of this function in milliseconds
|
||||
*/
|
||||
LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period)
|
||||
{
|
||||
tick_irq_flag = 0;
|
||||
sys_time += tick_period;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the elapsed milliseconds since start up
|
||||
* @return the elapsed milliseconds
|
||||
*/
|
||||
uint32_t lv_tick_get(void)
|
||||
{
|
||||
#if LV_TICK_CUSTOM == 0
|
||||
uint32_t result;
|
||||
do {
|
||||
tick_irq_flag = 1;
|
||||
result = sys_time;
|
||||
} while(!tick_irq_flag); /*'lv_tick_inc()' clears this flag which can be in an interrupt. Continue until make a non interrupted cycle */
|
||||
|
||||
return result;
|
||||
#else
|
||||
return LV_TICK_CUSTOM_SYS_TIME_EXPR;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the elapsed milliseconds since a previous time stamp
|
||||
* @param prev_tick a previous time stamp (return value of systick_get() )
|
||||
* @return the elapsed milliseconds since 'prev_tick'
|
||||
*/
|
||||
uint32_t lv_tick_elaps(uint32_t prev_tick)
|
||||
{
|
||||
uint32_t act_time = lv_tick_get();
|
||||
|
||||
/*If there is no overflow in sys_time simple subtract*/
|
||||
if(act_time >= prev_tick) {
|
||||
prev_tick = act_time - prev_tick;
|
||||
} else {
|
||||
prev_tick = UINT32_MAX - prev_tick + 1;
|
||||
prev_tick += act_time;
|
||||
}
|
||||
|
||||
return prev_tick;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
65
bdk/libs/lvgl/lv_hal/lv_hal_tick.h
Normal file
65
bdk/libs/lvgl/lv_hal/lv_hal_tick.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @file lv_hal_tick.h
|
||||
* Provide access to the system tick with 1 millisecond resolution
|
||||
*/
|
||||
|
||||
#ifndef LV_HAL_TICK_H
|
||||
#define LV_HAL_TICK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef LV_ATTRIBUTE_TICK_INC
|
||||
#define LV_ATTRIBUTE_TICK_INC
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* You have to call this function periodically
|
||||
* @param tick_period the call period of this function in milliseconds
|
||||
*/
|
||||
LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period);
|
||||
|
||||
/**
|
||||
* Get the elapsed milliseconds since start up
|
||||
* @return the elapsed milliseconds
|
||||
*/
|
||||
uint32_t lv_tick_get(void);
|
||||
|
||||
/**
|
||||
* Get the elapsed milliseconds since a previous time stamp
|
||||
* @param prev_tick a previous time stamp (return value of systick_get() )
|
||||
* @return the elapsed milliseconds since 'prev_tick'
|
||||
*/
|
||||
uint32_t lv_tick_elaps(uint32_t prev_tick);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_HAL_TICK_H*/
|
445
bdk/libs/lvgl/lv_misc/lv_anim.c
Normal file
445
bdk/libs/lvgl/lv_misc/lv_anim.c
Normal file
|
@ -0,0 +1,445 @@
|
|||
/**
|
||||
* @file anim.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_anim.h"
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "../lv_hal/lv_hal_tick.h"
|
||||
#include "lv_task.h"
|
||||
#include "lv_math.h"
|
||||
#include "lv_gc.h"
|
||||
|
||||
#if defined(LV_GC_INCLUDE)
|
||||
# include LV_GC_INCLUDE
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_ANIM_RESOLUTION 1024
|
||||
#define LV_ANIM_RES_SHIFT 10
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void anim_task(void * param);
|
||||
static bool anim_ready_handler(lv_anim_t * a);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static uint32_t last_task_run;
|
||||
static bool anim_list_changed;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Init. the animation module
|
||||
*/
|
||||
void lv_anim_init(void)
|
||||
{
|
||||
lv_ll_init(&LV_GC_ROOT(_lv_anim_ll), sizeof(lv_anim_t));
|
||||
last_task_run = lv_tick_get();
|
||||
lv_task_create(anim_task, LV_REFR_PERIOD, LV_TASK_PRIO_MID, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an animation
|
||||
* @param anim_p an initialized 'anim_t' variable. Not required after call.
|
||||
*/
|
||||
void lv_anim_create(lv_anim_t * anim_p)
|
||||
{
|
||||
LV_LOG_TRACE("animation create started")
|
||||
/* Do not let two animations for the same 'var' with the same 'fp'*/
|
||||
if(anim_p->fp != NULL) lv_anim_del(anim_p->var, anim_p->fp); /*fp == NULL would delete all animations of var*/
|
||||
|
||||
/*Add the new animation to the animation linked list*/
|
||||
lv_anim_t * new_anim = lv_ll_ins_head(&LV_GC_ROOT(_lv_anim_ll));
|
||||
lv_mem_assert(new_anim);
|
||||
if(new_anim == NULL) return;
|
||||
|
||||
/*Initialize the animation descriptor*/
|
||||
anim_p->playback_now = 0;
|
||||
memcpy(new_anim, anim_p, sizeof(lv_anim_t));
|
||||
|
||||
/*Set the start value*/
|
||||
if(new_anim->fp != NULL) new_anim->fp(new_anim->var, new_anim->start);
|
||||
|
||||
/* Creating an animation changed the linked list.
|
||||
* It's important if it happens in a ready callback. (see `anim_task`)*/
|
||||
anim_list_changed = true;
|
||||
|
||||
LV_LOG_TRACE("animation created")
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an animation for a variable with a given animator function
|
||||
* @param var pointer to variable
|
||||
* @param fp a function pointer which is animating 'var',
|
||||
* or NULL to delete all animations of 'var'
|
||||
* @return true: at least 1 animation is deleted, false: no animation is deleted
|
||||
*/
|
||||
bool lv_anim_del(void * var, lv_anim_fp_t fp)
|
||||
{
|
||||
lv_anim_t * a;
|
||||
lv_anim_t * a_next;
|
||||
bool del = false;
|
||||
a = lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll));
|
||||
while(a != NULL) {
|
||||
/*'a' might be deleted, so get the next object while 'a' is valid*/
|
||||
a_next = lv_ll_get_next(&LV_GC_ROOT(_lv_anim_ll), a);
|
||||
|
||||
if(a->var == var && (a->fp == fp || fp == NULL)) {
|
||||
lv_ll_rem(&LV_GC_ROOT(_lv_anim_ll), a);
|
||||
lv_mem_free(a);
|
||||
anim_list_changed = true; /*Read by `anim_task`. It need to know if a delete occurred in the linked list*/
|
||||
del = true;
|
||||
}
|
||||
|
||||
a = a_next;
|
||||
}
|
||||
|
||||
return del;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of currently running animations
|
||||
* @return the number of running animations
|
||||
*/
|
||||
uint16_t lv_anim_count_running(void)
|
||||
{
|
||||
uint16_t cnt = 0;
|
||||
lv_anim_t * a;
|
||||
LL_READ(LV_GC_ROOT(_lv_anim_ll), a) cnt++;
|
||||
|
||||
return cnt++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the time of an animation with a given speed and the start and end values
|
||||
* @param speed speed of animation in unit/sec
|
||||
* @param start start value of the animation
|
||||
* @param end end value of the animation
|
||||
* @return the required time [ms] for the animation with the given parameters
|
||||
*/
|
||||
uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end)
|
||||
{
|
||||
int32_t d = LV_MATH_ABS((int32_t) start - end);
|
||||
uint32_t time = (int32_t)((int32_t)(d * 1000) / speed);
|
||||
|
||||
if(time > UINT16_MAX) time = UINT16_MAX;
|
||||
|
||||
if(time == 0) {
|
||||
time++;
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation applying linear characteristic
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_linear(const lv_anim_t * a)
|
||||
{
|
||||
/*Calculate the current step*/
|
||||
uint16_t step;
|
||||
if(a->time == a->act_time) step = LV_ANIM_RESOLUTION; /*Use the last value if the time fully elapsed*/
|
||||
else step = (a->act_time * LV_ANIM_RESOLUTION) / a->time;
|
||||
|
||||
/* Get the new value which will be proportional to `step`
|
||||
* and the `start` and `end` values*/
|
||||
int32_t new_value;
|
||||
new_value = (int32_t) step * (a->end - a->start);
|
||||
new_value = new_value >> LV_ANIM_RES_SHIFT;
|
||||
new_value += a->start;
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation slowing down the start phase
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_ease_in(const lv_anim_t * a)
|
||||
{
|
||||
/*Calculate the current step*/
|
||||
uint32_t t;
|
||||
if(a->time == a->act_time) t = 1024;
|
||||
else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time;
|
||||
|
||||
int32_t step = lv_bezier3(t, 0, 1, 1, 1024);
|
||||
|
||||
int32_t new_value;
|
||||
new_value = (int32_t) step * (a->end - a->start);
|
||||
new_value = new_value >> 10;
|
||||
new_value += a->start;
|
||||
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation slowing down the end phase
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_ease_out(const lv_anim_t * a)
|
||||
{
|
||||
/*Calculate the current step*/
|
||||
|
||||
uint32_t t;
|
||||
if(a->time == a->act_time) t = 1024;
|
||||
else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time;
|
||||
|
||||
int32_t step = lv_bezier3(t, 0, 1023, 1023, 1024);
|
||||
|
||||
int32_t new_value;
|
||||
new_value = (int32_t) step * (a->end - a->start);
|
||||
new_value = new_value >> 10;
|
||||
new_value += a->start;
|
||||
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation applying an "S" characteristic (cosine)
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_ease_in_out(const lv_anim_t * a)
|
||||
{
|
||||
/*Calculate the current step*/
|
||||
|
||||
uint32_t t;
|
||||
if(a->time == a->act_time) t = 1024;
|
||||
else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time;
|
||||
|
||||
int32_t step = lv_bezier3(t, 0, 100, 924, 1024);
|
||||
|
||||
int32_t new_value;
|
||||
new_value = (int32_t) step * (a->end - a->start);
|
||||
new_value = new_value >> 10;
|
||||
new_value += a->start;
|
||||
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation with overshoot at the end
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_overshoot(const lv_anim_t * a)
|
||||
{
|
||||
/*Calculate the current step*/
|
||||
|
||||
uint32_t t;
|
||||
if(a->time == a->act_time) t = 1024;
|
||||
else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time;
|
||||
|
||||
int32_t step = lv_bezier3(t, 0, 600, 1300, 1024);
|
||||
|
||||
int32_t new_value;
|
||||
new_value = (int32_t) step * (a->end - a->start);
|
||||
new_value = new_value >> 10;
|
||||
new_value += a->start;
|
||||
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation with 3 bounces
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_bounce(const lv_anim_t * a)
|
||||
{
|
||||
/*Calculate the current step*/
|
||||
uint32_t t;
|
||||
if(a->time == a->act_time) t = 1024;
|
||||
else t = (uint32_t)((uint32_t)a->act_time * 1024) / a->time;
|
||||
|
||||
int32_t diff = (a->end - a->start);
|
||||
|
||||
/*3 bounces has 5 parts: 3 down and 2 up. One part is t / 5 long*/
|
||||
|
||||
if(t < 408){
|
||||
/*Go down*/
|
||||
t = (t * 2500) >> 10; /*[0..1024] range*/
|
||||
}
|
||||
else if(t >= 408 && t < 614) {
|
||||
/*First bounce back*/
|
||||
t -= 408;
|
||||
t = t * 5; /*to [0..1024] range*/
|
||||
t = 1024 - t;
|
||||
diff = diff / 6;
|
||||
}
|
||||
else if(t >= 614 && t < 819) {
|
||||
/*Fall back*/
|
||||
t -= 614;
|
||||
t = t * 5; /*to [0..1024] range*/
|
||||
diff = diff / 6;
|
||||
}
|
||||
else if(t >= 819 && t < 921) {
|
||||
/*Second bounce back*/
|
||||
t -= 819;
|
||||
t = t * 10; /*to [0..1024] range*/
|
||||
t = 1024 - t;
|
||||
diff = diff / 16;
|
||||
}
|
||||
else if(t >= 921 && t <= 1024) {
|
||||
/*Fall back*/
|
||||
t -= 921;
|
||||
t = t * 10; /*to [0..1024] range*/
|
||||
diff = diff / 16;
|
||||
}
|
||||
|
||||
if(t > 1024) t = 1024;
|
||||
|
||||
int32_t step = lv_bezier3(t, 1024, 1024, 800, 0);
|
||||
|
||||
int32_t new_value;
|
||||
|
||||
new_value = (int32_t) step * diff;
|
||||
new_value = new_value >> 10;
|
||||
new_value = a->end - new_value;
|
||||
|
||||
|
||||
return new_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation applying step characteristic.
|
||||
* (Set end value on the end of the animation)
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_step(const lv_anim_t * a)
|
||||
{
|
||||
if(a->act_time >= a->time) return a->end;
|
||||
else return a->start;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Periodically handle the animations.
|
||||
* @param param unused
|
||||
*/
|
||||
static void anim_task(void * param)
|
||||
{
|
||||
(void)param;
|
||||
|
||||
lv_anim_t * a;
|
||||
LL_READ(LV_GC_ROOT(_lv_anim_ll), a) {
|
||||
a->has_run = 0;
|
||||
}
|
||||
|
||||
uint32_t elaps = lv_tick_elaps(last_task_run);
|
||||
a = lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll));
|
||||
|
||||
while(a != NULL) {
|
||||
/*It can be set by `lv_anim_del()` typically in `end_cb`. If set then an animation delete happened in `anim_ready_handler`
|
||||
* which could make this linked list reading corrupt because the list is changed meanwhile
|
||||
*/
|
||||
anim_list_changed = false;
|
||||
|
||||
if(!a->has_run) {
|
||||
a->has_run = 1; /*The list readying might be reseted so need to know which anim has run already*/
|
||||
a->act_time += elaps;
|
||||
if(a->act_time >= 0) {
|
||||
if(a->act_time > a->time) a->act_time = a->time;
|
||||
|
||||
int32_t new_value;
|
||||
new_value = a->path(a);
|
||||
|
||||
if(a->fp != NULL) a->fp(a->var, new_value); /*Apply the calculated value*/
|
||||
|
||||
/*If the time is elapsed the animation is ready*/
|
||||
if(a->act_time >= a->time) {
|
||||
anim_ready_handler(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If the linked list changed due to anim. delete then it's not safe to continue
|
||||
* the reading of the list from here -> start from the head*/
|
||||
if(anim_list_changed) a = lv_ll_get_head(&LV_GC_ROOT(_lv_anim_ll));
|
||||
else a = lv_ll_get_next(&LV_GC_ROOT(_lv_anim_ll), a);
|
||||
}
|
||||
|
||||
last_task_run = lv_tick_get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an animation is ready to do the necessary thinks
|
||||
* e.g. repeat, play back, delete etc.
|
||||
* @param a pointer to an animation descriptor
|
||||
* @return true: animation delete occurred nnd the `LV_GC_ROOT(_lv_anim_ll)` has changed
|
||||
* */
|
||||
static bool anim_ready_handler(lv_anim_t * a)
|
||||
{
|
||||
|
||||
/*Delete the animation if
|
||||
* - no repeat and no play back (simple one shot animation)
|
||||
* - no repeat, play back is enabled and play back is ready */
|
||||
if((a->repeat == 0 && a->playback == 0) ||
|
||||
(a->repeat == 0 && a->playback == 1 && a->playback_now == 1)) {
|
||||
void (*cb)(void *) = a->end_cb;
|
||||
void * p = a->var;
|
||||
lv_ll_rem(&LV_GC_ROOT(_lv_anim_ll), a);
|
||||
lv_mem_free(a);
|
||||
anim_list_changed = true;
|
||||
|
||||
/* Call the callback function at the end*/
|
||||
/* Check if an animation is deleted in the cb function
|
||||
* if yes then the caller function has to know this*/
|
||||
if(cb != NULL) cb(p);
|
||||
}
|
||||
/*If the animation is not deleted then restart it*/
|
||||
else {
|
||||
a->act_time = - a->repeat_pause; /*Restart the animation*/
|
||||
/*Swap the start and end values in play back mode*/
|
||||
if(a->playback != 0) {
|
||||
/*If now turning back use the 'playback_pause*/
|
||||
if(a->playback_now == 0) a->act_time = - a->playback_pause;
|
||||
|
||||
/*Toggle the play back state*/
|
||||
a->playback_now = a->playback_now == 0 ? 1 : 0;
|
||||
/*Swap the start and end values*/
|
||||
int32_t tmp;
|
||||
tmp = a->start;
|
||||
a->start = a->end;
|
||||
a->end = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return anim_list_changed;
|
||||
}
|
||||
#endif
|
176
bdk/libs/lvgl/lv_misc/lv_anim.h
Normal file
176
bdk/libs/lvgl/lv_misc/lv_anim.h
Normal file
|
@ -0,0 +1,176 @@
|
|||
/**
|
||||
* @file anim.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ANIM_H
|
||||
#define ANIM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
struct _lv_anim_t;
|
||||
|
||||
typedef int32_t(*lv_anim_path_t)(const struct _lv_anim_t*);
|
||||
|
||||
typedef void (*lv_anim_fp_t)(void *, int32_t);
|
||||
typedef void (*lv_anim_cb_t)(void *);
|
||||
|
||||
typedef struct _lv_anim_t
|
||||
{
|
||||
void * var; /*Variable to animate*/
|
||||
lv_anim_fp_t fp; /*Animator function*/
|
||||
lv_anim_cb_t end_cb; /*Call it when the animation is ready*/
|
||||
lv_anim_path_t path; /*An array with the steps of animations*/
|
||||
int32_t start; /*Start value*/
|
||||
int32_t end; /*End value*/
|
||||
uint16_t time; /*Animation time in ms*/
|
||||
int16_t act_time; /*Current time in animation. Set to negative to make delay.*/
|
||||
uint16_t playback_pause; /*Wait before play back*/
|
||||
uint16_t repeat_pause; /*Wait before repeat*/
|
||||
uint8_t playback :1; /*When the animation is ready play it back*/
|
||||
uint8_t repeat :1; /*Repeat the animation infinitely*/
|
||||
/*Animation system use these - user shouldn't set*/
|
||||
uint8_t playback_now :1; /*Play back is in progress*/
|
||||
uint32_t has_run :1; /*Indicates the animation has run it this round*/
|
||||
} lv_anim_t;
|
||||
|
||||
/*Example initialization
|
||||
lv_anim_t a;
|
||||
a.var = obj;
|
||||
a.start = lv_obj_get_height(obj);
|
||||
a.end = new_height;
|
||||
a.fp = (lv_anim_fp_t)lv_obj_set_height;
|
||||
a.path = lv_anim_path_linear;
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = 200;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
*/
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Init. the animation module
|
||||
*/
|
||||
void lv_anim_init(void);
|
||||
|
||||
/**
|
||||
* Create an animation
|
||||
* @param anim_p an initialized 'anim_t' variable. Not required after call.
|
||||
*/
|
||||
void lv_anim_create(lv_anim_t * anim_p);
|
||||
|
||||
/**
|
||||
* Delete an animation for a variable with a given animatior function
|
||||
* @param var pointer to variable
|
||||
* @param fp a function pointer which is animating 'var',
|
||||
* or NULL to ignore it and delete all animation with 'var
|
||||
* @return true: at least 1 animation is deleted, false: no animation is deleted
|
||||
*/
|
||||
bool lv_anim_del(void * var, lv_anim_fp_t fp);
|
||||
|
||||
/**
|
||||
* Get the number of currently running animations
|
||||
* @return the number of running animations
|
||||
*/
|
||||
uint16_t lv_anim_count_running(void);
|
||||
|
||||
/**
|
||||
* Calculate the time of an animation with a given speed and the start and end values
|
||||
* @param speed speed of animation in unit/sec
|
||||
* @param start start value of the animation
|
||||
* @param end end value of the animation
|
||||
* @return the required time [ms] for the animation with the given parameters
|
||||
*/
|
||||
uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation applying linear characteristic
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_linear(const lv_anim_t *a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation slowing down the start phase
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_ease_in(const lv_anim_t * a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation slowing down the end phase
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_ease_out(const lv_anim_t * a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation applying an "S" characteristic (cosine)
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_ease_in_out(const lv_anim_t *a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation with overshoot at the end
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_overshoot(const lv_anim_t * a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation with 3 bounces
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_bounce(const lv_anim_t * a);
|
||||
|
||||
/**
|
||||
* Calculate the current value of an animation applying step characteristic.
|
||||
* (Set end value on the end of the animation)
|
||||
* @param a pointer to an animation
|
||||
* @return the current value to set
|
||||
*/
|
||||
int32_t lv_anim_path_step(const lv_anim_t *a);
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_ANIMATION == 0*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_ANIM_H*/
|
||||
|
200
bdk/libs/lvgl/lv_misc/lv_area.c
Normal file
200
bdk/libs/lvgl/lv_misc/lv_area.c
Normal file
|
@ -0,0 +1,200 @@
|
|||
/**
|
||||
* @file lv_area.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_area.h"
|
||||
#include "lv_math.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize an area
|
||||
* @param area_p pointer to an area
|
||||
* @param x1 left coordinate of the area
|
||||
* @param y1 top coordinate of the area
|
||||
* @param x2 right coordinate of the area
|
||||
* @param y2 bottom coordinate of the area
|
||||
*/
|
||||
void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2)
|
||||
{
|
||||
area_p->x1 = x1;
|
||||
area_p->y1 = y1;
|
||||
area_p->x2 = x2;
|
||||
area_p->y2 = y2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the width of an area
|
||||
* @param area_p pointer to an area
|
||||
* @param w the new width of the area (w == 1 makes x1 == x2)
|
||||
*/
|
||||
void lv_area_set_width(lv_area_t * area_p, lv_coord_t w)
|
||||
{
|
||||
area_p->x2 = area_p->x1 + w - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the height of an area
|
||||
* @param area_p pointer to an area
|
||||
* @param h the new height of the area (h == 1 makes y1 == y2)
|
||||
*/
|
||||
void lv_area_set_height(lv_area_t * area_p, lv_coord_t h)
|
||||
{
|
||||
area_p->y2 = area_p->y1 + h - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position of an area (width and height will be kept)
|
||||
* @param area_p pointer to an area
|
||||
* @param x the new x coordinate of the area
|
||||
* @param y the new y coordinate of the area
|
||||
*/
|
||||
void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y)
|
||||
{
|
||||
lv_coord_t w = lv_area_get_width(area_p);
|
||||
lv_coord_t h = lv_area_get_height(area_p);
|
||||
area_p->x1 = x;
|
||||
area_p->y1 = y;
|
||||
lv_area_set_width(area_p, w);
|
||||
lv_area_set_height(area_p, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with area of an area (x * y)
|
||||
* @param area_p pointer to an area
|
||||
* @return size of area
|
||||
*/
|
||||
uint32_t lv_area_get_size(const lv_area_t * area_p)
|
||||
{
|
||||
uint32_t size;
|
||||
|
||||
size = (uint32_t)(area_p->x2 - area_p->x1 + 1) *
|
||||
(area_p->y2 - area_p->y1 + 1);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the common parts of two areas
|
||||
* @param res_p pointer to an area, the result will be stored here
|
||||
* @param a1_p pointer to the first area
|
||||
* @param a2_p pointer to the second area
|
||||
* @return false: the two area has NO common parts, res_p is invalid
|
||||
*/
|
||||
bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p)
|
||||
{
|
||||
/* Get the smaller area from 'a1_p' and 'a2_p' */
|
||||
res_p->x1 = LV_MATH_MAX(a1_p->x1, a2_p->x1);
|
||||
res_p->y1 = LV_MATH_MAX(a1_p->y1, a2_p->y1);
|
||||
res_p->x2 = LV_MATH_MIN(a1_p->x2, a2_p->x2);
|
||||
res_p->y2 = LV_MATH_MIN(a1_p->y2, a2_p->y2);
|
||||
|
||||
/*If x1 or y1 greater then x2 or y2 then the areas union is empty*/
|
||||
bool union_ok = true;
|
||||
if((res_p->x1 > res_p->x2) ||
|
||||
(res_p->y1 > res_p->y2)) {
|
||||
union_ok = false;
|
||||
}
|
||||
|
||||
return union_ok;
|
||||
}
|
||||
/**
|
||||
* Join two areas into a third which involves the other two
|
||||
* @param res_p pointer to an area, the result will be stored here
|
||||
* @param a1_p pointer to the first area
|
||||
* @param a2_p pointer to the second area
|
||||
*/
|
||||
void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p)
|
||||
{
|
||||
a_res_p->x1 = LV_MATH_MIN(a1_p->x1, a2_p->x1);
|
||||
a_res_p->y1 = LV_MATH_MIN(a1_p->y1, a2_p->y1);
|
||||
a_res_p->x2 = LV_MATH_MAX(a1_p->x2, a2_p->x2);
|
||||
a_res_p->y2 = LV_MATH_MAX(a1_p->y2, a2_p->y2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a point is on an area
|
||||
* @param a_p pointer to an area
|
||||
* @param p_p pointer to a point
|
||||
* @return false:the point is out of the area
|
||||
*/
|
||||
bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p)
|
||||
{
|
||||
bool is_on = false;
|
||||
|
||||
if((p_p->x >= a_p->x1 && p_p->x <= a_p->x2) &&
|
||||
((p_p->y >= a_p->y1 && p_p->y <= a_p->y2))) {
|
||||
is_on = true;
|
||||
}
|
||||
|
||||
return is_on;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if two area has common parts
|
||||
* @param a1_p pointer to an area.
|
||||
* @param a2_p pointer to an other area
|
||||
* @return false: a1_p and a2_p has no common parts
|
||||
*/
|
||||
bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p)
|
||||
{
|
||||
if((a1_p->x1 <= a2_p->x2) &&
|
||||
(a1_p->x2 >= a2_p->x1) &&
|
||||
(a1_p->y1 <= a2_p->y2) &&
|
||||
(a1_p->y2 >= a2_p->y1)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an area is fully on an other
|
||||
* @param ain_p pointer to an area which could be in 'aholder_p'
|
||||
* @param aholder pointer to an area which could involve 'ain_p'
|
||||
* @return
|
||||
*/
|
||||
bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p)
|
||||
{
|
||||
bool is_in = false;
|
||||
|
||||
if(ain_p->x1 >= aholder_p->x1 &&
|
||||
ain_p->y1 >= aholder_p->y1 &&
|
||||
ain_p->x2 <= aholder_p->x2 &&
|
||||
ain_p->y2 <= aholder_p->y2) {
|
||||
is_in = true;
|
||||
}
|
||||
|
||||
return is_in;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
168
bdk/libs/lvgl/lv_misc/lv_area.h
Normal file
168
bdk/libs/lvgl/lv_misc/lv_area.h
Normal file
|
@ -0,0 +1,168 @@
|
|||
/**
|
||||
* @file lv_area.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_AREA_H
|
||||
#define LV_AREA_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <string.h>
|
||||
#include <utils/types.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_COORD_MAX (16383) /*To avoid overflow don't let the max [-32,32k] range */
|
||||
#define LV_COORD_MIN (-16384)
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef int16_t lv_coord_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
lv_coord_t x;
|
||||
lv_coord_t y;
|
||||
} lv_point_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
lv_coord_t x1;
|
||||
lv_coord_t y1;
|
||||
lv_coord_t x2;
|
||||
lv_coord_t y2;
|
||||
} lv_area_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize an area
|
||||
* @param area_p pointer to an area
|
||||
* @param x1 left coordinate of the area
|
||||
* @param y1 top coordinate of the area
|
||||
* @param x2 right coordinate of the area
|
||||
* @param y2 bottom coordinate of the area
|
||||
*/
|
||||
void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2);
|
||||
|
||||
/**
|
||||
* Copy an area
|
||||
* @param dest pointer to the destination area
|
||||
* @param src pointer to the source area
|
||||
*/
|
||||
inline static void lv_area_copy(lv_area_t * dest, const lv_area_t * src)
|
||||
{
|
||||
memcpy(dest, src, sizeof(lv_area_t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of an area
|
||||
* @param area_p pointer to an area
|
||||
* @return the width of the area (if x1 == x2 -> width = 1)
|
||||
*/
|
||||
static inline lv_coord_t lv_area_get_width(const lv_area_t * area_p)
|
||||
{
|
||||
return area_p->x2 - area_p->x1 + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of an area
|
||||
* @param area_p pointer to an area
|
||||
* @return the height of the area (if y1 == y2 -> height = 1)
|
||||
*/
|
||||
static inline lv_coord_t lv_area_get_height(const lv_area_t * area_p)
|
||||
{
|
||||
return area_p->y2 - area_p->y1 + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the width of an area
|
||||
* @param area_p pointer to an area
|
||||
* @param w the new width of the area (w == 1 makes x1 == x2)
|
||||
*/
|
||||
void lv_area_set_width(lv_area_t * area_p, lv_coord_t w);
|
||||
|
||||
/**
|
||||
* Set the height of an area
|
||||
* @param area_p pointer to an area
|
||||
* @param h the new height of the area (h == 1 makes y1 == y2)
|
||||
*/
|
||||
void lv_area_set_height(lv_area_t * area_p, lv_coord_t h);
|
||||
|
||||
/**
|
||||
* Set the position of an area (width and height will be kept)
|
||||
* @param area_p pointer to an area
|
||||
* @param x the new x coordinate of the area
|
||||
* @param y the new y coordinate of the area
|
||||
*/
|
||||
void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y);
|
||||
|
||||
/**
|
||||
* Return with area of an area (x * y)
|
||||
* @param area_p pointer to an area
|
||||
* @return size of area
|
||||
*/
|
||||
uint32_t lv_area_get_size(const lv_area_t * area_p);
|
||||
|
||||
/**
|
||||
* Get the common parts of two areas
|
||||
* @param res_p pointer to an area, the result will be stored her
|
||||
* @param a1_p pointer to the first area
|
||||
* @param a2_p pointer to the second area
|
||||
* @return false: the two area has NO common parts, res_p is invalid
|
||||
*/
|
||||
bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
|
||||
|
||||
/**
|
||||
* Join two areas into a third which involves the other two
|
||||
* @param res_p pointer to an area, the result will be stored here
|
||||
* @param a1_p pointer to the first area
|
||||
* @param a2_p pointer to the second area
|
||||
*/
|
||||
void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p);
|
||||
|
||||
/**
|
||||
* Check if a point is on an area
|
||||
* @param a_p pointer to an area
|
||||
* @param p_p pointer to a point
|
||||
* @return false:the point is out of the area
|
||||
*/
|
||||
bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p);
|
||||
|
||||
/**
|
||||
* Check if two area has common parts
|
||||
* @param a1_p pointer to an area.
|
||||
* @param a2_p pointer to an other area
|
||||
* @return false: a1_p and a2_p has no common parts
|
||||
*/
|
||||
bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p);
|
||||
|
||||
/**
|
||||
* Check if an area is fully on an other
|
||||
* @param ain_p pointer to an area which could be on aholder_p
|
||||
* @param aholder pointer to an area which could involve ain_p
|
||||
* @return
|
||||
*/
|
||||
bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
79
bdk/libs/lvgl/lv_misc/lv_circ.c
Normal file
79
bdk/libs/lvgl/lv_misc/lv_circ.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* @file lv_circ.c
|
||||
* Circle drawing algorithm (with Bresenham)
|
||||
* Only a 1/8 circle is calculated. Use CIRC_OCT1_X, CIRC_OCT1_Y macros to get
|
||||
* the other octets.
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_circ.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the circle drawing
|
||||
* @param c pointer to a point. The coordinates will be calculated here
|
||||
* @param tmp point to a variable. It will store temporary data
|
||||
* @param radius radius of the circle
|
||||
*/
|
||||
void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius)
|
||||
{
|
||||
c->x = radius;
|
||||
c->y = 0;
|
||||
*tmp = 1 - radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the circle drawing is ready or not
|
||||
* @param c same as in circ_init
|
||||
* @return true if the circle is not ready yet
|
||||
*/
|
||||
bool lv_circ_cont(lv_point_t * c)
|
||||
{
|
||||
return c->y <= c->x ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next point from the circle
|
||||
* @param c same as in circ_init. The next point stored here.
|
||||
* @param tmp same as in circ_init.
|
||||
*/
|
||||
void lv_circ_next(lv_point_t * c, lv_coord_t * tmp)
|
||||
{
|
||||
c->y++;
|
||||
|
||||
if(*tmp <= 0) {
|
||||
(*tmp) += 2 * c->y + 1; // Change in decision criterion for y -> y+1
|
||||
} else {
|
||||
c->x--;
|
||||
(*tmp) += 2 * (c->y - c->x) + 1; // Change for y -> y+1, x -> x-1
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
80
bdk/libs/lvgl/lv_misc/lv_circ.h
Normal file
80
bdk/libs/lvgl/lv_misc/lv_circ.h
Normal file
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
* @file lv_circ.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_CIRC_H
|
||||
#define LV_CIRC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stddef.h>
|
||||
#include "lv_area.h"
|
||||
#include <utils/types.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_CIRC_OCT1_X(p) (p.x)
|
||||
#define LV_CIRC_OCT1_Y(p) (p.y)
|
||||
#define LV_CIRC_OCT2_X(p) (p.y)
|
||||
#define LV_CIRC_OCT2_Y(p) (p.x)
|
||||
#define LV_CIRC_OCT3_X(p) (-p.y)
|
||||
#define LV_CIRC_OCT3_Y(p) (p.x)
|
||||
#define LV_CIRC_OCT4_X(p) (-p.x)
|
||||
#define LV_CIRC_OCT4_Y(p) (p.y)
|
||||
#define LV_CIRC_OCT5_X(p) (-p.x)
|
||||
#define LV_CIRC_OCT5_Y(p) (-p.y)
|
||||
#define LV_CIRC_OCT6_X(p) (-p.y)
|
||||
#define LV_CIRC_OCT6_Y(p) (-p.x)
|
||||
#define LV_CIRC_OCT7_X(p) (p.y)
|
||||
#define LV_CIRC_OCT7_Y(p) (-p.x)
|
||||
#define LV_CIRC_OCT8_X(p) (p.x)
|
||||
#define LV_CIRC_OCT8_Y(p) (-p.y)
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the circle drawing
|
||||
* @param c pointer to a point. The coordinates will be calculated here
|
||||
* @param tmp point to a variable. It will store temporary data
|
||||
* @param radius radius of the circle
|
||||
*/
|
||||
void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius);
|
||||
|
||||
/**
|
||||
* Test the circle drawing is ready or not
|
||||
* @param c same as in circ_init
|
||||
* @return true if the circle is not ready yet
|
||||
*/
|
||||
bool lv_circ_cont(lv_point_t * c);
|
||||
|
||||
/**
|
||||
* Get the next point from the circle
|
||||
* @param c same as in circ_init. The next point stored here.
|
||||
* @param tmp same as in circ_init.
|
||||
*/
|
||||
void lv_circ_next(lv_point_t * c, lv_coord_t * tmp);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
167
bdk/libs/lvgl/lv_misc/lv_color.c
Normal file
167
bdk/libs/lvgl/lv_misc/lv_color.c
Normal file
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lv_color.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_color.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
#define HUE_DEGREE 512
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Convert a HSV color to RGB
|
||||
* @param h hue [0..359]
|
||||
* @param s saturation [0..100]
|
||||
* @param v value [0..100]
|
||||
* @return the given RGB color in RGB (with LV_COLOR_DEPTH depth)
|
||||
*/
|
||||
lv_color_t lv_color_hsv_to_rgb(uint16_t hue, uint8_t sat, uint8_t val)
|
||||
{
|
||||
uint8_t r, g, b;
|
||||
|
||||
uint32_t h = (hue * 360 * HUE_DEGREE -1) / 360;
|
||||
uint32_t s = sat * 255 / 100;
|
||||
uint32_t v = val * 255 / 100;
|
||||
uint32_t p = (256 * v - s * v) / 256;
|
||||
uint32_t region = h / (60 * 512);
|
||||
|
||||
if(sat == 0)
|
||||
return LV_COLOR_MAKE(v, v, v);
|
||||
|
||||
if (region & 1)
|
||||
{
|
||||
uint32_t q = (256 * 60 * HUE_DEGREE * v - h * s * v + 60 * HUE_DEGREE * s * v * region) /
|
||||
(256 * 60 * HUE_DEGREE);
|
||||
|
||||
switch (region)
|
||||
{
|
||||
case 1:
|
||||
r = q;
|
||||
g = v;
|
||||
b = p;
|
||||
break;
|
||||
case 3:
|
||||
r = p;
|
||||
g = q;
|
||||
b = v;
|
||||
break;
|
||||
case 5:
|
||||
default:
|
||||
r = v;
|
||||
g = p;
|
||||
b = q;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t t = (256 * 60 * HUE_DEGREE * v + h * s * v - 60 * HUE_DEGREE * s * v * (region + 1)) /
|
||||
(256 * 60 * HUE_DEGREE);
|
||||
|
||||
switch (region)
|
||||
{
|
||||
case 0:
|
||||
r = v;
|
||||
g = t;
|
||||
b = p;
|
||||
break;
|
||||
case 2:
|
||||
r = p;
|
||||
g = v;
|
||||
b = t;
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
r = t;
|
||||
g = p;
|
||||
b = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return LV_COLOR_MAKE(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an RGB color to HSV
|
||||
* @param r red
|
||||
* @param g green
|
||||
* @param b blue
|
||||
* @return the given RGB color n HSV
|
||||
*/
|
||||
lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
lv_color_hsv_t hsv;
|
||||
uint8_t rgbMin, rgbMax;
|
||||
|
||||
rgbMin = r < g ? (r < b ? r : b) : (g < b ? g : b);
|
||||
rgbMax = r > g ? (r > b ? r : b) : (g > b ? g : b);
|
||||
|
||||
hsv.v = rgbMax;
|
||||
if(hsv.v == 0) {
|
||||
hsv.h = 0;
|
||||
hsv.s = 0;
|
||||
return hsv;
|
||||
}
|
||||
|
||||
hsv.s = 255 * (long)(rgbMax - rgbMin) / hsv.v;
|
||||
if(hsv.s == 0) {
|
||||
hsv.h = 0;
|
||||
return hsv;
|
||||
}
|
||||
|
||||
if(rgbMax == r)
|
||||
hsv.h = 0 + 43 * (g - b) / (rgbMax - rgbMin);
|
||||
else if(rgbMax == g)
|
||||
hsv.h = 85 + 43 * (b - r) / (rgbMax - rgbMin);
|
||||
else
|
||||
hsv.h = 171 + 43 * (r - g) / (rgbMax - rgbMin);
|
||||
|
||||
return hsv;
|
||||
}
|
455
bdk/libs/lvgl/lv_misc/lv_color.h
Normal file
455
bdk/libs/lvgl/lv_misc/lv_color.h
Normal file
|
@ -0,0 +1,455 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lv_color.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_COLOR_H
|
||||
#define LV_COLOR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
/*Error checking*/
|
||||
#if LV_COLOR_DEPTH == 24
|
||||
#error "LV_COLOR_DEPTH 24 is deprecated. Use LV_COLOR_DEPTH 32 instead (lv_conf.h)"
|
||||
#endif
|
||||
|
||||
#if LV_COLOR_DEPTH != 32 && LV_COLOR_SCREEN_TRANSP != 0
|
||||
#error "LV_COLOR_SCREEN_TRANSP requires LV_COLOR_DEPTH == 32. Set it in lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if LV_COLOR_DEPTH != 16 && LV_COLOR_16_SWAP != 0
|
||||
#error "LV_COLOR_16_SWAP requires LV_COLOR_DEPTH == 16. Set it in lv_conf.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_COLOR_WHITE LV_COLOR_MAKE(0xFF,0xFF,0xFF)
|
||||
#define LV_COLOR_SILVER LV_COLOR_MAKE(0xC0,0xC0,0xC0)
|
||||
#define LV_COLOR_GRAY LV_COLOR_MAKE(0x80,0x80,0x80)
|
||||
#define LV_COLOR_BLACK LV_COLOR_MAKE(0x00,0x00,0x00)
|
||||
#define LV_COLOR_RED LV_COLOR_MAKE(0xFF,0x00,0x00)
|
||||
#define LV_COLOR_MAROON LV_COLOR_MAKE(0x80,0x00,0x00)
|
||||
#define LV_COLOR_YELLOW LV_COLOR_MAKE(0xFF,0xFF,0x00)
|
||||
#define LV_COLOR_OLIVE LV_COLOR_MAKE(0x80,0x80,0x00)
|
||||
#define LV_COLOR_LIME LV_COLOR_MAKE(0x00,0xFF,0x00)
|
||||
#define LV_COLOR_GREEN LV_COLOR_MAKE(0x00,0x80,0x00)
|
||||
#define LV_COLOR_CYAN LV_COLOR_MAKE(0x00,0xFF,0xFF)
|
||||
#define LV_COLOR_AQUA LV_COLOR_CYAN
|
||||
#define LV_COLOR_TEAL LV_COLOR_MAKE(0x00,0x80,0x80)
|
||||
#define LV_COLOR_BLUE LV_COLOR_MAKE(0x00,0x00,0xFF)
|
||||
#define LV_COLOR_NAVY LV_COLOR_MAKE(0x00,0x00,0x80)
|
||||
#define LV_COLOR_MAGENTA LV_COLOR_MAKE(0xFF,0x00,0xFF)
|
||||
#define LV_COLOR_PURPLE LV_COLOR_MAKE(0x80,0x00,0x80)
|
||||
#define LV_COLOR_ORANGE LV_COLOR_MAKE(0xFF,0xA5,0x00)
|
||||
|
||||
enum {
|
||||
LV_OPA_TRANSP = 0,
|
||||
LV_OPA_0 = 0,
|
||||
LV_OPA_10 = 25,
|
||||
LV_OPA_20 = 51,
|
||||
LV_OPA_30 = 76,
|
||||
LV_OPA_40 = 102,
|
||||
LV_OPA_50 = 127,
|
||||
LV_OPA_60 = 153,
|
||||
LV_OPA_70 = 178,
|
||||
LV_OPA_80 = 204,
|
||||
LV_OPA_90 = 229,
|
||||
LV_OPA_100 = 255,
|
||||
LV_OPA_COVER = 255,
|
||||
};
|
||||
|
||||
#define LV_OPA_MIN 16 /*Opacities below this will be transparent*/
|
||||
#define LV_OPA_MAX 251 /*Opacities above this will fully cover*/
|
||||
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
#define LV_COLOR_SIZE 8
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
#define LV_COLOR_SIZE 8
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
#define LV_COLOR_SIZE 16
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
#define LV_COLOR_SIZE 32
|
||||
#else
|
||||
#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef union
|
||||
{
|
||||
uint8_t blue :1;
|
||||
uint8_t green :1;
|
||||
uint8_t red :1;
|
||||
uint8_t full :1;
|
||||
} lv_color1_t;
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t blue :2;
|
||||
uint8_t green :3;
|
||||
uint8_t red :3;
|
||||
};
|
||||
uint8_t full;
|
||||
} lv_color8_t;
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
#if LV_COLOR_16_SWAP == 0
|
||||
uint16_t blue :5;
|
||||
uint16_t green :6;
|
||||
uint16_t red :5;
|
||||
#else
|
||||
uint16_t green_h :3;
|
||||
uint16_t red :5;
|
||||
uint16_t blue :5;
|
||||
uint16_t green_l :3;
|
||||
#endif
|
||||
};
|
||||
uint16_t full;
|
||||
} lv_color16_t;
|
||||
|
||||
typedef union
|
||||
{
|
||||
struct
|
||||
{
|
||||
uint8_t blue;
|
||||
uint8_t green;
|
||||
uint8_t red;
|
||||
uint8_t alpha;
|
||||
};
|
||||
uint32_t full;
|
||||
} lv_color32_t;
|
||||
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
typedef uint8_t lv_color_int_t;
|
||||
typedef lv_color1_t lv_color_t;
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
typedef uint8_t lv_color_int_t;
|
||||
typedef lv_color8_t lv_color_t;
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
typedef uint16_t lv_color_int_t;
|
||||
typedef lv_color16_t lv_color_t;
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
typedef uint32_t lv_color_int_t;
|
||||
typedef lv_color32_t lv_color_t;
|
||||
#else
|
||||
#error "Invalid LV_COLOR_DEPTH in lv_conf.h! Set it to 1, 8, 16 or 32!"
|
||||
#endif
|
||||
|
||||
typedef uint8_t lv_opa_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t h;
|
||||
uint8_t s;
|
||||
uint8_t v;
|
||||
} lv_color_hsv_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/*In color conversations:
|
||||
* - When converting to bigger color type the LSB weight of 1 LSB is calculated
|
||||
* E.g. 16 bit Red has 5 bits
|
||||
* 8 bit Red has 2 bits
|
||||
* ----------------------
|
||||
* 8 bit red LSB = (2^5 - 1) / (2^2 - 1) = 31 / 3 = 10
|
||||
*
|
||||
* - When calculating to smaller color type simply shift out the LSBs
|
||||
* E.g. 8 bit Red has 2 bits
|
||||
* 16 bit Red has 5 bits
|
||||
* ----------------------
|
||||
* Shift right with 5 - 3 = 2
|
||||
*/
|
||||
|
||||
static inline uint8_t lv_color_to1(lv_color_t color)
|
||||
{
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
return color.full;
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
if((color.red & 0x4) ||
|
||||
(color.green & 0x4) ||
|
||||
(color.blue & 0x2)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
# if LV_COLOR_16_SWAP == 0
|
||||
if((color.red & 0x10) ||
|
||||
(color.green & 0x20) ||
|
||||
(color.blue & 0x10)) {
|
||||
return 1;
|
||||
# else
|
||||
if((color.red & 0x10) ||
|
||||
(color.green_h & 0x20) ||
|
||||
(color.blue & 0x10)) {
|
||||
return 1;
|
||||
# endif
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
if((color.red & 0x80) ||
|
||||
(color.green & 0x80) ||
|
||||
(color.blue & 0x80)) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint8_t lv_color_to8(lv_color_t color)
|
||||
{
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
if(color.full == 0) return 0;
|
||||
else return 0xFF;
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
return color.full;
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
|
||||
# if LV_COLOR_16_SWAP == 0
|
||||
lv_color8_t ret;
|
||||
ret.red = color.red >> 2; /* 5 - 3 = 2*/
|
||||
ret.green = color.green >> 3; /* 6 - 3 = 3*/
|
||||
ret.blue = color.blue >> 3; /* 5 - 2 = 3*/
|
||||
return ret.full;
|
||||
# else
|
||||
lv_color8_t ret;
|
||||
ret.red = color.red >> 2; /* 5 - 3 = 2*/
|
||||
ret.green = color.green_h; /* 6 - 3 = 3*/
|
||||
ret.blue = color.blue >> 3; /* 5 - 2 = 3*/
|
||||
return ret.full;
|
||||
# endif
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
lv_color8_t ret;
|
||||
ret.red = color.red >> 5; /* 8 - 3 = 5*/
|
||||
ret.green = color.green >> 5; /* 8 - 3 = 5*/
|
||||
ret.blue = color.blue >> 6; /* 8 - 2 = 6*/
|
||||
return ret.full;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint16_t lv_color_to16(lv_color_t color)
|
||||
{
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
if(color.full == 0) return 0;
|
||||
else return 0xFFFF;
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
lv_color16_t ret;
|
||||
# if LV_COLOR_16_SWAP == 0
|
||||
ret.red = color.red * 4; /*(2^5 - 1)/(2^3 - 1) = 31/7 = 4*/
|
||||
ret.green = color.green * 9; /*(2^6 - 1)/(2^3 - 1) = 63/7 = 9*/
|
||||
ret.blue = color.blue * 10; /*(2^5 - 1)/(2^2 - 1) = 31/3 = 10*/
|
||||
# else
|
||||
ret.red = color.red * 4;
|
||||
uint8_t g_tmp = color.green * 9;
|
||||
ret.green_h = (g_tmp & 0x1F) >> 3;
|
||||
ret.green_l = g_tmp & 0x07;
|
||||
ret.blue = color.blue * 10;
|
||||
# endif
|
||||
return ret.full;
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
return color.full;
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
lv_color16_t ret;
|
||||
# if LV_COLOR_16_SWAP == 0
|
||||
ret.red = color.red >> 3; /* 8 - 5 = 3*/
|
||||
ret.green = color.green >> 2; /* 8 - 6 = 2*/
|
||||
ret.blue = color.blue >> 3; /* 8 - 5 = 3*/
|
||||
# else
|
||||
ret.red = color.red >> 3;
|
||||
ret.green_h = (color.green & 0xE0) >> 5;
|
||||
ret.green_l = (color.green & 0x1C) >> 2;
|
||||
ret.blue = color.blue >> 3;
|
||||
# endif
|
||||
return ret.full;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline uint32_t lv_color_to32(lv_color_t color)
|
||||
{
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
if(color.full == 0) return 0;
|
||||
else return 0xFFFFFFFF;
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
lv_color32_t ret;
|
||||
ret.red = color.red * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
|
||||
ret.green = color.green * 36; /*(2^8 - 1)/(2^3 - 1) = 255/7 = 36*/
|
||||
ret.blue = color.blue * 85; /*(2^8 - 1)/(2^2 - 1) = 255/3 = 85*/
|
||||
ret.alpha = 0xFF;
|
||||
return ret.full;
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
# if LV_COLOR_16_SWAP == 0
|
||||
lv_color32_t ret;
|
||||
ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
|
||||
ret.green = color.green * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/
|
||||
ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
|
||||
ret.alpha = 0xFF;
|
||||
return ret.full;
|
||||
# else
|
||||
lv_color32_t ret;
|
||||
ret.red = color.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
|
||||
ret.green = ((color.green_h << 3) + color.green_l) * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/
|
||||
ret.blue = color.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
|
||||
ret.alpha = 0xFF;
|
||||
return ret.full;
|
||||
# endif
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
return color.full;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline lv_color_t lv_color_mix(const lv_color_t c1, const lv_color_t c2, uint8_t mix)
|
||||
{
|
||||
lv_color_t ret;
|
||||
#if LV_COLOR_DEPTH != 1 && LV_COLOR_DEPTH != 32
|
||||
/*LV_COLOR_DEPTH == 8, 16 or 32*/
|
||||
ret.red = (uint16_t)((uint16_t) c1.red * mix + (c2.red * (255 - mix))) >> 8;
|
||||
# if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP
|
||||
/*If swapped Green is in 2 parts*/
|
||||
uint16_t g_1 = (c1.green_h << 3) + c1.green_l;
|
||||
uint16_t g_2 = (c2.green_h << 3) + c2.green_l;
|
||||
uint16_t g_out = (uint16_t)((uint16_t) g_1 * mix + (g_2 * (255 - mix))) >> 8;
|
||||
ret.green_h = g_out >> 3;
|
||||
ret.green_l = g_out & 0x7;
|
||||
# else
|
||||
ret.green = (uint16_t)((uint16_t) c1.green * mix + (c2.green * (255 - mix))) >> 8;
|
||||
# endif
|
||||
ret.blue = (uint16_t)((uint16_t) c1.blue * mix + (c2.blue * (255 - mix))) >> 8;
|
||||
#else
|
||||
# if LV_COLOR_DEPTH == 32
|
||||
uint32_t rb = (((c1.full & 0x00FF00FF) * mix) + ((c2.full & 0x00FF00FF) * (255 - mix))) >> 8;
|
||||
uint32_t g = (((((c1.full & 0x0000FF00) >> 8) * mix) + (((c2.full & 0x0000FF00) >> 8) * (255 - mix))) >> 8) << 8;
|
||||
ret.full = 0xFF000000 | (0x00FF00FF & rb) | (0x0000FF00 & g);
|
||||
# else
|
||||
/*LV_COLOR_DEPTH == 1*/
|
||||
ret.full = mix > LV_OPA_50 ? c1.full : c2.full;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the brightness of a color
|
||||
* @param color a color
|
||||
* @return the brightness [0..255]
|
||||
*/
|
||||
static inline uint8_t lv_color_brightness(lv_color_t color)
|
||||
{
|
||||
lv_color32_t c32;
|
||||
c32.full = lv_color_to32(color);
|
||||
uint16_t bright = 3 * c32.red + c32.blue + 4 * c32.green;
|
||||
return (uint16_t) bright >> 3;
|
||||
}
|
||||
|
||||
/* The most simple macro to create a color from R,G and B values
|
||||
* The order of bit field is different on Big-endian and Little-endian machines*/
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(b8 >> 7 | g8 >> 7 | r8 >> 7)})
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 6, g8 >> 5, r8 >> 5}})
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
# if LV_COLOR_16_SWAP == 0
|
||||
# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8 >> 3, g8 >> 2, r8 >> 3}})
|
||||
# else
|
||||
# define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{g8 >> 5, r8 >> 3, b8 >> 3, (g8 >> 2) & 0x7}})
|
||||
# endif
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/
|
||||
#endif
|
||||
#else
|
||||
#if LV_COLOR_DEPTH == 1
|
||||
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){(r8 >> 7 | g8 >> 7 | b8 >> 7)})
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 6, g8 >> 5, b8 >> 5}})
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{r8 >> 3, g8 >> 2, b8 >> 3}})
|
||||
#elif LV_COLOR_DEPTH == 32
|
||||
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{0xff, r8, g8, b8}}) /*Fix 0xff alpha*/
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LV_COLOR_DEPTH == 32 // Concatenate into one 32-bit set.
|
||||
#define LV_COLOR_HEX(c) ((lv_color_t){.full = (c | 0xFF000000)})
|
||||
#else
|
||||
#define LV_COLOR_HEX(c) LV_COLOR_MAKE(((uint32_t)((uint32_t)c >> 16) & 0xFF), \
|
||||
((uint32_t)((uint32_t)c >> 8) & 0xFF), \
|
||||
((uint32_t) c & 0xFF))
|
||||
#endif
|
||||
|
||||
/*Usage LV_COLOR_HEX3(0x16C) which means LV_COLOR_HEX(0x1166CC)*/
|
||||
#define LV_COLOR_HEX3(c) LV_COLOR_MAKE((((c >> 4) & 0xF0) | ((c >> 8) & 0xF)), \
|
||||
((uint32_t)(c & 0xF0) | ((c & 0xF0) >> 4)), \
|
||||
((uint32_t)(c & 0xF) | ((c & 0xF) << 4)))
|
||||
|
||||
|
||||
/**
|
||||
* Convert a HSV color to RGB
|
||||
* @param h hue [0..359]
|
||||
* @param s saturation [0..100]
|
||||
* @param v value [0..100]
|
||||
* @return the given RGB color in RGB (with LV_COLOR_DEPTH depth)
|
||||
*/
|
||||
lv_color_t lv_color_hsv_to_rgb(uint16_t hue, uint8_t sat, uint8_t val);
|
||||
|
||||
/**
|
||||
* Convert an RGB color to HSV
|
||||
* @param r red
|
||||
* @param g green
|
||||
* @param b blue
|
||||
* @return the given RGB color n HSV
|
||||
*/
|
||||
lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r, uint8_t g, uint8_t b);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*USE_COLOR*/
|
269
bdk/libs/lvgl/lv_misc/lv_font.c
Normal file
269
bdk/libs/lvgl/lv_misc/lv_font.c
Normal file
|
@ -0,0 +1,269 @@
|
|||
/**
|
||||
* @file lv_font.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stddef.h>
|
||||
#include "lv_font.h"
|
||||
#include "lv_log.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the fonts
|
||||
*/
|
||||
void lv_font_init(void)
|
||||
{
|
||||
lv_font_builtin_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a font to an other to extend the character set.
|
||||
* @param child the font to add
|
||||
* @param parent this font will be extended. Using it later will contain the characters from `child`
|
||||
*/
|
||||
void lv_font_add(lv_font_t * child, lv_font_t * parent)
|
||||
{
|
||||
if(parent == NULL) return;
|
||||
|
||||
while(parent->next_page != NULL) {
|
||||
parent = parent->next_page; /*Got to the last page and add the new font there*/
|
||||
}
|
||||
|
||||
parent->next_page = child;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a font from a character set.
|
||||
* @param child the font to remove
|
||||
* @param parent remove `child` from here
|
||||
*/
|
||||
void lv_font_remove(lv_font_t * child, lv_font_t * parent)
|
||||
{
|
||||
if(parent == NULL) return;
|
||||
if(child == NULL) return;
|
||||
|
||||
while(parent->next_page != child) {
|
||||
parent = parent->next_page; /*Got to the last page and add the new font there*/
|
||||
}
|
||||
|
||||
parent->next_page = child->next_page;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tells if font which contains `letter` is monospace or not
|
||||
* @param font_p point to font
|
||||
* @param letter an UNICODE character code
|
||||
* @return true: the letter is monospace; false not monospace
|
||||
*/
|
||||
bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter)
|
||||
{
|
||||
const lv_font_t * font_i = font_p;
|
||||
int16_t w;
|
||||
while(font_i != NULL) {
|
||||
w = font_i->get_width(font_i, letter);
|
||||
if(w >= 0) {
|
||||
/*Glyph found*/
|
||||
if(font_i->monospace) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_i = font_i->next_page;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with the bitmap of a font.
|
||||
* @param font_p pointer to a font
|
||||
* @param letter an UNICODE character code
|
||||
* @return pointer to the bitmap of the letter
|
||||
*/
|
||||
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter)
|
||||
{
|
||||
const lv_font_t * font_i = font_p;
|
||||
while(font_i != NULL) {
|
||||
const uint8_t * bitmap = font_i->get_bitmap(font_i, letter);
|
||||
if(bitmap) return bitmap;
|
||||
|
||||
font_i = font_i->next_page;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a letter in a font. If `monospace` is set then return with it.
|
||||
* @param font_p pointer to a font
|
||||
* @param letter an UNICODE character code
|
||||
* @return the width of a letter
|
||||
*/
|
||||
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter)
|
||||
{
|
||||
const lv_font_t * font_i = font_p;
|
||||
int16_t w;
|
||||
while(font_i != NULL) {
|
||||
w = font_i->get_width(font_i, letter);
|
||||
if(w >= 0) {
|
||||
/*Glyph found*/
|
||||
uint8_t m = font_i->monospace;
|
||||
if(m) w = m;
|
||||
return w;
|
||||
}
|
||||
|
||||
font_i = font_i->next_page;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the letter without overwriting it with the `monospace` attribute
|
||||
* @param font_p pointer to a font
|
||||
* @param letter an UNICODE character code
|
||||
* @return the width of a letter
|
||||
*/
|
||||
uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter)
|
||||
{
|
||||
const lv_font_t * font_i = font_p;
|
||||
int16_t w;
|
||||
while(font_i != NULL) {
|
||||
w = font_i->get_width(font_i, letter);
|
||||
if(w >= 0) return w;
|
||||
|
||||
font_i = font_i->next_page;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bit-per-pixel of font
|
||||
* @param font pointer to font
|
||||
* @param letter a letter from font (font extensions can have different bpp)
|
||||
* @return bpp of the font (or font extension)
|
||||
*/
|
||||
uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter)
|
||||
{
|
||||
const lv_font_t * font_i = font;
|
||||
while(font_i != NULL) {
|
||||
if(letter >= font_i->unicode_first && letter <= font_i->unicode_last) {
|
||||
return font_i->bpp;
|
||||
}
|
||||
font_i = font_i->next_page;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range
|
||||
* @param font pointer to font
|
||||
* @param unicode_letter an unicode letter which bitmap should be get
|
||||
* @return pointer to the bitmap or NULL if not found
|
||||
*/
|
||||
const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter)
|
||||
{
|
||||
/*Check the range*/
|
||||
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
|
||||
|
||||
uint32_t index = (unicode_letter - font->unicode_first);
|
||||
return &font->glyph_bitmap[font->glyph_dsc[index].glyph_index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
|
||||
* @param font pointer to font
|
||||
* @param unicode_letter an unicode letter which bitmap should be get
|
||||
* @return pointer to the bitmap or NULL if not found
|
||||
*/
|
||||
const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter)
|
||||
{
|
||||
/*Check the range*/
|
||||
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; font->unicode_list[i] != 0; i++) {
|
||||
if(font->unicode_list[i] == unicode_letter) {
|
||||
return &font->glyph_bitmap[font->glyph_dsc[i].glyph_index];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range
|
||||
* @param font pointer to font
|
||||
* @param unicode_letter an unicode letter which width should be get
|
||||
* @return width of the gylph or -1 if not found
|
||||
*/
|
||||
int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter)
|
||||
{
|
||||
/*Check the range*/
|
||||
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t index = (unicode_letter - font->unicode_first);
|
||||
return font->glyph_dsc[index].w_px;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
|
||||
* @param font pointer to font
|
||||
* @param unicode_letter an unicode letter which width should be get
|
||||
* @return width of the glyph or -1 if not found
|
||||
*/
|
||||
int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter)
|
||||
{
|
||||
/*Check the range*/
|
||||
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return -1;
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; font->unicode_list[i] != 0; i++) {
|
||||
if(font->unicode_list[i] == unicode_letter) {
|
||||
return font->glyph_dsc[i].w_px;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
191
bdk/libs/lvgl/lv_misc/lv_font.h
Normal file
191
bdk/libs/lvgl/lv_misc/lv_font.h
Normal file
|
@ -0,0 +1,191 @@
|
|||
/**
|
||||
* @file lv_font.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_FONT_H
|
||||
#define LV_FONT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "lv_symbol_def.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t w_px :8;
|
||||
uint32_t glyph_index :24;
|
||||
} lv_font_glyph_dsc_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t unicode :21;
|
||||
uint32_t glyph_dsc_index :11;
|
||||
} lv_font_unicode_map_t;
|
||||
|
||||
typedef struct _lv_font_struct
|
||||
{
|
||||
uint32_t unicode_first;
|
||||
uint32_t unicode_last;
|
||||
const uint8_t * glyph_bitmap;
|
||||
const lv_font_glyph_dsc_t * glyph_dsc;
|
||||
const uint32_t * unicode_list;
|
||||
const uint8_t * (*get_bitmap)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's bitmap from a font*/
|
||||
int16_t (*get_width)(const struct _lv_font_struct *,uint32_t); /*Get a glyph's with with a given font*/
|
||||
struct _lv_font_struct * next_page; /*Pointer to a font extension*/
|
||||
uint32_t h_px :8;
|
||||
uint32_t bpp :4; /*Bit per pixel: 1, 2 or 4*/
|
||||
uint32_t monospace :8; /*Fix width (0: normal width)*/
|
||||
uint16_t glyph_cnt; /*Number of glyphs (letters) in the font*/
|
||||
} lv_font_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the fonts
|
||||
*/
|
||||
void lv_font_init(void);
|
||||
|
||||
/**
|
||||
* Add a font to an other to extend the character set.
|
||||
* @param child the font to add
|
||||
* @param parent this font will be extended. Using it later will contain the characters from `child`
|
||||
*/
|
||||
void lv_font_add(lv_font_t *child, lv_font_t *parent);
|
||||
|
||||
/**
|
||||
* Remove a font from a character set.
|
||||
* @param child the font to remove
|
||||
* @param parent remove `child` from here
|
||||
*/
|
||||
void lv_font_remove(lv_font_t * child, lv_font_t * parent);
|
||||
|
||||
/**
|
||||
* Tells if font which contains `letter` is monospace or not
|
||||
* @param font_p point to font
|
||||
* @param letter an UNICODE character code
|
||||
* @return true: the letter is monospace; false not monospace
|
||||
*/
|
||||
bool lv_font_is_monospace(const lv_font_t * font_p, uint32_t letter);
|
||||
|
||||
/**
|
||||
* Return with the bitmap of a font.
|
||||
* @param font_p pointer to a font
|
||||
* @param letter an UNICODE character code
|
||||
* @return pointer to the bitmap of the letter
|
||||
*/
|
||||
const uint8_t * lv_font_get_bitmap(const lv_font_t * font_p, uint32_t letter);
|
||||
|
||||
/**
|
||||
* Get the width of a letter in a font. If `monospace` is set then return with it.
|
||||
* @param font_p pointer to a font
|
||||
* @param letter an UNICODE character code
|
||||
* @return the width of a letter
|
||||
*/
|
||||
uint8_t lv_font_get_width(const lv_font_t * font_p, uint32_t letter);
|
||||
|
||||
|
||||
/**
|
||||
* Get the width of the letter without overwriting it with the `monospace` attribute
|
||||
* @param font_p pointer to a font
|
||||
* @param letter an UNICODE character code
|
||||
* @return the width of a letter
|
||||
*/
|
||||
uint8_t lv_font_get_real_width(const lv_font_t * font_p, uint32_t letter);
|
||||
|
||||
/**
|
||||
* Get the height of a font
|
||||
* @param font_p pointer to a font
|
||||
* @return the height of a font
|
||||
*/
|
||||
static inline uint8_t lv_font_get_height(const lv_font_t * font_p)
|
||||
{
|
||||
return font_p->h_px;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bit-per-pixel of font
|
||||
* @param font pointer to font
|
||||
* @param letter a letter from font (font extensions can have different bpp)
|
||||
* @return bpp of the font (or font extension)
|
||||
*/
|
||||
uint8_t lv_font_get_bpp(const lv_font_t * font, uint32_t letter);
|
||||
|
||||
/**
|
||||
* Generic bitmap get function used in 'font->get_bitmap' when the font contains all characters in the range
|
||||
* @param font pointer to font
|
||||
* @param unicode_letter an unicode letter which bitmap should be get
|
||||
* @return pointer to the bitmap or NULL if not found
|
||||
*/
|
||||
const uint8_t * lv_font_get_bitmap_continuous(const lv_font_t * font, uint32_t unicode_letter);
|
||||
|
||||
/**
|
||||
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
|
||||
* @param font pointer to font
|
||||
* @param unicode_letter an unicode letter which bitmap should be get
|
||||
* @return pointer to the bitmap or NULL if not found
|
||||
*/
|
||||
const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter);
|
||||
/**
|
||||
* Generic glyph width get function used in 'font->get_width' when the font contains all characters in the range
|
||||
* @param font pointer to font
|
||||
* @param unicode_letter an unicode letter which width should be get
|
||||
* @return width of the gylph or -1 if not found
|
||||
*/
|
||||
int16_t lv_font_get_width_continuous(const lv_font_t * font, uint32_t unicode_letter);
|
||||
|
||||
/**
|
||||
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
|
||||
* @param font pointer to font
|
||||
* @param unicode_letter an unicode letter which width should be get
|
||||
* @return width of the glyph or -1 if not found
|
||||
*/
|
||||
int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#define LV_FONT_DECLARE(font_name) extern lv_font_t font_name;
|
||||
|
||||
|
||||
/**********************
|
||||
* ADD BUILT IN FONTS
|
||||
**********************/
|
||||
#include "../lv_fonts/lv_font_builtin.h"
|
||||
|
||||
/*Declare the custom (user defined) fonts*/
|
||||
#ifdef LV_FONT_CUSTOM_DECLARE
|
||||
LV_FONT_CUSTOM_DECLARE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*USE_FONT*/
|
||||
|
627
bdk/libs/lvgl/lv_misc/lv_fs.c
Normal file
627
bdk/libs/lvgl/lv_misc/lv_fs.c
Normal file
|
@ -0,0 +1,627 @@
|
|||
/**
|
||||
* @file lv_fs.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_fs.h"
|
||||
#if USE_LV_FILESYSTEM
|
||||
|
||||
#include "lv_ll.h"
|
||||
#include <string.h>
|
||||
#include "lv_gc.h"
|
||||
|
||||
#if defined(LV_GC_INCLUDE)
|
||||
# include LV_GC_INCLUDE
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/* "free" is used as a function pointer (in lv_fs_drv_t).
|
||||
* We must make sure "free" was not defined to a platform specific
|
||||
* free function, otherwise compilation would fail.
|
||||
*/
|
||||
#ifdef free
|
||||
#undef free
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static const char * lv_fs_get_real_path(const char * path);
|
||||
static lv_fs_drv_t * lv_fs_get_drv(char letter);
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the File system interface
|
||||
*/
|
||||
void lv_fs_init(void)
|
||||
{
|
||||
lv_ll_init(&LV_GC_ROOT(_lv_drv_ll), sizeof(lv_fs_drv_t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a drive is rady or not. If the `ready` function was not initialized `true` will be returned.
|
||||
* @param letter letter of the drive
|
||||
* @return true: drive is ready; false: drive is not ready
|
||||
*/
|
||||
bool lv_fs_is_ready(char letter)
|
||||
{
|
||||
lv_fs_drv_t * drv = lv_fs_get_drv(letter);
|
||||
|
||||
if(drv == NULL) return false; /*An unknown driver in not ready*/
|
||||
|
||||
if(drv->ready == NULL) return true; /*Assume the driver is always ready if no handler provided*/
|
||||
|
||||
return drv->ready();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
|
||||
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode)
|
||||
{
|
||||
file_p->drv = NULL;
|
||||
file_p->file_d = NULL;
|
||||
|
||||
if(path == NULL) return LV_FS_RES_INV_PARAM;
|
||||
|
||||
char letter = path[0];
|
||||
|
||||
file_p->drv = lv_fs_get_drv(letter);
|
||||
|
||||
if(file_p->drv == NULL) {
|
||||
file_p->file_d = NULL;
|
||||
return LV_FS_RES_NOT_EX;
|
||||
}
|
||||
|
||||
if(file_p->drv->ready != NULL) {
|
||||
if(file_p->drv->ready() == false) {
|
||||
file_p->drv = NULL;
|
||||
file_p->file_d = NULL;
|
||||
return LV_FS_RES_HW_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
file_p->file_d = lv_mem_alloc(file_p->drv->file_size);
|
||||
lv_mem_assert(file_p->file_d);
|
||||
if(file_p->file_d == NULL) {
|
||||
file_p->drv = NULL;
|
||||
return LV_FS_RES_OUT_OF_MEM; /* Out of memory */
|
||||
}
|
||||
|
||||
if(file_p->drv->open == NULL) {
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
const char * real_path = lv_fs_get_real_path(path);
|
||||
lv_fs_res_t res = file_p->drv->open(file_p->file_d, real_path, mode);
|
||||
|
||||
if(res != LV_FS_RES_OK) {
|
||||
lv_mem_free(file_p->file_d);
|
||||
file_p->file_d = NULL;
|
||||
file_p->drv = NULL;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an already opened file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_close(lv_fs_file_t * file_p)
|
||||
{
|
||||
if(file_p->drv == NULL) {
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
if(file_p->drv->close == NULL) {
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
lv_fs_res_t res = file_p->drv->close(file_p->file_d);
|
||||
|
||||
lv_mem_free(file_p->file_d); /*Clean up*/
|
||||
file_p->file_d = NULL;
|
||||
file_p->drv = NULL;
|
||||
file_p->file_d = NULL;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a file
|
||||
* @param path path of the file to delete
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_remove(const char * path)
|
||||
{
|
||||
if(path == NULL) return LV_FS_RES_INV_PARAM;
|
||||
lv_fs_drv_t * drv = NULL;
|
||||
|
||||
char letter = path[0];
|
||||
|
||||
drv = lv_fs_get_drv(letter);
|
||||
if(drv == NULL) return LV_FS_RES_NOT_EX;
|
||||
if(drv->ready != NULL) {
|
||||
if(drv->ready() == false) return LV_FS_RES_HW_ERR;
|
||||
}
|
||||
|
||||
if(drv->remove == NULL) return LV_FS_RES_NOT_IMP;
|
||||
|
||||
const char * real_path = lv_fs_get_real_path(path);
|
||||
lv_fs_res_t res = drv->remove(real_path);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param buf pointer to a buffer where the read bytes are stored
|
||||
* @param btr Bytes To Read
|
||||
* @param br the number of real read bytes (Bytes Read). NULL if unused.
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_read(lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br)
|
||||
{
|
||||
if(br != NULL) *br = 0;
|
||||
if(file_p->drv == NULL) return LV_FS_RES_INV_PARAM;
|
||||
if(file_p->drv->read == NULL) return LV_FS_RES_NOT_IMP;
|
||||
|
||||
uint32_t br_tmp = 0;
|
||||
lv_fs_res_t res = file_p->drv->read(file_p->file_d, buf, btr, &br_tmp);
|
||||
if(br != NULL) *br = br_tmp;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write into a file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param buf pointer to a buffer with the bytes to write
|
||||
* @param btr Bytes To Write
|
||||
* @param br the number of real written bytes (Bytes Written). NULL if unused.
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_write(lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw)
|
||||
{
|
||||
if(bw != NULL) *bw = 0;
|
||||
|
||||
if(file_p->drv == NULL) {
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
if(file_p->drv->write == NULL) {
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
uint32_t bw_tmp = 0;
|
||||
lv_fs_res_t res = file_p->drv->write(file_p->file_d, buf, btw, &bw_tmp);
|
||||
if(bw != NULL) *bw = bw_tmp;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the position of the 'cursor' (read write pointer) in a file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param pos the new position expressed in bytes index (0: start of file)
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_seek(lv_fs_file_t * file_p, uint32_t pos)
|
||||
{
|
||||
if(file_p->drv == NULL) {
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
if(file_p->drv->seek == NULL) {
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
lv_fs_res_t res = file_p->drv->seek(file_p->file_d, pos);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the position of the read write pointer
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param pos_p pointer to store the position of the read write pointer
|
||||
* @return LV_FS_RES_OK or any error from 'fs_res_t'
|
||||
*/
|
||||
lv_fs_res_t lv_fs_tell(lv_fs_file_t * file_p, uint32_t * pos)
|
||||
{
|
||||
if(file_p->drv == NULL) {
|
||||
pos = 0;
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
if(file_p->drv->tell == NULL) {
|
||||
pos = 0;
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
lv_fs_res_t res = file_p->drv->tell(file_p->file_d, pos);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the file size to the current position of the read write pointer
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open )
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_trunc(lv_fs_file_t * file_p)
|
||||
{
|
||||
if(file_p->drv == NULL) {
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
if(file_p->drv->tell == NULL) {
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
lv_fs_res_t res = file_p->drv->trunc(file_p->file_d);
|
||||
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* Give the size of a file bytes
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param size pointer to a variable to store the size
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_size(lv_fs_file_t * file_p, uint32_t * size)
|
||||
{
|
||||
if(file_p->drv == NULL) {
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
if(file_p->drv->size == NULL) return LV_FS_RES_NOT_IMP;
|
||||
|
||||
|
||||
if(size == NULL) return LV_FS_RES_INV_PARAM;
|
||||
|
||||
lv_fs_res_t res = file_p->drv->size(file_p->file_d, size);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a file
|
||||
* @param oldname path to the file
|
||||
* @param newname path with the new name
|
||||
* @return LV_FS_RES_OK or any error from 'fs_res_t'
|
||||
*/
|
||||
lv_fs_res_t lv_fs_rename(const char * oldname, const char * newname)
|
||||
{
|
||||
if(!oldname || !newname) return LV_FS_RES_INV_PARAM;
|
||||
|
||||
char letter = oldname[0];
|
||||
|
||||
lv_fs_drv_t * drv = lv_fs_get_drv(letter);
|
||||
|
||||
if(!drv) {
|
||||
return LV_FS_RES_NOT_EX;
|
||||
}
|
||||
|
||||
if(drv->ready != NULL) {
|
||||
if(drv->ready() == false) {
|
||||
return LV_FS_RES_HW_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
if(drv->rename == NULL) return LV_FS_RES_NOT_IMP;
|
||||
|
||||
const char * old_real = lv_fs_get_real_path(oldname);
|
||||
const char * new_real = lv_fs_get_real_path(newname);
|
||||
lv_fs_res_t res = drv->rename(old_real, new_real);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize a 'fs_read_dir_t' variable for directory reading
|
||||
* @param rddir_p pointer to a 'fs_read_dir_t' variable
|
||||
* @param path path to a directory
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path)
|
||||
{
|
||||
if(path == NULL) return LV_FS_RES_INV_PARAM;
|
||||
|
||||
char letter = path[0];
|
||||
|
||||
rddir_p->drv = lv_fs_get_drv(letter);
|
||||
|
||||
if(rddir_p->drv == NULL) {
|
||||
rddir_p->dir_d = NULL;
|
||||
return LV_FS_RES_NOT_EX;
|
||||
}
|
||||
|
||||
rddir_p->dir_d = lv_mem_alloc(rddir_p->drv->rddir_size);
|
||||
lv_mem_assert(rddir_p->dir_d);
|
||||
if(rddir_p->dir_d == NULL) {
|
||||
rddir_p->dir_d = NULL;
|
||||
return LV_FS_RES_OUT_OF_MEM; /* Out of memory */
|
||||
}
|
||||
|
||||
if(rddir_p->drv->dir_open == NULL) {
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
const char * real_path = lv_fs_get_real_path(path);
|
||||
lv_fs_res_t res = rddir_p->drv->dir_open(rddir_p->dir_d, real_path);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next filename form a directory.
|
||||
* The name of the directories will begin with '/'
|
||||
* @param rddir_p pointer to an initialized 'fs_read_dir_t' variable
|
||||
* @param fn pointer to a buffer to store the filename
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_dir_read(lv_fs_dir_t * rddir_p, char * fn)
|
||||
{
|
||||
if(rddir_p->drv == NULL || rddir_p->dir_d == NULL) {
|
||||
fn[0] = '\0';
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
if(rddir_p->drv->dir_read == NULL) {
|
||||
return LV_FS_RES_NOT_IMP;
|
||||
}
|
||||
|
||||
lv_fs_res_t res = rddir_p->drv->dir_read(rddir_p->dir_d, fn);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the directory reading
|
||||
* @param rddir_p pointer to an initialized 'fs_read_dir_t' variable
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p)
|
||||
{
|
||||
if(rddir_p->drv == NULL || rddir_p->dir_d == NULL) {
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
lv_fs_res_t res;
|
||||
|
||||
if(rddir_p->drv->dir_close == NULL) {
|
||||
res = LV_FS_RES_NOT_IMP;
|
||||
} else {
|
||||
res = rddir_p->drv->dir_close(rddir_p->dir_d);
|
||||
}
|
||||
|
||||
lv_mem_free(rddir_p->dir_d); /*Clean up*/
|
||||
rddir_p->dir_d = NULL;
|
||||
rddir_p->drv = NULL;
|
||||
rddir_p->dir_d = NULL;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the free and total size of a driver in kB
|
||||
* @param letter the driver letter
|
||||
* @param total_p pointer to store the total size [kB]
|
||||
* @param free_p pointer to store the free size [kB]
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_free(char letter, uint32_t * total_p, uint32_t * free_p)
|
||||
{
|
||||
lv_fs_drv_t * drv = lv_fs_get_drv(letter);
|
||||
|
||||
if(drv == NULL) {
|
||||
return LV_FS_RES_INV_PARAM;
|
||||
}
|
||||
|
||||
lv_fs_res_t res;
|
||||
|
||||
if(drv->free == NULL) {
|
||||
res = LV_FS_RES_NOT_IMP;
|
||||
} else {
|
||||
uint32_t total_tmp = 0;
|
||||
uint32_t free_tmp = 0;
|
||||
res = drv->free(&total_tmp, &free_tmp);
|
||||
|
||||
if(total_p != NULL) *total_p = total_tmp;
|
||||
if(free_p != NULL) *free_p = free_tmp;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new drive
|
||||
* @param drv_p pointer to an lv_fs_drv_t structure which is inited with the
|
||||
* corresponding function pointers. The data will be copied so the variable can be local.
|
||||
*/
|
||||
void lv_fs_add_drv(lv_fs_drv_t * drv_p)
|
||||
{
|
||||
/*Save the new driver*/
|
||||
lv_fs_drv_t * new_drv;
|
||||
new_drv = lv_ll_ins_head(&LV_GC_ROOT(_lv_drv_ll));
|
||||
lv_mem_assert(new_drv);
|
||||
if(new_drv == NULL) return;
|
||||
|
||||
memcpy(new_drv, drv_p, sizeof(lv_fs_drv_t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill a buffer with the letters of existing drivers
|
||||
* @param buf buffer to store the letters ('\0' added after the last letter)
|
||||
* @return the buffer
|
||||
*/
|
||||
char * lv_fs_get_letters(char * buf)
|
||||
{
|
||||
lv_fs_drv_t * drv;
|
||||
uint8_t i = 0;
|
||||
|
||||
LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) {
|
||||
buf[i] = drv->letter;
|
||||
i++;
|
||||
}
|
||||
|
||||
buf[i] = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return with the extension of the filename
|
||||
* @param fn string with a filename
|
||||
* @return pointer to the beginning extension or empty string if no extension
|
||||
*/
|
||||
const char * lv_fs_get_ext(const char * fn)
|
||||
{
|
||||
uint16_t i;
|
||||
for(i = strlen(fn); i > 0; i --) {
|
||||
if(fn[i] == '.') {
|
||||
return &fn[i + 1];
|
||||
} else if(fn[i] == '/' || fn[i] == '\\') {
|
||||
return ""; /*No extension if a '\' or '/' found*/
|
||||
}
|
||||
}
|
||||
|
||||
return ""; /*Empty string if no '.' in the file name. */
|
||||
}
|
||||
|
||||
/**
|
||||
* Step up one level
|
||||
* @param path pointer to a file name
|
||||
* @return the truncated file name
|
||||
*/
|
||||
char * lv_fs_up(char * path)
|
||||
{
|
||||
uint16_t len = strlen(path);
|
||||
if(len == 0) return path;
|
||||
|
||||
len --; /*Go before the trailing '\0'*/
|
||||
|
||||
/*Ignore trailing '/' or '\'*/
|
||||
while(path[len] == '/' || path[len] == '\\') {
|
||||
path[len] = '\0';
|
||||
if(len > 0) len --;
|
||||
else return path;
|
||||
}
|
||||
|
||||
uint16_t i;
|
||||
for(i = len; i > 0; i --) {
|
||||
if(path[i] == '/' || path[i] == '\\') break;
|
||||
}
|
||||
|
||||
if(i > 0) path[i] = '\0';
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last element of a path (e.g. U:/folder/file -> file)
|
||||
* @param path a character sting with the path to search in
|
||||
* @return pointer to the beginning of the last element in the path
|
||||
*/
|
||||
const char * lv_fs_get_last(const char * path)
|
||||
{
|
||||
uint16_t len = strlen(path);
|
||||
if(len == 0) return path;
|
||||
|
||||
len --; /*Go before the trailing '\0'*/
|
||||
|
||||
/*Ignore trailing '/' or '\'*/
|
||||
while(path[len] == '/' || path[len] == '\\') {
|
||||
if(len > 0) len --;
|
||||
else return path;
|
||||
}
|
||||
|
||||
uint16_t i;
|
||||
for(i = len; i > 0; i --) {
|
||||
if(path[i] == '/' || path[i] == '\\') break;
|
||||
}
|
||||
|
||||
/*No '/' or '\' in the path so return with path itself*/
|
||||
if(i == 0) return path;
|
||||
|
||||
return &path[i + 1];
|
||||
}
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Leave the driver letters and / or \ letters from beginning of the path
|
||||
* @param path path string (E.g. S:/folder/file.txt)
|
||||
* @return pointer to the beginning of the real path (E.g. folder/file.txt)
|
||||
*/
|
||||
static const char * lv_fs_get_real_path(const char * path)
|
||||
{
|
||||
/* Example path: "S:/folder/file.txt"
|
||||
* Leave the letter and the : / \ characters*/
|
||||
|
||||
path ++; /*Ignore the driver letter*/
|
||||
|
||||
while(*path != '\0') {
|
||||
if(*path == ':' || *path == '\\' || *path == '/') {
|
||||
path ++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give a pointer to a driver from its letter
|
||||
* @param letter the driver letter
|
||||
* @return pointer to a driver or NULL if not found
|
||||
*/
|
||||
static lv_fs_drv_t * lv_fs_get_drv(char letter)
|
||||
{
|
||||
lv_fs_drv_t * drv;
|
||||
|
||||
LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) {
|
||||
if(drv->letter == letter) {
|
||||
return drv;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /*USE_LV_FILESYSTEM*/
|
276
bdk/libs/lvgl/lv_misc/lv_fs.h
Normal file
276
bdk/libs/lvgl/lv_misc/lv_fs.h
Normal file
|
@ -0,0 +1,276 @@
|
|||
/**
|
||||
* @file lv_fs.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_FS_H
|
||||
#define LV_FS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_LV_FILESYSTEM
|
||||
|
||||
#include <stdint.h>
|
||||
#include "lv_mem.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_FS_MAX_FN_LENGTH 64
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
enum
|
||||
{
|
||||
LV_FS_RES_OK = 0,
|
||||
LV_FS_RES_HW_ERR, /*Low level hardware error*/
|
||||
LV_FS_RES_FS_ERR, /*Error in the file system structure */
|
||||
LV_FS_RES_NOT_EX, /*Driver, file or directory is not exists*/
|
||||
LV_FS_RES_FULL, /*Disk full*/
|
||||
LV_FS_RES_LOCKED, /*The file is already opened*/
|
||||
LV_FS_RES_DENIED, /*Access denied. Check 'fs_open' modes and write protect*/
|
||||
LV_FS_RES_BUSY, /*The file system now can't handle it, try later*/
|
||||
LV_FS_RES_TOUT, /*Process time outed*/
|
||||
LV_FS_RES_NOT_IMP, /*Requested function is not implemented*/
|
||||
LV_FS_RES_OUT_OF_MEM, /*Not enough memory for an internal operation*/
|
||||
LV_FS_RES_INV_PARAM, /*Invalid parameter among arguments*/
|
||||
LV_FS_RES_UNKNOWN, /*Other unknown error*/
|
||||
};
|
||||
typedef uint8_t lv_fs_res_t;
|
||||
|
||||
struct __lv_fs_drv_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void * file_d;
|
||||
struct __lv_fs_drv_t* drv;
|
||||
} lv_fs_file_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void * dir_d;
|
||||
struct __lv_fs_drv_t * drv;
|
||||
} lv_fs_dir_t;
|
||||
|
||||
enum
|
||||
{
|
||||
LV_FS_MODE_WR = 0x01,
|
||||
LV_FS_MODE_RD = 0x02,
|
||||
};
|
||||
typedef uint8_t lv_fs_mode_t;
|
||||
|
||||
typedef struct __lv_fs_drv_t
|
||||
{
|
||||
char letter;
|
||||
uint16_t file_size;
|
||||
uint16_t rddir_size;
|
||||
bool (*ready) (void);
|
||||
|
||||
lv_fs_res_t (*open) (void * file_p, const char * path, lv_fs_mode_t mode);
|
||||
lv_fs_res_t (*close) (void * file_p);
|
||||
lv_fs_res_t (*remove) (const char * fn);
|
||||
lv_fs_res_t (*read) (void * file_p, void * buf, uint32_t btr, uint32_t * br);
|
||||
lv_fs_res_t (*write) (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
|
||||
lv_fs_res_t (*seek) (void * file_p, uint32_t pos);
|
||||
lv_fs_res_t (*tell) (void * file_p, uint32_t * pos_p);
|
||||
lv_fs_res_t (*trunc) (void * file_p);
|
||||
lv_fs_res_t (*size) (void * file_p, uint32_t * size_p);
|
||||
lv_fs_res_t (*rename) (const char * oldname, const char * newname);
|
||||
lv_fs_res_t (*free) (uint32_t * total_p, uint32_t * free_p);
|
||||
|
||||
lv_fs_res_t (*dir_open) (void * rddir_p, const char * path);
|
||||
lv_fs_res_t (*dir_read) (void * rddir_p, char * fn);
|
||||
lv_fs_res_t (*dir_close) (void * rddir_p);
|
||||
} lv_fs_drv_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize the File system interface
|
||||
*/
|
||||
void lv_fs_init(void);
|
||||
|
||||
/**
|
||||
* Add a new drive
|
||||
* @param drv_p pointer to an lv_fs_drv_t structure which is inited with the
|
||||
* corresponding function pointers. The data will be copied so the variable can be local.
|
||||
*/
|
||||
void lv_fs_add_drv(lv_fs_drv_t * drv_p);
|
||||
|
||||
/**
|
||||
* Test if a drive is rady or not. If the `ready` function was not initialized `true` will be returned.
|
||||
* @param letter letter of the drive
|
||||
* @return true: drive is ready; false: drive is not ready
|
||||
*/
|
||||
bool lv_fs_is_ready(char letter);
|
||||
|
||||
/**
|
||||
* Open a file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param path path to the file beginning with the driver letter (e.g. S:/folder/file.txt)
|
||||
* @param mode read: FS_MODE_RD, write: FS_MODE_WR, both: FS_MODE_RD | FS_MODE_WR
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_open (lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mode);
|
||||
|
||||
/**
|
||||
* Close an already opened file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_close (lv_fs_file_t * file_p);
|
||||
|
||||
/**
|
||||
* Delete a file
|
||||
* @param path path of the file to delete
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_remove (const char * path);
|
||||
|
||||
/**
|
||||
* Read from a file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param buf pointer to a buffer where the read bytes are stored
|
||||
* @param btr Bytes To Read
|
||||
* @param br the number of real read bytes (Bytes Read). NULL if unused.
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_read (lv_fs_file_t * file_p, void * buf, uint32_t btr, uint32_t * br);
|
||||
|
||||
/**
|
||||
* Write into a file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param buf pointer to a buffer with the bytes to write
|
||||
* @param btr Bytes To Write
|
||||
* @param br the number of real written bytes (Bytes Written). NULL if unused.
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_write (lv_fs_file_t * file_p, const void * buf, uint32_t btw, uint32_t * bw);
|
||||
|
||||
/**
|
||||
* Set the position of the 'cursor' (read write pointer) in a file
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param pos the new position expressed in bytes index (0: start of file)
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_seek (lv_fs_file_t * file_p, uint32_t pos);
|
||||
|
||||
/**
|
||||
* Give the position of the read write pointer
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param pos_p pointer to store the position of the read write pointer
|
||||
* @return LV_FS_RES_OK or any error from 'fs_res_t'
|
||||
*/
|
||||
lv_fs_res_t lv_fs_tell (lv_fs_file_t * file_p, uint32_t * pos);
|
||||
|
||||
/**
|
||||
* Truncate the file size to the current position of the read write pointer
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_fs_open )
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_trunc (lv_fs_file_t * file_p);
|
||||
|
||||
/**
|
||||
* Give the size of a file bytes
|
||||
* @param file_p pointer to a lv_fs_file_t variable
|
||||
* @param size pointer to a variable to store the size
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_size (lv_fs_file_t * file_p, uint32_t * size);
|
||||
|
||||
/**
|
||||
* Rename a file
|
||||
* @param oldname path to the file
|
||||
* @param newname path with the new name
|
||||
* @return LV_FS_RES_OK or any error from 'fs_res_t'
|
||||
*/
|
||||
lv_fs_res_t lv_fs_rename (const char * oldname, const char * newname);
|
||||
|
||||
/**
|
||||
* Initialize a 'fs_dir_t' variable for directory reading
|
||||
* @param rddir_p pointer to a 'fs_read_dir_t' variable
|
||||
* @param path path to a directory
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path);
|
||||
|
||||
/**
|
||||
* Read the next filename form a directory.
|
||||
* The name of the directories will begin with '/'
|
||||
* @param rddir_p pointer to an initialized 'fs_rdir_t' variable
|
||||
* @param fn pointer to a buffer to store the filename
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_dir_read (lv_fs_dir_t * rddir_p, char * fn);
|
||||
|
||||
/**
|
||||
* Close the directory reading
|
||||
* @param rddir_p pointer to an initialized 'fs_dir_t' variable
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_dir_close (lv_fs_dir_t * rddir_p);
|
||||
|
||||
/**
|
||||
* Get the free and total size of a driver in kB
|
||||
* @param letter the driver letter
|
||||
* @param total_p pointer to store the total size [kB]
|
||||
* @param free_p pointer to store the free size [kB]
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_fs_free (char letter, uint32_t * total_p, uint32_t * free_p);
|
||||
|
||||
/**
|
||||
* Fill a buffer with the letters of existing drivers
|
||||
* @param buf buffer to store the letters ('\0' added after the last letter)
|
||||
* @return the buffer
|
||||
*/
|
||||
char * lv_fs_get_letters(char * buf);
|
||||
|
||||
/**
|
||||
* Return with the extension of the filename
|
||||
* @param fn string with a filename
|
||||
* @return pointer to the beginning extension or empty string if no extension
|
||||
*/
|
||||
const char * lv_fs_get_ext(const char * fn);
|
||||
|
||||
/**
|
||||
* Step up one level
|
||||
* @param path pointer to a file name
|
||||
* @return the truncated file name
|
||||
*/
|
||||
char * lv_fs_up(char * path);
|
||||
|
||||
/**
|
||||
* Get the last element of a path (e.g. U:/folder/file -> file)
|
||||
* @param buf buffer to store the letters ('\0' added after the last letter)
|
||||
* @return pointer to the beginning of the last element in the path
|
||||
*/
|
||||
const char * lv_fs_get_last(const char * path);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_FILESYSTEM*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_FS_H*/
|
40
bdk/libs/lvgl/lv_misc/lv_gc.c
Normal file
40
bdk/libs/lvgl/lv_misc/lv_gc.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* @file lv_gc.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#include "lv_gc.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
#if (!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0
|
||||
LV_ROOTS
|
||||
#endif /* LV_ENABLE_GC */
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
75
bdk/libs/lvgl/lv_misc/lv_gc.h
Normal file
75
bdk/libs/lvgl/lv_misc/lv_gc.h
Normal file
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* @file lv_gc.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_GC_H
|
||||
#define LV_GC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "lv_mem.h"
|
||||
#include "lv_ll.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
#define LV_GC_ROOTS(prefix) \
|
||||
prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \
|
||||
prefix lv_ll_t _lv_scr_ll; /*Linked list of screens*/ \
|
||||
prefix lv_ll_t _lv_drv_ll;\
|
||||
prefix lv_ll_t _lv_file_ll;\
|
||||
prefix lv_ll_t _lv_anim_ll;\
|
||||
prefix void * _lv_def_scr;\
|
||||
prefix void * _lv_act_scr;\
|
||||
prefix void * _lv_top_layer;\
|
||||
prefix void * _lv_sys_layer;\
|
||||
prefix void * _lv_task_act;\
|
||||
prefix void * _lv_indev_list;\
|
||||
prefix void * _lv_disp_list;\
|
||||
|
||||
#define LV_NO_PREFIX
|
||||
#define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX)
|
||||
|
||||
#if LV_ENABLE_GC == 1
|
||||
# if LV_MEM_CUSTOM != 1
|
||||
# error "GC requires CUSTOM_MEM"
|
||||
# endif /* LV_MEM_CUSTOM */
|
||||
#else /* LV_ENABLE_GC */
|
||||
# define LV_GC_ROOT(x) x
|
||||
LV_GC_ROOTS(extern)
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_GC_H*/
|
376
bdk/libs/lvgl/lv_misc/lv_ll.c
Normal file
376
bdk/libs/lvgl/lv_misc/lv_ll.c
Normal file
|
@ -0,0 +1,376 @@
|
|||
/**
|
||||
* @file lv_ll.c
|
||||
* Handle linked lists.
|
||||
* The nodes are dynamically allocated by the 'lv_mem' module,
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lv_ll.h"
|
||||
#include "lv_mem.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LL_NODE_META_SIZE (sizeof(lv_ll_node_t*) + sizeof(lv_ll_node_t*))
|
||||
#define LL_PREV_P_OFFSET(ll_p) (ll_p->n_size)
|
||||
#define LL_NEXT_P_OFFSET(ll_p) (ll_p->n_size + sizeof(lv_ll_node_t*))
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void node_set_prev(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * prev);
|
||||
static void node_set_next(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * next);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize linked list
|
||||
* @param ll_dsc pointer to ll_dsc variable
|
||||
* @param node_size the size of 1 node in bytes
|
||||
*/
|
||||
void lv_ll_init(lv_ll_t * ll_p, uint32_t node_size)
|
||||
{
|
||||
ll_p->head = NULL;
|
||||
ll_p->tail = NULL;
|
||||
#ifdef LV_MEM_ENV64
|
||||
/*Round the size up to 8*/
|
||||
if(node_size & 0x7) {
|
||||
node_size = node_size & (~0x7);
|
||||
node_size += 8;
|
||||
}
|
||||
#else
|
||||
/*Round the size up to 4*/
|
||||
if(node_size & 0x3) {
|
||||
node_size = node_size & (~0x3);
|
||||
node_size += 4;
|
||||
}
|
||||
#endif
|
||||
|
||||
ll_p->n_size = node_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new head to a linked list
|
||||
* @param ll_p pointer to linked list
|
||||
* @return pointer to the new head
|
||||
*/
|
||||
void * lv_ll_ins_head(lv_ll_t * ll_p)
|
||||
{
|
||||
lv_ll_node_t * n_new;
|
||||
|
||||
n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE);
|
||||
|
||||
if(n_new != NULL) {
|
||||
node_set_prev(ll_p, n_new, NULL); /*No prev. before the new head*/
|
||||
node_set_next(ll_p, n_new, ll_p->head); /*After new comes the old head*/
|
||||
|
||||
if(ll_p->head != NULL) { /*If there is old head then before it goes the new*/
|
||||
node_set_prev(ll_p, ll_p->head, n_new);
|
||||
}
|
||||
|
||||
ll_p->head = n_new; /*Set the new head in the dsc.*/
|
||||
if(ll_p->tail == NULL) {/*If there is no tail (1. node) set the tail too*/
|
||||
ll_p->tail = n_new;
|
||||
}
|
||||
}
|
||||
|
||||
return n_new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new node in front of the n_act node
|
||||
* @param ll_p pointer to linked list
|
||||
* @param n_act pointer a node
|
||||
* @return pointer to the new head
|
||||
*/
|
||||
void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act)
|
||||
{
|
||||
lv_ll_node_t * n_new;
|
||||
lv_ll_node_t * n_prev;
|
||||
|
||||
if(NULL == ll_p || NULL == n_act) return NULL;
|
||||
|
||||
if(lv_ll_get_head(ll_p) == n_act) {
|
||||
n_new = lv_ll_ins_head(ll_p);
|
||||
if(n_new == NULL) return NULL;
|
||||
} else {
|
||||
n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE);
|
||||
if(n_new == NULL) return NULL;
|
||||
|
||||
n_prev = lv_ll_get_prev(ll_p, n_act);
|
||||
node_set_next(ll_p, n_prev, n_new);
|
||||
node_set_prev(ll_p, n_new, n_prev);
|
||||
node_set_prev(ll_p, n_act, n_new);
|
||||
node_set_next(ll_p, n_new, n_act);
|
||||
}
|
||||
|
||||
return n_new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new tail to a linked list
|
||||
* @param ll_p pointer to linked list
|
||||
* @return pointer to the new tail
|
||||
*/
|
||||
void * lv_ll_ins_tail(lv_ll_t * ll_p)
|
||||
{
|
||||
lv_ll_node_t * n_new;
|
||||
|
||||
n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE);
|
||||
if(n_new == NULL) return NULL;
|
||||
|
||||
if(n_new != NULL) {
|
||||
node_set_next(ll_p, n_new, NULL); /*No next after the new tail*/
|
||||
node_set_prev(ll_p, n_new, ll_p->tail); /*The prev. before new is tho old tail*/
|
||||
if(ll_p->tail != NULL) { /*If there is old tail then the new comes after it*/
|
||||
node_set_next(ll_p, ll_p->tail, n_new);
|
||||
}
|
||||
|
||||
ll_p->tail = n_new; /*Set the new tail in the dsc.*/
|
||||
if(ll_p->head == NULL) { /*If there is no head (1. node) set the head too*/
|
||||
ll_p->head = n_new;
|
||||
}
|
||||
}
|
||||
|
||||
return n_new;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the node 'node_p' from 'll_p' linked list.
|
||||
* It does not free the the memory of node.
|
||||
* @param ll_p pointer to the linked list of 'node_p'
|
||||
* @param node_p pointer to node in 'll_p' linked list
|
||||
*/
|
||||
void lv_ll_rem(lv_ll_t * ll_p, void * node_p)
|
||||
{
|
||||
if(lv_ll_get_head(ll_p) == node_p) {
|
||||
/*The new head will be the node after 'n_act'*/
|
||||
ll_p->head = lv_ll_get_next(ll_p, node_p);
|
||||
if(ll_p->head == NULL) {
|
||||
ll_p->tail = NULL;
|
||||
} else {
|
||||
node_set_prev(ll_p, ll_p->head, NULL);
|
||||
}
|
||||
} else if(lv_ll_get_tail(ll_p) == node_p) {
|
||||
/*The new tail will be the node before 'n_act'*/
|
||||
ll_p->tail = lv_ll_get_prev(ll_p, node_p);
|
||||
if(ll_p->tail == NULL) {
|
||||
ll_p->head = NULL;
|
||||
} else {
|
||||
node_set_next(ll_p, ll_p->tail, NULL);
|
||||
}
|
||||
} else {
|
||||
lv_ll_node_t * n_prev = lv_ll_get_prev(ll_p, node_p);
|
||||
lv_ll_node_t * n_next = lv_ll_get_next(ll_p, node_p);
|
||||
|
||||
node_set_next(ll_p, n_prev, n_next);
|
||||
node_set_prev(ll_p, n_next, n_prev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove and free all elements from a linked list. The list remain valid but become empty.
|
||||
* @param ll_p pointer to linked list
|
||||
*/
|
||||
void lv_ll_clear(lv_ll_t * ll_p)
|
||||
{
|
||||
void * i;
|
||||
void * i_next;
|
||||
|
||||
i = lv_ll_get_head(ll_p);
|
||||
i_next = NULL;
|
||||
|
||||
while(i != NULL) {
|
||||
i_next = lv_ll_get_next(ll_p, i);
|
||||
|
||||
lv_ll_rem(ll_p, i);
|
||||
lv_mem_free(i);
|
||||
|
||||
i = i_next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a node to a new linked list
|
||||
* @param ll_ori_p pointer to the original (old) linked list
|
||||
* @param ll_new_p pointer to the new linked list
|
||||
* @param node pointer to a node
|
||||
*/
|
||||
void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node)
|
||||
{
|
||||
lv_ll_rem(ll_ori_p, node);
|
||||
|
||||
/*Set node as head*/
|
||||
node_set_prev(ll_new_p, node, NULL);
|
||||
node_set_next(ll_new_p, node, ll_new_p->head);
|
||||
|
||||
if(ll_new_p->head != NULL) { /*If there is old head then before it goes the new*/
|
||||
node_set_prev(ll_new_p, ll_new_p->head, node);
|
||||
}
|
||||
|
||||
ll_new_p->head = node; /*Set the new head in the dsc.*/
|
||||
if(ll_new_p->tail == NULL) { /*If there is no tail (first node) set the tail too*/
|
||||
ll_new_p->tail = node;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with head node of the linked list
|
||||
* @param ll_p pointer to linked list
|
||||
* @return pointer to the head of 'll_p'
|
||||
*/
|
||||
void * lv_ll_get_head(const lv_ll_t * ll_p)
|
||||
{
|
||||
void * head = NULL;
|
||||
|
||||
if(ll_p != NULL) {
|
||||
head = ll_p->head;
|
||||
}
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with tail node of the linked list
|
||||
* @param ll_p pointer to linked list
|
||||
* @return pointer to the head of 'll_p'
|
||||
*/
|
||||
void * lv_ll_get_tail(const lv_ll_t * ll_p)
|
||||
{
|
||||
void * tail = NULL;
|
||||
|
||||
if(ll_p != NULL) {
|
||||
tail = ll_p->tail;
|
||||
}
|
||||
|
||||
return tail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with the pointer of the next node after 'n_act'
|
||||
* @param ll_p pointer to linked list
|
||||
* @param n_act pointer a node
|
||||
* @return pointer to the next node
|
||||
*/
|
||||
void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act)
|
||||
{
|
||||
void * next = NULL;
|
||||
|
||||
if(ll_p != NULL) {
|
||||
const lv_ll_node_t * n_act_d = n_act;
|
||||
memcpy(&next, n_act_d + LL_NEXT_P_OFFSET(ll_p), sizeof(void *));
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with the pointer of the previous node after 'n_act'
|
||||
* @param ll_p pointer to linked list
|
||||
* @param n_act pointer a node
|
||||
* @return pointer to the previous node
|
||||
*/
|
||||
void * lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act)
|
||||
{
|
||||
void * prev = NULL;
|
||||
|
||||
if(ll_p != NULL) {
|
||||
const lv_ll_node_t * n_act_d = n_act;
|
||||
memcpy(&prev, n_act_d + LL_PREV_P_OFFSET(ll_p), sizeof(void *));
|
||||
}
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
void lv_ll_swap(lv_ll_t * ll_p, void * n1_p, void * n2_p)
|
||||
{
|
||||
(void)(ll_p);
|
||||
(void)(n1_p);
|
||||
(void)(n2_p);
|
||||
/*TODO*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a nodw before an other node in the same linked list
|
||||
* @param ll_p pointer to a linked list
|
||||
* @param n_act pointer to node to move
|
||||
* @param n_after pointer to a node which should be after `n_act`
|
||||
*/
|
||||
void lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after)
|
||||
{
|
||||
if(n_act == n_after) return; /*Can't move before itself*/
|
||||
|
||||
|
||||
void * n_before;
|
||||
if(n_after != NULL) n_before = lv_ll_get_prev(ll_p, n_after);
|
||||
else n_before = lv_ll_get_tail(ll_p); /*if `n_after` is NULL `n_act` should be the new tail*/
|
||||
|
||||
if(n_act == n_before) return; /*Already before `n_after`*/
|
||||
|
||||
/*It's much easier to remove from the list and add again*/
|
||||
lv_ll_rem(ll_p, n_act);
|
||||
|
||||
/*Add again by setting the prev. and next nodes*/
|
||||
node_set_next(ll_p, n_before, n_act);
|
||||
node_set_prev(ll_p, n_act, n_before);
|
||||
node_set_prev(ll_p, n_after, n_act);
|
||||
node_set_next(ll_p, n_act, n_after);
|
||||
|
||||
/*If `n_act` was moved before NULL then it become the new tail*/
|
||||
if(n_after == NULL) ll_p->tail = n_act;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Set the 'pervious node pointer' of a node
|
||||
* @param ll_p pointer to linked list
|
||||
* @param act pointer to a node which prev. node pointer should be set
|
||||
* @param prev pointer to a node which should be the previous node before 'act'
|
||||
*/
|
||||
static void node_set_prev(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * prev)
|
||||
{
|
||||
if(act == NULL) return; /*Can't set the prev node of `NULL`*/
|
||||
|
||||
uint32_t node_p_size = sizeof(lv_ll_node_t *);
|
||||
if(prev) memcpy(act + LL_PREV_P_OFFSET(ll_p), &prev, node_p_size);
|
||||
else memset(act + LL_PREV_P_OFFSET(ll_p), 0, node_p_size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the 'next node pointer' of a node
|
||||
* @param ll_p pointer to linked list
|
||||
* @param act pointer to a node which next node pointer should be set
|
||||
* @param next pointer to a node which should be the next node before 'act'
|
||||
*/
|
||||
static void node_set_next(lv_ll_t * ll_p, lv_ll_node_t * act, lv_ll_node_t * next)
|
||||
{
|
||||
if(act == NULL) return; /*Can't set the next node of `NULL`*/
|
||||
|
||||
uint32_t node_p_size = sizeof(lv_ll_node_t *);
|
||||
if(next) memcpy(act + LL_NEXT_P_OFFSET(ll_p), &next, node_p_size);
|
||||
else memset(act + LL_NEXT_P_OFFSET(ll_p), 0, node_p_size);
|
||||
}
|
||||
|
145
bdk/libs/lvgl/lv_misc/lv_ll.h
Normal file
145
bdk/libs/lvgl/lv_misc/lv_ll.h
Normal file
|
@ -0,0 +1,145 @@
|
|||
/**
|
||||
* @file lv_ll.c
|
||||
* Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' module.
|
||||
*/
|
||||
|
||||
#ifndef LV_LL_H
|
||||
#define LV_LL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_mem.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/*Dummy type to make handling easier*/
|
||||
typedef uint8_t lv_ll_node_t;
|
||||
|
||||
/*Description of a linked list*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t n_size;
|
||||
lv_ll_node_t* head;
|
||||
lv_ll_node_t* tail;
|
||||
} lv_ll_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initialize linked list
|
||||
* @param ll_dsc pointer to ll_dsc variable
|
||||
* @param node_size the size of 1 node in bytes
|
||||
*/
|
||||
void lv_ll_init(lv_ll_t * ll_p, uint32_t node_size);
|
||||
|
||||
/**
|
||||
* Add a new head to a linked list
|
||||
* @param ll_p pointer to linked list
|
||||
* @return pointer to the new head
|
||||
*/
|
||||
void * lv_ll_ins_head(lv_ll_t * ll_p);
|
||||
|
||||
/**
|
||||
* Insert a new node in front of the n_act node
|
||||
* @param ll_p pointer to linked list
|
||||
* @param n_act pointer a node
|
||||
* @return pointer to the new head
|
||||
*/
|
||||
void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act);
|
||||
|
||||
/**
|
||||
* Add a new tail to a linked list
|
||||
* @param ll_p pointer to linked list
|
||||
* @return pointer to the new tail
|
||||
*/
|
||||
void * lv_ll_ins_tail(lv_ll_t * ll_p);
|
||||
|
||||
/**
|
||||
* Remove the node 'node_p' from 'll_p' linked list.
|
||||
* It does not free the the memory of node.
|
||||
* @param ll_p pointer to the linked list of 'node_p'
|
||||
* @param node_p pointer to node in 'll_p' linked list
|
||||
*/
|
||||
void lv_ll_rem(lv_ll_t * ll_p, void * node_p);
|
||||
|
||||
/**
|
||||
* Remove and free all elements from a linked list. The list remain valid but become empty.
|
||||
* @param ll_p pointer to linked list
|
||||
*/
|
||||
void lv_ll_clear(lv_ll_t * ll_p);
|
||||
|
||||
/**
|
||||
* Move a node to a new linked list
|
||||
* @param ll_ori_p pointer to the original (old) linked list
|
||||
* @param ll_new_p pointer to the new linked list
|
||||
* @param node pointer to a node
|
||||
*/
|
||||
void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node);
|
||||
|
||||
/**
|
||||
* Return with head node of the linked list
|
||||
* @param ll_p pointer to linked list
|
||||
* @return pointer to the head of 'll_p'
|
||||
*/
|
||||
void * lv_ll_get_head(const lv_ll_t * ll_p);
|
||||
|
||||
/**
|
||||
* Return with tail node of the linked list
|
||||
* @param ll_p pointer to linked list
|
||||
* @return pointer to the head of 'll_p'
|
||||
*/
|
||||
void * lv_ll_get_tail(const lv_ll_t * ll_p);
|
||||
|
||||
/**
|
||||
* Return with the pointer of the next node after 'n_act'
|
||||
* @param ll_p pointer to linked list
|
||||
* @param n_act pointer a node
|
||||
* @return pointer to the next node
|
||||
*/
|
||||
void * lv_ll_get_next(const lv_ll_t * ll_p, const void * n_act);
|
||||
|
||||
/**
|
||||
* Return with the pointer of the previous node after 'n_act'
|
||||
* @param ll_p pointer to linked list
|
||||
* @param n_act pointer a node
|
||||
* @return pointer to the previous node
|
||||
*/
|
||||
void * lv_ll_get_prev(const lv_ll_t * ll_p, const void * n_act);
|
||||
|
||||
/**
|
||||
* Move a nodw before an other node in the same linked list
|
||||
* @param ll_p pointer to a linked list
|
||||
* @param n_act pointer to node to move
|
||||
* @param n_after pointer to a node which should be after `n_act`
|
||||
*/
|
||||
void lv_ll_move_before(lv_ll_t * ll_p, void * n_act, void * n_after);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#define LL_READ(list, i) for(i = lv_ll_get_head(&list); i != NULL; i = lv_ll_get_next(&list, i))
|
||||
|
||||
#define LL_READ_BACK(list, i) for(i = lv_ll_get_tail(&list); i != NULL; i = lv_ll_get_prev(&list, i))
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
82
bdk/libs/lvgl/lv_misc/lv_log.c
Normal file
82
bdk/libs/lvgl/lv_misc/lv_log.c
Normal file
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* @file lv_log.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_log.h"
|
||||
#if USE_LV_LOG
|
||||
|
||||
#if LV_LOG_PRINTF
|
||||
#include <string.h>
|
||||
#include <mem/heap.h>
|
||||
#include <soc/uart.h>
|
||||
#include <utils/sprintf.h>
|
||||
#endif
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static void (*print_cb)(lv_log_level_t, const char *, uint32_t, const char *);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Register custom print (or anything else) function to call when log is added
|
||||
* @param f a function pointer:
|
||||
* `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)`
|
||||
*/
|
||||
void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *))
|
||||
{
|
||||
print_cb = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a log
|
||||
* @param level the level of log. (From `lv_log_level_t` enum)
|
||||
* @param file name of the file when the log added
|
||||
* @param line line number in the source code where the log added
|
||||
* @param dsc description of the log
|
||||
*/
|
||||
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc)
|
||||
{
|
||||
if(level >= _LV_LOG_LEVEL_NUM) return; /*Invalid level*/
|
||||
|
||||
if(level >= LV_LOG_LEVEL) {
|
||||
|
||||
#if LV_LOG_PRINTF
|
||||
static const char * lvl_prefix[] = {"Trace", "Info", "Warn", "Error"};
|
||||
char *log = (char *)malloc(0x1000);
|
||||
s_printf(log, "%s: %s \t(%s #%d)\r\n", lvl_prefix[level], dsc, file, line);
|
||||
uart_send(UART_B, (u8 *)log, strlen(log) + 1);
|
||||
//gfx_printf("%s: %s \t(%s #%d)\n", lvl_prefix[level], dsc, file, line);
|
||||
#else
|
||||
if(print_cb) print_cb(level, file, line, dsc);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_LOG*/
|
86
bdk/libs/lvgl/lv_misc/lv_log.h
Normal file
86
bdk/libs/lvgl/lv_misc/lv_log.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* @file lv_log.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_LOG_H
|
||||
#define LV_LOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/
|
||||
|
||||
#define LV_LOG_LEVEL_TRACE 0 /*A lot of logs to give detailed information*/
|
||||
#define LV_LOG_LEVEL_INFO 1 /*Log important events*/
|
||||
#define LV_LOG_LEVEL_WARN 2 /*Log if something unwanted happened but didn't caused problem*/
|
||||
#define LV_LOG_LEVEL_ERROR 3 /*Only critical issue, when the system may fail*/
|
||||
#define _LV_LOG_LEVEL_NUM 4
|
||||
|
||||
typedef int8_t lv_log_level_t;
|
||||
|
||||
#if USE_LV_LOG
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Register custom print (or anything else) function to call when log is added
|
||||
* @param f a function pointer:
|
||||
* `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)`
|
||||
*/
|
||||
void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *));
|
||||
|
||||
/**
|
||||
* Add a log
|
||||
* @param level the level of log. (From `lv_log_level_t` enum)
|
||||
* @param file name of the file when the log added
|
||||
* @param line line number in the source code where the log added
|
||||
* @param dsc description of the log
|
||||
*/
|
||||
void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc);
|
||||
#define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc);
|
||||
#define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc);
|
||||
#define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc);
|
||||
|
||||
#else /*USE_LV_LOG*/
|
||||
|
||||
/*Do nothing if `USE_LV_LOG 0`*/
|
||||
#define lv_log_add(level, file, line, dsc) {;}
|
||||
#define LV_LOG_TRACE(dsc) {;}
|
||||
#define LV_LOG_INFO(dsc) {;}
|
||||
#define LV_LOG_WARN(dsc) {;}
|
||||
#define LV_LOG_ERROR(dsc) {;}
|
||||
#endif /*USE_LV_LOG*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_LOG_H*/
|
165
bdk/libs/lvgl/lv_misc/lv_math.c
Normal file
165
bdk/libs/lvgl/lv_misc/lv_math.c
Normal file
|
@ -0,0 +1,165 @@
|
|||
/**
|
||||
* @file lv_math.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_math.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static int16_t sin0_90_table[] = {
|
||||
0, 572, 1144, 1715, 2286, 2856, 3425, 3993, 4560, 5126,
|
||||
5690, 6252, 6813, 7371, 7927, 8481, 9032, 9580, 10126, 10668,
|
||||
11207, 11743, 12275, 12803, 13328, 13848, 14364, 14876, 15383, 15886,
|
||||
16383, 16876, 17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621,
|
||||
21062, 21497, 21925, 22347, 22762, 23170, 23571, 23964, 24351, 24730,
|
||||
25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087,
|
||||
28377, 28659, 28932, 29196, 29451, 29697, 29934, 30162, 30381, 30591,
|
||||
30791, 30982, 31163, 31335, 31498, 31650, 31794, 31927, 32051, 32165,
|
||||
32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762,
|
||||
32767
|
||||
};
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Convert a number to string
|
||||
* @param num a number
|
||||
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
|
||||
* @return same as `buf` (just for convenience)
|
||||
*/
|
||||
char * lv_math_num_to_str(int32_t num, char * buf)
|
||||
{
|
||||
char * buf_ori = buf;
|
||||
if(num == 0) {
|
||||
buf[0] = '0';
|
||||
buf[1] = '\0';
|
||||
return buf;
|
||||
} else if(num < 0) {
|
||||
(*buf) = '-';
|
||||
buf++;
|
||||
num = LV_MATH_ABS(num);
|
||||
}
|
||||
uint32_t output = 0;
|
||||
int8_t i;
|
||||
|
||||
for(i = 31; i >= 0; i--) {
|
||||
if((output & 0xF) >= 5)
|
||||
output += 3;
|
||||
if(((output & 0xF0) >> 4) >= 5)
|
||||
output += (3 << 4);
|
||||
if(((output & 0xF00) >> 8) >= 5)
|
||||
output += (3 << 8);
|
||||
if(((output & 0xF000) >> 12) >= 5)
|
||||
output += (3 << 12);
|
||||
if(((output & 0xF0000) >> 16) >= 5)
|
||||
output += (3 << 16);
|
||||
if(((output & 0xF00000) >> 20) >= 5)
|
||||
output += (3 << 20);
|
||||
if(((output & 0xF000000) >> 24) >= 5)
|
||||
output += (3 << 24);
|
||||
if(((output & 0xF0000000) >> 28) >= 5)
|
||||
output += (3 << 28);
|
||||
output = (output << 1) | ((num >> i) & 1);
|
||||
}
|
||||
|
||||
uint8_t digit;
|
||||
bool leading_zero_ready = false;
|
||||
for(i = 28; i >= 0; i -= 4) {
|
||||
digit = ((output >> i) & 0xF) + '0';
|
||||
if(digit == '0' && leading_zero_ready == false) continue;
|
||||
|
||||
leading_zero_ready = true;
|
||||
(*buf) = digit;
|
||||
buf++;
|
||||
}
|
||||
|
||||
(*buf) = '\0';
|
||||
|
||||
return buf_ori;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return with sinus of an angle
|
||||
* @param angle
|
||||
* @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
|
||||
*/
|
||||
int16_t lv_trigo_sin(int16_t angle)
|
||||
{
|
||||
int16_t ret = 0;
|
||||
angle = angle % 360;
|
||||
|
||||
if(angle < 0) angle = 360 + angle;
|
||||
|
||||
if(angle < 90) {
|
||||
ret = sin0_90_table[angle];
|
||||
} else if(angle >= 90 && angle < 180) {
|
||||
angle = 180 - angle;
|
||||
ret = sin0_90_table[angle];
|
||||
} else if(angle >= 180 && angle < 270) {
|
||||
angle = angle - 180;
|
||||
ret = - sin0_90_table[angle];
|
||||
} else { /*angle >=270*/
|
||||
angle = 360 - angle;
|
||||
ret = - sin0_90_table[angle];
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a value of a Cubic Bezier function.
|
||||
* @param t time in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @param u0 start values in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @param u3 end values in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX]
|
||||
*/
|
||||
int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3)
|
||||
{
|
||||
uint32_t t_rem = 1024 - t;
|
||||
uint32_t t_rem2 = (t_rem * t_rem) >> 10;
|
||||
uint32_t t_rem3 = (t_rem2 * t_rem) >> 10;
|
||||
uint32_t t2 = (t * t) >> 10;
|
||||
uint32_t t3 = (t2 * t) >> 10;
|
||||
|
||||
|
||||
uint32_t v1 = ((uint32_t)t_rem3 * u0) >> 10;
|
||||
uint32_t v2 = ((uint32_t)3 * t_rem2 * t * u1) >> 20;
|
||||
uint32_t v3 = ((uint32_t)3 * t_rem * t2 * u2) >> 20;
|
||||
uint32_t v4 = ((uint32_t)t3 * u3) >> 10;
|
||||
|
||||
return v1 + v2 + v3 + v4;
|
||||
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
|
73
bdk/libs/lvgl/lv_misc/lv_math.h
Normal file
73
bdk/libs/lvgl/lv_misc/lv_math.h
Normal file
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* @file math_base.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_MATH_H
|
||||
#define LV_MATH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stdint.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_MATH_MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define LV_MATH_MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x)))
|
||||
|
||||
#define LV_TRIGO_SIN_MAX 32767
|
||||
#define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/
|
||||
|
||||
#define LV_BEZIER_VAL_MAX 1024 /*Max time in Bezier functions (not [0..1] to use integers) */
|
||||
#define LV_BEZIER_VAL_SHIFT 10 /*log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
/**
|
||||
* Convert a number to string
|
||||
* @param num a number
|
||||
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
|
||||
* @return same as `buf` (just for convenience)
|
||||
*/
|
||||
char * lv_math_num_to_str(int32_t num, char * buf);
|
||||
|
||||
/**
|
||||
* Return with sinus of an angle
|
||||
* @param angle
|
||||
* @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767
|
||||
*/
|
||||
int16_t lv_trigo_sin(int16_t angle);
|
||||
|
||||
/**
|
||||
* Calculate a value of a Cubic Bezier function.
|
||||
* @param t time in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @param u0 start values in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @param u3 end values in range of [0..LV_BEZIER_VAL_MAX]
|
||||
* @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX]
|
||||
*/
|
||||
int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
470
bdk/libs/lvgl/lv_misc/lv_mem.c
Normal file
470
bdk/libs/lvgl/lv_misc/lv_mem.c
Normal file
|
@ -0,0 +1,470 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lv_mem.c
|
||||
* General and portable implementation of malloc and free.
|
||||
* The dynamic memory monitoring is also supported.
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_mem.h"
|
||||
#include "lv_math.h"
|
||||
#include <string.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#if LV_MEM_CUSTOM != 0
|
||||
#include LV_MEM_CUSTOM_INCLUDE
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_MEM_ADD_JUNK 0 /*Add memory junk on alloc (0xaa) and free(0xbb) (just for testing purposes)*/
|
||||
|
||||
|
||||
#ifdef LV_MEM_ENV64
|
||||
# define MEM_UNIT uint64_t
|
||||
#else
|
||||
# define MEM_UNIT uint32_t
|
||||
#endif
|
||||
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
#if LV_ENABLE_GC == 0 /*gc custom allocations must not include header*/
|
||||
|
||||
/*The size of this union must be 32 bytes (uint32_t * 8)*/
|
||||
typedef union {
|
||||
struct {
|
||||
MEM_UNIT used: 1; //1: if the entry is used
|
||||
MEM_UNIT d_size: 31; //Size of the data
|
||||
};
|
||||
MEM_UNIT header; //The header (used + d_size)
|
||||
MEM_UNIT align[8]; //Align header size to MEM_UNIT * 8 bytes
|
||||
} lv_mem_header_t;
|
||||
|
||||
static_assert(sizeof(lv_mem_header_t) == 32, "Node header must be 32 bytes!");
|
||||
|
||||
typedef struct {
|
||||
lv_mem_header_t header;
|
||||
uint8_t first_data; /*First data byte in the allocated data (Just for easily create a pointer)*/
|
||||
} lv_mem_ent_t;
|
||||
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e);
|
||||
static void * ent_alloc(lv_mem_ent_t * e, uint32_t size);
|
||||
static void ent_trunc(lv_mem_ent_t * e, uint32_t size);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
static uint8_t * work_mem;
|
||||
#endif
|
||||
|
||||
static uint32_t zero_mem; /*Give the address of this variable if 0 byte should be allocated*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Initiaiize the dyn_mem module (work memory and other variables)
|
||||
*/
|
||||
void lv_mem_init(void)
|
||||
{
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
|
||||
#if LV_MEM_ADR == 0
|
||||
/*Allocate a large array to store the dynamically allocated data*/
|
||||
static LV_MEM_ATTR MEM_UNIT work_mem_int[LV_MEM_SIZE / sizeof(MEM_UNIT)];
|
||||
work_mem = (uint8_t *) work_mem_int;
|
||||
#else
|
||||
work_mem = (uint8_t *) LV_MEM_ADR;
|
||||
#endif
|
||||
|
||||
lv_mem_ent_t * full = (lv_mem_ent_t *)work_mem;
|
||||
full->header.used = 0;
|
||||
/*The total mem size id reduced by the first header and the close patterns */
|
||||
full->header.d_size = LV_MEM_SIZE - sizeof(lv_mem_header_t);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a memory dynamically
|
||||
* @param size size of the memory to allocate in bytes
|
||||
* @return pointer to the allocated memory
|
||||
*/
|
||||
void * lv_mem_alloc(uint32_t size)
|
||||
{
|
||||
if(size == 0) {
|
||||
return &zero_mem;
|
||||
}
|
||||
|
||||
/*Round the size to lv_mem_header_t*/
|
||||
if(size & (sizeof(lv_mem_header_t) - 1)) {
|
||||
size = size & (~(sizeof(lv_mem_header_t) - 1));
|
||||
size += sizeof(lv_mem_header_t);
|
||||
}
|
||||
|
||||
void * alloc = NULL;
|
||||
|
||||
#if LV_MEM_CUSTOM == 0 /*Use the allocation from dyn_mem*/
|
||||
lv_mem_ent_t * e = NULL;
|
||||
|
||||
//Search for a appropriate entry
|
||||
do {
|
||||
//Get the next entry
|
||||
e = ent_get_next(e);
|
||||
|
||||
/*If there is next entry then try to allocate there*/
|
||||
if(e != NULL) {
|
||||
alloc = ent_alloc(e, size);
|
||||
}
|
||||
//End if there is not next entry OR the alloc. is successful
|
||||
} while(e != NULL && alloc == NULL);
|
||||
|
||||
|
||||
#else /*Use custom, user defined malloc function*/
|
||||
#if LV_ENABLE_GC == 1 /*gc must not include header*/
|
||||
alloc = LV_MEM_CUSTOM_ALLOC(size);
|
||||
#else /* LV_ENABLE_GC */
|
||||
/*Allocate a header too to store the size*/
|
||||
alloc = LV_MEM_CUSTOM_ALLOC(size + sizeof(lv_mem_header_t));
|
||||
if(alloc != NULL) {
|
||||
((lv_mem_ent_t *) alloc)->header.d_size = size;
|
||||
((lv_mem_ent_t *) alloc)->header.used = 1;
|
||||
alloc = &((lv_mem_ent_t *) alloc)->first_data;
|
||||
}
|
||||
#endif /* LV_ENABLE_GC */
|
||||
#endif /* LV_MEM_CUSTOM */
|
||||
|
||||
#if LV_MEM_ADD_JUNK
|
||||
if(alloc != NULL) memset(alloc, 0xaa, size);
|
||||
#endif
|
||||
|
||||
if(alloc == NULL) LV_LOG_WARN("Couldn't allocate memory");
|
||||
|
||||
return alloc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free an allocated data
|
||||
* @param data pointer to an allocated memory
|
||||
*/
|
||||
void lv_mem_free(const void * data)
|
||||
{
|
||||
if(data == &zero_mem) return;
|
||||
if(data == NULL) return;
|
||||
|
||||
|
||||
#if LV_MEM_ADD_JUNK
|
||||
memset((void *)data, 0xbb, lv_mem_get_size(data));
|
||||
#endif
|
||||
|
||||
#if LV_ENABLE_GC==0
|
||||
/*e points to the header*/
|
||||
lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data - sizeof(lv_mem_header_t));
|
||||
e->header.used = 0;
|
||||
#endif
|
||||
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
#if LV_MEM_AUTO_DEFRAG
|
||||
/* Make a simple defrag.
|
||||
* Join the following free entries after this*/
|
||||
lv_mem_ent_t * e_next;
|
||||
e_next = ent_get_next(e);
|
||||
while(e_next != NULL) {
|
||||
if(e_next->header.used == 0) {
|
||||
e->header.d_size += e_next->header.d_size + sizeof(e->header);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
e_next = ent_get_next(e_next);
|
||||
}
|
||||
#endif
|
||||
#else /*Use custom, user defined free function*/
|
||||
#if LV_ENABLE_GC==0
|
||||
LV_MEM_CUSTOM_FREE(e);
|
||||
#else
|
||||
LV_MEM_CUSTOM_FREE((void*)data);
|
||||
#endif /*LV_ENABLE_GC*/
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Reallocate a memory with a new size. The old content will be kept.
|
||||
* @param data pointer to an allocated memory.
|
||||
* Its content will be copied to the new memory block and freed
|
||||
* @param new_size the desired new size in byte
|
||||
* @return pointer to the new memory
|
||||
*/
|
||||
|
||||
#if LV_ENABLE_GC==0
|
||||
|
||||
void * lv_mem_realloc(void * data_p, uint32_t new_size)
|
||||
{
|
||||
/*Round the size to lv_mem_header_t*/
|
||||
if(new_size & (sizeof(lv_mem_header_t) - 1)) {
|
||||
new_size = new_size & (~(sizeof(lv_mem_header_t) - 1));
|
||||
new_size += sizeof(lv_mem_header_t);
|
||||
}
|
||||
|
||||
/*data_p could be previously freed pointer (in this case it is invalid)*/
|
||||
if(data_p != NULL) {
|
||||
lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data_p - sizeof(lv_mem_header_t));
|
||||
if(e->header.used == 0) {
|
||||
data_p = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t old_size = lv_mem_get_size(data_p);
|
||||
if(old_size == new_size) return data_p; /*Also avoid reallocating the same memory*/
|
||||
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
/* Only truncate the memory is possible
|
||||
* If the 'old_size' was extended by a header size in 'ent_trunc' it avoids reallocating this same memory */
|
||||
if(new_size < old_size) {
|
||||
lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data_p - sizeof(lv_mem_header_t));
|
||||
ent_trunc(e, new_size);
|
||||
return &e->first_data;
|
||||
}
|
||||
#endif
|
||||
|
||||
void * new_p;
|
||||
new_p = lv_mem_alloc(new_size);
|
||||
|
||||
if(new_p != NULL && data_p != NULL) {
|
||||
/*Copy the old data to the new. Use the smaller size*/
|
||||
if(old_size != 0) {
|
||||
memcpy(new_p, data_p, LV_MATH_MIN(new_size, old_size));
|
||||
lv_mem_free(data_p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(new_p == NULL) LV_LOG_WARN("Couldn't allocate memory");
|
||||
|
||||
return new_p;
|
||||
}
|
||||
|
||||
#else /* LV_ENABLE_GC */
|
||||
|
||||
void * lv_mem_realloc(void * data_p, uint32_t new_size)
|
||||
{
|
||||
void * new_p = LV_MEM_CUSTOM_REALLOC(data_p, new_size);
|
||||
if(new_p == NULL) LV_LOG_WARN("Couldn't allocate memory");
|
||||
return new_p;
|
||||
}
|
||||
|
||||
#endif /* lv_enable_gc */
|
||||
|
||||
/**
|
||||
* Join the adjacent free memory blocks
|
||||
*/
|
||||
void lv_mem_defrag(void)
|
||||
{
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
lv_mem_ent_t * e_free;
|
||||
lv_mem_ent_t * e_next;
|
||||
e_free = ent_get_next(NULL);
|
||||
|
||||
while(1) {
|
||||
/*Search the next free entry*/
|
||||
while(e_free != NULL) {
|
||||
if(e_free->header.used != 0) {
|
||||
e_free = ent_get_next(e_free);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(e_free == NULL) return;
|
||||
|
||||
/*Joint the following free entries to the free*/
|
||||
e_next = ent_get_next(e_free);
|
||||
while(e_next != NULL) {
|
||||
if(e_next->header.used == 0) {
|
||||
e_free->header.d_size += e_next->header.d_size + sizeof(e_next->header);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
e_next = ent_get_next(e_next);
|
||||
}
|
||||
|
||||
if(e_next == NULL) return;
|
||||
|
||||
/*Continue from the lastly checked entry*/
|
||||
e_free = e_next;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Give information about the work memory of dynamic allocation
|
||||
* @param mon_p pointer to a dm_mon_p variable,
|
||||
* the result of the analysis will be stored here
|
||||
*/
|
||||
void lv_mem_monitor(lv_mem_monitor_t * mon_p)
|
||||
{
|
||||
/*Init the data*/
|
||||
memset(mon_p, 0, sizeof(lv_mem_monitor_t));
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
lv_mem_ent_t * e;
|
||||
e = NULL;
|
||||
|
||||
e = ent_get_next(e);
|
||||
|
||||
while(e != NULL) {
|
||||
if(e->header.used == 0) {
|
||||
mon_p->free_cnt++;
|
||||
mon_p->free_size += e->header.d_size;
|
||||
if(e->header.d_size > mon_p->free_biggest_size) {
|
||||
mon_p->free_biggest_size = e->header.d_size;
|
||||
}
|
||||
} else {
|
||||
mon_p->used_cnt++;
|
||||
}
|
||||
|
||||
e = ent_get_next(e);
|
||||
}
|
||||
mon_p->total_size = LV_MEM_SIZE;
|
||||
mon_p->used_pct = 100 - ((uint64_t)100U * mon_p->free_size) / mon_p->total_size;
|
||||
mon_p->frag_pct = (uint32_t)mon_p->free_biggest_size * 100U / mon_p->free_size;
|
||||
mon_p->frag_pct = 100 - mon_p->frag_pct;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the size of an allocated memory
|
||||
* @param data pointer to an allocated memory
|
||||
* @return the size of data memory in bytes
|
||||
*/
|
||||
|
||||
#if LV_ENABLE_GC==0
|
||||
|
||||
uint32_t lv_mem_get_size(const void * data)
|
||||
{
|
||||
if(data == NULL) return 0;
|
||||
if(data == &zero_mem) return 0;
|
||||
|
||||
lv_mem_ent_t * e = (lv_mem_ent_t *)((uint8_t *) data - sizeof(lv_mem_header_t));
|
||||
|
||||
return e->header.d_size;
|
||||
}
|
||||
|
||||
#else /* LV_ENABLE_GC */
|
||||
|
||||
uint32_t lv_mem_get_size(const void * data)
|
||||
{
|
||||
return LV_MEM_CUSTOM_GET_SIZE(data);
|
||||
}
|
||||
|
||||
#endif /*LV_ENABLE_GC*/
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
/**
|
||||
* Give the next entry after 'act_e'
|
||||
* @param act_e pointer to an entry
|
||||
* @return pointer to an entry after 'act_e'
|
||||
*/
|
||||
static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e)
|
||||
{
|
||||
lv_mem_ent_t * next_e = NULL;
|
||||
|
||||
if(act_e == NULL) { /*NULL means: get the first entry*/
|
||||
next_e = (lv_mem_ent_t *) work_mem;
|
||||
} else { /*Get the next entry */
|
||||
uint8_t * data = &act_e->first_data;
|
||||
next_e = (lv_mem_ent_t *)&data[act_e->header.d_size];
|
||||
|
||||
if(&next_e->first_data >= &work_mem[LV_MEM_SIZE]) next_e = NULL;
|
||||
}
|
||||
|
||||
return next_e;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to do the real allocation with a given size
|
||||
* @param e try to allocate to this entry
|
||||
* @param size size of the new memory in bytes
|
||||
* @return pointer to the allocated memory or NULL if not enough memory in the entry
|
||||
*/
|
||||
static void * ent_alloc(lv_mem_ent_t * e, uint32_t size)
|
||||
{
|
||||
void * alloc = NULL;
|
||||
|
||||
/*If the memory is free and big enough then use it */
|
||||
if(e->header.used == 0 && e->header.d_size >= size) {
|
||||
/*Truncate the entry to the desired size */
|
||||
ent_trunc(e, size),
|
||||
|
||||
e->header.used = 1;
|
||||
|
||||
/*Save the allocated data*/
|
||||
alloc = &e->first_data;
|
||||
}
|
||||
|
||||
return alloc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the data of entry to the given size
|
||||
* @param e Pointer to an entry
|
||||
* @param size new size in bytes
|
||||
*/
|
||||
static void ent_trunc(lv_mem_ent_t * e, uint32_t size)
|
||||
{
|
||||
/*Don't let empty space only for a header without data*/
|
||||
if(e->header.d_size == size + sizeof(lv_mem_header_t)) {
|
||||
size = e->header.d_size;
|
||||
}
|
||||
|
||||
/* Create the new entry after the current if there is space for it */
|
||||
if(e->header.d_size != size) {
|
||||
uint8_t * e_data = &e->first_data;
|
||||
lv_mem_ent_t * after_new_e = (lv_mem_ent_t *)&e_data[size];
|
||||
after_new_e->header.used = 0;
|
||||
after_new_e->header.d_size = e->header.d_size - size - sizeof(lv_mem_header_t);
|
||||
}
|
||||
|
||||
/* Set the new size for the original entry */
|
||||
e->header.d_size = size;
|
||||
}
|
||||
|
||||
#endif
|
127
bdk/libs/lvgl/lv_misc/lv_mem.h
Normal file
127
bdk/libs/lvgl/lv_misc/lv_mem.h
Normal file
|
@ -0,0 +1,127 @@
|
|||
/**
|
||||
* @file lv_mem.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_MEM_H
|
||||
#define LV_MEM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "lv_log.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
// Check windows
|
||||
#ifdef __WIN64
|
||||
//# define LV_MEM_ENV64
|
||||
#endif
|
||||
|
||||
// Check GCC
|
||||
#ifdef __GNUC__
|
||||
# if defined(__x86_64__) || defined(__ppc64__)
|
||||
//# define LV_MEM_ENV64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t total_size;
|
||||
uint32_t free_cnt;
|
||||
uint32_t free_size;
|
||||
uint32_t free_biggest_size;
|
||||
uint32_t used_cnt;
|
||||
uint8_t used_pct;
|
||||
uint8_t frag_pct;
|
||||
} lv_mem_monitor_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
|
||||
/**
|
||||
* Initiaize the dyn_mem module (work memory and other variables)
|
||||
*/
|
||||
void lv_mem_init(void);
|
||||
|
||||
/**
|
||||
* Allocate a memory dynamically
|
||||
* @param size size of the memory to allocate in bytes
|
||||
* @return pointer to the allocated memory
|
||||
*/
|
||||
void * lv_mem_alloc(uint32_t size);
|
||||
|
||||
/**
|
||||
* Free an allocated data
|
||||
* @param data pointer to an allocated memory
|
||||
*/
|
||||
void lv_mem_free(const void * data);
|
||||
|
||||
/**
|
||||
* Reallocate a memory with a new size. The old content will be kept.
|
||||
* @param data pointer to an allocated memory.
|
||||
* Its content will be copied to the new memory block and freed
|
||||
* @param new_size the desired new size in byte
|
||||
* @return pointer to the new memory
|
||||
*/
|
||||
void * lv_mem_realloc(void * data_p, uint32_t new_size);
|
||||
|
||||
/**
|
||||
* Join the adjacent free memory blocks
|
||||
*/
|
||||
void lv_mem_defrag(void);
|
||||
|
||||
/**
|
||||
* Give information about the work memory of dynamic allocation
|
||||
* @param mon_p pointer to a dm_mon_p variable,
|
||||
* the result of the analysis will be stored here
|
||||
*/
|
||||
void lv_mem_monitor(lv_mem_monitor_t * mon_p);
|
||||
|
||||
/**
|
||||
* Give the size of an allocated memory
|
||||
* @param data pointer to an allocated memory
|
||||
* @return the size of data memory in bytes
|
||||
*/
|
||||
uint32_t lv_mem_get_size(const void * data);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Halt on NULL pointer
|
||||
* p pointer to a memory
|
||||
*/
|
||||
#if USE_LV_LOG == 0
|
||||
# define lv_mem_assert(p) {if(p == NULL) while(1); }
|
||||
#else
|
||||
# define lv_mem_assert(p) {if(p == NULL) {LV_LOG_ERROR("Out of memory!"); while(1); }}
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_MEM_H*/
|
||||
|
19
bdk/libs/lvgl/lv_misc/lv_misc.mk
Normal file
19
bdk/libs/lvgl/lv_misc/lv_misc.mk
Normal file
|
@ -0,0 +1,19 @@
|
|||
CSRCS += lv_font.c
|
||||
CSRCS += lv_circ.c
|
||||
CSRCS += lv_area.c
|
||||
CSRCS += lv_task.c
|
||||
CSRCS += lv_fs.c
|
||||
CSRCS += lv_anim.c
|
||||
CSRCS += lv_mem.c
|
||||
CSRCS += lv_ll.c
|
||||
CSRCS += lv_color.c
|
||||
CSRCS += lv_txt.c
|
||||
CSRCS += lv_ufs.c
|
||||
CSRCS += lv_math.c
|
||||
CSRCS += lv_log.c
|
||||
CSRCS += lv_gc.c
|
||||
|
||||
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_misc
|
||||
VPATH += :$(LVGL_DIR)/lvgl/lv_misc
|
||||
|
||||
CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc"
|
223
bdk/libs/lvgl/lv_misc/lv_symbol_def.h
Normal file
223
bdk/libs/lvgl/lv_misc/lv_symbol_def.h
Normal file
|
@ -0,0 +1,223 @@
|
|||
/*
|
||||
* Copyright (c) 2019 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LV_SYMBOL_DEF_H
|
||||
#define LV_SYMBOL_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* With no UTF-8 support (192- 255) (192..241 is used)
|
||||
*
|
||||
* With UTF-8 support (in Supplemental Private Use Area-A): 0xF800 .. 0xF831
|
||||
* - Basic symbols: 0xE000..0xE01F
|
||||
* - File symbols: 0xE020..0xE03F
|
||||
* - Feedback symbols: 0xE040..0xE05F
|
||||
* - Reserved: 0xE060..0xE07F
|
||||
*/
|
||||
|
||||
#if LV_TXT_UTF8 == 0
|
||||
#define LV_SYMBOL_GLYPH_FIRST 0xC0
|
||||
#define SYMBOL_DOT _SYMBOL_VALUE1(C0)
|
||||
#define SYMBOL_CLOCK _SYMBOL_VALUE1(C1)
|
||||
#define SYMBOL_LIST _SYMBOL_VALUE1(C2)
|
||||
#define SYMBOL_OK _SYMBOL_VALUE1(C3)
|
||||
#define SYMBOL_CLOSE _SYMBOL_VALUE1(C4)
|
||||
#define SYMBOL_POWER _SYMBOL_VALUE1(C5)
|
||||
#define SYMBOL_SETTINGS _SYMBOL_VALUE1(C6)
|
||||
#define SYMBOL_TRASH _SYMBOL_VALUE1(C7)
|
||||
#define SYMBOL_HOME _SYMBOL_VALUE1(C8)
|
||||
#define SYMBOL_DOWNLOAD _SYMBOL_VALUE1(C9)
|
||||
#define SYMBOL_DRIVE _SYMBOL_VALUE1(CA)
|
||||
#define SYMBOL_REFRESH _SYMBOL_VALUE1(CB)
|
||||
#define SYMBOL_REBOOT _SYMBOL_VALUE1(CC)
|
||||
#define SYMBOL_CHIP _SYMBOL_VALUE1(CD)
|
||||
#define SYMBOL_SD _SYMBOL_VALUE1(CE)
|
||||
#define SYMBOL_CIRCUIT _SYMBOL_VALUE1(CF)
|
||||
#define SYMBOL_EDIT _SYMBOL_VALUE1(D0)
|
||||
#define SYMBOL_FILE_ALT _SYMBOL_VALUE1(D1)
|
||||
#define SYMBOL_FILE_CODE _SYMBOL_VALUE1(D2)
|
||||
#define SYMBOL_FILE_ARC _SYMBOL_VALUE1(D3)
|
||||
#define SYMBOL_TEMPERATURE _SYMBOL_VALUE1(D4)
|
||||
#define SYMBOL_MODULES _SYMBOL_VALUE1(D5)
|
||||
#define SYMBOL_MODULES_ALT _SYMBOL_VALUE1(D6)
|
||||
#define SYMBOL_LEFT _SYMBOL_VALUE1(D7)
|
||||
#define SYMBOL_RIGHT _SYMBOL_VALUE1(D8)
|
||||
#define SYMBOL_KEY _SYMBOL_VALUE1(D9)
|
||||
#define SYMBOL_INFO _SYMBOL_VALUE1(DA)
|
||||
#define SYMBOL_WARNING _SYMBOL_VALUE1(DB)
|
||||
#define SYMBOL_SHUFFLE _SYMBOL_VALUE1(DC)
|
||||
#define SYMBOL_UP _SYMBOL_VALUE1(DD)
|
||||
#define SYMBOL_DOWN _SYMBOL_VALUE1(DE)
|
||||
#define SYMBOL_BRIGHTNESS _SYMBOL_VALUE1(DF)
|
||||
#define SYMBOL_DIRECTORY _SYMBOL_VALUE1(E0)
|
||||
#define SYMBOL_UPLOAD _SYMBOL_VALUE1(E1)
|
||||
#define SYMBOL_USB _SYMBOL_VALUE1(E2)
|
||||
#define SYMBOL_TOOLS _SYMBOL_VALUE1(E3)
|
||||
#define SYMBOL_COPY _SYMBOL_VALUE1(E4)
|
||||
#define SYMBOL_SAVE _SYMBOL_VALUE1(E5)
|
||||
#define SYMBOL_CHARGE _SYMBOL_VALUE1(E6)
|
||||
#define SYMBOL_HINT _SYMBOL_VALUE1(E7)
|
||||
#define SYMBOL_KEYBOARD _SYMBOL_VALUE1(E8)
|
||||
#define SYMBOL_GPS _SYMBOL_VALUE1(E9)
|
||||
#define SYMBOL_FILE _SYMBOL_VALUE1(EA)
|
||||
#define SYMBOL_CAMERA _SYMBOL_VALUE1(EB)
|
||||
#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE1(EC)
|
||||
#define SYMBOL_BATTERY_3 _SYMBOL_VALUE1(ED)
|
||||
#define SYMBOL_BATTERY_2 _SYMBOL_VALUE1(EE)
|
||||
#define SYMBOL_BATTERY_1 _SYMBOL_VALUE1(EF)
|
||||
#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE1(F0)
|
||||
#define SYMBOL_SHRK _SYMBOL_VALUE1(F1)
|
||||
#define LV_SYMBOL_GLYPH_LAST 0xF1
|
||||
#define SYMBOL_DUMMY _SYMBOL_VALUE1(FF) /*Invalid symbol. If written before a string then `lv_img` will show it as a label*/
|
||||
|
||||
#else
|
||||
#define LV_SYMBOL_GLYPH_FIRST 0xF800
|
||||
#define SYMBOL_DOT _SYMBOL_VALUE3(EF,A0,80)
|
||||
#define SYMBOL_CLOCK _SYMBOL_VALUE3(EF,A0,81)
|
||||
#define SYMBOL_LIST _SYMBOL_VALUE3(EF,A0,82)
|
||||
#define SYMBOL_OK _SYMBOL_VALUE3(EF,A0,83)
|
||||
#define SYMBOL_CLOSE _SYMBOL_VALUE3(EF,A0,84)
|
||||
#define SYMBOL_POWER _SYMBOL_VALUE3(EF,A0,85)
|
||||
#define SYMBOL_SETTINGS _SYMBOL_VALUE3(EF,A0,86)
|
||||
#define SYMBOL_TRASH _SYMBOL_VALUE3(EF,A0,87)
|
||||
#define SYMBOL_HOME _SYMBOL_VALUE3(EF,A0,88)
|
||||
#define SYMBOL_DOWNLOAD _SYMBOL_VALUE3(EF,A0,89)
|
||||
#define SYMBOL_DRIVE _SYMBOL_VALUE3(EF,A0,8A)
|
||||
#define SYMBOL_REFRESH _SYMBOL_VALUE3(EF,A0,8B)
|
||||
#define SYMBOL_REBOOT _SYMBOL_VALUE3(EF,A0,8C)
|
||||
#define SYMBOL_CHIP _SYMBOL_VALUE3(EF,A0,8D)
|
||||
#define SYMBOL_SD _SYMBOL_VALUE3(EF,A0,8E)
|
||||
#define SYMBOL_CIRCUIT _SYMBOL_VALUE3(EF,A0,8F)
|
||||
#define SYMBOL_EDIT _SYMBOL_VALUE3(EF,A0,90)
|
||||
#define SYMBOL_FILE_ALT _SYMBOL_VALUE3(EF,A0,91)
|
||||
#define SYMBOL_FILE_CODE _SYMBOL_VALUE3(EF,A0,92)
|
||||
#define SYMBOL_FILE_ARC _SYMBOL_VALUE3(EF,A0,93)
|
||||
#define SYMBOL_TEMPERATURE _SYMBOL_VALUE3(EF,A0,94)
|
||||
#define SYMBOL_MODULES _SYMBOL_VALUE3(EF,A0,95)
|
||||
#define SYMBOL_MODULES_ALT _SYMBOL_VALUE3(EF,A0,96)
|
||||
#define SYMBOL_LEFT _SYMBOL_VALUE3(EF,A0,97)
|
||||
#define SYMBOL_RIGHT _SYMBOL_VALUE3(EF,A0,98)
|
||||
#define SYMBOL_KEY _SYMBOL_VALUE3(EF,A0,99)
|
||||
#define SYMBOL_INFO _SYMBOL_VALUE3(EF,A0,9A)
|
||||
#define SYMBOL_WARNING _SYMBOL_VALUE3(EF,A0,9B)
|
||||
#define SYMBOL_SHUFFLE _SYMBOL_VALUE3(EF,A0,9C)
|
||||
#define SYMBOL_UP _SYMBOL_VALUE3(EF,A0,9D)
|
||||
#define SYMBOL_DOWN _SYMBOL_VALUE3(EF,A0,9E)
|
||||
#define SYMBOL_BRIGHTNESS _SYMBOL_VALUE3(EF,A0,9F)
|
||||
#define SYMBOL_DIRECTORY _SYMBOL_VALUE3(EF,A0,A0)
|
||||
#define SYMBOL_UPLOAD _SYMBOL_VALUE3(EF,A0,A1)
|
||||
#define SYMBOL_USB _SYMBOL_VALUE3(EF,A0,A2)
|
||||
#define SYMBOL_TOOLS _SYMBOL_VALUE3(EF,A0,A3)
|
||||
#define SYMBOL_COPY _SYMBOL_VALUE3(EF,A0,A4)
|
||||
#define SYMBOL_SAVE _SYMBOL_VALUE3(EF,A0,A5)
|
||||
#define SYMBOL_CHARGE _SYMBOL_VALUE3(EF,A0,A6)
|
||||
#define SYMBOL_HINT _SYMBOL_VALUE3(EF,A0,A7)
|
||||
#define SYMBOL_KEYBOARD _SYMBOL_VALUE3(EF,A0,A8)
|
||||
#define SYMBOL_GPS _SYMBOL_VALUE3(EF,A0,A9)
|
||||
#define SYMBOL_FILE _SYMBOL_VALUE3(EF,A0,AA)
|
||||
#define SYMBOL_CAMERA _SYMBOL_VALUE3(EF,A0,AB)
|
||||
#define SYMBOL_BATTERY_FULL _SYMBOL_VALUE3(EF,A0,AC)
|
||||
#define SYMBOL_BATTERY_3 _SYMBOL_VALUE3(EF,A0,AD)
|
||||
#define SYMBOL_BATTERY_2 _SYMBOL_VALUE3(EF,A0,AE)
|
||||
#define SYMBOL_BATTERY_1 _SYMBOL_VALUE3(EF,A0,AF)
|
||||
#define SYMBOL_BATTERY_EMPTY _SYMBOL_VALUE3(EF,A0,B0)
|
||||
#define SYMBOL_SHRK _SYMBOL_VALUE3(EF,A0,B1)
|
||||
#define LV_SYMBOL_GLYPH_LAST 0xF831
|
||||
#define SYMBOL_DUMMY _SYMBOL_VALUE3(EF,A3,BF) /*Invalid symbol at (U+F831). If written before a string then `lv_img` will show it as a label*/
|
||||
#endif
|
||||
|
||||
#define _SYMBOL_VALUE1(x) (0x ## x)
|
||||
#define _SYMBOL_VALUE3(x, y, z) (0x ## z ## y ## x)
|
||||
#define _SYMBOL_NUMSTR(sym) LV_ ## sym ## _NUMSTR = sym
|
||||
|
||||
enum
|
||||
{
|
||||
_SYMBOL_NUMSTR(SYMBOL_DOT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_CLOCK),
|
||||
_SYMBOL_NUMSTR(SYMBOL_LIST),
|
||||
_SYMBOL_NUMSTR(SYMBOL_OK),
|
||||
_SYMBOL_NUMSTR(SYMBOL_CLOSE),
|
||||
_SYMBOL_NUMSTR(SYMBOL_POWER),
|
||||
_SYMBOL_NUMSTR(SYMBOL_SETTINGS),
|
||||
_SYMBOL_NUMSTR(SYMBOL_TRASH),
|
||||
_SYMBOL_NUMSTR(SYMBOL_HOME),
|
||||
_SYMBOL_NUMSTR(SYMBOL_DOWNLOAD),
|
||||
_SYMBOL_NUMSTR(SYMBOL_DRIVE),
|
||||
_SYMBOL_NUMSTR(SYMBOL_REFRESH),
|
||||
_SYMBOL_NUMSTR(SYMBOL_REBOOT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_CHIP),
|
||||
_SYMBOL_NUMSTR(SYMBOL_SD),
|
||||
_SYMBOL_NUMSTR(SYMBOL_CIRCUIT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_EDIT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_FILE_ALT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_FILE_CODE),
|
||||
_SYMBOL_NUMSTR(SYMBOL_FILE_ARC),
|
||||
_SYMBOL_NUMSTR(SYMBOL_TEMPERATURE),
|
||||
_SYMBOL_NUMSTR(SYMBOL_MODULES),
|
||||
_SYMBOL_NUMSTR(SYMBOL_MODULES_ALT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_LEFT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_RIGHT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_KEY),
|
||||
_SYMBOL_NUMSTR(SYMBOL_INFO),
|
||||
_SYMBOL_NUMSTR(SYMBOL_WARNING),
|
||||
_SYMBOL_NUMSTR(SYMBOL_SHUFFLE),
|
||||
_SYMBOL_NUMSTR(SYMBOL_UP),
|
||||
_SYMBOL_NUMSTR(SYMBOL_DOWN),
|
||||
_SYMBOL_NUMSTR(SYMBOL_BRIGHTNESS),
|
||||
_SYMBOL_NUMSTR(SYMBOL_DIRECTORY),
|
||||
_SYMBOL_NUMSTR(SYMBOL_UPLOAD),
|
||||
_SYMBOL_NUMSTR(SYMBOL_USB),
|
||||
_SYMBOL_NUMSTR(SYMBOL_TOOLS),
|
||||
_SYMBOL_NUMSTR(SYMBOL_COPY),
|
||||
_SYMBOL_NUMSTR(SYMBOL_SAVE),
|
||||
_SYMBOL_NUMSTR(SYMBOL_CHARGE),
|
||||
_SYMBOL_NUMSTR(SYMBOL_HINT),
|
||||
_SYMBOL_NUMSTR(SYMBOL_KEYBOARD),
|
||||
_SYMBOL_NUMSTR(SYMBOL_GPS),
|
||||
_SYMBOL_NUMSTR(SYMBOL_FILE),
|
||||
_SYMBOL_NUMSTR(SYMBOL_CAMERA),
|
||||
_SYMBOL_NUMSTR(SYMBOL_BATTERY_FULL),
|
||||
_SYMBOL_NUMSTR(SYMBOL_BATTERY_3),
|
||||
_SYMBOL_NUMSTR(SYMBOL_BATTERY_2),
|
||||
_SYMBOL_NUMSTR(SYMBOL_BATTERY_1),
|
||||
_SYMBOL_NUMSTR(SYMBOL_BATTERY_EMPTY),
|
||||
_SYMBOL_NUMSTR(SYMBOL_SHRK),
|
||||
_SYMBOL_NUMSTR(SYMBOL_DUMMY),
|
||||
};
|
||||
|
||||
#undef _SYMBOL_VALUE1
|
||||
#undef _SYMBOL_VALUE3
|
||||
|
||||
#define _SYMBOL_STR_(x) #x
|
||||
#define _SYMBOL_STR(x) _SYMBOL_STR_(x)
|
||||
#define _SYMBOL_CHAR(c) \x ## c
|
||||
#define _SYMBOL_VALUE1(x) _SYMBOL_STR(_SYMBOL_CHAR(x))
|
||||
#define _SYMBOL_VALUE3(x, y, z) _SYMBOL_STR(_SYMBOL_CHAR(x)_SYMBOL_CHAR(y)_SYMBOL_CHAR(z))
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*LV_SYMBOL_DEF_H*/
|
332
bdk/libs/lvgl/lv_misc/lv_task.c
Normal file
332
bdk/libs/lvgl/lv_misc/lv_task.c
Normal file
|
@ -0,0 +1,332 @@
|
|||
/**
|
||||
* @file lv_task.c
|
||||
* An 'lv_task' is a void (*fp) (void* param) type function which will be called periodically.
|
||||
* A priority (5 levels + disable) can be assigned to lv_tasks.
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include <stddef.h>
|
||||
#include "lv_task.h"
|
||||
#include "../lv_hal/lv_hal_tick.h"
|
||||
#include "lv_gc.h"
|
||||
|
||||
#if defined(LV_GC_INCLUDE)
|
||||
# include LV_GC_INCLUDE
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define IDLE_MEAS_PERIOD 500 /*[ms]*/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_task_exec(lv_task_t * lv_task_p);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static bool lv_task_run = false;
|
||||
static uint8_t idle_last = 0;
|
||||
static bool task_deleted;
|
||||
static bool task_created;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Init the lv_task module
|
||||
*/
|
||||
void lv_task_init(void)
|
||||
{
|
||||
lv_ll_init(&LV_GC_ROOT(_lv_task_ll), sizeof(lv_task_t));
|
||||
|
||||
/*Initially enable the lv_task handling*/
|
||||
lv_task_enable(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call it periodically to handle lv_tasks.
|
||||
*/
|
||||
LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void)
|
||||
{
|
||||
LV_LOG_TRACE("lv_task_handler started");
|
||||
|
||||
/*Avoid concurrent running of the task handler*/
|
||||
static bool task_handler_mutex = false;
|
||||
if(task_handler_mutex) return;
|
||||
task_handler_mutex = true;
|
||||
|
||||
static uint32_t idle_period_start = 0;
|
||||
static uint32_t handler_start = 0;
|
||||
static uint32_t busy_time = 0;
|
||||
|
||||
if(lv_task_run == false) return;
|
||||
|
||||
handler_start = lv_tick_get();
|
||||
|
||||
/* Run all task from the highest to the lowest priority
|
||||
* If a lower priority task is executed check task again from the highest priority
|
||||
* but on the priority of executed tasks don't run tasks before the executed*/
|
||||
lv_task_t * task_interrupter = NULL;
|
||||
lv_task_t * next;
|
||||
bool end_flag;
|
||||
do {
|
||||
end_flag = true;
|
||||
task_deleted = false;
|
||||
task_created = false;
|
||||
LV_GC_ROOT(_lv_task_act) = lv_ll_get_head(&LV_GC_ROOT(_lv_task_ll));
|
||||
while(LV_GC_ROOT(_lv_task_act)) {
|
||||
/* The task might be deleted if it runs only once ('once = 1')
|
||||
* So get next element until the current is surely valid*/
|
||||
next = lv_ll_get_next(&LV_GC_ROOT(_lv_task_ll), LV_GC_ROOT(_lv_task_act));
|
||||
|
||||
/*We reach priority of the turned off task. There is nothing more to do.*/
|
||||
if(((lv_task_t *)LV_GC_ROOT(_lv_task_act))->prio == LV_TASK_PRIO_OFF) {
|
||||
break;
|
||||
}
|
||||
|
||||
/*Here is the interrupter task. Don't execute it again.*/
|
||||
if(LV_GC_ROOT(_lv_task_act) == task_interrupter) {
|
||||
task_interrupter = NULL; /*From this point only task after the interrupter comes, so the interrupter is not interesting anymore*/
|
||||
LV_GC_ROOT(_lv_task_act) = next;
|
||||
continue; /*Load the next task*/
|
||||
}
|
||||
|
||||
/*Just try to run the tasks with highest priority.*/
|
||||
if(((lv_task_t *)LV_GC_ROOT(_lv_task_act))->prio == LV_TASK_PRIO_HIGHEST) {
|
||||
lv_task_exec(LV_GC_ROOT(_lv_task_act));
|
||||
}
|
||||
/*Tasks with higher priority then the interrupted shall be run in every case*/
|
||||
else if(task_interrupter) {
|
||||
if(((lv_task_t *)LV_GC_ROOT(_lv_task_act))->prio > task_interrupter->prio) {
|
||||
if(lv_task_exec(LV_GC_ROOT(_lv_task_act))) {
|
||||
task_interrupter = LV_GC_ROOT(_lv_task_act); /*Check all tasks again from the highest priority */
|
||||
end_flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* It is no interrupter task or we already reached it earlier.
|
||||
* Just run the remaining tasks*/
|
||||
else {
|
||||
if(lv_task_exec(LV_GC_ROOT(_lv_task_act))) {
|
||||
task_interrupter = LV_GC_ROOT(_lv_task_act); /*Check all tasks again from the highest priority */
|
||||
end_flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(task_deleted) break; /*If a task was deleted then this or the next item might be corrupted*/
|
||||
if(task_created) break; /*If a task was deleted then this or the next item might be corrupted*/
|
||||
|
||||
LV_GC_ROOT(_lv_task_act) = next; /*Load the next task*/
|
||||
}
|
||||
} while(!end_flag);
|
||||
|
||||
busy_time += lv_tick_elaps(handler_start);
|
||||
uint32_t idle_period_time = lv_tick_elaps(idle_period_start);
|
||||
if(idle_period_time >= IDLE_MEAS_PERIOD) {
|
||||
|
||||
idle_last = (uint32_t)((uint32_t)busy_time * 100) / IDLE_MEAS_PERIOD; /*Calculate the busy percentage*/
|
||||
idle_last = idle_last > 100 ? 0 : 100 - idle_last; /*But we need idle time*/
|
||||
busy_time = 0;
|
||||
idle_period_start = lv_tick_get();
|
||||
|
||||
|
||||
}
|
||||
|
||||
task_handler_mutex = false; /*Release the mutex*/
|
||||
|
||||
LV_LOG_TRACE("lv_task_handler ready");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new lv_task
|
||||
* @param task a function which is the task itself
|
||||
* @param period call period in ms unit
|
||||
* @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped)
|
||||
* @param param free parameter
|
||||
* @return pointer to the new task
|
||||
*/
|
||||
lv_task_t * lv_task_create(void (*task)(void *), uint32_t period, lv_task_prio_t prio, void * param)
|
||||
{
|
||||
lv_task_t * new_lv_task = NULL;
|
||||
lv_task_t * tmp;
|
||||
|
||||
/*Create task lists in order of priority from high to low*/
|
||||
tmp = lv_ll_get_head(&LV_GC_ROOT(_lv_task_ll));
|
||||
if(NULL == tmp) { /*First task*/
|
||||
new_lv_task = lv_ll_ins_head(&LV_GC_ROOT(_lv_task_ll));
|
||||
lv_mem_assert(new_lv_task);
|
||||
if(new_lv_task == NULL) return NULL;
|
||||
} else {
|
||||
do {
|
||||
if(tmp->prio <= prio) {
|
||||
new_lv_task = lv_ll_ins_prev(&LV_GC_ROOT(_lv_task_ll), tmp);
|
||||
lv_mem_assert(new_lv_task);
|
||||
if(new_lv_task == NULL) return NULL;
|
||||
break;
|
||||
}
|
||||
tmp = lv_ll_get_next(&LV_GC_ROOT(_lv_task_ll), tmp);
|
||||
} while(tmp != NULL);
|
||||
|
||||
if(tmp == NULL) { /*Only too high priority tasks were found*/
|
||||
new_lv_task = lv_ll_ins_tail(&LV_GC_ROOT(_lv_task_ll));
|
||||
lv_mem_assert(new_lv_task);
|
||||
if(new_lv_task == NULL) return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
new_lv_task->period = period;
|
||||
new_lv_task->task = task;
|
||||
new_lv_task->prio = prio;
|
||||
new_lv_task->param = param;
|
||||
new_lv_task->once = 0;
|
||||
new_lv_task->last_run = lv_tick_get();
|
||||
|
||||
task_created = true;
|
||||
|
||||
return new_lv_task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a lv_task
|
||||
* @param lv_task_p pointer to task created by lv_task_p
|
||||
*/
|
||||
void lv_task_del(lv_task_t * lv_task_p)
|
||||
{
|
||||
lv_ll_rem(&LV_GC_ROOT(_lv_task_ll), lv_task_p);
|
||||
|
||||
lv_mem_free(lv_task_p);
|
||||
|
||||
if(LV_GC_ROOT(_lv_task_act) == lv_task_p) task_deleted = true; /*The active task was deleted*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new priority for a lv_task
|
||||
* @param lv_task_p pointer to a lv_task
|
||||
* @param prio the new priority
|
||||
*/
|
||||
void lv_task_set_prio(lv_task_t * lv_task_p, lv_task_prio_t prio)
|
||||
{
|
||||
/*Find the tasks with new priority*/
|
||||
lv_task_t * i;
|
||||
LL_READ(LV_GC_ROOT(_lv_task_ll), i) {
|
||||
if(i->prio <= prio) {
|
||||
if(i != lv_task_p) lv_ll_move_before(&LV_GC_ROOT(_lv_task_ll), lv_task_p, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*There was no such a low priority so far then add the node to the tail*/
|
||||
if(i == NULL) {
|
||||
lv_ll_move_before(&LV_GC_ROOT(_lv_task_ll), lv_task_p, NULL);
|
||||
}
|
||||
|
||||
|
||||
lv_task_p->prio = prio;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set new period for a lv_task
|
||||
* @param lv_task_p pointer to a lv_task
|
||||
* @param period the new period
|
||||
*/
|
||||
void lv_task_set_period(lv_task_t * lv_task_p, uint32_t period)
|
||||
{
|
||||
lv_task_p->period = period;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a lv_task ready. It will not wait its period.
|
||||
* @param lv_task_p pointer to a lv_task.
|
||||
*/
|
||||
void lv_task_ready(lv_task_t * lv_task_p)
|
||||
{
|
||||
lv_task_p->last_run = lv_tick_get() - lv_task_p->period - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the lv_task after one call
|
||||
* @param lv_task_p pointer to a lv_task.
|
||||
*/
|
||||
void lv_task_once(lv_task_t * lv_task_p)
|
||||
{
|
||||
lv_task_p->once = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset a lv_task.
|
||||
* It will be called the previously set period milliseconds later.
|
||||
* @param lv_task_p pointer to a lv_task.
|
||||
*/
|
||||
void lv_task_reset(lv_task_t * lv_task_p)
|
||||
{
|
||||
lv_task_p->last_run = lv_tick_get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable the whole lv_task handling
|
||||
* @param en: true: lv_task handling is running, false: lv_task handling is suspended
|
||||
*/
|
||||
void lv_task_enable(bool en)
|
||||
{
|
||||
lv_task_run = en;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get idle percentage
|
||||
* @return the lv_task idle in percentage
|
||||
*/
|
||||
uint8_t lv_task_get_idle(void)
|
||||
{
|
||||
return idle_last;
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Execute task if its the priority is appropriate
|
||||
* @param lv_task_p pointer to lv_task
|
||||
* @return true: execute, false: not executed
|
||||
*/
|
||||
static bool lv_task_exec(lv_task_t * lv_task_p)
|
||||
{
|
||||
bool exec = false;
|
||||
|
||||
/*Execute if at least 'period' time elapsed*/
|
||||
uint32_t elp = lv_tick_elaps(lv_task_p->last_run);
|
||||
if(elp >= lv_task_p->period) {
|
||||
lv_task_p->last_run = lv_tick_get();
|
||||
task_deleted = false;
|
||||
task_created = false;
|
||||
lv_task_p->task(lv_task_p->param);
|
||||
|
||||
/*Delete if it was a one shot lv_task*/
|
||||
if(task_deleted == false) { /*The task might be deleted by itself as well*/
|
||||
if(lv_task_p->once != 0) {
|
||||
lv_task_del(lv_task_p);
|
||||
}
|
||||
}
|
||||
exec = true;
|
||||
}
|
||||
|
||||
return exec;
|
||||
}
|
||||
|
149
bdk/libs/lvgl/lv_misc/lv_task.h
Normal file
149
bdk/libs/lvgl/lv_misc/lv_task.h
Normal file
|
@ -0,0 +1,149 @@
|
|||
/**
|
||||
* @file lv_task.c
|
||||
* An 'lv_task' is a void (*fp) (void* param) type function which will be called periodically.
|
||||
* A priority (5 levels + disable) can be assigned to lv_tasks.
|
||||
*/
|
||||
|
||||
#ifndef LV_TASK_H
|
||||
#define LV_TASK_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "lv_mem.h"
|
||||
#include "lv_ll.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#ifndef LV_ATTRIBUTE_TASK_HANDLER
|
||||
#define LV_ATTRIBUTE_TASK_HANDLER
|
||||
#endif
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
/**
|
||||
* Possible priorities for lv_tasks
|
||||
*/
|
||||
#define LV_TASK_ONESHOT 0
|
||||
enum
|
||||
{
|
||||
LV_TASK_PRIO_OFF = 0,
|
||||
LV_TASK_PRIO_LOWEST,
|
||||
LV_TASK_PRIO_LOW,
|
||||
LV_TASK_PRIO_MID,
|
||||
LV_TASK_PRIO_HIGH,
|
||||
LV_TASK_PRIO_HIGHEST,
|
||||
LV_TASK_PRIO_NUM,
|
||||
};
|
||||
typedef uint8_t lv_task_prio_t;
|
||||
|
||||
/**
|
||||
* Descriptor of a lv_task
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t period;
|
||||
uint32_t last_run;
|
||||
void (*task) (void*);
|
||||
void * param;
|
||||
uint8_t prio:3;
|
||||
uint8_t once:1;
|
||||
} lv_task_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Init the lv_task module
|
||||
*/
|
||||
void lv_task_init(void);
|
||||
|
||||
/**
|
||||
* Call it periodically to handle lv_tasks.
|
||||
*/
|
||||
LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void);
|
||||
|
||||
/**
|
||||
* Create a new lv_task
|
||||
* @param task a function which is the task itself
|
||||
* @param period call period in ms unit
|
||||
* @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped)
|
||||
* @param param free parameter
|
||||
* @return pointer to the new task
|
||||
*/
|
||||
lv_task_t* lv_task_create(void (*task) (void *), uint32_t period, lv_task_prio_t prio, void * param);
|
||||
|
||||
/**
|
||||
* Delete a lv_task
|
||||
* @param lv_task_p pointer to task created by lv_task_p
|
||||
*/
|
||||
void lv_task_del(lv_task_t* lv_task_p);
|
||||
|
||||
/**
|
||||
* Set new priority for a lv_task
|
||||
* @param lv_task_p pointer to a lv_task
|
||||
* @param prio the new priority
|
||||
*/
|
||||
void lv_task_set_prio(lv_task_t* lv_task_p, lv_task_prio_t prio);
|
||||
|
||||
/**
|
||||
* Set new period for a lv_task
|
||||
* @param lv_task_p pointer to a lv_task
|
||||
* @param period the new period
|
||||
*/
|
||||
void lv_task_set_period(lv_task_t* lv_task_p, uint32_t period);
|
||||
|
||||
/**
|
||||
* Make a lv_task ready. It will not wait its period.
|
||||
* @param lv_task_p pointer to a lv_task.
|
||||
*/
|
||||
void lv_task_ready(lv_task_t* lv_task_p);
|
||||
|
||||
|
||||
/**
|
||||
* Delete the lv_task after one call
|
||||
* @param lv_task_p pointer to a lv_task.
|
||||
*/
|
||||
void lv_task_once(lv_task_t * lv_task_p);
|
||||
|
||||
/**
|
||||
* Reset a lv_task.
|
||||
* It will be called the previously set period milliseconds later.
|
||||
* @param lv_task_p pointer to a lv_task.
|
||||
*/
|
||||
void lv_task_reset(lv_task_t* lv_task_p);
|
||||
|
||||
/**
|
||||
* Enable or disable the whole lv_task handling
|
||||
* @param en: true: lv_task handling is running, false: lv_task handling is suspended
|
||||
*/
|
||||
void lv_task_enable(bool en);
|
||||
|
||||
/**
|
||||
* Get idle percentage
|
||||
* @return the lv_task idle in percentage
|
||||
*/
|
||||
uint8_t lv_task_get_idle(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
36
bdk/libs/lvgl/lv_misc/lv_templ.c
Normal file
36
bdk/libs/lvgl/lv_misc/lv_templ.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* @file lv_templ.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
38
bdk/libs/lvgl/lv_misc/lv_templ.h
Normal file
38
bdk/libs/lvgl/lv_misc/lv_templ.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* @file lv_templ.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_TEMPL_H
|
||||
#define LV_TEMPL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_TEMPL_H*/
|
793
bdk/libs/lvgl/lv_misc/lv_txt.c
Normal file
793
bdk/libs/lvgl/lv_misc/lv_txt.c
Normal file
|
@ -0,0 +1,793 @@
|
|||
/**
|
||||
* @file lv_text.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_txt.h"
|
||||
#include "lv_math.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define NO_BREAK_FOUND UINT32_MAX
|
||||
|
||||
#ifndef LV_TXT_LINE_BREAK_LONG_LEN
|
||||
#define LV_TXT_LINE_BREAK_LONG_LEN 12 /* If a character is at least this long, will break wherever "prettiest" */
|
||||
#endif
|
||||
|
||||
#ifndef LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN
|
||||
#define LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN 3 /* Minimum number of characters of a word to put on a line before a break */
|
||||
#endif
|
||||
|
||||
#ifndef LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN
|
||||
#define LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN 1 /* Minimum number of characters of a word to put on a line after a break */
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool is_break_char(uint32_t letter);
|
||||
|
||||
#if LV_TXT_UTF8
|
||||
static uint8_t lv_txt_utf8_size(const char * str);
|
||||
static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni);
|
||||
static uint32_t lv_txt_utf8_conv_wc(uint32_t c);
|
||||
static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i);
|
||||
static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i_start);
|
||||
static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id);
|
||||
static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id);
|
||||
static uint32_t lv_txt_utf8_get_length(const char * txt);
|
||||
#else
|
||||
static uint8_t lv_txt_ascii_size(const char * str);
|
||||
static uint32_t lv_txt_unicode_to_ascii(uint32_t letter_uni);
|
||||
static uint32_t lv_txt_ascii_conv_wc(uint32_t c);
|
||||
static uint32_t lv_txt_ascii_next(const char * txt, uint32_t * i);
|
||||
static uint32_t lv_txt_ascii_prev(const char * txt, uint32_t * i_start);
|
||||
static uint32_t lv_txt_ascii_get_byte_id(const char * txt, uint32_t utf8_id);
|
||||
static uint32_t lv_txt_ascii_get_char_id(const char * txt, uint32_t byte_id);
|
||||
static uint32_t lv_txt_ascii_get_length(const char * txt);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL VARIABLES
|
||||
**********************/
|
||||
#if LV_TXT_UTF8
|
||||
uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_utf8_size;
|
||||
uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_utf8;
|
||||
uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_utf8_conv_wc;
|
||||
uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_utf8_next;
|
||||
uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_utf8_prev;
|
||||
uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_utf8_get_byte_id;
|
||||
uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id;
|
||||
uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_utf8_get_length;
|
||||
#else
|
||||
uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_ascii_size;
|
||||
uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_ascii;
|
||||
uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_ascii_conv_wc;
|
||||
uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_ascii_next;
|
||||
uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_ascii_prev;
|
||||
uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_ascii_get_byte_id;
|
||||
uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t) = lv_txt_ascii_get_char_id;
|
||||
uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_ascii_get_length;
|
||||
#endif
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Get size of a text
|
||||
* @param size_res pointer to a 'point_t' variable to store the result
|
||||
* @param text pointer to a text
|
||||
* @param font pinter to font of the text
|
||||
* @param letter_space letter space of the text
|
||||
* @param txt.line_space line space of the text
|
||||
* @param flags settings for the text from 'txt_flag_t' enum
|
||||
* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks
|
||||
*/
|
||||
void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font,
|
||||
lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag)
|
||||
{
|
||||
size_res->x = 0;
|
||||
size_res->y = 0;
|
||||
|
||||
if(text == NULL) return;
|
||||
if(font == NULL) return;
|
||||
|
||||
if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
|
||||
|
||||
uint32_t line_start = 0;
|
||||
uint32_t new_line_start = 0;
|
||||
lv_coord_t act_line_length;
|
||||
uint8_t letter_height = lv_font_get_height(font);
|
||||
|
||||
/*Calc. the height and longest line*/
|
||||
while(text[line_start] != '\0') {
|
||||
new_line_start += lv_txt_get_next_line(&text[line_start], font, letter_space, max_width, flag);
|
||||
size_res->y += letter_height ;
|
||||
size_res->y += line_space;
|
||||
|
||||
/*Calculate the the longest line*/
|
||||
act_line_length = lv_txt_get_width(&text[line_start], new_line_start - line_start,
|
||||
font, letter_space, flag);
|
||||
|
||||
size_res->x = LV_MATH_MAX(act_line_length, size_res->x);
|
||||
line_start = new_line_start;
|
||||
}
|
||||
|
||||
/*Make the text one line taller if the last character is '\n' or '\r'*/
|
||||
if((line_start != 0) && (text[line_start - 1] == '\n' || text[line_start - 1] == '\r')) {
|
||||
size_res->y += letter_height + line_space;
|
||||
}
|
||||
|
||||
/*Correction with the last line space or set the height manually if the text is empty*/
|
||||
if(size_res->y == 0) size_res->y = letter_height;
|
||||
else size_res->y -= line_space;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next line of text. Check line length and break chars too.
|
||||
* @param txt a '\0' terminated string
|
||||
* @param font pointer to a font
|
||||
* @param letter_space letter space
|
||||
* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks
|
||||
* @param flags settings for the text from 'txt_flag_type' enum
|
||||
* @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different)
|
||||
*/
|
||||
uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
|
||||
lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag)
|
||||
{
|
||||
if(txt == NULL) return 0;
|
||||
if(font == NULL) return 0;
|
||||
|
||||
if(flag & LV_TXT_FLAG_EXPAND) max_width = LV_COORD_MAX;
|
||||
|
||||
uint32_t i = 0;
|
||||
lv_coord_t cur_w = 0;
|
||||
lv_coord_t w_at_last_break = 0;
|
||||
uint32_t n_char_since_last_break = 0; /* Used count word length of long words */
|
||||
uint32_t last_break = NO_BREAK_FOUND;
|
||||
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
|
||||
uint32_t letter = 0;
|
||||
|
||||
while(txt[i] != '\0') {
|
||||
lv_coord_t letter_width;
|
||||
letter = lv_txt_encoded_next(txt, &i);
|
||||
|
||||
/*Handle the recolor command*/
|
||||
if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
|
||||
if(lv_txt_is_cmd(&cmd_state, letter) != false) {
|
||||
continue; /*Skip the letter is it is part of a command*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*Check for new line chars*/
|
||||
if(letter == '\n' || letter == '\r') {
|
||||
uint32_t i_tmp = i;
|
||||
uint32_t letter_next = lv_txt_encoded_next(txt, &i_tmp);
|
||||
if(letter == '\r' && letter_next == '\n') i = i_tmp;
|
||||
|
||||
return i; /*Return with the first letter of the next line*/
|
||||
|
||||
} else { /*Check the actual length*/
|
||||
n_char_since_last_break++;
|
||||
letter_width = lv_font_get_width(font, letter);
|
||||
cur_w += letter_width;
|
||||
|
||||
/* Get the length of the current work and determine best place
|
||||
* to break the line. */
|
||||
if(cur_w > max_width) {
|
||||
if( last_break != NO_BREAK_FOUND ) {
|
||||
/* Continue searching for next breakable character to see if the next word will fit */
|
||||
uint32_t n_char_fit = n_char_since_last_break - 1;
|
||||
if( n_char_since_last_break <= LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN ) {
|
||||
i = last_break;
|
||||
}
|
||||
else {
|
||||
uint32_t i_tmp = i;
|
||||
cur_w -= w_at_last_break + letter_space; /*ignore the first letter_space after the break char */
|
||||
bool other = true;
|
||||
while(txt[i_tmp] != '\0') {
|
||||
letter = lv_txt_encoded_next(txt, &i_tmp);
|
||||
|
||||
/*Handle the recolor command*/
|
||||
if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
|
||||
if(lv_txt_is_cmd(&cmd_state, letter) != false) {
|
||||
continue; /*Skip the letter is it is part of a command*/
|
||||
}
|
||||
}
|
||||
|
||||
/*Check for new line chars*/
|
||||
if(letter == '\n' || letter == '\r' || is_break_char(letter)) {
|
||||
if(n_char_since_last_break >= LV_TXT_LINE_BREAK_LONG_LEN) {
|
||||
/* Figure out the prettiest place to break */
|
||||
uint32_t char_remain;
|
||||
lv_txt_encoded_prev(txt, &i);
|
||||
for(char_remain=n_char_since_last_break - n_char_fit;
|
||||
char_remain < LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN;
|
||||
char_remain++) {
|
||||
lv_txt_encoded_prev(txt, &i);
|
||||
}
|
||||
}
|
||||
else{
|
||||
i = last_break;
|
||||
}
|
||||
other = false;
|
||||
break;
|
||||
}
|
||||
n_char_since_last_break++;
|
||||
lv_coord_t letter_width2 = lv_font_get_width(font, letter);
|
||||
cur_w += letter_width2;
|
||||
if(cur_w > max_width) {
|
||||
/* Current letter already exceeds, return previous */
|
||||
lv_txt_encoded_prev(txt, &i);
|
||||
other = false;
|
||||
break;
|
||||
}
|
||||
if(letter_width2 > 0){
|
||||
cur_w += letter_space;
|
||||
}
|
||||
}
|
||||
if( other ) {
|
||||
if(n_char_since_last_break >= LV_TXT_LINE_BREAK_LONG_LEN) {
|
||||
/* Figure out the prettiest place to break */
|
||||
uint32_t char_remain;
|
||||
lv_txt_encoded_prev(txt, &i);
|
||||
for(char_remain=n_char_since_last_break - n_char_fit;
|
||||
char_remain < LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN;
|
||||
char_remain++){
|
||||
lv_txt_encoded_prev(txt, &i);
|
||||
}
|
||||
}
|
||||
else{
|
||||
i = last_break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Now this character is out of the area so it will be first character of the next line*/
|
||||
/* But 'i' already points to the next character (because of lv_txt_utf8_next) step beck one*/
|
||||
lv_txt_encoded_prev(txt, &i);
|
||||
}
|
||||
|
||||
/* Do not let to return without doing nothing.
|
||||
* Find at least one character (Avoid infinite loop )*/
|
||||
if(i == 0) lv_txt_encoded_next(txt, &i);
|
||||
|
||||
return i;
|
||||
}
|
||||
/*If this char still can fit to this line then check if
|
||||
* txt can be broken here later */
|
||||
else if(is_break_char(letter)) {
|
||||
last_break = i; /*Save the first char index after break*/
|
||||
w_at_last_break = cur_w;
|
||||
if(letter_width > 0) {
|
||||
w_at_last_break += letter_space;
|
||||
}
|
||||
n_char_since_last_break = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(letter_width > 0) {
|
||||
cur_w += letter_space;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the length of a text with a given font
|
||||
* @param txt a '\0' terminate string
|
||||
* @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8)
|
||||
* @param font pointer to a font
|
||||
* @param letter_space letter space
|
||||
* @param flags settings for the text from 'txt_flag_t' enum
|
||||
* @return length of a char_num long text
|
||||
*/
|
||||
lv_coord_t lv_txt_get_width(const char * txt, uint16_t length,
|
||||
const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag)
|
||||
{
|
||||
if(txt == NULL) return 0;
|
||||
if(font == NULL) return 0;
|
||||
|
||||
uint32_t i = 0;
|
||||
lv_coord_t width = 0;
|
||||
lv_txt_cmd_state_t cmd_state = LV_TXT_CMD_STATE_WAIT;
|
||||
uint32_t letter;
|
||||
|
||||
if(length != 0) {
|
||||
while(i< length){
|
||||
letter = lv_txt_encoded_next(txt, &i);
|
||||
if((flag & LV_TXT_FLAG_RECOLOR) != 0) {
|
||||
if(lv_txt_is_cmd(&cmd_state, letter) != false) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
lv_coord_t char_width = lv_font_get_width(font, letter);
|
||||
if(char_width > 0){
|
||||
width += char_width;
|
||||
width += letter_space;
|
||||
}
|
||||
}
|
||||
|
||||
if(width > 0) {
|
||||
width -= letter_space; /*Trim the last letter space. Important if the text is center aligned */
|
||||
}
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check next character in a string and decide if the character is part of the command or not
|
||||
* @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing
|
||||
* (Initied. to TXT_CMD_STATE_WAIT )
|
||||
* @param c the current character
|
||||
* @return true: the character is part of a command and should not be written,
|
||||
* false: the character should be written
|
||||
*/
|
||||
bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
if(c == (uint32_t)LV_TXT_COLOR_CMD[0]) {
|
||||
if(*state == LV_TXT_CMD_STATE_WAIT) { /*Start char*/
|
||||
*state = LV_TXT_CMD_STATE_PAR;
|
||||
ret = true;
|
||||
} else if(*state == LV_TXT_CMD_STATE_PAR) { /*Other start char in parameter is escaped cmd. char */
|
||||
*state = LV_TXT_CMD_STATE_WAIT;
|
||||
} else if(*state == LV_TXT_CMD_STATE_IN) { /*Command end */
|
||||
*state = LV_TXT_CMD_STATE_WAIT;
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*Skip the color parameter and wait the space after it*/
|
||||
if(*state == LV_TXT_CMD_STATE_PAR) {
|
||||
if(c == ' ') {
|
||||
*state = LV_TXT_CMD_STATE_IN; /*After the parameter the text is in the command*/
|
||||
}
|
||||
ret = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a string into an other
|
||||
* @param txt_buf the original text (must be big enough for the result text)
|
||||
* @param pos position to insert. Expressed in character index and not byte index (Different in UTF-8)
|
||||
* 0: before the original text, 1: after the first char etc.
|
||||
* @param ins_txt text to insert
|
||||
*/
|
||||
void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt)
|
||||
{
|
||||
uint32_t old_len = strlen(txt_buf);
|
||||
uint32_t ins_len = strlen(ins_txt);
|
||||
uint32_t new_len = ins_len + old_len;
|
||||
#if LV_TXT_UTF8 != 0
|
||||
pos = lv_txt_encoded_get_byte_id(txt_buf, pos); /*Convert to byte index instead of letter index*/
|
||||
#endif
|
||||
/*Copy the second part into the end to make place to text to insert*/
|
||||
uint32_t i;
|
||||
for(i = new_len; i >= pos + ins_len; i--) {
|
||||
txt_buf[i] = txt_buf[i - ins_len];
|
||||
}
|
||||
|
||||
/* Copy the text into the new space*/
|
||||
memcpy(txt_buf + pos, ins_txt, ins_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a part of a string
|
||||
* @param txt string to modify
|
||||
* @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.)
|
||||
* @param len number of characters to delete
|
||||
*/
|
||||
void lv_txt_cut(char * txt, uint32_t pos, uint32_t len)
|
||||
{
|
||||
|
||||
uint32_t old_len = strlen(txt);
|
||||
#if LV_TXT_UTF8 != 0
|
||||
pos = lv_txt_encoded_get_byte_id(txt, pos); /*Convert to byte index instead of letter index*/
|
||||
len = lv_txt_encoded_get_byte_id(&txt[pos], len);
|
||||
#endif
|
||||
|
||||
/*Copy the second part into the end to make place to text to insert*/
|
||||
uint32_t i;
|
||||
for(i = pos; i <= old_len - len; i++) {
|
||||
txt[i] = txt[i + len];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************
|
||||
* UTF-8 ENCODER/DECOER
|
||||
******************************/
|
||||
|
||||
#if LV_TXT_UTF8
|
||||
|
||||
/**
|
||||
* Give the size of an UTF-8 coded character
|
||||
* @param str pointer to a character in a string
|
||||
* @return length of the UTF-8 character (1,2,3 or 4). O on invalid code
|
||||
*/
|
||||
static uint8_t lv_txt_utf8_size(const char * str)
|
||||
{
|
||||
if((str[0] & 0x80) == 0) return 1;
|
||||
else if((str[0] & 0xE0) == 0xC0) return 2;
|
||||
else if((str[0] & 0xF0) == 0xE0) return 3;
|
||||
else if((str[0] & 0xF8) == 0xF0) return 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert an Unicode letter to UTF-8.
|
||||
* @param letter_uni an Unicode letter
|
||||
* @return UTF-8 coded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ű')
|
||||
*/
|
||||
static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni)
|
||||
{
|
||||
if(letter_uni < 128) return letter_uni;
|
||||
uint8_t bytes[4];
|
||||
|
||||
if(letter_uni < 0x0800) {
|
||||
bytes[0] = ((letter_uni >> 6) & 0x1F) | 0xC0;
|
||||
bytes[1] = ((letter_uni >> 0) & 0x3F) | 0x80;
|
||||
bytes[2] = 0;
|
||||
bytes[3] = 0;
|
||||
} else if(letter_uni < 0x010000) {
|
||||
bytes[0] = ((letter_uni >> 12) & 0x0F) | 0xE0;
|
||||
bytes[1] = ((letter_uni >> 6) & 0x3F) | 0x80;
|
||||
bytes[2] = ((letter_uni >> 0) & 0x3F) | 0x80;
|
||||
bytes[3] = 0;
|
||||
} else if(letter_uni < 0x110000) {
|
||||
bytes[0] = ((letter_uni >> 18) & 0x07) | 0xF0;
|
||||
bytes[1] = ((letter_uni >> 12) & 0x3F) | 0x80;
|
||||
bytes[2] = ((letter_uni >> 6) & 0x3F) | 0x80;
|
||||
bytes[3] = ((letter_uni >> 0) & 0x3F) | 0x80;
|
||||
}
|
||||
|
||||
uint32_t * res_p = (uint32_t *)bytes;
|
||||
return *res_p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a wide character, e.g. 'Á' little endian to be UTF-8 compatible
|
||||
* @param c a wide character or a Little endian number
|
||||
* @return `c` in big endian
|
||||
*/
|
||||
static uint32_t lv_txt_utf8_conv_wc(uint32_t c)
|
||||
{
|
||||
/*Swap the bytes (UTF-8 is big endian, but the MCUs are little endian)*/
|
||||
if((c & 0x80) != 0) {
|
||||
uint32_t swapped;
|
||||
uint8_t c8[4];
|
||||
memcpy(c8, &c, 4);
|
||||
swapped = (c8[0] << 24) + (c8[1] << 16) + (c8[2] << 8) + (c8[3]);
|
||||
uint8_t i;
|
||||
for(i = 0; i < 4; i++) {
|
||||
if((swapped & 0xFF) == 0) swapped = (swapped >> 8); /*Ignore leading zeros (they were in the end originally)*/
|
||||
}
|
||||
c = swapped;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode an UTF-8 character from a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i start byte index in 'txt' where to start.
|
||||
* After call it will point to the next UTF-8 char in 'txt'.
|
||||
* NULL to use txt[0] as index
|
||||
* @return the decoded Unicode character or 0 on invalid UTF-8 code
|
||||
*/
|
||||
static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i)
|
||||
{
|
||||
/* Unicode to UTF-8
|
||||
* 00000000 00000000 00000000 0xxxxxxx -> 0xxxxxxx
|
||||
* 00000000 00000000 00000yyy yyxxxxxx -> 110yyyyy 10xxxxxx
|
||||
* 00000000 00000000 zzzzyyyy yyxxxxxx -> 1110zzzz 10yyyyyy 10xxxxxx
|
||||
* 00000000 000wwwzz zzzzyyyy yyxxxxxx -> 11110www 10zzzzzz 10yyyyyy 10xxxxxx
|
||||
* */
|
||||
|
||||
uint32_t result = 0;
|
||||
|
||||
/*Dummy 'i' pointer is required*/
|
||||
uint32_t i_tmp = 0;
|
||||
if(i == NULL) i = &i_tmp;
|
||||
|
||||
/*Normal ASCII*/
|
||||
if((txt[*i] & 0x80) == 0) {
|
||||
result = txt[*i];
|
||||
(*i)++;
|
||||
}
|
||||
/*Real UTF-8 decode*/
|
||||
else {
|
||||
/*2 bytes UTF-8 code*/
|
||||
if((txt[*i] & 0xE0) == 0xC0) {
|
||||
result = (uint32_t)(txt[*i] & 0x1F) << 6;
|
||||
(*i)++;
|
||||
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
|
||||
result += (txt[*i] & 0x3F);
|
||||
(*i)++;
|
||||
}
|
||||
/*3 bytes UTF-8 code*/
|
||||
else if((txt[*i] & 0xF0) == 0xE0) {
|
||||
result = (uint32_t)(txt[*i] & 0x0F) << 12;
|
||||
(*i)++;
|
||||
|
||||
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
|
||||
result += (uint32_t)(txt[*i] & 0x3F) << 6;
|
||||
(*i)++;
|
||||
|
||||
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
|
||||
result += (txt[*i] & 0x3F);
|
||||
(*i)++;
|
||||
}
|
||||
/*4 bytes UTF-8 code*/
|
||||
else if((txt[*i] & 0xF8) == 0xF0) {
|
||||
result = (uint32_t)(txt[*i] & 0x07) << 18;
|
||||
(*i)++;
|
||||
|
||||
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
|
||||
result += (uint32_t)(txt[*i] & 0x3F) << 12;
|
||||
(*i)++;
|
||||
|
||||
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
|
||||
result += (uint32_t)(txt[*i] & 0x3F) << 6;
|
||||
(*i)++;
|
||||
|
||||
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
|
||||
result += txt[*i] & 0x3F;
|
||||
(*i)++;
|
||||
} else {
|
||||
(*i)++; /*Not UTF-8 char. Go the next.*/
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get previous UTF-8 character form a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i start byte index in 'txt' where to start. After the call it will point to the previous UTF-8 char in 'txt'.
|
||||
* @return the decoded Unicode character or 0 on invalid UTF-8 code
|
||||
*/
|
||||
static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i)
|
||||
{
|
||||
uint8_t c_size;
|
||||
uint8_t cnt = 0;
|
||||
|
||||
/*Try to find a !0 long UTF-8 char by stepping one character back*/
|
||||
(*i)--;
|
||||
do {
|
||||
if(cnt >= 4) return 0; /*No UTF-8 char found before the initial*/
|
||||
|
||||
c_size = lv_txt_encoded_size(&txt[*i]);
|
||||
if(c_size == 0) {
|
||||
if(*i != 0)(*i)--;
|
||||
else return 0;
|
||||
}
|
||||
cnt++;
|
||||
} while(c_size == 0);
|
||||
|
||||
uint32_t i_tmp = *i;
|
||||
uint32_t letter = lv_txt_encoded_next(txt, &i_tmp); /*Character found, get it*/
|
||||
|
||||
return letter;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a character index (in an UTF-8 text) to byte index.
|
||||
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param utf8_id character index
|
||||
* @return byte index of the 'utf8_id'th letter
|
||||
*/
|
||||
static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t byte_cnt = 0;
|
||||
for(i = 0; i < utf8_id; i++) {
|
||||
byte_cnt += lv_txt_encoded_size(&txt[byte_cnt]);
|
||||
}
|
||||
|
||||
return byte_cnt;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a byte index (in an UTF-8 text) to character index.
|
||||
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param byte_id byte index
|
||||
* @return character index of the letter at 'byte_id'th position
|
||||
*/
|
||||
static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id)
|
||||
{
|
||||
uint32_t i = 0;
|
||||
uint32_t char_cnt = 0;
|
||||
|
||||
while(i < byte_id) {
|
||||
lv_txt_encoded_next(txt, &i); /*'i' points to the next letter so use the prev. value*/
|
||||
char_cnt++;
|
||||
}
|
||||
|
||||
return char_cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of characters (and NOT bytes) in a string. Decode it with UTF-8 if enabled.
|
||||
* E.g.: "ÁBC" is 3 characters (but 4 bytes)
|
||||
* @param txt a '\0' terminated char string
|
||||
* @return number of characters
|
||||
*/
|
||||
static uint32_t lv_txt_utf8_get_length(const char * txt)
|
||||
{
|
||||
#if LV_TXT_UTF8 == 0
|
||||
return strlen(txt);
|
||||
#else
|
||||
uint32_t len = 0;
|
||||
uint32_t i = 0;
|
||||
|
||||
while(txt[i] != '\0') {
|
||||
lv_txt_encoded_next(txt, &i);
|
||||
len++;
|
||||
}
|
||||
|
||||
return len;
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
/**
|
||||
* Give the size of an UTF-8 coded character
|
||||
* @param str pointer to a character in a string
|
||||
* @return length of the UTF-8 character (1,2,3 or 4). O on invalid code
|
||||
*/
|
||||
static uint8_t lv_txt_ascii_size(const char * str)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert an Unicode letter to UTF-8.
|
||||
* @param letter_uni an Unicode letter
|
||||
* @return UTF-8 coded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ű')
|
||||
*/
|
||||
static uint32_t lv_txt_unicode_to_ascii(uint32_t letter_uni)
|
||||
{
|
||||
if(letter_uni < 128) return letter_uni;
|
||||
else return ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert wide characters to ASCII, however wide characters in ASCII range (e.g. 'A') are ASCII compatible by default.
|
||||
* So this function does nothing just returns with `c`.
|
||||
* @param c a character, e.g. 'A'
|
||||
* @return same as `c`
|
||||
*/
|
||||
static uint32_t lv_txt_ascii_conv_wc(uint32_t c)
|
||||
{
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode an UTF-8 character from a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i start byte index in 'txt' where to start.
|
||||
* After call it will point to the next UTF-8 char in 'txt'.
|
||||
* NULL to use txt[0] as index
|
||||
* @return the decoded Unicode character or 0 on invalid UTF-8 code
|
||||
*/
|
||||
static uint32_t lv_txt_ascii_next(const char * txt, uint32_t * i)
|
||||
{
|
||||
if(i == NULL) return txt[1]; /*Get the next char */
|
||||
|
||||
uint8_t letter = txt[*i] ;
|
||||
(*i)++;
|
||||
return letter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get previous UTF-8 character form a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i start byte index in 'txt' where to start. After the call it will point to the previous UTF-8 char in 'txt'.
|
||||
* @return the decoded Unicode character or 0 on invalid UTF-8 code
|
||||
*/
|
||||
static uint32_t lv_txt_ascii_prev(const char * txt, uint32_t * i)
|
||||
{
|
||||
if(i == NULL) return *(txt - 1); /*Get the prev. char */
|
||||
|
||||
(*i)--;
|
||||
uint8_t letter = txt[*i] ;
|
||||
|
||||
return letter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a character index (in an UTF-8 text) to byte index.
|
||||
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param utf8_id character index
|
||||
* @return byte index of the 'utf8_id'th letter
|
||||
*/
|
||||
static uint32_t lv_txt_ascii_get_byte_id(const char * txt, uint32_t utf8_id)
|
||||
{
|
||||
return utf8_id; /*In Non encoded no difference*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a byte index (in an UTF-8 text) to character index.
|
||||
* E.g. in "AÁRT" index of 'R' is 2th char but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param byte_id byte index
|
||||
* @return character index of the letter at 'byte_id'th position
|
||||
*/
|
||||
static uint32_t lv_txt_ascii_get_char_id(const char * txt, uint32_t byte_id)
|
||||
{
|
||||
return byte_id; /*In Non encoded no difference*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of characters (and NOT bytes) in a string. Decode it with UTF-8 if enabled.
|
||||
* E.g.: "ÁBC" is 3 characters (but 4 bytes)
|
||||
* @param txt a '\0' terminated char string
|
||||
* @return number of characters
|
||||
*/
|
||||
static uint32_t lv_txt_ascii_get_length(const char * txt)
|
||||
{
|
||||
return strlen(txt);
|
||||
}
|
||||
#endif
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Test if char is break char or not (a text can broken here or not)
|
||||
* @param letter a letter
|
||||
* @return false: 'letter' is not break char
|
||||
*/
|
||||
static bool is_break_char(uint32_t letter)
|
||||
{
|
||||
uint8_t i;
|
||||
bool ret = false;
|
||||
|
||||
/*Compare the letter to TXT_BREAK_CHARS*/
|
||||
for(i = 0; LV_TXT_BREAK_CHARS[i] != '\0'; i++) {
|
||||
if(letter == (uint32_t)LV_TXT_BREAK_CHARS[i]) {
|
||||
ret = true; /*If match then it is break char*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
197
bdk/libs/lvgl/lv_misc/lv_txt.h
Normal file
197
bdk/libs/lvgl/lv_misc/lv_txt.h
Normal file
|
@ -0,0 +1,197 @@
|
|||
/**
|
||||
* @file lv_text.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_TXT_H
|
||||
#define LV_TXT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#include "lv_area.h"
|
||||
#include "lv_font.h"
|
||||
#include "lv_area.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define LV_TXT_COLOR_CMD "#"
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
enum
|
||||
{
|
||||
LV_TXT_FLAG_NONE = 0x00,
|
||||
LV_TXT_FLAG_RECOLOR = 0x01, /*Enable parsing of recolor command*/
|
||||
LV_TXT_FLAG_EXPAND = 0x02, /*Ignore width to avoid automatic word wrapping*/
|
||||
LV_TXT_FLAG_CENTER = 0x04, /*Align the text to the middle*/
|
||||
LV_TXT_FLAG_RIGHT = 0x08, /*Align the text to the right*/
|
||||
};
|
||||
typedef uint8_t lv_txt_flag_t;
|
||||
|
||||
enum
|
||||
{
|
||||
LV_TXT_CMD_STATE_WAIT, /*Waiting for command*/
|
||||
LV_TXT_CMD_STATE_PAR, /*Processing the parameter*/
|
||||
LV_TXT_CMD_STATE_IN, /*Processing the command*/
|
||||
};
|
||||
typedef uint8_t lv_txt_cmd_state_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Get size of a text
|
||||
* @param size_res pointer to a 'point_t' variable to store the result
|
||||
* @param text pointer to a text
|
||||
* @param font pinter to font of the text
|
||||
* @param letter_space letter space of the text
|
||||
* @param line_space line space of the text
|
||||
* @param flags settings for the text from 'txt_flag_t' enum
|
||||
* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks
|
||||
*/
|
||||
void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t * font,
|
||||
lv_coord_t letter_space, lv_coord_t line_space, lv_coord_t max_width, lv_txt_flag_t flag);
|
||||
|
||||
/**
|
||||
* Get the next line of text. Check line length and break chars too.
|
||||
* @param txt a '\0' terminated string
|
||||
* @param font pointer to a font
|
||||
* @param letter_space letter space
|
||||
* @param max_width max with of the text (break the lines to fit this size) Set CORD_MAX to avoid line breaks
|
||||
* @param flags settings for the text from 'txt_flag_type' enum
|
||||
* @return the index of the first char of the new line (in byte index not letter index. With UTF-8 they are different)
|
||||
*/
|
||||
uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
|
||||
lv_coord_t letter_space, lv_coord_t max_width, lv_txt_flag_t flag);
|
||||
|
||||
/**
|
||||
* Give the length of a text with a given font
|
||||
* @param txt a '\0' terminate string
|
||||
* @param length length of 'txt' in byte count and not characters (Á is 1 character but 2 bytes in UTF-8)
|
||||
* @param font pointer to a font
|
||||
* @param letter_space letter space
|
||||
* @param flags settings for the text from 'txt_flag_t' enum
|
||||
* @return length of a char_num long text
|
||||
*/
|
||||
lv_coord_t lv_txt_get_width(const char * txt, uint16_t length,
|
||||
const lv_font_t * font, lv_coord_t letter_space, lv_txt_flag_t flag);
|
||||
|
||||
|
||||
/**
|
||||
* Check next character in a string and decide if te character is part of the command or not
|
||||
* @param state pointer to a txt_cmd_state_t variable which stores the current state of command processing
|
||||
* @param c the current character
|
||||
* @return true: the character is part of a command and should not be written,
|
||||
* false: the character should be written
|
||||
*/
|
||||
bool lv_txt_is_cmd(lv_txt_cmd_state_t * state, uint32_t c);
|
||||
|
||||
/**
|
||||
* Insert a string into an other
|
||||
* @param txt_buf the original text (must be big enough for the result text)
|
||||
* @param pos position to insert (0: before the original text, 1: after the first char etc.)
|
||||
* @param ins_txt text to insert
|
||||
*/
|
||||
void lv_txt_ins(char * txt_buf, uint32_t pos, const char * ins_txt);
|
||||
|
||||
/**
|
||||
* Delete a part of a string
|
||||
* @param txt string to modify
|
||||
* @param pos position where to start the deleting (0: before the first char, 1: after the first char etc.)
|
||||
* @param len number of characters to delete
|
||||
*/
|
||||
void lv_txt_cut(char * txt, uint32_t pos, uint32_t len);
|
||||
|
||||
/***************************************************************
|
||||
* GLOBAL FUNCTION POINTERS FOR CAHRACTER ENCODING INTERFACE
|
||||
***************************************************************/
|
||||
|
||||
/**
|
||||
* Give the size of an encoded character
|
||||
* @param str pointer to a character in a string
|
||||
* @return length of the encoded character (1,2,3 ...). O in invalid
|
||||
*/
|
||||
extern uint8_t (*lv_txt_encoded_size)(const char *);
|
||||
|
||||
|
||||
/**
|
||||
* Convert an Unicode letter to encoded
|
||||
* @param letter_uni an Unicode letter
|
||||
* @return Encoded character in Little Endian to be compatible with C chars (e.g. 'Á', 'Ü')
|
||||
*/
|
||||
extern uint32_t (*lv_txt_unicode_to_encoded)(uint32_t );
|
||||
|
||||
/**
|
||||
* Convert a wide character, e.g. 'Á' little endian to be compatible with the encoded format.
|
||||
* @param c a wide character
|
||||
* @return `c` in the encoded format
|
||||
*/
|
||||
extern uint32_t (*lv_txt_encoded_conv_wc) (uint32_t c);
|
||||
|
||||
/**
|
||||
* Decode the next encoded character from a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i start index in 'txt' where to start.
|
||||
* After the call it will point to the next encoded char in 'txt'.
|
||||
* NULL to use txt[0] as index
|
||||
* @return the decoded Unicode character or 0 on invalid data code
|
||||
*/
|
||||
extern uint32_t (*lv_txt_encoded_next)(const char *, uint32_t * );
|
||||
|
||||
/**
|
||||
* Get the previous encoded character form a string.
|
||||
* @param txt pointer to '\0' terminated string
|
||||
* @param i_start index in 'txt' where to start. After the call it will point to the previous encoded char in 'txt'.
|
||||
* @return the decoded Unicode character or 0 on invalid data
|
||||
*/
|
||||
extern uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *);
|
||||
|
||||
/**
|
||||
* Convert a letter index (in an the encoded text) to byte index.
|
||||
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param enc_id letter index
|
||||
* @return byte index of the 'enc_id'th letter
|
||||
*/
|
||||
extern uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t);
|
||||
|
||||
/**
|
||||
* Convert a byte index (in an encoded text) to character index.
|
||||
* E.g. in UTF-8 "AÁRT" index of 'R' is 2 but start at byte 3 because 'Á' is 2 bytes long
|
||||
* @param txt a '\0' terminated UTF-8 string
|
||||
* @param byte_id byte index
|
||||
* @return character index of the letter at 'byte_id'th position
|
||||
*/
|
||||
extern uint32_t (*lv_encoded_get_char_id)(const char *, uint32_t);
|
||||
|
||||
/**
|
||||
* Get the number of characters (and NOT bytes) in a string.
|
||||
* E.g. in UTF-8 "ÁBC" is 3 characters (but 4 bytes)
|
||||
* @param txt a '\0' terminated char string
|
||||
* @return number of characters
|
||||
*/
|
||||
extern uint32_t (*lv_txt_get_encoded_length)(const char *);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*USE_TXT*/
|
516
bdk/libs/lvgl/lv_misc/lv_ufs.c
Normal file
516
bdk/libs/lvgl/lv_misc/lv_ufs.c
Normal file
|
@ -0,0 +1,516 @@
|
|||
/**
|
||||
* @file lv_ufs.c
|
||||
* Implementation of RAM file system which do NOT support directories.
|
||||
* The API is compatible with the lv_fs_int module.
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_ufs.h"
|
||||
#if USE_LV_FILESYSTEM
|
||||
|
||||
#include "lv_ll.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "lv_gc.h"
|
||||
|
||||
#if defined(LV_GC_INCLUDE)
|
||||
# include LV_GC_INCLUDE
|
||||
#endif /* LV_ENABLE_GC */
|
||||
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_ufs_ent_t * lv_ufs_ent_get(const char * fn);
|
||||
static lv_ufs_ent_t * lv_ufs_ent_new(const char * fn);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static bool inited = false;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a driver for ufs and initialize it.
|
||||
*/
|
||||
void lv_ufs_init(void)
|
||||
{
|
||||
lv_ll_init(&LV_GC_ROOT(_lv_file_ll), sizeof(lv_ufs_ent_t));
|
||||
|
||||
lv_fs_drv_t ufs_drv;
|
||||
memset(&ufs_drv, 0, sizeof(lv_fs_drv_t)); /*Initialization*/
|
||||
|
||||
ufs_drv.file_size = sizeof(lv_ufs_file_t);
|
||||
ufs_drv.rddir_size = sizeof(lv_ufs_dir_t);
|
||||
ufs_drv.letter = UFS_LETTER;
|
||||
ufs_drv.ready = lv_ufs_ready;
|
||||
|
||||
ufs_drv.open = lv_ufs_open;
|
||||
ufs_drv.close = lv_ufs_close;
|
||||
ufs_drv.remove = lv_ufs_remove;
|
||||
ufs_drv.read = lv_ufs_read;
|
||||
ufs_drv.write = lv_ufs_write;
|
||||
ufs_drv.seek = lv_ufs_seek;
|
||||
ufs_drv.tell = lv_ufs_tell;
|
||||
ufs_drv.size = lv_ufs_size;
|
||||
ufs_drv.trunc = lv_ufs_trunc;
|
||||
ufs_drv.free = lv_ufs_free;
|
||||
|
||||
ufs_drv.dir_open = lv_ufs_dir_open;
|
||||
ufs_drv.dir_read = lv_ufs_dir_read;
|
||||
ufs_drv.dir_close = lv_ufs_dir_close;
|
||||
|
||||
lv_fs_add_drv(&ufs_drv);
|
||||
|
||||
inited = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the state of the ufs
|
||||
* @return true if ufs is initialized and can be used else false
|
||||
*/
|
||||
bool lv_ufs_ready(void)
|
||||
{
|
||||
return inited;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a file in ufs
|
||||
* @param file_p pointer to a lv_ufs_file_t variable
|
||||
* @param fn name of the file. There are no directories so e.g. "myfile.txt"
|
||||
* @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)
|
||||
* @return LV_FS_RES_OK: no error, the file is opened
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_open(void * file_p, const char * fn, lv_fs_mode_t mode)
|
||||
{
|
||||
lv_ufs_file_t * fp = file_p; /*Convert type*/
|
||||
lv_ufs_ent_t * ent = lv_ufs_ent_get(fn);
|
||||
|
||||
fp->ent = NULL;
|
||||
|
||||
/*If the file not exists ...*/
|
||||
if(ent == NULL) {
|
||||
if((mode & LV_FS_MODE_WR) != 0) { /*Create the file if opened for write*/
|
||||
ent = lv_ufs_ent_new(fn);
|
||||
if(ent == NULL) return LV_FS_RES_FULL; /*No space for the new file*/
|
||||
} else {
|
||||
return LV_FS_RES_NOT_EX; /*Can not read not existing file*/
|
||||
}
|
||||
}
|
||||
|
||||
/*Can not write already opened and const data files*/
|
||||
if((mode & LV_FS_MODE_WR) != 0) {
|
||||
if(ent->oc != 0) return LV_FS_RES_LOCKED;
|
||||
if(ent->const_data != 0) return LV_FS_RES_DENIED;
|
||||
}
|
||||
|
||||
/*No error, the file can be opened*/
|
||||
fp->ent = ent;
|
||||
fp->ar = mode & LV_FS_MODE_RD ? 1 : 0;
|
||||
fp->aw = mode & LV_FS_MODE_WR ? 1 : 0;
|
||||
fp->rwp = 0;
|
||||
ent->oc ++;
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a file with a constant data
|
||||
* @param fn name of the file (directories are not supported)
|
||||
* @param const_p pointer to a constant data
|
||||
* @param len length of the data pointed by 'const_p' in bytes
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len)
|
||||
{
|
||||
lv_ufs_file_t file;
|
||||
lv_fs_res_t res;
|
||||
|
||||
/*Error if the file already exists*/
|
||||
res = lv_ufs_open(&file, fn, LV_FS_MODE_RD);
|
||||
if(res == LV_FS_RES_OK) {
|
||||
lv_ufs_close(&file);
|
||||
return LV_FS_RES_DENIED;
|
||||
}
|
||||
|
||||
lv_ufs_close(&file);
|
||||
|
||||
res = lv_ufs_open(&file, fn, LV_FS_MODE_WR);
|
||||
if(res != LV_FS_RES_OK) return res;
|
||||
|
||||
lv_ufs_ent_t * ent = file.ent;
|
||||
|
||||
if(ent->data_d != NULL) return LV_FS_RES_DENIED;
|
||||
|
||||
ent->data_d = (void *) const_p;
|
||||
ent->size = len;
|
||||
ent->const_data = 1;
|
||||
|
||||
res = lv_ufs_close(&file);
|
||||
if(res != LV_FS_RES_OK) return res;
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an opened file
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_close(void * file_p)
|
||||
{
|
||||
lv_ufs_file_t * fp = file_p; /*Convert type*/
|
||||
|
||||
if(fp->ent == NULL) return LV_FS_RES_OK;
|
||||
|
||||
/*Decrement the Open counter*/
|
||||
if(fp->ent->oc > 0) {
|
||||
fp->ent->oc--;
|
||||
}
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a file. The file can not be opened.
|
||||
* @param fn '\0' terminated string
|
||||
* @return LV_FS_RES_OK: no error, the file is removed
|
||||
* LV_FS_RES_DENIED: the file was opened, remove failed
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_remove(const char * fn)
|
||||
{
|
||||
lv_ufs_ent_t * ent = lv_ufs_ent_get(fn);
|
||||
if(ent == NULL) return LV_FS_RES_DENIED; /*File not exists*/
|
||||
|
||||
/*Can not be deleted is opened*/
|
||||
if(ent->oc != 0) return LV_FS_RES_DENIED;
|
||||
|
||||
lv_ll_rem(&LV_GC_ROOT(_lv_file_ll), ent);
|
||||
lv_mem_free(ent->fn_d);
|
||||
ent->fn_d = NULL;
|
||||
if(ent->const_data == 0) {
|
||||
lv_mem_free(ent->data_d);
|
||||
ent->data_d = NULL;
|
||||
}
|
||||
|
||||
lv_mem_free(ent);
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from an opened file
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @param buf pointer to a memory block where to store the read data
|
||||
* @param btr number of Bytes To Read
|
||||
* @param br the real number of read bytes (Byte Read)
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_read(void * file_p, void * buf, uint32_t btr, uint32_t * br)
|
||||
{
|
||||
lv_ufs_file_t * fp = file_p; /*Convert type*/
|
||||
|
||||
lv_ufs_ent_t * ent = fp->ent;
|
||||
*br = 0;
|
||||
|
||||
if(ent->data_d == NULL || ent->size == 0) { /*Don't read empty files*/
|
||||
return LV_FS_RES_OK;
|
||||
} else if(fp->ar == 0) { /*The file is not opened for read*/
|
||||
return LV_FS_RES_DENIED;
|
||||
}
|
||||
|
||||
/*No error, read the file*/
|
||||
if(fp->rwp + btr > ent->size) { /*Check too much bytes read*/
|
||||
*br = ent->size - fp->rwp;
|
||||
} else {
|
||||
*br = btr;
|
||||
}
|
||||
|
||||
/*Read the data*/
|
||||
uint8_t * data8_p;
|
||||
if(ent->const_data == 0) {
|
||||
data8_p = (uint8_t *) ent->data_d;
|
||||
} else {
|
||||
data8_p = ent->data_d;
|
||||
}
|
||||
|
||||
data8_p += fp->rwp;
|
||||
memcpy(buf, data8_p, *br);
|
||||
|
||||
fp->rwp += *br; /*Refresh the read write pointer*/
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to an opened file
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
|
||||
* @param buf pointer to a memory block which content will be written
|
||||
* @param btw the number Bytes To Write
|
||||
* @param bw The real number of written bytes (Byte Written)
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_write(void * file_p, const void * buf, uint32_t btw, uint32_t * bw)
|
||||
{
|
||||
lv_ufs_file_t * fp = file_p; /*Convert type*/
|
||||
*bw = 0;
|
||||
|
||||
if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/
|
||||
|
||||
lv_ufs_ent_t * ent = fp->ent;
|
||||
|
||||
/*Reallocate data array if it necessary*/
|
||||
uint32_t new_size = fp->rwp + btw;
|
||||
if(new_size > ent->size) {
|
||||
uint8_t * new_data = lv_mem_realloc(ent->data_d, new_size);
|
||||
lv_mem_assert(new_data);
|
||||
if(new_data == NULL) return LV_FS_RES_FULL; /*Cannot allocate the new memory*/
|
||||
|
||||
ent->data_d = new_data;
|
||||
ent->size = new_size;
|
||||
}
|
||||
|
||||
/*Write the file*/
|
||||
uint8_t * data8_p = (uint8_t *) ent->data_d;
|
||||
data8_p += fp->rwp;
|
||||
memcpy(data8_p, buf, btw);
|
||||
*bw = btw;
|
||||
fp->rwp += *bw;
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the read write pointer. Also expand the file size if necessary.
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @param pos the new position of read write pointer
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_seek(void * file_p, uint32_t pos)
|
||||
{
|
||||
lv_ufs_file_t * fp = file_p; /*Convert type*/
|
||||
lv_ufs_ent_t * ent = fp->ent;
|
||||
|
||||
/*Simply move the rwp before EOF*/
|
||||
if(pos < ent->size) {
|
||||
fp->rwp = pos;
|
||||
} else { /*Expand the file size*/
|
||||
if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/
|
||||
|
||||
uint8_t * new_data = lv_mem_realloc(ent->data_d, pos);
|
||||
lv_mem_assert(new_data);
|
||||
if(new_data == NULL) return LV_FS_RES_FULL; /*Out of memory*/
|
||||
|
||||
ent->data_d = new_data;
|
||||
ent->size = pos;
|
||||
fp->rwp = pos;
|
||||
}
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the position of the read write pointer
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @param pos_p pointer to to store the result
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_tell(void * file_p, uint32_t * pos_p)
|
||||
{
|
||||
lv_ufs_file_t * fp = file_p; /*Convert type*/
|
||||
|
||||
*pos_p = fp->rwp;
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the file size to the current position of the read write pointer
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_trunc(void * file_p)
|
||||
{
|
||||
lv_ufs_file_t * fp = file_p; /*Convert type*/
|
||||
lv_ufs_ent_t * ent = fp->ent;
|
||||
|
||||
if(fp->aw == 0) return LV_FS_RES_DENIED; /*Not opened for write*/
|
||||
|
||||
void * new_data = lv_mem_realloc(ent->data_d, fp->rwp);
|
||||
lv_mem_assert(new_data);
|
||||
if(new_data == NULL) return LV_FS_RES_FULL; /*Out of memory*/
|
||||
|
||||
ent->data_d = new_data;
|
||||
ent->size = fp->rwp;
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the size of the file in bytes
|
||||
* @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @param size_p pointer to store the size
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_size(void * file_p, uint32_t * size_p)
|
||||
{
|
||||
lv_ufs_file_t * fp = file_p; /*Convert type*/
|
||||
lv_ufs_ent_t * ent = fp->ent;
|
||||
|
||||
*size_p = ent->size;
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a lv_ufs_read_dir_t variable to directory reading
|
||||
* @param rddir_p pointer to a 'ufs_dir_t' variable
|
||||
* @param path uFS doesn't support folders so it has to be ""
|
||||
* @return LV_FS_RES_OK or any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path)
|
||||
{
|
||||
lv_ufs_dir_t * lv_ufs_rddir_p = rddir_p;
|
||||
|
||||
lv_ufs_rddir_p->last_ent = NULL;
|
||||
|
||||
if(path[0] != '\0') return LV_FS_RES_NOT_EX; /*Must be "" */
|
||||
else return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the next file name
|
||||
* @param dir_p pointer to an initialized 'ufs_dir_t' variable
|
||||
* @param fn pointer to buffer to sore the file name
|
||||
* @return LV_FS_RES_OK or any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn)
|
||||
{
|
||||
lv_ufs_dir_t * ufs_dir_p = dir_p;
|
||||
|
||||
if(ufs_dir_p->last_ent == NULL) {
|
||||
ufs_dir_p->last_ent = lv_ll_get_head(&LV_GC_ROOT(_lv_file_ll));
|
||||
} else {
|
||||
ufs_dir_p->last_ent = lv_ll_get_next(&LV_GC_ROOT(_lv_file_ll), ufs_dir_p->last_ent);
|
||||
}
|
||||
|
||||
if(ufs_dir_p->last_ent != NULL) {
|
||||
strcpy(fn, ufs_dir_p->last_ent->fn_d);
|
||||
} else {
|
||||
fn[0] = '\0';
|
||||
}
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the directory reading
|
||||
* @param rddir_p pointer to an initialized 'ufs_dir_t' variable
|
||||
* @return LV_FS_RES_OK or any error from lv__fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_dir_close(void * rddir_p)
|
||||
{
|
||||
(void)rddir_p;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the size of a drive
|
||||
* @param total_p pointer to store the total size [kB]
|
||||
* @param free_p pointer to store the free site [kB]
|
||||
* @return LV_FS_RES_OK or any error from 'lv_fs_res_t'
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_free(uint32_t * total_p, uint32_t * free_p)
|
||||
{
|
||||
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
lv_mem_monitor_t mon;
|
||||
|
||||
lv_mem_monitor(&mon);
|
||||
*total_p = LV_MEM_SIZE >> 10; /*Convert bytes to kB*/
|
||||
*free_p = mon.free_size >> 10;
|
||||
#else
|
||||
*free_p = 0;
|
||||
#endif
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Gives the lv_ufs_entry from a filename
|
||||
* @param fn filename ('\0' terminated string)
|
||||
* @return pointer to the dynamically allocated entry with 'fn' filename.
|
||||
* NULL if no entry found with that name.
|
||||
*/
|
||||
static lv_ufs_ent_t * lv_ufs_ent_get(const char * fn)
|
||||
{
|
||||
lv_ufs_ent_t * fp;
|
||||
|
||||
LL_READ(LV_GC_ROOT(_lv_file_ll), fp) {
|
||||
if(strcmp(fp->fn_d, fn) == 0) {
|
||||
return fp;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new entry with 'fn' filename
|
||||
* @param fn filename ('\0' terminated string)
|
||||
* @return pointer to the dynamically allocated new entry.
|
||||
* NULL if no space for the entry.
|
||||
*/
|
||||
static lv_ufs_ent_t * lv_ufs_ent_new(const char * fn)
|
||||
{
|
||||
lv_ufs_ent_t * new_ent = NULL;
|
||||
new_ent = lv_ll_ins_head(&LV_GC_ROOT(_lv_file_ll)); /*Create a new file*/
|
||||
lv_mem_assert(new_ent);
|
||||
if(new_ent == NULL) return NULL;
|
||||
|
||||
new_ent->fn_d = lv_mem_alloc(strlen(fn) + 1); /*Save the name*/
|
||||
lv_mem_assert(new_ent->fn_d);
|
||||
if(new_ent->fn_d == NULL) return NULL;
|
||||
|
||||
strcpy(new_ent->fn_d, fn);
|
||||
new_ent->data_d = NULL;
|
||||
new_ent->size = 0;
|
||||
new_ent->oc = 0;
|
||||
new_ent->const_data = 0;
|
||||
|
||||
return new_ent;
|
||||
}
|
||||
|
||||
#endif /*USE_LV_FILESYSTEM*/
|
||||
|
213
bdk/libs/lvgl/lv_misc/lv_ufs.h
Normal file
213
bdk/libs/lvgl/lv_misc/lv_ufs.h
Normal file
|
@ -0,0 +1,213 @@
|
|||
/**
|
||||
* @file lv_ufs.h
|
||||
* Implementation of RAM file system which do NOT support directories.
|
||||
* The API is compatible with the lv_fs_int module.
|
||||
*/
|
||||
|
||||
#ifndef LV_UFS_H
|
||||
#define LV_UFS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_LV_FILESYSTEM
|
||||
|
||||
#include "lv_fs.h"
|
||||
#include "lv_mem.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define UFS_LETTER 'U'
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
/*Description of a file entry */
|
||||
typedef struct
|
||||
{
|
||||
char * fn_d;
|
||||
void * data_d;
|
||||
uint32_t size; /*Data length in bytes*/
|
||||
uint16_t oc; /*Open Count*/
|
||||
uint8_t const_data :1;
|
||||
} lv_ufs_ent_t;
|
||||
|
||||
/*File descriptor, used to handle opening an entry more times simultaneously
|
||||
Contains unique informations about the specific opening*/
|
||||
typedef struct
|
||||
{
|
||||
lv_ufs_ent_t* ent; /*Pointer to the entry*/
|
||||
uint32_t rwp; /*Read Write Pointer*/
|
||||
uint8_t ar :1; /*1: Access for read is enabled */
|
||||
uint8_t aw :1; /*1: Access for write is enabled */
|
||||
} lv_ufs_file_t;
|
||||
|
||||
/* Read directory descriptor.
|
||||
* It is used to to iterate through the entries in a directory*/
|
||||
typedef struct
|
||||
{
|
||||
lv_ufs_ent_t * last_ent;
|
||||
} lv_ufs_dir_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a driver for ufs and initialize it.
|
||||
*/
|
||||
void lv_ufs_init(void);
|
||||
|
||||
/**
|
||||
* Give the state of the ufs
|
||||
* @return true if ufs is initialized and can be used else false
|
||||
*/
|
||||
bool lv_ufs_ready(void);
|
||||
|
||||
/**
|
||||
* Open a file in ufs
|
||||
* @param file_p pointer to a lv_ufs_file_t variable
|
||||
* @param fn name of the file. There are no directories so e.g. "myfile.txt"
|
||||
* @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)
|
||||
* @return LV_FS_RES_OK: no error, the file is opened
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_open (void * file_p, const char * fn, lv_fs_mode_t mode);
|
||||
|
||||
/**
|
||||
* Create a file with a constant data
|
||||
* @param fn name of the file (directories are not supported)
|
||||
* @param const_p pointer to a constant data
|
||||
* @param len length of the data pointed by 'const_p' in bytes
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_create_const(const char * fn, const void * const_p, uint32_t len);
|
||||
|
||||
/**
|
||||
* Close an opened file
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_close (void * file_p);
|
||||
|
||||
/**
|
||||
* Remove a file. The file can not be opened.
|
||||
* @param fn '\0' terminated string
|
||||
* @return LV_FS_RES_OK: no error, the file is removed
|
||||
* LV_FS_RES_DENIED: the file was opened, remove failed
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_remove(const char * fn);
|
||||
|
||||
/**
|
||||
* Read data from an opened file
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @param buf pointer to a memory block where to store the read data
|
||||
* @param btr number of Bytes To Read
|
||||
* @param br the real number of read bytes (Byte Read)
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_read (void * file_p, void * buf, uint32_t btr, uint32_t * br);
|
||||
|
||||
/**
|
||||
* Write data to an opened file
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open)
|
||||
* @param buf pointer to a memory block which content will be written
|
||||
* @param btw the number Bytes To Write
|
||||
* @param bw The real number of written bytes (Byte Written)
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_write (void * file_p, const void * buf, uint32_t btw, uint32_t * bw);
|
||||
|
||||
/**
|
||||
* Set the read write pointer. Also expand the file size if necessary.
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @param pos the new position of read write pointer
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_seek (void * file_p, uint32_t pos);
|
||||
|
||||
/**
|
||||
* Give the position of the read write pointer
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @param pos_p pointer to to store the result
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_tell (void * file_p, uint32_t * pos_p);
|
||||
|
||||
/**
|
||||
* Truncate the file size to the current position of the read write pointer
|
||||
* @param file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_trunc (void * file_p);
|
||||
|
||||
/**
|
||||
* Give the size of the file in bytes
|
||||
* @param file_p file_p pointer to an 'ufs_file_t' variable. (opened with lv_ufs_open )
|
||||
* @param size_p pointer to store the size
|
||||
* @return LV_FS_RES_OK: no error, the file is read
|
||||
* any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_size (void * file_p, uint32_t * size_p);
|
||||
|
||||
/**
|
||||
* Initialize a lv_ufs_read_dir_t variable to directory reading
|
||||
* @param rddir_p pointer to a 'ufs_read_dir_t' variable
|
||||
* @param path uFS doesn't support folders so it has to be ""
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_dir_open(void * rddir_p, const char * path);
|
||||
|
||||
/**
|
||||
* Read the next file name
|
||||
* @param dir_p pointer to an initialized 'ufs_read_dir_t' variable
|
||||
* @param fn pointer to buffer to sore the file name
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_dir_read(void * dir_p, char * fn);
|
||||
|
||||
/**
|
||||
* Close the directory reading
|
||||
* @param rddir_p pointer to an initialized 'ufs_read_dir_t' variable
|
||||
* @return LV_FS_RES_OK or any error from lv_fs_res_t enum
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_dir_close(void * rddir_p);
|
||||
|
||||
/**
|
||||
* Give the size of a drive
|
||||
* @param total_p pointer to store the total size [kB]
|
||||
* @param free_p pointer to store the free site [kB]
|
||||
* @return LV_FS_RES_OK or any error from 'fs_res_t'
|
||||
*/
|
||||
lv_fs_res_t lv_ufs_free (uint32_t * total_p, uint32_t * free_p);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_FILESYSTEM*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
310
bdk/libs/lvgl/lv_objx/lv_arc.c
Normal file
310
bdk/libs/lvgl/lv_objx/lv_arc.c
Normal file
|
@ -0,0 +1,310 @@
|
|||
/**
|
||||
* @file lv_arc.c
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_arc.h"
|
||||
#if USE_LV_ARC != 0
|
||||
|
||||
#include "../lv_misc/lv_math.h"
|
||||
#include "../lv_draw/lv_draw_arc.h"
|
||||
#include "../lv_themes/lv_theme.h"
|
||||
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_arc_design(lv_obj_t * arc, const lv_area_t * mask, lv_design_mode_t mode);
|
||||
static lv_res_t lv_arc_signal(lv_obj_t * arc, lv_signal_t sign, void * param);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_signal_func_t ancestor_signal;
|
||||
static lv_design_func_t ancestor_design;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a arc object
|
||||
* @param par pointer to an object, it will be the parent of the new arc
|
||||
* @param copy pointer to a arc object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created arc
|
||||
*/
|
||||
lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
{
|
||||
|
||||
LV_LOG_TRACE("arc create started");
|
||||
|
||||
/*Create the ancestor of arc*/
|
||||
lv_obj_t * new_arc = lv_obj_create(par, copy);
|
||||
lv_mem_assert(new_arc);
|
||||
if(new_arc == NULL) return NULL;
|
||||
|
||||
/*Allocate the arc type specific extended data*/
|
||||
lv_arc_ext_t * ext = lv_obj_allocate_ext_attr(new_arc, sizeof(lv_arc_ext_t));
|
||||
lv_mem_assert(ext);
|
||||
if(ext == NULL) return NULL;
|
||||
|
||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_arc);
|
||||
if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_arc);
|
||||
|
||||
/*Initialize the allocated 'ext' */
|
||||
ext->angle_start = 45;
|
||||
ext->angle_end = 315;
|
||||
|
||||
/*The signal and design functions are not copied so set them here*/
|
||||
lv_obj_set_signal_func(new_arc, lv_arc_signal);
|
||||
lv_obj_set_design_func(new_arc, lv_arc_design);
|
||||
|
||||
/*Init the new arc arc*/
|
||||
if(copy == NULL) {
|
||||
/*Set the default styles*/
|
||||
lv_theme_t * th = lv_theme_get_current();
|
||||
if(th) {
|
||||
lv_arc_set_style(new_arc, LV_ARC_STYLE_MAIN, th->arc);
|
||||
} else {
|
||||
lv_arc_set_style(new_arc, LV_ARC_STYLE_MAIN, &lv_style_plain_color);
|
||||
}
|
||||
|
||||
}
|
||||
/*Copy an existing arc*/
|
||||
else {
|
||||
lv_arc_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
ext->angle_start = copy_ext->angle_start;
|
||||
ext->angle_end = copy_ext->angle_end;
|
||||
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_arc);
|
||||
}
|
||||
|
||||
LV_LOG_INFO("arc created");
|
||||
|
||||
return new_arc;
|
||||
}
|
||||
|
||||
/*======================
|
||||
* Add/remove functions
|
||||
*=====================*/
|
||||
|
||||
/*
|
||||
* New object specific "add" or "remove" functions come here
|
||||
*/
|
||||
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc.
|
||||
* @param arc pointer to an arc object
|
||||
* @param start the start angle [0..360]
|
||||
* @param end the end angle [0..360]
|
||||
*/
|
||||
void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end)
|
||||
{
|
||||
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
|
||||
|
||||
if(start > 360) start = 360;
|
||||
if(end > 360) end = 360;
|
||||
|
||||
ext->angle_start = start;
|
||||
ext->angle_end = end;
|
||||
|
||||
lv_obj_invalidate(arc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a style of a arc.
|
||||
* @param arc pointer to arc object
|
||||
* @param type which style should be set
|
||||
* @param style pointer to a style
|
||||
* */
|
||||
void lv_arc_set_style(lv_obj_t * arc, lv_arc_style_t type, lv_style_t * style)
|
||||
{
|
||||
switch(type) {
|
||||
case LV_ARC_STYLE_MAIN:
|
||||
lv_obj_set_style(arc, style);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the start angle of an arc.
|
||||
* @param arc pointer to an arc object
|
||||
* @return the start angle [0..360]
|
||||
*/
|
||||
uint16_t lv_arc_get_angle_start(lv_obj_t * arc)
|
||||
{
|
||||
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
|
||||
|
||||
return ext->angle_start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end angle of an arc.
|
||||
* @param arc pointer to an arc object
|
||||
* @return the end angle [0..360]
|
||||
*/
|
||||
uint16_t lv_arc_get_angle_end(lv_obj_t * arc)
|
||||
{
|
||||
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
|
||||
|
||||
return ext->angle_end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style of a arc.
|
||||
* @param arc pointer to arc object
|
||||
* @param type which style should be get
|
||||
* @return style pointer to the style
|
||||
* */
|
||||
lv_style_t * lv_arc_get_style(const lv_obj_t * arc, lv_arc_style_t type)
|
||||
{
|
||||
lv_style_t * style = NULL;
|
||||
|
||||
switch(type) {
|
||||
case LV_ARC_STYLE_MAIN:
|
||||
style = lv_obj_get_style(arc);
|
||||
break;
|
||||
default:
|
||||
style = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/*
|
||||
* New object specific "other" functions come here
|
||||
*/
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the arcs
|
||||
* @param arc pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
* LV_DESIGN_DRAW: draw the object (always return 'true')
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_arc_design(lv_obj_t * arc, const lv_area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
return false;
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
lv_arc_ext_t * ext = lv_obj_get_ext_attr(arc);
|
||||
lv_style_t * style = lv_arc_get_style(arc, LV_ARC_STYLE_MAIN);
|
||||
|
||||
lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(arc), lv_obj_get_height(arc))) / 2;
|
||||
lv_coord_t x = arc->coords.x1 + lv_obj_get_width(arc) / 2;
|
||||
lv_coord_t y = arc->coords.y1 + lv_obj_get_height(arc) / 2;
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(arc);
|
||||
lv_draw_arc(x, y, r, mask, ext->angle_start, ext->angle_end, style, opa_scale);
|
||||
|
||||
|
||||
/*Draw circle on the ends if enabled */
|
||||
if(style->line.rounded) {
|
||||
lv_coord_t thick_half = style->line.width / 2;
|
||||
lv_coord_t cir_x = ((r - thick_half) * lv_trigo_sin(ext->angle_start) >> LV_TRIGO_SHIFT);
|
||||
lv_coord_t cir_y = ((r - thick_half) * lv_trigo_sin(ext->angle_start + 90) >> LV_TRIGO_SHIFT);
|
||||
|
||||
lv_style_t cir_style;
|
||||
lv_style_copy(&cir_style, &lv_style_plain);
|
||||
cir_style.body.grad_color = style->line.color;
|
||||
cir_style.body.main_color = cir_style.body.grad_color;
|
||||
cir_style.body.radius = LV_RADIUS_CIRCLE;
|
||||
lv_area_t cir_area;
|
||||
cir_area.x1 = cir_x + x - thick_half;
|
||||
cir_area.y1 = cir_y + y - thick_half;
|
||||
cir_area.x2 = cir_x + x + thick_half;
|
||||
cir_area.y2 = cir_y + y + thick_half;
|
||||
|
||||
lv_draw_rect(&cir_area, mask, &cir_style, opa_scale);
|
||||
|
||||
cir_x = ((r - thick_half) * lv_trigo_sin(ext->angle_end) >> LV_TRIGO_SHIFT);
|
||||
cir_y = ((r - thick_half) * lv_trigo_sin(ext->angle_end + 90) >> LV_TRIGO_SHIFT);
|
||||
|
||||
cir_area.x1 = cir_x + x - thick_half;
|
||||
cir_area.y1 = cir_y + y - thick_half;
|
||||
cir_area.x2 = cir_x + x + thick_half;
|
||||
cir_area.y2 = cir_y + y + thick_half;
|
||||
|
||||
lv_draw_rect(&cir_area, mask, &cir_style, opa_scale);
|
||||
}
|
||||
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DESIGN_DRAW_POST) {
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the arc
|
||||
* @param arc pointer to a arc object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static lv_res_t lv_arc_signal(lv_obj_t * arc, lv_signal_t sign, void * param)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = ancestor_signal(arc, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
||||
} else if(sign == LV_SIGNAL_GET_TYPE) {
|
||||
lv_obj_type_t * buf = param;
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
|
||||
if(buf->type[i] == NULL) break;
|
||||
}
|
||||
buf->type[i] = "lv_arc";
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
127
bdk/libs/lvgl/lv_objx/lv_arc.h
Normal file
127
bdk/libs/lvgl/lv_objx/lv_arc.h
Normal file
|
@ -0,0 +1,127 @@
|
|||
/**
|
||||
* @file lv_arc.h
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LV_ARC_H
|
||||
#define LV_ARC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_CONF_INCLUDE_SIMPLE
|
||||
#include "lv_conf.h"
|
||||
#else
|
||||
#include "../../lv_conf.h"
|
||||
#endif
|
||||
|
||||
#if USE_LV_ARC != 0
|
||||
|
||||
#include "../lv_core/lv_obj.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
/*Data of arc*/
|
||||
typedef struct {
|
||||
/*New data for this type */
|
||||
lv_coord_t angle_start;
|
||||
lv_coord_t angle_end;
|
||||
} lv_arc_ext_t;
|
||||
|
||||
|
||||
/*Styles*/
|
||||
enum {
|
||||
LV_ARC_STYLE_MAIN,
|
||||
};
|
||||
typedef uint8_t lv_arc_style_t;
|
||||
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a arc objects
|
||||
* @param par pointer to an object, it will be the parent of the new arc
|
||||
* @param copy pointer to a arc object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created arc
|
||||
*/
|
||||
lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy);
|
||||
|
||||
/*======================
|
||||
* Add/remove functions
|
||||
*=====================*/
|
||||
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc.
|
||||
* @param arc pointer to an arc object
|
||||
* @param start the start angle [0..360]
|
||||
* @param end the end angle [0..360]
|
||||
*/
|
||||
void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end);
|
||||
|
||||
/**
|
||||
* Set a style of a arc.
|
||||
* @param arc pointer to arc object
|
||||
* @param type which style should be set
|
||||
* @param style pointer to a style
|
||||
* */
|
||||
void lv_arc_set_style(lv_obj_t * arc, lv_arc_style_t type, lv_style_t *style);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the start angle of an arc.
|
||||
* @param arc pointer to an arc object
|
||||
* @return the start angle [0..360]
|
||||
*/
|
||||
uint16_t lv_arc_get_angle_start(lv_obj_t * arc);
|
||||
|
||||
/**
|
||||
* Get the end angle of an arc.
|
||||
* @param arc pointer to an arc object
|
||||
* @return the end angle [0..360]
|
||||
*/
|
||||
uint16_t lv_arc_get_angle_end(lv_obj_t * arc);
|
||||
|
||||
/**
|
||||
* Get style of a arc.
|
||||
* @param arc pointer to arc object
|
||||
* @param type which style should be get
|
||||
* @return style pointer to the style
|
||||
* */
|
||||
lv_style_t * lv_arc_get_style(const lv_obj_t * arc, lv_arc_style_t type);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#endif /*USE_LV_ARC*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_ARC_H*/
|
429
bdk/libs/lvgl/lv_objx/lv_bar.c
Normal file
429
bdk/libs/lvgl/lv_objx/lv_bar.c
Normal file
|
@ -0,0 +1,429 @@
|
|||
|
||||
|
||||
/**
|
||||
* @file lv_bar.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_bar.h"
|
||||
#if USE_LV_BAR != 0
|
||||
|
||||
#include "../lv_draw/lv_draw.h"
|
||||
#include "../lv_themes/lv_theme.h"
|
||||
#include "../lv_misc/lv_anim.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode_t mode);
|
||||
static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_design_func_t ancestor_design_f;
|
||||
static lv_signal_func_t ancestor_signal;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Create a bar objects
|
||||
* @param par pointer to an object, it will be the parent of the new bar
|
||||
* @param copy pointer to a bar object, if not NULL then the new object will be copied from it
|
||||
* @return pointer to the created bar
|
||||
*/
|
||||
lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
{
|
||||
LV_LOG_TRACE("lv_bar create started");
|
||||
|
||||
/*Create the ancestor basic object*/
|
||||
lv_obj_t * new_bar = lv_obj_create(par, copy);
|
||||
lv_mem_assert(new_bar);
|
||||
if(new_bar == NULL) return NULL;
|
||||
|
||||
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_bar);
|
||||
if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_bar);
|
||||
|
||||
/*Allocate the object type specific extended data*/
|
||||
lv_bar_ext_t * ext = lv_obj_allocate_ext_attr(new_bar, sizeof(lv_bar_ext_t));
|
||||
lv_mem_assert(ext);
|
||||
if(ext == NULL) return NULL;
|
||||
|
||||
ext->min_value = 0;
|
||||
ext->max_value = 100;
|
||||
ext->cur_value = 0;
|
||||
ext->sym = 0;
|
||||
ext->style_indic = &lv_style_pretty_color;
|
||||
|
||||
lv_obj_set_signal_func(new_bar, lv_bar_signal);
|
||||
lv_obj_set_design_func(new_bar, lv_bar_design);
|
||||
|
||||
/*Init the new bar object*/
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_click(new_bar, false);
|
||||
lv_obj_set_size(new_bar, LV_DPI * 2, LV_DPI / 3);
|
||||
lv_bar_set_value(new_bar, ext->cur_value);
|
||||
|
||||
lv_theme_t * th = lv_theme_get_current();
|
||||
if(th) {
|
||||
lv_bar_set_style(new_bar, LV_BAR_STYLE_BG, th->bar.bg);
|
||||
lv_bar_set_style(new_bar, LV_BAR_STYLE_INDIC, th->bar.indic);
|
||||
} else {
|
||||
lv_obj_set_style(new_bar, &lv_style_pretty);
|
||||
}
|
||||
} else {
|
||||
lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy);
|
||||
ext->min_value = ext_copy->min_value;
|
||||
ext->max_value = ext_copy->max_value;
|
||||
ext->cur_value = ext_copy->cur_value;
|
||||
ext->style_indic = ext_copy->style_indic;
|
||||
ext->sym = ext_copy->sym;
|
||||
/*Refresh the style with new signal function*/
|
||||
lv_obj_refresh_style(new_bar);
|
||||
|
||||
lv_bar_set_value(new_bar, ext->cur_value);
|
||||
}
|
||||
|
||||
LV_LOG_INFO("bar created");
|
||||
|
||||
return new_bar;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set a new value on the bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param value new value
|
||||
*/
|
||||
void lv_bar_set_value(lv_obj_t * bar, int16_t value)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
if(ext->cur_value == value) return;
|
||||
|
||||
ext->cur_value = value > ext->max_value ? ext->max_value : value;
|
||||
ext->cur_value = ext->cur_value < ext->min_value ? ext->min_value : ext->cur_value;
|
||||
lv_obj_invalidate(bar);
|
||||
}
|
||||
|
||||
#if USE_LV_ANIMATION
|
||||
/**
|
||||
* Set a new value with animation on the bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param value new value
|
||||
* @param anim_time animation time in milliseconds
|
||||
*/
|
||||
void lv_bar_set_value_anim(lv_obj_t * bar, int16_t value, uint16_t anim_time)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
if(ext->cur_value == value) return;
|
||||
|
||||
int16_t new_value;
|
||||
new_value = value > ext->max_value ? ext->max_value : value;
|
||||
new_value = new_value < ext->min_value ? ext->min_value : new_value;
|
||||
|
||||
lv_anim_t a;
|
||||
a.var = bar;
|
||||
a.start = ext->cur_value;
|
||||
a.end = new_value;
|
||||
a.fp = (lv_anim_fp_t)lv_bar_set_value;
|
||||
a.path = lv_anim_path_linear;
|
||||
a.end_cb = NULL;
|
||||
a.act_time = 0;
|
||||
a.time = anim_time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Set minimum and the maximum values of a bar
|
||||
* @param bar pointer to the bar object
|
||||
* @param min minimum value
|
||||
* @param max maximum value
|
||||
*/
|
||||
void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
if(ext->min_value == min && ext->max_value == max) return;
|
||||
|
||||
ext->max_value = max;
|
||||
ext->min_value = min;
|
||||
if(ext->cur_value > max) {
|
||||
ext->cur_value = max;
|
||||
lv_bar_set_value(bar, ext->cur_value);
|
||||
}
|
||||
if(ext->cur_value < min) {
|
||||
ext->cur_value = min;
|
||||
lv_bar_set_value(bar, ext->cur_value);
|
||||
}
|
||||
lv_obj_invalidate(bar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the bar symmetric to zero. The indicator will grow from zero instead of the minimum position.
|
||||
* @param bar pointer to a bar object
|
||||
* @param en true: enable disable symmetric behavior; false: disable
|
||||
*/
|
||||
void lv_bar_set_sym(lv_obj_t * bar, bool en)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
ext->sym = en ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a style of a bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param type which style should be set
|
||||
* @param style pointer to a style
|
||||
*/
|
||||
void lv_bar_set_style(lv_obj_t * bar, lv_bar_style_t type, lv_style_t * style)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
|
||||
switch(type) {
|
||||
case LV_BAR_STYLE_BG:
|
||||
lv_obj_set_style(bar, style);
|
||||
break;
|
||||
case LV_BAR_STYLE_INDIC:
|
||||
ext->style_indic = style;
|
||||
lv_obj_refresh_ext_size(bar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the value of a bar
|
||||
* @param bar pointer to a bar object
|
||||
* @return the value of the bar
|
||||
*/
|
||||
int16_t lv_bar_get_value(const lv_obj_t * bar)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
return ext->cur_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum value of a bar
|
||||
* @param bar pointer to a bar object
|
||||
* @return the minimum value of the bar
|
||||
*/
|
||||
int16_t lv_bar_get_min_value(const lv_obj_t * bar)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
return ext->min_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum value of a bar
|
||||
* @param bar pointer to a bar object
|
||||
* @return the maximum value of the bar
|
||||
*/
|
||||
int16_t lv_bar_get_max_value(const lv_obj_t * bar)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
return ext->max_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether the bar is symmetric or not.
|
||||
* @param bar pointer to a bar object
|
||||
* @return true: symmetric is enabled; false: disable
|
||||
*/
|
||||
bool lv_bar_get_sym(lv_obj_t * bar)
|
||||
{
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
return ext->sym ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a style of a bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param type which style should be get
|
||||
* @return style pointer to a style
|
||||
*/
|
||||
lv_style_t * lv_bar_get_style(const lv_obj_t * bar, lv_bar_style_t type)
|
||||
{
|
||||
lv_style_t * style = NULL;
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
|
||||
switch(type) {
|
||||
case LV_BAR_STYLE_BG:
|
||||
style = lv_obj_get_style(bar);
|
||||
break;
|
||||
case LV_BAR_STYLE_INDIC:
|
||||
style = ext->style_indic;
|
||||
break;
|
||||
default:
|
||||
style = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the bars
|
||||
* @param bar pointer to an object
|
||||
* @param mask the object will be drawn only in this area
|
||||
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
* LV_DESIGN_DRAW: draw the object (always return 'true')
|
||||
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
||||
* @param return true/false, depends on 'mode'
|
||||
*/
|
||||
static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DESIGN_COVER_CHK) {
|
||||
/*Return false if the object is not covers the mask area*/
|
||||
return ancestor_design_f(bar, mask, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(bar);
|
||||
|
||||
#if USE_LV_GROUP == 0
|
||||
ancestor_design_f(bar, mask, mode);
|
||||
#else
|
||||
/* Draw the borders later if the bar is focused.
|
||||
* At value = 100% the indicator can cover to whole background and the focused style won't be visible*/
|
||||
if(lv_obj_is_focused(bar)) {
|
||||
lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG);
|
||||
lv_style_t style_tmp;
|
||||
lv_style_copy(&style_tmp, style_bg);
|
||||
style_tmp.body.border.width = 0;
|
||||
lv_draw_rect(&bar->coords, mask, &style_tmp, opa_scale);
|
||||
} else {
|
||||
ancestor_design_f(bar, mask, mode);
|
||||
}
|
||||
#endif
|
||||
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
|
||||
|
||||
if(ext->cur_value != ext->min_value || ext->sym) {
|
||||
lv_style_t * style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC);
|
||||
lv_area_t indic_area;
|
||||
lv_area_copy(&indic_area, &bar->coords);
|
||||
indic_area.x1 += style_indic->body.padding.hor;
|
||||
indic_area.x2 -= style_indic->body.padding.hor;
|
||||
indic_area.y1 += style_indic->body.padding.ver;
|
||||
indic_area.y2 -= style_indic->body.padding.ver;
|
||||
|
||||
lv_coord_t w = lv_area_get_width(&indic_area);
|
||||
lv_coord_t h = lv_area_get_height(&indic_area);
|
||||
|
||||
if(w >= h) {
|
||||
/*Horizontal*/
|
||||
indic_area.x2 = (int32_t)((int32_t)w * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value);
|
||||
indic_area.x2 = indic_area.x1 + indic_area.x2 - 1;
|
||||
|
||||
if(ext->sym && ext->min_value < 0 && ext->max_value > 0) {
|
||||
/*Calculate the coordinate of the zero point*/
|
||||
lv_coord_t zero;
|
||||
zero = indic_area.x1 + (-ext->min_value * w) / (ext->max_value - ext->min_value);
|
||||
if(indic_area.x2 > zero) indic_area.x1 = zero;
|
||||
else {
|
||||
indic_area.x1 = indic_area.x2;
|
||||
indic_area.x2 = zero;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
indic_area.y1 = (int32_t)((int32_t)h * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value);
|
||||
indic_area.y1 = indic_area.y2 - indic_area.y1 + 1;
|
||||
|
||||
if(ext->sym && ext->min_value < 0 && ext->max_value > 0) {
|
||||
/*Calculate the coordinate of the zero point*/
|
||||
lv_coord_t zero;
|
||||
zero = indic_area.y2 - (-ext->min_value * h) / (ext->max_value - ext->min_value);
|
||||
if(indic_area.y1 < zero) indic_area.y2 = zero;
|
||||
else {
|
||||
indic_area.y2 = indic_area.y1;
|
||||
indic_area.y1 = zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*Draw the indicator*/
|
||||
lv_draw_rect(&indic_area, mask, style_indic, opa_scale);
|
||||
}
|
||||
} else if(mode == LV_DESIGN_DRAW_POST) {
|
||||
#if USE_LV_GROUP
|
||||
/*Draw the border*/
|
||||
if(lv_obj_is_focused(bar)) {
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(bar);
|
||||
lv_style_t * style_bg = lv_bar_get_style(bar, LV_BAR_STYLE_BG);
|
||||
lv_style_t style_tmp;
|
||||
lv_style_copy(&style_tmp, style_bg);
|
||||
style_tmp.body.empty = 1;
|
||||
style_tmp.body.shadow.width = 0;
|
||||
lv_draw_rect(&bar->coords, mask, &style_tmp, opa_scale);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the bar
|
||||
* @param bar pointer to a bar object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static lv_res_t lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = ancestor_signal(bar, sign, param);
|
||||
if(res != LV_RES_OK) return res;
|
||||
|
||||
if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
|
||||
lv_style_t * style_indic = lv_bar_get_style(bar, LV_BAR_STYLE_INDIC);
|
||||
if(style_indic->body.shadow.width > bar->ext_size) bar->ext_size = style_indic->body.shadow.width;
|
||||
} else if(sign == LV_SIGNAL_GET_TYPE) {
|
||||
lv_obj_type_t * buf = param;
|
||||
uint8_t i;
|
||||
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
|
||||
if(buf->type[i] == NULL) break;
|
||||
}
|
||||
buf->type[i] = "lv_bar";
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue