Transition to hekate bdk layout

This commit is contained in:
shchmue 2020-06-26 14:17:06 -06:00
parent 4425e81085
commit 4ffd4ce7f0
317 changed files with 60891 additions and 1003 deletions

View file

@ -19,15 +19,26 @@ TARGET := Lockpick_RCM
BUILDDIR := build
OUTPUTDIR := output
SOURCEDIR = source
BDKDIR := bdk
BDKINC := -I./$(BDKDIR)
VPATH = $(dir ./$(SOURCEDIR)/) $(dir $(wildcard ./$(SOURCEDIR)/*/)) $(dir $(wildcard ./$(SOURCEDIR)/*/*/))
VPATH += $(dir $(wildcard ./$(BDKDIR)/)) $(dir $(wildcard ./$(BDKDIR)/*/)) $(dir $(wildcard ./$(BDKDIR)/*/*/))
OBJS = $(patsubst $(SOURCEDIR)/%.S, $(BUILDDIR)/$(TARGET)/%.o, \
$(patsubst $(SOURCEDIR)/%.c, $(BUILDDIR)/$(TARGET)/%.o, \
$(call rwildcard, $(SOURCEDIR), *.S *.c)))
OBJS += $(patsubst $(BDKDIR)/%.S, $(BUILDDIR)/$(TARGET)/%.o, \
$(patsubst $(BDKDIR)/%.c, $(BUILDDIR)/$(TARGET)/%.o, \
$(call rwildcard, $(BDKDIR), *.S *.c)))
GFX_INC := '"../$(SOURCEDIR)/gfx/gfx.h"'
FFCFG_INC := '"../$(SOURCEDIR)/libs/fatfs/ffconf.h"'
################################################################################
CUSTOMDEFINES := -DIPL_LOAD_ADDR=$(IPL_LOAD_ADDR)
CUSTOMDEFINES += -DLP_VER_MJ=$(LPVERSION_MAJOR) -DLP_VER_MN=$(LPVERSION_MINOR) -DLP_VER_BF=$(LPVERSION_BUGFX)
CUSTOMDEFINES += -DGFX_INC=$(GFX_INC) -DFFCFG_INC=$(FFCFG_INC)
ARCH := -march=armv4t -mtune=arm7tdmi -mthumb -mthumb-interwork
CFLAGS = $(ARCH) -O2 -nostdlib -ffunction-sections -fno-inline -fdata-sections -fomit-frame-pointer -std=gnu11 -Wall $(CUSTOMDEFINES)
@ -47,16 +58,26 @@ $(OUTPUTDIR)/$(TARGET).bin: $(BUILDDIR)/$(TARGET)/$(TARGET).elf
@mkdir -p "$(@D)"
$(OBJCOPY) -S -O binary $< $@
@echo -n "Payload size is "
@wc -c < $@
$(eval BIN_SIZE = $(shell wc -c < $(OUTPUTDIR)/$(TARGET).bin))
@echo $(BIN_SIZE)
@echo "Max size is 126296 Bytes."
@if [ ${BIN_SIZE} -gt 126296 ]; then echo "\e[1;33mPayload size exceeds limit!\e[0m"; fi
$(BUILDDIR)/$(TARGET)/$(TARGET).elf: $(OBJS)
$(CC) $(LDFLAGS) -T $(SOURCEDIR)/link.ld $^ -o $@
$(BUILDDIR)/$(TARGET)/%.o: $(SOURCEDIR)/%.c
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@
$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: $(SOURCEDIR)/%.S
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: $(BDKDIR)/%.c
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) $(BDKINC) -c $< -o $@
$(BUILDDIR)/$(TARGET)/%.o: $(BDKDIR)/%.S
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -c $< -o $@

233
bdk/exception_handlers.S Normal file
View file

@ -0,0 +1,233 @@
/*
* 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/>.
*/
/*
* Armv7tdmi Status register.
*
* bit0: Mode 0.
* bit1: Mode 1.
* bit2: Mode 2.
* bit3: Mode 3.
* bit4: Mode 4.
* bit5: Thumb state.
* bit6: FIQ disable.
* bit7: IRQ disable.
* bit8-27: Reserved.
* bit28: Overflow condition.
* bit29: Carry/Borrow/Extend condition.
* bit30: Zero condition.
* bit31: Negative/Less than condition.
*
* M[4:0] | Mode | Visible Thumb-state registers | Visible ARM-state registers
* 10000 | USER | r0r7, SP, LR, PC, CPSR | r0r14, PC, CPSR
* 10001 | FIQ | r0r7, SP_fiq, LR_fiq, PC, CPSR, SPSR_fiq | r0r7, r8_fiqr14_fiq, PC, CPSR, SPSR_fiq
* 10010 | IRQ | r0r7, SP_irq, LR_irq, PC, CPSR, SPSR_irq | r0r12, r13_irq, r14_irq, PC, CPSR, SPSR_irq
* 10011 | SVC | r0r7, SP_svc, LR_svc, PC, CPSR, SPSR_svc | r0r12, r13_svc, r14_svc, PC, CPSR, SPSR_svc
* 10111 | ABRT | r0r7, SP_abt, LR_abt, PC, CPSR, SPSR_abt | r0r12, r13_abt, r14_abt, PC, CPSR, SPSR_abt
* 11011 | UNDF | r0r7, SP_und, LR_und, PC, CPSR, SPSR_und | r0r12, r13_und, r14_und, PC, CPSR, SPSR_und
* 11111 | SYS | r0r7, SP, LR, PC, CPSR | r0r14, PC, CPSR
*/
#define EXCP_EN_ADDR 0x4003FFFC
#define EXCP_TYPE_ADDR 0x4003FFF8
#define EXCP_LR_ADDR 0x4003FFF4
#define EXCP_VEC_BASE 0x6000F000
#define EVP_COP_RESET_VECTOR 0x200
#define EVP_COP_UNDEF_VECTOR 0x204
#define EVP_COP_SWI_VECTOR 0x208
#define EVP_COP_PREFETCH_ABORT_VECTOR 0x20C
#define EVP_COP_DATA_ABORT_VECTOR 0x210
#define EVP_COP_RSVD_VECTOR 0x214
#define EVP_COP_IRQ_VECTOR 0x218
#define EVP_COP_FIQ_VECTOR 0x21C
#define MODE_USR 0x10
#define MODE_FIQ 0x11
#define MODE_IRQ 0x12
#define MODE_SVC 0x13
#define MODE_ABT 0x17
#define MODE_UDF 0x1B
#define MODE_SYS 0x1F
#define MODE_MASK 0x1F
#define FIQ 0x40
#define IRQ 0x80
.section .text._irq_setup
.arm
.extern ipl_main
.type ipl_main, %function
.extern svc_handler
.type svc_handler, %function
.extern irq_handler
.type irq_handler, %function
.extern fiq_setup
.type fiq_setup, %function
.extern fiq_handler
.type fiq_handler, %function
.globl _irq_setup
.type _irq_setup, %function
_irq_setup:
MRS R0, CPSR
BIC R0, R0, #MODE_MASK /* Clear mode bits */
ORR R0, R0, #(MODE_SVC | IRQ | FIQ) /* SUPERVISOR mode, IRQ/FIQ disabled */
MSR CPSR, R0
/* Setup IRQ stack pointer */
MSR CPSR, #(MODE_IRQ | IRQ | FIQ) /* IRQ mode, IRQ/FIQ disabled */
LDR SP, =0x40040000
/* Setup SYS stack pointer */
MSR CPSR, #(MODE_SYS | IRQ | FIQ) /* SYSTEM mode, IRQ/FIQ disabled */
LDR SP, =0x4003FF00 /* Will be changed later to DRAM */
MOV LR, PC
BL setup_vectors
/*BL fiq_setup*/
/* Enable interrupts */
BL irq_enable_cpu_irq_exceptions
B ipl_main
B .
_reset:
LDR R0, =EXCP_EN_ADDR
LDR R1, =0x30505645 /* EVP0 */
STR R1, [R0] /* EVP0 in EXCP_EN_ADDR */
LDR R0, =EXCP_LR_ADDR
MOV R1, LR
STR R1, [R0] /* Save LR in EXCP_LR_ADDR */
LDR R0, =__bss_start
EOR R1, R1, R1
LDR R2, =__bss_end
SUB R2, R2, R0
BL memset
B _irq_setup
_reset_handler:
LDR R0, =EXCP_TYPE_ADDR
LDR R1, =0x545352 /* RST */
STR R1, [R0] /* RST in EXCP_TYPE_ADDR */
B _reset
_undefined_handler:
LDR R0, =EXCP_TYPE_ADDR
LDR R1, =0x464455 /* UDF */
STR R1, [R0] /* UDF in EXCP_TYPE_ADDR */
B _reset
_prefetch_abort_handler:
LDR R0, =EXCP_TYPE_ADDR
LDR R1, =0x54424150 /* PABT */
STR R1, [R0] /* PABT in EXCP_TYPE_ADDR */
B _reset
_data_abort_handler:
LDR R0, =EXCP_TYPE_ADDR
LDR R1, =0x54424144 /* DABT */
STR R1, [R0] /* DABT in EXCP_TYPE_ADDR */
B _reset
.globl irq_enable_cpu_irq_exceptions
.type irq_enable_cpu_irq_exceptions, %function
irq_enable_cpu_irq_exceptions:
MRS R12, CPSR
BIC R12, R12, #(IRQ | FIQ) /* IRQ/FIQ enabled */
MSR CPSR, R12
BX LR
.globl irq_disable_cpu_irq_exceptions
.type irq_disable_cpu_irq_exceptions, %function
irq_disable_cpu_irq_exceptions:
MRS R12, CPSR
ORR R12, R12, #(IRQ | FIQ) /* IRQ/FIQ disabled */
MSR CPSR, R12
BX LR
_irq_handler:
MOV R13, R0 /* Save R0 in R13_IRQ */
SUB R0, LR, #4 /* Put return address in R0_SYS */
MOV LR, R1 /* Save R1 in R14_IRQ (LR) */
MRS R1, SPSR /* Put the SPSR in R1_SYS */
MSR CPSR_c, #(MODE_SYS | IRQ) /* SYSTEM mode, IRQ disabled */
STMFD SP!, {R0, R1} /* SPSR and PC */
STMFD SP!, {R2-R3, R12, LR} /* AAPCS-clobbered registers */
MOV R0, SP /* Make SP_SYS visible to IRQ mode */
SUB SP, SP, #8 /* Make room for stacking R0 and R1 */
MSR CPSR_c, #(MODE_IRQ | IRQ) /* IRQ mode, IRQ disabled */
STMFD R0!, {R13, R14} /* Finish saving the context (R0, R1) */
MSR CPSR_c, #(MODE_SYS | IRQ) /* SYSTEM mode, IRQ disabled */
LDR R12, =irq_handler
MOV LR, PC /* Copy the return address to link register */
BX R12 /* Call the C IRQ handler (ARM/THUMB) */
MSR CPSR_c, #(MODE_SYS | IRQ | FIQ) /* SYSTEM mode, IRQ/FIQ disabled */
MOV R0, SP /* Make SP_SYS visible to IRQ mode */
ADD SP, SP, #32 /* Fake unstacking 8 registers from SP_SYS */
MSR CPSR_c, #(MODE_IRQ | IRQ | FIQ) /* IRQ mode, IRQ/FIQ disabled */
MOV SP, R0 /* Copy SP_SYS to SP_IRQ */
LDR R0, [SP, #28] /* Load the saved SPSR from the stack */
MSR SPSR_cxsf, R0 /* Copy it into SPSR_IRQ */
LDMFD SP, {R0-R3, R12, LR}^ /* Unstack all saved USER/SYSTEM registers */
NOP /* Cant access barked registers immediately */
LDR LR, [SP, #24] /* Load return address from the SYS stack */
MOVS PC, LR /* Return restoring CPSR from SPSR */
_fiq_handler:
BL fiq_handler
setup_vectors:
/* Setup vectors */
LDR R0, =EXCP_VEC_BASE
LDR R1, =_reset_handler
STR R1, [R0, #EVP_COP_RESET_VECTOR]
LDR R1, =_undefined_handler
STR R1, [R0, #EVP_COP_UNDEF_VECTOR]
LDR R1, =_reset_handler
STR R1, [R0, #EVP_COP_SWI_VECTOR]
LDR R1, =_prefetch_abort_handler
STR R1, [R0, #EVP_COP_PREFETCH_ABORT_VECTOR]
LDR R1, =_data_abort_handler
STR R1, [R0, #EVP_COP_DATA_ABORT_VECTOR]
LDR R1, =_reset_handler
STR R1, [R0, #EVP_COP_RSVD_VECTOR]
LDR R1, =_irq_handler
STR R1, [R0, #EVP_COP_IRQ_VECTOR]
LDR R1, =_fiq_handler
STR R1, [R0, #EVP_COP_FIQ_VECTOR]
BX LR

24
bdk/fatfs_cfg.h Normal file
View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 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/>.
*/
#ifndef _FATFS_CFG_H_
#define _FATFS_CFG_H_
#ifdef FFCFG_INC
#include FFCFG_INC
#endif
#endif

View file

@ -18,16 +18,15 @@
#include <string.h>
#include "di.h"
#include "../gfx/gfx.h"
#include "../power/max77620.h"
#include "../power/max7762x.h"
#include "../soc/clock.h"
#include "../soc/gpio.h"
#include "../soc/i2c.h"
#include "../soc/pinmux.h"
#include "../soc/pmc.h"
#include "../soc/t210.h"
#include "../utils/util.h"
#include <power/max77620.h>
#include <power/max7762x.h>
#include <soc/clock.h>
#include <soc/gpio.h>
#include <soc/i2c.h>
#include <soc/pinmux.h>
#include <soc/pmc.h>
#include <soc/t210.h>
#include <utils/util.h>
#include "di.inl"
@ -145,13 +144,13 @@ void display_init()
// Decode Display ID.
_display_id = ((_display_id >> 8) & 0xFF00) | (_display_id & 0xFF);
if ((_display_id & 0xFF) == PANEL_JDI_LPM062M)
_display_id = PANEL_JDI_LPM062M;
if ((_display_id & 0xFF) == PANEL_JDI_XXX062M)
_display_id = PANEL_JDI_XXX062M;
// Initialize display panel.
switch (_display_id)
{
case PANEL_JDI_LPM062M:
case PANEL_JDI_XXX062M:
exec_cfg((u32 *)DSI_BASE, _display_init_config_jdi, 43);
_display_dsi_send_cmd(MIPI_DSI_DCS_SHORT_WRITE, MIPI_DCS_EXIT_SLEEP_MODE, 180000);
break;
@ -264,7 +263,7 @@ void display_end()
// De-initialize display panel.
switch (_display_id)
{
case PANEL_JDI_LPM062M:
case PANEL_JDI_XXX062M:
exec_cfg((u32 *)DSI_BASE, _display_deinit_config_jdi, 22);
break;
case PANEL_AUO_A062TAN01:
@ -337,15 +336,111 @@ void display_color_screen(u32 color)
display_backlight(true);
}
u32 *display_init_framebuffer()
u32 *display_init_framebuffer_pitch()
{
// Sanitize framebuffer area.
memset((u32 *)IPL_FB_ADDRESS, 0, 0x3C0000);
// This configures the framebuffer @ IPL_FB_ADDRESS with a resolution of 1280x720 (line stride 720).
exec_cfg((u32 *)DISPLAY_A_BASE, cfg_display_framebuffer, 32);
exec_cfg((u32 *)DISPLAY_A_BASE, cfg_display_framebuffer_pitch, 32);
usleep(35000);
return (u32 *)IPL_FB_ADDRESS;
}
u32 *display_init_framebuffer_pitch_inv()
{
// This configures the framebuffer @ NYX_FB_ADDRESS with a resolution of 1280x720 (line stride 720).
exec_cfg((u32 *)DISPLAY_A_BASE, cfg_display_framebuffer_pitch_inv, 34);
usleep(35000);
return (u32 *)NYX_FB_ADDRESS;
}
u32 *display_init_framebuffer_block()
{
// This configures the framebuffer @ NYX_FB_ADDRESS with a resolution of 1280x720 (line stride 720).
exec_cfg((u32 *)DISPLAY_A_BASE, cfg_display_framebuffer_block, 34);
usleep(35000);
return (u32 *)NYX_FB_ADDRESS;
}
u32 *display_init_framebuffer_log()
{
// This configures the framebuffer @ LOG_FB_ADDRESS with a resolution of 1280x720 (line stride 720).
exec_cfg((u32 *)DISPLAY_A_BASE, cfg_display_framebuffer_log, 20);
return (u32 *)LOG_FB_ADDRESS;
}
void display_activate_console()
{
DISPLAY_A(_DIREG(DC_CMD_DISPLAY_WINDOW_HEADER)) = WINDOW_D_SELECT; // Select window C.
DISPLAY_A(_DIREG(DC_WIN_WIN_OPTIONS)) = WIN_ENABLE; // Enable window DD.
DISPLAY_A(_DIREG(DC_WIN_POSITION)) = 0xFF80;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_UPDATE | WIN_D_UPDATE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_ACT_REQ | WIN_D_ACT_REQ;
for (u32 i = 0xFF80; i < 0x10000; i++)
{
DISPLAY_A(_DIREG(DC_WIN_POSITION)) = i & 0xFFFF;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_UPDATE | WIN_D_UPDATE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_ACT_REQ | WIN_D_ACT_REQ;
usleep(1000);
}
DISPLAY_A(_DIREG(DC_WIN_POSITION)) = 0;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_UPDATE | WIN_D_UPDATE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_ACT_REQ | WIN_D_ACT_REQ;
}
void display_deactivate_console()
{
DISPLAY_A(_DIREG(DC_CMD_DISPLAY_WINDOW_HEADER)) = WINDOW_D_SELECT; // Select window C.
for (u32 i = 0xFFFF; i > 0xFF7F; i--)
{
DISPLAY_A(_DIREG(DC_WIN_POSITION)) = i & 0xFFFF;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_UPDATE | WIN_D_UPDATE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_ACT_REQ | WIN_D_ACT_REQ;
usleep(500);
}
DISPLAY_A(_DIREG(DC_WIN_POSITION)) = 0;
DISPLAY_A(_DIREG(DC_WIN_WIN_OPTIONS)) = 0; // Disable window DD.
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_UPDATE | WIN_D_UPDATE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_ACT_REQ | WIN_D_ACT_REQ;
}
void display_init_cursor(void *crs_fb, u32 size)
{
// Setup cursor.
DISPLAY_A(_DIREG(DC_DISP_CURSOR_START_ADDR)) = CURSOR_CLIPPING(CURSOR_CLIP_WIN_A) | size | ((u32)crs_fb >> 10);
DISPLAY_A(_DIREG(DC_DISP_BLEND_CURSOR_CONTROL)) =
CURSOR_BLEND_R8G8B8A8 | CURSOR_BLEND_DST_FACTOR(CURSOR_BLEND_K1) | CURSOR_BLEND_SRC_FACTOR(CURSOR_BLEND_K1) | 0xFF;
DISPLAY_A(_DIREG(DC_DISP_DISP_WIN_OPTIONS)) |= CURSOR_ENABLE;
// Arm and activate changes.
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_UPDATE | CURSOR_UPDATE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_ACT_REQ | CURSOR_ACT_REQ;
}
void display_set_pos_cursor(u32 x, u32 y)
{
DISPLAY_A(_DIREG(DC_DISP_CURSOR_POSITION)) = x | (y << 16);
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_UPDATE | CURSOR_UPDATE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_ACT_REQ | CURSOR_ACT_REQ;
}
void display_deinit_cursor()
{
DISPLAY_A(_DIREG(DC_DISP_BLEND_CURSOR_CONTROL)) = 0;
DISPLAY_A(_DIREG(DC_DISP_DISP_WIN_OPTIONS)) &= ~CURSOR_ENABLE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_UPDATE | CURSOR_UPDATE;
DISPLAY_A(_DIREG(DC_CMD_STATE_CONTROL)) = GENERAL_ACT_REQ | CURSOR_ACT_REQ;
}

View file

@ -18,8 +18,8 @@
#ifndef _DI_H_
#define _DI_H_
#include "../../common/memory_map.h"
#include "../utils/types.h"
#include <memory_map.h>
#include <utils/types.h>
/*! Display registers. */
#define _DIREG(reg) ((reg) * 4)
@ -506,7 +506,9 @@
enum
{
PANEL_JDI_LPM062M = 0x10,
PANEL_JDI_XXX062M = 0x10,
PANEL_JDI_LAM062M109A = 0x0910,
PANEL_JDI_LPM062M326A = 0x2610,
PANEL_INL_P062CCA_AZ1 = 0x0F20,
PANEL_AUO_A062TAN01 = 0x0F30,
PANEL_INL_P062CCA_AZ2 = 0x1020,
@ -525,7 +527,12 @@ void display_backlight(bool enable);
void display_backlight_brightness(u32 brightness, u32 step_delay);
/*! Init display in full 1280x720 resolution (B8G8R8A8, line stride 768, framebuffer size = 1280*768*4 bytes). */
u32 *display_init_framebuffer();
u32 *display_init_framebuffer_pitch();
u32 *display_init_framebuffer_pitch_inv();
u32 *display_init_framebuffer_block();
u32 *display_init_framebuffer_log();
void display_activate_console();
void display_deactivate_console();
void display_init_cursor(void *crs_fb, u32 size);
void display_set_pos_cursor(u32 x, u32 y);
void display_deinit_cursor();

View file

@ -559,8 +559,8 @@ static const cfg_op_t cfg_display_one_color[8] = {
{DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_C_DISPLAY} // Continuous display.
};
//Display A config.
static const cfg_op_t cfg_display_framebuffer[32] = {
//Display A config linear pitch.
static const cfg_op_t cfg_display_framebuffer_pitch[32] = {
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT},
@ -568,14 +568,14 @@ static const cfg_op_t cfg_display_framebuffer[32] = {
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_COLOR_DEPTH, WIN_COLOR_DEPTH_B8G8R8A8}, //NX Default: T_A8B8G8R8, WIN_COLOR_DEPTH_R8G8B8A8
{DC_WIN_COLOR_DEPTH, WIN_COLOR_DEPTH_B8G8R8A8}, // NX Default: T_A8B8G8R8, WIN_COLOR_DEPTH_R8G8B8A8.
{DC_WIN_WIN_OPTIONS, 0},
{DC_WIN_WIN_OPTIONS, 0},
{DC_WIN_POSITION, 0}, //(0,0)
{DC_WIN_H_INITIAL_DDA, 0},
{DC_WIN_V_INITIAL_DDA, 0},
{DC_WIN_PRESCALED_SIZE, V_PRESCALED_SIZE(1280) | H_PRESCALED_SIZE(2880)},
{DC_WIN_DDA_INC, V_DDA_INC(0x1000) | H_DDA_INC(0x1000)}, // 1.0x
{DC_WIN_PRESCALED_SIZE, V_PRESCALED_SIZE(1280) | H_PRESCALED_SIZE(720 * 4)},
{DC_WIN_DDA_INC, V_DDA_INC(0x1000) | H_DDA_INC(0x1000)}, // 1.0x.
{DC_WIN_SIZE, V_SIZE(1280) | H_SIZE(720)},
{DC_WIN_LINE_STRIDE, UV_LINE_STRIDE(720 * 2) | LINE_STRIDE(720 * 4)}, // 720*2x720*4 (= 0x600 x 0xC00) bytes, see TRM for alignment requirements.
{DC_WIN_BUFFER_CONTROL, BUFFER_CONTROL_HOST},
@ -594,3 +594,103 @@ static const cfg_op_t cfg_display_framebuffer[32] = {
{DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE},
{DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ}
};
//Display A config linear pitch inverse + Win D support.
static const cfg_op_t cfg_display_framebuffer_pitch_inv[34] = {
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_D_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_COLOR_DEPTH, WIN_COLOR_DEPTH_B8G8R8A8}, // NX Default: T_A8B8G8R8, WIN_COLOR_DEPTH_R8G8B8A8.
{DC_WIN_WIN_OPTIONS, 0},
{DC_WIN_WIN_OPTIONS, 0},
{DC_WIN_POSITION, 0}, //(0,0)
{DC_WIN_H_INITIAL_DDA, 0},
{DC_WIN_V_INITIAL_DDA, 0},
{DC_WIN_PRESCALED_SIZE, V_PRESCALED_SIZE(1280) | H_PRESCALED_SIZE(720 * 4)},
{DC_WIN_DDA_INC, V_DDA_INC(0x1000) | H_DDA_INC(0x1000)}, // 1.0x.
{DC_WIN_SIZE, V_SIZE(1280) | H_SIZE(720)},
{DC_WIN_LINE_STRIDE, UV_LINE_STRIDE(720 * 2) | LINE_STRIDE(720 * 4)}, // 720*2x720*4 (= 0x600 x 0xC00) bytes, see TRM for alignment requirements.
{DC_WIN_BUFFER_CONTROL, BUFFER_CONTROL_HOST},
{DC_WINBUF_SURFACE_KIND, PITCH},
{DC_WINBUF_START_ADDR, NYX_FB_ADDRESS}, // Framebuffer address.
{DC_WINBUF_ADDR_H_OFFSET, 0}, // Linear: 0x383FFC, Block: 0x3813FC.
{DC_WINBUF_ADDR_V_OFFSET, 1279}, // Linear: 1279, Block: 0.
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_WIN_OPTIONS, WIN_ENABLE | V_DIRECTION}, // Enable window AD.
{DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_C_DISPLAY}, // Continuous display.
{DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE},
{DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ}
};
//Display A config block linear.
static const cfg_op_t cfg_display_framebuffer_block[34] = {
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_D_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_C_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_B_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_A_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_COLOR_DEPTH, WIN_COLOR_DEPTH_B8G8R8A8}, // NX Default: T_A8B8G8R8, WIN_COLOR_DEPTH_R8G8B8A8.
{DC_WIN_WIN_OPTIONS, 0},
{DC_WIN_WIN_OPTIONS, 0},
{DC_WIN_POSITION, 0}, //(0,0)
{DC_WIN_H_INITIAL_DDA, 0},
{DC_WIN_V_INITIAL_DDA, 0},
{DC_WIN_PRESCALED_SIZE, V_PRESCALED_SIZE(1280) | H_PRESCALED_SIZE(720 * 4)},
{DC_WIN_DDA_INC, V_DDA_INC(0x1000) | H_DDA_INC(0x1000)}, // 1.0x.
{DC_WIN_SIZE, V_SIZE(1280) | H_SIZE(720)},
{DC_WIN_LINE_STRIDE, UV_LINE_STRIDE(1280 * 2) | LINE_STRIDE(1280 * 4)}, //720*2x720*4 (= 0x600 x 0xC00) bytes, see TRM for alignment requirements.
{DC_WIN_BUFFER_CONTROL, BUFFER_CONTROL_HOST},
{DC_WINBUF_SURFACE_KIND, BLOCK_HEIGHT(4) | BLOCK},
{DC_WINBUF_START_ADDR, NYX_FB_ADDRESS}, // Framebuffer address.
{DC_WINBUF_ADDR_H_OFFSET, 0x3813FC}, // Linear: 0x383FFC, Block: 0x3813FC.
{DC_WINBUF_ADDR_V_OFFSET, 0}, // Linear: 1279, Block: 0.
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_WIN_OPTIONS, 0},
{DC_DISP_DISP_WIN_OPTIONS, DSI_ENABLE},
{DC_WIN_WIN_OPTIONS, WIN_ENABLE | SCAN_COLUMN | H_DIRECTION}, // Enable window AD. | SCAN_COLUMN | H_DIRECTION.
{DC_CMD_DISPLAY_COMMAND, DISP_CTRL_MODE_C_DISPLAY}, // Continuous display.
{DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_A_UPDATE},
{DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_A_ACT_REQ}
};
//Display D config.
static const cfg_op_t cfg_display_framebuffer_log[20] = {
{DC_CMD_DISPLAY_WINDOW_HEADER, WINDOW_D_SELECT},
{DC_WIN_WIN_OPTIONS, 0},
{DC_WIN_COLOR_DEPTH, WIN_COLOR_DEPTH_B8G8R8A8},
{DC_WIN_POSITION, 0}, //(0,0)
{DC_WIN_H_INITIAL_DDA, 0},
{DC_WIN_V_INITIAL_DDA, 0},
{DC_WIN_PRESCALED_SIZE, V_PRESCALED_SIZE(1280) | H_PRESCALED_SIZE(656 * 4)},
{DC_WIN_DDA_INC, V_DDA_INC(0x1000) | H_DDA_INC(0x1000)}, // 1.0x.
{DC_WIN_SIZE, V_SIZE(1280) | H_SIZE(656)},
{DC_WIN_LINE_STRIDE, UV_LINE_STRIDE(656 * 2) | LINE_STRIDE(656 * 4)}, //656*2x656*4 (= 0x600 x 0xC00) bytes, see TRM for alignment requirements.
{DC_WIN_BUFFER_CONTROL, BUFFER_CONTROL_HOST},
{DC_WINBUF_SURFACE_KIND, PITCH},
{DC_WINBUF_START_ADDR, LOG_FB_ADDRESS}, // Framebuffer address.
{DC_WINBUF_ADDR_H_OFFSET, 0},
{DC_WINBUF_ADDR_V_OFFSET, 0},
{DC_WINBUF_BLEND_LAYER_CONTROL, WIN_BLEND_ENABLE | WIN_K1(200)},
{DC_WINBUF_BLEND_MATCH_SELECT, WIN_BLEND_FACT_SRC_COLOR_MATCH_SEL_K1 | WIN_BLEND_FACT_DST_COLOR_MATCH_SEL_NEG_K1},
{DC_WIN_WIN_OPTIONS, 0}, // Enable window DD.
{DC_CMD_STATE_CONTROL, GENERAL_UPDATE | WIN_D_UPDATE},
{DC_CMD_STATE_CONTROL, GENERAL_ACT_REQ | WIN_D_ACT_REQ}
};

24
bdk/gfx_utils.h Normal file
View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 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/>.
*/
#ifndef _GFX_UTILS_H_
#define _GFX_UTILS_H_
#ifdef GFX_INC
#include GFX_INC
#endif
#endif

View file

@ -22,10 +22,10 @@
#include "elfarch.h"
#include "elf.h"
#include "../../utils/types.h"
#include <utils/types.h>
#ifdef DEBUG
#include "../../gfx/gfx.h"
#include <gfx_utils.h>
#define EL_DEBUG(format, ...) \
gfx_printf(format __VA_OPT__(, ) __VA_ARGS__)
#else

View file

@ -18,12 +18,13 @@
#include <string.h>
#include "ianos.h"
#include "../../common/common_module.h"
#include "../gfx/gfx.h"
#include "../libs/elfload/elfload.h"
#include "../mem/heap.h"
#include "../storage/nx_sd.h"
#include "../utils/types.h"
#include "elfload/elfload.h"
#include <module.h>
#include <mem/heap.h>
#include <storage/nx_sd.h>
#include <utils/types.h>
#include <gfx_utils.h>
#define IRAM_LIB_ADDR 0x4002B000
#define DRAM_LIB_ADDR 0xE0000000
@ -36,8 +37,8 @@ void *fileBuf = NULL;
static void _ianos_call_ep(moduleEntrypoint_t entrypoint, void *moduleConfig)
{
bdkParams_t bdkParameters = (bdkParams_t)malloc(sizeof(struct _bdkParams_t));
bdkParameters->gfxCon = &gfx_con;
bdkParameters->gfxCtx = &gfx_ctxt;
bdkParameters->gfxCon = (void *)&gfx_con;
bdkParameters->gfxCtx = (void *)&gfx_ctxt;
bdkParameters->memcpy = (memcpy_t)&memcpy;
bdkParameters->memset = (memset_t)&memset;
bdkParameters->sharedHeap = &_heap;
@ -63,26 +64,20 @@ static bool _ianos_read_cb(el_ctx *ctx, void *dest, size_t numberBytes, size_t o
}
//TODO: Support shared libraries.
uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void *moduleConfig)
uintptr_t ianos_loader(char *path, elfType_t type, void *moduleConfig)
{
el_ctx ctx;
uintptr_t epaddr = 0;
if (sdmount)
{
if (!sd_mount())
goto elfLoadFinalOut;
}
// Read library.
fileBuf = sd_file_read(path, NULL);
if (sdmount)
sd_unmount();
if (!fileBuf)
goto elfLoadFinalOut;
el_ctx ctx;
ctx.pread = _ianos_read_cb;
if (el_init(&ctx))
@ -94,7 +89,6 @@ uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void *moduleCon
case EXEC_ELF:
case AR64_ELF:
elfBuf = (void *)DRAM_LIB_ADDR;
sd_unmount();
break;
default:
elfBuf = malloc(ctx.memsz); // Aligned to 0x10 by default.
@ -123,6 +117,5 @@ elfFreeOut:
fileBuf = NULL;
elfLoadFinalOut:
return epaddr;
}

View file

@ -18,7 +18,7 @@
#ifndef IANOS_H
#define IANOS_H
#include "../utils/types.h"
#include <utils/types.h>
typedef enum
{
@ -29,6 +29,6 @@ typedef enum
KEEP_IN_RAM = (1 << 31) // Shared library mask.
} elfType_t;
uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void* config);
uintptr_t ianos_loader(char *path, elfType_t type, void* config);
#endif

118
bdk/input/als.c Normal file
View file

@ -0,0 +1,118 @@
/*
* Ambient light sensor driver for Nintendo Switch's Rohm BH1730
*
* 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/>.
*/
#include "als.h"
#include <power/max77620.h>
#include <power/max7762x.h>
#include <soc/clock.h>
#include <soc/i2c.h>
#include <soc/pinmux.h>
#include <utils/util.h>
#define HOS_GAIN BH1730_GAIN_64X
#define HOS_ITIME 38
void set_als_cfg(als_table_t *als_val, u8 gain, u8 itime)
{
i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_GAIN_REG), gain);
i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_TIMING_REG), (256 - itime));
als_val->gain = gain;
als_val->itime = itime;
}
void get_als_lux(als_table_t *als_val)
{
u32 data[2];
float pre_gain_lux;
float visible_light;
float ir_light;
float light_ratio;
u8 adc_ready = 0;
u8 retries = 100;
const float als_gain_idx_tbl[4] = { 1.0, 2.0, 64.0, 128.0 };
const float als_norm_res = 100.0;
const float als_multiplier = 3.6;
const float als_tint = 2.7;
// Wait for ADC to prepare new data.
while (!(adc_ready & BH1730_CTL_ADC_VALID) && retries)
{
retries--;
adc_ready = i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_CONTROL_REG));
}
// Get visible and ir light raw data.
data[0] = i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_DATA0LOW_REG)) +
(i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_DATA0HIGH_REG)) << 8);
data[1] = i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_DATA1LOW_REG)) +
(i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_DATA1HIGH_REG)) << 8);
als_val->over_limit = data[0] > 65534 || data[1] > 65534;
als_val->vi_light = data[0];
als_val->ir_light = data[1];
if (!data[0] || !retries)
{
als_val->lux = 0.0;
return;
}
visible_light = (float)data[0];
ir_light = (float)data[1];
light_ratio = (float)data[1] / (float)data[0];
// The following are specific to the light filter Switch uses.
if (light_ratio < 0.5)
pre_gain_lux = visible_light * 5.002 - ir_light * 7.502;
else if (light_ratio < 0.754)
pre_gain_lux = visible_light * 2.250 - ir_light * 2.000;
else if (light_ratio < 1.029)
pre_gain_lux = visible_light * 1.999 - ir_light * 1.667;
else if (light_ratio < 1.373)
pre_gain_lux = visible_light * 0.884 - ir_light * 0.583;
else if (light_ratio < 1.879)
pre_gain_lux = visible_light * 0.309 - ir_light * 0.165;
else pre_gain_lux = 0.0;
als_val->lux = (pre_gain_lux / als_gain_idx_tbl[als_val->gain]) * (als_norm_res / ((float)als_val->itime * als_tint)) * als_multiplier;
}
u8 als_init(als_table_t *als_val)
{
pinmux_config_i2c(I2C_2);
clock_enable_i2c(I2C_2);
i2c_init(I2C_2);
max77620_regulator_set_volt_and_flags(REGULATOR_LDO6, 2900000, MAX77620_POWER_MODE_NORMAL);
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_LDO6_CFG2, 0xD8 | MAX77620_LDO_CFG2_ADE_MASK);
u8 id = i2c_recv_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(0x12));
i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_SPEC(BH1730_SPECCMD_RESET), 0);
i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_GAIN_REG), HOS_GAIN);
i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_TIMING_REG), (256 - HOS_ITIME));
i2c_send_byte(I2C_2, BH1730_I2C_ADDR, BH1730_ADDR(BH1730_CONTROL_REG), BH1730_CTL_POWER_ON | BH1730_CTL_ADC_EN);
als_val->gain = HOS_GAIN;
als_val->itime = HOS_ITIME;
return id;
}

65
bdk/input/als.h Normal file
View file

@ -0,0 +1,65 @@
/*
* Ambient light sensor driver for Nintendo Switch's Rohm BH1730
*
* 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 __ALS_H_
#define __ALS_H_
#include <utils/types.h>
#define BH1730_I2C_ADDR 0x29
#define BH1730_CMD_MAGIC 0x80
#define BH1730_CMD_SETADDR 0x00
#define BH1730_CMD_SPECCMD 0x60
#define BH1730_SPECCMD_RESET 0x4
#define BH1730_CONTROL_REG 0x00
#define BH1730_CTL_ADC_VALID 0x10
#define BH1730_CTL_ONE_TIME 0x08
#define BH1730_CTL_DAT0_ONLY 0x04
#define BH1730_CTL_ADC_EN 0x02
#define BH1730_CTL_POWER_ON 0x01
#define BH1730_TIMING_REG 0x01
#define BH1730_GAIN_REG 0x07
#define BH1730_GAIN_1X 0x00
#define BH1730_GAIN_2X 0x01
#define BH1730_GAIN_64X 0x02
#define BH1730_GAIN_128X 0x03
#define BH1730_DATA0LOW_REG 0x14
#define BH1730_DATA0HIGH_REG 0x15
#define BH1730_DATA1LOW_REG 0x16
#define BH1730_DATA1HIGH_REG 0x17
#define BH1730_ADDR(reg) (BH1730_CMD_MAGIC | BH1730_CMD_SETADDR | reg)
#define BH1730_SPEC(cmd) (BH1730_CMD_MAGIC | BH1730_CMD_SPECCMD | cmd)
typedef struct _als_table_t
{
float lux;
bool over_limit;
u32 vi_light;
u32 ir_light;
u8 gain;
u8 itime;
} als_table_t;
void set_als_cfg(als_table_t *als_val, u8 gain, u8 itime);
void get_als_lux(als_table_t *als_val);
u8 als_init(als_table_t *als_val);
#endif /* __ALS_H_ */

872
bdk/input/joycon.c Normal file
View file

@ -0,0 +1,872 @@
/*
* Joy-Con UART driver for Nintendo Switch
*
* 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 <string.h>
#include "joycon.h"
#include <gfx_utils.h>
#include <power/max17050.h>
#include <power/regulator_5v.h>
#include <soc/bpmp.h>
#include <soc/clock.h>
#include <soc/gpio.h>
#include <soc/pinmux.h>
#include <soc/uart.h>
#include <soc/t210.h>
#include <utils/util.h>
// For disabling driver when logging is enabled.
#include <libs/lv_conf.h>
#define JC_WIRED_CMD 0x91
#define JC_WIRED_HID 0x92
#define JC_WIRED_INIT_REPLY 0x94
#define JC_INIT_HANDSHAKE 0xA5
#define JC_WIRED_CMD_MAC 0x01
#define JC_WIRED_CMD_10 0x10
#define JC_HID_OUTPUT_RPT 0x01
#define JC_HID_RUMBLE_RPT 0x10
#define JC_HID_INPUT_RPT 0x30
#define JC_HID_SUBMCD_RPT 0x21
#define JC_HID_SUBCMD_HCI_STATE 0x06
#define HCI_STATE_SLEEP 0x00
#define HCI_STATE_RECONNECT 0x01
#define HCI_STATE_PAIR 0x02
#define HCI_STATE_HOME 0x04
#define JC_HID_SUBCMD_SPI_READ 0x10
#define SPI_READ_OFFSET 0x20
#define JC_HID_SUBCMD_RUMBLE_CTL 0x48
#define JC_HID_SUBCMD_SND_RUMBLE 0xFF
#define JC_BTN_MASK_L 0xFF2900 // 0xFFE900: with charge status.
#define JC_BTN_MASK_R 0x76FF
#define JC_ID_L 1
#define JC_ID_R 2
enum
{
JC_BATT_EMTPY = 0,
JC_BATT_CRIT = 2,
JC_BATT_LOW = 4,
JC_BATT_MID = 6,
JC_BATT_FULL = 8
};
static const u8 init_jc[] = {
0xA1, 0xA2, 0xA3, 0xA4
};
static const u8 init_handshake[] = {
0x19, 0x01, 0x03, 0x07, 0x00, // Uart header.
JC_INIT_HANDSHAKE, 0x02, // Wired cmd and wired subcmd.
0x01, 0x7E, 0x00, 0x00, 0x00 // Wired subcmd data.
};
static const u8 init_get_info[] = {
0x19, 0x01, 0x03, 0x07, 0x00, // Uart header.
JC_WIRED_CMD, JC_WIRED_CMD_MAC, // Wired cmd and subcmd.
0x00, 0x00, 0x00, 0x00, 0x24 // Wired subcmd data.
};
static const u8 init_finilize[] = {
0x19, 0x01, 0x03, 0x07, 0x00, // Uart header.
JC_WIRED_CMD, JC_WIRED_CMD_10, // Wired cmd and subcmd.
0x00, 0x00, 0x00, 0x00, 0x3D // Wired subcmd data.
};
static const u8 nx_pad_status[] = {
0x19, 0x01, 0x03, 0x08, 0x00, // Uart header.
JC_WIRED_HID, 0x00, // Wired cmd and hid cmd.
0x01, 0x00, 0x00, 0x69, 0x2D, 0x1F // hid data.
};
typedef struct _jc_uart_hdr_t
{
u8 magic[3];
u8 total_size_lsb;
u8 total_size_msb;
} jc_uart_hdr_t;
typedef struct _jc_wired_hdr_t
{
jc_uart_hdr_t uart_hdr;
u8 cmd;
u8 data[5];
u8 crc;
u8 payload[];
} jc_wired_hdr_t;
typedef struct _jc_hid_out_rpt_t
{
u8 cmd;
u8 pkt_id;
u8 rumble[8];
u8 subcmd;
u8 subcmd_data[];
} jc_hid_out_rpt_t;
typedef struct _jc_hid_out_spi_read_t
{
u32 addr;
u8 size;
} jc_hid_out_spi_read_t;
typedef struct _jc_hid_in_rpt_t
{
u8 cmd;
u8 pkt_id;
u8 conn_info:4;
u8 batt_info:4;
u8 btn_right;
u8 btn_shared;
u8 btn_left;
u8 stick_h_left;
u8 stick_m_left;
u8 stick_v_left;
u8 stick_h_right;
u8 stick_m_right;
u8 stick_v_right;
u8 vib_decider;
u8 submcd_ack;
u8 subcmd;
u8 subcmd_data[];
} jc_hid_in_rpt_t;
typedef struct _jc_hid_in_spi_read_t
{
u32 addr;
u8 size;
u8 data[];
} jc_hid_in_spi_read_t;
typedef struct _jc_hid_in_pair_data_t
{
u8 magic;
u8 size;
u16 checksum;
u8 mac[6];
u8 ltk[16];
u8 pad0[10];
u8 bt_caps; // bit3: Secure conn supported host, bit5: Paired to TBFC supported host, bit6: iTBFC page supported
u8 pad1;
} jc_hid_in_pair_data_t;
typedef struct _joycon_ctxt_t
{
u8 buf[0x100]; //FIXME: If heap is used, dumping breaks.
u8 uart;
u8 type;
u8 mac[6];
u32 hw_init_done;
u32 last_received_time;
u32 last_status_req_time;
u8 rumble_sent;
u8 connected;
} joycon_ctxt_t;
static joycon_ctxt_t jc_l;
static joycon_ctxt_t jc_r;
static bool jc_init_done = false;
static u32 hid_pkt_inc = 0;
static jc_gamepad_rpt_t jc_gamepad;
void jc_power_supply(u8 uart, bool enable);
void joycon_send_raw(u8 uart_port, const u8 *buf, u16 size)
{
uart_send(uart_port, buf, size);
uart_wait_idle(uart_port, UART_TX_IDLE);
}
static u16 jc_packet_add_uart_hdr(jc_wired_hdr_t *out, u8 wired_cmd, u8 *data, u16 size)
{
out->uart_hdr.magic[0] = 0x19;
out->uart_hdr.magic[1] = 0x01;
out->uart_hdr.magic[2] = 0x3;
out->uart_hdr.total_size_lsb = 7;
out->uart_hdr.total_size_msb = 0;
out->cmd = wired_cmd;
if (data)
memcpy(out->data, data, size);
out->crc = 0; // wired crc8ccit can be skipped.
return sizeof(jc_wired_hdr_t);
}
static u16 jc_hid_output_rpt_craft(jc_wired_hdr_t *rpt, u8 *payload, u16 size)
{
u16 pkt_size = jc_packet_add_uart_hdr(rpt, JC_WIRED_HID, NULL, 0);
pkt_size += size;
rpt->uart_hdr.total_size_lsb += size;
rpt->data[0] = size >> 8;
rpt->data[1] = size & 0xFF;
if (payload)
memcpy(rpt->payload, payload, size);
return pkt_size;
}
void jc_send_hid_output_rpt(u8 uart, u8 *payload, u16 size)
{
u8 rpt[0x50];
memset(rpt, 0, sizeof(rpt));
u32 rpt_size = jc_hid_output_rpt_craft((jc_wired_hdr_t *)rpt, payload, size);
joycon_send_raw(uart, rpt, rpt_size);
}
static u8 jc_hid_pkt_id_incr()
{
u8 curr_id = hid_pkt_inc;
hid_pkt_inc++;
return (curr_id & 0xF);
}
void jc_send_hid_cmd(u8 uart, u8 subcmd, u8 *data, u16 size)
{
u8 temp[0x30];
u8 rumble_neutral[8] = {0x00, 0x01, 0x40, 0x40, 0x00, 0x01, 0x40, 0x40};
u8 rumble_init[8] = {0xc2, 0xc8, 0x03, 0x72, 0xc2, 0xc8, 0x03, 0x72};
memset(temp, 0, sizeof(temp));
jc_hid_out_rpt_t *hid_pkt = (jc_hid_out_rpt_t *)temp;
memcpy(hid_pkt->rumble, rumble_neutral, sizeof(rumble_neutral));
if (subcmd == JC_HID_SUBCMD_SND_RUMBLE)
{
bool send_r_rumble = jc_r.connected && !jc_r.rumble_sent;
bool send_l_rumble = jc_l.connected && !jc_l.rumble_sent;
// Enable rumble.
hid_pkt->cmd = JC_HID_OUTPUT_RPT;
hid_pkt->pkt_id = jc_hid_pkt_id_incr();
hid_pkt->subcmd = JC_HID_SUBCMD_RUMBLE_CTL;
hid_pkt->subcmd_data[0] = 1;
if (send_r_rumble)
jc_send_hid_output_rpt(UART_B, (u8 *)hid_pkt, 0x10);
if (send_l_rumble)
jc_send_hid_output_rpt(UART_C, (u8 *)hid_pkt, 0x10);
// Send rumble.
hid_pkt->cmd = JC_HID_RUMBLE_RPT;
hid_pkt->pkt_id = jc_hid_pkt_id_incr();
memcpy(hid_pkt->rumble, rumble_init, sizeof(rumble_init));
if (send_r_rumble)
jc_send_hid_output_rpt(UART_B, (u8 *)hid_pkt, 10);
if (send_l_rumble)
jc_send_hid_output_rpt(UART_C, (u8 *)hid_pkt, 10);
msleep(15);
// Disable rumble.
hid_pkt->cmd = JC_HID_OUTPUT_RPT;
hid_pkt->pkt_id = jc_hid_pkt_id_incr();
hid_pkt->subcmd = JC_HID_SUBCMD_RUMBLE_CTL;
hid_pkt->subcmd_data[0] = 0;
memcpy(hid_pkt->rumble, rumble_neutral, sizeof(rumble_neutral));
if (send_r_rumble)
jc_send_hid_output_rpt(UART_B, (u8 *)hid_pkt, 0x10);
if (send_l_rumble)
jc_send_hid_output_rpt(UART_C, (u8 *)hid_pkt, 0x10);
}
else
{
hid_pkt->cmd = JC_HID_OUTPUT_RPT;
hid_pkt->pkt_id = jc_hid_pkt_id_incr();
hid_pkt->subcmd = subcmd;
if (data)
memcpy(hid_pkt->subcmd_data, data, size);
u8 pkt_size = sizeof(jc_hid_out_rpt_t) + size;
jc_send_hid_output_rpt(uart, (u8 *)hid_pkt, pkt_size);
}
}
static void jc_charging_decider(u8 batt, u8 uart)
{
u32 system_batt_enough = max17050_get_cached_batt_volt() > 4000;
// Power supply control based on battery levels and charging.
if ((batt >> 1 << 1) < JC_BATT_LOW) // Level without checking charging.
jc_power_supply(uart, true);
else if (batt > (system_batt_enough ? JC_BATT_FULL : JC_BATT_MID)) // Addresses the charging bit.
jc_power_supply(uart, false);
}
static void jc_parse_wired_hid(joycon_ctxt_t *jc, const u8* packet, u32 size)
{
u32 btn_tmp;
jc_hid_in_rpt_t *hid_pkt = (jc_hid_in_rpt_t *)packet;
switch (hid_pkt->cmd)
{
case JC_HID_INPUT_RPT:
btn_tmp = hid_pkt->btn_right | hid_pkt->btn_shared << 8 | hid_pkt->btn_left << 16;
if (jc->type & JC_ID_L)
{
jc_gamepad.buttons &= ~JC_BTN_MASK_L;
jc_gamepad.buttons |= (btn_tmp & JC_BTN_MASK_L);
jc_gamepad.lstick_x = hid_pkt->stick_h_left | ((hid_pkt->stick_m_left & 0xF) << 8);
jc_gamepad.lstick_y = (hid_pkt->stick_m_left >> 4) | (hid_pkt->stick_v_left << 4);
jc_gamepad.batt_info_l = hid_pkt->batt_info;
}
else if (jc->type & JC_ID_R)
{
jc_gamepad.buttons &= ~JC_BTN_MASK_R;
jc_gamepad.buttons |= (btn_tmp & JC_BTN_MASK_R);
jc_gamepad.rstick_x = hid_pkt->stick_h_right | ((hid_pkt->stick_m_right & 0xF) << 8);
jc_gamepad.rstick_y = (hid_pkt->stick_m_right >> 4) | (hid_pkt->stick_v_right << 4);
jc_gamepad.batt_info_r = hid_pkt->batt_info;
}
jc_gamepad.conn_l = jc_l.connected;
jc_gamepad.conn_r = jc_r.connected;
jc_charging_decider(hid_pkt->batt_info, jc->uart);
break;
case JC_HID_SUBMCD_RPT:
if (hid_pkt->subcmd == JC_HID_SUBCMD_SPI_READ)
{
jc_bt_conn_t *bt_conn;
if (jc->type & JC_ID_L)
bt_conn = &jc_gamepad.bt_conn_l;
else
bt_conn = &jc_gamepad.bt_conn_r;
jc_hid_in_spi_read_t *spi_info = (jc_hid_in_spi_read_t *)hid_pkt->subcmd_data;
jc_hid_in_pair_data_t *pair_data = (jc_hid_in_pair_data_t *)spi_info->data;
// Check if we reply is pairing info.
if (spi_info->size == 0x1A && pair_data->magic == 0x95 && pair_data->size == 0x22)
{
bt_conn->type = jc->type;
memcpy(bt_conn->mac, jc->mac, 6);
memcpy(bt_conn->host_mac, pair_data->mac, 6);
for (u32 i = 16; i > 0; i--)
bt_conn->ltk[16 - i] = pair_data->ltk[i - 1];
}
}
break;
default:
break;
}
jc->last_received_time = get_tmr_ms();
}
static void jc_parse_wired_init(joycon_ctxt_t *jc, const u8* data, u32 size)
{
switch (data[0])
{
case JC_WIRED_CMD_MAC:
for (int i = 12; i > 6; i--)
jc->mac[12 - i] = data[i];
jc->type = data[6];
jc->connected = true;
default:
break;
}
}
static void jc_uart_pkt_parse(joycon_ctxt_t *jc, const u8* packet, size_t size)
{
jc_wired_hdr_t *pkt = (jc_wired_hdr_t *)packet;
switch (pkt->cmd)
{
case JC_WIRED_HID:
jc_parse_wired_hid(jc, pkt->payload, (pkt->data[0] << 8) | pkt->data[1]);
break;
case JC_WIRED_INIT_REPLY:
jc_parse_wired_init(jc, pkt->data, size - sizeof(jc_uart_hdr_t) - 1);
break;
default:
break;
}
}
static void jc_rcv_pkt(joycon_ctxt_t *jc)
{
if (gpio_read(GPIO_PORT_E, GPIO_PIN_6) && jc->uart == UART_C)
return;
else if (gpio_read(GPIO_PORT_H, GPIO_PIN_6) && jc->uart == UART_B)
return;
// Check if device stopped sending data.
u32 uart_irq = uart_get_IIR(jc->uart);
if ((uart_irq & 0x8) != 0x8)
return;
u32 len = uart_recv(jc->uart, (u8 *)jc->buf, 0x100);
// Check valid size and uart reply magic.
if (len > 7 && !memcmp(jc->buf, "\x19\x81\x03", 3))
{
jc_wired_hdr_t *pkt = (jc_wired_hdr_t *)(jc->buf);
jc_uart_pkt_parse(jc, jc->buf, pkt->uart_hdr.total_size_lsb + sizeof(jc_uart_hdr_t));
}
}
static bool jc_send_init_rumble(joycon_ctxt_t *jc)
{
// Send init rumble or request nx pad status report.
if ((jc_r.connected && !jc_r.rumble_sent) || (jc_l.connected && !jc_l.rumble_sent))
{
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
jc_send_hid_cmd(jc->uart, JC_HID_SUBCMD_SND_RUMBLE, NULL, 0);
if (jc_l.connected)
jc_l.rumble_sent = true;
if (jc_r.connected)
jc_r.rumble_sent = true;
if (jc->uart != UART_B)
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_GPIO);
else
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_GPIO);
return 1;
}
return 0;
}
static void jc_req_nx_pad_status(joycon_ctxt_t *jc)
{
bool sent_rumble = jc_send_init_rumble(jc);
if (sent_rumble)
return;
if (jc->last_status_req_time > get_tmr_ms() || !jc->connected)
return;
// Turn off Joy-Con detect.
if (jc->uart == UART_B)
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
else
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
joycon_send_raw(jc->uart, nx_pad_status, sizeof(nx_pad_status));
// Turn Joy-Con detect on.
if (jc->uart == UART_B)
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_GPIO);
else
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_GPIO);
jc->last_status_req_time = get_tmr_ms() + 15;
}
static bool _jc_validate_pairing_info(u8 *buf, bool *is_hos)
{
u8 crc = 0;
for (u32 i = 0; i < 0x22; i++)
crc += buf[4 + i];
crc += 0x68; // Host is Switch.
if ((crc ^ 0x55) == buf[2])
*is_hos = true;
crc -= 0x68;
crc += 0x08; // Host is PC.
if (*is_hos || (crc ^ 0x55) == buf[2])
return true;
return false;
}
jc_gamepad_rpt_t *jc_get_bt_pairing_info(bool *is_l_hos, bool *is_r_hos)
{
u8 retries;
jc_bt_conn_t *bt_conn;
bt_conn = &jc_gamepad.bt_conn_l;
memset(bt_conn->host_mac, 0, 6);
memset(bt_conn->ltk, 0, 16);
bt_conn = &jc_gamepad.bt_conn_r;
memset(bt_conn->host_mac, 0, 6);
memset(bt_conn->ltk, 0, 16);
while (jc_l.last_status_req_time > get_tmr_ms())
{
jc_rcv_pkt(&jc_r);
jc_rcv_pkt(&jc_l);
}
jc_hid_in_spi_read_t subcmd_data_l;
subcmd_data_l.addr = 0x2000;
subcmd_data_l.size = 0x1A;
jc_hid_in_spi_read_t subcmd_data_r;
subcmd_data_r.addr = 0x2000;
subcmd_data_r.size = 0x1A;
// Turn off Joy-Con detect.
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
bool jc_r_found = jc_r.connected ? false : true;
bool jc_l_found = jc_l.connected ? false : true;
u32 total_retries = 10;
retry:
retries = 10;
while (retries)
{
u32 time_now = get_tmr_ms();
if ((!jc_l_found && jc_l.last_status_req_time < time_now) || (!jc_r_found && jc_r.last_status_req_time < time_now))
{
if (!jc_l_found)
{
jc_send_hid_cmd(jc_l.uart, JC_HID_SUBCMD_SPI_READ, (u8 *)&subcmd_data_l, 5);
jc_l.last_status_req_time = get_tmr_ms() + 15;
}
if (!jc_r_found)
{
jc_send_hid_cmd(jc_r.uart, JC_HID_SUBCMD_SPI_READ, (u8 *)&subcmd_data_r, 5);
jc_r.last_status_req_time = get_tmr_ms() + 15;
}
retries--;
}
if (!jc_l_found)
{
memset(jc_l.buf, 0, 0x100);
jc_rcv_pkt(&jc_l);
bool is_hos = false;
if (_jc_validate_pairing_info(&jc_l.buf[SPI_READ_OFFSET], &is_hos))
{
bool is_active = jc_l.buf[SPI_READ_OFFSET] == 0x95;
if (!is_active)
subcmd_data_l.addr += 0x26; // Get next slot.
else
jc_l_found = true; // Entry is active.
if (jc_l_found && is_hos)
*is_l_hos = true;
}
}
if (!jc_r_found)
{
memset(jc_r.buf, 0, 0x100);
jc_rcv_pkt(&jc_r);
bool is_hos = false;
if (_jc_validate_pairing_info(&jc_r.buf[SPI_READ_OFFSET], &is_hos))
{
bool is_active = jc_r.buf[SPI_READ_OFFSET] == 0x95;
if (!is_active)
subcmd_data_r.addr += 0x26; // Get next slot.
else
jc_r_found = true; // Entry is active.
if (jc_r_found && is_hos)
*is_r_hos = true;
}
}
if (jc_l_found && jc_r_found)
break;
}
if (!jc_l_found || !jc_r_found)
{
if (total_retries)
{
total_retries--;
goto retry;
}
if (!jc_l_found)
{
bt_conn = &jc_gamepad.bt_conn_l;
memset(bt_conn->host_mac, 0, 6);
memset(bt_conn->ltk, 0, 16);
}
if (!jc_r_found)
{
bt_conn = &jc_gamepad.bt_conn_r;
memset(bt_conn->host_mac, 0, 6);
memset(bt_conn->ltk, 0, 16);
}
}
// Turn Joy-Con detect on.
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_GPIO);
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_GPIO);
return &jc_gamepad;
}
void jc_deinit()
{
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
u8 data = HCI_STATE_SLEEP;
if (jc_r.connected)
{
jc_send_hid_cmd(UART_B, JC_HID_SUBCMD_HCI_STATE, &data, 1);
jc_rcv_pkt(&jc_r);
}
if (jc_l.connected)
{
jc_send_hid_cmd(UART_C, JC_HID_SUBCMD_HCI_STATE, &data, 1);
jc_rcv_pkt(&jc_l);
}
jc_power_supply(UART_B, false);
jc_power_supply(UART_C, false);
}
static void jc_init_conn(joycon_ctxt_t *jc)
{
if (((u32)get_tmr_ms() - jc->last_received_time) > 1000)
{
jc_power_supply(jc->uart, true);
// Turn off Joy-Con detect.
if (jc->uart == UART_B)
{
jc_gamepad.buttons &= ~JC_BTN_MASK_R;
jc_gamepad.conn_r = false;
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
}
else
{
jc_gamepad.buttons &= ~JC_BTN_MASK_L;
jc_gamepad.conn_l = false;
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
}
uart_init(jc->uart, 1000000);
uart_invert(jc->uart, true, UART_INVERT_TXD);
uart_set_IIR(jc->uart);
joycon_send_raw(jc->uart, init_jc, 4);
joycon_send_raw(jc->uart, init_handshake, sizeof(init_handshake));
msleep(5);
jc_rcv_pkt(jc);
joycon_send_raw(jc->uart, init_get_info, sizeof(init_get_info));
msleep(5);
jc_rcv_pkt(jc);
joycon_send_raw(jc->uart, init_finilize, sizeof(init_finilize));
msleep(5);
jc_rcv_pkt(jc);
// Turn Joy-Con detect on.
if (jc->uart == UART_B)
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_GPIO);
else
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_GPIO);
jc->last_received_time = get_tmr_ms();
if (jc->connected)
jc_power_supply(jc->uart, false);
}
}
static void jc_conn_check()
{
// Check if a Joy-Con was disconnected.
if (gpio_read(GPIO_PORT_E, GPIO_PIN_6))
{
jc_power_supply(UART_C, false);
hid_pkt_inc = 0;
jc_l.connected = false;
jc_l.rumble_sent = false;
jc_gamepad.buttons &= ~JC_BTN_MASK_L;
jc_gamepad.conn_l = false;
jc_gamepad.batt_info_l = 0;
jc_gamepad.bt_conn_l.type = 0;
}
if (gpio_read(GPIO_PORT_H, GPIO_PIN_6))
{
jc_power_supply(UART_B, false);
hid_pkt_inc = 0;
jc_r.connected = false;
jc_r.rumble_sent = false;
jc_gamepad.buttons &= ~JC_BTN_MASK_R;
jc_gamepad.conn_r = false;
jc_gamepad.batt_info_r = 0;
jc_gamepad.bt_conn_r.type = 0;
}
}
void jc_power_supply(u8 uart, bool enable)
{
if (enable)
{
if (regulator_get_5v_dev_enabled(1 << uart))
return;
regulator_enable_5v(1 << uart);
if (jc_init_done)
{
if (uart == UART_C)
gpio_write(GPIO_PORT_CC, GPIO_PIN_3, GPIO_HIGH);
else
gpio_write(GPIO_PORT_K, GPIO_PIN_3, GPIO_HIGH);
return;
}
if (uart == UART_C)
{
// Joy-Con(L) Charge Detect.
PINMUX_AUX(PINMUX_AUX_SPDIF_IN) = PINMUX_PULL_DOWN | 1;
gpio_config(GPIO_PORT_CC, GPIO_PIN_3, GPIO_MODE_GPIO);
gpio_output_enable(GPIO_PORT_CC, GPIO_PIN_3, GPIO_OUTPUT_ENABLE);
gpio_write(GPIO_PORT_CC, GPIO_PIN_3, GPIO_HIGH);
}
else
{
// Joy-Con(R) Charge Detect.
PINMUX_AUX(PINMUX_AUX_GPIO_PK3) = PINMUX_DRIVE_4X | PINMUX_PULL_DOWN | 2;
gpio_config(GPIO_PORT_K, GPIO_PIN_3, GPIO_MODE_GPIO);
gpio_output_enable(GPIO_PORT_K, GPIO_PIN_3, GPIO_OUTPUT_ENABLE);
gpio_write(GPIO_PORT_K, GPIO_PIN_3, GPIO_HIGH);
}
}
else
{
if (!regulator_get_5v_dev_enabled(1 << uart))
return;
regulator_disable_5v(1 << uart);
if (uart == UART_C)
gpio_write(GPIO_PORT_CC, GPIO_PIN_3, GPIO_LOW);
else
gpio_write(GPIO_PORT_K, GPIO_PIN_3, GPIO_LOW);
}
}
void jc_init_hw()
{
jc_l.uart = UART_C;
jc_r.uart = UART_B;
#if (LV_LOG_PRINTF != 1)
jc_power_supply(UART_C, true);
jc_power_supply(UART_B, true);
// Joy-Con (R) IsAttached.
PINMUX_AUX(PINMUX_AUX_GPIO_PH6) = PINMUX_INPUT_ENABLE | PINMUX_TRISTATE;
gpio_config(GPIO_PORT_H, GPIO_PIN_6, GPIO_MODE_GPIO);
// Joy-Con (L) IsAttached.
PINMUX_AUX(PINMUX_AUX_GPIO_PE6) = PINMUX_INPUT_ENABLE | PINMUX_TRISTATE;
gpio_config(GPIO_PORT_E, GPIO_PIN_6, GPIO_MODE_GPIO);
// Configure pinmuxing for UART B and C.
pinmux_config_uart(UART_B);
pinmux_config_uart(UART_C);
// Ease the stress to APB.
bpmp_clk_rate_set(BPMP_CLK_NORMAL);
// Enable UART B and C clocks.
clock_enable_uart(UART_B);
clock_enable_uart(UART_C);
// Restore OC.
bpmp_clk_rate_set(BPMP_CLK_DEFAULT_BOOST);
// Turn Joy-Con detect on.
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_GPIO);
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_GPIO);
jc_init_done = true;
#endif
}
jc_gamepad_rpt_t *joycon_poll()
{
if (!jc_init_done)
return NULL;
if (!gpio_read(GPIO_PORT_H, GPIO_PIN_6))
jc_init_conn(&jc_r);
if (!gpio_read(GPIO_PORT_E, GPIO_PIN_6))
jc_init_conn(&jc_l);
if (!gpio_read(GPIO_PORT_H, GPIO_PIN_6))
jc_req_nx_pad_status(&jc_r);
if (!gpio_read(GPIO_PORT_E, GPIO_PIN_6))
jc_req_nx_pad_status(&jc_l);
if (!gpio_read(GPIO_PORT_H, GPIO_PIN_6))
jc_rcv_pkt(&jc_r);
if (!gpio_read(GPIO_PORT_E, GPIO_PIN_6))
jc_rcv_pkt(&jc_l);
jc_conn_check();
return &jc_gamepad;
}

98
bdk/input/joycon.h Normal file
View file

@ -0,0 +1,98 @@
/*
* Ambient light sensor driver for Nintendo Switch's Rohm BH1730
*
* 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 __JOYCON_H_
#define __JOYCON_H_
#include <utils/types.h>
#define JC_BTNS_DIRECTION_PAD 0xF0000
#define JC_BTNS_PREV_NEXT 0x800080
#define JC_BTNS_ENTER 0x400008
#define JC_BTNS_ESC 0x4
#define JC_BTNS_ALL (JC_BTNS_PREV_NEXT | JC_BTNS_ENTER | JC_BTNS_DIRECTION_PAD | JC_BTNS_ESC)
typedef struct _jc_bt_conn_t
{
u8 type;
u8 mac[6];
u8 host_mac[6];
u8 ltk[16];
} jc_bt_conn_t;
typedef struct _jc_gamepad_rpt_t
{
union
{
struct
{
// Joy-Con (R).
u32 y:1;
u32 x:1;
u32 b:1;
u32 a:1;
u32 sr_r:1;
u32 sl_r:1;
u32 r:1;
u32 zr:1;
// Shared
u32 minus:1;
u32 plus:1;
u32 r3:1;
u32 l3:1;
u32 home:1;
u32 cap:1;
u32 pad:1;
u32 wired:1;
// Joy-Con (L).
u32 down:1;
u32 up:1;
u32 right:1;
u32 left:1;
u32 sr_l:1;
u32 sl_l:1;
u32 l:1;
u32 zl:1;
};
u32 buttons;
};
u16 lstick_x;
u16 lstick_y;
u16 rstick_x;
u16 rstick_y;
bool center_stick_l;
bool center_stick_r;
bool conn_l;
bool conn_r;
u8 batt_info_l;
u8 batt_info_r;
jc_bt_conn_t bt_conn_l;
jc_bt_conn_t bt_conn_r;
} jc_gamepad_rpt_t;
void jc_power_supply(u8 uart, bool enable);
void jc_init_hw();
void jc_deinit();
jc_gamepad_rpt_t *joycon_poll();
jc_gamepad_rpt_t *jc_get_bt_pairing_info(bool *is_l_hos, bool *is_r_hos);
#endif

422
bdk/input/touch.c Normal file
View file

@ -0,0 +1,422 @@
/*
* Touch driver for Nintendo Switch's STM FingerTip S (4CD60D) touch controller
*
* Copyright (c) 2018 langerhans
* Copyright (c) 2018-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/>.
*/
#include <string.h>
#include <soc/clock.h>
#include <soc/i2c.h>
#include <soc/pinmux.h>
#include <power/max7762x.h>
#include <power/max77620.h>
#include <soc/gpio.h>
#include <soc/t210.h>
#include <utils/btn.h>
#include <utils/util.h>
#include "touch.h"
#include <gfx_utils.h>
#define DPRINTF(...) gfx_printf(__VA_ARGS__)
static int touch_command(u8 cmd, u8 *buf, u8 size)
{
int res = i2c_send_buf_small(I2C_3, STMFTS_I2C_ADDR, cmd, buf, size);
if (!res)
return 1;
return 0;
}
static int touch_read_reg(u8 *cmd, u32 csize, u8 *buf, u32 size)
{
int res = i2c_send_buf_small(I2C_3, STMFTS_I2C_ADDR, cmd[0], &cmd[1], csize - 1);
if (res)
res = i2c_recv_buf(buf, size, I2C_3, STMFTS_I2C_ADDR);
if (!res)
return 1;
return 0;
}
static int touch_wait_event(u8 event, u8 status, u32 timeout)
{
u32 timer = get_tmr_ms() + timeout;
while (true)
{
u8 tmp[8] = {0};
i2c_recv_buf_small(tmp, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_READ_ONE_EVENT);
if (tmp[1] == event && tmp[2] == status)
return 0;
if (get_tmr_ms() > timer)
return 1;
}
}
#define X_REAL_MAX 1264
#define Y_REAL_MAX 704
#define EDGE_OFFSET 15
static void _touch_compensate_limits(touch_event *event, bool touching)
{
event->x = MAX(event->x, EDGE_OFFSET);
event->x = MIN(event->x, X_REAL_MAX);
event->x -= EDGE_OFFSET;
u32 x_adj = (1280 * 1000) / (X_REAL_MAX - EDGE_OFFSET);
event->x = ((u32)event->x * x_adj) / 1000;
if (touching)
{
event->y = MAX(event->y, EDGE_OFFSET);
event->y = MIN(event->y, Y_REAL_MAX);
event->y -= EDGE_OFFSET;
u32 y_adj = (720 * 1000) / (Y_REAL_MAX - EDGE_OFFSET);
event->y = ((u32)event->y * y_adj) / 1000;
}
}
static void _touch_process_contact_event(touch_event *event, bool touching)
{
event->x = (event->raw[2] << 4) | ((event->raw[4] & STMFTS_MASK_Y_LSB) >> 4);
// Normally, GUI elements have bigger horizontal estate.
// Avoid parsing y axis when finger is removed to minimize touch noise.
if (touching)
{
event->y = (event->raw[3] << 4) | (event->raw[4] & STMFTS_MASK_X_MSB);
event->z = event->raw[5] | (event->raw[6] << 8);
event->z = event->z << 6;
u16 tmp = 0x40;
if ((event->raw[7] & 0x3F) != 1 && (event->raw[7] & 0x3F) != 0x3F)
tmp = event->raw[7] & 0x3F;
event->z /= tmp + 0x40;
event->fingers = ((event->raw[1] & STMFTS_MASK_TOUCH_ID) >> 4) + 1;
}
else
event->fingers = 0;
_touch_compensate_limits(event, touching);
}
static void _touch_parse_event(touch_event *event)
{
event->type = event->raw[1] & STMFTS_MASK_EVENT_ID;
switch (event->type)
{
case STMFTS_EV_MULTI_TOUCH_ENTER:
case STMFTS_EV_MULTI_TOUCH_MOTION:
_touch_process_contact_event(event, true);
if (event->z < 255) // Reject palm rest.
event->touch = true;
else
{
event->touch = false;
event->type = STMFTS_EV_MULTI_TOUCH_LEAVE;
}
break;
case STMFTS_EV_MULTI_TOUCH_LEAVE:
event->touch = false;
_touch_process_contact_event(event, false);
break;
case STMFTS_EV_NO_EVENT:
if (event->touch)
event->type = STMFTS_EV_MULTI_TOUCH_MOTION;
break;
default:
if (event->touch && event->raw[0] == STMFTS_EV_MULTI_TOUCH_MOTION)
event->type = STMFTS_EV_MULTI_TOUCH_MOTION;
else
event->type = STMFTS_EV_MULTI_TOUCH_LEAVE;
}
// gfx_con_setpos(&gfx_con, 0, 300);
// DPRINTF("x = %d \ny = %d \nz = %d \n", event->x, event->y, event->z);
// DPRINTF("0 = %02X\n1 = %02x\n2 = %02x\n3 = %02x\n", event->raw[0], event->raw[1], event->raw[2], event->raw[3]);
// DPRINTF("4 = %02X\n5 = %02x\n6 = %02x\n7 = %02x\n", event->raw[4], event->raw[5], event->raw[6], event->raw[7]);
}
void touch_poll(touch_event *event)
{
i2c_recv_buf_small(event->raw, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_LATEST_EVENT);
_touch_parse_event(event);
}
touch_event touch_poll_wait()
{
touch_event event;
do
{
touch_poll(&event);
} while (event.type != STMFTS_EV_MULTI_TOUCH_LEAVE);
return event;
}
touch_info touch_get_info()
{
touch_info info;
u8 buf[8];
memset(&buf, 0, 8);
i2c_recv_buf_small(buf, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_READ_INFO);
info.chip_id = buf[0] << 8 | buf[1];
info.fw_ver = buf[2] << 8 | buf[3];
info.config_id = buf[4];
info.config_ver = buf[5];
//DPRINTF("ID: %04X, FW Ver: %d.%02d\nCfg ID: %02x, Cfg Ver: %d\n",
// info.chip_id, info.fw_ver >> 8, info.fw_ver & 0xFF, info.config_id, info.config_ver);
return info;
}
int touch_get_fw_info(touch_fw_info_t *fw)
{
u8 buf[8] = {0};
// Get fw address info.
u8 cmd[3] = { STMFTS_RW_FRAMEBUFFER_REG, 0, 0x60 };
int res = touch_read_reg(cmd, 3, buf, 3);
if (!res)
{
// Get fw info.
cmd[1] = buf[2]; cmd[2] = buf[1];
res = touch_read_reg(cmd, 3, buf, 8);
if (!res)
{
fw->fw_id = (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8) | buf[4];
fw->ftb_ver = (buf[6] << 8) | buf[5];
}
cmd[2]++;
res = touch_read_reg(cmd, 3, buf, 8);
if (!res)
fw->fw_rev = (buf[7] << 8) | buf[6];
}
return res;
}
int touch_sys_reset()
{
u8 cmd[3] = { 0, 0x28, 0x80 }; // System reset cmd.
for (u8 retries = 0; retries < 3; retries++)
{
if (touch_command(STMFTS_WRITE_REG, cmd, 3))
{
msleep(10);
continue;
}
msleep(10);
if (touch_wait_event(STMFTS_EV_CONTROLLER_READY, 0, 20))
continue;
else
return 0;
}
return 1;
}
int touch_panel_ito_test(u8 *err)
{
int res = 0;
// Reset touchscreen module.
if (touch_sys_reset())
return res;
// Do ITO Production test.
u8 cmd[2] = { 1, 0 };
if (touch_command(STMFTS_ITO_CHECK, cmd, 2))
return res;
u32 timer = get_tmr_ms() + 2000;
while (true)
{
u8 tmp[8] = {0};
i2c_recv_buf_small(tmp, 8, I2C_3, STMFTS_I2C_ADDR, STMFTS_READ_ONE_EVENT);
if (tmp[1] == 0xF && tmp[2] == 0x5)
{
if (err)
{
err[0] = tmp[3];
err[1] = tmp[4];
}
res = 1;
break;
}
if (get_tmr_ms() > timer)
break;
}
// Reset touchscreen module.
touch_sys_reset();
return res;
}
int touch_get_fb_info(u8 *buf)
{
u8 tmp[5];
u8 cmd[3] = { STMFTS_RW_FRAMEBUFFER_REG, 0, 0 };
int res = 0;
for (u32 i = 0; i < 0x10000; i+=4)
{
if (!res)
{
cmd[1] = (i >> 8) & 0xFF;
cmd[2] = i & 0xFF;
memset(tmp, 0xCC, 5);
res = touch_read_reg(cmd, 3, tmp, 5);
memcpy(&buf[i], tmp + 1, 4);
}
}
return res;
}
int touch_sense_enable()
{
// Enable auto tuning calibration and multi-touch sensing.
u8 cmd = 1;
if (touch_command(STMFTS_AUTO_CALIBRATION, &cmd, 1))
return 0;
if (touch_command(STMFTS_MS_MT_SENSE_ON, NULL, 0))
return 0;
if (touch_command(STMFTS_CLEAR_EVENT_STACK, NULL, 0))
return 0;
return 1;
}
int touch_execute_autotune()
{
// Reset touchscreen module.
if (touch_sys_reset())
return 0;
// Trim low power oscillator.
if (touch_command(STMFTS_LP_TIMER_CALIB, NULL, 0))
return 0;
msleep(200);
// Apply Mutual Sense Compensation tuning.
if (touch_command(STMFTS_MS_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_MS_CX_TUNING_DONE, 2000))
return 0;
// Apply Self Sense Compensation tuning.
if (touch_command(STMFTS_SS_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_SS_CX_TUNING_DONE, 2000))
return 0;
// Save Compensation data to EEPROM.
if (touch_command(STMFTS_SAVE_CX_TUNING, NULL, 0))
return 0;
if (touch_wait_event(STMFTS_EV_STATUS, STMFTS_EV_STATUS_WRITE_CX_TUNE_DONE, 2000))
return 0;
return touch_sense_enable();
}
static int touch_init()
{
// Initialize touchscreen module.
if (touch_sys_reset())
return 0;
return touch_sense_enable();
}
int touch_power_on()
{
// Enables LDO6 for touchscreen VDD/AVDD supply
max77620_regulator_set_volt_and_flags(REGULATOR_LDO6, 2900000, MAX77620_POWER_MODE_NORMAL);
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_LDO6_CFG2,
MAX77620_LDO_CFG2_ADE_ENABLE | (3 << 3) | (MAX77620_POWER_MODE_NORMAL << MAX77620_LDO_POWER_MODE_SHIFT));
// Configure touchscreen GPIO.
PINMUX_AUX(PINMUX_AUX_DAP4_SCLK) = PINMUX_PULL_DOWN | 1;
gpio_config(GPIO_PORT_J, GPIO_PIN_7, GPIO_MODE_GPIO);
gpio_output_enable(GPIO_PORT_J, GPIO_PIN_7, GPIO_OUTPUT_ENABLE);
gpio_write(GPIO_PORT_J, GPIO_PIN_7, GPIO_HIGH);
// IRQ and more.
// PINMUX_AUX(PINMUX_AUX_TOUCH_INT) = PINMUX_INPUT_ENABLE | PINMUX_TRISTATE | PINMUX_PULL_UP | 3;
// gpio_config(GPIO_PORT_X, GPIO_PIN_1, GPIO_MODE_GPIO);
// gpio_write(GPIO_PORT_X, GPIO_PIN_1, GPIO_LOW);
// Configure Touscreen and GCAsic shared GPIO.
PINMUX_AUX(PINMUX_AUX_CAM_I2C_SDA) = PINMUX_LPDR | PINMUX_INPUT_ENABLE | PINMUX_TRISTATE | PINMUX_PULL_UP | 2;
PINMUX_AUX(PINMUX_AUX_CAM_I2C_SCL) = PINMUX_IO_HV | PINMUX_LPDR | PINMUX_TRISTATE | PINMUX_PULL_DOWN | 2;
gpio_config(GPIO_PORT_S, GPIO_PIN_3, GPIO_MODE_GPIO);
// Initialize I2C3.
pinmux_config_i2c(I2C_3);
clock_enable_i2c(I2C_3);
i2c_init(I2C_3);
// Wait for the touchscreen module to get ready.
touch_wait_event(STMFTS_EV_CONTROLLER_READY, 0, 20);
// Check for forced boot time calibration.
if (btn_read_vol() == (BTN_VOL_UP | BTN_VOL_DOWN))
{
u8 err[2];
if (touch_panel_ito_test(err))
if (!err[0] && !err[1])
return touch_execute_autotune();
}
// Initialize touchscreen.
u32 retries = 3;
while (retries)
{
if (touch_init())
return 1;
retries--;
}
return 0;
}
void touch_power_off()
{
// Disable touchscreen power.
gpio_write(GPIO_PORT_J, GPIO_PIN_7, GPIO_LOW);
// Disables LDO6 for touchscreen VDD, AVDD supply
max77620_regulator_enable(REGULATOR_LDO6, 0);
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_LDO6_CFG2,
MAX77620_LDO_CFG2_ADE_ENABLE | (2 << 3) | (MAX77620_POWER_MODE_NORMAL << MAX77620_LDO_POWER_MODE_SHIFT));
clock_disable_i2c(I2C_3);
}

157
bdk/input/touch.h Normal file
View file

@ -0,0 +1,157 @@
/*
* Touch driver for Nintendo Switch's STM FingerTip S (4CD60D) touch controller
*
* Copyright (c) 2018 langerhans
* Copyright (c) 2018-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/>.
*/
#ifndef __TOUCH_H_
#define __TOUCH_H_
#include <utils/types.h>
#define STMFTS_I2C_ADDR 0x49
/* I2C commands */
#define STMFTS_READ_INFO 0x80
#define STMFTS_READ_STATUS 0x84
#define STMFTS_READ_ONE_EVENT 0x85
#define STMFTS_READ_ALL_EVENT 0x86
#define STMFTS_LATEST_EVENT 0x87
#define STMFTS_SLEEP_IN 0x90
#define STMFTS_SLEEP_OUT 0x91
#define STMFTS_MS_MT_SENSE_OFF 0x92
#define STMFTS_MS_MT_SENSE_ON 0x93
#define STMFTS_SS_HOVER_SENSE_OFF 0x94
#define STMFTS_SS_HOVER_SENSE_ON 0x95
#define STMFTS_LP_TIMER_CALIB 0x97
#define STMFTS_MS_KEY_SENSE_OFF 0x9A
#define STMFTS_MS_KEY_SENSE_ON 0x9B
#define STMFTS_SYSTEM_RESET 0xA0
#define STMFTS_CLEAR_EVENT_STACK 0xA1
#define STMFTS_FULL_FORCE_CALIBRATION 0xA2
#define STMFTS_MS_CX_TUNING 0xA3
#define STMFTS_SS_CX_TUNING 0xA4
#define STMFTS_ITO_CHECK 0xA7
#define STMFTS_RELEASEINFO 0xAA
#define STMFTS_WRITE_REG 0xB6
#define STMFTS_AUTO_CALIBRATION 0xC3
#define STMFTS_NOISE_WRITE 0xC7
#define STMFTS_NOISE_READ 0xC8
#define STMFTS_RW_FRAMEBUFFER_REG 0xD0
#define STMFTS_SAVE_CX_TUNING 0xFC
#define STMFTS_UNK0 0xB8 //Request compensation
#define STMFTS_UNK1 0xCF
#define STMFTS_UNK2 0xF7
#define STMFTS_UNK3 0xFA
#define STMFTS_UNK4 0xF9
#define STMFTS_UNK5 0x62
/* events */
#define STMFTS_EV_NO_EVENT 0x00
#define STMFTS_EV_MULTI_TOUCH_DETECTED 0x02
#define STMFTS_EV_MULTI_TOUCH_ENTER 0x03
#define STMFTS_EV_MULTI_TOUCH_LEAVE 0x04
#define STMFTS_EV_MULTI_TOUCH_MOTION 0x05
#define STMFTS_EV_HOVER_ENTER 0x07
#define STMFTS_EV_HOVER_LEAVE 0x08
#define STMFTS_EV_HOVER_MOTION 0x09
#define STMFTS_EV_KEY_STATUS 0x0e
#define STMFTS_EV_ERROR 0x0f
#define STMFTS_EV_NOISE_READ 0x17
#define STMFTS_EV_NOISE_WRITE 0x18
#define STMFTS_EV_CONTROLLER_READY 0x10
#define STMFTS_EV_STATUS 0x16
#define STMFTS_EV_DEBUG 0xDB
#define STMFTS_EV_STATUS_MS_CX_TUNING_DONE 1
#define STMFTS_EV_STATUS_SS_CX_TUNING_DONE 2
#define STMFTS_EV_STATUS_WRITE_CX_TUNE_DONE 4
/* multi touch related event masks */
#define STMFTS_MASK_EVENT_ID 0x0F
#define STMFTS_MASK_TOUCH_ID 0xF0
#define STMFTS_MASK_LEFT_EVENT 0x0F
#define STMFTS_MASK_X_MSB 0x0F
#define STMFTS_MASK_Y_LSB 0xF0
/* key related event masks */
#define STMFTS_MASK_KEY_NO_TOUCH 0x00
#define STMFTS_MASK_KEY_MENU 0x01
#define STMFTS_MASK_KEY_BACK 0x02
#define STMFTS_EVENT_SIZE 8
#define STMFTS_STACK_DEPTH 32
#define STMFTS_DATA_MAX_SIZE (STMFTS_EVENT_SIZE * STMFTS_STACK_DEPTH)
#define STMFTS_MAX_FINGERS 10
typedef enum _touch_ito_error {
ITO_NO_ERROR = 0,
ITO_FORCE_OPEN,
ITO_SENSE_OPEN,
ITO_FORCE_SHRT_GND,
ITO_SENSE_SHRT_GND,
ITO_FORCE_SHRT_VCM,
ITO_SENSE_SHRT_VCM,
ITO_FORCE_SHRT_FORCE,
ITO_SENSE_SHRT_SENSE,
ITO_F2E_SENSE,
ITO_FPC_FORCE_OPEN,
ITO_FPC_SENSE_OPEN,
ITO_KEY_FORCE_OPEN,
ITO_KEY_SENSE_OPEN,
ITO_RESERVED0,
ITO_RESERVED1,
ITO_RESERVED2,
ITO_MAX_ERR_REACHED = 0xFF
} touch_ito_error;
typedef struct _touch_event {
u8 raw[8];
u16 type; // Event type.
u16 x; // Horizontal coordinates.
u16 y; // Vertical coordinates.
u32 z;
u8 fingers;
bool touch;
} touch_event;
typedef struct _touch_info {
u16 chip_id;
u16 fw_ver;
u16 config_id;
u16 config_ver;
} touch_info;
typedef struct _touch_fw_info_t {
u32 fw_id;
u16 ftb_ver;
u16 fw_rev;
} touch_fw_info_t;
void touch_poll(touch_event *event);
touch_event touch_poll_wait();
int touch_get_fw_info(touch_fw_info_t *fw);
touch_info touch_get_info();
int touch_panel_ito_test(u8 *err);
int touch_execute_autotune();
int touch_sense_enable();
int touch_power_on();
void touch_power_off();
#endif /* __TOUCH_H_ */

View file

@ -17,7 +17,7 @@
#ifndef _BLZ_H_
#define _BLZ_H_
#include "../../utils/types.h"
#include <utils/types.h>
typedef struct _blz_footer
{

View file

@ -9,7 +9,7 @@
extern "C" {
#endif
#include "../../utils/types.h"
#include <utils/types.h>
/* Status of Disk Functions */
typedef BYTE DSTATUS;
@ -23,6 +23,13 @@ typedef enum {
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 */

View file

@ -26,8 +26,8 @@
extern "C" {
#endif
#include "../../utils/types.h" /* Basic integer types */
#include "ffconf.h" /* FatFs configuration options */
#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).
@ -246,7 +246,7 @@ typedef enum {
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 */
#ifdef FF_FASTFS
#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

369
bdk/libs/lv_conf.h Normal file
View 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*/

View 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/

View 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! :)

View 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=

View file

@ -0,0 +1 @@
--convert-tabs --indent=spaces=4

View 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.

View 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"

View 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*/

View 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*/

View 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

View 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*/

View 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*/

View 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*/

File diff suppressed because it is too large Load diff

View 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*/

View 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);
}
}

View 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*/

View 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

View 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*/

View 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

View 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*/

View 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

View 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*/

View 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"

View 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;
}

View 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*/

View 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
}

View 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*/

View 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;
}

View 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*/

View 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;
}

View 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*/

View 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*/

View 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*/

File diff suppressed because it is too large Load diff

View 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*/

View 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

View 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*/

View 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

View 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*/

View 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*/

View 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*/

View 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*/

View 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*/

View 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*/

View 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
**********************/

View 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*/

View 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"

View 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*/

View 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

View 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"

View 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
**********************/

View 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

View 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
**********************/

View 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

View 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
**********************/

View 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*/

View 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

View 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*/

View 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
**********************/

View 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

View 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
**********************/

View 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

View 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;
}

View 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*/

View 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
**********************/

View 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*/

View 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*/

View 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*/

View 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
**********************/

View 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*/

Some files were not shown because too many files have changed in this diff Show more